|
@@ -1,21 +1,42 @@
|
|
|
package cn.rankin.productservice.controller.auth;
|
|
|
|
|
|
import cn.rankin.common.utils.api.model.APIResult;
|
|
|
+import cn.rankin.common.utils.constant.Constant;
|
|
|
+import cn.rankin.common.utils.util.BeanUtil;
|
|
|
import cn.rankin.data.api.auth.dto.InnerAuthDTO;
|
|
|
import cn.rankin.data.api.auth.vo.AuthResult;
|
|
|
+import cn.rankin.data.api.auth.vo.AuthVo;
|
|
|
+import cn.rankin.data.api.product.entity.Product;
|
|
|
+import cn.rankin.productservice.repository.ProductRepository;
|
|
|
+import cn.rankin.productservice.service.ProductService;
|
|
|
+import cn.rankin.productservice.service.auth.AuthClient;
|
|
|
import cn.rankin.productservice.service.auth.AuthService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@RestController
|
|
|
+@Slf4j
|
|
|
public class AuthController {
|
|
|
|
|
|
@Autowired
|
|
|
private AuthService authService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private AuthClient authClient;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ProductRepository productRepository;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ProductService productService;
|
|
|
+
|
|
|
@RequestMapping(value = "/auth", method = RequestMethod.POST)
|
|
|
public APIResult<AuthResult> auth(@RequestBody InnerAuthDTO authDTO) {
|
|
|
String userId = authDTO.getUserId();
|
|
@@ -23,4 +44,59 @@ public class AuthController {
|
|
|
String merchantId = authDTO.getMerchantId();
|
|
|
return authService.auth(userId, merchantId, itemId);
|
|
|
}
|
|
|
+
|
|
|
+ @RequestMapping(value = "/user/{uid}/product/valid", method = RequestMethod.GET)
|
|
|
+ public List<Map<String, Object>> getProductValid(@PathVariable("uid") String uid, @RequestParam("start") Long start,
|
|
|
+ @RequestParam("offset") Integer offset, @RequestParam("sortKey") String sortKey,
|
|
|
+ @RequestParam("direction") Sort.Direction direction){
|
|
|
+
|
|
|
+ List<AuthVo> authItems = authClient.getUserValidProduct(uid, Constant.BIZ_CODE).getData();
|
|
|
+ if (null == authItems){
|
|
|
+ authItems = new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ ArrayList<String> pids = new ArrayList<>();
|
|
|
+
|
|
|
+ HashMap<String, AuthVo> authMap = new HashMap<>();
|
|
|
+ for (AuthVo item: authItems ) {
|
|
|
+ if(null == item.getPid()) {
|
|
|
+ log.error("Pid Is Null, uid={}", uid);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ pids.add(item.getPid());
|
|
|
+ authMap.put(item.getPid(), item);
|
|
|
+ }
|
|
|
+
|
|
|
+ List< Map<String, Object> > result = new ArrayList<>();
|
|
|
+
|
|
|
+ if (pids.isEmpty()){
|
|
|
+ log.error("No Valid Pids For User, uid={}", uid);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Product> products = productRepository.findByPids(pids);
|
|
|
+
|
|
|
+ //assemble result
|
|
|
+ for(Product product : products){
|
|
|
+
|
|
|
+ String pid = product.getPid();
|
|
|
+ if (!authMap.containsKey(pid)){
|
|
|
+ log.error("Pid Not Exist in AuthMap, pid={}", pid);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ AuthVo authInfo = authMap.get(pid);
|
|
|
+
|
|
|
+ Map<String, Object> rec = BeanUtil.convertToMap(product, true);
|
|
|
+
|
|
|
+ rec.put("beginTime", authInfo.getStartTime());
|
|
|
+ rec.put("endTime", authInfo.getEndTime());
|
|
|
+
|
|
|
+ result.add(rec);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
}
|