Authored by LUOXC

refactor

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