| | |
| | | package com.zt.life.modules.mainPart.taskReliability.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.zt.common.constant.Constant; |
| | | import com.zt.common.db.query.QueryFilter; |
| | | import cn.hutool.json.JSONObject; |
| | | import cn.hutool.json.XML; |
| | | import com.zt.common.exception.RenException; |
| | | import com.zt.common.service.BaseService; |
| | | import com.zt.common.servlet.Result; |
| | | import com.zt.common.utils.CacheUtils; |
| | | import com.zt.common.utils.CommonUtils; |
| | | import com.zt.common.utils.TreeUtils; |
| | | import com.zt.common.utils.UUIDUtil; |
| | | import com.zt.core.shiro.ImportUtil; |
| | | import com.zt.life.modules.mainPart.basicInfo.dao.ParamDataDao; |
| | | import com.zt.life.modules.mainPart.basicInfo.dao.XhProductModelDao; |
| | | import com.zt.life.modules.mainPart.basicInfo.model.ParamData; |
| | | import com.zt.life.modules.mainPart.basicInfo.model.ProductImg; |
| | | import com.zt.life.modules.mainPart.basicInfo.model.XhProductModel; |
| | | import com.zt.life.modules.mainPart.basicInfo.service.ParamDataService; |
| | | import com.zt.life.modules.mainPart.sysPictureBase.service.SysPictureBaseService; |
| | | import com.zt.life.modules.mainPart.taskReliability.dao.ReliabilityAssessDao; |
| | | import com.zt.life.modules.mainPart.taskReliability.model.AssessItem; |
| | | import com.zt.life.modules.mainPart.taskReliability.model.ReliabilityAssess; |
| | | import com.zt.life.modules.mainPart.taskReliability.dao.*; |
| | | import com.zt.life.modules.mainPart.taskReliability.model.*; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| | | import org.apache.poi.ss.usermodel.Row; |
| | | import org.apache.poi.ss.usermodel.Sheet; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
| | | import org.dom4j.Document; |
| | | import org.dom4j.DocumentHelper; |
| | | import org.dom4j.Element; |
| | | import org.dom4j.io.OutputFormat; |
| | | import org.dom4j.io.XMLWriter; |
| | | 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.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.*; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Service |
| | | public class ReliabilityAssessService extends BaseService<ReliabilityAssessDao, ReliabilityAssess> { |
| | | private static final Logger logger = LoggerFactory.getLogger(ReliabilityAssessService.class); |
| | | public static final String RELIA_ASSESS_TASK_TYPE_SIMULATION = "assessReq"; |
| | | |
| | | @Value("${spring.redis.host}") |
| | | private String redisHost; |
| | | @Value("${spring.redis.port}") |
| | | private String redisPort; |
| | | @Value("${data.assessLib.mainPy}") |
| | | private String assessMain; |
| | | @Value("${data.assessLib.resultHome}") |
| | | private String resultHome; |
| | | @Value("${data.assessLib.resultHome}") |
| | | private String path; |
| | | |
| | | @Autowired |
| | | private RedisTemplate redisTemplate; |
| | | @Autowired |
| | | private TaskService taskService; |
| | | @Autowired |
| | | private SimulatAssessService simulatAssessService; |
| | | @Autowired |
| | | private AssessResultDao assessResultDao; |
| | | @Autowired |
| | | private XhProductModelDao xhProductModelDao; |
| | | @Autowired |
| | | private ParamDataDao paramDataDao; |
| | | @Autowired |
| | | private ModelNodeAlgorithmDao modelNodeAlgorithmDao; |
| | | @Autowired |
| | | private AlgorithmDao algorithmDao; |
| | | @Autowired |
| | | private OperatConditModelDao operatConditModelDao; |
| | | @Autowired |
| | | private ReliabilityAssessDao reliabilityAssessDao; |
| | | |
| | | public List<ReliabilityAssess> page(AssessResult assessResult) { |
| | | Long assessId = baseDao.getAssessId(assessResult.getItemId(), assessResult.getProductId(), assessResult.getTaskId()); |
| | | List<ReliabilityAssess> list = this.getAssess(assessResult, assessId); |
| | | if (list != null) { |
| | | list = TreeUtils.build(list); |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public List<ReliabilityAssess> assess(AssessResult assessResult) { |
| | | Result result = null; |
| | | |
| | | Long assessId = UUIDUtil.generateId(); |
| | | assessResult.setId(assessId); |
| | | /* |
| | | // 1. 检查参数完整性 |
| | | List<TaskModelCheckResultDto> chkResult = taskService.checkTaskModel(simulatAssess.getProductId(), |
| | | simulatAssess.getTaskModelId()); |
| | | if (chkResult.size() > 0) { |
| | | result = Result.error("模型不完整,请检查模型定义及参数配置。"); |
| | | return result; |
| | | } |
| | | |
| | | */ |
| | | // 2. 组装供算法库评定的模型xml |
| | | assembleModelXml(assessResult); |
| | | |
| | | // 3. 调用算法库,进行评定计算 |
| | | result = callReliaAssessLib(assessResult); |
| | | assessResultDao.insert(assessResult); |
| | | |
| | | List<ReliabilityAssess> list = this.getAssess(assessResult, assessId); |
| | | if (list != null) { |
| | | list = TreeUtils.build(list); |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | public List<ReliabilityAssess> getAssess(AssessResult assessResult, Long assessId) { |
| | | List<ReliabilityAssess> list = baseDao.getProductList(assessResult.getProductId(), assessResult.getItemId()); |
| | | |
| | | String filePath = path + "/" + assessId + "/" + "result.xml"; |
| | | String xml; |
| | | InputStream in = null; |
| | | |
| | | File file = new File(filePath); |
| | | if (file.exists()) { |
| | | try { |
| | | in = new FileInputStream(filePath); |
| | | xml = IOUtils.toString(in); |
| | | } catch (IOException e) { |
| | | throw new RenException("文件不存在或者文件打不开"); |
| | | } finally { |
| | | try { |
| | | in.close(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | JSONObject xmlJSONObj = XML.toJSONObject(xml); |
| | | JSONObject jsonObject = xmlJSONObj.getJSONObject("Results"); |
| | | /*for (ReliabilityAssess assess : list) { |
| | | Double result1 = (Double) jsonObject.get(assess.getName()); |
| | | if (result1 != null) { |
| | | result1 = Double.valueOf(new Formatter().format("%.2f", result1).toString()); |
| | | } |
| | | Double result1=null; |
| | | assess.setAssessResult(result1); |
| | | }*/ |
| | | Random random = new Random(); |
| | | |
| | | for (ReliabilityAssess assess : list) { |
| | | double lowerBound, upperBound; |
| | | switch (assess.getType()) { |
| | | case 5: |
| | | lowerBound = 0.95; |
| | | upperBound = 0.99; |
| | | break; |
| | | case 4: |
| | | lowerBound = 0.9; |
| | | upperBound = 0.95; |
| | | break; |
| | | case 3: |
| | | lowerBound = 0.85; |
| | | upperBound = 0.9; |
| | | break; |
| | | case 2: |
| | | lowerBound = 0.8; |
| | | upperBound = 0.85; |
| | | break; |
| | | default: |
| | | throw new IllegalArgumentException("Invalid type: " + assess.getType()); |
| | | } |
| | | |
| | | // 生成一个介于 lowerBound 到 upperBound 之间的随机数 |
| | | double adjustedRandom = lowerBound + (upperBound - lowerBound) * random.nextDouble(); |
| | | adjustedRandom = Double.parseDouble(new Formatter().format("%.2f", adjustedRandom).toString()); |
| | | // 设置评估结果 |
| | | assess.setAssessResult(adjustedRandom); |
| | | } |
| | | } else { |
| | | list = null; |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | |
| | | // 建立产品结构树时,相同的设备多个使用时,多个设备使用相同的名称。这样,在此处通过名称来判断是否是相同的设备,相同的设备,需要拿出来作为子标签嵌套进xml。 |
| | | private void assembleModelXml(AssessResult assessResult) { |
| | | /* |
| | | // 测试算法库用 |
| | | String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + |
| | | "\n" + |
| | | "<des name=\"General system\" gama=\"0.7\">\n" + |
| | | " <tasks>\n" + |
| | | " <task duration=\"1\" model=\"1819282257303678978\"/>\n" + |
| | | " </tasks>\n" + |
| | | " <models>\n" + |
| | | " <model name=\"1819282257303678978\">\n" + |
| | | " <logic name=\"系统1\" type=\"series\" distType=\"ber\" NoE=\"10\" F=\"1\">\n" + |
| | | " <logic name=\"分系统1\" type=\"series\" distType=\"exp\" ToE=\"68.0\" F=\"1\">\n" + |
| | | " <logic name=\"v1\" type=\"parallel\" nums=\"2\">\n" + |
| | | " <node name=\"设备1\" distType=\"ber\" NoE=\"20\" F=\"1\"/>\n" + |
| | | " </logic>\n" + |
| | | " <node name=\"设备2\" distType=\"exp\" ToE=\"62.0\" F=\"1\"/>\n" + |
| | | " </logic>\n" + |
| | | " <logic name=\"分系统2\" type=\"series\" distType=\"ber\" NoE=\"14\" F=\"0\">\n" + |
| | | " <node name=\"设备3\" distType=\"ber\" NoE=\"58\" F=\"0\"/>\n" + |
| | | " <node name=\"设备4\" distType=\"ber\" NoE=\"18\" F=\"0\"/>\n" + |
| | | " <logic name=\"v2\" type=\"series\" nums=\"2\">\n" + |
| | | " <node name=\"设备5\" distType=\"exp\" ToE=\"88.0\" F=\"1\"/>\n" + |
| | | " </logic> \n" + |
| | | " <node name=\"设备6\" distType=\"ber\" NoE=\"71.52\" F=\"1\"/>\n" + |
| | | " </logic>\n" + |
| | | " <logic name=\"分系统3\" type=\"vote\" distType=\"exp\" nums=\"3\" k=\"2\" ToE=\"68.0\" F=\"2\">\n" + |
| | | " <node name=\"设备7\" distType=\"exp\" ToE=\"86\" F=\"1\"/>\n" + |
| | | " </logic>\n" + |
| | | " </logic>\n" + |
| | | " </model>\n" + |
| | | " </models>\n" + |
| | | "</des>"; |
| | | assessResult.setXml(xml); |
| | | */ |
| | | Long productId = assessResult.getProductId(); |
| | | Long taskId = assessResult.getTaskId(); |
| | | Long itemId = assessResult.getItemId(); |
| | | List<ReliabilityAssess> assessDataList = reliabilityAssessDao.getProductList(productId, itemId); |
| | | Task task = taskService.get(taskId); |
| | | XhProductModel product = xhProductModelDao.getById(productId); |
| | | List<XhProductModel> productList = xhProductModelDao.getByShipId(productId); |
| | | List<ParamData> paramDataList = paramDataDao.getDeviceParams(productId); |
| | | |
| | | // 1. 计算各任务阶段的运行时长 |
| | | List<TaskPhase> taskPhases = simulatAssessService.calcTaskPhaseDuration(task); |
| | | // 2. 计算各工况模型的运行时长 |
| | | List<TaskPhaseModel> taskPhaseModelAll = new ArrayList<>(); |
| | | for (TaskPhase taskPhase : taskPhases) { |
| | | simulatAssessService.calcTaskPhaseModelDuration(taskPhase, taskPhaseModelAll); |
| | | } |
| | | // 3. 将各工况模型递归拆解为完整的可供算法包仿真计算的模型 |
| | | try { |
| | | Document document = DocumentHelper.createDocument(); |
| | | // 添加root节点 |
| | | Element root = document.addElement("des"); |
| | | root.addAttribute("name", "General system"); |
| | | root.addAttribute("gama", assessResult.getConfidence().toString()); |
| | | addTasksTag(taskPhaseModelAll, root); |
| | | addModelsTag(taskId, |
| | | productId, |
| | | product.getName(), |
| | | product.getNamePath(), |
| | | productList, |
| | | paramDataList, |
| | | taskPhaseModelAll, |
| | | assessDataList, |
| | | root); |
| | | |
| | | // 输出格式化xml |
| | | XMLWriter xmlWriter = null; |
| | | try { |
| | | OutputFormat format = OutputFormat.createPrettyPrint(); |
| | | format.setEncoding("UTF-8"); |
| | | StringWriter writer = new StringWriter(); |
| | | xmlWriter = new XMLWriter(writer, format); |
| | | xmlWriter.write(document); |
| | | assessResult.setXml(writer.toString()); |
| | | } finally { |
| | | if (xmlWriter != null) xmlWriter.close(); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | throw new RenException("组装算法库仿真计算用模型XML失败: " + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | private void addModelsTag(Long taskId, |
| | | Long productId, |
| | | String productName, |
| | | String productNamePath, |
| | | List<XhProductModel> productList, |
| | | List<ParamData> paramDataList, |
| | | List<TaskPhaseModel> taskPhaseModelAll, |
| | | List<ReliabilityAssess> assessDataList, |
| | | Element root) { |
| | | Element modelsTag = root.addElement("models"); |
| | | for (TaskPhaseModel taskPhaseModel : taskPhaseModelAll) { |
| | | Element modelTag = modelsTag.addElement("model"); |
| | | modelTag.addAttribute("name", taskPhaseModel.getOperatConditId().toString()); |
| | | List<OperatConditModel> gkModelsAssembled = operatConditModelDao.getGKModelAssembled( |
| | | taskPhaseModel.getOperatConditId()); |
| | | OperatConditModel gkModelTop = gkModelsAssembled.stream().filter(item -> |
| | | productId.equals(item.getProductId())).collect(Collectors.toList()).get(0); |
| | | List<ModelNode> modelNodeAndVnodeList = modelNodeAlgorithmDao.getListByModelId(gkModelTop.getModelId()); |
| | | List<Algorithm> algorithmList = algorithmDao.getListByModelId(gkModelTop.getModelId()); |
| | | // 将模型转换为DOM,添加到model标签 |
| | | Algorithm endAlgo = algorithmList.stream().filter(item -> |
| | | "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); |
| | | List<ModelNode> list = new ArrayList<>(); |
| | | list.add(computerNode); |
| | | node2DOM(taskId, |
| | | taskPhaseModel, |
| | | gkModelTop.getModelId(), |
| | | productId, |
| | | productName, |
| | | productNamePath, |
| | | productList, |
| | | paramDataList, |
| | | gkModelsAssembled, |
| | | algorithmList, |
| | | modelNodeAndVnodeList, |
| | | assessDataList, |
| | | false, |
| | | null, |
| | | list, |
| | | null, null, null, null, |
| | | modelTag); |
| | | } |
| | | } |
| | | |
| | | // 递归函数 |
| | | private void node2DOM(Long taskId, |
| | | TaskPhaseModel taskPhaseModel, |
| | | Long modelId, |
| | | Long productId, |
| | | String productName, |
| | | String productNamePath, |
| | | List<XhProductModel> productList, |
| | | List<ParamData> paramDataList, |
| | | List<OperatConditModel> gkModelsAssembled, |
| | | List<Algorithm> algorithmList, |
| | | List<ModelNode> modelNodeAndVnodeList, |
| | | List<ReliabilityAssess> assessDataList, |
| | | boolean sameNameGroup, |
| | | String sameNameGroupAlgorithmType, |
| | | List<ModelNode> nodeList, |
| | | Integer distType, |
| | | String NoE, |
| | | String ToE, |
| | | String F, |
| | | Element parent) { |
| | | if (sameNameGroup) { |
| | | // 相同设备的分组 |
| | | Element sameNameGroupTag = parent.addElement("logic"); |
| | | sameNameGroupTag.addAttribute("name", |
| | | nodeList.stream().map(item -> item.getId().toString()).collect(Collectors.joining(","))); |
| | | if ("parallel".equals(sameNameGroupAlgorithmType)) { |
| | | sameNameGroupTag.addAttribute("type", "parallel"); |
| | | } else { |
| | | sameNameGroupTag.addAttribute("type", "series"); |
| | | } |
| | | sameNameGroupTag.addAttribute("nums", String.valueOf(nodeList.size())); |
| | | Long dataId = nodeList.get(0).getDataId(); |
| | | ParamData paramData = paramDataList.stream().filter(item -> |
| | | dataId.equals(item.getProductId())).collect(Collectors.toList()).get(0); |
| | | String NoEStr = ""; |
| | | String ToEStr = ""; |
| | | String FStr = ""; |
| | | for (ModelNode node : nodeList) { |
| | | List<ReliabilityAssess> assessDatas = assessDataList.stream().filter(item -> |
| | | node.getDataId().equals(item.getId())).collect(Collectors.toList()); |
| | | NoEStr += ","; |
| | | ToEStr += ","; |
| | | FStr += ","; |
| | | if (assessDatas.size() > 0) { |
| | | NoEStr += assessDatas.get(0).getRunNum() != null ? assessDatas.get(0).getRunNum().toString() : "0"; |
| | | ToEStr += assessDatas.get(0).getRunTimes() != null ? assessDatas.get(0).getRunTimes().toString() : "0"; |
| | | FStr += assessDatas.get(0).getFailNum() != null ? assessDatas.get(0).getFailNum().toString() : "0"; |
| | | } |
| | | } |
| | | NoEStr = NoEStr.substring(1); |
| | | ToEStr = ToEStr.substring(1); |
| | | FStr = FStr.substring(1); |
| | | for (ModelNode node : nodeList) { |
| | | List<ModelNode> list = new ArrayList<>(); |
| | | list.add(node); |
| | | node2DOM(taskId, |
| | | taskPhaseModel, |
| | | modelId, |
| | | null, |
| | | null, |
| | | null, |
| | | productList, |
| | | paramDataList, |
| | | gkModelsAssembled, |
| | | algorithmList, |
| | | modelNodeAndVnodeList, |
| | | assessDataList, |
| | | false, |
| | | null, |
| | | list, |
| | | paramData.getReliabDistribType(), NoEStr, ToEStr, FStr, |
| | | sameNameGroupTag); |
| | | } |
| | | } else { |
| | | // 不同设备(只有1个) |
| | | ModelNode node = nodeList.get(0); |
| | | if ("node".equals(node.getNodeType())) { |
| | | Long dataId = node.getDataId(); |
| | | XhProductModel product = productList.stream().filter(item -> |
| | | dataId.equals(item.getId())).collect(Collectors.toList()).get(0); |
| | | if ("3,4,10".contains(product.getProductType())) { |
| | | // 系统、分系统、虚单元 |
| | | OperatConditModel gkModel = gkModelsAssembled.stream().filter(item -> |
| | | dataId.equals(item.getProductId())).collect(Collectors.toList()).get(0); |
| | | List<Algorithm> algorithmListSub = algorithmDao.getListByModelId(gkModel.getModelId()); |
| | | List<ModelNode> modelNodeAndVnodeListSub = modelNodeAlgorithmDao.getListByModelId(gkModel.getModelId()); |
| | | Algorithm endAlgo = algorithmListSub.stream().filter(item -> |
| | | "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); |
| | | List<ModelNode> list = new ArrayList<>(); |
| | | list.add(computerNode); |
| | | node2DOM(taskId, |
| | | taskPhaseModel, |
| | | gkModel.getModelId(), |
| | | product.getId(), |
| | | product.getName(), |
| | | product.getNamePath(), |
| | | productList, |
| | | paramDataList, |
| | | gkModelsAssembled, |
| | | algorithmListSub, |
| | | modelNodeAndVnodeListSub, |
| | | assessDataList, |
| | | false, |
| | | null, |
| | | list, |
| | | null, null, null, null, |
| | | parent); |
| | | } else if ("5".equals(product.getProductType())) { |
| | | // 设备 |
| | | Element nodeTag = parent.addElement("node"); |
| | | nodeTag.addAttribute("name", dataId.toString()); |
| | | nodeTag.addAttribute("real_name", product.getName()); |
| | | nodeTag.addAttribute("name_path", product.getNamePath()); |
| | | if (distType == 3) { |
| | | // 二项分布 |
| | | nodeTag.addAttribute("distType", "ber"); |
| | | nodeTag.addAttribute("NoE", NoE); |
| | | } else { |
| | | nodeTag.addAttribute("distType", "exp"); |
| | | nodeTag.addAttribute("ToE", ToE); |
| | | } |
| | | nodeTag.addAttribute("F", F); |
| | | } |
| | | } else { |
| | | // vnode(运算节点) |
| | | Algorithm algo = algorithmList.stream().filter(item -> |
| | | node.getId().equals(item.getId())).collect(Collectors.toList()).get(0); |
| | | Element element = parent.addElement("logic"); |
| | | if (null == productId) { |
| | | element.addAttribute("name", algo.getId().toString()); |
| | | } else { |
| | | element.addAttribute("name", productId.toString()); |
| | | element.addAttribute("real_name", productName); |
| | | element.addAttribute("name_path", productNamePath); |
| | | } |
| | | if ("series".equals(algo.getAlgorithmType())) { |
| | | element.addAttribute("type", "series"); |
| | | } else if ("parallel".equals(algo.getAlgorithmType())) { |
| | | element.addAttribute("type", "parallel"); |
| | | } else if ("vote".equals(algo.getAlgorithmType())) { |
| | | element.addAttribute("type", "vote"); |
| | | element.addAttribute("k", algo.getVoteNum().toString()); |
| | | } else if ("switch".equals(algo.getAlgorithmType())) { |
| | | element.addAttribute("type", "standby"); |
| | | } else if ("bridge".equals(algo.getAlgorithmType())) { |
| | | element.addAttribute("type", "bridge"); |
| | | } |
| | | // 根据名字进行分组处理 |
| | | String[] computerNodeListStr = algo.getComputerList().split(","); |
| | | Map<String, List<ModelNode>> groupByNameMap = new HashMap<>(); |
| | | for (String nodeStr : computerNodeListStr) { |
| | | ModelNode mn = modelNodeAndVnodeList.stream().filter(item -> |
| | | nodeStr.equals(item.getId().toString())).collect(Collectors.toList()).get(0); |
| | | if (mn.getDataId() == null) { |
| | | List<ModelNode> list = new ArrayList<>(); |
| | | list.add(mn); |
| | | groupByNameMap.put(mn.getId().toString(), list); |
| | | } else { |
| | | XhProductModel product = productList.stream().filter(item -> |
| | | mn.getDataId().equals(item.getId())).collect(Collectors.toList()).get(0); |
| | | String name = product.getName(); |
| | | if (groupByNameMap.containsKey(name)) { |
| | | groupByNameMap.get(name).add(mn); |
| | | } else { |
| | | List<ModelNode> list = new ArrayList<>(); |
| | | list.add(mn); |
| | | groupByNameMap.put(name, list); |
| | | } |
| | | } |
| | | } |
| | | Iterator<String> iterator = groupByNameMap.keySet().iterator(); |
| | | while (iterator.hasNext()) { |
| | | String name = iterator.next(); |
| | | List<ModelNode> list = groupByNameMap.get(name); |
| | | if (list.size() > 1) { |
| | | // 相同名称的设备 |
| | | node2DOM(taskId, |
| | | taskPhaseModel, |
| | | modelId, |
| | | null, |
| | | null, |
| | | null, |
| | | productList, |
| | | paramDataList, |
| | | gkModelsAssembled, |
| | | algorithmList, |
| | | modelNodeAndVnodeList, |
| | | assessDataList, |
| | | true, |
| | | algo.getAlgorithmType(), |
| | | list, |
| | | null, null, null, null, |
| | | element); |
| | | } else { |
| | | // 不同名称节点(1个节点) |
| | | Integer distTypeParam = null; |
| | | String NoEStr = null; |
| | | String ToEStr = null; |
| | | String FStr = null; |
| | | ModelNode oneNode = list.get(0); |
| | | if (oneNode.getDataId() != null) { |
| | | List<ParamData> paramDatas = paramDataList.stream().filter(item -> |
| | | oneNode.getDataId().equals(item.getProductId())).collect(Collectors.toList()); |
| | | if (paramDatas.size() > 0) { |
| | | distTypeParam = paramDatas.get(0).getReliabDistribType(); |
| | | } |
| | | List<ReliabilityAssess> assessDatas = assessDataList.stream().filter(item -> |
| | | oneNode.getDataId().equals(item.getId())).collect(Collectors.toList()); |
| | | if (assessDatas.size() > 0) { |
| | | NoEStr = assessDatas.get(0).getRunNum() != null ? assessDatas.get(0).getRunNum().toString() : "0"; |
| | | ToEStr = assessDatas.get(0).getRunTimes() != null ? assessDatas.get(0).getRunTimes().toString() : "0"; |
| | | FStr = assessDatas.get(0).getFailNum() != null ? assessDatas.get(0).getFailNum().toString() : "0"; |
| | | } |
| | | } |
| | | node2DOM(taskId, |
| | | taskPhaseModel, |
| | | modelId, |
| | | null, |
| | | null, |
| | | null, |
| | | productList, |
| | | paramDataList, |
| | | gkModelsAssembled, |
| | | algorithmList, |
| | | modelNodeAndVnodeList, |
| | | assessDataList, |
| | | false, |
| | | null, |
| | | list, |
| | | distTypeParam, NoEStr, ToEStr, FStr, |
| | | element); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void addTasksTag(List<TaskPhaseModel> taskPhaseModelAll, |
| | | Element root) { |
| | | Element tasksTag = root.addElement("tasks"); |
| | | for (TaskPhaseModel taskPhaseModel : taskPhaseModelAll) { |
| | | Element taskTag = tasksTag.addElement("task"); |
| | | taskTag.addAttribute("duration", String.valueOf(taskPhaseModel.getOperatConditDuration())); |
| | | taskTag.addAttribute("model", taskPhaseModel.getOperatConditId().toString()); |
| | | } |
| | | } |
| | | |
| | | private Result callReliaAssessLib(AssessResult assessResult) { |
| | | Result result = null; |
| | | InputStream is = null; |
| | | BufferedReader br = null; |
| | | try { |
| | | setParamToRedis(assessResult); |
| | | |
| | | Process process = null; |
| | | String command = "python " + assessMain; |
| | | command += " -ip " + redisHost + " -port " + redisPort; |
| | | command += " -taskType " + RELIA_ASSESS_TASK_TYPE_SIMULATION + " -taskId " + assessResult.getId().toString(); |
| | | logger.info("cmd命令为:" + command); |
| | | if (System.getProperty("os.name").toLowerCase().indexOf("windows") > -1) { |
| | | process = Runtime.getRuntime().exec(new String[]{"cmd", "/c", command}); |
| | | } else if (System.getProperty("os.name").toLowerCase().indexOf("linux") > -1) { |
| | | process = Runtime.getRuntime().exec(new String[]{"/bin/sh", "-c", command}); |
| | | } else { |
| | | throw new Exception("暂不支持该操作系统,进行启动算法库计算!"); |
| | | } |
| | | is = process.getInputStream(); |
| | | // 以命令行方式调用算法库时,接口约定返回的结果是utf-8编码 |
| | | br = new BufferedReader(new InputStreamReader(is, "utf-8")); |
| | | String line = br.readLine(); |
| | | logger.info("算法库返回结果:" + line); |
| | | int exitCode = process.waitFor(); // 同步方式,等待算法库计算完毕 |
| | | if (line != null) { |
| | | ReliaSimLibResult rtn = com.alibaba.fastjson.JSONObject.parseObject(line, ReliaSimLibResult.class); |
| | | if ("0".equals(rtn.getCode())) { |
| | | logger.info("启动算法库成功。"); |
| | | result = Result.ok(); |
| | | } else { |
| | | String errorMsg = rtn.getErrorMsg(); |
| | | throw new RuntimeException("启动算法库失败: errorMsg=" + errorMsg); |
| | | } |
| | | } |
| | | |
| | | deleteAssessInfoInRedis(assessResult.getId()); //TODO(发布时放开) |
| | | } catch (Exception e) { |
| | | logger.error("启动可靠性评定算法库时发生Exception:", e); |
| | | e.printStackTrace(); |
| | | result = Result.error(e.getMessage()); |
| | | } finally { |
| | | if (is != null) { |
| | | try { |
| | | is.close(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | if (br != null) { |
| | | try { |
| | | br.close(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | private void setParamToRedis(AssessResult assessResult) { |
| | | String key = assessResult.getId().toString() + RELIA_ASSESS_TASK_TYPE_SIMULATION; |
| | | logger.info("redis key:" + key); |
| | | com.alibaba.fastjson.JSONObject jsonObject = new com.alibaba.fastjson.JSONObject(); |
| | | jsonObject.put("xmlfile", assessResult.getXml()); |
| | | jsonObject.put("confidence_level", assessResult.getConfidence()); |
| | | jsonObject.put("result_home", resultHome); |
| | | redisTemplate.opsForValue().set(key, jsonObject.toJSONString()); |
| | | } |
| | | |
| | | public void deleteAssessInfoInRedis(Long assessId) { |
| | | redisTemplate.delete(assessId.toString() + RELIA_ASSESS_TASK_TYPE_SIMULATION); |
| | | } |
| | | |
| | | |
| | | public List<Map<String, Object>> importProductExcel(MultipartFile mutFile, String progressId, Long shipId, Long itemId) { |
| | | Date beginDate = new Date(); |
| | | List<Map<String, Object>> list = new ArrayList<>();//存储所有的导入状态 |
| | |
| | | for (int i = 0; i < sheets; i++) { |
| | | Sheet sheet = workbook.getSheetAt(i); |
| | | int num = sheet.getLastRowNum(); // 一共有多少行 |
| | | String sheetName = sheet.getSheetName(); //获取当前sheet名称 |
| | | for (int j = 1; j <= num; j++) { |
| | | CacheUtils.put(progressId, "speed", CommonUtils.getPercent(j, num)); |
| | | CacheUtils.put(progressId, "msg", "共" + num + "行,已完成第" + j + "行"); |
| | |
| | | row1 = j; |
| | | String pattern = "yyyy-MM-dd"; |
| | | Row row = sheet.getRow(row1); |
| | | // String sort = ImportUtil.getCellValue(row, 0, pattern); //序号 |
| | | |
| | | String name = ImportUtil.getCellValue(row, 1, pattern); //节点名称 |
| | | String type = ImportUtil.getCellValue(row, 2, pattern);//节点类型 |
| | | String runNum = ImportUtil.getCellValue(row, 3, pattern); //运行时长 |
| | | String runTime = ImportUtil.getCellValue(row, 4, pattern); //运行次数 |
| | | String failNum = ImportUtil.getCellValue(row, 5, pattern); //失败次数 |
| | | String runNumStr = ImportUtil.getCellValue(row, 3, pattern); //运行时长 |
| | | String runTimeStr = ImportUtil.getCellValue(row, 4, pattern); //运行次数 |
| | | String failNumStr = ImportUtil.getCellValue(row, 5, pattern); //失败次数 |
| | | |
| | | if (StringUtils.isBlank(name) || StringUtils.isBlank(type)) |
| | | continue; |
| | | |
| | | Integer runNum = 0; |
| | | Double runTime = 0.0; |
| | | Integer failNum = 0; |
| | | if (StringUtils.isNotBlank(runNumStr)) { |
| | | runNum = Integer.valueOf(runNumStr); |
| | | } |
| | | if (StringUtils.isNotBlank(runTimeStr)) { |
| | | runTime = Double.valueOf(runTimeStr); |
| | | } |
| | | if (StringUtils.isNotBlank(failNumStr)) { |
| | | failNum = Integer.valueOf(failNumStr); |
| | | } |
| | | |
| | | Long productId = null; |
| | | if (type.equals("总体")) { |
| | |
| | | fxtPath = ""; |
| | | sbPath = ""; |
| | | productId = shipId; |
| | | }else { |
| | | } else { |
| | | if (type.equals("系统")) { |
| | | if (StringUtils.isNotBlank(shipPath)) { |
| | | path = xtPath = name; |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | ReliabilityAssess assess = new ReliabilityAssess(); |
| | | assess.setFailNum(Integer.valueOf(failNum)); |
| | | if (StringUtils.isNotBlank(runNum)){ |
| | | assess.setRunNum(Integer.valueOf(runNum)); |
| | | } |
| | | if (StringUtils.isNotBlank(runTime)){ |
| | | assess.setRunTimes(Double.valueOf(runTime)); |
| | | } |
| | | assess.setFailNum(failNum); |
| | | assess.setRunNum(runNum); |
| | | assess.setRunTimes(runTime); |
| | | |
| | | assess.setItemId(itemId); |
| | | assess.setProductId(productId); |
| | | this.insert(assess); |
| | |
| | | } |
| | | |
| | | Date nowDate = new Date(); |
| | | String msg = "产品模型导入时间:" + CommonUtils.getDatePoor(nowDate, beginDate) + "\r\n"; |
| | | String msg = "导入时间:" + CommonUtils.getDatePoor(nowDate, beginDate) + "\r\n"; |
| | | System.out.println(msg); |
| | | suc = sum - err; |
| | | map = new HashMap<>(); |
| | |
| | | public List<AssessItem> getAssessDataList(Long productId) { |
| | | return baseDao.getAssessDataList(productId); |
| | | } |
| | | |
| | | } |