Explorar el Código

修改后端代码的不规范性

gt hace 2 años
padre
commit
a1d74bdec2

+ 4 - 4
chuanyi_server/src/main/java/com/judong/chuanyiserver/config/OpcServerDaPoolFactory.java

@@ -147,12 +147,12 @@ public class OpcServerDaPoolFactory {
          * @throws Exception
          */
         public Server create(String key) {
-            JSONObject jsonObject = (JSONObject) JSONObject.parse(key);
+            JSONObject jsonObject = JSONObject.parseObject(key);
             final ConnectionInformation ci = new ConnectionInformation();
-            ci.setHost((String) jsonObject.get("ip")); // 安装opc电脑IP
+            ci.setHost(jsonObject.getString("ip")); // 安装opc电脑IP
             ci.setDomain(""); // 域,为空就行
-            ci.setUser((String) jsonObject.get("user")); // 电脑上自己建好的用户名
-            ci.setPassword((String) jsonObject.get("password")); // 用户名的密码
+            ci.setUser(jsonObject.getString("user")); // 电脑上自己建好的用户名
+            ci.setPassword(jsonObject.getString("password")); // 用户名的密码
             // 使用MatrikonOPC Server的配置
 //            ci.setClsid("F8582CF2-88FB-11D0-B850-00C0F0104305"); // MatrikonOPC的注册表ID,可以在“组件服务”里看到
             // 使用Stoner Simulation Server的配置

+ 4 - 4
chuanyi_server/src/main/java/com/judong/chuanyiserver/controller/ConnectController.java

@@ -39,7 +39,7 @@ public class ConnectController {
      */
     @GetMapping("/testConnect")
     public Result testConnect(ServerInformation serverInformation) throws AlreadyConnectedException, JIException, UnknownHostException {
-        if (Blank.isEmpty(serverInformation.getIpAddress()) || Blank.isEmpty(serverInformation.getIpUserName()) || Blank.isEmpty(serverInformation.getIpPassword()) || Blank.isEmpty(serverInformation.getAgreementType())) {
+        if (Blank.isEmpty(serverInformation, serverInformation.getIpAddress(), serverInformation.getIpUserName(), serverInformation.getIpPassword(), serverInformation.getAgreementType())) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
         }
         return connectService.testConnect(serverInformation);
@@ -54,7 +54,7 @@ public class ConnectController {
     @PostMapping("/saveConnect")
 //    @PermissionControl
     public Result saveConnect(ServerInformation serverInformation) {
-        if (Blank.isEmpty(serverInformation.getIpAddress()) || Blank.isEmpty(serverInformation.getIpUserName()) || Blank.isEmpty(serverInformation.getIpPassword()) || Blank.isEmpty(serverInformation.getAgreementType())) {
+        if (Blank.isEmpty(serverInformation, serverInformation.getIpAddress(), serverInformation.getIpUserName(), serverInformation.getIpPassword(), serverInformation.getAgreementType())) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
         }
         return connectService.saveConnect(serverInformation);
@@ -105,7 +105,7 @@ public class ConnectController {
      */
     @GetMapping("/readItemValue")
     public Result readItemValue(int id, String itemName) throws Exception {
-        if (Blank.isEmpty(id) || Blank.isEmpty(itemName)) {
+        if (Blank.isEmpty(id, itemName)) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
         }
         return connectService.readItemValue(id, itemName);
@@ -119,7 +119,7 @@ public class ConnectController {
      */
     @PostMapping("/editConnect")
     public Result editConnect(ServerInformation serverInformation) {
-        if (Blank.isEmpty(serverInformation.getIpAddress()) || Blank.isEmpty(serverInformation.getIpUserName()) || Blank.isEmpty(serverInformation.getIpPassword()) || Blank.isEmpty(serverInformation.getAgreementType())) {
+        if (Blank.isEmpty(serverInformation, serverInformation.getIpAddress(), serverInformation.getIpUserName(), serverInformation.getIpPassword(), serverInformation.getAgreementType())) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
         }
         return connectService.editConnect(serverInformation);

+ 10 - 10
chuanyi_server/src/main/java/com/judong/chuanyiserver/controller/UserController.java

@@ -28,7 +28,7 @@ public class UserController {
      */
     @PostMapping("/frontUserLogin")
     public Result frontUserLogin(@RequestBody User user) {
-        if (Blank.isEmpty(user) ||Blank.isEmpty(user.getUserName()) || Blank.isEmpty(user.getPassword())) {
+        if (Blank.isEmpty(user, user.getUserName(), user.getPassword())) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
         }
         return userService.frontUserLogin(user.getUserName(), user.getPassword());
@@ -41,8 +41,8 @@ public class UserController {
      * @return
      */
     @PostMapping("/backUserLogin")
-    public Result backUserLogin(@RequestBody User user ) {
-        if (Blank.isEmpty(user) ||Blank.isEmpty(user.getUserName()) || Blank.isEmpty(user.getPassword())) {
+    public Result backUserLogin(@RequestBody User user) {
+        if (Blank.isEmpty(user, user.getUserName(), user.getPassword())) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
         }
         return userService.backUserLogin(user.getUserName(), user.getPassword());
@@ -68,7 +68,7 @@ public class UserController {
     @PostMapping("/addUser")
     @PermissionControl
     public Result addUser(String userName, String password) {
-        if (Blank.isEmpty(userName) || Blank.isEmpty(password)) {
+        if (Blank.isEmpty(userName, password)) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
         }
         return userService.addUser(userName, password);
@@ -99,7 +99,7 @@ public class UserController {
     @GetMapping("/getUserPage")
     @PermissionControl
     public Result getUserPage(int page, int limit) {
-        if (Blank.isEmpty(page) || Blank.isEmpty(limit) || page < 1 || limit < 1) {
+        if (Blank.isEmpty(page, limit) || page < 1 || limit < 1) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
         }
         return userService.getUserPage(page, limit);
@@ -128,7 +128,7 @@ public class UserController {
     @PostMapping("/updateUserStateById")
     @PermissionControl
     public Result updateUserStateById(String userId, Integer userState) {
-        if (Blank.isEmpty(userId) || Blank.isEmpty(userState)) {
+        if (Blank.isEmpty(userId, userState)) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
         }
         return userService.updateUserStateById(userId, userState);
@@ -173,7 +173,7 @@ public class UserController {
     @PostMapping("/assignRole")
     @PermissionControl
     public Result assignRole(@RequestBody User user) {
-        if (Blank.isEmpty(user) || Blank.isEmpty(user.getUserId()) || Blank.isEmpty(user.getRoleList())) {
+        if (Blank.isEmpty(user, user.getUserId(), user.getRoleList())) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
         }
         return userService.assignRole(user.getUserId(), user.getRoleList());
@@ -189,7 +189,7 @@ public class UserController {
     @GetMapping("/getRoleListByPage")
     @PermissionControl
     public Result getRoleListByPage(Integer page, Integer limit) {
-        if (Blank.isEmpty(page) || Blank.isEmpty(limit) || page < 1 || limit < 1) {
+        if (Blank.isEmpty(page, limit) || page < 1 || limit < 1) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
         }
         return userService.getRoleListByPage(page, limit);
@@ -265,7 +265,7 @@ public class UserController {
     @GetMapping("/getPermissionListByPage")
     @PermissionControl
     public Result getPermissionListByPage(Integer page, Integer limit) {
-        if (Blank.isEmpty(page) || Blank.isEmpty(limit) || page < 1 || limit < 1) {
+        if (Blank.isEmpty(page, limit) || page < 1 || limit < 1) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
         }
         return userService.getPermissionListByPage(page, limit);
@@ -295,7 +295,7 @@ public class UserController {
     @PostMapping("/assignPermission")
     @PermissionControl
     public Result assignPermission(@RequestBody Role role) {
-        if (Blank.isEmpty(role) || Blank.isEmpty(role.getId()) || Blank.isEmpty(role.getPermissionList())) {
+        if (Blank.isEmpty(role, role.getId(), role.getPermissionList())) {
             return Result.no(ResultEnum.REQUEST_WRONGPARAMS.getRespCode(), ResultEnum.REQUEST_WRONGPARAMS.getRespMsg());
         }
         return userService.assignPermission(role.getId(), role.getPermissionList());

+ 1 - 1
chuanyi_server/src/main/java/com/judong/chuanyiserver/exception/GlobalExceptionHandler.java

@@ -23,7 +23,7 @@ public class GlobalExceptionHandler {
      * 自定义异常处理
      */
     @ExceptionHandler(value = CustomException.class)
-    public Result hadndle(CustomException e) {
+    public Result handle(CustomException e) {
         e.printStackTrace();
         return Result.no(e.getCode(), e.getMessage());
     }

+ 9 - 9
chuanyi_server/src/main/java/com/judong/chuanyiserver/util/Result.java

@@ -4,32 +4,32 @@ package com.judong.chuanyiserver.util;
 import com.judong.chuanyiserver.enums.ResultEnum;
 
 public class Result {
-    private Integer Code;//响应码
-    private String Msg;//响应消息
-    private Object Data;//返回的数据
+    private Integer code;//响应码
+    private String msg;//响应消息
+    private Object data;//返回的数据
 
     public Integer getCode() {
-        return Code;
+        return code;
     }
 
     public void setCode(Integer code) {
-        Code = code;
+        code = code;
     }
 
     public String getMsg() {
-        return Msg;
+        return msg;
     }
 
     public void setMsg(String msg) {
-        Msg = msg;
+        msg = msg;
     }
 
     public Object getData() {
-        return Data;
+        return data;
     }
 
     public void setData(Object data) {
-        Data = data;
+        data = data;
     }
 
     public static Result ok(Object data) {