Merge remote-tracking branch 'origin/main'

This commit is contained in:
2026-04-14 14:25:29 +08:00
22 changed files with 409 additions and 67 deletions

View File

@@ -268,32 +268,53 @@ public class UserNameResponseAdvice implements ResponseBodyAdvice<Object> {
* 递归处理children字段
*/
private void processChildrenField(Object obj) throws Exception {
List<Field> fields = getAllFields(obj);
if (obj instanceof Map) {
// JSONObject 实现了 Map 接口,直接按 key 取值
Map<?, ?> map = (Map<?, ?>) obj;
Object children = map.get("children");
if (children != null) {
processBody(children);
}
} else {
List<Field> fields = getAllFields(obj);
for (Field field : fields) {
if ("children".equals(field.getName())) {
field.setAccessible(true);
Object children = field.get(obj);
for (Field field : fields) {
if ("children".equals(field.getName())) {
field.setAccessible(true);
Object children = field.get(obj);
if (children != null) {
// 递归处理children
processBody(children);
if (children != null) {
// 递归处理children
processBody(children);
}
// 找到children字段后就可以退出循环了
break;
}
// 找到children字段后就可以退出循环了
break;
}
}
}
private Set<Long> collectUserIds(Object obj) throws Exception {
Set<Long> userIds = new HashSet<>();
List<Field> fields = getAllFields(obj);
for (Field field : fields) {
if (isUserIdField(field)) {
field.setAccessible(true);
Long userId = (Long) field.get(obj);
userIds.add(userId);
if (obj instanceof Map) {
// JSONObject 实现了 Map 接口,直接按 key 取值
Map<?, ?> map = (Map<?, ?>) obj;
for (String key : Arrays.asList("creator", "updater", "userId")) {
Object value = map.get(key);
Long longValue = toLong(value);
if (longValue != null) {
userIds.add(longValue);
}
}
} else {
List<Field> fields = getAllFields(obj);
for (Field field : fields) {
if (isUserIdField(field)) {
field.setAccessible(true);
Long userId = (Long) field.get(obj);
userIds.add(userId);
}
}
}
@@ -321,24 +342,60 @@ public class UserNameResponseAdvice implements ResponseBodyAdvice<Object> {
return "creator".equals(fieldName) || "updater".equals(fieldName) || "userId".equals(fieldName);
}
private void setUserNamesToObject(Object obj, Map<Long, String> userNames) throws Exception {
List<Field> fields = getAllFields(obj);
/**
* 将值转为Long兼容 String、Number 等类型
*/
private Long toLong(Object value) {
if (value instanceof Long) {
return (Long) value;
} else if (value instanceof Number) {
return ((Number) value).longValue();
} else if (value instanceof String) {
String str = ((String) value).trim();
if (!str.isEmpty()) {
try {
return Long.parseLong(str);
} catch (NumberFormatException e) {
return null;
}
}
}
return null;
}
for (Field field : fields) {
if (isUserIdField(field)) {
field.setAccessible(true);
Long userId = (Long) field.get(obj);
String userName = userNames.get(userId);
if (userName != null) {
// 设置对应的name字段
String nameFieldName = field.getName() + "Name";
try {
Field nameField = getFieldRecursively(obj.getClass(), nameFieldName);
nameField.setAccessible(true);
nameField.set(obj, userName);
} catch (NoSuchFieldException e) {
// 如果没有对应的name字段忽略
log.debug("对象 {} 没有字段 {}", obj.getClass().getSimpleName(), nameFieldName);
private void setUserNamesToObject(Object obj, Map<Long, String> userNames) throws Exception {
if (obj instanceof Map) {
// JSONObject 实现了 Map 接口,直接通过 key 操作
Map<String, Object> map = (Map<String, Object>) obj;
for (String key : Arrays.asList("creator", "updater", "userId")) {
Object value = map.get(key);
Long userId = toLong(value);
if (userId != null) {
String userName = userNames.get(userId);
if (userName != null) {
map.put(key + "Name", userName);
}
}
}
} else {
List<Field> fields = getAllFields(obj);
for (Field field : fields) {
if (isUserIdField(field)) {
field.setAccessible(true);
Long userId = (Long) field.get(obj);
String userName = userNames.get(userId);
if (userName != null) {
// 设置对应的name字段
String nameFieldName = field.getName() + "Name";
try {
Field nameField = getFieldRecursively(obj.getClass(), nameFieldName);
nameField.setAccessible(true);
nameField.set(obj, userName);
} catch (NoSuchFieldException e) {
// 如果没有对应的name字段忽略
log.debug("对象 {} 没有字段 {}", obj.getClass().getSimpleName(), nameFieldName);
}
}
}
}

View File

@@ -247,4 +247,9 @@ public class SpdmTaskVo extends BaseEntity {
*/
private String toDoMarker;
/**
* 关联的需求的需求类型
*/
private String demandType;
}