瀏覽代碼

新增测温数据导入功能及修改测温uuid

hanqingsong 5 年之前
父節點
當前提交
8b861f0f77

+ 2 - 7
pom.xml

@@ -54,13 +54,8 @@
54 54
         </dependency>
55 55
         <dependency>
56 56
             <groupId>org.apache.cxf</groupId>
57
-            <artifactId>cxf-rt-frontend-jaxws</artifactId>
58
-            <version>3.1.6</version>
59
-        </dependency>
60
-        <dependency>
61
-            <groupId>org.apache.cxf</groupId>
62
-            <artifactId>cxf-rt-transports-http</artifactId>
63
-            <version>3.1.6</version>
57
+            <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
58
+            <version>3.2.4</version>
64 59
         </dependency>
65 60
         <!--添加webservice end-->
66 61
         <dependency>

+ 0 - 21
src/main/java/com/DepotIntelligentApplication.java

@@ -23,27 +23,6 @@ public class DepotIntelligentApplication {
23 23
 		SpringApplication.run(DepotIntelligentApplication.class, args);
24 24
 	}
25 25
 
26
-	/**
27
-	 * 注册一个dispatcherServlet,解决增加ws之后https接口访问不了问题
28
-	 */
29
-	@Bean
30
-	public ServletRegistrationBean restServlet(){
31
-		//注解扫描上下文
32
-		AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
33
-		//base package
34
-		applicationContext.scan("com.unissoft");
35
-		//通过构造函数指定dispatcherServlet的上下文
36
-		DispatcherServlet rest_dispatcherServlet = new DispatcherServlet(applicationContext);
37
-		//用ServletRegistrationBean包装servlet
38
-		ServletRegistrationBean registrationBean = new ServletRegistrationBean(rest_dispatcherServlet);
39
-		registrationBean.setLoadOnStartup(1);
40
-		//指定urlmapping
41
-		registrationBean.addUrlMappings("/*");
42
-		//指定name,如果不指定默认为dispatcherServlet
43
-		registrationBean.setName("rest");
44
-		return registrationBean;
45
-	}
46
-
47 26
 	@Bean
48 27
 	public ThreadPoolTaskScheduler threadPoolTaskScheduler() {
49 28
 		return new ThreadPoolTaskScheduler();

+ 85 - 0
src/main/java/com/chinaitop/depot/intelligent/grainsituation/controller/TemperImportController.java

@@ -0,0 +1,85 @@
1
+package com.chinaitop.depot.intelligent.grainsituation.controller;
2
+
3
+import com.chinaitop.depot.intelligent.grainsituation.service.TemperImportService;
4
+import com.chinaitop.depot.intelligent.utils.ImportServiceImpl;
5
+import com.unissoft.model.TypeEnum;
6
+import io.swagger.annotations.ApiImplicitParam;
7
+import io.swagger.annotations.ApiImplicitParams;
8
+import io.swagger.annotations.ApiOperation;
9
+import org.springframework.beans.factory.annotation.Autowired;
10
+import org.springframework.http.MediaType;
11
+import org.springframework.web.bind.annotation.RequestMapping;
12
+import org.springframework.web.bind.annotation.RequestMethod;
13
+import org.springframework.web.bind.annotation.RestController;
14
+import org.springframework.web.multipart.MultipartFile;
15
+
16
+import javax.annotation.Resource;
17
+import javax.servlet.http.HttpServletRequest;
18
+import java.util.ArrayList;
19
+import java.util.HashMap;
20
+import java.util.List;
21
+import java.util.Map;
22
+
23
+/**
24
+ * @author qingsong.han
25
+ * @description: 粮温历史数据导入
26
+ * @create 2020-08-03 9:39
27
+ */
28
+@RestController
29
+@RequestMapping(value = "/intelligentTemperature")
30
+public class TemperImportController {
31
+//    final static Logger logger = LoggerFactory.getLogger(GrainPushsServiceImpl.class);
32
+
33
+    @Resource
34
+    private ImportServiceImpl importService;
35
+    @Autowired
36
+    private TemperImportService temperImportService;
37
+
38
+    /**
39
+     * 导入excel
40
+     *
41
+     * @param file     文件
42
+     * @param fileType 类型:如xlsx
43
+     * @param orgId    组织机构id
44
+     * @return
45
+     */
46
+    @RequestMapping(value = "/importFile", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
47
+    @ApiOperation(value = "导入excel", notes = "导入excel")
48
+    @ApiImplicitParams({
49
+            @ApiImplicitParam(name = "file", value = "文件数据", paramType = "query"),
50
+            @ApiImplicitParam(name = "fileType", value = "文件后缀", paramType = "query"),
51
+            @ApiImplicitParam(name = "rootPath", value = "路径", paramType = "query"),
52
+            @ApiImplicitParam(name = "orgId", value = "组织机构id", paramType = "query")
53
+    })
54
+    public Map<String, Object> importFile(MultipartFile file, String fileType, HttpServletRequest request, Integer orgId) {
55
+
56
+        String[] titleArr = {"测温线缆列号(X)", "测温线缆行号(Y)", "测温点高度(Z)", "温度值"};//第一行的title
57
+        boolean[] emptyArr = {false, false, false, false};//指定列可为空,不可为空值为false.
58
+
59
+        List<List<String>> list = new ArrayList<List<String>>();//该list为数据返回的list
60
+        Map<String, Object> fileMap = new HashMap<>();
61
+        String errormsg = null;
62
+        try {
63
+            errormsg = importService.importFile(file, fileType, request, titleArr, emptyArr, list, 3);
64
+
65
+            if (errormsg != null && !"".equals(errormsg)) {
66
+                fileMap.put("errormsg", errormsg);
67
+                return fileMap;
68
+            }
69
+
70
+            //查询代储点名称和代储库名称对应的id
71
+            Map<String, Object> agentMap = importService.temperData(file, fileType, request);
72
+
73
+            if (list.size() > 0) {
74
+                errormsg = temperImportService.importData(list, orgId, agentMap);
75
+            }
76
+        } catch (Exception e) {
77
+            fileMap.put("errormsg", TypeEnum.ED.getCode()+",请检查模板数据!");
78
+            e.printStackTrace();
79
+            return fileMap;
80
+        }
81
+        fileMap.put("errormsg", errormsg);
82
+        return fileMap;
83
+    }
84
+
85
+}

+ 19 - 0
src/main/java/com/chinaitop/depot/intelligent/grainsituation/mapper/TemperImportMapper.java

@@ -0,0 +1,19 @@
1
+package com.chinaitop.depot.intelligent.grainsituation.mapper;
2
+
3
+import org.springframework.stereotype.Repository;
4
+
5
+import java.util.Map;
6
+
7
+/**
8
+ * @author qingsong.han
9
+ * @description:
10
+ * @create 2020-08-03 15:03
11
+ */
12
+@Repository
13
+public interface TemperImportMapper {
14
+    Map<String,Object> getNameId(Map<String, Object> agentMap);
15
+
16
+    Map<String,Object> getStorehouseId(Map<String, Object> enumData);
17
+
18
+    Map<String,Object> getWarehouseId(Map<String, Object> enumData);
19
+}

+ 67 - 0
src/main/java/com/chinaitop/depot/intelligent/grainsituation/mapper/TemperImportMapper.xml

@@ -0,0 +1,67 @@
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.chinaitop.depot.intelligent.grainsituation.mapper.TemperImportMapper" >
4
+    <select id="getNameId" parameterType="java.util.Map" resultType="java.util.HashMap">
5
+        SELECT
6
+        org_id depotid
7
+        FROM
8
+        org_info
9
+        WHERE org_name = #{depotName}
10
+    </select>
11
+    <select id="getEnumId" parameterType="java.util.Map" resultType="java.util.HashMap">
12
+        SELECT
13
+        enumId
14
+        FROM
15
+        basic_enum
16
+        WHERE
17
+        parentId = #{parentId}
18
+        AND enumName = #{enumName}
19
+    </select>
20
+    <select id="getEnumChildId" parameterType="java.util.Map" resultType="java.util.HashMap">
21
+        SELECT
22
+        enumId
23
+        FROM
24
+        basic_enum
25
+        WHERE
26
+        parentId = (
27
+        SELECT
28
+        enumId
29
+        FROM
30
+        basic_enum
31
+        WHERE
32
+        parentId = #{parentId}
33
+        AND gbCode = (
34
+        SELECT
35
+        substr(enumCode, 1, 1)
36
+        FROM
37
+        basic_enum
38
+        WHERE
39
+        parentId = #{parentId}
40
+        AND enumName = #{enumName}
41
+        )
42
+        )
43
+        AND enumName = #{enumName}
44
+    </select>
45
+    <select id="getStorehouseId" parameterType="java.util.Map" resultType="java.util.HashMap">
46
+        SELECT
47
+        storehouse_id storehouseid,
48
+        storehouse_code storehouse
49
+        FROM
50
+        basic_storehouse
51
+        WHERE del_flag = 1
52
+        AND depot_id = #{depotId}
53
+        AND storehouse_name = #{storehouseName}
54
+    </select>
55
+    <select id="getWarehouseId" parameterType="java.util.Map" resultType="java.util.HashMap">
56
+        SELECT
57
+        whouse.warehouse_id warehouseId,
58
+        warehouse_code house
59
+        FROM
60
+        basic_warehouse whouse
61
+        LEFT JOIN basic_storehouse shouse ON shouse.storehouse_id = whouse.storehouse_id
62
+        WHERE whouse.del_flag = 1
63
+        AND shouse.del_flag = 1
64
+        AND whouse.warehouse_name = #{warehouseName}
65
+        AND shouse.storehouse_id = #{storehouseId}
66
+    </select>
67
+</mapper>

+ 20 - 0
src/main/java/com/chinaitop/depot/intelligent/grainsituation/service/TemperImportService.java

@@ -0,0 +1,20 @@
1
+package com.chinaitop.depot.intelligent.grainsituation.service;
2
+
3
+import java.util.List;
4
+import java.util.Map;
5
+
6
+/**
7
+ * @author qingsong.han
8
+ * @description:
9
+ * @create 2020-08-03 14:59
10
+ */
11
+public interface TemperImportService {
12
+    /**
13
+     * 导入
14
+     *
15
+     * @param list
16
+     * @param orgId
17
+     * @return
18
+     */
19
+    String importData(List<List<String>> list, Integer orgId, Map<String, Object> agentMap);
20
+}

+ 191 - 0
src/main/java/com/chinaitop/depot/intelligent/grainsituation/service/impl/TemperImportServiceImpl.java

@@ -0,0 +1,191 @@
1
+package com.chinaitop.depot.intelligent.grainsituation.service.impl;
2
+
3
+import com.alibaba.fastjson.JSONObject;
4
+import com.chinaitop.depot.intelligent.grainsituation.mapper.TemperImportMapper;
5
+import com.chinaitop.depot.intelligent.grainsituation.model.TTestdata;
6
+import com.chinaitop.depot.intelligent.grainsituation.service.TemperImportService;
7
+import com.chinaitop.depot.intelligent.pushs.service.GrainPushsService;
8
+import com.chinaitop.depot.intelligent.utils.DateUtils;
9
+import com.chinaitop.depot.intelligent.utils.ParameterUtil;
10
+import org.apache.commons.lang.StringUtils;
11
+import org.springframework.stereotype.Service;
12
+
13
+import javax.annotation.Resource;
14
+import java.math.BigDecimal;
15
+import java.util.*;
16
+import java.util.regex.Pattern;
17
+import java.util.stream.Collectors;
18
+
19
+/**
20
+ * @author qingsong.han
21
+ * @description:
22
+ * @create 2020-08-03 15:00
23
+ */
24
+@Service
25
+public class TemperImportServiceImpl implements TemperImportService {
26
+    @Resource
27
+    private TemperImportMapper temperImportMapper;
28
+    @Resource
29
+    private GrainPushsService pushsService;
30
+
31
+    @Override
32
+    public String importData(List<List<String>> list, Integer orgId, Map<String, Object> agentMap) {
33
+        String msg = "";
34
+
35
+        TTestdata agentTemper = new TTestdata();
36
+        Map<String, Object> enumData = new HashMap<>();
37
+
38
+        Map<String, Object> agentsMap = temperImportMapper.getNameId(agentMap);
39
+        if (ParameterUtil.isnull(agentsMap) || ParameterUtil.isnull(agentsMap.get("depotid"))) {
40
+            msg = "粮库信息查询不到,请确认后再导入!";
41
+            return msg;
42
+        }
43
+
44
+        //仓房名称
45
+        enumData.put("storehouseName", agentMap.get("storehouseName"));
46
+        enumData.put("depotId", agentsMap.get("depotid"));
47
+        Map<String, Object> storehouseId = temperImportMapper.getStorehouseId(enumData);
48
+        if (ParameterUtil.isnull(storehouseId)) {
49
+            msg = "仓房信息查询不到,请确认后再导入!";
50
+            return msg;
51
+        }
52
+        //货位名称
53
+        enumData.put("warehouseName", agentMap.get("warehouseName"));
54
+        enumData.put("storehouseId", storehouseId.get("storehouseid"));
55
+        Map<String, Object> warehouseId = temperImportMapper.getWarehouseId(enumData);
56
+        if (ParameterUtil.isnull(warehouseId)) {
57
+            msg = "货位信息查询不到,请确认后再导入!";
58
+            return msg;
59
+        }
60
+        agentTemper.setStorehouse(storehouseId.get("storehouse").toString());
61
+        if (!(agentMap.get("houseTemperature") != null && agentMap.get("houseTemperature").toString().matches("^(-)?\\d+(.\\d{1,2})?$"))) { // 带1-2位小数的正数或负数
62
+            msg = "仓温输入值为字符!";
63
+            return msg;
64
+        }
65
+        agentTemper.setInh(new BigDecimal(agentMap.get("houseTemperature").toString()));
66
+        if (!(agentMap.get("houseHumidity") != null && agentMap.get("houseHumidity").toString().matches("^[0.0-9.0]+$"))) { // [0-9]没办法识别小数,[0.0-9.0]可以识别小数和整数
67
+            msg = "仓湿输入值为字符!";
68
+            return msg;
69
+        }
70
+        agentTemper.setOuttemp(new BigDecimal(agentMap.get("houseHumidity").toString()));
71
+        if (!(agentMap.get("gasTemperature") != null && agentMap.get("gasTemperature").toString().matches("^(-)?\\d+(.\\d{1,2})?$"))) { // 带1-2位小数的正数或负数
72
+            msg = "气温输入值为字符!";
73
+            return msg;
74
+        }
75
+        agentTemper.setOuth(new BigDecimal(agentMap.get("gasTemperature").toString()));
76
+        if (!(agentMap.get("gasHumidity") != null && agentMap.get("gasHumidity").toString().matches("^[0.0-9.0]+$"))) {
77
+            msg = "气湿输入值为字符!";
78
+            return msg;
79
+        }
80
+        // 格式化效验时间
81
+        String vDate = agentMap.get("detectionTime").toString();
82
+        if (StringUtils.isNotBlank(vDate)) {
83
+            if (!(DateUtils.dateStringInterval(vDate))) {
84
+                return "检测时间格式为(2020-08-08 10:52:13),其中:为英文符号!";
85
+            }
86
+        } else {
87
+            return "检测时间为空!";
88
+        }
89
+
90
+        Map<String, Object> pointMap = new HashMap<>();//一行温度数据
91
+        List<Map<String, Object>> pointList = new ArrayList<>();//温度集合数据
92
+
93
+        // mapList 数据封装
94
+        List<String> listMap = new ArrayList<>();
95
+        // 仓房信息map数据
96
+        Map<String, Object> houseMap = new HashMap<>();
97
+
98
+        houseMap.put("storehouse", storehouseId.get("storehouse"));
99
+        houseMap.put("house", warehouseId.get("house"));
100
+        // 处理时间
101
+        String string = agentMap.get("detectionTime").toString();
102
+        Date date = DateUtils.stringToData(string);
103
+        String s = DateUtils.formatDateYMDHMS(date);
104
+        houseMap.put("time", s);
105
+
106
+        houseMap.put("ilqYq", "0");
107
+        houseMap.put("intemp", agentMap.get("houseTemperature"));
108
+        houseMap.put("inh", agentMap.get("houseHumidity"));
109
+        houseMap.put("outtemp", agentMap.get("gasTemperature"));
110
+        houseMap.put("outh", agentMap.get("gasHumidity"));
111
+
112
+        Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
113
+        // z值顺序效验容器
114
+        Integer zV = 1;
115
+        for (int i = 0; i < list.size(); i++) {
116
+            List<String> revList = list.get(i);
117
+            for (int j = 0; j < revList.size(); j++) {
118
+                switch (j) {
119
+                    case 0:
120
+                        //测温线缆行号(X)
121
+                        pointMap = new HashMap<>();
122
+                        if (!pattern.matcher(revList.get(j)).matches()) {
123
+                            msg = "行不是整数,请确认后再导入!";
124
+                            return msg;
125
+                        }
126
+                        pointMap.put("x", revList.get(j));
127
+                        break;
128
+                    case 1:
129
+                        //测温线缆列号(Y)
130
+                        pointMap.put("y", revList.get(j));
131
+                        if (!pattern.matcher(revList.get(j)).matches()) {
132
+                            msg = "列不是整数,请确认后再导入!";
133
+                            return msg;
134
+                        }
135
+                        break;
136
+                    case 2:
137
+                        //测温点高度(Z)
138
+                        pointMap.put("z", revList.get(j));
139
+                        if (!pattern.matcher(revList.get(j)).matches()) {
140
+                            msg = "高度不是整数,请确认后再导入!";
141
+                            return msg;
142
+                        }
143
+                        // z值顺序效验
144
+                        if (zV <= Integer.parseInt(revList.get(j))) {
145
+                            zV = Integer.parseInt(revList.get(j));
146
+                        } else {
147
+                            msg = "测温点高度(Z),请顺序填写(1,1,1.2,2,2.3,3,3)!";
148
+                            return msg;
149
+                        }
150
+                        break;
151
+                    case 3:
152
+                        //温度值
153
+                        pointMap.put("temp", revList.get(j));
154
+                        break;
155
+                    default:
156
+                        break;
157
+                }
158
+            }
159
+            pointList.add(pointMap);
160
+        }
161
+        /*// 导入数据层倒叙重新赋值
162
+        // 计算层数
163
+        Map<Integer, List<Map<String, Object>>> z = pointList.stream().collect(Collectors.groupingBy(tem -> Integer.parseInt(tem.get("z").toString())));
164
+        Integer size = z.size();
165
+        // 初始比对计数器
166
+        int i1 = 1;
167
+        // 执行+1时机
168
+        int i = pointList.size() / size;
169
+        // 修改z层(倒叙)
170
+        for (Map<String, Object> pm : pointList) {
171
+            for (String k : pm.keySet()) {
172
+                if ("z".equals(k)) {
173
+                    pm.put(k, size.toString());
174
+                }
175
+            }
176
+            if (i1 == i) {
177
+                size--;
178
+            }
179
+            i1++;
180
+            if (i1 > i) {
181
+                i1 = 1;
182
+            }
183
+        }*/
184
+        houseMap.put("points", pointList); // 层温数据
185
+        listMap.add(JSONObject.toJSONString(houseMap));
186
+        String replace = listMap.toString().replace(" ", "");
187
+        pushsService.uploadGrainTemperatureData("source_ls", replace);
188
+        return msg;
189
+    }
190
+
191
+}

+ 11 - 13
src/main/java/com/chinaitop/depot/intelligent/pushs/service/impl/GrainPushsServiceImpl.java

@@ -49,9 +49,6 @@ public class GrainPushsServiceImpl implements GrainPushsService {
49 49
     private TWarningThresholdHistoryMapper tWarningThresholdHistoryMapper;
50 50
 
51 51
     @Resource
52
-    private UuidUtils uuidUtils;
53
-
54
-    @Resource
55 52
     private WarningMessage warningMessage;
56 53
 
57 54
     @Resource
@@ -95,7 +92,8 @@ public class GrainPushsServiceImpl implements GrainPushsService {
95 92
                 }
96 93
                 String orgId = temperatureRecordService.getOrgId(cDcsCodes.get(0));
97 94
                 ts.forEach(obj -> {
98
-                    String testdataId = uuidUtils.getCodeId(orgId, "t_testdata");
95
+                    String testdataId = UuidUtils.getCode();
96
+                    logger.info("testdataId: {}", testdataId);
99 97
                     TTestdata tTestdata = (TTestdata) obj;
100 98
                     String house = tTestdata.getStorehouse();
101 99
                     Date time = tTestdata.getTime();
@@ -141,7 +139,7 @@ public class GrainPushsServiceImpl implements GrainPushsService {
141 139
                         BigDecimal wh = threshold.getThreshold();
142 140
                         //-1 小于 0 等于 1 大于
143 141
                         if (wholeMax.compareTo(wh) == 1 && !wholeMax.toString().equals("250.0") && ilqYq.equals("0")) {
144
-                            String tid = uuidUtils.getCodeId(orgId, "t_warning_threshold_history");
142
+                            String tid = UuidUtils.getCode();
145 143
                             String desc = "整仓粮温(" + wholeMax + ")高于阈值(" + wh + ")";
146 144
                             TWarningThresholdHistory tt = warningMessage.saveWThreshold(tid, house, threshold, wholeMax, wh, time, desc, dataSource2, "0", "0");
147 145
                             tWarningThresholdHistorieList.add(tt);
@@ -152,7 +150,7 @@ public class GrainPushsServiceImpl implements GrainPushsService {
152 150
                             BigDecimal ww = wWarning.getThreshold();
153 151
                             BigDecimal subtract = wh.subtract(ww).setScale(2, RoundingMode.HALF_UP); //高温减去阈值
154 152
                             if (wholeMax.compareTo(subtract) == 1 && ilqYq.equals("0")) {
155
-                                String tid = uuidUtils.getCodeId(orgId, "t_warning_threshold_history");
153
+                                String tid = UuidUtils.getCode();
156 154
                                 String desc = "整仓粮温(" + wholeMax + ")高于阈值(" + subtract + ")";
157 155
                                 TWarningThresholdHistory tt = warningMessage.saveWThreshold(tid, house, wWarning, wholeMax, subtract, time, desc, dataSource2, "0", "1");
158 156
                                 tWarningThresholdHistorieList.add(tt);
@@ -165,7 +163,7 @@ public class GrainPushsServiceImpl implements GrainPushsService {
165 163
                         BigDecimal wl = wLowest.getThreshold().setScale(2, RoundingMode.HALF_UP);
166 164
                         //-1 小于 0 等于 1 大于
167 165
                         if (wMin.compareTo(wl) == -1 && !wMin.toString().equals("250.0") && ilqYq.equals("0")) {
168
-                            String tid = uuidUtils.getCodeId(orgId, "t_warning_threshold_history");
166
+                            String tid = UuidUtils.getCode();
169 167
                             String desc = "整仓粮温(" + wMin + ")低于阈值(" + wl + ")";
170 168
                             TWarningThresholdHistory tt = warningMessage.saveWThreshold(tid, house, wLowest, wMin, wl, time, desc, dataSource2, "0", "0");
171 169
                             tWarningThresholdHistorieList.add(tt);
@@ -176,7 +174,7 @@ public class GrainPushsServiceImpl implements GrainPushsService {
176 174
                             BigDecimal ww = wWarning.getThreshold();
177 175
                             BigDecimal wadd = wl.add(ww);//高温减去阈值
178 176
                             if (wMin.compareTo(wadd) == -1 && ilqYq.equals("0")) {
179
-                                String tid = uuidUtils.getCodeId(orgId, "t_warning_threshold_history");
177
+                                String tid = UuidUtils.getCode();
180 178
                                 String desc = "整仓粮温(" + wMin + ")低于阈值(" + wadd + ")";
181 179
                                 TWarningThresholdHistory tt = warningMessage.saveWThreshold(tid, house, wWarning, wMin, wadd, time, desc, dataSource2, "0", "1");
182 180
                                 tWarningThresholdHistorieList.add(tt);
@@ -211,7 +209,7 @@ public class GrainPushsServiceImpl implements GrainPushsService {
211 209
                         tTestdataLayer.setLmin(lsyerMin);
212 210
                         tTestdataLayer.setLhouse(house);
213 211
                         tTestdataLayer.setLtime(time);
214
-                        tTestdataLayer.setId(uuidUtils.getCodeId(orgId, "t_testdata_layer"));
212
+                        tTestdataLayer.setId(UuidUtils.getCode());
215 213
                         tTestdataLayer.setOrgId(orgId);
216 214
                         tTestdataLayer.setDataSource(dataSource2);
217 215
                         tTestdataLayer.setLqId(testdataId);
@@ -235,7 +233,7 @@ public class GrainPushsServiceImpl implements GrainPushsService {
235 233
                                         //-1 小于 0 等于 1 大于
236 234
                                         if (te.compareTo(threshold1) == 1 && !te.toString().equals("250.0")) {
237 235
                                             // tid id,cfCdoe 仓房编码,threshold 报警实体包括orgID,tthreshold 检测值,wThreshold 预警或报警设置值,date 检测时间,desc 描述信息,mode 0测温,1测虫,2测气,warning 0报警,1预警
238
-                                            String tid = uuidUtils.getCodeId(orgId, "t_warning_threshold_history");
236
+                                            String tid = UuidUtils.getCode();
239 237
                                             String desc = "第" + keyL + "层,第" + keyR + "行,第" + keyC + "列粮温(" + te + ")高于阈值(" + threshold1 + ")";
240 238
                                             TWarningThresholdHistory tt = warningMessage.saveWThreshold(tid, house, threshold, te, threshold1, time, desc, dataSource2, "0", "0");
241 239
                                             tWarningThresholdHistorieList.add(tt);
@@ -246,7 +244,7 @@ public class GrainPushsServiceImpl implements GrainPushsService {
246 244
                                             BigDecimal ww = wWarning.getThreshold();
247 245
                                             BigDecimal subtract = threshold1.subtract(ww).setScale(2, RoundingMode.HALF_UP); //高温减去阈值
248 246
                                             if (te.compareTo(subtract) == 1 && ilqYq.equals("0")) {
249
-                                                String tid = uuidUtils.getCodeId(orgId, "t_warning_threshold_history");
247
+                                                String tid = UuidUtils.getCode();
250 248
                                                 String desc = "第" + keyL + "层,第" + keyR + "行,第" + keyC + "列粮温(" + te + ")高于阈值(" + subtract + ")";
251 249
                                                 TWarningThresholdHistory tt = warningMessage.saveWThreshold(tid, house, wWarning, te, subtract, time, desc, dataSource2, "0", "1");
252 250
                                                 tWarningThresholdHistorieList.add(tt);
@@ -258,7 +256,7 @@ public class GrainPushsServiceImpl implements GrainPushsService {
258 256
                                         BigDecimal wl = wLowest.getThreshold().setScale(2, RoundingMode.HALF_UP);
259 257
                                         //-1 小于 0 等于 1 大于
260 258
                                         if (te.compareTo(wl) == -1 && !te.toString().equals("250.0")) {
261
-                                            String tid = uuidUtils.getCodeId(orgId, "t_warning_threshold_history");
259
+                                            String tid = UuidUtils.getCode();
262 260
                                             String desc = "第" + keyL + "层,第" + keyR + "行,第" + keyC + "列粮温(" + te + ")低于阈值(" + wl + ")";
263 261
                                             TWarningThresholdHistory tt = warningMessage.saveWThreshold(tid, house, wLowest, te, wl, time, desc, dataSource2, "0", "0");
264 262
                                             tWarningThresholdHistorieList.add(tt);
@@ -269,7 +267,7 @@ public class GrainPushsServiceImpl implements GrainPushsService {
269 267
                                             BigDecimal ww = wWarning.getThreshold();
270 268
                                             BigDecimal wadd = wl.add(ww).setScale(2, RoundingMode.HALF_UP);//高温减去阈值
271 269
                                             if (te.compareTo(wadd) == -1 && ilqYq.equals("0")) {
272
-                                                String tid = uuidUtils.getCodeId(orgId, "t_warning_threshold_history");
270
+                                                String tid = UuidUtils.getCode();
273 271
                                                 String desc = "第" + keyL + "层,第" + keyR + "行,第" + keyC + "列粮温(" + te + ")低于阈值(" + wadd + ")";
274 272
                                                 TWarningThresholdHistory tt = warningMessage.saveWThreshold(tid, house, wWarning, te, wadd, time, desc, dataSource2, "0", "1");
275 273
                                                 tWarningThresholdHistorieList.add(tt);

+ 36 - 0
src/main/java/com/chinaitop/depot/intelligent/utils/DateUtils.java

@@ -62,4 +62,40 @@ public class DateUtils {
62 62
         }
63 63
         return null;
64 64
     }
65
+
66
+    /**
67
+     * 用于效验粮温导入excel时间字符串效验
68
+     *
69
+     * @param str 时间字符串(yyyy-MM-dd HH:mm:ss)
70
+     * @return boolean
71
+     */
72
+    public static boolean dateStringInterval(String str) {
73
+        boolean flag = false; // 返回
74
+        str = str.trim(); // 去除时间首尾空格
75
+        int ymd = 0; // -符计数器
76
+        int hms = 0; // 英文:计数器
77
+        int ds = 0; // 日和小时中间空格计数器
78
+        // 效验时间
79
+        for (int i = 0; i < str.length(); i++) {
80
+            if (str.codePointAt(i) == 45) { // 英文字符-对应的是45,并查看有几个-
81
+                ymd++;
82
+            } else if (str.codePointAt(i) == 58) { // 英文字符:对应的是58,并查看有几个:
83
+                hms++;
84
+            } else if (str.codePointAt(i) == 32) { // 日和小时中间空格,空格对应32
85
+                ds++;
86
+            }
87
+        }
88
+        // 时间格式效验,规定格式(yyyy-MM-dd HH:mm:ss)
89
+        if (ymd == 2 && hms == 2 && ds == 1) { // 必须为(yyyy-MM-dd)两个-,和(HH:mm:ss) 两个英文:
90
+            flag = true;
91
+        }
92
+        return flag;
93
+    }
94
+
95
+    // 获取日期格式化
96
+    public static String formatDateYMDHMS(Date date) {
97
+        SimpleDateFormat dateTime = new SimpleDateFormat("yyyyMMddHHmmss");
98
+        return dateTime.format(date);
99
+    }
100
+
65 101
 }

+ 48 - 0
src/main/java/com/chinaitop/depot/intelligent/utils/ExcelImportUtils.java

@@ -0,0 +1,48 @@
1
+package com.chinaitop.depot.intelligent.utils;
2
+
3
+import org.apache.poi.ss.usermodel.Cell;
4
+import org.apache.poi.ss.usermodel.Row;
5
+
6
+/**
7
+ * @auther mafy
8
+ * @createtime 2017/10/26 0026
9
+ */
10
+public class ExcelImportUtils {
11
+
12
+    //是否是2003的excel,返回true是2003
13
+    public static boolean isExcel2003(String filePath)  {
14
+        return filePath.matches("^.+\\.(?i)(xls)$");
15
+    }
16
+
17
+    //是否是2007的excel,返回true是2007
18
+    public static boolean isExcel2007(String filePath)  {
19
+        return filePath.matches("^.+\\.(?i)(xlsx)$");
20
+    }
21
+
22
+    /**
23
+     * 验证EXCEL文件
24
+     * @param filePath
25
+     * @return
26
+     */
27
+    public static boolean validateExcel(String filePath){
28
+        if (filePath == null || !(isExcel2003(filePath) || isExcel2007(filePath))){
29
+            return false;
30
+        }
31
+        return true;
32
+    }
33
+
34
+    public static boolean isEmpty(String type,int index,boolean[] NotEmpty){//判断是否可为空
35
+        return NotEmpty[index];
36
+    }
37
+
38
+    //判断导入的excel是否和模板相同
39
+    public  static boolean isSame(Row row, int totalCells,String[] titleArr){
40
+        for (int i = 0; i < totalCells; i++) {
41
+            Cell cell = row.getCell(i);//第一行的每一列
42
+            if(!ParameterUtil.isequal(cell.getStringCellValue(),titleArr[i]) || (totalCells != titleArr.length)){
43
+                return false;
44
+            }
45
+        }
46
+        return true;
47
+    }
48
+}

+ 216 - 0
src/main/java/com/chinaitop/depot/intelligent/utils/ImportServiceImpl.java

@@ -0,0 +1,216 @@
1
+package com.chinaitop.depot.intelligent.utils;
2
+
3
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
4
+import org.apache.poi.ss.usermodel.*;
5
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
6
+import org.springframework.stereotype.Service;
7
+import org.springframework.util.StringUtils;
8
+import org.springframework.web.multipart.MultipartFile;
9
+
10
+import javax.servlet.http.HttpServletRequest;
11
+import java.io.File;
12
+import java.io.FileInputStream;
13
+import java.io.IOException;
14
+import java.io.InputStream;
15
+import java.util.ArrayList;
16
+import java.util.HashMap;
17
+import java.util.List;
18
+import java.util.Map;
19
+
20
+/**
21
+ * @auther mafy
22
+ * @createtime 2017/10/26 0026
23
+ * 导入公共类,直接调用importFile方法即可
24
+ */
25
+@Service
26
+public class ImportServiceImpl {
27
+
28
+
29
+
30
+    public String importFile(MultipartFile file, String fileType, HttpServletRequest request, String[] titleArr, boolean[] emptyArr, List<List<String>> lists, Integer numLines) throws Exception{
31
+
32
+        // 服务器路径
33
+        String rootPath = request.getSession().getServletContext().getRealPath("");
34
+        // 文件相对路径
35
+        String relativePath = "/upload/" + fileType;
36
+        //创建临时文件
37
+        createTemp(file,rootPath,relativePath);
38
+        //读取临时文件,并且返回错误信息
39
+        String fileAllpath = rootPath+relativePath+"/"+file.getOriginalFilename();
40
+
41
+        String retVal = readExcelValue(fileAllpath,titleArr,emptyArr,lists,numLines);
42
+
43
+        return retVal;
44
+    }
45
+
46
+    /**
47
+     * 获取第一行的代储点名称和代储库名称
48
+     * @return
49
+     * @throws Exception
50
+     */
51
+    public Map<String, Object> nameData(MultipartFile file, String fileType, HttpServletRequest request) throws Exception{
52
+        Map<String, Object> modelMap = new HashMap<String, Object>();
53
+        // 服务器路径
54
+        String rootPath = request.getSession().getServletContext().getRealPath("");
55
+        // 文件相对路径
56
+        String relativePath = "/upload/" + fileType;
57
+        //读取临时文件,并且返回错误信息
58
+        String fileAllpath = rootPath+relativePath+"/"+file.getOriginalFilename();
59
+        //获取File
60
+        File tempFile = new File(fileAllpath);
61
+        Row row = getWorkbook(tempFile,fileAllpath).getSheetAt(0).getRow(0);
62
+        //第一行第二列,第四列是名称
63
+        modelMap.put("agentName",row.getCell(1).toString());
64
+        modelMap.put("agentDepotName",row.getCell(3).toString());
65
+        //删除临时文件
66
+        if(tempFile.exists()){ tempFile.delete(); }
67
+        return modelMap;
68
+    }
69
+
70
+    /**
71
+     * 粮情信息数据
72
+     * @return
73
+     * @throws Exception
74
+     */
75
+    public Map<String, Object> temperData(MultipartFile file, String fileType, HttpServletRequest request) throws Exception{
76
+        Map<String, Object> modelMap = new HashMap<String, Object>();
77
+        // 服务器路径
78
+        String rootPath = request.getSession().getServletContext().getRealPath("");
79
+        // 文件相对路径
80
+        String relativePath = "/upload/" + fileType;
81
+        //读取临时文件,并且返回错误信息
82
+        String fileAllpath = rootPath+relativePath+"/"+file.getOriginalFilename();
83
+        //获取File
84
+        File tempFile = new File(fileAllpath);
85
+        Row row = getWorkbook(tempFile,fileAllpath).getSheetAt(0).getRow(0);
86
+        //第一行第二列,第四列是名称
87
+        modelMap.put("depotName",row.getCell(1).toString());//粮库名称
88
+        modelMap.put("storehouseName",row.getCell(3).toString());//仓房名称
89
+        modelMap.put("warehouseName",row.getCell(5).toString());//货位名称
90
+
91
+        row = getWorkbook(tempFile,fileAllpath).getSheetAt(0).getRow(1);
92
+        modelMap.put("houseTemperature",row.getCell(1).toString());//仓温
93
+        modelMap.put("houseHumidity",row.getCell(3).toString());//仓湿
94
+        modelMap.put("gasTemperature",row.getCell(5).toString());//气温
95
+
96
+        row = getWorkbook(tempFile,fileAllpath).getSheetAt(0).getRow(2);
97
+        modelMap.put("gasHumidity",row.getCell(1).toString());//气湿
98
+        modelMap.put("detectionTime",row.getCell(3).toString());//检测时间
99
+
100
+        //删除临时文件
101
+        if(tempFile.exists()){ tempFile.delete(); }
102
+        return modelMap;
103
+    }
104
+
105
+    /**
106
+     * 创建临时文件
107
+     * @param file 上传过来的文件流
108
+     * @param rootPath 根目录
109
+     * @param relativePath 相对路径
110
+     * @throws Exception
111
+     */
112
+    public void createTemp(MultipartFile file, String rootPath, String relativePath) throws Exception{
113
+        // 如路径不存在,则创建它
114
+        File directory = new File(rootPath + relativePath);
115
+        if (!directory.exists()) {
116
+            directory.mkdirs();
117
+        }
118
+        String filePath = relativePath + "/" + file.getOriginalFilename();
119
+        // 复制 文件
120
+        file.transferTo(new File(rootPath + filePath));
121
+    }
122
+
123
+
124
+    /**
125
+     * 解析Excel里面的数据,目前只支持1个sheet
126
+     * @param fileName
127
+     * @return
128
+     */
129
+    public String readExcelValue(String fileName,String[] titleArr,boolean[] emptyArr,List<List<String>> list,Integer numLines){
130
+
131
+        //获取File
132
+        File tempFile = new File(fileName);
133
+
134
+        StringBuilder errorMSG = new StringBuilder("");//错误信息收集器
135
+        int sheetNum = 1;//sheet的总数
136
+        //循环每一个sheet
137
+        for (int i = 0; i < sheetNum; i++) {
138
+            String err = everySheet(getWorkbook(tempFile,fileName).getSheetAt(i),titleArr,emptyArr,list,numLines);
139
+            if(ParameterUtil.isnotnull(err)){
140
+                errorMSG.append("第"+(i+1)+"个sheet,名称为:"+getWorkbook(tempFile,fileName).getSheetName(i)+",错误信息:"+err);
141
+            }
142
+        }
143
+
144
+        if(ParameterUtil.isequal(numLines,0)){
145
+            //删除临时文件
146
+            if(tempFile.exists()){ tempFile.delete(); }
147
+        }
148
+
149
+        return errorMSG.toString();
150
+    }
151
+
152
+
153
+    //获取workbook
154
+    private Workbook getWorkbook(File file , String FileName){
155
+        Workbook wb = null;
156
+        try {
157
+            InputStream is = new FileInputStream(file);
158
+            if(ExcelImportUtils.isExcel2007(FileName))
159
+                wb = new XSSFWorkbook(is);
160
+            else
161
+                wb = new HSSFWorkbook(is);
162
+        } catch (IOException e) {
163
+            e.printStackTrace();
164
+        }
165
+        return wb;
166
+    }
167
+
168
+
169
+    //遍历每一个sheet,获取值和错误信息
170
+    private String  everySheet(Sheet sheet,String[] titleArr,boolean[] emptyArr,List<List<String>> list,Integer numLines){
171
+        String errorMsg = "", br = "<br/>";
172
+        //得到当前sheet的Excel的行数
173
+        int totalRows=sheet.getPhysicalNumberOfRows();
174
+        //总列数
175
+        int totalCells = 0;
176
+        //得到Excel的列数(前提是有行数),从第二行算起
177
+        if(totalRows>=2 && sheet.getRow(1+numLines) != null){
178
+            totalCells=sheet.getRow(0+numLines).getPhysicalNumberOfCells();
179
+        }else{
180
+            return "请确认excel的数据";
181
+        }
182
+
183
+        if (!ExcelImportUtils.isSame(sheet.getRow(numLines),totalCells,titleArr)){ return "导入excel和模板不一致"; }//判断标题是否正确
184
+
185
+        //开始处理数据,循环Excel行数,从第二行开始。标题不入库
186
+        for(int r=(1+numLines);r<totalRows;r++){
187
+            List<String> rowList = new ArrayList<String>();
188
+            String rowMessage = "";
189
+            Row row = sheet.getRow(r);
190
+            if (row == null){
191
+                errorMsg += br+"第"+(r+1+numLines)+"行数据异常,请仔细检查!";
192
+                continue;
193
+            }
194
+
195
+            //循环Excel的列
196
+            for(int c = 0; c <totalCells; c++){
197
+                Cell cell = row.getCell(c);
198
+                if(cell == null){
199
+                    rowList.add("");
200
+                }else{
201
+                    cell.setCellType(Cell.CELL_TYPE_STRING);
202
+                    String cellVal = cell.getStringCellValue();
203
+                    if((StringUtils.isEmpty(cellVal) && !emptyArr[c])){
204
+                        errorMsg+=br+"第"+(r+1+numLines)+"行,第"+(c+1)+"列数据不可为空或者数据异常";
205
+                        rowList.add("error");
206
+                    }else{
207
+                        //正常数据处理
208
+                        rowList.add(cellVal);
209
+                    }
210
+                }
211
+                if(c == totalCells-1) list.add(rowList);//将每一行的数据添加到list中
212
+            }
213
+        }
214
+        return errorMsg;
215
+    }
216
+}

+ 1 - 0
src/main/java/com/chinaitop/depot/intelligent/utils/VerificationSourceUtils.java

@@ -15,6 +15,7 @@ public class VerificationSourceUtils {
15 15
         Map<String, String> source = Maps.newHashMap();
16 16
         source.put("source_zkyh","1");
17 17
         source.put("source_zy","0");
18
+        source.put("source_ls","2"); // 历史数据导入
18 19
         return source;
19 20
     }
20 21
 

+ 1 - 4
src/main/java/com/unissoft/serviceconfig/CxfConfig.java

@@ -14,10 +14,7 @@ import javax.xml.ws.Endpoint;
14 14
 
15 15
 @Configuration
16 16
 public class CxfConfig {
17
-    @Bean
18
-    public ServletRegistrationBean dispatcherServlet() {
19
-        return new ServletRegistrationBean(new CXFServlet(),"/intelligent/*");
20
-    }
17
+
21 18
     @Bean(name = Bus.DEFAULT_BUS_ID)
22 19
     public SpringBus springBus() {
23 20
         return new SpringBus();

+ 8 - 0
src/main/resources/bootstrap.yml

@@ -1,10 +1,18 @@
1 1
 spring:
2 2
   profiles:
3 3
     active: clouda
4
+  servlet:
5
+    multipart:
6
+      #单个文件上传大小
7
+      max-file-size: 10MB
8
+      #总数上传大小
9
+      max-request-size: 20MB
4 10
 server:
5 11
   port: 9028
6 12
   tomcat:
7 13
     uri-encoding: utf-8
14
+cxf:
15
+  path: /intelligent
8 16
 ---
9 17
 # 注册中心配置 defaultZone: http://eureka-depot:9001/eureka/
10 18
 eureka: