| | |
| | | import cn.hutool.json.XML; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import com.zt.common.annotation.LogOperation; |
| | | import com.zt.common.annotation.QueryParam; |
| | | import com.zt.common.constant.Constant; |
| | | import com.zt.common.db.query.QueryFilter; |
| | | import com.zt.common.exception.RenException; |
| | | import com.zt.common.servlet.PageResult; |
| | | import com.zt.common.servlet.Result; |
| | | import com.zt.common.validator.AssertUtils; |
| | | import com.zt.common.validator.ValidatorUtils; |
| | |
| | | import com.zt.life.modules.mainPart.taskReliability.model.*; |
| | | import com.zt.life.modules.mainPart.taskReliability.service.SimulatAssessService; |
| | | import com.zt.life.modules.mainPart.taskReliability.service.TaskService; |
| | | import com.zt.life.modules.mainPart.utils.OSUtils.ProcessUtils; |
| | | 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.apache.commons.lang3.StringUtils; |
| | |
| | | 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; |
| | |
| | | if (result2) |
| | | return Result.ok(); |
| | | else |
| | | return Result.error(); |
| | | return Result.error("算法库计算失败!"); |
| | | } |
| | | |
| | | @GetMapping("process") |
| | | @ApiOperation("获取算法库进程信息") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = Constant.Q.PAGE, value = Constant.QV.PAGE, required = true, dataType = Constant.QT.INT), |
| | | @ApiImplicitParam(name = Constant.Q.LIMIT, value = Constant.QV.LIMIT, required = true, dataType = Constant.QT.INT), |
| | | @ApiImplicitParam(name = "isAlive", value = "存活", dataType = Constant.QT.Boolean), |
| | | }) |
| | | public PageResult<SimulatAssess> process(@ApiIgnore @QueryParam QueryFilter queryFilter) { |
| | | List<SimulatAssess> page = simulatAssessService.process(queryFilter); |
| | | return PageResult.ok(page); |
| | | } |
| | | |
| | | |
| | | @PostMapping("getResultXML") |
| | | public Result<SimulaDataDto> getResultXML(@RequestBody SimulatAssess simulatAssess) { |
| | |
| | | String progress2 = ""; |
| | | String key = null; |
| | | if (taskList.length == 1) { |
| | | key = taskList[0].toString() + simulatAssessService.RELIA_SIM_TASK_TYPE_PROGRESS; |
| | | Long taskId = taskList[0]; |
| | | SimulatAssess simulatAssess = simulatAssessService.get(taskId); |
| | | boolean isProcessAlive = ProcessUtils.isProcessAlive(simulatAssess.getPid()); |
| | | key = taskId.toString() + simulatAssessService.RELIA_SIM_TASK_TYPE_PROGRESS; |
| | | progress2 = (String) redisTemplate.opsForValue().get(key); |
| | | if (progress2 == null) progress2 = "0"; |
| | | progress = Integer.parseInt(progress2); |
| | | if (progress == null) progress = 0; |
| | | updateSimulateAssess(simulatAssess, isProcessAlive, progress); |
| | | if (progress < 100 && !isProcessAlive) { |
| | | logger.error("算法库进程在计算途中异常终止了:taskId="+taskId+" pid="+simulatAssess.getPid()+" progress="+progress); |
| | | simulatAssessService.deleteSimInfoInRedis(taskId); |
| | | return Result.error("算法库进程在计算途中异常终止了!"); |
| | | } |
| | | if (progress == 100) { |
| | | try { |
| | | Thread.sleep(1000); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | isProcessAlive = ProcessUtils.isProcessAlive(simulatAssess.getPid()); |
| | | simulatAssess.setProcessIsAlive(isProcessAlive); |
| | | simulatAssessService.update(simulatAssess); |
| | | //simulatAssessService.deleteSimInfoInRedis(taskId); |
| | | } |
| | | } else { |
| | | for (Long taskId : taskList) { |
| | | int progTmp = 0; |
| | | SimulatAssess simulatAssess = simulatAssessService.get(taskId); |
| | | boolean isProcessAlive = ProcessUtils.isProcessAlive(simulatAssess.getPid()); |
| | | key = taskId.toString() + simulatAssessService.RELIA_SIM_TASK_TYPE_PROGRESS; |
| | | progress2 = (String) redisTemplate.opsForValue().get(key); |
| | | progress = progress + Integer.parseInt(progress2); |
| | | if (progress2 == null) progress2 = "0"; |
| | | progTmp = Integer.parseInt(progress2); |
| | | updateSimulateAssess(simulatAssess, isProcessAlive, progTmp); |
| | | if (progTmp < 100 && !isProcessAlive) { |
| | | logger.error("算法库进程在计算途中异常终止了:taskId="+taskId+" pid="+simulatAssess.getPid()+" progress="+progTmp); |
| | | // simulatAssessService.deleteSimInfoInRedis(taskId); |
| | | return Result.error("算法库进程在计算途中异常终止了!"); |
| | | } |
| | | progress = progress / taskList.length; |
| | | if (progress == 100) { |
| | | if (progTmp == 100) { |
| | | try { |
| | | Thread.sleep(500); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | isProcessAlive = ProcessUtils.isProcessAlive(simulatAssess.getPid()); |
| | | simulatAssess.setProcessIsAlive(isProcessAlive); |
| | | simulatAssessService.update(simulatAssess); |
| | | //simulatAssessService.deleteSimInfoInRedis(taskId); |
| | | } |
| | | progress = progress + progTmp; |
| | | } |
| | | progress = progress / taskList.length; |
| | | } |
| | | |
| | | return Result.ok(progress.toString()); |
| | | } |
| | | |
| | | private void updateSimulateAssess(SimulatAssess simulatAssess, boolean isProcessAlive, int progress) { |
| | | if (!isProcessAlive) { |
| | | simulatAssess.setProcessIsAlive(false); |
| | | simulatAssess.setProgress(progress); |
| | | simulatAssess.setProcessEndTime(new Date()); |
| | | simulatAssessService.update(simulatAssess); |
| | | } else { |
| | | if (simulatAssess.getProgress() != progress) { |
| | | simulatAssess.setProgress(progress); |
| | | simulatAssessService.update(simulatAssess); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @GetMapping("ReliabilityWeakness") |
| | |
| | | return Result.ok(data); |
| | | } |
| | | |
| | | @GetMapping("killProcess") |
| | | public Result<SchemeComparDto> killProcess(@RequestParam("taskId") Long taskId) { |
| | | SimulatAssess simulatAssess = simulatAssessService.get(taskId); |
| | | ProcessUtils.killProcess(simulatAssess.getPid()); |
| | | boolean isProcessAlive = ProcessUtils.isProcessAlive(simulatAssess.getPid()); |
| | | simulatAssess.setProcessIsAlive(isProcessAlive); |
| | | simulatAssessService.update(simulatAssess); |
| | | return Result.ok(); |
| | | } |
| | | |
| | | @PutMapping |
| | | @ApiOperation("修改") |
| | | @LogOperation("修改") |