|  | @@ -1,248 +0,0 @@
 | 
											
												
													
														|  | -package com.miniframe.bisiness.es;
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -import java.io.IOException;
 |  | 
 | 
											
												
													
														|  | -import java.math.BigDecimal;
 |  | 
 | 
											
												
													
														|  | -import java.nio.file.Files;
 |  | 
 | 
											
												
													
														|  | -import java.nio.file.Path;
 |  | 
 | 
											
												
													
														|  | -import java.nio.file.Paths;
 |  | 
 | 
											
												
													
														|  | -import java.util.*;
 |  | 
 | 
											
												
													
														|  | -import java.util.concurrent.CompletableFuture;
 |  | 
 | 
											
												
													
														|  | -import java.util.stream.Collectors;
 |  | 
 | 
											
												
													
														|  | -import java.util.stream.Stream;
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -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.es.model.ES0013BaseModel;
 |  | 
 | 
											
												
													
														|  | -import com.miniframe.mappers.es.dao.EsMapper;
 |  | 
 | 
											
												
													
														|  | -import com.miniframe.model.es.*;
 |  | 
 | 
											
												
													
														|  | -import com.miniframe.model.es.dao.*;
 |  | 
 | 
											
												
													
														|  | -import com.miniframe.tools.XIFileUtils;
 |  | 
 | 
											
												
													
														|  | -import com.miniframe.tools.docker.DockerExe;
 |  | 
 | 
											
												
													
														|  | -import es.service.LogService;
 |  | 
 | 
											
												
													
														|  | -import es.template.TemplateGenerator;
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -/**
 |  | 
 | 
											
												
													
														|  | - * 无锡发动机,“项目求解”逻辑处理(重新生成不覆盖)。
 |  | 
 | 
											
												
													
														|  | - */
 |  | 
 | 
											
												
													
														|  | -public class ES0013Service extends ES0013BaseModel implements ExecProcessFlow {
 |  | 
 | 
											
												
													
														|  | -	
 |  | 
 | 
											
												
													
														|  | -	private static final long serialVersionUID = -7051358269847459502L;
 |  | 
 | 
											
												
													
														|  | -		
 |  | 
 | 
											
												
													
														|  | -	/**
 |  | 
 | 
											
												
													
														|  | -	 * 无锡发动机,“项目求解”业务核心处理
 |  | 
 | 
											
												
													
														|  | - 	 */
 |  | 
 | 
											
												
													
														|  | -	public void transExecute() throws Exception {
 |  | 
 | 
											
												
													
														|  | -		String pid = this.getA_es0013().getPid();
 |  | 
 | 
											
												
													
														|  | -		XIFileUtils.mkdir(XIFileUtils.getRootPathStr());
 |  | 
 | 
											
												
													
														|  | -		XIFileUtils.mkdir(XIFileUtils.getRootPathStr()+"/es");
 |  | 
 | 
											
												
													
														|  | -		XIFileUtils.mkdir(XIFileUtils.getRootPathStr()+"/es/"+pid);
 |  | 
 | 
											
												
													
														|  | -		XIFileUtils.mkdir(XIFileUtils.getRootPathStr()+"/es/"+pid+"/Calculate");
 |  | 
 | 
											
												
													
														|  | -		XIFileUtils.mkdir(XIFileUtils.getRootPathStr()+"/es/"+pid+"/Calculate/Geometry");//几何路径
 |  | 
 | 
											
												
													
														|  | -		TemplateGenerator.createPipenetXml(pid);
 |  | 
 | 
											
												
													
														|  | -		EsMapper esMapper = UtilTools.getBean(EsMapper.class);
 |  | 
 | 
											
												
													
														|  | -		Integer maxser =esMapper.getProJobSer(pid);
 |  | 
 | 
											
												
													
														|  | -		maxser=maxser==null?0:maxser;
 |  | 
 | 
											
												
													
														|  | -		String jobId = insertJob(pid,maxser);
 |  | 
 | 
											
												
													
														|  | -		run(pid,jobId,maxser+1);
 |  | 
 | 
											
												
													
														|  | -	}
 |  | 
 | 
											
												
													
														|  | -	private String updateJob(String jobId) {
 |  | 
 | 
											
												
													
														|  | -		EsProJobMapper epjDao = UtilTools.getBean(EsProJobMapper.class);
 |  | 
 | 
											
												
													
														|  | -		EsProJob esjob =epjDao.selectByPrimaryKey(jobId);
 |  | 
 | 
											
												
													
														|  | -		esjob.setEndTime(new Date());
 |  | 
 | 
											
												
													
														|  | -		epjDao.updateByPrimaryKey(esjob);
 |  | 
 | 
											
												
													
														|  | -		return jobId;
 |  | 
 | 
											
												
													
														|  | -	}
 |  | 
 | 
											
												
													
														|  | -	private String insertJob(String pid,Integer maxser) {
 |  | 
 | 
											
												
													
														|  | -		EsProJobMapper epjDao = UtilTools.getBean(EsProJobMapper.class);
 |  | 
 | 
											
												
													
														|  | -		EsProJob esjob = new EsProJob();
 |  | 
 | 
											
												
													
														|  | -		String jobId = UtilTools.getUUid();
 |  | 
 | 
											
												
													
														|  | -		esjob.setJobId(jobId);
 |  | 
 | 
											
												
													
														|  | -		esjob.setPid(pid);
 |  | 
 | 
											
												
													
														|  | -		esjob.setStartTime(new Date());
 |  | 
 | 
											
												
													
														|  | -		esjob.setEndTime(new Date());
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -		esjob.setSer(maxser+1);
 |  | 
 | 
											
												
													
														|  | -		esjob.setUid(this.getA_eshead().getUserId());
 |  | 
 | 
											
												
													
														|  | -		esjob.setCreateTime(new Date());
 |  | 
 | 
											
												
													
														|  | -		esjob.setUpdateTime(new Date());
 |  | 
 | 
											
												
													
														|  | -		epjDao.insert(esjob);
 |  | 
 | 
											
												
													
														|  | -		return jobId;
 |  | 
 | 
											
												
													
														|  | -	}
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -	private void run(String pid,String jobId,Integer maxser) throws Exception {
 |  | 
 | 
											
												
													
														|  | -		LogService.clearLog(pid);
 |  | 
 | 
											
												
													
														|  | -		LogService.addLog(pid,"求解——————————————————开始");
 |  | 
 | 
											
												
													
														|  | -		DockerExe.stopDocker(pid);
 |  | 
 | 
											
												
													
														|  | -		DockerExe.run(pid);
 |  | 
 | 
											
												
													
														|  | -		final int[] con = {0};
 |  | 
 | 
											
												
													
														|  | -		final String[] line = {""};
 |  | 
 | 
											
												
													
														|  | -		CompletableFuture<Void> cf = CompletableFuture.supplyAsync(()-> {try {
 |  | 
 | 
											
												
													
														|  | -			DockerExe.getDockerLogs(pid,new ResultCallback.Adapter<Frame>() {
 |  | 
 | 
											
												
													
														|  | -				@Override
 |  | 
 | 
											
												
													
														|  | -				public void onNext(Frame frame) {
 |  | 
 | 
											
												
													
														|  | -					if(con[0] <100){
 |  | 
 | 
											
												
													
														|  | -						line[0]+=new String(frame.getPayload());
 |  | 
 | 
											
												
													
														|  | -						con[0]++;
 |  | 
 | 
											
												
													
														|  | -					}else{
 |  | 
 | 
											
												
													
														|  | -						LogService.addLog(pid, 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, line[0]);
 |  | 
 | 
											
												
													
														|  | -					throwable.printStackTrace();
 |  | 
 | 
											
												
													
														|  | -					DockerExe.stopDocker(pid);
 |  | 
 | 
											
												
													
														|  | -					super.onError(throwable);
 |  | 
 | 
											
												
													
														|  | -				}
 |  | 
 | 
											
												
													
														|  | -				@Override
 |  | 
 | 
											
												
													
														|  | -				public void onComplete() {
 |  | 
 | 
											
												
													
														|  | -					System.out.println("日志获取完成");
 |  | 
 | 
											
												
													
														|  | -					LogService.addLog(pid, line[0]);
 |  | 
 | 
											
												
													
														|  | -					DockerExe.stopDocker(pid);
 |  | 
 | 
											
												
													
														|  | -					super.onComplete();
 |  | 
 | 
											
												
													
														|  | -				}
 |  | 
 | 
											
												
													
														|  | -			});
 |  | 
 | 
											
												
													
														|  | -			LogService.addLog(pid,"求解——————————————————成功");
 |  | 
 | 
											
												
													
														|  | -			readFileSaveTb(pid,jobId);
 |  | 
 | 
											
												
													
														|  | -			mvFiles(pid, maxser);
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -			updateJob(jobId);
 |  | 
 | 
											
												
													
														|  | -		} catch (Exception e) {
 |  | 
 | 
											
												
													
														|  | -			LogService.addLog(pid,"求解——————————————————失败");
 |  | 
 | 
											
												
													
														|  | -			e.printStackTrace();
 |  | 
 | 
											
												
													
														|  | -		}
 |  | 
 | 
											
												
													
														|  | -			return null;
 |  | 
 | 
											
												
													
														|  | -		});
 |  | 
 | 
											
												
													
														|  | -	}
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -	private void mvFiles(String pid, Integer maxser) {
 |  | 
 | 
											
												
													
														|  | -		//文件移动
 |  | 
 | 
											
												
													
														|  | -		XIFileUtils.mkdir(XIFileUtils.getRootPathStr()+"/es/"+ pid +"/Calculate/"+ maxser);
 |  | 
 | 
											
												
													
														|  | -		Path directory = Paths.get(XIFileUtils.getRootPathStr()+"/es/"+ pid +"/Calculate"); // 替换为你的目录路径
 |  | 
 | 
											
												
													
														|  | -		try (Stream<Path> stream = Files.list(directory)) {
 |  | 
 | 
											
												
													
														|  | -			stream.forEach(path -> {
 |  | 
 | 
											
												
													
														|  | -				if (Files.isRegularFile(path)) { // 确保是普通文件
 |  | 
 | 
											
												
													
														|  | -					XIFileUtils.fileCopy(path.toString(),
 |  | 
 | 
											
												
													
														|  | -							XIFileUtils.getRootPathStr()+"/es/"+ pid +"/Calculate/"+ maxser +"/"+path.getFileName());
 |  | 
 | 
											
												
													
														|  | -					System.out.println("File: " + path.getFileName());
 |  | 
 | 
											
												
													
														|  | -				}
 |  | 
 | 
											
												
													
														|  | -			});
 |  | 
 | 
											
												
													
														|  | -		} catch (IOException e) {
 |  | 
 | 
											
												
													
														|  | -			e.printStackTrace();
 |  | 
 | 
											
												
													
														|  | -		}
 |  | 
 | 
											
												
													
														|  | -	}
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -	private void readFileSaveTb(String pid,String jobId) throws Exception{
 |  | 
 | 
											
												
													
														|  | -		EsProComMapper pcdao = UtilTools.getBean(EsProComMapper.class);
 |  | 
 | 
											
												
													
														|  | -		EsProComSQLBuilder pcsb = new EsProComSQLBuilder();
 |  | 
 | 
											
												
													
														|  | -		EsProComSQLBuilder.Criteria pcsc = pcsb.createCriteria();
 |  | 
 | 
											
												
													
														|  | -		pcsc.andPidEqualTo(pid);
 |  | 
 | 
											
												
													
														|  | -		pcsc.andComIdNotEqualTo("-1");//排除模拟数据
 |  | 
 | 
											
												
													
														|  | -		List<EsProCom> epcList = pcdao.selectByExample(pcsb);
 |  | 
 | 
											
												
													
														|  | -		for(int i=0;i<epcList.size();i++){
 |  | 
 | 
											
												
													
														|  | -			int step = 0;
 |  | 
 | 
											
												
													
														|  | -			String fileName = epcList.get(i).getIdCode();
 |  | 
 | 
											
												
													
														|  | -			if(fileName.isEmpty()) continue;
 |  | 
 | 
											
												
													
														|  | -			fileName = fileName + epcList.get(i).getSer().toString();
 |  | 
 | 
											
												
													
														|  | -			String comId = epcList.get(i).getComId();
 |  | 
 | 
											
												
													
														|  | -			String pcId = epcList.get(i).getPcId();
 |  | 
 | 
											
												
													
														|  | -			List<String> lines = Files.readAllLines(Paths.get(XIFileUtils.getRootPathStr()+"/es/"+pid+"/Calculate/"+fileName));
 |  | 
 | 
											
												
													
														|  | -			List<List<String>> data = lines.stream()
 |  | 
 | 
											
												
													
														|  | -					.filter(line -> !line.trim().isEmpty()) // 跳过空行
 |  | 
 | 
											
												
													
														|  | -					.map(line -> {
 |  | 
 | 
											
												
													
														|  | -						return Arrays.stream(line.split(",")) // 分割逗号
 |  | 
 | 
											
												
													
														|  | -								.map(String::trim)           // 去除空格
 |  | 
 | 
											
												
													
														|  | -								.collect(Collectors.toList());
 |  | 
 | 
											
												
													
														|  | -					})
 |  | 
 | 
											
												
													
														|  | -					.collect(Collectors.toList());
 |  | 
 | 
											
												
													
														|  | -			List<String> keyList = new ArrayList<>();
 |  | 
 | 
											
												
													
														|  | -			for(int j=0;j<data.size();j++){
 |  | 
 | 
											
												
													
														|  | -				for(int k=0;k<data.get(j).size();k++){
 |  | 
 | 
											
												
													
														|  | -					if(j==1){
 |  | 
 | 
											
												
													
														|  | -						String pcrId = insertIntoTbKey(data.get(j-1).get(k),data.get(j).get(k),jobId,comId,pcId);
 |  | 
 | 
											
												
													
														|  | -						keyList.add(pcrId);
 |  | 
 | 
											
												
													
														|  | -					}else if(j>1){
 |  | 
 | 
											
												
													
														|  | -                        if(k==0)++step;
 |  | 
 | 
											
												
													
														|  | -						insertIntoTbValue(data.get(j).get(k),jobId,Integer.valueOf(step),comId,keyList.get(k),pcId);
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -					}
 |  | 
 | 
											
												
													
														|  | -				}
 |  | 
 | 
											
												
													
														|  | -			}
 |  | 
 | 
											
												
													
														|  | -		}
 |  | 
 | 
											
												
													
														|  | -	}
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -	private void insertIntoTbValue(String value,String job_id,Integer step,String comId,String pcrId,String pcId) throws Exception{
 |  | 
 | 
											
												
													
														|  | -		EsProResultValueMapper eprvMapper = UtilTools.getBean(EsProResultValueMapper.class);
 |  | 
 | 
											
												
													
														|  | -		EsProResultValue eprv = new EsProResultValue();
 |  | 
 | 
											
												
													
														|  | -		eprv.setPcrvId(UtilTools.getUUid());
 |  | 
 | 
											
												
													
														|  | -		eprv.setPcrId(pcrId);
 |  | 
 | 
											
												
													
														|  | -		eprv.setPid(this.getA_es0013().getPid());
 |  | 
 | 
											
												
													
														|  | -		eprv.setComId(comId);
 |  | 
 | 
											
												
													
														|  | -		eprv.setPcId(pcId);
 |  | 
 | 
											
												
													
														|  | -		eprv.setJobId(job_id);
 |  | 
 | 
											
												
													
														|  | -		eprv.setValue(value);
 |  | 
 | 
											
												
													
														|  | -		eprv.setUid(this.getA_eshead().getUserId());
 |  | 
 | 
											
												
													
														|  | -		eprv.setCreateTime(new Date());
 |  | 
 | 
											
												
													
														|  | -		eprv.setUpdateTime(new Date());
 |  | 
 | 
											
												
													
														|  | -		eprv.setRemark("");
 |  | 
 | 
											
												
													
														|  | -		eprv.setStep(step);
 |  | 
 | 
											
												
													
														|  | -		eprvMapper.insert(eprv);
 |  | 
 | 
											
												
													
														|  | -	}
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -	private String insertIntoTbKey(String key_en,String key_zh,String jobId,String comId,String pcId) throws Exception{
 |  | 
 | 
											
												
													
														|  | -		EsProResultKeyMapper eprkMapper = UtilTools.getBean(EsProResultKeyMapper.class);
 |  | 
 | 
											
												
													
														|  | -		EsProResultKey eprk = new EsProResultKey();
 |  | 
 | 
											
												
													
														|  | -		String pcrId = UtilTools.getUUid();
 |  | 
 | 
											
												
													
														|  | -		eprk.setPcrId(pcrId);
 |  | 
 | 
											
												
													
														|  | -		eprk.setPid(this.getA_es0013().getPid());
 |  | 
 | 
											
												
													
														|  | -		eprk.setComId(comId);
 |  | 
 | 
											
												
													
														|  | -		eprk.setPcId(pcId);
 |  | 
 | 
											
												
													
														|  | -		eprk.setJobId(jobId);
 |  | 
 | 
											
												
													
														|  | -		eprk.setKeyEn(key_en);
 |  | 
 | 
											
												
													
														|  | -		eprk.setKeyZh(key_zh);
 |  | 
 | 
											
												
													
														|  | -		eprk.setUid(this.getA_eshead().getUserId());
 |  | 
 | 
											
												
													
														|  | -		eprk.setCreateTime(new Date());
 |  | 
 | 
											
												
													
														|  | -		eprk.setUpdateTime(new Date());
 |  | 
 | 
											
												
													
														|  | -		eprk.setRemark("");
 |  | 
 | 
											
												
													
														|  | -		eprkMapper.insert(eprk);
 |  | 
 | 
											
												
													
														|  | -		return pcrId;
 |  | 
 | 
											
												
													
														|  | -	}
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -	/**
 |  | 
 | 
											
												
													
														|  | -	 * 无锡发动机,“项目求解”业务前处理
 |  | 
 | 
											
												
													
														|  | - 	 */
 |  | 
 | 
											
												
													
														|  | -	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();
 |  | 
 | 
											
												
													
														|  | -	}
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -}
 |  | 
 |