|
|
|
@ -5,9 +5,9 @@ import com.gitee.fastmybatis.core.query.Query; |
|
|
|
|
import com.gitee.sop.openapi.config.RedisOperator; |
|
|
|
|
import com.gitee.sop.openapi.entity.IsvAuthTokenEntity; |
|
|
|
|
import com.gitee.sop.openapi.entity.IsvInfoEntity; |
|
|
|
|
import com.gitee.sop.openapi.mapper.IsvAuthTokenMapper; |
|
|
|
|
import com.gitee.sop.openapi.mapper.IsvInfoMapper; |
|
|
|
|
import com.gitee.sop.openapi.po.AuthCodePo; |
|
|
|
|
import com.gitee.sop.openapi.repository.IsvAuthTokenRepository; |
|
|
|
|
import com.gitee.sop.openapi.repository.IsvInfoRepository; |
|
|
|
|
import com.gitee.sop.openapi.vo.AuthCodeVo; |
|
|
|
|
import com.gitee.sop.openapi.util.MD5GeneratorUtil; |
|
|
|
|
import com.gitee.sop.openapi.util.RedisKeyUtil; |
|
|
|
@ -24,15 +24,15 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
@Service |
|
|
|
|
public class AuthCodeService implements AuthService { |
|
|
|
|
|
|
|
|
|
private final IsvInfoMapper isvInfoMapper; |
|
|
|
|
private final IsvAuthTokenMapper isvAuthTokenMapper; |
|
|
|
|
private final IsvInfoRepository isvInfoRepository; |
|
|
|
|
private final IsvAuthTokenRepository isvAuthTokenRepository; |
|
|
|
|
private final RedisOperator redisOperator; |
|
|
|
|
|
|
|
|
|
public AuthCodeService(final IsvInfoMapper isvInfoMapper, |
|
|
|
|
final IsvAuthTokenMapper isvAuthTokenMapper, |
|
|
|
|
public AuthCodeService(final IsvInfoRepository isvInfoRepository, |
|
|
|
|
final IsvAuthTokenRepository isvAuthTokenRepository, |
|
|
|
|
final RedisOperator redisOperator) { |
|
|
|
|
this.isvInfoMapper = isvInfoMapper; |
|
|
|
|
this.isvAuthTokenMapper = isvAuthTokenMapper; |
|
|
|
|
this.isvInfoRepository = isvInfoRepository; |
|
|
|
|
this.isvAuthTokenRepository = isvAuthTokenRepository; |
|
|
|
|
this.redisOperator = redisOperator; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -40,7 +40,7 @@ public class AuthCodeService implements AuthService { |
|
|
|
|
@Transactional |
|
|
|
|
public AuthCodeVo getCode(AuthCodePo authCodePo) { |
|
|
|
|
|
|
|
|
|
IsvInfoEntity isvInfo = isvInfoMapper.getByColumn("app_key", authCodePo.getAppId()); |
|
|
|
|
IsvInfoEntity isvInfo = isvInfoRepository.findFirstByAppKey(authCodePo.getAppId()); |
|
|
|
|
if (isvInfo == null || isvInfo.getStatus().intValue() == FORBIDDEN) { |
|
|
|
|
log.error("appId已禁用:{}", authCodePo.getAppId()); |
|
|
|
|
throw new ServiceException("应用ID未申请或已被禁用"); |
|
|
|
@ -48,11 +48,7 @@ public class AuthCodeService implements AuthService { |
|
|
|
|
|
|
|
|
|
String authCode = MD5GeneratorUtil.generateValue(); |
|
|
|
|
|
|
|
|
|
Query query = new Query() |
|
|
|
|
.eq("app_key", authCodePo.getAppId()) |
|
|
|
|
.eq("user_id", authCodePo.getUserId()) |
|
|
|
|
.eq("status", ENABLE_TOKEN); |
|
|
|
|
IsvAuthTokenEntity authTokenEntity = isvAuthTokenMapper.getByQuery(query); |
|
|
|
|
IsvAuthTokenEntity authTokenEntity = isvAuthTokenRepository.findFirstByAppKeyAndUserIdAndStatusTrue(authCodePo.getAppId(), authCodePo.getUserId()); |
|
|
|
|
AuthCodeVo authCodeVo = new AuthCodeVo(); |
|
|
|
|
authCodeVo.setCode(authCode); |
|
|
|
|
if (authTokenEntity == null) { |
|
|
|
@ -61,11 +57,9 @@ public class AuthCodeService implements AuthService { |
|
|
|
|
authTokenEntity.setAppAuthCode(authCode); |
|
|
|
|
authTokenEntity.setAppKey(authCodePo.getAppId()); |
|
|
|
|
authTokenEntity.setUserId(authCodePo.getUserId()); |
|
|
|
|
isvAuthTokenMapper.save(authTokenEntity); |
|
|
|
|
} else { |
|
|
|
|
authTokenEntity.setAppAuthCode(authCode); |
|
|
|
|
isvAuthTokenMapper.update(authTokenEntity); |
|
|
|
|
} |
|
|
|
|
authTokenEntity.setAppAuthCode(authCode); |
|
|
|
|
isvAuthTokenRepository.save(authTokenEntity); |
|
|
|
|
|
|
|
|
|
// 写入redis缓存
|
|
|
|
|
try { |
|
|
|
@ -87,14 +81,14 @@ public class AuthCodeService implements AuthService { |
|
|
|
|
.eq("user_id", userId) |
|
|
|
|
.eq("status", ENABLE_TOKEN); |
|
|
|
|
|
|
|
|
|
IsvAuthTokenEntity authTokenEntity = isvAuthTokenMapper.getByQuery(query); |
|
|
|
|
IsvAuthTokenEntity authTokenEntity = isvAuthTokenRepository.findFirstByUserIdAndStatusTrue(userId); |
|
|
|
|
if (authTokenEntity == null) { |
|
|
|
|
throw new ServiceException("用户未授权插件应用"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
authTokenEntity.setStatus(ENABLE_TOKEN); |
|
|
|
|
isvAuthTokenMapper.update(authTokenEntity); |
|
|
|
|
authTokenEntity.setStatus(true); |
|
|
|
|
isvAuthTokenRepository.save(authTokenEntity); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
throw new ServiceException("解除授权失败,系统忙,请稍后!"); |
|
|
|
|
} |
|
|
|
|