获取详情匹配抖店类目

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.MoveSystemSourceCategory;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.phprpc.util.AssocArray;
import org.phprpc.util.PHPSerializer;
import org.springframework.beans.factory.annotation.Autowired;
@ -66,24 +67,26 @@ 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());
MoveSystemSourceCategory moveSystemSourceCategory = moveSystemSourceCategoryService.selectBySourceCategoryId(sourceCategoryId.toString());
if (!ObjectUtil.isEmpty(moveSystemSourceCategory)) {
Long moveSystemSourceCategoryId = moveSystemSourceCategory.getMoveSystemSourceCategoryId();
PHPSerializer p = new PHPSerializer();
String content = moveSystemSourceCategory.getMatchCategoryList();
AssocArray assocArray = (AssocArray) p.unserialize(content.getBytes());
Map assocMap = assocArrayToHash(assocArray);
List<String> assocMapKeys = new ArrayList<>(assocMap.keySet());
log.info("assocArrayToHash" + assocMapKeys.get(assocMapKeys.size() - 1));
Long categoryId = Long.valueOf(assocMapKeys.get(assocMapKeys.size() - 1));
List<Long> categoryIds = this.getCategoryIdList(categoryId);
Category category = categoryService.selectByPrimaryKey(Long.valueOf(assocMapKeys.get(assocMapKeys.size() - 1)));
String path = category.getPath();
List<String> pathArr = Arrays.asList(path.split(">"));
product.put("ddCid", categoryIds);
product.put("ddCategoryList", pathArr);
Map<String,Object> assocMap = assocArrayToHash(assocArray);
Long categoryId = this.getBestCategoryId(sourceCateListStr, assocMap);
if (ObjectUtil.isEmpty(categoryId)) {
product.put("ddCid", "");
product.put("ddCategoryList", "");
} else {
List<Long> categoryIds = this.getCategoryIdList(categoryId);
Category category = categoryService.selectByPrimaryKey(categoryId);
String path = category.getPath();
List<String> pathArr = Arrays.asList(path.split(">"));
product.put("ddCid", categoryIds);
product.put("ddCategoryList", pathArr);
}
} else {
product.put("ddCid", "");
product.put("ddCategoryList", "");
@ -131,4 +134,25 @@ public class GetProductInfoByProductId extends SPIBaseService implements Extensi
log.info(result + "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