|
@@ -1,6 +1,9 @@
|
|
|
package com.fdkankan.ucenter.controller;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.fdkankan.common.constant.ErrorCode;
|
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
|
import com.fdkankan.common.util.JwtUtil;
|
|
|
import com.fdkankan.ucenter.common.Result;
|
|
@@ -12,7 +15,9 @@ import com.fdkankan.ucenter.vo.request.CameraParam;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("/user/camera")
|
|
@@ -68,10 +73,22 @@ public class CameraController {
|
|
|
*/
|
|
|
@PostMapping("/add")
|
|
|
public Result add(@RequestBody JSONObject jsonObject,@RequestHeader String token){
|
|
|
+ String snCodes = jsonObject.getString("snCode");
|
|
|
+ if(StrUtil.isEmpty(snCodes)){
|
|
|
+ throw new BusinessException(ErrorCode.PARAM_ERROR.code(), "snCode不能为空");
|
|
|
+ }
|
|
|
+ snCodes = snCodes.trim();
|
|
|
+ if(StrUtil.isEmpty(snCodes)){
|
|
|
+ throw new BusinessException(ErrorCode.PARAM_ERROR.code(), "snCode不能为空");
|
|
|
+ }
|
|
|
String username = JwtUtil.getUsername(token);
|
|
|
- List<String> errorSnCode = cameraService.bind( jsonObject.getString("snCode"), username);
|
|
|
JSONObject object = new JSONObject();
|
|
|
- object.put("errorSnCode",errorSnCode);
|
|
|
+ List<String> errorSnCode = cameraService.bind(snCodes, username);
|
|
|
+ if(CollUtil.isNotEmpty(errorSnCode)){
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ errorSnCode.stream().forEach(snCode -> map.put(snCode, "相机已被绑定,请勿重复绑定!"));
|
|
|
+ object.put("errorSnCode",map);
|
|
|
+ }
|
|
|
return Result.success(object);
|
|
|
}
|
|
|
|
|
@@ -120,4 +137,9 @@ public class CameraController {
|
|
|
return Result.success(cameraService.getAllList(jsonObject.getString("childName"),token));
|
|
|
}
|
|
|
|
|
|
+ public static void main(String[] args) {
|
|
|
+ String username = JwtUtil.getUsername("eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMzYzMTI2Mjc1OCIsInVzZXJOYW1lIjoiMTM2MzEyNjI3NTgiLCJpYXQiOjE2ODczMTg3NTYsImp0aSI6ImExNjc0N2NiLTA0NDQtNGYzYS05NjQ3LTc5NDc3MzViZGRhNSJ9.FwonX6kDLnek8qFFoRZZPJ6WOcOY0-R_EM75Yj9fwyg");
|
|
|
+ System.out.println(username);
|
|
|
+ }
|
|
|
+
|
|
|
}
|