Remove useless country mapper from OrderCreationRequestBody

pull/8040/head
Qiuyi LI 2024-09-18 17:30:49 +02:00
parent 566368ec35
commit 431d2049bd
3 changed files with 13 additions and 22 deletions

View File

@ -7,7 +7,7 @@ public class JsonOrderCreationRequestBody extends OrderCreationRequestBody {
private final String jsonString; private final String jsonString;
public JsonOrderCreationRequestBody(String jsonString) { public JsonOrderCreationRequestBody(String jsonString) {
super(null, null); super(null);
this.jsonString = jsonString; this.jsonString = jsonString;
} }

View File

@ -19,8 +19,6 @@ public class OrderCreationRequestBody implements RequestBody {
private List<ShoumanOrderContent> orderContents; private List<ShoumanOrderContent> orderContents;
private Map<String, Country> countryMap;
private final static String DEFAULT_SPLIT = ";"; private final static String DEFAULT_SPLIT = ";";
private final static String LINE_BREAK = "\n"; private final static String LINE_BREAK = "\n";
private final static String QUOTE = ":"; private final static String QUOTE = ":";
@ -30,9 +28,8 @@ public class OrderCreationRequestBody implements RequestBody {
private final static String PRODUCT_GROUP_KEY = "_gpo_product_group"; private final static String PRODUCT_GROUP_KEY = "_gpo_product_group";
private final static String PARENT_PRODUCT_GROUP_KEY = "_gpo_parent_product_group"; private final static String PARENT_PRODUCT_GROUP_KEY = "_gpo_parent_product_group";
public OrderCreationRequestBody(List<ShoumanOrderContent> orderContents, Map<String, Country> countryMap) { public OrderCreationRequestBody(List<ShoumanOrderContent> orderContents) {
this.orderContents = orderContents; this.orderContents = orderContents;
this.countryMap = countryMap;
} }
@Override @Override
@ -48,8 +45,6 @@ public class OrderCreationRequestBody implements RequestBody {
putNonNull(json, "address", "收货人:王生 收货地址: 广东省东镇芦莞市寮步溪二路40号汇元佳科技园二栋10楼公司前台 手机17633551138"); putNonNull(json, "address", "收货人:王生 收货地址: 广东省东镇芦莞市寮步溪二路40号汇元佳科技园二栋10楼公司前台 手机17633551138");
putNonNull(json, "addressee", "王生"); putNonNull(json, "addressee", "王生");
putNonNull(json, "city", "东莞市"); putNonNull(json, "city", "东莞市");
String countryName = anyContent.getCountry();
Country country = countryMap.get(countryName);
putNonNull(json, "country", "CHINA"); putNonNull(json, "country", "CHINA");
putNonNull(json, "countryCode", "CN"); putNonNull(json, "countryCode", "CN");
// TODO: 2023/11/29 Change to real address // TODO: 2023/11/29 Change to real address
@ -148,16 +143,16 @@ public class OrderCreationRequestBody implements RequestBody {
for (ShoumanOrderContent necklace : necklaces) { for (ShoumanOrderContent necklace : necklaces) {
String necklacePgValue = extractProductGroupValue(necklace.getCustomizationData().split(DEFAULT_SPLIT), PRODUCT_GROUP_KEY); String necklacePgValue = extractProductGroupValue(necklace.getCustomizationData().split(DEFAULT_SPLIT), PRODUCT_GROUP_KEY);
for (ShoumanOrderContent gem : gems) { for (ShoumanOrderContent gem : gems) {
String gemPgValue = extractProductGroupValue(gem.getCustomizationData().split(DEFAULT_SPLIT), PARENT_PRODUCT_GROUP_KEY); String gemPgValue = extractProductGroupValue(gem.getCustomizationData().split(DEFAULT_SPLIT), PARENT_PRODUCT_GROUP_KEY);
if (necklacePgValue != null && necklacePgValue.equalsIgnoreCase(gemPgValue)) { if (necklacePgValue != null && necklacePgValue.equalsIgnoreCase(gemPgValue)) {
// We need the remark from necklace for colour/material/month/font AND we need remark from // We need the remark from necklace for colour/material/month/font AND we need remark from
// gem for the mention of its presence // gem for the mention of its presence
gem.setRemark(necklace.getRemark().concat(gem.getRemark())); gem.setRemark(necklace.getRemark().concat(gem.getRemark()));
// We need the custom data from necklace to parse the name // We need the custom data from necklace to parse the name
gem.setCustomizationData(necklace.getCustomizationData()); gem.setCustomizationData(necklace.getCustomizationData());
reducedContents.add(gem); reducedContents.add(gem);
break; break;
} }
} }
} }
return reducedContents; return reducedContents;

View File

@ -28,14 +28,10 @@ public class ShoumanOrderCreationJob implements Job {
private PlatformOrderContentMapper platformOrderContentMapper; private PlatformOrderContentMapper platformOrderContentMapper;
@Autowired @Autowired
private IShoumanOrderService shoumanOrderService; private IShoumanOrderService shoumanOrderService;
@Autowired
private CountryMapper countryMapper;
@Override @Override
public void execute(JobExecutionContext context) throws JobExecutionException { public void execute(JobExecutionContext context) throws JobExecutionException {
log.info("Started Shouman order creation job"); log.info("Started Shouman order creation job");
Map<String, Country> countryCodeMap = countryMapper.findAll().stream()
.collect(toMap(Country::getMabangName, Function.identity()));
List<ShoumanOrderContent> shoumanOrderContents = platformOrderContentMapper.searchShoumanOrderContent(); List<ShoumanOrderContent> shoumanOrderContents = platformOrderContentMapper.searchShoumanOrderContent();
log.info("Fetched {} shouman order contents", shoumanOrderContents.size()); log.info("Fetched {} shouman order contents", shoumanOrderContents.size());
@ -47,7 +43,7 @@ public class ShoumanOrderCreationJob implements Job {
log.info("Started constructing Shouman request bodies"); log.info("Started constructing Shouman request bodies");
List<ShoumanOrder> shoumanOrders = new ArrayList<>(); List<ShoumanOrder> shoumanOrders = new ArrayList<>();
for (Map.Entry<String, List<ShoumanOrderContent>> entry : groupedByPlatformOrderId.entrySet()) { for (Map.Entry<String, List<ShoumanOrderContent>> entry : groupedByPlatformOrderId.entrySet()) {
OrderCreationRequestBody requestBody = new OrderCreationRequestBody(entry.getValue(), countryCodeMap); OrderCreationRequestBody requestBody = new OrderCreationRequestBody(entry.getValue());
ShoumanOrder shoumanOrder = new ShoumanOrder(); ShoumanOrder shoumanOrder = new ShoumanOrder();
shoumanOrder.setOrderJson(requestBody.parameters().toJSONString()); shoumanOrder.setOrderJson(requestBody.parameters().toJSONString());
shoumanOrder.setPlatformOrderId(entry.getKey()); shoumanOrder.setPlatformOrderId(entry.getKey());