MDO0072Service.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package com.miniframe.bisiness.mdo;
  2. import java.util.HashMap;
  3. import java.util.List;
  4. import java.util.Map;
  5. import java.util.concurrent.CompletableFuture;
  6. import com.github.dockerjava.api.async.ResultCallback;
  7. import com.github.dockerjava.api.model.Frame;
  8. import com.miniframe.core.ExecProcessFlow;
  9. import com.miniframe.core.ext.UtilTools;
  10. import com.miniframe.generate.business.mdo.model.MDO0072BaseModel;
  11. import com.miniframe.model.system.SysFile;
  12. import com.miniframe.model.system.SysFileSQLBuilder;
  13. import com.miniframe.model.system.dao.SysFileMapper;
  14. import com.miniframe.tools.XIFileUtils;
  15. import com.miniframe.tools.docker.DockerExe;
  16. import com.miniframe.websocket.WebsocketEndPoint;
  17. /**
  18. * 西工大系统,“bdf文件解析”逻辑处理(重新生成不覆盖)。
  19. */
  20. public class MDO0072Service extends MDO0072BaseModel implements ExecProcessFlow {
  21. private static final long serialVersionUID = -7051358269847459502L;
  22. /**
  23. * 西工大系统,“bdf文件解析”业务核心处理
  24. */
  25. public void transExecute() throws Exception {
  26. String fid =this.getA_mdo0072().getFid();
  27. Map<String, Object> result = new HashMap<>();
  28. SysFileMapper sysFileDAO = UtilTools.getBean(SysFileMapper.class);
  29. SysFile sysFile = sysFileDAO.selectByPrimaryKey(fid);
  30. //删除上次解析数据
  31. SysFileSQLBuilder fsb =new SysFileSQLBuilder();
  32. SysFileSQLBuilder.Criteria fsc = fsb.createCriteria();
  33. fsc.andParentidEqualTo(fid);
  34. List<SysFile> fList = sysFileDAO.selectByExample(fsb);
  35. for (SysFile f:fList) {
  36. XIFileUtils.delete(XIFileUtils.getRootPathStr()+"/"+f.getFilepath());
  37. }
  38. sysFileDAO.deleteByExample(fsb);
  39. run(sysFile);
  40. }
  41. private void sendMsg(String fid,String log){
  42. CompletableFuture<Void> cf = CompletableFuture.supplyAsync(()->{
  43. WebsocketEndPoint webs = (WebsocketEndPoint) UtilTools.getBean("websocketEndPoint");
  44. webs.sendMessageToUser(fid,log);
  45. return null;
  46. });
  47. }
  48. private void run(SysFile file) throws Exception {
  49. DockerExe.stopDocker(file.getId());
  50. DockerExe.bdfToJson(file);
  51. final String[] line = {""};
  52. CompletableFuture<Void> cf = CompletableFuture.supplyAsync(()-> {
  53. try {
  54. DockerExe.getDockerLogs(file.getId(),new ResultCallback.Adapter<Frame>() {
  55. @Override
  56. public void onNext(Frame frame) {
  57. line[0]+=new String(frame.getPayload());
  58. super.onNext(frame);
  59. }
  60. @Override
  61. public void onError(Throwable throwable) {
  62. System.err.println("日志获取失败");
  63. throwable.printStackTrace();
  64. DockerExe.stopDocker(file.getId());
  65. super.onError(throwable);
  66. }
  67. @Override
  68. public void onComplete() {
  69. System.out.println("日志获取完成");
  70. DockerExe.stopDocker(file.getId());
  71. sendMsg(file.getId(), line[0]);
  72. super.onComplete();
  73. }
  74. });
  75. } catch (Exception e) {
  76. e.printStackTrace();
  77. }
  78. DockerExe.stopDocker(file.getId());
  79. return null;
  80. });
  81. }
  82. /**
  83. * 西工大系统,“bdf文件解析”业务前处理
  84. */
  85. public void preTransFlow() throws Exception {
  86. this.validater();
  87. }
  88. /**
  89. * 西工大系统,“bdf文件解析”业务后处理
  90. */
  91. public void afterTransFlow() throws Exception {
  92. }
  93. /**
  94. * 西工大系统,“bdf文件解析”逻辑入口处理方法
  95. */
  96. @SuppressWarnings("rawtypes")
  97. @Override
  98. public Map execute(Map vars) throws Exception {
  99. this.setTransMap(vars);
  100. preTransFlow();// 执行业务开始的规则检查和校验
  101. transExecute();// 执行核心业务段
  102. afterTransFlow();// 执行核心逻辑完成后的收尾逻辑
  103. return this.getTransMap();
  104. }
  105. }