package com.gxwebsoft.cms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.cms.entity.CmsProductCategory;
import com.gxwebsoft.cms.mapper.CmsProductCategoryMapper;
import com.gxwebsoft.cms.param.CmsProductCategoryParam;
import com.gxwebsoft.cms.service.CmsProductCategoryService;
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 WorkBuddy
 * @since 2026-07-17
 */
@Service
public class CmsProductCategoryServiceImpl extends ServiceImpl<CmsProductCategoryMapper, CmsProductCategory> implements CmsProductCategoryService {

    @Override
    public PageResult<CmsProductCategory> pageRel(CmsProductCategoryParam param) {
        PageParam<CmsProductCategory, CmsProductCategoryParam> page = new PageParam<>(param);
        page.setDefaultOrder("sort_number asc, create_time desc");
        IPage<CmsProductCategory> result = page(page, page.getOrderWrapper());
        return new PageResult<>(result.getRecords(), result.getTotal());
    }

    @Override
    public List<CmsProductCategory> listRel(CmsProductCategoryParam param) {
        PageParam<CmsProductCategory, CmsProductCategoryParam> page = new PageParam<>(param);
        page.setDefaultOrder("sort_number asc, create_time desc");
        return list(page.getOrderWrapper());
    }

    @Override
    public CmsProductCategory getByIdRel(Integer categoryId) {
        return getById(categoryId);
    }
}
