AFT001Service.java 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. package com.miniframe.bisiness.system;
  2. import java.io.File;
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Map;
  6. import java.util.stream.Stream;
  7. import com.alibaba.nacos.shaded.com.google.gson.JsonArray;
  8. import com.alibaba.nacos.shaded.com.google.gson.JsonObject;
  9. import com.alibaba.nacos.shaded.io.grpc.netty.shaded.io.netty.util.internal.StringUtil;
  10. import com.fasterxml.jackson.core.JsonProcessingException;
  11. import com.miniframe.aftercure.ActionMsg;
  12. import com.miniframe.aftercure.AnimationFile;
  13. import com.miniframe.aftercure.SliceMsg;
  14. import com.miniframe.aftercure.StreamMsg;
  15. import com.miniframe.constant.MFConstant;
  16. import com.miniframe.core.ExecProcessFlow;
  17. import com.miniframe.core.exception.BusinessException;
  18. import com.miniframe.core.ext.UtilTools;
  19. import com.miniframe.generate.business.system.model.AFT001BaseModel;
  20. import com.miniframe.model.system.*;
  21. import com.miniframe.model.system.dao.*;
  22. import com.miniframe.service.mq.CaeMQ;
  23. import com.miniframe.solverconfig.fem.FEMPath;
  24. import com.miniframe.solverconfig.hcfd.HcfdPath;
  25. import com.miniframe.spring.mq.MFMqUtils;
  26. import com.miniframe.tools.XIFileUtils;
  27. import com.miniframe.tools.XiJsonUtil;
  28. import org.json.JSONArray;
  29. import org.json.JSONObject;
  30. /**
  31. * 基础系统,“后处理消息发送”逻辑处理(重新生成不覆盖)。
  32. */
  33. public class AFT001Service extends AFT001BaseModel implements ExecProcessFlow {
  34. private static final long serialVersionUID = -7051358269847459502L;
  35. /**
  36. * 基础系统,“后处理消息发送”业务核心处理
  37. */
  38. public void transExecute() throws Exception {
  39. String usrId =this.getA_systemhead().getUserId();
  40. String solverConfigId =getA_aft001().getSolverConfigId();
  41. String proId =getA_aft001().getPid();
  42. String paramJson =getA_aft001().getParamJson();
  43. String action =getA_aft001().getAction();
  44. String step=getA_aft001().getStep();
  45. String scalarName =getA_aft001().getScalarName();
  46. String level =getA_aft001().getLevel();
  47. String range0 =getA_aft001().getRange0();
  48. String range1 =getA_aft001().getRange1();
  49. AdiSolverConfigMapper configMapper = UtilTools.getBean(AdiSolverConfigMapper.class);
  50. AdiSolverConfig config= configMapper.selectByPrimaryKey(solverConfigId);
  51. if(config==null){
  52. throw new BusinessException("EB4000011");
  53. }
  54. AdiSolverMapper solverMapper = UtilTools.getBean(AdiSolverMapper.class);
  55. AdiSolver solver = solverMapper.selectByPrimaryKey(config.getSolverid());
  56. if(solver==null){
  57. throw new BusinessException("EB4000011");
  58. }
  59. ActionMsg msg =new ActionMsg();
  60. msg.setUsrId(usrId);
  61. msg.setSolverConfigid(solverConfigId);
  62. msg.setProId(proId);
  63. msg.setAction(action);
  64. if(action.equals("init")){
  65. msg.setParamJson(paramJson);
  66. }else if(action.equals("loaddata")){
  67. if(solver.getSolverModel().equals("HCFDLab")){
  68. AdiModelingMapper modelingMapper = UtilTools.getBean(AdiModelingMapper.class);
  69. AdiModelingSQLBuilder sb = new AdiModelingSQLBuilder();
  70. AdiModelingSQLBuilder.Criteria sc =sb.createCriteria();
  71. sc.andPidEqualTo(proId);
  72. List<AdiModeling> modelings =modelingMapper.selectByExample(sb);
  73. if(modelings.isEmpty()){
  74. throw new BusinessException("EB4000015");
  75. }else{
  76. AdiModeling modeling = modelings.get(0);
  77. SysFileMapper fileMapper = UtilTools.getBean(SysFileMapper.class);
  78. SysFile file =fileMapper.selectByPrimaryKey(modeling.getGridFile());
  79. if(file==null){
  80. throw new BusinessException("EB4000015");
  81. }
  82. JSONObject obj = new JSONObject();
  83. obj.put("filePath",XIFileUtils.getRootPathStr()+ MFConstant.separator+file.getFilepath());
  84. // obj.put("filePath","F:\\czm\\vtkfile\\tf.ugrid");
  85. obj.put("fileType",modeling.getGridFileType().toLowerCase());
  86. msg.setParamJson(obj.toString());
  87. }
  88. }else if(solver.getSolverModel().equals("FEMLab(结构力学)")){
  89. AdiModelingMapper modelingMapper = UtilTools.getBean(AdiModelingMapper.class);
  90. AdiModelingSQLBuilder sb = new AdiModelingSQLBuilder();
  91. AdiModelingSQLBuilder.Criteria sc =sb.createCriteria();
  92. sc.andPidEqualTo(proId);
  93. List<AdiModeling> modelings =modelingMapper.selectByExample(sb);
  94. if(modelings.isEmpty()){
  95. throw new BusinessException("EB4000015");
  96. }else{
  97. AdiModeling modeling = modelings.get(0);
  98. SysFileMapper fileMapper = UtilTools.getBean(SysFileMapper.class);
  99. SysFile file =fileMapper.selectByPrimaryKey(modeling.getVtkFile());
  100. if(file==null){
  101. throw new BusinessException("EB4000015");
  102. }
  103. JSONObject obj = new JSONObject();
  104. obj.put("filePath",XIFileUtils.getRootPathStr()+ MFConstant.separator+file.getFilepath());
  105. // obj.put("filePath","F:\\czm\\vtkfile\\f.vtk");
  106. obj.put("fileType",modeling.getGridFileType().toLowerCase());
  107. msg.setParamJson(obj.toString());
  108. }
  109. }
  110. }else if(action.equals("zoomout")){//缩小
  111. }else if(action.equals("zoomin")){//放大
  112. }else if(action.equals("AlignToPlusAxisX")){//正x轴对齐
  113. }else if(action.equals("AlignToPlusAxisY")){//正y轴对齐
  114. }else if(action.equals("AlignToPlusAxisZ")){//正z轴对齐
  115. }else if(action.equals("AlignToMinusAxisX")){//负x轴对齐
  116. }else if(action.equals("AlignToMinusAxisY")){//负y轴对齐
  117. }else if(action.equals("AlignToMinusAxisZ")){//负z轴对齐
  118. }else if(action.equals("TransformToIsometric")){//等距视图显示
  119. }else if(action.equals("ResultImport")){
  120. if(solver.getSolverModel().equals("HCFDLab")) {
  121. String jobPath = XIFileUtils.getRootPathStr()+ MFConstant.separator+proId;
  122. String exePath = jobPath+ MFConstant.separator+"hcfd";
  123. String testPath = exePath+ MFConstant.separator+"test";
  124. String exeOutPath = testPath+ MFConstant.separator+"data_out";
  125. List<File> fileList = HcfdPath.getStepFiles(proId, getA_aft001().getIsVolume(), step);
  126. if(fileList.isEmpty()){
  127. throw new BusinessException("EB4000017");
  128. }
  129. String fileName="";
  130. for (int i = 0; i < fileList.size(); i++) {
  131. if(i==fileList.size()-1){
  132. fileName +=fileList.get(i).getName();
  133. }else {
  134. fileName +=fileList.get(i).getName()+",";
  135. }
  136. }
  137. JSONObject obj = new JSONObject();
  138. // obj.put("filePath", "C:\\Users\\Administrator\\Documents\\WeChat Files\\wxid_18qjhi0tq90d22\\FileStorage\\File\\2023-06");
  139. // obj.put("fileType", "ascii");
  140. // obj.put("fileName", "tfg_part1_tec_volume_timestep100.dat");
  141. obj.put("filePath", exeOutPath);
  142. obj.put("fileType", "ascii");
  143. obj.put("fileName", fileName);
  144. msg.setParamJson(obj.toString());
  145. }else if(solver.getSolverModel().equals("FEMLab(结构力学)")){
  146. if(StringUtil.isNullOrEmpty(step)){
  147. step ="1";
  148. }
  149. String jobPath = XIFileUtils.getRootPathStr()+ MFConstant.separator+solver.getPid();
  150. String exePath = jobPath+ MFConstant.separator+"fem";
  151. String exeOutPath = exePath+ MFConstant.separator+"data_out";
  152. File file;
  153. if(!step.equals("0")) {
  154. file = new File(exeOutPath + MFConstant.separator + "dynamicResponse-transient" + step + ".vtk");
  155. }else {
  156. file = new File(exeOutPath+MFConstant.separator+"dynamicResponse-transient.vtk");
  157. }
  158. if(!file.exists()){
  159. throw new BusinessException("EB4000017");
  160. }
  161. JSONObject obj = new JSONObject();
  162. obj.put("filePath", exeOutPath);
  163. obj.put("fileType", "ascii");
  164. if(!step.equals("0")){
  165. obj.put("fileName", "dynamicResponse-transient"+step+".vtk");
  166. }else {
  167. obj.put("fileName", "dynamicResponse-transient.vtk");//静态 模态
  168. }
  169. msg.setParamJson(obj.toString());
  170. }
  171. }else if(action.equals("ContourDisplay")){
  172. JSONObject obj = new JSONObject();
  173. obj.put("level",level);
  174. obj.put("range",range0+","+range1);
  175. obj.put("scalarName",scalarName);
  176. msg.setParamJson(obj.toString());
  177. }else if(action.equals("LineDisplay")){
  178. JSONObject obj = new JSONObject();
  179. obj.put("level",level);
  180. obj.put("range",range0+","+range1);
  181. obj.put("scalarName",scalarName);
  182. msg.setParamJson(obj.toString());
  183. }else if(action.equals("VectorDisplay")){
  184. if(this.getA_aft001().getScaleFactor()==null
  185. ||"".equals(this.getA_aft001().getScaleFactor())||
  186. this.getA_aft001().getDataU()==null
  187. ||"".equals(this.getA_aft001().getDataU())||
  188. this.getA_aft001().getDataV()==null
  189. ||"".equals(this.getA_aft001().getDataV())||
  190. this.getA_aft001().getDataW()==null
  191. ||"".equals(this.getA_aft001().getDataW())
  192. ){
  193. throw new BusinessException("EB4000013");
  194. }
  195. JSONObject obj = new JSONObject();
  196. obj.put("scaleFactor",this.getA_aft001().getScaleFactor());
  197. obj.put("dataU",this.getA_aft001().getDataU());
  198. obj.put("dataV",this.getA_aft001().getDataV());
  199. obj.put("dataW",this.getA_aft001().getDataW());
  200. msg.setParamJson(obj.toString());
  201. }else if(action.equals("SolidSurfaceDisplay")){
  202. String r =this.getA_aft001().getR();
  203. String g =this.getA_aft001().getG();
  204. String b =this.getA_aft001().getB();
  205. String transparency=this.getA_aft001().getTransparency();
  206. String showHideState=this.getA_aft001().getShowHideState();
  207. if(r==null || "".equals(r)
  208. ||g==null || "".equals(g)
  209. ||b==null || "".equals(b)
  210. ||transparency==null || "".equals(transparency)
  211. ||showHideState==null || "".equals(showHideState)
  212. ){
  213. throw new BusinessException("EB4000013");
  214. }
  215. JSONObject obj = new JSONObject();
  216. obj.put("r",r);
  217. obj.put("g",g);
  218. obj.put("b",b);
  219. obj.put("transparency",transparency);
  220. obj.put("showHideState","1".equals(showHideState)?true:false);
  221. msg.setParamJson(obj.toString());
  222. }else if(action.equals("SliceDisplayAdd")){
  223. String index = this.getA_aft001().getIndex();
  224. JSONObject obj = new JSONObject();
  225. obj.put("index",index);
  226. msg.setParamJson(obj.toString());
  227. }else if(action.equals("SliceDisplayUpdate")){
  228. }else if(action.equals("SliceDisplayDel")){
  229. String index = this.getA_aft001().getIndex();
  230. JSONObject obj = new JSONObject();
  231. obj.put("index",index);
  232. msg.setParamJson(obj.toString());
  233. }else if(action.equals("SliceDisplayApply")){
  234. try {
  235. List<SliceMsg> list = XiJsonUtil.jsonToList(paramJson,SliceMsg.class);
  236. msg.setParamJson(paramJson);
  237. }catch (Exception e){
  238. throw new BusinessException("EB4000014");
  239. }
  240. }else if(action.equals("StreamDisplayCreate")){
  241. try {
  242. String x = this.getA_aft001().getX();
  243. String y = this.getA_aft001().getY();
  244. String z = this.getA_aft001().getZ();
  245. String u=this.getA_aft001().getDataU();
  246. String v=this.getA_aft001().getDataV();
  247. String w=this.getA_aft001().getDataW();
  248. if(
  249. // StringUtil.isNullOrEmpty(x)
  250. // ||StringUtil.isNullOrEmpty(y)
  251. // ||StringUtil.isNullOrEmpty(z)
  252. // ||
  253. StringUtil.isNullOrEmpty(w)
  254. ||StringUtil.isNullOrEmpty(u)
  255. ||StringUtil.isNullOrEmpty(v)
  256. ){
  257. throw new BusinessException("EB4000016");
  258. }
  259. JSONObject obj = new JSONObject();
  260. // obj.put("x",x);
  261. // obj.put("y",y);
  262. // obj.put("z",z);
  263. obj.put("u",u);
  264. obj.put("v",v);
  265. obj.put("w",w);
  266. msg.setParamJson(obj.toString());
  267. }catch (Exception e){
  268. throw new BusinessException("EB4000016");
  269. }
  270. }else if(action.equals("StreamDisplayDeleteAll")){
  271. }else if(action.equals("StreamDisplayApply")){
  272. try{
  273. StreamMsg streamMsg= XiJsonUtil.jsonToPojo(paramJson, StreamMsg.class);
  274. if(StringUtil.isNullOrEmpty(streamMsg.getDirection())){
  275. throw new BusinessException("EB4000014");
  276. }
  277. //Both,Forward,Backward
  278. if(!"Both".equals(streamMsg.getDirection())
  279. &&!"Forward".equals(streamMsg.getDirection())
  280. &&!"Backward".equals(streamMsg.getDirection())){
  281. throw new BusinessException("EB4000014");
  282. }
  283. if(StringUtil.isNullOrEmpty(streamMsg.getStreamstyle())){
  284. throw new BusinessException("EB4000014");
  285. }
  286. //(Line,Ribbon,Tube)
  287. if(!"Line".equals(streamMsg.getStreamstyle())
  288. &&!"Ribbon".equals(streamMsg.getStreamstyle())
  289. &&!"Tube".equals(streamMsg.getStreamstyle())){
  290. throw new BusinessException("EB4000014");
  291. }
  292. msg.setParamJson(paramJson);
  293. }catch (Exception e){
  294. throw new BusinessException("EB4000014");
  295. }
  296. }else if(action.equals("animation")){
  297. delOldImg(solverConfigId, proId, action);
  298. JSONObject obj = new JSONObject();
  299. String hideZones =this.getA_aft001().getHideZones();
  300. obj.put("hideZones",hideZones);
  301. if(StringUtil.isNullOrEmpty(this.getA_aft001().getIsVolume())){
  302. obj.put("isVolume","");
  303. }else{
  304. obj.put("isVolume",this.getA_aft001().getIsVolume());
  305. }
  306. animationTypePara(scalarName, level, range0, range1, obj);
  307. if(solver.getSolverModel().equals("HCFDLab")) {
  308. animationHcfdFile(proId, obj,msg);
  309. }else if(solver.getSolverModel().equals("FEMLab(结构力学)")){
  310. animationFemFile(proId, obj,msg);
  311. }
  312. msg.setParamJson(obj.toString());
  313. }
  314. MFMqUtils.get(CaeMQ.class).sendCaein(XiJsonUtil.objectToJson(msg));
  315. }
  316. private void delOldImg(String solverConfigId, String proId, String action) {
  317. AdiSolverConfigImgMapper configImgMapper= UtilTools.getBean(AdiSolverConfigImgMapper.class);
  318. AdiSolverConfigImg img = new AdiSolverConfigImg();
  319. img.setAnimationtype(getA_aft001().getAnimationType());
  320. img.setAction(action);
  321. img.setPid(proId);
  322. if(!StringUtil.isNullOrEmpty(this.getA_aft001().getIsVolume())){
  323. img.setIsvolume(this.getA_aft001().getIsVolume());
  324. }
  325. img.setSolverConfigId(solverConfigId);
  326. configImgMapper.delete(img);
  327. }
  328. /**
  329. * FEM 动画文件获取
  330. * @param proId
  331. * @param obj
  332. * @throws BusinessException
  333. */
  334. private void animationFemFile(String proId, JSONObject obj,ActionMsg msg ) throws BusinessException, JsonProcessingException {
  335. String jobPath = XIFileUtils.getRootPathStr()+ MFConstant.separator+ proId;
  336. String exePath = jobPath+ MFConstant.separator+"fem";
  337. String exeOutPath = exePath+ MFConstant.separator+"data_out";
  338. List<Integer> steps = FEMPath.femTeps(proId);
  339. List<AnimationFile> animationFiles =new ArrayList<>();
  340. for (Integer st:steps) {
  341. List<File> fileList = FEMPath.getStepFiles(proId,st.toString());
  342. String fileName="";
  343. for (int i = 0; i < fileList.size(); i++) {
  344. if(i==fileList.size()-1){
  345. fileName +=fileList.get(i).getName();
  346. }else {
  347. fileName +=fileList.get(i).getName()+",";
  348. }
  349. }
  350. AnimationFile animationFile =new AnimationFile();
  351. animationFile.setStep(st);
  352. animationFile.setFilename(fileName);
  353. animationFiles.add(animationFile);
  354. }
  355. obj.put("filePath", exeOutPath);
  356. obj.put("fileType", "ascii");
  357. obj.put("fileNames", XiJsonUtil.objectToJson(animationFiles));
  358. // msg.setFileNames(XiJsonUtil.objectToJson(animationFiles));
  359. }
  360. /**
  361. * 根据渲染类型 设置参数
  362. * @param scalarName
  363. * @param level
  364. * @param range0
  365. * @param range1
  366. * @param obj
  367. * @throws BusinessException
  368. */
  369. private void animationTypePara(String scalarName, String level, String range0, String range1, JSONObject obj) throws BusinessException {
  370. String animationType = getA_aft001().getAnimationType();
  371. if(StringUtil.isNullOrEmpty(animationType)){
  372. throw new BusinessException("EB4000018");
  373. }else if(animationType.equals("ContourDisplay")){
  374. obj.put("animationType","ContourDisplay");
  375. obj.put("level", level);
  376. obj.put("range", range0 +","+ range1);
  377. obj.put("scalarName", scalarName);
  378. }else if(animationType.equals("LineDisplay")){
  379. obj.put("animationType","LineDisplay");
  380. obj.put("level", level);
  381. obj.put("range", range0 +","+ range1);
  382. obj.put("scalarName", scalarName);
  383. }else if(animationType.equals("VectorDisplay")){
  384. if(this.getA_aft001().getScaleFactor()==null
  385. ||"".equals(this.getA_aft001().getScaleFactor())||
  386. this.getA_aft001().getDataU()==null
  387. ||"".equals(this.getA_aft001().getDataU())||
  388. this.getA_aft001().getDataV()==null
  389. ||"".equals(this.getA_aft001().getDataV())||
  390. this.getA_aft001().getDataW()==null
  391. ||"".equals(this.getA_aft001().getDataW())
  392. ){
  393. throw new BusinessException("EB4000013");
  394. }
  395. obj.put("animationType","VectorDisplay");
  396. obj.put("scaleFactor",this.getA_aft001().getScaleFactor());
  397. obj.put("dataU",this.getA_aft001().getDataU());
  398. obj.put("dataV",this.getA_aft001().getDataV());
  399. obj.put("dataW",this.getA_aft001().getDataW());
  400. }else if(animationType.equals("SolidSurfaceDisplay")){
  401. obj.put("animationType","SolidSurfaceDisplay");
  402. String r =this.getA_aft001().getR();
  403. String g =this.getA_aft001().getG();
  404. String b =this.getA_aft001().getB();
  405. String transparency=this.getA_aft001().getTransparency();
  406. String showHideState=this.getA_aft001().getShowHideState();
  407. if(r==null || "".equals(r)
  408. ||g==null || "".equals(g)
  409. ||b==null || "".equals(b)
  410. ||transparency==null || "".equals(transparency)
  411. ||showHideState==null || "".equals(showHideState)
  412. ){
  413. throw new BusinessException("EB4000013");
  414. }
  415. obj.put("r",r);
  416. obj.put("g",g);
  417. obj.put("b",b);
  418. obj.put("transparency",transparency);
  419. obj.put("showHideState","1".equals(showHideState)?true:false);
  420. }
  421. }
  422. /**
  423. * Hcfd 动画文件获取
  424. * @param proId
  425. * @param obj
  426. * @throws BusinessException
  427. */
  428. private void animationHcfdFile(String proId, JSONObject obj,ActionMsg msg ) throws BusinessException, JsonProcessingException {
  429. String jobPath = XIFileUtils.getRootPathStr()+ MFConstant.separator+ proId;
  430. String exePath = jobPath+ MFConstant.separator+"hcfd";
  431. String testPath = exePath+ MFConstant.separator+"test";
  432. String exeOutPath = testPath+ MFConstant.separator+"data_out";
  433. // JSONArray jsonArray = new JSONArray();
  434. List<AnimationFile> animationFiles =new ArrayList<>();
  435. List<Integer> steps =HcfdPath.hcfdTeps(proId);
  436. for (Integer st:steps) {
  437. List<File> fileList = HcfdPath.getStepFiles(proId, getA_aft001().getIsVolume(), st.toString());
  438. String fileName="";
  439. for (int i = 0; i < fileList.size(); i++) {
  440. if(i==fileList.size()-1){
  441. fileName +=fileList.get(i).getName();
  442. }else {
  443. fileName +=fileList.get(i).getName()+",";
  444. }
  445. }
  446. AnimationFile animationFile =new AnimationFile();
  447. animationFile.setStep(st);
  448. animationFile.setFilename(fileName);
  449. animationFiles.add(animationFile);
  450. }
  451. obj.put("filePath", exeOutPath);
  452. obj.put("fileType", "ascii");
  453. obj.put("fileNames", XiJsonUtil.objectToJson(animationFiles));
  454. // msg.setFileNames(XiJsonUtil.objectToJson(animationFiles));
  455. }
  456. /**
  457. * 基础系统,“后处理消息发送”业务前处理
  458. */
  459. public void preTransFlow() throws Exception {
  460. this.validater();
  461. }
  462. /**
  463. * 基础系统,“后处理消息发送”业务后处理
  464. */
  465. public void afterTransFlow() throws Exception {
  466. }
  467. /**
  468. * 基础系统,“后处理消息发送”逻辑入口处理方法
  469. */
  470. @SuppressWarnings("rawtypes")
  471. @Override
  472. public Map execute(Map vars) throws Exception {
  473. this.setTransMap(vars);
  474. preTransFlow();// 执行业务开始的规则检查和校验
  475. transExecute();// 执行核心业务段
  476. afterTransFlow();// 执行核心逻辑完成后的收尾逻辑
  477. return this.getTransMap();
  478. }
  479. }