|
|
|
@ -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>
|
|
|
|
|
* 当客户输入商品连接,或者在货源列表中心选择某个商品铺货的时候,
|
|
|
|
|
* 根据正则匹配到链接中的商品id,把商品id给1688代理
|
|
|
|
|
* 其返回商品数据,渲染给客户查看,最终发起搬家
|
|
|
|
@ -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;
|
|
|
|
|