Преглед на файлове

补充自动注册时的初始化行为,注册账户对于的dms记录

ximinghao преди 3 месеца
родител
ревизия
b39d9616ea

+ 9 - 0
src/main/java/com/skyversation/xjcy/bean/User.java

@@ -1,9 +1,18 @@
 package com.skyversation.xjcy.bean;
 
+import com.alibaba.fastjson.JSONObject;
 import lombok.Data;
 
 @Data
 public class User implements FromJSON{
     private String cUsercode;
     private String cGlGs;
+    public JSONObject toJSON(){
+        JSONObject json = new JSONObject();
+        json.put("c_usercode", cUsercode);
+        json.put("c_gl_gs", cGlGs);
+        json.put("title", cUsercode);
+        json.put("content", cUsercode);
+        return json;
+    }
 }

+ 9 - 0
src/main/java/com/skyversation/xjcy/dms/DMSService.java

@@ -236,6 +236,15 @@ public class DMSService {
         return queryDmsList(request, token, DMSColumn.CLUE.getId());
     }
 
+    public List<JSONObject> getUserJSONByCode(String userCode) {
+        DMSRequest request = new DMSRequest();
+        request.type = DMSRequest.DMSRequestType.List;
+        request.addWhere("user_code", "1", userCode);
+        List<JSONObject> result = queryDmsList(request, DMSColumn.USER.getId(), DMSColumn.USER.getId());
+        return result;
+    }
+
+
     //下面几个接口是重计算用的,有重新插入的需求,不能放进queryEnum,不能领域化
     public List<JSONObject> getAllParkByLy(String lyCode, String token) {
         DMSRequest requestChildren = new DMSRequest();

+ 34 - 4
src/main/java/com/skyversation/xjcy/oauth/AuthService.java

@@ -2,6 +2,9 @@ package com.skyversation.xjcy.oauth;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.skyversation.xjcy.bean.User;
+import com.skyversation.xjcy.dms.DMSColumn;
+import com.skyversation.xjcy.dms.DMSService;
 import com.skyversation.xjcy.service.WeChatService;
 import com.skyversation.xjcy.util.HttpUtil;
 import com.skyversation.xjcy.util.MessageManage;
@@ -16,6 +19,7 @@ import javax.annotation.PostConstruct;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -64,6 +68,11 @@ public class AuthService {
     private static final String RESPONSE_FIELD_CONTENT = "content";
     /** 响应字段:用户ID */
     private static final String RESPONSE_FIELD_ID = "id";
+    /**
+     * 响应字段:用户名
+     */
+    private static final String RESPONSE_FIELD_USERNAME = "username";
+    private final DMSService dMSService;
 
 
     // ============================ 内部类定义 ============================
@@ -111,9 +120,10 @@ public class AuthService {
 
     // ============================ 构造方法 ============================
 
-    public AuthService(WeChatService weChatService, PhoneService phoneService) {
+    public AuthService(WeChatService weChatService, PhoneService phoneService, DMSService dMSService) {
         this.weChatService = weChatService;
         this.phoneService = phoneService;
+        this.dMSService = dMSService;
     }
 
     // ============================ 初始化方法 ============================
@@ -259,8 +269,20 @@ public class AuthService {
     /**
      * 初始化用户数据
      */
-    private boolean initUser(int userId) {
-        //TODO 初始化用户
+    private boolean initUser(JSONObject userId) {
+        String usercode = userId.getJSONObject(RESPONSE_FIELD_CONTENT).getString(RESPONSE_FIELD_USERNAME);
+        if (usercode == null || usercode.isEmpty()) {
+            return false;
+        }
+        if (!isUserDmsDataExist(usercode)){
+            User user = new User();
+            user.setCUsercode(usercode);
+            boolean insertSuccess = dMSService.insertToDms(user.toJSON(),getTokenOfServiceAccount(), DMSColumn.USER);
+            if (!insertSuccess) {
+                return false;
+            }
+        }
+
         return true;
     }
 
@@ -289,6 +311,14 @@ public class AuthService {
         }
     }
 
+    /**
+     * 检查用户账户DMS数据存在性
+     */
+    private boolean isUserDmsDataExist(String userCode){
+        List<JSONObject> js = dMSService.getUserJSONByCode(userCode);
+        return !js.isEmpty();
+    }
+
     /**
      * 尝试注册并初始化用户
      */
@@ -306,7 +336,7 @@ public class AuthService {
 
         Integer userId = userUnInitResult.getJSONObject(RESPONSE_FIELD_CONTENT).getInteger(RESPONSE_FIELD_ID);
         if (userId != null) {
-            return initUser(userId);
+            return initUser(userUnInitResult);
         }
         return false;
     }