package vip.xiaonuo.Timer; import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import vip.xiaonuo.common.timer.CommonTimerTaskRunner; import vip.xiaonuo.modular.ai.taskInspection.entity.TaskInspection; import vip.xiaonuo.modular.ai.taskInspection.mapper.TaskInspectionMapper; import vip.xiaonuo.modular.ai.warningRemind.entity.WarningRemind; import vip.xiaonuo.modular.ai.warningRemind.mapper.WarningRemindMapper; import vip.xiaonuo.modular.base.baseConfig.entity.BaseConfig; import vip.xiaonuo.modular.base.baseConfig.mapper.BaseConfigMapper; import vip.xiaonuo.modular.energy.energyDevice.entity.EnergyDevice; import vip.xiaonuo.modular.energy.energyDevice.mapper.EnergyDeviceMapper; import vip.xiaonuo.modular.energy.energyElectricity.entity.EnergyElectricity; import vip.xiaonuo.modular.energy.energyElectricity.mapper.EnergyElectricityMapper; import vip.xiaonuo.modular.energy.energyThreshold.entity.EnergyThreshold; import vip.xiaonuo.modular.energy.energyThreshold.mapper.EnergyThresholdMapper; import vip.xiaonuo.modular.energy.energyWater.entity.EnergyWater; import vip.xiaonuo.modular.energy.energyWater.mapper.EnergyWaterMapper; import vip.xiaonuo.modular.env.envdevice.entity.EnvDevice; import vip.xiaonuo.modular.warning.warningInfo.entity.WarningInfo; import vip.xiaonuo.modular.warning.warningInfo.mapper.WarningInfoMapper; import vip.xiaonuo.modular.warning.warningManager.entity.WarningManager; import vip.xiaonuo.modular.warning.warningManager.mapper.WarningManagerMapper; import java.math.BigDecimal; import java.util.Date; import java.util.List; @Slf4j @Component public class ProEnergyData implements CommonTimerTaskRunner { @Autowired private EnergyDeviceMapper deviceMapper; @Autowired private EnergyElectricityMapper electricityMapper; @Autowired private EnergyWaterMapper waterMapper; @Autowired private EnergyThresholdMapper energyThresholdMapper; @Autowired private WarningInfoMapper warningInfoMapper; @Autowired private WarningManagerMapper warningManagerMapper; @Autowired private WarningRemindMapper warningRemindMapper; @Autowired private BaseConfigMapper baseConfigMapper; @Autowired private TaskInspectionMapper taskInspectionMapper; @Override @Transactional public void action() { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.eq("org_id", "1543842934270394370").eq("delete_flag", "NOT_DELETE") .eq("status", 1); List energyDevices = deviceMapper.selectList(queryWrapper); for (EnergyDevice energyDevice : energyDevices) { Date now = new Date(); String orgId = energyDevice.getOrgId(); String pigpenId = energyDevice.getInstallPosition(); String waterValue = NumberUtils.getNumFloat(5.0, 20.0); String electricityValue = NumberUtils.getNumFloat(10.0, 100.0); EnergyWater energyWater = new EnergyWater(); energyWater.setOrgId(orgId); energyWater.setUnitId(pigpenId); energyWater.setDeviceCode(energyDevice.getDeviceCode()); energyWater.setCreateDate(now); energyWater.setOriginalDate(now); energyWater.setWaterValue(waterValue); energyWater.setOriginalValue(waterValue); EnergyElectricity energyElectricity = new EnergyElectricity(); energyElectricity.setOrgId(orgId); energyElectricity.setUnitId(pigpenId); energyElectricity.setDeviceCode(energyDevice.getDeviceCode()); energyElectricity.setCreateDate(now); energyElectricity.setOriginalDate(now); energyElectricity.setElectricityValue(electricityValue); energyElectricity.setOriginalValue(electricityValue); electricityMapper.insert(energyElectricity); waterMapper.insert(energyWater); BigDecimal water = new BigDecimal(waterValue); BigDecimal ele = new BigDecimal(electricityValue); BaseConfig baseConfig = baseConfigMapper.selectOne(new QueryWrapper().lambda().eq(BaseConfig::getConfigName, "预警类型").eq(BaseConfig::getParentId, 0)); BaseConfig envWarning = baseConfigMapper.selectOne(new QueryWrapper().lambda().eq(BaseConfig::getConfigName, "能耗预警").eq(BaseConfig::getParentId, baseConfig.getId())); WarningRemind warningRemind = warningRemindMapper.selectOne(new QueryWrapper().lambda() .eq(WarningRemind::getWarningTypeId, envWarning.getId()) .eq(WarningRemind::getOrgId, orgId).eq(WarningRemind::getUnitId, pigpenId)); if (ObjectUtil.isNotEmpty(warningRemind)) { if (warningRemind.getTodayNoRemind() != 1) { EnergyThreshold energyThreshold = energyThresholdMapper.selectOne(new QueryWrapper().lambda().eq(EnergyThreshold::getOrgId, orgId).eq(EnergyThreshold::getUnitId, pigpenId).eq(EnergyThreshold::getIsEnable, 1)); if (ObjectUtil.isNotEmpty(energyThreshold)) { BigDecimal waterLower = energyThreshold.getWaterLower(); if (water.compareTo(waterLower) < 0) { WarningInfo warningInfo = new WarningInfo(); warningInfo.setWarningContent("用水" + water + "吨低于阈值"); warningInfo.setUnitId(pigpenId); warningInfo.setWarningTime(now); warningInfo.setOrgId(orgId); warningInfo.setWarningTypeId(envWarning.getId()); WarningManager warningManager = warningManagerMapper.selectOne(new QueryWrapper().lambda().eq(WarningManager::getOrgId, orgId).eq(WarningManager::getType, 1)); if (ObjectUtil.isNotEmpty(warningManager)){ warningInfo.setWarningNotifierId(warningManager.getSecondManagerId()); } warningInfoMapper.insert(warningInfo); this.generateInspection(warningManager,warningInfo,orgId); } BigDecimal waterUpper = energyThreshold.getWaterUpper(); if (water.compareTo(waterUpper) > 0) { WarningInfo warningInfo = new WarningInfo(); warningInfo.setWarningContent("用水" + water + "吨高于阈值"); warningInfo.setUnitId(pigpenId); warningInfo.setWarningTime(now); warningInfo.setOrgId(orgId); warningInfo.setWarningTypeId(envWarning.getId()); WarningManager warningManager = warningManagerMapper.selectOne(new QueryWrapper().lambda().eq(WarningManager::getOrgId, orgId).eq(WarningManager::getType, 1)); if (ObjectUtil.isNotEmpty(warningManager)){ warningInfo.setWarningNotifierId(warningManager.getSecondManagerId()); } warningInfoMapper.insert(warningInfo); this.generateInspection(warningManager,warningInfo,orgId); } BigDecimal electricityLower = energyThreshold.getElectricityLower(); if (ele.compareTo(electricityLower) < 0) { WarningInfo warningInfo = new WarningInfo(); warningInfo.setWarningContent("用电" + ele + "kw·h低于阈值"); warningInfo.setUnitId(pigpenId); warningInfo.setWarningTime(now); warningInfo.setOrgId(orgId); warningInfo.setWarningTypeId(envWarning.getId()); WarningManager warningManager = warningManagerMapper.selectOne(new QueryWrapper().lambda().eq(WarningManager::getOrgId, orgId).eq(WarningManager::getType, 1)); if (ObjectUtil.isNotEmpty(warningManager)){ warningInfo.setWarningNotifierId(warningManager.getSecondManagerId()); } warningInfoMapper.insert(warningInfo); this.generateInspection(warningManager,warningInfo,orgId); } BigDecimal electricityUpper = energyThreshold.getElectricityUpper(); if (ele.compareTo(electricityUpper) > 0) { WarningInfo warningInfo = new WarningInfo(); warningInfo.setWarningContent("用电" + ele + "kw·h高于阈值"); warningInfo.setUnitId(pigpenId); warningInfo.setWarningTime(now); warningInfo.setOrgId(orgId); warningInfo.setWarningTypeId(envWarning.getId()); WarningManager warningManager = warningManagerMapper.selectOne(new QueryWrapper().lambda().eq(WarningManager::getOrgId, orgId).eq(WarningManager::getType, 1)); if (ObjectUtil.isNotEmpty(warningManager)){ warningInfo.setWarningNotifierId(warningManager.getSecondManagerId()); } warningInfoMapper.insert(warningInfo); this.generateInspection(warningManager,warningInfo,orgId); } BigDecimal sevenDayEleTotal = electricityMapper.getSevenDayTotal(orgId, pigpenId); BigDecimal sevenDayWaterTotal = waterMapper.getSevenDayTotal(orgId, pigpenId); BigDecimal sevenDayWaterLower = energyThreshold.getSevenDayWaterLower(); if (sevenDayWaterTotal.compareTo(sevenDayWaterLower) < 0) { WarningInfo warningInfo = new WarningInfo(); warningInfo.setWarningContent("七日用水" + sevenDayWaterTotal + "吨低于阈值"); warningInfo.setUnitId(pigpenId); warningInfo.setWarningTime(now); warningInfo.setOrgId(orgId); warningInfo.setWarningTypeId(envWarning.getId()); WarningManager warningManager = warningManagerMapper.selectOne(new QueryWrapper().lambda().eq(WarningManager::getOrgId, orgId).eq(WarningManager::getType, 1)); if (ObjectUtil.isNotEmpty(warningManager)){ warningInfo.setWarningNotifierId(warningManager.getSecondManagerId()); } warningInfoMapper.insert(warningInfo); this.generateInspection(warningManager,warningInfo,orgId); } BigDecimal sevenDayWaterUpper = energyThreshold.getSevenDayWaterUpper(); if (sevenDayWaterTotal.compareTo(sevenDayWaterUpper) > 0) { WarningInfo warningInfo = new WarningInfo(); warningInfo.setWarningContent("七日用水" + sevenDayWaterTotal + "吨高于阈值"); warningInfo.setUnitId(pigpenId); warningInfo.setWarningTime(now); warningInfo.setOrgId(orgId); warningInfo.setWarningTypeId(envWarning.getId()); WarningManager warningManager = warningManagerMapper.selectOne(new QueryWrapper().lambda().eq(WarningManager::getOrgId, orgId).eq(WarningManager::getType, 1)); if (ObjectUtil.isNotEmpty(warningManager)){ warningInfo.setWarningNotifierId(warningManager.getSecondManagerId()); } warningInfoMapper.insert(warningInfo); this.generateInspection(warningManager,warningInfo,orgId); } BigDecimal sevenDayElectricityLower = energyThreshold.getSevenDayElectricityLower(); if (sevenDayEleTotal.compareTo(sevenDayElectricityLower) < 0) { WarningInfo warningInfo = new WarningInfo(); warningInfo.setWarningContent("七日用电" + sevenDayEleTotal + "kw·h低于阈值"); warningInfo.setUnitId(pigpenId); warningInfo.setWarningTime(now); warningInfo.setOrgId(orgId); warningInfo.setWarningTypeId(envWarning.getId()); WarningManager warningManager = warningManagerMapper.selectOne(new QueryWrapper().lambda().eq(WarningManager::getOrgId, orgId).eq(WarningManager::getType, 1)); if (ObjectUtil.isNotEmpty(warningManager)){ warningInfo.setWarningNotifierId(warningManager.getSecondManagerId()); } warningInfoMapper.insert(warningInfo); this.generateInspection(warningManager,warningInfo,orgId); } BigDecimal sevenDayElectricityUpper = energyThreshold.getSevenDayElectricityUpper(); if (sevenDayEleTotal.compareTo(sevenDayElectricityUpper) > 0) { WarningInfo warningInfo = new WarningInfo(); warningInfo.setWarningContent("七日用电" + sevenDayEleTotal + "kw·h高于阈值"); warningInfo.setUnitId(pigpenId); warningInfo.setWarningTime(now); warningInfo.setOrgId(orgId); warningInfo.setWarningTypeId(envWarning.getId()); WarningManager warningManager = warningManagerMapper.selectOne(new QueryWrapper().lambda().eq(WarningManager::getOrgId, orgId).eq(WarningManager::getType, 1)); if (ObjectUtil.isNotEmpty(warningManager)){ warningInfo.setWarningNotifierId(warningManager.getSecondManagerId()); } warningInfoMapper.insert(warningInfo); this.generateInspection(warningManager,warningInfo,orgId); } } } } } } private void generateInspection(WarningManager warningManager, WarningInfo warningInfo,String orgId){ TaskInspection taskInspection = new TaskInspection(); if (ObjectUtil.isNotEmpty(warningManager)){ taskInspection.setNotifierId(warningManager.getSecondManagerId()); taskInspection.setWarningId(warningInfo.getId()); taskInspection.setOrgId(orgId); taskInspectionMapper.insert(taskInspection); } } }