90 lines
3.3 KiB
Java
90 lines
3.3 KiB
Java
|
|
package com.cbsd.client.pretreatment;
|
|||
|
|
|
|||
|
|
import com.cbsd.client.pretreatment.CalculateUtils;
|
|||
|
|
import com.cbsd.client.pretreatment.IPreTreatmentInterface;
|
|||
|
|
|
|||
|
|
import java.util.Map;
|
|||
|
|
|
|||
|
|
public class Pretreatment_12ddd0fdb0dc4312975a9007d9ad3f79 implements IPreTreatmentInterface {
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 预处理
|
|||
|
|
* @param command 指令内容
|
|||
|
|
* @param repeatCount 重复次数
|
|||
|
|
* @param hitCount 命中次数
|
|||
|
|
* @param latestHitTime 最后命中时间
|
|||
|
|
* @param dataMap 数据集合,key为协议字段属性名(label),value为物理值
|
|||
|
|
* @param calculateUtils 计算工具类
|
|||
|
|
* @return 结果
|
|||
|
|
*/
|
|||
|
|
@Override
|
|||
|
|
public String pretreatment(String command, int repeatCount, int hitCount, String latestHitTime, Map<String, String> dataMap, CalculateUtils calculateUtils) {
|
|||
|
|
String commandPart = "";
|
|||
|
|
if (command != null && command.length() >= 2) {
|
|||
|
|
commandPart = command.substring(command.length() - 2);
|
|||
|
|
} else if (command != null) {
|
|||
|
|
// 如果指令长度不足2位,用0补齐
|
|||
|
|
commandPart = String.format("%2s", command).replace(' ', '0');
|
|||
|
|
} else {
|
|||
|
|
commandPart = "00";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
String repeatCountStr = String.format("%02d", repeatCount % 100);
|
|||
|
|
String hitCountStr = String.format("%02d", hitCount % 100);
|
|||
|
|
|
|||
|
|
String dataMapPart = "00"; // 默认值
|
|||
|
|
if (dataMap != null && !dataMap.isEmpty()) {
|
|||
|
|
// 遍历dataMap的所有值,拼接成一个字符串
|
|||
|
|
StringBuilder allValues = new StringBuilder();
|
|||
|
|
for (Map.Entry<String, String> entry : dataMap.entrySet()) {
|
|||
|
|
String value = entry.getValue();
|
|||
|
|
if (value != null) {
|
|||
|
|
allValues.append(value);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
String allValuesStr = allValues.toString();
|
|||
|
|
if (allValuesStr.length() >= 2) {
|
|||
|
|
// 取最后2位
|
|||
|
|
dataMapPart = allValuesStr.substring(0, 2);
|
|||
|
|
} else if (allValuesStr.length() == 1) {
|
|||
|
|
// 如果只有1位,前面补0
|
|||
|
|
dataMapPart = "0" + allValuesStr;
|
|||
|
|
}
|
|||
|
|
// 如果为空,保持默认值"00"
|
|||
|
|
}
|
|||
|
|
if (latestHitTime != null && latestHitTime.length() >= 19) {
|
|||
|
|
// 提取所有数字字符
|
|||
|
|
StringBuilder numbers = new StringBuilder();
|
|||
|
|
for (int i = 0; i < latestHitTime.length(); i++) {
|
|||
|
|
char c = latestHitTime.charAt(i);
|
|||
|
|
if (Character.isDigit(c)) {
|
|||
|
|
numbers.append(c);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 检查是否提取到了足够的数字(至少14位:yyyyMMddHHmmss)
|
|||
|
|
if (numbers.length() >= 14) {
|
|||
|
|
// 取前14位数字(年月日时分秒)
|
|||
|
|
String timeDigits = numbers.substring(6, 14);
|
|||
|
|
// 在最前面补两个0,形成8字节(16个字符)的十六进制表示
|
|||
|
|
return commandPart + hitCountStr + repeatCountStr +dataMapPart + timeDigits;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 如果latestHitTime格式不正确,返回默认值
|
|||
|
|
return command;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 描述
|
|||
|
|
*
|
|||
|
|
* @return 描述内容
|
|||
|
|
*/
|
|||
|
|
@Override
|
|||
|
|
public String comment() {
|
|||
|
|
return "";
|
|||
|
|
}
|
|||
|
|
}
|