package com.zt.life.modules.mainPart.taskReliability.controller;
|
|
|
import cn.hutool.json.JSONObject;
|
import cn.hutool.json.XML;
|
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.utils.JsonUtils;
|
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.model.SimulatAssess;
|
import com.zt.life.modules.mainPart.taskReliability.service.SimulatAssessService;
|
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.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.web.bind.annotation.*;
|
import springfox.documentation.annotations.ApiIgnore;
|
|
import java.io.IOException;
|
import java.io.InputStream;
|
|
|
/**
|
* simulat_assess
|
*
|
* @author zt generator
|
* @since 1.0.0 2024-03-20
|
*/
|
@RestController
|
@RequestMapping("/taskReliability/SimulatAssess/")
|
@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;
|
|
@Autowired
|
private PythonLib pythonLib;
|
|
@Value("${data.reliaSimLib.resultHome}")
|
private String path;
|
|
@Autowired
|
private SimulatAssessService simulatAssessService;
|
|
@GetMapping("page")
|
@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 = Constant.Q.ORDER_FIELD, value = Constant.QV.ORDER_FIELD, dataType = Constant.QT.STRING),
|
@ApiImplicitParam(name = Constant.Q.ORDER, value = Constant.QV.ORDER, dataType = Constant.QT.STRING),
|
})
|
public PageResult<SimulatAssess> page(@ApiIgnore @QueryParam QueryFilter queryFilter) {
|
|
return PageResult.ok(simulatAssessService.page(queryFilter));
|
}
|
|
@GetMapping("{id}")
|
@ApiOperation("信息")
|
public Result<SimulatAssess> get(@PathVariable("id") Long id) {
|
SimulatAssess data = simulatAssessService.get(id);
|
|
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);
|
|
return result;
|
}
|
|
@GetMapping("getResultXML")
|
public Result getResultXML(Long taskId) {
|
String filePath = path + "/"+taskId+"/"+"result.xml";
|
InputStream in = JsonUtils.class.getResourceAsStream(filePath);
|
String xml = null;
|
try {
|
xml = IOUtils.toString(in);
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
JSONObject xmlJSONObj = XML.toJSONObject(xml);
|
|
|
return Result.ok();
|
}
|
|
@GetMapping("getCalcProgress")
|
public Result getCalcProgress(Long taskId) {
|
String key = taskId.toString() + taskTypeProgress;
|
String progress = (String)redisTemplate.opsForValue().get(key);
|
if (progress==null) progress = "0";
|
return Result.ok(progress);
|
}
|
|
@PutMapping
|
@ApiOperation("修改")
|
@LogOperation("修改")
|
public Result update(@RequestBody SimulatAssess simulatAssess) {
|
//效验数据
|
ValidatorUtils.validateEntity(simulatAssess, UpdateGroup.class, DefaultGroup.class);
|
simulatAssessService.update(simulatAssess);
|
|
return Result.ok();
|
}
|
|
@DeleteMapping
|
@ApiOperation("删除")
|
@LogOperation("删除")
|
public Result delete(@RequestBody Long[] ids) {
|
//效验数据
|
AssertUtils.isArrayEmpty(ids, "id");
|
simulatAssessService.delete(ids);
|
|
return Result.ok();
|
}
|
|
}
|