package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.ShopCouponApplyCateMapper;
import com.gxwebsoft.shop.service.ShopCouponApplyCateService;
import com.gxwebsoft.shop.entity.ShopCouponApplyCate;
import com.gxwebsoft.shop.param.ShopCouponApplyCateParam;
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-11 12:47:49
 */
@Service
public class ShopCouponApplyCateServiceImpl extends ServiceImpl<ShopCouponApplyCateMapper, ShopCouponApplyCate> implements ShopCouponApplyCateService {

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

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

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

    @Override
    public void removeByCouponId(Integer couponId) {
        remove(
                new LambdaQueryWrapper<ShopCouponApplyCate>()
                        .eq(ShopCouponApplyCate::getCouponId, couponId)
        );
    }

}
