package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.GoodsCategoryMapper;
import com.gxwebsoft.shop.service.GoodsCategoryService;
import com.gxwebsoft.shop.entity.GoodsCategory;
import com.gxwebsoft.shop.param.GoodsCategoryParam;
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-03-30 19:34:16
 */
@Service
public class GoodsCategoryServiceImpl extends ServiceImpl<GoodsCategoryMapper, GoodsCategory> implements GoodsCategoryService {

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

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

    @Override
    public GoodsCategory getByIdRel(Integer categoryId) {
        GoodsCategoryParam param = new GoodsCategoryParam();
        param.setCategoryId(categoryId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
