Authored by LUOXC

refactor

@@ -56,7 +56,7 @@ public class BaseNoticeFacade { @@ -56,7 +56,7 @@ public class BaseNoticeFacade {
56 } 56 }
57 57
58 public Notice withInBox(InboxBusinessTypeEnum businessType, Object... args) { 58 public Notice withInBox(InboxBusinessTypeEnum businessType, Object... args) {
59 - inBoxContent = buildInboxReqVO(uid, buildParams(args), businessType); 59 + inBoxContent = buildInboxContent(businessType, args);
60 return this; 60 return this;
61 } 61 }
62 62
@@ -66,7 +66,7 @@ public class BaseNoticeFacade { @@ -66,7 +66,7 @@ public class BaseNoticeFacade {
66 } 66 }
67 67
68 public Notice withSms(InboxBusinessTypeEnum businessType, Object... args) { 68 public Notice withSms(InboxBusinessTypeEnum businessType, Object... args) {
69 - smsContent = getReplacedContent(businessType.getContent(), args); 69 + smsContent = buildSmsContent(businessType, args);
70 return this; 70 return this;
71 } 71 }
72 72
@@ -86,6 +86,7 @@ public class BaseNoticeFacade { @@ -86,6 +86,7 @@ public class BaseNoticeFacade {
86 InboxReqVO inBoxContent = getInBoxContent(); 86 InboxReqVO inBoxContent = getInBoxContent();
87 if (Objects.nonNull(inBoxContent)) { 87 if (Objects.nonNull(inBoxContent)) {
88 try { 88 try {
  89 + inBoxContent.setUid(uid);
89 InBoxResponse resp = inBoxSDK.addInbox(inBoxContent); 90 InBoxResponse resp = inBoxSDK.addInbox(inBoxContent);
90 log.info("send in box success, uid {}, content {} response {}", uid, inBoxContent, resp); 91 log.info("send in box success, uid {}, content {} response {}", uid, inBoxContent, resp);
91 } catch (Exception e) { 92 } catch (Exception e) {
@@ -171,11 +172,19 @@ public class BaseNoticeFacade { @@ -171,11 +172,19 @@ public class BaseNoticeFacade {
171 return req; 172 return req;
172 } 173 }
173 174
  175 + protected InboxReqVO buildInboxContent(InboxBusinessTypeEnum ibt,Object... params) {
  176 + InboxReqVO req = new InboxReqVO();
  177 + req.setType(ibt.getType());
  178 + req.setBusinessType(ibt.getBusinessType());
  179 + req.setParams(buildParams(params));
  180 + return req;
  181 + }
  182 +
174 protected String getReplacedContent(String content, Object... params) { 183 protected String getReplacedContent(String content, Object... params) {
175 return MessageFormatter.arrayFormat(content, params).getMessage(); 184 return MessageFormatter.arrayFormat(content, params).getMessage();
176 } 185 }
177 186
178 - protected String replaceSMSContent(InboxBusinessTypeEnum ibte, Object... params){ 187 + protected String buildSmsContent(InboxBusinessTypeEnum ibte, Object... params){
179 return getReplacedContent(ibte.getContent(), params); 188 return getReplacedContent(ibte.getContent(), params);
180 } 189 }
181 190
@@ -20,7 +20,6 @@ import lombok.NonNull; @@ -20,7 +20,6 @@ import lombok.NonNull;
20 import org.apache.commons.lang3.StringUtils; 20 import org.apache.commons.lang3.StringUtils;
21 import org.slf4j.Logger; 21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory; 22 import org.slf4j.LoggerFactory;
23 -import org.slf4j.helpers.MessageFormatter;  
24 import org.springframework.beans.factory.annotation.Autowired; 23 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.stereotype.Service; 24 import org.springframework.stereotype.Service;
26 25
@@ -33,8 +32,6 @@ import java.util.concurrent.ArrayBlockingQueue; @@ -33,8 +32,6 @@ import java.util.concurrent.ArrayBlockingQueue;
33 import java.util.concurrent.ExecutorService; 32 import java.util.concurrent.ExecutorService;
34 import java.util.concurrent.ThreadPoolExecutor; 33 import java.util.concurrent.ThreadPoolExecutor;
35 import java.util.concurrent.TimeUnit; 34 import java.util.concurrent.TimeUnit;
36 -import java.util.function.Function;  
37 -import java.util.function.Supplier;  
38 35
39 /** 36 /**
40 * Created by chenchao on 2018/10/8. 37 * Created by chenchao on 2018/10/8.
@@ -96,29 +93,27 @@ public class InBoxFacade extends BaseNoticeFacade{ @@ -96,29 +93,27 @@ public class InBoxFacade extends BaseNoticeFacade{
96 } 93 }
97 94
98 95
99 -  
100 /** 96 /**
101 * 卖家发货后 97 * 卖家发货后
  98 + *
102 * @param buyerUid 99 * @param buyerUid
103 * @param orderCode 100 * @param orderCode
104 */ 101 */
105 public void sellerDeliver2Depot(int buyerUid, long orderCode, SellerOrderGoods psog) { 102 public void sellerDeliver2Depot(int buyerUid, long orderCode, SellerOrderGoods psog) {
106 try { 103 try {
107 - executorService.execute(() -> {  
108 -  
109 logger.info("notice buyer seller deliver 2 depot, buyerUid {}, orderCode {}", buyerUid, orderCode); 104 logger.info("notice buyer seller deliver 2 depot, buyerUid {}, orderCode {}", buyerUid, orderCode);
  105 + newNotice(buyerUid)
  106 + .withInBox(InboxBusinessTypeEnum.NOTICE_BUYER_WHEN_SELLER_DELIVER, orderCode)
  107 + .withPush(() -> ufoSendService.sellerDeliverNotice(String.valueOf(buyerUid), String.valueOf(orderCode)))
  108 + .withSms(() -> {
110 String skupTypeText = SkupType.getSkupType(psog.getAttributes()).attrName(); 109 String skupTypeText = SkupType.getSkupType(psog.getAttributes()).attrName();
111 String prdName = psog.getProductName(); 110 String prdName = psog.getProductName();
112 String sizeName = psog.getSizeName(); 111 String sizeName = psog.getSizeName();
113 Product product = productMapper.selectByPrimaryKey(psog.getProductId()); 112 Product product = productMapper.selectByPrimaryKey(psog.getProductId());
114 String productCode = product.getProductCode(); 113 String productCode = product.getProductCode();
115 -  
116 - newNotice(buyerUid)  
117 - .withInBox(InboxBusinessTypeEnum.NOTICE_BUYER_WHEN_SELLER_DELIVER, orderCode)  
118 - .withPush(() -> ufoSendService.sellerDeliverNotice(String.valueOf(buyerUid), String.valueOf(orderCode)))  
119 - .withSms(InboxBusinessTypeEnum.SMS_NOTICE_BUYER_WHEN_SELLER_DELIVER, skupTypeText, prdName, sizeName, productCode, orderCode) 114 + return buildSmsContent(InboxBusinessTypeEnum.SMS_NOTICE_BUYER_WHEN_SELLER_DELIVER, skupTypeText, prdName, sizeName, productCode, orderCode);
  115 + })
120 .send(); 116 .send();
121 - });  
122 } catch (Exception ex) { 117 } catch (Exception ex) {
123 logger.warn("notice buyer seller deliver 2 depot fail, buyerUid {}, orderCode {}", buyerUid, orderCode, ex); 118 logger.warn("notice buyer seller deliver 2 depot fail, buyerUid {}, orderCode {}", buyerUid, orderCode, ex);
124 } 119 }
@@ -131,19 +126,18 @@ public class InBoxFacade extends BaseNoticeFacade{ @@ -131,19 +126,18 @@ public class InBoxFacade extends BaseNoticeFacade{
131 */ 126 */
132 public void appraisePassAndDeliveryGoodsToBuyerNoticeBuyer(int buyerUid, long orderCode, SellerOrderGoods psog) { 127 public void appraisePassAndDeliveryGoodsToBuyerNoticeBuyer(int buyerUid, long orderCode, SellerOrderGoods psog) {
133 try { 128 try {
134 - executorService.execute(() -> {  
135 logger.info("notice buyer appraise pass, buyerUid {}, orderCode {}", buyerUid, orderCode); 129 logger.info("notice buyer appraise pass, buyerUid {}, orderCode {}", buyerUid, orderCode);
  130 + newNotice(buyerUid)
  131 + .withInBox(InboxBusinessTypeEnum.PURCHASE_SENDED, orderCode)
  132 + .withSms(() -> {
136 Product product = productMapper.selectByPrimaryKey(psog.getProductId()); 133 Product product = productMapper.selectByPrimaryKey(psog.getProductId());
137 String productCode = Optional.ofNullable(product).map(Product::getProductCode).orElse(""); 134 String productCode = Optional.ofNullable(product).map(Product::getProductCode).orElse("");
138 String skupTypeText = SkupType.getSkupType(psog.getAttributes()).attrName(); 135 String skupTypeText = SkupType.getSkupType(psog.getAttributes()).attrName();
139 String prdName = psog.getProductName(); 136 String prdName = psog.getProductName();
140 String sizeName = psog.getSizeName(); 137 String sizeName = psog.getSizeName();
141 -  
142 - newNotice(buyerUid)  
143 - .withInBox(InboxBusinessTypeEnum.PURCHASE_SENDED, orderCode)  
144 - .withSms(InboxBusinessTypeEnum.SMS_SEND, skupTypeText, prdName, sizeName, productCode, orderCode) 138 + return buildSmsContent(InboxBusinessTypeEnum.SMS_SEND, skupTypeText, prdName, sizeName, productCode, orderCode);
  139 + })
145 .send(); 140 .send();
146 - });  
147 } catch (Exception e) { 141 } catch (Exception e) {
148 logger.warn("notice buyer appraise pass fail, buyerUid {}, orderCode {}", buyerUid, orderCode, e); 142 logger.warn("notice buyer appraise pass fail, buyerUid {}, orderCode {}", buyerUid, orderCode, e);
149 } 143 }
@@ -151,20 +145,21 @@ public class InBoxFacade extends BaseNoticeFacade{ @@ -151,20 +145,21 @@ public class InBoxFacade extends BaseNoticeFacade{
151 145
152 public void appraisePassNoticeSeller(int buyerUid, long orderCode, SellerOrderGoods psog) { 146 public void appraisePassNoticeSeller(int buyerUid, long orderCode, SellerOrderGoods psog) {
153 try { 147 try {
154 - executorService.execute(() -> {  
155 logger.info("notice seller appraise pass, buyerUid {}, orderCode {}", buyerUid, orderCode); 148 logger.info("notice seller appraise pass, buyerUid {}, orderCode {}", buyerUid, orderCode);
  149 + newNotice(psog.getUid())
  150 + .withInBox(() -> {
156 String prdName = psog.getProductName(); 151 String prdName = psog.getProductName();
157 Product product = productMapper.selectByPrimaryKey(psog.getProductId()); 152 Product product = productMapper.selectByPrimaryKey(psog.getProductId());
158 String productCode = Optional.ofNullable(product).map(Product::getProductCode).orElse(""); 153 String productCode = Optional.ofNullable(product).map(Product::getProductCode).orElse("");
159 String sizeName = psog.getSizeName(); 154 String sizeName = psog.getSizeName();
160 - Integer sellerUid = psog.getUid();  
161 String skupTypeText = SkupType.getSkupType(psog.getAttributes()).attrName(); 155 String skupTypeText = SkupType.getSkupType(psog.getAttributes()).attrName();
162 -  
163 - newNotice(sellerUid)  
164 - .withInBox(InboxBusinessTypeEnum.NOTICE_SELLER_WHEN_APPRAISE_PASS, skupTypeText, prdName, sizeName, productCode)  
165 - .withSms(InboxBusinessTypeEnum.SMS_NOTICE_SELLER_WHEN_APPRAISE_PASS, skupTypeText, orderCode) 156 + return buildInboxContent(InboxBusinessTypeEnum.NOTICE_SELLER_WHEN_APPRAISE_PASS,skupTypeText, prdName, sizeName, productCode);
  157 + })
  158 + .withSms(() -> {
  159 + String skupTypeText = SkupType.getSkupType(psog.getAttributes()).attrName();
  160 + return buildSmsContent(InboxBusinessTypeEnum.SMS_NOTICE_SELLER_WHEN_APPRAISE_PASS, skupTypeText, orderCode);
  161 + })
166 .send(); 162 .send();
167 - });  
168 163
169 } catch (Exception e) { 164 } catch (Exception e) {
170 logger.warn("notice seller appraise pass fail, buyerUid {}, orderCode {}", buyerUid, orderCode, e); 165 logger.warn("notice seller appraise pass fail, buyerUid {}, orderCode {}", buyerUid, orderCode, e);
@@ -1475,7 +1470,7 @@ public class InBoxFacade extends BaseNoticeFacade{ @@ -1475,7 +1470,7 @@ public class InBoxFacade extends BaseNoticeFacade{
1475 if(autoReSell){ 1470 if(autoReSell){
1476 sms=InboxBusinessTypeEnum.SMS_NOTICE_SELLER_AUTO_RESELL_WHEN_BUYER_CANCEL_NO_RESPONSIBILITY; 1471 sms=InboxBusinessTypeEnum.SMS_NOTICE_SELLER_AUTO_RESELL_WHEN_BUYER_CANCEL_NO_RESPONSIBILITY;
1477 } 1472 }
1478 - String content = replaceSMSContent(sms, orderCode,skupTypeText, prdName,sizeName,productCode); 1473 + String content = buildSmsContent(sms, orderCode,skupTypeText, prdName,sizeName,productCode);
1479 sendSmsService.smsSendByMobile(content,mobileList); 1474 sendSmsService.smsSendByMobile(content,mobileList);
1480 logger.info("record noticeSellerWhenBuyerCancelNoResponsibility inbox sms msg, sellerUid {}, orderCode {},prdName {}", 1475 logger.info("record noticeSellerWhenBuyerCancelNoResponsibility inbox sms msg, sellerUid {}, orderCode {},prdName {}",
1481 sellerUid, orderCode, prdName); 1476 sellerUid, orderCode, prdName);