From 5aaeebe0f1dbd9df48655ff5fce044908a824de5 Mon Sep 17 00:00:00 2001 From: daiqy88 Date: Fri, 31 Oct 2025 16:13:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ccag/service/impl/ProjectServiceImpl.java | 53 ++++++++++--------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/ccag-tvs-sim/ccag-tvs-sim-biz/src/main/java/com/ccag/service/impl/ProjectServiceImpl.java b/ccag-tvs-sim/ccag-tvs-sim-biz/src/main/java/com/ccag/service/impl/ProjectServiceImpl.java index c41edf9..3caf86b 100644 --- a/ccag-tvs-sim/ccag-tvs-sim-biz/src/main/java/com/ccag/service/impl/ProjectServiceImpl.java +++ b/ccag-tvs-sim/ccag-tvs-sim-biz/src/main/java/com/ccag/service/impl/ProjectServiceImpl.java @@ -10,6 +10,7 @@ import com.ccag.common.util.DateUtils; import com.ccag.config.TenantProperties; import com.ccag.dao.ProjectMapper; import com.ccag.dao.SystemMapper; +import com.ccag.entity.bo.system.office.OfficeProxy; import com.ccag.entity.bo.task.*; import com.ccag.entity.pojo.pbs.ProjectRunFile; import com.ccag.entity.pojo.project.*; @@ -512,32 +513,34 @@ public class ProjectServiceImpl implements ProjectService { return SdmResponse.success(); } List result = new ArrayList<>(); - int runningStatus = -1; - try { - log.info("开始同步执行脚本"); - Process process = Runtime.getRuntime().exec(commands); - log.info("准备获取脚本输出"); - if (req.getHasReturn() != null && req.getHasReturn() == 1) { - log.info("开始获取脚本输出"); - BufferedInputStream reader = new BufferedInputStream(process.getInputStream()); - byte[] line = new byte[1024]; - while (reader.read(line) > 0) { - log.info("executePython:" + line); - result.add(Arrays.toString(line)); - } - } - log.info("脚本执行完成"); - runningStatus = process.waitFor(); - log.info("脚本运行状态:" + runningStatus); - } catch (IOException | InterruptedException e) { - log.error("执行脚本失败:" + e); - return SdmResponse.failed("执行脚本失败:" + e); + String[] cmdParams = commands.split(" "); + if(cmdParams.length != 4) + { + return SdmResponse.failed("param size error"); } - if (runningStatus != 0) { - log.error(EXECUTE_SCRIPT_FAIL); - return SdmResponse.failed(EXECUTE_SCRIPT_FAIL); - } else { - log.info(commands + "执行脚本完成!"); + OfficeProxy officeProxy = new OfficeProxy(); + if(commands.contains("excelToJson.py")) //excel转为json库 + { + String excelPath = cmdParams[1]; + String dictPath = cmdParams[3]; + String jsonContents = officeProxy.excelToJson(excelPath,dictPath); + result.add(jsonContents); + } + else if(commands.contains("jsonToExcel.py"))//json库导出excel + { + String jsonPath = cmdParams[1]; + int type = Integer.parseInt(cmdParams[2]); + String dictPath = cmdParams[3]; + int index = dictPath.lastIndexOf(File.separator); + if(index > 0) { + String savePath = dictPath.substring(0, index); + String excelPath = savePath + File.separator + "分析项清单.xlsx"; + officeProxy.jsonToExcel(jsonPath, dictPath, excelPath, type); + result.add(excelPath); + } + else { + log.error("生成excel保存路径错误"); + } } return SdmResponse.success(result); }