Преглед изворни кода

Merge branch 'dev' of depot-qinghai/depot-monitor-qinghai into dev-2.15.0

gdd пре 4 месеци
родитељ
комит
93c4d966a7

+ 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>

+ 2 - 1
src/main/java/com/chinaitop/depot/basic/mapper/MonitorCameraMapper.xml

@@ -30,6 +30,7 @@
30 30
     <result column="camera_index_code" property="cameraIndexCode" jdbcType="VARCHAR" />
31 31
     <result column="status" property="status" jdbcType="INTEGER" />
32 32
     <result column="status_name" property="statusName" jdbcType="VARCHAR" />
33
+    <result column="storehouse_id" property="storehouseId" jdbcType="VARCHAR" />
33 34
   </resultMap>
34 35
   <sql id="Example_Where_Clause" >
35 36
     <where >
@@ -117,7 +118,7 @@
117 118
   <select id="selectById" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
118 119
     select mc.id, mc.org_id, mc.nvr_id, mc.name, mc.alias, mc.username, mc.password, mc.ip, mc.subnetmask, mc.gateway, mc.type, 
119 120
     mc.port, mc.factory, mc.live, mc.model_number, mc.serial_number, mc.installation_site, mc.installation_method, 
120
-    mc.Irradiated_area, mc.power_position, mc.remark, mc.channel_number, mc.isremove, mc.update_time, cs.storehouse_idmc,mc.camera_index_code
121
+    mc.Irradiated_area, mc.power_position, mc.remark, mc.channel_number, mc.isremove, mc.update_time, cs.storehouse_id,mc.camera_index_code
121 122
     from monitor_camera mc
122 123
     left join camera_storehouse cs on cs.camera_id = mc.id
123 124
     where mc.id = #{id,jdbcType=INTEGER}

+ 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());

+ 1 - 1
src/main/java/com/chinaitop/depot/hk/dto/req/CaptureReqDTO.java

@@ -12,7 +12,7 @@ import lombok.Data;
12 12
  * @date 2024/6/22
13 13
  **/
14 14
 @Data
15
-@AllArgsConstructor
15
+//@AllArgsConstructor
16 16
 public class CaptureReqDTO {
17 17
     /**
18 18
      * 监控点编号

+ 4 - 2
src/main/java/com/chinaitop/depot/hk/dto/req/RecordStartReqDTO.java

@@ -1,6 +1,6 @@
1 1
 package com.chinaitop.depot.hk.dto.req;
2 2
 
3
-import lombok.AllArgsConstructor;
3
+
4 4
 import lombok.Data;
5 5
 
6 6
 /**
@@ -12,7 +12,7 @@ import lombok.Data;
12 12
  * @date 2024/6/20
13 13
  **/
14 14
 @Data
15
-@AllArgsConstructor
15
+//@AllArgsConstructor
16 16
 public class RecordStartReqDTO {
17 17
 
18 18
     /**
@@ -29,5 +29,7 @@ public class RecordStartReqDTO {
29 29
      * 存储类型,0-中心存储,1-设备存储,默认为0-中心存储,如果不指定则默认采用中心存储方式
30 30
      */
31 31
     private Integer type;
32
+
33
+    
32 34
 }
33 35
 

+ 41 - 25
src/main/java/com/chinaitop/depot/monitor/controller/PreviewPlaybackController.java

@@ -15,25 +15,31 @@ import com.chinaitop.depot.monitor.model.CameraCapture;
15 15
 import com.chinaitop.depot.monitor.model.CameraRecord;
16 16
 import com.chinaitop.depot.monitor.service.CameraCaptureService;
17 17
 import com.chinaitop.depot.monitor.service.CameraRecordService;
18
+import com.fasterxml.jackson.core.JsonParseException;
19
+import com.fasterxml.jackson.databind.JsonMappingException;
20
+import com.fasterxml.jackson.databind.ObjectMapper;
18 21
 
19 22
 import io.swagger.annotations.Api;
20
-import io.swagger.annotations.ApiImplicitParam;
21
-import io.swagger.annotations.ApiImplicitParams;
22 23
 import io.swagger.annotations.ApiOperation;
23 24
 
24 25
 import org.springframework.beans.factory.annotation.Value;
25 26
 import org.springframework.http.MediaType;
26 27
 import org.springframework.util.LinkedMultiValueMap;
27 28
 import org.springframework.util.MultiValueMap;
29
+import org.springframework.web.bind.annotation.RequestBody;
28 30
 import org.springframework.web.bind.annotation.RequestMapping;
29 31
 import org.springframework.web.bind.annotation.RequestMethod;
30 32
 import org.springframework.web.bind.annotation.RestController;
31 33
 import org.springframework.web.client.RestTemplate;
32 34
 
35
+import java.io.IOException;
36
+
33 37
 import javax.annotation.Resource;
34 38
 
35 39
 /**
36 40
  * 视频预览回放
41
+ * 
42
+ * 预览---开始手动录像---停止手动录像----回放--手动抓图--云台控制
37 43
  */
38 44
 @RestController
39 45
 @RequestMapping(value = "/previewPlayback")
@@ -62,9 +68,6 @@ public class PreviewPlaybackController {
62 68
      */
63 69
     @RequestMapping(value="/getPreview", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
64 70
     @ApiOperation(value="预览", notes = "预览")
65
-    @ApiImplicitParams({
66
-            @ApiImplicitParam(name = "{cameraIndexCode}", value = "监控点编号", paramType = "query")
67
-    })
68 71
     public PreviewResDTO getAlarmPhone(PreviewReqDTO previewReqDTO) {
69 72
         return hkService.previewURLs(previewReqDTO);
70 73
     }
@@ -75,23 +78,9 @@ public class PreviewPlaybackController {
75 78
      * @param playbackReqDTO
76 79
      * @return
77 80
      */
78
-    @RequestMapping(value="/getPlayback", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
81
+    @RequestMapping(value="/getPlayback", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
79 82
     @ApiOperation(value="回放", notes = "回放")
80
-    /*@ApiImplicitParams({
81
-            @ApiImplicitParam(name = "cameraIndexCode", value = "监控点唯一标识,分页获取监控点资源接口获取返回参数", paramType = "query"),
82
-            @ApiImplicitParam(name = "recordLocation", value = "存储类型, 0:中心存储, 1:设备存储 (默认为中心存储)", paramType = "query"),
83
-            @ApiImplicitParam(name = "protocol", value = "取流协议", paramType = "query"),
84
-            @ApiImplicitParam(name = "transmode", value = "传输协议,默认为TCP", paramType = "query"),
85
-            @ApiImplicitParam(name = "beginTime", value = "开始时间,ISO8601格式", paramType = "query"),
86
-            @ApiImplicitParam(name = "endTime", value = "结束时间,与开始时间相差不超过三天,ISO8601格式", paramType = "query"),
87
-            @ApiImplicitParam(name = "uuid", value = "分页查询id,用于继续查询剩余片段,默认为空字符串 (设备存储生效)", paramType = "query"),
88
-            @ApiImplicitParam(name = "uuid", value = "分页查询id,用于继续查询剩余片段,默认为空字符串 (设备存储生效)", paramType = "query"),
89
-            @ApiImplicitParam(name = "expand", value = "扩展内容,支持指定解码格式等,格式:key=value,多个以&隔开", paramType = "query"),
90
-            @ApiImplicitParam(name = "streamform", value = "输出码流转封装格式,默认为RTP ,ps", paramType = "query"),
91
-            @ApiImplicitParam(name = "lockType", value = "查询录像的锁定类型,默认查询全部录像 0  1未锁定 2锁定", paramType = "query")
92
-
93
-    })*/
94
-    public PlaybackResDTO getPlayback(PlaybackReqDTO playbackReqDTO) {
83
+    public PlaybackResDTO getPlayback(@RequestBody PlaybackReqDTO playbackReqDTO) {
95 84
         return hkService.playbackURLs(playbackReqDTO);
96 85
     }
97 86
 
@@ -100,10 +89,23 @@ public class PreviewPlaybackController {
100 89
      * 开始手动录像
101 90
      * @param recordStartReqDTO
102 91
      * @return
92
+     * @throws IOException 
93
+     * @throws JsonMappingException 
94
+     * @throws JsonParseException 
103 95
      */
104
-    @RequestMapping(value="/recordStart", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
96
+    @RequestMapping(value="/recordStart", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
105 97
     @ApiOperation(value="开始手动录像", notes = "开始手动录像")
106
-    public RecordStartResDTO recordStart(RecordStartReqDTO recordStartReqDTO,CameraRecord cameraRecord) {
98
+    public RecordStartResDTO recordStart(String recordStartReqDTOJson, String cameraRecordJson) throws Exception {
99
+    	
100
+        
101
+        // JSON字符串转对象
102
+        ObjectMapper mapper1 = new ObjectMapper();
103
+        CameraRecord cameraRecord = (CameraRecord)mapper1.readValue(cameraRecordJson, CameraRecord.class);
104
+        
105
+        // JSON字符串转对象
106
+        ObjectMapper mapper = new ObjectMapper();
107
+        RecordStartReqDTO recordStartReqDTO = (RecordStartReqDTO)mapper.readValue(recordStartReqDTOJson, RecordStartReqDTO.class);
108
+        
107 109
     	
108 110
     	RecordStartResDTO recordStartResDTO = hkService.recordStart(recordStartReqDTO);
109 111
     	
@@ -127,12 +129,26 @@ public class PreviewPlaybackController {
127 129
     /**
128 130
      * 手动抓图
129 131
      * @param captureReqDTO
132
+     * @throws IOException 
133
+     * @throws JsonMappingException 
134
+     * @throws JsonParseException 
130 135
      */
131
-    @RequestMapping(value="/manualCapture", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
136
+    @RequestMapping(value="/manualCapture", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
132 137
     @ApiOperation(value="手动抓图", notes = "手动抓图")
133
-    public String manualCapture(CaptureReqDTO captureReqDTO,CameraCapture cameraCapture) {
138
+    public String manualCapture(String captureReqDTOJson, String cameraCaptureJson) throws Exception {
139
+    	
140
+    	
141
+    	// JSON字符串转对象
142
+        ObjectMapper mapper1 = new ObjectMapper();
143
+        CaptureReqDTO captureReqDTO = (CaptureReqDTO)mapper1.readValue(captureReqDTOJson, CaptureReqDTO.class);
144
+        
145
+        // JSON字符串转对象
146
+        ObjectMapper mapper = new ObjectMapper();
147
+        CameraCapture cameraCapture = (CameraCapture)mapper.readValue(cameraCaptureJson, CameraCapture.class);
148
+        
134 149
     	CaptureResDTO captureResDTO = hkService.manualCapture(captureReqDTO);
135 150
          
151
+    	
136 152
          //加到表里
137 153
     	CameraCapture cameraCapture1 = cameraCaptureService.save(cameraCapture,captureResDTO.getPicUrl());
138 154
          if(cameraCapture1.getId()>0){

+ 3 - 2
src/main/java/com/chinaitop/depot/monitor/service/impl/CameraCaptureServiceImpl.java

@@ -25,8 +25,9 @@ public class CameraCaptureServiceImpl implements CameraCaptureService{
25 25
 		//cameraCapture.setCameraId(cameraCapture.getCameraId());
26 26
 		//cameraCapture.setOrgId(cameraCapture.getOrgId()+"");
27 27
 		// 图片地址转 文件流  picUrl
28
-		String wjl = NetFileUtil.getBase64Content(picUrl);
29
-		cameraCapture.setCntxwjl(wjl);
28
+		//String wjl = NetFileUtil.getBase64Content(picUrl);
29
+		//System.out.println(wjl.length()+"*******************");
30
+		cameraCapture.setCntxwjl(picUrl);//文件地址
30 31
 		//cameraCapture.setStorehouseId(cameraCapture.getStorehouseId());
31 32
 		//cameraCapture.setTxwjhzm(txwjhzm);//图像文件后缀名
32 33
 		//cameraCapture.setWarehouseId(cameraCapture.getWarehouseId());//

+ 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