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