package cn.iocoder.yudao.module.pms.dal.mysql.inspect;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.pms.controller.admin.inspect.plan.vo.IotInspectPlanPageReqVO;
import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDevicePageReqVO;
import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
import cn.iocoder.yudao.module.pms.dal.dataobject.inspect.IotInspectPlanDO;
import cn.iocoder.yudao.module.pms.dal.dataobject.maintain.IotMaintainDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * 巡检计划 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface IotInspectPlanMapper extends BaseMapperX<IotInspectPlanDO> {

    default PageResult<IotInspectPlanDO> selectPage(IotInspectPlanPageReqVO reqVO, Collection<Long> ids) {
        return selectPage(reqVO, new LambdaQueryWrapperX<IotInspectPlanDO>()
                .likeIfPresent(IotInspectPlanDO::getPlanTitle, reqVO.getPlanTitle())
                .eqIfPresent(IotInspectPlanDO::getPlanCode, reqVO.getPlanCode())
                .eqIfPresent(IotInspectPlanDO::getPlanCycle, reqVO.getPlanCycle())
                .eqIfPresent(IotInspectPlanDO::getPlanUnit, reqVO.getPlanUnit())
                .eqIfPresent(IotInspectPlanDO::getCharge, reqVO.getCharge())
                .eqIfPresent(IotInspectPlanDO::getDeviceIds, reqVO.getDeviceIds())
                .eqIfPresent(IotInspectPlanDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(IotInspectPlanDO::getCreateTime, reqVO.getCreateTime())
                .inIfPresent(IotInspectPlanDO::getDeptId, ids)
                .orderByDesc(IotInspectPlanDO::getId));
    }
    default Long selectCountByPlanCode(List<String> planCodes) {
        return selectCount(new LambdaQueryWrapperX<IotInspectPlanDO>()
                .inIfPresent(IotInspectPlanDO::getPlanCode, planCodes));
    }

    default List<IotInspectPlanDO> getListByJsonDeviceId(String deviceId) {
        return selectList(new LambdaQueryWrapperX<IotInspectPlanDO>()
                .likeIfPresent(IotInspectPlanDO::getDeviceIds, deviceId));
    }
}
