Quellcode durchsuchen

时实数据功能查询速度优化

hanqingsong vor 4 Jahren
Ursprung
Commit
1035a793b5

+ 3 - 3
src/main/java/com/chinaitop/depot/intelligent/grainsituation/controller/RealTimeDataController.java

@@ -47,16 +47,16 @@ public class RealTimeDataController {
47 47
             @ApiImplicitParam(name = "pageSize", value = "每页条数", paramType = "query", defaultValue = "10"),
48 48
             @ApiImplicitParam(name = "storehouse", value = "仓房编码", paramType = "query")
49 49
     })
50
-    public ResponseEntity<PageInfo<TTestdata>> getByCfCodes(Integer pageNum, Integer pageSize, String storehouse) {
50
+    public ResponseEntity<PageInfo<TTestdata>> getByCfCodes(Integer pageNum, Integer pageSize, String storehouse, String orgId) {
51 51
         List<TTestdata> list = null;
52 52
         if (StringUtils.isNotBlank(storehouse)) {
53 53
             PageHelper.startPage(1, 1);
54
-            list = grainCheckAnalyzeService.getByCfCode(storehouse);
54
+            list = grainCheckAnalyzeService.getByCfCode(storehouse, orgId);
55 55
         } else {
56 56
             if (null != pageNum && null != pageSize) {
57 57
                 PageHelper.startPage(pageNum, (pageSize == 1 ? 10 : pageSize));
58 58
             }
59
-            list = grainCheckAnalyzeService.getNewest(storehouse);
59
+            list = grainCheckAnalyzeService.getNewest(storehouse, orgId);
60 60
         }
61 61
         PageInfo<TTestdata> pageInfo = new PageInfo<>(list);
62 62
         return ResponseEntity.ok(pageInfo);

+ 28 - 11
src/main/java/com/chinaitop/depot/intelligent/grainsituation/mapper/TTestdataMapper.xml

@@ -399,18 +399,35 @@
399 399
   </select>
400 400
   <select id="getNewest" resultMap="BaseResultMap" parameterType="java.util.Map">
401 401
     SELECT
402
-    <include refid="Base_Column_List"/>
403
-    FROM
404
-    (
405
-    SELECT
406
-    <include refid="Base_Column_List"/>
402
+        t2.id,
403
+        t2.org_id,
404
+        t2.storehouse,
405
+        t2.house,
406
+        t2.time,
407
+        t2.inTemp,
408
+        t2.inH,
409
+        t2.outTemp,
410
+        t2.outH,
411
+        t2.max,
412
+        t2.min,
413
+        t2.avg,
414
+        t2.data_source,
415
+        t2.updatetime,
416
+        t2.iLq_yq
407 417
     FROM
408
-    t_testdata
409
-    ORDER BY
410
-    time DESC limit 10000000000
411
-    ) a
412
-    GROUP BY
413
-    a.storehouse
418
+        (
419
+            SELECT
420
+                MAX(time) time,
421
+                org_id
422
+            FROM
423
+                t_testdata
424
+            WHERE
425
+                org_id = #{orgId}
426
+            GROUP BY
427
+                storehouse
428
+        ) t1
429
+    LEFT JOIN t_testdata t2 ON t1.time = t2.time
430
+    AND t1.org_id = t2.org_id
414 431
   </select>
415 432
 
416 433
     <select id="getById" resultMap="ResultMapWithBLOBs" parameterType="java.lang.String">

+ 2 - 2
src/main/java/com/chinaitop/depot/intelligent/grainsituation/service/GrainCheckAnalyzeService.java

@@ -29,7 +29,7 @@ public interface GrainCheckAnalyzeService {
29 29
      * @param storehouse
30 30
      * @return
31 31
      */
32
-    List<TTestdata> getNewest(String storehouse);
32
+    List<TTestdata> getNewest(String storehouse, String orgId);
33 33
 
34
-    List<TTestdata> getByCfCode(String storehouse);
34
+    List<TTestdata> getByCfCode(String storehouse, String orgId);
35 35
 }

+ 8 - 3
src/main/java/com/chinaitop/depot/intelligent/grainsituation/service/impl/GrainCheckAnalyzeServiceImpl.java

@@ -121,17 +121,22 @@ public class GrainCheckAnalyzeServiceImpl implements GrainCheckAnalyzeService {
121 121
      * @return
122 122
      */
123 123
     @Override
124
-    public List<TTestdata> getNewest(String storehouse) {
124
+    public List<TTestdata> getNewest(String storehouse, String orgId) {
125 125
         Map<String, Object> map = new HashMap<>();
126
-        if (StringUtils.isNotBlank(storehouse))
126
+        if (StringUtils.isNotBlank(storehouse)) {
127 127
             map.put("storehouse",storehouse);
128
+        }
129
+        if (StringUtils.isNotBlank(orgId)) {
130
+            map.put("orgId",orgId);
131
+        }
128 132
         return tTestdataMapper.getNewest(map);
129 133
     }
130 134
 
131 135
     @Override
132
-    public List<TTestdata> getByCfCode(String storehouse) {
136
+    public List<TTestdata> getByCfCode(String storehouse, String orgId) {
133 137
         TTestdataExample example = new TTestdataExample();
134 138
         TTestdataExample.Criteria criteria = example.createCriteria();
139
+        criteria.andOrgIdEqualTo(orgId);
135 140
         criteria.andStorehouseEqualTo(storehouse);
136 141
         example.setOrderByClause("time desc");
137 142
         List<TTestdata> tTestdata = tTestdataMapper.selectByExample(example);