Authored by chenchao

optimized replicate code

@@ -7,27 +7,29 @@ import com.yohobuy.ufo.model.order.bo.ButtonShowBo; @@ -7,27 +7,29 @@ import com.yohobuy.ufo.model.order.bo.ButtonShowBo;
7 import com.yohobuy.ufo.model.order.bo.GoodsInfo; 7 import com.yohobuy.ufo.model.order.bo.GoodsInfo;
8 import com.yohobuy.ufo.model.order.bo.OrderInfo; 8 import com.yohobuy.ufo.model.order.bo.OrderInfo;
9 import com.yohobuy.ufo.model.order.common.*; 9 import com.yohobuy.ufo.model.order.common.*;
10 -import com.yohobuy.ufo.model.order.constants.OrderConstant;  
11 import com.yohobuy.ufo.model.order.resp.OrderListInfo; 10 import com.yohobuy.ufo.model.order.resp.OrderListInfo;
12 import com.yohobuy.ufo.model.order.resp.PageResp; 11 import com.yohobuy.ufo.model.order.resp.PageResp;
13 import com.yohobuy.ufo.model.order.vo.OrderListVo; 12 import com.yohobuy.ufo.model.order.vo.OrderListVo;
14 import com.yohoufo.common.helper.ImageUrlAssist; 13 import com.yohoufo.common.helper.ImageUrlAssist;
15 import com.yohoufo.common.utils.DateUtil; 14 import com.yohoufo.common.utils.DateUtil;
16 -import com.yohoufo.dal.order.*;  
17 -import com.yohoufo.dal.order.model.*;  
18 -import com.yohoufo.dal.product.model.Storage; 15 +import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
  16 +import com.yohoufo.dal.order.BuyerOrderMapper;
  17 +import com.yohoufo.dal.order.SellerOrderGoodsMapper;
  18 +import com.yohoufo.dal.order.SellerOrderMapper;
  19 +import com.yohoufo.dal.order.model.BuyerOrder;
  20 +import com.yohoufo.dal.order.model.BuyerOrderGoods;
  21 +import com.yohoufo.dal.order.model.SellerOrder;
  22 +import com.yohoufo.dal.order.model.SellerOrderGoods;
19 import com.yohoufo.order.model.request.OrderListRequest; 23 import com.yohoufo.order.model.request.OrderListRequest;
20 import com.yohoufo.order.service.AbsSellerOrderViewService; 24 import com.yohoufo.order.service.AbsSellerOrderViewService;
21 import com.yohoufo.order.service.IOrderListService; 25 import com.yohoufo.order.service.IOrderListService;
22 import com.yohoufo.order.service.cache.OrderCacheService; 26 import com.yohoufo.order.service.cache.OrderCacheService;
23 -import com.yohoufo.order.service.impl.processor.SellerOrderPrepareProcessor;  
24 import com.yohoufo.order.service.proxy.ProductProxyService; 27 import com.yohoufo.order.service.proxy.ProductProxyService;
25 import com.yohoufo.order.service.proxy.UserProxyService; 28 import com.yohoufo.order.service.proxy.UserProxyService;
26 import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator; 29 import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
27 import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta; 30 import com.yohoufo.order.service.support.codegenerator.bean.CodeMeta;
28 import com.yohoufo.order.utils.LoggerUtils; 31 import com.yohoufo.order.utils.LoggerUtils;
29 import com.yohoufo.order.utils.OrderAssist; 32 import com.yohoufo.order.utils.OrderAssist;
30 -import com.yohoufo.product.response.StorageDataResp;  
31 import com.yohoufo.product.response.StorageInfoResp; 33 import com.yohoufo.product.response.StorageInfoResp;
32 import org.apache.commons.collections.CollectionUtils; 34 import org.apache.commons.collections.CollectionUtils;
33 import org.slf4j.Logger; 35 import org.slf4j.Logger;
@@ -35,8 +37,10 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -35,8 +37,10 @@ import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.stereotype.Service; 37 import org.springframework.stereotype.Service;
36 38
37 import java.math.BigDecimal; 39 import java.math.BigDecimal;
38 -import java.util.*;  
39 -import java.util.function.Consumer; 40 +import java.util.List;
  41 +import java.util.Map;
  42 +import java.util.Objects;
  43 +import java.util.Set;
40 import java.util.stream.Collectors; 44 import java.util.stream.Collectors;
41 45
42 46
@@ -69,7 +73,10 @@ public class SellerOrderListService extends AbsOrderListService implements IOrde @@ -69,7 +73,10 @@ public class SellerOrderListService extends AbsOrderListService implements IOrde
69 private ProductProxyService productProxyService; 73 private ProductProxyService productProxyService;
70 74
71 @Autowired 75 @Autowired
72 - private SellerOrderPrepareProcessor sellerOrderPrepareProcessor; 76 + private OrderCodeGenerator orderCodeGenerator;
  77 +
  78 + @Autowired
  79 + private SkupListService skupListService;
73 80
74 81
75 public List<OrderListInfo> buildOrderList(List<SellerOrderGoods> sogList, SellerType sellerType){ 82 public List<OrderListInfo> buildOrderList(List<SellerOrderGoods> sogList, SellerType sellerType){
@@ -152,8 +159,7 @@ public class SellerOrderListService extends AbsOrderListService implements IOrde @@ -152,8 +159,7 @@ public class SellerOrderListService extends AbsOrderListService implements IOrde
152 void setAddressInfo(OrderListInfo orderListInfo) { 159 void setAddressInfo(OrderListInfo orderListInfo) {
153 160
154 } 161 }
155 - @Autowired  
156 - private OrderCodeGenerator orderCodeGenerator; 162 +
157 163
158 @Override 164 @Override
159 protected void resetDynamicProporties(List<OrderListInfo> list, int type) { 165 protected void resetDynamicProporties(List<OrderListInfo> list, int type) {
@@ -187,44 +193,16 @@ public class SellerOrderListService extends AbsOrderListService implements IOrde @@ -187,44 +193,16 @@ public class SellerOrderListService extends AbsOrderListService implements IOrde
187 193
188 194
189 195
190 -  
191 /** 196 /**
192 * 需要商品提供批量接口,减少db net IO, 目前的工期太短,后期再优化 197 * 需要商品提供批量接口,减少db net IO, 目前的工期太短,后期再优化
193 * @param sogList 198 * @param sogList
194 * @return 199 * @return
195 */ 200 */
196 public Map<String,String> buildOverPriceTipsMap(List<SellerOrderGoods> sogList){ 201 public Map<String,String> buildOverPriceTipsMap(List<SellerOrderGoods> sogList){
197 - Map<String,String> map = new HashMap<>(sogList.size());  
198 Set<Integer> storageIds = sogList.parallelStream().map(SellerOrderGoods::getStorageId) 202 Set<Integer> storageIds = sogList.parallelStream().map(SellerOrderGoods::getStorageId)
199 .collect(Collectors.toSet()); 203 .collect(Collectors.toSet());
200 Map<Integer, StorageInfoResp> getStorageDataMap = productProxyService.getStorageDataMap(storageIds); 204 Map<Integer, StorageInfoResp> getStorageDataMap = productProxyService.getStorageDataMap(storageIds);
201 - final String defaultResult = "";  
202 - for(SellerOrderGoods sog : sogList) {  
203 -  
204 - int storageId = sog.getStorageId();  
205 - BigDecimal prdPrice = sog.getGoodsPrice();  
206 - String key = OrderAssist.overFlowPriceKey(storageId, prdPrice);  
207 - if (map.containsKey(key)){  
208 - continue;  
209 - }  
210 - StorageInfoResp storage = getStorageDataMap.get(storageId);  
211 - Optional<StorageInfoResp> sdro = Optional.ofNullable(storage);  
212 - Consumer<StorageInfoResp> sdrc = (sdr)-> {  
213 - BigDecimal slp = sdr.getSuggestHighPrice();  
214 - String value;  
215 - try {  
216 - log.info("in buildOverPriceTipsMap, prdPrice {}, storageId {} StorageDataResp {}",  
217 - prdPrice, storageId, sdr);  
218 - boolean isOverflow = sellerOrderPrepareProcessor.isOverSuggestMaxPrice(slp, prdPrice);  
219 - value = isOverflow ? OrderConstant.Tips.SUGGEST_MAX_PRICE_OVERFLOW : defaultResult;  
220 - } catch (Exception ex) {  
221 - log.warn("in buildOverPriceTipsMap storageId {},prdPrice {}", storageId, prdPrice, ex);  
222 - value = defaultResult;  
223 - }  
224 - map.put(key, value);  
225 - };  
226 - sdro.ifPresent(sdrc);  
227 - } 205 + Map<String,String> map = skupListService.buildOverPriceTipsMap(storageIds, sogList, getStorageDataMap);
228 return map; 206 return map;
229 } 207 }
230 208
@@ -18,7 +18,6 @@ import com.yohoufo.common.helper.ImageUrlAssist; @@ -18,7 +18,6 @@ import com.yohoufo.common.helper.ImageUrlAssist;
18 import com.yohoufo.dal.order.SellerOrderGoodsMapper; 18 import com.yohoufo.dal.order.SellerOrderGoodsMapper;
19 import com.yohoufo.dal.order.SellerOrderGoodsViewMapper; 19 import com.yohoufo.dal.order.SellerOrderGoodsViewMapper;
20 import com.yohoufo.dal.order.model.SellerOrderGoods; 20 import com.yohoufo.dal.order.model.SellerOrderGoods;
21 -import com.yohoufo.dal.product.model.Storage;  
22 import com.yohoufo.order.model.request.OrderListRequest; 21 import com.yohoufo.order.model.request.OrderListRequest;
23 import com.yohoufo.order.model.request.SellerGoodsListRequest; 22 import com.yohoufo.order.model.request.SellerGoodsListRequest;
24 import com.yohoufo.order.service.impl.processor.SellerOrderPrepareProcessor; 23 import com.yohoufo.order.service.impl.processor.SellerOrderPrepareProcessor;
@@ -26,7 +25,6 @@ import com.yohoufo.order.service.proxy.ProductProxyService; @@ -26,7 +25,6 @@ import com.yohoufo.order.service.proxy.ProductProxyService;
26 import com.yohoufo.order.service.proxy.UserProxyService; 25 import com.yohoufo.order.service.proxy.UserProxyService;
27 import com.yohoufo.order.utils.LoggerUtils; 26 import com.yohoufo.order.utils.LoggerUtils;
28 import com.yohoufo.order.utils.OrderAssist; 27 import com.yohoufo.order.utils.OrderAssist;
29 -import com.yohoufo.product.response.StorageDataResp;  
30 import com.yohoufo.product.response.StorageInfoResp; 28 import com.yohoufo.product.response.StorageInfoResp;
31 import org.apache.commons.collections.CollectionUtils; 29 import org.apache.commons.collections.CollectionUtils;
32 import org.apache.commons.lang3.StringUtils; 30 import org.apache.commons.lang3.StringUtils;
@@ -8,6 +8,6 @@ import java.math.BigDecimal; @@ -8,6 +8,6 @@ import java.math.BigDecimal;
8 public class OrderAssist { 8 public class OrderAssist {
9 9
10 public static String overFlowPriceKey(Integer storageId, BigDecimal salePrice){ 10 public static String overFlowPriceKey(Integer storageId, BigDecimal salePrice){
11 - return new StringBuilder(storageId).append(salePrice).toString(); 11 + return new StringBuilder().append(storageId).append("_").append(salePrice).toString();
12 } 12 }
13 } 13 }