123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- package com.miniframe.bisiness.mdo;
- 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.MDO0072BaseModel;
- 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.docker.DockerExe;
- import com.miniframe.websocket.WebsocketEndPoint;
- /**
- * 西工大系统,“bdf文件解析”逻辑处理(重新生成不覆盖)。
- */
- public class MDO0072Service extends MDO0072BaseModel implements ExecProcessFlow {
-
- private static final long serialVersionUID = -7051358269847459502L;
-
- /**
- * 西工大系统,“bdf文件解析”业务核心处理
- */
- public void transExecute() throws Exception {
- String fid =this.getA_mdo0072().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.bdfToJson(file);
- final String[] line = {""};
- CompletableFuture<Void> cf = CompletableFuture.supplyAsync(()-> {
- try {
- DockerExe.getDockerLogs(file.getId(),new ResultCallback.Adapter<Frame>() {
- @Override
- public void onNext(Frame frame) {
- line[0]+=new String(frame.getPayload());
- super.onNext(frame);
- }
- @Override
- public void onError(Throwable throwable) {
- System.err.println("日志获取失败");
- throwable.printStackTrace();
- DockerExe.stopDocker(file.getId());
- super.onError(throwable);
- }
- @Override
- public void onComplete() {
- System.out.println("日志获取完成");
- DockerExe.stopDocker(file.getId());
- sendMsg(file.getId(), line[0]);
- super.onComplete();
- }
- });
- } catch (Exception e) {
- e.printStackTrace();
- }
- DockerExe.stopDocker(file.getId());
- return null;
- });
- }
-
- /**
- * 西工大系统,“bdf文件解析”业务前处理
- */
- public void preTransFlow() throws Exception {
- this.validater();
- }
-
- /**
- * 西工大系统,“bdf文件解析”业务后处理
- */
- public void afterTransFlow() throws Exception {
-
- }
-
- /**
- * 西工大系统,“bdf文件解析”逻辑入口处理方法
- */
- @SuppressWarnings("rawtypes")
- @Override
- public Map execute(Map vars) throws Exception {
- this.setTransMap(vars);
- preTransFlow();// 执行业务开始的规则检查和校验
- transExecute();// 执行核心业务段
- afterTransFlow();// 执行核心逻辑完成后的收尾逻辑
- return this.getTransMap();
- }
- }
|