168 lines
8.8 KiB
Java
168 lines
8.8 KiB
Java
package com.zhgd.xmgl.async;
|
||
|
||
import cn.hutool.core.bean.BeanUtil;
|
||
import cn.hutool.http.HttpUtil;
|
||
import cn.hutool.json.JSONUtil;
|
||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||
import com.zhgd.redis.lock.RedisRepository;
|
||
import com.zhgd.xmgl.modules.basicdata.entity.ThirdPartyPlatformService;
|
||
import com.zhgd.xmgl.modules.project.entity.ProjectExternalSystemService;
|
||
import com.zhgd.xmgl.modules.project.entity.ProjectUfaceConfig;
|
||
import com.zhgd.xmgl.modules.project.mapper.ProjectExternalSystemServiceMapper;
|
||
import com.zhgd.xmgl.modules.project.mapper.ProjectUfaceConfigMapper;
|
||
import com.zhgd.xmgl.modules.basicdata.mapper.ThirdPartyPlatformServiceMapper;
|
||
import com.zhgd.xmgl.modules.electrical.entity.ElectricalData;
|
||
import com.zhgd.xmgl.modules.electrical.entity.ElectricalDev;
|
||
import com.zhgd.xmgl.modules.electrical.entity.ElectricalWarning;
|
||
import com.zhgd.xmgl.util.ElectricBoxUtils;
|
||
import lombok.extern.slf4j.Slf4j;
|
||
import org.apache.commons.lang3.StringUtils;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.scheduling.annotation.Async;
|
||
import org.springframework.stereotype.Component;
|
||
|
||
import java.text.SimpleDateFormat;
|
||
import java.util.Date;
|
||
import java.util.HashMap;
|
||
import java.util.Map;
|
||
|
||
/**
|
||
* @program: wisdomSite
|
||
* @description: 异步发送配电箱数据
|
||
* @author: Mr.Peng
|
||
* @create: 2021-07-28 17:42
|
||
**/
|
||
@Slf4j
|
||
@Component
|
||
public class AsyncElectricalDev {
|
||
@Autowired
|
||
private ProjectUfaceConfigMapper projectUfaceConfigMapper;
|
||
@Autowired
|
||
private ThirdPartyPlatformServiceMapper thirdPartyPlatformServiceMapper;
|
||
@Autowired
|
||
private ProjectExternalSystemServiceMapper projectExternalSystemServiceMapper;
|
||
@Autowired
|
||
private RedisRepository redisRepository;
|
||
/**
|
||
* 转发配电箱实时数据
|
||
*/
|
||
@Async("electricalExecutor")
|
||
public void sendElectricalData(ElectricalData electricalData, ElectricalDev electricalDev, int alarmFlag) {
|
||
try {
|
||
QueryWrapper<ProjectUfaceConfig> queryWrapper =new QueryWrapper<>();
|
||
queryWrapper.lambda().eq(ProjectUfaceConfig::getProjectSn, electricalDev.getProjectSn());
|
||
ProjectUfaceConfig tempProjectUfaceConfig=projectUfaceConfigMapper.selectOne(queryWrapper);
|
||
if(tempProjectUfaceConfig!=null&& StringUtils.isNotEmpty(tempProjectUfaceConfig.getHousing())&&!"0".equals(tempProjectUfaceConfig.getHousing())) {
|
||
String[] arr = tempProjectUfaceConfig.getHousing().split(",");
|
||
Map<String, Object> currentData= BeanUtil.beanToMap(electricalData);
|
||
currentData.put("alarmType",alarmFlag);
|
||
Map<String,Object> data=new HashMap<>(16);
|
||
data.put("projectSn",electricalDev.getProjectSn());
|
||
data.put("electricalData",currentData);
|
||
data.put("electricalDev",electricalDev);
|
||
for (String housingId : arr) {
|
||
ThirdPartyPlatformService dictionariesRecord = thirdPartyPlatformServiceMapper.selectById(housingId);
|
||
if (dictionariesRecord != null && StringUtils.isNotEmpty(dictionariesRecord.getServiceUrl())&&dictionariesRecord.getElectricalSystem()==1) {
|
||
log.info("-----开始执行配电箱实时数据下发----" + dictionariesRecord.getServiceName());
|
||
String result = HttpUtil.post(dictionariesRecord.getServiceUrl() + "/saveElectricalData", JSONUtil.toJsonStr(data));
|
||
log.info("-----下发执行配电箱实时数据结果----" + result);
|
||
}
|
||
}
|
||
}
|
||
}catch (Exception e){
|
||
log.error("error:", e);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 转发逸风智建配电箱实时数据
|
||
*/
|
||
@Async("electricalExecutor")
|
||
public void sendYFZJElectricalData(ElectricalData electricalData, ElectricalDev electricalDev, int temperatureAlarm,int leakageAlarm,int currentAlarm,int voltageAlarm) {
|
||
try {
|
||
QueryWrapper<ProjectExternalSystemService> queryWrapper =new QueryWrapper<>();
|
||
queryWrapper.lambda().eq(ProjectExternalSystemService::getProjectSn, electricalDev.getProjectSn())
|
||
.eq(ProjectExternalSystemService::getSystemType,3)
|
||
.eq(ProjectExternalSystemService::getState,1);
|
||
ProjectExternalSystemService tempProjectExternalSystemService=projectExternalSystemServiceMapper.selectOne(queryWrapper);
|
||
if(tempProjectExternalSystemService!=null) {
|
||
String countKey="Electrical"+electricalDev.getDevSn();
|
||
String token=null;
|
||
if (redisRepository.exists(countKey)) {
|
||
token = (String) redisRepository.get(countKey);
|
||
}else{
|
||
token= ElectricBoxUtils.getToken(electricalDev.getDevSn(),electricalDev.getDevScret(),tempProjectExternalSystemService.getSystemUrl());
|
||
if(token!=null){
|
||
redisRepository.setExpire(countKey,token,60*50);
|
||
}
|
||
}
|
||
if(token!=null){
|
||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||
Map<String,Object> param=new HashMap<>(16);
|
||
param.put("token",token);
|
||
param.put("modelTag","Data");
|
||
param.put("gTime",sdf.format(new Date()));
|
||
Map<String,Object> data=new HashMap<>(16);
|
||
data.put("GTime",electricalData.getUploadTime());
|
||
//data.put("DianD",electricalData)
|
||
data.put("WenD_A",electricalData.getCableTemperatureA());
|
||
data.put("WenD_B",electricalData.getCableTemperatureB());
|
||
data.put("WenD_C",electricalData.getCableTemperatureC());
|
||
///data.put("WenD_N")
|
||
data.put("LouDL",electricalData.getElectricLeakage());
|
||
if(StringUtils.isNotEmpty(electricalData.getAmbientTemperature())) {
|
||
data.put("WenD", electricalData.getAmbientTemperature());
|
||
}else{
|
||
data.put("WenD", "");
|
||
}
|
||
data.put("DianL_A",electricalData.getPhaseCurrentA());
|
||
data.put("DianL_B",electricalData.getPhaseCurrentB());
|
||
data.put("DianL_C",electricalData.getPhaseCurrentC());
|
||
data.put("DianY_A",electricalData.getVoltageA());
|
||
data.put("DIanY_B",electricalData.getVoltageB());
|
||
data.put("DIanY_C",electricalData.getVoltageC());
|
||
data.put("A_LouD",leakageAlarm);
|
||
data.put("A_WenD",temperatureAlarm);
|
||
data.put("A_DianL",currentAlarm);
|
||
data.put("A_DianY",voltageAlarm);
|
||
param.put("datas",data);
|
||
ElectricBoxUtils.sendData(param,tempProjectExternalSystemService.getSystemUrl());
|
||
}
|
||
}
|
||
}catch (Exception e){
|
||
log.error("error:", e);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 发送配电箱设备数据
|
||
* @param electricalDev
|
||
* @param electricalWarning
|
||
*/
|
||
@Async("electricalExecutor")
|
||
public void sendElectricalDev(ElectricalDev electricalDev, ElectricalWarning electricalWarning) {
|
||
try {
|
||
QueryWrapper<ProjectUfaceConfig> queryWrapper =new QueryWrapper<>();
|
||
queryWrapper.lambda().eq(ProjectUfaceConfig::getProjectSn, electricalDev.getProjectSn());
|
||
ProjectUfaceConfig tempProjectUfaceConfig=projectUfaceConfigMapper.selectOne(queryWrapper);
|
||
if(tempProjectUfaceConfig!=null&& StringUtils.isNotEmpty(tempProjectUfaceConfig.getHousing())&&!"0".equals(tempProjectUfaceConfig.getHousing())) {
|
||
String[] arr = tempProjectUfaceConfig.getHousing().split(",");
|
||
Map<String,Object> data=new HashMap<>(16);
|
||
data.put("projectSn",electricalDev.getProjectSn());
|
||
data.put("electricalWarning",electricalWarning);
|
||
data.put("electricalDev",electricalDev);
|
||
for (String housingId : arr) {
|
||
ThirdPartyPlatformService dictionariesRecord = thirdPartyPlatformServiceMapper.selectById(housingId);
|
||
if (dictionariesRecord != null && StringUtils.isNotEmpty(dictionariesRecord.getServiceUrl())&&dictionariesRecord.getElectricalSystem()==1) {
|
||
log.info("-----开始执行配电箱设备数据下发----" + dictionariesRecord.getServiceName());
|
||
String result = HttpUtil.post(dictionariesRecord.getServiceUrl() + "/saveElectricalDev", JSONUtil.toJsonStr(data));
|
||
log.info("-----下发执行配电箱设备数据结果----" + result);
|
||
}
|
||
}
|
||
}
|
||
}catch (Exception e){
|
||
log.error("error:", e);
|
||
}
|
||
}
|
||
}
|