package com.miniframe.modo.temp; import com.miniframe.core.ext.UtilTools; import com.miniframe.generate.appcode.ComType; import com.miniframe.mdo.service.LogService; import com.miniframe.mdo.utils.MdoUidUtils; import com.miniframe.model.mdo.*; import com.miniframe.model.mdo.dao.*; import com.miniframe.modo.temp.cpacs.*; import com.miniframe.modo.temp.problem.*; import com.miniframe.modo.temp.workflow.*; import freemarker.template.Configuration; import freemarker.template.Template; import freemarker.template.TemplateException; import tk.mybatis.mapper.util.StringUtil; import java.io.FileWriter; import java.io.IOException; import java.io.StringWriter; import java.util.*; import java.util.stream.Collectors; public class TemplateGenerator { /** * 创建 执行文件 * @param pid * @throws IOException * @throws TemplateException */ public static void createRunpy(String pid) throws IOException, TemplateException { Configuration cfg = new Configuration(Configuration.VERSION_2_3_0); // 设置模板所在目录 cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates"); // 获取模板对象 Template template = cfg.getTemplate("run.ftl"); // 定义数据模型(Map) Map dataModel = new HashMap<>(); dataModel.put("problemPath",LogService.BPATH + "/" + pid + "/in/problem.xml"); // 将数据模型传入模板进行处理 StringWriter writer = new StringWriter(); template.process(dataModel, writer); FileWriter fileWriter = new FileWriter(LogService.BPATH + "/" + pid + "/in/run.py"); fileWriter.write(writer.toString()); fileWriter.close(); } /** * 创建 执行文件 * @param pid * @throws IOException * @throws TemplateException */ public static void createRunpy2(String pid) throws IOException, TemplateException { Configuration cfg = new Configuration(Configuration.VERSION_2_3_0); // 设置模板所在目录 cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates"); // 获取模板对象 Template template = cfg.getTemplate("run2.ftl"); // 定义数据模型(Map) Map dataModel = new HashMap<>(); dataModel.put("problemPath",LogService.BPATH + "/" + pid + "/in/problem.xml"); // 将数据模型传入模板进行处理 StringWriter writer = new StringWriter(); template.process(dataModel, writer); FileWriter fileWriter = new FileWriter(LogService.BPATH + "/" + pid + "/in/run.py"); fileWriter.write(writer.toString()); fileWriter.close(); } /** * 创建problem.xml * @param pid * @throws IOException * @throws TemplateException */ public static void createProblemXml(String pid,ProblemVo vo) throws IOException, TemplateException { //Problem.xml 写入 Configuration cfg = new Configuration(Configuration.VERSION_2_3_0); // 设置模板所在目录 cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates"); // 获取模板对象 Template template = cfg.getTemplate("problem.ftl"); // 定义数据模型(Map) Map dataModel = new HashMap<>(); // ProblemVo vo = findProblemVo(pid); dataModel.put("vo",vo); // dataModel.put("geoFilePath", BPATH + "/" + aid + "/" + jid + "/Geometry"); // 将数据模型传入模板进行处理 StringWriter writer = new StringWriter(); template.process(dataModel, writer); FileWriter fileWriter = new FileWriter(LogService.BPATH + "/" + pid + "/in/problem.xml"); fileWriter.write(writer.toString()); fileWriter.close(); } public static ProblemVo findProblemVo(String pid) throws IOException { ProblemVo vo = new ProblemVo(); HeaderVo header =new HeaderVo(); header.setName(pid); header.setTimestamp(new Date()); vo.setHeader(header); List designVariables=findDesignVariables(pid); vo.setDesignVariables(designVariables); List objectives = findObjectives(pid); vo.setObjectives(objectives); List constraints = findConstraints(pid); vo.setConstraints(constraints); MdoProEvolution evolution = findEvolution(pid); vo.setEvolution(evolution); MdoProSurro surro = findSurro(pid); vo.setSurro(surro); MdoProGrad grad = findGrad(pid); vo.setGrad(grad); return vo; } /** * TODO 创建 cpacsxml * @return */ public static String createcCpacsXml(String pid,CpacsVo vo) { try { if(vo ==null){ return null; } Configuration cfg = new Configuration(Configuration.VERSION_2_3_0); // 设置模板所在目录 cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates"); // 获取模板对象 Template template = cfg.getTemplate("cpacs.ftl"); // 定义数据模型(Map) Map dataModel = new HashMap<>(); dataModel.put("vo",vo); //dataModel.put("geoFilePath", BPATH + "/" + aid + "/" + jid + "/Geometry"); // 将数据模型传入模板进行处理 StringWriter writer = new StringWriter(); template.process(dataModel, writer); FileWriter fileWriter = new FileWriter(LogService.BPATH + "/" + pid + "/in/cpacs.xml"); fileWriter.write(writer.toString()); fileWriter.close(); return LogService.BPATH + "/" + pid + "/in/cpacs.xml"; }catch (Exception e){ return null; } } public static WorkflowVo getWorkflowVo(String pid) { WorkflowVo vo = new WorkflowVo(); MdoProXfoil xfoil = findXfoil(pid); MdoProAdflow adflow = findAdflow(pid); MdoProFsi fsi= findFsi(pid); MdoProMathfunc mathfunc = findMashfunc(pid); //不用生成 if(xfoil==null&& adflow==null&&mathfunc==null){ return null; } HeaderVo header =new HeaderVo(); header.setName(pid); header.setTimestamp(new Date()); vo.setHeader(header); List executeOrders =new ArrayList<>(); if(fsi!=null){ FsiflowVo fsivo = new FsiflowVo(); fsivo.setUid("aeroelastic"); fsivo.setName("pyAeroelasticADJ"); List inUids = findFsiInUids(pid); fsivo.setInUids(inUids); List outUids= findFsiOutUid(pid); fsivo.setOutUids(outUids); vo.setFsivo(fsivo); executeOrders.add(fsivo.getUid()); }else if(xfoil!=null){ XfoilflowVo xfoilvo = new XfoilflowVo(); xfoilvo.setUid("xfoil"); xfoilvo.setName("pyXFoil"); List inUids = findXfoilInUids(pid); xfoilvo.setInUids(inUids); List outUids= findXfoilOutUid(pid); xfoilvo.setOutUids(outUids); vo.setXfoilvo(xfoilvo); executeOrders.add(xfoilvo.getUid()); }else if(adflow!=null){ AdflowVo adflowVo = new AdflowVo(); adflowVo.setUid("ADflow"); adflowVo.setName("pyADflow"); List inUids = findAdflowInUids(pid); adflowVo.setInUids(inUids); List outUids= findAdflowOutUid(pid); adflowVo.setOutUids(outUids); vo.setAdflowvo(adflowVo); executeOrders.add(adflowVo.getUid()); } if(mathfunc!=null){ MathFuncflowVo mathfuncflowvo = new MathFuncflowVo(); mathfuncflowvo.setUid("mathFunc1"); mathfuncflowvo.setName("MathFunc"); mathfuncflowvo.setInUids(findMathFuncInParaVos(pid,mathfunc)); mathfuncflowvo.setOutUids(findMathFuncOutParaVos(pid,mathfunc)); vo.setMathfuncflowvo(mathfuncflowvo); executeOrders.add(mathfuncflowvo.getUid()); } vo.setExecuteorders(executeOrders); List paravos = getAllParaVos(pid); //TODO ffd 问题 for (ParaVo pvo:paravos) { if(pvo.getLable().equals("localFFD")){ pvo.setLable("FFD"); } } vo.setParavos(paravos); return vo; } private static List getAllParaVos(String pid) { List paravos =new ArrayList<>(); paravos.addAll(findMathFuncInMySelfParaVos(pid));//自建 MathFunc in //in param List inPlist = getInParaVos(pid); paravos.addAll(inPlist); //mathfunc 自动流转变量 List mathfuncInPram = getMathFuncZdlz(pid); paravos.addAll(mathfuncInPram); List allUid = findAllOutUids(pid);// 可修改变量 for (String uid:allUid) { ParaVo pvo =new ParaVo(); pvo.setUid(uid); pvo.setLable(uid.substring(uid.lastIndexOf("/")+1,uid.length())); paravos.add(pvo); } List distinctList = paravos.stream().distinct().collect(Collectors.toList()); return distinctList; } private static List getMathFuncZdlz(String pid){ List mathfuncInPrams = new ArrayList<>(); MdoProInoutParaMapper dao = UtilTools.getBean(MdoProInoutParaMapper.class); MdoProInoutParaSQLBuilder sb = new MdoProInoutParaSQLBuilder(); MdoProInoutParaSQLBuilder.Criteria sc = sb.createCriteria(); sc.andPidEqualTo(pid); sc.andComtypeEqualTo(Integer.valueOf(ComType.MathFunc.getIndex()));//match sc.andFlagEqualTo(1);//启用 sc.andTypeEqualTo(1);//输入参数 sc.andFcomidIsNotNull();//非自建 List paras = dao.selectByExample(sb); for (MdoProInoutPara para:paras) { ParaVo vo = new ParaVo(); String uid ; uid =MdoUidUtils.getUidByComTyeAndPcode(para.getComtype().toString(),para.getCode()); vo.setUid(uid); vo.setLable(para.getCode()); mathfuncInPrams.add(vo); } return mathfuncInPrams; } private static List getInParaVos(String pid) { MdoProjectVariateMapper vDao =UtilTools.getBean(MdoProjectVariateMapper.class); MdoProjectVariateSQLBuilder vsb = new MdoProjectVariateSQLBuilder(); vsb.createCriteria().andPidEqualTo(pid); List vList =vDao.selectByExample(vsb); Set inParas = new HashSet<>(); for (MdoProjectVariate v:vList) { ParaVo p= new ParaVo(); p.setLable(v.getName()); p.setUid(v.getUid()); inParas.add(p); } List inPlist = new ArrayList<>(inParas); return inPlist; } private static List findMathFuncInMySelfParaVos(String pid) { List inParaVos = new ArrayList<>(); MdoProInoutParaMapper dao = UtilTools.getBean(MdoProInoutParaMapper.class); MdoProInoutParaSQLBuilder sb = new MdoProInoutParaSQLBuilder(); MdoProInoutParaSQLBuilder.Criteria sc = sb.createCriteria(); sc.andPidEqualTo(pid); sc.andComtypeEqualTo(Integer.valueOf(ComType.MathFunc.getIndex())); sc.andFlagEqualTo(1);//启用 sc.andTypeEqualTo(1);//输入参数 sc.andFcomidIsNull();//自建 List paras = dao.selectByExample(sb); for (MdoProInoutPara para:paras) { ParaVo vo = new ParaVo(); String uid ; uid =MdoUidUtils.getUidByComTyeAndPcode(para.getComtype().toString(),para.getCode()); vo.setUid(uid); vo.setLable(para.getName()); inParaVos.add(vo); } return inParaVos; } private static List findAllOutUids(String pid) { MdoMapper mDao = UtilTools.getBean(MdoMapper.class); List uids = mDao.selectAllOutUid(pid); return uids; } private static List findMathFuncOutParaVos(String pid,MdoProMathfunc mathfunc) { List outParaVos = new ArrayList<>(); MdoProInoutParaMapper dao = UtilTools.getBean(MdoProInoutParaMapper.class); MdoProInoutParaSQLBuilder sb = new MdoProInoutParaSQLBuilder(); MdoProInoutParaSQLBuilder.Criteria sc = sb.createCriteria(); sc.andPidEqualTo(pid); sc.andComtypeEqualTo(Integer.valueOf(ComType.MathFunc.getIndex())); sc.andFlagEqualTo(1);//启用 sc.andTypeEqualTo(2);//输出参数 sc.andFatheridEqualTo(mathfunc.getId()); List paras = dao.selectByExample(sb); for (MdoProInoutPara para:paras) { ParaVo vo = new ParaVo(); String uid ; if(para.getFcomtype()!=null){//来源 uid =MdoUidUtils.getUidByComTyeAndPcode(para.getFcomtype().toString(),para.getCode()); }else{ uid =MdoUidUtils.getUidByComTyeAndPcode(para.getComtype().toString(),para.getCode()); } vo.setUid(uid); String[] pythons = mathfunc.getEquation().split("\n"); for (String py:pythons) { if(py.startsWith(para.getCode()+"=")){ vo.setLable(py.replace(para.getCode()+"=","")); } } outParaVos.add(vo); } return outParaVos; } private static List findMathFuncInParaVos(String pid,MdoProMathfunc mathfunc) { List inParaVos = new ArrayList<>(); MdoProInoutParaMapper dao = UtilTools.getBean(MdoProInoutParaMapper.class); MdoProInoutParaSQLBuilder sb = new MdoProInoutParaSQLBuilder(); MdoProInoutParaSQLBuilder.Criteria sc = sb.createCriteria(); sc.andPidEqualTo(pid); sc.andComtypeEqualTo(Integer.valueOf(ComType.MathFunc.getIndex())); sc.andFlagEqualTo(1);//启用 sc.andTypeEqualTo(1);//输入参数 sc.andFatheridEqualTo(mathfunc.getId()); List paras = dao.selectByExample(sb); for (MdoProInoutPara para:paras) { ParaVo vo = new ParaVo(); String uid ; if(para.getFcomtype()!=null){//来源 uid =MdoUidUtils.getUidByComTyeAndPcode(para.getFcomtype().toString(),para.getCode()); }else{ uid =MdoUidUtils.getUidByComTyeAndPcode(para.getComtype().toString(),para.getCode()); } vo.setUid(uid); vo.setLable(para.getName()); inParaVos.add(vo); } return inParaVos; } private static List findAdflowOutUid(String pid) { List outUids = new ArrayList<>(); MdoMapper mDao = UtilTools.getBean(MdoMapper.class); List cuids = mDao.selectAdflowCuids(pid); List ouids = mDao.selectAdflowOuids(pid); outUids.addAll(cuids); outUids.addAll(ouids); return outUids; } private static List findAdflowInUids(String pid) { MdoMapper mDao = UtilTools.getBean(MdoMapper.class); List vuids = mDao.selectAdflowVuids(pid); return vuids; } private static List findXfoilOutUid(String pid) { List outUids = new ArrayList<>(); MdoMapper mDao = UtilTools.getBean(MdoMapper.class); List cuids = mDao.selectXfoilCuids(pid); List ouids = mDao.selectXfoilOuids(pid); outUids.addAll(cuids); outUids.addAll(ouids); return outUids; } private static List findXfoilInUids(String pid) { MdoMapper mDao = UtilTools.getBean(MdoMapper.class); List vuids = mDao.selectXfoilVuids(pid); return vuids; } private static List findFsiOutUid(String pid) { List outUids = new ArrayList<>(); MdoMapper mDao = UtilTools.getBean(MdoMapper.class); List cuids = mDao.selectFsiCuids(pid); List ouids = mDao.selectFsiOuids(pid); outUids.addAll(cuids); outUids.addAll(ouids); //自动流转变量 List mathfuncInPrams = getMathFuncZdlz(pid); for (ParaVo vo:mathfuncInPrams) { outUids.add(vo.getUid()); } return outUids; } private static List findFsiInUids(String pid) { MdoMapper mDao = UtilTools.getBean(MdoMapper.class); List vuids = mDao.selectFsiVuids(pid); return vuids; } public static CpacsVo getCpacsVo(String pid) { CpacsVo vo = new CpacsVo(); HeaderVo header =new HeaderVo(); header.setName(pid); header.setTimestamp(new Date()); vo.setHeader(header); MdoProXfoil xfoil = findXfoil(pid); vo.setXfoil(xfoil); MdoProAdflow adflow = findAdflow(pid); vo.setAdflow(adflow); MdoProMathfunc mathfunc = findMashfunc(pid); vo.setMathfunc(mathfunc); MdoProTacs tacs = findTasc(pid); if(tacs!=null){ tacs.setThickness(tacs.getThickness().replace(",",";")); } vo.setTacs(tacs); MdoProFsi fsi =findFsi(pid); vo.setFsi(fsi); //不用生成 if(xfoil==null && adflow==null && mathfunc==null){ return null; } if(xfoil!=null){ List xInoutList = findMdoProInoutParas(pid, xfoil.getId()); XfoilInVo xinvo = new XfoilInVo(); // alpha mach reynolds xinvo.setAlpha(getValByParaListAndCode(xInoutList,"alpha")); xinvo.setMach(getValByParaListAndCode(xInoutList,"mach")); xinvo.setReynolds(getValByParaListAndCode(xInoutList,"reynolds")); vo.setXinvo(xinvo); XfoilOutVo xoutvo = new XfoilOutVo(); xoutvo.setCl(getValByParaListAndCode(xInoutList,"cl")); xoutvo.setCd(getValByParaListAndCode(xInoutList,"cd")); xoutvo.setCdp(getValByParaListAndCode(xInoutList,"cdp")); xoutvo.setCm(getValByParaListAndCode(xInoutList,"cm")); xoutvo.setXtr_upper(getValByParaListAndCode(xInoutList,"xtr_upper")); xoutvo.setXtr_lower(getValByParaListAndCode(xInoutList,"xtr_lower")); vo.setXoutvo(xoutvo); } if(adflow!=null){ List adInoutList = findMdoProInoutParas(pid, adflow.getId()); AdflowInVo adinvo = new AdflowInVo(); adinvo.setMode(getValByParaListAndCode(adInoutList,"mode")); adinvo.setAlpha(getValByParaListAndCode(adInoutList,"alpha")); adinvo.setMach(getValByParaListAndCode(adInoutList,"mach")); adinvo.setReynolds(getValByParaListAndCode(adInoutList,"reynolds")); adinvo.setTemperature(getValByParaListAndCode(adInoutList,"temperature")); adinvo.setReynoldsLength(getValByParaListAndCode(adInoutList,"reynoldsLength")); vo.setAdinvo(adinvo); AdflowOutVo adoutvo = new AdflowOutVo(); String cl = getValByParaListAndCode(adInoutList,"cl"); if("false".equals(cl)){ adoutvo.setIscl(false); }else{ adoutvo.setIscl(true); adoutvo.setCl(cl); } String cd = getValByParaListAndCode(adInoutList,"cd"); if("false".equals(cd)){ adoutvo.setIscd(false); }else{ adoutvo.setIscd(true); adoutvo.setCd(cd); } String cmz = getValByParaListAndCode(adInoutList,"cmz"); if("false".equals(cmz)){ adoutvo.setIscmz(false); }else{ adoutvo.setIscmz(true); adoutvo.setCmz(cmz); } String cmy = getValByParaListAndCode(adInoutList,"cmy"); if("false".equals(cmy)){ adoutvo.setIscmy(false); }else{ adoutvo.setIscmy(true); adoutvo.setCmy(cmy); } vo.setAdoutvo(adoutvo); } if(tacs!=null){ List adInoutList = findMdoProInoutParas(pid, tacs.getId()); TacsOutVo tacsoutvo =new TacsOutVo(); String mass = getValByParaListAndCode(adInoutList,"mass"); if("false".equals(mass)){ tacsoutvo.setIsmass(false); }else{ tacsoutvo.setIsmass(true); tacsoutvo.setMass(mass); } String ks_vmfailure = getValByParaListAndCode(adInoutList,"ks_vmfailure"); if("false".equals(ks_vmfailure)){ tacsoutvo.setIsks_vmfailure(false); }else{ tacsoutvo.setIsks_vmfailure(true); tacsoutvo.setKs_vmfailure(ks_vmfailure); } String maxdeform = getValByParaListAndCode(adInoutList,"maxdeform"); if("false".equals(maxdeform)){ tacsoutvo.setIsmaxdeform(false); }else{ tacsoutvo.setIsmaxdeform(true); tacsoutvo.setMaxdeform(maxdeform); } vo.setTacsoutvo(tacsoutvo); } if(mathfunc!=null){ List adInoutList = findMdoProInoutParas(pid, mathfunc.getId()); List tList = adInoutList.stream().filter(x ->{ return x.getFcomid()==null; }).collect(Collectors.toList()); List mathfuncvos= new ArrayList<>(); for (MdoProInoutPara p:tList) { MathfuncVo mathfuncVo =new MathfuncVo(); mathfuncVo.setCode(p.getCode()); mathfuncVo.setValue(p.getValue()); mathfuncvos.add(mathfuncVo); } vo.setMathfuncvos(mathfuncvos); } MdoProCst cst = findCst(pid); vo.setCst(cst); MdoProFfd ffd = getFfd(pid); vo.setFfd(ffd); return vo; } private static MdoProFsi findFsi(String pid) { MdoProFsiMapper xdao = UtilTools.getBean(MdoProFsiMapper.class); MdoProFsiSQLBuilder xsb = new MdoProFsiSQLBuilder(); MdoProFsiSQLBuilder.Criteria xsc =xsb.createCriteria(); xsc.andPidEqualTo(pid); List xList = xdao.selectByExample(xsb); MdoProFsi fsi =null; if(xList!=null&&!xList.isEmpty()){ fsi=xList.get(0); } return fsi; } private static MdoProTacs findTasc(String pid) { MdoProTacsMapper xdao = UtilTools.getBean(MdoProTacsMapper.class); MdoProTacsSQLBuilder xsb = new MdoProTacsSQLBuilder(); MdoProTacsSQLBuilder.Criteria xsc =xsb.createCriteria(); xsc.andPidEqualTo(pid); List xList = xdao.selectByExample(xsb); MdoProTacs tacs =null; if(xList!=null&&!xList.isEmpty()){ tacs=xList.get(0); } return tacs; } private static List findMdoProInoutParas(String pid, String fatherid) { MdoProInoutParaMapper xdao = UtilTools.getBean(MdoProInoutParaMapper.class); MdoProInoutParaSQLBuilder xsb = new MdoProInoutParaSQLBuilder(); MdoProInoutParaSQLBuilder.Criteria xsc =xsb.createCriteria(); xsc.andPidEqualTo(pid); xsc.andFatheridEqualTo(fatherid); xsc.andFlagEqualTo(1);//已选择的 List inList = xdao.selectByExample(xsb); return inList; } private static String getValByParaListAndCode(List inList,String code) { String value ="0"; List tList = inList.stream().filter(x ->{ return code.equals(x.getCode()); }).collect(Collectors.toList()); if(tList!=null&&!tList.isEmpty()){ value = tList.get(0).getValue(); }else{ value ="false"; } return value; } private static MdoProMathfunc findMashfunc(String pid) { MdoProMathfuncMapper mdao = UtilTools.getBean(MdoProMathfuncMapper.class); MdoProMathfuncSQLBuilder sb = new MdoProMathfuncSQLBuilder(); MdoProMathfuncSQLBuilder.Criteria sc =sb.createCriteria(); sc.andPidEqualTo(pid); List mList = mdao.selectByExample(sb); MdoProMathfunc m =null; if(mList!=null&&!mList.isEmpty()){ m=mList.get(0); } return m; } private static MdoProFfd getFfd(String pid) { MdoProFfdMapper xdao = UtilTools.getBean(MdoProFfdMapper.class); MdoProFfdSQLBuilder xsb = new MdoProFfdSQLBuilder(); MdoProFfdSQLBuilder.Criteria xsc =xsb.createCriteria(); xsc.andPidEqualTo(pid); xsc.andCheckedEqualTo(1); List xList = xdao.selectByExample(xsb); MdoProFfd ffd =null; if(xList!=null&&!xList.isEmpty()){ ffd=xList.get(0); } return ffd; } private static MdoProCst findCst(String pid) { MdoProCstMapper xdao = UtilTools.getBean(MdoProCstMapper.class); MdoProCstSQLBuilder xsb = new MdoProCstSQLBuilder(); MdoProCstSQLBuilder.Criteria xsc =xsb.createCriteria(); xsc.andPidEqualTo(pid); xsc.andCheckedEqualTo(1); List xList = xdao.selectByExample(xsb); MdoProCst cst =null; if(xList!=null&&!xList.isEmpty()){ cst=xList.get(0); } return cst; } private static MdoProAdflow findAdflow(String pid) { MdoProAdflowMapper xdao = UtilTools.getBean(MdoProAdflowMapper.class); MdoProAdflowSQLBuilder xsb = new MdoProAdflowSQLBuilder(); MdoProAdflowSQLBuilder.Criteria xsc =xsb.createCriteria(); xsc.andPidEqualTo(pid); xsc.andCheckedEqualTo(1); List xList = xdao.selectByExample(xsb); MdoProAdflow adflow =null; if(xList!=null&&!xList.isEmpty()){ adflow=xList.get(0); } return adflow; } private static MdoProXfoil findXfoil(String pid) { MdoProXfoilMapper xdao = UtilTools.getBean(MdoProXfoilMapper.class); MdoProXfoilSQLBuilder xsb = new MdoProXfoilSQLBuilder(); MdoProXfoilSQLBuilder.Criteria xsc =xsb.createCriteria(); xsc.andPidEqualTo(pid); xsc.andCheckedEqualTo(1); List xList = xdao.selectByExample(xsb); MdoProXfoil xfoil =null; if(xList!=null&&!xList.isEmpty()){ xfoil=xList.get(0); } return xfoil; } /** * TODO 创建 workflowXml * @return */ public static String createcWorkflowXml3(String pid,WorkflowVo vo){ try { if(vo ==null){ return null; } Configuration cfg = new Configuration(Configuration.VERSION_2_3_0); // 设置模板所在目录 cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates"); // 获取模板对象 Template template = cfg.getTemplate("workflow3.ftl"); // 定义数据模型(Map) Map dataModel = new HashMap<>(); // CpacsVo vo = getCpacsVo(pid); dataModel.put("vo",vo); //dataModel.put("geoFilePath", BPATH + "/" + aid + "/" + jid + "/Geometry"); // 将数据模型传入模板进行处理 StringWriter writer = new StringWriter(); template.process(dataModel, writer); FileWriter fileWriter = new FileWriter(LogService.BPATH + "/" + pid + "/in/workflow.xml"); fileWriter.write(writer.toString()); fileWriter.close(); return LogService.BPATH + "/" + pid + "/in/workflow.xml"; }catch (Exception e){ return null; } } /** * TODO 创建 workflowXml * @return */ public static String createcWorkflowXml2(String pid,WorkflowVo vo){ try { if(vo ==null){ return null; } Configuration cfg = new Configuration(Configuration.VERSION_2_3_0); // 设置模板所在目录 cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates"); // 获取模板对象 Template template = cfg.getTemplate("workflow2.ftl"); // 定义数据模型(Map) Map dataModel = new HashMap<>(); // CpacsVo vo = getCpacsVo(pid); dataModel.put("vo",vo); //dataModel.put("geoFilePath", BPATH + "/" + aid + "/" + jid + "/Geometry"); // 将数据模型传入模板进行处理 StringWriter writer = new StringWriter(); template.process(dataModel, writer); FileWriter fileWriter = new FileWriter(LogService.BPATH + "/" + pid + "/in/workflow.xml"); fileWriter.write(writer.toString()); fileWriter.close(); return LogService.BPATH + "/" + pid + "/in/workflow.xml"; }catch (Exception e){ return null; } } /** * TODO 创建 workflowXml * @return */ public static String createcWorkflowXml(String pid,WorkflowVo vo){ try { if(vo ==null){ return null; } Configuration cfg = new Configuration(Configuration.VERSION_2_3_0); // 设置模板所在目录 cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates"); // 获取模板对象 Template template = cfg.getTemplate("workflow.ftl"); // 定义数据模型(Map) Map dataModel = new HashMap<>(); // CpacsVo vo = getCpacsVo(pid); dataModel.put("vo",vo); //dataModel.put("geoFilePath", BPATH + "/" + aid + "/" + jid + "/Geometry"); // 将数据模型传入模板进行处理 StringWriter writer = new StringWriter(); template.process(dataModel, writer); FileWriter fileWriter = new FileWriter(LogService.BPATH + "/" + pid + "/in/workflow.xml"); fileWriter.write(writer.toString()); fileWriter.close(); return LogService.BPATH + "/" + pid + "/in/workflow.xml"; }catch (Exception e){ return null; } } /** * @return */ public static String createcWorkflowXmlT(String pid,WorkflowVo vo){ try { if(vo ==null){ return null; } Configuration cfg = new Configuration(Configuration.VERSION_2_3_0); // 设置模板所在目录 cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates"); // 获取模板对象 Template template = cfg.getTemplate("workflow_t.ftl"); // 定义数据模型(Map) Map dataModel = new HashMap<>(); dataModel.put("vo",vo); //dataModel.put("geoFilePath", BPATH + "/" + aid + "/" + jid + "/Geometry"); // 将数据模型传入模板进行处理 StringWriter writer = new StringWriter(); template.process(dataModel, writer); FileWriter fileWriter = new FileWriter(LogService.BPATH + "/" + pid + "/in/workflow.xml"); fileWriter.write(writer.toString()); fileWriter.close(); return LogService.BPATH + "/" + pid + "/in/workflow.xml"; }catch (Exception e){ return null; } } private static MdoProGrad findGrad(String pid) { MdoProGrad grad = null; MdoProGradMapper edao = UtilTools.getBean(MdoProGradMapper.class); MdoProGradSQLBuilder esb =new MdoProGradSQLBuilder(); MdoProGradSQLBuilder.Criteria esc = esb.createCriteria(); esc.andPidEqualTo(pid); esc.andCheckedEqualTo((short) 1); List eList = edao.selectByExample(esb); if(eList==null || eList.isEmpty()){ grad=null; }else{ grad = eList.get(0); } return grad; } private static MdoProSurro findSurro(String pid) { MdoProSurro surro = null; MdoProSurroMapper edao = UtilTools.getBean(MdoProSurroMapper.class); MdoProSurroSQLBuilder esb =new MdoProSurroSQLBuilder(); MdoProSurroSQLBuilder.Criteria esc = esb.createCriteria(); esc.andPidEqualTo(pid); esc.andCheckedEqualTo((short) 1); List eList = edao.selectByExample(esb); if(eList==null || eList.isEmpty()){ surro=null; }else{ surro = eList.get(0); } return surro; } private static MdoProEvolution findEvolution(String pid) { MdoProEvolution evolution = null; MdoProEvolutionMapper edao = UtilTools.getBean(MdoProEvolutionMapper.class); MdoProEvolutionSQLBuilder esb =new MdoProEvolutionSQLBuilder(); MdoProEvolutionSQLBuilder.Criteria esc = esb.createCriteria(); esc.andPidEqualTo(pid); esc.andCheckedEqualTo((short) 1); List eList = edao.selectByExample(esb); if(eList==null || eList.isEmpty()){ evolution=null; }else{ evolution = eList.get(0); } return evolution; } private static List findConstraints(String pid) { List constraints = new ArrayList<>(); MdoProjectConstraintMapper cdao = UtilTools.getBean(MdoProjectConstraintMapper.class); MdoProjectConstraintSQLBuilder csb = new MdoProjectConstraintSQLBuilder(); csb.createCriteria().andPidEqualTo(pid); List cList = cdao.selectByExample(csb); for (MdoProjectConstraint c:cList) { Constraint vc =new Constraint(); vc.setuID(c.getUid()!=null?c.getUid():c.getId()); vc.setName(c.getName()); vc.setValue(c.getReference()); vc.setLower(c.getLower()); vc.setUpper(c.getUpper()); constraints.add(vc); } return constraints; } private static List findObjectives(String pid) { List objectives = new ArrayList<>(); MdoProjectObjfunMapper objdao = UtilTools.getBean(MdoProjectObjfunMapper.class); MdoProjectObjfunSQLBuilder objsb = new MdoProjectObjfunSQLBuilder(); objsb.createCriteria().andPidEqualTo(pid); List objList =objdao.selectByExample(objsb); for (MdoProjectObjfun obj:objList) { Objective vObj =new Objective(); vObj.setuID(obj.getUid()!=null?obj.getUid():obj.getId()); vObj.setName(obj.getName()); vObj.setValue(obj.getReference()); vObj.setWeight(obj.getWeight()); if("-1".equals(obj.getOptdir())){ //-1 最大化 1 最小化 vObj.setFlag("max"); }else{ vObj.setFlag("min"); } objectives.add(vObj); } return objectives; } /** * 查询设计变量 * @param pid * @return */ private static List findDesignVariables(String pid) { List designVariables =new ArrayList<>(); MdoProjectVariateMapper vDao =UtilTools.getBean(MdoProjectVariateMapper.class); MdoProjectVariateSQLBuilder vsb = new MdoProjectVariateSQLBuilder(); vsb.createCriteria().andPidEqualTo(pid); List vList =vDao.selectByExample(vsb); Map> vMap=new HashMap<>(); for (MdoProjectVariate v:vList) { String vName =v.getName(); if(vMap.get(vName)==null||vMap.get(vName).isEmpty()){ vMap.put(vName,new ArrayList<>()); vMap.get(vName).add(v); }else{ vMap.get(vName).add(v); } } Set vkeys =vMap.keySet(); for (String key : vkeys) { DesignVariable dv = new DesignVariable(); dv.setName(key); List tVlist =vMap.get(key); List values = new ArrayList<>(); List lowerbounds = new ArrayList<>(); List upperbounds = new ArrayList<>(); String uid = null; for (MdoProjectVariate tv:tVlist) { if(!StringUtil.isEmpty(tv.getUid())){ uid=tv.getUid(); } values.add(tv.getReference()); lowerbounds.add(tv.getLower()); upperbounds.add(tv.getUpper()); } dv.setValue(values); dv.setLowerbound(lowerbounds); dv.setUpperbound(upperbounds); dv.setuID(uid!=null?uid:UtilTools.getUUid());//TODO 目前结构不清 designVariables.add(dv); } return designVariables; } /** * python 控件写入 * @param pid * @return * @throws IOException */ public static String writePython(String pid) throws IOException { MdoProPythonMapper ppDao = UtilTools.getBean(MdoProPythonMapper.class); MdoProPythonSQLBuilder ppsb = new MdoProPythonSQLBuilder(); ppsb.createCriteria().andPidEqualTo(pid); List ppList = ppDao.selectByExample(ppsb); if(!ppList.isEmpty()){ String ppPath =LogService.BPATH+"/"+ pid+"/in/py.py"; MdoProPython pp =ppList.get(0); FileWriter writer =new FileWriter(ppPath); writer.write(pp.getPtython()); writer.close(); return ppPath; } return ""; } }