package cn.iocoder.yudao.module.pms.dal.mysql.qhse.measure;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.pms.controller.admin.qhse.measure.vo.IotMeasureBookPageReqVO;
import cn.iocoder.yudao.module.pms.dal.dataobject.qhse.measure.IotMeasureBookDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;
import java.util.Set;

/**
 * 计量器具台账 Mapper
 *
 * @author 超级管理员
 */
@Mapper
public interface IotMeasureBookMapper extends BaseMapperX<IotMeasureBookDO> {

    default PageResult<IotMeasureBookDO> selectPage(IotMeasureBookPageReqVO reqVO, Set<Long> ids) {
        return selectPage(reqVO, new LambdaQueryWrapperX<IotMeasureBookDO>()
                .eqIfPresent(IotMeasureBookDO::getMeasureCode, reqVO.getMeasureCode())
                .likeIfPresent(IotMeasureBookDO::getMeasureName, reqVO.getMeasureName())
                .eqIfPresent(IotMeasureBookDO::getClassify, reqVO.getClassify())
                .eqIfPresent(IotMeasureBookDO::getStatus, reqVO.getStatus())
                .eqIfPresent(IotMeasureBookDO::getDutyPerson, reqVO.getDutyPerson())
                .betweenIfPresent(IotMeasureBookDO::getBuyDate, reqVO.getBuyDate())
                .eqIfPresent(IotMeasureBookDO::getBrand, reqVO.getBrand())
                .likeIfPresent(IotMeasureBookDO::getSerialNo, reqVO.getSerialNo())
                .likeIfPresent(IotMeasureBookDO::getModelName, reqVO.getModelName())
                .betweenIfPresent(IotMeasureBookDO::getLastTime, reqVO.getLastTime())
                .eqIfPresent(IotMeasureBookDO::getMeasureUnit, reqVO.getMeasureUnit())
                .eqIfPresent(IotMeasureBookDO::getMeasurePrice, reqVO.getMeasurePrice())
                .eqIfPresent(IotMeasureBookDO::getMeasurePic, reqVO.getMeasurePic())
                .eqIfPresent(IotMeasureBookDO::getRemark, reqVO.getRemark())
                .eqIfPresent(IotMeasureBookDO::getExpired, reqVO.getExpired())
                .betweenIfPresent(IotMeasureBookDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(IotMeasureBookDO::getAlertWarn, reqVO.getAlertWarn())
                .inIfPresent(IotMeasureBookDO::getDeptId, ids)
                .orderByDesc(IotMeasureBookDO::getId));
    }

    default Long selectCountByDeptAndExpireAndWarn(IotMeasureBookPageReqVO reqVO, Set<Long> ids) {
        return selectCount(new LambdaQueryWrapperX<IotMeasureBookDO>()
                .eqIfPresent(IotMeasureBookDO::getExpired, reqVO.getExpired())
                .eqIfPresent(IotMeasureBookDO::getAlertWarn, reqVO.getAlertWarn())
                .inIfPresent(IotMeasureBookDO::getDeptId, ids)
                .betweenIfPresent(IotMeasureBookDO::getCreateTime, reqVO.getCreateTime()));
    }

    default List<IotMeasureBookDO> selectListByDept(IotMeasureBookPageReqVO reqVO, Set<Long> ids) {
        return selectList(new LambdaQueryWrapperX<IotMeasureBookDO>()
                .eqIfPresent(IotMeasureBookDO::getExpired, reqVO.getExpired())
                .inIfPresent(IotMeasureBookDO::getDeptId, ids));
    }

}
