TemplateGenerator.java 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. package com.miniframe.template;
  2. import com.miniframe.core.exception.BusinessException;
  3. import com.miniframe.core.ext.UtilTools;
  4. import com.miniframe.model.system.*;
  5. import com.miniframe.model.system.dao.*;
  6. import com.miniframe.tools.XIFileUtils;
  7. import com.miniframe.tools.XIIniFileUtils;
  8. import freemarker.template.Configuration;
  9. import freemarker.template.Template;
  10. import freemarker.template.TemplateException;
  11. import tk.mybatis.mapper.util.StringUtil;
  12. import java.io.FileWriter;
  13. import java.io.IOException;
  14. import java.io.StringWriter;
  15. import java.util.*;
  16. public class TemplateGenerator {
  17. public static final String BPATH = "/cephfs/disaster";
  18. public static void createWaterControl(Integer aid, Integer jid, String totaltime, String dt, String dx, String reportstep, String interactionstep) throws IOException, TemplateException {
  19. Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
  20. // 设置模板所在目录
  21. cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
  22. // 获取模板对象
  23. Template template = cfg.getTemplate("waterControl.ftl");
  24. // 定义数据模型(Map)
  25. Map<String, Object> dataModel = new HashMap<>();
  26. //几何文件路径
  27. dataModel.put("geoFilePath", BPATH + "/" + aid + "/" + jid + "/Geometry");
  28. //initFile 文件路径
  29. dataModel.put("initFilePath", BPATH + "/" + aid + "/" + jid + "/water" + "/" + "water.init");
  30. //midPath
  31. dataModel.put("midPath", BPATH + "/" + aid + "/" + jid + "/water" + "/mid");
  32. //monitorPath
  33. dataModel.put("monitorPath", BPATH + "/" + aid + "/" + jid + "/monitor.in");
  34. //outPath
  35. dataModel.put("outPath", BPATH + "/" + aid + "/" + jid + "/water" + "/out");
  36. dataModel.put("totaltime", totaltime);
  37. dataModel.put("dt", dt);
  38. dataModel.put("dx", dx);
  39. dataModel.put("reportstep", reportstep);
  40. dataModel.put("interactionstep", interactionstep);
  41. DSourceMapper dsm = UtilTools.getBean(DSourceMapper.class);
  42. DSourceSQLBuilder dss = new DSourceSQLBuilder();
  43. DSourceSQLBuilder.Criteria dssc = dss.createCriteria();
  44. dssc.andAidEqualTo(aid);
  45. // dssc.andSTypeEqualTo("Fire");
  46. List<DSource> dources = dsm.selectByExample(dss);
  47. //waterSourcenum 灾源数量
  48. dataModel.put("waterSourcenum", dources.size());
  49. //边界
  50. DBoundaryMapper dBoundaryMapper = UtilTools.getBean(DBoundaryMapper.class);
  51. DBoundarySQLBuilder sb = new DBoundarySQLBuilder();
  52. DBoundarySQLBuilder.Criteria sc = sb.createCriteria();
  53. sc.andAidEqualTo(aid);
  54. List<DBoundary> boundaries = dBoundaryMapper.selectByExample(sb);
  55. //边界数量
  56. dataModel.put("boundarynum", boundaries.size());
  57. // 将数据模型传入模板进行处理
  58. StringWriter writer = new StringWriter();
  59. template.process(dataModel, writer);
  60. mkDirs(aid, jid, "/water");
  61. FileWriter fileWriter = new FileWriter(BPATH + "/" + aid + "/" + jid + "/" + "/water" + "/water.control");
  62. fileWriter.write(writer.toString());
  63. fileWriter.close();
  64. }
  65. public static void createWaterRunsh(Integer aid, Integer jid) throws IOException, TemplateException {
  66. Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
  67. // 设置模板所在目录
  68. cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
  69. // 获取模板对象
  70. Template template = cfg.getTemplate("waterRunsh.ftl");
  71. // 定义数据模型(Map)
  72. Map<String, Object> dataModel = new HashMap<>();
  73. //几何文件路径
  74. dataModel.put("waterControlPath", BPATH + "/" + aid + "/" + jid + "/water" + "/water.control");
  75. // 将数据模型传入模板进行处理
  76. StringWriter writer = new StringWriter();
  77. template.process(dataModel, writer);
  78. FileWriter fileWriter = new FileWriter(BPATH + "/" + aid + "/" + jid + "/water" + "/" + "runWater.sh");
  79. fileWriter.write(writer.toString());
  80. fileWriter.close();
  81. }
  82. public static void createWaterInit(Integer aid, Integer jid) throws IOException, TemplateException {
  83. FireInitVo vo = new FireInitVo();
  84. //TODO 这个版本不需要传感器数据
  85. // DNodeValMapper dnvm= UtilTools.getBean(DNodeValMapper.class);
  86. // DNodeValSQLBuilder dns = new DNodeValSQLBuilder();
  87. // DNodeValSQLBuilder.Criteria dnsc= dns.createCriteria();
  88. // dnsc.andAidEqualTo(aid);
  89. // List<DNodeVal> nodeVals=dnvm.selectByExample(dns);
  90. // vo.setNodeVals(nodeVals);
  91. DSourceMapper dsm = UtilTools.getBean(DSourceMapper.class);
  92. DSourceSQLBuilder dss = new DSourceSQLBuilder();
  93. DSourceSQLBuilder.Criteria dssc = dss.createCriteria();
  94. dssc.andAidEqualTo(aid);
  95. // dssc.andSTypeEqualTo("Water");
  96. List<DSource> dources = dsm.selectByExample(dss);
  97. DSourceValMapper dsvm = UtilTools.getBean(DSourceValMapper.class);
  98. DSourceValSQLBuilder dsvs = new DSourceValSQLBuilder();
  99. List<DSourceVo> dourceVos = new ArrayList<>();
  100. for (DSource ds : dources) {
  101. DSourceValSQLBuilder.Criteria dsvc = dsvs.createCriteria();
  102. dsvc.andSidEqualTo(ds.getId());
  103. List<DSourceVal> dSourceVals = dsvm.selectByExample(dsvs);
  104. DSourceVo dsourcevo = new DSourceVo();
  105. dsourcevo.setDsource(ds);
  106. dsourcevo.setDsourceVals(dSourceVals);
  107. dourceVos.add(dsourcevo);
  108. dsvs.clear();
  109. }
  110. vo.setDourceVos(dourceVos);
  111. //边界
  112. DBoundaryMapper dBoundaryMapper = UtilTools.getBean(DBoundaryMapper.class);
  113. DBoundarySQLBuilder sb = new DBoundarySQLBuilder();
  114. DBoundarySQLBuilder.Criteria sc = sb.createCriteria();
  115. sc.andAidEqualTo(aid);
  116. List<DBoundary> boundaries = dBoundaryMapper.selectByExample(sb);
  117. Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
  118. // 设置模板所在目录
  119. cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
  120. // 获取模板对象
  121. Template template = cfg.getTemplate("waterInit.ftl");
  122. // 定义数据模型(Map)
  123. Map<String, Object> dataModel = new HashMap<>();
  124. //几何文件路径
  125. dataModel.put("vo", vo);
  126. //边界
  127. dataModel.put("boundaries", boundaries);
  128. // 将数据模型传入模板进行处理
  129. StringWriter writer = new StringWriter();
  130. template.process(dataModel, writer);
  131. // 输出结果到控制台或保存为文件
  132. // System.out.println(writer.toString());
  133. FileWriter fileWriter = new FileWriter(BPATH + "/" + aid + "/" + jid + "/water" + "/" + "water.init");
  134. fileWriter.write(writer.toString());
  135. fileWriter.close();
  136. }
  137. /**
  138. * 生成几何文件
  139. */
  140. public static void createGeometry(Integer aid, Integer jid) throws IOException, TemplateException {
  141. Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
  142. // 设置模板所在目录
  143. cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
  144. // 获取模板对象
  145. Template template = cfg.getTemplate("geometry.ftl");
  146. // 定义数据模型(Map)
  147. Map<String, Object> dataModel = new HashMap<>();
  148. DNodeMapper nodeMapper = UtilTools.getBean(DNodeMapper.class);
  149. List<DNode> nodes = nodeMapper.selectAll();
  150. Collections.sort(nodes, (n1, n2) -> n1.getId().compareTo(n2.getId()));
  151. //节点数量
  152. dataModel.put("nodenum", nodes.size());
  153. //节点
  154. dataModel.put("nodes", nodes);
  155. DPipeMapper pipeMapper = UtilTools.getBean(DPipeMapper.class);
  156. List<DPipe> pipes = pipeMapper.selectAll();
  157. Collections.sort(pipes, (n1, n2) -> n1.getId().compareTo(n2.getId()));
  158. //管道数量
  159. dataModel.put("pipenum", pipes.size());
  160. //管道
  161. dataModel.put("pipes", pipes);
  162. // 将数据模型传入模板进行处理
  163. StringWriter writer = new StringWriter();
  164. template.process(dataModel, writer);
  165. mkDirs(aid, jid, "/fire");
  166. FileWriter fileWriter = new FileWriter(BPATH + "/" + aid + "/" + jid + "/Geometry");
  167. fileWriter.write(writer.toString());
  168. fileWriter.close();
  169. }
  170. private static void mkDirs(Integer aid, Integer jid, String s) {
  171. XIFileUtils.mkdir(BPATH);
  172. XIFileUtils.mkdir(BPATH + "/" + aid);
  173. XIFileUtils.mkdir(BPATH + "/" + aid + "/" + jid);
  174. XIFileUtils.mkdir(BPATH + "/" + aid + "/" + jid + s);
  175. XIFileUtils.mkdir(BPATH + "/" + aid + "/" + jid + s + "/mid");
  176. XIFileUtils.mkdir(BPATH + "/" + aid + "/" + jid + s + "/out");
  177. }
  178. private static void mkGassDirs(Integer aid, Integer jid) {
  179. String s = "/gas";
  180. XIFileUtils.mkdir(BPATH);
  181. XIFileUtils.mkdir(BPATH + "/" + aid);
  182. XIFileUtils.mkdir(BPATH + "/" + aid + "/" + jid);
  183. XIFileUtils.mkdir(BPATH + "/" + aid + "/" + jid + s);
  184. XIFileUtils.mkdir(BPATH + "/" + aid + "/" + jid + s + "/" );
  185. XIFileUtils.mkdir(BPATH + "/" + aid + "/" + jid + s + "/" + "/mid");
  186. XIFileUtils.mkdir(BPATH + "/" + aid + "/" + jid + s + "/" + "/out");
  187. XIFileUtils.mkdir(BPATH + "/" + aid + "/" + jid + s + "/" + "/case");
  188. XIFileUtils.mkdir(BPATH + "/" + aid + "/" + jid + s + "/" + "/data_his");
  189. XIFileUtils.mkdir(BPATH + "/" + aid + "/" + jid + s + "/" + "/data_mnt");
  190. XIFileUtils.mkdir(BPATH + "/" + aid + "/" + jid + s + "/" + "/data_rst");
  191. }
  192. /**
  193. * 生成监测点文件
  194. */
  195. public static void createMonitor(Integer aid, Integer jid) throws IOException, TemplateException {
  196. Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
  197. // 设置模板所在目录
  198. cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
  199. // 获取模板对象
  200. Template template = cfg.getTemplate("monitor.ftl");
  201. // 定义数据模型(Map)
  202. Map<String, Object> dataModel = new HashMap<>();
  203. DChecknodeMapper checknodeMapper = UtilTools.getBean(DChecknodeMapper.class);
  204. List<DChecknode> monitors = checknodeMapper.selectAll();
  205. Collections.sort(monitors, (n1, n2) -> n1.getId().compareTo(n2.getId()));
  206. dataModel.put("monnum", monitors.size());
  207. //管道
  208. dataModel.put("monitors", monitors);
  209. // 将数据模型传入模板进行处理
  210. StringWriter writer = new StringWriter();
  211. template.process(dataModel, writer);
  212. mkDirs(aid, jid, "/fire");
  213. FileWriter fileWriter = new FileWriter(BPATH + "/" + aid + "/" + jid + "/monitor.in");
  214. fileWriter.write(writer.toString());
  215. fileWriter.close();
  216. }
  217. public static void createFireControl(Integer aid, Integer jid, String totaltime,
  218. String dt, String dx, String reportstep, String interactionstep,
  219. String cocodes) throws IOException, TemplateException {
  220. Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
  221. // 设置模板所在目录
  222. cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
  223. // 获取模板对象
  224. Template template = cfg.getTemplate("fireControl.ftl");
  225. // 定义数据模型(Map)
  226. Map<String, Object> dataModel = new HashMap<>();
  227. //几何文件路径
  228. dataModel.put("geoFilePath", BPATH + "/" + aid + "/" + jid + "/Geometry");
  229. //fireinit 文件路径
  230. dataModel.put("initFilePath", BPATH + "/" + aid + "/" + jid + "/fire" + "/" + "Fire.init");
  231. //fireInteractionPath 阀门文件路径
  232. dataModel.put("fireInteractionPath", "/home/disaster/fire/Fire.interaction");
  233. //midPath
  234. dataModel.put("monitorPath", BPATH + "/" + aid + "/" + jid + "/monitor.in");
  235. //midPath
  236. dataModel.put("midPath", BPATH + "/" + aid + "/" + jid + "/fire" + "/mid");
  237. //outPath
  238. dataModel.put("outPath", BPATH + "/" + aid + "/" + jid + "/fire" + "/out");
  239. dataModel.put("totaltime", totaltime);
  240. dataModel.put("dt", dt);
  241. dataModel.put("dx", dx);
  242. dataModel.put("reportstep", reportstep);
  243. dataModel.put("interactionstep", interactionstep);
  244. DSourceMapper dsm = UtilTools.getBean(DSourceMapper.class);
  245. DSourceSQLBuilder dss = new DSourceSQLBuilder();
  246. DSourceSQLBuilder.Criteria dssc = dss.createCriteria();
  247. dssc.andAidEqualTo(aid);
  248. // dssc.andSTypeEqualTo("Fire");
  249. List<DSource> dources = dsm.selectByExample(dss);
  250. //fireSourceNum 灾源数量
  251. dataModel.put("fireSourceNum", dources.size());
  252. //边界
  253. DBoundaryMapper dBoundaryMapper = UtilTools.getBean(DBoundaryMapper.class);
  254. DBoundarySQLBuilder sb = new DBoundarySQLBuilder();
  255. DBoundarySQLBuilder.Criteria sc = sb.createCriteria();
  256. sc.andAidEqualTo(aid);
  257. List<DBoundary> boundaries = dBoundaryMapper.selectByExample(sb);
  258. //边界数量
  259. dataModel.put("boundarynum", boundaries.size());
  260. //物理量
  261. String[] codes = cocodes.split(",");
  262. List<String> concodeList = new ArrayList<>();
  263. for (String concode : codes
  264. ) {
  265. concodeList.add(concode);
  266. }
  267. DConMapper conMapper = UtilTools.getBean(DConMapper.class);
  268. DConSQLBuilder consb = new DConSQLBuilder();
  269. DConSQLBuilder.Criteria consc = consb.createCriteria();
  270. consc.andCodeIn(concodeList);
  271. List<DCon> cons = conMapper.selectByExample(consb);
  272. dataModel.put("conNum", cons.size());
  273. dataModel.put("cons", cons);
  274. // 将数据模型传入模板进行处理
  275. StringWriter writer = new StringWriter();
  276. template.process(dataModel, writer);
  277. mkDirs(aid, jid, "/fire");
  278. FileWriter fileWriter = new FileWriter(BPATH + "/" + aid + "/" + jid + "/" + "/fire" + "/Fire.control");
  279. fileWriter.write(writer.toString());
  280. fileWriter.close();
  281. }
  282. public static void createFireRunsh(Integer aid, Integer jid) throws IOException, TemplateException {
  283. Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
  284. // 设置模板所在目录
  285. cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
  286. // 获取模板对象
  287. Template template = cfg.getTemplate("fireRunsh.ftl");
  288. // 定义数据模型(Map)
  289. Map<String, Object> dataModel = new HashMap<>();
  290. //几何文件路径
  291. dataModel.put("firecontrolPath", BPATH + "/" + aid + "/" + jid + "/fire" + "/Fire.control");
  292. // 将数据模型传入模板进行处理
  293. StringWriter writer = new StringWriter();
  294. template.process(dataModel, writer);
  295. FileWriter fileWriter = new FileWriter(BPATH + "/" + aid + "/" + jid + "/fire" + "/" + "runFile.sh");
  296. fileWriter.write(writer.toString());
  297. fileWriter.close();
  298. }
  299. public static void createFireInit(Integer aid, Integer jid) throws IOException, TemplateException {
  300. FireInitVo vo = new FireInitVo();
  301. //TODO 求解器暂时不需要此数据
  302. // DNodeValMapper dnvm= UtilTools.getBean(DNodeValMapper.class);
  303. // DNodeValSQLBuilder dns = new DNodeValSQLBuilder();
  304. // DNodeValSQLBuilder.Criteria dnsc= dns.createCriteria();
  305. // dnsc.andAidEqualTo(aid);
  306. // List<DNodeVal> nodeVals=dnvm.selectByExample(dns);
  307. // vo.setNodeVals(nodeVals);
  308. DSourceMapper dsm = UtilTools.getBean(DSourceMapper.class);
  309. DSourceSQLBuilder dss = new DSourceSQLBuilder();
  310. DSourceSQLBuilder.Criteria dssc = dss.createCriteria();
  311. dssc.andAidEqualTo(aid);
  312. // dssc.andSTypeEqualTo("Fire");
  313. List<DSource> dources = dsm.selectByExample(dss);
  314. DSourceValMapper dsvm = UtilTools.getBean(DSourceValMapper.class);
  315. DSourceValSQLBuilder dsvs = new DSourceValSQLBuilder();
  316. List<DSourceVo> dourceVos = new ArrayList<>();
  317. for (DSource ds : dources) {
  318. DSourceValSQLBuilder.Criteria dsvc = dsvs.createCriteria();
  319. dsvc.andSidEqualTo(ds.getId());
  320. List<DSourceVal> dSourceVals = dsvm.selectByExample(dsvs);
  321. DSourceVo dsourcevo = new DSourceVo();
  322. dsourcevo.setDsource(ds);
  323. dsourcevo.setDsourceVals(dSourceVals);
  324. dourceVos.add(dsourcevo);
  325. dsvs.clear();
  326. }
  327. vo.setDourceVos(dourceVos);
  328. //边界
  329. DBoundaryMapper dBoundaryMapper = UtilTools.getBean(DBoundaryMapper.class);
  330. DBoundarySQLBuilder sb = new DBoundarySQLBuilder();
  331. DBoundarySQLBuilder.Criteria sc = sb.createCriteria();
  332. sc.andAidEqualTo(aid);
  333. List<DBoundary> boundaries = dBoundaryMapper.selectByExample(sb);
  334. Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
  335. // 设置模板所在目录
  336. cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
  337. // 获取模板对象
  338. Template template = cfg.getTemplate("fireInit.ftl");
  339. // 定义数据模型(Map)
  340. Map<String, Object> dataModel = new HashMap<>();
  341. //几何文件路径
  342. dataModel.put("vo", vo);
  343. //边界
  344. dataModel.put("boundaries", boundaries);
  345. // 将数据模型传入模板进行处理
  346. StringWriter writer = new StringWriter();
  347. template.process(dataModel, writer);
  348. // 输出结果到控制台或保存为文件
  349. // System.out.println(writer.toString());
  350. FileWriter fileWriter = new FileWriter(BPATH + "/" + aid + "/" + jid + "/fire" + "/" + "Fire.init");
  351. fileWriter.write(writer.toString());
  352. fileWriter.close();
  353. }
  354. public static void main(String[] args) throws Exception {
  355. // TemplateGenerator.createWaterRunsh(5);
  356. float myFloat = 495545.603f;
  357. String formattedString = String.format("%.32f", myFloat);
  358. System.out.println(myFloat); // 输出: 123.46
  359. System.out.println(formattedString); // 输出: 123.46
  360. }
  361. public static void createGasControl(Integer aid, Integer jid, String totaltime,
  362. String dt, String dx, String reportstep, String interactionstep,
  363. String cocodes) throws IOException, TemplateException {
  364. Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
  365. // 设置模板所在目录
  366. cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
  367. // 获取模板对象
  368. Template template = cfg.getTemplate("mashGasControl.ftl");
  369. // 定义数据模型(Map)
  370. Map<String, Object> dataModel = new HashMap<>();
  371. //几何文件路径
  372. dataModel.put("geoFilePath", BPATH + "/" + aid + "/" + jid + "/Geometry");
  373. //fireinit 文件路径
  374. dataModel.put("initFilePath", BPATH + "/" + aid + "/" + jid + "/gas" + "/" + "MashGas.init");
  375. //midPath
  376. dataModel.put("monitorPath", BPATH + "/" + aid + "/" + jid + "/monitor.in");
  377. //midPath
  378. dataModel.put("midPath", BPATH + "/" + aid + "/" + jid + "/gas" + "/" + "mid");
  379. //outPath
  380. dataModel.put("outPath", BPATH + "/" + aid + "/" + jid + "/gas" + "/" + "out");
  381. //CPUS
  382. dataModel.put("cups", 4);
  383. dataModel.put("totaltime", totaltime);
  384. dataModel.put("dt", dt);
  385. dataModel.put("dx", dx);
  386. dataModel.put("reportstep", reportstep);
  387. dataModel.put("interactionstep", interactionstep);
  388. DBoundaryMapper dBoundaryMapper = UtilTools.getBean(DBoundaryMapper.class);
  389. DBoundarySQLBuilder sb = new DBoundarySQLBuilder();
  390. DBoundarySQLBuilder.Criteria sc = sb.createCriteria();
  391. sc.andAidEqualTo(aid);
  392. List<DBoundary> boundaries = dBoundaryMapper.selectByExample(sb);
  393. //边界数量
  394. dataModel.put("boundarynum", boundaries.size());
  395. //TODO
  396. dataModel.put("mashgasnumber", 1);
  397. //fireInteractionPath 阀门文件路径
  398. dataModel.put("fireInteractionPath", "/home/disaster/fire/Fire.interaction");
  399. //物理量
  400. if (StringUtil.isEmpty(cocodes)) {
  401. dataModel.put("conNum", 0);
  402. dataModel.put("cons", new ArrayList<>());
  403. } else {
  404. String[] codes = cocodes.split(",");
  405. List<String> concodeList = new ArrayList<>();
  406. for (String concode : codes
  407. ) {
  408. concodeList.add(concode);
  409. }
  410. DConMapper conMapper = UtilTools.getBean(DConMapper.class);
  411. DConSQLBuilder consb = new DConSQLBuilder();
  412. DConSQLBuilder.Criteria consc = consb.createCriteria();
  413. consc.andCodeIn(concodeList);
  414. List<DCon> cons = conMapper.selectByExample(consb);
  415. dataModel.put("conNum", cons.size());
  416. dataModel.put("cons", cons);
  417. }
  418. // 将数据模型传入模板进行处理
  419. StringWriter writer = new StringWriter();
  420. template.process(dataModel, writer);
  421. mkGassDirs(aid, jid);
  422. FileWriter fileWriter = new FileWriter(BPATH + "/" + aid + "/" + jid + "/" + "/gas" + "/MashGas.control");
  423. fileWriter.write(writer.toString());
  424. fileWriter.close();
  425. }
  426. public static void createGasInit(Integer aid, Integer jid, Integer gid) throws IOException, TemplateException, BusinessException {
  427. Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
  428. // 设置模板所在目录
  429. cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
  430. // 获取模板对象
  431. Template template = cfg.getTemplate("mashGasInit.ftl");
  432. // 定义数据模型(Map)
  433. Map<String, Object> dataModel = new HashMap<>();
  434. DGasBlastAreaMapper blastMapper = UtilTools.getBean(DGasBlastAreaMapper.class);
  435. DGasBlastAreaSQLBuilder blastSb = new DGasBlastAreaSQLBuilder();
  436. DGasBlastAreaSQLBuilder.Criteria blastSc = blastSb.createCriteria();
  437. blastSc.andGidEqualTo(gid);
  438. List<DGasBlastArea> blastList = blastMapper.selectByExample(blastSb);
  439. if (blastList.isEmpty()) {
  440. throw new BusinessException("EB3100023");
  441. }
  442. //边界
  443. DBoundaryMapper dBoundaryMapper = UtilTools.getBean(DBoundaryMapper.class);
  444. DBoundarySQLBuilder sb = new DBoundarySQLBuilder();
  445. DBoundarySQLBuilder.Criteria sc = sb.createCriteria();
  446. sc.andAidEqualTo(aid);
  447. List<DBoundary> boundaries = dBoundaryMapper.selectByExample(sb);
  448. dataModel.put("boundaries", boundaries);
  449. dataModel.put("blastnum", blastList.size());
  450. dataModel.put("blastList", blastList);
  451. DGasGatherAreaMapper gatherMapper = UtilTools.getBean(DGasGatherAreaMapper.class);
  452. DGasGatherAreaSQLBuilder gatherSb = new DGasGatherAreaSQLBuilder();
  453. DGasGatherAreaSQLBuilder.Criteria gatherSc = gatherSb.createCriteria();
  454. gatherSc.andGidEqualTo(gid);
  455. gatherSb.setOrderByClause("id ASC");
  456. List<DGasGatherArea> gatherList = gatherMapper.selectByExample(gatherSb);
  457. if (gatherList.isEmpty()) {
  458. throw new BusinessException("EB3100024");
  459. }
  460. dataModel.put("gathernum", gatherList.size());
  461. dataModel.put("gatherList", gatherList);
  462. DGasMapper gasMapper = UtilTools.getBean(DGasMapper.class);
  463. DGas gas = gasMapper.selectByPrimaryKey(gid);
  464. dataModel.put("gas", gas);
  465. // 将数据模型传入模板进行处理
  466. StringWriter writer = new StringWriter();
  467. template.process(dataModel, writer);
  468. mkGassDirs(aid, jid);
  469. FileWriter fileWriter = new FileWriter(BPATH + "/" + aid + "/" + jid + "/" + "/gas" + "/MashGas.init");
  470. fileWriter.write(writer.toString());
  471. fileWriter.close();
  472. }
  473. public static void createGassRunsh(Integer aid, Integer jid) throws IOException, TemplateException {
  474. Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
  475. // 设置模板所在目录
  476. cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
  477. // 获取模板对象
  478. Template template = cfg.getTemplate("mashGasRunsh.ftl");
  479. // 定义数据模型(Map)
  480. Map<String, Object> dataModel = new HashMap<>();
  481. dataModel.put("casepath", BPATH + "/" + aid + "/" + jid + "/gas" + "/case");
  482. dataModel.put("datahis", BPATH + "/" + aid + "/" + jid + "/gas" + "/data_his");
  483. dataModel.put("gascontrol", BPATH + "/" + aid + "/" + jid + "/gas" + "/MashGas.control");
  484. dataModel.put("gasescapecontrol", BPATH + "/" + aid + "/" + jid + "/" + "/gas" + "/gasEscape.control");
  485. // 将数据模型传入模板进行处理
  486. StringWriter writer = new StringWriter();
  487. template.process(dataModel, writer);
  488. mkGassDirs(aid, jid);
  489. FileWriter fileWriter = new FileWriter(BPATH + "/" + aid + "/" + jid + "/" + "/gas" + "/run.sh");
  490. fileWriter.write(writer.toString());
  491. fileWriter.close();
  492. }
  493. public static void createGas1Control(Integer aid, Integer jid, String totaltime,
  494. String dt, String dx, String reportstep, String interactionstep,
  495. String cocodes) throws IOException, TemplateException {
  496. Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
  497. // 设置模板所在目录
  498. cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
  499. // 获取模板对象
  500. Template template = cfg.getTemplate("mashGas1Control.ftl");
  501. // 定义数据模型(Map)
  502. Map<String, Object> dataModel = new HashMap<>();
  503. //几何文件路径
  504. dataModel.put("geoFilePath", BPATH + "/" + aid + "/" + jid + "/Geometry");
  505. //fireinit 文件路径
  506. dataModel.put("initFilePath", BPATH + "/" + aid + "/" + jid + "/gas" + "/" + "MashGas.init");
  507. //midPath
  508. dataModel.put("monitorPath", BPATH + "/" + aid + "/" + jid + "/monitor.in");
  509. //midPath
  510. dataModel.put("midPath", BPATH + "/" + aid + "/" + jid + "/gas" + "/" + "mid");
  511. //outPath
  512. dataModel.put("outPath", BPATH + "/" + aid + "/" + jid + "/gas" + "/" + "out");
  513. //CPUS
  514. dataModel.put("cups", 4);
  515. dataModel.put("totaltime", totaltime);
  516. dataModel.put("dt", dt);
  517. dataModel.put("dx", dx);
  518. dataModel.put("reportstep", reportstep);
  519. dataModel.put("interactionstep", interactionstep);
  520. DBoundaryMapper dBoundaryMapper = UtilTools.getBean(DBoundaryMapper.class);
  521. DBoundarySQLBuilder sb = new DBoundarySQLBuilder();
  522. DBoundarySQLBuilder.Criteria sc = sb.createCriteria();
  523. sc.andAidEqualTo(aid);
  524. List<DBoundary> boundaries = dBoundaryMapper.selectByExample(sb);
  525. //边界数量
  526. dataModel.put("boundarynum", boundaries.size());
  527. //TODO
  528. dataModel.put("mashgasnumber", 1);
  529. //物理量
  530. if (StringUtil.isEmpty(cocodes)) {
  531. dataModel.put("conNum", 0);
  532. dataModel.put("cons", new ArrayList<>());
  533. } else {
  534. String[] codes = cocodes.split(",");
  535. List<String> concodeList = new ArrayList<>();
  536. for (String concode : codes
  537. ) {
  538. concodeList.add(concode);
  539. }
  540. DConMapper conMapper = UtilTools.getBean(DConMapper.class);
  541. DConSQLBuilder consb = new DConSQLBuilder();
  542. DConSQLBuilder.Criteria consc = consb.createCriteria();
  543. consc.andCodeIn(concodeList);
  544. List<DCon> cons = conMapper.selectByExample(consb);
  545. dataModel.put("conNum", cons.size());
  546. dataModel.put("cons", cons);
  547. }
  548. // 将数据模型传入模板进行处理
  549. StringWriter writer = new StringWriter();
  550. template.process(dataModel, writer);
  551. mkGassDirs(aid, jid);
  552. FileWriter fileWriter = new FileWriter(BPATH + "/" + aid + "/" + jid + "/" + "/gas" + "/MashGas.control");
  553. fileWriter.write(writer.toString());
  554. fileWriter.close();
  555. }
  556. public static void createGas1Init(Integer aid, Integer jid, Integer gid) throws IOException, TemplateException, BusinessException {
  557. Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
  558. // 设置模板所在目录
  559. cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
  560. // 获取模板对象
  561. Template template = cfg.getTemplate("mashGas1Init.ftl");
  562. // 定义数据模型(Map)
  563. Map<String, Object> dataModel = new HashMap<>();
  564. //边界
  565. DBoundaryMapper dBoundaryMapper = UtilTools.getBean(DBoundaryMapper.class);
  566. DBoundarySQLBuilder sb = new DBoundarySQLBuilder();
  567. DBoundarySQLBuilder.Criteria sc = sb.createCriteria();
  568. sc.andAidEqualTo(aid);
  569. List<DBoundary> boundaries = dBoundaryMapper.selectByExample(sb);
  570. dataModel.put("boundaries", boundaries);
  571. DGasMapper gasMapper = UtilTools.getBean(DGasMapper.class);
  572. DGas gas = gasMapper.selectByPrimaryKey(gid);
  573. dataModel.put("b", gas);
  574. // 将数据模型传入模板进行处理
  575. StringWriter writer = new StringWriter();
  576. template.process(dataModel, writer);
  577. mkGassDirs(aid, jid);
  578. FileWriter fileWriter = new FileWriter(BPATH + "/" + aid + "/" + jid + "/" + "/gas" + "/MashGas.init");
  579. fileWriter.write(writer.toString());
  580. fileWriter.close();
  581. }
  582. public static void createGass1Runsh(Integer aid, Integer jid) throws IOException, TemplateException {
  583. Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
  584. // 设置模板所在目录
  585. cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
  586. // 获取模板对象
  587. Template template = cfg.getTemplate("mashGas1Runsh.ftl");
  588. // 定义数据模型(Map)
  589. Map<String, Object> dataModel = new HashMap<>();
  590. dataModel.put("gascontrol", BPATH + "/" + aid + "/" + jid + "/gas" + "/MashGas.control");
  591. dataModel.put("gasescapecontrol", BPATH + "/" + aid + "/" + jid + "/" + "/gas" + "/gasEscape.control");
  592. dataModel.put("midPath", BPATH + "/" + aid + "/" + jid + "/gas" + "/" + "mid");
  593. // 将数据模型传入模板进行处理
  594. StringWriter writer = new StringWriter();
  595. template.process(dataModel, writer);
  596. mkGassDirs(aid, jid);
  597. FileWriter fileWriter = new FileWriter(BPATH + "/" + aid + "/" + jid + "/" + "/gas" + "/run.sh");
  598. fileWriter.write(writer.toString());
  599. fileWriter.close();
  600. }
  601. }