package com.gxwebsoft.apps.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.apps.mapper.EquipmentGoodsMapper;
import com.gxwebsoft.apps.service.EquipmentGoodsService;
import com.gxwebsoft.apps.entity.EquipmentGoods;
import com.gxwebsoft.apps.param.EquipmentGoodsParam;
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-02-28 22:40:50
 */
@Service
public class EquipmentGoodsServiceImpl extends ServiceImpl<EquipmentGoodsMapper, EquipmentGoods> implements EquipmentGoodsService {

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

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

    @Override
    public EquipmentGoods getByIdRel(Integer goodsId) {
        EquipmentGoodsParam param = new EquipmentGoodsParam();
        param.setGoodsId(goodsId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
