二级和app修改
This commit is contained in:
@@ -0,0 +1,55 @@
|
|||||||
|
package com.fizz.business.controller;
|
||||||
|
|
||||||
|
import com.fizz.business.constants.enums.DeviceEnum;
|
||||||
|
import com.ruoyi.common.annotation.Anonymous;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/deviceEnum")
|
||||||
|
@Tag(name = "设备枚举")
|
||||||
|
@Anonymous
|
||||||
|
public class DeviceEnumController {
|
||||||
|
|
||||||
|
@GetMapping("/all")
|
||||||
|
@Operation(description = "获取DeviceEnum全量定义(用于前端动态渲染)")
|
||||||
|
public R<List<DeviceDefVO>> all() {
|
||||||
|
List<DeviceDefVO> list = Arrays.stream(DeviceEnum.values())
|
||||||
|
.map(DeviceDefVO::from)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
return R.ok(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class DeviceDefVO {
|
||||||
|
private String deviceCode; // DeviceEnum.name()
|
||||||
|
private Integer idx;
|
||||||
|
private String desc;
|
||||||
|
private Double basePosition;
|
||||||
|
private String sectionType;
|
||||||
|
private String sourceType;
|
||||||
|
private List<String> paramFields;
|
||||||
|
|
||||||
|
public static DeviceDefVO from(DeviceEnum e) {
|
||||||
|
DeviceDefVO vo = new DeviceDefVO();
|
||||||
|
vo.setDeviceCode(e.name());
|
||||||
|
vo.setIdx(e.getIdx());
|
||||||
|
vo.setDesc(e.getDesc());
|
||||||
|
vo.setBasePosition(e.getBasePosition());
|
||||||
|
vo.setSectionType(e.getSectionType().name());
|
||||||
|
vo.setSourceType(e.getSourceType().name());
|
||||||
|
vo.setParamFields(e.getParamFields());
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
package com.fizz.business.controller;
|
||||||
|
|
||||||
|
import com.fizz.business.domain.msg.AppMeasureCoatMessage;
|
||||||
|
import com.fizz.business.domain.msg.AppMeasureEntryMessage;
|
||||||
|
import com.fizz.business.domain.msg.AppMeasureExitMessage;
|
||||||
|
import com.fizz.business.domain.msg.AppMeasureFurnaceMessage;
|
||||||
|
import com.ruoyi.common.annotation.Anonymous;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/deviceFieldMeta")
|
||||||
|
@Tag(name = "设备字段元数据")
|
||||||
|
@Anonymous
|
||||||
|
public class DeviceFieldMetaController {
|
||||||
|
|
||||||
|
@GetMapping("/all")
|
||||||
|
@Operation(description = "获取测量字段的友好文案(来自 @Schema(description))")
|
||||||
|
public R<Map<String, FieldMetaVO>> all() {
|
||||||
|
Map<String, FieldMetaVO> map = new HashMap<>();
|
||||||
|
// 4个消息类全扫一遍
|
||||||
|
collect(map, AppMeasureEntryMessage.class);
|
||||||
|
collect(map, AppMeasureFurnaceMessage.class);
|
||||||
|
collect(map, AppMeasureCoatMessage.class);
|
||||||
|
collect(map, AppMeasureExitMessage.class);
|
||||||
|
return R.ok(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void collect(Map<String, FieldMetaVO> map, Class<?> clazz) {
|
||||||
|
for (Field f : clazz.getDeclaredFields()) {
|
||||||
|
String fieldName = f.getName();
|
||||||
|
Schema schema = f.getAnnotation(Schema.class);
|
||||||
|
if (schema == null) continue;
|
||||||
|
|
||||||
|
String desc = schema.description();
|
||||||
|
if (desc == null || desc.trim().isEmpty()) continue;
|
||||||
|
|
||||||
|
FieldMetaVO vo = new FieldMetaVO();
|
||||||
|
vo.setLabel(parseLabel(desc));
|
||||||
|
vo.setUnit(parseUnit(desc));
|
||||||
|
vo.setDescription(desc);
|
||||||
|
map.putIfAbsent(fieldName, vo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 例:"上层平均涂层重量 (g/m²)" -> label=上层平均涂层重量
|
||||||
|
private String parseLabel(String desc) {
|
||||||
|
int idx = desc.indexOf('(');
|
||||||
|
if (idx > 0) return desc.substring(0, idx).trim();
|
||||||
|
idx = desc.indexOf('(');
|
||||||
|
if (idx > 0) return desc.substring(0, idx).trim();
|
||||||
|
return desc.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 例:"上层平均涂层重量 (g/m²)" -> unit=g/m²
|
||||||
|
private String parseUnit(String desc) {
|
||||||
|
int l = desc.indexOf('(');
|
||||||
|
int r = desc.indexOf(')');
|
||||||
|
if (l >= 0 && r > l) return desc.substring(l + 1, r).trim();
|
||||||
|
l = desc.indexOf('(');
|
||||||
|
r = desc.indexOf(')');
|
||||||
|
if (l >= 0 && r > l) return desc.substring(l + 1, r).trim();
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class FieldMetaVO {
|
||||||
|
private String label;
|
||||||
|
private String unit;
|
||||||
|
private String description;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user