Authored by LUOXC

refactor

@@ -17,20 +17,12 @@ import com.yohoufo.dal.order.model.ExpressRecord; @@ -17,20 +17,12 @@ import com.yohoufo.dal.order.model.ExpressRecord;
17 import com.yohoufo.order.common.LogisticsTypes; 17 import com.yohoufo.order.common.LogisticsTypes;
18 import com.yohoufo.order.model.bo.ErpExpressBo; 18 import com.yohoufo.order.model.bo.ErpExpressBo;
19 import com.yohoufo.order.mq.publisher.ConsumerExceptionPublisher; 19 import com.yohoufo.order.mq.publisher.ConsumerExceptionPublisher;
20 -import com.yohoufo.order.service.IBuyerOrderService;  
21 -import com.yohoufo.order.service.impl.BuyerOrderCancelService;  
22 import com.yohoufo.order.utils.LoggerUtils; 20 import com.yohoufo.order.utils.LoggerUtils;
23 -import com.yohoufo.order.utils.PubThreadFactory;  
24 import org.apache.commons.lang3.StringUtils; 21 import org.apache.commons.lang3.StringUtils;
25 import org.slf4j.Logger; 22 import org.slf4j.Logger;
26 import org.springframework.beans.factory.annotation.Autowired; 23 import org.springframework.beans.factory.annotation.Autowired;
27 import org.springframework.stereotype.Component; 24 import org.springframework.stereotype.Component;
28 25
29 -import java.util.concurrent.ArrayBlockingQueue;  
30 -import java.util.concurrent.ExecutorService;  
31 -import java.util.concurrent.ThreadPoolExecutor;  
32 -import java.util.concurrent.TimeUnit;  
33 -  
34 26
35 @Component 27 @Component
36 public class ExpressInfoUpdateConsumer implements YhConsumer { 28 public class ExpressInfoUpdateConsumer implements YhConsumer {
@@ -40,8 +32,6 @@ private static final Logger LOGGER = LoggerUtils.getMqConsumerLogger(); @@ -40,8 +32,6 @@ private static final Logger LOGGER = LoggerUtils.getMqConsumerLogger();
40 32
41 private final String topic = "ufo.order.updateExpressInfo"; 33 private final String topic = "ufo.order.updateExpressInfo";
42 34
43 - private ExecutorService executorService = new ThreadPoolExecutor(5, 10, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<>(1000), new PubThreadFactory("express-consumer-processor"));  
44 -  
45 @Autowired 35 @Autowired
46 private ExpressInfoMapper expressInfoMapper; 36 private ExpressInfoMapper expressInfoMapper;
47 37
@@ -54,12 +44,6 @@ private static final Logger LOGGER = LoggerUtils.getMqConsumerLogger(); @@ -54,12 +44,6 @@ private static final Logger LOGGER = LoggerUtils.getMqConsumerLogger();
54 @Autowired 44 @Autowired
55 private BuyerOrderMapper buyerOrderMapper; 45 private BuyerOrderMapper buyerOrderMapper;
56 46
57 - @Autowired  
58 - private IBuyerOrderService buyerOrderService;  
59 -  
60 - @Autowired  
61 - private BuyerOrderCancelService buyerOrderCancelService;  
62 -  
63 public String getMessageTopic() { 47 public String getMessageTopic() {
64 return topic; 48 return topic;
65 } 49 }
@@ -17,6 +17,7 @@ import java.util.stream.Collectors; @@ -17,6 +17,7 @@ import java.util.stream.Collectors;
17 import javax.annotation.Resource; 17 import javax.annotation.Resource;
18 18
19 import com.yohoufo.order.service.listener.BuyerOrderChangeEvent; 19 import com.yohoufo.order.service.listener.BuyerOrderChangeEvent;
  20 +import com.yohoufo.order.utils.NamedThreadFactory;
20 import org.apache.commons.collections.CollectionUtils; 21 import org.apache.commons.collections.CollectionUtils;
21 import org.apache.commons.lang3.StringUtils; 22 import org.apache.commons.lang3.StringUtils;
22 import org.slf4j.Logger; 23 import org.slf4j.Logger;
@@ -103,7 +104,6 @@ import com.yohoufo.order.service.proxy.SellerNoticeFacade; @@ -103,7 +104,6 @@ import com.yohoufo.order.service.proxy.SellerNoticeFacade;
103 import com.yohoufo.order.service.seller.setting.SellerService; 104 import com.yohoufo.order.service.seller.setting.SellerService;
104 import com.yohoufo.order.utils.BuyerOrderUtils; 105 import com.yohoufo.order.utils.BuyerOrderUtils;
105 import com.yohoufo.order.utils.PaymentHelper; 106 import com.yohoufo.order.utils.PaymentHelper;
106 -import com.yohoufo.order.utils.PubThreadFactory;  
107 107
108 import lombok.Data; 108 import lombok.Data;
109 109
@@ -117,7 +117,7 @@ public class AppraiseService { @@ -117,7 +117,7 @@ public class AppraiseService {
117 117
118 private ExecutorService executorService = new ThreadPoolExecutor(5, 10, 60, TimeUnit.SECONDS, 118 private ExecutorService executorService = new ThreadPoolExecutor(5, 10, 60, TimeUnit.SECONDS,
119 new ArrayBlockingQueue<>(1000), 119 new ArrayBlockingQueue<>(1000),
120 - new PubThreadFactory("appraise-processor")); 120 + NamedThreadFactory.newThreadFactory("appraise"));
121 121
122 @Autowired 122 @Autowired
123 private IExpressInfoService expressInfoService; 123 private IExpressInfoService expressInfoService;
@@ -4,7 +4,7 @@ import com.yohobuy.ufo.model.order.common.OperateTypeEnum; @@ -4,7 +4,7 @@ import com.yohobuy.ufo.model.order.common.OperateTypeEnum;
4 import com.yohoufo.common.utils.DateUtil; 4 import com.yohoufo.common.utils.DateUtil;
5 import com.yohoufo.dal.order.OrderOperateRecordMapper; 5 import com.yohoufo.dal.order.OrderOperateRecordMapper;
6 import com.yohoufo.dal.order.model.OrderOperateRecord; 6 import com.yohoufo.dal.order.model.OrderOperateRecord;
7 -import com.yohoufo.order.utils.PubThreadFactory; 7 +import com.yohoufo.order.utils.NamedThreadFactory;
8 import org.slf4j.Logger; 8 import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory; 9 import org.slf4j.LoggerFactory;
10 import org.springframework.beans.factory.annotation.Autowired; 10 import org.springframework.beans.factory.annotation.Autowired;
@@ -19,15 +19,16 @@ import java.util.concurrent.TimeUnit; @@ -19,15 +19,16 @@ import java.util.concurrent.TimeUnit;
19 public class OrderOperateRecordService { 19 public class OrderOperateRecordService {
20 private final Logger logger = LoggerFactory.getLogger(getClass()); 20 private final Logger logger = LoggerFactory.getLogger(getClass());
21 21
22 - private ExecutorService executorService = new ThreadPoolExecutor(5, 10, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<>(1000),new PubThreadFactory("order-operate-record")); 22 + private ExecutorService executorService = new ThreadPoolExecutor(5, 10,
  23 + 60, TimeUnit.SECONDS, new ArrayBlockingQueue<>(1000), NamedThreadFactory.newThreadFactory("order-operate-record"));
23 24
24 @Autowired 25 @Autowired
25 private OrderOperateRecordMapper orderOperateRecordMapper; 26 private OrderOperateRecordMapper orderOperateRecordMapper;
26 27
27 - public void addRecord(Long orderCode,String userName, OperateTypeEnum operateType){ 28 + public void addRecord(Long orderCode, String userName, OperateTypeEnum operateType) {
28 try { 29 try {
29 logger.info("OrderOperateRecordService add enter , operateType {}, orderCode {} ,userName {}", 30 logger.info("OrderOperateRecordService add enter , operateType {}, orderCode {} ,userName {}",
30 - operateType, orderCode ,userName); 31 + operateType, orderCode, userName);
31 executorService.execute(() -> { 32 executorService.execute(() -> {
32 OrderOperateRecord optRecord = new OrderOperateRecord(); 33 OrderOperateRecord optRecord = new OrderOperateRecord();
33 optRecord.setOrderCode(String.valueOf(orderCode)); 34 optRecord.setOrderCode(String.valueOf(orderCode));
@@ -36,7 +37,7 @@ public class OrderOperateRecordService { @@ -36,7 +37,7 @@ public class OrderOperateRecordService {
36 optRecord.setUserName(userName); 37 optRecord.setUserName(userName);
37 optRecord.setUpdateTime(DateUtil.getCurrentTimeSecond()); 38 optRecord.setUpdateTime(DateUtil.getCurrentTimeSecond());
38 optRecord.setOldInfo(""); 39 optRecord.setOldInfo("");
39 - logger.info("OrderOperateRecordService add execute , OrderOperateRecord {} ",optRecord ); 40 + logger.info("OrderOperateRecordService add execute , OrderOperateRecord {} ", optRecord);
40 orderOperateRecordMapper.insert(optRecord); 41 orderOperateRecordMapper.insert(optRecord);
41 42
42 }); 43 });
@@ -4,7 +4,7 @@ import com.yohoufo.common.utils.DateUtil; @@ -4,7 +4,7 @@ import com.yohoufo.common.utils.DateUtil;
4 import com.yohoufo.dal.order.BuyerOrderStatusFlowMapper; 4 import com.yohoufo.dal.order.BuyerOrderStatusFlowMapper;
5 import com.yohoufo.dal.order.model.BuyerOrderStatusFlow; 5 import com.yohoufo.dal.order.model.BuyerOrderStatusFlow;
6 import com.yohoufo.order.service.IInviteSettlementService; 6 import com.yohoufo.order.service.IInviteSettlementService;
7 -import com.yohoufo.order.utils.PubThreadFactory; 7 +import com.yohoufo.order.utils.NamedThreadFactory;
8 import org.slf4j.Logger; 8 import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory; 9 import org.slf4j.LoggerFactory;
10 import org.springframework.beans.factory.annotation.Autowired; 10 import org.springframework.beans.factory.annotation.Autowired;
@@ -19,9 +19,11 @@ import java.util.concurrent.TimeUnit; @@ -19,9 +19,11 @@ import java.util.concurrent.TimeUnit;
19 public class OrderStatusFlowService { 19 public class OrderStatusFlowService {
20 private final Logger logger = LoggerFactory.getLogger(getClass()); 20 private final Logger logger = LoggerFactory.getLogger(getClass());
21 21
22 - private ExecutorService executorService = new ThreadPoolExecutor(5, 10, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<>(1000), new PubThreadFactory("order-status-flow")); 22 + private ExecutorService executorService = new ThreadPoolExecutor(5, 10,
  23 + 60, TimeUnit.SECONDS, new ArrayBlockingQueue<>(1000), NamedThreadFactory.newThreadFactory("order-status-flow"));
23 24
24 - private ExecutorService inviteExecutorService = new ThreadPoolExecutor(5, 10, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<>(1000), new PubThreadFactory("invite-order-executor")); 25 + private ExecutorService inviteExecutorService = new ThreadPoolExecutor(5, 10,
  26 + 60, TimeUnit.SECONDS, new ArrayBlockingQueue<>(1000), NamedThreadFactory.newThreadFactory("invite-order-executor"));
25 27
26 @Autowired 28 @Autowired
27 private BuyerOrderStatusFlowMapper buyerOrderStatusFlowMapper; 29 private BuyerOrderStatusFlowMapper buyerOrderStatusFlowMapper;
1 -package com.yohoufo.order.service.proxy;  
2 -  
3 -import com.yoho.message.sdk.service.ufo.IUFOSendService;  
4 -import com.yohoufo.dal.order.SellerOrderMapper;  
5 -import com.yohoufo.dal.product.ProductMapper;  
6 -import com.yohoufo.inboxclient.sdk.InBoxSDK;  
7 -import com.yohoufo.order.utils.PubThreadFactory;  
8 -import org.springframework.beans.factory.annotation.Autowired;  
9 -import org.springframework.stereotype.Service;  
10 -  
11 -import javax.annotation.PostConstruct;  
12 -import java.util.concurrent.ArrayBlockingQueue;  
13 -import java.util.concurrent.ExecutorService;  
14 -import java.util.concurrent.ThreadPoolExecutor;  
15 -import java.util.concurrent.TimeUnit;  
16 -  
17 -@Service  
18 -public class SellerOrderMessage {  
19 -  
20 - private ExecutorService executorService;  
21 -  
22 - @Autowired  
23 - private InBoxSDK inBoxSDK;  
24 -  
25 - @Autowired  
26 - private SendSmsService sendSmsService;  
27 -  
28 - @Autowired  
29 - private UserProxyService userProxyService;  
30 -  
31 - @Autowired  
32 - private ProductMapper productMapper;  
33 -  
34 - @Autowired  
35 - private SellerOrderMapper sellerOrderMapper;  
36 -  
37 - @Autowired  
38 - private IUFOSendService ufoSendService;  
39 -  
40 - @PostConstruct  
41 - public void init() {  
42 - executorService = new ThreadPoolExecutor(5, 10,  
43 - 60, TimeUnit.SECONDS,  
44 - new ArrayBlockingQueue<>(1000),  
45 - new PubThreadFactory("seller-order-message"));  
46 - }  
47 -  
48 -  
49 -}  
1 -package com.yohoufo.order.utils;  
2 -  
3 -import java.util.concurrent.ThreadFactory;  
4 -import java.util.concurrent.atomic.AtomicInteger;  
5 -  
6 -/**  
7 - * 自定义java api线程池内工作线程工厂  
8 - * 指定生成线程名称:pool-XXX-thread-[num]  
9 - */  
10 -public class PubThreadFactory implements ThreadFactory {  
11 -  
12 - private static final AtomicInteger poolNumber = new AtomicInteger(1);  
13 - private final AtomicInteger threadNumber = new AtomicInteger(1);  
14 - private final String namePrefix;  
15 - private final ThreadGroup group;  
16 -  
17 - public PubThreadFactory(String nameProcessor) {  
18 - SecurityManager s = System.getSecurityManager();  
19 - group = (s != null) ? s.getThreadGroup() :  
20 - Thread.currentThread().getThreadGroup();  
21 - namePrefix = "pool-"+nameProcessor+"-" +  
22 - poolNumber.getAndIncrement() +  
23 - "-thread-";  
24 - }  
25 -  
26 -  
27 - @Override  
28 - public Thread newThread(Runnable r) {  
29 - Thread t = new Thread(group, r,  
30 - namePrefix + threadNumber.getAndIncrement(),  
31 - 0);  
32 - if (t.isDaemon())  
33 - t.setDaemon(true);  
34 - if (t.getPriority() != Thread.NORM_PRIORITY)  
35 - t.setPriority(Thread.NORM_PRIORITY);  
36 - return t;  
37 - }  
38 -}