| | |
| | | import cn.hutool.json.JSONArray; |
| | | import cn.hutool.json.JSONObject; |
| | | import cn.hutool.json.XML; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | 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.validator.AssertUtils; |
| | | import com.zt.common.validator.ValidatorUtils; |
| | | 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.dto.SimulaDataDto; |
| | | import com.zt.life.modules.mainPart.taskReliability.dto.ProductStatusDto; |
| | | import com.zt.life.modules.mainPart.taskReliability.dto.StatusDto; |
| | | import com.zt.life.modules.mainPart.taskReliability.model.CurveParam; |
| | | import com.zt.life.modules.mainPart.taskReliability.model.SimulatAssess; |
| | | import com.zt.life.modules.mainPart.taskReliability.model.Task; |
| | | import com.zt.life.modules.mainPart.taskReliability.service.SimulatAssessService; |
| | | import com.zt.life.modules.mainPart.taskReliability.service.TaskService; |
| | | 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.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import springfox.documentation.annotations.ApiIgnore; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | |
| | | /** |
| | |
| | | public class SimulatAssessController { |
| | | private static final Logger logger = LoggerFactory.getLogger(SimulatAssessController.class); |
| | | private static final String taskTypeProgress = "calcprog"; |
| | | private List<Map<String, Double>> dialgram = new ArrayList<>(); |
| | | |
| | | @Autowired |
| | | private RedisTemplate redisTemplate; |
| | |
| | | private SimulatAssessService simulatAssessService; |
| | | |
| | | private JSONObject xmlJSONObj; |
| | | |
| | | private JSONObject dialgramJson; |
| | | |
| | | /* @GetMapping("page") |
| | | @ApiOperation("分页") |
| | |
| | | |
| | | @GetMapping("getSimulatList") |
| | | @ApiOperation("信息") |
| | | public Result<List<SimulatAssess>> getSimulatList(Long productId,Long taskModelId) { |
| | | List<SimulatAssess> data = simulatAssessService.getList(productId,taskModelId); |
| | | public Result<List<SimulatAssess>> getSimulatList(Long productId, Long taskModelId) { |
| | | List<SimulatAssess> data = simulatAssessService.getList(productId, taskModelId); |
| | | |
| | | return Result.ok(data); |
| | | } |
| | | |
| | | @GetMapping("getSimulatParams") |
| | | @ApiOperation("信息") |
| | | public Result<SimulatAssess> getSimulatParams(Long id, Long taskModelId) { |
| | | SimulatAssess data = simulatAssessService.getParams(id, taskModelId); |
| | | |
| | | return Result.ok(data); |
| | | } |
| | |
| | | @PostMapping("analyze") |
| | | public Result<Long> analyze(@RequestBody SimulatAssess simulatAssess) { |
| | | //效验数据 |
| | | /* |
| | | ValidatorUtils.validateEntity(simulatAssess, AddGroup.class, DefaultGroup.class); |
| | | Long taskId = UUIDUtil.generateId(); |
| | | Integer time = simulatAssess.getSamplPeriod(); |
| | | Integer Frequency = simulatAssess.getSimulatFrequency(); |
| | | HashMap<String, Object> paramMap = new HashMap<>(); |
| | | paramMap.put("taskId", taskId); |
| | | paramMap.put("time", time); |
| | | 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); |
| | | // Result result = pythonLib.callPython(simulatAssess); |
| | | Result result = simulatAssessService.simulate(simulatAssess); |
| | | |
| | | return result; |
| | | } |
| | | |
| | | @PostMapping("getResultXML") |
| | | public Result<SimulaDataDto> getResultXML(@RequestBody SimulatAssess simulatAssess) { |
| | | if (simulatAssess.getDataType().equals("fz")){ |
| | | Integer num = simulatAssessService.getNumById(simulatAssess.getProductId(),simulatAssess.getTaskModelId()); |
| | | simulatAssess.setName("仿真记录" + (num+1)); |
| | | if (simulatAssess.getDataType().equals("fz")) { |
| | | Integer num = simulatAssessService.getNumById(simulatAssess.getProductId(), simulatAssess.getTaskModelId()); |
| | | simulatAssess.setName("仿真记录" + (num + 1)); |
| | | simulatAssessService.insert(simulatAssess); |
| | | } |
| | | String filePath = path + "/" + simulatAssess.getId() + "/" + "result.xml"; |
| | |
| | | return data; |
| | | } |
| | | |
| | | @GetMapping("getStatus") |
| | | public Result<List<ProductStatusDto>> getStatus(Long productId, Long taskId, Long fzId) { |
| | | String filePath = path + "/" + fzId + "/" + "status.json"; |
| | | ObjectMapper mapper = new ObjectMapper(); |
| | | String jsonStr = null; |
| | | try { |
| | | // 使用 ObjectMapper 的 readValue 方法,将文件中的 JSON 数据转换为一个 Java 对象 |
| | | // 这里使用 Object 类作为泛型参数,表示任意类型的对象 |
| | | Object obj = mapper.readValue(new File(filePath), Object.class); |
| | | // 使用 ObjectMapper 的 writeValueAsString 方法,将 Java 对象转换为 JSON 字符串 |
| | | jsonStr = mapper.writeValueAsString(obj); |
| | | |
| | | } catch (IOException e) { |
| | | // 处理异常 |
| | | e.printStackTrace(); |
| | | } |
| | | dialgramJson = new JSONObject(jsonStr); |
| | | List<ProductStatusDto> childList = this.getStatusData(productId, taskId); |
| | | return Result.ok(childList); |
| | | |
| | | } |
| | | |
| | | public List<ProductStatusDto> getStatusData(Long productId, Long taskId) { |
| | | List<ProductStatusDto> childList = simulatAssessService.getChildren(productId, taskId); |
| | | for (ProductStatusDto item : childList) { |
| | | if (dialgram.size() > 0) { |
| | | dialgram.clear(); |
| | | } |
| | | JSONArray jsonArray = dialgramJson.getJSONArray(String.valueOf(item.getId())); |
| | | if (jsonArray != null) { |
| | | this.processJSONArray(jsonArray, item); |
| | | } |
| | | } |
| | | return childList; |
| | | } |
| | | |
| | | public void processJSONArray(JSONArray jsonArray, ProductStatusDto productStatusDto) { |
| | | String status = null; |
| | | Double times = null; |
| | | for (int i = 0; i < jsonArray.size(); i++) { |
| | | Object item = jsonArray.get(i); |
| | | if (item instanceof JSONArray) { |
| | | processJSONArray((JSONArray) item, productStatusDto); // 递归调用 |
| | | } else { |
| | | if (item instanceof Double) { |
| | | times = (Double) item; |
| | | } else { |
| | | status = String.valueOf(item); |
| | | } |
| | | } |
| | | } |
| | | if (status != null || times != null) { |
| | | StatusDto statusDto =new StatusDto(); |
| | | statusDto.setTimes(times); |
| | | statusDto.setStatus(status); |
| | | productStatusDto.getStatusList().add(statusDto); |
| | | } |
| | | } |
| | | |
| | | @GetMapping("getCalcProgress") |
| | | public Result getCalcProgress(Long taskId) { |
| | | String key = taskId.toString() + taskTypeProgress; |
| | |
| | | return Result.ok(); |
| | | } |
| | | |
| | | |
| | | |
| | | } |