Browse Source

bug修复

dsx 2 years ago
parent
commit
4fe163c45a

+ 24 - 2
src/main/java/com/fdkankan/ucenter/controller/CameraController.java

@@ -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);
+    }
+
 }

+ 3 - 2
src/main/java/com/fdkankan/ucenter/service/impl/CameraServiceImpl.java

@@ -226,9 +226,10 @@ public class CameraServiceImpl extends ServiceImpl<ICameraMapper, Camera> implem
 
     @Override
     public List<String> bind( String snCodes, String username) {
-        User user = userService.getByUserName(qczjAesUtil.encrypt(username));
+        User user = userService.getByUserName(username);
         String[] snCodeArr = snCodes.split(",");
-        List<String> snCodeList = Arrays.asList(snCodeArr);
+        List<String> snCodeList = Arrays.asList(snCodeArr)
+                .stream().map(snCode -> snCode.trim()).collect(Collectors.toList());
         //汽车之家绑定相机默认入库添加会员权益
         List<String> errorSnCode = qczjService.inCameraAndIncrement(user.getId(), snCodeList);
 

+ 7 - 0
src/main/java/com/fdkankan/ucenter/service/impl/LoginService.java

@@ -3,6 +3,7 @@ package com.fdkankan.ucenter.service.impl;
 import com.alibaba.fastjson.JSONObject;
 import com.fdkankan.common.constant.ConstantFilePath;
 import com.fdkankan.common.constant.ConstantRegex;
+import com.fdkankan.common.constant.ErrorCode;
 import com.fdkankan.common.exception.BusinessException;
 import com.fdkankan.common.util.*;
 import com.fdkankan.redis.constant.RedisKey;
@@ -300,6 +301,12 @@ public class LoginService {
         if (StringUtils.isEmpty(oldPassword) || StringUtils.isEmpty(newPassword)){
             throw new BusinessException(LoginConstant.FAILURE_CODE_3001, LoginConstant.FAILURE_MSG_3001);
         }
+        //原密码校验
+        oldPassword = SecurityUtil.MD5(oldPassword);
+        if(!oldPassword.equals(user.getPassword())){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_3027);
+        }
+
         //正则判断密码是否符合规则(8位以上并且数字英文组合)
         if(!newPassword.matches(ConstantRegex.PASSWORD_REGEX)){
             throw new BusinessException(LoginConstant.FAILURE_CODE_3011, LoginConstant.FAILURE_MSG_3011);

+ 1 - 1
src/main/java/com/fdkankan/ucenter/service/impl/UserServiceImpl.java

@@ -123,7 +123,7 @@ public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements I
     public void updatePassword(String phoneNum, String password) {
         LambdaUpdateWrapper<User> wrapper = new LambdaUpdateWrapper<>();
         wrapper.set(User::getPassword,password)
-                .eq(User::getUserName,phoneNum);
+                .eq(User::getUserName, phoneNum);
         this.update(wrapper);
     }