Explorar el Código

时实数据查询优化

hanqingsong hace 4 años
padre
commit
72188610b2

+ 3 - 3
depot-intelligent/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);

+ 29 - 12
depot-intelligent/src/main/java/com/chinaitop/depot/intelligent/grainsituation/mapper/TTestdataMapper.xml

@@ -80,7 +80,7 @@
80 80
     </where>
81 81
   </sql>
82 82
   <sql id="Base_Column_List" >
83
-    id, org_id, storehouse, house, time, inTemp, inH, outTemp, outH, max, min, avg, data_source, 
83
+    id, org_id, storehouse, house, time, inTemp, inH, outTemp, outH, max, min, avg, data_source,
84 84
     updatetime, iLq_yq
85 85
   </sql>
86 86
   <sql id="Blob_Column_List" >
@@ -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 = 163
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
depot-intelligent/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
depot-intelligent/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);

+ 2 - 1
depot-web/src/main/resources/static/app/intelligent/grainInspect/service/realTimeDataService.js

@@ -10,7 +10,8 @@ angular.module('app.intelligent').service("realTimeDataService", function($http,
10 10
             params : {
11 11
                 pageNum : pageInfo.pageNum,
12 12
                 pageSize : pageInfo.pageSize,
13
-                storehouse : search == undefined ? "":search.storehouse
13
+                storehouse : search == undefined ? "":search.storehouse,
14
+                orgId : $rootScope.orgInfo.orgId
14 15
             }
15 16
         }).then(function successCallback(response) {
16 17
             // 请求成功执行代码