AFT001Service.java 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  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. String jobPath = XIFileUtils.getRootPathStr()+ MFConstant.separator+solver.getPid();
  147. String exePath = jobPath+ MFConstant.separator+"fem";
  148. String exeOutPath = exePath+ MFConstant.separator+"data_out";
  149. File file = new File(exeOutPath+MFConstant.separator+"dynamicResponse-transient"+step+".vtk");
  150. if(!file.exists()){
  151. throw new BusinessException("EB4000017");
  152. }
  153. JSONObject obj = new JSONObject();
  154. obj.put("filePath", exeOutPath);
  155. obj.put("fileType", "ascii");
  156. obj.put("fileName", "dynamicResponse-transient"+step+".vtk");
  157. msg.setParamJson(obj.toString());
  158. }
  159. }else if(action.equals("ContourDisplay")){
  160. JSONObject obj = new JSONObject();
  161. obj.put("level",level);
  162. obj.put("range",range0+","+range1);
  163. obj.put("scalarName",scalarName);
  164. msg.setParamJson(obj.toString());
  165. }else if(action.equals("LineDisplay")){
  166. JSONObject obj = new JSONObject();
  167. obj.put("level",level);
  168. obj.put("range",range0+","+range1);
  169. obj.put("scalarName",scalarName);
  170. msg.setParamJson(obj.toString());
  171. }else if(action.equals("VectorDisplay")){
  172. if(this.getA_aft001().getScaleFactor()==null
  173. ||"".equals(this.getA_aft001().getScaleFactor())||
  174. this.getA_aft001().getDataU()==null
  175. ||"".equals(this.getA_aft001().getDataU())||
  176. this.getA_aft001().getDataV()==null
  177. ||"".equals(this.getA_aft001().getDataV())||
  178. this.getA_aft001().getDataW()==null
  179. ||"".equals(this.getA_aft001().getDataW())
  180. ){
  181. throw new BusinessException("EB4000013");
  182. }
  183. JSONObject obj = new JSONObject();
  184. obj.put("scaleFactor",this.getA_aft001().getScaleFactor());
  185. obj.put("dataU",this.getA_aft001().getDataU());
  186. obj.put("dataV",this.getA_aft001().getDataV());
  187. obj.put("dataW",this.getA_aft001().getDataW());
  188. msg.setParamJson(obj.toString());
  189. }else if(action.equals("SolidSurfaceDisplay")){
  190. String r =this.getA_aft001().getR();
  191. String g =this.getA_aft001().getG();
  192. String b =this.getA_aft001().getB();
  193. String transparency=this.getA_aft001().getTransparency();
  194. String showHideState=this.getA_aft001().getShowHideState();
  195. if(r==null || "".equals(r)
  196. ||g==null || "".equals(g)
  197. ||b==null || "".equals(b)
  198. ||transparency==null || "".equals(transparency)
  199. ||showHideState==null || "".equals(showHideState)
  200. ){
  201. throw new BusinessException("EB4000013");
  202. }
  203. JSONObject obj = new JSONObject();
  204. obj.put("r",r);
  205. obj.put("g",g);
  206. obj.put("b",b);
  207. obj.put("transparency",transparency);
  208. obj.put("showHideState","1".equals(showHideState)?true:false);
  209. msg.setParamJson(obj.toString());
  210. }else if(action.equals("SliceDisplayAdd")){
  211. String index = this.getA_aft001().getIndex();
  212. JSONObject obj = new JSONObject();
  213. obj.put("index",index);
  214. msg.setParamJson(obj.toString());
  215. }else if(action.equals("SliceDisplayUpdate")){
  216. }else if(action.equals("SliceDisplayDel")){
  217. String index = this.getA_aft001().getIndex();
  218. JSONObject obj = new JSONObject();
  219. obj.put("index",index);
  220. msg.setParamJson(obj.toString());
  221. }else if(action.equals("SliceDisplayApply")){
  222. try {
  223. List<SliceMsg> list = XiJsonUtil.jsonToList(paramJson,SliceMsg.class);
  224. msg.setParamJson(paramJson);
  225. }catch (Exception e){
  226. throw new BusinessException("EB4000014");
  227. }
  228. }else if(action.equals("StreamDisplayCreate")){
  229. try {
  230. String x = this.getA_aft001().getX();
  231. String y = this.getA_aft001().getY();
  232. String z = this.getA_aft001().getZ();
  233. String u=this.getA_aft001().getDataU();
  234. String v=this.getA_aft001().getDataV();
  235. String w=this.getA_aft001().getDataW();
  236. if(
  237. // StringUtil.isNullOrEmpty(x)
  238. // ||StringUtil.isNullOrEmpty(y)
  239. // ||StringUtil.isNullOrEmpty(z)
  240. // ||
  241. StringUtil.isNullOrEmpty(w)
  242. ||StringUtil.isNullOrEmpty(u)
  243. ||StringUtil.isNullOrEmpty(v)
  244. ){
  245. throw new BusinessException("EB4000016");
  246. }
  247. JSONObject obj = new JSONObject();
  248. // obj.put("x",x);
  249. // obj.put("y",y);
  250. // obj.put("z",z);
  251. obj.put("u",u);
  252. obj.put("v",v);
  253. obj.put("w",w);
  254. msg.setParamJson(obj.toString());
  255. }catch (Exception e){
  256. throw new BusinessException("EB4000016");
  257. }
  258. }else if(action.equals("StreamDisplayDeleteAll")){
  259. }else if(action.equals("StreamDisplayApply")){
  260. try{
  261. StreamMsg streamMsg= XiJsonUtil.jsonToPojo(paramJson, StreamMsg.class);
  262. if(StringUtil.isNullOrEmpty(streamMsg.getDirection())){
  263. throw new BusinessException("EB4000014");
  264. }
  265. //Both,Forward,Backward
  266. if(!"Both".equals(streamMsg.getDirection())
  267. &&!"Forward".equals(streamMsg.getDirection())
  268. &&!"Backward".equals(streamMsg.getDirection())){
  269. throw new BusinessException("EB4000014");
  270. }
  271. if(StringUtil.isNullOrEmpty(streamMsg.getStreamstyle())){
  272. throw new BusinessException("EB4000014");
  273. }
  274. //(Line,Ribbon,Tube)
  275. if(!"Line".equals(streamMsg.getStreamstyle())
  276. &&!"Ribbon".equals(streamMsg.getStreamstyle())
  277. &&!"Tube".equals(streamMsg.getStreamstyle())){
  278. throw new BusinessException("EB4000014");
  279. }
  280. msg.setParamJson(paramJson);
  281. }catch (Exception e){
  282. throw new BusinessException("EB4000014");
  283. }
  284. }else if(action.equals("animation")){
  285. delOldImg(solverConfigId, proId, action);
  286. JSONObject obj = new JSONObject();
  287. String hideZones =this.getA_aft001().getHideZones();
  288. obj.put("hideZones",hideZones);
  289. animationTypePara(scalarName, level, range0, range1, obj);
  290. if(solver.getSolverModel().equals("HCFDLab")) {
  291. animationHcfdFile(proId, obj,msg);
  292. }else if(solver.getSolverModel().equals("FEMLab(结构力学)")){
  293. animationFemFile(proId, obj,msg);
  294. }
  295. msg.setParamJson(obj.toString());
  296. }
  297. MFMqUtils.get(CaeMQ.class).sendCaein(XiJsonUtil.objectToJson(msg));
  298. }
  299. private void delOldImg(String solverConfigId, String proId, String action) {
  300. AdiSolverConfigImgMapper configImgMapper= UtilTools.getBean(AdiSolverConfigImgMapper.class);
  301. AdiSolverConfigImg img = new AdiSolverConfigImg();
  302. img.setAnimationtype(getA_aft001().getAnimationType());
  303. img.setAction(action);
  304. img.setPid(proId);
  305. img.setSolverConfigId(solverConfigId);
  306. configImgMapper.delete(img);
  307. }
  308. /**
  309. * FEM 动画文件获取
  310. * @param proId
  311. * @param obj
  312. * @throws BusinessException
  313. */
  314. private void animationFemFile(String proId, JSONObject obj,ActionMsg msg ) throws BusinessException, JsonProcessingException {
  315. String jobPath = XIFileUtils.getRootPathStr()+ MFConstant.separator+ proId;
  316. String exePath = jobPath+ MFConstant.separator+"fem";
  317. String exeOutPath = exePath+ MFConstant.separator+"data_out";
  318. List<Integer> steps = FEMPath.femTeps(proId);
  319. List<AnimationFile> animationFiles =new ArrayList<>();
  320. for (Integer st:steps) {
  321. List<File> fileList = FEMPath.getStepFiles(proId,st.toString());
  322. String fileName="";
  323. for (int i = 0; i < fileList.size(); i++) {
  324. if(i==fileList.size()-1){
  325. fileName +=fileList.get(i).getName();
  326. }else {
  327. fileName +=fileList.get(i).getName()+",";
  328. }
  329. }
  330. AnimationFile animationFile =new AnimationFile();
  331. animationFile.setStep(st);
  332. animationFile.setFilename(fileName);
  333. animationFiles.add(animationFile);
  334. }
  335. obj.put("filePath", exeOutPath);
  336. obj.put("fileType", "ascii");
  337. obj.put("fileNames", XiJsonUtil.objectToJson(animationFiles));
  338. // msg.setFileNames(XiJsonUtil.objectToJson(animationFiles));
  339. }
  340. /**
  341. * 根据渲染类型 设置参数
  342. * @param scalarName
  343. * @param level
  344. * @param range0
  345. * @param range1
  346. * @param obj
  347. * @throws BusinessException
  348. */
  349. private void animationTypePara(String scalarName, String level, String range0, String range1, JSONObject obj) throws BusinessException {
  350. String animationType = getA_aft001().getAnimationType();
  351. if(StringUtil.isNullOrEmpty(animationType)){
  352. throw new BusinessException("4000018");
  353. }else if(animationType.equals("ContourDisplay")){
  354. obj.put("animationType","ContourDisplay");
  355. obj.put("level", level);
  356. obj.put("range", range0 +","+ range1);
  357. obj.put("scalarName", scalarName);
  358. }else if(animationType.equals("LineDisplay")){
  359. obj.put("animationType","LineDisplay");
  360. obj.put("level", level);
  361. obj.put("range", range0 +","+ range1);
  362. obj.put("scalarName", scalarName);
  363. }else if(animationType.equals("VectorDisplay")){
  364. if(this.getA_aft001().getScaleFactor()==null
  365. ||"".equals(this.getA_aft001().getScaleFactor())||
  366. this.getA_aft001().getDataU()==null
  367. ||"".equals(this.getA_aft001().getDataU())||
  368. this.getA_aft001().getDataV()==null
  369. ||"".equals(this.getA_aft001().getDataV())||
  370. this.getA_aft001().getDataW()==null
  371. ||"".equals(this.getA_aft001().getDataW())
  372. ){
  373. throw new BusinessException("EB4000013");
  374. }
  375. obj.put("animationType","VectorDisplay");
  376. obj.put("scaleFactor",this.getA_aft001().getScaleFactor());
  377. obj.put("dataU",this.getA_aft001().getDataU());
  378. obj.put("dataV",this.getA_aft001().getDataV());
  379. obj.put("dataW",this.getA_aft001().getDataW());
  380. }else if(animationType.equals("SolidSurfaceDisplay")){
  381. obj.put("animationType","SolidSurfaceDisplay");
  382. String r =this.getA_aft001().getR();
  383. String g =this.getA_aft001().getG();
  384. String b =this.getA_aft001().getB();
  385. String transparency=this.getA_aft001().getTransparency();
  386. String showHideState=this.getA_aft001().getShowHideState();
  387. if(r==null || "".equals(r)
  388. ||g==null || "".equals(g)
  389. ||b==null || "".equals(b)
  390. ||transparency==null || "".equals(transparency)
  391. ||showHideState==null || "".equals(showHideState)
  392. ){
  393. throw new BusinessException("EB4000013");
  394. }
  395. obj.put("r",r);
  396. obj.put("g",g);
  397. obj.put("b",b);
  398. obj.put("transparency",transparency);
  399. obj.put("showHideState","1".equals(showHideState)?true:false);
  400. }
  401. }
  402. /**
  403. * Hcfd 动画文件获取
  404. * @param proId
  405. * @param obj
  406. * @throws BusinessException
  407. */
  408. private void animationHcfdFile(String proId, JSONObject obj,ActionMsg msg ) throws BusinessException, JsonProcessingException {
  409. String jobPath = XIFileUtils.getRootPathStr()+ MFConstant.separator+ proId;
  410. String exePath = jobPath+ MFConstant.separator+"hcfd";
  411. String testPath = exePath+ MFConstant.separator+"test";
  412. String exeOutPath = testPath+ MFConstant.separator+"data_out";
  413. // JSONArray jsonArray = new JSONArray();
  414. List<AnimationFile> animationFiles =new ArrayList<>();
  415. List<Integer> steps =HcfdPath.hcfdTeps(proId);
  416. for (Integer st:steps) {
  417. List<File> fileList = HcfdPath.getStepFiles(proId, getA_aft001().getIsVolume(), st.toString());
  418. String fileName="";
  419. for (int i = 0; i < fileList.size(); i++) {
  420. if(i==fileList.size()-1){
  421. fileName +=fileList.get(i).getName();
  422. }else {
  423. fileName +=fileList.get(i).getName()+",";
  424. }
  425. }
  426. AnimationFile animationFile =new AnimationFile();
  427. animationFile.setStep(st);
  428. animationFile.setFilename(fileName);
  429. animationFiles.add(animationFile);
  430. }
  431. obj.put("filePath", exeOutPath);
  432. obj.put("fileType", "ascii");
  433. obj.put("fileNames", XiJsonUtil.objectToJson(animationFiles));
  434. // msg.setFileNames(XiJsonUtil.objectToJson(animationFiles));
  435. }
  436. /**
  437. * 基础系统,“后处理消息发送”业务前处理
  438. */
  439. public void preTransFlow() throws Exception {
  440. this.validater();
  441. }
  442. /**
  443. * 基础系统,“后处理消息发送”业务后处理
  444. */
  445. public void afterTransFlow() throws Exception {
  446. }
  447. /**
  448. * 基础系统,“后处理消息发送”逻辑入口处理方法
  449. */
  450. @SuppressWarnings("rawtypes")
  451. @Override
  452. public Map execute(Map vars) throws Exception {
  453. this.setTransMap(vars);
  454. preTransFlow();// 执行业务开始的规则检查和校验
  455. transExecute();// 执行核心业务段
  456. afterTransFlow();// 执行核心逻辑完成后的收尾逻辑
  457. return this.getTransMap();
  458. }
  459. }