|  |  | 
 |  |  | import cn.hutool.json.XML; | 
 |  |  | import com.fasterxml.jackson.databind.ObjectMapper; | 
 |  |  | import com.spire.pdf.tables.table.convert.Convert; | 
 |  |  | import com.zt.common.db.query.QueryFilter; | 
 |  |  | import com.zt.common.exception.RenException; | 
 |  |  | import com.zt.common.service.BaseService; | 
 |  |  | import com.zt.common.servlet.Result; | 
 |  |  | 
 |  |  | import com.zt.life.modules.mainPart.taskReliability.dto.TaskPhaseConstraintDto; | 
 |  |  | import com.zt.life.modules.mainPart.taskReliability.model.*; | 
 |  |  | import com.zt.life.modules.mainPart.utils.GetStringSpace; | 
 |  |  | import com.zt.life.modules.mainPart.utils.OSUtils.ProcessUtils; | 
 |  |  | import io.swagger.models.auth.In; | 
 |  |  | import org.apache.commons.io.IOUtils; | 
 |  |  | import org.apache.commons.lang3.StringUtils; | 
 |  |  | 
 |  |  |     Map<Integer, String> templetsStrMap2 = new HashMap<>(); | 
 |  |  |  | 
 |  |  |     private JSONObject xmlJSONObj; | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 分页查询 | 
 |  |  | 
 |  |  |                         currentStatusDto.setX2(nextStatusDto.getX1()); | 
 |  |  |                         statusDtoListNew.add(new TimeDiagramStatusDto(nextStatusDto.getX1(), nextStatusDto.getX2(), nextStatusDto.getStatus())); | 
 |  |  |                     } else if (nextStatusDto.getX1() > currentStatusDto.getX1() && nextStatusDto.getX2() < currentStatusDto.getX2()) { | 
 |  |  |                         currentStatusDto.setX2(nextStatusDto.getX1()); | 
 |  |  |                         statusDtoListNew.add(new TimeDiagramStatusDto(nextStatusDto.getX1(), nextStatusDto.getX2(), nextStatusDto.getStatus())); | 
 |  |  |                         statusDtoListOld.add(new TimeDiagramStatusDto(nextStatusDto.getX2(), currentStatusDto.getX2(), currentStatusDto.getStatus())); | 
 |  |  |                         currentStatusDto.setX2(nextStatusDto.getX1()); | 
 |  |  |                     } | 
 |  |  |                 } else { | 
 |  |  |                     if (nextStatusDto.getX1() >= currentStatusDto.getX2()) { | 
 |  |  | 
 |  |  |                 this.processJSONArray(jsonArray, item, taskId); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         childList.removeIf(item -> item.getStatusList().size() == 0); | 
 |  |  |         return childList; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  | 
 |  |  |         return result; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  |     public Boolean simulate(SimulatAssess simulatAssess) { | 
 |  |  |         Boolean result = false; | 
 |  |  |         // 2. 组装供算法库仿真的模型xml | 
 |  |  | 
 |  |  |         result = callReliaSimLib(simulatAssess); | 
 |  |  |  | 
 |  |  |         return result; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public List<SimulatAssess> process(QueryFilter queryFilter) { | 
 |  |  |         List<SimulatAssess> page = baseDao.getProcessList(queryFilter.getParams()); | 
 |  |  |         return queryFilter.getPageList(page); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private Boolean callReliaSimLib(SimulatAssess simulatAssess) { | 
 |  |  | 
 |  |  |             } else { | 
 |  |  |                 throw new RenException("暂不支持该操作系统,进行启动算法库计算!"); | 
 |  |  |             } | 
 |  |  |             long pid = ProcessUtils.getProcessId(process); | 
 |  |  |             logger.info("算法库PID:" + pid); | 
 |  |  |             is = process.getInputStream(); | 
 |  |  |             // 以命令行方式调用算法库时,接口约定返回的结果是utf-8编码 | 
 |  |  |             br = new BufferedReader(new InputStreamReader(is, "utf-8")); | 
 |  |  | 
 |  |  |                 ReliaSimLibResult rtn = com.alibaba.fastjson.JSONObject.parseObject(line, ReliaSimLibResult.class); | 
 |  |  |                 if ("0".equals(rtn.getCode())) { | 
 |  |  |                     logger.info("启动可靠性仿真评估算法库成功。"); | 
 |  |  |                     newProcess(simulatAssess, pid, command); | 
 |  |  |                     update(simulatAssess); | 
 |  |  |                     result = true; | 
 |  |  |                 } else { | 
 |  |  |                     String errorMsg = rtn.getErrorMsg(); | 
 |  |  | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         return result; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     public void newProcess(SimulatAssess simulatAssess, long pid, String command) { | 
 |  |  |         simulatAssess.setPid(pid); | 
 |  |  |         simulatAssess.setCommandLine(command); | 
 |  |  |         simulatAssess.setProcessIsAlive(true); | 
 |  |  |         simulatAssess.setProcessStartTime(new Date()); | 
 |  |  |         simulatAssess.setProgress(0); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private void setParamToRedis(SimulatAssess simulatAssess) { | 
 |  |  | 
 |  |  |             Element root = document.addElement("des"); | 
 |  |  |             root.addAttribute("name", "General system"); | 
 |  |  |             addTasksTag(taskPhaseModelAll, root); | 
 |  |  |             addModelsTag(taskId, | 
 |  |  |             addModelsTag(simulatAssess, | 
 |  |  |                     taskId, | 
 |  |  |                     productId, | 
 |  |  |                     product.getName(), | 
 |  |  |                     product.getNamePath(), | 
 |  |  | 
 |  |  |                     ele = repairModelTag.addElement("shape"); | 
 |  |  |                     ele.addAttribute("value", String.valueOf(repairModel.getParam3())); | 
 |  |  |                     break; | 
 |  |  |                 case RepairModel.TYPE_DIRAC: | 
 |  |  |                     ele = repairModelTag.addElement("repair-time"); | 
 |  |  |                     ele.addAttribute("value", String.valueOf(repairModel.getParam1())); | 
 |  |  |                     break; | 
 |  |  |                 default: | 
 |  |  |                     break; | 
 |  |  |             } | 
 |  |  | 
 |  |  |         return taskPhases; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private void addModelsTag(Long taskId, | 
 |  |  |     private void addModelsTag(SimulatAssess simulatAssess, | 
 |  |  |                               Long taskId, | 
 |  |  |                               Long productId, | 
 |  |  |                               String productName, | 
 |  |  |                               String productNamePath, | 
 |  |  | 
 |  |  |                     "end".equals(item.getAlgorithmType())).collect(Collectors.toList()).get(0); | 
 |  |  |             ModelNode computerNode = modelNodeAndVnodeList.stream().filter(item -> | 
 |  |  |                     endAlgo.getComputerList().equals(item.getId().toString())).collect(Collectors.toList()).get(0); | 
 |  |  |             node2DOM(taskId, | 
 |  |  |             node2DOM(simulatAssess, | 
 |  |  |                     taskId, | 
 |  |  |                     taskPhaseModel, | 
 |  |  |                     gkModelTop.getModelId(), | 
 |  |  |                     productId, | 
 |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     // 递归函数 | 
 |  |  |     private void node2DOM(Long taskId, | 
 |  |  |     private void node2DOM(SimulatAssess simulatAssess, | 
 |  |  |                           Long taskId, | 
 |  |  |                           TaskPhaseModel taskPhaseModel, | 
 |  |  |                           Long modelId, | 
 |  |  |                           Long productId, | 
 |  |  | 
 |  |  |                         "end".equals(item.getAlgorithmType())).collect(Collectors.toList()).get(0); | 
 |  |  |                 ModelNode computerNode = modelNodeAndVnodeListSub.stream().filter(item -> | 
 |  |  |                         endAlgo.getComputerList().equals(item.getId().toString())).collect(Collectors.toList()).get(0); | 
 |  |  |                 node2DOM(taskId, | 
 |  |  |                 node2DOM(simulatAssess, | 
 |  |  |                         taskId, | 
 |  |  |                         taskPhaseModel, | 
 |  |  |                         gkModel.getModelId(), | 
 |  |  |                         product.getId(), | 
 |  |  | 
 |  |  |  | 
 |  |  |                 if (1 == paramData.getRepairable()) { | 
 |  |  |                     // 可维修 | 
 |  |  |                     RepairModel repairModel = createRepairModel(paramData); | 
 |  |  |                     RepairModel repairModel = null; | 
 |  |  |                     if (isRepairDirac(simulatAssess.getRepairDiracFlag(), taskPhaseModel, product.getId())) { | 
 |  |  |                         repairModel = createRepairModelDirac(0); | 
 |  |  |                     } else { | 
 |  |  |                         repairModel = createRepairModel(paramData); | 
 |  |  |                     } | 
 |  |  |                     repairModels.add(repairModel); | 
 |  |  |                     Element repairTag = nodeTag.addElement("repair_model"); | 
 |  |  |                     repairTag.addAttribute("name", repairModel.getId().toString()); | 
 |  |  | 
 |  |  |             for (String nodeStr : computerNodeListStr) { | 
 |  |  |                 ModelNode mn = modelNodeAndVnodeList.stream().filter(item -> | 
 |  |  |                         nodeStr.equals(item.getId().toString())).collect(Collectors.toList()).get(0); | 
 |  |  |                 node2DOM(taskId, | 
 |  |  |                 node2DOM(simulatAssess, | 
 |  |  |                         taskId, | 
 |  |  |                         taskPhaseModel, | 
 |  |  |                         modelId, | 
 |  |  |                         null, | 
 |  |  | 
 |  |  |         return failureModel; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private boolean isRepairDirac(Boolean repairDiracFlag, TaskPhaseModel taskPhaseModel, Long productId) { | 
 |  |  |         boolean result = false; | 
 |  |  |  | 
 |  |  |         if (repairDiracFlag != null && repairDiracFlag) { | 
 |  |  |             if (taskPhaseModel.getPhaseConstraints() == null) { | 
 |  |  |                 result = true; | 
 |  |  |             } else { | 
 |  |  |                 List<TaskPhaseConstraintDto> list = taskPhaseModel.getPhaseConstraints().stream().filter(item -> | 
 |  |  |                         productId.equals(item.getProductId())).collect(Collectors.toList()); | 
 |  |  |                 if (list.size() == 0) { | 
 |  |  |                     result = true; | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         return result; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private RepairModel createRepairModelDirac(double time) { | 
 |  |  |         RepairModel repairModel = new RepairModel(); | 
 |  |  |         repairModel.setId(UUIDUtil.generateId()); | 
 |  |  |         repairModel.setType(RepairModel.TYPE_DIRAC); | 
 |  |  |         repairModel.setParam1(0); | 
 |  |  |         return repairModel; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private RepairModel createRepairModel(ParamData paramData) { | 
 |  |  |         RepairModel repairModel = new RepairModel(); | 
 |  |  |         repairModel.setId(UUIDUtil.generateId()); | 
 |  |  |         switch (paramData.getRepairDistribType()) { | 
 |  |  |             case 1: | 
 |  |  |                 // 指数分布 | 
 |  |  |                 repairModel.setType(FailureModel.TYPE_EXP); | 
 |  |  |                 repairModel.setType(RepairModel.TYPE_EXP); | 
 |  |  |                 repairModel.setParam1(1.0 / paramData.getRepairMttcr()); | 
 |  |  |                 break; | 
 |  |  |             case 2: | 
 |  |  |                 // 威布尔分布 | 
 |  |  |                 repairModel.setType(FailureModel.TYPE_WBL); | 
 |  |  |                 repairModel.setType(RepairModel.TYPE_WBL); | 
 |  |  |                 repairModel.setParam2(paramData.getRepairMttcrOtherParams2()); | 
 |  |  |                 repairModel.setParam3(paramData.getRepairMttcrOtherParams3()); | 
 |  |  |                 break; | 
 |  |  |             case 3: | 
 |  |  |                 // 二项分布(维修没有) | 
 |  |  |                 break; | 
 |  |  |             default: | 
 |  |  |                 break; |