This commit is contained in:
2026-01-23 17:52:02 +08:00
10 changed files with 188 additions and 17 deletions

View File

@@ -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);
}
};
}
}

View File

@@ -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;
}

View File

@@ -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+)?$");
}
}

View File

@@ -105,7 +105,7 @@ public class HpcHandler implements ExecutionHandler<Map<String, Object>,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());
}

View File

@@ -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<org.springframework.core.env.PropertySource<?>> 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<String, Object> 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);
}
}

View File

@@ -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<SimulationRunMapper, S
runPerformance.setId(null);
runPerformance.setRunId(simulationRun.getUuid());
runPerformance.setUuid(RandomUtil.generateString(32));
runPerformance.setCompleteStatus(RunPerformanceStatusEnum.UNCOMPLETED.getCode());
runPerformance.setCompleteStatus(PerformanceStatusEnum.UNCOMPLETED.getCode());
runPerformance.setCreator(userId);
runPerformance.setCreateTime(null);
runPerformanceList.add(runPerformance);

View File

@@ -43,7 +43,7 @@ import com.sdm.common.utils.SystemOperate;
import com.sdm.common.utils.excel.ExcelUtil;
import com.sdm.project.bo.ExportOperate;
import com.sdm.project.common.MemberTypeEnum;
import com.sdm.project.common.RunPerformanceStatusEnum;
import com.sdm.common.entity.enums.PerformanceStatusEnum;
import com.sdm.project.common.TaskExeStatusEnum;
import com.sdm.project.dao.SimulationDemandMapper;
import com.sdm.project.dao.SimulationNodeMapper;
@@ -2075,7 +2075,7 @@ public class TaskServiceImpl implements ITaskService {
CommonGetCompleteFromPerformanceVo commonGetCompleteFromPerformanceVo = new CommonGetCompleteFromPerformanceVo();
commonGetCompleteFromPerformanceVo.setNodeName(eachTaskVo.getDiscipline());
commonGetCompleteFromPerformanceVo.setCompleteStatus(StringUtils.isNotBlank(performanceNodePo.getCompleteStatus()) ?
performanceNodePo.getCompleteStatus() : RunPerformanceStatusEnum.UNCOMPLETED.getCode());
performanceNodePo.getCompleteStatus() : PerformanceStatusEnum.UNCOMPLETED.getCode());
commonCompleteStatisticsFromPerformance.add(commonGetCompleteFromPerformanceVo);
}
// 按tag分组统计指标状态
@@ -2154,7 +2154,7 @@ public class TaskServiceImpl implements ITaskService {
commonGetCompleteFromPerformanceVo.setTag(resultTagId);
commonGetCompleteFromPerformanceVo.setNodeName(nodeMap.get(resultTagIdArr[resultTagIdArr.length - 1]));
commonGetCompleteFromPerformanceVo.setCompleteStatus(StringUtils.isNotBlank(performanceNodePo.getCompleteStatus()) ?
performanceNodePo.getCompleteStatus() : RunPerformanceStatusEnum.UNCOMPLETED.getCode());
performanceNodePo.getCompleteStatus() : PerformanceStatusEnum.UNCOMPLETED.getCode());
commonCompleteStatisticsFromPerformance.add(commonGetCompleteFromPerformanceVo);
}
// 按tag分组统计指标状态

View File

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@@ -66,6 +67,9 @@ public class TaskPerformanceDto {
@Schema(description = "标准")
private String standard;
@Schema(description = "计算及结果值")
private String resultValue;
@Schema(description = "租户ID")
private String tenantId;

View File

@@ -80,7 +80,7 @@ public class SimulationPerformance implements Serializable {
@TableField("method")
private String method;
@ApiModelProperty(value = "指标完成情况 未完成 不合格 风险可控 未分析 合格")
@ApiModelProperty(value = "指标完成情况 未完成 不合格 风险可控 未分析 合格 ")
@TableField("completeStatus")
private String completeStatus;

View File

@@ -4,12 +4,14 @@ import com.alibaba.fastjson2.JSONArray;
import com.sdm.common.common.SdmResponse;
import com.sdm.common.entity.ExportExcelFormat;
import com.sdm.common.entity.enums.ApprovalFileDataStatusEnum;
import com.sdm.common.entity.enums.PerformanceStatusEnum;
import com.sdm.common.entity.req.data.KnowledgeExportExcelParam;
import com.sdm.common.entity.req.performance.PerformanceExportExcelFormat;
import com.sdm.common.entity.req.performance.PerformanceExportExcelParam;
import com.sdm.common.entity.resp.PageDataResp;
import com.sdm.common.entity.resp.task.PerformanceResp;
import com.sdm.common.service.BaseService;
import com.sdm.common.utils.CommonUtils;
import com.sdm.common.utils.RandomUtil;
import com.sdm.common.utils.excel.ExcelUtil;
import com.sdm.task.model.dto.TaskPerformanceDto;
@@ -31,7 +33,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
@@ -131,9 +135,48 @@ public class SimulationPerformanceServiceImpl extends ServiceImpl<SimulationPerf
public SdmResponse editPerformance(TaskPerformanceDto performanceDto) {
SimulationPerformance simulationPerformance = new SimulationPerformance();
BeanUtils.copyProperties(performanceDto, simulationPerformance);
// 目标值
String targetValueStr = simulationPerformance.getTargetValue();
// 分析值
String resultValueStr = simulationPerformance.getResultValue();
// 达标方式
String method = simulationPerformance.getMethod();
// 校验
if (StringUtils.isNotBlank(targetValueStr) && StringUtils.isNotBlank(resultValueStr)) {
if (!validateNumber(targetValueStr) || !validateNumber(resultValueStr)) {
return SdmResponse.failed("请输入有效的目标值和分析值");
}
try {
// 转换为BigDecimal自动处理整数和小数
BigDecimal targetValue = new BigDecimal(targetValueStr);
BigDecimal resultValue = new BigDecimal(resultValueStr);
int comparison = resultValue.compareTo(targetValue);
boolean isPassed = switch (method) {
case "" -> 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();