省平台数据推送通路打通

dev
songwenxuan 2025-09-21 10:00:06 +08:00
parent d822014e60
commit 95b64732f7
10 changed files with 576 additions and 343 deletions

View File

@ -19,30 +19,34 @@ import javax.annotation.Resource;
@Component
@Order(value = 1)
public class StartModBusTcpServer implements ApplicationRunner {
@Resource
private DeviceService deviceService;
// 线圈(Coils) 01,05,15 00000-09999 读写 开关量输出new SimpleDigitalOut(true);
// 离散输入(DI) 02 10000-19999 只读 开关量输入new SimpleDigitalIn(false);
// 保持寄存器 读写 new SimpleRegister(251);
// 输入寄存器 只读 new SimpleInputRegister(45);
@Override
public void run(ApplicationArguments args) throws Exception {
deviceService.initMqOrderList();
// 离散输入(DI) 02 10000-1FFFF 10001-19999 只读位
// 输入寄存器(IR) 04 30000-3FFFF 30001-39999 只读16位值
ModbusSlave slave = ModbusSlaveFactory.createTCPSlave(1888, 5);
// 高炉
slave.addProcessImage(1, deviceService.getGlProcessImage());
// 转炉
slave.addProcessImage(2, deviceService.getZlProcessImage());
// 精炼炉
slave.addProcessImage(3, deviceService.getLfProcessImage());
// 煤气报警器
slave.addProcessImage(4, deviceService.getMqProcessImage());
slave.open();
}
//
// @Resource
// private DeviceService deviceService;
//
//
// // 线圈(Coils) 01,05,15 00000-09999 读写 开关量输出new SimpleDigitalOut(true);
// // 离散输入(DI) 02 10000-19999 只读 开关量输入new SimpleDigitalIn(false);
// // 保持寄存器 读写 new SimpleRegister(251);
// // 输入寄存器 只读 new SimpleInputRegister(45);
// @Override
// public void run(ApplicationArguments args) throws Exception {
// deviceService.initMqOrderList();
// // 离散输入(DI) 02 10000-1FFFF 10001-19999 只读位
// // 输入寄存器(IR) 04 30000-3FFFF 30001-39999 只读16位值
// ModbusSlave slave = ModbusSlaveFactory.createTCPSlave(1888, 5);
// // 高炉
// slave.addProcessImage(1, deviceService.getGlProcessImage());
// // 转炉
// slave.addProcessImage(2, deviceService.getZlProcessImage());
// // 精炼炉
// slave.addProcessImage(3, deviceService.getLfProcessImage());
// // 煤气报警器
// slave.addProcessImage(4, deviceService.getMqProcessImage());
// slave.open();
//
// }
}

View File

@ -0,0 +1,26 @@
package com.netsdk.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
@Configuration
public class RestTemplateConfig {
@Bean
public RestTemplate restTemplate(ClientHttpRequestFactory factory) {
return new RestTemplate(factory);
}
@Bean
public ClientHttpRequestFactory simpleClientHttpRequestFactory() {
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
// 设置连接超时时间 5秒
factory.setConnectTimeout(5000);
// 设置读取超时时间 5秒
factory.setReadTimeout(5000);
return factory;
}
}

View File

@ -10,5 +10,5 @@ import java.util.HashMap;
*/
@Mapper
public interface OtherMapper {
ArrayList<HashMap<String, String>> getAllMqOrderList();
// ArrayList<HashMap<String, String>> getAllMqOrderList();
}

View File

@ -6,12 +6,12 @@ import com.ghgande.j2mod.modbus.procimg.ProcessImage;
* @author lin
*/
public interface DeviceService {
ProcessImage getGlProcessImage();
ProcessImage getZlProcessImage();
ProcessImage getLfProcessImage();
ProcessImage getMqProcessImage();
void initMqOrderList();
// ProcessImage getGlProcessImage();
//
// ProcessImage getZlProcessImage();
//
// ProcessImage getLfProcessImage();
//
// ProcessImage getMqProcessImage();
// void initMqOrderList();
}

View File

@ -24,309 +24,309 @@ import java.util.HashMap;
*/
@Service
public class DeviceServiceImpl implements DeviceService {
@Resource
private RedisUtil redisUtil;
@Resource
private OtherMapper otherMapper;
@Override
public ProcessImage getGlProcessImage() {
// 高炉设备初始话获取数据
JSONArray objects = JSONObject.parseArray((String) redisUtil.get("GL_LIST"));
// SBXH-GL-1 高炉#炉顶工作压力
// 高炉#炉顶放散阀联锁投入状态#东大放散阀状态-关到位 SBXH-GL-2-2
// 高炉#炉顶放散阀联锁投入状态#东大放散阀状态-开到位 SBXH-GL-2-1
// 高炉#炉顶放散阀联锁投入状态#西大放散阀状态-开到位 SBXH-GL-2-3
// 高炉#炉顶放散阀联锁投入状态#西大放散阀状态-关到位 SBXH-GL-2-4
SimpleProcessImage spi = new SimpleProcessImage();
// 离散输入(DI) 02 10000-1FFFF 10001-19999 只读位
SimpleInputRegister SBXH_GL_2_5 = new SimpleInputRegister();
SimpleInputRegister dynamicRegHig = new SimpleInputRegister(0);
SimpleInputRegister dynamicReglow = new SimpleInputRegister(0);
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-GL-1" + "hig", dynamicRegHig);
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-GL-1" + "low", dynamicReglow);
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-GL-2-5", SBXH_GL_2_5);
for (int i = 0; i < objects.size(); i++) {
JSONObject jsonObject = objects.getJSONObject(i);
if ("SBXH-GL-1".equals(jsonObject.getString("IPCDEVICE_ID"))) {
float intValue = jsonObject.getFloatValue("CURRENT_VALUE");
int bits = Float.floatToIntBits(intValue);
dynamicRegHig.setValue((bits >> 16) & 0xFFFF);
dynamicReglow.setValue(bits & 0xFFFF);
}
if ("SBXH-GL-2-5".equals(jsonObject.getString("IPCDEVICE_ID"))) {
double intValue = jsonObject.getDouble("CURRENT_VALUE");
SBXH_GL_2_5.setValue((int) intValue);
}
}
// SBXH-GL-1 高炉#炉顶工作压力
// 输入寄存器(IR) 04 30000-3FFFF 30001-39999 只读16位值
spi.addInputRegister(dynamicRegHig);
spi.addInputRegister(dynamicReglow);
spi.addInputRegister(SBXH_GL_2_5);
int inputRegisterCount = spi.getInputRegisterCount();
for (int i = inputRegisterCount; i < 1000; i++) {
spi.addInputRegister(new SimpleInputRegister(0));
}
return spi;
}
@Override
public ProcessImage getZlProcessImage() {
JSONArray objects = JSONObject.parseArray((String) redisUtil.get("ZL_LIST"));
SimpleProcessImage spi = new SimpleProcessImage();
initZlSimpleInputRegister(spi);
for (int i = 0; i < objects.size(); i++) {
JSONObject jsonObject = objects.getJSONObject(i);
float intValue = jsonObject.getFloatValue("CURRENT_VALUE");
if ("1".equals(jsonObject.getString("SIGNAL_TYPE"))) {
// 模拟量
SimpleInputRegister simpleInputRegister_hig = SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.get(jsonObject.getString("IPCDEVICE_ID") + "hig");
SimpleInputRegister simpleInputRegister_low = SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.get(jsonObject.getString("IPCDEVICE_ID") + "low");
if (simpleInputRegister_hig != null) {
int bits = Float.floatToIntBits(intValue);
simpleInputRegister_hig.setValue((bits >> 16) & 0xFFFF);
simpleInputRegister_low.setValue(bits & 0xFFFF);
}
} else {
SimpleInputRegister simpleInputRegister = SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.get(jsonObject.getString("IPCDEVICE_ID"));
if (simpleInputRegister == null) continue;
// 开关量
simpleInputRegister.setValue((int) intValue);
}
}
// 这个别删除、省局要求 寄存器数量不能少于1000个哪怕没数据
int inputRegisterCount = spi.getInputRegisterCount();
for (int i = inputRegisterCount; i < 1000; i++) {
spi.addInputRegister(new SimpleInputRegister(0));
}
return spi;
}
private void initZlSimpleInputRegister(SimpleProcessImage spi) {
SimpleInputRegister SBXH_ZL_1_1_hig = new SimpleInputRegister(0);
SimpleInputRegister SBXH_ZL_1_1_low = new SimpleInputRegister(0);
SimpleInputRegister SBXH_ZL_1_2_hig = new SimpleInputRegister(0);
SimpleInputRegister SBXH_ZL_1_2_low = new SimpleInputRegister(0);
SimpleInputRegister SBXH_ZL_2_1_hig = new SimpleInputRegister(0);
SimpleInputRegister SBXH_ZL_2_1_low = new SimpleInputRegister(0);
SimpleInputRegister SBXH_ZL_2_2_hig = new SimpleInputRegister(0);
SimpleInputRegister SBXH_ZL_2_2_low = new SimpleInputRegister(0);
SimpleInputRegister SBXH_ZL_4_1_hig = new SimpleInputRegister(0);
SimpleInputRegister SBXH_ZL_4_1_low = new SimpleInputRegister(0);
SimpleInputRegister SBXH_ZL_4_2_hig = new SimpleInputRegister(0);
SimpleInputRegister SBXH_ZL_4_2_low = new SimpleInputRegister(0);
SimpleInputRegister SBXH_ZL_5_1_hig = new SimpleInputRegister(0);
SimpleInputRegister SBXH_ZL_5_1_low = new SimpleInputRegister(0);
SimpleInputRegister SBXH_ZL_5_2_hig = new SimpleInputRegister(0);
SimpleInputRegister SBXH_ZL_5_2_low = new SimpleInputRegister(0);
// 水冷氧枪-氧气压力1#枪氧气压力
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-1-1" + "hig", SBXH_ZL_1_1_hig);
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-1-1" + "low", SBXH_ZL_1_1_low);
// 水冷氧枪-氧气压力2#枪氧气压力
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-1-2" + "hig", SBXH_ZL_1_2_hig);
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-1-2" + "low", SBXH_ZL_1_2_low);
// 水冷氧枪-冷却水进水流量 1#枪冷却水进水流量
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-2-1" + "hig", SBXH_ZL_2_1_hig);
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-2-1" + "low", SBXH_ZL_2_1_low);
// 水冷氧枪-冷却水进水流量 2#枪冷却水进水流量
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-2-2" + "hig", SBXH_ZL_2_2_hig);
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-2-2" + "low", SBXH_ZL_2_2_low);
// 水冷氧枪-冷却水出水温度1#枪冷却水出水温度
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-4-1" + "hig", SBXH_ZL_4_1_hig);
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-4-1" + "low", SBXH_ZL_4_1_low);
// 水冷氧枪-冷却水出水温度2#枪冷却水出水温度
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-4-2" + "hig", SBXH_ZL_4_2_hig);
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-4-2" + "low", SBXH_ZL_4_2_low);
// 水冷氧枪-冷却水进出水流量差 SBXH-ZL_5-1 1#枪冷却水进出水流量差
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL_5-1" + "hig", SBXH_ZL_5_1_hig);
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL_5-1" + "low", SBXH_ZL_5_1_low);
// 水冷氧枪-冷却水进出水流量差 SBXH-ZL_5-2 2#枪冷却水进出水流量差
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL_5-2" + "hig", SBXH_ZL_5_2_hig);
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL_5-2" + "low", SBXH_ZL_5_2_low);
// 氧气压力与氧枪自动升起联锁投入状态
SimpleInputRegister SBXH_ZL_5 = new SimpleInputRegister();
// 冷却水进水流量与氧枪自动升起联锁投入状态
SimpleInputRegister SBXH_ZL_6 = new SimpleInputRegister();
// 冷却水出水温度与氧枪自动升起联锁投入状态
SimpleInputRegister SBXH_ZL_7 = new SimpleInputRegister();
// 进出水流量差与氧枪自动升起联锁投入状态
SimpleInputRegister SBXH_ZL_8 = new SimpleInputRegister();
// 冷却水进出水流量差与炉体倾动联锁投入状态
SimpleInputRegister SBXH_ZL_9 = new SimpleInputRegister();
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-5", SBXH_ZL_5);
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-6", SBXH_ZL_6);
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-7", SBXH_ZL_7);
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-8", SBXH_ZL_8);
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-9", SBXH_ZL_9);
spi.addInputRegister(SBXH_ZL_1_1_hig);
spi.addInputRegister(SBXH_ZL_1_1_low);
spi.addInputRegister(SBXH_ZL_1_2_hig);
spi.addInputRegister(SBXH_ZL_1_2_low);
spi.addInputRegister(SBXH_ZL_2_1_hig);
spi.addInputRegister(SBXH_ZL_2_1_low);
spi.addInputRegister(SBXH_ZL_2_2_hig);
spi.addInputRegister(SBXH_ZL_2_2_low);
spi.addInputRegister(SBXH_ZL_5_1_hig);
spi.addInputRegister(SBXH_ZL_5_1_low);
spi.addInputRegister(SBXH_ZL_5_2_hig);
spi.addInputRegister(SBXH_ZL_5_2_low);
spi.addInputRegister(SBXH_ZL_4_1_hig);
spi.addInputRegister(SBXH_ZL_4_1_low);
spi.addInputRegister(SBXH_ZL_4_2_hig);
spi.addInputRegister(SBXH_ZL_4_2_low);
spi.addInputRegister(SBXH_ZL_5);
spi.addInputRegister(SBXH_ZL_6);
spi.addInputRegister(SBXH_ZL_7);
spi.addInputRegister(SBXH_ZL_8);
spi.addInputRegister(SBXH_ZL_9);
}
@Override
public ProcessImage getLfProcessImage() {
JSONArray objects = JSONObject.parseArray((String) redisUtil.get("JL_LIST"));
SimpleProcessImage spi = new SimpleProcessImage();
initLfSimpleInputRegister(spi);
for (int i = 0; i < objects.size(); i++) {
JSONObject jsonObject = objects.getJSONObject(i);
float intValue = jsonObject.getFloatValue("CURRENT_VALUE");
if ("1".equals(jsonObject.getString("SIGNAL_TYPE"))) {
// 模拟量
SimpleInputRegister simpleInputRegister_hig = SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.get(jsonObject.getString("IPCDEVICE_ID") + "hig");
SimpleInputRegister simpleInputRegister_low = SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.get(jsonObject.getString("IPCDEVICE_ID") + "low");
if (simpleInputRegister_hig != null) {
int bits = Float.floatToIntBits(intValue);
simpleInputRegister_hig.setValue((bits >> 16) & 0xFFFF);
simpleInputRegister_low.setValue(bits & 0xFFFF);
}
} else {
SimpleInputRegister simpleInputRegister = SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.get(jsonObject.getString("IPCDEVICE_ID"));
// SBXH-JL-3
SimpleInputRegister simpleInputRegister1 = SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.get(jsonObject.getString("IPCDEVICE_ID") + "_1");
if (simpleInputRegister1 != null) {
simpleInputRegister1.setValue((int) intValue);
}
if (simpleInputRegister == null) continue;
// 开关量
simpleInputRegister.setValue((int) intValue);
}
}
int inputRegisterCount = spi.getInputRegisterCount();
for (int i = inputRegisterCount; i < 1000; i++) {
spi.addInputRegister(new SimpleInputRegister(0));
}
// 冷却水出水温度与电极自动断 电联锁投入状态
// 冷却水出水温度与电极升起联锁投入状态
// 进出水流量差与电极自动断电联锁投入状态
// 进出水流量差与电极升起联锁投入状态
return spi;
}
@Override
public ProcessImage getMqProcessImage() {
JSONArray objects = JSONObject.parseArray((String) redisUtil.get("MQ_LIST"));
SimpleProcessImage spi = new SimpleProcessImage();
initMqSimpleInputRegister(spi);
for (int i = 0; i < objects.size(); i++) {
JSONObject jsonObject = objects.getJSONObject(i);
float intValue = jsonObject.getFloatValue("CURRENT_VALUE");
SimpleInputRegister simpleInputRegister = SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.get(jsonObject.getString("IPCDEVICE_ID"));
if (simpleInputRegister == null) continue;
// 开关量
simpleInputRegister.setValue((int) intValue);
}
int inputRegisterCount = spi.getInputRegisterCount();
for (int i = inputRegisterCount; i < 1000; i++) {
spi.addInputRegister(new SimpleInputRegister(0));
}
return spi;
}
@Override
public void initMqOrderList() {
ArrayList<HashMap<String, String>> allMqOrderList = otherMapper.getAllMqOrderList();
for (HashMap<String, String> hashMap : allMqOrderList) {
SyncGlScheduledTasks.MQ_ORDER_MAP.put(Integer.parseInt(String.valueOf(hashMap.get("ID"))), hashMap.get("IPCDEVICE_ID"));
}
}
private void initMqSimpleInputRegister(SimpleProcessImage spi) {
int size = SyncGlScheduledTasks.MQ_ORDER_MAP.size();
for (int i = 0; i < size; i++) {
SimpleInputRegister simpleInputRegister = new SimpleInputRegister();
spi.addInputRegister(simpleInputRegister);
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put(SyncGlScheduledTasks.MQ_ORDER_MAP.get(i), simpleInputRegister);
}
}
private void initLfSimpleInputRegister(SimpleProcessImage spi) {
// 冷却水出水温度
// SBXH-JL-1-1 1#冷却水出水温度
// SBXH-JL-1-2 2#冷却水出水温度
//冷却水进出水流量差
// SBXH-JL-3-1 1#冷却水进出水流量差
// SBXH-JL-3-2 2#冷却水进出水流量差
SimpleInputRegister SBXH_JL_1_1_hig = new SimpleInputRegister(0);
SimpleInputRegister SBXH_JL_1_1_low = new SimpleInputRegister(0);
SimpleInputRegister SBXH_JL_1_2_hig = new SimpleInputRegister(0);
SimpleInputRegister SBXH_JL_1_2_low = new SimpleInputRegister(0);
SimpleInputRegister SBXH_JL_3_1_hig = new SimpleInputRegister(0);
SimpleInputRegister SBXH_JL_3_1_low = new SimpleInputRegister(0);
SimpleInputRegister SBXH_JL_3_2_hig = new SimpleInputRegister(0);
SimpleInputRegister SBXH_JL_3_2_low = new SimpleInputRegister(0);
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-1-1" + "hig", SBXH_JL_1_1_hig);
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-1-1" + "low", SBXH_JL_1_1_low);
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-1-2" + "hig", SBXH_JL_1_2_hig);
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-1-2" + "low", SBXH_JL_1_2_low);
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-3-1" + "hig", SBXH_JL_3_1_hig);
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-3-1" + "low", SBXH_JL_3_1_low);
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-3-2" + "hig", SBXH_JL_3_2_hig);
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-3-2" + "low", SBXH_JL_3_2_low);
// 冷却水出水温度与电极自动断电联锁投入状态 冷却水出水温度与电极升起联锁投入状态 1#炉盖回水温度联锁
SimpleInputRegister SBXH_JL_3 = new SimpleInputRegister();
SimpleInputRegister SBXH_JL_3_1 = new SimpleInputRegister();
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-3", SBXH_JL_3);
// 冷却水出水温度与电极升起联锁投入状态 1#炉盖回水温度联锁
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-3_1", SBXH_JL_3);
// 冷却水出水温度与电极自动断电联锁投入状态 冷却水出水温度与电极升起联锁投入状态 2#炉盖回水温度联锁
SimpleInputRegister SBXH_JL_4 = new SimpleInputRegister();
SimpleInputRegister SBXH_JL_4_1 = new SimpleInputRegister();
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-4", SBXH_JL_4);
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-4_1", SBXH_JL_4);
// 进出水流量差与电极自动断电联锁投入状态 进出水流量差与电极升起联锁投入状态 1#炉盖回水流量差联锁
SimpleInputRegister SBXH_JL_5 = new SimpleInputRegister();
SimpleInputRegister SBXH_JL_5_1 = new SimpleInputRegister();
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-5", SBXH_JL_5);
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-5_1", SBXH_JL_5);
// 进出水流量差与电极自动断电联锁投入状态 进出水流量差与电极升起联锁投入状态 2#炉盖回水流量差联锁
SimpleInputRegister SBXH_JL_6 = new SimpleInputRegister();
SimpleInputRegister SBXH_JL_6_1 = new SimpleInputRegister();
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-6", SBXH_JL_6);
SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-6_1", SBXH_JL_6);
spi.addInputRegister(SBXH_JL_1_1_hig);
spi.addInputRegister(SBXH_JL_1_2_low);
spi.addInputRegister(SBXH_JL_1_2_hig);
spi.addInputRegister(SBXH_JL_1_2_low);
spi.addInputRegister(SBXH_JL_3_1_hig);
spi.addInputRegister(SBXH_JL_3_1_low);
spi.addInputRegister(SBXH_JL_3_2_hig);
spi.addInputRegister(SBXH_JL_3_2_low);
spi.addInputRegister(SBXH_JL_3);
spi.addInputRegister(SBXH_JL_4);
spi.addInputRegister(SBXH_JL_5);
spi.addInputRegister(SBXH_JL_6);
spi.addInputRegister(SBXH_JL_3_1);
spi.addInputRegister(SBXH_JL_4_1);
spi.addInputRegister(SBXH_JL_5_1);
spi.addInputRegister(SBXH_JL_6_1);
}
// @Resource
// private RedisUtil redisUtil;
// @Resource
// private OtherMapper otherMapper;
//
// @Override
// public ProcessImage getGlProcessImage() {
// // 高炉设备初始话获取数据
// JSONArray objects = JSONObject.parseArray((String) redisUtil.get("GL_LIST"));
// // SBXH-GL-1 高炉#炉顶工作压力
// // 高炉#炉顶放散阀联锁投入状态#东大放散阀状态-关到位 SBXH-GL-2-2
// // 高炉#炉顶放散阀联锁投入状态#东大放散阀状态-开到位 SBXH-GL-2-1
// // 高炉#炉顶放散阀联锁投入状态#西大放散阀状态-开到位 SBXH-GL-2-3
// // 高炉#炉顶放散阀联锁投入状态#西大放散阀状态-关到位 SBXH-GL-2-4
// SimpleProcessImage spi = new SimpleProcessImage();
// // 离散输入(DI) 02 10000-1FFFF 10001-19999 只读位
// SimpleInputRegister SBXH_GL_2_5 = new SimpleInputRegister();
// SimpleInputRegister dynamicRegHig = new SimpleInputRegister(0);
// SimpleInputRegister dynamicReglow = new SimpleInputRegister(0);
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-GL-1" + "hig", dynamicRegHig);
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-GL-1" + "low", dynamicReglow);
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-GL-2-5", SBXH_GL_2_5);
//
// for (int i = 0; i < objects.size(); i++) {
// JSONObject jsonObject = objects.getJSONObject(i);
// if ("SBXH-GL-1".equals(jsonObject.getString("IPCDEVICE_ID"))) {
// float intValue = jsonObject.getFloatValue("CURRENT_VALUE");
// int bits = Float.floatToIntBits(intValue);
// dynamicRegHig.setValue((bits >> 16) & 0xFFFF);
// dynamicReglow.setValue(bits & 0xFFFF);
// }
// if ("SBXH-GL-2-5".equals(jsonObject.getString("IPCDEVICE_ID"))) {
// double intValue = jsonObject.getDouble("CURRENT_VALUE");
// SBXH_GL_2_5.setValue((int) intValue);
// }
//
// }
// // SBXH-GL-1 高炉#炉顶工作压力
// // 输入寄存器(IR) 04 30000-3FFFF 30001-39999 只读16位值
// spi.addInputRegister(dynamicRegHig);
// spi.addInputRegister(dynamicReglow);
// spi.addInputRegister(SBXH_GL_2_5);
// int inputRegisterCount = spi.getInputRegisterCount();
// for (int i = inputRegisterCount; i < 1000; i++) {
// spi.addInputRegister(new SimpleInputRegister(0));
// }
// return spi;
// }
//
// @Override
// public ProcessImage getZlProcessImage() {
// JSONArray objects = JSONObject.parseArray((String) redisUtil.get("ZL_LIST"));
// SimpleProcessImage spi = new SimpleProcessImage();
// initZlSimpleInputRegister(spi);
// for (int i = 0; i < objects.size(); i++) {
// JSONObject jsonObject = objects.getJSONObject(i);
// float intValue = jsonObject.getFloatValue("CURRENT_VALUE");
// if ("1".equals(jsonObject.getString("SIGNAL_TYPE"))) {
// // 模拟量
// SimpleInputRegister simpleInputRegister_hig = SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.get(jsonObject.getString("IPCDEVICE_ID") + "hig");
// SimpleInputRegister simpleInputRegister_low = SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.get(jsonObject.getString("IPCDEVICE_ID") + "low");
// if (simpleInputRegister_hig != null) {
// int bits = Float.floatToIntBits(intValue);
// simpleInputRegister_hig.setValue((bits >> 16) & 0xFFFF);
// simpleInputRegister_low.setValue(bits & 0xFFFF);
// }
// } else {
// SimpleInputRegister simpleInputRegister = SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.get(jsonObject.getString("IPCDEVICE_ID"));
// if (simpleInputRegister == null) continue;
// // 开关量
// simpleInputRegister.setValue((int) intValue);
// }
// }
// // 这个别删除、省局要求 寄存器数量不能少于1000个哪怕没数据
// int inputRegisterCount = spi.getInputRegisterCount();
// for (int i = inputRegisterCount; i < 1000; i++) {
// spi.addInputRegister(new SimpleInputRegister(0));
// }
// return spi;
// }
//
// private void initZlSimpleInputRegister(SimpleProcessImage spi) {
// SimpleInputRegister SBXH_ZL_1_1_hig = new SimpleInputRegister(0);
// SimpleInputRegister SBXH_ZL_1_1_low = new SimpleInputRegister(0);
// SimpleInputRegister SBXH_ZL_1_2_hig = new SimpleInputRegister(0);
// SimpleInputRegister SBXH_ZL_1_2_low = new SimpleInputRegister(0);
// SimpleInputRegister SBXH_ZL_2_1_hig = new SimpleInputRegister(0);
// SimpleInputRegister SBXH_ZL_2_1_low = new SimpleInputRegister(0);
// SimpleInputRegister SBXH_ZL_2_2_hig = new SimpleInputRegister(0);
// SimpleInputRegister SBXH_ZL_2_2_low = new SimpleInputRegister(0);
// SimpleInputRegister SBXH_ZL_4_1_hig = new SimpleInputRegister(0);
// SimpleInputRegister SBXH_ZL_4_1_low = new SimpleInputRegister(0);
// SimpleInputRegister SBXH_ZL_4_2_hig = new SimpleInputRegister(0);
// SimpleInputRegister SBXH_ZL_4_2_low = new SimpleInputRegister(0);
// SimpleInputRegister SBXH_ZL_5_1_hig = new SimpleInputRegister(0);
// SimpleInputRegister SBXH_ZL_5_1_low = new SimpleInputRegister(0);
// SimpleInputRegister SBXH_ZL_5_2_hig = new SimpleInputRegister(0);
// SimpleInputRegister SBXH_ZL_5_2_low = new SimpleInputRegister(0);
//
//
// // 水冷氧枪-氧气压力1#枪氧气压力
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-1-1" + "hig", SBXH_ZL_1_1_hig);
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-1-1" + "low", SBXH_ZL_1_1_low);
// // 水冷氧枪-氧气压力2#枪氧气压力
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-1-2" + "hig", SBXH_ZL_1_2_hig);
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-1-2" + "low", SBXH_ZL_1_2_low);
// // 水冷氧枪-冷却水进水流量 1#枪冷却水进水流量
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-2-1" + "hig", SBXH_ZL_2_1_hig);
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-2-1" + "low", SBXH_ZL_2_1_low);
// // 水冷氧枪-冷却水进水流量 2#枪冷却水进水流量
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-2-2" + "hig", SBXH_ZL_2_2_hig);
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-2-2" + "low", SBXH_ZL_2_2_low);
// // 水冷氧枪-冷却水出水温度1#枪冷却水出水温度
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-4-1" + "hig", SBXH_ZL_4_1_hig);
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-4-1" + "low", SBXH_ZL_4_1_low);
// // 水冷氧枪-冷却水出水温度2#枪冷却水出水温度
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-4-2" + "hig", SBXH_ZL_4_2_hig);
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-4-2" + "low", SBXH_ZL_4_2_low);
// // 水冷氧枪-冷却水进出水流量差 SBXH-ZL_5-1 1#枪冷却水进出水流量差
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL_5-1" + "hig", SBXH_ZL_5_1_hig);
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL_5-1" + "low", SBXH_ZL_5_1_low);
// // 水冷氧枪-冷却水进出水流量差 SBXH-ZL_5-2 2#枪冷却水进出水流量差
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL_5-2" + "hig", SBXH_ZL_5_2_hig);
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL_5-2" + "low", SBXH_ZL_5_2_low);
//
//
// // 氧气压力与氧枪自动升起联锁投入状态
// SimpleInputRegister SBXH_ZL_5 = new SimpleInputRegister();
// // 冷却水进水流量与氧枪自动升起联锁投入状态
// SimpleInputRegister SBXH_ZL_6 = new SimpleInputRegister();
// // 冷却水出水温度与氧枪自动升起联锁投入状态
// SimpleInputRegister SBXH_ZL_7 = new SimpleInputRegister();
// // 进出水流量差与氧枪自动升起联锁投入状态
// SimpleInputRegister SBXH_ZL_8 = new SimpleInputRegister();
// // 冷却水进出水流量差与炉体倾动联锁投入状态
// SimpleInputRegister SBXH_ZL_9 = new SimpleInputRegister();
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-5", SBXH_ZL_5);
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-6", SBXH_ZL_6);
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-7", SBXH_ZL_7);
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-8", SBXH_ZL_8);
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-ZL-9", SBXH_ZL_9);
// spi.addInputRegister(SBXH_ZL_1_1_hig);
// spi.addInputRegister(SBXH_ZL_1_1_low);
// spi.addInputRegister(SBXH_ZL_1_2_hig);
// spi.addInputRegister(SBXH_ZL_1_2_low);
// spi.addInputRegister(SBXH_ZL_2_1_hig);
// spi.addInputRegister(SBXH_ZL_2_1_low);
// spi.addInputRegister(SBXH_ZL_2_2_hig);
// spi.addInputRegister(SBXH_ZL_2_2_low);
// spi.addInputRegister(SBXH_ZL_5_1_hig);
// spi.addInputRegister(SBXH_ZL_5_1_low);
// spi.addInputRegister(SBXH_ZL_5_2_hig);
// spi.addInputRegister(SBXH_ZL_5_2_low);
// spi.addInputRegister(SBXH_ZL_4_1_hig);
// spi.addInputRegister(SBXH_ZL_4_1_low);
// spi.addInputRegister(SBXH_ZL_4_2_hig);
// spi.addInputRegister(SBXH_ZL_4_2_low);
//
// spi.addInputRegister(SBXH_ZL_5);
// spi.addInputRegister(SBXH_ZL_6);
// spi.addInputRegister(SBXH_ZL_7);
// spi.addInputRegister(SBXH_ZL_8);
// spi.addInputRegister(SBXH_ZL_9);
// }
//
// @Override
// public ProcessImage getLfProcessImage() {
// JSONArray objects = JSONObject.parseArray((String) redisUtil.get("JL_LIST"));
// SimpleProcessImage spi = new SimpleProcessImage();
// initLfSimpleInputRegister(spi);
// for (int i = 0; i < objects.size(); i++) {
// JSONObject jsonObject = objects.getJSONObject(i);
// float intValue = jsonObject.getFloatValue("CURRENT_VALUE");
// if ("1".equals(jsonObject.getString("SIGNAL_TYPE"))) {
// // 模拟量
// SimpleInputRegister simpleInputRegister_hig = SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.get(jsonObject.getString("IPCDEVICE_ID") + "hig");
// SimpleInputRegister simpleInputRegister_low = SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.get(jsonObject.getString("IPCDEVICE_ID") + "low");
// if (simpleInputRegister_hig != null) {
// int bits = Float.floatToIntBits(intValue);
// simpleInputRegister_hig.setValue((bits >> 16) & 0xFFFF);
// simpleInputRegister_low.setValue(bits & 0xFFFF);
// }
// } else {
// SimpleInputRegister simpleInputRegister = SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.get(jsonObject.getString("IPCDEVICE_ID"));
//// SBXH-JL-3
// SimpleInputRegister simpleInputRegister1 = SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.get(jsonObject.getString("IPCDEVICE_ID") + "_1");
// if (simpleInputRegister1 != null) {
// simpleInputRegister1.setValue((int) intValue);
// }
// if (simpleInputRegister == null) continue;
// // 开关量
// simpleInputRegister.setValue((int) intValue);
// }
// }
// int inputRegisterCount = spi.getInputRegisterCount();
// for (int i = inputRegisterCount; i < 1000; i++) {
// spi.addInputRegister(new SimpleInputRegister(0));
// }
//// 冷却水出水温度与电极自动断 电联锁投入状态
//// 冷却水出水温度与电极升起联锁投入状态
//// 进出水流量差与电极自动断电联锁投入状态
//// 进出水流量差与电极升起联锁投入状态
// return spi;
// }
//
// @Override
// public ProcessImage getMqProcessImage() {
// JSONArray objects = JSONObject.parseArray((String) redisUtil.get("MQ_LIST"));
// SimpleProcessImage spi = new SimpleProcessImage();
// initMqSimpleInputRegister(spi);
// for (int i = 0; i < objects.size(); i++) {
// JSONObject jsonObject = objects.getJSONObject(i);
// float intValue = jsonObject.getFloatValue("CURRENT_VALUE");
// SimpleInputRegister simpleInputRegister = SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.get(jsonObject.getString("IPCDEVICE_ID"));
// if (simpleInputRegister == null) continue;
// // 开关量
// simpleInputRegister.setValue((int) intValue);
// }
// int inputRegisterCount = spi.getInputRegisterCount();
// for (int i = inputRegisterCount; i < 1000; i++) {
// spi.addInputRegister(new SimpleInputRegister(0));
// }
// return spi;
// }
//
// @Override
// public void initMqOrderList() {
// ArrayList<HashMap<String, String>> allMqOrderList = otherMapper.getAllMqOrderList();
// for (HashMap<String, String> hashMap : allMqOrderList) {
// SyncGlScheduledTasks.MQ_ORDER_MAP.put(Integer.parseInt(String.valueOf(hashMap.get("ID"))), hashMap.get("IPCDEVICE_ID"));
// }
//
// }
//
// private void initMqSimpleInputRegister(SimpleProcessImage spi) {
// int size = SyncGlScheduledTasks.MQ_ORDER_MAP.size();
// for (int i = 0; i < size; i++) {
// SimpleInputRegister simpleInputRegister = new SimpleInputRegister();
// spi.addInputRegister(simpleInputRegister);
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put(SyncGlScheduledTasks.MQ_ORDER_MAP.get(i), simpleInputRegister);
// }
// }
//
// private void initLfSimpleInputRegister(SimpleProcessImage spi) {
// // 冷却水出水温度
//// SBXH-JL-1-1 1#冷却水出水温度
//// SBXH-JL-1-2 2#冷却水出水温度
// //冷却水进出水流量差
//// SBXH-JL-3-1 1#冷却水进出水流量差
//// SBXH-JL-3-2 2#冷却水进出水流量差
// SimpleInputRegister SBXH_JL_1_1_hig = new SimpleInputRegister(0);
// SimpleInputRegister SBXH_JL_1_1_low = new SimpleInputRegister(0);
// SimpleInputRegister SBXH_JL_1_2_hig = new SimpleInputRegister(0);
// SimpleInputRegister SBXH_JL_1_2_low = new SimpleInputRegister(0);
// SimpleInputRegister SBXH_JL_3_1_hig = new SimpleInputRegister(0);
// SimpleInputRegister SBXH_JL_3_1_low = new SimpleInputRegister(0);
// SimpleInputRegister SBXH_JL_3_2_hig = new SimpleInputRegister(0);
// SimpleInputRegister SBXH_JL_3_2_low = new SimpleInputRegister(0);
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-1-1" + "hig", SBXH_JL_1_1_hig);
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-1-1" + "low", SBXH_JL_1_1_low);
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-1-2" + "hig", SBXH_JL_1_2_hig);
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-1-2" + "low", SBXH_JL_1_2_low);
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-3-1" + "hig", SBXH_JL_3_1_hig);
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-3-1" + "low", SBXH_JL_3_1_low);
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-3-2" + "hig", SBXH_JL_3_2_hig);
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-3-2" + "low", SBXH_JL_3_2_low);
// // 冷却水出水温度与电极自动断电联锁投入状态 冷却水出水温度与电极升起联锁投入状态 1#炉盖回水温度联锁
// SimpleInputRegister SBXH_JL_3 = new SimpleInputRegister();
// SimpleInputRegister SBXH_JL_3_1 = new SimpleInputRegister();
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-3", SBXH_JL_3);
// // 冷却水出水温度与电极升起联锁投入状态 1#炉盖回水温度联锁
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-3_1", SBXH_JL_3);
// // 冷却水出水温度与电极自动断电联锁投入状态 冷却水出水温度与电极升起联锁投入状态 2#炉盖回水温度联锁
// SimpleInputRegister SBXH_JL_4 = new SimpleInputRegister();
// SimpleInputRegister SBXH_JL_4_1 = new SimpleInputRegister();
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-4", SBXH_JL_4);
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-4_1", SBXH_JL_4);
// // 进出水流量差与电极自动断电联锁投入状态 进出水流量差与电极升起联锁投入状态 1#炉盖回水流量差联锁
// SimpleInputRegister SBXH_JL_5 = new SimpleInputRegister();
// SimpleInputRegister SBXH_JL_5_1 = new SimpleInputRegister();
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-5", SBXH_JL_5);
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-5_1", SBXH_JL_5);
// // 进出水流量差与电极自动断电联锁投入状态 进出水流量差与电极升起联锁投入状态 2#炉盖回水流量差联锁
// SimpleInputRegister SBXH_JL_6 = new SimpleInputRegister();
// SimpleInputRegister SBXH_JL_6_1 = new SimpleInputRegister();
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-6", SBXH_JL_6);
// SyncGlScheduledTasks.SIMPLE_DIGITAL_INMAP_2.put("SBXH-JL-6_1", SBXH_JL_6);
// spi.addInputRegister(SBXH_JL_1_1_hig);
// spi.addInputRegister(SBXH_JL_1_2_low);
// spi.addInputRegister(SBXH_JL_1_2_hig);
// spi.addInputRegister(SBXH_JL_1_2_low);
// spi.addInputRegister(SBXH_JL_3_1_hig);
// spi.addInputRegister(SBXH_JL_3_1_low);
// spi.addInputRegister(SBXH_JL_3_2_hig);
// spi.addInputRegister(SBXH_JL_3_2_low);
// spi.addInputRegister(SBXH_JL_3);
// spi.addInputRegister(SBXH_JL_4);
// spi.addInputRegister(SBXH_JL_5);
// spi.addInputRegister(SBXH_JL_6);
// spi.addInputRegister(SBXH_JL_3_1);
// spi.addInputRegister(SBXH_JL_4_1);
// spi.addInputRegister(SBXH_JL_5_1);
// spi.addInputRegister(SBXH_JL_6_1);
//
// }
}

View File

@ -0,0 +1,72 @@
package com.netsdk.utils;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
public class AESUtil {
// 算法常量与需求一致AES/CBC/PKCS5Padding
private static final String ALGORITHM = "AES";
private static final String TRANSFORMATION = "AES/CBC/PKCS5Padding";
// 1. Base64编码的密钥和IV需解码为原始字节
private static final String BASE64_KEY = "U6NtbmbAGGwqrcX+ZLEpKw=="; // 实时报表KEY
private static final String BASE64_IV = "PUsyOGZfmX8Jt3J7l4M26A=="; // 实时报表IV
// 2. 静态初始化解码Base64获取原始密钥和IV字节仅初始化一次提升性能
private static final byte[] KEY;
private static final byte[] IV;
static {
try {
// 解码Base64密钥关键修复获取AES要求的原始字节
KEY = Base64.getDecoder().decode(BASE64_KEY);
// 解码Base64初始向量CBC模式必须且长度需与AES块大小一致16字节
IV = Base64.getDecoder().decode(BASE64_IV);
// 验证密钥和IV长度避免配置错误可选但推荐
validateKeyAndIvLength();
} catch (Exception e) {
throw new RuntimeException("AES密钥/IV初始化失败" + e.getMessage(), e);
}
}
/**
* AESCBC/PKCS5PaddingBase64
* @param plainText JSON
* @return Base64
* @throws Exception
*/
public static String encrypt(String plainText) throws Exception {
// 3. 构建AES密钥使用解码后的原始字节
SecretKeySpec secretKey = new SecretKeySpec(KEY, ALGORITHM);
// 4. 构建IV参数CBC模式必须使用解码后的原始字节
IvParameterSpec ivParameterSpec = new IvParameterSpec(IV);
// 5. 初始化加密器
Cipher cipher = Cipher.getInstance(TRANSFORMATION);
cipher.init(Cipher.ENCRYPT_MODE, secretKey, ivParameterSpec);
// 6. 加密指定UTF-8编码避免乱码
byte[] encryptedBytes = cipher.doFinal(plainText.getBytes(StandardCharsets.UTF_8));
// 7. 加密结果转Base64便于传输避免二进制数据乱码
return Base64.getEncoder().encodeToString(encryptedBytes);
}
/**
* IVAES16/24/32IV16AES
*/
private static void validateKeyAndIvLength() {
// 验证密钥长度128位=16字节192位=24字节256位=32字节
if (KEY.length != 16 && KEY.length != 24 && KEY.length != 32) {
throw new IllegalArgumentException("AES密钥长度非法必须是16/24/32字节对应128/192/256位当前长度" + KEY.length);
}
// 验证IV长度CBC模式下IV必须与AES块大小一致16字节
if (IV.length != 16) {
throw new IllegalArgumentException("AES IV长度非法必须是16字节当前长度" + IV.length);
}
}
}

View File

@ -0,0 +1,111 @@
package com.netsdk.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.netsdk.entity.PageData;
import org.springframework.http.*;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
/**
* RedisMES
*
* @author
*/
@Component
public class ProvincialPlatformDataPushScheduled {
private static final String URL = "http://1.71.182.111:86/iot-cascade-receive/iot/cascade/http-report"; //省平台推送接口
@Resource
private RedisUtil redisUtil;
@Resource
private RestTemplate restTemplate; // 注入RestTemplate用于HTTP请求
@Scheduled(cron = "*/5 * * * * ?")
public void scheduled() throws Exception {
// 先填写基础报文 数据上报报文格式如下: appId、serviceId、dataId、data
// 实时数据和报警数据的报文格式、appId、serviceId等信息不同。
HashMap<String, Object> baseMap = new HashMap<>();
// 定义一个本次消息公用dataIdUUID 调用方生成证明单次数据的身份相同dataId的数据省平台只接收一次。
String dataId = UuidUtil.get32UUID();
baseMap.put("appId", "1ae355c6-4440-4579-823b-c0b9758171f6");
baseMap.put("serviceId", "7292a7ee6b8f4c7093a17bbe12771903");
baseMap.put("dataId", dataId);
// 接下来定义data也就是需要向省平台推送的数据
Map<String, Object> dataMap = new HashMap<String, Object>();
dataMap.put("dataId", dataId);
dataMap.put("areaCode", "14"); //企业所属省份的行政区划
dataMap.put("enterpriseId", "GT1407810001"); //企业数据接入标识
dataMap.put("gatewayId", "GT140781000101"); //网关编码:企业数据接入标识+01
//初始化报文当前时间戳 定义格式化模板年月日时分秒24小时制
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
// 获取当前时间
LocalDateTime now = LocalDateTime.now();
// 格式化时间
String collectTime = now.format(formatter);
dataMap.put("collectTime", collectTime); //时间戳格式YYYYMMDDHHmmss
dataMap.put("isConnectDataSource", false); //数据源连通性
dataMap.put("reportType", "report"); //报文类型report表示实时报文
//定义datas指标数据集合
List<Map<String, Object>> dataList = new ArrayList<>();
//--------------------------定义测试数据----------------------------------
HashMap<String, Object> data = new HashMap<>();
data.put("quotaId", 11); // 指标编码
data.put("value", 66); // 指标当前采集值
data.put("datas", false); // 质量戳
dataList.add(data);
//--------------------------测试数据结束----------------------------------
//真实数据逻辑(注释部分)
//取出存储在Redis中的数据
//List<PageData> mesDataList = JSONArray.parseArray(redisUtil.get("MES_DATA_LIST").toString(), PageData.class);
dataMap.put("datas", dataList);
//使用AES加密dataMap
String encrypt = AESUtil.encrypt(JSON.toJSONString(dataMap));
baseMap.put("data", encrypt);
//发送HTTP请求到平台
sendDataToPlatform(baseMap);
}
/**
*
* @param data
*/
private void sendDataToPlatform(Map<String, Object> data) {
try {
//设置请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
//创建请求实体
HttpEntity<String> requestEntity = new HttpEntity<>(JSON.toJSONString(data), headers);
//发送POST请求
ResponseEntity<String> response = restTemplate.postForEntity(URL, requestEntity, String.class);
//处理响应
if (response.getStatusCode().is2xxSuccessful()) {
System.out.println("数据推送成功,响应内容:" + response.getBody());
} else {
System.err.println("数据推送失败,状态码:" + response.getStatusCodeValue() +
",响应内容:" + response.getBody());
}
} catch (Exception e) {
System.err.println("数据推送发生异常:" + e.getMessage());
e.printStackTrace();
}
}
}

View File

@ -31,8 +31,8 @@ public class SyncGlScheduledTasks {
private RedisUtil redisUtil;
// 每五秒执行一次
@Scheduled(fixedDelay = 5000)
@Async
// @Scheduled(fixedDelay = 5000)
// @Async
public void taskWithFixedDelay() {
JSONArray objects = JSONObject.parseArray((String) redisUtil.get("GL_LIST"));
JSONArray zLobjects = JSONObject.parseArray((String) redisUtil.get("ZL_LIST"));

View File

@ -0,0 +1,20 @@
package com.netsdk.utils;
import java.util.UUID;
/**
* UUID(32)
*/
public class UuidUtil {
public static String get32UUID() {
String uuid = UUID.randomUUID().toString().trim().replaceAll("-", "");
return uuid;
}
public static void main(String[] args) {
System.out.println(get32UUID());
}
}

View File

@ -2,9 +2,9 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.netsdk.mapper.datasource.other.OtherMapper">
<select id="getAllMqOrderList" resultType="java.util.HashMap">
select *
from mq_docking
where ISDELETE = 0
</select>
<!-- <select id="getAllMqOrderList" resultType="java.util.HashMap">-->
<!-- select *-->
<!-- from mq_docking-->
<!-- where ISDELETE = 0-->
<!-- </select>-->
</mapper>