Bladeren bron

油井测量数据、衍生数据计算,存储管理

chenwen 1 jaar geleden
bovenliggende
commit
673ba3cf0c

+ 33 - 1
src/main/java/com/hb/proj/analysis/controller/ProduceParamController.java

@@ -2,11 +2,13 @@ package com.hb.proj.analysis.controller;
 
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import com.hb.proj.allconfig.AccessToken;
+import com.hb.proj.analysis.service.ProduceParamCalculator;
 import com.hb.proj.analysis.service.ProduceParamService;
 import com.hb.proj.model.WellAnalysisParamPO;
 import com.hb.proj.model.WellMeasurePO;
@@ -25,6 +27,9 @@ public class ProduceParamController {
 	@Autowired
 	private ProduceParamService  service;
 	
+	@Autowired
+	private RedisTemplate<String,Object> redisTemplate;
+	
 	/**
 	 * 获得指定井的最新生成动态参数
 	 * @param wellId
@@ -100,6 +105,33 @@ public class ProduceParamController {
 	 */
 	@RequestMapping("/calcParam")
 	public RespVO<Object>  calcParam(@NotBlank(message="缺少井号") String wellId){
-		return RespVOBuilder.ok();
+		
+		WellMeasurePO measure=service.getLastMeasureParam(wellId);
+		if(measure==null) {
+			return RespVOBuilder.error("缺少该井的测量数据");
+		}
+		
+		WellPumpPO pump=service.getLastPumpParam(wellId);
+		if(pump==null) {
+			return RespVOBuilder.error("缺少该井的泵数据");
+		}
+		
+		/*
+		WellAnalysisParamPO analysis=service.getLastAnalysisParam(wellId);
+		
+		//引用相同数据计算过
+		if(analysis!=null && analysis.getRefMeasureId().equals(measure.getMeasureId()) && analysis.getRefPumpId().equals(pump.getPumpId()) ) {
+			return RespVOBuilder.ok();
+		}*/
+		
+		//实时采集数据:冲次(要求单位 次/min)
+		Double freq=(Double)redisTemplate.opsForHash().get(wellId,"freq");
+		
+		//计算出新的分析参数
+		WellAnalysisParamPO analysis=ProduceParamCalculator.calc(measure, pump, freq);
+		analysis.setWellId(wellId);
+		service.addAnalysisParam(analysis);
+		
+		return RespVOBuilder.ok(analysis);
 	}
 }

+ 62 - 37
src/main/java/com/hb/proj/analysis/service/ProduceParamCalculator.java

@@ -1,56 +1,76 @@
 package com.hb.proj.analysis.service;
 
-import com.hb.proj.model.LiquidPO;
 import com.hb.proj.model.WellAnalysisParamPO;
 import com.hb.proj.model.WellMeasurePO;
 import com.hb.proj.model.WellPumpPO;
-import com.hb.proj.model.WellRtDataVO;
 
 public class ProduceParamCalculator {
 
-	public WellAnalysisParamPO  calc(WellMeasurePO measure,WellPumpPO pump,WellRtDataVO wellRt,LiquidPO liquid) {
+	public static WellAnalysisParamPO  calc(WellMeasurePO measure,WellPumpPO pump,Double rtFreq) {
+		
 		WellAnalysisParamPO  analyParam=new WellAnalysisParamPO();
+		analyParam.setRefMeasureId(measure.getMeasureId());
+		analyParam.setRefPumpId(pump.getPumpId());
+		
+		//含水率原值为百分数,计算时要*0.01
+		Double waterRatio=measure.getWaterRatio()!=null?(measure.getWaterRatio().doubleValue()*0.01):null;
 		
 		/**
 		 * 计量油量=计量液量*(1-含水率)
 		 * 计量水量=计量液量*含水率
 		 */
-		analyParam.setMeteredOilYield(measure.getMeteredLiquidYield()*(1-measure.getWaterRatio())); 
-		analyParam.setMeteredWaterYield(measure.getMeteredLiquidYield()*measure.getWaterRatio());  
+		if(isNotNull(measure.getMeteredLiquidYield(),waterRatio)) {
+			analyParam.setMeteredOilYield(measure.getMeteredLiquidYield()*(1-waterRatio)); 
+			analyParam.setMeteredWaterYield(measure.getMeteredLiquidYield()*waterRatio);  
+		}
+		
 		
 		/**
 		 * 测量油量=测量液量*(1-含水率)
 		 * 测量水量=测量液量*(1-含水率)
 		 */
-		analyParam.setMeasureOilYield(measure.getMeasureLiquidYield()*(1-measure.getWaterRatio()));
-		analyParam.setMeasureWaterYield(measure.getMeasureLiquidYield()*measure.getWaterRatio());
+		if(isNotNull(measure.getMeasureLiquidYield(),waterRatio)) {
+			analyParam.setMeasureOilYield(measure.getMeasureLiquidYield()*(1-waterRatio));
+			analyParam.setMeasureWaterYield(measure.getMeasureLiquidYield()*waterRatio);
+		}
+		
 		
 		
 		/**
-		 * 泵理论排量=截面积*柱塞冲程*spm*24*60*泵系数
+		 * 泵理论排量=截面积*柱塞冲程*spm*24*60*泵系数*0.000001
 		 * 理论排量按每分钟1冲次,泵系数为1计算。
 		 * 新泵时为1,长期使用小于1,用于修正泵理论排量
 		 * spm 冲次频率(每分钟) 目前固定为1
 		 */
-		pump.setSpm(1);
-		double tempYield=pump.getPi()*Math.pow(pump.getBasicDiam()/2,2)*pump.getStroke()*pump.getPumpCoeff()*pump.getSpm()*24*60;
-		pump.setTheoryVolume(tempYield);
+		if(isNotNull(pump.getBasicDiam(),pump.getStroke(),pump.getPumpCoeff())){
+			pump.setSpm(1);
+			double tempYield=pump.getPi()*Math.pow(pump.getBasicDiam()/2,2)*pump.getStroke()*pump.getPumpCoeff()*pump.getSpm()*24*60*0.000001;
+			pump.setTheoryVolume(tempYield);
+		}
+		
 		
 		
 		/**
 		 * 理论液量=泵理论排量*冲次
 		 */
-		analyParam.setTheoryLiquidYield(pump.getTheoryVolume()*wellRt.getFreq());
+		if(pump.getTheoryVolume()!=null) {
+			analyParam.setTheoryLiquidYield(pump.getTheoryVolume()*rtFreq);
+		}
+		
 		
 		/**
 		 * 测量泵效=测量液量/理论液量
 		 * 校准泵效=计量液量/理论液量
 		 * 综合泵效=弹性伸缩*泵充满度*漏失系数*地表体积系数
 		 */
+		if(isNotNull(measure.getMeasureLiquidYield(),measure.getMeteredLiquidYield(),analyParam.getTheoryLiquidYield())) {
+			analyParam.setMeasuredPumpEff(measure.getMeasureLiquidYield()/analyParam.getTheoryLiquidYield());
+			analyParam.setCorrectPumpEff(measure.getMeteredLiquidYield()/analyParam.getTheoryLiquidYield());
+		}
+		if(isNotNull(measure.getElasticCoeff(),pump.getFillDegree(),pump.getLeakCoeff(),measure.getSurfaceCompCoe())) {
+			analyParam.setComPumpEff(measure.getElasticCoeff()*pump.getFillDegree()*pump.getLeakCoeff()*measure.getSurfaceCompCoe());
+		}
 		
-		analyParam.setMeasuredPumpEff(measure.getMeasureLiquidYield()/analyParam.getTheoryLiquidYield());
-		analyParam.setCorrectPumpEff(measure.getMeteredLiquidYield()/analyParam.getTheoryLiquidYield());
-		analyParam.setComPumpEff(measure.getElasticCoeff()*pump.getFillDegree()*pump.getLeakCoeff()*measure.getSurfaceCompCoe());
 		
 		
 		/**
@@ -58,16 +78,22 @@ public class ProduceParamCalculator {
 		 * 实际油量=实际液量*(1-含水率),用于绘制IPR曲线
 		 * 实际水量=实际液量´含水率,用于绘制IPR曲线
 		 */
-		analyParam.setRealLiquidYield(analyParam.getCorrectPumpEff()*analyParam.getTheoryLiquidYield());
-		analyParam.setRealOilYield(analyParam.getRealLiquidYield()*(1-measure.getWaterRatio()));
-		analyParam.setRealWaterYield(analyParam.getRealLiquidYield()*measure.getWaterRatio());
+		if(isNotNull(analyParam.getCorrectPumpEff(),analyParam.getTheoryLiquidYield(),analyParam.getRealLiquidYield(),waterRatio)) {
+			analyParam.setRealLiquidYield(analyParam.getCorrectPumpEff()*analyParam.getTheoryLiquidYield());
+			analyParam.setRealOilYield(analyParam.getRealLiquidYield()*(1-waterRatio));
+			analyParam.setRealWaterYield(analyParam.getRealLiquidYield()*waterRatio);
+		}
+		
 		
 		
 		/**
 		 * 深度压差(m)=折算动液面深度-折算静液面深度
 		 * 流动压差(Mpa)=油藏压力-井底生产压力=深度压差*混液密度*g/1000
 		 */
-		analyParam.setDiffPressBtmflow(analyParam.getDiffPressDepth()*measure.getMixLiquidDensity()*measure.getGravity()/1000);
+		if(isNotNull(analyParam.getDiffPressDepth(),measure.getMixLiquidDensity(),measure.getGravity())) {
+			analyParam.setDiffPressBtmflow(analyParam.getDiffPressDepth()*measure.getMixLiquidDensity()*measure.getGravity()/1000);
+		}
+		
 		
 		/**
 		 * 油指数_J=功图液量/流动压差
@@ -75,27 +101,26 @@ public class ProduceParamCalculator {
 		 * 计量指数_J=计量液量/流动压差
 		 * 计量指数_K=计量液量/深度压差
 		 */
+		if(isNotNull(analyParam.getDiagramLiquidYield(),analyParam.getDiffPressBtmflow(),analyParam.getDiffPressDepth())) {
+			analyParam.setProductIndexJ(analyParam.getDiagramLiquidYield()/analyParam.getDiffPressBtmflow());
+			analyParam.setProductIndexK(analyParam.getDiagramLiquidYield()/analyParam.getDiffPressDepth());
+		}
 		
-		analyParam.setProductIndexJ(analyParam.getDiagramLiquidYield()/analyParam.getDiffPressBtmflow());
-		analyParam.setProductIndexK(analyParam.getDiagramLiquidYield()/analyParam.getDiffPressDepth());
-		
-		analyParam.setMeteredProductIndexJ(measure.getMeteredLiquidYield()/analyParam.getDiffPressBtmflow());
-		analyParam.setMeteredProductIndexK(measure.getMeteredLiquidYield()/analyParam.getDiffPressDepth());
+		if(isNotNull(measure.getMeteredLiquidYield(),analyParam.getDiffPressBtmflow(),analyParam.getDiffPressDepth())) {
+			analyParam.setMeteredProductIndexJ(measure.getMeteredLiquidYield()/analyParam.getDiffPressBtmflow());
+			analyParam.setMeteredProductIndexK(measure.getMeteredLiquidYield()/analyParam.getDiffPressDepth());
+		}
 		
-		/**
-		 * 折算静深度=静液面深度-(套压(MPa)/(液体密度(kg/l)*重力加速度(m/s2)))*1000
-		 * 套管压力不为零时的静液面深度.计算折算深度时要用对应时间的套压
-		 * 
-		 * 折算动深度=校正动液面深度-(套压(MPa)/(液体密度(kg/l)*重力加速度(m/s2)))*1000
-		 * 套管压力不为零时的动液面深度。计算折算深度时要用对应时间的套压
-		 * 
-		 * 套压:指动液面设备返回的套压值
-		 * 校正液面深度,手动计算保存后,折算动液面深度也要跟随变化吧
-		 */
-		Double disD=liquid.getCasingPressDev()*1000/(measure.getMixLiquidDensity()*measure.getGravity());
-		analyParam.setCvtStaticLiquidDepth(measure.getStaticLiquidDepth()-disD);
-		analyParam.setCvtStaticLiquidDepth(liquid.getLiquidDepth()-disD);
 		
+	
 		return analyParam;
 	}
+	
+	private static  boolean isNotNull(Double... vals) {
+		boolean rst=true;
+		for(Double val : vals) {
+			rst=val!=null && rst;
+		}
+		return rst;
+	}
 }

+ 18 - 0
src/main/java/com/hb/proj/analysis/service/ProduceParamService.java

@@ -53,6 +53,22 @@ public class ProduceParamService {
 		return dao.queryForPojo(sql, WellMeasurePO.class, wellId);
 	}
 	
+	/**
+	 * 获得指定时间前最新的测量数据
+	 * @param wellId
+	 * @param beforeTime
+	 * @return
+	 */
+	public WellMeasurePO  getLastMeasureBefore(String wellId,Date beforeTime) {
+		String sql="""
+				select * from tzl_well_measure 
+				where del_if=false and well_id=? and create_time<?
+				order by create_time desc limit 1
+				""";
+		return dao.queryForPojo(sql, WellMeasurePO.class, wellId,beforeTime);
+	}
+	
+	
 	/**
 	 * 增加抽油泵参数
 	 * @param pump
@@ -115,4 +131,6 @@ public class ProduceParamService {
 				""";
 		return dao.queryForPojo(sql, WellAnalysisParamPO.class,wellId);
 	}
+	
+	
 }

+ 4 - 7
src/main/java/com/hb/proj/model/WellAnalysisParamPO.java

@@ -128,17 +128,14 @@ public class WellAnalysisParamPO {
 	 */
 	private Double meteredProductIndexK;
 	
-	/**
-	 * 折算静液深度
-	 */
-	private Double cvtStaticLiquidDepth;
 	
 	/**
-	 * 折算动液深度
+	 * 计算时引用的测量数据记录id
 	 */
-	private Double cvtDynLiquidDepth;
-	
 	private String refMeasureId;
 	
+	/**
+	 * 计算时引用的泵数据记录id
+	 */
 	private String refPumpId;
 }

+ 1 - 4
src/main/java/com/hb/proj/model/WellMeasurePO.java

@@ -76,9 +76,6 @@ public class WellMeasurePO {
 	private Double meteredLiquidYield; 
 	
 	
-	/**
-	 * 静液面深
-	 */
-	private Double staticLiquidDepth;
+	
 	
 }