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.module.qms.core.aspect.annotation.QmsPermission;
import com.zt.plat.module.qms.enums.QmsCommonConstant;
import com.zt.plat.module.qms.resource.device.controller.vo.DeviceApplyPageReqVO;
import com.zt.plat.module.qms.resource.device.dal.dataobject.DeviceApplyDO;
import org.apache.ibatis.annotations.Mapper;

import static com.zt.plat.module.qms.enums.QmsPermissionConstant.DEPT_DATA_AND_SUB;
import static com.zt.plat.module.qms.enums.QmsPermissionConstant.DEVICE_MANAGER;

/**
 * 设备通用流程,验收、降级、停用、报废、还原、启用 Mapper
 *
 * @author 后台管理-1
 */
@Mapper
public interface DeviceApplyMapper extends BaseMapperX<DeviceApplyDO> {

    @QmsPermission(deptDataRoleCodes = DEPT_DATA_AND_SUB, moduleDataRoleCodes = DEVICE_MANAGER)
    default PageResult<DeviceApplyDO> selectPage(DeviceApplyPageReqVO reqVO) {
        LambdaQueryWrapperX<DeviceApplyDO> wrapper = new LambdaQueryWrapperX<>();
        wrapper.neIfPresent(DeviceApplyDO::getBusinessStatus, QmsCommonConstant.TEMP_DATA_CODE)
                .likeIfPresent(DeviceApplyDO::getBusinessName, reqVO.getBusinessName())
                .likeIfPresent(DeviceApplyDO::getApplyDepartmentName, reqVO.getApplyDepartmentName())
                .eqIfPresent(DeviceApplyDO::getApplyDepartment, reqVO.getApplyDepartment())
                .likeIfPresent(DeviceApplyDO::getApplyUserName, reqVO.getApplyUserName())
                .eqIfPresent(DeviceApplyDO::getApplyUser, reqVO.getApplyUser())
                .likeIfPresent(DeviceApplyDO::getTitle, reqVO.getTitle())
                .eqIfPresent(DeviceApplyDO::getBusinessCode, reqVO.getBusinessCode())
                .betweenIfPresent(DeviceApplyDO::getBusinessDate, reqVO.getBusinessDate())
                .eqIfPresent(DeviceApplyDO::getBusinessReason, reqVO.getBusinessReason())
                .eqIfPresent(DeviceApplyDO::getBusinessStatus, reqVO.getBusinessStatus())
                .eqIfPresent(DeviceApplyDO::getBusinessUser, reqVO.getBusinessUser())
                .eqIfPresent(DeviceApplyDO::getBusinessUserId, reqVO.getBusinessUserId())
                .eqIfPresent(DeviceApplyDO::getBusinessDepartment, reqVO.getBusinessDepartment())
                .eqIfPresent(DeviceApplyDO::getBusinessDepartmentId, reqVO.getBusinessDepartmentId())
                .betweenIfPresent(DeviceApplyDO::getPlanGivebackDate, reqVO.getPlanGivebackDate())
                .eqIfPresent(DeviceApplyDO::getGivebackReceiveUser, reqVO.getGivebackReceiveUser())
                .eqIfPresent(DeviceApplyDO::getGivebackReceiveUserId, reqVO.getGivebackReceiveUserId())
                .eqIfPresent(DeviceApplyDO::getDataCollectionId, reqVO.getDataCollectionId())
                .eqIfPresent(DeviceApplyDO::getFormData, reqVO.getFormData())
                .eqIfPresent(DeviceApplyDO::getFlowInstanceId, reqVO.getFlowInstanceId())
                .eqIfPresent(DeviceApplyDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
                .eqIfPresent(DeviceApplyDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(DeviceApplyDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(DeviceApplyDO::getId);
        return selectPage(reqVO, wrapper);
    }

}