package com.gxwebsoft.tower.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.tower.mapper.TowerPurchaseMapper;
import com.gxwebsoft.tower.service.TowerPurchaseService;
import com.gxwebsoft.tower.entity.TowerPurchase;
import com.gxwebsoft.tower.param.TowerPurchaseParam;
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 2024-02-05 20:53:32
 */
@Service
public class TowerPurchaseServiceImpl extends ServiceImpl<TowerPurchaseMapper, TowerPurchase> implements TowerPurchaseService {

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

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

    @Override
    public TowerPurchase getByIdRel(Integer purchaseId) {
        TowerPurchaseParam param = new TowerPurchaseParam();
        param.setPurchaseId(purchaseId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
