package com.zt.plat.module.qms.resource.device.dal.mapper;

import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;
import com.zt.plat.framework.mybatis.core.query.MPJLambdaWrapperX;
import com.zt.plat.module.qms.business.reportdoc.controller.vo.ReportDocumentMainRespVO;
import com.zt.plat.module.qms.business.reportdoc.dal.dataobject.ReportDocumentDataDO;
import com.zt.plat.module.qms.business.reportdoc.dal.dataobject.ReportDocumentMainDO;
import com.zt.plat.module.qms.resource.device.controller.vo.DeviceConfigBusinessRulePageReqVO;
import com.zt.plat.module.qms.resource.device.controller.vo.DeviceConfigBusinessRuleRespVO;
import com.zt.plat.module.qms.resource.device.dal.dataobject.DeviceConfigBusinessItemDO;
import com.zt.plat.module.qms.resource.device.dal.dataobject.DeviceConfigBusinessRuleDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 设备-业务配置 Mapper
 *
 * @author 后台管理-1
 */
@Mapper
public interface DeviceConfigBusinessRuleMapper extends BaseMapperX<DeviceConfigBusinessRuleDO> {

    default PageResult<DeviceConfigBusinessRuleRespVO> selectPage(DeviceConfigBusinessRulePageReqVO reqVO) {
        MPJLambdaWrapperX<DeviceConfigBusinessRuleDO> wrapper = new MPJLambdaWrapperX<>();
        wrapper.selectAll(DeviceConfigBusinessRuleDO.class);
        wrapper.selectSub(DeviceConfigBusinessItemDO.class, s->
                s.selectCount(DeviceConfigBusinessItemDO::getRuleId).eq(DeviceConfigBusinessItemDO::getRuleId, DeviceConfigBusinessRuleDO::getId), DeviceConfigBusinessRuleRespVO::getItemCount);
        wrapper.eqIfPresent(DeviceConfigBusinessRuleDO::getProductId, reqVO.getProductId())
                .inIfPresent(DeviceConfigBusinessRuleDO::getProductId, reqVO.getProductIdList())
                .eqIfPresent(DeviceConfigBusinessRuleDO::getBusinessDomain, reqVO.getBusinessDomain())
                .eqIfPresent(DeviceConfigBusinessRuleDO::getRequireFlag, reqVO.getRequireFlag())
                .eqIfPresent(DeviceConfigBusinessRuleDO::getSubitemDomainType, reqVO.getSubitemDomainType())
                .eqIfPresent(DeviceConfigBusinessRuleDO::getFrequencyType, reqVO.getFrequencyType())
                .eqIfPresent(DeviceConfigBusinessRuleDO::getFrequency, reqVO.getFrequency())
                .eqIfPresent(DeviceConfigBusinessRuleDO::getFrequencyRemark, reqVO.getFrequencyRemark())
                .eqIfPresent(DeviceConfigBusinessRuleDO::getReportTemplateKey, reqVO.getReportTemplateKey())
                .eqIfPresent(DeviceConfigBusinessRuleDO::getFormComponent, reqVO.getFormComponent())
                .eqIfPresent(DeviceConfigBusinessRuleDO::getTreatmentMethod, reqVO.getTreatmentMethod())
                .eqIfPresent(DeviceConfigBusinessRuleDO::getTreatmentUser, reqVO.getTreatmentUser())
                .eqIfPresent(DeviceConfigBusinessRuleDO::getCalibrationCheckType, reqVO.getCalibrationCheckType())
                .eqIfPresent(DeviceConfigBusinessRuleDO::getStandard, reqVO.getStandard())
                .eqIfPresent(DeviceConfigBusinessRuleDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
                .eqIfPresent(DeviceConfigBusinessRuleDO::getRemark, reqVO.getRemark())

                .betweenIfPresent(DeviceConfigBusinessRuleDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(DeviceConfigBusinessRuleDO::getId);
//        return selectPage(reqVO, new LambdaQueryWrapperX<DeviceConfigBusinessRuleDO>()
                return selectJoinPage(reqVO, DeviceConfigBusinessRuleRespVO.class, wrapper);
    }

}