Commit 30aae562 authored by wujiang's avatar wujiang

提交代码

parent 35b81f8b
......@@ -93,4 +93,6 @@ public class EquipmentIndexVO implements Serializable {
@ApiModelProperty(value = "装备指标名称")
private String equipmentIndexName;
private String newAddress;
}
......@@ -43,7 +43,6 @@ public class EquipmentSpecificIndex extends BaseEntity {
@ApiModelProperty(value = "装备名称(冗余字段)")
@TableField("equipment_specific_name")
private String equipmentSpecificName;
// equipmentSpecialName
@ApiModelProperty(value = "指标名称(冗余字段)")
@TableField("equipment_index_name")
......@@ -104,8 +103,6 @@ public class EquipmentSpecificIndex extends BaseEntity {
@TableField(exist = false)
private String indexName;
@TableField(exist = false)
private String equipmentSpecificIndexName;
......@@ -206,4 +203,7 @@ public class EquipmentSpecificIndex extends BaseEntity {
@ApiModelProperty(value = "网关标识")
@TableField(value = "gateway_id")
private String gatewayId;
@TableField(value = "new_address")
private String newAddress;
}
......@@ -6,6 +6,7 @@ import com.yeejoin.equip.kafka.KafkaProducerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
......@@ -17,6 +18,7 @@ import java.util.concurrent.ConcurrentHashMap;
@Component
@Slf4j
@DependsOn("SystemInit")
public class ConnectionManager {
private final Map<String, Connector> connectors = new ConcurrentHashMap<>();
......
......@@ -103,10 +103,18 @@ public class MqttConnector implements Connector, MqttCallback {
}
String values = msg.getString("values");
JSONObject vobj = JSONObject.parseObject(values,JSONObject.class);
Map<String,String> map = SystemInit.map.get(gatewayId);
for(String key:vobj.keySet())
{
JSONObject result = new JSONObject();
result.put("address",key);
if(map.containsKey(key))
{
String oldAddress = map.get(key);
result.put("address",oldAddress);
}else
{
result.put("address",key);
}
result.put("value",vobj.get(key));
result.put("gatewayId",gatewayId);
//log.info("===========接收MQTT订阅消息,address:{},gatewayId:{},value:{}", address,gatewayId,value);
......@@ -130,10 +138,18 @@ public class MqttConnector implements Connector, MqttCallback {
}
String values = msg.getString("values");
JSONObject vobj = JSONObject.parseObject(values,JSONObject.class);
Map<String,String> map = SystemInit.map.get(gatewayId);
for(String key:vobj.keySet())
{
JSONObject result = new JSONObject();
result.put("address",key);
if(map.containsKey(key))
{
String oldAddress = map.get(key);
result.put("address",oldAddress);
}else
{
result.put("address",key);
}
result.put("value",vobj.get(key));
result.put("gatewayId",gatewayId);
//log.info("===========接收MQTT订阅消息,address:{},gatewayId:{},value:{}", address,gatewayId,value);
......
package com.yeejoin.equip.eqmx;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yeejoin.equip.entity.EquipmentIndexVO;
import com.yeejoin.equip.entity.EquipmentSpecificIndex;
import com.yeejoin.equip.mapper.mysql.EquipmentSpecificIndexMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
@Component("SystemInit")
public class SystemInit {
public static Map<String, Map<String,String>> map = new HashMap<>();
@Autowired
private EquipmentSpecificIndexMapper equipmentSpecificIndexMapper;
@PostConstruct
public void point()
{
List<EquipmentIndexVO> list = equipmentSpecificIndexMapper.getEquipSpecificIndexList(null);
Map<String, Map<String, String>> result = list.stream()
.collect(Collectors.groupingBy(
EquipmentIndexVO::getGatewayId,
Collectors.toMap(
vo-> Optional.ofNullable(vo.getNewAddress()).orElse(""),
EquipmentIndexVO::getIndexAddress
)
));
map=result;
}
}
......@@ -187,7 +187,7 @@ public class ElasticSearchUtil {
@Override
public void onResponse(UpdateResponse updateResponse) {
if (DocWriteResponse.Result.UPDATED.equals(updateResponse.getResult())) {
log.info("索引:【{}】,主键:【{}】修改成功", indexName, id);
//log.info("索引:【{}】,主键:【{}】修改成功", indexName, id);
}
}
......
......@@ -15,6 +15,7 @@
<result property="equipmentIndexName" column="equipment_index_name"/>
<result property="equipmentSpecificName" column="equipment_specific_name"/>
<result property="dataType" column="data_type"/>
<result property="newAddress" column="new_address"/>
</resultMap>
<select id="getEquipSpecificIndexList" resultMap="ComplementCode">
......@@ -30,7 +31,8 @@
si.data_type,
si.equipment_specific_name,
si.equipment_index_name,
si.is_alarm
si.is_alarm,
si.new_address
FROM
wl_equipment_specific_index si
LEFT JOIN wl_equipment_index ei ON si.equipment_index_id = ei.id
......
......@@ -59,10 +59,11 @@ public class JXDZExecute {
@Scheduled(cron = "0 0 */1 * * ?")
@PostConstruct
public void hourInterface() {
// if (!jxdzScheduledEnable) {
// return;
// }
if (!jxdzScheduledEnable) {
return;
}
log.info("开始执行小时任务");
//发送请求传入的参数
NeedDataVO needDataVO = new NeedDataVO();
......@@ -149,6 +150,7 @@ public class JXDZExecute {
}
@Scheduled(cron = "0 0 1 * * ?")
@PostConstruct
public void dayInterface() {
if (!jxdzScheduledEnable) {
return;
......
package com.yeejoin.amos.boot.module.jxiop.biz.jxdz.utils;
import cn.hutool.core.codec.Base64;
import cn.hutool.crypto.asymmetric.SM2;
import com.alibaba.fastjson.JSONObject;
import com.csii.pp.icbc.util.SM2Utils;
import com.yeejoin.amos.boot.module.jxiop.biz.jxdz.vo.NeedDataVO;
import com.yeejoin.amos.component.robot.AmosRequestContext;
import lombok.extern.slf4j.Slf4j;
//import org.bouncycastle.asn1.gm.GMNamedCurves;
//import org.bouncycastle.asn1.x9.X9ECParameters;
//import org.bouncycastle.crypto.engines.SM2Engine;
//import org.bouncycastle.crypto.params.ECDomainParameters;
//import org.bouncycastle.crypto.params.ECPublicKeyParameters;
//import org.bouncycastle.crypto.params.ParametersWithRandom;
//import org.bouncycastle.math.ec.ECPoint;
//import org.bouncycastle.util.encoders.Hex;
import org.bouncycastle.asn1.gm.GMNamedCurves;
import org.bouncycastle.asn1.x9.X9ECParameters;
import org.bouncycastle.crypto.engines.SM2Engine;
import org.bouncycastle.crypto.params.ECDomainParameters;
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
import org.bouncycastle.crypto.params.ParametersWithRandom;
import org.bouncycastle.math.ec.ECPoint;
import org.bouncycastle.util.encoders.Hex;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.*;
......@@ -20,6 +22,7 @@ import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.SecureRandom;
import java.util.List;
......@@ -33,7 +36,7 @@ import java.util.Objects;
public class JXDZUtils {
@Value("${coreIp:iiet-jepcc.powerchina.cn:8088}")
String coreIp;
@Value("${jxdzIp:122.70.153.215:9003}")
@Value("${jxdzIp:210.12.143.88:9003}")
String jxdzIp;
@Value("${jxdzTokenUserName:jiangxi_epc}")
String jxdzTokenUserName;
......@@ -49,25 +52,24 @@ public class JXDZUtils {
public static String GF_CODE="PPC17063608260011";
private String dataEncrypt(String obj, String publicKey) {
// X9ECParameters sm2ECParameters = GMNamedCurves.getByName("sm2p256v1");
// ECDomainParameters domainParameters = new ECDomainParameters(sm2ECParameters.getCurve(), sm2ECParameters.getG(),
// sm2ECParameters.getN(), sm2ECParameters.getH());
// ECPoint pukPoint = sm2ECParameters.getCurve()
// .decodePoint(Hex.decode(publicKey));
// ECPublicKeyParameters publicKeyParameters = new ECPublicKeyParameters(pukPoint, domainParameters);
// SM2Engine.Mode mode = SM2Engine.Mode.C1C3C2;
// SM2Engine sm2Engine = new SM2Engine(mode);
// // 设置sm2为加密模式
// sm2Engine.init(true, new ParametersWithRandom(publicKeyParameters, new SecureRandom()));
// byte[] arrayOfBytes = null;
// byte[] in = obj.getBytes(StandardCharsets.UTF_8);
// try {
// arrayOfBytes = sm2Engine.processBlock(in, 0, in.length);
// } catch (Exception e) {
// e.printStackTrace();
// }
// return Base64.encode(arrayOfBytes);
return null;
X9ECParameters sm2ECParameters = GMNamedCurves.getByName("sm2p256v1");
ECDomainParameters domainParameters = new ECDomainParameters(sm2ECParameters.getCurve(), sm2ECParameters.getG(),
sm2ECParameters.getN(), sm2ECParameters.getH());
ECPoint pukPoint = sm2ECParameters.getCurve()
.decodePoint(Hex.decode(publicKey));
ECPublicKeyParameters publicKeyParameters = new ECPublicKeyParameters(pukPoint, domainParameters);
SM2Engine.Mode mode = SM2Engine.Mode.C1C3C2;
SM2Engine sm2Engine = new SM2Engine(mode);
// 设置sm2为加密模式
sm2Engine.init(true, new ParametersWithRandom(publicKeyParameters, new SecureRandom()));
byte[] arrayOfBytes = null;
byte[] in = obj.getBytes(StandardCharsets.UTF_8);
try {
arrayOfBytes = sm2Engine.processBlock(in, 0, in.length);
} catch (Exception e) {
e.printStackTrace();
}
return Base64.encode(arrayOfBytes);
}
......@@ -213,7 +215,7 @@ public class JXDZUtils {
* @param reaccessId
* @return
*/
private String buildEncryptData(Long platformId, Long time, List data, Long reaccessId) {
private String buildEncryptData(Long platformId, Long time, List data, Long reaccessId) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("platformId", platformId);
if (!Objects.isNull(reaccessId)) {
......@@ -222,6 +224,11 @@ public class JXDZUtils {
jsonObject.put("time", time);
jsonObject.put("data", data);
log.info("发送的原始数据{}",jsonObject);
// try {
// return SM2Utils.encrypt(publicKey.getBytes(),jsonObject.toJSONString().getBytes());
// } catch (Exception e) {
// throw new RuntimeException(e);
// }
return dataEncrypt(jsonObject.toJSONString(), publicKey);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment