dingxin 6 年前
父节点
当前提交
64e9a62c50

+ 37
- 0
CODE/smart-community/app-api/src/main/java/com/community/huiju/controller/BaseController.java 查看文件

1
 package com.community.huiju.controller;
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
 import com.community.huiju.model.ToCommunities;
6
 import com.community.huiju.model.ToCommunities;
4
 import com.community.huiju.service.CommunityServiceI;
7
 import com.community.huiju.service.CommunityServiceI;
8
+import com.community.huiju.vo.TaUserVO;
9
+import org.springframework.beans.BeanUtils;
5
 import org.springframework.beans.factory.annotation.Autowired;
10
 import org.springframework.beans.factory.annotation.Autowired;
6
 
11
 
12
+import javax.servlet.http.HttpSession;
13
+
7
 /**
14
 /**
8
  * 公共 controller
15
  * 公共 controller
9
  */
16
  */
24
         return false;
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
         JSONObject jsonObject = JSONObject.parseObject(parameter);
51
         JSONObject jsonObject = JSONObject.parseObject(parameter);
52
         ResponseBean responseBean = iTaUserService.login(jsonObject.getString("loginName"),jsonObject.getString("code"));
52
         ResponseBean responseBean = iTaUserService.login(jsonObject.getString("loginName"),jsonObject.getString("code"));
53
         TaUserVO userVO = (TaUserVO) responseBean.getData();
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
         return responseBean;
55
         return responseBean;
63
 
56
 
64
     }
57
     }

+ 1
- 1
CODE/smart-community/app-api/src/main/java/com/community/huiju/dao/TaUserMapper.java 查看文件

33
      * @param map
33
      * @param map
34
      * @return 用户
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
      * 更新当前用户电话