From 3cdad023eec111154857d3b7b0eb59336c6a3378 Mon Sep 17 00:00:00 2001 From: jinlin <jinlin> Date: 星期三, 24 七月 2024 14:38:07 +0800 Subject: [PATCH] 修改 --- modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/controller/SimulatAssessController.java | 62 +++++++++++++++++++++++------- 1 files changed, 47 insertions(+), 15 deletions(-) diff --git a/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/controller/SimulatAssessController.java b/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/controller/SimulatAssessController.java index 88d71d9..b12fc35 100644 --- a/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/controller/SimulatAssessController.java +++ b/modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/controller/SimulatAssessController.java @@ -1,32 +1,37 @@ package com.zt.life.modules.mainPart.taskReliability.controller; -import cn.hutool.http.HttpUtil; +import cn.hutool.json.JSONObject; +import cn.hutool.json.XML; import com.zt.common.annotation.LogOperation; import com.zt.common.constant.Constant; import com.zt.common.annotation.QueryParam; import com.zt.common.db.query.QueryFilter; import com.zt.common.servlet.Result; import com.zt.common.servlet.PageResult; -import com.zt.common.utils.UUIDUtil; +import com.zt.common.utils.JsonUtils; import com.zt.common.validator.AssertUtils; import com.zt.common.validator.ValidatorUtils; -import com.zt.common.validator.group.AddGroup; import com.zt.common.validator.group.DefaultGroup; import com.zt.common.validator.group.UpdateGroup; +import com.zt.life.modules.mainPart.async.PythonLib; import com.zt.life.modules.mainPart.taskReliability.model.SimulatAssess; import com.zt.life.modules.mainPart.taskReliability.service.SimulatAssessService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; +import org.apache.commons.io.IOUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.web.bind.annotation.*; import springfox.documentation.annotations.ApiIgnore; -import javax.servlet.http.HttpServletResponse; -import java.util.HashMap; -import java.util.List; +import java.io.IOException; +import java.io.InputStream; /** @@ -39,6 +44,18 @@ @RequestMapping("/taskReliability/SimulatAssess/") @Api(tags = "simulat_assess") public class SimulatAssessController { + private static final Logger logger = LoggerFactory.getLogger(SimulatAssessController.class); + private static final String taskTypeProgress = "calcreq"; + + @Autowired + private RedisTemplate redisTemplate; + + @Autowired + private PythonLib pythonLib; + + @Value("${data.reliaSimLib.resultHome}") + private String path; + @Autowired private SimulatAssessService simulatAssessService; @@ -66,6 +83,7 @@ @PostMapping("analyze") public Result<Long> analyze(@RequestBody SimulatAssess simulatAssess) { //鏁堥獙鏁版嵁 +/* ValidatorUtils.validateEntity(simulatAssess, AddGroup.class, DefaultGroup.class); Long taskId = UUIDUtil.generateId(); Integer time = simulatAssess.getSamplPeriod(); @@ -76,22 +94,36 @@ paramMap.put("Frequency", Frequency); paramMap.put("url", "http://localhost:8050/test-project//taskReliability/SimulatAssess/calculate"); String result1 = HttpUtil.get("http://localhost:8080/system/user/get", paramMap); +*/ + Result result = pythonLib.callPython(simulatAssess); - return Result.ok(taskId); + return result; } - @GetMapping("calculate") - public Result calculate(Long taskId, String List, String code, String errorMsg) { - SimulatAssess simulatAssess = new SimulatAssess(); - simulatAssess.setId(taskId); - simulatAssess.setCurveData(List); - simulatAssess.setCode(code); - simulatAssess.setErrorMsg(errorMsg); - simulatAssessService.insert(simulatAssess); + @GetMapping("getResultXML") + public Result getResultXML(Long taskId) { + String filePath = path + "/"+taskId+"/"+"result.xml"; + InputStream in = JsonUtils.class.getResourceAsStream(filePath); + String xml = null; + try { + xml = IOUtils.toString(in); + } catch (IOException e) { + e.printStackTrace(); + } + JSONObject xmlJSONObj = XML.toJSONObject(xml); + return Result.ok(); } + @GetMapping("getCalcProgress") + public String getCalcProgress(Long taskId) { + String key = taskId.toString() + taskTypeProgress; + String progress = (String)redisTemplate.opsForValue().get(key); + if (progress==null) progress = "0"; + return progress; + } + @PutMapping @ApiOperation("淇敼") @LogOperation("淇敼") -- Gitblit v1.9.1