feat(plcSchemaDetail):增加数据类型翻译并优化数据处理逻辑

- 在 PlcSchemaDetailDto 中添加 typeName 字段并使用 DictTranslate 注解进行数据类型翻译
- 优化 PlcSchemaDetailService 中的 JSON 数据处理逻辑
- 移除无效的字段并改进字段命名规则
-采用更高效的字段迭代方式并使用 HashMap 进行计数
This commit is contained in:
2025-05-09 20:18:59 +08:00
parent 9093cd6d8b
commit 69035a7f59
2 changed files with 31 additions and 21 deletions

View File

@@ -2,6 +2,7 @@ package cn.lihongjie.coal.plcSchemaDetail.dto;
import cn.lihongjie.coal.base.dto.OrgCommonDto;
import cn.lihongjie.coal.base.dto.SimpleDto;
import cn.lihongjie.coal.pojoProcessor.DictTranslate;
import lombok.Data;
@@ -21,7 +22,11 @@ public class PlcSchemaDetailDto extends OrgCommonDto {
private String type;
@DictTranslate(dictKey = "plc.schema.detail.type")
private String typeName;
@Comment("父级表头")
private String displayGroup;
}

View File

@@ -22,6 +22,7 @@ import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.ConversionService;
import org.springframework.data.domain.Page;
@@ -30,6 +31,8 @@ import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -46,8 +49,7 @@ public class PlcSchemaDetailService
@Autowired private DbFunctionService dbFunctionService;
@Autowired private ObjectMapper objectMapper;
@Autowired
private PlcSchemaService plcSchemaService;
@Autowired private PlcSchemaService plcSchemaService;
public PlcSchemaDetailDto create(CreatePlcSchemaDetailDto request) {
PlcSchemaDetailEntity entity = mapper.toEntity(request);
@@ -147,6 +149,7 @@ public class PlcSchemaDetailService
JsonNode jsonNode = objectMapper.readTree(json);
Map<String, Integer> counter = new HashMap<>();
List<PlcSchemaDetailEntity> entities = new java.util.ArrayList<>();
@@ -154,12 +157,19 @@ public class PlcSchemaDetailService
ObjectNode node = (ObjectNode) jsonNode;
int cnt = 0;
while (node.fields().hasNext()) {
Iterator<Map.Entry<String, JsonNode>> fields = node.fields();
while (fields.hasNext()) {
Map.Entry<String, JsonNode> next = fields.next();
if (StringUtils.equalsAnyIgnoreCase(next.getKey(), "deviceCode", "time")) {
continue;
}
Map.Entry<String, JsonNode> next = node.fields().next();
PlcSchemaDetailEntity entity = new PlcSchemaDetailEntity();
entity.setPlcSchema(plcSchemaService.get(id));
entity.setName(next.getKey().replace(".Value", ""));
entity.setName(next.getKey().replace(".Value", "").replace("$", ""));
entity.setStatus(1);
@@ -175,36 +185,31 @@ public class PlcSchemaDetailService
if (next.getValue().isTextual()) {
entity.setType("string");
entity.setCode(getNextCode("string", organizationId));
entity.setType("str");
entity.setCode(
"str" + counter.compute("string", (k, v) -> v == null ? 1 : v + 1));
} else if (next.getValue().isFloatingPointNumber()) {
entity.setType("double");
entity.setCode(getNextCode("double", organizationId));
entity.setCode(
"double" + counter.compute("double", (k, v) -> v == null ? 1 : v + 1));
}else if (next.getValue().isBoolean()){
} else if (next.getValue().isBoolean()) {
entity.setType("bool");
entity.setCode(getNextCode("bool", organizationId));
}else if (next.getValue().isIntegralNumber()){
entity.setCode(
"bool" + counter.compute("bool", (k, v) -> v == null ? 1 : v + 1));
} else if (next.getValue().isIntegralNumber()) {
entity.setType("int");
entity.setCode(getNextCode("int", organizationId));
entity.setCode("int" + counter.compute("int", (k, v) -> v == null ? 1 : v + 1));
}else {
} else {
throw new BizException("不支持的数据类型 " + next.getValue().getNodeType());
}
}
}