Преглед изворни кода

动液面衍生数据计算、处理(静液面深度、折算静深度、折算液面深度)接口

chenwen пре 1 година
родитељ
комит
5d4da8a858

+ 14 - 0
src/main/java/com/hb/proj/allconfig/BusinessException.java

@@ -0,0 +1,14 @@
+package com.hb.proj.allconfig;
+
+public class BusinessException extends RuntimeException {
+
+	private static final long serialVersionUID = -4532034995158699310L;
+
+	public BusinessException() {
+		super();
+	}
+	
+	public BusinessException(String msg) {
+		super(msg);
+	}
+}

+ 5 - 4
src/main/java/com/hb/proj/allconfig/RequestValidateExceptionHandler.java

@@ -2,9 +2,6 @@ package com.hb.proj.allconfig;
 
 import java.util.Set;
 
-import jakarta.validation.ConstraintViolation;
-import jakarta.validation.ConstraintViolationException;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.validation.BindException;
@@ -17,6 +14,9 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
 import com.hb.proj.utils.RespVO;
 import com.hb.proj.utils.RespVOBuilder;
 
+import jakarta.validation.ConstraintViolation;
+import jakarta.validation.ConstraintViolationException;
+
 @RestControllerAdvice
 public class RequestValidateExceptionHandler {
 	
@@ -56,8 +56,9 @@ public class RequestValidateExceptionHandler {
 	
 	@ExceptionHandler(Exception.class)
 	public RespVO<Object> otherExceptionHandler(Exception e) {
+		boolean isBE=e instanceof BusinessException;
 		logger.error("服务出错",e);
-		return RespVOBuilder.error(RespVOBuilder.API_EXE_ERROR,"服务出错");
+		return RespVOBuilder.error(RespVOBuilder.API_EXE_ERROR,isBE?e.getMessage():"服务出错");
 		
 	}
 }

+ 29 - 0
src/main/java/com/hb/proj/data/controller/LiquidController.java

@@ -1,6 +1,7 @@
 package com.hb.proj.data.controller;
 
 import java.util.Date;
+import java.util.Set;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.HashOperations;
@@ -102,9 +103,37 @@ public class LiquidController {
 	@RequestMapping("/save")
 	public RespVO<Object>  save(@Validated LiquidPO liquid){
 		service.saveCalculate(liquid);
+		
+		//更新本记录折算液面深度
+		LiquidPO dbliquid=service.getHadSound(liquid.getDataId().toString());
+		service.updateConvertAndStatic(dbliquid);
+
+		//如果是使用的音速法计算
+		if(dbliquid.getComputeMode().equals(LiquidPO.MODE_SOUND_SPEED)) {
+			
+			Set<String> ids=service.addDefDepthForCorrect(dbliquid); //同步继承记录的校正深度、校正音速
+			if(ids!=null) {
+				for(String id : ids) {
+					service.updateConvertAndStatic(service.getHadSound(id)); //同步继承记录的折算液面深度,静液面数据
+				}
+			}
+		}
+		
+		return RespVOBuilder.ok();
+	}
+	
+	/**
+	 * 静液面测算保存(标记记录为静液面)
+	 * @param dataId
+	 * @return
+	 */
+	@RequestMapping("/saveStaticCalc")
+	public RespVO<Object>  saveStaticCalc(@NotBlank(message="记录号不能为空") String dataId){
+		service.saveStaticCalcTag(dataId);
 		return RespVOBuilder.ok();
 	}
 	
+	
 	/**
 	 * 逻辑删除单个记录
 	 * @param liquid

+ 49 - 0
src/main/java/com/hb/proj/data/service/LiquidCalculator.java

@@ -0,0 +1,49 @@
+package com.hb.proj.data.service;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.hb.proj.model.LiquidPO;
+import com.hb.proj.model.WellMeasurePO;
+
+/**
+ * 动液面相关数据计算
+ * @author cwen
+ *
+ */
+public class LiquidCalculator {
+	
+	private static final Logger logger=LoggerFactory.getLogger(LiquidCalculator.class);
+
+	/**
+	 * 计算折算动液面深度
+	 * 折算液面深度( m)=校正动液面深度(m)-(套压(动液面采集值MPa)/(混液密度(kg/l)*重力加速度(m/s2)))*1000
+	 * @param liquid  动液面数据对象
+	 * @param measure 测量数据对象
+	 * @return
+	 */
+	public static Double calcConvertLiquidDepth(LiquidPO liquid,WellMeasurePO measure) {
+		
+		if(liquid==null || liquid.getLiquidDepth()==null || liquid.getCasingPressDev()==null) {
+			return null;
+		}
+		
+		if(measure==null || measure.getMixLiquidDensity()==null || measure.getGravity()==null) {
+			return null;
+		}
+		
+		try {
+			double rst=0;
+			rst=(liquid.getCasingPressDev()*1000)/(measure.getMixLiquidDensity()*measure.getGravity());
+			rst=liquid.getLiquidDepth()-rst;
+			rst=Math.round(rst*100)*0.01;
+			
+			return rst;
+		}
+		catch(Exception e) {
+			logger.error("折算动液面深度计算出错:{}",e.getMessage());
+			return null;
+		}
+		
+	}
+}

+ 156 - 13
src/main/java/com/hb/proj/data/service/LiquidService.java

@@ -4,10 +4,14 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import com.hb.proj.allconfig.BusinessException;
+import com.hb.proj.analysis.service.ProduceParamService;
 import com.hb.proj.model.LiquidPO;
 import com.hb.proj.model.LiquidVO;
 import com.hb.xframework.dao.core.SpringJdbcDAO;
@@ -19,6 +23,8 @@ public class LiquidService {
 	@Autowired
 	private SpringJdbcDAO  dao;
 	
+	@Autowired
+	private ProduceParamService  produceParamService;
 	
 	/**
 	 * 分页查询指定井的动液面数据  目前不用del_if过滤
@@ -34,9 +40,7 @@ public class LiquidService {
 					select w.well_name,data_id,test_time,liquid_depth,compute_mode,sound_speed_dev,liquid_depth_dev,casing_press_dev,
 					battery_voltage,sound_speed_factor,sound_speed_calc,sound_speed,
 					
-					(select sound_speed_factor from tzl_gather_data_liquid d2 where d2.well_id=d.well_id and d2.del_if=false 
-					and  d2.compute_mode='sound_speed' and d2.test_time between date_sub(d.test_time,interval 3 month ) 
-					and d.test_time order by d2.test_time desc limit 1) pre_sound_speed_factor
+					liquid_depth_static,liquid_depth_static_convert,liquid_depth_convert,static_calc_if
 					
 					from tzl_gather_data_liquid d
 					left join tzl_well w on d.well_id=w.well_id
@@ -46,6 +50,41 @@ public class LiquidService {
 		return dao.queryForPagedData(sql, pageNo, pageSize, LiquidVO.class, wellId,startTime,endTime);
 	}
 	
+	
+	/**
+	 * 获得动液面单个记录明细数据
+	 * @param dataId
+	 * @return
+	 */
+	public LiquidPO  getDtl(String dataId) {
+		return dao.queryForPojo("select * from tzl_gather_data_liquid where data_id=?", LiquidPO.class, dataId);
+	}
+	
+	/**
+	 *  获得动液面单个记录明细数据(含音速法相关数据)
+	 * @param dataId
+	 * @return
+	 */
+	public LiquidPO  getHadSound(String dataId) {
+		String sql="""
+				select data_id,well_id,test_time,liquid_depth,sound_speed,sound_speed_factor,sound_interval,
+				compute_mode,sound_speed_dev,sound_speed_calc,liquid_depth_dev,casing_press_dev,liquid_depth_static,
+				liquid_depth_static_convert,liquid_depth_convert,static_calc_if
+				from tzl_gather_data_liquid
+				where data_id=?
+				""";
+		return dao.queryForPojo(sql, LiquidPO.class, dataId);
+	}
+	
+	
+	/**
+	 * 逻辑删除动液面记录
+	 * @param dataId
+	 */
+	public void delete(String dataId) {
+		dao.exeUpdate("update tzl_gather_data_liquid set del_if=true where data_id=?", dataId);
+	}
+	
 	/**
 	 * 保存收到计算结果
 	 * @param liquid
@@ -68,8 +107,9 @@ public class LiquidService {
 			args.addAll(Arrays.asList(liquid.getHoopStartPos(),liquid.getHoopEndPos(),liquid.getAvgLengthPipe(),liquid.getHoopCount(),liquid.getSoundSpeedCalc()));
 		}
 		else if(liquid.getComputeMode().equals(LiquidPO.MODE_SOUND_SPEED)) {
-			sql+=",sound_speed=?,sound_speed_factor=?";
+			sql+=",sound_speed=?,sound_speed_calc=?,sound_speed_factor=?";
 			args.add(liquid.getSoundSpeed());
+			args.add(liquid.getSoundSpeed()); //音速法计算时,输入音速作为校正音速
 			args.add(liquid.getSoundSpeedFactor());
 		}
 		else if(liquid.getComputeMode().equals(LiquidPO.MODE_SOUND_MARK)) {
@@ -85,22 +125,125 @@ public class LiquidService {
 		dao.exeUpdate(sql, args.toArray());
 	}
 	
-	
 	/**
-	 * 获得动液面单个记录明细数据
+	 * 标记为静液面测算记录
 	 * @param dataId
-	 * @return
 	 */
-	public LiquidPO  getDtl(String dataId) {
-		return dao.queryForPojo("select * from tzl_gather_data_liquid where data_id=?", LiquidPO.class, dataId);
+	public void saveStaticCalcTag(String dataId) {
+		dao.exeUpdate("update tzl_gather_data_liquid set static_calc_if=true where data_id=?", dataId);
+		
+		//标记后要进行静液面相关数据同步
+		LiquidPO  liquid=getHadSound(dataId);
+		if(liquid==null) {
+			return;
+		}
+		liquid.setStaticCalcIf(true);
+		updateStaticLiquid(liquid);
+		
+	}
+	
+	/**
+	 * 2023.10.10
+	 * 校正液面深度更新时(手动计算后,用音速法)---继承k系数进行默认校正深度、校正音速计算
+	 * 仅限于当前液面之后的记录,直到下个用音速法计算的记录前,且校正液面深度无值
+	 * 公式:
+	 * 默认校正深度=液面深度(设备采集值)*k(本记录之前最新的k系数)   【后期有更新的k系数也不再重复计算】
+	 * 默认校正音速=被继承记录输入音速
+	 * @param liquid
+	 * @return 参与同步更新的记录id
+	 */
+	public Set<String> addDefDepthForCorrect(LiquidPO  liquid) {
+		if(!liquid.getComputeMode().equals(LiquidPO.MODE_SOUND_SPEED)) {
+			return null;
+		}
+		
+		String sql="""
+				select min(test_time) from tzl_gather_data_liquid 
+				where well_id=? and test_time>? and compute_mode=?
+				""";
+		
+		LiquidPO  endLiquid=dao.queryForPojo(sql, LiquidPO.class, liquid.getWellId(),liquid.getTestTime(),LiquidPO.MODE_SOUND_SPEED);
+		Date endTime=endLiquid!=null && endLiquid.getTestTime()!=null?endLiquid.getTestTime():new Date();
+		
+		//参与更新记录的id
+		sql="""
+				select data_id,'1' tag from tzl_gather_data_liquid 
+				where well_id=? and liquid_depth is null 
+				and test_time>? and test_time<?
+				""";
+		Map<String,Object> dataIdMap=dao.queryForMapping(sql, "data_id", "tag", liquid.getWellId(),liquid.getTestTime(),endTime);
+		
+		if(dataIdMap==null || dataIdMap.size()==0) {
+			return null;
+		}
+		
+		sql="""
+				update tzl_gather_data_liquid   set liquid_depth=liquid_depth_dev*?,sound_speed_calc=?
+				where well_id=? and liquid_depth is null 
+				and test_time>? 
+				and test_time<?
+				""";
+		dao.exeUpdate(sql, liquid.getSoundSpeedFactor(),liquid.getSoundSpeed(), liquid.getWellId(),liquid.getTestTime(),endTime);
+		
+		return dataIdMap.keySet();
+		
 	}
 	
 	
+	
+	
+	
 	/**
-	 * 逻辑删除动液面记录
-	 * @param dataId
+	 * 2023.10.10
+	 * 校正液面深度更新时(手动计算后,不限计算方法)---更新当前及继承记录的折算液面深度、静液面深度、折算静深度
+	 * 若当前记录没有用过静液面测算,则只同步更新当前记录折算液面深度
+	 * 若当前记录用过过静液面测算,则更新当前记录折算液面深度,同时更新当前液面之后的记录的静液面深度、折算静深度,直到下个使用过静液面测算的记录前
+	 * 公式: 静液面深度=校正液面深度
+	 * 		折算静深度=折算液面深度
+	 * @param liquid
 	 */
-	public void delete(String dataId) {
-		dao.exeUpdate("update tzl_gather_data_liquid set del_if=true where data_id=?", dataId);
+	public void updateConvertAndStatic(LiquidPO  liquid) {
+		
+		//根据新的校正液面深度计算新的折算动液面深度
+		Double newConvertLiquid=LiquidCalculator.calcConvertLiquidDepth(liquid, produceParamService.getLastMeasureBefore(liquid.getWellId(),liquid.getTestTime()));
+		if(newConvertLiquid==null) {
+			throw new BusinessException("更新折算液面深度失败,请检测相关参数设置");
+		}
+		
+		//更新当前记录的折算液面深度
+		String  sql="""
+					update tzl_gather_data_liquid set liquid_depth_convert=?
+					where data_id=?
+					""";
+		dao.exeUpdate(sql, newConvertLiquid,liquid.getDataId());
+		
+		
+		if(!liquid.isStaticCalcIf()) {
+			return;
+		}
+		
+		liquid.setLiquidDepthConvert(newConvertLiquid);
+		updateStaticLiquid(liquid);
+	}
+	
+	
+	/**
+	 * 当前是静液面测算记录,同步本记录和继承该记录的 静液面深度、折算静深度
+	 * @param liquid
+	 */
+	public void updateStaticLiquid(LiquidPO  liquid) {
+		String sql="""
+				select min(test_time) from tzl_gather_data_liquid
+				where well_id=? and test_time>? and static_calc_if=true
+				""";
+		
+		LiquidPO  endLiquid=dao.queryForPojo(sql, LiquidPO.class, liquid.getWellId(),liquid.getTestTime());
+		Date endTime=endLiquid!=null && endLiquid.getTestTime()!=null?endLiquid.getTestTime():new Date();
+		
+		sql="""
+				update tzl_gather_data_liquid set liquid_depth_static=?,liquid_depth_static_convert=?
+				where well_id=? and  test_time>=? and test_time<?
+				""";
+		dao.exeUpdate(sql, liquid.getLiquidDepth(),liquid.getLiquidDepthConvert(), liquid.getWellId(),liquid.getTestTime(),endTime);				
 	}
 }

+ 24 - 0
src/main/java/com/hb/proj/model/LiquidPO.java

@@ -101,4 +101,28 @@ public class LiquidPO {
 	 * 计算音速(校正音速,接箍法、音标法)
 	 */
 	private Double soundSpeedCalc;
+	
+	/**
+	 * 静液面深 单位 m
+	 */
+	private Double liquidDepthStatic;
+	
+	/**
+	 * 折算静液面深度 单位 m
+	 */
+	private Double liquidDepthStaticConvert;
+	
+	/**
+	 * 折算动液面深度 单位 m
+	 */
+	private Double liquidDepthConvert;
+	
+	/**
+	 * 是否为静液面计算
+	 */
+	private Boolean staticCalcIf;
+	
+	public Boolean isStaticCalcIf() {
+		return staticCalcIf!=null && staticCalcIf.booleanValue();
+	}
 }

+ 0 - 42
src/main/java/com/hb/proj/model/LiquidVO.java

@@ -1,7 +1,5 @@
 package com.hb.proj.model;
 
-import org.apache.commons.lang3.StringUtils;
-
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 
@@ -13,8 +11,6 @@ public class LiquidVO extends LiquidPO {
 	
 	private String computeModeName;
 	
-	private Double preSoundSpeedFactor; //最近使用了音速法的记录的音速系数
-	
 	
 	public void setComputeMode(String computeMode) {
 		super.setComputeMode(computeMode);
@@ -28,46 +24,8 @@ public class LiquidVO extends LiquidPO {
 			this.computeModeName="音标法";
 		}
 		
-		setDefSoundSpeedCalc(computeMode,this.getSoundSpeed());
-		
-		setDefLiquidDepth(computeMode,this.getLiquidDepthDev());
 		
 	}
 	
-	public void setSoundSpeed(Double soundSpeed) {
-		super.setSoundSpeed(soundSpeed);
-		setDefSoundSpeedCalc(this.getComputeMode(),soundSpeed);
-	}
-	
-	public void setLiquidDepthDev(Double liquidDepthDev) {
-		super.setLiquidDepthDev(liquidDepthDev);
-		setDefLiquidDepth(this.getComputeMode(),liquidDepthDev);
-	}
-	
-	public void setPreSoundSpeedFactor(Double preFactor) {
-		this.preSoundSpeedFactor=preFactor;
-		setDefLiquidDepth(this.getComputeMode(),this.getLiquidDepthDev());
-	}
-	
-	
-	//参与计算的属性set方法中都要注入,避免set方法调用先后顺序使注入方法无效
-	//如果是音速法,则校正音速=输入音速参数
-	private void setDefSoundSpeedCalc(String computeMode,Double soundSpeed) {
-		if(LiquidPO.MODE_SOUND_SPEED.equals(computeMode)) {
-			this.setSoundSpeedCalc(soundSpeed);
-		}
-	}
-	
-	
-	//还未手动计算过,校正深度默认=液面深度(设备)* 音速系数
-	private void setDefLiquidDepth(String computeMode,Double liquidDepthDev) {
-		if(StringUtils.isBlank(computeMode) && liquidDepthDev!=null) {
-			Double dep=liquidDepthDev*(this.preSoundSpeedFactor!=null?this.preSoundSpeedFactor:1);
-			if(dep!=null) {
-				this.setLiquidDepth(Double.parseDouble(String.format("%.2f", dep)));
-			}
-		}
-	}
-	
 	
 }