package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.ShopStoreWarehouseMapper;
import com.gxwebsoft.shop.service.ShopStoreWarehouseService;
import com.gxwebsoft.shop.entity.ShopStoreWarehouse;
import com.gxwebsoft.shop.param.ShopStoreWarehouseParam;
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-02-07 18:10:25
 */
@Service
public class ShopStoreWarehouseServiceImpl extends ServiceImpl<ShopStoreWarehouseMapper, ShopStoreWarehouse> implements ShopStoreWarehouseService {

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

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

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

}
