diff --git a/pom.xml b/pom.xml index efba1a6..a0ec4a1 100644 --- a/pom.xml +++ b/pom.xml @@ -104,6 +104,12 @@ + + ink.wgink + login-wechat + 1.0-SNAPSHOT + + ink.wgink service-position diff --git a/src/main/java/cn/com/tenlion/usercenter/controller/resource/userexpand/UserExpandResourceController.java b/src/main/java/cn/com/tenlion/usercenter/controller/resource/userexpand/UserExpandResourceController.java index 5998974..00587eb 100644 --- a/src/main/java/cn/com/tenlion/usercenter/controller/resource/userexpand/UserExpandResourceController.java +++ b/src/main/java/cn/com/tenlion/usercenter/controller/resource/userexpand/UserExpandResourceController.java @@ -1,6 +1,8 @@ package cn.com.tenlion.usercenter.controller.resource.userexpand; +import cn.com.tenlion.usercenter.pojo.dtos.userexpand.GridUserAuthBindDTO; import cn.com.tenlion.usercenter.pojo.dtos.userexpand.UserExpandDTO; +import cn.com.tenlion.usercenter.pojo.vos.userexpand.GridUserAuthBindVO; import cn.com.tenlion.usercenter.pojo.vos.userexpand.UserExpandVO; import cn.com.tenlion.usercenter.service.userexpand.IUserExpandService; import ink.wgink.annotation.CheckRequestBodyAnnotation; @@ -43,6 +45,17 @@ public class UserExpandResourceController extends DefaultBaseController { return new SuccessResult(); } + @ApiOperation(value = "认证并绑定网格员", notes = "认证并绑定网格员接口") + @ApiImplicitParams({ + @ApiImplicitParam(name = "access_token", value = "token", paramType = "query") + }) + @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) + @PostMapping(name = "auth-and-bind") + @CheckRequestBodyAnnotation + public GridUserAuthBindDTO authAndBind(@RequestBody GridUserAuthBindVO gridUserAuthBindVO) { + return userExpandService.getAuthAndBindResult(gridUserAuthBindVO); + } + @ApiOperation(value = "拓展属性详情", notes = "拓展属性详情接口") @ApiImplicitParams({ @ApiImplicitParam(name = "userId", value = "用户ID", paramType = "path") diff --git a/src/main/java/cn/com/tenlion/usercenter/pojo/dtos/userexpand/GridUserAuthBindDTO.java b/src/main/java/cn/com/tenlion/usercenter/pojo/dtos/userexpand/GridUserAuthBindDTO.java new file mode 100644 index 0000000..9af2afd --- /dev/null +++ b/src/main/java/cn/com/tenlion/usercenter/pojo/dtos/userexpand/GridUserAuthBindDTO.java @@ -0,0 +1,59 @@ +package cn.com.tenlion.usercenter.pojo.dtos.userexpand; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.util.ArrayList; +import java.util.List; + +/** + * @ClassName: GridUserAuthBindDTO + * @Description: 网格用户认证绑定 + * @Author: wanggeng + * @Date: 2022/5/24 15:33 + * @Version: 1.0 + */ +@ApiModel +public class GridUserAuthBindDTO { + + @ApiModelProperty(name = "userId", value = "用户ID") + private String userId; + @ApiModelProperty(name = "areaCode", value = "区域编码") + private String areaCode; + @ApiModelProperty(name = "userLevel", value = "用户级别") + private Integer userLevel; + @ApiModelProperty(name = "areaCodes", value = "地区编码列表") + private List areaCodes; + + public String getUserId() { + return userId == null ? "" : userId.trim(); + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getAreaCode() { + return areaCode == null ? "" : areaCode.trim(); + } + + public void setAreaCode(String areaCode) { + this.areaCode = areaCode; + } + + public Integer getUserLevel() { + return userLevel == null ? 0 : userLevel; + } + + public void setUserLevel(Integer userLevel) { + this.userLevel = userLevel; + } + + public List getAreaCodes() { + return areaCodes == null ? new ArrayList() : areaCodes; + } + + public void setAreaCodes(List areaCodes) { + this.areaCodes = areaCodes; + } +} diff --git a/src/main/java/cn/com/tenlion/usercenter/pojo/vos/userexpand/GridUserAuthBindVO.java b/src/main/java/cn/com/tenlion/usercenter/pojo/vos/userexpand/GridUserAuthBindVO.java new file mode 100644 index 0000000..8ec7a91 --- /dev/null +++ b/src/main/java/cn/com/tenlion/usercenter/pojo/vos/userexpand/GridUserAuthBindVO.java @@ -0,0 +1,51 @@ +package cn.com.tenlion.usercenter.pojo.vos.userexpand; + +import ink.wgink.annotation.CheckEmptyAnnotation; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +/** + * @ClassName: GridUserAuthVO + * @Description: 网格员认证+绑定 + * @Author: wanggeng + * @Date: 2022/5/24 15:28 + * @Version: 1.0 + */ +@ApiModel +public class GridUserAuthBindVO { + + @ApiModelProperty(name = "userId", value = "需要绑定的用户ID") + @CheckEmptyAnnotation(name = "用户ID") + private String userId; + @ApiModelProperty(name = "username", value = "用户名") + @CheckEmptyAnnotation(name = "用户名") + private String username; + @ApiModelProperty(name = "password", value = "密码") + @CheckEmptyAnnotation(name = "密码") + private String password; + + public String getUserId() { + return userId == null ? "" : userId.trim(); + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getUsername() { + return username == null ? "" : username.trim(); + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password == null ? "" : password.trim(); + } + + public void setPassword(String password) { + this.password = password; + } + +} diff --git a/src/main/java/cn/com/tenlion/usercenter/service/userexpand/IUserExpandService.java b/src/main/java/cn/com/tenlion/usercenter/service/userexpand/IUserExpandService.java index 0b3ec14..64c8d21 100644 --- a/src/main/java/cn/com/tenlion/usercenter/service/userexpand/IUserExpandService.java +++ b/src/main/java/cn/com/tenlion/usercenter/service/userexpand/IUserExpandService.java @@ -1,8 +1,10 @@ package cn.com.tenlion.usercenter.service.userexpand; +import cn.com.tenlion.usercenter.pojo.dtos.userexpand.GridUserAuthBindDTO; import cn.com.tenlion.usercenter.pojo.dtos.userexpand.OnlineGridMemberDTO; import cn.com.tenlion.usercenter.pojo.dtos.userexpand.UserExpandDTO; import cn.com.tenlion.usercenter.pojo.pos.userexpand.UserExpandPO; +import cn.com.tenlion.usercenter.pojo.vos.userexpand.GridUserAuthBindVO; import cn.com.tenlion.usercenter.pojo.vos.userexpand.UserExpandVO; import ink.wgink.interfaces.user.IUserExpandBaseService; import ink.wgink.pojo.dtos.user.UserDTO; @@ -84,4 +86,12 @@ public interface IUserExpandService extends IUserExpandBaseService listOnlineGridMemberReleaseByAreaCode(String areaCode); + + /** + * 认证并绑定网格员 + * + * @param gridUserAuthBindVO + * @return + */ + GridUserAuthBindDTO getAuthAndBindResult(GridUserAuthBindVO gridUserAuthBindVO); } diff --git a/src/main/java/cn/com/tenlion/usercenter/service/userexpand/impl/UserExpandServiceImpl.java b/src/main/java/cn/com/tenlion/usercenter/service/userexpand/impl/UserExpandServiceImpl.java index b91d342..3bf3b94 100644 --- a/src/main/java/cn/com/tenlion/usercenter/service/userexpand/impl/UserExpandServiceImpl.java +++ b/src/main/java/cn/com/tenlion/usercenter/service/userexpand/impl/UserExpandServiceImpl.java @@ -5,19 +5,24 @@ import cn.com.tenlion.usercenter.consts.ISmartCityUserCenterConsts; import cn.com.tenlion.usercenter.dao.userexpand.IUserExpandDao; import cn.com.tenlion.usercenter.manager.HuaWeiSMCManager; import cn.com.tenlion.usercenter.pojo.dtos.huawei.SMCMeetingDTO; +import cn.com.tenlion.usercenter.pojo.dtos.userexpand.GridUserAuthBindDTO; import cn.com.tenlion.usercenter.pojo.dtos.userexpand.OnlineGridMemberDTO; import cn.com.tenlion.usercenter.pojo.dtos.userexpand.UserExpandDTO; import cn.com.tenlion.usercenter.pojo.pos.userexpand.UserExpandPO; +import cn.com.tenlion.usercenter.pojo.vos.userexpand.GridUserAuthBindVO; import cn.com.tenlion.usercenter.pojo.vos.userexpand.UserExpandVO; import cn.com.tenlion.usercenter.service.userexpand.IUserExpandService; import ink.wgink.common.base.DefaultBaseService; +import ink.wgink.exceptions.ParamsException; import ink.wgink.exceptions.SearchException; import ink.wgink.interfaces.department.IDepartmentBaseService; import ink.wgink.interfaces.department.IDepartmentUserBaseService; import ink.wgink.interfaces.role.IRoleUserBaseService; -import ink.wgink.interfaces.user.IUserBaseService; import ink.wgink.module.dictionary.pojo.dtos.DataDTO; import ink.wgink.module.instantmessage.websocket.manager.WebSocketChannelManager; +import ink.wgink.module.map.pojo.dtos.grid.GridDTO; +import ink.wgink.module.map.service.grid.IGridRelationService; +import ink.wgink.module.map.service.grid.IGridService; import ink.wgink.mongo.module.dictionary.service.IMongoDataService; import ink.wgink.pojo.ListPage; import ink.wgink.pojo.dtos.department.DepartmentDTO; @@ -26,12 +31,15 @@ import ink.wgink.pojo.dtos.user.UserDTO; import ink.wgink.pojo.pos.DepartmentPO; import ink.wgink.pojo.result.SuccessResultList; import ink.wgink.pojo.session.WebSocketSession; +import ink.wgink.service.user.pojo.pos.UserPO; +import ink.wgink.service.user.service.IUserService; import ink.wgink.util.ArrayListUtil; import ink.wgink.util.map.HashMapUtil; import ink.wgink.util.string.WStringUtil; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import java.util.ArrayList; @@ -52,7 +60,7 @@ public class UserExpandServiceImpl extends DefaultBaseService implements IUserEx @Autowired private ParamsConfigProperties paramsConfigProperties; @Autowired - private IUserBaseService userBaseService; + private IUserService userService; @Autowired private IUserExpandDao userExpandDao; @Autowired @@ -62,10 +70,17 @@ public class UserExpandServiceImpl extends DefaultBaseService implements IUserEx @Autowired private IRoleUserBaseService roleUserBaseService; @Autowired + private IGridRelationService gridRelationService; + @Autowired + private IGridService gridService; + @Autowired private IMongoDataService mongoDataService; + @Autowired + private PasswordEncoder passwordEncoder; private static final String SMC_STATE_DELETE = "delete"; private static final String SMC_STATE_BIND = "bind"; + @Override public String getRoute() { return "route/user-expand/update"; @@ -73,7 +88,7 @@ public class UserExpandServiceImpl extends DefaultBaseService implements IUserEx @Override public UserExpandDTO get(String userId) { - UserDTO userDTO = userBaseService.get(userId); + UserDTO userDTO = userService.get(userId); if (userDTO == null) { throw new SearchException("用户不存在"); } @@ -94,7 +109,7 @@ public class UserExpandServiceImpl extends DefaultBaseService implements IUserEx @Override public List listByUserIds(List userIds) { - List userDTOs = userBaseService.listByUserIds(userIds); + List userDTOs = userService.listByUserIds(userIds); if (userDTOs.isEmpty()) { return new ArrayList<>(); } @@ -106,7 +121,7 @@ public class UserExpandServiceImpl extends DefaultBaseService implements IUserEx @Override public List listByUsernames(List usernames) { - List userDTOs = userBaseService.listByUsernames(usernames); + List userDTOs = userService.listByUsernames(usernames); if (userDTOs.isEmpty()) { return new ArrayList<>(); } @@ -217,7 +232,7 @@ public class UserExpandServiceImpl extends DefaultBaseService implements IUserEx * @throws Exception */ private void setSMCMeeting(String userId, Map params) throws Exception { - UserDTO userDTO = userBaseService.get(userId); + UserDTO userDTO = userService.get(userId); SMCMeetingDTO meeting = HuaWeiSMCManager.createMeeting(userDTO.getUserName(), userDTO.getUserUsername()); LOG.debug("meeting: {}", meeting); params.put("smcMeetingId", meeting.getMeetingId()); @@ -235,7 +250,7 @@ public class UserExpandServiceImpl extends DefaultBaseService implements IUserEx @Override public List listByUserIdsAndAreaCode(List userIds, String areaCode) { - List userDTOs = userBaseService.listByUserIds(userIds); + List userDTOs = userService.listByUserIds(userIds); if (userDTOs.isEmpty()) { return new ArrayList<>(); } @@ -307,7 +322,7 @@ public class UserExpandServiceImpl extends DefaultBaseService implements IUserEx onlineUserIds.add(webSocketSession.getUserId()); }); LOG.debug("area code: {}, user count: {}, online user count", areaCode, userExpandDTOs.size(), webSocketSessions.size()); - return userBaseService.listByUserIds(onlineUserIds); + return userService.listByUserIds(onlineUserIds); } @Override @@ -334,7 +349,7 @@ public class UserExpandServiceImpl extends DefaultBaseService implements IUserEx onlineUserIds.add(webSocketSession.getUserId()); }); // 在线用户列表 - List userDTOs = userBaseService.listByUserIds(onlineUserIds); + List userDTOs = userService.listByUserIds(onlineUserIds); LOG.debug("build online grid member list"); List gridMemberDTOs = new ArrayList<>(); userDTOs.forEach(userDTO -> { @@ -361,6 +376,31 @@ public class UserExpandServiceImpl extends DefaultBaseService implements IUserEx return gridMemberDTOs; } + @Override + public GridUserAuthBindDTO getAuthAndBindResult(GridUserAuthBindVO gridUserAuthBindVO) { + // 查询小程序端要绑定的网格员账号是否正确 + UserPO userPO = userService.getPOByUsername(gridUserAuthBindVO.getUsername()); + if (passwordEncoder.matches(userPO.getUserPassword(), gridUserAuthBindVO.getPassword())) { + throw new ParamsException("用户名密码不匹配"); + } + GridUserAuthBindDTO gridUserAuthBindDTO = new GridUserAuthBindDTO(); + gridUserAuthBindDTO.setUserId(userPO.getUserId()); + // 查询用户信息 + UserExpandPO userExpandPO = getPO(userPO.getUserId()); + if (userExpandPO != null) { + gridUserAuthBindDTO.setAreaCode(userExpandPO.getAreaCode()); + gridUserAuthBindDTO.setUserLevel(userExpandPO.getUserLevel()); + } + // 查询网格信息 + List gridIds = gridRelationService.listGridId(userPO.getUserId()); + if (!gridIds.isEmpty()) { + List gridDTOS = gridService.list(gridIds); + List gridCodes = ArrayListUtil.listBeanStringIdValue(gridDTOS, "gridCode", GridDTO.class); + gridUserAuthBindDTO.setAreaCodes(gridCodes); + } + return gridUserAuthBindDTO; + } + /** * 设置用户 *