package com.gxwebsoft.tower.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.tower.mapper.TowerWarehouseMapper;
import com.gxwebsoft.tower.service.TowerWarehouseService;
import com.gxwebsoft.tower.entity.TowerWarehouse;
import com.gxwebsoft.tower.param.TowerWarehouseParam;
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-05-20 15:06:43
 */
@Service
public class TowerWarehouseServiceImpl extends ServiceImpl<TowerWarehouseMapper, TowerWarehouse> implements TowerWarehouseService {

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

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

    @Override
    public TowerWarehouse getByIdRel(Integer warehouseId) {
        TowerWarehouseParam param = new TowerWarehouseParam();
        param.setWarehouseId(warehouseId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
