| | |
| | | import org.yeshi.utils.NumberUtil;
|
| | |
|
| | | import com.aliyun.openservices.ons.api.Message;
|
| | | import com.aliyun.openservices.ons.api.Producer;
|
| | | import com.aliyun.openservices.ons.api.SendResult;
|
| | | import com.aliyun.openservices.ons.api.transaction.LocalTransactionExecuter;
|
| | | import com.aliyun.openservices.ons.api.transaction.TransactionProducer;
|
| | |
| | |
|
| | | @Resource(name = "orderTransactionProducer")
|
| | | private TransactionProducer orderTransactionProducer;
|
| | |
|
| | | @Resource(name = "producer")
|
| | | private Producer producer;
|
| | |
|
| | | @Resource
|
| | | private OrderMoneySettleService orderMoneySettleService;
|
| | |
| | | * @param sourceType
|
| | | * @param hongBaoType
|
| | | */
|
| | | @Transactional
|
| | | private void addHongBaoWithMQ(List<CommonOrderAddResultDTO> commonOrderList, String orderId, Long uid,
|
| | | int sourceType, int hongBaoType) {
|
| | | // TODO 区分添加与修改
|
| | |
|
| | | final List<CommonOrder> coList = convertCommonOrder(commonOrderList);
|
| | | OrderMQMsg mqMsg = new OrderMQMsg(orderId, sourceType, uid);
|
| | | Message msg = new Message(MQTopicName.TOPIC_ORDER.name(), OrderTopicTagEnum.orderStatistic.name(),
|
| | | new Gson().toJson(mqMsg).getBytes());
|
| | | SendResult result = orderTransactionProducer.send(msg, new LocalTransactionExecuter() {
|
| | | @Override
|
| | | public TransactionStatus execute(Message arg0, Object arg1) {
|
| | | int resultCode = 0;
|
| | | try {
|
| | | resultCode = hongBaoV2Service.addHongBao(coList, hongBaoType);
|
| | | } catch (HongBaoException e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e, "addJDOrder或addHongBao出错", "订单号:" + orderId);
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }
|
| | | return TransactionStatus.CommitTransaction;
|
| | | // if (resultCode != 0)
|
| | | // return TransactionStatus.CommitTransaction;
|
| | | // else
|
| | | // return TransactionStatus.RollbackTransaction;
|
| | | int resultCode = 0;
|
| | | try {
|
| | | resultCode = hongBaoV2Service.addHongBao(coList, hongBaoType);
|
| | | } catch (HongBaoException e) {
|
| | | try {
|
| | | LogHelper.errorDetailInfo(e, "addJDOrder或addHongBao出错", "订单号:" + orderId);
|
| | | } catch (Exception e1) {
|
| | | e1.printStackTrace();
|
| | | }
|
| | | }, null);
|
| | | System.out.println(result);
|
| | | }
|
| | | if (resultCode == 1) {// 只发送新增消息
|
| | | OrderMQMsg mqMsg = new OrderMQMsg(orderId, sourceType, uid, OrderMQMsg.HANDLE_TYPE_ADD,
|
| | | isCommonOrderValid(coList));
|
| | | Message msg = new Message(MQTopicName.TOPIC_ORDER.name(), OrderTopicTagEnum.orderStatistic.name(),
|
| | | new Gson().toJson(mqMsg).getBytes());
|
| | | producer.send(msg);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 订单是否有效
|
| | | * |
| | | * @param coList
|
| | | * @return
|
| | | */
|
| | | private boolean isCommonOrderValid(List<CommonOrder> coList) {
|
| | | for (CommonOrder commonOrder : coList) {
|
| | | if (commonOrder.getState() == CommonOrder.STATE_JS || commonOrder.getState() == CommonOrder.STATE_FK
|
| | | || commonOrder.getState() == CommonOrder.STATE_WQ) {
|
| | | return true;
|
| | | }
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | }
|