소스 검색

添加了自动账号注册接口,临时只允许特定账号访问

ximinghao 3 주 전
부모
커밋
050fa7d09f

+ 39 - 0
src/main/java/com/skyversation/xjcy/controller/OtherController.java

@@ -1,6 +1,7 @@
 package com.skyversation.xjcy.controller;
 
 import cn.hutool.extra.qrcode.BufferedImageLuminanceSource;
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.google.zxing.*;
 import com.google.zxing.common.HybridBinarizer;
@@ -151,4 +152,42 @@ public class OtherController {
             return MessageManage.error(-1,"未知错误");
         }
     }
+    @PostMapping(value = "createUser")
+    public String createUser(@RequestParam String account,      // JSON 字符串
+                             @RequestParam String userType,
+                             @RequestParam String userRoles,    // JSON 数组字符串
+                             @RequestHeader String token) {
+        JSONObject jsonObject = authService.getUserContentByToken(token);
+        String username = jsonObject.getString(RESPONSE_FIELD_USERNAME);
+        AuthService.Account accountObj = parseAccount(account);
+        List<AuthService.Role> roleList = parseRoles(userRoles);
+        if (!"user_xmh".equals(username)) {return MessageManage.error(-1,"仅特定账号");}
+        boolean regSuccess = authService.tryRegAndInit(accountObj,userType,roleList);
+        if (!regSuccess) {return MessageManage.error(501,"账号注册失败");}
+        return MessageManage.successWithNoData("账号注册成功");
+    }
+
+    private AuthService.Account parseAccount(String json) {
+        JSONObject obj = JSON.parseObject(json);
+
+        String username   = obj.getString("username");
+        String password   = obj.getString("password");
+        Integer serviceId = obj.getInteger("serviceId");
+        String telephone  = obj.getString("telephone");
+
+        return new AuthService.Account(username, password, serviceId, telephone);
+    }
+    private List<AuthService.Role> parseRoles(String json) {
+        // 传入的应该是 JSON 数组字符串,如:
+        // [{"roleId":"1","serviceId":"100"},{"roleId":"2","serviceId":"200"}]
+        List<JSONObject> list = JSON.parseArray(json, JSONObject.class);
+
+        List<AuthService.Role> roles = new ArrayList<>(list.size());
+        for (JSONObject obj : list) {
+            String roleId    = obj.getString("roleId");
+            String serviceId = obj.getString("serviceId");
+            roles.add(new AuthService.Role(roleId, serviceId));
+        }
+        return roles;
+    }
 }

+ 11 - 9
src/main/java/com/skyversation/xjcy/service/AuthService.java

@@ -535,7 +535,7 @@ public class AuthService {
     /**
      * 初始化用户数据
      */
-    private boolean initUser(JSONObject userJSON, Account account) {
+    private boolean initUser(JSONObject userJSON, Account account, String userType, List<Role> roleList) {
         boolean allSuccess = true;
         JSONObject userContent = userJSON.getJSONObject(RESPONSE_FIELD_CONTENT);
         String usercode = userContent.getString(RESPONSE_FIELD_USERNAME);
@@ -547,7 +547,7 @@ public class AuthService {
             User user = new User();
             user.setCUsercode(usercode);
             user.setCUserStatus("1");
-            user.setCType("4");
+            user.setCType(userType);
             user.setCTel(account.getTelephone());
             boolean insertSuccess = dMSService.insertToDms(user.toJSON(), getTokenOfServiceAccount(), DMSColumn.USER);
             if (!insertSuccess) {
@@ -555,7 +555,7 @@ public class AuthService {
             }
         }
 
-        allSuccess = allSuccess && updateRoles(userContent, ROLE_CONFIG_MAP.get("INIT_ROLE"), Collections.emptyList());
+        allSuccess = allSuccess && updateRoles(userContent, roleList, Collections.emptyList());
         return allSuccess;
     }
 
@@ -599,11 +599,7 @@ public class AuthService {
         }
         return null;
     }
-
-    /**
-     * 尝试注册并初始化用户
-     */
-    private boolean tryRegAndInit(Account account) {
+    public boolean tryRegAndInit(Account account, String userType, List<Role> roleList) {
         // 尝试注册
         JSONObject regResult = register(account);
         if (!isSuccess(regResult)) {
@@ -619,7 +615,7 @@ public class AuthService {
         if (userId != null) {
             boolean b = false;
             try {
-                b = initUser(userUnInitResult,account);
+                b = initUser(userUnInitResult,account,userType,roleList);
             } catch (Exception e) {
                 deleteUser(userId);
                 throw new RuntimeException(e);
@@ -631,6 +627,12 @@ public class AuthService {
         }
         return false;
     }
+    /**
+     * 尝试注册并初始化用户
+     */
+    public boolean tryRegAndInit(Account account) {
+        return  tryRegAndInit(account,"4",ROLE_CONFIG_MAP.get("INIT_ROLE"));
+    }
 
     /**
      * 检查响应是否成功

+ 31 - 10
src/main/java/com/skyversation/xjcy/service/DataCountService.java

@@ -591,7 +591,7 @@ public class DataCountService {
                         parkCount++;
                         allPark.add(industrialPark);
                         if (parkTypeCount.containsKey(industrialPark.getCLandUse())) {
-                            parkTypeCount.put(industrialPark.getCLandUse(), parkCount + 1);
+                            parkTypeCount.put(industrialPark.getCLandUse(), parkTypeCount.get(industrialPark.getCLandUse()) + 1);
                         } else {
                             parkTypeCount.put(industrialPark.getCLandUse(), 1);
                         }
@@ -809,19 +809,28 @@ public class DataCountService {
                 roomBuckets.get(vacant).add(room);
             }
         }
-        // 房间数据更改,根据租赁得到的空房间并不完整,暂时不处理房间数量问题,租赁空置面积改为总面积减去其他面积
-        // 总面积
+        // 更改计算逻辑,按照注释说明:
+        // 1) 租赁维度的已预约、到期中止、即将到期(reserved/terminated/expiringSoon)由租赁数据计算
+        // 2) 总体空置和总体已用以总体数据为准(allPark 的总量),不直接用租赁数据计算
+        // 3) 租赁视角的空置/已用可由总体减去其它租赁项倒推得到,确保不丢失总量一致性
+
+        // 总面积(总体口径)
         BigDecimal totalBuildArea = allPark.stream()
                 .map(IndustrialPark::getCBuildingArea)
                 .filter(Objects::nonNull)
                 .reduce(BigDecimal.ZERO, BigDecimal::add);
 
-        BigDecimal expiringSoonArea = roomBuckets.get(expiringSoon)
-                .stream()
-                .map(IndustrialPark::getCBuildingArea)
+        // 总体空置(使用总体数据,不从租赁数据直接汇总)
+        BigDecimal totalVacantArea = allPark.stream()
+                .map(IndustrialPark::getCVacantArea)
                 .filter(Objects::nonNull)
                 .reduce(BigDecimal.ZERO, BigDecimal::add);
-        BigDecimal utilizedArea = roomBuckets.get(utilized)
+
+        // 总体已用(由总面积减总体空置得到)
+        BigDecimal totalUsedArea = totalBuildArea.subtract(totalVacantArea);
+
+        // --- 租赁口径计算:已预约 / 到期中止 / 即将到期  ---
+        BigDecimal expiringSoonArea = roomBuckets.get(expiringSoon)
                 .stream()
                 .map(IndustrialPark::getCBuildingArea)
                 .filter(Objects::nonNull)
@@ -836,16 +845,28 @@ public class DataCountService {
                 .map(IndustrialPark::getCBuildingArea)
                 .filter(Objects::nonNull)
                 .reduce(BigDecimal.ZERO, BigDecimal::add);
-        BigDecimal vacantArea = totalBuildArea.subtract(expiringSoonArea).subtract(utilizedArea).subtract(reservedArea).subtract(terminatedArea);
+
+        // --- 倒推租赁视角的空置和已用,保证与总体数据口径一致 ---
+        // 租赁空置(leasingVacant) = 总体空置 - 已预约 - 到期中止
+        BigDecimal leasingVacantArea = totalVacantArea
+                .subtract(reservedArea)
+                .subtract(terminatedArea)
+                .max(BigDecimal.ZERO);
+
+        // 租赁已用(leasingUsed) = 总体已用 - 即将到期(注意:总体已用 = leasingUsed + expiringSoon)
+        BigDecimal leasingUsedArea = totalUsedArea
+                .subtract(expiringSoonArea)
+                .max(BigDecimal.ZERO);
+
 
         tempCacheTownData.put("leaseVacantRoomCount", roomBuckets.get(vacant).size());
-        tempCacheTownData.put("leaseVacantAreaCount", vacantArea);
+        tempCacheTownData.put("leaseVacantAreaCount", leasingVacantArea);
 
         tempCacheTownData.put("leaseExpiringSoonRoomCount", roomBuckets.get(expiringSoon).size());
         tempCacheTownData.put("leaseExpiringSoonAreaCount", expiringSoonArea);
 
         tempCacheTownData.put("leaseUtilizedRoomCount", roomBuckets.get(utilized).size());
-        tempCacheTownData.put("leaseUtilizedAreaCount", utilizedArea);
+        tempCacheTownData.put("leaseUtilizedAreaCount", leasingUsedArea);
 
         tempCacheTownData.put("leaseReservedRoomCount", roomBuckets.get(reserved).size());
         tempCacheTownData.put("leaseReservedAreaCount", reservedArea);