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.MerchantPackageGoodsMapper;
import com.gxwebsoft.shop.service.MerchantPackageGoodsService;
import com.gxwebsoft.shop.entity.MerchantPackageGoods;
import com.gxwebsoft.shop.param.MerchantPackageGoodsParam;
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-11-20 01:55:04
 */
@Service
public class MerchantPackageGoodsServiceImpl extends ServiceImpl<MerchantPackageGoodsMapper, MerchantPackageGoods> implements MerchantPackageGoodsService {

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

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

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

    @Override
    public List<MerchantPackageGoods> listByPackage(Integer packageId) {
        return list(
                new LambdaQueryWrapper<MerchantPackageGoods>()
                        .eq(MerchantPackageGoods::getPackageId, packageId)
        );
    }

}
