package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.CategoryMapper;
import com.gxwebsoft.shop.service.CategoryService;
import com.gxwebsoft.shop.entity.Category;
import com.gxwebsoft.shop.param.CategoryParam;
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 2022-11-22 17:45:37
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

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

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

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

}
