商品详情返回price

20230922-ljl-fixBug
cxxxxxxx详 1 year ago
parent d90d805456
commit ec239b955c

@ -5,7 +5,7 @@ curl --location --request POST 'localhost:8080/base/cloud/spi' \
--data-raw '{
"appId":"7264840234423027259",
"authId":"4463798",
"method":"searchDSProductCatTree",
"method":"testSpi",
"data":"{\"moveCollectTaskDetailIds\":[26],\"deleteOnSaleProduct\":0,\"deleteProduct\":0}"
}'

@ -6,13 +6,20 @@ import com.jinritemai.cloud.base.api.BaseRequest;
import com.jinritemai.cloud.base.api.BaseResponse;
import com.jinritemai.cloud.base.api.ExtensionService;
import com.jinritemai.cloud.base.api.ExtensionServiceHandler;
import com.ms.api.biz.MoveService;
import com.ms.api.bo.MoveShopSettingBO;
import com.ms.api.common.R;
import com.ms.api.common.Ret;
import com.ms.api.common.SPIBaseService;
import com.ms.api.dto.ItemDTO;
import com.ms.api.service.MoveShopSettingService;
import com.ms.api.tool.CommonTool;
import com.ms.api.tool.DsJsonRequestTemplate;
import com.ms.api.tool.SecurityTool;
import com.ms.dal.entity.MoveShopSetting;
import lombok.extern.slf4j.Slf4j;
import org.modelmapper.ModelMapper;
import org.modelmapper.convention.MatchingStrategies;
import org.springframework.beans.factory.annotation.Autowired;
import java.io.BufferedReader;
@ -24,25 +31,33 @@ import java.util.HashMap;
@ExtensionService("testSpi")
@Slf4j
public class TestSpiService extends SPIBaseService implements ExtensionServiceHandler<ItemDTO, JSONObject> {
public class TestSpiService extends SPIBaseService implements ExtensionServiceHandler<ItemDTO, Ret> {
@Autowired
private DsJsonRequestTemplate dsJsonRequestTemplate;
@Autowired
private MoveService moveService;
@Autowired
private MoveShopSettingService moveShopSettingService;
@Override
public BaseResponse<JSONObject> handle(BaseRequest<ItemDTO> req) {
public BaseResponse<Ret> handle(BaseRequest<ItemDTO> req) {
initHandle(req);
getAuthCode();
String res = null;
HashMap<String, Object> params = new HashMap<>();
params.put("platformItemId", SecurityTool.encodeByAES("3638605009077281167"));
params.put("sourceItemId", "1000090775");
params.put("authCode", authCode);
// double sourcePrice = moveBaseData.getDoubleValue("jd_price");
MoveShopSetting moveShopSetting = moveShopSettingService.getDetailByShopId(shopId);
ModelMapper modelMapper = new ModelMapper();
// 修改匹配策略为严格
modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
MoveShopSettingBO condition = modelMapper.map(moveShopSetting, MoveShopSettingBO.class);
double sourcePrice = 3.00;
try {
res = dsJsonRequestTemplate.execute("/micro_move/add_platform_item_to_source_item_relation", params);
log.info("rrrr"+res);
double mPrice = moveService.processConditionPrice(condition, sourcePrice);
log.info("rrrr"+mPrice);
} catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage());
}
return R.ok(JSON.parseObject(res));
return R.ok(Ret.success());
}
}

@ -1,5 +1,6 @@
package com.ms.api.biz;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
@ -192,11 +193,11 @@ public class MoveService {
if (condition.getAliPriceType().equals(MoveConst.ALI_PRICE_TYPE_CONSIGN) && consignPrice > 0) {
queueMsg.setPrice(moveBaseData.getInteger("consign_price"));
}
double sourcePrice = moveBaseData.getDoubleValue("price");
double sourcePrice = moveBaseData.getDoubleValue("jd_price");
double mPrice = processConditionPrice(condition, sourcePrice);
productDetailBase.put("price", mPrice * 100);
double market_price = moveBaseData.getIntValue("market_price") > 0 ? moveBaseData.getIntValue("market_price") : queueMsg.getPrice();
productDetailBase.put("marketPrice", market_price * 100);
// double market_price = moveBaseData.getIntValue("market_price") > 0 ? moveBaseData.getIntValue("market_price") : queueMsg.getPrice();
// productDetailBase.put("marketPrice", market_price * 100);
// 处理名称
String buildName = buildProductName(condition, moveBaseData.getString("title"), moveBaseData.getString("brand_name"));
@ -268,12 +269,12 @@ public class MoveService {
if (price <= 0) {
return 99999;
}
double pricePercent = Double.parseDouble(condition.getPriceDecimal());
double pricePercent = condition.getPricePercent().doubleValue();
double priceAdd = condition.getPriceAdd().doubleValue();
double priceSub = condition.getPriceSub().doubleValue();
int priceTail = condition.getPriceTail();
String priceDecimal = condition.getPriceDecimal();
double priceDecimalDiyValue = Double.valueOf(condition.getPriceDecimalDiyValue());
double priceDecimalDiyValue = !ObjectUtil.isEmpty(condition.getPriceDecimalDiyValue()) ? Double.valueOf(condition.getPriceDecimalDiyValue()) : 0.00;
return getConditionDdPrice(price, pricePercent, priceAdd, priceSub, priceTail, priceDecimal, priceDecimalDiyValue);
}
@ -287,7 +288,7 @@ public class MoveService {
price = CommonTool.numFormat((pricePercent * price) / 100, 2);
}
if (priceAdd > 0) {
price = CommonTool.numFormat((priceAdd * price), 2);
price = CommonTool.numFormat((priceAdd + price), 2);
}
if (priceSub > 0 && (price > priceSub)) {
price = CommonTool.numFormat((price - priceSub), 2);

@ -2,24 +2,32 @@ package com.ms.api.spi.move;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jinritemai.cloud.base.api.BaseRequest;
import com.jinritemai.cloud.base.api.BaseResponse;
import com.jinritemai.cloud.base.api.ExtensionService;
import com.jinritemai.cloud.base.api.ExtensionServiceHandler;
import com.ms.api.biz.MoveService;
import com.ms.api.bo.MoveShopSettingBO;
import com.ms.api.common.R;
import com.ms.api.common.Ret;
import com.ms.api.common.SPIBaseService;
import com.ms.api.consts.MoveConst;
import com.ms.api.dto.move.GetProductInfoRequestDTO;
import com.ms.api.service.CategoryService;
import com.ms.api.service.CategoryShopService;
import com.ms.api.service.MoveShopSettingService;
import com.ms.api.service.MoveSystemSourceCategoryService;
import com.ms.api.tool.DsJsonRequestTemplate;
import com.ms.dal.entity.Category;
import com.ms.dal.entity.CategoryShop;
import com.ms.dal.entity.MoveShopSetting;
import com.ms.dal.entity.MoveSystemSourceCategory;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.modelmapper.ModelMapper;
import org.modelmapper.convention.MatchingStrategies;
import org.phprpc.util.AssocArray;
import org.phprpc.util.PHPSerializer;
import org.springframework.beans.factory.annotation.Autowired;
@ -30,7 +38,7 @@ import java.util.regex.Pattern;
/**
* 1688
*
* <p>
*
* idid1688
*
@ -50,6 +58,12 @@ public class GetProductInfoByProductId extends SPIBaseService implements Extensi
@Autowired
private CategoryShopService categoryShopService;
@Autowired
private MoveService moveService;
@Autowired
private MoveShopSettingService moveShopSettingService;
@Override
public BaseResponse<Ret> handle(BaseRequest<GetProductInfoRequestDTO> req) {
// ----逻辑校验----
@ -57,14 +71,14 @@ public class GetProductInfoByProductId extends SPIBaseService implements Extensi
// ----业务处理----
initHandle(req);
getAuthCode();
GetProductInfoRequestDTO fields = req.getData();
GetProductInfoRequestDTO fields = req.getData();
List<String> productIds = fields.getProductIds();
List<Object> productInfo = new ArrayList<>();
List<String> fetchFailIds = new ArrayList<>();
for (int i=0; i < productIds.size(); i++){
for (int i = 0; i < productIds.size(); i++) {
HashMap<String, Object> params = new HashMap<>();
params.put("productId",productIds.get(i));
params.put("authCode",authCode);
params.put("productId", productIds.get(i));
params.put("authCode", authCode);
String res = null;
JSONObject resObj = null;
try {
@ -72,14 +86,15 @@ public class GetProductInfoByProductId extends SPIBaseService implements Extensi
resObj = JSON.parseObject(res);
JSONObject product = resObj.getJSONObject("productInfo");
Long sourceCategoryId = product.getLong("1688cid");
// 处理类目
String sourceCateListStr = StringUtils.join(product.getJSONArray("cateList"), ">");
log.info("productInfo:::"+sourceCategoryId.toString());
log.info("productInfo:::" + sourceCategoryId.toString());
MoveSystemSourceCategory moveSystemSourceCategory = moveSystemSourceCategoryService.selectBySourceCategoryId(sourceCategoryId.toString());
if (!ObjectUtil.isEmpty(moveSystemSourceCategory)) {
PHPSerializer p = new PHPSerializer();
String content = moveSystemSourceCategory.getMatchCategoryList();
AssocArray assocArray = (AssocArray) p.unserialize(content.getBytes());
Map<String,Object> assocMap = assocArrayToHash(assocArray);
Map<String, Object> assocMap = assocArrayToHash(assocArray);
Long categoryId = this.getBestCategoryId(sourceCateListStr, assocMap);
if (ObjectUtil.isEmpty(categoryId)) {
product.put("ddCid", "");
@ -96,6 +111,29 @@ public class GetProductInfoByProductId extends SPIBaseService implements Extensi
product.put("ddCid", "");
product.put("ddCategoryList", "");
}
// 处理价格
Double price = product.getDoubleValue("jd_price");
JSONObject skuMap = product.getJSONObject("skuMap");
Double consignPrice = 0D;
for (String key : skuMap.keySet()) {
JSONObject item = JSONObject.parseObject(skuMap.get(key).toString());
Double cPrice = item.getDoubleValue("consignPrice");
if (cPrice > consignPrice) {
consignPrice = cPrice;
}
}
if (Objects.isNull(consignPrice)) {
consignPrice = 0D;
}
MoveShopSetting moveShopSetting = moveShopSettingService.getDetailByShopId(shopId);
ModelMapper modelMapper = new ModelMapper();
modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
MoveShopSettingBO condition = modelMapper.map(moveShopSetting, MoveShopSettingBO.class);
if (condition.getAliPriceType().equals(MoveConst.ALI_PRICE_TYPE_CONSIGN) && consignPrice > 0) {
price = consignPrice;
}
double mPrice = moveService.processConditionPrice(condition, price);
product.put("price", mPrice);
productInfo.add(resObj.getJSONObject("productInfo"));
log.info(res);
} catch (Exception e) {
@ -115,7 +153,7 @@ public class GetProductInfoByProductId extends SPIBaseService implements Extensi
private List<Long> getCategoryIdList(Long categoryId) {
List<Long> categoryIdList = new ArrayList<>();
while(categoryId != 0) {
while (categoryId != 0) {
Category category = categoryService.selectByPrimaryKey(categoryId);
categoryIdList.add(categoryId);
categoryId = Long.valueOf(category.getParentCategoryId());
@ -128,12 +166,12 @@ public class GetProductInfoByProductId extends SPIBaseService implements Extensi
HashMap hashMap = assocArray.toHashMap();
Map result = new HashMap();
for (Object key : hashMap.keySet()) {
if(hashMap.get(key) instanceof AssocArray) {
result.put(key.toString(),assocArrayToHash((AssocArray) hashMap.get(key)));
}else if(hashMap.get(key) instanceof byte[]) {
result.put(key.toString(),new String((byte[]) hashMap.get(key)));
}else {
result.put(key.toString(),hashMap.get(key));
if (hashMap.get(key) instanceof AssocArray) {
result.put(key.toString(), assocArrayToHash((AssocArray) hashMap.get(key)));
} else if (hashMap.get(key) instanceof byte[]) {
result.put(key.toString(), new String((byte[]) hashMap.get(key)));
} else {
result.put(key.toString(), hashMap.get(key));
}
}
log.info(result + "result");

@ -7,19 +7,26 @@ import com.jinritemai.cloud.base.api.BaseRequest;
import com.jinritemai.cloud.base.api.BaseResponse;
import com.jinritemai.cloud.base.api.ExtensionService;
import com.jinritemai.cloud.base.api.ExtensionServiceHandler;
import com.ms.api.biz.MoveService;
import com.ms.api.bo.MoveShopSettingBO;
import com.ms.api.common.R;
import com.ms.api.common.Ret;
import com.ms.api.common.SPIBaseService;
import com.ms.api.consts.MoveConst;
import com.ms.api.dto.move.GetProductInfoRequestDTO;
import com.ms.api.service.CategoryService;
import com.ms.api.service.CategoryShopService;
import com.ms.api.service.MoveShopSettingService;
import com.ms.api.service.MoveSystemSourceCategoryService;
import com.ms.api.tool.DsJsonRequestTemplate;
import com.ms.api.common.UniqueKeyMultiValueMap;
import com.ms.dal.entity.Category;
import com.ms.dal.entity.MoveShopSetting;
import com.ms.dal.entity.MoveSystemSourceCategory;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.modelmapper.ModelMapper;
import org.modelmapper.convention.MatchingStrategies;
import org.phprpc.util.AssocArray;
import org.phprpc.util.PHPSerializer;
import org.springframework.beans.factory.annotation.Autowired;
@ -31,7 +38,7 @@ import java.util.regex.Pattern;
/**
* 1688
*
* <p>
*
* idid1688
*
@ -52,26 +59,32 @@ public class GetProductInfoService extends SPIBaseService implements ExtensionSe
@Autowired
private CategoryShopService categoryShopService;
@Autowired
private MoveService moveService;
@Autowired
private MoveShopSettingService moveShopSettingService;
@Override
public BaseResponse<Ret> handle(BaseRequest<GetProductInfoRequestDTO> req) {
initHandle(req);
getAuthCode();
// ----参数校验----
GetProductInfoRequestDTO fields = req.getData();
GetProductInfoRequestDTO fields = req.getData();
// List<String> sourceItemUrls = new ArrayList<>();
List<String> sourceItemUrls = fields.getSourceItemUrls();
// sourceItemUrls.add("https://detail.1688.com/offer/682805686164.html?spm=a2638t.b_90254924.bangdan-list.3.3872436cl59VWf&cosite=baidujj_pz&tracelog=p4p&_p_isad=1&clickid=3906df8adbe74c3faba6eefc496fa074&sessionid=3fa85d5fd57096560a3cfa71088c6e4a");
// sourceItemUrls.add("https://detail.1688.com/offer/682805686164.html?spm=a2638t.b_90254924.bangdan-list.3.3872436cl59VWf&cosite=baidujj_pz&tracelog=p4p&_p_isad=1&clickid=3906df8adbe74c3faba6eefc496fa074&sessionid=3fa85d5fd57096560a3cfa71088c6e4a");
List<Object> productInfo = new ArrayList<>();
List<String> fetchFailUrls = new ArrayList<>();
for (int i=0; i < sourceItemUrls.size(); i++){
for (int i = 0; i < sourceItemUrls.size(); i++) {
String url = sourceItemUrls.get(i);
Pattern pattern = Pattern.compile("(.*\\.1688\\.com\\/(?:offer|pic)\\/|caigou\\.1688\\.com\\/detail\\/)(\\d+).(htm|html)", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(url);
if (matcher.find()) {
HashMap<String, Object> params = new HashMap<>();
params.put("productId",matcher.group(2));
params.put("authCode",authCode);
params.put("productId", matcher.group(2));
params.put("authCode", authCode);
String res = null;
JSONObject resObj = null;
try {
@ -80,13 +93,13 @@ public class GetProductInfoService extends SPIBaseService implements ExtensionSe
JSONObject product = resObj.getJSONObject("productInfo");
Long sourceCategoryId = product.getLong("1688cid");
String sourceCateListStr = StringUtils.join(product.getJSONArray("cateList"), ">");
log.info("productInfo:::"+sourceCategoryId.toString());
log.info("productInfo:::" + sourceCategoryId.toString());
MoveSystemSourceCategory moveSystemSourceCategory = moveSystemSourceCategoryService.selectBySourceCategoryId(sourceCategoryId.toString());
if (!ObjectUtil.isEmpty(moveSystemSourceCategory)) {
PHPSerializer p = new PHPSerializer();
String content = moveSystemSourceCategory.getMatchCategoryList();
AssocArray assocArray = (AssocArray) p.unserialize(content.getBytes());
Map<String,Object> assocMap = assocArrayToHash(assocArray);
Map<String, Object> assocMap = assocArrayToHash(assocArray);
Long categoryId = this.getBestCategoryId(sourceCateListStr, assocMap);
if (ObjectUtil.isEmpty(categoryId)) {
product.put("ddCid", "");
@ -103,6 +116,29 @@ public class GetProductInfoService extends SPIBaseService implements ExtensionSe
product.put("ddCid", "");
product.put("ddCategoryList", "");
}
// 处理价格
Double price = product.getDoubleValue("jd_price");
JSONObject skuMap = product.getJSONObject("skuMap");
Double consignPrice = 0D;
for (String key : skuMap.keySet()) {
JSONObject item = JSONObject.parseObject(skuMap.get(key).toString());
Double cPrice = item.getDoubleValue("consignPrice");
if (cPrice > consignPrice) {
consignPrice = cPrice;
}
}
if (Objects.isNull(consignPrice)) {
consignPrice = 0D;
}
MoveShopSetting moveShopSetting = moveShopSettingService.getDetailByShopId(shopId);
ModelMapper modelMapper = new ModelMapper();
modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
MoveShopSettingBO condition = modelMapper.map(moveShopSetting, MoveShopSettingBO.class);
if (condition.getAliPriceType().equals(MoveConst.ALI_PRICE_TYPE_CONSIGN) && consignPrice > 0) {
price = consignPrice;
}
double mPrice = moveService.processConditionPrice(condition, price);
product.put("price", mPrice);
productInfo.add(resObj.getJSONObject("productInfo"));
log.info(res);
} catch (Exception e) {
@ -125,9 +161,10 @@ public class GetProductInfoService extends SPIBaseService implements ExtensionSe
// ----结果返回----
return R.ok(Ret.success(result));
}
private List<Long> getCategoryIdList(Long categoryId) {
List<Long> categoryIdList = new ArrayList<>();
while(categoryId != 0) {
while (categoryId != 0) {
Category category = categoryService.selectByPrimaryKey(categoryId);
categoryIdList.add(categoryId);
categoryId = Long.valueOf(category.getParentCategoryId());
@ -135,21 +172,23 @@ public class GetProductInfoService extends SPIBaseService implements ExtensionSe
Collections.reverse(categoryIdList);
return categoryIdList;
}
private static Map assocArrayToHash(AssocArray assocArray) {
HashMap hashMap = assocArray.toHashMap();
Map result = new HashMap();
for (Object key : hashMap.keySet()) {
if(hashMap.get(key) instanceof AssocArray) {
result.put(key.toString(),assocArrayToHash((AssocArray) hashMap.get(key)));
}else if(hashMap.get(key) instanceof byte[]) {
result.put(key.toString(),new String((byte[]) hashMap.get(key)));
}else {
result.put(key.toString(),hashMap.get(key));
if (hashMap.get(key) instanceof AssocArray) {
result.put(key.toString(), assocArrayToHash((AssocArray) hashMap.get(key)));
} else if (hashMap.get(key) instanceof byte[]) {
result.put(key.toString(), new String((byte[]) hashMap.get(key)));
} else {
result.put(key.toString(), hashMap.get(key));
}
}
log.info(result + "result");
return result;
}
private Long getBestCategoryId(String sourceCateListStr, Map assocMap) {
Double max = 0.00;
Long categoryId = null;

@ -522,7 +522,6 @@ public class CommonTool {
DecimalFormat decimalFormat = new DecimalFormat(pattern.toString());
String formattedString = decimalFormat.format(number);
return Double.parseDouble(formattedString);
}

Loading…
Cancel
Save