|
@@ -0,0 +1,132 @@
|
|
|
+package com.miniframe.bisiness.mdo;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
+
|
|
|
+import com.github.dockerjava.api.async.ResultCallback;
|
|
|
+import com.github.dockerjava.api.model.Frame;
|
|
|
+import com.miniframe.core.ExecProcessFlow;
|
|
|
+import com.miniframe.core.ext.UtilTools;
|
|
|
+import com.miniframe.generate.business.mdo.model.MDO0061BaseModel;
|
|
|
+import com.miniframe.mdo.service.LogService;
|
|
|
+import com.miniframe.model.mdo.MdoProComvalSQLBuilder;
|
|
|
+import com.miniframe.model.mdo.dao.MdoProComvalMapper;
|
|
|
+import com.miniframe.model.system.SysFile;
|
|
|
+import com.miniframe.model.system.SysFileSQLBuilder;
|
|
|
+import com.miniframe.model.system.dao.SysFileMapper;
|
|
|
+import com.miniframe.tools.XIFileUtils;
|
|
|
+import com.miniframe.tools.XIUtils;
|
|
|
+import com.miniframe.tools.docker.DockerExe;
|
|
|
+import com.miniframe.tools.file.*;
|
|
|
+import com.miniframe.websocket.WebsocketEndPoint;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 西工大系统,“cgns文件解析”逻辑处理(重新生成不覆盖)。
|
|
|
+ */
|
|
|
+public class MDO0061Service extends MDO0061BaseModel implements ExecProcessFlow {
|
|
|
+
|
|
|
+ private static final long serialVersionUID = -7051358269847459502L;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 西工大系统,“cgns文件解析”业务核心处理
|
|
|
+ */
|
|
|
+ public void transExecute() throws Exception {
|
|
|
+ String fid = this.getA_mdo0061().getFid();
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ SysFileMapper sysFileDAO = UtilTools.getBean(SysFileMapper.class);
|
|
|
+ SysFile sysFile = sysFileDAO.selectByPrimaryKey(fid);
|
|
|
+
|
|
|
+ //删除上次解析数据
|
|
|
+ SysFileSQLBuilder fsb =new SysFileSQLBuilder();
|
|
|
+ SysFileSQLBuilder.Criteria fsc = fsb.createCriteria();
|
|
|
+ fsc.andParentidEqualTo(fid);
|
|
|
+ List<SysFile> fList = sysFileDAO.selectByExample(fsb);
|
|
|
+ for (SysFile f:fList) {
|
|
|
+ XIFileUtils.delete(XIFileUtils.getRootPathStr()+"/"+f.getFilepath());
|
|
|
+ }
|
|
|
+ sysFileDAO.deleteByExample(fsb);
|
|
|
+ run(sysFile);
|
|
|
+
|
|
|
+ }
|
|
|
+ private void sendMsg(String fid,String log){
|
|
|
+ CompletableFuture<Void> cf = CompletableFuture.supplyAsync(()->{
|
|
|
+ WebsocketEndPoint webs = (WebsocketEndPoint) UtilTools.getBean("websocketEndPoint");
|
|
|
+ webs.sendMessageToUser(fid,log);
|
|
|
+ return null;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void run(SysFile file) throws Exception {
|
|
|
+ DockerExe.stopDocker(file.getId());
|
|
|
+ DockerExe.cgnsToJson(file);
|
|
|
+ final int[] con = {0};
|
|
|
+ final String[] line = {""};
|
|
|
+ CompletableFuture<Void> cf = CompletableFuture.supplyAsync(()-> {
|
|
|
+ try {
|
|
|
+ DockerExe.getDockerLogs(file.getId(),new ResultCallback.Adapter<Frame>() {
|
|
|
+ @Override
|
|
|
+ public void onNext(Frame frame) {
|
|
|
+ if(con[0] <100){
|
|
|
+ line[0]+=new String(frame.getPayload());
|
|
|
+ con[0]++;
|
|
|
+ }else{
|
|
|
+ sendMsg(file.getId(), line[0]);
|
|
|
+ line[0]="";
|
|
|
+ con[0] =0;
|
|
|
+ }
|
|
|
+ sendMsg(file.getId(), line[0]);
|
|
|
+ System.out.print(new String(frame.getPayload()));
|
|
|
+ super.onNext(frame);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(Throwable throwable) {
|
|
|
+ System.err.println("日志获取失败");
|
|
|
+ throwable.printStackTrace();
|
|
|
+ super.onError(throwable);
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public void onComplete() {
|
|
|
+ System.out.println("日志获取完成");
|
|
|
+ super.onComplete();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 西工大系统,“cgns文件解析”业务前处理
|
|
|
+ */
|
|
|
+ public void preTransFlow() throws Exception {
|
|
|
+ this.validater();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 西工大系统,“cgns文件解析”业务后处理
|
|
|
+ */
|
|
|
+ public void afterTransFlow() throws Exception {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 西工大系统,“cgns文件解析”逻辑入口处理方法
|
|
|
+ */
|
|
|
+ @SuppressWarnings("rawtypes")
|
|
|
+ @Override
|
|
|
+ public Map execute(Map vars) throws Exception {
|
|
|
+ this.setTransMap(vars);
|
|
|
+ preTransFlow();// 执行业务开始的规则检查和校验
|
|
|
+ transExecute();// 执行核心业务段
|
|
|
+ afterTransFlow();// 执行核心逻辑完成后的收尾逻辑
|
|
|
+ return this.getTransMap();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|