|
|
@ -7,15 +7,20 @@ import com.epmet.commons.tools.exception.EpmetException; |
|
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
|
import com.epmet.commons.tools.redis.common.CustomerStaffRedis; |
|
|
|
import com.epmet.commons.tools.security.dto.GovTokenDto; |
|
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
|
import com.epmet.commons.tools.security.password.PasswordUtils; |
|
|
|
import com.epmet.commons.tools.utils.CpUserDetailRedis; |
|
|
|
import com.epmet.commons.tools.utils.DateUtils; |
|
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
import com.epmet.dto.UserDTO; |
|
|
|
import com.epmet.dto.UserWechatDTO; |
|
|
|
import com.epmet.dto.form.GovWebLoginFormDTO; |
|
|
|
import com.epmet.dto.form.GovWebOperLoginFormDTO; |
|
|
|
import com.epmet.dto.form.LoginCommonFormDTO; |
|
|
|
import com.epmet.dto.result.GovWebOperLoginResultDTO; |
|
|
|
import com.epmet.dto.result.UserTokenResultDTO; |
|
|
|
import com.epmet.feign.EpmetUserFeignClient; |
|
|
|
import com.epmet.feign.EpmetUserOpenFeignClient; |
|
|
|
import com.epmet.jwt.JwtTokenProperties; |
|
|
|
import com.epmet.jwt.JwtTokenUtils; |
|
|
|
import com.epmet.service.CaptchaService; |
|
|
@ -50,6 +55,8 @@ public class GovWebServiceImpl implements GovWebService { |
|
|
|
private EpmetUserFeignClient epmetUserFeignClient; |
|
|
|
@Autowired |
|
|
|
private ThirdLoginServiceImpl thirdLoginService; |
|
|
|
@Autowired |
|
|
|
private EpmetUserOpenFeignClient epmetUserOpenFeignClient; |
|
|
|
|
|
|
|
/** |
|
|
|
* @param formDTO |
|
|
@ -98,40 +105,68 @@ public class GovWebServiceImpl implements GovWebService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String generateTokenBySSOKey(String customerId, String userId) { |
|
|
|
CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(customerId, userId); |
|
|
|
if (staffInfo == null){ |
|
|
|
log.error("工作人员信息不存在,customerId:{},userId:{}", customerId, userId); |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String generateTokenBySSOKey(String customerId, String userId, String app, String client) { |
|
|
|
// 生成token
|
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
map.put("app", "gov"); |
|
|
|
map.put("client", "web"); |
|
|
|
map.put(LoginConstant.CLIENT_APP, app); |
|
|
|
map.put("client", client); |
|
|
|
map.put("userId", userId); |
|
|
|
String token = jwtTokenUtils.createToken(map); |
|
|
|
int expire = jwtTokenProperties.getExpire(); |
|
|
|
|
|
|
|
String orgIdPath = thirdLoginService.getOrgIdPath(userId); |
|
|
|
String[] orgIdPathParts = orgIdPath.split(":"); |
|
|
|
if (LoginConstant.APP_RESI.equals(app)){ |
|
|
|
Result<UserDTO> userDTOResult = epmetUserOpenFeignClient.queryUserClient(userId); |
|
|
|
if (!userDTOResult.success()&&userDTOResult.getData() != null){ |
|
|
|
log.error("居民信息不存在,customerId:{},userId:{}", customerId, userId); |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode()); |
|
|
|
} |
|
|
|
LoginCommonFormDTO formDTO = new LoginCommonFormDTO(); |
|
|
|
formDTO.setApp(app); |
|
|
|
formDTO.setClient(client); |
|
|
|
this.saveResiTokenDto(formDTO,userId, new UserWechatDTO(),token,customerId); |
|
|
|
}else if (LoginConstant.APP_GOV.equals(app)){ |
|
|
|
CustomerStaffInfoCacheResult staffInfo = CustomerStaffRedis.getStaffInfo(customerId, userId); |
|
|
|
if (staffInfo == null){ |
|
|
|
log.error("工作人员信息不存在,customerId:{},userId:{}", customerId, userId); |
|
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode()); |
|
|
|
} |
|
|
|
int expire = jwtTokenProperties.getExpire(); |
|
|
|
GovTokenDto tokenDto = new GovTokenDto(); |
|
|
|
tokenDto.setCustomerId(customerId); |
|
|
|
tokenDto.setApp("gov"); |
|
|
|
tokenDto.setClient("web"); |
|
|
|
tokenDto.setUserId(userId); |
|
|
|
tokenDto.setToken(token); |
|
|
|
tokenDto.setUpdateTime(System.currentTimeMillis()); |
|
|
|
tokenDto.setExpireTime(jwtTokenUtils.getExpiration(token).getTime()); |
|
|
|
tokenDto.setAgencyId(staffInfo.getAgencyId()); |
|
|
|
tokenDto.setRootAgencyId(staffInfo.getAgencyId()); |
|
|
|
//tokenDto.setDeptIdList(thirdLoginService.getDeptartmentIdList(userId));
|
|
|
|
//tokenDto.setGridIdList(thirdLoginService.getGridIdList(userId));
|
|
|
|
//tokenDto.setRoleList(thirdLoginService.queryGovStaffRoles(userId, orgIdPathParts[orgIdPathParts.length - 1]));
|
|
|
|
//tokenDto.setOrgIdPath(orgIdPath);
|
|
|
|
cpUserDetailRedis.set(tokenDto, expire); |
|
|
|
} |
|
|
|
|
|
|
|
GovTokenDto tokenDto = new GovTokenDto(); |
|
|
|
logger.info("截止时间:" + DateUtils.format(jwtTokenUtils.getExpiration(token), "yyyy-MM-dd HH:mm:ss")); |
|
|
|
return token; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description 将token存入redis |
|
|
|
**/ |
|
|
|
private String saveResiTokenDto(LoginCommonFormDTO formDTO, String userId, UserWechatDTO userWechatDTO, String token, String customerId) { |
|
|
|
int expire = jwtTokenProperties.getExpire(); |
|
|
|
TokenDto tokenDto = new TokenDto(); |
|
|
|
tokenDto.setCustomerId(customerId); |
|
|
|
tokenDto.setApp("gov"); |
|
|
|
tokenDto.setClient("web"); |
|
|
|
tokenDto.setApp(formDTO.getApp()); |
|
|
|
tokenDto.setClient(formDTO.getClient()); |
|
|
|
tokenDto.setUserId(userId); |
|
|
|
//tokenDto.setOpenId(userWechatDTO.getWxOpenId());
|
|
|
|
//tokenDto.setSessionKey(userWechatDTO.getSessionKey());
|
|
|
|
//tokenDto.setUnionId(userWechatDTO.getUnionId());
|
|
|
|
tokenDto.setToken(token); |
|
|
|
tokenDto.setUpdateTime(System.currentTimeMillis()); |
|
|
|
tokenDto.setExpireTime(jwtTokenUtils.getExpiration(token).getTime()); |
|
|
|
tokenDto.setAgencyId(staffInfo.getAgencyId()); |
|
|
|
tokenDto.setRootAgencyId(staffInfo.getAgencyId()); |
|
|
|
//tokenDto.setDeptIdList(thirdLoginService.getDeptartmentIdList(userId));
|
|
|
|
//tokenDto.setGridIdList(thirdLoginService.getGridIdList(userId));
|
|
|
|
//tokenDto.setRoleList(thirdLoginService.queryGovStaffRoles(userId, orgIdPathParts[orgIdPathParts.length - 1]));
|
|
|
|
//tokenDto.setOrgIdPath(orgIdPath);
|
|
|
|
|
|
|
|
cpUserDetailRedis.set(tokenDto, expire); |
|
|
|
logger.info("截止时间:" + DateUtils.format(jwtTokenUtils.getExpiration(token), "yyyy-MM-dd HH:mm:ss")); |
|
|
|
return token; |
|
|
|