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

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

/**
 * 设备-使用记录 Mapper
 *
 * @author 后台管理-1
 */
@Mapper
public interface DeviceUseRecordMapper extends BaseMapperX<DeviceUseRecordDO> {

    default PageResult<DeviceUseRecordDO> selectPage(DeviceUseRecordPageReqVO reqVO) {

        LambdaQueryWrapperX<DeviceUseRecordDO> query = new LambdaQueryWrapperX<DeviceUseRecordDO>()
                .eqIfPresent(DeviceUseRecordDO::getDeviceId, reqVO.getDeviceId())
                .likeIfPresent(DeviceUseRecordDO::getUserName, reqVO.getUserName())
                .eqIfPresent(DeviceUseRecordDO::getUserId, reqVO.getUserId())
                .betweenIfPresent(DeviceUseRecordDO::getUseTimeStart, reqVO.getUseTimeStart())
                .betweenIfPresent(DeviceUseRecordDO::getUseTimeEnd, reqVO.getUseTimeEnd())
                .eqIfPresent(DeviceUseRecordDO::getUseRemark, reqVO.getUseRemark())
                .eqIfPresent(DeviceUseRecordDO::getStateBefore, reqVO.getStateBefore())
                .eqIfPresent(DeviceUseRecordDO::getStateRun, reqVO.getStateRun())
                .eqIfPresent(DeviceUseRecordDO::getStateAfter, reqVO.getStateAfter())
                .eqIfPresent(DeviceUseRecordDO::getTemperature, reqVO.getTemperature())
                .eqIfPresent(DeviceUseRecordDO::getHumidity, reqVO.getHumidity())
                .eqIfPresent(DeviceUseRecordDO::getDataSource, reqVO.getDataSource())
                .eqIfPresent(DeviceUseRecordDO::getSystemDepartmentCode, reqVO.getSystemDepartmentCode())
                .eqIfPresent(DeviceUseRecordDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(DeviceUseRecordDO::getCreateTime, reqVO.getCreateTime());
        if("0".equals(reqVO.getUseTimeEndFlag()))
            query.isNull(DeviceUseRecordDO::getUseTimeEnd);
        if("1".equals(reqVO.getUseTimeEndFlag()))
            query.isNotNull(DeviceUseRecordDO::getUseTimeEnd);
        query.orderByDesc(DeviceUseRecordDO::getId);
        return selectPage(reqVO, query);
    }

    IPage<DeviceInfomationUseRecordVO> queryPageListWithCount(Page<DeviceInfomationUseRecordVO> page, @Param("param") DeviceUseRecordPageReqVO param);


//    DeviceUseRecordVO queryVoById(@Param("id") Long id);


}