package com.gxwebsoft.shop.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.PaymentTemplateMapper;
import com.gxwebsoft.shop.service.PaymentTemplateService;
import com.gxwebsoft.shop.entity.PaymentTemplate;
import com.gxwebsoft.shop.param.PaymentTemplateParam;
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 2022-12-09 13:59:38
 */
@Service
public class PaymentTemplateServiceImpl extends ServiceImpl<PaymentTemplateMapper, PaymentTemplate> implements PaymentTemplateService {

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

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

    @Override
    public PaymentTemplate getByIdRel(Integer templateId) {
        PaymentTemplateParam param = new PaymentTemplateParam();
        param.setTemplateId(templateId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
