package com.zt.plat.module.qms.business.reportdoc.dal.mapper;

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.qms.business.reportdoc.controller.vo.*;
import com.zt.plat.module.qms.business.reportdoc.dal.dataobject.ReportDocumentTypeDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 报告类型配置 Mapper
 *
 * @author 后台管理
 */
@Mapper
public interface ReportDocumentTypeMapper extends BaseMapperX<ReportDocumentTypeDO> {

    default PageResult<ReportDocumentTypeDO> selectPage(ReportDocumentTypePageReqVO reqVO) {
        LambdaQueryWrapperX<ReportDocumentTypeDO> wrapper = new LambdaQueryWrapperX<>();
        wrapper.eqIfPresent(ReportDocumentTypeDO::getConfigReportTypeId, reqVO.getConfigReportTypeId());
        wrapper.likeIfPresent(ReportDocumentTypeDO::getName, reqVO.getName());
        wrapper.eqIfPresent(ReportDocumentTypeDO::getMainId, reqVO.getMainId());
        wrapper.eqIfPresent(ReportDocumentTypeDO::getCurrentFlag, reqVO.getCurrentFlag());
        wrapper.eqIfPresent(ReportDocumentTypeDO::getFlowKey, reqVO.getFlowKey());
        wrapper.eqIfPresent(ReportDocumentTypeDO::getReportKey, reqVO.getReportKey());
        wrapper.eqIfPresent(ReportDocumentTypeDO::getCodeRule, reqVO.getCodeRule());
        wrapper.eqIfPresent(ReportDocumentTypeDO::getDocumentType, reqVO.getDocumentType());
        wrapper.eqIfPresent(ReportDocumentTypeDO::getPermission, reqVO.getPermission());
        wrapper.eqIfPresent(ReportDocumentTypeDO::getSampleCount, reqVO.getSampleCount());
        wrapper.eqIfPresent(ReportDocumentTypeDO::getCustomConfig, reqVO.getCustomConfig());
        wrapper.eqIfPresent(ReportDocumentTypeDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode());
        wrapper.betweenIfPresent(ReportDocumentTypeDO::getCreateTime, reqVO.getCreateTime());
        wrapper.eqIfPresent(ReportDocumentTypeDO::getRemark, reqVO.getRemark());
        wrapper.eqIfPresent(ReportDocumentTypeDO::getVersion, reqVO.getVersion());
        wrapper.likeIfPresent(ReportDocumentTypeDO::getPageComponent, reqVO.getPageComponent());
        wrapper.likeIfPresent(ReportDocumentTypeDO::getPageComponentMobile, reqVO.getPageComponentMobile());
        wrapper.orderByDesc(ReportDocumentTypeDO::getId);
        if(reqVO.getMainId() != null){
            wrapper.orderByDesc(ReportDocumentTypeDO::getVersion);
        }
        wrapper.orderByAsc(ReportDocumentTypeDO::getSortNo);
        return selectPage(reqVO, wrapper);

    }

    List<ReportDocumentTypeDO> selectListWithPermission(@Param("param") ReportDocumentTypePageReqVO param);


}