瀏覽代碼

添加 获取当前用户信息和权限

weiximei 6 年之前
父節點
當前提交
f523a4dceb

+ 21
- 0
CODE/smart-community/operate-api/src/main/java/com/community/huiju/controller/UserController.java 查看文件

4
 import com.community.commom.constant.Constant;
4
 import com.community.commom.constant.Constant;
5
 import com.community.commom.mode.ResponseBean;
5
 import com.community.commom.mode.ResponseBean;
6
 import com.community.commom.session.UserElement;
6
 import com.community.commom.session.UserElement;
7
+import com.community.huiju.model.ToUser;
7
 import com.community.huiju.service.IToUserService;
8
 import com.community.huiju.service.IToUserService;
8
 import com.community.huiju.vo.ToUserVO;
9
 import com.community.huiju.vo.ToUserVO;
9
 import io.swagger.annotations.Api;
10
 import io.swagger.annotations.Api;
56
     }
57
     }
57
 
58
 
58
 
59
 
60
+    @ApiOperation(value = "获取用户信息",nickname = "获取用户信息")
61
+    @ApiImplicitParams({
62
+            @ApiImplicitParam(paramType = "header",dataType = "String",name = "X-Auth-Token",value = "Token"),
63
+    })
64
+    @RequestMapping(value = "/user/info",method = RequestMethod.GET)
65
+    public ResponseBean getInfo(HttpSession session) {
66
+        ResponseBean response = new ResponseBean();
67
+
68
+        UserElement userElement = (UserElement) session.getAttribute(Constant.WEB_USER_SESSION);
69
+        if (null == userElement) {
70
+            response.addError("请登录!");
71
+            return response;
72
+        }
73
+
74
+        response = iToUserService.getInfo(userElement.getId());
75
+
76
+        return response;
77
+    }
78
+
79
+
59
 }
80
 }

+ 9
- 0
CODE/smart-community/operate-api/src/main/java/com/community/huiju/dao/ToSysRoleMapper.java 查看文件

3
 import com.community.huiju.model.ToSysRole;
3
 import com.community.huiju.model.ToSysRole;
4
 import org.apache.ibatis.annotations.Mapper;
4
 import org.apache.ibatis.annotations.Mapper;
5
 
5
 
6
+import java.util.List;
7
+
6
 @Mapper
8
 @Mapper
7
 public interface ToSysRoleMapper {
9
 public interface ToSysRoleMapper {
8
     int deleteByPrimaryKey(Integer id);
10
     int deleteByPrimaryKey(Integer id);
16
     int updateByPrimaryKeySelective(ToSysRole record);
18
     int updateByPrimaryKeySelective(ToSysRole record);
17
 
19
 
18
     int updateByPrimaryKey(ToSysRole record);
20
     int updateByPrimaryKey(ToSysRole record);
21
+
22
+    /**
23
+     * 根据用户ID查询所有角色
24
+     * @param userId
25
+     * @return
26
+     */
27
+    List<ToSysRole> selectRoleByUserId(Integer userId);
19
 }
28
 }

+ 18
- 0
CODE/smart-community/operate-api/src/main/java/com/community/huiju/service/IToSysRoleService.java 查看文件

1
+package com.community.huiju.service;
2
+
3
+import com.community.huiju.model.ToSysRole;
4
+
5
+import java.util.List;
6
+
7
+/**
8
+ * 角色 业务
9
+ * @author weiximei
10
+ */
11
+public interface IToSysRoleService {
12
+    /**
13
+     * 根据用户ID查询所有角色
14
+     * @param userId
15
+     * @return
16
+     */
17
+    List<ToSysRole> selectRoleByUserId(Integer userId);
18
+}

+ 7
- 0
CODE/smart-community/operate-api/src/main/java/com/community/huiju/service/IToUserService.java 查看文件

16
      */
16
      */
17
     ResponseBean login(String loginName,String code);
17
     ResponseBean login(String loginName,String code);
18
 
18
 
19
+    /**
20
+     * 获取用户信息
21
+     * @param userId
22
+     * @return
23
+     */
24
+    ResponseBean getInfo(Integer userId);
25
+
19
 }
26
 }

+ 24
- 0
CODE/smart-community/operate-api/src/main/java/com/community/huiju/service/impl/ToSysRoleServiceImpl.java 查看文件

1
+package com.community.huiju.service.impl;
2
+
3
+import com.community.huiju.dao.ToSysRoleMapper;
4
+import com.community.huiju.model.ToSysRole;
5
+import com.community.huiju.service.IToSysRoleService;
6
+import lombok.extern.slf4j.Slf4j;
7
+import org.springframework.beans.factory.annotation.Autowired;
8
+import org.springframework.stereotype.Service;
9
+
10
+import java.util.List;
11
+
12
+@Service("iToSysRoleService")
13
+@Slf4j
14
+public class ToSysRoleServiceImpl implements IToSysRoleService {
15
+
16
+    @Autowired
17
+    private ToSysRoleMapper toSysRoleMapper;
18
+
19
+    @Override
20
+    public List<ToSysRole> selectRoleByUserId(Integer userId) {
21
+
22
+        return toSysRoleMapper.selectRoleByUserId(userId);
23
+    }
24
+}

+ 28
- 0
CODE/smart-community/operate-api/src/main/java/com/community/huiju/service/impl/ToUserServerImpl.java 查看文件

3
 import com.community.commom.mode.ResponseBean;
3
 import com.community.commom.mode.ResponseBean;
4
 import com.community.commom.utils.AccountValidatorUtil;
4
 import com.community.commom.utils.AccountValidatorUtil;
5
 import com.community.huiju.common.code.cache.AppkeyCache;
5
 import com.community.huiju.common.code.cache.AppkeyCache;
6
+import com.community.huiju.dao.ToSysRoleMapper;
6
 import com.community.huiju.dao.ToUserMapper;
7
 import com.community.huiju.dao.ToUserMapper;
8
+import com.community.huiju.model.ToSysRole;
7
 import com.community.huiju.model.ToUser;
9
 import com.community.huiju.model.ToUser;
8
 import com.community.huiju.service.IToUserService;
10
 import com.community.huiju.service.IToUserService;
9
 import com.community.huiju.vo.ToUserVO;
11
 import com.community.huiju.vo.ToUserVO;
13
 import org.springframework.beans.factory.annotation.Autowired;
15
 import org.springframework.beans.factory.annotation.Autowired;
14
 import org.springframework.stereotype.Service;
16
 import org.springframework.stereotype.Service;
15
 
17
 
18
+import java.util.List;
19
+
16
 @Service("iToUserServer")
20
 @Service("iToUserServer")
17
 @Slf4j
21
 @Slf4j
18
 public class ToUserServerImpl implements IToUserService {
22
 public class ToUserServerImpl implements IToUserService {
20
     @Autowired
24
     @Autowired
21
     private ToUserMapper toUserMapper;
25
     private ToUserMapper toUserMapper;
22
 
26
 
27
+    @Autowired
28
+    private ToSysRoleMapper toSysRoleMapper;
29
+
23
     @Override
30
     @Override
24
     public ResponseBean login(String loginName, String code) {
31
     public ResponseBean login(String loginName, String code) {
25
 
32
 
52
         response.addSuccess(userVO);
59
         response.addSuccess(userVO);
53
         return response;
60
         return response;
54
     }
61
     }
62
+
63
+
64
+    @Override
65
+    public ResponseBean getInfo(Integer userId) {
66
+        ResponseBean response = new ResponseBean();
67
+        ToUser toUser = toUserMapper.selectByPrimaryKey(userId);
68
+        if (toUser == null) {
69
+            response.addError("用户不存在!");
70
+            return response;
71
+        }
72
+
73
+        ToUserVO toUserVO = new ToUserVO();
74
+        BeanUtils.copyProperties(toUser,toUserVO);
75
+
76
+        List<ToSysRole> sysRoleList = toSysRoleMapper.selectRoleByUserId(userId);
77
+        toUserVO.setRoles(sysRoleList);
78
+
79
+        response.addSuccess(toUserVO);
80
+
81
+        return response;
82
+    }
55
 }
83
 }

+ 5
- 0
CODE/smart-community/operate-api/src/main/java/com/community/huiju/vo/ToUserVO.java 查看文件

1
 package com.community.huiju.vo;
1
 package com.community.huiju.vo;
2
 
2
 
3
+import com.community.huiju.model.ToSysRole;
3
 import lombok.AllArgsConstructor;
4
 import lombok.AllArgsConstructor;
4
 import lombok.Data;
5
 import lombok.Data;
5
 import lombok.NoArgsConstructor;
6
 import lombok.NoArgsConstructor;
6
 
7
 
7
 import java.util.Date;
8
 import java.util.Date;
9
+import java.util.List;
8
 
10
 
9
 /**
11
 /**
10
  * @author weiximei
12
  * @author weiximei
49
     /** 用户token **/
51
     /** 用户token **/
50
     private String token;
52
     private String token;
51
 
53
 
54
+    /** 角色 **/
55
+    private List<ToSysRole> roles;
56
+
52
 }
57
 }

+ 6
- 0
CODE/smart-community/operate-api/src/main/resources/mapper/ToSysRoleMapper.xml 查看文件

125
       update_date = #{updateDate,jdbcType=TIMESTAMP}
125
       update_date = #{updateDate,jdbcType=TIMESTAMP}
126
     where id = #{id,jdbcType=INTEGER}
126
     where id = #{id,jdbcType=INTEGER}
127
   </update>
127
   </update>
128
+
129
+  <select id="selectRoleByUserId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
130
+    select
131
+    role.*
132
+     from to_sys_user_role ur left join to_sys_role role on ur.role_id = role.id where ur.user_id=#{userId}
133
+  </select>
128
 </mapper>
134
 </mapper>

+ 1
- 1
CODE/smart-community/zuul/src/main/resources/mapper/ToSysRoleMapper.xml 查看文件

129
   <select id="selectRoleByUserId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
129
   <select id="selectRoleByUserId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
130
     select
130
     select
131
     role.*
131
     role.*
132
-     from to_sys_user_role ur left join ta_sys_role role on ur.role_id = role.id where ur.user_id=#{userId}
132
+     from to_sys_user_role ur left join to_sys_role role on ur.role_id = role.id where ur.user_id=#{userId}
133
   </select>
133
   </select>
134
 
134
 
135
 </mapper>
135
 </mapper>