TemplateGenerator.java 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950
  1. package com.miniframe.modo.temp;
  2. import com.miniframe.core.ext.UtilTools;
  3. import com.miniframe.generate.appcode.ComType;
  4. import com.miniframe.mdo.service.LogService;
  5. import com.miniframe.mdo.utils.MdoUidUtils;
  6. import com.miniframe.model.mdo.*;
  7. import com.miniframe.model.mdo.dao.*;
  8. import com.miniframe.modo.temp.cpacs.*;
  9. import com.miniframe.modo.temp.problem.*;
  10. import com.miniframe.modo.temp.workflow.*;
  11. import freemarker.template.Configuration;
  12. import freemarker.template.Template;
  13. import freemarker.template.TemplateException;
  14. import tk.mybatis.mapper.util.StringUtil;
  15. import java.io.FileWriter;
  16. import java.io.IOException;
  17. import java.io.StringWriter;
  18. import java.util.*;
  19. import java.util.stream.Collectors;
  20. public class TemplateGenerator {
  21. /**
  22. * 创建 执行文件
  23. * @param pid
  24. * @throws IOException
  25. * @throws TemplateException
  26. */
  27. public static void createRunpy(String pid) throws IOException, TemplateException {
  28. Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
  29. // 设置模板所在目录
  30. cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
  31. // 获取模板对象
  32. Template template = cfg.getTemplate("run.ftl");
  33. // 定义数据模型(Map)
  34. Map<String, Object> dataModel = new HashMap<>();
  35. dataModel.put("problemPath",LogService.BPATH + "/" + pid + "/in/problem.xml");
  36. // 将数据模型传入模板进行处理
  37. StringWriter writer = new StringWriter();
  38. template.process(dataModel, writer);
  39. FileWriter fileWriter = new FileWriter(LogService.BPATH + "/" + pid + "/in/run.py");
  40. fileWriter.write(writer.toString());
  41. fileWriter.close();
  42. }
  43. /**
  44. * 创建 执行文件
  45. * @param pid
  46. * @throws IOException
  47. * @throws TemplateException
  48. */
  49. public static void createRunpy2(String pid) throws IOException, TemplateException {
  50. Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
  51. // 设置模板所在目录
  52. cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
  53. // 获取模板对象
  54. Template template = cfg.getTemplate("run2.ftl");
  55. // 定义数据模型(Map)
  56. Map<String, Object> dataModel = new HashMap<>();
  57. dataModel.put("problemPath",LogService.BPATH + "/" + pid + "/in/problem.xml");
  58. // 将数据模型传入模板进行处理
  59. StringWriter writer = new StringWriter();
  60. template.process(dataModel, writer);
  61. FileWriter fileWriter = new FileWriter(LogService.BPATH + "/" + pid + "/in/run.py");
  62. fileWriter.write(writer.toString());
  63. fileWriter.close();
  64. }
  65. /**
  66. * 创建problem.xml
  67. * @param pid
  68. * @throws IOException
  69. * @throws TemplateException
  70. */
  71. public static void createProblemXml(String pid,ProblemVo vo) throws IOException, TemplateException {
  72. //Problem.xml 写入
  73. Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
  74. // 设置模板所在目录
  75. cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
  76. // 获取模板对象
  77. Template template = cfg.getTemplate("problem.ftl");
  78. // 定义数据模型(Map)
  79. Map<String, Object> dataModel = new HashMap<>();
  80. // ProblemVo vo = findProblemVo(pid);
  81. dataModel.put("vo",vo);
  82. // dataModel.put("geoFilePath", BPATH + "/" + aid + "/" + jid + "/Geometry");
  83. // 将数据模型传入模板进行处理
  84. StringWriter writer = new StringWriter();
  85. template.process(dataModel, writer);
  86. FileWriter fileWriter = new FileWriter(LogService.BPATH + "/" + pid + "/in/problem.xml");
  87. fileWriter.write(writer.toString());
  88. fileWriter.close();
  89. }
  90. public static ProblemVo findProblemVo(String pid) throws IOException {
  91. ProblemVo vo = new ProblemVo();
  92. HeaderVo header =new HeaderVo();
  93. header.setName(pid);
  94. header.setTimestamp(new Date());
  95. vo.setHeader(header);
  96. List<DesignVariable> designVariables=findDesignVariables(pid);
  97. vo.setDesignVariables(designVariables);
  98. List<Objective> objectives = findObjectives(pid);
  99. vo.setObjectives(objectives);
  100. List<Constraint> constraints = findConstraints(pid);
  101. vo.setConstraints(constraints);
  102. MdoProEvolution evolution = findEvolution(pid);
  103. vo.setEvolution(evolution);
  104. MdoProSurro surro = findSurro(pid);
  105. vo.setSurro(surro);
  106. MdoProGrad grad = findGrad(pid);
  107. vo.setGrad(grad);
  108. return vo;
  109. }
  110. /**
  111. * TODO 创建 cpacsxml
  112. * @return
  113. */
  114. public static String createcCpacsXml(String pid,CpacsVo vo) {
  115. try {
  116. if(vo ==null){
  117. return null;
  118. }
  119. Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
  120. // 设置模板所在目录
  121. cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
  122. // 获取模板对象
  123. Template template = cfg.getTemplate("cpacs.ftl");
  124. // 定义数据模型(Map)
  125. Map<String, Object> dataModel = new HashMap<>();
  126. dataModel.put("vo",vo);
  127. //dataModel.put("geoFilePath", BPATH + "/" + aid + "/" + jid + "/Geometry");
  128. // 将数据模型传入模板进行处理
  129. StringWriter writer = new StringWriter();
  130. template.process(dataModel, writer);
  131. FileWriter fileWriter = new FileWriter(LogService.BPATH + "/" + pid + "/in/cpacs.xml");
  132. fileWriter.write(writer.toString());
  133. fileWriter.close();
  134. return LogService.BPATH + "/" + pid + "/in/cpacs.xml";
  135. }catch (Exception e){
  136. return null;
  137. }
  138. }
  139. public static WorkflowVo getWorkflowVo(String pid) {
  140. WorkflowVo vo = new WorkflowVo();
  141. MdoProXfoil xfoil = findXfoil(pid);
  142. MdoProAdflow adflow = findAdflow(pid);
  143. MdoProFsi fsi= findFsi(pid);
  144. MdoProMathfunc mathfunc = findMashfunc(pid);
  145. //不用生成
  146. if(xfoil==null&& adflow==null&&mathfunc==null){
  147. return null;
  148. }
  149. HeaderVo header =new HeaderVo();
  150. header.setName(pid);
  151. header.setTimestamp(new Date());
  152. vo.setHeader(header);
  153. List<String> executeOrders =new ArrayList<>();
  154. if(fsi!=null){
  155. FsiflowVo fsivo = new FsiflowVo();
  156. fsivo.setUid("aeroelastic");
  157. fsivo.setName("pyAeroelasticADJ");
  158. List<String> inUids = findFsiInUids(pid);
  159. fsivo.setInUids(inUids);
  160. List<String> outUids= findFsiOutUid(pid);
  161. fsivo.setOutUids(outUids);
  162. vo.setFsivo(fsivo);
  163. executeOrders.add(fsivo.getUid());
  164. }else if(xfoil!=null){
  165. XfoilflowVo xfoilvo = new XfoilflowVo();
  166. xfoilvo.setUid("xfoil");
  167. xfoilvo.setName("pyXFoil");
  168. List<String> inUids = findXfoilInUids(pid);
  169. xfoilvo.setInUids(inUids);
  170. List<String> outUids= findXfoilOutUid(pid);
  171. xfoilvo.setOutUids(outUids);
  172. vo.setXfoilvo(xfoilvo);
  173. executeOrders.add(xfoilvo.getUid());
  174. }else if(adflow!=null){
  175. AdflowVo adflowVo = new AdflowVo();
  176. adflowVo.setUid("ADflow");
  177. adflowVo.setName("pyADflow");
  178. List<String> inUids = findAdflowInUids(pid);
  179. adflowVo.setInUids(inUids);
  180. List<String> outUids= findAdflowOutUid(pid);
  181. adflowVo.setOutUids(outUids);
  182. vo.setAdflowvo(adflowVo);
  183. executeOrders.add(adflowVo.getUid());
  184. }
  185. if(mathfunc!=null){
  186. MathFuncflowVo mathfuncflowvo = new MathFuncflowVo();
  187. mathfuncflowvo.setUid("mathFunc1");
  188. mathfuncflowvo.setName("MathFunc");
  189. mathfuncflowvo.setInUids(findMathFuncInParaVos(pid,mathfunc));
  190. mathfuncflowvo.setOutUids(findMathFuncOutParaVos(pid,mathfunc));
  191. vo.setMathfuncflowvo(mathfuncflowvo);
  192. executeOrders.add(mathfuncflowvo.getUid());
  193. }
  194. vo.setExecuteorders(executeOrders);
  195. List<ParaVo> paravos = getAllParaVos(pid);
  196. //TODO ffd 问题
  197. for (ParaVo pvo:paravos) {
  198. if(pvo.getLable().equals("localFFD")){
  199. pvo.setLable("FFD");
  200. }
  201. }
  202. vo.setParavos(paravos);
  203. return vo;
  204. }
  205. private static List<ParaVo> getAllParaVos(String pid) {
  206. List<ParaVo> paravos =new ArrayList<>();
  207. paravos.addAll(findMathFuncInMySelfParaVos(pid));//自建 MathFunc in
  208. //in param
  209. List<ParaVo> inPlist = getInParaVos(pid);
  210. paravos.addAll(inPlist);
  211. //mathfunc 自动流转变量
  212. List<ParaVo> mathfuncInPram = getMathFuncZdlz(pid);
  213. paravos.addAll(mathfuncInPram);
  214. List<String> allUid = findAllOutUids(pid);// 可修改变量
  215. for (String uid:allUid) {
  216. ParaVo pvo =new ParaVo();
  217. pvo.setUid(uid);
  218. pvo.setLable(uid.substring(uid.lastIndexOf("/")+1,uid.length()));
  219. paravos.add(pvo);
  220. }
  221. List<ParaVo> distinctList = paravos.stream().distinct().collect(Collectors.toList());
  222. return distinctList;
  223. }
  224. private static List<ParaVo> getMathFuncZdlz(String pid){
  225. List<ParaVo> mathfuncInPrams = new ArrayList<>();
  226. MdoProInoutParaMapper dao = UtilTools.getBean(MdoProInoutParaMapper.class);
  227. MdoProInoutParaSQLBuilder sb = new MdoProInoutParaSQLBuilder();
  228. MdoProInoutParaSQLBuilder.Criteria sc = sb.createCriteria();
  229. sc.andPidEqualTo(pid);
  230. sc.andComtypeEqualTo(Integer.valueOf(ComType.MathFunc.getIndex()));//match
  231. sc.andFlagEqualTo(1);//启用
  232. sc.andTypeEqualTo(1);//输入参数
  233. sc.andFcomidIsNotNull();//非自建
  234. List<MdoProInoutPara> paras = dao.selectByExample(sb);
  235. for (MdoProInoutPara para:paras) {
  236. ParaVo vo = new ParaVo();
  237. String uid ;
  238. uid =MdoUidUtils.getUidByComTyeAndPcode(para.getComtype().toString(),para.getCode());
  239. vo.setUid(uid);
  240. vo.setLable(para.getCode());
  241. mathfuncInPrams.add(vo);
  242. }
  243. return mathfuncInPrams;
  244. }
  245. private static List<ParaVo> getInParaVos(String pid) {
  246. MdoProjectVariateMapper vDao =UtilTools.getBean(MdoProjectVariateMapper.class);
  247. MdoProjectVariateSQLBuilder vsb = new MdoProjectVariateSQLBuilder();
  248. vsb.createCriteria().andPidEqualTo(pid);
  249. List<MdoProjectVariate> vList =vDao.selectByExample(vsb);
  250. Set<ParaVo> inParas = new HashSet<>();
  251. for (MdoProjectVariate v:vList) {
  252. ParaVo p= new ParaVo();
  253. p.setLable(v.getName());
  254. p.setUid(v.getUid());
  255. inParas.add(p);
  256. }
  257. List<ParaVo> inPlist = new ArrayList<>(inParas);
  258. return inPlist;
  259. }
  260. private static List<ParaVo> findMathFuncInMySelfParaVos(String pid) {
  261. List<ParaVo> inParaVos = new ArrayList<>();
  262. MdoProInoutParaMapper dao = UtilTools.getBean(MdoProInoutParaMapper.class);
  263. MdoProInoutParaSQLBuilder sb = new MdoProInoutParaSQLBuilder();
  264. MdoProInoutParaSQLBuilder.Criteria sc = sb.createCriteria();
  265. sc.andPidEqualTo(pid);
  266. sc.andComtypeEqualTo(Integer.valueOf(ComType.MathFunc.getIndex()));
  267. sc.andFlagEqualTo(1);//启用
  268. sc.andTypeEqualTo(1);//输入参数
  269. sc.andFcomidIsNull();//自建
  270. List<MdoProInoutPara> paras = dao.selectByExample(sb);
  271. for (MdoProInoutPara para:paras) {
  272. ParaVo vo = new ParaVo();
  273. String uid ;
  274. uid =MdoUidUtils.getUidByComTyeAndPcode(para.getComtype().toString(),para.getCode());
  275. vo.setUid(uid);
  276. vo.setLable(para.getName());
  277. inParaVos.add(vo);
  278. }
  279. return inParaVos;
  280. }
  281. private static List<String> findAllOutUids(String pid) {
  282. MdoMapper mDao = UtilTools.getBean(MdoMapper.class);
  283. List<String> uids = mDao.selectAllOutUid(pid);
  284. return uids;
  285. }
  286. private static List<ParaVo> findMathFuncOutParaVos(String pid,MdoProMathfunc mathfunc) {
  287. List<ParaVo> outParaVos = new ArrayList<>();
  288. MdoProInoutParaMapper dao = UtilTools.getBean(MdoProInoutParaMapper.class);
  289. MdoProInoutParaSQLBuilder sb = new MdoProInoutParaSQLBuilder();
  290. MdoProInoutParaSQLBuilder.Criteria sc = sb.createCriteria();
  291. sc.andPidEqualTo(pid);
  292. sc.andComtypeEqualTo(Integer.valueOf(ComType.MathFunc.getIndex()));
  293. sc.andFlagEqualTo(1);//启用
  294. sc.andTypeEqualTo(2);//输出参数
  295. sc.andFatheridEqualTo(mathfunc.getId());
  296. List<MdoProInoutPara> paras = dao.selectByExample(sb);
  297. for (MdoProInoutPara para:paras) {
  298. ParaVo vo = new ParaVo();
  299. String uid ;
  300. if(para.getFcomtype()!=null){//来源
  301. uid =MdoUidUtils.getUidByComTyeAndPcode(para.getFcomtype().toString(),para.getCode());
  302. }else{
  303. uid =MdoUidUtils.getUidByComTyeAndPcode(para.getComtype().toString(),para.getCode());
  304. }
  305. vo.setUid(uid);
  306. String[] pythons = mathfunc.getEquation().split("\n");
  307. for (String py:pythons) {
  308. if(py.startsWith(para.getCode()+"=")){
  309. vo.setLable(py.replace(para.getCode()+"=",""));
  310. }
  311. }
  312. outParaVos.add(vo);
  313. }
  314. return outParaVos;
  315. }
  316. private static List<ParaVo> findMathFuncInParaVos(String pid,MdoProMathfunc mathfunc) {
  317. List<ParaVo> inParaVos = new ArrayList<>();
  318. MdoProInoutParaMapper dao = UtilTools.getBean(MdoProInoutParaMapper.class);
  319. MdoProInoutParaSQLBuilder sb = new MdoProInoutParaSQLBuilder();
  320. MdoProInoutParaSQLBuilder.Criteria sc = sb.createCriteria();
  321. sc.andPidEqualTo(pid);
  322. sc.andComtypeEqualTo(Integer.valueOf(ComType.MathFunc.getIndex()));
  323. sc.andFlagEqualTo(1);//启用
  324. sc.andTypeEqualTo(1);//输入参数
  325. sc.andFatheridEqualTo(mathfunc.getId());
  326. List<MdoProInoutPara> paras = dao.selectByExample(sb);
  327. for (MdoProInoutPara para:paras) {
  328. ParaVo vo = new ParaVo();
  329. String uid ;
  330. if(para.getFcomtype()!=null){//来源
  331. uid =MdoUidUtils.getUidByComTyeAndPcode(para.getFcomtype().toString(),para.getCode());
  332. }else{
  333. uid =MdoUidUtils.getUidByComTyeAndPcode(para.getComtype().toString(),para.getCode());
  334. }
  335. vo.setUid(uid);
  336. vo.setLable(para.getName());
  337. inParaVos.add(vo);
  338. }
  339. return inParaVos;
  340. }
  341. private static List<String> findAdflowOutUid(String pid) {
  342. List<String> outUids = new ArrayList<>();
  343. MdoMapper mDao = UtilTools.getBean(MdoMapper.class);
  344. List<String> cuids = mDao.selectAdflowCuids(pid);
  345. List<String> ouids = mDao.selectAdflowOuids(pid);
  346. outUids.addAll(cuids);
  347. outUids.addAll(ouids);
  348. return outUids;
  349. }
  350. private static List<String> findAdflowInUids(String pid) {
  351. MdoMapper mDao = UtilTools.getBean(MdoMapper.class);
  352. List<String> vuids = mDao.selectAdflowVuids(pid);
  353. return vuids;
  354. }
  355. private static List<String> findXfoilOutUid(String pid) {
  356. List<String> outUids = new ArrayList<>();
  357. MdoMapper mDao = UtilTools.getBean(MdoMapper.class);
  358. List<String> cuids = mDao.selectXfoilCuids(pid);
  359. List<String> ouids = mDao.selectXfoilOuids(pid);
  360. outUids.addAll(cuids);
  361. outUids.addAll(ouids);
  362. return outUids;
  363. }
  364. private static List<String> findXfoilInUids(String pid) {
  365. MdoMapper mDao = UtilTools.getBean(MdoMapper.class);
  366. List<String> vuids = mDao.selectXfoilVuids(pid);
  367. return vuids;
  368. }
  369. private static List<String> findFsiOutUid(String pid) {
  370. List<String> outUids = new ArrayList<>();
  371. MdoMapper mDao = UtilTools.getBean(MdoMapper.class);
  372. List<String> cuids = mDao.selectFsiCuids(pid);
  373. List<String> ouids = mDao.selectFsiOuids(pid);
  374. outUids.addAll(cuids);
  375. outUids.addAll(ouids);
  376. //自动流转变量
  377. List<ParaVo> mathfuncInPrams = getMathFuncZdlz(pid);
  378. for (ParaVo vo:mathfuncInPrams) {
  379. outUids.add(vo.getUid());
  380. }
  381. return outUids;
  382. }
  383. private static List<String> findFsiInUids(String pid) {
  384. MdoMapper mDao = UtilTools.getBean(MdoMapper.class);
  385. List<String> vuids = mDao.selectFsiVuids(pid);
  386. return vuids;
  387. }
  388. public static CpacsVo getCpacsVo(String pid) {
  389. CpacsVo vo = new CpacsVo();
  390. HeaderVo header =new HeaderVo();
  391. header.setName(pid);
  392. header.setTimestamp(new Date());
  393. vo.setHeader(header);
  394. MdoProXfoil xfoil = findXfoil(pid);
  395. vo.setXfoil(xfoil);
  396. MdoProAdflow adflow = findAdflow(pid);
  397. vo.setAdflow(adflow);
  398. MdoProMathfunc mathfunc = findMashfunc(pid);
  399. vo.setMathfunc(mathfunc);
  400. MdoProTacs tacs = findTasc(pid);
  401. if(tacs!=null){
  402. tacs.setThickness(tacs.getThickness().replace(",",";"));
  403. }
  404. vo.setTacs(tacs);
  405. MdoProFsi fsi =findFsi(pid);
  406. vo.setFsi(fsi);
  407. //不用生成
  408. if(xfoil==null && adflow==null && mathfunc==null){
  409. return null;
  410. }
  411. if(xfoil!=null){
  412. List<MdoProInoutPara> xInoutList = findMdoProInoutParas(pid, xfoil.getId());
  413. XfoilInVo xinvo = new XfoilInVo();
  414. // alpha mach reynolds
  415. xinvo.setAlpha(getValByParaListAndCode(xInoutList,"alpha"));
  416. xinvo.setMach(getValByParaListAndCode(xInoutList,"mach"));
  417. xinvo.setReynolds(getValByParaListAndCode(xInoutList,"reynolds"));
  418. vo.setXinvo(xinvo);
  419. XfoilOutVo xoutvo = new XfoilOutVo();
  420. xoutvo.setCl(getValByParaListAndCode(xInoutList,"cl"));
  421. xoutvo.setCd(getValByParaListAndCode(xInoutList,"cd"));
  422. xoutvo.setCdp(getValByParaListAndCode(xInoutList,"cdp"));
  423. xoutvo.setCm(getValByParaListAndCode(xInoutList,"cm"));
  424. xoutvo.setXtr_upper(getValByParaListAndCode(xInoutList,"xtr_upper"));
  425. xoutvo.setXtr_lower(getValByParaListAndCode(xInoutList,"xtr_lower"));
  426. vo.setXoutvo(xoutvo);
  427. }
  428. if(adflow!=null){
  429. List<MdoProInoutPara> adInoutList = findMdoProInoutParas(pid, adflow.getId());
  430. AdflowInVo adinvo = new AdflowInVo();
  431. adinvo.setMode(getValByParaListAndCode(adInoutList,"mode"));
  432. adinvo.setAlpha(getValByParaListAndCode(adInoutList,"alpha"));
  433. adinvo.setMach(getValByParaListAndCode(adInoutList,"mach"));
  434. adinvo.setReynolds(getValByParaListAndCode(adInoutList,"reynolds"));
  435. adinvo.setTemperature(getValByParaListAndCode(adInoutList,"temperature"));
  436. adinvo.setReynoldsLength(getValByParaListAndCode(adInoutList,"reynoldsLength"));
  437. vo.setAdinvo(adinvo);
  438. AdflowOutVo adoutvo = new AdflowOutVo();
  439. String cl = getValByParaListAndCode(adInoutList,"cl");
  440. if("false".equals(cl)){
  441. adoutvo.setIscl(false);
  442. }else{
  443. adoutvo.setIscl(true);
  444. adoutvo.setCl(cl);
  445. }
  446. String cd = getValByParaListAndCode(adInoutList,"cd");
  447. if("false".equals(cd)){
  448. adoutvo.setIscd(false);
  449. }else{
  450. adoutvo.setIscd(true);
  451. adoutvo.setCd(cd);
  452. }
  453. String cmz = getValByParaListAndCode(adInoutList,"cmz");
  454. if("false".equals(cmz)){
  455. adoutvo.setIscmz(false);
  456. }else{
  457. adoutvo.setIscmz(true);
  458. adoutvo.setCmz(cmz);
  459. }
  460. String cmy = getValByParaListAndCode(adInoutList,"cmy");
  461. if("false".equals(cmy)){
  462. adoutvo.setIscmy(false);
  463. }else{
  464. adoutvo.setIscmy(true);
  465. adoutvo.setCmy(cmy);
  466. }
  467. vo.setAdoutvo(adoutvo);
  468. }
  469. if(tacs!=null){
  470. List<MdoProInoutPara> adInoutList = findMdoProInoutParas(pid, tacs.getId());
  471. TacsOutVo tacsoutvo =new TacsOutVo();
  472. String mass = getValByParaListAndCode(adInoutList,"mass");
  473. if("false".equals(mass)){
  474. tacsoutvo.setIsmass(false);
  475. }else{
  476. tacsoutvo.setIsmass(true);
  477. tacsoutvo.setMass(mass);
  478. }
  479. String ks_vmfailure = getValByParaListAndCode(adInoutList,"ks_vmfailure");
  480. if("false".equals(ks_vmfailure)){
  481. tacsoutvo.setIsks_vmfailure(false);
  482. }else{
  483. tacsoutvo.setIsks_vmfailure(true);
  484. tacsoutvo.setKs_vmfailure(ks_vmfailure);
  485. }
  486. String maxdeform = getValByParaListAndCode(adInoutList,"maxdeform");
  487. if("false".equals(maxdeform)){
  488. tacsoutvo.setIsmaxdeform(false);
  489. }else{
  490. tacsoutvo.setIsmaxdeform(true);
  491. tacsoutvo.setMaxdeform(maxdeform);
  492. }
  493. vo.setTacsoutvo(tacsoutvo);
  494. }
  495. if(mathfunc!=null){
  496. List<MdoProInoutPara> adInoutList = findMdoProInoutParas(pid, mathfunc.getId());
  497. List<MdoProInoutPara> tList = adInoutList.stream().filter(x ->{
  498. return x.getFcomid()==null;
  499. }).collect(Collectors.toList());
  500. List<MathfuncVo> mathfuncvos= new ArrayList<>();
  501. for (MdoProInoutPara p:tList) {
  502. MathfuncVo mathfuncVo =new MathfuncVo();
  503. mathfuncVo.setCode(p.getCode());
  504. mathfuncVo.setValue(p.getValue());
  505. mathfuncvos.add(mathfuncVo);
  506. }
  507. vo.setMathfuncvos(mathfuncvos);
  508. }
  509. MdoProCst cst = findCst(pid);
  510. vo.setCst(cst);
  511. MdoProFfd ffd = getFfd(pid);
  512. vo.setFfd(ffd);
  513. return vo;
  514. }
  515. private static MdoProFsi findFsi(String pid) {
  516. MdoProFsiMapper xdao = UtilTools.getBean(MdoProFsiMapper.class);
  517. MdoProFsiSQLBuilder xsb = new MdoProFsiSQLBuilder();
  518. MdoProFsiSQLBuilder.Criteria xsc =xsb.createCriteria();
  519. xsc.andPidEqualTo(pid);
  520. List<MdoProFsi> xList = xdao.selectByExample(xsb);
  521. MdoProFsi fsi =null;
  522. if(xList!=null&&!xList.isEmpty()){
  523. fsi=xList.get(0);
  524. }
  525. return fsi;
  526. }
  527. private static MdoProTacs findTasc(String pid) {
  528. MdoProTacsMapper xdao = UtilTools.getBean(MdoProTacsMapper.class);
  529. MdoProTacsSQLBuilder xsb = new MdoProTacsSQLBuilder();
  530. MdoProTacsSQLBuilder.Criteria xsc =xsb.createCriteria();
  531. xsc.andPidEqualTo(pid);
  532. List<MdoProTacs> xList = xdao.selectByExample(xsb);
  533. MdoProTacs tacs =null;
  534. if(xList!=null&&!xList.isEmpty()){
  535. tacs=xList.get(0);
  536. }
  537. return tacs;
  538. }
  539. private static List<MdoProInoutPara> findMdoProInoutParas(String pid, String fatherid) {
  540. MdoProInoutParaMapper xdao = UtilTools.getBean(MdoProInoutParaMapper.class);
  541. MdoProInoutParaSQLBuilder xsb = new MdoProInoutParaSQLBuilder();
  542. MdoProInoutParaSQLBuilder.Criteria xsc =xsb.createCriteria();
  543. xsc.andPidEqualTo(pid);
  544. xsc.andFatheridEqualTo(fatherid);
  545. xsc.andFlagEqualTo(1);//已选择的
  546. List<MdoProInoutPara> inList = xdao.selectByExample(xsb);
  547. return inList;
  548. }
  549. private static String getValByParaListAndCode(List<MdoProInoutPara> inList,String code) {
  550. String value ="0";
  551. List<MdoProInoutPara> tList = inList.stream().filter(x ->{
  552. return code.equals(x.getCode());
  553. }).collect(Collectors.toList());
  554. if(tList!=null&&!tList.isEmpty()){
  555. value = tList.get(0).getValue();
  556. }else{
  557. value ="false";
  558. }
  559. return value;
  560. }
  561. private static MdoProMathfunc findMashfunc(String pid) {
  562. MdoProMathfuncMapper mdao = UtilTools.getBean(MdoProMathfuncMapper.class);
  563. MdoProMathfuncSQLBuilder sb = new MdoProMathfuncSQLBuilder();
  564. MdoProMathfuncSQLBuilder.Criteria sc =sb.createCriteria();
  565. sc.andPidEqualTo(pid);
  566. List<MdoProMathfunc> mList = mdao.selectByExample(sb);
  567. MdoProMathfunc m =null;
  568. if(mList!=null&&!mList.isEmpty()){
  569. m=mList.get(0);
  570. }
  571. return m;
  572. }
  573. private static MdoProFfd getFfd(String pid) {
  574. MdoProFfdMapper xdao = UtilTools.getBean(MdoProFfdMapper.class);
  575. MdoProFfdSQLBuilder xsb = new MdoProFfdSQLBuilder();
  576. MdoProFfdSQLBuilder.Criteria xsc =xsb.createCriteria();
  577. xsc.andPidEqualTo(pid);
  578. xsc.andCheckedEqualTo(1);
  579. List<MdoProFfd> xList = xdao.selectByExample(xsb);
  580. MdoProFfd ffd =null;
  581. if(xList!=null&&!xList.isEmpty()){
  582. ffd=xList.get(0);
  583. }
  584. return ffd;
  585. }
  586. private static MdoProCst findCst(String pid) {
  587. MdoProCstMapper xdao = UtilTools.getBean(MdoProCstMapper.class);
  588. MdoProCstSQLBuilder xsb = new MdoProCstSQLBuilder();
  589. MdoProCstSQLBuilder.Criteria xsc =xsb.createCriteria();
  590. xsc.andPidEqualTo(pid);
  591. xsc.andCheckedEqualTo(1);
  592. List<MdoProCst> xList = xdao.selectByExample(xsb);
  593. MdoProCst cst =null;
  594. if(xList!=null&&!xList.isEmpty()){
  595. cst=xList.get(0);
  596. }
  597. return cst;
  598. }
  599. private static MdoProAdflow findAdflow(String pid) {
  600. MdoProAdflowMapper xdao = UtilTools.getBean(MdoProAdflowMapper.class);
  601. MdoProAdflowSQLBuilder xsb = new MdoProAdflowSQLBuilder();
  602. MdoProAdflowSQLBuilder.Criteria xsc =xsb.createCriteria();
  603. xsc.andPidEqualTo(pid);
  604. xsc.andCheckedEqualTo(1);
  605. List<MdoProAdflow> xList = xdao.selectByExample(xsb);
  606. MdoProAdflow adflow =null;
  607. if(xList!=null&&!xList.isEmpty()){
  608. adflow=xList.get(0);
  609. }
  610. return adflow;
  611. }
  612. private static MdoProXfoil findXfoil(String pid) {
  613. MdoProXfoilMapper xdao = UtilTools.getBean(MdoProXfoilMapper.class);
  614. MdoProXfoilSQLBuilder xsb = new MdoProXfoilSQLBuilder();
  615. MdoProXfoilSQLBuilder.Criteria xsc =xsb.createCriteria();
  616. xsc.andPidEqualTo(pid);
  617. xsc.andCheckedEqualTo(1);
  618. List<MdoProXfoil> xList = xdao.selectByExample(xsb);
  619. MdoProXfoil xfoil =null;
  620. if(xList!=null&&!xList.isEmpty()){
  621. xfoil=xList.get(0);
  622. }
  623. return xfoil;
  624. }
  625. /**
  626. * TODO 创建 workflowXml
  627. * @return
  628. */
  629. public static String createcWorkflowXml3(String pid,WorkflowVo vo){
  630. try {
  631. if(vo ==null){
  632. return null;
  633. }
  634. Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
  635. // 设置模板所在目录
  636. cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
  637. // 获取模板对象
  638. Template template = cfg.getTemplate("workflow3.ftl");
  639. // 定义数据模型(Map)
  640. Map<String, Object> dataModel = new HashMap<>();
  641. // CpacsVo vo = getCpacsVo(pid);
  642. dataModel.put("vo",vo);
  643. //dataModel.put("geoFilePath", BPATH + "/" + aid + "/" + jid + "/Geometry");
  644. // 将数据模型传入模板进行处理
  645. StringWriter writer = new StringWriter();
  646. template.process(dataModel, writer);
  647. FileWriter fileWriter = new FileWriter(LogService.BPATH + "/" + pid + "/in/workflow.xml");
  648. fileWriter.write(writer.toString());
  649. fileWriter.close();
  650. return LogService.BPATH + "/" + pid + "/in/workflow.xml";
  651. }catch (Exception e){
  652. return null;
  653. }
  654. }
  655. /**
  656. * TODO 创建 workflowXml
  657. * @return
  658. */
  659. public static String createcWorkflowXml2(String pid,WorkflowVo vo){
  660. try {
  661. if(vo ==null){
  662. return null;
  663. }
  664. Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
  665. // 设置模板所在目录
  666. cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
  667. // 获取模板对象
  668. Template template = cfg.getTemplate("workflow2.ftl");
  669. // 定义数据模型(Map)
  670. Map<String, Object> dataModel = new HashMap<>();
  671. // CpacsVo vo = getCpacsVo(pid);
  672. dataModel.put("vo",vo);
  673. //dataModel.put("geoFilePath", BPATH + "/" + aid + "/" + jid + "/Geometry");
  674. // 将数据模型传入模板进行处理
  675. StringWriter writer = new StringWriter();
  676. template.process(dataModel, writer);
  677. FileWriter fileWriter = new FileWriter(LogService.BPATH + "/" + pid + "/in/workflow.xml");
  678. fileWriter.write(writer.toString());
  679. fileWriter.close();
  680. return LogService.BPATH + "/" + pid + "/in/workflow.xml";
  681. }catch (Exception e){
  682. return null;
  683. }
  684. }
  685. /**
  686. * TODO 创建 workflowXml
  687. * @return
  688. */
  689. public static String createcWorkflowXml(String pid,WorkflowVo vo){
  690. try {
  691. if(vo ==null){
  692. return null;
  693. }
  694. Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
  695. // 设置模板所在目录
  696. cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
  697. // 获取模板对象
  698. Template template = cfg.getTemplate("workflow.ftl");
  699. // 定义数据模型(Map)
  700. Map<String, Object> dataModel = new HashMap<>();
  701. // CpacsVo vo = getCpacsVo(pid);
  702. dataModel.put("vo",vo);
  703. //dataModel.put("geoFilePath", BPATH + "/" + aid + "/" + jid + "/Geometry");
  704. // 将数据模型传入模板进行处理
  705. StringWriter writer = new StringWriter();
  706. template.process(dataModel, writer);
  707. FileWriter fileWriter = new FileWriter(LogService.BPATH + "/" + pid + "/in/workflow.xml");
  708. fileWriter.write(writer.toString());
  709. fileWriter.close();
  710. return LogService.BPATH + "/" + pid + "/in/workflow.xml";
  711. }catch (Exception e){
  712. return null;
  713. }
  714. }
  715. /**
  716. * @return
  717. */
  718. public static String createcWorkflowXmlT(String pid,WorkflowVo vo){
  719. try {
  720. if(vo ==null){
  721. return null;
  722. }
  723. Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
  724. // 设置模板所在目录
  725. cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
  726. // 获取模板对象
  727. Template template = cfg.getTemplate("workflow_t.ftl");
  728. // 定义数据模型(Map)
  729. Map<String, Object> dataModel = new HashMap<>();
  730. dataModel.put("vo",vo);
  731. //dataModel.put("geoFilePath", BPATH + "/" + aid + "/" + jid + "/Geometry");
  732. // 将数据模型传入模板进行处理
  733. StringWriter writer = new StringWriter();
  734. template.process(dataModel, writer);
  735. FileWriter fileWriter = new FileWriter(LogService.BPATH + "/" + pid + "/in/workflow.xml");
  736. fileWriter.write(writer.toString());
  737. fileWriter.close();
  738. return LogService.BPATH + "/" + pid + "/in/workflow.xml";
  739. }catch (Exception e){
  740. return null;
  741. }
  742. }
  743. private static MdoProGrad findGrad(String pid) {
  744. MdoProGrad grad = null;
  745. MdoProGradMapper edao = UtilTools.getBean(MdoProGradMapper.class);
  746. MdoProGradSQLBuilder esb =new MdoProGradSQLBuilder();
  747. MdoProGradSQLBuilder.Criteria esc = esb.createCriteria();
  748. esc.andPidEqualTo(pid);
  749. esc.andCheckedEqualTo((short) 1);
  750. List<MdoProGrad> eList = edao.selectByExample(esb);
  751. if(eList==null || eList.isEmpty()){
  752. grad=null;
  753. }else{
  754. grad = eList.get(0);
  755. }
  756. return grad;
  757. }
  758. private static MdoProSurro findSurro(String pid) {
  759. MdoProSurro surro = null;
  760. MdoProSurroMapper edao = UtilTools.getBean(MdoProSurroMapper.class);
  761. MdoProSurroSQLBuilder esb =new MdoProSurroSQLBuilder();
  762. MdoProSurroSQLBuilder.Criteria esc = esb.createCriteria();
  763. esc.andPidEqualTo(pid);
  764. esc.andCheckedEqualTo((short) 1);
  765. List<MdoProSurro> eList = edao.selectByExample(esb);
  766. if(eList==null || eList.isEmpty()){
  767. surro=null;
  768. }else{
  769. surro = eList.get(0);
  770. }
  771. return surro;
  772. }
  773. private static MdoProEvolution findEvolution(String pid) {
  774. MdoProEvolution evolution = null;
  775. MdoProEvolutionMapper edao = UtilTools.getBean(MdoProEvolutionMapper.class);
  776. MdoProEvolutionSQLBuilder esb =new MdoProEvolutionSQLBuilder();
  777. MdoProEvolutionSQLBuilder.Criteria esc = esb.createCriteria();
  778. esc.andPidEqualTo(pid);
  779. esc.andCheckedEqualTo((short) 1);
  780. List<MdoProEvolution> eList = edao.selectByExample(esb);
  781. if(eList==null || eList.isEmpty()){
  782. evolution=null;
  783. }else{
  784. evolution = eList.get(0);
  785. }
  786. return evolution;
  787. }
  788. private static List<Constraint> findConstraints(String pid) {
  789. List<Constraint> constraints = new ArrayList<>();
  790. MdoProjectConstraintMapper cdao = UtilTools.getBean(MdoProjectConstraintMapper.class);
  791. MdoProjectConstraintSQLBuilder csb = new MdoProjectConstraintSQLBuilder();
  792. csb.createCriteria().andPidEqualTo(pid);
  793. List<MdoProjectConstraint> cList = cdao.selectByExample(csb);
  794. for (MdoProjectConstraint c:cList) {
  795. Constraint vc =new Constraint();
  796. vc.setuID(c.getUid()!=null?c.getUid():c.getId());
  797. vc.setName(c.getName());
  798. vc.setValue(c.getReference());
  799. vc.setLower(c.getLower());
  800. vc.setUpper(c.getUpper());
  801. constraints.add(vc);
  802. }
  803. return constraints;
  804. }
  805. private static List<Objective> findObjectives(String pid) {
  806. List<Objective> objectives = new ArrayList<>();
  807. MdoProjectObjfunMapper objdao = UtilTools.getBean(MdoProjectObjfunMapper.class);
  808. MdoProjectObjfunSQLBuilder objsb = new MdoProjectObjfunSQLBuilder();
  809. objsb.createCriteria().andPidEqualTo(pid);
  810. List<MdoProjectObjfun> objList =objdao.selectByExample(objsb);
  811. for (MdoProjectObjfun obj:objList) {
  812. Objective vObj =new Objective();
  813. vObj.setuID(obj.getUid()!=null?obj.getUid():obj.getId());
  814. vObj.setName(obj.getName());
  815. vObj.setValue(obj.getReference());
  816. vObj.setWeight(obj.getWeight());
  817. if("-1".equals(obj.getOptdir())){ //-1 最大化 1 最小化
  818. vObj.setFlag("max");
  819. }else{
  820. vObj.setFlag("min");
  821. }
  822. objectives.add(vObj);
  823. }
  824. return objectives;
  825. }
  826. /**
  827. * 查询设计变量
  828. * @param pid
  829. * @return
  830. */
  831. private static List<DesignVariable> findDesignVariables(String pid) {
  832. List<DesignVariable> designVariables =new ArrayList<>();
  833. MdoProjectVariateMapper vDao =UtilTools.getBean(MdoProjectVariateMapper.class);
  834. MdoProjectVariateSQLBuilder vsb = new MdoProjectVariateSQLBuilder();
  835. vsb.createCriteria().andPidEqualTo(pid);
  836. List<MdoProjectVariate> vList =vDao.selectByExample(vsb);
  837. Map<String,List<MdoProjectVariate>> vMap=new HashMap<>();
  838. for (MdoProjectVariate v:vList) {
  839. String vName =v.getName();
  840. if(vMap.get(vName)==null||vMap.get(vName).isEmpty()){
  841. vMap.put(vName,new ArrayList<>());
  842. vMap.get(vName).add(v);
  843. }else{
  844. vMap.get(vName).add(v);
  845. }
  846. }
  847. Set<String> vkeys =vMap.keySet();
  848. for (String key : vkeys) {
  849. DesignVariable dv = new DesignVariable();
  850. dv.setName(key);
  851. List<MdoProjectVariate> tVlist =vMap.get(key);
  852. List<String> values = new ArrayList<>();
  853. List<String> lowerbounds = new ArrayList<>();
  854. List<String> upperbounds = new ArrayList<>();
  855. String uid = null;
  856. for (MdoProjectVariate tv:tVlist) {
  857. if(!StringUtil.isEmpty(tv.getUid())){
  858. uid=tv.getUid();
  859. }
  860. values.add(tv.getReference());
  861. lowerbounds.add(tv.getLower());
  862. upperbounds.add(tv.getUpper());
  863. }
  864. dv.setValue(values);
  865. dv.setLowerbound(lowerbounds);
  866. dv.setUpperbound(upperbounds);
  867. dv.setuID(uid!=null?uid:UtilTools.getUUid());//TODO 目前结构不清
  868. designVariables.add(dv);
  869. }
  870. return designVariables;
  871. }
  872. /**
  873. * python 控件写入
  874. * @param pid
  875. * @return
  876. * @throws IOException
  877. */
  878. public static String writePython(String pid) throws IOException {
  879. MdoProPythonMapper ppDao = UtilTools.getBean(MdoProPythonMapper.class);
  880. MdoProPythonSQLBuilder ppsb = new MdoProPythonSQLBuilder();
  881. ppsb.createCriteria().andPidEqualTo(pid);
  882. List<MdoProPython> ppList = ppDao.selectByExample(ppsb);
  883. if(!ppList.isEmpty()){
  884. String ppPath =LogService.BPATH+"/"+ pid+"/in/py.py";
  885. MdoProPython pp =ppList.get(0);
  886. FileWriter writer =new FileWriter(ppPath);
  887. writer.write(pp.getPtython());
  888. writer.close();
  889. return ppPath;
  890. }
  891. return "";
  892. }
  893. }