package com.miniframe.bisiness.system; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import com.miniframe.core.ExecProcessFlow; import com.miniframe.core.IniFileReader; import com.miniframe.core.exception.BusinessException; import com.miniframe.core.ext.UtilTools; import com.miniframe.generate.business.system.model.C00005BaseModel; import com.miniframe.model.system.*; import com.miniframe.model.system.dao.AdiModelingMapper; import com.miniframe.model.system.dao.AdiProjectMapper; import com.miniframe.model.system.dao.AdiSolverConfigMapper; import com.miniframe.model.system.dao.AdiSolverMapper; import com.miniframe.solverconfig.fem.FEMOrder; import com.miniframe.solverconfig.fem.FEMParam; import com.miniframe.solverconfig.fem.FEMPath; import com.miniframe.solverconfig.hcfd.HcfdExe; import com.miniframe.solverconfig.hcfd.HcfdParam; import com.miniframe.solverconfig.hcfd.HcfdPath; import com.miniframe.solverjob.AdiSolverJobService; import com.miniframe.tools.XiJsonUtil; import com.miniframe.tools.ali.HttpUtils; import org.apache.http.HttpResponse; /** * 基础系统,“求解”逻辑处理(重新生成不覆盖)。 */ public class C00005Service extends C00005BaseModel implements ExecProcessFlow { private static final long serialVersionUID = -7051358269847459502L; /** * 基础系统,“求解”业务核心处理 */ public void transExecute() throws Exception { String solverConfigId = getA_c00005().getSolverConfigId(); String uid =getA_systemhead().getUserId(); AdiSolverConfigMapper configMapper = UtilTools.getBean(AdiSolverConfigMapper.class); AdiSolverConfig config = configMapper.selectByPrimaryKey(solverConfigId); if(null==config){ throw new BusinessException("EB4000007"); } AdiSolverMapper solverMapper = UtilTools.getBean(AdiSolverMapper.class); AdiSolver solver = solverMapper.selectByPrimaryKey(config.getSolverid()); if(null==solver){ throw new BusinessException("EB4000009"); } AdiProjectMapper projectMapper = UtilTools.getBean(AdiProjectMapper.class); AdiProject project = projectMapper.selectByPrimaryKey(config.getPid()); if(null==project){ throw new BusinessException("EB4000008"); } AdiModelingMapper modelingMapper = UtilTools.getBean(AdiModelingMapper.class); AdiModelingSQLBuilder modelingsb = new AdiModelingSQLBuilder(); AdiModelingSQLBuilder.Criteria modelingsc = modelingsb.createCriteria(); modelingsc.andPidEqualTo(project.getId()); List modelingList = modelingMapper.selectByExample(modelingsb); if(null==modelingList||modelingList.isEmpty()){ throw new BusinessException("EB4000010"); } AdiModeling modeling = modelingList.get(0); AdiSolverJob job =AdiSolverJobService.createJob(config);//创建执行任务 /** * 删除上次创建的索引日志数据 */ delEsIndex(project.getId()); if(solver.getCompany().equals("ADI.SimWork")&& solver.getSolverModel().equals("HCFDLab")){ HcfdParam param = XiJsonUtil.jsonToPojo(config.getParameterObj(),HcfdParam.class); HcfdExe.CreateMpbcFile(null,config); HcfdExe.CreateNmlFile(null,config); HcfdPath.hcfdCreatPath(modeling,config,job); String vfred=""; String afred=""; vfred=param.getNmlParam().getVolume_animation_freq().toString(); afred=param.getNmlParam().getAnimation_freq().toString(); String url="http://localhost:8082/solverres";//TODO 通过资源数据获取IP System.out.println(url); httpExeJob(job,"hcfd",url,vfred,afred,null); } if(solver.getCompany().equals("ADI.SimWork")&& solver.getSolverModel().equals("FEMLab(结构力学)")){ FEMParam param =XiJsonUtil.jsonToPojo(config.getParameterObj(),FEMParam.class); FEMOrder.CreateAnalysisFile(null,config); FEMPath.femCreatePath(modeling,config,job); String url="http://192.168.0.109:8082/solverres";//TODO 通过资源数据获取IP System.out.println(url); httpExeJob(job,"fem",url,null,null,null); } } /** * 执行前 删除上次创建的索引日志数据 */ private void delEsIndex(String proId) throws Exception { String host = "http://192.168.0.43:8031/del"; String path =""; String method=""; Map headers = new HashMap<>(); Map querys= new HashMap<>(); Map bodys= new HashMap<>(); bodys.put("projectId", proId); HttpResponse response= HttpUtils.doPost(host,path,method,headers,querys,bodys); } /** * onespace * @param job * @param url * @param vfred * @param afred * @throws Exception */ private void httpExeJob(AdiSolverJob job,String projectType,String url,String vfred,String afred ,String resources) throws Exception { String path =""; String method=""; Map headers = new HashMap<>(); Map querys= new HashMap<>(); Map bodys= new HashMap<>(); bodys.put("jobId", job.getId()); bodys.put("projectType", projectType); bodys.put("jobOrder", ""); bodys.put("projectId", job.getPid()); bodys.put("orderType", ""); bodys.put("vfreq", vfred); bodys.put("afreq", afred); bodys.put("resources", resources); //异步执行 求解 ExecutorService cachedThreadPool = Executors.newCachedThreadPool(); cachedThreadPool.execute(new Runnable() { @Override public void run() { try { HttpResponse response= HttpUtils.doPost(url,path,method,headers,querys,bodys); } catch (Exception exception) { exception.printStackTrace(); } } }); } /** * 基础系统,“求解”业务前处理 */ 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(); } }