package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.ShopArticleMapper;
import com.gxwebsoft.shop.service.ShopArticleService;
import com.gxwebsoft.shop.entity.ShopArticle;
import com.gxwebsoft.shop.param.ShopArticleParam;
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 2025-08-13 05:14:53
 */
@Service
public class ShopArticleServiceImpl extends ServiceImpl<ShopArticleMapper, ShopArticle> implements ShopArticleService {

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

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

    @Override
    public ShopArticle getByIdRel(Integer articleId) {
        ShopArticleParam param = new ShopArticleParam();
        param.setArticleId(articleId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
