123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700 |
- package com.miniframe.template;
- import com.miniframe.core.exception.BusinessException;
- import com.miniframe.core.ext.UtilTools;
- import com.miniframe.model.system.*;
- import com.miniframe.model.system.dao.*;
- import com.miniframe.tools.XIFileUtils;
- import com.miniframe.tools.XIIniFileUtils;
- 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.*;
- public class TemplateGenerator {
- public static final String BPATH = "/cephfs/disaster";
- public static void createWaterControl(Integer aid, Integer jid, String totaltime, String dt, String dx, String reportstep, String interactionstep) throws IOException, TemplateException {
- Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
- // 设置模板所在目录
- cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
- // 获取模板对象
- Template template = cfg.getTemplate("waterControl.ftl");
- // 定义数据模型(Map)
- Map<String, Object> dataModel = new HashMap<>();
- //几何文件路径
- dataModel.put("geoFilePath", BPATH + "/" + aid + "/" + jid + "/Geometry");
- //initFile 文件路径
- dataModel.put("initFilePath", BPATH + "/" + aid + "/" + jid + "/water" + "/" + "water.init");
- //midPath
- dataModel.put("midPath", BPATH + "/" + aid + "/" + jid + "/water" + "/mid");
- //monitorPath
- dataModel.put("monitorPath", BPATH + "/" + aid + "/" + jid + "/monitor.in");
- //outPath
- dataModel.put("outPath", BPATH + "/" + aid + "/" + jid + "/water" + "/out");
- dataModel.put("totaltime", totaltime);
- dataModel.put("dt", dt);
- dataModel.put("dx", dx);
- dataModel.put("reportstep", reportstep);
- dataModel.put("interactionstep", interactionstep);
- DSourceMapper dsm = UtilTools.getBean(DSourceMapper.class);
- DSourceSQLBuilder dss = new DSourceSQLBuilder();
- DSourceSQLBuilder.Criteria dssc = dss.createCriteria();
- dssc.andAidEqualTo(aid);
- // dssc.andSTypeEqualTo("Fire");
- List<DSource> dources = dsm.selectByExample(dss);
- //waterSourcenum 灾源数量
- dataModel.put("waterSourcenum", dources.size());
- //边界
- DBoundaryMapper dBoundaryMapper = UtilTools.getBean(DBoundaryMapper.class);
- DBoundarySQLBuilder sb = new DBoundarySQLBuilder();
- DBoundarySQLBuilder.Criteria sc = sb.createCriteria();
- sc.andAidEqualTo(aid);
- List<DBoundary> boundaries = dBoundaryMapper.selectByExample(sb);
- //边界数量
- dataModel.put("boundarynum", boundaries.size());
- // 将数据模型传入模板进行处理
- StringWriter writer = new StringWriter();
- template.process(dataModel, writer);
- mkDirs(aid, jid, "/water");
- FileWriter fileWriter = new FileWriter(BPATH + "/" + aid + "/" + jid + "/" + "/water" + "/water.control");
- fileWriter.write(writer.toString());
- fileWriter.close();
- }
- public static void createWaterRunsh(Integer aid, Integer jid) throws IOException, TemplateException {
- Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
- // 设置模板所在目录
- cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
- // 获取模板对象
- Template template = cfg.getTemplate("waterRunsh.ftl");
- // 定义数据模型(Map)
- Map<String, Object> dataModel = new HashMap<>();
- //几何文件路径
- dataModel.put("waterControlPath", BPATH + "/" + aid + "/" + jid + "/water" + "/water.control");
- // 将数据模型传入模板进行处理
- StringWriter writer = new StringWriter();
- template.process(dataModel, writer);
- FileWriter fileWriter = new FileWriter(BPATH + "/" + aid + "/" + jid + "/water" + "/" + "runWater.sh");
- fileWriter.write(writer.toString());
- fileWriter.close();
- }
- public static void createWaterInit(Integer aid, Integer jid) throws IOException, TemplateException {
- FireInitVo vo = new FireInitVo();
- //TODO 这个版本不需要传感器数据
- // DNodeValMapper dnvm= UtilTools.getBean(DNodeValMapper.class);
- // DNodeValSQLBuilder dns = new DNodeValSQLBuilder();
- // DNodeValSQLBuilder.Criteria dnsc= dns.createCriteria();
- // dnsc.andAidEqualTo(aid);
- // List<DNodeVal> nodeVals=dnvm.selectByExample(dns);
- // vo.setNodeVals(nodeVals);
- DSourceMapper dsm = UtilTools.getBean(DSourceMapper.class);
- DSourceSQLBuilder dss = new DSourceSQLBuilder();
- DSourceSQLBuilder.Criteria dssc = dss.createCriteria();
- dssc.andAidEqualTo(aid);
- // dssc.andSTypeEqualTo("Water");
- List<DSource> dources = dsm.selectByExample(dss);
- DSourceValMapper dsvm = UtilTools.getBean(DSourceValMapper.class);
- DSourceValSQLBuilder dsvs = new DSourceValSQLBuilder();
- List<DSourceVo> dourceVos = new ArrayList<>();
- for (DSource ds : dources) {
- DSourceValSQLBuilder.Criteria dsvc = dsvs.createCriteria();
- dsvc.andSidEqualTo(ds.getId());
- List<DSourceVal> dSourceVals = dsvm.selectByExample(dsvs);
- DSourceVo dsourcevo = new DSourceVo();
- dsourcevo.setDsource(ds);
- dsourcevo.setDsourceVals(dSourceVals);
- dourceVos.add(dsourcevo);
- dsvs.clear();
- }
- vo.setDourceVos(dourceVos);
- //边界
- DBoundaryMapper dBoundaryMapper = UtilTools.getBean(DBoundaryMapper.class);
- DBoundarySQLBuilder sb = new DBoundarySQLBuilder();
- DBoundarySQLBuilder.Criteria sc = sb.createCriteria();
- sc.andAidEqualTo(aid);
- List<DBoundary> boundaries = dBoundaryMapper.selectByExample(sb);
- Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
- // 设置模板所在目录
- cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
- // 获取模板对象
- Template template = cfg.getTemplate("waterInit.ftl");
- // 定义数据模型(Map)
- Map<String, Object> dataModel = new HashMap<>();
- //几何文件路径
- dataModel.put("vo", vo);
- //边界
- dataModel.put("boundaries", boundaries);
- // 将数据模型传入模板进行处理
- StringWriter writer = new StringWriter();
- template.process(dataModel, writer);
- // 输出结果到控制台或保存为文件
- // System.out.println(writer.toString());
- FileWriter fileWriter = new FileWriter(BPATH + "/" + aid + "/" + jid + "/water" + "/" + "water.init");
- fileWriter.write(writer.toString());
- fileWriter.close();
- }
- /**
- * 生成几何文件
- */
- public static void createGeometry(Integer aid, Integer jid) throws IOException, TemplateException {
- Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
- // 设置模板所在目录
- cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
- // 获取模板对象
- Template template = cfg.getTemplate("geometry.ftl");
- // 定义数据模型(Map)
- Map<String, Object> dataModel = new HashMap<>();
- DNodeMapper nodeMapper = UtilTools.getBean(DNodeMapper.class);
- List<DNode> nodes = nodeMapper.selectAll();
- Collections.sort(nodes, (n1, n2) -> n1.getId().compareTo(n2.getId()));
- //节点数量
- dataModel.put("nodenum", nodes.size());
- //节点
- dataModel.put("nodes", nodes);
- DPipeMapper pipeMapper = UtilTools.getBean(DPipeMapper.class);
- List<DPipe> pipes = pipeMapper.selectAll();
- Collections.sort(pipes, (n1, n2) -> n1.getId().compareTo(n2.getId()));
- //管道数量
- dataModel.put("pipenum", pipes.size());
- //管道
- dataModel.put("pipes", pipes);
- // 将数据模型传入模板进行处理
- StringWriter writer = new StringWriter();
- template.process(dataModel, writer);
- mkDirs(aid, jid, "/fire");
- FileWriter fileWriter = new FileWriter(BPATH + "/" + aid + "/" + jid + "/Geometry");
- fileWriter.write(writer.toString());
- fileWriter.close();
- }
- private static void mkDirs(Integer aid, Integer jid, String s) {
- XIFileUtils.mkdir(BPATH);
- XIFileUtils.mkdir(BPATH + "/" + aid);
- XIFileUtils.mkdir(BPATH + "/" + aid + "/" + jid);
- XIFileUtils.mkdir(BPATH + "/" + aid + "/" + jid + s);
- XIFileUtils.mkdir(BPATH + "/" + aid + "/" + jid + s + "/mid");
- XIFileUtils.mkdir(BPATH + "/" + aid + "/" + jid + s + "/out");
- }
- private static void mkGassDirs(Integer aid, Integer jid) {
- String s = "/gas";
- XIFileUtils.mkdir(BPATH);
- XIFileUtils.mkdir(BPATH + "/" + aid);
- XIFileUtils.mkdir(BPATH + "/" + aid + "/" + jid);
- XIFileUtils.mkdir(BPATH + "/" + aid + "/" + jid + s);
- XIFileUtils.mkdir(BPATH + "/" + aid + "/" + jid + s + "/" );
- XIFileUtils.mkdir(BPATH + "/" + aid + "/" + jid + s + "/" + "/mid");
- XIFileUtils.mkdir(BPATH + "/" + aid + "/" + jid + s + "/" + "/out");
- XIFileUtils.mkdir(BPATH + "/" + aid + "/" + jid + s + "/" + "/case");
- XIFileUtils.mkdir(BPATH + "/" + aid + "/" + jid + s + "/" + "/data_his");
- XIFileUtils.mkdir(BPATH + "/" + aid + "/" + jid + s + "/" + "/data_mnt");
- XIFileUtils.mkdir(BPATH + "/" + aid + "/" + jid + s + "/" + "/data_rst");
- }
- /**
- * 生成监测点文件
- */
- public static void createMonitor(Integer aid, Integer jid) throws IOException, TemplateException {
- Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
- // 设置模板所在目录
- cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
- // 获取模板对象
- Template template = cfg.getTemplate("monitor.ftl");
- // 定义数据模型(Map)
- Map<String, Object> dataModel = new HashMap<>();
- DChecknodeMapper checknodeMapper = UtilTools.getBean(DChecknodeMapper.class);
- List<DChecknode> monitors = checknodeMapper.selectAll();
- Collections.sort(monitors, (n1, n2) -> n1.getId().compareTo(n2.getId()));
- dataModel.put("monnum", monitors.size());
- //管道
- dataModel.put("monitors", monitors);
- // 将数据模型传入模板进行处理
- StringWriter writer = new StringWriter();
- template.process(dataModel, writer);
- mkDirs(aid, jid, "/fire");
- FileWriter fileWriter = new FileWriter(BPATH + "/" + aid + "/" + jid + "/monitor.in");
- fileWriter.write(writer.toString());
- fileWriter.close();
- }
- public static void createFireControl(Integer aid, Integer jid, String totaltime,
- String dt, String dx, String reportstep, String interactionstep,
- String cocodes) throws IOException, TemplateException {
- Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
- // 设置模板所在目录
- cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
- // 获取模板对象
- Template template = cfg.getTemplate("fireControl.ftl");
- // 定义数据模型(Map)
- Map<String, Object> dataModel = new HashMap<>();
- //几何文件路径
- dataModel.put("geoFilePath", BPATH + "/" + aid + "/" + jid + "/Geometry");
- //fireinit 文件路径
- dataModel.put("initFilePath", BPATH + "/" + aid + "/" + jid + "/fire" + "/" + "Fire.init");
- //fireInteractionPath 阀门文件路径
- dataModel.put("fireInteractionPath", "/home/disaster/fire/Fire.interaction");
- //midPath
- dataModel.put("monitorPath", BPATH + "/" + aid + "/" + jid + "/monitor.in");
- //midPath
- dataModel.put("midPath", BPATH + "/" + aid + "/" + jid + "/fire" + "/mid");
- //outPath
- dataModel.put("outPath", BPATH + "/" + aid + "/" + jid + "/fire" + "/out");
- dataModel.put("totaltime", totaltime);
- dataModel.put("dt", dt);
- dataModel.put("dx", dx);
- dataModel.put("reportstep", reportstep);
- dataModel.put("interactionstep", interactionstep);
- DSourceMapper dsm = UtilTools.getBean(DSourceMapper.class);
- DSourceSQLBuilder dss = new DSourceSQLBuilder();
- DSourceSQLBuilder.Criteria dssc = dss.createCriteria();
- dssc.andAidEqualTo(aid);
- // dssc.andSTypeEqualTo("Fire");
- List<DSource> dources = dsm.selectByExample(dss);
- //fireSourceNum 灾源数量
- dataModel.put("fireSourceNum", dources.size());
- //边界
- DBoundaryMapper dBoundaryMapper = UtilTools.getBean(DBoundaryMapper.class);
- DBoundarySQLBuilder sb = new DBoundarySQLBuilder();
- DBoundarySQLBuilder.Criteria sc = sb.createCriteria();
- sc.andAidEqualTo(aid);
- List<DBoundary> boundaries = dBoundaryMapper.selectByExample(sb);
- //边界数量
- dataModel.put("boundarynum", boundaries.size());
- //物理量
- String[] codes = cocodes.split(",");
- List<String> concodeList = new ArrayList<>();
- for (String concode : codes
- ) {
- concodeList.add(concode);
- }
- DConMapper conMapper = UtilTools.getBean(DConMapper.class);
- DConSQLBuilder consb = new DConSQLBuilder();
- DConSQLBuilder.Criteria consc = consb.createCriteria();
- consc.andCodeIn(concodeList);
- List<DCon> cons = conMapper.selectByExample(consb);
- dataModel.put("conNum", cons.size());
- dataModel.put("cons", cons);
- // 将数据模型传入模板进行处理
- StringWriter writer = new StringWriter();
- template.process(dataModel, writer);
- mkDirs(aid, jid, "/fire");
- FileWriter fileWriter = new FileWriter(BPATH + "/" + aid + "/" + jid + "/" + "/fire" + "/Fire.control");
- fileWriter.write(writer.toString());
- fileWriter.close();
- }
- public static void createFireRunsh(Integer aid, Integer jid) throws IOException, TemplateException {
- Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
- // 设置模板所在目录
- cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
- // 获取模板对象
- Template template = cfg.getTemplate("fireRunsh.ftl");
- // 定义数据模型(Map)
- Map<String, Object> dataModel = new HashMap<>();
- //几何文件路径
- dataModel.put("firecontrolPath", BPATH + "/" + aid + "/" + jid + "/fire" + "/Fire.control");
- // 将数据模型传入模板进行处理
- StringWriter writer = new StringWriter();
- template.process(dataModel, writer);
- FileWriter fileWriter = new FileWriter(BPATH + "/" + aid + "/" + jid + "/fire" + "/" + "runFile.sh");
- fileWriter.write(writer.toString());
- fileWriter.close();
- }
- public static void createFireInit(Integer aid, Integer jid) throws IOException, TemplateException {
- FireInitVo vo = new FireInitVo();
- //TODO 求解器暂时不需要此数据
- // DNodeValMapper dnvm= UtilTools.getBean(DNodeValMapper.class);
- // DNodeValSQLBuilder dns = new DNodeValSQLBuilder();
- // DNodeValSQLBuilder.Criteria dnsc= dns.createCriteria();
- // dnsc.andAidEqualTo(aid);
- // List<DNodeVal> nodeVals=dnvm.selectByExample(dns);
- // vo.setNodeVals(nodeVals);
- DSourceMapper dsm = UtilTools.getBean(DSourceMapper.class);
- DSourceSQLBuilder dss = new DSourceSQLBuilder();
- DSourceSQLBuilder.Criteria dssc = dss.createCriteria();
- dssc.andAidEqualTo(aid);
- // dssc.andSTypeEqualTo("Fire");
- List<DSource> dources = dsm.selectByExample(dss);
- DSourceValMapper dsvm = UtilTools.getBean(DSourceValMapper.class);
- DSourceValSQLBuilder dsvs = new DSourceValSQLBuilder();
- List<DSourceVo> dourceVos = new ArrayList<>();
- for (DSource ds : dources) {
- DSourceValSQLBuilder.Criteria dsvc = dsvs.createCriteria();
- dsvc.andSidEqualTo(ds.getId());
- List<DSourceVal> dSourceVals = dsvm.selectByExample(dsvs);
- DSourceVo dsourcevo = new DSourceVo();
- dsourcevo.setDsource(ds);
- dsourcevo.setDsourceVals(dSourceVals);
- dourceVos.add(dsourcevo);
- dsvs.clear();
- }
- vo.setDourceVos(dourceVos);
- //边界
- DBoundaryMapper dBoundaryMapper = UtilTools.getBean(DBoundaryMapper.class);
- DBoundarySQLBuilder sb = new DBoundarySQLBuilder();
- DBoundarySQLBuilder.Criteria sc = sb.createCriteria();
- sc.andAidEqualTo(aid);
- List<DBoundary> boundaries = dBoundaryMapper.selectByExample(sb);
- Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
- // 设置模板所在目录
- cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
- // 获取模板对象
- Template template = cfg.getTemplate("fireInit.ftl");
- // 定义数据模型(Map)
- Map<String, Object> dataModel = new HashMap<>();
- //几何文件路径
- dataModel.put("vo", vo);
- //边界
- dataModel.put("boundaries", boundaries);
- // 将数据模型传入模板进行处理
- StringWriter writer = new StringWriter();
- template.process(dataModel, writer);
- // 输出结果到控制台或保存为文件
- // System.out.println(writer.toString());
- FileWriter fileWriter = new FileWriter(BPATH + "/" + aid + "/" + jid + "/fire" + "/" + "Fire.init");
- fileWriter.write(writer.toString());
- fileWriter.close();
- }
- public static void main(String[] args) throws Exception {
- // TemplateGenerator.createWaterRunsh(5);
- float myFloat = 495545.603f;
- String formattedString = String.format("%.32f", myFloat);
- System.out.println(myFloat); // 输出: 123.46
- System.out.println(formattedString); // 输出: 123.46
- }
- public static void createGasControl(Integer aid, Integer jid, String totaltime,
- String dt, String dx, String reportstep, String interactionstep,
- String cocodes) throws IOException, TemplateException {
- Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
- // 设置模板所在目录
- cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
- // 获取模板对象
- Template template = cfg.getTemplate("mashGasControl.ftl");
- // 定义数据模型(Map)
- Map<String, Object> dataModel = new HashMap<>();
- //几何文件路径
- dataModel.put("geoFilePath", BPATH + "/" + aid + "/" + jid + "/Geometry");
- //fireinit 文件路径
- dataModel.put("initFilePath", BPATH + "/" + aid + "/" + jid + "/gas" + "/" + "MashGas.init");
- //midPath
- dataModel.put("monitorPath", BPATH + "/" + aid + "/" + jid + "/monitor.in");
- //midPath
- dataModel.put("midPath", BPATH + "/" + aid + "/" + jid + "/gas" + "/" + "mid");
- //outPath
- dataModel.put("outPath", BPATH + "/" + aid + "/" + jid + "/gas" + "/" + "out");
- //CPUS
- dataModel.put("cups", 4);
- dataModel.put("totaltime", totaltime);
- dataModel.put("dt", dt);
- dataModel.put("dx", dx);
- dataModel.put("reportstep", reportstep);
- dataModel.put("interactionstep", interactionstep);
- DBoundaryMapper dBoundaryMapper = UtilTools.getBean(DBoundaryMapper.class);
- DBoundarySQLBuilder sb = new DBoundarySQLBuilder();
- DBoundarySQLBuilder.Criteria sc = sb.createCriteria();
- sc.andAidEqualTo(aid);
- List<DBoundary> boundaries = dBoundaryMapper.selectByExample(sb);
- //边界数量
- dataModel.put("boundarynum", boundaries.size());
- //TODO
- dataModel.put("mashgasnumber", 1);
- //fireInteractionPath 阀门文件路径
- dataModel.put("fireInteractionPath", "/home/disaster/fire/Fire.interaction");
- //物理量
- if (StringUtil.isEmpty(cocodes)) {
- dataModel.put("conNum", 0);
- dataModel.put("cons", new ArrayList<>());
- } else {
- String[] codes = cocodes.split(",");
- List<String> concodeList = new ArrayList<>();
- for (String concode : codes
- ) {
- concodeList.add(concode);
- }
- DConMapper conMapper = UtilTools.getBean(DConMapper.class);
- DConSQLBuilder consb = new DConSQLBuilder();
- DConSQLBuilder.Criteria consc = consb.createCriteria();
- consc.andCodeIn(concodeList);
- List<DCon> cons = conMapper.selectByExample(consb);
- dataModel.put("conNum", cons.size());
- dataModel.put("cons", cons);
- }
- // 将数据模型传入模板进行处理
- StringWriter writer = new StringWriter();
- template.process(dataModel, writer);
- mkGassDirs(aid, jid);
- FileWriter fileWriter = new FileWriter(BPATH + "/" + aid + "/" + jid + "/" + "/gas" + "/MashGas.control");
- fileWriter.write(writer.toString());
- fileWriter.close();
- }
- public static void createGasInit(Integer aid, Integer jid, Integer gid) throws IOException, TemplateException, BusinessException {
- Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
- // 设置模板所在目录
- cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
- // 获取模板对象
- Template template = cfg.getTemplate("mashGasInit.ftl");
- // 定义数据模型(Map)
- Map<String, Object> dataModel = new HashMap<>();
- DGasBlastAreaMapper blastMapper = UtilTools.getBean(DGasBlastAreaMapper.class);
- DGasBlastAreaSQLBuilder blastSb = new DGasBlastAreaSQLBuilder();
- DGasBlastAreaSQLBuilder.Criteria blastSc = blastSb.createCriteria();
- blastSc.andGidEqualTo(gid);
- List<DGasBlastArea> blastList = blastMapper.selectByExample(blastSb);
- if (blastList.isEmpty()) {
- throw new BusinessException("EB3100023");
- }
- //边界
- DBoundaryMapper dBoundaryMapper = UtilTools.getBean(DBoundaryMapper.class);
- DBoundarySQLBuilder sb = new DBoundarySQLBuilder();
- DBoundarySQLBuilder.Criteria sc = sb.createCriteria();
- sc.andAidEqualTo(aid);
- List<DBoundary> boundaries = dBoundaryMapper.selectByExample(sb);
- dataModel.put("boundaries", boundaries);
- dataModel.put("blastnum", blastList.size());
- dataModel.put("blastList", blastList);
- DGasGatherAreaMapper gatherMapper = UtilTools.getBean(DGasGatherAreaMapper.class);
- DGasGatherAreaSQLBuilder gatherSb = new DGasGatherAreaSQLBuilder();
- DGasGatherAreaSQLBuilder.Criteria gatherSc = gatherSb.createCriteria();
- gatherSc.andGidEqualTo(gid);
- gatherSb.setOrderByClause("id ASC");
- List<DGasGatherArea> gatherList = gatherMapper.selectByExample(gatherSb);
- if (gatherList.isEmpty()) {
- throw new BusinessException("EB3100024");
- }
- dataModel.put("gathernum", gatherList.size());
- dataModel.put("gatherList", gatherList);
- DGasMapper gasMapper = UtilTools.getBean(DGasMapper.class);
- DGas gas = gasMapper.selectByPrimaryKey(gid);
- dataModel.put("gas", gas);
- // 将数据模型传入模板进行处理
- StringWriter writer = new StringWriter();
- template.process(dataModel, writer);
- mkGassDirs(aid, jid);
- FileWriter fileWriter = new FileWriter(BPATH + "/" + aid + "/" + jid + "/" + "/gas" + "/MashGas.init");
- fileWriter.write(writer.toString());
- fileWriter.close();
- }
- public static void createGassRunsh(Integer aid, Integer jid) throws IOException, TemplateException {
- Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
- // 设置模板所在目录
- cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
- // 获取模板对象
- Template template = cfg.getTemplate("mashGasRunsh.ftl");
- // 定义数据模型(Map)
- Map<String, Object> dataModel = new HashMap<>();
- dataModel.put("casepath", BPATH + "/" + aid + "/" + jid + "/gas" + "/case");
- dataModel.put("datahis", BPATH + "/" + aid + "/" + jid + "/gas" + "/data_his");
- dataModel.put("gascontrol", BPATH + "/" + aid + "/" + jid + "/gas" + "/MashGas.control");
- dataModel.put("gasescapecontrol", BPATH + "/" + aid + "/" + jid + "/" + "/gas" + "/gasEscape.control");
- // 将数据模型传入模板进行处理
- StringWriter writer = new StringWriter();
- template.process(dataModel, writer);
- mkGassDirs(aid, jid);
- FileWriter fileWriter = new FileWriter(BPATH + "/" + aid + "/" + jid + "/" + "/gas" + "/run.sh");
- fileWriter.write(writer.toString());
- fileWriter.close();
- }
- public static void createGas1Control(Integer aid, Integer jid, String totaltime,
- String dt, String dx, String reportstep, String interactionstep,
- String cocodes) throws IOException, TemplateException {
- Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
- // 设置模板所在目录
- cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
- // 获取模板对象
- Template template = cfg.getTemplate("mashGas1Control.ftl");
- // 定义数据模型(Map)
- Map<String, Object> dataModel = new HashMap<>();
- //几何文件路径
- dataModel.put("geoFilePath", BPATH + "/" + aid + "/" + jid + "/Geometry");
- //fireinit 文件路径
- dataModel.put("initFilePath", BPATH + "/" + aid + "/" + jid + "/gas" + "/" + "MashGas.init");
- //midPath
- dataModel.put("monitorPath", BPATH + "/" + aid + "/" + jid + "/monitor.in");
- //midPath
- dataModel.put("midPath", BPATH + "/" + aid + "/" + jid + "/gas" + "/" + "mid");
- //outPath
- dataModel.put("outPath", BPATH + "/" + aid + "/" + jid + "/gas" + "/" + "out");
- //CPUS
- dataModel.put("cups", 4);
- dataModel.put("totaltime", totaltime);
- dataModel.put("dt", dt);
- dataModel.put("dx", dx);
- dataModel.put("reportstep", reportstep);
- dataModel.put("interactionstep", interactionstep);
- DBoundaryMapper dBoundaryMapper = UtilTools.getBean(DBoundaryMapper.class);
- DBoundarySQLBuilder sb = new DBoundarySQLBuilder();
- DBoundarySQLBuilder.Criteria sc = sb.createCriteria();
- sc.andAidEqualTo(aid);
- List<DBoundary> boundaries = dBoundaryMapper.selectByExample(sb);
- //边界数量
- dataModel.put("boundarynum", boundaries.size());
- //TODO
- dataModel.put("mashgasnumber", 1);
- //物理量
- if (StringUtil.isEmpty(cocodes)) {
- dataModel.put("conNum", 0);
- dataModel.put("cons", new ArrayList<>());
- } else {
- String[] codes = cocodes.split(",");
- List<String> concodeList = new ArrayList<>();
- for (String concode : codes
- ) {
- concodeList.add(concode);
- }
- DConMapper conMapper = UtilTools.getBean(DConMapper.class);
- DConSQLBuilder consb = new DConSQLBuilder();
- DConSQLBuilder.Criteria consc = consb.createCriteria();
- consc.andCodeIn(concodeList);
- List<DCon> cons = conMapper.selectByExample(consb);
- dataModel.put("conNum", cons.size());
- dataModel.put("cons", cons);
- }
- // 将数据模型传入模板进行处理
- StringWriter writer = new StringWriter();
- template.process(dataModel, writer);
- mkGassDirs(aid, jid);
- FileWriter fileWriter = new FileWriter(BPATH + "/" + aid + "/" + jid + "/" + "/gas" + "/MashGas.control");
- fileWriter.write(writer.toString());
- fileWriter.close();
- }
- public static void createGas1Init(Integer aid, Integer jid, Integer gid) throws IOException, TemplateException, BusinessException {
- Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
- // 设置模板所在目录
- cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
- // 获取模板对象
- Template template = cfg.getTemplate("mashGas1Init.ftl");
- // 定义数据模型(Map)
- Map<String, Object> dataModel = new HashMap<>();
- //边界
- DBoundaryMapper dBoundaryMapper = UtilTools.getBean(DBoundaryMapper.class);
- DBoundarySQLBuilder sb = new DBoundarySQLBuilder();
- DBoundarySQLBuilder.Criteria sc = sb.createCriteria();
- sc.andAidEqualTo(aid);
- List<DBoundary> boundaries = dBoundaryMapper.selectByExample(sb);
- dataModel.put("boundaries", boundaries);
- DGasMapper gasMapper = UtilTools.getBean(DGasMapper.class);
- DGas gas = gasMapper.selectByPrimaryKey(gid);
- dataModel.put("b", gas);
- // 将数据模型传入模板进行处理
- StringWriter writer = new StringWriter();
- template.process(dataModel, writer);
- mkGassDirs(aid, jid);
- FileWriter fileWriter = new FileWriter(BPATH + "/" + aid + "/" + jid + "/" + "/gas" + "/MashGas.init");
- fileWriter.write(writer.toString());
- fileWriter.close();
- }
- public static void createGass1Runsh(Integer aid, Integer jid) throws IOException, TemplateException {
- Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
- // 设置模板所在目录
- cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
- // 获取模板对象
- Template template = cfg.getTemplate("mashGas1Runsh.ftl");
- // 定义数据模型(Map)
- Map<String, Object> dataModel = new HashMap<>();
- dataModel.put("gascontrol", BPATH + "/" + aid + "/" + jid + "/gas" + "/MashGas.control");
- dataModel.put("gasescapecontrol", BPATH + "/" + aid + "/" + jid + "/" + "/gas" + "/gasEscape.control");
- dataModel.put("midPath", BPATH + "/" + aid + "/" + jid + "/gas" + "/" + "mid");
- // 将数据模型传入模板进行处理
- StringWriter writer = new StringWriter();
- template.process(dataModel, writer);
- mkGassDirs(aid, jid);
- FileWriter fileWriter = new FileWriter(BPATH + "/" + aid + "/" + jid + "/" + "/gas" + "/run.sh");
- fileWriter.write(writer.toString());
- fileWriter.close();
- }
- }
|