From 518b9c8c34364e59eafa5448b5994f30b0a38e70 Mon Sep 17 00:00:00 2001 From: daixiaogang <2510234660@qq.com> Date: Tue, 12 Sep 2023 09:35:05 +0800 Subject: [PATCH] buildCreateProductV2Data --- .../java/com/ms/api/bo/MoveShopSettingBO.java | 4 + .../java/com/ms/api/consts/MoveConst.java | 9 ++ .../ProcessProductPublishTaskService.java | 115 ++++++++++++++++-- 3 files changed, 115 insertions(+), 13 deletions(-) diff --git a/ms-biz/src/main/java/com/ms/api/bo/MoveShopSettingBO.java b/ms-biz/src/main/java/com/ms/api/bo/MoveShopSettingBO.java index 55ccda17..200eaae5 100644 --- a/ms-biz/src/main/java/com/ms/api/bo/MoveShopSettingBO.java +++ b/ms-biz/src/main/java/com/ms/api/bo/MoveShopSettingBO.java @@ -155,4 +155,8 @@ public class MoveShopSettingBO { private String filterEmptyColorImg; + private int baseMarketPriceType; + + private int marketPrice; + } diff --git a/ms-biz/src/main/java/com/ms/api/consts/MoveConst.java b/ms-biz/src/main/java/com/ms/api/consts/MoveConst.java index 671e8edd..d8561478 100644 --- a/ms-biz/src/main/java/com/ms/api/consts/MoveConst.java +++ b/ms-biz/src/main/java/com/ms/api/consts/MoveConst.java @@ -38,4 +38,13 @@ public class MoveConst { public static final int MOVE_PUBLISH_TO_PIC_QUQUE_AGAIN_WAIT_SPEC_PIC_AUDIT_PASS = 9898; public static final int MOVE_PUBLISH_TO_PIC_QUQUE_AGAIN_WAIT_MAIN_IMG_PIC_AUDIT_PASS = 9899; public static final int MOVE_PUBLISH_TO_PIC_QUQUE_AGAIN_WAIT_NOTE_IMG_PIC_AUDIT_PASS = 9897; + + public static final int baseMarketPriceTypeDdPrice = 1; + public static final int maxMarketPrice = 9999999; // 划线价最高9999999.99(单位元) + + public static final String priceDecimalTypeHoldFenJiao = "holdFenJiao"; + public static final String priceDecimalTypeKeepSource = "keepSource"; + public static final String priceDecimalTypeClearFenJiao = "clearFenJiao"; + public static final String priceDecimalTypeClearFen = "clearFen"; + public static final String priceDecimalTypeDiy = "diy"; } diff --git a/ms-biz/src/main/java/com/ms/api/task/ProcessProductPublishTaskService.java b/ms-biz/src/main/java/com/ms/api/task/ProcessProductPublishTaskService.java index 0414e090..cae31e6f 100644 --- a/ms-biz/src/main/java/com/ms/api/task/ProcessProductPublishTaskService.java +++ b/ms-biz/src/main/java/com/ms/api/task/ProcessProductPublishTaskService.java @@ -19,6 +19,7 @@ import javax.annotation.Resource; import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.doudian.open.api.material_batchUploadImageSync.MaterialBatchUploadImageSyncRequest; import com.doudian.open.api.material_batchUploadImageSync.MaterialBatchUploadImageSyncResponse; @@ -42,6 +43,7 @@ import com.ms.api.common.StrStrMap; import com.ms.api.common.TaskBaseService; import com.ms.api.consts.CommonConst; import com.ms.api.consts.MaterialConst; +import com.ms.api.consts.MoveConst; import com.ms.api.consts.RedisKeyConst; import com.ms.api.consts.StatusConst; import com.ms.api.paas.RedisService; @@ -575,6 +577,7 @@ public class ProcessProductPublishTaskService extends TaskBaseService { } productDetailBase = processSpuPriceMaybeOutRange(productDetailBase); productDetailBase = processSpuMarketPriceMaybeOutRange(productDetailBase, condition); + moveBaseData.put("publishTips", publishTips); Ret mRet = CommonTool.successResult(); StrObjMap mData = new StrObjMap(); mData.put("productDetailBase", productDetailBase); @@ -585,23 +588,109 @@ public class ProcessProductPublishTaskService extends TaskBaseService { } private JSONObject processSpuMarketPriceMaybeOutRange(JSONObject productDetailBase, MoveShopSettingBO condition) { - return null; + if (condition.getIsFastMode() != 0 && (condition.getBaseMarketPriceType() == MoveConst.baseMarketPriceTypeDdPrice)) { + // TODO: 2023/9/12 condition 缺少太多参数了 转成 + productDetailBase.put("marketPrice", processConditionMarketPrice((JSONObject) JSONObject.toJSON(condition), productDetailBase.getDouble("price") / 100, productDetailBase.getDouble("marketPrice") / 100)); + productDetailBase.put("marketPrice", productDetailBase.getDouble("marketPrice") * 100); + } + + JSONArray specPrices = productDetailBase.getJSONArray("specPrices"); + double[] priceList = new double[specPrices.size()]; + double maxSkuPrice = Double.NEGATIVE_INFINITY; + + for (int i = 0; i < specPrices.size(); i++) { + JSONObject specPrice = specPrices.getJSONObject(i); + double price = specPrice.getDouble("price"); + priceList[i] = price; + maxSkuPrice = Math.max(maxSkuPrice, price); + } + + if (productDetailBase.getDouble("marketPrice") < maxSkuPrice) { + productDetailBase.put("marketPrice", maxSkuPrice); + } + + double maxMarketPrice = MoveConst.maxMarketPrice * 100; + if (productDetailBase.getDouble("marketPrice") > maxMarketPrice) { + productDetailBase.put("marketPrice", maxMarketPrice); + } + + return productDetailBase; + } + + private Object processConditionMarketPrice(JSONObject condition, double price, double marketPrice) { + if (condition.getIntValue("baseMarketPriceType") == (MoveConst.baseMarketPriceTypeDdPrice)) { + marketPrice = price; + } + String[] sourcePriceDecimalDigits = String.valueOf(marketPrice).replaceAll("0+$", "").split("\\."); + if (condition.containsKey("marketPricePercent")) { + marketPrice = CommonTool.numFormat((condition.getDouble("marketPricePercent") * marketPrice) / 100,2); + } + if (condition.containsKey("marketPriceAdd")) { + marketPrice = CommonTool.numFormat(condition.getDouble("marketPriceAdd") + marketPrice,2); + } + if (condition.containsKey("marketPriceSub") && marketPrice > condition.getDouble("marketPriceSub")) { + marketPrice = CommonTool.numFormat(marketPrice - condition.getDouble("marketPriceSub"),2); + } + if (condition.containsKey("marketPriceTail")) { + marketPrice = ((int) (marketPrice / 10) * 10) + condition.getIntValue("marketPriceTail"); + marketPrice = CommonTool.numFormat(marketPrice,2); + } + + if (!condition.containsKey("marketPriceTail")) { + if (Objects.equals(condition.getString("marketPriceDecimal"), MoveConst.priceDecimalTypeClearFenJiao)) { + marketPrice = CommonTool.numFormat(marketPrice, 0); + } else if (Objects.equals(condition.getString("marketPriceDecimal"), MoveConst.priceDecimalTypeClearFen)) { + marketPrice = CommonTool.numFormat(marketPrice, 1); + } else if (Objects.equals(condition.getString("marketPriceDecimal"), MoveConst.priceDecimalTypeKeepSource)) { + if (sourcePriceDecimalDigits[1].isEmpty()) { + marketPrice = CommonTool.numFormat(marketPrice, 0); + } else if (sourcePriceDecimalDigits[1].length() == 2) { + marketPrice = CommonTool.numFormat(marketPrice, 2); + } else if (sourcePriceDecimalDigits[1].length() == 1) { + marketPrice = CommonTool.numFormat(marketPrice, 1); + } + } else if (Objects.equals(condition.getString("marketPriceDecimal"), MoveConst.priceDecimalTypeDiy)) { + marketPrice = processPriceDecimalDiyValue(marketPrice, condition.getDouble("marketPriceDecimalDiyValue")); + } + } + if (marketPrice < price) { + marketPrice = price; + } + return marketPrice; + } + + private double processPriceDecimalDiyValue(double price, Double priceDecimalDiyValue) { + String strPriceDecimalDiyValue = String.valueOf(priceDecimalDiyValue.intValue()); + + if (strPriceDecimalDiyValue.length() > 2) { + strPriceDecimalDiyValue = strPriceDecimalDiyValue.substring(0, 2); + } + + return CommonTool.numFormat(price,0) + Double.parseDouble("." + strPriceDecimalDiyValue); } private JSONObject processSpuPriceMaybeOutRange(JSONObject productDetailBase) { -// JSONArray specPrices = productDetailBase.getJSONArray("specPrices"); -// -// double minSkuPrice = specPrices.stream().map(x->x.); -// double maxSkuPrice = Double.NEGATIVE_INFINITY; -// -// for (int i = 0; i < specPrices.length(); i++) { -// JSONObject specPrice = specPrices.getJSONObject(i); -// double price = specPrice.getDouble("price"); -// minSkuPrice = Math.min(minSkuPrice, price); -// maxSkuPrice = Math.max(maxSkuPrice, price); -// } - return null; + JSONArray specPrices = productDetailBase.getJSONArray("specPrices"); + + double minSkuPrice = Double.POSITIVE_INFINITY; + double maxSkuPrice = Double.NEGATIVE_INFINITY; + + for (int i = 0; i < specPrices.size(); i++) { + JSONObject specPrice = specPrices.getJSONObject(i); + double price = specPrice.getDouble("price"); + minSkuPrice = Math.min(minSkuPrice, price); + maxSkuPrice = Math.max(maxSkuPrice, price); + } + if (minSkuPrice <= 0) { + return productDetailBase; + } + + double productPrice = productDetailBase.getDouble("price"); + if (productPrice < minSkuPrice || productPrice > maxSkuPrice) { + productDetailBase.put("price", minSkuPrice); + } + return productDetailBase; } private StrObjMap checkHasRepeatSpec(StrObjMap colorSpecArrCalc, StrObjMap sizeSpecArrCalc) {