From d73687bc6115007145b4aab050e4e29ff87fd8ae Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期一, 01 三月 2021 18:44:36 +0800
Subject: [PATCH] 布丸代码优化

---
 src/main/java/com/yeshi/buwan/controller/parser/CommentParser.java |   91 +++++++++++++++++++++++++++++++++++----------
 1 files changed, 71 insertions(+), 20 deletions(-)

diff --git a/src/main/java/com/yeshi/buwan/controller/parser/CommentParser.java b/src/main/java/com/yeshi/buwan/controller/parser/CommentParser.java
index f43455c..1b22a41 100644
--- a/src/main/java/com/yeshi/buwan/controller/parser/CommentParser.java
+++ b/src/main/java/com/yeshi/buwan/controller/parser/CommentParser.java
@@ -3,8 +3,11 @@
 import com.google.gson.GsonBuilder;
 import com.yeshi.buwan.domain.*;
 import com.yeshi.buwan.domain.user.LoginUser;
-import com.yeshi.buwan.exception.LoginUserException;
+import com.yeshi.buwan.dto.user.LoginInfoDto;
+import com.yeshi.buwan.dto.user.QQUserInfo;
+import com.yeshi.buwan.exception.user.LoginUserException;
 import com.yeshi.buwan.exception.SMSException;
+import com.yeshi.buwan.exception.user.RegisterUserException;
 import com.yeshi.buwan.service.imp.CommentService;
 import com.yeshi.buwan.service.imp.MaskKeyService;
 import com.yeshi.buwan.service.imp.SystemService;
@@ -85,17 +88,50 @@
             return;
         }
 
-        DetailSystem detailSystem = systemService.getDetailSystemByPackage(acceptData.getPackageName());
-        LoginUser lu = userService.getLoginUser(openid, detailSystem.getId(), Integer.parseInt(loginType), portrait,
-                name, UserParser.getIp(request) + ":" + request.getRemotePort());
-        if (lu != null) {
-            JSONObject object = new JSONObject();
-            object.put("LoginUid", lu.getId());
-            out.print(JsonUtil.loadTrueJson(object.toString()));
-        } else {
-            out.print(JsonUtil.loadFalseJson("鐧诲綍澶辫触"));
+        LoginInfoDto loginInfoDto = new LoginInfoDto();
+        loginInfoDto.setSystemId(acceptData.getDetailSystem().getSystem().getId());
+
+        int loginTypeInt = Integer.parseInt(loginType);
+        loginInfoDto.setLoginType(loginTypeInt);
+
+        switch (loginTypeInt) {
+            case LoginUser.LOGIN_TYPE_EMAIL:
+                loginInfoDto.setEmail(openid);
+                break;
+            case LoginUser.LOGIN_TYPE_QQ:
+                QQUserInfo qqUserInfo = new QQUserInfo();
+                qqUserInfo.setName(name);
+                qqUserInfo.setOpenId(openid);
+                qqUserInfo.setPortrait(portrait);
+                qqUserInfo.setSex(sex);
+                loginInfoDto.setQqUserInfo(qqUserInfo);
+                break;
         }
 
+
+        try {
+            LoginUser lu = userService.login(loginInfoDto);
+            if (lu != null) {
+                JSONObject object = new JSONObject();
+                object.put("LoginUid", lu.getId());
+                out.print(JsonUtil.loadTrueJson(object.toString()));
+            } else {
+                out.print(JsonUtil.loadFalseJson("鐧诲綍澶辫触"));
+            }
+        } catch (LoginUserException e) {
+            //鐢ㄦ埛涓嶅瓨鍦�
+            if (e.getCode() == LoginUserException.CODE_NO_USER && loginTypeInt == LoginUser.LOGIN_TYPE_EMAIL) {
+                //娉ㄥ唽
+                try {
+                    userService.register(loginInfoDto);
+                } catch (RegisterUserException e1) {
+                    out.print(JsonUtil.loadFalseJson("鐧诲綍澶辫触"));
+                }
+
+            } else {
+                out.print(JsonUtil.loadFalseJson(e.getMessage()));
+            }
+        }
     }
 
 
@@ -113,19 +149,34 @@
             return;
         }
 
-        DetailSystem detailSystem = systemService.getDetailSystemByPackage(acceptData.getPackageName());
+        LoginInfoDto loginInfoDto = new LoginInfoDto();
+        loginInfoDto.setSystemId(acceptData.getDetailSystem().getSystem().getId());
+        loginInfoDto.setLoginType(LoginUser.LOGIN_TYPE_WX);
+        loginInfoDto.setWeiXinUser(weiXinUser);
 
 
-        LoginUser lu = userService.getLoginUser(weiXinUser.getOpenid(), detailSystem.getId(), 2, weiXinUser.getHeadimgurl(),
-                weiXinUser.getNickname(), UserParser.getIp(request) + ":" + request.getRemotePort());
-        if (lu != null) {
-            JSONObject object = new JSONObject();
-            object.put("user", new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().toJson(lu));
-            out.print(JsonUtil.loadTrueJson(object.toString()));
-        } else {
-            out.print(JsonUtil.loadFalseJson("鐧诲綍澶辫触"));
+        try {
+            LoginUser lu = userService.login(loginInfoDto);
+            if (lu != null) {
+                JSONObject object = new JSONObject();
+                object.put("user", new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().toJson(lu));
+                out.print(JsonUtil.loadTrueJson(object.toString()));
+            } else {
+                out.print(JsonUtil.loadFalseJson("鐧诲綍澶辫触"));
+            }
+        } catch (LoginUserException e) {
+            //鐢ㄦ埛涓嶅瓨鍦�
+            if (e.getCode() == LoginUserException.CODE_NO_USER) {
+                //娉ㄥ唽
+                try {
+                    userService.register(loginInfoDto);
+                } catch (RegisterUserException e1) {
+                    out.print(JsonUtil.loadFalseJson("鐧诲綍澶辫触"));
+                }
+            } else {
+                out.print(JsonUtil.loadFalseJson(e.getMessage()));
+            }
         }
-
     }
 
     /**

--
Gitblit v1.8.0