Przeglądaj źródła

update
提交修改内容

wangzl 4 miesięcy temu
rodzic
commit
26f3ab6048

+ 7 - 4
tr-modules/tr-module-smartFollowUp/src/main/java/cn/tr/module/smart/common/service/impl/BizMpPublishTaskServiceImpl.java

@@ -1,6 +1,5 @@
 package cn.tr.module.smart.common.service.impl;
 
-import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.tr.core.exception.ServiceException;
@@ -22,7 +21,6 @@ import cn.tr.module.smart.common.repository.BizMpPublishTaskRepository;
 import cn.tr.module.smart.common.repository.BizQuestionGroupRepository;
 import cn.tr.module.smart.common.service.IBizMpPublishTaskService;
 import cn.tr.module.smart.common.service.helper.BizClinicRoomHelper;
-import cn.tr.module.smart.common.util.ReflectConverter;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import org.quartz.JobDetail;
 import org.quartz.JobKey;
@@ -129,7 +127,7 @@ public class BizMpPublishTaskServiceImpl implements IBizMpPublishTaskService {
             for (BizMpPublishTaskPO task : bizMpPublishTaskPOS) {
                 List<JobKeyEntity> cronJob = task.getCronJob();
                 List<JobKey> collect = cronJob.stream()
-                        .map(jobKeyEntity -> ReflectConverter.convert(jobKeyEntity, JobKey.class))
+                        .map(jobKeyEntity -> new JobKey(jobKeyEntity.getName(), jobKeyEntity.getGroup()))
                         .collect(Collectors.toList());
                 for (JobKey jobKey : collect) {
                     scheduler.deleteJob(jobKey);
@@ -172,7 +170,12 @@ public class BizMpPublishTaskServiceImpl implements IBizMpPublishTaskService {
             jobKeys.add(scheduleJob.getKey());
         }
         List<JobKeyEntity> collect = jobKeys.stream()
-                .map(jobKey -> ReflectConverter.convert(jobKey, JobKeyEntity.class))
+                .map(jobKey -> {
+                    JobKeyEntity jobKeyEntity = new JobKeyEntity();
+                    jobKeyEntity.setName(jobKey.getName());
+                    jobKeyEntity.setGroup(jobKey.getGroup());
+                    return jobKeyEntity;
+                })
                 .collect(Collectors.toList());
         mpPublishTask.setCronJob(collect);
         baseRepository.insert(mpPublishTask);

+ 0 - 147
tr-modules/tr-module-smartFollowUp/src/main/java/cn/tr/module/smart/common/util/ReflectConverter.java

@@ -1,147 +0,0 @@
-package cn.tr.module.smart.common.util;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author wangzl
- * @description: 基于反射的对象类型转换工具类
- * @date 2025/7/29 16:55
- */
-public class ReflectConverter {
-
-    /**
-     * 将源对象转换为目标类型的对象
-     * @param source 源对象
-     * @param targetClass 目标类的Class对象
-     * @return 转换后的目标对象
-     */
-    public static <T> T convert(Object source, Class<T> targetClass) {
-        if (source == null) {
-            return null;
-        }
-
-        try {
-            // 创建目标对象实例
-            T target = targetClass.getDeclaredConstructor().newInstance();
-
-            // 获取源对象和目标对象的所有字段(包括父类)
-            List<Field> sourceFields = getAllFields(source.getClass());
-            List<Field> targetFields = getAllFields(targetClass);
-
-            // 遍历目标字段,从源对象中匹配并赋值
-            for (Field targetField : targetFields) {
-                // 跳过静态字段和final字段
-                if (Modifier.isStatic(targetField.getModifiers()) || Modifier.isFinal(targetField.getModifiers())) {
-                    continue;
-                }
-
-                // 根据字段名匹配源字段
-                Field sourceField = findFieldByName(sourceFields, targetField.getName());
-                if (sourceField == null) {
-                    continue; // 源对象中无对应字段,跳过
-                }
-
-                // 设置字段可访问
-                sourceField.setAccessible(true);
-                targetField.setAccessible(true);
-
-                // 获取源字段值
-                Object value = sourceField.get(source);
-                if (value == null) {
-                    continue; // 源字段值为null,不赋值
-                }
-
-                // 处理类型转换(此处简化处理,实际可扩展更多类型)
-                Object convertedValue = convertValue(value, targetField.getType());
-
-                // 赋值到目标字段
-                targetField.set(target, convertedValue);
-            }
-
-            return target;
-        } catch (Exception e) {
-            throw new RuntimeException("对象转换失败: " + e.getMessage(), e);
-        }
-    }
-
-    /**
-     * 获取类及其所有父类的字段
-     */
-    private static List<Field> getAllFields(Class<?> clazz) {
-        List<Field> fields = new ArrayList<>();
-        Class<?> currentClass = clazz;
-        // 遍历所有父类,直到Object类
-        while (currentClass != null && currentClass != Object.class) {
-            Field[] declaredFields = currentClass.getDeclaredFields();
-            for (Field field : declaredFields) {
-                fields.add(field);
-            }
-            currentClass = currentClass.getSuperclass();
-        }
-        return fields;
-    }
-
-    /**
-     * 根据字段名从字段列表中查找字段
-     */
-    private static Field findFieldByName(List<Field> fields, String fieldName) {
-        for (Field field : fields) {
-            if (field.getName().equals(fieldName)) {
-                return field;
-            }
-        }
-        return null;
-    }
-
-    /**
-     * 简单的字段值类型转换(可根据需求扩展)
-     */
-    private static Object convertValue(Object value, Class<?> targetType) {
-        // 类型相同,直接返回
-        if (targetType.isInstance(value)) {
-            return value;
-        }
-
-        // 基本类型与包装类转换(如int与Integer)
-        if (targetType.isPrimitive()) {
-            targetType = getWrapperClass(targetType);
-        }
-
-        // 字符串转数字(示例)
-        if (targetType == Integer.class && value instanceof String) {
-            return Integer.parseInt((String) value);
-        }
-        if (targetType == Long.class && value instanceof String) {
-            return Long.parseLong((String) value);
-        }
-        if (targetType == Double.class && value instanceof String) {
-            return Double.parseDouble((String) value);
-        }
-
-        // 数字转字符串
-        if (targetType == String.class && value instanceof Number) {
-            return value.toString();
-        }
-
-        // 其他类型转换可在此扩展(如日期转换等)
-        throw new IllegalArgumentException("不支持的类型转换: " + value.getClass() + " -> " + targetType);
-    }
-
-    /**
-     * 获取基本类型对应的包装类
-     */
-    private static Class<?> getWrapperClass(Class<?> primitiveType) {
-        if (primitiveType == int.class) return Integer.class;
-        if (primitiveType == long.class) return Long.class;
-        if (primitiveType == double.class) return Double.class;
-        if (primitiveType == boolean.class) return Boolean.class;
-        if (primitiveType == float.class) return Float.class;
-        if (primitiveType == short.class) return Short.class;
-        if (primitiveType == byte.class) return Byte.class;
-        if (primitiveType == char.class) return Character.class;
-        return primitiveType;
-    }
-}