diff --git a/common/src/main/java/com/sdm/common/config/DataSourcePreWarmer.java b/common/src/main/java/com/sdm/common/config/DataSourcePreWarmer.java new file mode 100644 index 00000000..a075b282 --- /dev/null +++ b/common/src/main/java/com/sdm/common/config/DataSourcePreWarmer.java @@ -0,0 +1,47 @@ +package com.sdm.common.config;//package com.sdm.project.config.mybatis; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.ApplicationRunner; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import javax.sql.DataSource; +import java.sql.Connection; + +@Slf4j +@Configuration +public class DataSourcePreWarmer { + + @Bean + public ApplicationRunner secondDataSourcePreWarmer( + @Qualifier("secondDataSource") DataSource secondDataSource) { + return args -> { + try (Connection conn = secondDataSource.getConnection()) { + log.info("✅ secondDataSource 预热成功,连接已建立: {}", conn); + } catch (Exception e) { + log.error("❌ secondDataSource 预热失败", e); + throw new RuntimeException(e); + } + }; + } + + @Bean + public ApplicationRunner mainDataSourcePreWarmer( + @Qualifier("masterDataSource") DataSource master, + @Qualifier("slaveDataSource") DataSource slave) { + return args -> { + try { + try (Connection c1 = master.getConnection()) { + log.info("✅ masterDataSource 预热成功: {}", c1); + } + try (Connection c2 = slave.getConnection()) { + log.info("✅ slaveDataSource 预热成功: {}", c2); + } + } catch (Exception e) { + log.error("❌ 主从数据源预热失败", e); + throw new RuntimeException(e); + } + }; + } +} \ No newline at end of file diff --git a/project/src/main/java/com/sdm/project/common/RunPerformanceStatusEnum.java b/common/src/main/java/com/sdm/common/entity/enums/PerformanceStatusEnum.java similarity index 74% rename from project/src/main/java/com/sdm/project/common/RunPerformanceStatusEnum.java rename to common/src/main/java/com/sdm/common/entity/enums/PerformanceStatusEnum.java index 08ddace9..f001619b 100644 --- a/project/src/main/java/com/sdm/project/common/RunPerformanceStatusEnum.java +++ b/common/src/main/java/com/sdm/common/entity/enums/PerformanceStatusEnum.java @@ -1,4 +1,4 @@ -package com.sdm.project.common; +package com.sdm.common.entity.enums; import lombok.Getter; @@ -6,7 +6,7 @@ import lombok.Getter; * 指标完成情况状态枚举 */ @Getter -public enum RunPerformanceStatusEnum { +public enum PerformanceStatusEnum { UNCOMPLETED("未完成", "0"), NOT_STARTED("不合格", "1"), @@ -18,7 +18,7 @@ public enum RunPerformanceStatusEnum { private final String code; - RunPerformanceStatusEnum(String name, String code) { + PerformanceStatusEnum(String name, String code) { this.name = name; this.code = code; } diff --git a/common/src/main/java/com/sdm/common/utils/CommonUtils.java b/common/src/main/java/com/sdm/common/utils/CommonUtils.java new file mode 100644 index 00000000..d1f1f18a --- /dev/null +++ b/common/src/main/java/com/sdm/common/utils/CommonUtils.java @@ -0,0 +1,36 @@ +package com.sdm.common.utils; + +public class CommonUtils { + + /** + * 检查字符串是否为有效的数字格式 + */ + public static boolean isValidNumberFormat(String str) { + if (str == null || str.isEmpty()) { + return false; + } + + // 支持: + // 1. 整数:123, -123, +123 + // 2. 小数:123.45, .45, 123. + // 3. 科学计数法:1.23e10, 1.23E-10 + // 4. 排除:空字符串、纯空格、多个小数点、非法字符 + + // 去除首尾空格 + str = str.trim(); + + // 检查是否为空 + if (str.isEmpty()) { + return false; + } + + // 检查是否只包含数字、小数点、正负号、e/E + if (!str.matches("^[+-]?[\\d.eE]+$")) { + return false; + } + + // 更精确的正则表达式 + return str.matches("^[+-]?(\\d+(\\.\\d*)?|\\.\\d+)([eE][+-]?\\d+)?$"); + } + +} diff --git a/flowable/src/main/java/com/sdm/flowable/delegate/handler/HpcHandler.java b/flowable/src/main/java/com/sdm/flowable/delegate/handler/HpcHandler.java index 611b9f9c..bdd9d4d7 100644 --- a/flowable/src/main/java/com/sdm/flowable/delegate/handler/HpcHandler.java +++ b/flowable/src/main/java/com/sdm/flowable/delegate/handler/HpcHandler.java @@ -105,7 +105,7 @@ public class HpcHandler implements ExecutionHandler,HPCExecu if(!submitResp.isSuccess()|| StringUtils.isBlank(submitResp.getData())){ // 推送失败消息 sendMsg(ThreadLocalContext.getTenantId(),ThreadLocalContext.getUserId(),submitHpcTaskRemoteReq.getJobName(),"失败"); - log.error("HpcHandler submit failed,jobName:{}",params); + log.error("HpcHandler submit failed:{}",JSONObject.toJSONString(params)); throw new RuntimeException("HpcHandler submit failed,"+submitResp.getMessage()); } diff --git a/outbridge/src/main/java/com/sdm/outbridge/config/CommonConfig.java b/outbridge/src/main/java/com/sdm/outbridge/config/CommonConfig.java index fe7d40cc..71968877 100644 --- a/outbridge/src/main/java/com/sdm/outbridge/config/CommonConfig.java +++ b/outbridge/src/main/java/com/sdm/outbridge/config/CommonConfig.java @@ -1,13 +1,19 @@ package com.sdm.outbridge.config; //// common模块:com.xxx.common.config.CommonConfig +import com.sdm.common.utils.AESUtil; +import org.apache.commons.lang3.StringUtils; import org.springframework.boot.env.YamlPropertySourceLoader; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; +import org.springframework.core.env.EnumerablePropertySource; +import org.springframework.core.env.MapPropertySource; import org.springframework.core.io.support.DefaultPropertySourceFactory; import org.springframework.core.io.support.EncodedResource; import java.io.IOException; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * 加载common模块的自定义配置文件 @@ -25,7 +31,48 @@ public class CommonConfig { } List> sources = new YamlPropertySourceLoader() .load(resource.getResource().getFilename(), resource.getResource()); - return sources.get(0); + org.springframework.core.env.PropertySource originalSource = sources.get(0); + org.springframework.core.env.PropertySource decryptedSource = + decryptPropertySource(originalSource); + return decryptedSource; } } + + private static org.springframework.core.env.PropertySource decryptPropertySource(org.springframework.core.env.PropertySource source) { + // 只处理可枚举的属性源(yml加载后的源都是EnumerablePropertySource) + if (!(source instanceof EnumerablePropertySource)) { + return source; + } + + EnumerablePropertySource enumerableSource = (EnumerablePropertySource) source; + Map decryptedProperties = new HashMap<>(); + // 遍历所有配置项 + for (String propertyName : enumerableSource.getPropertyNames()) { + Object value = enumerableSource.getProperty(propertyName); + if (value != null && value instanceof String) { + String strValue = (String) value; + if (strValue.startsWith("ENC(") && strValue.endsWith(")")) { + // 解密并替换值 + String spdmEnkey = StringUtils.isBlank(System.getProperty("spdm.enkey"))? + System.getenv("spdm.enkey"):System.getProperty("spdm.enkey"); + String encryptedValue = strValue.substring(4, strValue.length() - 1); + try { + decryptedProperties.put(propertyName, AESUtil.decodeNew(encryptedValue, spdmEnkey)); + } catch (Exception e) { + System.out.println("利元亨现场配置解密异常:"+e.getMessage()); + throw new RuntimeException(e); + } + } else { + // 非加密值,直接保留 + decryptedProperties.put(propertyName, strValue); + } + } else { + // 非字符串类型,直接保留 + decryptedProperties.put(propertyName, value); + } + } + // 生成新的属性源(名称和原始源一致,确保覆盖) + return new MapPropertySource(source.getName(), decryptedProperties); + } + } \ No newline at end of file diff --git a/project/src/main/java/com/sdm/project/service/impl/SimulationRunServiceImpl.java b/project/src/main/java/com/sdm/project/service/impl/SimulationRunServiceImpl.java index 829d5deb..879b1496 100644 --- a/project/src/main/java/com/sdm/project/service/impl/SimulationRunServiceImpl.java +++ b/project/src/main/java/com/sdm/project/service/impl/SimulationRunServiceImpl.java @@ -12,12 +12,8 @@ import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.sdm.common.common.SdmResponse; import com.sdm.common.common.ThreadLocalContext; -import com.sdm.common.config.FlowableConfig; import com.sdm.common.entity.constants.NumberConstants; -import com.sdm.common.entity.enums.ApproveTypeEnum; -import com.sdm.common.entity.enums.DirTypeEnum; -import com.sdm.common.entity.enums.FileBizTypeEnum; -import com.sdm.common.entity.enums.NodeTypeEnum; +import com.sdm.common.entity.enums.*; import com.sdm.common.entity.flowable.dto.FlowElementDTO; import com.sdm.common.entity.flowable.dto.ProcessDefinitionDTO; import com.sdm.common.entity.req.capability.FlowNodeDto; @@ -60,7 +56,6 @@ import com.sdm.project.model.resp.KeyResultAndTaskInfoResp; import com.sdm.project.model.resp.RunVersionInfoResp; import com.sdm.project.model.vo.SpdmNodeVo; import com.sdm.common.entity.resp.project.SpdmTaskVo; -import com.sdm.project.model.vo.SpdmTaskMemberVo; import com.sdm.project.service.*; import jakarta.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; @@ -84,7 +79,6 @@ import java.nio.file.StandardCopyOption; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.*; -import java.util.function.UnaryOperator; import java.util.stream.Collectors; import static com.sdm.common.service.BaseService.generateUuid; @@ -629,7 +623,7 @@ public class SimulationRunServiceImpl extends ServiceImpl comparison >= 0; + case ">" -> comparison > 0; + case "<" -> comparison < 0; + case "≤" -> comparison <= 0; + default -> throw new IllegalArgumentException("无效运算符: " + method); + }; + simulationPerformance.setCompleteStatus(isPassed ? PerformanceStatusEnum.STARTED.getCode() : PerformanceStatusEnum.NOT_STARTED.getCode()); + } catch (Exception e) { + log.error("数字格式异常:", e); + return SdmResponse.failed("请输入有效的目标值和分析值"); + } + } return SdmResponse.success(this.updateById(simulationPerformance)); } + private boolean validateNumber(String input) { + String trimmed = input.trim(); + // 前置格式检查 - 验证是不是有效数字格式 + if (!CommonUtils.isValidNumberFormat(trimmed)) { + return false; + } + return true; + } + @Override public SdmResponse exportPerformance(PerformanceExportExcelFormat performanceExportExcelFormat, HttpServletResponse httpServletResponse) { SdmResponse response = new SdmResponse();