package com.gxwebsoft.glt.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.glt.mapper.GltTicketTemplateMapper;
import com.gxwebsoft.glt.service.GltTicketTemplateService;
import com.gxwebsoft.glt.entity.GltTicketTemplate;
import com.gxwebsoft.glt.param.GltTicketTemplateParam;
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 2026-02-03 18:55:54
 */
@Service
public class GltTicketTemplateServiceImpl extends ServiceImpl<GltTicketTemplateMapper, GltTicketTemplate> implements GltTicketTemplateService {

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

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

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

}
