Authored by tanling

本地提交

  1 +package com.yohoufo.order.annotation;
  2 +
  3 +import com.yohoufo.order.common.BlackTypeEnum;
  4 +import org.springframework.stereotype.Component;
  5 +
  6 +import java.lang.annotation.*;
  7 +
  8 +@Retention(RetentionPolicy.RUNTIME)
  9 +@Target(ElementType.METHOD)
  10 +@Documented
  11 +@Component
  12 +public @interface BlackUserType {
  13 + BlackTypeEnum blackType();
  14 +}
  15 +
@@ -10,8 +10,8 @@ import com.yohoufo.common.annotation.IgnoreSignature; @@ -10,8 +10,8 @@ import com.yohoufo.common.annotation.IgnoreSignature;
10 import com.yohoufo.common.exception.GatewayException; 10 import com.yohoufo.common.exception.GatewayException;
11 import com.yohoufo.common.exception.UfoServiceException; 11 import com.yohoufo.common.exception.UfoServiceException;
12 import com.yohoufo.dal.order.model.SellerOrder; 12 import com.yohoufo.dal.order.model.SellerOrder;
  13 +import com.yohoufo.order.annotation.BlackUserType;
13 import com.yohoufo.order.common.BlackTypeEnum; 14 import com.yohoufo.order.common.BlackTypeEnum;
14 -import com.yohoufo.order.interceptor.BlackUserInterceptor;  
15 import com.yohoufo.order.model.request.OrderListRequest; 15 import com.yohoufo.order.model.request.OrderListRequest;
16 import com.yohoufo.order.model.request.OrderRequest; 16 import com.yohoufo.order.model.request.OrderRequest;
17 import com.yohoufo.order.model.response.OrderSubmitResp; 17 import com.yohoufo.order.model.response.OrderSubmitResp;
@@ -92,6 +92,7 @@ public class SellerOrderController { @@ -92,6 +92,7 @@ public class SellerOrderController {
92 */ 92 */
93 @RequestMapping(params = "method=ufo.sellerOrder.publishPrd") 93 @RequestMapping(params = "method=ufo.sellerOrder.publishPrd")
94 @ResponseBody 94 @ResponseBody
  95 + @BlackUserType(blackType = BlackTypeEnum.SELL)
95 public ApiResponse publishPrd(@RequestParam(name = "uid", required = true)int uid, 96 public ApiResponse publishPrd(@RequestParam(name = "uid", required = true)int uid,
96 @RequestParam(name = "storage_id", required = true)int storage_id, 97 @RequestParam(name = "storage_id", required = true)int storage_id,
97 @RequestParam(name="price", required = true)String price, 98 @RequestParam(name="price", required = true)String price,
@@ -108,8 +109,6 @@ public class SellerOrderController { @@ -108,8 +109,6 @@ public class SellerOrderController {
108 .build(); 109 .build();
109 logger.info("in ufo.sellerOrder.publishPrd, req {}", req); 110 logger.info("in ufo.sellerOrder.publishPrd, req {}", req);
110 111
111 - BlackUserInterceptor.getBlackUserInteceptor(BlackTypeEnum.SELL.getCode()).before(uid);  
112 -  
113 OrderSubmitResp resp = sellerOrderService.publishPrd(req); 112 OrderSubmitResp resp = sellerOrderService.publishPrd(req);
114 return new ApiResponse.ApiResponseBuilder().data(resp).code(200).message("发布成功").build(); 113 return new ApiResponse.ApiResponseBuilder().data(resp).code(200).message("发布成功").build();
115 } 114 }
@@ -524,6 +523,7 @@ public class SellerOrderController { @@ -524,6 +523,7 @@ public class SellerOrderController {
524 */ 523 */
525 @RequestMapping(params = "method=ufo.seller.publishImperfectPrd") 524 @RequestMapping(params = "method=ufo.seller.publishImperfectPrd")
526 @ResponseBody 525 @ResponseBody
  526 + @BlackUserType(blackType = BlackTypeEnum.SELL)
527 public ApiResponse publishImperfectPrd(@RequestParam(name = "uid")int uid, 527 public ApiResponse publishImperfectPrd(@RequestParam(name = "uid")int uid,
528 @RequestParam(name = "storage_id")int storage_id, 528 @RequestParam(name = "storage_id")int storage_id,
529 @RequestParam(name="price")String price, 529 @RequestParam(name="price")String price,
@@ -548,8 +548,6 @@ public class SellerOrderController { @@ -548,8 +548,6 @@ public class SellerOrderController {
548 .build(); 548 .build();
549 logger.info("in ufo.sellerOrder.publishImperfectPrd, req {}", req); 549 logger.info("in ufo.sellerOrder.publishImperfectPrd, req {}", req);
550 550
551 - BlackUserInterceptor.getBlackUserInteceptor(BlackTypeEnum.SELL.getCode()).before(uid);  
552 -  
553 OrderSubmitResp resp = imperfectGoodsService.publish(req); 551 OrderSubmitResp resp = imperfectGoodsService.publish(req);
554 return new ApiResponse.ApiResponseBuilder().data(resp).code(200).message("发布成功").build(); 552 return new ApiResponse.ApiResponseBuilder().data(resp).code(200).message("发布成功").build();
555 } 553 }
@@ -2,12 +2,13 @@ package com.yohoufo.order.controller; @@ -2,12 +2,13 @@ package com.yohoufo.order.controller;
2 2
3 import com.google.common.collect.Lists; 3 import com.google.common.collect.Lists;
4 import com.yohoufo.common.ApiResponse; 4 import com.yohoufo.common.ApiResponse;
  5 +import com.yohoufo.order.annotation.BlackUserType;
  6 +import com.yohoufo.order.common.BlackTypeEnum;
5 import com.yohoufo.order.constants.CouponConstants; 7 import com.yohoufo.order.constants.CouponConstants;
6 import com.yohoufo.order.model.request.ShoppingRequest; 8 import com.yohoufo.order.model.request.ShoppingRequest;
7 import com.yohoufo.order.model.response.*; 9 import com.yohoufo.order.model.response.*;
8 import com.yohoufo.order.service.IBuyerOrderService; 10 import com.yohoufo.order.service.IBuyerOrderService;
9 import com.yohoufo.order.service.IShoppingService; 11 import com.yohoufo.order.service.IShoppingService;
10 -import com.yohoufo.order.service.impl.SellerOrderService;  
11 import com.yohoufo.order.service.impl.SellerOrderViewService; 12 import com.yohoufo.order.service.impl.SellerOrderViewService;
12 import com.yohoufo.order.utils.CouponCodeUtils; 13 import com.yohoufo.order.utils.CouponCodeUtils;
13 import com.yohoufo.order.utils.LoggerUtils; 14 import com.yohoufo.order.utils.LoggerUtils;
@@ -99,6 +100,7 @@ public class ShoppingController { @@ -99,6 +100,7 @@ public class ShoppingController {
99 * @return 100 * @return
100 */ 101 */
101 @RequestMapping(params = "method=ufo.order.submit") 102 @RequestMapping(params = "method=ufo.order.submit")
  103 + @BlackUserType(blackType = BlackTypeEnum.BUY)
102 public ApiResponse submit(@RequestParam(name = "uid") int uid, 104 public ApiResponse submit(@RequestParam(name = "uid") int uid,
103 @RequestParam(name = "skup") int skup, 105 @RequestParam(name = "skup") int skup,
104 @RequestParam(name = "coupon_code",required = false) String couponCode, 106 @RequestParam(name = "coupon_code",required = false) String couponCode,
@@ -5,24 +5,57 @@ import com.yoho.error.ServiceError; @@ -5,24 +5,57 @@ import com.yoho.error.ServiceError;
5 import com.yoho.error.exception.ServiceException; 5 import com.yoho.error.exception.ServiceException;
6 import com.yohoufo.dal.order.BlackUserMapper; 6 import com.yohoufo.dal.order.BlackUserMapper;
7 import com.yohoufo.dal.order.model.BlackUser; 7 import com.yohoufo.dal.order.model.BlackUser;
  8 +import com.yohoufo.order.annotation.BlackUserType;
8 import com.yohoufo.order.common.BlackTypeEnum; 9 import com.yohoufo.order.common.BlackTypeEnum;
9 import org.apache.commons.collections.CollectionUtils; 10 import org.apache.commons.collections.CollectionUtils;
  11 +import org.aspectj.lang.JoinPoint;
  12 +import org.aspectj.lang.annotation.Aspect;
  13 +import org.aspectj.lang.annotation.Before;
  14 +import org.aspectj.lang.annotation.Pointcut;
  15 +import org.aspectj.lang.reflect.MethodSignature;
10 import org.slf4j.Logger; 16 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory; 17 import org.slf4j.LoggerFactory;
12 import org.springframework.beans.BeansException; 18 import org.springframework.beans.BeansException;
13 -import org.springframework.beans.factory.BeanNameAware;  
14 import org.springframework.beans.factory.annotation.Autowired; 19 import org.springframework.beans.factory.annotation.Autowired;
15 import org.springframework.context.ApplicationContext; 20 import org.springframework.context.ApplicationContext;
16 import org.springframework.context.ApplicationContextAware; 21 import org.springframework.context.ApplicationContextAware;
17 import org.springframework.stereotype.Component; 22 import org.springframework.stereotype.Component;
18 23
  24 +import java.lang.annotation.Annotation;
19 import java.util.List; 25 import java.util.List;
20 import java.util.Map; 26 import java.util.Map;
21 import java.util.stream.Collectors; 27 import java.util.stream.Collectors;
22 28
23 -public abstract class BlackUserInterceptor implements ApplicationContextAware { 29 +@Aspect
  30 +@Component
  31 +public class BlackUserAspect {
24 32
25 - Logger logger = LoggerFactory.getLogger(BlackUserInterceptor.class); 33 + private static Map<Integer, AbstractBlackUserInterceptor> blackUserInteceptorMap = Maps.newHashMap();
  34 +
  35 +
  36 + @Pointcut("@annotation(com.yohoufo.order.annotation.BlackUserType)")
  37 + private void pointId(){
  38 +
  39 + }
  40 +
  41 + @Before("pointId()")
  42 + private void before(JoinPoint joinPoint) throws Throwable{
  43 +
  44 +
  45 + Object[] argsa = joinPoint.getArgs();
  46 +
  47 + Annotation[][] parameterTypes = ((MethodSignature)joinPoint.getSignature()).getMethod().getParameterAnnotations();
  48 +
  49 + BlackUserType blackUserAnnotation = ((MethodSignature) joinPoint.getSignature()).getMethod().getAnnotation(BlackUserType.class);
  50 +
  51 + blackUserInteceptorMap.get(blackUserAnnotation.blackType()).before((int)argsa[0]);
  52 +
  53 + }
  54 +
  55 +
  56 + private abstract static class AbstractBlackUserInterceptor implements ApplicationContextAware {
  57 +
  58 + Logger logger = LoggerFactory.getLogger(AbstractBlackUserInterceptor.class);
26 59
27 @Autowired 60 @Autowired
28 BlackUserMapper blackUserMapper; 61 BlackUserMapper blackUserMapper;
@@ -52,22 +85,46 @@ public abstract class BlackUserInterceptor implements ApplicationContextAware { @@ -52,22 +85,46 @@ public abstract class BlackUserInterceptor implements ApplicationContextAware {
52 abstract int getBlackType(); 85 abstract int getBlackType();
53 86
54 87
55 - private static final Map<Integer, BlackUserInterceptor> blackUserInteceptorMap = Maps.newHashMap(); 88 + abstract ServiceException getServiceException();
  89 +
56 90
57 - public static BlackUserInterceptor getBlackUserInteceptor(Integer code){  
58 - return blackUserInteceptorMap.get(code); 91 + @Override
  92 + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
  93 + Map<String, AbstractBlackUserInterceptor> map = applicationContext.getBeansOfType(AbstractBlackUserInterceptor.class);
  94 + for (String beanName : map.keySet()){
  95 + AbstractBlackUserInterceptor abstractBlackUserInterceptor = map.get(beanName);
  96 + blackUserInteceptorMap.put(abstractBlackUserInterceptor.getBlackType(), abstractBlackUserInterceptor);
  97 + }
  98 + }
59 } 99 }
60 100
61 - abstract ServiceException getServiceException();  
62 101
  102 + @Component
  103 + private static class BuyBlackUserInterceptor extends AbstractBlackUserInterceptor {
63 104
64 @Override 105 @Override
65 - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {  
66 - // 重构map中的拦截器key,value  
67 - Map<String, BlackUserInterceptor> map = applicationContext.getBeansOfType(BlackUserInterceptor.class);  
68 - for (String beanName: map.keySet()){  
69 - BlackUserInterceptor interceptor = (BlackUserInterceptor) applicationContext.getBean(beanName);  
70 - blackUserInteceptorMap.put(interceptor.getBlackType(), interceptor); 106 + int getBlackType() {
  107 + return BlackTypeEnum.BUY.getCode();
  108 + }
  109 +
  110 + @Override
  111 + ServiceException getServiceException() {
  112 + return new ServiceException(ServiceError.NOT_ALLOW_BLACK_UID_BUY);
  113 + }
  114 +
  115 + }
  116 +
  117 + @Component
  118 + private static class SellBlackUserInterceptor extends AbstractBlackUserInterceptor {
  119 +
  120 + @Override
  121 + int getBlackType() {
  122 + return BlackTypeEnum.SELL.getCode();
  123 + }
  124 +
  125 + @Override
  126 + ServiceException getServiceException() {
  127 + return new ServiceException(ServiceError.NOT_ALLOW_BLACK_UID_SELL);
71 } 128 }
72 129
73 } 130 }
1 -package com.yohoufo.order.interceptor;  
2 -  
3 -import com.yoho.error.ServiceError;  
4 -import com.yoho.error.exception.ServiceException;  
5 -import com.yohoufo.order.common.BlackTypeEnum;  
6 -import org.springframework.stereotype.Component;  
7 -  
8 -@Component  
9 -public class BuyBlackUserInterceptor extends BlackUserInterceptor {  
10 -  
11 - @Override  
12 - int getBlackType() {  
13 - return BlackTypeEnum.BUY.getCode();  
14 - }  
15 -  
16 - @Override  
17 - ServiceException getServiceException() {  
18 - return new ServiceException(ServiceError.NOT_ALLOW_BLACK_UID_BUY);  
19 - }  
20 -  
21 -}  
1 -package com.yohoufo.order.interceptor;  
2 -  
3 -import com.yoho.error.ServiceError;  
4 -import com.yoho.error.exception.ServiceException;  
5 -import com.yohoufo.order.common.BlackTypeEnum;  
6 -import org.springframework.stereotype.Component;  
7 -  
8 -@Component  
9 -public class SellBlackUserInterceptor extends BlackUserInterceptor {  
10 -  
11 - @Override  
12 - int getBlackType() {  
13 - return BlackTypeEnum.SELL.getCode();  
14 - }  
15 -  
16 - @Override  
17 - ServiceException getServiceException() {  
18 - return new ServiceException(ServiceError.NOT_ALLOW_BLACK_UID_SELL);  
19 - }  
20 -  
21 -  
22 -}  
@@ -27,12 +27,10 @@ import com.yohoufo.order.charge.model.ChargeGoods; @@ -27,12 +27,10 @@ import com.yohoufo.order.charge.model.ChargeGoods;
27 import com.yohoufo.order.charge.model.ChargeParam; 27 import com.yohoufo.order.charge.model.ChargeParam;
28 import com.yohoufo.order.charge.model.ChargeResult; 28 import com.yohoufo.order.charge.model.ChargeResult;
29 import com.yohoufo.order.charge.model.CouponMatchResult; 29 import com.yohoufo.order.charge.model.CouponMatchResult;
30 -import com.yohoufo.order.common.BlackTypeEnum;  
31 import com.yohoufo.order.event.BuyerCancelEvent; 30 import com.yohoufo.order.event.BuyerCancelEvent;
32 import com.yohoufo.order.event.ErpBuyerOrderEvent; 31 import com.yohoufo.order.event.ErpBuyerOrderEvent;
33 import com.yohoufo.order.event.NotPaidNoticeEvent; 32 import com.yohoufo.order.event.NotPaidNoticeEvent;
34 import com.yohobuy.ufo.model.order.vo.AddressInfo; 33 import com.yohobuy.ufo.model.order.vo.AddressInfo;
35 -import com.yohoufo.order.interceptor.BlackUserInterceptor;  
36 import com.yohoufo.order.model.bo.CouponBo; 34 import com.yohoufo.order.model.bo.CouponBo;
37 import com.yohoufo.order.model.dto.BuyerOrderSubmitResult; 35 import com.yohoufo.order.model.dto.BuyerOrderSubmitResult;
38 import com.yohoufo.order.model.dto.OrderBuilder; 36 import com.yohoufo.order.model.dto.OrderBuilder;
@@ -276,9 +274,6 @@ public class ShoppingServiceImpl implements IShoppingService { @@ -276,9 +274,6 @@ public class ShoppingServiceImpl implements IShoppingService {
276 throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY); 274 throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
277 } 275 }
278 276
279 - // 黑名单拦截  
280 - BlackUserInterceptor.getBlackUserInteceptor(BlackTypeEnum.BUY.getCode()).before(uid);  
281 -  
282 shoppingRiskWatchDog.checkWaitingPayCnt(uid); 277 shoppingRiskWatchDog.checkWaitingPayCnt(uid);
283 //查询并校验用户地址 278 //查询并校验用户地址
284 Pair<AddressInfo, AddressInfo> userAddressPair = getAndCheckAddressInfo(shoppingRequest); 279 Pair<AddressInfo, AddressInfo> userAddressPair = getAndCheckAddressInfo(shoppingRequest);
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<beans xmlns="http://www.springframework.org/schema/beans"
  3 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
  4 + xmlns:context="http://www.springframework.org/schema/context"
  5 + xmlns:aop="http://www.springframework.org/schema/aop"
  6 + xmlns:tx="http://www.springframework.org/schema/tx"
  7 + xsi:schemaLocation="http://www.springframework.org/schema/beans
  8 + http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
  9 + http://www.springframework.org/schema/context
  10 + http://www.springframework.org/schema/context/spring-context-3.1.xsd
  11 + http://www.springframework.org/schema/aop
  12 + http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
  13 + http://www.springframework.org/schema/tx
  14 + http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
  15 +
  16 + <aop:aspectj-autoproxy />
  17 +
  18 +
  19 +</beans>