Bläddra i källkod

add white user model

huodongdong 6 år sedan
förälder
incheckning
ac39c034af

+ 37 - 1
rankin-api-web/src/main/java/cn/rankin/apiweb/service/auth/AuthService.java

@@ -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);

+ 9 - 0
rankin-api-web/src/main/java/cn/rankin/apiweb/service/user/UserClient.java

@@ -5,6 +5,7 @@ import cn.rankin.common.utils.api.model.APIResult;
 import cn.rankin.data.api.user.dto.TerminalDeviceDTO;
 import cn.rankin.data.api.user.vo.TerminalDeviceVo;
 import cn.rankin.data.api.user.vo.TerminalUserVo;
+import cn.rankin.data.api.user.vo.WhiteUserVo;
 import org.springframework.cloud.netflix.feign.FeignClient;
 import org.springframework.stereotype.Component;
 import org.springframework.web.bind.annotation.*;
@@ -30,6 +31,9 @@ public interface UserClient {
     @RequestMapping(value = "/device/deviceCode/{deviceCode}", method = RequestMethod.GET)
     APIResult<TerminalDeviceVo> findByDeviceCode(@PathVariable("deviceCode") String deviceCode);
 
+    @RequestMapping(value = "/white/user/{userId}", method = RequestMethod.GET)
+    APIResult<WhiteUserVo> findWhiteUserById(@PathVariable String userId);
+
     @Component
     class UserServiceHystrix implements UserClient {
 
@@ -62,5 +66,10 @@ public interface UserClient {
         public APIResult findByDeviceCode(String deviceCode) {
             return APIResult.error(ApiWebCode.SERVER_ERROR);
         }
+
+        @Override
+        public APIResult<WhiteUserVo> findWhiteUserById(String userId) {
+            return APIResult.error(ApiWebCode.SERVER_ERROR);
+        }
     }
 }

+ 57 - 0
rankin-cms-web/src/main/java/cn/rankin/cmsweb/controller/user/WhiteUserController.java

@@ -0,0 +1,57 @@
+package cn.rankin.cmsweb.controller.user;
+
+import cn.rankin.cmsweb.assist.resolver.NeedUser;
+import cn.rankin.cmsweb.code.CmsWebAPICode;
+import cn.rankin.cmsweb.entity.UserDetails;
+import cn.rankin.cmsweb.service.user.WhiteUserService;
+import cn.rankin.common.utils.api.model.APIResult;
+import cn.rankin.common.utils.api.page.Page;
+import cn.rankin.data.api.user.dto.WhiteUserDTO;
+import cn.rankin.data.api.user.dto.WhiteUserSearchDTO;
+import cn.rankin.data.api.user.entity.WhiteUser;
+import cn.rankin.data.api.user.vo.WhiteUserVo;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+
+@RestController
+@RequestMapping(value = "/white/user")
+public class WhiteUserController {
+
+    @Autowired
+    private WhiteUserService whiteUserService;
+
+    @RequestMapping(value = "/{userId}", method = RequestMethod.GET)
+    public APIResult<WhiteUserVo> getWhiteUser(@PathVariable String userId) {
+        return whiteUserService.findUserByUserId(userId);
+    }
+
+    @RequestMapping(method = RequestMethod.POST)
+    public APIResult<WhiteUserVo> create(@NeedUser UserDetails user, @RequestBody WhiteUserDTO whiteUserDTO) {
+        if (!user.isPlatForm()) {
+            return APIResult.error(CmsWebAPICode.ACCESS_DENIED);
+        }
+        return whiteUserService.addWhiteUser(whiteUserDTO);
+    }
+
+    @RequestMapping(method = RequestMethod.PUT)
+    public APIResult<WhiteUserVo> update(@NeedUser UserDetails user, @RequestBody WhiteUserDTO whiteUserDTO) {
+        if (!user.isPlatForm()) {
+            return APIResult.error(CmsWebAPICode.ACCESS_DENIED);
+        }
+        return whiteUserService.updateWhiteUser(whiteUserDTO);
+    }
+
+    @RequestMapping(method = RequestMethod.DELETE)
+    public APIResult<Boolean> delete(@NeedUser UserDetails user, @RequestBody WhiteUserDTO whiteUserDTO) {
+        if (!user.isPlatForm()) {
+            return APIResult.error(CmsWebAPICode.ACCESS_DENIED);
+        }
+        return whiteUserService.deleteWhiteUser(whiteUserDTO);
+    }
+
+    @RequestMapping(value = "/list", method = RequestMethod.GET)
+    public APIResult<Page<WhiteUser>> search(WhiteUserSearchDTO searchDTO) {
+        return whiteUserService.search(searchDTO);
+    }
+}

+ 30 - 0
rankin-cms-web/src/main/java/cn/rankin/cmsweb/service/user/WhiteUserService.java

@@ -0,0 +1,30 @@
+package cn.rankin.cmsweb.service.user;
+
+import cn.rankin.common.utils.api.model.APIResult;
+import cn.rankin.common.utils.api.page.Page;
+import cn.rankin.data.api.user.dto.WhiteUserDTO;
+import cn.rankin.data.api.user.dto.WhiteUserSearchDTO;
+import cn.rankin.data.api.user.entity.WhiteUser;
+import cn.rankin.data.api.user.vo.WhiteUserVo;
+import org.springframework.cloud.netflix.feign.FeignClient;
+import org.springframework.web.bind.annotation.*;
+
+@FeignClient(name = "${service.user.name}")
+public interface WhiteUserService {
+
+    @RequestMapping(value = "/white/user/{userId}", method = RequestMethod.GET)
+    APIResult<WhiteUserVo> findUserByUserId(@PathVariable String userId);
+
+    @RequestMapping(value = "/white/user", method = RequestMethod.POST)
+    APIResult<WhiteUserVo> addWhiteUser(@RequestBody WhiteUserDTO whiteUserDTO);
+
+    @RequestMapping(value = "/white/user", method = RequestMethod.PUT)
+    APIResult<WhiteUserVo> updateWhiteUser(@RequestBody WhiteUserDTO whiteUserDTO);
+
+    @RequestMapping(value = "/white/user", method = RequestMethod.DELETE)
+    APIResult<Boolean> deleteWhiteUser(@RequestBody WhiteUserDTO whiteUserDTO);
+
+    @RequestMapping(value = "/white/user/list", method = RequestMethod.POST)
+    APIResult<Page<WhiteUser>> search(@RequestBody WhiteUserSearchDTO searchDTO);
+
+}

+ 1 - 1
rankin-data-api/src/main/java/cn/rankin/data/api/auth/vo/AuthResult.java

@@ -20,7 +20,7 @@ public class AuthResult implements Serializable {
 
     private Long endTime;
 
-    public Long getValidTime() {
+    private Long getValidTime() {
         if (startTime == null || endTime == null) {
             return 0L;
         }

+ 1 - 1
rankin-user-service/src/main/java/cn/rankin/userservice/controller/WhiteUserController.java

@@ -71,7 +71,7 @@ public class WhiteUserController {
         return APIResult.error(UserServiceAPICode.NOT_EXISTS);
     }
 
-    @RequestMapping(value = "/list", method = RequestMethod.GET)
+    @RequestMapping(value = "/list", method = RequestMethod.POST)
     public APIResult<Page<WhiteUser>> search(WhiteUserSearchDTO searchDTO) {
         WhiteUser sample = new WhiteUser();
         String code = searchDTO.getCode();