package com.gxwebsoft.apps.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.apps.mapper.EquipmentRecordMapper;
import com.gxwebsoft.apps.service.EquipmentRecordService;
import com.gxwebsoft.apps.entity.EquipmentRecord;
import com.gxwebsoft.apps.param.EquipmentRecordParam;
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-03 01:23:53
 */
@Service
public class EquipmentRecordServiceImpl extends ServiceImpl<EquipmentRecordMapper, EquipmentRecord> implements EquipmentRecordService {

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

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

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

}
