package com.gxwebsoft.apps.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.apps.mapper.EquipmentAlarmMapper;
import com.gxwebsoft.apps.service.EquipmentAlarmService;
import com.gxwebsoft.apps.entity.EquipmentAlarm;
import com.gxwebsoft.apps.param.EquipmentAlarmParam;
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 23:49:44
 */
@Service
public class EquipmentAlarmServiceImpl extends ServiceImpl<EquipmentAlarmMapper, EquipmentAlarm> implements EquipmentAlarmService {

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

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

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

}
