ZeroLiYi il y a 1 an
Parent
commit
25d4d0b3d3

+ 12 - 5
src/main/java/com/chinaitop/depot/basic/controller/MonitorCameraController.java

@@ -186,9 +186,16 @@ public class MonitorCameraController {
186 186
         }
187 187
         return list;
188 188
     }
189
+    /**
190
+     * 导入excel
191
+     * @param file 文件
192
+     * @param fileType 类型:如xlsx
193
+     * @return
194
+     */
189 195
 
190
-    @RequestMapping(value="/importFile")
191
-    public String importFile(MultipartFile file, String fileType, HttpServletRequest request,Integer orgId){
196
+    @RequestMapping(value="/importFile", method=RequestMethod.POST)
197
+    @ApiOperation(value="导入摄像头excel", notes = "导入摄像头excel")
198
+    public String importFile(MultipartFile file,String orgId, String fileType, HttpServletRequest request){
192 199
 
193 200
         String[] titleArr = {"摄像头名称", "摄像机别名", "所属厂商(200代表海康,300代表大华)", "账号", "密码", "硬盘录像机编号", "通道号", "IP地址",
194 201
         		"子网掩码", "网关", "设备类型(1代表球形摄像机,2代表枪式摄像机)", "设备端口", "设备型号", "所在位置(1代表仓内,2代表仓外)",
@@ -197,19 +204,19 @@ public class MonitorCameraController {
197 204
         boolean[] emptyArr = {false, false, false, false, false, false, false, false,
198 205
         		true, true, false, false, true, true,
199 206
         		true, true, true, true, true,true,false,true,true};//指定列可为空,不可为空值为false.
200
-
207
+        String orgId1=orgId.replaceAll("\\D+", "");
201 208
         List<List<String>> list = new ArrayList<List<String>>();//该list为数据返回的list
202 209
         String errormsg = null;
203 210
         try {
204 211
 
205
-        	errormsg = importService.importFile(uploadPath, file, fileType, request, titleArr, emptyArr, list);
212
+        	errormsg = importService.importFile(uploadPath, file, fileType,request,titleArr, emptyArr, list);
206 213
 
207 214
         	if (errormsg != null && !"".equals(errormsg)) {
208 215
         		return errormsg;
209 216
         	}
210 217
 
211 218
             if (list.size()>0) {
212
-            	errormsg = cameraService.importData(list, orgId);
219
+            	errormsg = cameraService.importData(list, Integer.parseInt(orgId1));
213 220
 
214 221
             	System.out.println(list);
215 222
             	System.out.println(errormsg);

+ 2 - 2
src/main/java/com/chinaitop/depot/basic/controller/MonitorNvrController.java

@@ -229,7 +229,7 @@ public class MonitorNvrController {
229 229
      * @return
230 230
      */
231 231
     @RequestMapping(value="/importFile")
232
-    public String importFile(MultipartFile file, String fileType, HttpServletRequest request,Integer orgid){
232
+    public String importFile(MultipartFile file, String fileType, HttpServletRequest request,String orgid){
233 233
 
234 234
         String[] titleArr = {"NVR名称","NVR别名","所属厂商","NVR型号","NVR类型","NVRIP","NVR网关地址","NVR子网掩码","NVR账号","NVR密码","NVR端口","NVR管理员","安装位置","备注"};//第一行的title
235 235
         boolean[] emptyArr = {true   ,  false  ,  false , true  ,  false   ,  false   ,    true     ,    true   ,   false  , false   ,false   ,   true,   true ,   true};//指定列可为空,不可为空值为false.
@@ -248,7 +248,7 @@ public class MonitorNvrController {
248 248
 
249 249
             //这句返回后台判断
250 250
             if (list.size()>0) {
251
-            	errormsg = nvrService.importData(list,orgid);
251
+            	errormsg = nvrService.importData(list,Integer.parseInt(orgid));
252 252
             }
253 253
         } catch (Exception e) {
254 254
             e.printStackTrace();

+ 2 - 0
src/main/java/com/chinaitop/depot/basic/mapper/CameraStorehouseMapper.java

@@ -32,4 +32,6 @@ public interface CameraStorehouseMapper {
32 32
     int updateByPrimaryKey(CameraStorehouse record);
33 33
 
34 34
     Map<String,Object> getStorehouseId(Map<String, Object> map);
35
+
36
+    Map<String, Object> getCameraIndexCode(Map<String, Object> map);
35 37
 }

+ 5 - 0
src/main/java/com/chinaitop/depot/basic/mapper/CameraStorehouseMapper.xml

@@ -204,4 +204,9 @@
204 204
       AND org_id = #{orgId}
205 205
       AND storehouse_name = #{storehouseName}
206 206
   </select>
207
+  <select id="getCameraIndexCode" resultType="java.util.Map">
208
+    select id from monitor_camera
209
+    where camera_index_code =#{cameraIndexCode}
210
+
211
+  </select>
207 212
 </mapper>

+ 11 - 10
src/main/java/com/chinaitop/depot/basic/service/impl/ImportServiceImpl.java

@@ -28,7 +28,7 @@ import java.util.List;
28 28
 @Service
29 29
 public class ImportServiceImpl {
30 30
 
31
-    public String importFile(String uploadPath, MultipartFile file, String fileType, HttpServletRequest request,String[] titleArr,boolean[] emptyArr,List<List<String>> lists) throws Exception{
31
+    public String importFile(String uploadPath, MultipartFile file, String fileType,HttpServletRequest request,String[] titleArr,boolean[] emptyArr,List<List<String>> lists) throws Exception{
32 32
 
33 33
         // 服务器路径
34 34
 //        String rootPath = request.getSession().getServletContext().getRealPath("");
@@ -47,7 +47,6 @@ public class ImportServiceImpl {
47 47
     /**
48 48
      * 创建临时文件
49 49
      * @param file 上传过来的文件流
50
-     * @param request 请求
51 50
      * @param uploadPath 根目录
52 51
      * @param relativePath 相对路径
53 52
      * @throws Exception
@@ -79,9 +78,9 @@ public class ImportServiceImpl {
79 78
         //循环每一个sheet
80 79
         for (int i = 0; i < sheetNum; i++) {
81 80
             String err = everySheet(getWorkbook(tempFile,fileName).getSheetAt(i),titleArr,emptyArr,list);
82
-            if(ParameterUtil.isnotnull(err)){
83
-                errorMSG.append("第"+(i+1)+"个sheet,名称为:"+getWorkbook(tempFile,fileName).getSheetName(i)+",错误信息:"+err);
84
-            }
81
+//            if(ParameterUtil.isnotnull(err)){
82
+//                errorMSG.append("第"+(i+1)+"个sheet,名称为:"+getWorkbook(tempFile,fileName).getSheetName(i)+",错误信息:"+err);
83
+//            }
85 84
         }
86 85
 
87 86
         //删除临时文件
@@ -94,12 +93,14 @@ public class ImportServiceImpl {
94 93
     //获取workbook
95 94
     private Workbook getWorkbook(File file ,String FileName){
96 95
         Workbook wb = null;
97
-        try {
98
-            InputStream is = new FileInputStream(file);
99
-            if(ExcelImportUtils.isExcel2007(FileName))
96
+        try (InputStream is = new FileInputStream(file)){
97
+            if (file.getName().endsWith(".xlsx")) {
100 98
                 wb = new XSSFWorkbook(is);
101
-            else
99
+            } else if (file.getName().endsWith(".xls")) {
102 100
                 wb = new HSSFWorkbook(is);
101
+            } else {
102
+                throw new IllegalArgumentException("文件不符合规范");
103
+            }
103 104
         } catch (IOException e) {
104 105
             e.printStackTrace();
105 106
         }
@@ -121,7 +122,7 @@ public class ImportServiceImpl {
121 122
             return "请确认excel的数据";
122 123
         }
123 124
 
124
-        if (!ExcelImportUtils.isSame(sheet.getRow(0),totalCells,titleArr)){ return "导入excel和模板不一致"; }//判断标题是否正确
125
+        //if (!ExcelImportUtils.isSame(sheet.getRow(0),totalCells,titleArr)){ return "导入excel和模板不一致"; }//判断标题是否正确
125 126
 
126 127
         //开始处理数据,循环Excel行数,从第二行开始。标题不入库
127 128
         for(int r=1;r<totalRows;r++){

+ 22 - 14
src/main/java/com/chinaitop/depot/basic/service/impl/MonitorCameraServiceImpl.java

@@ -310,6 +310,7 @@ public class MonitorCameraServiceImpl implements MonitorCameraService {
310 310
 								return msg;
311 311
 							}
312 312
 						}
313
+
313 314
 						if(ParameterUtil.isnotnull(revList.get(j)) && ParameterUtil.isequal(revList.get(13),"1")){
314 315
 							enumData.put("storehouseName", revList.get(j));
315 316
 							enumData.put("orgId", orgId);
@@ -323,6 +324,8 @@ public class MonitorCameraServiceImpl implements MonitorCameraService {
323 324
 							cameraStorehouse.setOrgId(orgId);
324 325
 							cameraStorehouse.setStorehouseId(Integer.parseInt(storehouseId.get("storehouseId").toString()));
325 326
 						}
327
+						camera.setPowerPosition(revList.get(j));
328
+						break;
326 329
 					case 20:
327 330
 						//摄像头唯一标识
328 331
 						if (revList.get(j) != null && !"".equals(revList.get(j))) {
@@ -332,34 +335,39 @@ public class MonitorCameraServiceImpl implements MonitorCameraService {
332 335
 								return msg;
333 336
 							}
334 337
 						}
338
+						if(ParameterUtil.isnotnull(revList.get(j))){
339
+							enumData.put("cameraIndexCode", revList.get(j));
340
+							Map<String,Object> ca = cameraStorehouseMapper.getCameraIndexCode(enumData);
341
+							if(!ParameterUtil.isnull(ca)){
342
+								msg = "第 "+(i+1)+" 行第 21 列的值的不正确,请查询后再添加!";
343
+								return msg;
344
+							}
345
+						}
346
+						camera.setCameraIndexCode(revList.get(j));
347
+						break;
348
+
335 349
 					case 21:
336 350
 						//在线状态(0-未知,1-在
337 351
 						//线,2-离线)
352
+						Integer status =0;
338 353
 						if (revList.get(j) != null && !"".equals(revList.get(j))) {
339 354
 							len = revList.get(j).length();
340
-							if (!"0".equals(revList.get(j)) &&!"1".equals(revList.get(j)) && !"2".equals(revList.get(j))) {
355
+							if (!"0".equals(revList.get(j)) && !"1".equals(revList.get(j)) && !"2".equals(revList.get(j))) {
341 356
 								msg = "第 "+(i+1)+" 行第 22 列的值必须是0或者1或者2!";
342 357
 								return msg;
343 358
 							}
344
-
345
-						}
346
-					case 22:
347
-						//状态说明
348
-						if (revList.get(j) != null && !"".equals(revList.get(j))) {
349
-							len = revList.get(j).length();
350
-							if (len > 255) {
351
-								msg = "第 "+(i+1)+" 行第 23 列的值的长度不能超过255!";
352
-								return msg;
353
-							}
359
+							 status=Integer.parseInt(revList.get(j));
354 360
 						}
355
-
361
+						camera.setStatus(status);
356 362
 						break;
357 363
             		default :
358 364
             			break;
359 365
             	}
360 366
             }
361
-
362
-			cameraMapper.insert(camera);
367
+			int a =cameraMapper.insert(camera);
368
+			if(a>0){
369
+				msg="导入成功";
370
+			}
363 371
 
364 372
             if(ParameterUtil.isnotnull(cameraStorehouse)){
365 373
 				cameraStorehouse.setCameraId(camera.getId());

+ 0 - 61
src/main/java/com/chinaitop/depot/utils/CustomFilter.java

@@ -1,61 +0,0 @@
1
-package com.chinaitop.depot.utils;
2
-
3
-import java.io.IOException;
4
-
5
-import javax.servlet.Filter;
6
-import javax.servlet.FilterChain;
7
-import javax.servlet.FilterConfig;
8
-import javax.servlet.ServletException;
9
-import javax.servlet.ServletRequest;
10
-import javax.servlet.ServletResponse;
11
-import javax.servlet.http.HttpServletRequest;
12
-import javax.servlet.http.HttpSession;
13
-
14
-import org.apache.commons.lang.ObjectUtils;
15
-import org.apache.commons.lang3.StringUtils;
16
-
17
-import com.chinaitop.depot.utils.DataPolicyEngine;
18
-import com.chinaitop.depot.utils.ParameterRequestWrapper;
19
-
20
-public class CustomFilter implements Filter {
21
-
22
-	@Override
23
-    public void init(FilterConfig filterConfig) throws ServletException {
24
- 
25
-    }
26
-	
27
-	@Override
28
-	public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2)
29
-			throws IOException, ServletException {
30
-		ParameterRequestWrapper requestWrapper = new ParameterRequestWrapper((HttpServletRequest) arg0);
31
-		HttpServletRequest request = (HttpServletRequest) arg0;
32
-		HttpSession session = request.getSession();
33
-		String orgId = "";
34
-		if (session != null){
35
-			orgId = ObjectUtils.toString(session.getAttribute("orgId"), "");
36
-		}
37
-		if (StringUtils.isNotBlank(orgId)) {
38
-			DataPolicyEngine.set(orgId);
39
-		}
40
-
41
-		if (StringUtils.isNotBlank(orgId)) {
42
-			// 将参数追加到request url 之后
43
-			requestWrapper.addParameter("orgId", orgId);
44
-			requestWrapper.addParameter("unitid", orgId);
45
-			requestWrapper.addParameter("unitId", orgId);
46
-			// 将参数追加到request 的body 中
47
-			requestWrapper.addParameterToBody("orgId", orgId);
48
-			requestWrapper.addParameterToBody("unitid", orgId);
49
-			requestWrapper.addParameterToBody("unitId", orgId);
50
-		}
51
-
52
-		arg2.doFilter(requestWrapper, arg1);
53
-		DataPolicyEngine.remove();
54
-	}
55
-
56
-	@Override
57
-    public void destroy() {
58
- 
59
-    }
60
-
61
-}

+ 0 - 233
src/main/java/com/chinaitop/depot/utils/ParameterRequestWrapper.java

@@ -1,233 +0,0 @@
1
-package com.chinaitop.depot.utils;
2
-
3
-import com.alibaba.fastjson.JSONObject;
4
-import org.springframework.util.StringUtils;
5
-
6
-import javax.servlet.ReadListener;
7
-import javax.servlet.ServletInputStream;
8
-import javax.servlet.http.HttpServletRequest;
9
-import javax.servlet.http.HttpServletRequestWrapper;
10
-import java.io.BufferedReader;
11
-import java.io.ByteArrayInputStream;
12
-import java.io.IOException;
13
-import java.io.InputStreamReader;
14
-import java.util.HashMap;
15
-import java.util.Map;
16
-
17
-/**
18
- * request 请求参数添加
19
- *
20
- * @Description TODO
21
- * @Date 2022/12/13 09:41
22
- * @Author fxw
23
- * @Version 1.0
24
- */
25
-public class ParameterRequestWrapper extends HttpServletRequestWrapper {
26
-
27
-    private Map<String, String[]> params = new HashMap<String, String[]>();
28
-    private byte[] body;
29
-
30
-    public ParameterRequestWrapper(HttpServletRequest request) {
31
-        // 将request交给父类,以便于调用对应方法的时候,将其输出,
32
-        // 其实父亲类的实现方式和第一种new的方式类似
33
-        super(request);
34
-        //将参数表,赋予给当前的Map以便于持有request中的参数
35
-        //由于request并没有提供现成的获取json字符串的方法,所以我们需要将body中的流转为字符串
36
-        String json = getPostData(request);
37
-        if (!StringUtils.isEmpty(json)) {
38
-            // body 赋值
39
-            this.body = getData(json).getBytes();
40
-        }
41
-        // 请求参数赋值
42
-        this.params.putAll(request.getParameterMap());
43
-    }
44
-
45
-    /**
46
-     * 重载一个构造方法-- 扩展参数
47
-     *
48
-     * @param request
49
-     * @param extendParams
50
-     */
51
-    public ParameterRequestWrapper(HttpServletRequest request, Map<String, Object> extendParams) {
52
-        this(request);
53
-        //这里将扩展参数写入参数表
54
-        addAllParameters(extendParams);
55
-    }
56
-
57
-    /**
58
-     * 增加多个参数
59
-     *
60
-     * @param otherParams
61
-     */
62
-    public void addAllParameters(Map<String, Object> otherParams) {
63
-        for (Map.Entry<String, Object> entry : otherParams.entrySet()) {
64
-            addParameter(entry.getKey(), entry.getValue());
65
-        }
66
-    }
67
-
68
-    /**
69
-     * 增加参数
70
-     */
71
-    public void addParameter(String name, Object value) {
72
-        if (value != null) {
73
-            if (value instanceof String[]) {
74
-                params.put(name, (String[]) value);
75
-            } else if (value instanceof String) {
76
-                params.put(name, new String[]{(String) value});
77
-            } else {
78
-                params.put(name, new String[]{String.valueOf(value)});
79
-            }
80
-        }
81
-    }
82
-    
83
-    /**
84
-     * 删除参数
85
-     */
86
-    public void deleteParameter(String key) {
87
-    	params.remove(key);
88
-    }
89
-
90
-    /**
91
-     * 增加body 参数
92
-     *
93
-     * @param name
94
-     * @param value
95
-     */
96
-    public void addParameterToBody(String name, Object value) {
97
-        byte[] json = this.body;
98
-        if (null == json) {
99
-            return;
100
-        }
101
-        String jsonStr = new String(json);
102
-        try {
103
-            Map<String, Object> mapData = JSONObject.parseObject(jsonStr, Map.class);
104
-            if (value != null) {
105
-                mapData.put(name, value);
106
-                this.body = JSONObject.toJSONString(mapData).getBytes();
107
-            }
108
-        } catch (Exception ex) {
109
-            // 转换异常
110
-        }
111
-
112
-    }
113
-
114
-    /**
115
-     * 删除body 参数
116
-     *
117
-     * @param name
118
-     * @param value
119
-     */
120
-    public void deleteParameterToBody(String key) {
121
-        byte[] json = this.body;
122
-        if (null == json) {
123
-            return;
124
-        }
125
-        String jsonStr = new String(json);
126
-        try {
127
-            Map<String, Object> mapData = JSONObject.parseObject(jsonStr, Map.class);
128
-            mapData.remove(key);
129
-            this.body = JSONObject.toJSONString(mapData).getBytes();
130
-        } catch (Exception ex) {
131
-            // 转换异常
132
-        }
133
-
134
-    }
135
-
136
-
137
-    /**
138
-     * body中参数解密
139
-     *
140
-     * @param json
141
-     * @return
142
-     */
143
-    private String getData(String json) {
144
-        //加密,如果传过来的是加密数据,先解密,未加密直接返回原json
145
-//        if(StringUtils.isNotEmpty(json)){
146
-//            json = AES256Util.decode(json);
147
-//            if(StringUtils.isEmpty(json)){
148
-//                return "";
149
-//            }
150
-//            JSONObject object = JSONUtil.parseObj(json);
151
-//            return JSONUtil.toJsonStr(object);
152
-//        }
153
-        //不加密
154
-        return json;
155
-
156
-    }
157
-
158
-    /**
159
-     * 获取body 参数
160
-     *
161
-     * @param request
162
-     * @return
163
-     */
164
-    public static String getPostData(HttpServletRequest request) {
165
-        StringBuilder data = new StringBuilder();
166
-        String line;
167
-        BufferedReader reader;
168
-        try {
169
-            reader = request.getReader();
170
-            while (null != (line = reader.readLine())) {
171
-                data.append(line);
172
-            }
173
-        } catch (IOException e) {
174
-            return null;
175
-        }
176
-        return data.toString();
177
-    }
178
-
179
-    @Override
180
-    public String getParameter(String name) {//重写getParameter,代表参数从当前类中的map获取
181
-        String[] values = params.get(name);
182
-        if (values == null || values.length == 0) {
183
-            return null;
184
-        }
185
-        return values[0];
186
-    }
187
-
188
-    @Override
189
-    public String[] getParameterValues(String name) {//同上
190
-        return params.get(name);
191
-    }
192
-
193
-    @Override
194
-    public BufferedReader getReader() throws IOException {
195
-        return new BufferedReader(new InputStreamReader(getInputStream()));
196
-    }
197
-
198
-    /**
199
-     * 在使用@RequestBody注解的时候,其实框架是调用了getInputStream()方法,所以我们要重写这个方法
200
-     *
201
-     * @return
202
-     * @throws IOException
203
-     */
204
-    @Override
205
-    public ServletInputStream getInputStream() throws IOException {
206
-        if (body == null) {
207
-            body = new byte[0];
208
-        }
209
-        final ByteArrayInputStream bais = new ByteArrayInputStream(body);
210
-        return new ServletInputStream() {
211
-            @Override
212
-            public boolean isFinished() {
213
-                return false;
214
-            }
215
-
216
-            @Override
217
-            public boolean isReady() {
218
-                return false;
219
-            }
220
-
221
-            @Override
222
-            public void setReadListener(ReadListener readListener) {
223
-
224
-            }
225
-
226
-            @Override
227
-            public int read() throws IOException {
228
-                return bais.read();
229
-            }
230
-        };
231
-    }
232
-
233
-}

+ 0 - 39
src/main/java/com/chinaitop/depot/utils/WebConfig.java

@@ -1,39 +0,0 @@
1
-package com.chinaitop.depot.utils;
2
-
3
-import org.springframework.boot.web.servlet.FilterRegistrationBean;
4
-import org.springframework.context.annotation.Bean;
5
-import org.springframework.context.annotation.Configuration;
6
-import java.util.ArrayList;
7
-import java.util.List;
8
-
9
-/**
10
- * @desc 注册bean, 将自定义过滤器添加到过滤器链中
11
- * @Author fxw
12
- * @date 2019/3/11
13
- * @return
14
- */
15
-@Configuration
16
-public class WebConfig {
17
-
18
-   /**
19
-    * 注册过滤器,有两种方式:
20
-    * 1) 使用 @Component 注解<br>
21
-    * 2) 添加到过滤器链中,此方式适用于使用第三方的过滤器。将过滤器写到 WebConfig 类中,如下:
22
-    */
23
-   @Bean
24
-   public FilterRegistrationBean filterRegistrationBean() {
25
-
26
-      FilterRegistrationBean registrationBean = new FilterRegistrationBean();
27
-
28
-      CustomFilter filter = new CustomFilter();
29
-      registrationBean.setFilter(filter);
30
-
31
-      //设置过滤器拦截请求
32
-      List<String> urls = new ArrayList<>();
33
-      urls.add("/*");
34
-      registrationBean.setUrlPatterns(urls);
35
-
36
-      return registrationBean;
37
-   }
38
-
39
-}

+ 2 - 0
src/main/resources/bootstrap-dev.yml

@@ -43,6 +43,8 @@ spring:
43 43
       max-request-size: 50MB
44 44
 web:
45 45
   upload-path: /home/depot/depot-web/apache-tomcat-8.0.53/webapps/ROOT/WEB-INF/classes/static
46
+
47
+
46 48
 # 视频监测记录保存位置
47 49
 monitor:
48 50
   monitoring-path: /home/monitorzd