package com.gxwebsoft.common.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.system.entity.MerchantApply;
import com.gxwebsoft.common.system.mapper.MerchantApplyMapper;
import com.gxwebsoft.common.system.param.MerchantApplyParam;
import com.gxwebsoft.common.system.service.MerchantApplyService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商户入驻申请Service实现
 *
 * @author 科技小王子
 * @since 2024-04-05 01:24:36
 */
@Service
public class MerchantApplyServiceImpl extends ServiceImpl<MerchantApplyMapper, MerchantApply> implements MerchantApplyService {

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

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

    @Override
    public MerchantApply getByIdRel(Integer applyId) {
        MerchantApplyParam param = new MerchantApplyParam();
        param.setApplyId(applyId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
