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.MerchantCollectMapper;
import com.gxwebsoft.shop.service.MerchantCollectService;
import com.gxwebsoft.shop.entity.MerchantCollect;
import com.gxwebsoft.shop.param.MerchantCollectParam;
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-05-23 12:05:53
 */
@Service
public class MerchantCollectServiceImpl extends ServiceImpl<MerchantCollectMapper, MerchantCollect> implements MerchantCollectService {

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

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

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

    @Override
    public MerchantCollect check(Integer merchantId, Integer userId) {
        return getOne(
                new LambdaQueryWrapper<MerchantCollect>()
                        .eq(MerchantCollect::getMerchantId, merchantId)
                        .eq(MerchantCollect::getUserId, userId)
        );
    }

}
