package com.gxwebsoft.apps.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.apps.mapper.EquipmentOrderMapper;
import com.gxwebsoft.apps.service.EquipmentOrderService;
import com.gxwebsoft.apps.entity.EquipmentOrder;
import com.gxwebsoft.apps.param.EquipmentOrderParam;
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-04-14 21:24:31
 */
@Service
public class EquipmentOrderServiceImpl extends ServiceImpl<EquipmentOrderMapper, EquipmentOrder> implements EquipmentOrderService {

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

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

    @Override
    public EquipmentOrder getByIdRel(Integer orderId) {
        EquipmentOrderParam param = new EquipmentOrderParam();
        param.setOrderId(orderId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
