|
@@ -1,22 +1,58 @@
|
|
|
package cn.rankin.apiweb.service.auth;
|
|
|
|
|
|
+import cn.rankin.apiweb.service.user.UserClient;
|
|
|
import cn.rankin.common.utils.api.model.APIResult;
|
|
|
+import cn.rankin.common.utils.api.model.BaseCode;
|
|
|
import cn.rankin.data.api.auth.dto.InnerAuthDTO;
|
|
|
import cn.rankin.data.api.auth.vo.AuthResult;
|
|
|
+import cn.rankin.data.api.user.vo.WhiteUserVo;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
public class AuthService{
|
|
|
|
|
|
@Autowired
|
|
|
+ private UserClient userClient;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
private AuthClient authClient;
|
|
|
|
|
|
+ public APIResult<AuthResult> authWhiteUser(String userId, String productId) {
|
|
|
+ APIResult<WhiteUserVo> result = userClient.findWhiteUserById(userId);
|
|
|
+ if (!result.getSuccess()) {
|
|
|
+ log.error("user white user auth error, code={}, msg={}", result.getCode(), result.getMessage());
|
|
|
+ return APIResult.error(new BaseCode(result.getCode(), result.getMessage()));
|
|
|
+ }
|
|
|
+ WhiteUserVo whiteUserVo = result.getData();
|
|
|
+
|
|
|
+ AuthResult authResult = new AuthResult();
|
|
|
+ authResult.setUserId(userId);
|
|
|
+ authResult.setPid(productId);
|
|
|
+ Date startTime = whiteUserVo.getStartTime();
|
|
|
+ authResult.setStartTime(startTime.getTime());
|
|
|
+ Date endTime = whiteUserVo.getEndTime();
|
|
|
+ if (endTime != null) {
|
|
|
+ authResult.setEndTime(endTime.getTime());
|
|
|
+ }
|
|
|
+ return APIResult.ok(authResult);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
public APIResult<AuthResult> auth(String userId, String merchantId, String itemId) {
|
|
|
- log.info("auth vo: {}, item: {}", userId, itemId);
|
|
|
+ log.info("auth start: userId={}, itemId={}", userId, itemId);
|
|
|
+
|
|
|
+ // 如果在白名单里就不再查询鉴权信息
|
|
|
+ APIResult<AuthResult> whiteUserAuthApiResult = this.authWhiteUser(userId, itemId);
|
|
|
+ if (whiteUserAuthApiResult.getSuccess()) {
|
|
|
+ return whiteUserAuthApiResult;
|
|
|
+ }
|
|
|
+
|
|
|
InnerAuthDTO authDTO = new InnerAuthDTO();
|
|
|
authDTO.setItemId(itemId);
|
|
|
authDTO.setUserId(userId);
|