获取详情匹配抖店类目

20230922-ljl-fixBug
cxxxxxxx详 1 year ago
parent 434c9a0214
commit 8b1a4b585a

@ -17,6 +17,7 @@ import com.ms.api.tool.DsJsonRequestTemplate;
import com.ms.dal.entity.Category; import com.ms.dal.entity.Category;
import com.ms.dal.entity.MoveSystemSourceCategory; import com.ms.dal.entity.MoveSystemSourceCategory;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.phprpc.util.AssocArray; import org.phprpc.util.AssocArray;
import org.phprpc.util.PHPSerializer; import org.phprpc.util.PHPSerializer;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -66,24 +67,26 @@ public class GetProductInfoByProductId extends SPIBaseService implements Extensi
resObj = JSON.parseObject(res); resObj = JSON.parseObject(res);
JSONObject product = resObj.getJSONObject("productInfo"); JSONObject product = resObj.getJSONObject("productInfo");
Long sourceCategoryId = product.getLong("1688cid"); 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()); MoveSystemSourceCategory moveSystemSourceCategory = moveSystemSourceCategoryService.selectBySourceCategoryId(sourceCategoryId.toString());
if (!ObjectUtil.isEmpty(moveSystemSourceCategory)) { if (!ObjectUtil.isEmpty(moveSystemSourceCategory)) {
Long moveSystemSourceCategoryId = moveSystemSourceCategory.getMoveSystemSourceCategoryId();
PHPSerializer p = new PHPSerializer(); PHPSerializer p = new PHPSerializer();
String content = moveSystemSourceCategory.getMatchCategoryList(); String content = moveSystemSourceCategory.getMatchCategoryList();
AssocArray assocArray = (AssocArray) p.unserialize(content.getBytes()); AssocArray assocArray = (AssocArray) p.unserialize(content.getBytes());
Map assocMap = assocArrayToHash(assocArray); Map<String,Object> assocMap = assocArrayToHash(assocArray);
List<String> assocMapKeys = new ArrayList<>(assocMap.keySet()); Long categoryId = this.getBestCategoryId(sourceCateListStr, assocMap);
if (ObjectUtil.isEmpty(categoryId)) {
log.info("assocArrayToHash" + assocMapKeys.get(assocMapKeys.size() - 1)); product.put("ddCid", "");
Long categoryId = Long.valueOf(assocMapKeys.get(assocMapKeys.size() - 1)); product.put("ddCategoryList", "");
} else {
List<Long> categoryIds = this.getCategoryIdList(categoryId); List<Long> categoryIds = this.getCategoryIdList(categoryId);
Category category = categoryService.selectByPrimaryKey(Long.valueOf(assocMapKeys.get(assocMapKeys.size() - 1))); Category category = categoryService.selectByPrimaryKey(categoryId);
String path = category.getPath(); String path = category.getPath();
List<String> pathArr = Arrays.asList(path.split(">")); List<String> pathArr = Arrays.asList(path.split(">"));
product.put("ddCid", categoryIds); product.put("ddCid", categoryIds);
product.put("ddCategoryList", pathArr); product.put("ddCategoryList", pathArr);
}
} else { } else {
product.put("ddCid", ""); product.put("ddCid", "");
product.put("ddCategoryList", ""); product.put("ddCategoryList", "");
@ -131,4 +134,25 @@ public class GetProductInfoByProductId extends SPIBaseService implements Extensi
log.info(result + "result"); log.info(result + "result");
return result; return result;
} }
private Long getBestCategoryId(String sourceCateListStr, Map assocMap) {
Double max = 0.00;
Long categoryId = null;
for (Object key : assocMap.keySet()) {
System.out.println("key:" + key + ", value:" + assocMap.get(key));
Category category = categoryService.selectByPrimaryKey(Long.valueOf(key.toString()));
if (!ObjectUtil.isEmpty(category)) {
Double score = this.getJaroWinklerDistance(sourceCateListStr, category.getPath());
if (score > max) {
max = score;
categoryId = Long.valueOf(key.toString());
}
}
}
return categoryId;
}
private double getJaroWinklerDistance(String first, String second) {
return StringUtils.getJaroWinklerDistance(first, second);
}
} }

Loading…
Cancel
Save