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

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.resource.device.controller.vo.DeviceCalibrationVO;
import com.zt.plat.module.qms.resource.device.controller.vo.DeviceInfomationMaintainVO;
import com.zt.plat.module.qms.resource.device.controller.vo.DeviceMaintainPageReqVO;
import com.zt.plat.module.qms.resource.device.dal.dataobject.DeviceCalibrationDO;
import com.zt.plat.module.qms.resource.device.controller.vo.DeviceCalibrationPageReqVO;
import com.zt.plat.module.qms.resource.device.dal.dataobject.DevicePeriodCheckDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 设备-检定校准 Mapper
 *
 * @author 后台管理-1
 */
@Mapper
public interface DeviceCalibrationMapper extends BaseMapperX<DeviceCalibrationDO> {

    default PageResult<DeviceCalibrationDO> selectPage(DeviceCalibrationPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<DeviceCalibrationDO>()
                .eqIfPresent(DeviceCalibrationDO::getPlanId, reqVO.getPlanId())
                .eqIfPresent(DeviceCalibrationDO::getEffectiveFlag, reqVO.getEffectiveFlag())
                .eqIfPresent(DeviceCalibrationDO::getDeviceId, reqVO.getDeviceId())
                .likeIfPresent(DeviceCalibrationDO::getSupplierName, reqVO.getSupplierName())
                .eqIfPresent(DeviceCalibrationDO::getSupplierId, reqVO.getSupplierId())
                .eqIfPresent(DeviceCalibrationDO::getSpecification, reqVO.getSpecification())
                .betweenIfPresent(DeviceCalibrationDO::getPlanCheckDate, reqVO.getPlanCheckDate())
                .betweenIfPresent(DeviceCalibrationDO::getLastCheckDate, reqVO.getLastCheckDate())
                .eqIfPresent(DeviceCalibrationDO::getFrequencyRemark, reqVO.getFrequencyRemark())
                .eqIfPresent(DeviceCalibrationDO::getCheckType, reqVO.getCheckType())
                .betweenIfPresent(DeviceCalibrationDO::getCheckDate, reqVO.getCheckDate())
                .eqIfPresent(DeviceCalibrationDO::getAgent, reqVO.getAgent())
                .eqIfPresent(DeviceCalibrationDO::getCertificateCode, reqVO.getCertificateCode())
                .betweenIfPresent(DeviceCalibrationDO::getValidityDate, reqVO.getValidityDate())
                .eqIfPresent(DeviceCalibrationDO::getCheckContent, reqVO.getCheckContent())
                .eqIfPresent(DeviceCalibrationDO::getCheckResult, reqVO.getCheckResult())
                .eqIfPresent(DeviceCalibrationDO::getFlowStatus, reqVO.getFlowStatus())
                .eqIfPresent(DeviceCalibrationDO::getFlowInstanceId, reqVO.getFlowInstanceId())
                .eqIfPresent(DeviceCalibrationDO::getCancelFlag, reqVO.getCancelFlag())
                .eqIfPresent(DeviceCalibrationDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
                .eqIfPresent(DeviceCalibrationDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(DeviceCalibrationDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(DeviceCalibrationDO::getCreateTime));
    }

    /*
     * 查询指定设备的最新数据
     * */
    List<DeviceCalibrationVO> getLastDataCheckList(@Param("param") JSONObject param);

    DeviceCalibrationVO getLastData(@Param("param") JSONObject param);


    IPage<DeviceCalibrationVO> queryPageList(Page<DeviceCalibrationPageReqVO> page, @Param("param") DeviceCalibrationPageReqVO param);

}