package com.miniframe.bisiness.ac; import java.util.Map; import java.util.concurrent.CompletableFuture; import ac.template.TemplateGenerator; import com.github.dockerjava.api.async.ResultCallback; import com.github.dockerjava.api.model.Frame; import com.miniframe.core.ExecProcessFlow; import com.miniframe.generate.business.ac.model.AC00006BaseModel; import com.miniframe.tools.XIFileUtils; import com.miniframe.tools.docker.DockerExe; import service.LogService; /** * 气动设计系统,“项目求解”逻辑处理(重新生成不覆盖)。 */ public class AC00006Service extends AC00006BaseModel implements ExecProcessFlow { private static final long serialVersionUID = -7051358269847459502L; /** * 气动设计系统,“项目求解”业务核心处理 */ public void transExecute() throws Exception { String pid = this.getA_ac00006().getPid(); Integer type =this.getA_ac00006().getType();//类型0 气动 1 结构 2 气弹 XIFileUtils.mkdir(XIFileUtils.getRootPathStr()); XIFileUtils.mkdir(XIFileUtils.getRootPathStr()+"/ac"); XIFileUtils.mkdir(XIFileUtils.getRootPathStr()+"/ac/"+pid); XIFileUtils.mkdir(XIFileUtils.getRootPathStr()+"/ac/"+pid+"/"+type); TemplateGenerator.createGuiXml(pid,type); run(pid,type); } private void run(String pid,Integer type) throws Exception { LogService.clearLog(pid,type); LogService.addLog(pid,type,"求解——————————————————开始"); DockerExe.stopDocker(pid); DockerExe.run(pid,type); final int[] con = {0}; final String[] line = {""}; CompletableFuture cf = CompletableFuture.supplyAsync(()-> {try { DockerExe.getDockerLogs(pid,new ResultCallback.Adapter() { @Override public void onNext(Frame frame) { if(con[0] <100){ line[0]+=new String(frame.getPayload()); con[0]++; }else{ line[0]+=new String(frame.getPayload()); LogService.addLog(pid,type, line[0]); line[0]=""; con[0] =0; } // LogService.addLog(pid, new String(frame.getPayload())); System.out.print(new String(frame.getPayload())); super.onNext(frame); } @Override public void onError(Throwable throwable) { System.err.println("日志获取失败"); LogService.addLog(pid,type,line[0]); throwable.printStackTrace(); DockerExe.stopDocker(pid); super.onError(throwable); } @Override public void onComplete() { System.out.println("日志获取完成"); LogService.addLog(pid,type, line[0]); DockerExe.stopDocker(pid); super.onComplete(); } }); LogService.addLog(pid,type,"求解——————————————————成功"); } catch (Exception e) { LogService.addLog(pid,type,"求解——————————————————失败"); e.printStackTrace(); } return null; }); } /** * 气动设计系统,“项目求解”业务前处理 */ public void preTransFlow() throws Exception { this.validater(); } /** * 气动设计系统,“项目求解”业务后处理 */ public void afterTransFlow() throws Exception { } /** * 气动设计系统,“项目求解”逻辑入口处理方法 */ @SuppressWarnings("rawtypes") @Override public Map execute(Map vars) throws Exception { this.setTransMap(vars); preTransFlow();// 执行业务开始的规则检查和校验 transExecute();// 执行核心业务段 afterTransFlow();// 执行核心逻辑完成后的收尾逻辑 return this.getTransMap(); } }