Showing
4 changed files
with
205 additions
and
103 deletions
@@ -16,6 +16,7 @@ import java.util.stream.Collectors; | @@ -16,6 +16,7 @@ import java.util.stream.Collectors; | ||
16 | import javax.annotation.Resource; | 16 | import javax.annotation.Resource; |
17 | 17 | ||
18 | import com.yohoufo.order.service.DepositService; | 18 | import com.yohoufo.order.service.DepositService; |
19 | +import com.yohoufo.order.service.proxy.*; | ||
19 | import org.apache.commons.collections.CollectionUtils; | 20 | import org.apache.commons.collections.CollectionUtils; |
20 | import org.apache.commons.lang3.StringUtils; | 21 | import org.apache.commons.lang3.StringUtils; |
21 | import org.slf4j.Logger; | 22 | import org.slf4j.Logger; |
@@ -91,10 +92,6 @@ import com.yohoufo.order.service.handler.penalty.PenaltyResult; | @@ -91,10 +92,6 @@ import com.yohoufo.order.service.handler.penalty.PenaltyResult; | ||
91 | import com.yohoufo.order.service.handler.penalty.SellerEarnestMoney2BuyerPenaltyCalculator; | 92 | import com.yohoufo.order.service.handler.penalty.SellerEarnestMoney2BuyerPenaltyCalculator; |
92 | import com.yohoufo.order.service.impl.function.BuyerNoticeSender; | 93 | import com.yohoufo.order.service.impl.function.BuyerNoticeSender; |
93 | import com.yohoufo.order.service.listener.OrderChangeListenerContainer; | 94 | import com.yohoufo.order.service.listener.OrderChangeListenerContainer; |
94 | -import com.yohoufo.order.service.proxy.InBoxFacade; | ||
95 | -import com.yohoufo.order.service.proxy.OrderOperateRecordService; | ||
96 | -import com.yohoufo.order.service.proxy.OrderStatusFlowService; | ||
97 | -import com.yohoufo.order.service.proxy.ProductProxyService; | ||
98 | import com.yohoufo.order.service.seller.setting.SellerService; | 95 | import com.yohoufo.order.service.seller.setting.SellerService; |
99 | import com.yohoufo.order.utils.BuyerOrderUtils; | 96 | import com.yohoufo.order.utils.BuyerOrderUtils; |
100 | import com.yohoufo.order.utils.PaymentHelper; | 97 | import com.yohoufo.order.utils.PaymentHelper; |
@@ -142,6 +139,9 @@ public class AppraiseService { | @@ -142,6 +139,9 @@ public class AppraiseService { | ||
142 | @Autowired | 139 | @Autowired |
143 | private InBoxFacade inBoxFacade; | 140 | private InBoxFacade inBoxFacade; |
144 | 141 | ||
142 | + @Autowired | ||
143 | + private BuyerNoticeFacade buyerNoticeFacade; | ||
144 | + | ||
145 | 145 | ||
146 | @Autowired | 146 | @Autowired |
147 | TransferService transferService; | 147 | TransferService transferService; |
@@ -284,7 +284,7 @@ public class AppraiseService { | @@ -284,7 +284,7 @@ public class AppraiseService { | ||
284 | appraiseExpressInfoBo.getDepotNum(), | 284 | appraiseExpressInfoBo.getDepotNum(), |
285 | appraiseExpressInfoBo.getMobile()); | 285 | appraiseExpressInfoBo.getMobile()); |
286 | // 通知买家已发货 | 286 | // 通知买家已发货 |
287 | - inBoxFacade.noticeBuyerWhenDeliveryDepositGoodsToBuyer(buyerOrder.getUid(), appraiseExpressInfoBo.getWayBillCode(), | 287 | + buyerNoticeFacade.deliveryDepositGoodsToBuyer(buyerOrder.getUid(), appraiseExpressInfoBo.getWayBillCode(), |
288 | () -> cleanCacheAfterUpdateStatus(buyerOrder.getOrderCode(), buyerOrder.getUid(), buyerOrder.getSellerUid()), | 288 | () -> cleanCacheAfterUpdateStatus(buyerOrder.getOrderCode(), buyerOrder.getUid(), buyerOrder.getSellerUid()), |
289 | sellerOrderGoods -> Optional.ofNullable(sellerOrderGoods).map(SellerOrderGoods::getProductId).map(productMapper::selectByPrimaryKey).orElse(null)); | 289 | sellerOrderGoods -> Optional.ofNullable(sellerOrderGoods).map(SellerOrderGoods::getProductId).map(productMapper::selectByPrimaryKey).orElse(null)); |
290 | }else { | 290 | }else { |
@@ -331,7 +331,7 @@ public class AppraiseService { | @@ -331,7 +331,7 @@ public class AppraiseService { | ||
331 | //清缓存 | 331 | //清缓存 |
332 | SellerOrderGoods sellerOrderGoods = cleanCacheAfterUpdateStatus(buyerOrder.getOrderCode(), buyerOrder.getUid(), buyerOrder.getSellerUid()); | 332 | SellerOrderGoods sellerOrderGoods = cleanCacheAfterUpdateStatus(buyerOrder.getOrderCode(), buyerOrder.getUid(), buyerOrder.getSellerUid()); |
333 | Product product = Optional.ofNullable(sellerOrderGoods).map(SellerOrderGoods::getProductId).map(productMapper::selectByPrimaryKey).orElse(null); | 333 | Product product = Optional.ofNullable(sellerOrderGoods).map(SellerOrderGoods::getProductId).map(productMapper::selectByPrimaryKey).orElse(null); |
334 | - inBoxFacade.noticeBuyerWhenDeliveryGoodsToBuyer(buyerUid, orderCode, sellerOrderGoods, product); | 334 | + buyerNoticeFacade.deliveryGoodsToBuyer(buyerUid, orderCode, sellerOrderGoods, product); |
335 | } else { | 335 | } else { |
336 | LOGGER.warn("in deliveryGoodsToBuyer update status number zero, buyer Order orderCode {} pstatus {}, expect Order Status {}", | 336 | LOGGER.warn("in deliveryGoodsToBuyer update status number zero, buyer Order orderCode {} pstatus {}, expect Order Status {}", |
337 | orderCode, buyerOrder.getStatus(), expectOrderStatus); | 337 | orderCode, buyerOrder.getStatus(), expectOrderStatus); |
1 | +package com.yohoufo.order.service.proxy; | ||
2 | + | ||
3 | +import com.yoho.message.sdk.common.model.SendMessageRspBo; | ||
4 | +import com.yohobuy.ufo.model.enums.InboxBusinessTypeEnum; | ||
5 | +import com.yohoufo.inboxclient.model.InBoxResponse; | ||
6 | +import com.yohoufo.inboxclient.model.InboxReqVO; | ||
7 | +import com.yohoufo.inboxclient.sdk.InBoxSDK; | ||
8 | +import lombok.extern.slf4j.Slf4j; | ||
9 | +import org.apache.commons.lang3.StringUtils; | ||
10 | +import org.slf4j.helpers.MessageFormatter; | ||
11 | +import org.springframework.beans.factory.annotation.Autowired; | ||
12 | + | ||
13 | +import java.util.Arrays; | ||
14 | +import java.util.List; | ||
15 | +import java.util.Objects; | ||
16 | +import java.util.concurrent.ArrayBlockingQueue; | ||
17 | +import java.util.concurrent.ExecutorService; | ||
18 | +import java.util.concurrent.ThreadPoolExecutor; | ||
19 | +import java.util.concurrent.TimeUnit; | ||
20 | +import java.util.function.Supplier; | ||
21 | + | ||
22 | +@Slf4j | ||
23 | +public class BaseNoticeFacade { | ||
24 | + | ||
25 | + private ExecutorService executorService = new ThreadPoolExecutor(5, 10, | ||
26 | + 60, TimeUnit.SECONDS, | ||
27 | + new ArrayBlockingQueue<>(1000), new InBoxThreadFactory()); | ||
28 | + | ||
29 | + @Autowired | ||
30 | + private InBoxSDK inBoxSDK; | ||
31 | + | ||
32 | + @Autowired | ||
33 | + private SendSmsService sendSmsService; | ||
34 | + | ||
35 | + @Autowired | ||
36 | + private UserProxyService userProxyService; | ||
37 | + | ||
38 | + public Notice newNotice(int uid) { | ||
39 | + return new Notice(uid); | ||
40 | + } | ||
41 | + | ||
42 | + public class Notice { | ||
43 | + | ||
44 | + private final int uid; | ||
45 | + | ||
46 | + private InboxReqVO inBoxContent; | ||
47 | + private String smsContent; | ||
48 | + | ||
49 | + private Supplier<SendMessageRspBo> pushSupplier; | ||
50 | + | ||
51 | + public Notice(int uid) { | ||
52 | + this.uid = uid; | ||
53 | + } | ||
54 | + | ||
55 | + public Notice withInBox(InboxBusinessTypeEnum businessType, Object... args) { | ||
56 | + inBoxContent = buildInboxReqVO(uid, buildParams(args), businessType); | ||
57 | + return this; | ||
58 | + } | ||
59 | + | ||
60 | + public Notice withSms(InboxBusinessTypeEnum businessType, Object... args) { | ||
61 | + smsContent = getReplacedContent(businessType.getContent(), args); | ||
62 | + return this; | ||
63 | + } | ||
64 | + | ||
65 | + public Notice withPush(Supplier<SendMessageRspBo> pushSupplier) { | ||
66 | + this.pushSupplier = pushSupplier; | ||
67 | + return this; | ||
68 | + } | ||
69 | + | ||
70 | + public void send() { | ||
71 | + executorService.execute(() -> { | ||
72 | + log.warn("send, uid {} inBoxContent {} smsContent {}", uid, inBoxContent, smsContent); | ||
73 | + try { | ||
74 | + if (Objects.nonNull(inBoxContent)) { | ||
75 | + InBoxResponse resp = inBoxSDK.addInbox(inBoxContent); | ||
76 | + log.info("send in box success, uid {}, content {} response {}", uid, inBoxContent, resp); | ||
77 | + } | ||
78 | + if (Objects.nonNull(pushSupplier)) { | ||
79 | + SendMessageRspBo resp = pushSupplier.get(); | ||
80 | + log.info("send push success, uid {}, response {}", uid, inBoxContent, resp); | ||
81 | + } | ||
82 | + if (Objects.nonNull(smsContent)) { | ||
83 | + String phone = userProxyService.getMobile(uid); | ||
84 | + if (StringUtils.isBlank(phone)) { | ||
85 | + log.warn("send sms fail, uid {} content {} phone is blank", uid, smsContent); | ||
86 | + } else { | ||
87 | + List<String> mobileList = Arrays.asList(phone); | ||
88 | + sendSmsService.smsSendByMobile(smsContent, mobileList); | ||
89 | + log.info("send sms success, uid {} content {} phone {} ", uid, smsContent, phone); | ||
90 | + } | ||
91 | + } | ||
92 | + } catch (Exception e) { | ||
93 | + log.warn("send fail, uid {} inBoxContent {} smsContent {}", uid, inBoxContent, smsContent, e); | ||
94 | + } | ||
95 | + }); | ||
96 | + } | ||
97 | + | ||
98 | + private String buildParams(Object... objects) { | ||
99 | + if (objects == null) { | ||
100 | + return null; | ||
101 | + } | ||
102 | + | ||
103 | + if (objects.length == 1) { | ||
104 | + return objects[0].toString(); | ||
105 | + } | ||
106 | + | ||
107 | + String params = StringUtils.join(objects, ","); | ||
108 | + return params; | ||
109 | + } | ||
110 | + | ||
111 | + private InboxReqVO buildInboxReqVO(int uid, String params, InboxBusinessTypeEnum ibt) { | ||
112 | + InboxReqVO req = new InboxReqVO(); | ||
113 | + req.setType(ibt.getType()); | ||
114 | + req.setBusinessType(ibt.getBusinessType()); | ||
115 | + req.setUid(uid); | ||
116 | + req.setParams(params); | ||
117 | + return req; | ||
118 | + } | ||
119 | + | ||
120 | + private String getReplacedContent(String content, Object... params) { | ||
121 | + return MessageFormatter.arrayFormat(content, params).getMessage(); | ||
122 | + } | ||
123 | + | ||
124 | + } | ||
125 | + | ||
126 | +} |
1 | +package com.yohoufo.order.service.proxy; | ||
2 | + | ||
3 | +import com.yoho.message.sdk.service.ufo.IUFOSendService; | ||
4 | +import com.yohobuy.ufo.model.enums.InboxBusinessTypeEnum; | ||
5 | +import com.yohobuy.ufo.model.order.constants.SkupType; | ||
6 | +import com.yohoufo.dal.order.model.SellerOrderGoods; | ||
7 | +import com.yohoufo.dal.product.model.Product; | ||
8 | +import lombok.extern.slf4j.Slf4j; | ||
9 | +import org.springframework.beans.factory.annotation.Autowired; | ||
10 | +import org.springframework.stereotype.Service; | ||
11 | + | ||
12 | +import java.util.Optional; | ||
13 | +import java.util.function.Function; | ||
14 | +import java.util.function.Supplier; | ||
15 | + | ||
16 | +@Service | ||
17 | +@Slf4j | ||
18 | +public class BuyerNoticeFacade extends BaseNoticeFacade { | ||
19 | + | ||
20 | + @Autowired | ||
21 | + private IUFOSendService ufoSendService; | ||
22 | + | ||
23 | + | ||
24 | + /** | ||
25 | + * 平台发货给买家 | ||
26 | + * | ||
27 | + * @return | ||
28 | + */ | ||
29 | + public void deliveryDepositGoodsToBuyer(int buyerUid, String wayBillCode, Supplier<SellerOrderGoods> psogSupplier, Function<SellerOrderGoods, Product> productFunction) { | ||
30 | + try { | ||
31 | + log.info("notice buyer delivery deposit goods to buyer, uid {}, wayBillCode {}", buyerUid, wayBillCode); | ||
32 | + SellerOrderGoods psog = psogSupplier.get(); | ||
33 | + Product product = productFunction.apply(psog); | ||
34 | + String prdName = psog.getProductName(); | ||
35 | + String sizeName = psog.getSizeName(); | ||
36 | + String productCode = Optional.ofNullable(product).map(Product::getProductCode).orElse(""); | ||
37 | + newNotice(buyerUid) | ||
38 | + .withInBox(InboxBusinessTypeEnum.NOTICE_BUYER_WHEN_DEPOSIT_GOODS_PURCHASE_SENDED, prdName, sizeName, productCode) | ||
39 | + .withSms(InboxBusinessTypeEnum.SMS_NOTICE_BUYER_WHEN_DEPOSIT_GOODS_PURCHASE_SENDED, prdName, sizeName, productCode, wayBillCode) | ||
40 | + .send(); | ||
41 | + log.info("notice buyer delivery deposit goods to buyer success, uid {}, wayBillCode {}", buyerUid, wayBillCode); | ||
42 | + } catch (Exception e) { | ||
43 | + log.warn("notice buyer delivery deposit goods to buyer fail, uid {}, wayBillCode {}", buyerUid, wayBillCode, e); | ||
44 | + } | ||
45 | + | ||
46 | + } | ||
47 | + | ||
48 | + /** | ||
49 | + * 平台发货给买家 | ||
50 | + * | ||
51 | + * @return | ||
52 | + */ | ||
53 | + public void deliveryGoodsToBuyer(int buyerUid, long orderCode, SellerOrderGoods psog, Product product) { | ||
54 | + try { | ||
55 | + log.info("notice buyer delivery goods to buyer, buyerUid {}, orderCode {}", buyerUid, orderCode); | ||
56 | + String skupTypeText = SkupType.getSkupType(psog.getAttributes()).attrName(); | ||
57 | + String prdName = psog.getProductName(); | ||
58 | + String sizeName = psog.getSizeName(); | ||
59 | + String productCode = Optional.ofNullable(product).map(Product::getProductCode).orElse(""); | ||
60 | + | ||
61 | + newNotice(buyerUid) | ||
62 | + .withInBox(InboxBusinessTypeEnum.PURCHASE_SENDED, orderCode) | ||
63 | + .withSms(InboxBusinessTypeEnum.SMS_SEND, skupTypeText, prdName, sizeName, productCode, orderCode) | ||
64 | + .withPush(() -> ufoSendService.platformDeliverBuyer(String.valueOf(buyerUid), String.valueOf(orderCode))) | ||
65 | + .send(); | ||
66 | + | ||
67 | + log.info("notice buyer delivery goods to buyer success, buyerUid {}, orderCode {}", buyerUid, orderCode); | ||
68 | + } catch (Exception e) { | ||
69 | + log.warn("notice buyer delivery goods to buyer fail, buyerUid {}, orderCode {}", buyerUid, orderCode, e); | ||
70 | + } | ||
71 | + } | ||
72 | + | ||
73 | +} |
@@ -166,103 +166,6 @@ public class InBoxFacade { | @@ -166,103 +166,6 @@ public class InBoxFacade { | ||
166 | } | 166 | } |
167 | 167 | ||
168 | /** | 168 | /** |
169 | - * 平台发货给买家 | ||
170 | - * | ||
171 | - * @return | ||
172 | - */ | ||
173 | - public void noticeBuyerWhenDeliveryGoodsToBuyer(int buyerUid, long orderCode, SellerOrderGoods psog,Product product) { | ||
174 | - | ||
175 | - executorService.execute(()->{ | ||
176 | - | ||
177 | - try { | ||
178 | - logger.info("record noticeBuyerWhenDeliveryGoodsToBuyer inbox msg, buyerUid {}, orderCode {}, psog {},SellerOrderGoods {} product {}", | ||
179 | - buyerUid, orderCode, psog, JSON.toJSONString(psog), JSON.toJSONString(product)); | ||
180 | - String skupTypeText=SkupType.getSkupType(psog.getAttributes()).attrName(); | ||
181 | - String prdName = psog.getProductName(); | ||
182 | - String sizeName = psog.getSizeName(); | ||
183 | - String productCode = Optional.ofNullable(product).map(Product::getProductCode).orElse(""); | ||
184 | - | ||
185 | - InboxBusinessTypeEnum ibt = InboxBusinessTypeEnum.PURCHASE_SENDED; | ||
186 | - String params = buildParams(orderCode); | ||
187 | - InboxReqVO req = buildInboxReqVO(buyerUid, params, ibt); | ||
188 | - | ||
189 | - InBoxResponse resp = inBoxSDK.addInbox(req); | ||
190 | - logger.info("record noticeBuyerWhenDeliveryGoodsToBuyer inbox msg, buyerUid {}, orderCode {}, prdName {},SellerOrderGoods {} resp {}", | ||
191 | - buyerUid, orderCode, prdName, JSON.toJSONString(psog), resp); | ||
192 | - | ||
193 | - //发push | ||
194 | - SendMessageRspBo bo = ufoSendService.platformDeliverBuyer(String.valueOf(buyerUid),String.valueOf(orderCode)); | ||
195 | - logger.info("record noticeBuyerWhenDeliveryGoodsToBuyer push buyer uid is {}, orderCode is {}, result is {}", buyerUid, orderCode, JSON.toJSONString(bo)); | ||
196 | - | ||
197 | - | ||
198 | - //seller notice | ||
199 | - | ||
200 | - | ||
201 | - //短信 | ||
202 | - String phone = userProxyService.getMobile(buyerUid); | ||
203 | - if (StringUtils.isBlank(phone)){ | ||
204 | - logger.warn("in noticeBuyerWhenDeliveryGoodsToBuyer notice buyer sms fail, buyerUid {} orderCode {} prdName {} ", buyerUid, orderCode,prdName); | ||
205 | - }else{ | ||
206 | - List<String> mobileList = Arrays.asList(phone); | ||
207 | - String content = getReplacedContent(InboxBusinessTypeEnum.SMS_SEND.getContent(),skupTypeText,prdName,sizeName,productCode,orderCode); | ||
208 | - sendSmsService.smsSendByMobile(content,mobileList); | ||
209 | - logger.info("record noticeBuyerWhenDeliveryGoodsToBuyer notice buyer sms msg, buyerUid {}, orderCode {}, prdName {} phone {}", | ||
210 | - buyerUid, orderCode,prdName, phone); | ||
211 | - } | ||
212 | - } catch (Exception e) { | ||
213 | - logger.warn("InBoxFacade noticeBuyerWhenDeliveryGoodsToBuyer error inbox msg, buyerUid {}, orderCode {} ,psog {}", | ||
214 | - buyerUid, orderCode, psog, e); | ||
215 | - } | ||
216 | - }); | ||
217 | - | ||
218 | - } | ||
219 | - | ||
220 | - /** | ||
221 | - * 平台发货给买家 | ||
222 | - * | ||
223 | - * @return | ||
224 | - */ | ||
225 | - public void noticeBuyerWhenDeliveryDepositGoodsToBuyer(int buyerUid, String wayBillCode, Supplier<SellerOrderGoods> psogSupplier, Function<SellerOrderGoods,Product> productFunction) { | ||
226 | - | ||
227 | - executorService.execute(()->{ | ||
228 | - | ||
229 | - try { | ||
230 | - SellerOrderGoods psog = psogSupplier.get(); | ||
231 | - Product product = productFunction.apply(psog); | ||
232 | - logger.info("noticeBuyerWhenDeliveryDepositGoodsToBuyer, buyerUid {}, wayBillCode {}, psog {},SellerOrderGoods {} product {}", | ||
233 | - buyerUid, wayBillCode, psog, JSON.toJSONString(psog), JSON.toJSONString(product)); | ||
234 | - String prdName = psog.getProductName(); | ||
235 | - String sizeName = psog.getSizeName(); | ||
236 | - String productCode = Optional.ofNullable(product).map(Product::getProductCode).orElse(""); | ||
237 | - | ||
238 | - InboxBusinessTypeEnum ibt = InboxBusinessTypeEnum.NOTICE_BUYER_WHEN_DEPOSIT_GOODS_PURCHASE_SENDED; | ||
239 | - String params = buildParams(prdName,sizeName,productCode); | ||
240 | - InboxReqVO req = buildInboxReqVO(buyerUid, params, ibt); | ||
241 | - | ||
242 | - InBoxResponse resp = inBoxSDK.addInbox(req); | ||
243 | - logger.info("noticeBuyerWhenDeliveryDepositGoodsToBuyer, buyerUid {}, wayBillCode {}, prdName {},SellerOrderGoods {} resp {}", | ||
244 | - buyerUid, wayBillCode, prdName, JSON.toJSONString(psog), resp); | ||
245 | - | ||
246 | - //短信 | ||
247 | - String phone = userProxyService.getMobile(buyerUid); | ||
248 | - if (StringUtils.isBlank(phone)){ | ||
249 | - logger.warn("noticeBuyerWhenDeliveryDepositGoodsToBuyer notice buyer sms fail, buyerUid {} wayBillCode {} prdName {} ", | ||
250 | - buyerUid, wayBillCode,prdName); | ||
251 | - }else{ | ||
252 | - List<String> mobileList = Arrays.asList(phone); | ||
253 | - String content = getReplacedContent(InboxBusinessTypeEnum.SMS_NOTICE_BUYER_WHEN_DEPOSIT_GOODS_PURCHASE_SENDED.getContent(),prdName,sizeName,productCode,wayBillCode); | ||
254 | - sendSmsService.smsSendByMobile(content,mobileList); | ||
255 | - logger.info("noticeBuyerWhenDeliveryDepositGoodsToBuyer notice buyer sms msg, buyerUid {}, wayBillCode {}, prdName {} phone {}", | ||
256 | - buyerUid, wayBillCode,prdName, phone); | ||
257 | - } | ||
258 | - } catch (Exception e) { | ||
259 | - logger.warn("noticeBuyerWhenDeliveryDepositGoodsToBuyer fail, buyerUid {}, wayBillCode {}", buyerUid, wayBillCode, e); | ||
260 | - } | ||
261 | - }); | ||
262 | - | ||
263 | - } | ||
264 | - | ||
265 | - /** | ||
266 | * 平台已发货给买家 | 169 | * 平台已发货给买家 |
267 | * | 170 | * |
268 | * @return | 171 | * @return |
-
Please register or login to post a comment