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.ExpressTemplateDetailMapper;
import com.gxwebsoft.shop.service.ExpressTemplateDetailService;
import com.gxwebsoft.shop.entity.ExpressTemplateDetail;
import com.gxwebsoft.shop.param.ExpressTemplateDetailParam;
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-05 18:03:28
 */
@Service
public class ExpressTemplateDetailServiceImpl extends ServiceImpl<ExpressTemplateDetailMapper, ExpressTemplateDetail> implements ExpressTemplateDetailService {

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

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

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

    @Override
    public List<ExpressTemplateDetail> listByTemplateId(Integer templateId) {
        return list(
                new LambdaQueryWrapper<ExpressTemplateDetail>()
                        .eq(ExpressTemplateDetail::getTemplateId, templateId)
        );
    }

}
