From 9ca3077fb0a9bb8354c29fa540576c09042c18bc Mon Sep 17 00:00:00 2001 From: yangyang Date: Thu, 5 Mar 2026 16:28:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Ahpc=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E9=85=8D=E7=BD=AE=E5=A2=9E=E5=8A=A0=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E7=9B=B8=E5=85=B3=E9=85=8D=E7=BD=AE=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../req/pbs/SimulationHpcCommandAllReq.java | 31 ++++ .../SimulationHpcCommandPlaceholderReq.java | 71 +++++++++ .../req/pbs/SimulationHpcCommandReq.java | 66 ++++++++ .../pbs/hpc/SimulationHpcCommandAllResp.java | 35 ++++ .../SimulationHpcCommandFeignClientImpl.java | 69 ++++++++ .../SimulationHpcCommandController.java | 110 +++++++++++++ .../pbs/service/impl/HpcCommandService.java | 150 ++++++++++++++++++ .../system/model/dto/HpcCommandConfigDto.java | 32 ++++ .../model/entity/AppCenterItemBean.java | 10 +- .../impl/SimulationAppCenterServiceImpl.java | 149 ++++++++++++++++- 10 files changed, 721 insertions(+), 2 deletions(-) create mode 100644 common/src/main/java/com/sdm/common/entity/req/pbs/SimulationHpcCommandAllReq.java create mode 100644 common/src/main/java/com/sdm/common/entity/req/pbs/SimulationHpcCommandPlaceholderReq.java create mode 100644 common/src/main/java/com/sdm/common/entity/req/pbs/SimulationHpcCommandReq.java create mode 100644 common/src/main/java/com/sdm/common/entity/resp/pbs/hpc/SimulationHpcCommandAllResp.java create mode 100644 common/src/main/java/com/sdm/common/feign/impl/pbs/SimulationHpcCommandFeignClientImpl.java create mode 100644 pbs/src/main/java/com/sdm/pbs/controller/SimulationHpcCommandController.java create mode 100644 pbs/src/main/java/com/sdm/pbs/service/impl/HpcCommandService.java create mode 100644 system/src/main/java/com/sdm/system/model/dto/HpcCommandConfigDto.java diff --git a/common/src/main/java/com/sdm/common/entity/req/pbs/SimulationHpcCommandAllReq.java b/common/src/main/java/com/sdm/common/entity/req/pbs/SimulationHpcCommandAllReq.java new file mode 100644 index 00000000..638c3238 --- /dev/null +++ b/common/src/main/java/com/sdm/common/entity/req/pbs/SimulationHpcCommandAllReq.java @@ -0,0 +1,31 @@ +package com.sdm.common.entity.req.pbs; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.util.List; + +/** + *

+ * 仿真软件命令配置表 + *

+ * + * @author author + * @since 2025-12-01 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@Schema(description = "仿真软件hpc命令配置远程请求") +public class SimulationHpcCommandAllReq implements Serializable { + + private static final long serialVersionUID = 1L; + + private SimulationHpcCommandReq commandReq; + + private List placeholderReqList; + +} \ No newline at end of file diff --git a/common/src/main/java/com/sdm/common/entity/req/pbs/SimulationHpcCommandPlaceholderReq.java b/common/src/main/java/com/sdm/common/entity/req/pbs/SimulationHpcCommandPlaceholderReq.java new file mode 100644 index 00000000..02f5a62a --- /dev/null +++ b/common/src/main/java/com/sdm/common/entity/req/pbs/SimulationHpcCommandPlaceholderReq.java @@ -0,0 +1,71 @@ +package com.sdm.common.entity.req.pbs; + + +import com.baomidou.mybatisplus.annotation.*; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonIgnore; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.time.LocalDateTime; + +/** + *

+ * 仿真工具命令占位符配置表 + *

+ * + * @author author + * @since 2025-12-01 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@Schema(description = "仿真工具hpc命令占位符配置表") +public class SimulationHpcCommandPlaceholderReq implements Serializable { + + private static final long serialVersionUID = 1L; + + @Schema(description = "自增主键") + private Long id; + + @Schema(description = "app注册的Id") + private String appUuid; + + @Schema(description = "占位符英文名称") + private String keyEnName; + + @Schema(description = "占位符中文名称") + private String keyCnName; + + @Schema(description = "占位符值的类型(file:共享云盘文件;input:用户自定义输入)") + private String valueType; + + @Schema(description = "是否展示(Y:是,N:否),N时必须填写默认值") + private String isDisplay; + + @Schema(description = "是否拼接(Y:是,N:否),N时不用拼接到命令") + private String featchType; + + @Schema(description = "默认值:valueType为file且isDisplay为N时必填") + private String defaultValue; + + @Schema(description = "文件正则表达式:valueType为file时必填,用于过滤对应的求解文件") + private String fileRegular; + + @Schema(description = "创建者ID") + private Long creatorId; + + @Schema(description = "创建时间") + private LocalDateTime createTime; + + @Schema(description = "更新者ID") + private Long updaterId; + + @Schema(description = "修改时间") + private LocalDateTime updateTime; + + +} \ No newline at end of file diff --git a/common/src/main/java/com/sdm/common/entity/req/pbs/SimulationHpcCommandReq.java b/common/src/main/java/com/sdm/common/entity/req/pbs/SimulationHpcCommandReq.java new file mode 100644 index 00000000..f085ef75 --- /dev/null +++ b/common/src/main/java/com/sdm/common/entity/req/pbs/SimulationHpcCommandReq.java @@ -0,0 +1,66 @@ +package com.sdm.common.entity.req.pbs; + +import com.baomidou.mybatisplus.annotation.*; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonIgnore; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.time.LocalDateTime; +import java.util.HashMap; +import java.util.Map; + +/** + *

+ * 仿真软件命令配置表 + *

+ * + * @author author + * @since 2025-12-01 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@Schema(description = "仿真软件hpc命令配置表") +public class SimulationHpcCommandReq implements Serializable { + + private static final long serialVersionUID = 1L; + + @Schema(description = "自增主键") + private Long id; + + @Schema(description = "app注册的Id") + private String appUuid; + + @Schema(description = "软件名称,对应的simulation_app_repository的appName,名字建议格式appName_v1") + private String softName; + + @Schema(description = "软件版本号") + private String softVersion; + + @Schema(description = "功能描述(如:电池仿真)") + private String functionDsc; + + @Schema(description = "功能对应的CMD命令") + private String command; + + @Schema(description = "预留-软件执行完成后筛选回传文件正则,用于过滤回传文件") + private String postFileRegular; + + @Schema(description = "创建者ID") + private Long creatorId; + + @Schema(description = "创建时间") + private LocalDateTime createTime; + + @Schema(description = "更新者ID") + private Long updaterId; + + @Schema(description = "修改时间") + private LocalDateTime updateTime; + + +} \ No newline at end of file diff --git a/common/src/main/java/com/sdm/common/entity/resp/pbs/hpc/SimulationHpcCommandAllResp.java b/common/src/main/java/com/sdm/common/entity/resp/pbs/hpc/SimulationHpcCommandAllResp.java new file mode 100644 index 00000000..1b72f6fd --- /dev/null +++ b/common/src/main/java/com/sdm/common/entity/resp/pbs/hpc/SimulationHpcCommandAllResp.java @@ -0,0 +1,35 @@ +package com.sdm.common.entity.resp.pbs.hpc; + +import com.sdm.common.entity.req.pbs.SimulationHpcCommandPlaceholderReq; +import com.sdm.common.entity.req.pbs.SimulationHpcCommandReq; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.util.List; + +/** + *

+ * 仿真软件命令配置表 + *

+ * + * @author author + * @since 2025-12-01 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@Schema(description = "仿真软件hpc命令配置远程请求") +public class SimulationHpcCommandAllResp implements Serializable { + + private static final long serialVersionUID = 1L; + + private String appUuid; + + private SimulationHpcCommandReq commandReq; + + private List placeholderReqList; + +} \ No newline at end of file diff --git a/common/src/main/java/com/sdm/common/feign/impl/pbs/SimulationHpcCommandFeignClientImpl.java b/common/src/main/java/com/sdm/common/feign/impl/pbs/SimulationHpcCommandFeignClientImpl.java new file mode 100644 index 00000000..64b18004 --- /dev/null +++ b/common/src/main/java/com/sdm/common/feign/impl/pbs/SimulationHpcCommandFeignClientImpl.java @@ -0,0 +1,69 @@ +package com.sdm.common.feign.impl.pbs; + +import com.sdm.common.common.SdmResponse; +import com.sdm.common.entity.req.pbs.SimulationHpcCommandAllReq; +import com.sdm.common.entity.resp.pbs.hpc.SimulationHpcCommandAllResp; +import com.sdm.common.feign.inter.pbs.ISimulationHpcCommandFeignClient; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Slf4j +@Component +public class SimulationHpcCommandFeignClientImpl implements ISimulationHpcCommandFeignClient { + + @Autowired + private ISimulationHpcCommandFeignClient simulationHpcCommandFeignClient; + + @Override + public SdmResponse hpcCommandSaveDb(SimulationHpcCommandAllReq req) { + SdmResponse response; + try { + response = simulationHpcCommandFeignClient.hpcCommandSaveDb(req); + return response; + } catch (Exception e) { + log.error("hpcCommandSaveDb Exception:{}", e.getMessage()); + return SdmResponse.failed("Hpc命令配置保存失败:"+e.getMessage()); + } + + } + + @Override + public SdmResponse hpcCommandUpdateDb(SimulationHpcCommandAllReq allReq) { + SdmResponse response; + try { + response = simulationHpcCommandFeignClient.hpcCommandUpdateDb(allReq); + return response; + } catch (Exception e) { + log.error("hpcCommandUpdateDb Exception:{}", e.getMessage()); + return SdmResponse.failed("Hpc命令配置修改失败:"+e.getMessage()); + } + } + + @Override + public SdmResponse deleteHpcCommandConfigs(String appId) { + SdmResponse response; + try { + response = simulationHpcCommandFeignClient.deleteHpcCommandConfigs(appId); + return response; + } catch (Exception e) { + log.error("deleteHpcCommandConfigs Exception:{}", e.getMessage()); + return SdmResponse.failed("Hpc命令配置删除失败:"+e.getMessage()); + } + } + + @Override + public SdmResponse> getHpcCommandConfigs(List hpcUuidList) { + SdmResponse> response; + try { + response = simulationHpcCommandFeignClient.getHpcCommandConfigs(hpcUuidList); + return response; + } catch (Exception e) { + log.error("getHpcCommandConfigs Exception:{}", e.getMessage()); + return SdmResponse.failed("Hpc命令配置查询失败:"+e.getMessage()); + } + } + +} diff --git a/pbs/src/main/java/com/sdm/pbs/controller/SimulationHpcCommandController.java b/pbs/src/main/java/com/sdm/pbs/controller/SimulationHpcCommandController.java new file mode 100644 index 00000000..389b8f82 --- /dev/null +++ b/pbs/src/main/java/com/sdm/pbs/controller/SimulationHpcCommandController.java @@ -0,0 +1,110 @@ +package com.sdm.pbs.controller; + +import com.sdm.common.common.SdmResponse; +import com.sdm.common.entity.req.pbs.SimulationHpcCommandAllReq; +import com.sdm.common.entity.req.pbs.SimulationHpcCommandPlaceholderReq; +import com.sdm.common.entity.req.pbs.SimulationHpcCommandReq; +import com.sdm.common.entity.resp.pbs.hpc.SimulationHpcCommandAllResp; +import com.sdm.common.feign.inter.pbs.ISimulationHpcCommandFeignClient; +import com.sdm.pbs.model.entity.SimulationHpcCommand; +import com.sdm.pbs.model.entity.SimulationHpcCommandPlaceholder; +import com.sdm.pbs.service.impl.HpcCommandService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.tuple.Pair; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@RestController +@RequestMapping("/pbs") +@Tag(name = "HPC命令配置", description = "HPC命令相关接口") +public class SimulationHpcCommandController implements ISimulationHpcCommandFeignClient { + + @Autowired + private HpcCommandService hpcCommandService; + + + @PostMapping("/hpcCommandSaveDb") + @Operation(summary = "hpc命令配置数据入库") + public SdmResponse hpcCommandSaveDb(@RequestBody SimulationHpcCommandAllReq req) { + Pair> pair = convertCommandAndPlaceholders(req); + try { + boolean b = hpcCommandService.hpcCommandSaveDb(pair.getLeft(), pair.getRight()); + if(b){ + return SdmResponse.success("数据保存成功"); + } + } catch (Exception e) { + log.error("hpcCommandSaveDb save error:{}", e.getMessage()); + } + return SdmResponse.failed("数据保存失败"); + } + + @PostMapping("/hpcCommandUpdateDb") + @Operation(summary = "hpc命令配置数据修改") + public SdmResponse hpcCommandUpdateDb(@RequestBody SimulationHpcCommandAllReq allReq) { + Pair> pair = convertCommandAndPlaceholders(allReq); + try { + boolean b = hpcCommandService.hpcCommandUpdateDb(pair.getLeft(), pair.getRight()); + if(b){ + return SdmResponse.success("数据修改成功"); + } + } catch (Exception e) { + log.error("hpcCommandUpdateDb update error:{}", e.getMessage()); + } + return SdmResponse.failed("数据修改失败"); + } + + @DeleteMapping("/deleteHpcCommandConfigs") + @Operation(summary = "hpc命令配置数据删除") + public SdmResponse deleteHpcCommandConfigs(@RequestParam String appId) { + try { + boolean b = hpcCommandService.deleteHpcCommandConfigs(appId); + if(b){ + return SdmResponse.success("数据删除成功"); + } + } catch (Exception e) { + log.error("deleteHpcCommandConfigs delete error:{}", e.getMessage()); + } + return SdmResponse.failed("数据删除失败"); + } + + @PostMapping("/getHpcCommandConfigs") + @Operation(summary = "hpc命令配置数据查询") + public SdmResponse> getHpcCommandConfigs(@RequestBody List hpcUuidList) { + Listreqs = hpcCommandService.getHpcCommandConfigs(hpcUuidList); + return SdmResponse.success(reqs); + } + + + /** + * 私有转换方法:返回 Pair<主命令, 占位符列表> + * left = SimulationHpcCommand + * right = List + */ + private Pair> convertCommandAndPlaceholders(SimulationHpcCommandAllReq req) { + // 1. 转换主命令 + SimulationHpcCommandReq commandReq = req.getCommandReq(); + SimulationHpcCommand hpcCommand = new SimulationHpcCommand(); + BeanUtils.copyProperties(commandReq, hpcCommand); + + // 2. 转换占位符列表 + List placeholderReqList = req.getPlaceholderReqList(); + List placeholders = new ArrayList<>(); + for (SimulationHpcCommandPlaceholderReq placeholderReq : placeholderReqList) { + SimulationHpcCommandPlaceholder placeholder = new SimulationHpcCommandPlaceholder(); + BeanUtils.copyProperties(placeholderReq, placeholder); + placeholders.add(placeholder); + } + + // 3. 封装成 Pair 返回 + return Pair.of(hpcCommand, placeholders); + } + + +} diff --git a/pbs/src/main/java/com/sdm/pbs/service/impl/HpcCommandService.java b/pbs/src/main/java/com/sdm/pbs/service/impl/HpcCommandService.java new file mode 100644 index 00000000..5f7ceaa8 --- /dev/null +++ b/pbs/src/main/java/com/sdm/pbs/service/impl/HpcCommandService.java @@ -0,0 +1,150 @@ +package com.sdm.pbs.service.impl; + +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.sdm.common.entity.req.pbs.SimulationHpcCommandPlaceholderReq; +import com.sdm.common.entity.req.pbs.SimulationHpcCommandReq; +import com.sdm.common.entity.resp.pbs.hpc.SimulationHpcCommandAllResp; +import com.sdm.pbs.model.entity.SimulationHpcCommand; +import com.sdm.pbs.model.entity.SimulationHpcCommandPlaceholder; +import com.sdm.pbs.service.ISimulationCommandPlaceholderService; +import com.sdm.pbs.service.ISimulationSoftConfigService; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; + +@Slf4j +@Service +public class HpcCommandService { + + @Autowired + private ISimulationSoftConfigService simulationSoftConfigService; + + @Autowired + private ISimulationCommandPlaceholderService simulationCommandPlaceholderService; + + @Transactional(rollbackFor = Exception.class) + public boolean hpcCommandSaveDb(SimulationHpcCommand hpcCommand, List placeholders) { + boolean save = simulationSoftConfigService.save(hpcCommand); + if(!save) {throw new RuntimeException("simulation_hpc_command save failed");} + if(CollectionUtils.isNotEmpty(placeholders)) { + boolean saves = simulationCommandPlaceholderService.saveBatch(placeholders); + if(!saves) {throw new RuntimeException("simulation_hpc_command_placeholder save failed");} + } + return true; + } + + @Transactional(rollbackFor = Exception.class) + public boolean hpcCommandUpdateDb(SimulationHpcCommand hpcCommand, List placeholders) { + String appUuid = hpcCommand.getAppUuid(); + // 先删除,然后再新增 + boolean b1 = simulationSoftConfigService.remove(Wrappers.lambdaQuery(SimulationHpcCommand.class).eq(SimulationHpcCommand::getAppUuid, appUuid)); + if(!b1) {throw new RuntimeException("simulation_hpc_command remove failed");} + boolean b2 = simulationCommandPlaceholderService.remove(Wrappers.lambdaQuery(SimulationHpcCommandPlaceholder.class).eq(SimulationHpcCommandPlaceholder::getAppUuid, appUuid)); + if(!b1) {throw new RuntimeException("simulation_hpc_command_placeholder remove failed");} + boolean save = simulationSoftConfigService.save(hpcCommand); + if(!save) {throw new RuntimeException("simulation_hpc_command save failed");} + if(CollectionUtils.isNotEmpty(placeholders)) { + boolean saves = simulationCommandPlaceholderService.saveBatch(placeholders); + if(!saves) {throw new RuntimeException("simulation_hpc_command_placeholder save failed");} + } + return true; + } + + @Transactional(rollbackFor = Exception.class) + public boolean deleteHpcCommandConfigs(String appUuid) { + // 先删除,然后再新增 + boolean b1 = simulationSoftConfigService.remove(Wrappers.lambdaQuery(SimulationHpcCommand.class).eq(SimulationHpcCommand::getAppUuid, appUuid)); + if(!b1) {throw new RuntimeException("deleteHpcCommandConfigs simulation_hpc_command remove failed");} + boolean b2 = simulationCommandPlaceholderService.remove(Wrappers.lambdaQuery(SimulationHpcCommandPlaceholder.class).eq(SimulationHpcCommandPlaceholder::getAppUuid, appUuid)); + if(!b1) {throw new RuntimeException("deleteHpcCommandConfigs simulation_hpc_command_placeholder remove failed");} + return true; + } + + /** + * 获取HPC命令配置(优化健壮性版本) + * @param hpcUuidList 应用UUID集合 + * @return 命令配置响应集合 + */ + public List getHpcCommandConfigs(List hpcUuidList) { + // 1. 入参判空:参数为null/空集合,直接返回空集合,避免后续查询报错 + if (CollectionUtils.isEmpty(hpcUuidList)) { + log.warn("getHpcCommandConfigs 入参hpcUuidList为空,直接返回空结果"); + return new ArrayList<>(); + } + + List results = new ArrayList<>(); + try { + // 2. 查询主命令配置,防止返回null,用空集合兜底 + List dbHpcCommands = simulationSoftConfigService.lambdaQuery() + .in(SimulationHpcCommand::getAppUuid, hpcUuidList) + .list(); + // 主数据为空,直接返回空结果 + if (CollectionUtils.isEmpty(dbHpcCommands)) { + log.info("getHpcCommandConfigs 根据hpcUuidList未查询到主命令配置数据"); + return results; + } + + // 3. 查询占位符配置,空集合兜底 + List placeholderList = simulationCommandPlaceholderService.lambdaQuery() + .in(SimulationHpcCommandPlaceholder::getAppUuid, hpcUuidList) + .list(); + + // 4. 分组转换:空集合分组后不会报错,无需额外判空 + Map> dbPlaceholderMap = + Optional.ofNullable(placeholderList) // 包裹,为null则空Optional + .orElseGet(ArrayList::new) // null → 空集合 + .stream() + .collect(Collectors.groupingBy(SimulationHpcCommandPlaceholder::getAppUuid)); + + // 5. 遍历组装结果 + for (SimulationHpcCommand dbHpcCommand : dbHpcCommands) { + // 防护:主数据对象为null时跳过 + if (dbHpcCommand == null) { + log.warn("遍历到空的SimulationHpcCommand对象,已跳过"); + continue; + } + + String appUuid = dbHpcCommand.getAppUuid(); + SimulationHpcCommandAllResp resp = new SimulationHpcCommandAllResp(); + resp.setAppUuid(appUuid); + + // 拷贝主命令属性 + SimulationHpcCommandReq commandReq = new SimulationHpcCommandReq(); + BeanUtils.copyProperties(dbHpcCommand, commandReq); + resp.setCommandReq(commandReq); + + // 6. Map取值判空,防止空指针遍历 + List placeholderListByApp = dbPlaceholderMap.getOrDefault(appUuid, new ArrayList<>()); + + // 7. Stream简化集合转换,自带空集合安全处理 + List placeholderReqList = placeholderListByApp.stream() + .map(placeholder -> { + SimulationHpcCommandPlaceholderReq req = new SimulationHpcCommandPlaceholderReq(); + BeanUtils.copyProperties(placeholder, req); + return req; + }) + .collect(Collectors.toList()); + resp.setPlaceholderReqList(placeholderReqList); + + results.add(resp); + } + + } catch (Exception e) { + // 8. 全局异常捕获,记录日志,避免服务崩溃 + log.error("getHpcCommandConfigs 查询HPC命令配置异常,入参:{}", hpcUuidList, e); + // 抛出业务异常/返回空集合,根据业务场景选择 + // throw new RuntimeException("查询HPC命令配置失败", e); + } + return results; + } + +} diff --git a/system/src/main/java/com/sdm/system/model/dto/HpcCommandConfigDto.java b/system/src/main/java/com/sdm/system/model/dto/HpcCommandConfigDto.java new file mode 100644 index 00000000..cc0992a5 --- /dev/null +++ b/system/src/main/java/com/sdm/system/model/dto/HpcCommandConfigDto.java @@ -0,0 +1,32 @@ +package com.sdm.system.model.dto; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Data +public class HpcCommandConfigDto { + + @Schema(description = "占位符英文名称") + private String keyEnName; + + @Schema(description = "占位符中文名称") + private String keyCnName; + + @Schema(description = "占位符值的类型(file:共享云盘文件;input:用户自定义输入)") + private String valueType; + + @Schema(description = "是否展示(Y:是,N:否),N时必须填写默认值") + @JsonIgnore + private String isDisplay; + + @Schema(description = "是否拼接(Y:是,N:否),N时不用拼接到命令") + private String featchType; + + @Schema(description = "默认值:valueType为file且isDisplay为N时必填") + private String defaultValue; + + @Schema(description = "文件正则表达式:valueType为file时必填,用于过滤对应的求解文件") + private String fileRegular; + +} diff --git a/system/src/main/java/com/sdm/system/model/entity/AppCenterItemBean.java b/system/src/main/java/com/sdm/system/model/entity/AppCenterItemBean.java index ad635167..0ac9b4a2 100644 --- a/system/src/main/java/com/sdm/system/model/entity/AppCenterItemBean.java +++ b/system/src/main/java/com/sdm/system/model/entity/AppCenterItemBean.java @@ -1,7 +1,9 @@ package com.sdm.system.model.entity; import com.sdm.common.entity.bo.BaseBean; -import lombok.Data; +import com.sdm.system.model.dto.HpcCommandConfigDto; + +import java.util.List; /** * 应用中心具体应用 @@ -41,4 +43,10 @@ public class AppCenterItemBean extends BaseBean { public String creatorName; public String createTime; // 应用创建时间 + + public String hpcCommand;// hpc动态的命令 + + public List commandConfigs; // hpc求解器命令的动态配置参数 + + } diff --git a/system/src/main/java/com/sdm/system/service/impl/SimulationAppCenterServiceImpl.java b/system/src/main/java/com/sdm/system/service/impl/SimulationAppCenterServiceImpl.java index 3b2c2f91..cce0235f 100644 --- a/system/src/main/java/com/sdm/system/service/impl/SimulationAppCenterServiceImpl.java +++ b/system/src/main/java/com/sdm/system/service/impl/SimulationAppCenterServiceImpl.java @@ -3,23 +3,35 @@ package com.sdm.system.service.impl; import com.sdm.common.common.SdmResponse; import com.sdm.common.common.ThreadLocalContext; import com.sdm.common.entity.bo.DataPageInfo; +import com.sdm.common.entity.req.pbs.SimulationHpcCommandAllReq; +import com.sdm.common.entity.req.pbs.SimulationHpcCommandPlaceholderReq; +import com.sdm.common.entity.req.pbs.SimulationHpcCommandReq; import com.sdm.common.entity.req.system.UserQueryReq; +import com.sdm.common.entity.resp.pbs.hpc.SimulationHpcCommandAllResp; import com.sdm.common.entity.resp.system.CIDUserResp; +import com.sdm.common.feign.inter.pbs.ISimulationHpcCommandFeignClient; import com.sdm.common.feign.inter.system.ISysUserFeignClient; import com.sdm.common.service.BaseService; import com.sdm.system.dao.SimulationAppManageMapper; +import com.sdm.system.model.dto.HpcCommandConfigDto; import com.sdm.system.model.entity.AppCenterItemBean; import com.sdm.system.model.entity.AppConfigureBean; import com.sdm.system.model.entity.AppItemStatisticInfo; import com.sdm.system.service.ISimulatinoAppCenterService; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; @Slf4j @Service @@ -30,6 +42,15 @@ public class SimulationAppCenterServiceImpl extends BaseService implements ISimu @Autowired private ISysUserFeignClient sysUserFeignClient; + @Value("#{'${app.needSaveHpcTypes:3,5}'.split(',')}") + private List needSaveHpcTypes; + + @Value("${hpcConfig.button:false}") + private boolean hpcConfigButton; + + @Autowired + private ISimulationHpcCommandFeignClient simulationHpcCommandFeignClient; + /** * 判定是否有重名应用 * @param appBean @@ -50,6 +71,7 @@ public class SimulationAppCenterServiceImpl extends BaseService implements ISimu * @return */ @Override + @Transactional(rollbackFor = Exception.class) public SdmResponse addSimulationApp(AppCenterItemBean appBean) { SdmResponse response = SdmResponse.success(); @@ -65,15 +87,24 @@ public class SimulationAppCenterServiceImpl extends BaseService implements ISimu { response = SdmResponse.failed("添加应用失败"); } + // 升级开关打开 && 处理hpc动态命令配置参数,3 hpc 5 openpbs + if(hpcConfigButton && needSaveHpcTypes.contains(appBean.appType)){ + if(StringUtils.isBlank(appBean.hpcCommand)){ + throw new RuntimeException("HPC命令不能为空"); + } + insertOrUpdateHpcCommandConfigs(appBean,false); + } return response; } + /** * 修改应用 * @param appBean * @return */ @Override + @Transactional(rollbackFor = Exception.class) public SdmResponse updateSimulationApp(AppCenterItemBean appBean) { SdmResponse response = SdmResponse.success(); String queryCondition = " uuid='"+appBean.uuid+"'"; @@ -95,24 +126,43 @@ public class SimulationAppCenterServiceImpl extends BaseService implements ISimu response = SdmResponse.failed("修改应用失败"); } } + // hpc的应用数据修改 + if(hpcConfigButton && needSaveHpcTypes.contains(appBean.appType)){ + if(StringUtils.isBlank(appBean.hpcCommand)){ + throw new RuntimeException("HPC命令不能为空"); + } + insertOrUpdateHpcCommandConfigs(appBean,true); + } return response; } + + /** * 删除应用 * @param appId * @return */ @Override + @Transactional(rollbackFor = Exception.class) public SdmResponse deleteSimulationApp(String appId) { SdmResponse response = SdmResponse.success(); - if(appManageMapper.deleteSimulationApp(appId) <= 0) + String queryCondition = " uuid='"+appId+"'"; + List appList = appManageMapper.querySimulationAppByCondition(queryCondition); + if(CollectionUtils.isEmpty(appList) ||appManageMapper.deleteSimulationApp(appId) <= 0) { response = SdmResponse.failed("删除应用失败"); } + // hpc的应用数据删除 + int appType = appList.get(0).appType; + if(hpcConfigButton && needSaveHpcTypes.contains(appType)){ + deleteHpcCommandConfigs(appId); + } return response; } + + /** * 查询系统所有应用 * @return @@ -133,12 +183,19 @@ public class SimulationAppCenterServiceImpl extends BaseService implements ISimu UserQueryReq req = new UserQueryReq(); List userIds = new ArrayList<>(); req.setTenantId(ThreadLocalContext.getTenantId()); + // 处理hpc类应用的配置数据 + // 筛选并提取 uuid 集合 + List hpcUuidList = new ArrayList<>(); for(AppCenterItemBean appBean : appBeans) { userIds.add(appBean.creator); + if( needSaveHpcTypes.contains(appBean.appType)){ + hpcUuidList.add(appBean.uuid); + } } req.setUserIds(userIds); SdmResponse> userResp = sysUserFeignClient.listUserByIds(req); + SdmResponse> hpcCommandResp = simulationHpcCommandFeignClient.getHpcCommandConfigs(hpcUuidList); if(userResp.isSuccess()) { List cidUsers = userResp.getData(); @@ -154,6 +211,10 @@ public class SimulationAppCenterServiceImpl extends BaseService implements ISimu { appBean.creatorName = user.getUsername(); } + // 处理hpc 配置 + if(hpcCommandResp.isSuccess()&&needSaveHpcTypes.contains(appBean.appType)){ + dealHpcConfig(appBean,hpcCommandResp); + } } } @@ -166,6 +227,36 @@ public class SimulationAppCenterServiceImpl extends BaseService implements ISimu return response; } + // hpc类型的应用的配置 + private void dealHpcConfig(AppCenterItemBean appBean, SdmResponse> hpcCommandResp) { + String uuid = appBean.uuid; + List data = hpcCommandResp.getData(); + Map> remoteMap = data.stream() + .collect(Collectors.groupingBy(SimulationHpcCommandAllResp::getAppUuid)); + // 对应uuid + if(remoteMap.containsKey(uuid)){ + log.info("dealHpcConfig data size:{}",remoteMap.size()); + SimulationHpcCommandAllResp resp = remoteMap.get(uuid).get(0); + SimulationHpcCommandReq remoteCommandReq = resp.getCommandReq(); + List remotePlaceholderReqList = resp.getPlaceholderReqList(); + // hpc的命令 + appBean.hpcCommand=remoteCommandReq.getCommand(); + List commandConfigs = new ArrayList<>(); + for(SimulationHpcCommandPlaceholderReq remote : remotePlaceholderReqList){ + HpcCommandConfigDto dto = new HpcCommandConfigDto(); + dto.setKeyEnName(remote.getKeyEnName()); + dto.setKeyCnName(remote.getKeyCnName()); + dto.setValueType(remote.getValueType()); + dto.setIsDisplay(remote.getIsDisplay()); + dto.setFeatchType(remote.getFeatchType()); + dto.setDefaultValue(remote.getDefaultValue()); + dto.setFileRegular(remote.getFileRegular()); + commandConfigs.add(dto); + } + appBean.commandConfigs = commandConfigs; + } + } + /** * 通过类型查询应用 * @param type @@ -336,4 +427,60 @@ public class SimulationAppCenterServiceImpl extends BaseService implements ISimu response.setData(count); return response; } + + private void insertOrUpdateHpcCommandConfigs(AppCenterItemBean appBean,boolean isUpdate) { + List commandConfigs = appBean.commandConfigs; + // simulation_hpc_command + SimulationHpcCommandReq simulationHpcCommandReq = new SimulationHpcCommandReq(); + simulationHpcCommandReq.setAppUuid(appBean.uuid) + .setSoftName(appBean.appName) + .setSoftVersion(appBean.appVersion) + .setFunctionDsc(appBean.comment) + .setCommand(appBean.hpcCommand) + .setCreatorId(ThreadLocalContext.getUserId()) + .setCreateTime(LocalDateTime.now()) + .setUpdaterId(ThreadLocalContext.getUserId()) + .setUpdateTime(LocalDateTime.now()); + // SimulationHpcCommandPlaceholderReq + List placeholderReqs = new ArrayList<>(); + for (HpcCommandConfigDto dto : commandConfigs) { + SimulationHpcCommandPlaceholderReq placeholderReq = new SimulationHpcCommandPlaceholderReq(); + placeholderReq.setAppUuid(appBean.uuid) + .setKeyEnName(dto.getKeyEnName()) + .setKeyCnName(dto.getKeyCnName()) + // 暂时不用这个字段的值 + .setValueType("input") + .setIsDisplay(dto.getIsDisplay()) + .setFeatchType(dto.getFeatchType()) + .setDefaultValue(dto.getDefaultValue()) + // 预留字段,主文件的正则 + .setFileRegular(null) + .setCreatorId(ThreadLocalContext.getUserId()) + .setCreateTime(LocalDateTime.now()) + .setUpdaterId(ThreadLocalContext.getUserId()) + .setUpdateTime(LocalDateTime.now()); + placeholderReqs.add(placeholderReq); + } + SimulationHpcCommandAllReq allReq = new SimulationHpcCommandAllReq(); + allReq.setCommandReq(simulationHpcCommandReq); + allReq.setPlaceholderReqList(placeholderReqs); + SdmResponse opResponse = SdmResponse.failed(); + if(isUpdate){ + opResponse = simulationHpcCommandFeignClient.hpcCommandUpdateDb(allReq); + }else { + opResponse = simulationHpcCommandFeignClient.hpcCommandSaveDb(allReq); + } + if (!opResponse.isSuccess()){ + throw new RuntimeException("操作配置命令失败"); + } + } + + private void deleteHpcCommandConfigs(String appId) { + SdmResponse opResponse = simulationHpcCommandFeignClient.deleteHpcCommandConfigs(appId); + if (!opResponse.isSuccess()){ + throw new RuntimeException("删除配置命令失败"); + } + } + + }