package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.ShopStoreMapper;
import com.gxwebsoft.shop.service.ShopStoreService;
import com.gxwebsoft.shop.entity.ShopStore;
import com.gxwebsoft.shop.param.ShopStoreParam;
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 15:00:25
 */
@Service
public class ShopStoreServiceImpl extends ServiceImpl<ShopStoreMapper, ShopStore> implements ShopStoreService {

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

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

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

}
