package com.miniframe.bisiness.system; import java.io.File; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.stream.Stream; import com.alibaba.nacos.shaded.com.google.gson.JsonArray; import com.alibaba.nacos.shaded.com.google.gson.JsonObject; import com.alibaba.nacos.shaded.io.grpc.netty.shaded.io.netty.util.internal.StringUtil; import com.fasterxml.jackson.core.JsonProcessingException; import com.miniframe.aftercure.ActionMsg; import com.miniframe.aftercure.AnimationFile; import com.miniframe.aftercure.SliceMsg; import com.miniframe.aftercure.StreamMsg; import com.miniframe.constant.MFConstant; import com.miniframe.core.ExecProcessFlow; import com.miniframe.core.exception.BusinessException; import com.miniframe.core.ext.UtilTools; import com.miniframe.generate.business.system.model.AFT001BaseModel; import com.miniframe.model.system.*; import com.miniframe.model.system.dao.*; import com.miniframe.service.mq.CaeMQ; import com.miniframe.solverconfig.fem.FEMPath; import com.miniframe.solverconfig.hcfd.HcfdPath; import com.miniframe.spring.mq.MFMqUtils; import com.miniframe.tools.XIFileUtils; import com.miniframe.tools.XiJsonUtil; import org.json.JSONArray; import org.json.JSONObject; /** * 基础系统,“后处理消息发送”逻辑处理(重新生成不覆盖)。 */ public class AFT001Service extends AFT001BaseModel implements ExecProcessFlow { private static final long serialVersionUID = -7051358269847459502L; /** * 基础系统,“后处理消息发送”业务核心处理 */ public void transExecute() throws Exception { String usrId =this.getA_systemhead().getUserId(); String solverConfigId =getA_aft001().getSolverConfigId(); String proId =getA_aft001().getPid(); String paramJson =getA_aft001().getParamJson(); String action =getA_aft001().getAction(); String step=getA_aft001().getStep(); String scalarName =getA_aft001().getScalarName(); String level =getA_aft001().getLevel(); String range0 =getA_aft001().getRange0(); String range1 =getA_aft001().getRange1(); AdiSolverConfigMapper configMapper = UtilTools.getBean(AdiSolverConfigMapper.class); AdiSolverConfig config= configMapper.selectByPrimaryKey(solverConfigId); if(config==null){ throw new BusinessException("EB4000011"); } AdiSolverMapper solverMapper = UtilTools.getBean(AdiSolverMapper.class); AdiSolver solver = solverMapper.selectByPrimaryKey(config.getSolverid()); if(solver==null){ throw new BusinessException("EB4000011"); } ActionMsg msg =new ActionMsg(); msg.setUsrId(usrId); msg.setSolverConfigid(solverConfigId); msg.setProId(proId); msg.setAction(action); if(action.equals("init")){ msg.setParamJson(paramJson); }else if(action.equals("loaddata")){ if(solver.getSolverModel().equals("HCFDLab")){ AdiModelingMapper modelingMapper = UtilTools.getBean(AdiModelingMapper.class); AdiModelingSQLBuilder sb = new AdiModelingSQLBuilder(); AdiModelingSQLBuilder.Criteria sc =sb.createCriteria(); sc.andPidEqualTo(proId); List modelings =modelingMapper.selectByExample(sb); if(modelings.isEmpty()){ throw new BusinessException("EB4000015"); }else{ AdiModeling modeling = modelings.get(0); SysFileMapper fileMapper = UtilTools.getBean(SysFileMapper.class); SysFile file =fileMapper.selectByPrimaryKey(modeling.getGridFile()); if(file==null){ throw new BusinessException("EB4000015"); } JSONObject obj = new JSONObject(); obj.put("filePath",XIFileUtils.getRootPathStr()+ MFConstant.separator+file.getFilepath()); // obj.put("filePath","F:\\czm\\vtkfile\\tf.ugrid"); obj.put("fileType",modeling.getGridFileType().toLowerCase()); msg.setParamJson(obj.toString()); } }else if(solver.getSolverModel().equals("FEMLab(结构力学)")){ AdiModelingMapper modelingMapper = UtilTools.getBean(AdiModelingMapper.class); AdiModelingSQLBuilder sb = new AdiModelingSQLBuilder(); AdiModelingSQLBuilder.Criteria sc =sb.createCriteria(); sc.andPidEqualTo(proId); List modelings =modelingMapper.selectByExample(sb); if(modelings.isEmpty()){ throw new BusinessException("EB4000015"); }else{ AdiModeling modeling = modelings.get(0); SysFileMapper fileMapper = UtilTools.getBean(SysFileMapper.class); SysFile file =fileMapper.selectByPrimaryKey(modeling.getVtkFile()); if(file==null){ throw new BusinessException("EB4000015"); } JSONObject obj = new JSONObject(); obj.put("filePath",XIFileUtils.getRootPathStr()+ MFConstant.separator+file.getFilepath()); // obj.put("filePath","F:\\czm\\vtkfile\\f.vtk"); obj.put("fileType",modeling.getGridFileType().toLowerCase()); msg.setParamJson(obj.toString()); } } }else if(action.equals("zoomout")){//缩小 }else if(action.equals("zoomin")){//放大 }else if(action.equals("AlignToPlusAxisX")){//正x轴对齐 }else if(action.equals("AlignToPlusAxisY")){//正y轴对齐 }else if(action.equals("AlignToPlusAxisZ")){//正z轴对齐 }else if(action.equals("AlignToMinusAxisX")){//负x轴对齐 }else if(action.equals("AlignToMinusAxisY")){//负y轴对齐 }else if(action.equals("AlignToMinusAxisZ")){//负z轴对齐 }else if(action.equals("TransformToIsometric")){//等距视图显示 }else if(action.equals("ResultImport")){ if(solver.getSolverModel().equals("HCFDLab")) { String jobPath = XIFileUtils.getRootPathStr()+ MFConstant.separator+proId; String exePath = jobPath+ MFConstant.separator+"hcfd"; String testPath = exePath+ MFConstant.separator+"test"; String exeOutPath = testPath+ MFConstant.separator+"data_out"; List fileList = HcfdPath.getStepFiles(proId, getA_aft001().getIsVolume(), step); if(fileList.isEmpty()){ throw new BusinessException("EB4000017"); } String fileName=""; for (int i = 0; i < fileList.size(); i++) { if(i==fileList.size()-1){ fileName +=fileList.get(i).getName(); }else { fileName +=fileList.get(i).getName()+","; } } JSONObject obj = new JSONObject(); // obj.put("filePath", "C:\\Users\\Administrator\\Documents\\WeChat Files\\wxid_18qjhi0tq90d22\\FileStorage\\File\\2023-06"); // obj.put("fileType", "ascii"); // obj.put("fileName", "tfg_part1_tec_volume_timestep100.dat"); obj.put("filePath", exeOutPath); obj.put("fileType", "ascii"); obj.put("fileName", fileName); msg.setParamJson(obj.toString()); }else if(solver.getSolverModel().equals("FEMLab(结构力学)")){ if(StringUtil.isNullOrEmpty(step)){ step ="1"; } String jobPath = XIFileUtils.getRootPathStr()+ MFConstant.separator+solver.getPid(); String exePath = jobPath+ MFConstant.separator+"fem"; String exeOutPath = exePath+ MFConstant.separator+"data_out"; File file; if(!step.equals("0")) { file = new File(exeOutPath + MFConstant.separator + "dynamicResponse-transient" + step + ".vtk"); }else { file = new File(exeOutPath+MFConstant.separator+"dynamicResponse-transient.vtk"); } if(!file.exists()){ throw new BusinessException("EB4000017"); } JSONObject obj = new JSONObject(); obj.put("filePath", exeOutPath); obj.put("fileType", "ascii"); if(!step.equals("0")){ obj.put("fileName", "dynamicResponse-transient"+step+".vtk"); }else { obj.put("fileName", "dynamicResponse-transient.vtk");//静态 模态 } msg.setParamJson(obj.toString()); } }else if(action.equals("ContourDisplay")){ JSONObject obj = new JSONObject(); obj.put("level",level); obj.put("range",range0+","+range1); obj.put("scalarName",scalarName); msg.setParamJson(obj.toString()); }else if(action.equals("LineDisplay")){ JSONObject obj = new JSONObject(); obj.put("level",level); obj.put("range",range0+","+range1); obj.put("scalarName",scalarName); msg.setParamJson(obj.toString()); }else if(action.equals("VectorDisplay")){ if(this.getA_aft001().getScaleFactor()==null ||"".equals(this.getA_aft001().getScaleFactor())|| this.getA_aft001().getDataU()==null ||"".equals(this.getA_aft001().getDataU())|| this.getA_aft001().getDataV()==null ||"".equals(this.getA_aft001().getDataV())|| this.getA_aft001().getDataW()==null ||"".equals(this.getA_aft001().getDataW()) ){ throw new BusinessException("EB4000013"); } JSONObject obj = new JSONObject(); obj.put("scaleFactor",this.getA_aft001().getScaleFactor()); obj.put("dataU",this.getA_aft001().getDataU()); obj.put("dataV",this.getA_aft001().getDataV()); obj.put("dataW",this.getA_aft001().getDataW()); msg.setParamJson(obj.toString()); }else if(action.equals("SolidSurfaceDisplay")){ String r =this.getA_aft001().getR(); String g =this.getA_aft001().getG(); String b =this.getA_aft001().getB(); String transparency=this.getA_aft001().getTransparency(); String showHideState=this.getA_aft001().getShowHideState(); if(r==null || "".equals(r) ||g==null || "".equals(g) ||b==null || "".equals(b) ||transparency==null || "".equals(transparency) ||showHideState==null || "".equals(showHideState) ){ throw new BusinessException("EB4000013"); } JSONObject obj = new JSONObject(); obj.put("r",r); obj.put("g",g); obj.put("b",b); obj.put("transparency",transparency); obj.put("showHideState","1".equals(showHideState)?true:false); msg.setParamJson(obj.toString()); }else if(action.equals("SliceDisplayAdd")){ String index = this.getA_aft001().getIndex(); JSONObject obj = new JSONObject(); obj.put("index",index); msg.setParamJson(obj.toString()); }else if(action.equals("SliceDisplayUpdate")){ }else if(action.equals("SliceDisplayDel")){ String index = this.getA_aft001().getIndex(); JSONObject obj = new JSONObject(); obj.put("index",index); msg.setParamJson(obj.toString()); }else if(action.equals("SliceDisplayApply")){ try { List list = XiJsonUtil.jsonToList(paramJson,SliceMsg.class); msg.setParamJson(paramJson); }catch (Exception e){ throw new BusinessException("EB4000014"); } }else if(action.equals("StreamDisplayCreate")){ try { String x = this.getA_aft001().getX(); String y = this.getA_aft001().getY(); String z = this.getA_aft001().getZ(); String u=this.getA_aft001().getDataU(); String v=this.getA_aft001().getDataV(); String w=this.getA_aft001().getDataW(); if( // StringUtil.isNullOrEmpty(x) // ||StringUtil.isNullOrEmpty(y) // ||StringUtil.isNullOrEmpty(z) // || StringUtil.isNullOrEmpty(w) ||StringUtil.isNullOrEmpty(u) ||StringUtil.isNullOrEmpty(v) ){ throw new BusinessException("EB4000016"); } JSONObject obj = new JSONObject(); // obj.put("x",x); // obj.put("y",y); // obj.put("z",z); obj.put("u",u); obj.put("v",v); obj.put("w",w); msg.setParamJson(obj.toString()); }catch (Exception e){ throw new BusinessException("EB4000016"); } }else if(action.equals("StreamDisplayDeleteAll")){ }else if(action.equals("StreamDisplayApply")){ try{ StreamMsg streamMsg= XiJsonUtil.jsonToPojo(paramJson, StreamMsg.class); if(StringUtil.isNullOrEmpty(streamMsg.getDirection())){ throw new BusinessException("EB4000014"); } //Both,Forward,Backward if(!"Both".equals(streamMsg.getDirection()) &&!"Forward".equals(streamMsg.getDirection()) &&!"Backward".equals(streamMsg.getDirection())){ throw new BusinessException("EB4000014"); } if(StringUtil.isNullOrEmpty(streamMsg.getStreamstyle())){ throw new BusinessException("EB4000014"); } //(Line,Ribbon,Tube) if(!"Line".equals(streamMsg.getStreamstyle()) &&!"Ribbon".equals(streamMsg.getStreamstyle()) &&!"Tube".equals(streamMsg.getStreamstyle())){ throw new BusinessException("EB4000014"); } msg.setParamJson(paramJson); }catch (Exception e){ throw new BusinessException("EB4000014"); } }else if(action.equals("animation")){ delOldImg(solverConfigId, proId, action); JSONObject obj = new JSONObject(); String hideZones =this.getA_aft001().getHideZones(); obj.put("hideZones",hideZones); if(StringUtil.isNullOrEmpty(this.getA_aft001().getIsVolume())){ obj.put("isVolume",""); }else{ obj.put("isVolume",this.getA_aft001().getIsVolume()); } animationTypePara(scalarName, level, range0, range1, obj); if(solver.getSolverModel().equals("HCFDLab")) { animationHcfdFile(proId, obj,msg); }else if(solver.getSolverModel().equals("FEMLab(结构力学)")){ animationFemFile(proId, obj,msg); } msg.setParamJson(obj.toString()); } MFMqUtils.get(CaeMQ.class).sendCaein(XiJsonUtil.objectToJson(msg)); } private void delOldImg(String solverConfigId, String proId, String action) { AdiSolverConfigImgMapper configImgMapper= UtilTools.getBean(AdiSolverConfigImgMapper.class); AdiSolverConfigImg img = new AdiSolverConfigImg(); img.setAnimationtype(getA_aft001().getAnimationType()); img.setAction(action); img.setPid(proId); if(!StringUtil.isNullOrEmpty(this.getA_aft001().getIsVolume())){ img.setIsvolume(this.getA_aft001().getIsVolume()); } img.setSolverConfigId(solverConfigId); configImgMapper.delete(img); } /** * FEM 动画文件获取 * @param proId * @param obj * @throws BusinessException */ private void animationFemFile(String proId, JSONObject obj,ActionMsg msg ) throws BusinessException, JsonProcessingException { String jobPath = XIFileUtils.getRootPathStr()+ MFConstant.separator+ proId; String exePath = jobPath+ MFConstant.separator+"fem"; String exeOutPath = exePath+ MFConstant.separator+"data_out"; List steps = FEMPath.femTeps(proId); List animationFiles =new ArrayList<>(); for (Integer st:steps) { List fileList = FEMPath.getStepFiles(proId,st.toString()); String fileName=""; for (int i = 0; i < fileList.size(); i++) { if(i==fileList.size()-1){ fileName +=fileList.get(i).getName(); }else { fileName +=fileList.get(i).getName()+","; } } AnimationFile animationFile =new AnimationFile(); animationFile.setStep(st); animationFile.setFilename(fileName); animationFiles.add(animationFile); } obj.put("filePath", exeOutPath); obj.put("fileType", "ascii"); obj.put("fileNames", XiJsonUtil.objectToJson(animationFiles)); // msg.setFileNames(XiJsonUtil.objectToJson(animationFiles)); } /** * 根据渲染类型 设置参数 * @param scalarName * @param level * @param range0 * @param range1 * @param obj * @throws BusinessException */ private void animationTypePara(String scalarName, String level, String range0, String range1, JSONObject obj) throws BusinessException { String animationType = getA_aft001().getAnimationType(); if(StringUtil.isNullOrEmpty(animationType)){ throw new BusinessException("EB4000018"); }else if(animationType.equals("ContourDisplay")){ obj.put("animationType","ContourDisplay"); obj.put("level", level); obj.put("range", range0 +","+ range1); obj.put("scalarName", scalarName); }else if(animationType.equals("LineDisplay")){ obj.put("animationType","LineDisplay"); obj.put("level", level); obj.put("range", range0 +","+ range1); obj.put("scalarName", scalarName); }else if(animationType.equals("VectorDisplay")){ if(this.getA_aft001().getScaleFactor()==null ||"".equals(this.getA_aft001().getScaleFactor())|| this.getA_aft001().getDataU()==null ||"".equals(this.getA_aft001().getDataU())|| this.getA_aft001().getDataV()==null ||"".equals(this.getA_aft001().getDataV())|| this.getA_aft001().getDataW()==null ||"".equals(this.getA_aft001().getDataW()) ){ throw new BusinessException("EB4000013"); } obj.put("animationType","VectorDisplay"); obj.put("scaleFactor",this.getA_aft001().getScaleFactor()); obj.put("dataU",this.getA_aft001().getDataU()); obj.put("dataV",this.getA_aft001().getDataV()); obj.put("dataW",this.getA_aft001().getDataW()); }else if(animationType.equals("SolidSurfaceDisplay")){ obj.put("animationType","SolidSurfaceDisplay"); String r =this.getA_aft001().getR(); String g =this.getA_aft001().getG(); String b =this.getA_aft001().getB(); String transparency=this.getA_aft001().getTransparency(); String showHideState=this.getA_aft001().getShowHideState(); if(r==null || "".equals(r) ||g==null || "".equals(g) ||b==null || "".equals(b) ||transparency==null || "".equals(transparency) ||showHideState==null || "".equals(showHideState) ){ throw new BusinessException("EB4000013"); } obj.put("r",r); obj.put("g",g); obj.put("b",b); obj.put("transparency",transparency); obj.put("showHideState","1".equals(showHideState)?true:false); } } /** * Hcfd 动画文件获取 * @param proId * @param obj * @throws BusinessException */ private void animationHcfdFile(String proId, JSONObject obj,ActionMsg msg ) throws BusinessException, JsonProcessingException { String jobPath = XIFileUtils.getRootPathStr()+ MFConstant.separator+ proId; String exePath = jobPath+ MFConstant.separator+"hcfd"; String testPath = exePath+ MFConstant.separator+"test"; String exeOutPath = testPath+ MFConstant.separator+"data_out"; // JSONArray jsonArray = new JSONArray(); List animationFiles =new ArrayList<>(); List steps =HcfdPath.hcfdTeps(proId); for (Integer st:steps) { List fileList = HcfdPath.getStepFiles(proId, getA_aft001().getIsVolume(), st.toString()); String fileName=""; for (int i = 0; i < fileList.size(); i++) { if(i==fileList.size()-1){ fileName +=fileList.get(i).getName(); }else { fileName +=fileList.get(i).getName()+","; } } AnimationFile animationFile =new AnimationFile(); animationFile.setStep(st); animationFile.setFilename(fileName); animationFiles.add(animationFile); } obj.put("filePath", exeOutPath); obj.put("fileType", "ascii"); obj.put("fileNames", XiJsonUtil.objectToJson(animationFiles)); // msg.setFileNames(XiJsonUtil.objectToJson(animationFiles)); } /** * 基础系统,“后处理消息发送”业务前处理 */ public void preTransFlow() throws Exception { this.validater(); } /** * 基础系统,“后处理消息发送”业务后处理 */ public void afterTransFlow() throws Exception { } /** * 基础系统,“后处理消息发送”逻辑入口处理方法 */ @SuppressWarnings("rawtypes") @Override public Map execute(Map vars) throws Exception { this.setTransMap(vars); preTransFlow();// 执行业务开始的规则检查和校验 transExecute();// 执行核心业务段 afterTransFlow();// 执行核心逻辑完成后的收尾逻辑 return this.getTransMap(); } }