From 36754ba47da7a3277d5be183a523c912a1dc4cef Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期四, 31 三月 2022 15:07:08 +0800
Subject: [PATCH] service服务bug修复

---
 src/main/resources/code/service/app/src/main/java/com/ks/app/controller/client/api/UserController.java |  141 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 140 insertions(+), 1 deletions(-)

diff --git a/src/main/resources/code/service/app/src/main/java/com/ks/app/controller/client/api/UserController.java b/src/main/resources/code/service/app/src/main/java/com/ks/app/controller/client/api/UserController.java
index f4867b0..dbce9da 100644
--- a/src/main/resources/code/service/app/src/main/java/com/ks/app/controller/client/api/UserController.java
+++ b/src/main/resources/code/service/app/src/main/java/com/ks/app/controller/client/api/UserController.java
@@ -3,14 +3,28 @@
 import com.ks.app.dto.user.LoginInfoDTO;
 import com.ks.app.entity.user.UserInfo;
 import com.ks.app.entity.user.UserLoginRecord;
+import com.ks.app.entity.vip.UserVIPInfo;
 import com.ks.app.exception.user.LoginException;
 import com.ks.app.service.inter.user.UserAccountService;
+import com.ks.app.service.inter.user.UserInfoService;
+import com.ks.app.service.inter.vip.VIPService;
+import com.ks.app.service.manager.VerifyCodeManager;
+import com.ks.app.utils.ApiCodeConstant;
+import com.ks.app.utils.annotation.UserLogin;
 import com.ks.app.vo.AcceptData;
+import com.ks.app.vo.user.UserInfoVO;
+import com.ks.lib.common.exception.ParamsException;
+import com.ks.push.exception.BPushDeviceTokenException;
+import com.ks.push.pojo.DO.BPushDeviceToken;
+import com.ks.push.pojo.DO.PushPlatform;
+import com.ks.push.service.BDeviceTokenService;
+import org.apache.dubbo.config.annotation.Reference;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
 import org.yeshi.utils.JsonUtil;
 import org.yeshi.utils.StringUtil;
+import org.yeshi.utils.ThreadUtil;
 
 import javax.annotation.Resource;
 
@@ -27,6 +41,18 @@
     @Resource
     private UserAccountService userAccountService;
 
+    @Resource
+    private UserInfoService userInfoService;
+
+    @Resource
+    private VIPService vipService;
+
+    @Resource
+    private VerifyCodeManager verifyCodeManager;
+
+    //@Reference(version = "1.0", check = false)
+    private BDeviceTokenService bDeviceTokenService;
+
     @ResponseBody
     @RequestMapping("loginPhone")
     public String loginPhone(AcceptData acceptData, String phone, String vcode, String token) {
@@ -40,7 +66,7 @@
             loginInfo.setPhone(phone);
             loginInfo.setVcode(vcode);
 
-        } else if (StringUtil.isNullOrEmpty(token)) {
+        } else if (!StringUtil.isNullOrEmpty(token)) {
             loginInfo.setPhoneAuthInfo(token);
         } else {
             return JsonUtil.loadFalseResult("淇℃伅涓嶅畬鏁�");
@@ -48,6 +74,18 @@
         loginInfo.setSystem(acceptData.getSystem());
         try {
             UserInfo userInfo = userAccountService.login(loginInfo);
+            ThreadUtil.run(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        //鐧诲綍鎴愬姛
+                        bDeviceTokenService.bindUid(acceptData.getSystem().name(), acceptData.getUtdId(), userInfo.getId() + "");
+                    } catch (Exception e) {
+
+                    }
+                }
+            });
+
             return JsonUtil.loadTrueResult(JsonUtil.getApiCommonGson().toJson(userInfo));
         } catch (LoginException e) {
             return JsonUtil.loadFalseResult(e.getMessage());
@@ -55,5 +93,106 @@
 
     }
 
+    @UserLogin(uid = "#uid")
+    @ResponseBody
+    @RequestMapping("logout")
+    public String logout(AcceptData acceptData, Long uid) {
+        try {
+            //瑙g粦UID
+            bDeviceTokenService.unBindUid(acceptData.getSystem().name(), acceptData.getUtdId());
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return JsonUtil.loadTrueResult("");
+    }
+
+
+    @UserLogin(uid = "#uid")
+    @ResponseBody
+    @RequestMapping("unRegister")
+    public String unRegister(AcceptData acceptData, String vcode, String phone) {
+
+        if (StringUtil.isNullOrEmpty(vcode)) {
+            return JsonUtil.loadFalseResult("楠岃瘉鐮佷笉鑳戒负绌�");
+        }
+
+        if (StringUtil.isNullOrEmpty(phone)) {
+            return JsonUtil.loadFalseResult("鎵嬫満鍙蜂笉鑳戒负绌�");
+        }
+
+        if (!verifyCodeManager.isPhoneCodeRight(acceptData.getSystem(), phone, vcode)) {
+            return JsonUtil.loadFalseResult("楠岃瘉鐮侀敊璇�");
+        }
+
+        UserInfo user = userInfoService.selectValidByPhone(acceptData.getSystem(), phone);
+        if (user == null) {
+            return JsonUtil.loadFalseResult("涓嶅瓨鍦ㄧ粦瀹氳鎵嬫満鍙风殑鐢ㄦ埛");
+        }
+        //娉ㄩ攢
+        userAccountService.unRegister(user.getId());
+        return JsonUtil.loadTrueResult("");
+    }
+
+    @UserLogin(uid = "#uid")
+    @ResponseBody
+    @RequestMapping("getUserInfo")
+    public String getUserInfo(AcceptData acceptData, Long uid) {
+
+        UserInfo user = userInfoService.get(uid);
+
+        if (user == null) {
+            return JsonUtil.loadFalseResult("鐢ㄦ埛涓嶅瓨鍦�");
+        }
+        if (user.getStatus() == UserInfo.STATUS_FORBIDDEN) {
+            return JsonUtil.loadFalseResult(ApiCodeConstant.CODE_FAIL_USER_FORBIDDEN, "璐﹀彿琚皝绂�");
+        }
+
+        if (user.getStatus() == UserInfo.STATUS_OWN_DELETE) {
+            return JsonUtil.loadFalseResult(ApiCodeConstant.CODE_FAIL_USER_DELETE, "鐢ㄦ埛宸茶鍒犻櫎");
+        }
+
+        UserInfoVO vo = new UserInfoVO();
+        vo.setId(user.getId() + "");
+        vo.setNickName(user.getNickName());
+        vo.setPortrait(user.getPortrait());
+
+        UserVIPInfo userVIPInfo = vipService.getVIPInfo(user.getId());
+        if (userVIPInfo != null) {
+            vo.setVipExpireTime(userVIPInfo.getExpireDate().getTime());
+        }
+
+
+        return JsonUtil.loadTrueResult(vo);
+    }
+
+    @ResponseBody
+    @RequestMapping("uploadPushRegId")
+    public String uploadPushRegId(AcceptData acceptData, Long uid, String regId) {
+
+        BPushDeviceToken deviceToken = new BPushDeviceToken();
+        deviceToken.setAppCode(acceptData.getSystem().name());
+        deviceToken.setDeviceId(acceptData.getUtdId());
+        deviceToken.setBuildModel(acceptData.getDeviceType());
+        deviceToken.setBuildVersion(acceptData.getOsVersion());
+        deviceToken.setToken(regId);
+        deviceToken.setType(PushPlatform.jpush);
+        if (uid != null) {
+            deviceToken.setUid(uid + "");
+        }
+        deviceToken.setVersionCode(acceptData.getVersion());
+
+        try {
+            bDeviceTokenService.save(deviceToken);
+            return JsonUtil.loadTrueResult("");
+        } catch (BPushDeviceTokenException e) {
+            return JsonUtil.loadTrueResult(e.getMessage());
+        } catch (ParamsException e) {
+            return JsonUtil.loadTrueResult(e.getMessage());
+        }
+
+
+    }
+
 
 }

--
Gitblit v1.8.0