Pārlūkot izejas kodu

人员位置数据

huangxingxing 7 mēneši atpakaļ
vecāks
revīzija
bb015bb33e

+ 166 - 102
src/main/java/com/miniframe/bisiness/system/M00004Service.java

@@ -1,20 +1,25 @@
 package com.miniframe.bisiness.system;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.*;
+
 import com.miniframe.core.ExecProcessFlow;
 import com.miniframe.core.exception.BusinessException;
 import com.miniframe.core.ext.UtilTools;
 import com.miniframe.generate.business.system.model.M00004BaseModel;
 import com.miniframe.generate.comm.system.*;
-import com.miniframe.model.system.DAccident;
-import com.miniframe.model.system.DJob;
-import com.miniframe.model.system.DMway;
-import com.miniframe.model.system.DMwaySQLBuilder;
+import com.miniframe.model.system.*;
 import com.miniframe.model.system.dao.DAccidentMapper;
 import com.miniframe.model.system.dao.DJobMapper;
 import com.miniframe.model.system.dao.DMwayMapper;
+import com.miniframe.model.system.dao.DPtpipeassMapper;
+import com.miniframe.template.TemplateGenerator;
+import com.miniframe.template.TemplateGenerator2;
+import com.miniframe.tools.XIDateTimeUtils;
+import com.miniframe.tools.XIFileUtils;
 
 /**
  * 基础系统,“平台对接求解结果”逻辑处理(重新生成不覆盖)。
@@ -45,101 +50,45 @@ public class M00004Service extends M00004BaseModel implements ExecProcessFlow {
 		if("2".equals(job.getState())){
 			throw new BusinessException("EMB00002");
 		}
-
 		List <D_M00004_PTS_RECODE> pts =new ArrayList<>();//管道时间数据
-
-		//----------------------
-		D_M00004_PTS_RECODE pt1=new D_M00004_PTS_RECODE();
-		pt1.setTime("2024-12-06 10:26:37 +0800");
-		List<D_M00004_PTS_PIPES_RECODE> pips1 =new ArrayList<>();
-		pt1.setPipes(pips1);
-
-		D_M00004_PTS_PIPES_RECODE pip1 =new D_M00004_PTS_PIPES_RECODE();
-		pip1.setGrade("0");
-		pip1.setPname("巷道1");
-		pip1.setPcode("pipes1");
-		pips1.add(pip1);
-
-		D_M00004_PTS_PIPES_RECODE pip2 =new D_M00004_PTS_PIPES_RECODE();
-		pip2.setGrade("0");
-		pip2.setPname("巷道2");
-		pip2.setPcode("pipes2");
-		pips1.add(pip2);
-
-		D_M00004_PTS_PIPES_RECODE pip3 =new D_M00004_PTS_PIPES_RECODE();
-		pip3.setGrade("0");
-		pip3.setPname("巷道3");
-		pip3.setPcode("pipes3");
-		pips1.add(pip3);
-		D_M00004_PTS_PIPES_RECODE pip4 =new D_M00004_PTS_PIPES_RECODE();
-		pip4.setGrade("0");
-		pip4.setPname("巷道4");
-		pip4.setPcode("pipes4");
-		pips1.add(pip4);
-
-
-		pts.add(pt1);
-		//----------------------
-
-		D_M00004_PTS_RECODE pt2=new D_M00004_PTS_RECODE();
-		pt2.setTime("2024-12-06 10:27:37 +0800");
-		List<D_M00004_PTS_PIPES_RECODE> pips2 =new ArrayList<>();
-		pt2.setPipes(pips2);
-
-		D_M00004_PTS_PIPES_RECODE pip_1 =new D_M00004_PTS_PIPES_RECODE();
-		pip_1.setGrade("0");
-		pip_1.setPname("巷道1");
-		pip_1.setPcode("pipes1");
-		pips2.add(pip_1);
-
-		D_M00004_PTS_PIPES_RECODE pip_2 =new D_M00004_PTS_PIPES_RECODE();
-		pip_2.setGrade("1");
-		pip_2.setPname("巷道2");
-		pip_2.setPcode("pipes2");
-		pips2.add(pip_2);
-
-		D_M00004_PTS_PIPES_RECODE pip_3 =new D_M00004_PTS_PIPES_RECODE();
-		pip_3.setGrade("1");
-		pip_3.setPname("巷道3");
-		pip_3.setPcode("pipes3");
-		pips2.add(pip_3);
-		D_M00004_PTS_PIPES_RECODE pip_4 =new D_M00004_PTS_PIPES_RECODE();
-		pip_4.setGrade("02");
-		pip_4.setPname("巷道4");
-		pip_4.setPcode("pipes4");
-		pips2.add(pip_4);
-		pts.add(pt2);
-		//----------------------
-
-		D_M00004_PTS_RECODE pt3=new D_M00004_PTS_RECODE();
-		pt3.setTime("2024-12-06 10:28:37 +0800");
-		List<D_M00004_PTS_PIPES_RECODE> pips3 =new ArrayList<>();
-		pt3.setPipes(pips3);
-
-		D_M00004_PTS_PIPES_RECODE pip_21 =new D_M00004_PTS_PIPES_RECODE();
-		pip_21.setGrade("0");
-		pip_21.setPname("巷道1");
-		pip_21.setPcode("pipes1");
-		pips3.add(pip_21);
-
-		D_M00004_PTS_PIPES_RECODE pip_22 =new D_M00004_PTS_PIPES_RECODE();
-		pip_22.setGrade("2");
-		pip_22.setPname("巷道2");
-		pip_22.setPcode("pipes2");
-		pips3.add(pip_22);
-
-		D_M00004_PTS_PIPES_RECODE pip_23 =new D_M00004_PTS_PIPES_RECODE();
-		pip_23.setGrade("2");
-		pip_23.setPname("巷道3");
-		pip_23.setPcode("pipes3");
-		pips3.add(pip_23);
-		D_M00004_PTS_PIPES_RECODE pip_24 =new D_M00004_PTS_PIPES_RECODE();
-		pip_24.setGrade("1");
-		pip_24.setPname("巷道4");
-		pip_24.setPcode("pipes4");
-		pips3.add(pip_24);
-		pts.add(pt3);
-
+		String totaltime =job.getTotaltime();//模拟时间
+		String dt=job.getDt();//时间步长
+		String acctime =job.getAcctime();//开始时间
+		String genPtah = TemplateGenerator2.BPATH + "/" + aid + "/" + da.getJid() + "/";
+		int steps = Integer.valueOf(totaltime)/Integer.valueOf(dt);
+		if("Gass".equals(da.getType())||"Gass1".equals(da.getType())){//瓦斯爆炸
+			genPtah=genPtah+"/gas/out";
+		}else if("Water".equals(da.getType())){
+			genPtah=genPtah+"water/out";
+		}else if("Fire".equals(da.getType())){
+			genPtah=genPtah+"fire/out";
+		}else{
+			throw  new BusinessException("");
+		}
+		for (int i = 1; i <=steps; i++) {
+			D_M00004_PTS_RECODE pr =new D_M00004_PTS_RECODE();
+			Date startTime =XIDateTimeUtils.getDateFromZonedStr(acctime);
+			Date thisTime = new Date(startTime.getTime()+Long.valueOf(String.valueOf(i * Integer.valueOf(dt))));
+			pr.setTime(XIDateTimeUtils.getDateStrFromDate(thisTime));
+			String postFile =genPtah+"/POST"+i+".1d";
+			// 使用try-with-resources语句自动关闭资源
+			List<String> wsPcode = new ArrayList<>();//存储危险pcode
+			readFilePipeDangers(postFile, wsPcode);
+			DPtpipeassMapper ptDao = UtilTools.getBean(DPtpipeassMapper.class);
+			DPtpipeassSQLBuilder ptsb = new DPtpipeassSQLBuilder();
+			DPtpipeassSQLBuilder.Criteria ptsc = ptsb.createCriteria();
+			ptsc.andPcodeIn(wsPcode);
+			List<DPtpipeass> ptList = ptDao.selectByExample(ptsb);
+			List<D_M00004_PTS_PIPES_RECODE>  pipes= new ArrayList<>();
+			for (DPtpipeass pt: ptList) {
+				D_M00004_PTS_PIPES_RECODE recode = new D_M00004_PTS_PIPES_RECODE();
+				recode.setPcode(pt.getPtcode());
+				recode.setGrade("1");
+				pipes.add(recode);
+			}
+			pr.setPipes(pipes);
+			pts.add(pr);
+		}
 
 		DMwayMapper wdao = UtilTools.getBean(DMwayMapper.class);
 		DMwaySQLBuilder wsb =new DMwaySQLBuilder();
@@ -157,7 +106,122 @@ public class M00004Service extends M00004BaseModel implements ExecProcessFlow {
 		this.getD_m00004().setLines(lines);
 		this.getD_m00004().setPts(pts);
 	}
-	
+
+	/**
+	 * //			pos,Temperature,Pressure,CO2,CO
+	 * //			pipes1:       6
+	 * //			0.0000000000,25.0000000030,20.0198567067,0.0000100000,0.0000100000
+	 * //			0.2000000030,25.0000000004,20.0198567058,0.0000100000,0.0000100000
+	 * //			0.4000000060,25.0000000000,20.0198567049,0.0000100000,0.0000100000
+	 * //			0.6000000238,25.0000000000,20.0198567040,0.0000100000,0.0000100000
+	 * //			0.8000000119,24.9999999997,20.0198567032,0.0000100000,0.0000100000
+	 * //			1.0000000000,24.9999999977,20.0198567023,0.0000100000,0.0000100000
+	 * //			pipes2:      86
+	 * //			0.0000000000,25.0000000030,20.0198567067,0.0000100000,0.0000100000
+	 * //			0.0117647061,25.0000000003,20.0198567087,0.0000100000,0.0000100000
+	 * //			0.0235294122,25.0000000000,20.0198567107,0.0000100000,0.0000100000
+	 * //			0.0352941193,25.0000000000,20.0198567127,0.0000100000,0.0000100000
+	 * //			0.0470588244,25.0000000000,20.0198567147,0.0000100000,0.0000100000
+	 * @param postFile
+	 * @param wsPcode
+	 */
+	private void readFilePipeDangers(String postFile, List<String> wsPcode) {
+		try (BufferedReader br = new BufferedReader(new FileReader(postFile))) {
+			String line;
+			List<String> salars = new ArrayList<>();
+			boolean fristFlag = true;//首行判断
+			boolean pcodFlag = true;//判断是否继续读取
+			// 逐行读取,直到文件末尾
+			while ((line = br.readLine()) != null) {
+				if(fristFlag){
+					String[] salar= line.split(",");
+					salars= Arrays.asList(salar);
+					fristFlag=false;
+					continue;
+				}
+				if(line.startsWith("pip")){//巷道行
+					if(pcodFlag){//如果上一个巷道安全
+						if(!wsPcode.isEmpty()){
+							wsPcode.remove(wsPcode.size()-1);
+						}
+					}
+					wsPcode.add(line.split(":")[0]);
+					pcodFlag=true;
+					continue;
+				}
+				if(pcodFlag){
+					String[] salarVals = line.split(",");
+					for (int j = 0; j < salars.size(); j++) {
+						double val = Double.valueOf(salarVals[j]);
+						if("pos".equals(salars.get(j))){
+
+						}else if("Temperature".equals(salars.get(j))){
+							if(val>=40){//危险
+								pcodFlag=false;
+								break;
+							}
+						}else if("Pressure".equals(salars.get(j))) {
+
+						}else if("CO2".equals(salars.get(j))){
+							if(val>=1800){//危险
+								pcodFlag=false;
+								break;
+							}
+						}else if("CO".equals(salars.get(j))){
+							if(val>=30){//危险
+								pcodFlag=false;
+								break;
+							}
+						}else if("CH4".equals(salars.get(j))){
+							if(val>=250000){//危险
+								pcodFlag=false;
+								break;
+							}
+						}else if("SO2".equals(salars.get(j))){
+							if(val>=10){//危险
+								pcodFlag=false;
+								break;
+							}
+						}else if("NO".equals(salars.get(j))){
+							if(val>=10){//危险
+								pcodFlag=false;
+								break;
+							}
+						}else if("NO2".equals(salars.get(j))){
+							if(val>=10){//危险
+								pcodFlag=false;
+								break;
+							}
+						}else if("H2S".equals(salars.get(j))){
+							if(val>=10){//危险
+								pcodFlag=false;
+								break;
+							}
+						}else if("NH3".equals(salars.get(j))){
+							if(val>=30){//危险
+								pcodFlag=false;
+								break;
+							}
+						}else if("CL2".equals(salars.get(j))){
+							if(val>=30){//危险
+								pcodFlag=false;
+								break;
+							}
+						}else if("Height".equals(salars.get(j))){
+							if(val>=1.5){//危险
+								pcodFlag=false;
+								break;
+							}
+						}
+					}
+				}
+			}
+		} catch (IOException e) {
+			// 异常处理
+			e.printStackTrace();
+		}
+	}
+
 	/**
 	 * 基础系统,“平台对接求解结果”业务前处理
  	 */

+ 111 - 0
src/test/java/com/miniframe/PipeDangerTest.java

@@ -0,0 +1,111 @@
+package com.miniframe;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class PipeDangerTest {
+
+    public static void main(String[] args) {
+        String postFile ="C:\\Users\\Administrator\\Desktop\\fsdownload\\POST17.1d";
+        List<String> salars = new ArrayList<>();
+        List<String> wsPcode = new ArrayList<>();//存储危险pcode
+        try (BufferedReader br = new BufferedReader(new FileReader(postFile))) {
+            String line;
+            boolean fristFlag = true;//首行判断
+            boolean pcodFlag = true;//判断是否继续读取
+            // 逐行读取,直到文件末尾
+            while ((line = br.readLine()) != null) {
+                if(fristFlag){
+                    String[] salar= line.split(",");
+                    salars= Arrays.asList(salar);
+                    fristFlag=false;
+                    continue;
+                }
+                if(line.startsWith("pip")){//巷道行
+                    if(pcodFlag){//如果上一个巷道安全
+                        if(!wsPcode.isEmpty()){
+                            wsPcode.remove(wsPcode.size()-1);
+                        }
+                    }
+                    wsPcode.add(line.split(":")[0]);
+                    pcodFlag=true;
+                    continue;
+                }
+                if(pcodFlag){
+                    String[] salarVals = line.split(",");
+                    for (int j = 0; j < salars.size(); j++) {
+                        double val = Double.valueOf(salarVals[j]);
+                        if("pos".equals(salars.get(j))){
+
+                        }else if("Temperature".equals(salars.get(j))){
+                            if(val>=40){//危险
+                                pcodFlag=false;
+                                break;
+                            }
+                        }else if("Pressure".equals(salars.get(j))) {
+
+                        }else if("CO2".equals(salars.get(j))){
+                            if(val>=1800){//危险
+                                pcodFlag=false;
+                                break;
+                            }
+                        }else if("CO".equals(salars.get(j))){
+                            if(val>=30){//危险
+                                pcodFlag=false;
+                                break;
+                            }
+                        }else if("CH4".equals(salars.get(j))){
+                            if(val>=250000){//危险
+                                pcodFlag=false;
+                                break;
+                            }
+                        }else if("SO2".equals(salars.get(j))){
+                            if(val>=10){//危险
+                                pcodFlag=false;
+                                break;
+                            }
+                        }else if("NO".equals(salars.get(j))){
+                            if(val>=10){//危险
+                                pcodFlag=false;
+                                break;
+                            }
+                        }else if("NO2".equals(salars.get(j))){
+                            if(val>=10){//危险
+                                pcodFlag=false;
+                                break;
+                            }
+                        }else if("H2S".equals(salars.get(j))){
+                            if(val>=10){//危险
+                                pcodFlag=false;
+                                break;
+                            }
+                        }else if("NH3".equals(salars.get(j))){
+                            if(val>=30){//危险
+                                pcodFlag=false;
+                                break;
+                            }
+                        }else if("CL2".equals(salars.get(j))){
+                            if(val>=30){//危险
+                                pcodFlag=false;
+                                break;
+                            }
+                        }else if("Height".equals(salars.get(j))){
+                            if(val>=1.5){//危险
+                                pcodFlag=false;
+                                break;
+                            }
+                        }
+                    }
+                }
+            }
+        } catch (IOException e) {
+            // 异常处理
+            e.printStackTrace();
+        }
+        System.out.println(wsPcode);
+    }
+}