123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- package com.miniframe.bisiness.mdo;
- import java.io.File;
- import java.io.FileWriter;
- import java.io.IOException;
- 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.exception.BusinessException;
- import com.miniframe.core.ext.UtilTools;
- import com.miniframe.generate.business.mdo.model.MDO0039BaseModel;
- import com.miniframe.mdo.service.LogService;
- import com.miniframe.model.mdo.MdoProPython;
- import com.miniframe.model.mdo.MdoProPythonSQLBuilder;
- import com.miniframe.model.mdo.MdoProject;
- import com.miniframe.model.mdo.dao.MdoProPythonMapper;
- import com.miniframe.model.mdo.dao.MdoProjectMapper;
- import com.miniframe.modo.temp.TemplateGenerator;
- import com.miniframe.tools.XIFileUtils;
- import com.miniframe.tools.docker.DockerExe;
- import freemarker.template.Configuration;
- import freemarker.template.Template;
- import lombok.SneakyThrows;
- /**
- * 西工大系统,“新版求解v2”逻辑处理(重新生成不覆盖)。
- */
- public class MDO0039Service extends MDO0039BaseModel implements ExecProcessFlow {
-
- private static final long serialVersionUID = -7051358269847459502L;
-
- /**
- * 西工大系统,“新版求解v2”业务核心处理
- */
- public void transExecute() throws Exception {
- String pid = this.getA_mdo0039().getPid();
- MdoProjectMapper proDao = UtilTools.getBean(MdoProjectMapper.class);
- MdoProject pro =proDao.selectByPrimaryKey(pid);
- if(pro==null){
- throw new BusinessException("MDO000001");
- }
- //创建文件路径
- XIFileUtils.mkdir(LogService.BPATH);
- XIFileUtils.mkdir(LogService.BPATH+"/"+pro.getId());
- XIFileUtils.mkdir(LogService.BPATH+"/"+pro.getId()+"/in");
- XIFileUtils.mkdir(LogService.BPATH+"/"+pro.getId()+"/out");
- //日志文件清空
- LogService.clearLog(pid);
- //创建problem.xml
- TemplateGenerator.createProblemXml(pid);
- //创建run.py
- TemplateGenerator.createRunpy(pid);
- run(pid);
- }
- //异步执行
- @SneakyThrows
- public void run(String pid )throws Exception{
- LogService.addLog(pid,"求解——————————————————开始");
- DockerExe.stopDocker(pid);
- CompletableFuture<Void> cf = CompletableFuture.supplyAsync(()-> {try {
- DockerExe.getDockerLogs(pid,new ResultCallback.Adapter<Frame>() {
- @Override
- public void onNext(Frame frame) {
- 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("日志获取失败");
- throwable.printStackTrace();
- super.onError(throwable);
- }
- @Override
- public void onComplete() {
- System.out.println("日志获取完成");
- super.onComplete();
- }
- });
- LogService.addLog(pid,"求解——————————————————成功");
- } catch (Exception e) {
- LogService.addLog(pid,"求解——————————————————失败");
- e.printStackTrace();
- }
- return null;
- });
- }
- /**
- * 西工大系统,“新版求解v2”业务前处理
- */
- public void preTransFlow() throws Exception {
- this.validater();
- }
-
- /**
- * 西工大系统,“新版求解v2”业务后处理
- */
- public void afterTransFlow() throws Exception {
-
- }
-
- /**
- * 西工大系统,“新版求解v2”逻辑入口处理方法
- */
- @SuppressWarnings("rawtypes")
- @Override
- public Map execute(Map vars) throws Exception {
- this.setTransMap(vars);
- preTransFlow();// 执行业务开始的规则检查和校验
- transExecute();// 执行核心业务段
- afterTransFlow();// 执行核心逻辑完成后的收尾逻辑
- return this.getTransMap();
- }
- }
|