|
@@ -41,13 +41,35 @@ public class TemplateGenerator {
|
|
|
fileWriter.write(writer.toString());
|
|
|
fileWriter.close();
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 创建 执行文件
|
|
|
+ * @param pid
|
|
|
+ * @throws IOException
|
|
|
+ * @throws TemplateException
|
|
|
+ */
|
|
|
+ public static void createRunpy2(String pid) throws IOException, TemplateException {
|
|
|
+ Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
|
|
|
+ // 设置模板所在目录
|
|
|
+ cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
|
|
|
+ // 获取模板对象
|
|
|
+ Template template = cfg.getTemplate("run2.ftl");
|
|
|
+ // 定义数据模型(Map)
|
|
|
+ Map<String, Object> dataModel = new HashMap<>();
|
|
|
+ dataModel.put("problemPath",LogService.BPATH + "/" + pid + "/in/problem.xml");
|
|
|
+ // 将数据模型传入模板进行处理
|
|
|
+ StringWriter writer = new StringWriter();
|
|
|
+ template.process(dataModel, writer);
|
|
|
+ FileWriter fileWriter = new FileWriter(LogService.BPATH + "/" + pid + "/in/run.py");
|
|
|
+ fileWriter.write(writer.toString());
|
|
|
+ fileWriter.close();
|
|
|
+ }
|
|
|
/**
|
|
|
* 创建problem.xml
|
|
|
* @param pid
|
|
|
* @throws IOException
|
|
|
* @throws TemplateException
|
|
|
*/
|
|
|
- public static void createProblemXml(String pid) throws IOException, TemplateException {
|
|
|
+ public static void createProblemXml(String pid,ProblemVo vo) throws IOException, TemplateException {
|
|
|
//Problem.xml 写入
|
|
|
Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
|
|
|
// 设置模板所在目录
|
|
@@ -57,7 +79,7 @@ public class TemplateGenerator {
|
|
|
// 定义数据模型(Map)
|
|
|
Map<String, Object> dataModel = new HashMap<>();
|
|
|
|
|
|
- ProblemVo vo = findProblemVo(pid);
|
|
|
+// ProblemVo vo = findProblemVo(pid);
|
|
|
|
|
|
dataModel.put("vo",vo);
|
|
|
// dataModel.put("geoFilePath", BPATH + "/" + aid + "/" + jid + "/Geometry");
|
|
@@ -87,8 +109,7 @@ public class TemplateGenerator {
|
|
|
vo.setSurro(surro);
|
|
|
MdoProGrad grad = findGrad(pid);
|
|
|
vo.setGrad(grad);
|
|
|
- List<Solver> solvers = findSolvers(pid);
|
|
|
- vo.setSolvers(solvers);
|
|
|
+
|
|
|
return vo;
|
|
|
}
|
|
|
|
|
@@ -96,8 +117,11 @@ public class TemplateGenerator {
|
|
|
* TODO 创建 cpacsxml
|
|
|
* @return
|
|
|
*/
|
|
|
- public static String createcCpacsXml(String pid) {
|
|
|
+ public static String createcCpacsXml(String pid,CpacsVo vo) {
|
|
|
try {
|
|
|
+ if(vo ==null){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
|
|
|
// 设置模板所在目录
|
|
|
cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
|
|
@@ -105,20 +129,46 @@ public class TemplateGenerator {
|
|
|
Template template = cfg.getTemplate("cpacs.ftl");
|
|
|
// 定义数据模型(Map)
|
|
|
Map<String, Object> dataModel = new HashMap<>();
|
|
|
- CpacsVo vo = new CpacsVo();
|
|
|
- HeaderVo header =new HeaderVo();
|
|
|
- header.setName(pid);
|
|
|
- header.setTimestamp(new Date());
|
|
|
- vo.setHeader(header);
|
|
|
-
|
|
|
- MdoProXfoil xfoil = findXfoil(pid);
|
|
|
- vo.setXfoil(xfoil);
|
|
|
- MdoProAdflow adflow = findAdflow(pid);
|
|
|
- vo.setAdflow(adflow);
|
|
|
- //不用生成
|
|
|
- if(xfoil==null&& adflow==null){
|
|
|
- return "";
|
|
|
- }
|
|
|
+
|
|
|
+ dataModel.put("vo",vo);
|
|
|
+ //dataModel.put("geoFilePath", BPATH + "/" + aid + "/" + jid + "/Geometry");
|
|
|
+ // 将数据模型传入模板进行处理
|
|
|
+ StringWriter writer = new StringWriter();
|
|
|
+ template.process(dataModel, writer);
|
|
|
+ FileWriter fileWriter = new FileWriter(LogService.BPATH + "/" + pid + "/in/cpacs.xml");
|
|
|
+ fileWriter.write(writer.toString());
|
|
|
+ fileWriter.close();
|
|
|
+ return LogService.BPATH + "/" + pid + "/in/cpacs.xml";
|
|
|
+ }catch (Exception e){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public static WorkflowVo getWorkflowVo(String pid) {
|
|
|
+ WorkflowVo vo = new WorkflowVo();
|
|
|
+ MdoProXfoil xfoil = findXfoil(pid);
|
|
|
+ MdoProAdflow adflow = findAdflow(pid);
|
|
|
+ //不用生成
|
|
|
+ if(xfoil==null&& adflow==null){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+ public static CpacsVo getCpacsVo(String pid) {
|
|
|
+ CpacsVo vo = new CpacsVo();
|
|
|
+ HeaderVo header =new HeaderVo();
|
|
|
+ header.setName(pid);
|
|
|
+ header.setTimestamp(new Date());
|
|
|
+ vo.setHeader(header);
|
|
|
+
|
|
|
+ MdoProXfoil xfoil = findXfoil(pid);
|
|
|
+ vo.setXfoil(xfoil);
|
|
|
+ MdoProAdflow adflow = findAdflow(pid);
|
|
|
+ vo.setAdflow(adflow);
|
|
|
+ //不用生成
|
|
|
+ if(xfoil==null&& adflow==null){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if(xfoil!=null){
|
|
|
List<MdoProInoutPara> xInoutList = findMdoProInoutParas(pid, xfoil.getId());
|
|
|
XfoilInVo xinvo = new XfoilInVo();
|
|
|
// alpha mach reynolds
|
|
@@ -134,8 +184,8 @@ public class TemplateGenerator {
|
|
|
xoutvo.setXtr_upper(getValByParaListAndCode(xInoutList,"xtr_upper"));
|
|
|
xoutvo.setXtr_lower(getValByParaListAndCode(xInoutList,"xtr_lower"));
|
|
|
vo.setXoutvo(xoutvo);
|
|
|
-
|
|
|
-
|
|
|
+ }
|
|
|
+ if(adflow!=null){
|
|
|
List<MdoProInoutPara> adInoutList = findMdoProInoutParas(pid, adflow.getId());
|
|
|
AdflowInVo adinvo = new AdflowInVo();
|
|
|
adinvo.setMode(getValByParaListAndCode(adInoutList,"mode"));
|
|
@@ -151,24 +201,16 @@ public class TemplateGenerator {
|
|
|
adoutvo.setCd(getValByParaListAndCode(adInoutList,"cd"));
|
|
|
adoutvo.setCmz(getValByParaListAndCode(adInoutList,"cmz"));
|
|
|
vo.setAdoutvo(adoutvo);
|
|
|
+ }
|
|
|
|
|
|
- MdoProCst cst = findCst(pid);
|
|
|
- vo.setCst(cst);
|
|
|
- MdoProFfd ffd = getFfd(pid);
|
|
|
- vo.setFfd(ffd);
|
|
|
|
|
|
- dataModel.put("vo",vo);
|
|
|
- //dataModel.put("geoFilePath", BPATH + "/" + aid + "/" + jid + "/Geometry");
|
|
|
- // 将数据模型传入模板进行处理
|
|
|
- StringWriter writer = new StringWriter();
|
|
|
- template.process(dataModel, writer);
|
|
|
- FileWriter fileWriter = new FileWriter(LogService.BPATH + "/" + pid + "/in/cpacs.xml");
|
|
|
- fileWriter.write(writer.toString());
|
|
|
- fileWriter.close();
|
|
|
- return LogService.BPATH + "/" + pid + "/in/cpacs.xml";
|
|
|
- }catch (Exception e){
|
|
|
- return null;
|
|
|
- }
|
|
|
+
|
|
|
+
|
|
|
+ MdoProCst cst = findCst(pid);
|
|
|
+ vo.setCst(cst);
|
|
|
+ MdoProFfd ffd = getFfd(pid);
|
|
|
+ vo.setFfd(ffd);
|
|
|
+ return vo;
|
|
|
}
|
|
|
|
|
|
private static List<MdoProInoutPara> findMdoProInoutParas(String pid, String fatherid) {
|
|
@@ -200,7 +242,7 @@ public class TemplateGenerator {
|
|
|
xsc.andCheckedEqualTo(1);
|
|
|
List<MdoProFfd> xList = xdao.selectByExample(xsb);
|
|
|
MdoProFfd ffd =null;
|
|
|
- if(xList!=null&&xList.isEmpty()){
|
|
|
+ if(xList!=null&&!xList.isEmpty()){
|
|
|
ffd=xList.get(0);
|
|
|
}
|
|
|
return ffd;
|
|
@@ -214,7 +256,7 @@ public class TemplateGenerator {
|
|
|
xsc.andCheckedEqualTo(1);
|
|
|
List<MdoProCst> xList = xdao.selectByExample(xsb);
|
|
|
MdoProCst cst =null;
|
|
|
- if(xList!=null&&xList.isEmpty()){
|
|
|
+ if(xList!=null&&!xList.isEmpty()){
|
|
|
cst=xList.get(0);
|
|
|
}
|
|
|
return cst;
|
|
@@ -228,7 +270,7 @@ public class TemplateGenerator {
|
|
|
xsc.andCheckedEqualTo(1);
|
|
|
List<MdoProAdflow> xList = xdao.selectByExample(xsb);
|
|
|
MdoProAdflow adflow =null;
|
|
|
- if(xList!=null&&xList.isEmpty()){
|
|
|
+ if(xList!=null&&!xList.isEmpty()){
|
|
|
adflow=xList.get(0);
|
|
|
}
|
|
|
return adflow;
|
|
@@ -242,7 +284,7 @@ public class TemplateGenerator {
|
|
|
xsc.andCheckedEqualTo(1);
|
|
|
List<MdoProXfoil> xList = xdao.selectByExample(xsb);
|
|
|
MdoProXfoil xfoil =null;
|
|
|
- if(xList!=null&&xList.isEmpty()){
|
|
|
+ if(xList!=null&&!xList.isEmpty()){
|
|
|
xfoil=xList.get(0);
|
|
|
}
|
|
|
return xfoil;
|
|
@@ -252,34 +294,36 @@ public class TemplateGenerator {
|
|
|
* TODO 创建 workflowXml
|
|
|
* @return
|
|
|
*/
|
|
|
- public static String createcWorkflowXml(String pid){
|
|
|
-
|
|
|
- return null;
|
|
|
- }
|
|
|
+ public static String createcWorkflowXml(String pid,WorkflowVo vo){
|
|
|
+ try {
|
|
|
+ if(vo ==null){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ Configuration cfg = new Configuration(Configuration.VERSION_2_3_0);
|
|
|
+ // 设置模板所在目录
|
|
|
+ cfg.setClassForTemplateLoading(TemplateGenerator.class, "/templates");
|
|
|
+ // 获取模板对象
|
|
|
+ Template template = cfg.getTemplate("workflow.ftl");
|
|
|
+ // 定义数据模型(Map)
|
|
|
+ Map<String, Object> dataModel = new HashMap<>();
|
|
|
+// CpacsVo vo = getCpacsVo(pid);
|
|
|
|
|
|
- /**
|
|
|
- * 获取 求解器配置
|
|
|
- * @param pid
|
|
|
- * @return
|
|
|
- * @throws IOException
|
|
|
- */
|
|
|
- private static List<Solver> findSolvers(String pid) throws IOException {
|
|
|
- //TODO 目前只有函数求解器
|
|
|
- MdoProjectMapper pDao = UtilTools.getBean(MdoProjectMapper.class);
|
|
|
- MdoProject p = pDao.selectByPrimaryKey(pid);
|
|
|
- List<Solver> solvers =new ArrayList<>();
|
|
|
- //ptyon py.py 文件 写入
|
|
|
- String ppPath=writePython(pid);
|
|
|
- if(!StringUtil.isEmpty(ppPath)){
|
|
|
- Solver solver =new Solver();
|
|
|
- solver.setPythonPath(ppPath);
|
|
|
- solver.setStype(p.getStype());
|
|
|
- solvers.add(solver);
|
|
|
+ dataModel.put("vo",vo);
|
|
|
+ //dataModel.put("geoFilePath", BPATH + "/" + aid + "/" + jid + "/Geometry");
|
|
|
+ // 将数据模型传入模板进行处理
|
|
|
+ StringWriter writer = new StringWriter();
|
|
|
+ template.process(dataModel, writer);
|
|
|
+ FileWriter fileWriter = new FileWriter(LogService.BPATH + "/" + pid + "/in/workflow.xml");
|
|
|
+ fileWriter.write(writer.toString());
|
|
|
+ fileWriter.close();
|
|
|
+ return LogService.BPATH + "/" + pid + "/in/workflow.xml";
|
|
|
+ }catch (Exception e){
|
|
|
+ return null;
|
|
|
}
|
|
|
- return solvers;
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
private static MdoProGrad findGrad(String pid) {
|
|
|
MdoProGrad grad = null;
|
|
|
MdoProGradMapper edao = UtilTools.getBean(MdoProGradMapper.class);
|
|
@@ -337,7 +381,7 @@ public class TemplateGenerator {
|
|
|
List<MdoProjectConstraint> cList = cdao.selectByExample(csb);
|
|
|
for (MdoProjectConstraint c:cList) {
|
|
|
Constraint vc =new Constraint();
|
|
|
- vc.setuID(c.getId());
|
|
|
+ vc.setuID(c.getUid()!=null?c.getUid():c.getId());
|
|
|
vc.setName(c.getName());
|
|
|
vc.setValue(c.getReference());
|
|
|
vc.setLower(c.getLower());
|
|
@@ -355,7 +399,7 @@ public class TemplateGenerator {
|
|
|
List<MdoProjectObjfun> objList =objdao.selectByExample(objsb);
|
|
|
for (MdoProjectObjfun obj:objList) {
|
|
|
Objective vObj =new Objective();
|
|
|
- vObj.setuID(obj.getId());
|
|
|
+ vObj.setuID(obj.getUid()!=null?obj.getUid():obj.getId());
|
|
|
vObj.setName(obj.getName());
|
|
|
vObj.setValue(obj.getReference());
|
|
|
vObj.setWeight(obj.getWeight());
|
|
@@ -398,7 +442,11 @@ public class TemplateGenerator {
|
|
|
List<String> values = new ArrayList<>();
|
|
|
List<String> lowerbounds = new ArrayList<>();
|
|
|
List<String> upperbounds = new ArrayList<>();
|
|
|
+ String uid = null;
|
|
|
for (MdoProjectVariate tv:tVlist) {
|
|
|
+ if(!StringUtil.isEmpty(tv.getUid())){
|
|
|
+ uid=tv.getUid();
|
|
|
+ }
|
|
|
values.add(tv.getReference());
|
|
|
lowerbounds.add(tv.getLower());
|
|
|
upperbounds.add(tv.getUpper());
|
|
@@ -406,7 +454,7 @@ public class TemplateGenerator {
|
|
|
dv.setValue(values);
|
|
|
dv.setLowerbound(lowerbounds);
|
|
|
dv.setUpperbound(upperbounds);
|
|
|
- dv.setuID(UtilTools.getUUid());//TODO 目前结构不清
|
|
|
+ dv.setuID(uid!=null?uid:UtilTools.getUUid());//TODO 目前结构不清
|
|
|
designVariables.add(dv);
|
|
|
}
|
|
|
return designVariables;
|
|
@@ -418,7 +466,7 @@ public class TemplateGenerator {
|
|
|
* @return
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
- private static String writePython(String pid) throws IOException {
|
|
|
+ public static String writePython(String pid) throws IOException {
|
|
|
MdoProPythonMapper ppDao = UtilTools.getBean(MdoProPythonMapper.class);
|
|
|
MdoProPythonSQLBuilder ppsb = new MdoProPythonSQLBuilder();
|
|
|
ppsb.createCriteria().andPidEqualTo(pid);
|
|
@@ -433,4 +481,6 @@ public class TemplateGenerator {
|
|
|
}
|
|
|
return "";
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|