可配置网关采集信息功能与数据接口接收采集卡配置信息更新

This commit is contained in:
zhangjunwen 2024-09-24 10:55:51 +08:00
parent aa91bf9e92
commit ca37310b18
11 changed files with 202 additions and 110 deletions

View File

@ -39,7 +39,8 @@ public class MqttAutoStart implements ApplicationRunner {
@Value("${imt.data.mqtt.Qos}")
private int Qos;
private static final boolean START = false;
@Value("${imt.data.mqtt.start}")
private boolean START;
@Override
public void run(ApplicationArguments args) throws MqttException {

View File

@ -90,9 +90,9 @@ public class MyMqttCallback implements MqttCallback {
String deviceType = (String) map.get("deviceType");
String gatewayCode = deviceName.substring(0,17);
Map<String,Object> mapping = getGatewayMapping(gatewayCode);
String msgType = (String) mapping.get("msgType");
String msgType = (String) mapping.get(deviceType + "MsgType");
if(map.get("msgType") != null && msgType.equals(map.get("msgType"))){
process((String)mapping.get(deviceType),(String)mapping.get("equipId"),(Map<String,String>)mapping.get(deviceType + "_msg"),(Map<String,Object>)map.get("msg"));
process((String)mapping.get(deviceType),(String)mapping.get("equipId"),(Map<String,String>)mapping.get(deviceType + "Params"),(Map<String,Object>)map.get("msg"));
}else{
logger.info("数据未存储!");
}
@ -136,75 +136,78 @@ public class MyMqttCallback implements MqttCallback {
private Map<String, Object> getGatewayMapping(String gatewayCode) {
GatewayInfoService gatewayInfoService = SpringUtils.getBean(GatewayInfoService.class);
GatewayInfoDO gatewayInfo = gatewayInfoService.getGatewayInfoByGatewayCode(gatewayCode);
//TODO 通过网关信息查询采集卡映射和参数映射
//通过配置获取
Map<String, Object> cardMapping = gatewayInfoService.getGatewayCardAndParamByCatch(gatewayInfo.getGatewayId());
cardMapping.put("equipId", gatewayInfo.getEquipId());
cardMapping.put("gatewayId", gatewayInfo.getGatewayId());
Map<String,Object> cardMapping = new HashMap<>();
cardMapping.put("equipId",gatewayInfo.getEquipId());
cardMapping.put("msgType","POST_TELEMETRY_REQUEST");
cardMapping.put("JCka1","gateway_current_data");
cardMapping.put("JCka2","gateway_hy_data");
cardMapping.put("PT100T16","gateway_temp_data");
cardMapping.put("JCZ163R","gateway_aclr_data");
cardMapping.put("FANUC","gateway_fanuc_data");
Map<String,String> paramMapping1 = new HashMap<>();
paramMapping1.put("CH0","chip_removal_1");
paramMapping1.put("Ch1","chip_removal_2");
cardMapping.put("JCka1_msg",paramMapping1);
Map<String,String> paramMapping2 = new HashMap<>();
paramMapping2.put("CH0","hy_1");
paramMapping2.put("Ch1","hy_2");
paramMapping2.put("Ch2","hy_3");
cardMapping.put("JCka2_msg",paramMapping2);
Map<String,String> paramMapping3 = new HashMap<>();
paramMapping3.put("T1","zn_temp");
paramMapping3.put("T2","z0_temp");
paramMapping3.put("T3","zp_temp");
paramMapping3.put("T4","cr1_temp");
paramMapping3.put("T5","cr2_temp");
paramMapping3.put("T6","xn_temp");
paramMapping3.put("T7","x0_temp");
paramMapping3.put("T8","xp_temp");
paramMapping3.put("T9","yn_temp");
paramMapping3.put("T10","y0_temp");
paramMapping3.put("T11","yp_temp");
cardMapping.put("PT100T16_msg",paramMapping3);
Map<String,String> paramMapping4 = new HashMap<>();
paramMapping4.put("XaR","x_aclr_rms");
paramMapping4.put("YaR","y_aclr_rms");
paramMapping4.put("ZaR","z_aclr_rms");
paramMapping4.put("XvR","x_speed_rms");
paramMapping4.put("YvR","y_speed_rms");
paramMapping4.put("ZvR","z_speed_rms");
paramMapping4.put("XdR","x_dis_rms");
paramMapping4.put("YdR","y_dis_rms");
paramMapping4.put("ZdR","z_dis_rms");
paramMapping4.put("XaP","x_aclr_peak");
paramMapping4.put("YaP","y_aclr_peak");
paramMapping4.put("ZaP","z_aclr_peak");
paramMapping4.put("XvP","x_speed_peak");
paramMapping4.put("YvP","y_speed_peak");
paramMapping4.put("ZvP","z_speed_peak");
paramMapping4.put("XdPP","x_dis_peak");
paramMapping4.put("YdPP","y_dis_peak");
paramMapping4.put("ZdPP","z_dis_peak");
cardMapping.put("JCZ163R_msg",paramMapping4);
Map<String,String> paramMapping5 = new HashMap<>();
paramMapping5.put("WorkTime","work_time");
paramMapping5.put("PowerTime","power_time");
paramMapping5.put("TotalProcess","total_process");
paramMapping5.put("ProcessNum","process_num");
cardMapping.put("FANUC_msg",paramMapping5);
// Map<String,Object> cardMapping = new HashMap<>();
// cardMapping.put("equipId",gatewayInfo.getEquipId());
// cardMapping.put("msgType","POST_TELEMETRY_REQUEST");
// cardMapping.put("JCka1","gateway_current_data");
// cardMapping.put("JCka2","gateway_hy_data");
// cardMapping.put("PT100T16","gateway_temp_data");
// cardMapping.put("JCZ163R","gateway_aclr_data");
// cardMapping.put("FANUC","gateway_fanuc_data");
//
//
// Map<String,String> paramMapping1 = new HashMap<>();
// paramMapping1.put("CH0","chip_removal_1");
// paramMapping1.put("Ch1","chip_removal_2");
//
// cardMapping.put("JCka1_msg",paramMapping1);
//
// Map<String,String> paramMapping2 = new HashMap<>();
// paramMapping2.put("CH0","hy_1");
// paramMapping2.put("Ch1","hy_2");
// paramMapping2.put("Ch2","hy_3");
//
// cardMapping.put("JCka2_msg",paramMapping2);
//
// Map<String,String> paramMapping3 = new HashMap<>();
// paramMapping3.put("T1","zn_temp");
// paramMapping3.put("T2","z0_temp");
// paramMapping3.put("T3","zp_temp");
// paramMapping3.put("T4","cr1_temp");
// paramMapping3.put("T5","cr2_temp");
// paramMapping3.put("T6","xn_temp");
// paramMapping3.put("T7","x0_temp");
// paramMapping3.put("T8","xp_temp");
// paramMapping3.put("T9","yn_temp");
// paramMapping3.put("T10","y0_temp");
// paramMapping3.put("T11","yp_temp");
//
// cardMapping.put("PT100T16_msg",paramMapping3);
//
// Map<String,String> paramMapping4 = new HashMap<>();
// paramMapping4.put("XaR","x_aclr_rms");
// paramMapping4.put("YaR","y_aclr_rms");
// paramMapping4.put("ZaR","z_aclr_rms");
// paramMapping4.put("XvR","x_speed_rms");
// paramMapping4.put("YvR","y_speed_rms");
// paramMapping4.put("ZvR","z_speed_rms");
// paramMapping4.put("XdR","x_dis_rms");
// paramMapping4.put("YdR","y_dis_rms");
// paramMapping4.put("ZdR","z_dis_rms");
// paramMapping4.put("XaP","x_aclr_peak");
// paramMapping4.put("YaP","y_aclr_peak");
// paramMapping4.put("ZaP","z_aclr_peak");
// paramMapping4.put("XvP","x_speed_peak");
// paramMapping4.put("YvP","y_speed_peak");
// paramMapping4.put("ZvP","z_speed_peak");
// paramMapping4.put("XdPP","x_dis_peak");
// paramMapping4.put("YdPP","y_dis_peak");
// paramMapping4.put("ZdPP","z_dis_peak");
//
// cardMapping.put("JCZ163R_msg",paramMapping4);
//
// Map<String,String> paramMapping5 = new HashMap<>();
// paramMapping5.put("WorkTime","work_time");
// paramMapping5.put("PowerTime","power_time");
// paramMapping5.put("TotalProcess","total_process");
// paramMapping5.put("ProcessNum","process_num");
//
// cardMapping.put("FANUC_msg",paramMapping5);
return cardMapping;
}

View File

@ -23,45 +23,45 @@ public class DataProducerTask implements ApplicationRunner {
@Override
public void run(ApplicationArguments args) throws Exception {
Timer timer1 = new Timer();
timer1.schedule(new TimerTask() {
@Override
public void run() {
threadPoolTaskExecutor.execute(new Channel1DataProcess());
}
},1000,10000);
Timer timer2 = new Timer();
timer2.schedule(new TimerTask() {
@Override
public void run() {
threadPoolTaskExecutor.execute(new Channel2DataProcess());
}
},5000,10000);
Timer timer3 = new Timer();
timer3.schedule(new TimerTask() {
@Override
public void run() {
threadPoolTaskExecutor.execute(new Channel3DataProcess());
}
},10000,10000);
Timer timer4 = new Timer();
timer4.schedule(new TimerTask() {
@Override
public void run() {
threadPoolTaskExecutor.execute(new Channel4DataProcess());
}
},14000,10000);
Timer timer5 = new Timer();
timer5.schedule(new TimerTask() {
@Override
public void run() {
threadPoolTaskExecutor.execute(new Channel5DataProcess());
}
},19000,10000);
// Timer timer1 = new Timer();
// timer1.schedule(new TimerTask() {
// @Override
// public void run() {
// threadPoolTaskExecutor.execute(new Channel1DataProcess());
// }
// },1000,10000);
//
// Timer timer2 = new Timer();
// timer2.schedule(new TimerTask() {
// @Override
// public void run() {
// threadPoolTaskExecutor.execute(new Channel2DataProcess());
// }
// },5000,10000);
//
// Timer timer3 = new Timer();
// timer3.schedule(new TimerTask() {
// @Override
// public void run() {
// threadPoolTaskExecutor.execute(new Channel3DataProcess());
// }
// },10000,10000);
//
// Timer timer4 = new Timer();
// timer4.schedule(new TimerTask() {
// @Override
// public void run() {
// threadPoolTaskExecutor.execute(new Channel4DataProcess());
// }
// },14000,10000);
//
// Timer timer5 = new Timer();
// timer5.schedule(new TimerTask() {
// @Override
// public void run() {
// threadPoolTaskExecutor.execute(new Channel5DataProcess());
// }
// },19000,10000);
}
}

View File

@ -52,4 +52,8 @@ public interface GatewayCardInfoService {
*/
PageResult<GatewayCardInfoDO> getGatewayCardInfoPage(GatewayCardInfoPageReqVO pageReqVO);
/**
* 通过网关id获取采集卡列表
*/
List<GatewayCardInfoDO> getGatewayCardInfoListByGatewayId(String gatewayId);
}

View File

@ -1,5 +1,6 @@
package com.inspur.module.system.service.gatewayinfo;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
@ -71,4 +72,11 @@ public class GatewayCardInfoServiceImpl implements GatewayCardInfoService {
return gatewayCardInfoMapper.selectPage(pageReqVO);
}
/**
* 通过网关id获取采集卡列表
*/
@Override
public List<GatewayCardInfoDO> getGatewayCardInfoListByGatewayId(String gatewayId){
return gatewayCardInfoMapper.selectList(GatewayCardInfoDO::getGatewayId, gatewayId);
}
}

View File

@ -66,4 +66,9 @@ public interface GatewayCardParamsService {
* 根据采集卡id查询参数列表
*/
List<GatewayCardParamsDO> getGatewayCardParamsByCardId(String cardId);
/**
* 根据网关id查询采集卡参数列表
*/
List<GatewayCardParamsDO> getGatewayCardParamsByGatewayId(String gatewayId);
}

View File

@ -102,4 +102,11 @@ public class GatewayCardParamsServiceImpl implements GatewayCardParamsService {
return gatewayCardParamsMapper.selectList(cardId);
}
/**
* 根据网关id查询采集卡参数列表
*/
@Override
public List<GatewayCardParamsDO> getGatewayCardParamsByGatewayId(String gatewayId){
return gatewayCardParamsMapper.selectList(GatewayCardParamsDO::getGatewayId, gatewayId);
}
}

View File

@ -57,4 +57,9 @@ public interface GatewayInfoService {
* 根据机床网关编号获取机床网关信息
*/
GatewayInfoDO getGatewayInfoByGatewayCode(String gatewayCode);
/**
* 根据网关id获取机床网关网卡信息和参数信息
*/
Map<String, Object> getGatewayCardAndParamByCatch(String gatewayId);
}

View File

@ -2,8 +2,12 @@ package com.inspur.module.system.service.gatewayinfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.inspur.framework.common.util.json.JsonUtils;
import com.inspur.framework.tenant.core.aop.TenantIgnore;
import com.inspur.module.system.dal.dataobject.alarm.AlarmRulesDO;
import com.inspur.module.system.dal.dataobject.gatewayinfo.GatewayCardInfoDO;
import com.inspur.module.system.dal.dataobject.gatewayinfo.GatewayCardParamsDO;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@ -36,6 +40,15 @@ public class GatewayInfoServiceImpl implements GatewayInfoService {
@Resource
private GatewayInfoMapper gatewayInfoMapper;
@Resource
private GatewayCardInfoService gatewayCardInfoService;
@Resource
private GatewayCardParamsService gatewayCardParamsService;
@Resource
private StringRedisTemplate stringRedisTemplate;
@Override
@TenantIgnore
public String createGatewayInfo(GatewayInfoSaveReqVO createReqVO) {
@ -96,4 +109,49 @@ public class GatewayInfoServiceImpl implements GatewayInfoService {
return gatewayInfoMapper.selectGatewayByGatewayCode(gatewayCode);
}
/**
* 根据网关id获取机床网关网卡信息和参数信息
*/
@Override
@TenantIgnore
public Map<String, Object> getGatewayCardAndParamByCatch(String gatewayId){
//先从缓存中获取
if(Boolean.TRUE.equals(stringRedisTemplate.hasKey("cardmapping_" + gatewayId))){
return JsonUtils.parseObject(stringRedisTemplate.opsForValue().get("gateway_" + gatewayId), Map.class);
}
//获取网卡信息
List<GatewayCardInfoDO> cardList = gatewayCardInfoService.getGatewayCardInfoListByGatewayId(gatewayId);
//获取参数信息
List<GatewayCardParamsDO> paramsList = gatewayCardParamsService.getGatewayCardParamsByCardId(gatewayId);
if(cardList.size() == 0 || paramsList.size() == 0){
return null;
}
Map<String, Object> resultMap = getGatewayCardAndParamMapping(cardList, paramsList);
stringRedisTemplate.opsForValue().set("cardmapping_" + gatewayId, JsonUtils.toJsonString(resultMap));
return resultMap;
}
/**
* 根据采集卡列表和参数列表产生网关卡映射
*/
private Map<String, Object> getGatewayCardAndParamMapping(List<GatewayCardInfoDO> cardList, List<GatewayCardParamsDO> paramsList){
Map<String, Object> cardMap = new HashMap<>();
for (GatewayCardInfoDO gatewayCardInfoDO : cardList) {
Map<String,String> paramsMap = new HashMap<>();
//获取网卡的名称类型消息类型
//String cardName = gatewayCardInfoDO.getCardName();//对应网关deviceName
String cardType = gatewayCardInfoDO.getCardType();//对应网关deviceType
String msgType = gatewayCardInfoDO.getMsgType();//对应网关msgType
String cardId = gatewayCardInfoDO.getCardId();
cardMap.put(cardType, "gateway_" + gatewayCardInfoDO.getCardTableMapping() + "_data");//表名
cardMap.put(cardType + "MsgType", msgType);
paramsList.stream().filter(params -> params.getCardId().equals(cardId)).forEach(params -> paramsMap.put(params.getChannelName(), params.getParamMappingName()));
cardMap.put(cardType + "Params", paramsMap);
}
return cardMap;
}
}

View File

@ -324,4 +324,5 @@ imt:
timeOut: 10
keepAlive: 20
Qos: 1
start: true
debug: false

BIN
imt-ui/dist.zip Normal file

Binary file not shown.