Parcourir la source

添加查询条件-代码优化-01

hanqingsong il y a 5 ans
Parent
commit
28e07a4d45

+ 9 - 9
depot-intelligent/src/main/java/com/chinaitop/depot/intelligent/grainsituation/controller/TemperatureRecordController.java

@@ -1,5 +1,6 @@
1 1
 package com.chinaitop.depot.intelligent.grainsituation.controller;
2 2
 
3
+import com.chinaitop.depot.intelligent.common.ConstantCommon;
3 4
 import com.chinaitop.depot.intelligent.grainsituation.model.TTestdata;
4 5
 import com.chinaitop.depot.intelligent.grainsituation.model.TTestdataLayer;
5 6
 import com.chinaitop.depot.intelligent.grainsituation.service.TPointsService;
@@ -17,9 +18,7 @@ import io.swagger.annotations.ApiImplicitParams;
17 18
 import io.swagger.annotations.ApiOperation;
18 19
 import org.apache.commons.lang.StringUtils;
19 20
 import org.springframework.beans.factory.annotation.Autowired;
20
-import org.springframework.beans.factory.annotation.Value;
21 21
 import org.springframework.http.MediaType;
22
-import org.springframework.web.bind.annotation.RequestBody;
23 22
 import org.springframework.web.bind.annotation.RequestMapping;
24 23
 import org.springframework.web.bind.annotation.RequestMethod;
25 24
 import org.springframework.web.bind.annotation.RestController;
@@ -50,19 +49,21 @@ public class TemperatureRecordController {
50 49
             @ApiImplicitParam(name = "vCfCode", value = "仓库名称", paramType = "query"),
51 50
             @ApiImplicitParam(name = "tType", value = "检测类型0测温,1粮油,2测水分", paramType = "query")
52 51
     })
53
-    public ResponseEntity<PageInfo<TTestdata>> getList(Integer pageNum, Integer pageSize, String vCfCode, String vDatatime, String startTime, String endTime, String tType,String orgId) {
54
-        List<TTestdata> list = null;
52
+    public ResponseEntity getList(Integer pageNum, Integer pageSize, String vCfCode, String vDatatime, String startTime, String endTime, String tType, String orgId) {
55 53
         try {
54
+            if (StringUtils.isBlank(tType))
55
+                return ResponseEntity.failed(ConstantCommon.CHECK_TYPE);
56
+            if (StringUtils.isBlank(orgId))
57
+                return ResponseEntity.failed(ConstantCommon.ORGID_NOT_NULL);
56 58
             if (null != pageNum && null != pageSize) {
57 59
                 PageHelper.startPage(pageNum, pageSize);
58 60
             }
59
-            list = temperatureRecordService.getList(vCfCode, vDatatime, startTime, endTime, tType, orgId);
61
+            PageInfo<TTestdata> list = temperatureRecordService.getList(vCfCode, vDatatime, startTime, endTime, tType, orgId);
62
+            return ResponseEntity.ok(list);
60 63
         } catch (Exception e) {
61 64
             e.printStackTrace();
62 65
             return ResponseEntity.failed(e.getMessage());
63 66
         }
64
-        PageInfo<TTestdata> pageInfo = new PageInfo<TTestdata>(list);
65
-        return ResponseEntity.ok(pageInfo);
66 67
     }
67 68
 
68 69
     /**
@@ -91,11 +92,10 @@ public class TemperatureRecordController {
91 92
     }
92 93
 
93 94
     /**
94
-     *
95 95
      * @param lqId
96 96
      * @param vCfCode
97 97
      * @param vDatatime
98
-     * @param viewFlag true: 表格数据,false: 3D三温图数据
98
+     * @param viewFlag  true: 表格数据,false: 3D三温图数据
99 99
      * @return
100 100
      */
101 101
     @RequestMapping(value = "/findByHouseAndTimes", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)

+ 2 - 7
depot-intelligent/src/main/java/com/chinaitop/depot/intelligent/grainsituation/mapper/TTestdataMapper.xml

@@ -453,10 +453,8 @@
453 453
     select
454 454
     <include refid="Base_Column_List" />
455 455
     from t_testdata
456
-    WHERE 1=1
457
-    <if test="orgId != null and orgId != ''" >
458
-      AND org_id = #{orgId}
459
-    </if>
456
+    WHERE org_id = #{orgId}
457
+    AND iLq_yq = #{tType}
460 458
     <if test="vCfCode != null and vCfCode != ''" >
461 459
       AND storehouse = #{vCfCode}
462 460
     </if>
@@ -466,9 +464,6 @@
466 464
     <if test="startTime != null and endTime != null" >
467 465
       AND time between #{startTime} AND #{endTime}
468 466
     </if>
469
-    <if test="tType != null and tType != ''" >
470
-      AND iLq_yq = #{tType}
471
-    </if>
472 467
     ORDER BY
473 468
     DATE_FORMAT(time, '%Y-%m-%d') DESC,
474 469
     storehouse

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

@@ -2,6 +2,7 @@ package com.chinaitop.depot.intelligent.grainsituation.service;
2 2
 
3 3
 import com.chinaitop.depot.intelligent.grainsituation.model.TTestdata;
4 4
 import com.chinaitop.depot.intelligent.grainsituation.model.TTestdataLayer;
5
+import com.github.pagehelper.PageInfo;
5 6
 import org.apache.ibatis.annotations.Param;
6 7
 
7 8
 import java.util.ArrayList;
@@ -9,7 +10,7 @@ import java.util.Date;
9 10
 import java.util.List;
10 11
 
11 12
 public interface TemperatureRecordService {
12
-    List<TTestdata> getList(String vCfCode, String vDatatime, String startTime, String endTime,String tType,String orgId);
13
+    PageInfo<TTestdata> getList(String vCfCode, String vDatatime, String startTime, String endTime, String tType, String orgId);
13 14
 
14 15
     List<TTestdataLayer> findByHouseAndTime(String lqId,String vCfCode, String vDatatime);
15 16
 

+ 5 - 5
depot-intelligent/src/main/java/com/chinaitop/depot/intelligent/grainsituation/service/impl/TemperatureRecordServiceImpl.java

@@ -1,12 +1,12 @@
1 1
 package com.chinaitop.depot.intelligent.grainsituation.service.impl;
2 2
 
3
-import com.alibaba.fastjson.JSON;
4 3
 import com.chinaitop.depot.intelligent.grainsituation.mapper.TTestdataLayerMapper;
5 4
 import com.chinaitop.depot.intelligent.grainsituation.mapper.TTestdataMapper;
6 5
 import com.chinaitop.depot.intelligent.grainsituation.model.*;
7 6
 import com.chinaitop.depot.intelligent.grainsituation.service.TemperatureRecordService;
8 7
 import com.chinaitop.depot.intelligent.utils.DateUtils;
9 8
 import com.chinaitop.depot.intelligent.utils.JsonToObjectUtils;
9
+import com.github.pagehelper.PageInfo;
10 10
 import com.google.common.collect.Lists;
11 11
 import com.google.common.collect.Maps;
12 12
 import org.apache.commons.lang.StringUtils;
@@ -22,12 +22,11 @@ import java.util.stream.Collectors;
22 22
 public class TemperatureRecordServiceImpl implements TemperatureRecordService {
23 23
     @Resource
24 24
     private TTestdataMapper tTestdataMapper;
25
-
26 25
     @Resource
27 26
     private TTestdataLayerMapper tTestdataLayerMapper;
28 27
 
29 28
     @Override
30
-    public List<TTestdata> getList(String vCfCode, String vDatatime, String startTime, String endTime, String tType, String orgId) {
29
+    public PageInfo<TTestdata> getList(String vCfCode, String vDatatime, String startTime, String endTime, String tType, String orgId) {
31 30
         HashMap<String, String> map = Maps.newHashMap();
32 31
         map.put("vCfCode", vCfCode);
33 32
         map.put("tType", tType);
@@ -40,10 +39,11 @@ public class TemperatureRecordServiceImpl implements TemperatureRecordService {
40 39
             map.put("time1", vDatatime + DateUtils.startTime);
41 40
             map.put("time2", vDatatime + DateUtils.endTime);
42 41
         }
43
-        return tTestdataMapper.selectByMultipleConditions(map);
42
+        List<TTestdata> tTestdata = tTestdataMapper.selectByMultipleConditions(map);
43
+        PageInfo<TTestdata> pageInfo = new PageInfo<TTestdata>(tTestdata);
44
+        return pageInfo;
44 45
     }
45 46
 
46
-
47 47
     @Override
48 48
     public List<TTestdataLayer> findByHouseAndTime(String lqId, String vCfCode, String vDatatime) {
49 49
         TTestdataLayerExample tTestdataLayerExample = new TTestdataLayerExample();