package com.gxwebsoft.tower.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.tower.mapper.TowerEquipmentMapper;
import com.gxwebsoft.tower.service.TowerEquipmentService;
import com.gxwebsoft.tower.entity.TowerEquipment;
import com.gxwebsoft.tower.param.TowerEquipmentParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 塔吊设备管理Service实现
 *
 * @author 科技小王子
 * @since 2023-05-20 15:06:43
 */
@Service
public class TowerEquipmentServiceImpl extends ServiceImpl<TowerEquipmentMapper, TowerEquipment> implements TowerEquipmentService {

    @Override
    public PageResult<TowerEquipment> pageRel(TowerEquipmentParam param) {
        PageParam<TowerEquipment, TowerEquipmentParam> page = new PageParam<>(param);
        page.setDefaultOrder("create_time desc");
        List<TowerEquipment> list = baseMapper.selectPageRel(page, param);
        return new PageResult<>(list, page.getTotal());
    }

    @Override
    public List<TowerEquipment> listRel(TowerEquipmentParam param) {
        List<TowerEquipment> list = baseMapper.selectListRel(param);
        // 排序
        PageParam<TowerEquipment, TowerEquipmentParam> page = new PageParam<>();
        page.setDefaultOrder("create_time desc");
        return page.sortRecords(list);
    }

    @Override
    public TowerEquipment getByIdRel(Integer equipmentId) {
        TowerEquipmentParam param = new TowerEquipmentParam();
        param.setEquipmentId(equipmentId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
