package cn.iocoder.yudao.module.pms.dal.mysql.yanfan.device;

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.yanfan.device.vo.DeviceShortOutput;
import cn.iocoder.yudao.module.pms.controller.admin.yanfan.device.vo.YfIotDevicePageReqVO;
import cn.iocoder.yudao.module.pms.controller.admin.yanfan.device.vo.YfIotDeviceRespVO;
import cn.iocoder.yudao.module.pms.controller.admin.yanfan.device.vo.YfIotDeviceSaveReqVO;
import cn.iocoder.yudao.module.pms.dal.dataobject.maintain.IotMaintainDO;
import cn.iocoder.yudao.module.pms.dal.dataobject.yanfan.device.YfIotDeviceDO;
import liquibase.pro.packaged.Y;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

/**
 * 设备 Mapper
 *
 * @author 超级管理员
 */
@Mapper
public interface YfIotDeviceMapper extends BaseMapperX<YfIotDeviceDO> {
    int updateDeviceStatus(YfIotDeviceDO device);
    int selectDeviceCountBySerialNumber(String serialNumber);
    YfIotDeviceDO selectDeviceBySerialNumber(String serialNumber);
    int deleteDeviceByDeviceIds(Long[] deviceIds);
    int delGwDevCode(String serialNumber);
    List<String> selectGwDevCodeList(@Param("serialNumber") String serialNumber);
    default PageResult<YfIotDeviceDO> selectPage(YfIotDevicePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<YfIotDeviceDO>()
                .likeIfPresent(YfIotDeviceDO::getDeviceName, reqVO.getDeviceName())
                .eqIfPresent(YfIotDeviceDO::getProductId, reqVO.getProductId())
                .likeIfPresent(YfIotDeviceDO::getProductName, reqVO.getProductName())
                .likeIfPresent(YfIotDeviceDO::getTenantName, reqVO.getTenantName())
                .eqIfPresent(YfIotDeviceDO::getSerialNumber, reqVO.getSerialNumber())
                .eqIfPresent(YfIotDeviceDO::getGwDevCode, reqVO.getGwDevCode())
                .eqIfPresent(YfIotDeviceDO::getFirmwareVersion, reqVO.getFirmwareVersion())
                .eqIfPresent(YfIotDeviceDO::getStatus, reqVO.getStatus())
                .eqIfPresent(YfIotDeviceDO::getRssi, reqVO.getRssi())
                .eqIfPresent(YfIotDeviceDO::getIsShadow, reqVO.getIsShadow())
                .eqIfPresent(YfIotDeviceDO::getLocationWay, reqVO.getLocationWay())
                .eqIfPresent(YfIotDeviceDO::getThingsModelValue, reqVO.getThingsModelValue())
                .eqIfPresent(YfIotDeviceDO::getNetworkAddress, reqVO.getNetworkAddress())
                .eqIfPresent(YfIotDeviceDO::getNetworkIp, reqVO.getNetworkIp())
                .eqIfPresent(YfIotDeviceDO::getLongitude, reqVO.getLongitude())
                .eqIfPresent(YfIotDeviceDO::getLatitude, reqVO.getLatitude())
                .betweenIfPresent(YfIotDeviceDO::getActiveTime, reqVO.getActiveTime())
                .eqIfPresent(YfIotDeviceDO::getSummary, reqVO.getSummary())
                .eqIfPresent(YfIotDeviceDO::getImgUrl, reqVO.getImgUrl())
                .eqIfPresent(YfIotDeviceDO::getDelFlag, reqVO.getDelFlag())
                .eqIfPresent(YfIotDeviceDO::getCreateBy, reqVO.getCreateBy())
                .betweenIfPresent(YfIotDeviceDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(YfIotDeviceDO::getUpdateBy, reqVO.getUpdateBy())
                .eqIfPresent(YfIotDeviceDO::getRemark, reqVO.getRemark())
                .eqIfPresent(YfIotDeviceDO::getIsSimulate, reqVO.getIsSimulate())
                .eqIfPresent(YfIotDeviceDO::getSlaveId, reqVO.getSlaveId())
                .eqIfPresent(YfIotDeviceDO::getClientId, reqVO.getClientId())
                .eqIfPresent(YfIotDeviceDO::getClientId, reqVO.getClientId())
                .eqIfPresent(YfIotDeviceDO::getPostDev, reqVO.getPostDev())
                .eqIfPresent(YfIotDeviceDO::getGetDev, reqVO.getGetDev())
                .eqIfPresent(YfIotDeviceDO::getMqttstats, reqVO.getMqttstats())
                .orderByDesc(YfIotDeviceDO::getDeviceId));
    }


    default Long deviceCountInProducts(List<Long> productIds) {
        return selectCount(new LambdaQueryWrapperX<YfIotDeviceDO>()
                .inIfPresent(YfIotDeviceDO::getProductId, productIds));
    }
    List<YfIotDeviceRespVO> selectDeviceList(YfIotDeviceSaveReqVO device);
    /**
     * 查询设备
     *
     * @param deviceId 设备主键
     * @return 设备
     */
    YfIotDeviceRespVO selectDeviceByDeviceId(Long deviceId);
    int getDeviceNumCount(String deviceNum);
    List<DeviceShortOutput> selectDeviceShortList(YfIotDeviceSaveReqVO device);
}
