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.DevicePeriodCheckVO;
import com.zt.plat.module.qms.resource.device.dal.dataobject.DevicePeriodCheckDO;
import com.zt.plat.module.qms.resource.device.controller.vo.DevicePeriodCheckPageReqVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 设备-期间核查 Mapper
 *
 * @author 后台管理-1
 */
@Mapper
public interface DevicePeriodCheckMapper extends BaseMapperX<DevicePeriodCheckDO> {

    default PageResult<DevicePeriodCheckDO> selectPage(DevicePeriodCheckPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<DevicePeriodCheckDO>()
                .eqIfPresent(DevicePeriodCheckDO::getPlanId, reqVO.getPlanId())
                .eqIfPresent(DevicePeriodCheckDO::getEffectiveFlag, reqVO.getEffectiveFlag())
                .eqIfPresent(DevicePeriodCheckDO::getDeviceId, reqVO.getDeviceId())
                .eqIfPresent(DevicePeriodCheckDO::getCheckPersonRemark, reqVO.getCheckPersonRemark())
                .likeIfPresent(DevicePeriodCheckDO::getCheckPersonName, reqVO.getCheckPersonName())
                .eqIfPresent(DevicePeriodCheckDO::getCheckPersonId, reqVO.getCheckPersonId())
                .likeIfPresent(DevicePeriodCheckDO::getRecheckPersonName, reqVO.getRecheckPersonName())
                .eqIfPresent(DevicePeriodCheckDO::getRecheckPersonId, reqVO.getRecheckPersonId())
                .eqIfPresent(DevicePeriodCheckDO::getCheckAccording, reqVO.getCheckAccording())
                .eqIfPresent(DevicePeriodCheckDO::getCheckAccordingRemark, reqVO.getCheckAccordingRemark())
                .eqIfPresent(DevicePeriodCheckDO::getCheckContent, reqVO.getCheckContent())
                .eqIfPresent(DevicePeriodCheckDO::getCheckResult, reqVO.getCheckResult())
                .eqIfPresent(DevicePeriodCheckDO::getCheckRemark, reqVO.getCheckRemark())
                .betweenIfPresent(DevicePeriodCheckDO::getCheckDate, reqVO.getCheckDate())
                .betweenIfPresent(DevicePeriodCheckDO::getLastCheckDate, reqVO.getLastCheckDate())
                .eqIfPresent(DevicePeriodCheckDO::getPlanCheckDateStart, reqVO.getPlanCheckDateStart())
                .eqIfPresent(DevicePeriodCheckDO::getPlanCheckDateEnd, reqVO.getPlanCheckDateEnd())
                .eqIfPresent(DevicePeriodCheckDO::getFrequencyRemark, reqVO.getFrequencyRemark())
                .eqIfPresent(DevicePeriodCheckDO::getFlowStatus, reqVO.getFlowStatus())
                .eqIfPresent(DevicePeriodCheckDO::getFlowInstanceId, reqVO.getFlowInstanceId())
                .eqIfPresent(DevicePeriodCheckDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
                .eqIfPresent(DevicePeriodCheckDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(DevicePeriodCheckDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(DevicePeriodCheckDO::getCreateTime));
    }

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

    IPage<DevicePeriodCheckVO> queryPageListDevice(Page<DevicePeriodCheckPageReqVO> page, @Param("param") DevicePeriodCheckPageReqVO param);

    IPage<DevicePeriodCheckVO> queryPageListMaterial(Page<DevicePeriodCheckPageReqVO> page, @Param("param") DevicePeriodCheckPageReqVO param);

    DevicePeriodCheckVO getLastDataDevice(@Param("param") JSONObject param);
    DevicePeriodCheckVO getLastDataMaterial(@Param("param") JSONObject param);
}