Browse Source

实时采集井相关、预警参数动态调整

zhao.renji 3 weeks ago
parent
commit
5d3f8b86a6
32 changed files with 873 additions and 308 deletions
  1. 1 0
      pom.xml
  2. 19 0
      yujing-common/src/main/java/com/cn/tianji/common/RedisUtil.java
  3. 2 0
      yujing-common/src/main/java/com/cn/tianji/service/PullDataSICPService.java
  4. 5 0
      yujing-common/src/main/java/com/cn/tianji/service/WellDrillingService.java
  5. 7 0
      yujing-common/src/main/java/com/cn/tianji/service/impl/PullDataSICPServiceImpl.java
  6. 164 2
      yujing-common/src/main/java/com/cn/tianji/service/impl/WellDrillingServiceImpl.java
  7. 9 0
      yujing-condition-identification/src/main/java/com/cn/tianji/controller/WorkingConditionCalculationController.java
  8. 8 0
      yujing-condition-identification/src/main/java/com/cn/tianji/service/DataSupplementationService.java
  9. 137 0
      yujing-condition-identification/src/main/java/com/cn/tianji/service/Impl/DataSupplementationServiceImpl.java
  10. 0 4
      yujing-condition-identification/src/main/resources/config/application-prod.yml
  11. 5 9
      yujing-hook-load-warning/src/main/resources/config/application-prod.yml
  12. 2 0
      yujing-pull/src/main/java/com/cn/tianji/service/PullSICPDataService.java
  13. 1 1
      yujing-pull/src/main/java/com/cn/tianji/service/impl/BizServiceImpl.java
  14. 56 15
      yujing-pull/src/main/java/com/cn/tianji/service/impl/PullSICPDataServiceImpl.java
  15. 5 3
      yujing-pull/src/main/java/com/cn/tianji/task/PullDataTask.java
  16. 11 2
      yujing-pull/src/main/java/com/cn/tianji/task/PullSICPDataTask.java
  17. 0 4
      yujing-pull/src/main/resources/config/application-prod.yml
  18. 3 3
      yujing-pull/src/main/resources/config/application.yml
  19. 8 12
      yujing-pumping-pressure/src/main/resources/config/application-prod.yml
  20. 8 12
      yujing-torque/src/main/resources/config/application-prod.yml
  21. 1 0
      yujing-total-pool-volume/pom.xml
  22. 24 29
      yujing-total-pool-volume/src/main/resources/config/application-prod.yml
  23. 0 0
      yujing-total-pool-volume/warn-logs/error/total-pool-volume-error-2024-08-07.0.log
  24. 6 0
      yujing-warning-calculation/pom.xml
  25. 7 6
      yujing-warning-calculation/src/main/java/com/cn/tianji/common/DrillingOutHookLoadCatch.java
  26. 4 3
      yujing-warning-calculation/src/main/java/com/cn/tianji/common/PittotalCache.java
  27. 47 0
      yujing-warning-calculation/src/main/java/com/cn/tianji/entity/HookLoadCatch.java
  28. 19 0
      yujing-warning-calculation/src/main/java/com/cn/tianji/entity/TotalPoolVolumeCatch.java
  29. 11 2
      yujing-warning-calculation/src/main/java/com/cn/tianji/service/impl/ConditionDeterminationServiceImpl.java
  30. 54 42
      yujing-warning-calculation/src/main/java/com/cn/tianji/service/impl/ConditionIdentificationServiceImpl.java
  31. 64 48
      yujing-warning-calculation/src/main/java/com/cn/tianji/service/impl/DrillingOutHookLoadServiceImpl.java
  32. 185 111
      yujing-warning-calculation/src/main/java/com/cn/tianji/service/impl/TotalPoolVolumeServiceImpl.java

+ 1 - 0
pom.xml

@@ -74,6 +74,7 @@
             <artifactId>spring-boot-starter-data-redis</artifactId>
         </dependency>
 
+
         <!-- mybatis-plus相关-->
         <dependency>
             <groupId>com.baomidou</groupId>

+ 19 - 0
yujing-common/src/main/java/com/cn/tianji/common/RedisUtil.java

@@ -2,6 +2,7 @@ package com.cn.tianji.common;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.core.SessionCallback;
 import org.springframework.stereotype.Component;
 import org.springframework.util.CollectionUtils;
 
@@ -545,4 +546,22 @@ public class RedisUtil {
             return 0;
         }
     }
+
+    /**
+     * 执行 Redis 事务操作
+     *
+     * @param transactionOperations 事务操作的消费者函数
+     * @throws RuntimeException 如果事务执行过程中发生异常
+     */
+    public void executeTransaction(SessionCallback<List<Object>> transactionOperations) throws RuntimeException {
+        try {
+            // 执行事务
+            List<Object> results = redisTemplate.execute(transactionOperations);
+            if (results == null) {
+                throw new RuntimeException("事务执行失败,结果为null");
+            }
+        } catch (Exception e) {
+            throw new RuntimeException("事务执行失败", e);
+        }
+    }
 }

+ 2 - 0
yujing-common/src/main/java/com/cn/tianji/service/PullDataSICPService.java

@@ -7,6 +7,8 @@ import java.util.List;
 
 public interface PullDataSICPService {
 
+    void createTables(List<String> jhs);
+
     /**
      * 更新采集井数据列表
      */

+ 5 - 0
yujing-common/src/main/java/com/cn/tianji/service/WellDrillingService.java

@@ -3,6 +3,7 @@ package com.cn.tianji.service;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.cn.tianji.entity.WellDrilling;
+import com.cn.tianji.entity.WellDrillingSICP;
 
 import java.util.List;
 
@@ -21,4 +22,8 @@ public interface WellDrillingService extends IService<WellDrilling> {
     String getLastDateByJh(String tableName);
 
     void createTable(String paramString, long paramLong);
+
+    List<WellDrilling> sicpToLtdData(List<WellDrillingSICP> sicpList);
+
+    WellDrilling sicpToLtd(WellDrillingSICP item);
 }

+ 7 - 0
yujing-common/src/main/java/com/cn/tianji/service/impl/PullDataSICPServiceImpl.java

@@ -44,6 +44,13 @@ public class PullDataSICPServiceImpl implements PullDataSICPService {
     private ApplicationContext context;
 
 
+    @Override
+    public void createTables(List<String> jhs){
+        jhs.forEach(item->{
+            String jhTableName = "LTD_" + item.replace('-', '_').toUpperCase().trim();
+            wellDrillingSICPService.createTable(jhTableName,System.currentTimeMillis());
+        });
+    }
 
     /**
      * 更新采集井数据列表

+ 164 - 2
yujing-common/src/main/java/com/cn/tianji/service/impl/WellDrillingServiceImpl.java

@@ -3,14 +3,18 @@ package com.cn.tianji.service.impl;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.cn.tianji.entity.WellDrilling;
+import com.cn.tianji.entity.WellDrillingSICP;
 import com.cn.tianji.mapper.WellDrillingMapper;
 import com.cn.tianji.service.WellDrillingService;
-import org.apache.ibatis.annotations.Param;
+import com.cn.tianji.util.CommonUtil;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
-import java.util.Map;
 
 /**
  * @author Zhao RenJi
@@ -63,4 +67,162 @@ public class WellDrillingServiceImpl extends ServiceImpl<WellDrillingMapper, Wel
     public void createTable(String paramString, long paramLong){
        mapper.createTable(paramString,paramLong);
     };
+
+
+    @Override
+    public  List<WellDrilling> sicpToLtdData(List<WellDrillingSICP> sicpList) {
+        List<WellDrilling> saveList = new ArrayList<>();
+        sicpList.forEach(item -> {
+            WellDrilling model = sicpToLtd(item);
+            saveList.add(model);
+        });
+        saveList.sort(Comparator.comparing(WellDrilling::getTime));
+        return saveList ;
+    }
+
+    @Override
+    public WellDrilling sicpToLtd(WellDrillingSICP item) {
+        WellDrilling model = new WellDrilling();
+        model.setJh(item.getJh());
+        model.setTid(item.getTIME());
+        model.setTime(item.getTIME());
+        model.setId(BigDecimal.valueOf(-999.25));
+        try {
+            model.setDepth(CommonUtil.convertStringToBigDecimal(item.getDMEA()));
+            model.setVdepth(CommonUtil.convertStringToBigDecimal(item.getDVER()));
+            model.setLagtime(CommonUtil.convertStringToBigDecimal(item.getTRTT()));
+            model.setLagstrokes(CommonUtil.convertStringToBigDecimal(item.getLSTK()));
+            model.setBitdepth(CommonUtil.convertStringToBigDecimal(item.getDBTM()));
+            model.setKellyin(CommonUtil.convertStringToBigDecimal(item.getKELLYIN()));
+            model.setHkh(CommonUtil.convertStringToBigDecimal(item.getBPOS()));
+            model.setHks(CommonUtil.convertStringToBigDecimal(item.getBSPD()));
+            model.setWoh(CommonUtil.convertStringToBigDecimal(item.getHKLA()));
+            model.setRpm(CommonUtil.convertStringToBigDecimal(item.getRPMA()));
+
+            model.setWob(CommonUtil.convertStringToBigDecimal(item.getWOBA()));
+            BigDecimal tqa= CommonUtil.convertStringToBigDecimal(item.getTQA());
+            if(tqa.compareTo(BigDecimal.valueOf(0.0))>0){
+                model.setTorque(tqa);
+            }else{
+                model.setTorque(CommonUtil.convertStringToBigDecimal(item.getTTQA()));
+            }
+            model.setTdTorque(CommonUtil.convertStringToBigDecimal(item.getTTQA()));
+            model.setSpp(CommonUtil.convertStringToBigDecimal(item.getSPPA()));
+            model.setWhp(CommonUtil.convertStringToBigDecimal(item.getCHKP()));
+            model.setPump1(CommonUtil.convertStringToBigDecimal(item.getSPM1()));
+            model.setPump2(CommonUtil.convertStringToBigDecimal(item.getSPM2()));
+            model.setPump3(CommonUtil.convertStringToBigDecimal(item.getSPM3()));
+            model.setPumptotal(CommonUtil.convertStringToBigDecimal(item.getTSPM()));
+
+            model.setStrokes1(CommonUtil.convertStringToBigDecimal(item.getSTROKES1()));
+            model.setStrokes2(CommonUtil.convertStringToBigDecimal(item.getSTROKES2()));
+            model.setStrokes3(CommonUtil.convertStringToBigDecimal(item.getSTROKES3()));
+            model.setStrokestotal(CommonUtil.convertStringToBigDecimal(item.getSTKC()));
+            model.setVopInst(CommonUtil.convertStringToBigDecimal(item.getVOP_INST()));
+            model.setVopMavg(CommonUtil.convertStringToBigDecimal(item.getVOP_MAVG()));
+            model.setFlowin(CommonUtil.convertStringToBigDecimal(item.getMFIA()));
+            model.setFlowout(CommonUtil.convertStringToBigDecimal(item.getMFOA()));
+            model.setFlowoutpercent(CommonUtil.convertStringToBigDecimal(item.getMFOP()));
+            model.setMwin(CommonUtil.convertStringToBigDecimal(item.getMDIA()));
+
+            model.setMwout(CommonUtil.convertStringToBigDecimal(item.getMDOA()));
+            model.setTempin(CommonUtil.convertStringToBigDecimal(item.getMTIA()));
+            model.setTempout(CommonUtil.convertStringToBigDecimal(item.getMTOA()));
+            model.setCondin(CommonUtil.convertStringToBigDecimal(item.getMCOA()));
+            model.setCondout(CommonUtil.convertStringToBigDecimal(item.getMCIA()));
+            model.setPit1(CommonUtil.convertStringToBigDecimal(item.getTV01()));
+            model.setPit2(CommonUtil.convertStringToBigDecimal(item.getTV02()));
+            model.setPit3(CommonUtil.convertStringToBigDecimal(item.getTV03()));
+            model.setPit4(CommonUtil.convertStringToBigDecimal(item.getTV04()));
+            model.setPit5(CommonUtil.convertStringToBigDecimal(item.getTV05()));
+            model.setPit6(CommonUtil.convertStringToBigDecimal(item.getTV06()));
+            model.setPit7(CommonUtil.convertStringToBigDecimal(item.getTV07()));
+            model.setPit8(CommonUtil.convertStringToBigDecimal(item.getTV08()));
+            model.setPit9(CommonUtil.convertStringToBigDecimal(item.getTV09()));
+            model.setPit10(CommonUtil.convertStringToBigDecimal(item.getTV10()));
+            model.setPit11(CommonUtil.convertStringToBigDecimal(item.getTV11()));
+            model.setPit12(CommonUtil.convertStringToBigDecimal(item.getTV12()));
+            model.setPittotal(CommonUtil.convertStringToBigDecimal(item.getTVT()));
+
+            model.setC1(CommonUtil.convertStringToBigDecimal(item.getMETH()));
+            model.setC2(CommonUtil.convertStringToBigDecimal(item.getETH()));
+            model.setC3(CommonUtil.convertStringToBigDecimal(item.getPRP()));
+            model.setIc4(CommonUtil.convertStringToBigDecimal(item.getIBUT()));
+            model.setNc4(CommonUtil.convertStringToBigDecimal(item.getNBUT()));
+            model.setIc5(CommonUtil.convertStringToBigDecimal(item.getIPEN()));
+            model.setNc5(CommonUtil.convertStringToBigDecimal(item.getNPEN()));
+            model.setEc5(CommonUtil.convertStringToBigDecimal(item.getEPEN()));
+            model.setIc6(CommonUtil.convertStringToBigDecimal(item.getIHEX()));
+            model.setNc6(CommonUtil.convertStringToBigDecimal(item.getNHEX()));
+
+            model.setStat(BigDecimal.valueOf(-999.25));
+            model.setLagdepth(BigDecimal.valueOf(-999.25));
+            model.setBitoff(BigDecimal.valueOf(-999.25));
+            model.setWohCalc(BigDecimal.valueOf(-999.25));
+            model.setFloatWeight(BigDecimal.valueOf(-999.25));
+            model.setRopInst(BigDecimal.valueOf(-999.25));
+            model.setRopMavg(BigDecimal.valueOf(-999.25));
+            model.setEcd(BigDecimal.valueOf(-999.25));
+            model.setTriptandvol(BigDecimal.valueOf(-999.25));
+            model.setActpittotal(BigDecimal.valueOf(-999.25));
+            model.setGainlossvol(BigDecimal.valueOf(-999.25));
+            model.setTg(BigDecimal.valueOf(-999.25));
+            model.setCo2(BigDecimal.valueOf(-999.25));
+            model.setH2(BigDecimal.valueOf(-999.25));
+            model.setH2s1(BigDecimal.valueOf(-999.25));
+            model.setH2s2(BigDecimal.valueOf(-999.25));
+            model.setH2s3(BigDecimal.valueOf(-999.25));
+            model.setH2s4(BigDecimal.valueOf(-999.25));
+            model.setH2s5(BigDecimal.valueOf(-999.25));
+            model.setH2s6(BigDecimal.valueOf(-999.25));
+            model.setH2s7(BigDecimal.valueOf(-999.25));
+            model.setH2s8(BigDecimal.valueOf(-999.25));
+
+            model.setStringlen(BigDecimal.valueOf(-999.25));
+            model.setCurpipe(BigDecimal.valueOf(-999.25));
+            model.setBitno(BigDecimal.valueOf(-999.25));
+            model.setBitsize(BigDecimal.valueOf(-999.25));
+            model.setBittype(BigDecimal.valueOf(-999.25));
+            model.setBitrun(BigDecimal.valueOf(-999.25));
+            model.setBittime(BigDecimal.valueOf(-999.25));
+            model.setBitdrilltime(BigDecimal.valueOf(-999.25));
+            model.setBitcost(BigDecimal.valueOf(-999.25));
+            model.setTotaldays(BigDecimal.valueOf(-999.25));
+
+            model.setStandsdone(BigDecimal.valueOf(-999.25));
+            model.setStandstogo(BigDecimal.valueOf(-999.25));
+            model.setTripoverpull(BigDecimal.valueOf(-999.25));
+            model.setDc(BigDecimal.valueOf(-999.25));
+            model.setSigma(BigDecimal.valueOf(-999.25));
+            model.setFree95(BigDecimal.valueOf(-999.25));
+            model.setFree96(BigDecimal.valueOf(-999.25));
+            model.setFree97(BigDecimal.valueOf(-999.25));
+            model.setFree98(BigDecimal.valueOf(-999.25));
+            model.setFree99(BigDecimal.valueOf(-999.25));
+            model.setFree100(BigDecimal.valueOf(-999.25));
+            model.setFree101(BigDecimal.valueOf(-999.25));
+            model.setFree102(BigDecimal.valueOf(-999.25));
+            model.setFree103(BigDecimal.valueOf(-999.25));
+            model.setFree104(BigDecimal.valueOf(-999.25));
+            model.setFree105(BigDecimal.valueOf(-999.25));
+            model.setFree106(BigDecimal.valueOf(-999.25));
+            model.setFree107(BigDecimal.valueOf(-999.25));
+            model.setFree108(BigDecimal.valueOf(-999.25));
+            model.setFree109(BigDecimal.valueOf(-999.25));
+            model.setFree110(BigDecimal.valueOf(-999.25));
+            model.setFree111(BigDecimal.valueOf(-999.25));
+            model.setFree112(BigDecimal.valueOf(-999.25));
+            model.setFree113(BigDecimal.valueOf(-999.25));
+            model.setFree114(BigDecimal.valueOf(-999.25));
+            model.setFree115(BigDecimal.valueOf(-999.25));
+            model.setFree116(BigDecimal.valueOf(-999.25));
+            model.setFree117(BigDecimal.valueOf(-999.25));
+            model.setFree118(BigDecimal.valueOf(-999.25));
+            model.setFree119(BigDecimal.valueOf(-999.25));
+            model.setFree120(BigDecimal.valueOf(-999.25));
+        } catch (ParseException e) {
+            e.printStackTrace();
+        }
+        return model;
+    }
 }

+ 9 - 0
yujing-condition-identification/src/main/java/com/cn/tianji/controller/WorkingConditionCalculationController.java

@@ -2,6 +2,7 @@ package com.cn.tianji.controller;
 
 
 import com.cn.tianji.common.Result;
+import com.cn.tianji.service.DataSupplementationService;
 import com.cn.tianji.service.WorkingConditionCalculationService;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -16,10 +17,18 @@ public class WorkingConditionCalculationController {
     @Resource
     private WorkingConditionCalculationService workingConditionCalculationService;
 
+    @Resource
+    private DataSupplementationService dataSupplementationService;
+
     @GetMapping
     public Result<?> workingConditionCalculation(@RequestParam("workingConditionCalculationLogId") String workingConditionCalculationLogId){
        return workingConditionCalculationService.workingConditionCalculation(workingConditionCalculationLogId);
     }
 
+    @GetMapping("/sicpDataSupp")
+    public Result<?> sicpDataSupp(@RequestParam("jh") String jh,@RequestParam("statrTime")String statrTime,@RequestParam("endTime")String endTime){
+        dataSupplementationService.sicpDataSupp( jh,  statrTime,  endTime);
+        return Result.OK();
+    }
 
 }

+ 8 - 0
yujing-condition-identification/src/main/java/com/cn/tianji/service/DataSupplementationService.java

@@ -0,0 +1,8 @@
+package com.cn.tianji.service;
+
+import lombok.SneakyThrows;
+
+public interface DataSupplementationService {
+    @SneakyThrows
+    void sicpDataSupp(String jh, String statrTime, String endTime);
+}

+ 137 - 0
yujing-condition-identification/src/main/java/com/cn/tianji/service/Impl/DataSupplementationServiceImpl.java

@@ -0,0 +1,137 @@
+package com.cn.tianji.service.Impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.cn.tianji.dto.ConditionDeterminationDto;
+import com.cn.tianji.entity.OperatingConditionThreshold;
+import com.cn.tianji.entity.WellDrilling;
+import com.cn.tianji.entity.WellDrillingSICP;
+import com.cn.tianji.service.*;
+import lombok.SneakyThrows;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 数据补录逻辑层
+ *
+ */
+@Service
+@Slf4j
+public class DataSupplementationServiceImpl implements DataSupplementationService {
+
+
+    @Resource
+    private PullDataSICPService pullDataSICPService;
+
+    @Resource
+    private WellDrillingService wellDrillingService;
+
+    @Resource
+    private OperatingConditionThresholdService operatingConditionThresholdService;
+
+    @Resource
+    private ConditionIdentificationService conditionIdentificationService;
+
+    private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
+
+
+    @Override
+    @SneakyThrows
+    public void sicpDataSupp(String jh, String statrTime, String endTime){
+        String saveJh = "LTD_" + jh.replace('-', '_').toUpperCase().trim();
+        Date currentStartTime = sdf.parse(statrTime);
+        Date finalEndTime = sdf.parse(endTime);
+        QueryWrapper<OperatingConditionThreshold> operatingConditionThresholdQueryWrapper = new QueryWrapper<>();
+        operatingConditionThresholdQueryWrapper.lambda().eq(OperatingConditionThreshold::getJh, jh);
+        OperatingConditionThreshold operatingConditionThresholdModel = operatingConditionThresholdService.getOne(operatingConditionThresholdQueryWrapper);
+        boolean isEndPull = currentStartTime.before(finalEndTime);
+        while (isEndPull){
+            log.info("采集开始时间:{}",statrTime);
+            List<WellDrillingSICP> sicpWellDataByJhTime = pullDataSICPService.getSicpWellDataByJhTime(jh, statrTime);
+            log.info("数据长度:{}",sicpWellDataByJhTime.size());
+            if(!sicpWellDataByJhTime.isEmpty()) {
+                List<WellDrilling> saveList = wellDrillingService.sicpToLtdData(sicpWellDataByJhTime);
+//                log.info("数据:{}",saveList);
+                String time  = conditionDetermination(saveList, saveJh, jh, sdf.parse(statrTime), operatingConditionThresholdModel);
+                //log.info("最后一位数据:{}",saveList.get(saveList.size() - 1));
+                //String time = saveList.get(saveList.size() - 1).getTime();
+//                log.info("最后时间:{}",time);
+                Date parse = sdf.parse(time);
+                Calendar calendar = Calendar.getInstance();
+                calendar.setTime(parse);
+                calendar.add(Calendar.SECOND, 2);
+                Date lastTime = calendar.getTime();
+                statrTime=sdf.format(lastTime);
+                isEndPull = lastTime.before(finalEndTime);
+            }
+        }
+    }
+
+    public String conditionDetermination(List<WellDrilling> saveList,String tableName, String jh,Date startTime,OperatingConditionThreshold operatingConditionThresholdModel){
+        List<WellDrilling> startBeforData = getStartBeforData(tableName, startTime);
+        String time="";
+        for (int i = 0; i < saveList.size(); i++) {
+            List<WellDrilling> calList = new ArrayList<>();
+            List<WellDrilling> saveLists = new ArrayList<>();
+            WellDrilling wellDrilling = saveList.get(i);
+            log.info("识别点位数据时间:{}",wellDrilling.getTime());
+            if(i<2){
+                if(!startBeforData.isEmpty()){
+                    calList.add(startBeforData.get(startBeforData.size()-2));
+                    calList.add(startBeforData.get(startBeforData.size()-1));
+                    startBeforData.remove(0);
+                    startBeforData.add(wellDrilling);
+                }
+            }else{
+                WellDrilling wellDrillingOne = saveList.get(i-2);
+                WellDrilling wellDrillingTwo = saveList.get(i-1);
+                calList.add(wellDrillingOne);
+                calList.add(wellDrillingTwo);
+            }
+
+            calList.add(wellDrilling);
+            if(calList.size()>=3){
+//                log.info("识别的数据长度:{}",calList.size());
+//                log.info("识别数据:{}",calList.get(calList.size()-1));
+                ConditionDeterminationDto conditionDeterminationDto = conditionIdentificationService.conditionDetermination(calList, operatingConditionThresholdModel);
+                wellDrilling.setMotion(conditionDeterminationDto.getMotion());
+                wellDrilling.setOperatingMode(conditionDeterminationDto.getOperatingMode());
+                saveLists.add(wellDrilling);
+                wellDrillingService.insertTableBatch(tableName,saveLists);
+            }
+            time=wellDrilling.getTime();
+        }
+        log.info("识别结束最后的时间:{}",time);
+        return time;
+    }
+
+
+    /**
+     *
+     * 获取数据库中采集数据之前的数据
+     * @param tableName
+     * @param endTime
+     * @return
+     */
+    public  List<WellDrilling> getStartBeforData(String tableName, Date endTime){
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(endTime);
+        calendar.add(Calendar.MINUTE, -2);
+        Date startTime = calendar.getTime();
+        String startTimeString = sdf.format(startTime);
+        String endTimeString = sdf.format(endTime);
+        QueryWrapper<WellDrilling> wrapper = new QueryWrapper<>();
+        wrapper.apply("TO_DATE(SUBSTR(TIME, 1, 19), 'yyyy-MM-dd HH24:mi:ss') >= to_date({0},'yyyy-mm-dd hh24:mi:ss')", startTimeString);
+        wrapper.apply("TO_DATE(SUBSTR(TIME, 1, 19), 'yyyy-MM-dd HH24:mi:ss') <= to_date({0},'yyyy-mm-dd hh24:mi:ss')", endTimeString);
+        wrapper.lambda().orderByDesc(WellDrilling::getTime);
+        return wellDrillingService.selectListOrcale(tableName,wrapper);
+    }
+
+}

+ 0 - 4
yujing-condition-identification/src/main/resources/config/application-prod.yml

@@ -27,25 +27,21 @@ spring:
         connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
       datasource:
         master:
-          validationQuery: SELECT 1 FROM DUAL
           driver-class-name: oracle.jdbc.OracleDriver
           url: jdbc:oracle:thin:@//10.66.116.46:1521/JT_ZJ
           username: jtznyj
           password: jtznyj#2021
         chartDataSource:
-          validationQuery: SELECT 1 FROM DUAL
           driver-class-name: oracle.jdbc.OracleDriver
           url: jdbc:oracle:thin:@//10.66.116.46/jt
           username: jtgcyth2018
           password: Sljtyw_2018
         yjDataSource:
-          validationQuery: SELECT 1 FROM DUAL
           driver-class-name: oracle.jdbc.OracleDriver
           url: jdbc:oracle:thin:@//10.66.116.46:1521/JT_LJ
           username: tj_zjgc
           password: ZjgcTJ#zjgc@2024
         zjyDataSource:
-          validationQuery: SELECT 1 FROM DUAL
           driver-class-name: oracle.jdbc.OracleDriver
           url: jdbc:oracle:thin:@//10.66.116.46:1521/JT_ZJ
           username: zjycs

+ 5 - 9
yujing-hook-load-warning/src/main/resources/config/application-prod.yml

@@ -27,29 +27,25 @@ spring:
         connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
       datasource:
         master:
-          validationQuery: SELECT 1 FROM DUAL
           driver-class-name: oracle.jdbc.OracleDriver
           url: jdbc:oracle:thin:@//10.66.116.46:1521/JT_ZJ
           username: jtznyj
           password: jtznyj#2021
         chartDataSource:
-          validationQuery: SELECT 1 FROM DUAL
           driver-class-name: oracle.jdbc.OracleDriver
           url: jdbc:oracle:thin:@//10.66.116.46/jt
           username: jtgcyth2018
           password: Sljtyw_2018
         yjDataSource:
-          validationQuery: SELECT 1 FROM DUAL
           driver-class-name: oracle.jdbc.OracleDriver
           url: jdbc:oracle:thin:@//10.66.116.46:1521/JT_LJ
           username: tj_zjgc
           password: ZjgcTJ#zjgc@2024
-        zjyDataSource:
-          validationQuery: SELECT 1 FROM DUAL
-          driver-class-name: oracle.jdbc.OracleDriver
-          url: jdbc:oracle:thin:@//10.66.116.46:1521/JT_ZJ
-          username: zjycs
-          password: Zjy_2019
+#        zjyDataSource:
+#          driver-class-name: oracle.jdbc.OracleDriver
+#          url: jdbc:oracle:thin:@//10.66.116.46:1521/JT_ZJ
+#          username: zjycs
+#          password: Zjy_2019
 rocketmq:
   name-server: localhost:9876	 # 这里需要换成自己的 rocketMq 的地址
   consumer:

+ 2 - 0
yujing-pull/src/main/java/com/cn/tianji/service/PullSICPDataService.java

@@ -9,4 +9,6 @@ public interface PullSICPDataService {
     void updTableByJhs(List<String> jhs);
 
     void pullData(List<String> jhs);
+
+    void createTable(List<String> jhs);
 }

+ 1 - 1
yujing-pull/src/main/java/com/cn/tianji/service/impl/BizServiceImpl.java

@@ -822,7 +822,7 @@ public class BizServiceImpl implements BizService {
                 .collect(Collectors.toList());
         //更新创建井表
         this.createTable(jhList);
-        jhList.add("顺深2斜");
+        jhList.add("顺北806斜");
         //更新实时数据表
         yjRealTimeLogService.saveRealTimeLog(jhList);
         return jhJsonArray;

+ 56 - 15
yujing-pull/src/main/java/com/cn/tianji/service/impl/PullSICPDataServiceImpl.java

@@ -5,7 +5,6 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.cn.tianji.common.CommonUtils;
 import com.cn.tianji.common.RedisUtil;
-import com.cn.tianji.common.util.CaffeineCacheUtil;
 import com.cn.tianji.dto.ConditionDeterminationDto;
 import com.cn.tianji.entity.OperatingConditionThreshold;
 import com.cn.tianji.entity.WellDrilling;
@@ -16,7 +15,6 @@ import com.cn.tianji.util.CommonUtil;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
 
@@ -26,13 +24,9 @@ import java.math.BigDecimal;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.time.Duration;
-import java.time.LocalDate;
 import java.time.LocalDateTime;
-import java.time.LocalTime;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 @Service
@@ -177,7 +171,7 @@ public class PullSICPDataServiceImpl implements PullSICPDataService {
         String saveJh = "LTD_" + jh.replace('-', '_').toUpperCase().trim();
         log.info("采集井号:{};采集时间:{}",jh,time);
         List<WellDrillingSICP> sicpWellDataByJhTime = pullDataSICPService.getSicpWellDataByJhTime(jh, time);
-        //log.info("采集的数据:{}",sicpWellDataByJhTime);
+        log.info("数据长度:{}",sicpWellDataByJhTime.size());
         if(sicpWellDataByJhTime.size()>0){
         List<WellDrilling> saveList = sicpToLtdData(sicpWellDataByJhTime);
         conditionDetermination(saveList,saveJh,jh,time);
@@ -186,20 +180,32 @@ public class PullSICPDataServiceImpl implements PullSICPDataService {
 
     public void conditionDetermination(List<WellDrilling> saveList,String tableName, String jh,String startTime){
         List<WellDrilling> startBeforData = getStartBeforData(jh, startTime);
+        List<String> startBeforTime1 = startBeforData.stream().map(WellDrilling::getTime).collect(Collectors.toList());
+        log.info("首次缓存的数据:{}",startBeforTime1);
+        saveList.sort((a, b) -> a.getTime().compareTo(b.getTime()));
         for (int i=0;i<saveList.size();i++){
-            List<WellDrilling> conList=new ArrayList<>();
+//            List<WellDrilling> conList=new ArrayList<>();
             WellDrilling model = saveList.get(i);
-            conList=startBeforData;
-            conList.add(model);
-            startBeforData.remove(0);
+//            conList=startBeforData;
             startBeforData.add(model);
+            //log.info("参考数据:{}",startBeforData);
             OperatingConditionThreshold operatingConditionThreshold = getOperatingCatchByJh(jh);
-            ConditionDeterminationDto conditionDeterminationDto = conditionIdentificationService.conditionDetermination(conList, operatingConditionThreshold);
+            log.info("识别时间:{}",model.getTime());
+            List<String> collect = startBeforData.stream().map(WellDrilling::getTime).collect(Collectors.toList());
+            log.info("识别的数据:{}",collect);
+            ConditionDeterminationDto conditionDeterminationDto = conditionIdentificationService.conditionDetermination(startBeforData, operatingConditionThreshold);
             saveList.get(i).setOperatingMode(conditionDeterminationDto.getOperatingMode());
             saveList.get(i).setMotion(conditionDeterminationDto.getMotion());
             //log.info("识别的数据:{}",saveList.get(i));
             sendWellDrillingMessageService.sendMessage(conditionDeterminationDto.getMotion(),  saveList.get(i),  saveList.get(i).getJh());
+            startBeforData.remove(0);
+//            startBeforData.add(model);
+            List<String> startBeforTime = startBeforData.stream().map(WellDrilling::getTime).collect(Collectors.toList());
+            log.info("缓存的数据:{}",startBeforTime);
         }
+//        redisUtil.del(jh+"_beforData_condition");
+//        redisUtil.set(jh+"_beforData_condition",startBeforData);
+//        log.info("缓存数据:{}",startBeforData);
        // log.info("插入的数据:{}",saveList);
         String selectJh = "\"" + tableName + "\"";
         int i = wellDrillingService.insertTableBatch(selectJh, saveList);
@@ -256,7 +262,7 @@ public class PullSICPDataServiceImpl implements PullSICPDataService {
 
     @SneakyThrows
     public  List<WellDrilling> getStartBeforData(String jh, String startTime){
-        String redisKey=jh+"_condition";
+        String redisKey=jh+"_beforData_condition";
         boolean isHaveBeforData = redisUtil.hasKey(redisKey);
         List<WellDrilling> beforData=new ArrayList<>();
         if(isHaveBeforData){
@@ -270,16 +276,46 @@ public class PullSICPDataServiceImpl implements PullSICPDataService {
                 e.printStackTrace();
             }
         }else{
+            log.info("首次获取数据");
             Date parse = sdf.parse(startTime);
             Date specifiedTime = CommonUtils.getSpecifiedTime(parse, Calendar.MINUTE, -3);
             List<WellDrillingSICP> sicpWellDataByJhTime = pullDataSICPService.getSicpWellDataByJhTime(jh, sdf.format(specifiedTime));
             List<WellDrilling> startBeforData =  sicpToLtdData(sicpWellDataByJhTime);
-            beforData.add(startBeforData.get(startBeforData.size()-2));
-            beforData.add(startBeforData.get(startBeforData.size()-1));
+            List<WellDrilling> wellDrillings = filterData(startBeforData, parse);
+            List<String> startBeforTime = wellDrillings.stream().map(WellDrilling::getTime).collect(Collectors.toList());
+            log.info("筛选后的数据:{}",startBeforTime);
+            beforData.add(wellDrillings.get(wellDrillings.size()-3));
+            beforData.add(wellDrillings.get(wellDrillings.size()-2));
         }
+        log.info("beforData数据长度{}",beforData.size());
+       // log.info("最终的结果数据:{}",beforData);
        return beforData;
     }
 
+    public List<WellDrilling> filterData( List<WellDrilling> list,Date time){
+        List<WellDrilling> res=new ArrayList<>();
+        list.forEach(item->{
+            String timec = item.getTime();
+            timec= timec.contains(".") ? timec.substring(0, timec.indexOf(".")) : timec;
+            Date parse =new Date();
+            try {
+                 parse = sdf.parse(timec);
+            } catch (ParseException e) {
+                e.printStackTrace();
+            }
+            boolean before = time.before(parse);
+            if(!before){
+                res.add(item);
+            }
+        });
+       // log.info("筛选的结果数据:{}",res);
+
+        res.remove(res.size()-1);
+        res.sort((a, b) -> a.getTime().compareTo(b.getTime()));
+        res.forEach(items->log.info("时间:{}",items.getTime()));
+        return res;
+    }
+
     public  List<WellDrilling> sicpToLtdData(List<WellDrillingSICP> sicpList) {
         List<WellDrilling> saveList = new ArrayList<>();
         sicpList.forEach(item -> {
@@ -433,4 +469,9 @@ public class PullSICPDataServiceImpl implements PullSICPDataService {
         }
         return model;
     }
+
+    @Override
+    public void createTable(List<String> jhs){
+        pullDataSICPService.createTables(jhs);
+    }
 }

+ 5 - 3
yujing-pull/src/main/java/com/cn/tianji/task/PullDataTask.java

@@ -1,6 +1,7 @@
 package com.cn.tianji.task;
 
 import com.alibaba.fastjson.JSONArray;
+import com.cn.tianji.common.CommonUtils;
 import com.cn.tianji.service.BizService;
 import com.cn.tianji.service.YjRealTimeLogService;
 import lombok.extern.slf4j.Slf4j;
@@ -103,14 +104,15 @@ public class PullDataTask {
 
     @Scheduled(fixedDelay = 30,timeUnit = TimeUnit.SECONDS,initialDelay = 30L)
     public void pullRealTimeData(){
-        LocalDateTime startTime = LocalDateTime.now();
+        Date startTime = new Date();
         List<String> jhList = bizService.getJhList();
         log.info("缓存井列表数据:{}",jhList);
         if(jhList.size()>0){
             bizService.pullRealTimeData(jhList);
         }
-        LocalDateTime endTime = LocalDateTime.now();
-        log.info("采集井实时数据开始时间:{};结束时间:{}",startTime,endTime);
+        Date endTime = new Date();
+        long warnTimeDiff = CommonUtils.timeDifference_(startTime, endTime);
+        log.info("采集井实时数据开始时间:{};结束时间:{};耗时:{}毫秒",startTime,endTime,warnTimeDiff);
     }
 
     @Scheduled(fixedDelay = 30,timeUnit = TimeUnit.MINUTES,initialDelay = 30L)

+ 11 - 2
yujing-pull/src/main/java/com/cn/tianji/task/PullSICPDataTask.java

@@ -6,6 +6,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
+import javax.annotation.PostConstruct;
 import javax.annotation.Resource;
 import java.util.ArrayList;
 import java.util.List;
@@ -47,10 +48,18 @@ public class PullSICPDataTask {
 //        }
 //    }
 
-    @Scheduled(fixedDelay = 40,timeUnit = TimeUnit.SECONDS,initialDelay = 30L)
+//    @PostConstruct
+//    public void createTable(){
+//        List<String> jhs=new ArrayList<>();
+//        jhs.add("顺北806斜");
+//        pullSICPDataService.createTable(jhs);
+//    }
+
+
+//    @Scheduled(fixedDelay = 40,timeUnit = TimeUnit.SECONDS,initialDelay = 30L)
     public void pullDataTask(){
         List<String> jhs=new ArrayList<>();
-        jhs.add("顺深2斜");
+        jhs.add("顺北806斜");
         log.info("sicp数据采集任务执行");
         pullSICPDataService.pullData(jhs);
     }

+ 0 - 4
yujing-pull/src/main/resources/config/application-prod.yml

@@ -27,25 +27,21 @@ spring:
         connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
       datasource:
         master:
-          validationQuery: SELECT 1 FROM DUAL
           driver-class-name: oracle.jdbc.OracleDriver
           url: jdbc:oracle:thin:@//10.66.116.46:1521/JT_ZJ
           username: jtznyj
           password: jtznyj#2021
         chartDataSource:
-          validationQuery: SELECT 1 FROM DUAL
           driver-class-name: oracle.jdbc.OracleDriver
           url: jdbc:oracle:thin:@//10.66.116.46/jt
           username: jtgcyth2018
           password: Sljtyw_2018
         yjDataSource:
-          validationQuery: SELECT 1 FROM DUAL
           driver-class-name: oracle.jdbc.OracleDriver
           url: jdbc:oracle:thin:@//10.66.116.46:1521/JT_LJ
           username: tj_zjgc
           password: ZjgcTJ#zjgc@2024
         wlwmroDataSource:
-          validationQuery: SELECT 1 FROM DUAL
           driver-class-name: oracle.jdbc.OracleDriver
           url: jdbc:oracle:thin:@//10.66.116.46/JT_ZJ
           username: wlwmro

+ 3 - 3
yujing-pull/src/main/resources/config/application.yml

@@ -8,9 +8,9 @@ spring:
     name: yujing-pull
   mvc:
     static-path-pattern: /**
-    jackson:
-      time-zone: GMT+8
-      date-format: "yyyy-MM-dd HH:mm:ss"
+  jackson:
+    time-zone: GMT+8
+    date-format: "yyyy-MM-dd HH:mm:ss"
   redis:
     database: 0
     host: localhost

+ 8 - 12
yujing-pumping-pressure/src/main/resources/config/application-prod.yml

@@ -27,29 +27,25 @@ spring:
         connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
       datasource:
         master:
-          validationQuery: SELECT 1 FROM DUAL
           driver-class-name: oracle.jdbc.OracleDriver
-          url: jdbc:oracle:thin:@//10.66.116.46:1521/JT_ZJ
+          url: jdbc:oracle:thin:@//10.66.116.45:1521/JT_ZJ
           username: jtznyj
           password: jtznyj#2021
         chartDataSource:
-          validationQuery: SELECT 1 FROM DUAL
           driver-class-name: oracle.jdbc.OracleDriver
-          url: jdbc:oracle:thin:@//10.66.116.46/jt
+          url: jdbc:oracle:thin:@//10.66.116.45/jt
           username: jtgcyth2018
           password: Sljtyw_2018
         yjDataSource:
-          validationQuery: SELECT 1 FROM DUAL
           driver-class-name: oracle.jdbc.OracleDriver
-          url: jdbc:oracle:thin:@//10.66.116.46:1521/JT_LJ
+          url: jdbc:oracle:thin:@//10.66.116.45:1521/JT_LJ
           username: tj_zjgc
           password: ZjgcTJ#zjgc@2024
-        zjyDataSource:
-          validationQuery: SELECT 1 FROM DUAL
-          driver-class-name: oracle.jdbc.OracleDriver
-          url: jdbc:oracle:thin:@//10.66.116.46:1521/JT_ZJ
-          username: zjycs
-          password: Zjy_2019
+#        zjyDataSource:
+#          driver-class-name: oracle.jdbc.OracleDriver
+#          url: jdbc:oracle:thin:@//10.66.116.45:1521/JT_ZJ
+#          username: zjycs
+#          password: Zjy_2019
 rocketmq:
   name-server: localhost:9876	 # 这里需要换成自己的 rocketMq 的地址
   consumer:

+ 8 - 12
yujing-torque/src/main/resources/config/application-prod.yml

@@ -27,29 +27,25 @@ spring:
         connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
       datasource:
         master:
-          validationQuery: SELECT 1 FROM DUAL
           driver-class-name: oracle.jdbc.OracleDriver
-          url: jdbc:oracle:thin:@//10.66.116.46:1521/JT_ZJ
+          url: jdbc:oracle:thin:@//10.66.116.45:1521/JT_ZJ
           username: jtznyj
           password: jtznyj#2021
         chartDataSource:
-          validationQuery: SELECT 1 FROM DUAL
           driver-class-name: oracle.jdbc.OracleDriver
-          url: jdbc:oracle:thin:@//10.66.116.46/jt
+          url: jdbc:oracle:thin:@//10.66.116.45/jt
           username: jtgcyth2018
           password: Sljtyw_2018
         yjDataSource:
-          validationQuery: SELECT 1 FROM DUAL
           driver-class-name: oracle.jdbc.OracleDriver
-          url: jdbc:oracle:thin:@//10.66.116.46:1521/JT_LJ
+          url: jdbc:oracle:thin:@//10.66.116.45:1521/JT_LJ
           username: tj_zjgc
           password: ZjgcTJ#zjgc@2024
-        zjyDataSource:
-          validationQuery: SELECT 1 FROM DUAL
-          driver-class-name: oracle.jdbc.OracleDriver
-          url: jdbc:oracle:thin:@//10.66.116.46:1521/JT_ZJ
-          username: zjycs
-          password: Zjy_2019
+#        zjyDataSource:
+#          driver-class-name: oracle.jdbc.OracleDriver
+#          url: jdbc:oracle:thin:@//10.66.116.45:1521/JT_ZJ
+#          username: zjycs
+#          password: Zjy_2019
 rocketmq:
   name-server: localhost:9876	 # 这里需要换成自己的 rocketMq 的地址
   consumer:

+ 1 - 0
yujing-total-pool-volume/pom.xml

@@ -44,6 +44,7 @@
                         </goals>
                         <configuration>
                             <attach>false</attach>
+
                         </configuration>
                     </execution>
                 </executions>

+ 24 - 29
yujing-total-pool-volume/src/main/resources/config/application-prod.yml

@@ -4,52 +4,47 @@ spring:
       primary: master
       druid: # 全局druid参数,绝大部分值和默认保持一致。(现已支持的参数如下,不清楚含义不要乱设置)
         # 连接池的配置信息
-        # 初始化大小,最小,最大
+        # 基础连接池参数
+        # 基础配置
         initial-size: 5
-        min-idle: 5
-        maxActive: 20
-        # 配置获取连接等待超时的时间
-        maxWait: 60000
-        # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
-        timeBetweenEvictionRunsMillis: 60000
-        # 配置一个连接在池中最小生存的时间,单位是毫秒
-        minEvictableIdleTimeMillis: 300000
-        validationQuery: SELECT 1 FROM DUAL
-        testWhileIdle: true
-        testOnBorrow: false
-        testOnReturn: false
-        # 打开PSCache,并且指定每个连接上PSCache的大小
-        poolPreparedStatements: true
-        maxPoolPreparedStatementPerConnectionSize: 20
-        # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
-        filters: stat,wall,slf4j
-        # 通过connectProperties属性来打开mergeSql功能;慢SQL记录
-        connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000
+        min-idle: 10
+        max-active: 50
+        max-wait: 60000  # 获取连接超时时间(毫秒)
+
+        # 连接有效性检查配置
+        validation-query: SELECT 1 FROM DUAL  # Oracle 验证查询
+        test-on-borrow: true      # 借出连接时校验
+        test-on-return: false     # 归还连接时不校验
+        test-while-idle: true     # 空闲时定期校验
+        time-between-eviction-runs-millis: 60000  # 空闲检查间隔(毫秒)
+        min-evictable-idle-time-millis: 300000    # 最小空闲时间(小于数据库超时)
+        max-evictable-idle-time-millis: 600000    # 最大空闲时间(小于数据库超时)
+
+        # 连接泄漏检测
+        remove-abandoned: true            # 启用泄漏回收
+        remove-abandoned-timeout: 180     # 泄漏连接存活阈值(秒)
+        log-abandoned: true               # 记录泄漏日志
       datasource:
         master:
-          validationQuery: SELECT 1 FROM DUAL
           driver-class-name: oracle.jdbc.OracleDriver
           url: jdbc:oracle:thin:@//10.66.116.46:1521/JT_ZJ
           username: jtznyj
           password: jtznyj#2021
         chartDataSource:
-          validationQuery: SELECT 1 FROM DUAL
           driver-class-name: oracle.jdbc.OracleDriver
           url: jdbc:oracle:thin:@//10.66.116.46/jt
           username: jtgcyth2018
           password: Sljtyw_2018
         yjDataSource:
-          validationQuery: SELECT 1 FROM DUAL
           driver-class-name: oracle.jdbc.OracleDriver
           url: jdbc:oracle:thin:@//10.66.116.46:1521/JT_LJ
           username: tj_zjgc
           password: ZjgcTJ#zjgc@2024
-        zjyDataSource:
-          validationQuery: SELECT 1 FROM DUAL
-          driver-class-name: oracle.jdbc.OracleDriver
-          url: jdbc:oracle:thin:@//10.66.116.46:1521/JT_ZJ
-          username: zjycs
-          password: Zjy_2019
+#        zjyDataSource:
+#          driver-class-name: oracle.jdbc.OracleDriver
+#          url: jdbc:oracle:thin:@//10.66.116.46:1521/JT_ZJ
+#          username: zjycs
+#          password: Zjy_2019
 rocketmq:
   name-server: localhost:9876	 # 这里需要换成自己的 rocketMq 的地址
   consumer:

+ 0 - 0
yujing-total-pool-volume/warn-logs/error/total-pool-volume-error-2024-08-07.0.log


+ 6 - 0
yujing-warning-calculation/pom.xml

@@ -17,6 +17,12 @@
             <artifactId>yujing-common</artifactId>
             <version>0.0.1-SNAPSHOT</version>
         </dependency>
+        <dependency>
+            <groupId>org.jetbrains</groupId>
+            <artifactId>annotations</artifactId>
+            <version>13.0</version>
+            <scope>compile</scope>
+        </dependency>
     </dependencies>
 
     <properties>

+ 7 - 6
yujing-warning-calculation/src/main/java/com/cn/tianji/common/DrillingOutHookLoadCatch.java

@@ -1,5 +1,6 @@
 package com.cn.tianji.common;
 
+import com.cn.tianji.entity.HookLoadCatch;
 import com.cn.tianji.entity.WellDrilling;
 import lombok.Data;
 
@@ -32,12 +33,12 @@ public class DrillingOutHookLoadCatch implements Serializable {
     /**
      * 当前柱缓存数据
      */
-    private List<WellDrilling> nowColumnData;
+    private List<HookLoadCatch> nowColumnData;
 
     /**
      * 上一柱缓存数据
      */
-    private List<WellDrilling> perColumnData;
+    private List<HookLoadCatch> perColumnData;
 
     /**
      * 报警参考值:由上一柱数据计算得到
@@ -67,12 +68,12 @@ public class DrillingOutHookLoadCatch implements Serializable {
     /**
      * 活动钻具预警缓存数据
      */
-    private List<WellDrilling> mobileDrillingToolsData;
+    private List<HookLoadCatch> mobileDrillingToolsData;
 
     /**
      * 活动钻具参考数据
      */
-    private List<WellDrilling> referenceMobileDrillingToolsData;
+    private List<HookLoadCatch> referenceMobileDrillingToolsData;
 
     /**
      * 是否已判断工况
@@ -87,10 +88,10 @@ public class DrillingOutHookLoadCatch implements Serializable {
     /**
      * 活动钻具参考柱起点数据
      */
-    private WellDrilling referenceMobileDrillingToolsStartData;
+    private HookLoadCatch referenceMobileDrillingToolsStartData;
 
     /**
      * 活动钻具预警起点数据
      */
-    private WellDrilling mobileDrillingToolsStartData;
+    private HookLoadCatch mobileDrillingToolsStartData;
 }

+ 4 - 3
yujing-warning-calculation/src/main/java/com/cn/tianji/common/PittotalCache.java

@@ -1,5 +1,6 @@
 package com.cn.tianji.common;
 
+import com.cn.tianji.entity.TotalPoolVolumeCatch;
 import com.cn.tianji.entity.TotalPoolVolumeWarnLog;
 import com.cn.tianji.entity.WarnHistory;
 import com.cn.tianji.entity.WellDrilling;
@@ -41,12 +42,12 @@ public class PittotalCache implements Serializable {
     /**
      * 速率参考值缓存数据
      */
-    private List<WellDrilling> rateData;
+    private List<TotalPoolVolumeCatch> rateData;
 
     /**
      * 参考值缓存数据
      */
-    private List<WellDrilling> referenceData;
+    private List<TotalPoolVolumeCatch> referenceData;
     /**
      *参考值
      */
@@ -55,7 +56,7 @@ public class PittotalCache implements Serializable {
 
     private Date lastWarnDate;
 
-    private List<WarnHistory> warnListOld;
+    private List<TotalPoolVolumeCatch> warnListOld;
 
     /**
      * 预警缓存数据

+ 47 - 0
yujing-warning-calculation/src/main/java/com/cn/tianji/entity/HookLoadCatch.java

@@ -0,0 +1,47 @@
+package com.cn.tianji.entity;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+@Data
+public class HookLoadCatch implements Serializable {
+
+    private String jh;
+
+    private String tid;
+
+    private String time;
+
+    /**
+     *大钩负荷
+     */
+    private BigDecimal woh;
+
+    /**
+     *大钩高度
+     */
+    private BigDecimal hkh;
+
+    /**
+     *钻头位置
+     */
+    private BigDecimal bitdepth;
+
+    /**
+     *井深
+     */
+    private BigDecimal depth;
+
+
+    /**
+     * 工况
+     */
+    private String operatingMode;
+
+    /**
+     * 动作
+     */
+    private String motion;
+}

+ 19 - 0
yujing-warning-calculation/src/main/java/com/cn/tianji/entity/TotalPoolVolumeCatch.java

@@ -0,0 +1,19 @@
+package com.cn.tianji.entity;
+
+import com.baomidou.mybatisplus.annotation.TableId;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+@Data
+public class TotalPoolVolumeCatch implements Serializable {
+
+    private String jh;
+
+    private String tid;
+
+    private String time;
+
+    private BigDecimal pittotal;
+}

+ 11 - 2
yujing-warning-calculation/src/main/java/com/cn/tianji/service/impl/ConditionDeterminationServiceImpl.java

@@ -59,11 +59,20 @@ public class ConditionDeterminationServiceImpl  implements ConditionDeterminatio
      */
     @Override
     public Boolean isFarBottom(List<BigDecimal> bitDepthList,List<BigDecimal> depthList,BigDecimal threshold){
-        BigDecimal depthSum = depthList.stream().reduce(BigDecimal.ZERO, BigDecimal::add);
+
+        if(bitDepthList.size()==0){
+            log.info("钻头位置数据长度为0");
+           return true;
+        }
+        if(bitDepthList.size()==0){
+            log.info("井深数组长度为0");
+            return true;
+        }
         BigDecimal bitDepthSum = bitDepthList.stream().reduce(BigDecimal.ZERO,BigDecimal::add);
+        BigDecimal depthSum = depthList.stream().reduce(BigDecimal.ZERO, BigDecimal::add);
         BigDecimal depthSubtract = depthSum.subtract(bitDepthSum);
         BigDecimal averageBitDepth= depthSubtract.divide(BigDecimal.valueOf(bitDepthList.size()),2, RoundingMode.HALF_UP);
-        log.info("是否离开井底:井深均值{};阈值:{}",averageBitDepth,threshold);
+//        log.info("是否离开井底:井深均值{};阈值:{}",averageBitDepth,threshold);
         int thresholdCom = averageBitDepth.compareTo(threshold);
         return thresholdCom>0;
     }

+ 54 - 42
yujing-warning-calculation/src/main/java/com/cn/tianji/service/impl/ConditionIdentificationServiceImpl.java

@@ -25,6 +25,7 @@ import java.util.stream.Collectors;
 
 /**
  * 工况识别
+ *
  * @author Zhao RenJi
  */
 @Service
@@ -40,65 +41,76 @@ public class ConditionIdentificationServiceImpl implements ConditionIdentificati
     private DrillingConditionDeterminationService drillingConditionDeterminationService;
 
 
-    CommonUtils commonUtils=new CommonUtils();
+    CommonUtils commonUtils = new CommonUtils();
     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
     @Override
-    public ConditionDeterminationDto conditionDetermination(List<WellDrilling> wellDrillingLists, OperatingConditionThreshold operatingConditionThreshold){
-        ConditionDeterminationDto model= new ConditionDeterminationDto();
+    public ConditionDeterminationDto conditionDetermination(List<WellDrilling> wellDrillingLists, OperatingConditionThreshold operatingConditionThreshold) {
+        ConditionDeterminationDto model = new ConditionDeterminationDto();
+
         //log.info("排序前的数据:{}",wellDrillingLists);
-        List<WellDrilling> wellDrillingList=listReorder(wellDrillingLists);
-        //log.info("排序后的数据:{}",wellDrillingList);
-        String action="未识别动作";
-        WellDrilling nowPoint=wellDrillingList.get(wellDrillingList.size()-1);
-        WellDrilling perPoint=wellDrillingList.get(0);
-       // log.info("工况识别开始:井号:{};识别点位时间:{};参考点位时间:{}",nowPoint.getJh(),nowPoint.getTime(),perPoint.getTime());
+        List<WellDrilling> wellDrillingList = listReorder(wellDrillingLists);
+//        log.info("排序后的数据长度:{}",wellDrillingList);
+        String action = "未识别动作";
+        WellDrilling nowPoint = wellDrillingList.get(wellDrillingList.size() - 1);
+        WellDrilling perPoint = wellDrillingList.get(0);
+        // log.info("工况识别开始:井号:{};识别点位时间:{};参考点位时间:{}",nowPoint.getJh(),nowPoint.getTime(),perPoint.getTime());
         nowPoint.setTime(CommonUtils.removeMilliseconds(nowPoint.getTime()));
         perPoint.setTime(CommonUtils.removeMilliseconds(perPoint.getTime()));
-        long timeSub = 0;
-        try {
-            timeSub = commonUtils.timeDifference(sdf.parse(perPoint.getTime()),sdf.parse(nowPoint.getTime()));
-        } catch (ParseException e) {
-            e.printStackTrace();
-        }
-        BigDecimal timeSubBig = BigDecimal.valueOf(timeSub);
-        List<BigDecimal> bitDepthList = wellDrillingList.stream().map(WellDrilling::getBitdepth).collect(Collectors.toList());
-        List<BigDecimal> depthList = wellDrillingList.stream().map(WellDrilling::getDepth).collect(Collectors.toList());
-        //离开井底阈值
-        BigDecimal farBottomThresholdBig=operatingConditionThreshold.getFarBottom();
-        //是否离开井底
-        Boolean isFarBottom = conditionDeterminationService.isFarBottom(bitDepthList,depthList, farBottomThresholdBig);
-        String workStatus="起下钻";
-
-        if(isFarBottom){
-            //起下钻工况
-            action= trippingConditionDeterminationService.trippingConditionDetermination(wellDrillingList,timeSubBig,operatingConditionThreshold);
-            workStatus="起下钻";
-        }else{
-            //钻进工况
-            action= drillingConditionDeterminationService.drillingConditionDetermination(nowPoint,perPoint,timeSubBig,operatingConditionThreshold);
-            workStatus="钻进";
-        }
         model.setJh(nowPoint.getJh());
         model.setTime(nowPoint.getTime());
-        model.setOperatingMode(workStatus);
-        model.setMotion(action);
-        log.info("工况识别结束:井号:{},当前点工况:{},当前点动作:{},当前点时间:{},参考点位时间:{}",nowPoint.getJh(),workStatus,action,nowPoint.getTime(),perPoint.getTime());
+        try {
+            long timeSub = 0;
+            try {
+                timeSub = commonUtils.timeDifference(sdf.parse(perPoint.getTime()), sdf.parse(nowPoint.getTime()));
+            } catch (ParseException e) {
+                e.printStackTrace();
+            }
+            BigDecimal timeSubBig = BigDecimal.valueOf(timeSub);
+            List<BigDecimal> bitDepthList = wellDrillingList.stream().map(WellDrilling::getBitdepth).collect(Collectors.toList());
+            List<BigDecimal> depthList = wellDrillingList.stream().map(WellDrilling::getDepth).collect(Collectors.toList());
+            //离开井底阈值
+            BigDecimal farBottomThresholdBig = operatingConditionThreshold.getFarBottom();
+            //是否离开井底
+            Boolean isFarBottom = conditionDeterminationService.isFarBottom(bitDepthList, depthList, farBottomThresholdBig);
+            String workStatus = "起下钻";
+
+            if (isFarBottom) {
+                //起下钻工况
+                action = trippingConditionDeterminationService.trippingConditionDetermination(wellDrillingList, timeSubBig, operatingConditionThreshold);
+                workStatus = "起下钻";
+            } else {
+                //钻进工况
+                action = drillingConditionDeterminationService.drillingConditionDetermination(nowPoint, perPoint, timeSubBig, operatingConditionThreshold);
+                workStatus = "钻进";
+            }
+
+            model.setOperatingMode(workStatus);
+            model.setMotion(action);
+            log.info("工况识别结束:井号:{},当前点工况:{},当前点动作:{},当前点时间:{},参考点位时间:{}", nowPoint.getJh(), workStatus, action, nowPoint.getTime(), perPoint.getTime());
+
+        } catch (Exception e) {
+            log.info("工况识别异常:{}", e);
+            model.setOperatingMode("未识别工况");
+            model.setMotion("未识别动作");
+        }
         return model;
     }
 
     /**
      * 对数组倒序排序
+     *
      * @param list
      * @return
      */
-    public List<WellDrilling> listReorder(List<WellDrilling> list){
+    public List<WellDrilling> listReorder(List<WellDrilling> list) {
         // 使用Stream API进行排序
 //        List<WellDrilling> sortedEntities = list.stream()
 //                .sorted(Comparator.comparing(WellDrilling::getTime))
 //                .collect(Collectors.toList());
         // 使用Comparator.comparing根据time属性进行倒序排序
 
-      //  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+        //  SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
 
 //        list.forEach(item->{
 //            log.info("排序前数据:井号{};时间{}",item.getJh(),item.getTime());
@@ -106,7 +118,7 @@ public class ConditionIdentificationServiceImpl implements ConditionIdentificati
         //正序
         list.sort((a, b) -> a.getTime().compareTo(b.getTime()));
         //倒序
-       // list.sort((a, b) -> b.getTime().compareTo(a.getTime()));
+        // list.sort((a, b) -> b.getTime().compareTo(a.getTime()));
 //        Comparator<WellDrilling> dateTimeComparator  = Comparator.comparing(WellDrilling::getTime, (t1, t2) -> {
 //            Date d1 = null;
 //            Date d2 = null;
@@ -123,8 +135,8 @@ public class ConditionIdentificationServiceImpl implements ConditionIdentificati
 //        list.forEach(item->{
 //            log.info("排序后数据:井号{};时间{}",item.getJh(),item.getTime());
 //        });
-         return list;
-        }
+        return list;
+    }
 
 
-    }
+}

+ 64 - 48
yujing-warning-calculation/src/main/java/com/cn/tianji/service/impl/DrillingOutHookLoadServiceImpl.java

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.cn.tianji.common.CommonUtils;
 import com.cn.tianji.common.DrillingOutHookLoadCatch;
 import com.cn.tianji.common.RedisUtil;
+import com.cn.tianji.entity.HookLoadCatch;
 import com.cn.tianji.entity.HookLoadWarnLog;
 import com.cn.tianji.entity.WarnHistory;
 import com.cn.tianji.entity.WellDrilling;
@@ -68,7 +69,7 @@ public class DrillingOutHookLoadServiceImpl implements DrillingOutHookLoadServic
     public void hookLoadWarnCalculate(WellDrilling nowPoint, String redisHasKey, BigDecimal warnValue, BigDecimal rodWeight,
                                       BigDecimal activityOne,BigDecimal activityTwo) {
         Date startTime = new Date();
-
+        HookLoadCatch point = createPoint(nowPoint);
         //1.判断当前点工况
         //2.如果是上提下方钻具,则获取当前井是否由上一柱缓存数据
         //3.如果没有则记录当前点
@@ -87,7 +88,7 @@ public class DrillingOutHookLoadServiceImpl implements DrillingOutHookLoadServic
         if (isWarnAction) {
             if (isHave) {
                 //判断缓存数据是否超过当前数据30分钟
-                boolean b = determineCachedDataTimeDiff(redisHasKey, nowPoint);
+                boolean b = determineCachedDataTimeDiff(redisHasKey, point);
                 if (b) {
                     redisUtil.del(redisHasKey);
                 } else {
@@ -98,8 +99,8 @@ public class DrillingOutHookLoadServiceImpl implements DrillingOutHookLoadServic
                 DrillingOutHookLoadCatch hookLoadCatch = new DrillingOutHookLoadCatch();
                 hookLoadCatch.setJh(jh);
                 hookLoadCatch.setRecordingSteps(1);
-                List<WellDrilling> columnList = new ArrayList<>();
-                columnList.add(nowPoint);
+                List<HookLoadCatch> columnList = new ArrayList<>();
+                columnList.add(point);
                 hookLoadCatch.setPerColumnData(columnList);
                 hookLoadCatch.setMobileDrillingToolsStep(0);
                 hookLoadCatch.setIsMobileDrillingTools(false);
@@ -129,17 +130,18 @@ public class DrillingOutHookLoadServiceImpl implements DrillingOutHookLoadServic
      */
     public void warnCalculation(String redisHasKey, WellDrilling nowPoint, BigDecimal rodWeight,
                                 BigDecimal warnValue,BigDecimal activityOne,BigDecimal activityTwo) {
+        HookLoadCatch point = createPoint(nowPoint);
         DrillingOutHookLoadCatch hookLoadCatch = JSONObject.toJavaObject(JSONObject.parseObject(JSON.toJSONString(redisUtil.get(redisHasKey))), DrillingOutHookLoadCatch.class);
         Integer recordingSteps = hookLoadCatch.getRecordingSteps();
         if (recordingSteps == 1) {
-            List<WellDrilling> perColumnData = hookLoadCatch.getPerColumnData();
-            List<WellDrilling> nowColumnData = hookLoadCatch.getNowColumnData();
-            perColumnData.add(nowPoint);
-            nowColumnData.add(nowPoint);
+            List<HookLoadCatch> perColumnData = hookLoadCatch.getPerColumnData();
+            List<HookLoadCatch> nowColumnData = hookLoadCatch.getNowColumnData();
+            perColumnData.add(point);
+            nowColumnData.add(point);
             hookLoadCatch.setPerColumnData(perColumnData);
             hookLoadCatch.setNowColumnData(nowColumnData);
         } else if (recordingSteps == 2) {
-            List<WellDrilling> nowColumnData = hookLoadCatch.getNowColumnData();
+            List<HookLoadCatch> nowColumnData = hookLoadCatch.getNowColumnData();
             if (nowColumnData == null) {
                 nowColumnData = new ArrayList<>();
             }
@@ -147,7 +149,7 @@ public class DrillingOutHookLoadServiceImpl implements DrillingOutHookLoadServic
             nowColumnData = hookLoadCatch.getNowColumnData();
             //当前点是否预警点
             if (!hookLoadCatch.getIsWarnNowPoint()) {
-                nowColumnData.add(nowPoint);
+                nowColumnData.add(point);
             };
             hookLoadCatch.setNowColumnData(nowColumnData);
             hookLoadCatch.setIfDetermineWorkingConditions(false);
@@ -163,11 +165,11 @@ public class DrillingOutHookLoadServiceImpl implements DrillingOutHookLoadServic
      * @param nowPoint
      */
     @SneakyThrows
-    public boolean determineCachedDataTimeDiff(String redisHasKey, WellDrilling nowPoint) {
+    public boolean determineCachedDataTimeDiff(String redisHasKey, HookLoadCatch nowPoint) {
         DrillingOutHookLoadCatch hookLoadCatch = JSONObject.toJavaObject(JSONObject.parseObject(JSON.toJSONString(redisUtil.get(redisHasKey))), DrillingOutHookLoadCatch.class);
-        List<WellDrilling> perColumnData = hookLoadCatch.getPerColumnData();
+        List<HookLoadCatch> perColumnData = hookLoadCatch.getPerColumnData();
         if(perColumnData.size()>0){
-            WellDrilling catchData = perColumnData.get(perColumnData.size() - 1);
+            HookLoadCatch catchData = perColumnData.get(perColumnData.size() - 1);
             String nowPointtime = nowPoint.getTime();
             String catchDatatime = catchData.getTime();
             long l = CommonUtils.timeDifference(sdf.parse(nowPointtime), sdf.parse(catchDatatime));
@@ -192,8 +194,8 @@ public class DrillingOutHookLoadServiceImpl implements DrillingOutHookLoadServic
             DrillingOutHookLoadCatch hookLoadCatch = JSONObject.toJavaObject(JSONObject.parseObject(JSON.toJSONString(redisUtil.get(redisHasKey))), DrillingOutHookLoadCatch.class);
             if (!hookLoadCatch.getIfDetermineWorkingConditions()) {
                 Integer recordingSteps = hookLoadCatch.getRecordingSteps();
-                List<WellDrilling> perColumnData = hookLoadCatch.getPerColumnData();
-                List<BigDecimal> collect = perColumnData.stream().map(WellDrilling::getHkh).collect(Collectors.toList());
+                List<HookLoadCatch> perColumnData = hookLoadCatch.getPerColumnData();
+                List<BigDecimal> collect = perColumnData.stream().map(HookLoadCatch::getHkh).collect(Collectors.toList());
                 Optional<BigDecimal> maxHkh = collect.stream().max(BigDecimal::compareTo);
                 //上一柱大钩最后的位置
                 BigDecimal maxHkhBigDecimal = BigDecimal.ZERO;
@@ -218,7 +220,7 @@ public class DrillingOutHookLoadServiceImpl implements DrillingOutHookLoadServic
                         hookLoadCatch.setNowColumnData(new ArrayList<>());
                     } else {
                         //如果不是初次记录则将当前记录数据放入上一柱记录数据,清空当前柱记录数据
-                        List<WellDrilling> perColumnData1 = hookLoadCatch.getPerColumnData();
+                        List<HookLoadCatch> perColumnData1 = hookLoadCatch.getPerColumnData();
                         perColumnData1 = hookLoadCatch.getNowColumnData();
                         hookLoadCatch.setPerColumnData(perColumnData1);
                         hookLoadCatch.setNowColumnData(new ArrayList<>());
@@ -229,7 +231,7 @@ public class DrillingOutHookLoadServiceImpl implements DrillingOutHookLoadServic
                         //判断一柱工况
                         String workingCondition = determineWorkingConditions(hookLoadCatch.getPerColumnData());
                         //移除记录柱不在当前工况中的动作数据
-                        List<WellDrilling> wellDrillings = removeNonOperatingConditionAction(hookLoadCatch.getPerColumnData(), workingCondition);
+                        List<HookLoadCatch> wellDrillings = removeNonOperatingConditionAction(hookLoadCatch.getPerColumnData(), workingCondition);
                         hookLoadCatch.setPerColumnData(wellDrillings);
                         //计算上一柱钩载参考值
                         BigDecimal wohMaximum = getWohMaximum(hookLoadCatch.getPerColumnData(), workingCondition);
@@ -267,8 +269,8 @@ public class DrillingOutHookLoadServiceImpl implements DrillingOutHookLoadServic
      * @param list             已记录柱数据
      * @param workingCondition 工况
      */
-    public List<WellDrilling> removeNonOperatingConditionAction(List<WellDrilling> list, String workingCondition) {
-        List<WellDrilling> resList = new ArrayList<>();
+    public List<HookLoadCatch> removeNonOperatingConditionAction(List<HookLoadCatch> list, String workingCondition) {
+        List<HookLoadCatch> resList = new ArrayList<>();
         //根据工况保留工况下的动作数据
         if (workingCondition.equals(WorkingConditionEnum.TripOut.getValue())) {
             //起钻筛选起钻动作数据
@@ -325,8 +327,8 @@ public class DrillingOutHookLoadServiceImpl implements DrillingOutHookLoadServic
                 if (res >= 0) {
                     log.info("当前点为预警点:时间:{};钩载:{}", nowPoint.getTime(), nowPoint.getWoh());
                     hookLoadCatch.setIsWarnNowPoint(true);
-                    List<WellDrilling> perColumnData = hookLoadCatch.getNowColumnData();
-                    List<BigDecimal> wohList = perColumnData.stream().map(WellDrilling::getWoh).collect(Collectors.toList());
+                    List<HookLoadCatch> perColumnData = hookLoadCatch.getNowColumnData();
+                    List<BigDecimal> wohList = perColumnData.stream().map(HookLoadCatch::getWoh).collect(Collectors.toList());
                     BigDecimal minReferenceWoh = wohList.stream().min(BigDecimal::compareTo).get();
                     BigDecimal maxReferenceWoh = wohList.stream().max(BigDecimal::compareTo).get();
                     hookLoadWarnLogService.saveHookLoadWarnLog(nowPoint, nowPoint.getOperatingMode(), workingCondition, nowPoint.getMotion(), perColumnData.get(0).getTime(), perColumnData.get(perColumnData.size() - 1).getTime(),
@@ -343,12 +345,12 @@ public class DrillingOutHookLoadServiceImpl implements DrillingOutHookLoadServic
                 res = alarmReferenceSubtract.compareTo(warnValue);
                 if (res >= 0) {
                     log.info("当前点为预警点:时间:{};钩载:{}", nowPoint.getTime(), nowPoint.getWoh());
-                    List<WellDrilling> nowColumnData = hookLoadCatch.getNowColumnData();
-                    List<WellDrilling> perColumnData = hookLoadCatch.getPerColumnData();
+                    List<HookLoadCatch> nowColumnData = hookLoadCatch.getNowColumnData();
+                    List<HookLoadCatch> perColumnData = hookLoadCatch.getPerColumnData();
                     BigDecimal nowHkh = nowPoint.getHkh();
                     if(nowColumnData.size()>0){
                         //WellDrilling perPoint = perColumnData.get(perColumnData.size() - 1);
-                        List<BigDecimal> collect = nowColumnData.stream().map(WellDrilling::getHkh).collect(Collectors.toList());
+                        List<BigDecimal> collect = nowColumnData.stream().map(HookLoadCatch::getHkh).collect(Collectors.toList());
                         Optional<BigDecimal> maxHkh =  collect.stream().max(BigDecimal::compareTo);
                         BigDecimal perHkh= maxHkh.get();
                       //  BigDecimal perHkh = perPoint.getHkh();
@@ -356,7 +358,7 @@ public class DrillingOutHookLoadServiceImpl implements DrillingOutHookLoadServic
                         int i = subtract.compareTo(BigDecimal.valueOf(25));
                         if(i<0){
                             hookLoadCatch.setIsWarnNowPoint(true);
-                            List<BigDecimal> wohList = perColumnData.stream().map(WellDrilling::getWoh).collect(Collectors.toList());
+                            List<BigDecimal> wohList = perColumnData.stream().map(HookLoadCatch::getWoh).collect(Collectors.toList());
                             BigDecimal minReferenceWoh = wohList.stream().min(BigDecimal::compareTo).get();
                             BigDecimal maxReferenceWoh = wohList.stream().max(BigDecimal::compareTo).get();
                             hookLoadWarnLogService.saveHookLoadWarnLog(nowPoint, nowPoint.getOperatingMode(), workingCondition, nowPoint.getMotion(), perColumnData.get(0).getTime(), perColumnData.get(perColumnData.size() - 1).getTime(),
@@ -388,16 +390,17 @@ public class DrillingOutHookLoadServiceImpl implements DrillingOutHookLoadServic
      */
     public DrillingOutHookLoadCatch mobileDrillingTools(DrillingOutHookLoadCatch hookLoadCatch, WellDrilling nowPoint, Boolean isMobileDrillingTools,
                                                         BigDecimal activityOne,BigDecimal activityTwo) {
+        HookLoadCatch point = createPoint(nowPoint);
         if (isMobileDrillingTools) {
             hookLoadCatch = recordMobileDrillingToolsData(hookLoadCatch, nowPoint);
         } else {
             //活动钻具记录步骤
             Integer mobileDrillingToolsStep = hookLoadCatch.getMobileDrillingToolsStep();
-            List<WellDrilling> referenceMobileDrillingToolsData = hookLoadCatch.getReferenceMobileDrillingToolsData();
-            List<BigDecimal> referenceWohList = referenceMobileDrillingToolsData.stream().map(WellDrilling::getWoh).collect(Collectors.toList());
+            List<HookLoadCatch> referenceMobileDrillingToolsData = hookLoadCatch.getReferenceMobileDrillingToolsData();
+            List<BigDecimal> referenceWohList = referenceMobileDrillingToolsData.stream().map(HookLoadCatch::getWoh).collect(Collectors.toList());
             switch (mobileDrillingToolsStep) {
                 case 0:
-                    hookLoadCatch.setReferenceMobileDrillingToolsStartData(nowPoint);
+                    hookLoadCatch.setReferenceMobileDrillingToolsStartData(point);
                     break;
                 case 1:
                     //结束第一次活动钻具参考数据记录
@@ -407,12 +410,12 @@ public class DrillingOutHookLoadServiceImpl implements DrillingOutHookLoadServic
                     activeDrillingToolsWarnCal(nowPoint.getJh(), nowPoint.getOperatingMode(), nowPoint.getMotion(), hookLoadCatch, activityTwo, 1);
                     break;
                 case 2:
-                    hookLoadCatch.setMobileDrillingToolsStartData(nowPoint);
+                    hookLoadCatch.setMobileDrillingToolsStartData(point);
                     break;
                 case 3:
                     //结束第二次及以上次数活动钻具数据记录并计算预警
-                    List<WellDrilling> mobileDrillingToolsData = hookLoadCatch.getMobileDrillingToolsData();
-                    List<BigDecimal> wohList = mobileDrillingToolsData.stream().map(WellDrilling::getWoh).collect(Collectors.toList());
+                    List<HookLoadCatch> mobileDrillingToolsData = hookLoadCatch.getMobileDrillingToolsData();
+                    List<BigDecimal> wohList = mobileDrillingToolsData.stream().map(HookLoadCatch::getWoh).collect(Collectors.toList());
                     BigDecimal pointWohFluctuatedValue = calculateVolatility(wohList);
                     //
                     activeDrillingToolsWarnCal(nowPoint.getJh(), nowPoint.getOperatingMode(), nowPoint.getMotion(), hookLoadCatch, activityTwo, 2);
@@ -490,45 +493,46 @@ public class DrillingOutHookLoadServiceImpl implements DrillingOutHookLoadServic
      * @return HookLoadCatch 缓存数据
      */
     public DrillingOutHookLoadCatch recordMobileDrillingToolsData(DrillingOutHookLoadCatch hookLoadCatch, WellDrilling nowPoint) {
+        HookLoadCatch point = createPoint(nowPoint);
         //活动钻具步骤
         Integer mobileDrillingToolsStep = hookLoadCatch.getMobileDrillingToolsStep();
         //参考数据
-        List<WellDrilling> referenceMobileDrillingToolsData = hookLoadCatch.getReferenceMobileDrillingToolsData();
+        List<HookLoadCatch> referenceMobileDrillingToolsData = hookLoadCatch.getReferenceMobileDrillingToolsData();
         //预警数据
-        List<WellDrilling> mobileDrillingToolsData = hookLoadCatch.getMobileDrillingToolsData();
-        WellDrilling referenceMobileDrillingToolsStartData = hookLoadCatch.getReferenceMobileDrillingToolsStartData();
+        List<HookLoadCatch> mobileDrillingToolsData = hookLoadCatch.getMobileDrillingToolsData();
+        HookLoadCatch referenceMobileDrillingToolsStartData = hookLoadCatch.getReferenceMobileDrillingToolsStartData();
         //判断样本起点数据是否存在
         if (referenceMobileDrillingToolsStartData != null) {
             switch (mobileDrillingToolsStep) {
                 case 0:
                     //未开始
-                    List<WellDrilling> nowColumnData = hookLoadCatch.getNowColumnData();
+                    List<HookLoadCatch> nowColumnData = hookLoadCatch.getNowColumnData();
                     if (nowColumnData.size() > 0) {
-                        WellDrilling lastPoint = nowColumnData.get(nowColumnData.size() - 1);
+                        HookLoadCatch lastPoint = nowColumnData.get(nowColumnData.size() - 1);
                         String workingCondition = hookLoadCatch.getWorkingCondition();
                         Boolean isMobileDrillingTools = judgeIsMobileDrillingTools(workingCondition, lastPoint.getMotion());
                         if (!isMobileDrillingTools) {
                             hookLoadCatch.setMobileDrillingToolsStep(1);
                             referenceMobileDrillingToolsData.add(referenceMobileDrillingToolsStartData);
-                            referenceMobileDrillingToolsData.add(nowPoint);
+                            referenceMobileDrillingToolsData.add(point);
                             hookLoadCatch.setReferenceMobileDrillingToolsData(referenceMobileDrillingToolsData);
                             //   hookLoadCatch.setNowColumnData(new ArrayList<>());
                         }
                     }
                     break;
                 case 1:
-                    referenceMobileDrillingToolsData.add(nowPoint);
+                    referenceMobileDrillingToolsData.add(point);
                     hookLoadCatch.setReferenceMobileDrillingToolsData(referenceMobileDrillingToolsData);
                     break;
                 case 2:
                     hookLoadCatch.setMobileDrillingToolsStep(3);
                     mobileDrillingToolsData.add(hookLoadCatch.getMobileDrillingToolsStartData());
-                    mobileDrillingToolsData.add(nowPoint);
+                    mobileDrillingToolsData.add(point);
 //                    hookLoadCatch.setNowColumnData(new ArrayList<>());
                     hookLoadCatch.setMobileDrillingToolsData(mobileDrillingToolsData);
                     break;
                 case 3:
-                    mobileDrillingToolsData.add(nowPoint);
+                    mobileDrillingToolsData.add(point);
                     hookLoadCatch.setMobileDrillingToolsData(mobileDrillingToolsData);
                     break;
                 default:
@@ -586,14 +590,14 @@ public class DrillingOutHookLoadServiceImpl implements DrillingOutHookLoadServic
      * @param list 上提/下方钻具记录数据
      * @return 工况:起钻/下钻
      */
-    public String determineWorkingConditions(List<WellDrilling> list) {
+    public String determineWorkingConditions(List<HookLoadCatch> list) {
         String res = "";
         //记录上提/下方钻具动作数据中的钻
         if (list.size() == 0) {
             return res;
         }
-        WellDrilling oneWellDrilling = list.get(0);
-        WellDrilling lastWellDrilling = list.get(list.size() - 1);
+        HookLoadCatch oneWellDrilling = list.get(0);
+        HookLoadCatch lastWellDrilling = list.get(list.size() - 1);
         BigDecimal oneBitDepth = oneWellDrilling.getBitdepth();
         BigDecimal lastBitDepth = lastWellDrilling.getBitdepth();
         BigDecimal bitDepthSubtract = oneBitDepth.subtract(lastBitDepth);
@@ -616,12 +620,12 @@ public class DrillingOutHookLoadServiceImpl implements DrillingOutHookLoadServic
      * @param workingCondition 当前工况
      * @return 钩载最值
      */
-    public BigDecimal getWohMaximum(List<WellDrilling> list, String workingCondition) {
+    public BigDecimal getWohMaximum(List<HookLoadCatch> list, String workingCondition) {
         BigDecimal res = BigDecimal.ZERO;
         if (list.size() == 0) {
             return res;
         }
-        List<BigDecimal> collect = list.stream().map(WellDrilling::getWoh).collect(Collectors.toList());
+        List<BigDecimal> collect = list.stream().map(HookLoadCatch::getWoh).collect(Collectors.toList());
         if (workingCondition.equals(WorkingConditionEnum.TripOut.getValue())) {
             //起钻
             res = collect.stream().max(BigDecimal::compareTo).get();
@@ -633,7 +637,7 @@ public class DrillingOutHookLoadServiceImpl implements DrillingOutHookLoadServic
     }
 
     public void activeDrillingToolsWarnCal(String jh, String operatingMode, String motion, DrillingOutHookLoadCatch hookLoadCatch, BigDecimal warnValue, Integer step) {
-        List<WellDrilling> activeDrillingToolsData = new ArrayList<>();
+        List<HookLoadCatch> activeDrillingToolsData = new ArrayList<>();
         if (step == 1) {
             activeDrillingToolsData = hookLoadCatch.getReferenceMobileDrillingToolsData();
         } else {
@@ -663,11 +667,11 @@ public class DrillingOutHookLoadServiceImpl implements DrillingOutHookLoadServic
      * @param activeDrillingToolsData
      * @return
      */
-    public HookLoadWarnLog activeDrillingToolsWarn(List<WellDrilling> activeDrillingToolsData) {
+    public HookLoadWarnLog activeDrillingToolsWarn(List<HookLoadCatch> activeDrillingToolsData) {
         // DrillingOutHookLoadCatch hookLoadCatch= new DrillingOutHookLoadCatch();
         BigDecimal hkhStartPosition = activeDrillingToolsData.get(0).getHkh();
         BigDecimal hkhEndPosition = activeDrillingToolsData.get(activeDrillingToolsData.size() - 1).getHkh();
-        List<BigDecimal> wohList = activeDrillingToolsData.stream().map(WellDrilling::getWoh).collect(Collectors.toList());
+        List<BigDecimal> wohList = activeDrillingToolsData.stream().map(HookLoadCatch::getWoh).collect(Collectors.toList());
         BigDecimal wohMax = wohList.stream().max(BigDecimal::compareTo).get();
         BigDecimal wohMin = wohList.stream().min(BigDecimal::compareTo).get();
         return activeDrillingToolsCalculate(hkhStartPosition, hkhEndPosition, wohMax, wohMin);
@@ -696,4 +700,16 @@ public class DrillingOutHookLoadServiceImpl implements DrillingOutHookLoadServic
         return hookLoadWarnLog;
     }
 
+    public HookLoadCatch createPoint(WellDrilling point){
+        HookLoadCatch model=new HookLoadCatch();
+        model.setTid(point.getTid());
+        model.setJh(point.getJh());
+        model.setTime(point.getTime());
+        model.setBitdepth(point.getBitdepth());
+        model.setWoh(point.getWoh());
+        model.setHkh(point.getHkh());
+        model.setDepth(point.getDepth());
+        return model;
+    }
+
 }

+ 185 - 111
yujing-warning-calculation/src/main/java/com/cn/tianji/service/impl/TotalPoolVolumeServiceImpl.java

@@ -7,16 +7,16 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.cn.tianji.common.CommonUtils;
 import com.cn.tianji.common.PittotalCache;
 import com.cn.tianji.common.RedisUtil;
-import com.cn.tianji.entity.TotalPoolVolumeWarnLog;
-import com.cn.tianji.entity.WarnHistory;
-import com.cn.tianji.entity.WellDrilling;
-import com.cn.tianji.entity.YjTotalPoolWarnValue;
+import com.cn.tianji.entity.*;
 import com.cn.tianji.service.TotalPoolVolumeService;
 import com.cn.tianji.service.TotalPoolVolumeWarnLogService;
 import com.cn.tianji.service.WarnHistoryService;
 import com.cn.tianji.service.WellDrillingService;
 import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
+import org.jetbrains.annotations.NotNull;
+import org.springframework.data.redis.core.RedisOperations;
+import org.springframework.data.redis.core.SessionCallback;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
@@ -53,43 +53,51 @@ public class TotalPoolVolumeServiceImpl implements TotalPoolVolumeService {
     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
     @Override
-    public void totalPoolVolumeWarn(WellDrilling nowPoint, String redisHasKey,List<YjTotalPoolWarnValue> warnValueDatas) throws ParseException {
-        String jh=nowPoint.getJh();
-        Date nowDate=new Date();
+    public void totalPoolVolumeWarn(@NotNull WellDrilling nowPoint, String redisHasKey, List<YjTotalPoolWarnValue> warnValueDatas) throws ParseException {
+        String jh = nowPoint.getJh();
+        Date nowDate = new Date();
 //        String redisHasKey = jh + "_total_pool_volume";
-       // String jhTableCode = wellDrillingService.getTableCode(jh);
+        // String jhTableCode = wellDrillingService.getTableCode(jh);
         String jhTableCode = CommonUtils.getJhTableName(jh);
-        BigDecimal nowPittotalBig= new BigDecimal(0.0);
+        BigDecimal nowPittotalBig = new BigDecimal(0.0);
+        TotalPoolVolumeCatch catchModel = createCatchModel(nowPoint);
         try {
-             nowPittotalBig = nowPoint.getPittotal();
-        }catch (Exception e){
+            nowPittotalBig = nowPoint.getPittotal();
+        } catch (Exception e) {
             e.printStackTrace();
-            log.error("总池体积异常,井号:{}",jh);
-            return;
+            log.error("总池体积异常,井号:{}", jh);
+            throw new RuntimeException("获取Pittotal失败", e);
         }
         BigDecimal bigDecimal = BigDecimal.valueOf(-999.25);
         int i = nowPittotalBig.compareTo(bigDecimal);
-        if(i<=0){
-            log.error("总池体积异常,井号:{},总池体积:{}",jh,bigDecimal);
+        if (i <= 0) {
+            log.error("总池体积异常,井号:{},总池体积:{}", jh, bigDecimal);
             return;
         }
         boolean isPittotalCatch = redisUtil.hasKey(redisHasKey);
         //获取当前点往前5分钟的钻进数据
-        PittotalCache pittotalCache =new PittotalCache();
-        if(isPittotalCatch){
+        PittotalCache pittotalCache = new PittotalCache();
+        if (isPittotalCatch) {
             pittotalCache = JSONObject.toJavaObject(JSONObject.parseObject(JSON.toJSONString(redisUtil.get(redisHasKey))), PittotalCache.class);
             //判断总池体积差值是否超过预警值
-            pittotalCache=warn(nowPittotalBig,nowPoint,pittotalCache,warnValueDatas);
+            pittotalCache = warn(nowPittotalBig, nowPoint, pittotalCache, warnValueDatas);
             //判断计算时间是否超过5分钟
             long calTimeDiff = CommonUtils.timeDifference(pittotalCache.getStartTime(), sdf.parse(nowPoint.getTime()));
-            if(calTimeDiff >= 5 * 60){
-                log.info("计算时间超过5分钟时间差:{}分",(calTimeDiff/60));
-                List<WellDrilling> referenceData = getReferenceValue(jhTableCode, nowPoint,Calendar.MINUTE, -5);
-                BigDecimal pittotalSumBig = referenceData.stream().map(WellDrilling::getPittotal) .reduce(BigDecimal.ZERO, BigDecimal::add);
-                BigDecimal referenceValueBig= pittotalSumBig.divide(new BigDecimal(referenceData.size()), MathContext.DECIMAL128).setScale(2, RoundingMode.HALF_UP);
-                pittotalCache.setStartTime(sdf.parse(nowPoint.getTime()));
-                pittotalCache.setReferenceData(referenceData);
-                pittotalCache.setReferenceValue(referenceValueBig);
+            if (calTimeDiff >= 5 * 60) {
+                // log.info("计算时间超过5分钟时间差:{}分",(calTimeDiff/60));
+                List<TotalPoolVolumeCatch> referenceData = getReferenceValue(jhTableCode, nowPoint, Calendar.MINUTE, -5);
+                if (!referenceData.isEmpty()) {
+                    BigDecimal pittotalSumBig = referenceData.stream().map(TotalPoolVolumeCatch::getPittotal).reduce(BigDecimal.ZERO, BigDecimal::add);
+                    log.info("井号:{},pittotalSumBig:{},referenceData.size(){}", jh, pittotalSumBig, referenceData.size());
+                    try {
+                        BigDecimal referenceValueBig = pittotalSumBig.divide(new BigDecimal(referenceData.size()), MathContext.DECIMAL128).setScale(2, RoundingMode.HALF_UP);
+                        pittotalCache.setStartTime(sdf.parse(nowPoint.getTime()));
+                        pittotalCache.setReferenceData(referenceData);
+                        pittotalCache.setReferenceValue(referenceValueBig);
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                }
             }
             //判断速率时间是否超过30秒
 //            long rateTimeDiff = CommonUtils.timeDifference(pittotalCache.getRateStartTime(), sdf.parse(nowPoint.getTime()));
@@ -97,112 +105,213 @@ public class TotalPoolVolumeServiceImpl implements TotalPoolVolumeService {
 //                log.info("计算时间超过30秒时间差:{}秒",rateTimeDiff);
 //
 //            }
-            List<WellDrilling> rateData = pittotalCache.getRateData();
+            List<TotalPoolVolumeCatch> rateData = pittotalCache.getRateData();
+
             rateData.remove(0);
-            rateData.add(nowPoint);
+            rateData.add(catchModel);
             pittotalCache.setRateData(rateData);
             pittotalCache.setRateStartTime(sdf.parse(rateData.get(0).getTime()));
             pittotalCache.setRateStartPittotal(rateData.get(0).getPittotal());
-            redisUtil.set(redisHasKey, pittotalCache);
-        }else{
-            List<WellDrilling> referenceData = getReferenceValue(jhTableCode, nowPoint, Calendar.MINUTE,-5);
-            List<WellDrilling> rateData = getReferenceValue(jhTableCode, nowPoint, Calendar.SECOND,-30);
-            if(referenceData.size()>25){
-                BigDecimal pittotalSumBig = referenceData.stream().map(WellDrilling::getPittotal) .reduce(BigDecimal.ZERO, BigDecimal::add);
-                BigDecimal referenceValueBig= pittotalSumBig.divide(new BigDecimal(referenceData.size()), MathContext.DECIMAL128).setScale(2, RoundingMode.HALF_UP);
+            PittotalCache finalPittotalCache = pittotalCache;
+            redisUtil.set(redisHasKey, finalPittotalCache);
+        } else {
+            List<TotalPoolVolumeCatch> referenceData = getReferenceValue(jhTableCode, nowPoint, Calendar.MINUTE, -5);
+            List<TotalPoolVolumeCatch> rateData = getReferenceValue(jhTableCode, nowPoint, Calendar.SECOND, -30);
+            if (referenceData.size() > 25) {
+                BigDecimal pittotalSumBig = referenceData.stream().map(TotalPoolVolumeCatch::getPittotal).reduce(BigDecimal.ZERO, BigDecimal::add);
+                BigDecimal referenceValueBig = pittotalSumBig.divide(new BigDecimal(referenceData.size()), MathContext.DECIMAL128).setScale(2, RoundingMode.HALF_UP);
                 pittotalCache.setReferenceData(referenceData);
                 pittotalCache.setStartTime(sdf.parse(nowPoint.getTime()));
                 pittotalCache.setReferenceValue(referenceValueBig);
                 pittotalCache.setRateStartTime(sdf.parse(rateData.get(0).getTime()));
                 pittotalCache.setRateStartPittotal(rateData.get(0).getPittotal());
                 pittotalCache.setRateData(rateData);
-                pittotalCache=warn(nowPittotalBig,nowPoint,pittotalCache,warnValueDatas);
-                redisUtil.set(redisHasKey, pittotalCache);
+                pittotalCache = warn(nowPittotalBig, nowPoint, pittotalCache, warnValueDatas);
+                PittotalCache finalPittotalCache1 = pittotalCache;
+                redisUtil.set(redisHasKey, finalPittotalCache1);
             }
         }
-        Date endDate=new Date();
+        Date endDate = new Date();
         long warnTimeDiff = CommonUtils.timeDifference_(nowDate, endDate);
-        log.info("计算耗时:{}毫秒",warnTimeDiff);
+        log.info("计算耗时:{}毫秒", warnTimeDiff);
     }
 
+//    @Override
+//    public void totalPoolVolumeWarn(@NotNull WellDrilling nowPoint, String redisHasKey, List<YjTotalPoolWarnValue> warnValueDatas)  {
+//        log.warn("总池体积主键aaaa:{}",redisHasKey);
+//        // 定义事务操作
+//        SessionCallback<List<Object>> transactionOperations = new SessionCallback<List<Object>>() {
+//            @Override
+//            public List<Object> execute(RedisOperations operations) {
+//                operations.multi();
+//                try {
+//                    String jh = nowPoint.getJh();
+//
+//                    BigDecimal nowPittotalBig = new BigDecimal(0.0);
+//                    String jhTableCode = CommonUtils.getJhTableName(jh);
+//                    TotalPoolVolumeCatch catchModel = createCatchModel(nowPoint);
+//
+//                    try {
+//                        nowPittotalBig = nowPoint.getPittotal();
+//                    } catch (Exception e) {
+//                        log.error("总池体积异常,井号:{}", jh, e);
+//                        throw new RuntimeException("获取Pittotal失败", e);
+//                    }
+//
+//                    BigDecimal bigDecimal = BigDecimal.valueOf(-999.25);
+//                    int i = nowPittotalBig.compareTo(bigDecimal);
+//                    if (i <= 0) {
+//                        log.error("总池体积异常,井号:{},总池体积:{}", jh, bigDecimal);
+//                        throw new RuntimeException("总池体积异常");
+//                    }
+//                    log.warn("总池体积主键:{}",redisHasKey);
+//                    boolean isPittotalCatch = redisUtil.hasKey(redisHasKey);
+//                    PittotalCache pittotalCache = new PittotalCache();
+//                    if (isPittotalCatch) {
+//                        pittotalCache = JSONObject.toJavaObject(JSONObject.parseObject(JSON.toJSONString(redisUtil.get(redisHasKey))), PittotalCache.class);
+//                        pittotalCache = warn(nowPittotalBig, nowPoint, pittotalCache, warnValueDatas);
+//                        long calTimeDiff = CommonUtils.timeDifference(pittotalCache.getStartTime(), sdf.parse(nowPoint.getTime()));
+//                        if (calTimeDiff >= 5 * 60) {
+//                            log.info("计算时间超过5分钟时间差:{}分", (calTimeDiff / 60));
+//                            List<TotalPoolVolumeCatch> referenceData = getReferenceValue(jhTableCode, nowPoint, Calendar.MINUTE, -5);
+//                            BigDecimal pittotalSumBig = referenceData.stream().map(TotalPoolVolumeCatch::getPittotal).reduce(BigDecimal.ZERO, BigDecimal::add);
+//                            BigDecimal referenceValueBig = pittotalSumBig.divide(new BigDecimal(referenceData.size()), MathContext.DECIMAL128).setScale(2, RoundingMode.HALF_UP);
+//                            pittotalCache.setStartTime(sdf.parse(nowPoint.getTime()));
+//                            pittotalCache.setReferenceData(referenceData);
+//                            pittotalCache.setReferenceValue(referenceValueBig);
+//                        }
+//
+//                        List<TotalPoolVolumeCatch> rateData = pittotalCache.getRateData();
+//                        rateData.remove(0);
+//                        rateData.add(catchModel);
+//                        pittotalCache.setRateData(rateData);
+//                        pittotalCache.setRateStartTime(sdf.parse(rateData.get(0).getTime()));
+//                        pittotalCache.setRateStartPittotal(rateData.get(0).getPittotal());
+//                        operations.opsForValue().set(redisHasKey, pittotalCache);
+//                    } else {
+//                        List<TotalPoolVolumeCatch> referenceData = getReferenceValue(jhTableCode, nowPoint, Calendar.MINUTE, -5);
+//                        List<TotalPoolVolumeCatch> rateData = getReferenceValue(jhTableCode, nowPoint, Calendar.SECOND, -30);
+//                        if (referenceData.size() > 25) {
+//                            BigDecimal pittotalSumBig = referenceData.stream().map(TotalPoolVolumeCatch::getPittotal).reduce(BigDecimal.ZERO, BigDecimal::add);
+//                            BigDecimal referenceValueBig = pittotalSumBig.divide(new BigDecimal(referenceData.size()), MathContext.DECIMAL128).setScale(2, RoundingMode.HALF_UP);
+//                            pittotalCache.setReferenceData(referenceData);
+//                            pittotalCache.setStartTime(sdf.parse(nowPoint.getTime()));
+//                            pittotalCache.setReferenceValue(referenceValueBig);
+//                            pittotalCache.setRateStartTime(sdf.parse(rateData.get(0).getTime()));
+//                            pittotalCache.setRateStartPittotal(rateData.get(0).getPittotal());
+//                            pittotalCache.setRateData(rateData);
+//                            pittotalCache = warn(nowPittotalBig, nowPoint, pittotalCache, warnValueDatas);
+//                            operations.opsForValue().set(redisHasKey, pittotalCache);
+//                        }
+//                    }
+//
+//                } catch (Exception e) {
+//                    log.error("事务执行过程中发生异常", e);
+//                    throw new RuntimeException("事务执行失败", e);
+//                }
+//                return operations.exec();
+//            }
+//        };
+//        // 执行事务
+//        try {
+//            Date nowDate = new Date();
+//            redisUtil.executeTransaction(transactionOperations);
+//            log.info("事务执行成功");
+//            Date endDate=new Date();
+//            long warnTimeDiff = CommonUtils.timeDifference_(nowDate, endDate);
+//            log.info("计算耗时:{}毫秒",warnTimeDiff);
+//        } catch (RuntimeException e) {
+//            log.error("事务执行失败: {}", e.getMessage());
+//        }
+//
+//
+//    }
+
     /**
      * 获取指定时间范围内的数据
+     *
      * @param jhTableName 井表名
-     * @param nowPoint 当前点数据
-     * @param mi 时间差
+     * @param nowPoint    当前点数据
+     * @param mi          时间差
      * @return
      */
-    public List<WellDrilling> getReferenceValue(String jhTableName, WellDrilling nowPoint, int type, Integer mi) throws ParseException {
+    public List<TotalPoolVolumeCatch> getReferenceValue(String jhTableName, @NotNull WellDrilling nowPoint, int type, Integer mi) throws ParseException {
         Calendar calendar = Calendar.getInstance();
         calendar.setTime(sdf.parse(nowPoint.getTime()));
         calendar.add(type, mi);
         Date time = calendar.getTime();
-        String startTime= sdf.format(time);
-        String endTime= CommonUtils.removeMilliseconds(nowPoint.getTime());
-        log.info("获取的井;{};开始时间:{};结束时间:{}",jhTableName,startTime,endTime);
+        String startTime = sdf.format(time);
+        String endTime = CommonUtils.removeMilliseconds(nowPoint.getTime());
+        log.info("获取的井;{};开始时间:{};结束时间:{}", jhTableName, startTime, endTime);
         //查询当前点前一分钟的点
         QueryWrapper<WellDrilling> wrapper = new QueryWrapper<WellDrilling>();
         // wrapper.apply(("TIME <= '" + sdf.format(time) + "'"));
-        wrapper.apply("TO_DATE(SUBSTR(TIME, 1, 19), 'yyyy-MM-dd HH24:mi:ss') <= to_date({0},'yyyy-mm-dd hh24:mi:ss')",endTime);
-        wrapper.apply("TO_DATE(SUBSTR(TIME, 1, 19), 'yyyy-MM-dd HH24:mi:ss') >= to_date({0},'yyyy-mm-dd hh24:mi:ss')",startTime);
+        wrapper.apply("TO_DATE(SUBSTR(TIME, 1, 19), 'yyyy-MM-dd HH24:mi:ss') <= to_date({0},'yyyy-mm-dd hh24:mi:ss')", endTime);
+        wrapper.apply("TO_DATE(SUBSTR(TIME, 1, 19), 'yyyy-MM-dd HH24:mi:ss') >= to_date({0},'yyyy-mm-dd hh24:mi:ss')", startTime);
         wrapper.orderByDesc("time");
-        return wellDrillingService.selectListOrcale(jhTableName, wrapper);
+        List<WellDrilling> wellDrillings = wellDrillingService.selectListOrcale(jhTableName, wrapper);
+        List<TotalPoolVolumeCatch> res = new ArrayList<>();
+        wellDrillings.forEach(item -> {
+            TotalPoolVolumeCatch catchModel = createCatchModel(item);
+            res.add(catchModel);
+        });
+        return res;
     }
 
-    public PittotalCache warn(BigDecimal nowPittotalBig, WellDrilling nowPoint, PittotalCache pittotalCache,List<YjTotalPoolWarnValue> warnValueDatas) throws ParseException {
+    public PittotalCache warn(@NotNull BigDecimal nowPittotalBig, WellDrilling nowPoint, @NotNull PittotalCache pittotalCache, List<YjTotalPoolWarnValue> warnValueDatas) throws ParseException {
         BigDecimal pittotalSub = nowPittotalBig.subtract(pittotalCache.getReferenceValue()).setScale(1, RoundingMode.HALF_UP);
         BigDecimal rantePittotalSub = nowPittotalBig.subtract(pittotalCache.getRateStartPittotal()).setScale(1, RoundingMode.HALF_UP);
-        log.info("参考值均值:{};当前点值:{},起点时间:{}",pittotalCache.getReferenceValue(),nowPittotalBig,pittotalCache.getStartTime());
-        log.info("参考值均值(速率):{};当前点值:{},起点时间:{}",pittotalCache.getRateStartPittotal(),nowPittotalBig,pittotalCache.getRateStartTime());
+        log.info("参考值均值:{};当前点值:{},起点时间:{}", pittotalCache.getReferenceValue(), nowPittotalBig, pittotalCache.getStartTime());
+        log.info("参考值均值(速率):{};当前点值:{},起点时间:{}", pittotalCache.getRateStartPittotal(), nowPittotalBig, pittotalCache.getRateStartTime());
         int wanrType = pittotalSub.compareTo(BigDecimal.ZERO);
         //判断预警类被
         //井漏
-        if(wanrType<0){
+        if (wanrType < 0) {
             List<YjTotalPoolWarnValue> warnData = warnValueDatas.stream().filter(item -> item.getWarnType().equals("井漏")).collect(Collectors.toList());
             BigDecimal pittotalWarnValue = warnData.get(0).getPittotalWarn();
             BigDecimal ranteWarnValue = warnData.get(0).getRanteWarn();
             int pittotalWarn = pittotalSub.compareTo(pittotalWarnValue);
             int ranteWarn = rantePittotalSub.compareTo(ranteWarnValue);
-            if(pittotalWarn<=0&&ranteWarn<=0){
-                pittotalCache = saveOrUpdateTotalPoolVolumeWarnLog(nowPoint,pittotalCache,"井漏",pittotalSub.setScale(2,RoundingMode.HALF_UP),
-                        rantePittotalSub.setScale(2,RoundingMode.HALF_UP),pittotalWarnValue,ranteWarnValue,"小于");
+            if (pittotalWarn <= 0 && ranteWarn <= 0) {
+                pittotalCache = saveOrUpdateTotalPoolVolumeWarnLog(nowPoint, pittotalCache, "井漏", pittotalSub.setScale(2, RoundingMode.HALF_UP),
+                        rantePittotalSub.setScale(2, RoundingMode.HALF_UP), pittotalWarnValue, ranteWarnValue, "小于");
             }
-        }else{ //溢流
+        } else { //溢流
             List<YjTotalPoolWarnValue> warnData = warnValueDatas.stream().filter(item -> item.getWarnType().equals("溢流")).collect(Collectors.toList());
             BigDecimal pittotalWarnValue = warnData.get(0).getPittotalWarn();
             BigDecimal ranteWarnValue = warnData.get(0).getRanteWarn();
             int pittotalWarn = pittotalSub.compareTo(pittotalWarnValue);
             int ranteWarn = rantePittotalSub.compareTo(ranteWarnValue);
-            if(pittotalWarn>=0&&ranteWarn>=0){
-                pittotalCache = saveOrUpdateTotalPoolVolumeWarnLog(nowPoint,pittotalCache,"溢流",pittotalSub.setScale(2,RoundingMode.HALF_UP),
-                        rantePittotalSub.setScale(2,RoundingMode.HALF_UP),pittotalWarnValue,ranteWarnValue,"大于");
+            if (pittotalWarn >= 0 && ranteWarn >= 0) {
+                pittotalCache = saveOrUpdateTotalPoolVolumeWarnLog(nowPoint, pittotalCache, "溢流", pittotalSub.setScale(2, RoundingMode.HALF_UP),
+                        rantePittotalSub.setScale(2, RoundingMode.HALF_UP), pittotalWarnValue, ranteWarnValue, "大于");
             }
         }
         return pittotalCache;
     }
 
     @SneakyThrows
-    public PittotalCache saveOrUpdateTotalPoolVolumeWarnLog(WellDrilling nowPoint, PittotalCache pittotalCache,String warnType, BigDecimal pittotalSub,BigDecimal ratePittotalSub,BigDecimal referenceWarnValue,BigDecimal rateWarnValue,String sizeStr){
-        List<WellDrilling> referenceData = pittotalCache.getReferenceData();
-        Date warnTime=sdf.parse(nowPoint.getTime());
-        String jh=nowPoint.getJh();
-        TotalPoolVolumeWarnLog totalPoolVolumeWarnLog = totalPoolVolumeWarnLogService.createTotalPoolVolumeWarnLog(jh, nowPoint.getOperatingMode(), nowPoint.getMotion(), warnType,warnTime , nowPoint.getPittotal(), pittotalCache.getReferenceValue(),
+    public PittotalCache saveOrUpdateTotalPoolVolumeWarnLog(@NotNull WellDrilling nowPoint, @NotNull PittotalCache pittotalCache, String warnType, BigDecimal pittotalSub, BigDecimal ratePittotalSub, BigDecimal referenceWarnValue, BigDecimal rateWarnValue, String sizeStr) {
+        List<TotalPoolVolumeCatch> referenceData = pittotalCache.getReferenceData();
+        Date warnTime = sdf.parse(nowPoint.getTime());
+        String jh = nowPoint.getJh();
+        TotalPoolVolumeWarnLog totalPoolVolumeWarnLog = totalPoolVolumeWarnLogService.createTotalPoolVolumeWarnLog(jh, nowPoint.getOperatingMode(), nowPoint.getMotion(), warnType, warnTime, nowPoint.getPittotal(), pittotalCache.getReferenceValue(),
                 sdf.parse(referenceData.get(referenceData.size() - 1).getTime()), sdf.parse(referenceData.get(0).getTime()), pittotalCache.getRateStartPittotal(), pittotalCache.getRateStartTime(), sdf.parse(nowPoint.getTime()), pittotalSub, ratePittotalSub,
                 referenceWarnValue, rateWarnValue, sizeStr);
         Date lastWarnDate = pittotalCache.getLastWarnDate();
-        if(lastWarnDate!=null){
+        if (lastWarnDate != null) {
             long warnTimeDiff = CommonUtils.timeDifference(lastWarnDate, warnTime);
-            if(warnTimeDiff >= 12){
+            if (warnTimeDiff >= 12) {
                 //大于10秒说明不是连续的预警数据,重新记录
                 List<TotalPoolVolumeWarnLog> list = new ArrayList<>();
                 totalPoolVolumeWarnLog.setDataType("0");
                 list.add(totalPoolVolumeWarnLog);
                 pittotalCache.setWarnList(list);
-            }else{
+            } else {
                 List<TotalPoolVolumeWarnLog> warnList = pittotalCache.getWarnList();
                 totalPoolVolumeWarnLog.setDataType("1");
                 warnList.add(totalPoolVolumeWarnLog);
-                if(warnList.size()>=3){
+                if (warnList.size() >= 3) {
                     totalPoolVolumeWarnLogService.save(totalPoolVolumeWarnLog);
 //                    QueryWrapper<TotalPoolVolumeWarnLog> wrapper = new QueryWrapper<>();
 //                    wrapper.eq("JH",jh);
@@ -220,7 +329,7 @@ public class TotalPoolVolumeServiceImpl implements TotalPoolVolumeService {
                 }
                 pittotalCache.setWarnList(warnList);
             }
-        }else{
+        } else {
             List<TotalPoolVolumeWarnLog> list = new ArrayList<>();
             list.add(totalPoolVolumeWarnLog);
             pittotalCache.setWarnList(list);
@@ -229,48 +338,13 @@ public class TotalPoolVolumeServiceImpl implements TotalPoolVolumeService {
         return pittotalCache;
     }
 
-    public PittotalCache saveOrUpdateWarnHistory(String jh, Float bitDepth, Float warnPit, Date warnTime, Float startPit, Date startTime, Float jlSub, Float pitValue,String warnDes,PittotalCache pittotalCache) {
 
-        WarnHistory history = new WarnHistory();
-        history.setJh(jh);
-        history.setWarnType("总池体积变化异常");
-        history.setWarnBitdepth(bitDepth);
-        history.setWarnWoh(warnPit);
-        history.setWarnTime(warnTime);
-        history.setPitStartTime(startTime);
-        history.setPitStart(startPit);
-        history.setPitSub(jlSub);
-        history.setPitValue(pitValue);
-        history.setWarnDes(warnDes);
-        Date lastWarnDate = pittotalCache.getLastWarnDate();
-        if(lastWarnDate!=null){
-            long warnTimeDiff = CommonUtils.timeDifference(lastWarnDate, warnTime);
-            //判断最新预警时间与最后预警时间是否为连续时间
-            if(warnTimeDiff >= 10){ //大于10秒说明不是连续的预警数据,重新记录
-                List<WarnHistory>  warnList= new ArrayList<>();
-                pittotalCache.setWarnListOld(warnList);
-            }else{
-                List<WarnHistory> warnList = pittotalCache.getWarnListOld();
-                warnList.add(history);
-                if(warnList.size()>=3){
-                    QueryWrapper<WarnHistory> wrapper = new QueryWrapper<>();
-                    wrapper.eq("JH",jh).eq("WARN_TIME",lastWarnDate);
-                    List<WarnHistory> list = warnHistoryService.list(wrapper);
-                    if(list.size()>0){
-                        WarnHistory updateModel = list.get(0);
-                        history.setId(updateModel.getId());
-                        warnHistoryService.updateById(history);
-                    }else{
-                       warnHistoryService.save(history);
-                    }
-                }
-            }
-        }else{
-            List<WarnHistory> list = new ArrayList<>();
-            list.add(history);
-            pittotalCache.setWarnListOld(list);
-        }
-        pittotalCache.setLastWarnDate(warnTime);
-        return pittotalCache;
+    public TotalPoolVolumeCatch createCatchModel(@NotNull WellDrilling point) {
+        TotalPoolVolumeCatch molde = new TotalPoolVolumeCatch();
+        molde.setTid(point.getTid());
+        molde.setJh(point.getJh());
+        molde.setTime(point.getTime());
+        molde.setPittotal(point.getPittotal());
+        return molde;
     }
 }