jinlin
2024-08-12 658f06778c80893e8618d62357cebf49aea9346e
modules/mainPart/src/main/java/com/zt/life/modules/mainPart/taskReliability/controller/SimulatAssessController.java
@@ -36,10 +36,7 @@
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;
import java.util.*;
/**
@@ -53,7 +50,6 @@
@Api(tags = "simulat_assess")
public class SimulatAssessController {
    private static final Logger logger = LoggerFactory.getLogger(SimulatAssessController.class);
    private static final String taskTypeProgress = "calcprog";
    @Autowired
    private RedisTemplate redisTemplate;
@@ -113,7 +109,8 @@
    @PostMapping("analyze")
    public Result<Long> analyze(@RequestBody SimulatAssess simulatAssess) {
        //效验数据
        Result result = pythonLib.callPython(simulatAssess);
//        Result result = pythonLib.callPython(simulatAssess);
        Result result = simulatAssessService.simulate(simulatAssess);
        return result;
    }
@@ -127,11 +124,18 @@
        }
        String filePath = path + "/" + simulatAssess.getId() + "/" + "result.xml";
        String xml = null;
        InputStream in =null;
        try {
            InputStream in = new FileInputStream(filePath);
            in = new FileInputStream(filePath);
            xml = IOUtils.toString(in);
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        xmlJSONObj = XML.toJSONObject(xml);
        simulatAssess.setShowProductId(simulatAssess.getProductId());
@@ -163,24 +167,35 @@
            if (nameValue instanceof Long) {
                productId = (Long) nameValue;
                if (productId.equals(simulatAssess.getShowProductId())) {
                    JSONArray jsonArray2 = jsonArray.getJSONObject(i).getJSONArray("phase");
                    Object object = jsonArray.getJSONObject(i).get("phase");
                    List<Double> doubleArray = new ArrayList<>();
                    String availability = null;
                    for (int j = 0; j < jsonArray2.size(); j++) {
                        if (availability != null) {
                            availability = availability + " " + jsonArray2.getJSONObject(j).get("availability");
                        } else {
                            availability = (String) jsonArray2.getJSONObject(j).get("availability");
                    if (object instanceof JSONArray) {
                        JSONArray jsonArray2 = jsonArray.getJSONObject(i).getJSONArray("phase");
                        for (int j = 0; j < jsonArray2.size(); j++) {
                            if (availability != null) {
                                availability = availability + " " + jsonArray2.getJSONObject(j).get("availability");
                            } else {
                                availability = (String) jsonArray2.getJSONObject(j).get("availability");
                            }
                        }
                    } else {
                        JSONObject jsonObject2 = jsonArray.getJSONObject(i).getJSONObject("phase");
                        availability = (String) jsonObject2.get("availability");
                    }
                    String[] arr = availability.split(" ");
                    // 遍历子字符串数组,将每个元素转换为double并存储到double数组中
                    for (int a = 0; a < arr.length; a++) {
                        doubleArray.add(Double.parseDouble(arr[a]));
                    }
                    param.setYData(doubleArray);
                    data.setMtbf((Double) jsonArray.getJSONObject(i).get("mttf"));
                    data.setMttr((Double) jsonArray.getJSONObject(i).get("mttr"));
                    Double mtbf = (Double) jsonArray.getJSONObject(i).get("mttf");
                    Double mttr = (Double) jsonArray.getJSONObject(i).get("mttr");
                    Double msr = (Double) jsonArray.getJSONObject(i).get("msr");
                    data.setMtbf(mtbf);
                    data.setMttr(mttr);
                    data.setMsr(msr);
                }
                data.setCurveParam(param);
            }
@@ -192,7 +207,7 @@
    @GetMapping("getStatus")
    public Result<String> getTimeDiagram(Long productId, Long taskId, Long fzId) {
        String data = simulatAssessService.getTimeDiagram(productId, taskId, fzId);
        return  Result.ok(data);
        return Result.ok(data);
    }
    @GetMapping("getDiagram")
@@ -221,9 +236,12 @@
    @GetMapping("getCalcProgress")
    public Result getCalcProgress(Long taskId) {
        String key = taskId.toString() + taskTypeProgress;
        String key = taskId.toString() + simulatAssessService.RELIA_SIM_TASK_TYPE_PROGRESS;
        String progress = (String) redisTemplate.opsForValue().get(key);
        if (progress == null) progress = "0";
        if(Objects.equals(progress, "100")){
            simulatAssessService.deleteSimInfoInRedis(taskId);
        }
        return Result.ok(progress);
    }