编写南京盐城驰诚对接接口

master
alsszer 1 week ago
parent 3ba9930af1
commit 1e95123dc6

@ -80,10 +80,10 @@ public class ThingModelMessageDataImpl implements IThingModelMessageData {
return new Paging<>(count, ruleLogs.stream().map(r ->
new ThingModelMessage(r.getTime().toString(), r.getMid(),
deviceId, r.getProductKey(), r.getDeviceName(),
r.getUid(), r.getType(),r.getIdentifier(),r.getCode(),
r.getUid(), r.getType(),r.getIdentifier(),r.getDeviceStatus(),r.getCode(),
JsonUtils.parseObject(r.getData(), Map.class),
r.getTime(), r.getReportTime()))
.collect(Collectors.toList()));//r.getDeviceStatus(),
.collect(Collectors.toList()));
}
@Override
@ -120,7 +120,7 @@ public class ThingModelMessageDataImpl implements IThingModelMessageData {
return new Paging<>(count, ruleLogs.stream().map(r ->
new ThingModelMessage(r.getTime().toString(), r.getMid(),
r.getDeviceId(), r.getProductKey(), r.getDeviceName(),
r.getUid(), r.getType(), r.getIdentifier(), r.getCode(),
r.getUid(), r.getType(), r.getIdentifier(), r.getDeviceStatus(), r.getCode(),
JsonUtils.parseObject(r.getData(), Map.class),
r.getTime(), r.getReportTime()))
.collect(Collectors.toList()));

@ -376,10 +376,17 @@ public class DeviceManagerServiceImpl implements IDeviceManagerService {
@Override
public boolean batchDeleteDevice(List<String> ids) {
deviceInfoData.deleteByIds(ids);
//TODO 批量删除时发出事件
if (ids == null || ids.isEmpty()) {
return true;
}
for (String id : ids) {
DeviceInfo device = deviceInfoData.findByDeviceId(id);
if (device == null) {
continue;
}
deviceInfoData.deleteById(device.getDeviceId());
eventPublisher.publishEvent(new DeviceSyncEvent(this, "delete", device));
}
return true;
}

@ -2,8 +2,10 @@ package cc.iotkit.openapi.sync;
import cc.iotkit.manager.config.DeviceSyncConfig;
import cc.iotkit.manager.event.DeviceSyncEvent;
import cc.iotkit.model.device.DeviceInfo;
import cc.iotkit.system.dto.vo.SysTenantVo;
import cc.iotkit.system.service.ISysTenantService;
import cn.hutool.core.util.ObjectUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -30,12 +32,26 @@ public class DeviceSyncService {
private final OkHttpClient httpClient = new OkHttpClient.Builder().build();
public void sync(DeviceSyncEvent event) {
if (event == null || event.getDevice() == null) {
log.warn("设备同步事件缺少设备信息,跳过同步");
return;
}
if (!config.isEnable()) {
log.info("设备同步功能未启用跳过同步operation={}, deviceId={}",
event.getOperation(), event.getDevice().getDeviceId());
return;
}
// 产品白名单过滤,只同步指定产品下的设备
if (ObjectUtil.isNotEmpty(config.getSyncProductKeys())) {
String productKey = event.getDevice().getProductKey();
if (!config.getSyncProductKeys().contains(productKey)) {
log.info("设备产品不在同步白名单内跳过同步operation={}, deviceId={}, productKey={}",
event.getOperation(), event.getDevice().getDeviceId(), productKey);
return;
}
}
int maxRetry = config.getRetry();
for (int i = 0; i < maxRetry; i++) {
try {
@ -54,13 +70,17 @@ public class DeviceSyncService {
}
private void doSync(DeviceSyncEvent event) throws Exception {
String deviceId = event.getDevice().getDeviceId();
String token = encrypt(deviceId, config.getEncryptKey());
DeviceInfo device = event.getDevice();
// 盐城要求 deviceCode 为设备 IMEIFIGARO 设备 deviceName 即 IMEI
String deviceCode = config.isUseDeviceNameAsCode()
? device.getDeviceName()
: device.getDeviceId();
String token = encrypt(deviceCode, config.getEncryptKey());
if ("delete".equals(event.getOperation())) {
doDelete(deviceId, token);
doDelete(deviceCode, token);
} else {
doAddOrEdit(event, deviceId, token);
doAddOrEdit(event, deviceCode, token);
}
}
@ -84,7 +104,8 @@ public class DeviceSyncService {
Map<String, Object> body = new HashMap<>();
body.put("deviceCode", deviceId);
body.put("token", token);
body.put("deviceModel", event.getDevice().getModel());
// 已与甲方确认deviceModel 传产品 key
body.put("deviceModel", event.getDevice().getProductKey());
body.put("longitude", event.getDevice().getLongitude());
body.put("latitude", event.getDevice().getLatitude());
body.put("districtName", "");
@ -139,6 +160,7 @@ public class DeviceSyncService {
}
public static String encrypt(String message, String key) throws Exception {
// 加密方式与甲方提供的 DesUtil.java 一致DES/CBC/PKCS5Paddingkey 字节同时作为 IVBase64 输出
Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
DESKeySpec desKeySpec = new DESKeySpec(key.getBytes(StandardCharsets.UTF_8));
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");

@ -224,8 +224,7 @@ public class ThingServiceImpl implements IThingService {
.identifier(ThingModelMessage.ID_PROPERTY_REPORT)
.data(propertyReport.getParams())
.time(propertyReport.getTime())
// 注释原因ThingModelMessage 核心类中不存在 deviceStatus 字段,调用会导致编译失败
// .deviceStatus(device.getDeviceStatus())
.deviceStatus(device.getDeviceStatus())
.occurred(propertyReport.getTime())
.build()
);
@ -367,8 +366,7 @@ public class ThingServiceImpl implements IThingService {
.deviceName(device.getDeviceName())
.productKey(device.getProductKey())
.time(System.currentTimeMillis())
// 注释原因ThingModelMessage 核心类中不存在 deviceStatus 字段,调用会导致编译失败
// .deviceStatus(device.getDeviceStatus())
.deviceStatus(device.getDeviceStatus())
.occurred(System.currentTimeMillis())
.build();
//增加启用未启用条件查询
@ -919,9 +917,7 @@ public class ThingServiceImpl implements IThingService {
private String registerDevice(DeviceInfo device, DeviceRegister register, String parentId) {
String productKey = register.getProductKey();
// 注释原因DeviceRegister 核心类中不存在 params 字段,调用 getParams() 会导致编译失败
// 原 imei/iccid 入库、信号强度/版本号保存逻辑因依赖 params 会失效,待核心库补齐字段后再恢复
Map<String, Object> params = null;
Map<String, Object> params = register.getParams();
try {
if (params != null && !params.isEmpty()) {
if (ObjectUtil.isNotNull(params.get("imei"))) {

@ -165,24 +165,22 @@ public class RuleExecutor {
public void execute(ThingModelMessage message, Rule rule) {
// 注释原因ThingModelMessage 核心类中不存在 deviceStatus 字段,调用 getDeviceStatus() 会导致编译失败
// 该字段在历史版本中存在但已被移除,原逻辑无法生效,故注释掉相关代码以保留历史痕迹
// log.info("The listener did not match the appropriate content,deviceStatus:{},{}", rule.getId(), message.getDeviceStatus());
// if(ObjectUtil.isNull(message.getDeviceStatus())
// || message.getDeviceStatus().equals(2) ||
// message.getDeviceStatus().equals(1)
// ){
// List<AlertConfig> config = iAlertConfigData.findByDeviceName(message.getDeviceName());
// log.info("The listener did not match the appropriate content,deviceStatus:{},{}", rule.getId(), message.getDeviceStatus());
// if(!config.isEmpty()){
// return;
// }else{
// List<AlertConfig> config1 = iAlertConfigData.findByRuleInfoId(rule.getId());
// if(!config1.isEmpty()){
// return;
// }
// }
// }
log.info("The listener did not match the appropriate content,deviceStatus:{},{}", rule.getId(), message.getDeviceStatus());
if(ObjectUtil.isNull(message.getDeviceStatus())
|| message.getDeviceStatus().equals(2) ||
message.getDeviceStatus().equals(1)
){
List<AlertConfig> config = iAlertConfigData.findByDeviceName(message.getDeviceName());
log.info("The listener did not match the appropriate content,deviceStatus:{},{}", rule.getId(), message.getDeviceStatus());
if(!config.isEmpty()){
return;
}else{
List<AlertConfig> config1 = iAlertConfigData.findByRuleInfoId(rule.getId());
if(!config1.isEmpty()){
return;
}
}
}
if (!doListeners(message, rule)) {
/* if(ObjectUtil.isNotNull(message.getDeviceStatus())
&& (message.getDeviceStatus().equals(1) || message.getDeviceStatus().equals(2))

Loading…
Cancel
Save