20260411:数据推送模板推送优化
This commit is contained in:
parent
3bef373309
commit
bb2bd720fb
@ -216,7 +216,7 @@ public class ThingsModelPushHandler {
|
|||||||
}
|
}
|
||||||
String dataText = String.join(";", levelTextMap.get(chosen));
|
String dataText = String.join(";", levelTextMap.get(chosen));
|
||||||
if (dataText.length() > 32) {
|
if (dataText.length() > 32) {
|
||||||
dataText = dataText.substring(0, 29) + "...";
|
dataText = dataText.substring(0, 30) + "..";
|
||||||
}
|
}
|
||||||
|
|
||||||
return sendTemplateMsg(config, msgParams, serialNumber, chosen, dataText, pushUrl, openIdMap);
|
return sendTemplateMsg(config, msgParams, serialNumber, chosen, dataText, pushUrl, openIdMap);
|
||||||
@ -358,12 +358,13 @@ public class ThingsModelPushHandler {
|
|||||||
List<String> varNames = extractVarNames(msgParams.getContent());
|
List<String> varNames = extractVarNames(msgParams.getContent());
|
||||||
|
|
||||||
Map<String, String> map = new LinkedHashMap<>();
|
Map<String, String> map = new LinkedHashMap<>();
|
||||||
String deviceDisplay = StringUtils.isNotEmpty(config.getDeviceName())
|
// TODO 目前还没想好要怎样处理
|
||||||
? config.getDeviceName() : serialNumber;
|
// String deviceDisplay = StringUtils.isNotEmpty(config.getDeviceName())
|
||||||
|
// ? config.getDeviceName() : serialNumber;
|
||||||
for (int i = 0; i < varNames.size(); i++) {
|
for (int i = 0; i < varNames.size(); i++) {
|
||||||
String varName = varNames.get(i);
|
String varName = varNames.get(i);
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
map.put(varName, deviceDisplay);
|
map.put(varName, varName.contains("thing") ? config.getDeviceName() : serialNumber);
|
||||||
} else if (i == 1) {
|
} else if (i == 1) {
|
||||||
map.put(varName, level.getLabel());
|
map.put(varName, level.getLabel());
|
||||||
} else if (i == 2) {
|
} else if (i == 2) {
|
||||||
@ -371,7 +372,7 @@ public class ThingsModelPushHandler {
|
|||||||
} else if (i == 3) {
|
} else if (i == 3) {
|
||||||
map.put(varName, simpleDateFormat.format(new Date()));
|
map.put(varName, simpleDateFormat.format(new Date()));
|
||||||
} else {
|
} else {
|
||||||
map.put(varName, config.getDeviceAddress());
|
map.put(varName, buildDeviceAddress(config.getDeviceAddress()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -436,4 +437,80 @@ public class ThingsModelPushHandler {
|
|||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提取:城市 + 街道后详细地址
|
||||||
|
*/
|
||||||
|
public static String parse(String address) {
|
||||||
|
if (address == null || address.isEmpty()) {
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
String city = extractCity(address);
|
||||||
|
String detail = extractAfterStreet(address);
|
||||||
|
|
||||||
|
return city + detail;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建微信模板推送地址
|
||||||
|
* @param deviceAddress 全地址
|
||||||
|
* @return 精简地址
|
||||||
|
*/
|
||||||
|
private static String buildDeviceAddress(String deviceAddress) {
|
||||||
|
|
||||||
|
if (StringUtils.isEmpty(deviceAddress)) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
String addr = extractCity(deviceAddress) + extractAfterStreet(deviceAddress);
|
||||||
|
return addr.length() > 20 ? addr.substring(0, 18) + ".." : addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提取城市(xx市)
|
||||||
|
*/
|
||||||
|
private static String extractCity(String address) {
|
||||||
|
int cityStart = address.indexOf("市");
|
||||||
|
if (cityStart != -1) {
|
||||||
|
// 往前找“省”或开头
|
||||||
|
int provinceIndex = address.lastIndexOf("省", cityStart);
|
||||||
|
if (provinceIndex != -1) {
|
||||||
|
return address.substring(provinceIndex + 1, cityStart);
|
||||||
|
} else {
|
||||||
|
// 没有省,直接取前面的部分
|
||||||
|
return address.substring(0, cityStart);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提取“街道”后面的详细地址
|
||||||
|
*/
|
||||||
|
private static String extractAfterStreet(String address) {
|
||||||
|
int index = address.indexOf("街道");
|
||||||
|
if (index != -1) {
|
||||||
|
return address.substring(index + 2); // “街道”两个字
|
||||||
|
}
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 测试
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String addr1 = "未知地址";
|
||||||
|
String addr2 = "湖南省长沙市岳麓区学士街道盛乐迪便利店(智达佳园店)";
|
||||||
|
|
||||||
|
String parse1 = parse(addr1);
|
||||||
|
System.out.println(parse1 + "," + parse1.length());
|
||||||
|
String parse2 = parse(addr2);
|
||||||
|
System.out.println(parse2 + "," + parse2.length());
|
||||||
|
|
||||||
|
ThingsModelPushHandler obj = new ThingsModelPushHandler();
|
||||||
|
String content = "设备名称 {{thing23.DATA}} 告警级别 {{const100.DATA}} 监测数据 {{character_string159.DATA}} 上报时间 {{time160.DATA}} 设备地址 {{thing98.DATA}}";
|
||||||
|
List<String> strings = obj.extractVarNames(content);
|
||||||
|
System.out.println("strings = " + strings);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,6 @@ import com.fastbee.common.utils.CalculateUtils;
|
|||||||
import com.fastbee.common.utils.DateUtils;
|
import com.fastbee.common.utils.DateUtils;
|
||||||
import com.fastbee.common.utils.SecurityUtils;
|
import com.fastbee.common.utils.SecurityUtils;
|
||||||
import com.fastbee.common.utils.StringUtils;
|
import com.fastbee.common.utils.StringUtils;
|
||||||
import com.fastbee.iot.cache.SceneModelTagCache;
|
|
||||||
import com.fastbee.iot.domain.*;
|
import com.fastbee.iot.domain.*;
|
||||||
import com.fastbee.iot.model.*;
|
import com.fastbee.iot.model.*;
|
||||||
import com.fastbee.iot.model.dto.ThingsModelDTO;
|
import com.fastbee.iot.model.dto.ThingsModelDTO;
|
||||||
@ -49,8 +48,6 @@ public class DataCenterServiceImpl implements DataCenterService {
|
|||||||
@Resource
|
@Resource
|
||||||
private IThingsModelService thingsModelService;
|
private IThingsModelService thingsModelService;
|
||||||
@Resource
|
@Resource
|
||||||
private SceneModelTagCache sceneModelTagCache;
|
|
||||||
@Resource
|
|
||||||
private IAlertLogService alertLogService;
|
private IAlertLogService alertLogService;
|
||||||
@Resource
|
@Resource
|
||||||
private IProductSubGatewayService productSubGatewayService;
|
private IProductSubGatewayService productSubGatewayService;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user