package com.zt.plat.module.base.dal.mysql.tmpltp;

import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.zt.plat.module.base.controller.admin.templtp.vo.TemplateInstancePageReqVO;
import com.zt.plat.module.base.dal.dataobject.tmpltp.TemplateInstanceDO;
import com.zt.plat.module.tmpltp.enums.TmplStsEnum;
import org.apache.ibatis.annotations.Mapper;


/**
 * 模板实例 Mapper
 *
 * @author 后台管理
 */
@Mapper
public interface TemplateInstanceMapper extends BaseMapperX<TemplateInstanceDO> {

    default PageResult<TemplateInstanceDO> selectPage(TemplateInstancePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<TemplateInstanceDO>()
                .eqIfPresent(TemplateInstanceDO::getTpId, reqVO.getTpId())
                .likeIfPresent(TemplateInstanceDO::getName, reqVO.getName())
                .eqIfPresent(TemplateInstanceDO::getCdg, reqVO.getCdg())
                .eqIfPresent(TemplateInstanceDO::getDsp, reqVO.getDsp())
                .eqIfPresent(TemplateInstanceDO::getCntt, reqVO.getCntt())
                .eqIfPresent(TemplateInstanceDO::getOrigCntt, reqVO.getOrigCntt())
                .eqIfPresent(TemplateInstanceDO::getFileTp, reqVO.getFileTp())
                .eqIfPresent(TemplateInstanceDO::getVer, reqVO.getVer())
                .eqIfPresent(TemplateInstanceDO::getSts, reqVO.getSts())
                .betweenIfPresent(TemplateInstanceDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(TemplateInstanceDO::getId));
    }
    default PageResult<TemplateInstanceDO> listExcludingDisabled(TemplateInstancePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<TemplateInstanceDO>()
                .eqIfPresent(TemplateInstanceDO::getTpId, reqVO.getTpId())
                .likeIfPresent(TemplateInstanceDO::getName, reqVO.getName())
                .eqIfPresent(TemplateInstanceDO::getCdg, reqVO.getCdg())
                .eqIfPresent(TemplateInstanceDO::getDsp, reqVO.getDsp())
                .eqIfPresent(TemplateInstanceDO::getCntt, reqVO.getCntt())
                .eqIfPresent(TemplateInstanceDO::getOrigCntt, reqVO.getOrigCntt())
                .eqIfPresent(TemplateInstanceDO::getFileTp, reqVO.getFileTp())
                .eqIfPresent(TemplateInstanceDO::getVer, reqVO.getVer())
                .eqIfPresent(TemplateInstanceDO::getSts, reqVO.getSts())
                .betweenIfPresent(TemplateInstanceDO::getCreateTime, reqVO.getCreateTime())
                .ne(TemplateInstanceDO::getSts, TmplStsEnum.STOPPED.getCode()) // 不包含停用状态（不等于停用状态）
                .orderByDesc(TemplateInstanceDO::getId));
    }

}
