package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.ShopWarehouseMapper;
import com.gxwebsoft.shop.service.ShopWarehouseService;
import com.gxwebsoft.shop.entity.ShopWarehouse;
import com.gxwebsoft.shop.param.ShopWarehouseParam;
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 2026-01-30 17:46:48
 */
@Service
public class ShopWarehouseServiceImpl extends ServiceImpl<ShopWarehouseMapper, ShopWarehouse> implements ShopWarehouseService {

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

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

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

}
