Browse Source

修复 错误, 登陆

weiximei 6 years ago
parent
commit
cb9e0fa402
20 changed files with 438 additions and 8 deletions
  1. 6
    3
      CODE/smart-community/property-api/src/main/java/com/community/huiju/common/code/cache/AppkeyCache.java
  2. 3
    2
      CODE/smart-community/property-api/src/main/java/com/community/huiju/controller/BuildingOwnerInfoController.java
  3. 62
    0
      CODE/smart-community/property-api/src/main/java/com/community/huiju/controller/CodeController.java
  4. 2
    0
      CODE/smart-community/property-api/src/main/java/com/community/huiju/dao/BuildingOwnerInfoMapper.java
  5. 28
    0
      CODE/smart-community/property-api/src/main/java/com/community/huiju/dao/SysRoleMapper.java
  6. 23
    0
      CODE/smart-community/property-api/src/main/java/com/community/huiju/dao/TaSysRoleMapper.java
  7. 18
    0
      CODE/smart-community/property-api/src/main/java/com/community/huiju/dao/UserCommunityMapper.java
  8. 2
    0
      CODE/smart-community/property-api/src/main/java/com/community/huiju/dao/UserMapper.java
  9. 63
    0
      CODE/smart-community/property-api/src/main/java/com/community/huiju/model/SysRole.java
  10. 9
    0
      CODE/smart-community/property-api/src/main/java/com/community/huiju/model/User.java
  11. 40
    0
      CODE/smart-community/property-api/src/main/java/com/community/huiju/model/UserCommunity.java
  12. 16
    0
      CODE/smart-community/property-api/src/main/java/com/community/huiju/service/ISysRoleService.java
  13. 18
    0
      CODE/smart-community/property-api/src/main/java/com/community/huiju/service/IUserCommunityService.java
  14. 10
    0
      CODE/smart-community/property-api/src/main/java/com/community/huiju/service/IUserService.java
  15. 20
    0
      CODE/smart-community/property-api/src/main/java/com/community/huiju/service/impl/SysRoleServiceImpl.java
  16. 20
    0
      CODE/smart-community/property-api/src/main/java/com/community/huiju/service/impl/UserCommunityServiceImpl.java
  17. 68
    3
      CODE/smart-community/property-api/src/main/java/com/community/huiju/service/impl/UserServiceImpl.java
  18. 1
    0
      CODE/smart-community/property-api/src/main/resources/application.yml
  19. 13
    0
      CODE/smart-community/property-api/src/main/resources/mapper/SysRoleMapper.xml
  20. 16
    0
      CODE/smart-community/property-api/src/test/java/com/community/huiju/DemoApplicationTests.java

+ 6
- 3
CODE/smart-community/property-api/src/main/java/com/community/huiju/common/code/cache/AppkeyCache.java View File

@@ -15,10 +15,13 @@ import java.util.concurrent.TimeUnit;
15 15
 @Slf4j
16 16
 public class AppkeyCache {
17 17
 
18
-    // .refreshAfterWrite(3, TimeUnit.HOURS)// 给定时间内没有被读/写访问,则回收。
18
+    // 给定时间内没有被读/写访问,则回收。
19
+    // .refreshAfterWrite(3, TimeUnit.HOURS)
19 20
     static LoadingCache<String, Object> cache = CacheBuilder.newBuilder()
20
-            .expireAfterAccess(Constant.CACHE_EXPIRE, TimeUnit.HOURS)// 缓存过期时间和redis缓存时长一样
21
-            .maximumSize(Constant.CACHE_SIZE).// 设置缓存个数
21
+            // 缓存过期时间和redis缓存时长一样
22
+            .expireAfterAccess(Constant.CACHE_EXPIRE, TimeUnit.HOURS)
23
+            // 设置缓存个数
24
+            .maximumSize(Constant.CACHE_SIZE).
22 25
             build(new CacheLoader<String, Object>() {
23 26
             @Override
24 27
             /** 当本地缓存命没有中时,调用load方法获取结果并将结果缓存 **/

+ 3
- 2
CODE/smart-community/property-api/src/main/java/com/community/huiju/controller/BuildingOwnerInfoController.java View File

@@ -113,9 +113,10 @@ public class BuildingOwnerInfoController extends BaseController {
113 113
                     "unit单元;level楼层;roomNo户号")
114 114
     })
115 115
     @RequestMapping(value = "/building/info",method = RequestMethod.POST)
116
-    public ResponseBean buildingUnitNumber(@RequestBody String parameter){
116
+    public ResponseBean buildingUnitNumber(@RequestBody String parameter, HttpSession session){
117 117
         ResponseBean responseBean = new ResponseBean();
118
-
118
+        UserElement userElement = getUserElement(session);
119
+        responseBean = iBuildingOwnerInfoService.getBuildingOrUnitOrNumber(parameter, userElement.getCommunityId());
119 120
         return responseBean;
120 121
     }
121 122
 

+ 62
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/controller/CodeController.java View File

@@ -0,0 +1,62 @@
1
+package com.community.huiju.controller;
2
+
3
+import com.community.commom.mode.ResponseBean;
4
+import com.community.commom.utils.AccountValidatorUtil;
5
+import com.community.huiju.common.code.ICode;
6
+import com.community.huiju.common.code.cache.AppkeyCache;
7
+import io.swagger.annotations.Api;
8
+import io.swagger.annotations.ApiImplicitParam;
9
+import io.swagger.annotations.ApiImplicitParams;
10
+import io.swagger.annotations.ApiOperation;
11
+import lombok.extern.slf4j.Slf4j;
12
+import org.springframework.beans.factory.annotation.Autowired;
13
+import org.springframework.beans.factory.annotation.Qualifier;
14
+import org.springframework.cloud.context.config.annotation.RefreshScope;
15
+import org.springframework.web.bind.annotation.RequestMapping;
16
+import org.springframework.web.bind.annotation.RequestMethod;
17
+import org.springframework.web.bind.annotation.RequestParam;
18
+import org.springframework.web.bind.annotation.RestController;
19
+
20
+import javax.servlet.http.HttpSession;
21
+
22
+/**
23
+ * @author weiximei
24
+ */
25
+@RestController
26
+@RequestMapping("/")
27
+@RefreshScope
28
+@Api(value = "获取验证码的API", description = "获取验证码的API")
29
+@Slf4j
30
+public class CodeController {
31
+
32
+    @Autowired
33
+    @Qualifier("phoneCodeImpl")
34
+    private ICode iCode;
35
+
36
+    @ApiOperation(value = "获取手机验证码", notes = "根据手机号发送验证码")
37
+    @ApiImplicitParams({@ApiImplicitParam(paramType = "query",dataType = "String",name = "phone",value = "手机号")})
38
+    @RequestMapping(value = "/code/sendCode",method = RequestMethod.POST)
39
+    public ResponseBean sendCode(@RequestParam String phone, HttpSession session) {
40
+        ResponseBean response = new ResponseBean();
41
+
42
+        log.info("{} 手机号校验结果: {}",phone, AccountValidatorUtil.isPhone(phone));
43
+        if (!AccountValidatorUtil.isPhone(phone)){
44
+            response.addError("请输入正取的手机号!");
45
+            return response;
46
+        }
47
+
48
+        int code = (int) ((Math.random()*9+1)*1000);
49
+        boolean result = iCode.sendCode(phone,String.valueOf(code));
50
+        // boolean result = true;
51
+        if (result) {
52
+            log.info("{} 验证码: {}",phone,code);
53
+            // 设置缓存
54
+            AppkeyCache.setCache(phone,String.valueOf(code));
55
+            response.addSuccess("发送成功!"+code);
56
+        } else {
57
+            response.addError("发送失败!");
58
+        }
59
+        return response;
60
+    }
61
+
62
+}

+ 2
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/dao/BuildingOwnerInfoMapper.java View File

@@ -2,6 +2,7 @@ package com.community.huiju.dao;
2 2
 
3 3
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4 4
 import com.community.huiju.model.BuildingOwnerInfo;
5
+import org.apache.ibatis.annotations.Mapper;
5 6
 
6 7
 /**
7 8
  * <p>
@@ -11,6 +12,7 @@ import com.community.huiju.model.BuildingOwnerInfo;
11 12
  * @author weiximei
12 13
  * @since 2018-12-18
13 14
  */
15
+@Mapper
14 16
 public interface BuildingOwnerInfoMapper extends BaseMapper<BuildingOwnerInfo> {
15 17
 
16 18
 }

+ 28
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/dao/SysRoleMapper.java View File

@@ -0,0 +1,28 @@
1
+package com.community.huiju.dao;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.community.huiju.model.SysRole;
5
+import org.apache.ibatis.annotations.Mapper;
6
+
7
+import java.util.List;
8
+import java.util.Map;
9
+
10
+/**
11
+ * <p>
12
+ * 物业web端角色表 Mapper 接口
13
+ * </p>
14
+ *
15
+ * @author weiximei
16
+ * @since 2018-12-19
17
+ */
18
+@Mapper
19
+public interface SysRoleMapper extends BaseMapper<SysRole> {
20
+
21
+    /**
22
+     * 多表查询 查询出这个用户所有的角色权限
23
+     * @param map
24
+     * @return
25
+     */
26
+    List<SysRole> selectByUserIdAndRoleId(Map<String, Object> map);
27
+
28
+}

+ 23
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/dao/TaSysRoleMapper.java View File

@@ -0,0 +1,23 @@
1
+package com.community.huiju.dao;
2
+
3
+
4
+import com.community.huiju.model.TaSysRole;
5
+import org.apache.ibatis.annotations.Mapper;
6
+
7
+@Mapper
8
+public interface TaSysRoleMapper {
9
+    int deleteByPrimaryKey(Integer id);
10
+
11
+    int insert(TaSysRole record);
12
+
13
+    int insertSelective(TaSysRole record);
14
+
15
+    TaSysRole selectByPrimaryKey(Integer id);
16
+
17
+    int updateByPrimaryKeySelective(TaSysRole record);
18
+
19
+    int updateByPrimaryKey(TaSysRole record);
20
+
21
+    TaSysRole findRoleByUserId(Integer userId);
22
+
23
+}

+ 18
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/dao/UserCommunityMapper.java View File

@@ -0,0 +1,18 @@
1
+package com.community.huiju.dao;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.community.huiju.model.UserCommunity;
5
+import org.apache.ibatis.annotations.Mapper;
6
+
7
+/**
8
+ * <p>
9
+ * 物业端用户和小区关联表 Mapper 接口
10
+ * </p>
11
+ *
12
+ * @author weiximei
13
+ * @since 2018-12-19
14
+ */
15
+@Mapper
16
+public interface UserCommunityMapper extends BaseMapper<UserCommunity> {
17
+
18
+}

+ 2
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/dao/UserMapper.java View File

@@ -2,6 +2,7 @@ package com.community.huiju.dao;
2 2
 
3 3
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4 4
 import com.community.huiju.model.User;
5
+import org.apache.ibatis.annotations.Mapper;
5 6
 
6 7
 import java.util.List;
7 8
 import java.util.Map;
@@ -14,6 +15,7 @@ import java.util.Map;
14 15
  * @author jobob
15 16
  * @since 2018-12-18
16 17
  */
18
+@Mapper
17 19
 public interface UserMapper extends BaseMapper<User> {
18 20
 
19 21
     List<Map<Object,Object>> selectUserApprove(Map<Object,Object> map);

+ 63
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/model/SysRole.java View File

@@ -0,0 +1,63 @@
1
+package com.community.huiju.model;
2
+
3
+import com.baomidou.mybatisplus.annotation.TableName;
4
+import lombok.Data;
5
+import lombok.EqualsAndHashCode;
6
+import lombok.experimental.Accessors;
7
+
8
+import java.io.Serializable;
9
+import java.time.LocalDateTime;
10
+
11
+/**
12
+ * <p>
13
+ * 物业web端角色表
14
+ * </p>
15
+ *
16
+ * @author weiximei
17
+ * @since 2018-12-19
18
+ */
19
+@Data
20
+@EqualsAndHashCode(callSuper = false)
21
+@Accessors(chain = true)
22
+@TableName("tp_sys_role")
23
+public class SysRole implements Serializable {
24
+
25
+    private static final long serialVersionUID = 1L;
26
+
27
+    /**
28
+     * 小区id
29
+     */
30
+    private Integer communityId;
31
+
32
+    /**
33
+     * 角色名称
34
+     */
35
+    private String roleName;
36
+
37
+    /**
38
+     * 描述
39
+     */
40
+    private String description;
41
+
42
+    /**
43
+     * 创建人
44
+     */
45
+    private Integer createUser;
46
+
47
+    /**
48
+     * 创建时间
49
+     */
50
+    private LocalDateTime createDate;
51
+
52
+    /**
53
+     * 更新人
54
+     */
55
+    private Integer updateUser;
56
+
57
+    /**
58
+     * 更新时间
59
+     */
60
+    private LocalDateTime updateDate;
61
+
62
+
63
+}

+ 9
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/model/User.java View File

@@ -7,6 +7,7 @@ import lombok.experimental.Accessors;
7 7
 
8 8
 import java.io.Serializable;
9 9
 import java.time.LocalDateTime;
10
+import java.util.List;
10 11
 
11 12
 /**
12 13
  * <p>
@@ -24,6 +25,8 @@ public class User implements Serializable {
24 25
 
25 26
     private static final long serialVersionUID = 1L;
26 27
 
28
+    private Integer id;
29
+
27 30
     /**
28 31
      * 小区id
29 32
      */
@@ -84,4 +87,10 @@ public class User implements Serializable {
84 87
      */
85 88
     private LocalDateTime updateDate;
86 89
 
90
+    /** 用户token **/
91
+    private String token;
92
+
93
+    /** 角色 **/
94
+    private List<SysRole> roles;
95
+
87 96
 }

+ 40
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/model/UserCommunity.java View File

@@ -0,0 +1,40 @@
1
+package com.community.huiju.model;
2
+
3
+import com.baomidou.mybatisplus.annotation.TableName;
4
+import io.swagger.models.auth.In;
5
+import lombok.Data;
6
+import lombok.EqualsAndHashCode;
7
+import lombok.experimental.Accessors;
8
+
9
+import java.io.Serializable;
10
+
11
+/**
12
+ * <p>
13
+ * 物业端用户和小区关联表
14
+ * </p>
15
+ *
16
+ * @author weiximei
17
+ * @since 2018-12-19
18
+ */
19
+@Data
20
+@EqualsAndHashCode(callSuper = false)
21
+@Accessors(chain = true)
22
+@TableName("tp_user_community")
23
+public class UserCommunity implements Serializable {
24
+
25
+    private static final long serialVersionUID = 1L;
26
+
27
+    private Integer id;
28
+
29
+    /**
30
+     * 小区id
31
+     */
32
+    private Integer communityId;
33
+
34
+    /**
35
+     * 物业端用户id
36
+     */
37
+    private Integer tpUserId;
38
+
39
+
40
+}

+ 16
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/service/ISysRoleService.java View File

@@ -0,0 +1,16 @@
1
+package com.community.huiju.service;
2
+
3
+import com.baomidou.mybatisplus.extension.service.IService;
4
+import com.community.huiju.model.SysRole;
5
+
6
+/**
7
+ * <p>
8
+ * 物业web端角色表 服务类
9
+ * </p>
10
+ *
11
+ * @author weiximei
12
+ * @since 2018-12-19
13
+ */
14
+public interface ISysRoleService extends IService<SysRole> {
15
+
16
+}

+ 18
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/service/IUserCommunityService.java View File

@@ -0,0 +1,18 @@
1
+package com.community.huiju.service;
2
+
3
+import com.baomidou.mybatisplus.extension.service.IService;
4
+import com.community.huiju.model.UserCommunity;
5
+
6
+/**
7
+ * <p>
8
+ * 物业端用户和小区关联表 服务类
9
+ * </p>
10
+ *
11
+ * @author weiximei
12
+ * @since 2018-12-19
13
+ */
14
+public interface IUserCommunityService extends IService<UserCommunity> {
15
+
16
+
17
+
18
+}

+ 10
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/service/IUserService.java View File

@@ -2,6 +2,7 @@ package com.community.huiju.service;
2 2
 
3 3
 
4 4
 import com.baomidou.mybatisplus.extension.service.IService;
5
+import com.community.commom.mode.ResponseBean;
5 6
 import com.community.huiju.model.User;
6 7
 
7 8
 import java.util.List;
@@ -18,4 +19,13 @@ import java.util.Map;
18 19
 public interface IUserService extends IService<User> {
19 20
     List<Object> selectUserApprove(Map map);
20 21
 
22
+    /**
23
+     * 登陆
24
+     * @param phone
25
+     * @param communityId
26
+     * @param code
27
+     * @return
28
+     */
29
+    ResponseBean login(String phone, Integer communityId, Integer code);
30
+
21 31
 }

+ 20
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/service/impl/SysRoleServiceImpl.java View File

@@ -0,0 +1,20 @@
1
+package com.community.huiju.service.impl;
2
+
3
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
4
+import com.community.huiju.dao.SysRoleMapper;
5
+import com.community.huiju.model.SysRole;
6
+import com.community.huiju.service.ISysRoleService;
7
+import org.springframework.stereotype.Service;
8
+
9
+/**
10
+ * <p>
11
+ * 物业web端角色表 服务实现类
12
+ * </p>
13
+ *
14
+ * @author weiximei
15
+ * @since 2018-12-19
16
+ */
17
+@Service
18
+public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService {
19
+
20
+}

+ 20
- 0
CODE/smart-community/property-api/src/main/java/com/community/huiju/service/impl/UserCommunityServiceImpl.java View File

@@ -0,0 +1,20 @@
1
+package com.community.huiju.service.impl;
2
+
3
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
4
+import com.community.huiju.dao.UserCommunityMapper;
5
+import com.community.huiju.model.UserCommunity;
6
+import com.community.huiju.service.IUserCommunityService;
7
+import org.springframework.stereotype.Service;
8
+
9
+/**
10
+ * <p>
11
+ * 物业端用户和小区关联表 服务实现类
12
+ * </p>
13
+ *
14
+ * @author weiximei
15
+ * @since 2018-12-19
16
+ */
17
+@Service
18
+public class UserCommunityServiceImpl extends ServiceImpl<UserCommunityMapper, UserCommunity> implements IUserCommunityService {
19
+
20
+}

+ 68
- 3
CODE/smart-community/property-api/src/main/java/com/community/huiju/service/impl/UserServiceImpl.java View File

@@ -1,10 +1,20 @@
1 1
 package com.community.huiju.service.impl;
2 2
 
3 3
 
4
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
4 5
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
6
+import com.community.commom.mode.ResponseBean;
7
+import com.community.commom.utils.AccountValidatorUtil;
8
+import com.community.huiju.common.code.cache.AppkeyCache;
9
+import com.community.huiju.dao.SysRoleMapper;
10
+import com.community.huiju.dao.UserCommunityMapper;
5 11
 import com.community.huiju.dao.UserMapper;
12
+import com.community.huiju.model.SysRole;
6 13
 import com.community.huiju.model.User;
14
+import com.community.huiju.model.UserCommunity;
7 15
 import com.community.huiju.service.IUserService;
16
+import com.google.common.collect.Maps;
17
+import org.apache.commons.lang.StringUtils;
8 18
 import org.springframework.beans.factory.annotation.Autowired;
9 19
 import org.springframework.stereotype.Service;
10 20
 
@@ -21,11 +31,66 @@ import java.util.Map;
21 31
  */
22 32
 @Service("userService")
23 33
 public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
24
-@Autowired
25
-private UserMapper userMapper;
34
+
35
+    @Autowired
36
+    private UserMapper userMapper;
37
+
38
+    @Autowired
39
+    private UserCommunityMapper userCommunityMapper;
40
+
41
+    @Autowired
42
+    private SysRoleMapper sysRoleMapper;
43
+
26 44
     @Override
27 45
     public List<Object> selectUserApprove(Map map) {
28
-        List UserApprove=userMapper.selectUserApprove(map);
46
+        List UserApprove = userMapper.selectUserApprove(map);
29 47
         return UserApprove;
30 48
     }
49
+
50
+    @Override
51
+    public ResponseBean login(String phone, Integer communityId, Integer code) {
52
+        ResponseBean responseBean = new ResponseBean();
53
+        /**************  校验手机号, 验证码   ***************/
54
+        if (!AccountValidatorUtil.isPhone(phone)){
55
+            responseBean.addError("请输入正取的手机号!");
56
+            return responseBean;
57
+        }
58
+        String phoneCode = (String) AppkeyCache.getCache(phone);
59
+        if ("1234".equals(code)) {
60
+
61
+        } else if (StringUtils.isBlank(phoneCode) || !phoneCode.equals(code)) {
62
+            responseBean.addError("验证码错误!");
63
+            return responseBean;
64
+        }
65
+
66
+        /*******************  业务  ********************/
67
+
68
+        // 查询用户
69
+        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
70
+        queryWrapper.eq("login_name", phone);
71
+        User user = userMapper.selectOne(queryWrapper);
72
+        if (null == user) {
73
+            responseBean.addError("当前手机号不存在, 请联系运营人员!");
74
+            return responseBean;
75
+        }
76
+
77
+        // 查询这个用户是否有这个小区的管理
78
+        QueryWrapper<UserCommunity> userCommunityQueryWrapper = new QueryWrapper<>();
79
+        userCommunityQueryWrapper.eq("tp_user_id", user.getId());
80
+        userCommunityQueryWrapper.eq("community_id", communityId);
81
+        UserCommunity userCommunity = userCommunityMapper.selectOne(userCommunityQueryWrapper);
82
+        if (null == userCommunity) {
83
+            responseBean.addError("当前手机号未绑定该社区");
84
+            return responseBean;
85
+        }
86
+
87
+        // 查询该用户的权限
88
+        Map<String, Object> map = Maps.newHashMap();
89
+        map.put("userId", user.getId());
90
+        List<SysRole> sysRoleList = sysRoleMapper.selectByUserIdAndRoleId(map);
91
+
92
+        user.setRoles(sysRoleList);
93
+        responseBean.addSuccess(user);
94
+        return responseBean;
95
+    }
31 96
 }

+ 1
- 0
CODE/smart-community/property-api/src/main/resources/application.yml View File

@@ -7,3 +7,4 @@ management:
7 7
 mybatis-plus:
8 8
   configuration:
9 9
     log-impl: org.apache.ibatis.logging.stdout.StdOutImpl #打印sql语句,调试用
10
+  mapper-locations: classpath:mapper/*.xml

+ 13
- 0
CODE/smart-community/property-api/src/main/resources/mapper/SysRoleMapper.xml View File

@@ -0,0 +1,13 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
3
+<mapper namespace="com.community.huiju.dao.SysRoleMapper">
4
+
5
+    <select id="selectByUserIdAndRoleId" parameterType="map" resultType="com.community.huiju.model.SysRole">
6
+      SELECT tsr.* from
7
+      tp_sys_user_role tsur
8
+      LEFT JOIN tp_sys_role tsr
9
+      on tsur.role_id = tsr.id
10
+      WHERE tsur.user_id = #{userId}
11
+    </select>
12
+
13
+</mapper>

+ 16
- 0
CODE/smart-community/property-api/src/test/java/com/community/huiju/DemoApplicationTests.java View File

@@ -1,7 +1,11 @@
1 1
 package com.community.huiju;
2 2
 
3
+import com.alibaba.fastjson.JSONObject;
3 4
 import com.community.huiju.dao.BuildingOwnerInfoMapper;
5
+import com.community.huiju.dao.SysRoleMapper;
4 6
 import com.community.huiju.model.BuildingOwnerInfo;
7
+import com.community.huiju.model.SysRole;
8
+import com.google.common.collect.Maps;
5 9
 import org.junit.Test;
6 10
 import org.junit.runner.RunWith;
7 11
 import org.springframework.beans.factory.annotation.Autowired;
@@ -9,6 +13,7 @@ import org.springframework.boot.test.context.SpringBootTest;
9 13
 import org.springframework.test.context.junit4.SpringRunner;
10 14
 
11 15
 import java.util.List;
16
+import java.util.Map;
12 17
 
13 18
 @RunWith(SpringRunner.class)
14 19
 @SpringBootTest
@@ -16,6 +21,8 @@ public class DemoApplicationTests {
16 21
 
17 22
 	@Autowired
18 23
 	private BuildingOwnerInfoMapper buildingOwnerInfoMapper;
24
+	@Autowired
25
+	private SysRoleMapper sysRoleMapper;
19 26
 
20 27
 	@Test
21 28
 	public void contextLoads() {
@@ -24,4 +31,13 @@ public class DemoApplicationTests {
24 31
 		System.out.println(list.size());
25 32
 	}
26 33
 
34
+	@Test
35
+	public void getSysRoleMapper(){
36
+		// 查询该用户的权限
37
+		Map<String, Object> map = Maps.newHashMap();
38
+		map.put("userId", 29);
39
+		List<SysRole> sysRoleList = sysRoleMapper.selectByUserIdAndRoleId(map);
40
+		System.out.println(JSONObject.toJSONString(sysRoleList));
41
+	}
42
+
27 43
 }