package com.gxwebsoft.apps.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.apps.mapper.EquipmentFaultMapper;
import com.gxwebsoft.apps.service.EquipmentFaultService;
import com.gxwebsoft.apps.entity.EquipmentFault;
import com.gxwebsoft.apps.param.EquipmentFaultParam;
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 2022-12-01 18:40:25
 */
@Service
public class EquipmentFaultServiceImpl extends ServiceImpl<EquipmentFaultMapper, EquipmentFault> implements EquipmentFaultService {

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

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

    @Override
    public EquipmentFault getByIdRel(Integer id) {
        EquipmentFaultParam param = new EquipmentFaultParam();
        param.setId(id);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
