瀏覽代碼

change to mysql

kerry 5 年之前
父節點
當前提交
d55ef1ff2a

+ 10 - 0
elastic-load-data/config/application-mysql.yml 查看文件

@@ -0,0 +1,10 @@
1
+database:
2
+  #url: jdbc:mysql:replication://192.168.10.210:6446,192.168.10.210:6447/fmmp?serverTimezone=Asia/Shanghai
3
+  url: jdbc:mysql://192.168.10.210:6446/fmmp?serverTimezone=Asia/Shanghai
4
+  user: root
5
+  password: R00T@mysql
6
+elasticsearch:
7
+  host: 192.168.10.241:9200,192.168.10.242:9200,192.168.10.243:9200
8
+  schema: http
9
+  user: elastic
10
+  password: abcd!234

+ 1 - 1
elastic-load-data/config/application.yml 查看文件

@@ -1,3 +1,3 @@
1 1
 profile:
2
-  active: dev
2
+  active: mysql
3 3
 #  active: production

+ 6 - 0
elastic-load-data/pom.xml 查看文件

@@ -95,6 +95,12 @@
95 95
             <groupId>cglib</groupId>
96 96
             <artifactId>cglib</artifactId>
97 97
         </dependency>
98
+        <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
99
+        <dependency>
100
+            <groupId>mysql</groupId>
101
+            <artifactId>mysql-connector-java</artifactId>
102
+            <version>8.0.18</version>
103
+        </dependency>
98 104
 
99 105
     </dependencies>
100 106
 

+ 3 - 2
elastic-load-data/src/main/java/com/vcarecity/test/module/ServiceModule.java 查看文件

@@ -2,7 +2,7 @@ package com.vcarecity.test.module;
2 2
 
3 3
 import com.google.inject.AbstractModule;
4 4
 import com.vcarecity.test.service.ObtainDataService;
5
-import com.vcarecity.test.service.oracle.OracleObtainDataServiceImpl;
5
+import com.vcarecity.test.service.mysql.MySQLObtainDataServiceImpl;
6 6
 
7 7
 /**
8 8
  * @author Kerry on 19/12/09
@@ -11,6 +11,7 @@ import com.vcarecity.test.service.oracle.OracleObtainDataServiceImpl;
11 11
 public class ServiceModule extends AbstractModule {
12 12
     @Override
13 13
     protected void configure() {
14
-        bind(ObtainDataService.class).to(OracleObtainDataServiceImpl.class);
14
+        //bind(ObtainDataService.class).to(OracleObtainDataServiceImpl.class);
15
+        bind(ObtainDataService.class).to(MySQLObtainDataServiceImpl.class);
15 16
     }
16 17
 }

+ 73 - 0
elastic-load-data/src/main/java/com/vcarecity/test/service/mysql/MySQLObtainDataServiceImpl.java 查看文件

@@ -0,0 +1,73 @@
1
+package com.vcarecity.test.service.mysql;
2
+
3
+import com.google.inject.Inject;
4
+import com.vcarecity.test.entity.UnitAgencyEntity;
5
+import com.vcarecity.test.service.ObtainDataService;
6
+import com.vcarecity.test.typehandler.TypeHandler;
7
+import lombok.extern.slf4j.Slf4j;
8
+
9
+import javax.sql.DataSource;
10
+import java.sql.Connection;
11
+import java.sql.PreparedStatement;
12
+import java.sql.ResultSet;
13
+import java.sql.SQLException;
14
+import java.util.List;
15
+
16
+/**
17
+ * @author VcKerry on 12/18/19
18
+ */
19
+
20
+@Slf4j
21
+public class MySQLObtainDataServiceImpl implements ObtainDataService {
22
+
23
+    //language=mysql
24
+    private static final String OB_SQL = "SELECT TU.UNIT_ID,\n" +
25
+            "       TU.DTU_NO,\n" +
26
+            "       TU.PUSER_CODE,\n" +
27
+            "       TAG.AGENCY_ID,\n" +
28
+            "       TAG.AGENCY_PATH,\n" +
29
+            "       TAG.AGENCY_NAME,\n" +
30
+            "       TB.BUILDING_ID,\n" +
31
+            "       TB.NAME_OF_BUILDING,\n" +
32
+            "       TUT.UNIT_TYPE_ID,\n" +
33
+            "       TUT.UNIT_TYPE\n" +
34
+            "FROM T_UNIT TU\n" +
35
+            "         INNER JOIN T_AGENCY TAG ON TU.AGENCY_ID = TAG.AGENCY_ID AND TU.ISDELETED = 0\n" +
36
+            "         INNER JOIN T_BUILDING TB ON TB.BUILDING_ID = TU.BUILDING_ID\n" +
37
+            "         INNER JOIN T_UNIT_TYPE TUT ON TUT.UNIT_TYPE_ID = TU.UNIT_TYPE_ID  limit ?,?";
38
+
39
+    private final DataSource dataSource;
40
+    private final TypeHandler typeHandler;
41
+
42
+    @Inject
43
+    public MySQLObtainDataServiceImpl(DataSource dataSource,
44
+                                      TypeHandler typeHandler) {
45
+        this.dataSource = dataSource;
46
+        this.typeHandler = typeHandler;
47
+        logger.info("MySQLObtainDataServiceImpl. dataSource = {}", dataSource);
48
+    }
49
+
50
+    @Override
51
+    public List<UnitAgencyEntity> queryUnitAgencyDataByPage(int page, int size) {
52
+
53
+        logger.debug("SQL = {}. page = {}, size = {}", OB_SQL, page, size);
54
+
55
+        int begin = page * size;
56
+        int end =  size;
57
+
58
+        try (Connection connection = dataSource.getConnection();
59
+             final PreparedStatement ps = connection.prepareStatement(OB_SQL)) {
60
+            ps.setInt(1, begin);
61
+            ps.setInt(2, end);
62
+
63
+            try (ResultSet resultSet = ps.executeQuery()) {
64
+                return typeHandler.resultHandler(resultSet, UnitAgencyEntity.class);
65
+            } catch (IllegalAccessException | InstantiationException e) {
66
+                e.printStackTrace();
67
+            }
68
+        } catch (SQLException e) {
69
+            e.printStackTrace();
70
+        }
71
+        return null;
72
+    }
73
+}

+ 3 - 3
elastic-load-data/src/main/java/com/vcarecity/test/service/oracle/OracleObtainDataServiceImpl.java 查看文件

@@ -79,10 +79,10 @@ public class OracleObtainDataServiceImpl implements ObtainDataService {
79 79
             "                TB.BUILDING_ID,\n" +
80 80
             "                TB.NAME_OF_BUILDING,\n" +
81 81
             "                TUT.UNIT_TYPE_ID,\n" +
82
-            "                TUT.UNIT_TYPE," +
82
+            "                TUT.UNIT_TYPE,\n" +
83 83
             "                ROWNUM RN\n" +
84
-            "         FROM T_AGENCY TAG\n" +
85
-            "                  INNER JOIN T_UNIT TU ON TU.AGENCY_ID = TAG.AGENCY_ID AND TU.ISDELETED = 0\n" +
84
+            "         FROM T_UNIT TU\n" +
85
+            "                  INNER JOIN T_AGENCY TAG ON TU.AGENCY_ID = TAG.AGENCY_ID AND TU.ISDELETED = 0\n" +
86 86
             "                  INNER JOIN T_BUILDING TB ON TB.BUILDING_ID = TU.BUILDING_ID\n" +
87 87
             "                  INNER JOIN T_UNIT_TYPE TUT ON TUT.UNIT_TYPE_ID = TU.UNIT_TYPE_ID\n" +
88 88
             "         where ROWNUM <= ?\n" +

+ 16 - 2
elastic-publish-service/pom.xml 查看文件

@@ -29,11 +29,18 @@
29 29
             <artifactId>mybatis-spring-boot-starter</artifactId>
30 30
             <version>2.1.1</version>
31 31
         </dependency>
32
+
32 33
         <dependency>
33
-            <groupId>oracle.jdbc</groupId>
34
-            <artifactId>ojdbc8</artifactId>
34
+            <groupId>org.springframework.boot</groupId>
35
+            <artifactId>spring-boot-starter-data-redis</artifactId>
35 36
         </dependency>
36 37
 
38
+
39
+        <!-- <dependency>
40
+             <groupId>oracle.jdbc</groupId>
41
+             <artifactId>ojdbc8</artifactId>
42
+         </dependency>-->
43
+
37 44
         <dependency>
38 45
             <groupId>org.elasticsearch.client</groupId>
39 46
             <artifactId>elasticsearch-rest-high-level-client</artifactId>
@@ -53,6 +60,13 @@
53 60
             <scope>provided</scope>
54 61
         </dependency>
55 62
 
63
+        <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
64
+        <dependency>
65
+            <groupId>mysql</groupId>
66
+            <artifactId>mysql-connector-java</artifactId>
67
+            <version>8.0.18</version>
68
+        </dependency>
69
+
56 70
         <dependency>
57 71
             <groupId>org.springframework.boot</groupId>
58 72
             <artifactId>spring-boot-starter-test</artifactId>

+ 28 - 0
elastic-publish-service/src/main/java/com/vcarecity/publish/config/RedisConfig.java 查看文件

@@ -0,0 +1,28 @@
1
+package com.vcarecity.publish.config;
2
+
3
+import org.springframework.context.annotation.Bean;
4
+import org.springframework.context.annotation.Configuration;
5
+import org.springframework.data.redis.connection.RedisConnectionFactory;
6
+import org.springframework.data.redis.core.RedisTemplate;
7
+import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
8
+import org.springframework.data.redis.serializer.StringRedisSerializer;
9
+
10
+/**
11
+ * @author VcKerry on 12/18/19
12
+ */
13
+
14
+@Configuration
15
+public class RedisConfig {
16
+
17
+    @Bean
18
+    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
19
+        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
20
+        redisTemplate.setConnectionFactory(connectionFactory);
21
+        redisTemplate.setKeySerializer(new StringRedisSerializer());
22
+        redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
23
+        redisTemplate.setHashKeySerializer(new StringRedisSerializer());
24
+        redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
25
+        return redisTemplate;
26
+    }
27
+
28
+}

+ 9 - 0
elastic-publish-service/src/main/java/com/vcarecity/publish/constants/CheckConstant.java 查看文件

@@ -0,0 +1,9 @@
1
+package com.vcarecity.publish.constants;
2
+
3
+/**
4
+ * @author VcKerry on 12/18/19
5
+ */
6
+
7
+public class CheckConstant {
8
+    public static final long CHECK_TIME_INTERVAL = 1000 * 3 * 60;
9
+}

+ 31 - 31
elastic-publish-service/src/main/java/com/vcarecity/publish/elastic/service/impl/ElasticUpdateServiceImpl.java 查看文件

@@ -62,7 +62,6 @@ public class ElasticUpdateServiceImpl implements ElasticUpdateService {
62 62
         params.put("dtuNo", "000000000001");
63 63
         params.put("puserCode", "/0/000000000001/1/12345678/");
64 64
 
65
-
66 65
         UpdateByQueryRequest request = new UpdateByQueryRequest("unit-agency");
67 66
         request.setQuery(QueryBuilders.termQuery("unitId", 12345678));
68 67
         request.setMaxDocs(1);
@@ -88,8 +87,15 @@ public class ElasticUpdateServiceImpl implements ElasticUpdateService {
88 87
                 updateList.add(uae);
89 88
             }
90 89
         }
90
+
91
+        logger.info("key = {}, update = {}, delete = {}", key, updateList.size(), deleteId.size());
92
+        logger.debug("delete; {} : {}", key, deleteId);
93
+
91 94
         // 先删除
92
-        deleteByQuery(key, deleteId);
95
+        if (!deleteId.isEmpty()) {
96
+            this.deleteByQuery(key, deleteId);
97
+        }
98
+
93 99
         if (updateList.isEmpty()) {
94 100
             return;
95 101
         }
@@ -97,7 +103,7 @@ public class ElasticUpdateServiceImpl implements ElasticUpdateService {
97 103
         List<UnitAgencyMergeEntity> addData = updateDataByQuery(key, updateList);
98 104
 
99 105
         // 添加数据
100
-        addElasticData(addData);
106
+        this.addElasticData(addData);
101 107
     }
102 108
 
103 109
 
@@ -116,19 +122,15 @@ public class ElasticUpdateServiceImpl implements ElasticUpdateService {
116 122
     @Override
117 123
     public List<UnitAgencyMergeEntity> updateDataByQuery(String key, List<UnitAgencyMergeEntity> data) throws IOException {
118 124
         List<UnitAgencyMergeEntity> addList = new ArrayList<>();
119
-
125
+        final BeanCopier beanCopier = BeanCopier.create(UnitAgencyMergeEntity.class, UnitAgencyDetailEntity.class, false);
120 126
         for (UnitAgencyMergeEntity item : data) {
121 127
 
122
-            Map<String, Object> params = objectMapper.convertValue(item, new TypeReference<Map<String, Object>>() {
123
-                @Override
124
-                public Type getType() {
125
-                    return super.getType();
126
-                }
127
-            });
128
+            Map<String, Object> params = createElasticDataMap(beanCopier, item);
129
+            Object value = params.get(key);
130
+            params.remove(key);
128 131
 
129 132
             UpdateByQueryRequest request = new UpdateByQueryRequest(INDEX);
130
-            request.setQuery(QueryBuilders.termQuery(key, params.get(key)));
131
-
133
+            request.setQuery(QueryBuilders.termQuery(key, value));
132 134
             request.setScript(new Script(ScriptType.INLINE, "painless", getPainlessCode(params), params));
133 135
 
134 136
             BulkByScrollResponse response = restHighLevelClient.updateByQuery(request, RequestOptions.DEFAULT);
@@ -153,32 +155,14 @@ public class ElasticUpdateServiceImpl implements ElasticUpdateService {
153 155
         List<Map<String, Object>> saveResult = new ArrayList<>(data.size());
154 156
 
155 157
         for (UnitAgencyMergeEntity item : data) {
156
-            List<Integer> agencyIds = AgencyPathUtil.splitAgencyId(item.getAgencyPath());
157
-            List<String> agencyPathDetail = agencyService.getAgencyPathDetail(agencyIds);
158
-
159
-            UnitAgencyDetailEntity target = new UnitAgencyDetailEntity();
160
-            beanCopier.copy(item, target, null);
161
-
162
-            target.setAgencyDetail(String.join("", agencyPathDetail));
163
-
164
-            Map<String, Object> map = objectMapper.convertValue(target, new TypeReference<Map<String, Object>>() {
165
-                @Override
166
-                public Type getType() {
167
-                    return super.getType();
168
-                }
169
-            });
170
-            final Map<String, Integer> queryMap = AgencyPathUtil.agencyPathQueryMap(agencyIds);
171
-            map.putAll(queryMap);
172
-
158
+            Map<String, Object> map = createElasticDataMap(beanCopier, item);
173 159
             saveResult.add(map);
174
-
175 160
         }
176 161
         if (saveResult.isEmpty()) {
177 162
             return;
178 163
         }
179 164
         try {
180 165
             BulkRequest bulkRequest = new BulkRequest();
181
-
182 166
             for (Map<String, Object> val : saveResult) {
183 167
                 IndexRequest indexRequest = createIndexRequest(INDEX, val);
184 168
                 bulkRequest.add(indexRequest);
@@ -188,7 +172,23 @@ public class ElasticUpdateServiceImpl implements ElasticUpdateService {
188 172
         } catch (IOException e) {
189 173
             e.printStackTrace();
190 174
         }
175
+    }
191 176
 
177
+    private Map<String, Object> createElasticDataMap(BeanCopier beanCopier, UnitAgencyMergeEntity item) {
178
+        List<Integer> agencyIds = AgencyPathUtil.splitAgencyId(item.getAgencyPath());
179
+        List<String> agencyPathDetail = agencyService.getAgencyPathDetail(agencyIds);
180
+        UnitAgencyDetailEntity target = new UnitAgencyDetailEntity();
181
+        beanCopier.copy(item, target, null);
182
+        target.setAgencyDetail(String.join("", agencyPathDetail));
183
+        Map<String, Object> map = objectMapper.convertValue(target, new TypeReference<Map<String, Object>>() {
184
+            @Override
185
+            public Type getType() {
186
+                return super.getType();
187
+            }
188
+        });
189
+        final Map<String, Integer> queryMap = AgencyPathUtil.agencyPathQueryMap(agencyIds);
190
+        map.putAll(queryMap);
191
+        return map;
192 192
     }
193 193
 
194 194
 

+ 22 - 9
elastic-publish-service/src/main/java/com/vcarecity/publish/service/impl/CheckTimeServiceImpl.java 查看文件

@@ -1,14 +1,14 @@
1 1
 package com.vcarecity.publish.service.impl;
2 2
 
3
+import com.vcarecity.publish.constants.CheckConstant;
3 4
 import com.vcarecity.publish.service.CheckTimeService;
4 5
 import com.vcarecity.publish.util.DateUtil;
6
+import org.springframework.data.redis.core.RedisTemplate;
5 7
 import org.springframework.stereotype.Service;
6 8
 
7 9
 import java.time.LocalDateTime;
8 10
 import java.time.ZoneId;
9 11
 import java.util.Date;
10
-import java.util.Map;
11
-import java.util.concurrent.ConcurrentHashMap;
12 12
 
13 13
 /**
14 14
  * @author VcKerry on 12/17/19
@@ -17,22 +17,35 @@ import java.util.concurrent.ConcurrentHashMap;
17 17
 @Service
18 18
 public class CheckTimeServiceImpl implements CheckTimeService {
19 19
 
20
-    private final Map<String, Long> timeCache = new ConcurrentHashMap<>(4);
21 20
 
21
+    public static final String REDIS_KEY_PREFIX = "elastic:";
22
+
23
+    private final RedisTemplate<String, Object> redisTemplate;
24
+
25
+
26
+    public CheckTimeServiceImpl(RedisTemplate<String, Object> redisTemplate) {
27
+        this.redisTemplate = redisTemplate;
28
+    }
22 29
 
23 30
     @Override
24 31
     public String getLastDateTime(String key) {
32
+        String redisKey = REDIS_KEY_PREFIX + key;
25 33
 
26
-        Long aLong = timeCache.get(key);
27
-        if (aLong == null) {
28
-            aLong = System.currentTimeMillis();
29
-            timeCache.put(key, aLong);
34
+        Object value = redisTemplate.opsForValue().get(redisKey);
35
+
36
+        if (value != null) {
37
+            LocalDateTime.ofInstant(new Date(Long.parseLong(value.toString())).toInstant(), ZoneId.systemDefault()).format(DateUtil.DATE_TIME_FORMATTER);
30 38
         }
31
-        return LocalDateTime.ofInstant(new Date(aLong).toInstant(), ZoneId.systemDefault()).format(DateUtil.DATE_TIME_FORMATTER);
39
+
40
+        long last = System.currentTimeMillis() - CheckConstant.CHECK_TIME_INTERVAL;
41
+        redisTemplate.opsForValue().set(redisKey, last);
42
+
43
+        return LocalDateTime.ofInstant(new Date(last).toInstant(), ZoneId.systemDefault()).format(DateUtil.DATE_TIME_FORMATTER);
32 44
     }
33 45
 
34 46
     @Override
35 47
     public void setLastDateTime(String key, long lastDateTime) {
36
-        timeCache.put(key, lastDateTime);
48
+        String redisKey = REDIS_KEY_PREFIX + key;
49
+        redisTemplate.opsForValue().set(redisKey, lastDateTime);
37 50
     }
38 51
 }

+ 18 - 5
elastic-publish-service/src/main/java/com/vcarecity/publish/task/CheckUpdateTask.java 查看文件

@@ -6,6 +6,7 @@ import com.vcarecity.publish.mapper.UnitMapper;
6 6
 import com.vcarecity.publish.service.CheckTimeService;
7 7
 import com.vcarecity.publish.elastic.service.ElasticUpdateService;
8 8
 import com.vcarecity.publish.util.DateUtil;
9
+import lombok.extern.slf4j.Slf4j;
9 10
 import org.springframework.stereotype.Component;
10 11
 
11 12
 import java.time.LocalDateTime;
@@ -17,6 +18,7 @@ import java.util.List;
17 18
  * @author Kerry on 19/12/11
18 19
  */
19 20
 
21
+@Slf4j
20 22
 @Component
21 23
 public class CheckUpdateTask {
22 24
 
@@ -36,22 +38,28 @@ public class CheckUpdateTask {
36 38
         this.unitMapper = unitMapper;
37 39
     }
38 40
 
39
-
40
-    public void checkTask() {
41
+    public void checkUpdateTask() {
41 42
 
42 43
         // 当前更新时间
43 44
         long curCheckTime = System.currentTimeMillis();
44 45
         String toDateTime = LocalDateTime.ofInstant(new Date(curCheckTime).toInstant(), ZoneId.systemDefault()).format(DateUtil.DATE_TIME_FORMATTER);
45 46
 
47
+
46 48
         List<UnitAgencyMergeEntity> updateUaList;
47 49
         String fromDateTime;
48 50
 
49 51
         // 获取上一次的时间
50 52
         fromDateTime = checkTimeService.getLastDateTime("T_UNIT");
53
+
54
+        logger.info("start checkUpdateTask on T_UNIT from:{}. to:{}", fromDateTime, toDateTime);
55
+
51 56
         try {
52 57
             updateUaList = unitMapper.findUpdateUaList(fromDateTime, toDateTime);
58
+
59
+            logger.debug("T_UNIT update list size = {}", updateUaList.size());
60
+
53 61
             if (!updateUaList.isEmpty()) {
54
-                elasticUpdateService.updateUnit(updateUaList);
62
+                elasticUpdateService.handlerDataChange("unitId", updateUaList);
55 63
             }
56 64
             checkTimeService.setLastDateTime("T_UNIT", curCheckTime);
57 65
             updateUaList.clear();
@@ -59,12 +67,17 @@ public class CheckUpdateTask {
59 67
             e.printStackTrace();
60 68
         }
61 69
 
62
-
63 70
         fromDateTime = checkTimeService.getLastDateTime("T_AGENCY");
71
+
72
+        logger.info("start checkUpdateTask on T_AGENCY from:{}. to:{}", fromDateTime, toDateTime);
73
+
64 74
         try {
65 75
             updateUaList = agencyMapper.findUpdateUaList(fromDateTime, toDateTime);
76
+
77
+            logger.debug("T_AGENCY update list size = {}", updateUaList.size());
78
+
66 79
             if (!updateUaList.isEmpty()) {
67
-                elasticUpdateService.updateAgency(updateUaList);
80
+                elasticUpdateService.handlerDataChange("agencyId", updateUaList);
68 81
             }
69 82
             checkTimeService.setLastDateTime("T_AGENCY", curCheckTime);
70 83
             updateUaList.clear();

+ 10 - 5
elastic-publish-service/src/main/resources/application-dev.yml 查看文件

@@ -2,9 +2,9 @@ server:
2 2
   port: 7080
3 3
 spring:
4 4
   datasource:
5
-    url: jdbc:oracle:thin:@192.168.10.112:1521:orcl
6
-    username: C##FMMP
7
-    password: vcare~1(^_^)
5
+    url: jdbc:mysql:replication://192.168.10.210:6446,192.168.10.210:6447/fmmp?serverTimezone=Asia/Shanghai
6
+    username: root
7
+    password: R00T@mysql
8 8
   elasticsearch:
9 9
     rest:
10 10
       uris:
@@ -13,8 +13,11 @@ spring:
13 13
         - http://192.168.10.243:9200
14 14
       username: elastic
15 15
       password: abcd!234
16
-
17
-debug: true
16
+  redis:
17
+    database: 2
18
+    host: 192.168.10.112
19
+    port: 6379
20
+    password: admin~1(^-^)
18 21
 logging:
19 22
   level:
20 23
     com:
@@ -22,3 +25,5 @@ logging:
22 25
 mybatis:
23 26
   type-aliases-package: com.vcarecity.publish.entity
24 27
   mapper-locations: classpath:mapper/*.xml
28
+
29
+debug: true

+ 2 - 4
elastic-publish-service/src/main/resources/mapper/AgencyMapper.xml 查看文件

@@ -37,12 +37,10 @@
37 37
                TB.BUILDING_ID,
38 38
                TB.NAME_OF_BUILDING,
39 39
                TUT.UNIT_TYPE_ID,
40
-               TUT.UNIT_TYPE,
41
-               ROWNUM RN
40
+               TUT.UNIT_TYPE
42 41
         FROM (select *
43 42
               from T_AGENCY I_TAG
44
-              where UPDATESTAMP between to_date('${fromDate}', 'YYYY-MM-DD HH24:MI:SS')
45
-                        and to_date('${toDate}', 'YYYY-MM-DD HH24:MI:SS')
43
+              where UPDATESTAMP between '${fromDate}' and '${toDate}'
46 44
              ) TAG
47 45
                  INNER JOIN T_UNIT TU ON TU.AGENCY_ID = TAG.AGENCY_ID
48 46
                  INNER JOIN T_BUILDING TB ON TB.BUILDING_ID = TU.BUILDING_ID

+ 2 - 4
elastic-publish-service/src/main/resources/mapper/UnitMapper.xml 查看文件

@@ -35,12 +35,10 @@
35 35
                TB.BUILDING_ID,
36 36
                TB.NAME_OF_BUILDING,
37 37
                TUT.UNIT_TYPE_ID,
38
-               TUT.UNIT_TYPE,
39
-               ROWNUM RN
38
+               TUT.UNIT_TYPE
40 39
         FROM (select *
41 40
               from T_UNIT I_TU
42
-              where UPDATESTAMP between to_date('${fromDate}', 'YYYY-MM-DD HH24:MI:SS')
43
-                        and to_date('${toDate}', 'YYYY-MM-DD HH24:MI:SS')
41
+              where UPDATESTAMP between '${fromDate}' and '${toDate}'
44 42
              ) TU
45 43
                  INNER JOIN T_AGENCY TAG ON TU.AGENCY_ID = TAG.AGENCY_ID
46 44
                  INNER JOIN T_BUILDING TB ON TB.BUILDING_ID = TU.BUILDING_ID

+ 11 - 3
elastic-publish-service/src/test/java/com/vcarecity/publish/mapper/UnitMapperTest.java 查看文件

@@ -1,10 +1,12 @@
1 1
 package com.vcarecity.publish.mapper;
2 2
 
3 3
 import com.vcarecity.publish.entity.UnitAgencyMergeEntity;
4
+import com.vcarecity.publish.util.DateUtil;
4 5
 import org.junit.jupiter.api.Test;
5 6
 import org.springframework.beans.factory.annotation.Autowired;
6 7
 import org.springframework.boot.test.context.SpringBootTest;
7 8
 
9
+import java.time.LocalDateTime;
8 10
 import java.util.List;
9 11
 
10 12
 @SpringBootTest
@@ -22,12 +24,18 @@ class UnitMapperTest {
22 24
 
23 25
     @Test
24 26
     public void findUpdateUaList() {
25
-        String from = "2018-12-23 15:00:00";
26
-        String to = "2018-12-24 15:00:00";
27
+
28
+        LocalDateTime now = LocalDateTime.now();
29
+        LocalDateTime last = now.minusHours(1L);
30
+
31
+        String from = last.format(DateUtil.DATE_TIME_FORMATTER);
32
+        String to = now.format(DateUtil.DATE_TIME_FORMATTER);
27 33
         List<UnitAgencyMergeEntity> updateUaList = unitMapper.findUpdateUaList(from, to);
28 34
 
35
+        System.out.println(updateUaList.size());
36
+
29 37
         for (UnitAgencyMergeEntity unitAgencyMergeEntity : updateUaList) {
30
-            System.out.println(unitAgencyMergeEntity);
38
+            // System.out.println(unitAgencyMergeEntity);
31 39
         }
32 40
     }
33 41
 }

+ 16 - 0
elastic-publish-service/src/test/java/com/vcarecity/publish/task/CheckUpdateTaskTest.java 查看文件

@@ -0,0 +1,16 @@
1
+package com.vcarecity.publish.task;
2
+
3
+import org.junit.jupiter.api.Test;
4
+import org.springframework.beans.factory.annotation.Autowired;
5
+import org.springframework.boot.test.context.SpringBootTest;
6
+
7
+@SpringBootTest
8
+class CheckUpdateTaskTest {
9
+    @Autowired
10
+    private CheckUpdateTask checkUpdateTask;
11
+
12
+    @Test
13
+    void checkUpdateTask() {
14
+        checkUpdateTask.checkUpdateTask();
15
+    }
16
+}