|
|
@ -11,7 +11,7 @@ import com.elink.esua.epdc.commons.tools.exception.RenException; |
|
|
|
import com.elink.esua.epdc.commons.tools.redis.RedisUtils; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.*; |
|
|
|
import com.elink.esua.epdc.dto.*; |
|
|
|
import com.elink.esua.epdc.dto.epdc.EpdcGridLeaderRegisterDTO; |
|
|
|
import com.elink.esua.epdc.dto.epdc.form.EpdcGridLeaderRegisterFormDTO; |
|
|
|
import com.elink.esua.epdc.dto.epdc.GridLeaderRegisterDTO; |
|
|
|
import com.elink.esua.epdc.dto.epdc.form.*; |
|
|
|
import com.elink.esua.epdc.dto.epdc.result.EpdcUserInfoResultDTO; |
|
|
@ -178,29 +178,10 @@ public class AppUserServiceImpl implements AppUserService { |
|
|
|
} |
|
|
|
// 用户已注册且审核通过,正常登录系统
|
|
|
|
else if (AppUserAuditStateEnum.AUDIT_SUCCESS.value().equals(state)) { |
|
|
|
String userId = userDto.getId(); |
|
|
|
TokenDto tokenInfo = tokenUtil.getTokenInfo(userId); |
|
|
|
// 生成token
|
|
|
|
String token = jwtTokenUtils.generateToken(userId); |
|
|
|
Long expire; |
|
|
|
// 用户已登录过,且用户缓存信息未超时
|
|
|
|
if (null != tokenInfo) { |
|
|
|
tokenUtil.delayToken(userId); |
|
|
|
expire = tokenUtil.getExpire(userId); |
|
|
|
} else { |
|
|
|
expire = (long) jwtTokenProperties.getExpire(); |
|
|
|
} |
|
|
|
TokenDto tokenDto = ConvertUtils.sourceToTarget(userDto, TokenDto.class); |
|
|
|
tokenDto.setUserId(userId); |
|
|
|
cpUserDetailRedis.set(tokenDto, expire); |
|
|
|
// 暂用,部署生产环境时删除
|
|
|
|
redisUtils.set("epdc:sys:security:cpuser:token:" + userId, token); |
|
|
|
|
|
|
|
authorization.setUserState(AppUserStateEnum.REGISTERED.value()); |
|
|
|
authorization.setToken(token); |
|
|
|
authorization.setUserId(userId); |
|
|
|
authorization.setExpire(expire); |
|
|
|
authorization.setGrid(userDto.getGrid()); |
|
|
|
tokenDto.setUserId(userDto.getId()); |
|
|
|
authorization = this.packageEpdcAppAuthorization(tokenDto, userDto.getGrid()); |
|
|
|
|
|
|
|
return new Result().ok(authorization); |
|
|
|
} else { |
|
|
|
return new Result().error("Login failed"); |
|
|
@ -222,7 +203,7 @@ public class AppUserServiceImpl implements AppUserService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<EpdcAppAuthorizationDTO> maGridLeaderRegister(EpdcGridLeaderRegisterFormDTO formDto) { |
|
|
|
public Result<EpdcAppAuthorizationDTO> maGridLeaderRegister(EpdcGridLeaderRegisterSubmitFormDTO formDto) { |
|
|
|
|
|
|
|
String mobile = formDto.getMobile(); |
|
|
|
|
|
|
@ -247,7 +228,7 @@ public class AppUserServiceImpl implements AppUserService { |
|
|
|
UserDTO appUser = this.packageGridLeaderWhileRegister(leaderRegisterDto.getSysUser(), formDto.getWxCode()); |
|
|
|
List<UserGridRelationDTO> userGridList = ConvertUtils.sourceToTarget(leaderRegisterDto.getLeaderGridList(), UserGridRelationDTO.class); |
|
|
|
|
|
|
|
EpdcGridLeaderRegisterDTO registerDto = new EpdcGridLeaderRegisterDTO(); |
|
|
|
EpdcGridLeaderRegisterFormDTO registerDto = new EpdcGridLeaderRegisterFormDTO(); |
|
|
|
registerDto.setUserDto(appUser); |
|
|
|
registerDto.setUserGridList(userGridList); |
|
|
|
|
|
|
@ -258,23 +239,12 @@ public class AppUserServiceImpl implements AppUserService { |
|
|
|
|
|
|
|
UserDTO newAppUser = appUserResult.getData(); |
|
|
|
|
|
|
|
String appUserId = newAppUser.getId(); |
|
|
|
int expire = jwtTokenProperties.getExpire(); |
|
|
|
String token = jwtTokenUtils.generateToken(appUserId); |
|
|
|
EpdcAppAuthorizationDTO authorization = new EpdcAppAuthorizationDTO(); |
|
|
|
// 网格长注册,默认审核通过
|
|
|
|
authorization.setUserState(AppUserStateEnum.REGISTERED.value()); |
|
|
|
// 用户已注册且审核通过,正常登录系统
|
|
|
|
TokenDto tokenDto = ConvertUtils.sourceToTarget(newAppUser, TokenDto.class); |
|
|
|
tokenDto.setUserId(appUserId); |
|
|
|
cpUserDetailRedis.set(tokenDto, expire); |
|
|
|
// 暂用,部署生产环境时删除
|
|
|
|
redisUtils.set("epdc:sys:security:cpuser:token:" + appUserId, token); |
|
|
|
tokenDto.setUserId(newAppUser.getId()); |
|
|
|
|
|
|
|
EpdcAppAuthorizationDTO authorization = this.packageEpdcAppAuthorization(tokenDto, newAppUser.getGrid()); |
|
|
|
|
|
|
|
authorization.setToken(token); |
|
|
|
authorization.setUserId(appUserId); |
|
|
|
authorization.setExpire((long) expire); |
|
|
|
authorization.setGrid(newAppUser.getGrid()); |
|
|
|
return new Result().ok(authorization); |
|
|
|
} |
|
|
|
|
|
|
@ -566,4 +536,56 @@ public class AppUserServiceImpl implements AppUserService { |
|
|
|
} |
|
|
|
return userFeignClient.updateMobileOrAvatar(userDto); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Result<EpdcAppAuthorizationDTO> gridLeaderSwitchGrid(TokenDto userDetail, String gridId) { |
|
|
|
|
|
|
|
String userId = userDetail.getUserId(); |
|
|
|
|
|
|
|
EpdcLeaderSwitchGridFormDTO switchGrid = new EpdcLeaderSwitchGridFormDTO(); |
|
|
|
switchGrid.setAppUserId(userId); |
|
|
|
switchGrid.setGridId(gridId); |
|
|
|
// 更新用户-网格关系表,更新将要切换的网格的 SWITCHED_TIME 字段
|
|
|
|
Result<UserGridRelationDTO> appUserResult = userFeignClient.leaderSwitchGrid(switchGrid); |
|
|
|
if (!appUserResult.success()) { |
|
|
|
return new Result().error(appUserResult.getMsg()); |
|
|
|
} |
|
|
|
UserGridRelationDTO userGridRelation = appUserResult.getData(); |
|
|
|
|
|
|
|
userDetail.setGridId(Long.parseLong(gridId)); |
|
|
|
EpdcAppAuthorizationDTO authorization = this.packageEpdcAppAuthorization(userDetail, userGridRelation.getGrid()); |
|
|
|
|
|
|
|
return new Result().ok(authorization); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 组装成功登录的数据 |
|
|
|
* EpdcAppAuthorizationDTO的userState属性默认设置为AppUserStateEnum.REGISTERED |
|
|
|
* |
|
|
|
* @param tokenDto 缓存的用户数据 |
|
|
|
* @param grid 网格名称 |
|
|
|
* @return com.elink.esua.epdc.dto.result.EpdcAppAuthorizationDTO |
|
|
|
* @author work@yujt.net.cn |
|
|
|
* @date 2019/10/23 13:57 |
|
|
|
*/ |
|
|
|
private EpdcAppAuthorizationDTO packageEpdcAppAuthorization(TokenDto tokenDto, String grid) { |
|
|
|
String userId = tokenDto.getUserId(); |
|
|
|
// 生成token
|
|
|
|
String token = jwtTokenUtils.generateToken(userId); |
|
|
|
int expire = jwtTokenProperties.getExpire(); |
|
|
|
|
|
|
|
cpUserDetailRedis.set(tokenDto, expire); |
|
|
|
|
|
|
|
EpdcAppAuthorizationDTO authorization = new EpdcAppAuthorizationDTO(); |
|
|
|
authorization.setUserState(AppUserStateEnum.REGISTERED.value()); |
|
|
|
authorization.setToken(token); |
|
|
|
authorization.setUserId(userId); |
|
|
|
authorization.setExpire((long) expire); |
|
|
|
authorization.setGrid(grid); |
|
|
|
|
|
|
|
// 暂用,部署生产环境时删除
|
|
|
|
redisUtils.set("epdc:sys:security:cpuser:token:" + userId, token); |
|
|
|
|
|
|
|
return authorization; |
|
|
|
} |
|
|
|
} |
|
|
|