xsr 1 year ago
parent
commit
8d50a5ca68

+ 4 - 0
pom.xml

@@ -67,6 +67,10 @@
67 67
             <version>2.0-SNAPSHOT</version>
68 68
         </dependency>
69 69
         <dependency>
70
+            <groupId>org.springframework.cloud</groupId>
71
+            <artifactId>spring-cloud-starter-openfeign</artifactId>
72
+        </dependency>
73
+        <dependency>
70 74
             <groupId>com.oracle.database.jdbc</groupId>
71 75
             <artifactId>ojdbc8</artifactId>
72 76
             <version>19.3.0.0</version>

+ 53 - 0
src/main/java/com/gct/tool/config/FeignConfig.java

@@ -0,0 +1,53 @@
1
+package com.gct.tool.config;
2
+
3
+
4
+import feign.RequestInterceptor;
5
+import feign.RequestTemplate;
6
+import lombok.extern.slf4j.Slf4j;
7
+import org.springframework.context.EnvironmentAware;
8
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
9
+import org.springframework.context.annotation.Bean;
10
+import org.springframework.context.annotation.Configuration;
11
+import org.springframework.core.env.Environment;
12
+import org.springframework.web.client.RestTemplate;
13
+
14
+import java.util.Arrays;
15
+import java.util.List;
16
+import java.util.concurrent.ThreadLocalRandom;
17
+
18
+
19
+/**
20
+ * feign 调用配置,统一添加token请求头
21
+ * @author: NewMeanning
22
+ * @create: 2021-01-29 00:10
23
+ **/
24
+@Slf4j
25
+@Configuration
26
+public class FeignConfig implements RequestInterceptor, EnvironmentAware {
27
+
28
+    private static String token;
29
+
30
+    private static Environment env;
31
+
32
+    @Override
33
+    public void apply(RequestTemplate requestTemplate) {
34
+        requestTemplate.header("token",token);//请求头添加token
35
+    }
36
+
37
+    @Override
38
+    public void setEnvironment(Environment environment) {
39
+        //获取配置的认证中心主机地址  todo 升级为自动从Nacos中读取,目前这里读取不到
40
+        this.env = environment;
41
+        List<String> hostList = Arrays.asList(this.env.getProperty("auth.hostList").split(","));
42
+        //手动获取RestTemplate 实例
43
+        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
44
+        applicationContext.register(RestTemplate.class);
45
+        applicationContext.refresh();
46
+        RestTemplate restTemplate= (RestTemplate) applicationContext.getBean("restTemplate");
47
+        //自定义轮询方式负载
48
+        int index = ThreadLocalRandom.current().nextInt(hostList.size());
49
+        String url = "http://"+hostList.get(index)+"/token";
50
+        token = restTemplate.getForObject(url,String.class);
51
+//        log.info("token:{}",token);
52
+    }
53
+}

+ 74 - 0
src/main/java/com/gct/tool/config/QuartzTaskConfig.java

@@ -0,0 +1,74 @@
1
+package com.gct.tool.config;
2
+
3
+import com.gct.tool.quartztask.LoadBaseDataTask;
4
+import com.gct.tool.quartztask.ProduceTask;
5
+import org.quartz.JobBuilder;
6
+import org.quartz.JobDetail;
7
+import org.quartz.Trigger;
8
+import org.quartz.TriggerBuilder;
9
+import org.slf4j.LoggerFactory;
10
+import org.springframework.context.annotation.Bean;
11
+import org.springframework.context.annotation.Configuration;
12
+
13
+import static org.quartz.CronScheduleBuilder.cronSchedule;
14
+
15
+/**
16
+ * class name: QuartzTaskConfig
17
+ *
18
+ * @author lloyd
19
+ * @version 1.0
20
+ * @since 2021/5/21 上午10:21
21
+ */
22
+@Configuration
23
+public class QuartzTaskConfig {
24
+
25
+    @Bean
26
+    public JobDetail jobDetail1() {
27
+        try {
28
+            return JobBuilder.newJob(LoadBaseDataTask.class)
29
+                    .withIdentity("LoadBaseData" ,"Group1")
30
+                    .storeDurably()
31
+                    .build();
32
+        } catch (Exception e) {
33
+            LoggerFactory.getLogger(this.getClass()).error("Create JobDetail bean failed:{},jobName->{},jobGroup->{}", e.getMessage(),"LoadBaseData","Group1");
34
+            throw e;
35
+        }
36
+    }
37
+
38
+    @Bean
39
+    public Trigger trigger1() {
40
+        try {
41
+            return TriggerBuilder.newTrigger()
42
+                    .forJob("LoadBaseData", "Group1")
43
+                    .withSchedule(cronSchedule("0/1 0 0/1 * * ?")).build();
44
+        } catch (Exception e) {
45
+            LoggerFactory.getLogger(this.getClass()).error("Create Trigger bean failed:{},jobName->{},jobGroup->{}", e.getMessage(),"LoadBaseData","Group1");
46
+            throw e;
47
+        }
48
+    }
49
+
50
+    @Bean
51
+    public JobDetail jobDetail2() {
52
+        try {
53
+            return JobBuilder.newJob(ProduceTask.class)
54
+                    .withIdentity("Produce" ,"Group1")
55
+                    .storeDurably()
56
+                    .build();
57
+        } catch (Exception e) {
58
+            LoggerFactory.getLogger(this.getClass()).error("Create JobDetail bean failed:{},jobName->{},jobGroup->{}", e.getMessage(),"LoadBaseData","Group1");
59
+            throw e;
60
+        }
61
+    }
62
+
63
+    @Bean
64
+    public Trigger trigger2() {
65
+        try {
66
+            return TriggerBuilder.newTrigger()
67
+                    .forJob("Produce", "Group1")
68
+                    .withSchedule(cronSchedule("0/1 0 0/1 * * ?")).build();
69
+        } catch (Exception e) {
70
+            LoggerFactory.getLogger(this.getClass()).error("Create Trigger bean failed:{},jobName->{},jobGroup->{}", e.getMessage(),"Produce","Group1");
71
+            throw e;
72
+        }
73
+    }
74
+}

+ 0 - 20
src/main/java/com/gct/tool/mapper/centralbase/CbCdWellSourceMapper.java

@@ -1,20 +0,0 @@
1
-package com.gct.tool.mapper.centralbase;
2
-
3
-import com.baomidou.dynamic.datasource.annotation.DS;
4
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
5
-import com.gct.tool.entity.centralbase.CbCdWellSource;
6
-import org.apache.ibatis.annotations.Mapper;
7
-
8
-/**
9
- * <p>
10
- * 单井基础信息 Mapper 接口
11
- * </p>
12
- *
13
- * @author wsy
14
- * @since 2021-01-19
15
- */
16
-@Mapper
17
-@DS("centralbase")
18
-public interface CbCdWellSourceMapper extends BaseMapper<CbCdWellSource> {
19
-
20
-}

+ 0 - 38
src/main/java/com/gct/tool/mapper/centralbase/CbCdWellSourceMapper.xml

@@ -1,38 +0,0 @@
1
-<?xml version="1.0" encoding="UTF-8"?>
2
-<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
-<mapper namespace="com.gct.tool.mapper.centralbase.CbCdWellSourceMapper">
4
-
5
-    <!-- 通用查询映射结果 -->
6
-    <resultMap id="BaseResultMap" type="com.gct.tool.entity.centralbase.CbCdWellSource">
7
-        <result column="well_id" property="wellId"/>
8
-        <result column="well_common_name" property="wellCommonName"/>
9
-        <result column="well_legal_name" property="wellLegalName"/>
10
-        <result column="reason" property="reason"/>
11
-        <result column="well_purpose" property="wellPurpose"/>
12
-        <result column="p_start_prod_stitum" property="pStartProdStitum"/>
13
-        <result column="target_formation" property="targetFormation"/>
14
-        <result column="spud_date" property="spudDate"/>
15
-        <result column="org_id" property="orgId"/>
16
-        <result column="struct_id" property="structId"/>
17
-        <result column="oilfield_id" property="oilfieldId"/>
18
-        <result column="exp_area_id" property="expAreaId"/>
19
-        <result column="group_unit_id" property="groupUnitId"/>
20
-        <result column="station_id" property="stationId"/>
21
-        <result column="geo_latitude" property="geoLatitude"/>
22
-        <result column="geo_longitude" property="geoLongitude"/>
23
-        <result column="geo_offset_reference" property="geoOffsetReference"/>
24
-        <result column="geo_offset_east" property="geoOffsetEast"/>
25
-        <result column="geo_offset_north" property="geoOffsetNorth"/>
26
-        <result column="remarks" property="remarks"/>
27
-        <result column="is_deviated" property="isDeviated"/>
28
-        <result column="end_status" property="endStatus"/>
29
-        <result column="completion_name" property="completionName"/>
30
-        <result column="PRODUCING_AREA_name" property="producingAreaName"/>
31
-        <result column="top_tvd" property="topTvd"/>
32
-        <result column="bottom_tvd" property="bottomTvd"/>
33
-        <result column="completion_id" property="completionId"/>
34
-    </resultMap>
35
-</mapper>
36
-
37
-
38
-

+ 21 - 0
src/main/java/com/gct/tool/mapper/centralbase/CbPcProWellboreStatusDailyMapper.java

@@ -0,0 +1,21 @@
1
+package com.gct.tool.mapper.centralbase;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.gct.centralbase.entity.CbPcProWellboreStatusDaily;
5
+import org.apache.ibatis.annotations.Mapper;
6
+import org.apache.ibatis.annotations.Param;
7
+
8
+/**
9
+ * <p>
10
+ * 采出井井筒状态日数据 Mapper 接口
11
+ * </p>
12
+ *
13
+ * @author wsy
14
+ * @since 2021-01-19
15
+ */
16
+@Mapper
17
+public interface CbPcProWellboreStatusDailyMapper extends BaseMapper<CbPcProWellboreStatusDaily> {
18
+    public CbPcProWellboreStatusDaily getWellBoreStatusDaily(@Param("wellId") String wellId,@Param("prodDate") String prodDate);
19
+
20
+    CbPcProWellboreStatusDaily getA2DataForCalProduction(@Param("wellId") String wellName,@Param("prodDate") String dateTime);
21
+}

+ 48 - 0
src/main/java/com/gct/tool/mapper/centralbase/CbPcProWellboreStatusDailyMapper.xml

@@ -0,0 +1,48 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.gct.centralbase.mapper.CbPcProWellboreStatusDailyMapper">
4
+
5
+    <cache flushInterval="6000000" size="5096"/>
6
+
7
+    <!-- 通用查询映射结果 -->
8
+    <resultMap id="BaseResultMap" type="com.gct.centralbase.entity.CbPcProWellboreStatusDaily">
9
+        <result column="well_id" property="wellId"/>
10
+        <result column="prod_date" property="prodDate"/>
11
+        <result column="oil_prod_method" property="oilProdMethod"/>
12
+        <result column="oil_nozzle" property="oilNozzle"/>
13
+        <result column="back_pres" property="backPres"/>
14
+        <result column="up_current" property="upCurrent"/>
15
+        <result column="down_current" property="downCurrent"/>
16
+        <result column="elec_pump_current_a" property="elecPumpCurrentA"/>
17
+        <result column="elec_pump_current_b" property="elecPumpCurrentB"/>
18
+        <result column="elec_pump_current_c" property="elecPumpCurrentC"/>
19
+        <result column="elec_pump_voltage" property="elecPumpVoltage"/>
20
+        <result column="wh_temp" property="whTemp"/>
21
+        <result column="main_line_pres" property="mainLinePres"/>
22
+        <result column="avg_oil_pres" property="avgOilPres"/>
23
+        <result column="avg_casing_pres" property="avgCasingPres"/>
24
+        <result column="tubing_pres" property="tubingPres"/>
25
+        <result column="casing_pres" property="casingPres"/>
26
+        <result column="cable_setting_depth" property="cableSettingDepth"/>
27
+        <result column="pump_depth" property="pumpDepth"/>
28
+        <result column="casing_inner_diameter" property="casingInnerDiameter"/>
29
+        <result column="start_pump_liq_level" property="startPumpLiqLevel"/>
30
+        <result column="end_pump_liq_level" property="endPumpLiqLevel"/>
31
+        <result column="submergence_depth" property="submergenceDepth"/>
32
+    </resultMap>
33
+    <select id="getA2DataForCalProduction" resultMap="BaseResultMap">
34
+        select *
35
+        from centralbase.cb_pc_pro_wellbore_status_daily
36
+        where well_id = #{wellId}
37
+          and (prod_date::timestamp between  #{prodDate}::timestamp - INTERVAL '2 day' and #{prodDate}::timestamp)
38
+        order by prod_date desc limit 1
39
+    </select>
40
+    <select id="getWellBoreStatusDaily" parameterType="string"
41
+            resultType="com.gct.centralbase.entity.CbPcProWellboreStatusDaily">
42
+        select *
43
+        from centralbase.cb_pc_pro_wellbore_status_daily
44
+        where well_id = #{wellId}
45
+          and (prod_date::timestamp between  #{prodDate}::timestamp - INTERVAL '2 day' and #{prodDate}::timestamp)
46
+        order by prod_date desc limit 1
47
+    </select>
48
+</mapper>

+ 27 - 0
src/main/java/com/gct/tool/mapper/centralbase/CbPcProWellboreVolDailyMapper.java

@@ -0,0 +1,27 @@
1
+package com.gct.tool.mapper.centralbase;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
+import com.gct.centralbase.entity.CbPcProWellboreVolDaily;
7
+import org.apache.ibatis.annotations.Mapper;
8
+import org.apache.ibatis.annotations.Param;
9
+
10
+import java.util.Map;
11
+
12
+/**
13
+ * <p>
14
+ * 采出井井筒生产日数据 Mapper 接口
15
+ * </p>
16
+ *
17
+ * @author wsy
18
+ * @since 2021-01-19
19
+ */
20
+@Mapper
21
+public interface CbPcProWellboreVolDailyMapper extends BaseMapper<CbPcProWellboreVolDaily> {
22
+    CbPcProWellboreVolDaily getWellBoreVolDaily(String wellId,String prodDate);
23
+
24
+    CbPcProWellboreVolDaily getA2DataForCalVolDaily(@Param("wellName") String wellName, @Param("dataTime") String dataTime);
25
+
26
+    Page<Map<String,Object>> getCbPcProWellBoreVolDaily(IPage<Map<String,Object>> page, @Param("sql") String sql);
27
+}

+ 74 - 0
src/main/java/com/gct/tool/mapper/centralbase/CbPcProWellboreVolDailyMapper.xml

@@ -0,0 +1,74 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.gct.centralbase.mapper.CbPcProWellboreVolDailyMapper">
4
+
5
+    <cache flushInterval="6000000" size="5096"/>
6
+
7
+    <!-- 通用查询映射结果 -->
8
+    <resultMap id="BaseResultMap" type="com.gct.centralbase.entity.CbPcProWellboreVolDaily">
9
+        <result column="well_id" property="wellId"/>
10
+        <result column="prod_date" property="prodDate"/>
11
+        <result column="prod_time" property="prodTime"/>
12
+        <result column="liq_prod_daily" property="liqProdDaily"/>
13
+        <result column="oil_prod_daily" property="oilProdDaily"/>
14
+        <result column="water_prod_daily" property="waterProdDaily"/>
15
+        <result column="gas_prod_daily" property="gasProdDaily"/>
16
+        <result column="water_cut" property="waterCut"/>
17
+        <result column="sand_content_ratio" property="sandContentRatio"/>
18
+        <result column="gas_oil_ratio" property="gasOilRatio"/>
19
+        <result column="gas_fluid_content" property="gasFluidContent"/>
20
+        <result column="gas_chloride_content" property="gasChlorideContent"/>
21
+        <result column="stim_key_id" property="stimKeyId"/>
22
+        <result column="water_gas_ratio" property="waterGasRatio"/>
23
+        <result column="remarks" property="remarks"/>
24
+        <result column="stim_content" property="stimContent"/>
25
+    </resultMap>
26
+    <resultMap id="map2" type="com.gct.centralbase.entity.CbPcProWellboreVolDaily">
27
+        <result column="well_id" property="wellId"/>
28
+        <result column="prod_date" property="prodDate"/>
29
+        <result column="prod_time" property="prodTime"/>
30
+        <result column="liq_prod_daily" property="liqProdDaily"/>
31
+        <result column="oil_prod_daily" property="oilProdDaily"/>
32
+        <result column="water_prod_daily" property="waterProdDaily"/>
33
+        <result column="gas_prod_daily" property="gasProdDaily"/>
34
+        <result column="water_cut" property="waterCut"/>
35
+        <result column="sand_content_ratio" property="sandContentRatio"/>
36
+        <result column="gas_oil_ratio" property="gasOilRatio"/>
37
+        <result column="gas_fluid_content" property="gasFluidContent"/>
38
+        <result column="gas_chloride_content" property="gasChlorideContent"/>
39
+        <result column="stim_key_id" property="stimKeyId"/>
40
+        <result column="water_gas_ratio" property="waterGasRatio"/>
41
+        <result column="remarks" property="remarks"/>
42
+        <result column="stim_content" property="stimContent"/>
43
+        <result column="org_id" property="orgId"/>
44
+    </resultMap>
45
+    <select id="getWellBoreVolDaily" parameterType="string"
46
+            resultType="com.gct.centralbase.entity.CbPcProWellboreVolDaily">
47
+        select *
48
+        from centralbase.cb_pc_pro_wellbore_vol_daily
49
+        where well_id = #{wellId}
50
+          and (prod_date::timestamp between  #{prodDate}::timestamp - INTERVAL '2 day' and #{prodDate}::timestamp)
51
+        order by prod_date desc limit 1
52
+    </select>
53
+    <select id="getA2DataForCalVolDaily" parameterType="string" resultMap="BaseResultMap">
54
+
55
+        select *
56
+        from centralbase.cb_pc_pro_wellbore_vol_daily
57
+        where well_id = #{wellName}
58
+          and (prod_date::timestamp between  #{dataTime}::timestamp - INTERVAL '2 day' and #{dataTime}::timestamp)
59
+        order by prod_date desc limit 1
60
+    </select>
61
+
62
+    <!--<select id="getCbPcProWellBoreVolDaily" resultMap="BaseResultMap">
63
+        select centralbase.cb_pc_pro_wellbore_vol_daily.*, centralbase.cb_cd_well_source.org_id as org_id
64
+        from centralbase.cb_pc_pro_wellbore_vol_daily,
65
+             centralbase.cb_cd_well_source
66
+        where prod_date::date = #{prodDate}:: timestamp :: date
67
+          and cb_pc_pro_wellbore_vol_daily.well_id = cb_cd_well_source.well_id
68
+            limit #{pageSize} offset (#{curPage}-1)*#{pageSize}
69
+    </select>-->
70
+
71
+    <select id="getCbPcProWellBoreVolDaily" resultType="java.util.Map">
72
+        ${sql}
73
+    </select>
74
+</mapper>

+ 45 - 0
src/main/java/com/gct/tool/quartztask/LoadBaseDataTask.java

@@ -0,0 +1,45 @@
1
+package com.gct.tool.quartztask;
2
+
3
+import org.quartz.JobExecutionContext;
4
+import org.quartz.JobExecutionException;
5
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
6
+import org.springframework.http.HttpEntity;
7
+import org.springframework.http.HttpHeaders;
8
+import org.springframework.http.MediaType;
9
+import org.springframework.http.ResponseEntity;
10
+import org.springframework.scheduling.quartz.QuartzJobBean;
11
+import org.springframework.web.client.RestTemplate;
12
+
13
+/**
14
+ * @author xusirui 2023/7/9
15
+ */
16
+public class LoadBaseDataTask extends QuartzJobBean {\
17
+
18
+    RestTemplate restTemplate;
19
+
20
+    public LoadBaseDataTask(){
21
+        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
22
+        applicationContext.register(RestTemplate.class);
23
+        applicationContext.refresh();
24
+        restTemplate= (RestTemplate) applicationContext.getBean("restTemplate");
25
+    }
26
+
27
+    public String getToken(){
28
+        HttpHeaders headers = new HttpHeaders();
29
+        headers.setContentType(MediaType.APPLICATION_JSON);
30
+        HttpEntity request1 = new HttpEntity<>(request, headers);
31
+        log.info("请求报文:{}",request);
32
+
33
+        ResponseEntity<String> jsonObjectResponseEntity = restTemplate.postForEntity(url, request1, String.class);
34
+        String resp = jsonObjectResponseEntity.getBody();
35
+        log.info("响应报文:{}",resp);
36
+
37
+    }
38
+
39
+
40
+    @Override
41
+    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
42
+
43
+
44
+    }
45
+}

+ 15 - 0
src/main/java/com/gct/tool/quartztask/ProduceTask.java

@@ -0,0 +1,15 @@
1
+package com.gct.tool.quartztask;
2
+
3
+import org.quartz.JobExecutionContext;
4
+import org.quartz.JobExecutionException;
5
+import org.springframework.scheduling.quartz.QuartzJobBean;
6
+
7
+/**
8
+ * @author xusirui 2023/7/9
9
+ */
10
+public class ProduceTask extends QuartzJobBean {
11
+    @Override
12
+    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
13
+
14
+    }
15
+}

+ 0 - 1
src/main/java/com/gct/tool/service/centralbase/CbCdWellSourceServiceImpl.java

@@ -2,7 +2,6 @@ package com.gct.tool.service.centralbase;
2 2
 
3 3
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
4 4
 import com.gct.tool.entity.centralbase.CbCdWellSource;
5
-import com.gct.tool.mapper.centralbase.CbCdWellSourceMapper;
6 5
 import org.springframework.stereotype.Service;
7 6
 
8 7
 import java.util.ArrayList;

+ 2 - 3
src/main/resources/application-pro.yml

@@ -55,6 +55,5 @@ swagger:
55 55
     key-name: token
56 56
   enabled: true
57 57
 
58
-gt-total: 24
59
-begin-date: 2022-11-28
60
-end-date: 2022-12-08
58
+auth:
59
+  hostList: 10.79.32.183:9001