dingxin 6 年 前
コミット
64e9a62c50

+ 37
- 0
CODE/smart-community/app-api/src/main/java/com/community/huiju/controller/BaseController.java ファイルの表示

@@ -1,9 +1,16 @@
1 1
 package com.community.huiju.controller;
2 2
 
3
+import com.community.commom.constant.Constant;
4
+import com.community.commom.session.UserElement;
5
+import com.community.huiju.exception.WisdomException;
3 6
 import com.community.huiju.model.ToCommunities;
4 7
 import com.community.huiju.service.CommunityServiceI;
8
+import com.community.huiju.vo.TaUserVO;
9
+import org.springframework.beans.BeanUtils;
5 10
 import org.springframework.beans.factory.annotation.Autowired;
6 11
 
12
+import javax.servlet.http.HttpSession;
13
+
7 14
 /**
8 15
  * 公共 controller
9 16
  */
@@ -24,4 +31,34 @@ public class BaseController {
24 31
         return false;
25 32
     }
26 33
 
34
+    /**
35
+     * 设置用户 session
36
+     * @param userVO
37
+     * @param session
38
+     */
39
+    protected void setUserSession(TaUserVO userVO, HttpSession session) {
40
+        if (null == userVO) {
41
+            throw new WisdomException("用户信息不能为空!");
42
+        }
43
+
44
+        UserElement userElement = new UserElement();
45
+        BeanUtils.copyProperties(userVO,userElement);
46
+        userElement.setLoginType(Constant.APP_LOGIN_TYPE);
47
+        session.setAttribute(Constant.APP_USER_SESSION,userElement);
48
+        userVO.setToken(session.getId());
49
+    }
50
+
51
+    /**
52
+     * 获取用户 session
53
+     * @param session
54
+     * @return
55
+     */
56
+    protected UserElement getUserElement(HttpSession session) {
57
+        UserElement userElement = (UserElement) session.getAttribute(Constant.APP_USER_SESSION);
58
+        if (null == userElement) {
59
+            throw new WisdomException("用户 session 不存在!");
60
+        }
61
+        return userElement;
62
+    }
63
+
27 64
 }

+ 1
- 8
CODE/smart-community/app-api/src/main/java/com/community/huiju/controller/UserController.java ファイルの表示

@@ -51,14 +51,7 @@ public class UserController extends BaseController {
51 51
         JSONObject jsonObject = JSONObject.parseObject(parameter);
52 52
         ResponseBean responseBean = iTaUserService.login(jsonObject.getString("loginName"),jsonObject.getString("code"));
53 53
         TaUserVO userVO = (TaUserVO) responseBean.getData();
54
-
55
-        if (null != userVO) {
56
-            UserElement userElement = new UserElement();
57
-            BeanUtils.copyProperties(userVO,userElement);
58
-            userElement.setLoginType(Constant.APP_LOGIN_TYPE);
59
-            session.setAttribute(Constant.APP_USER_SESSION,userElement);
60
-            userVO.setToken(session.getId());
61
-        }
54
+        setUserSession(userVO, session);
62 55
         return responseBean;
63 56
 
64 57
     }

+ 1
- 1
CODE/smart-community/app-api/src/main/java/com/community/huiju/dao/TaUserMapper.java ファイルの表示

@@ -33,7 +33,7 @@ public interface TaUserMapper {
33 33
      * @param map
34 34
      * @return 用户
35 35
      */
36
-    TaUser selectByLoginName(Map<String, Object> map);
36
+    TaUser selectByLoginName(@Param("map") Map<String, Object> map);
37 37
 
38 38
     /**
39 39
      * 更新当前用户电话