Merge branch 'master' of codeup.aliyun.com:64d9c5feeceb191898f636d7/honor-dd-light-ds-java

20230922-ljl-fixBug
ljl 1 year ago
commit ebaaf7c9cc

@ -70,6 +70,7 @@ public class DsCatService {
JSONArray treeData = getDSProductCatTree(); JSONArray treeData = getDSProductCatTree();
Queue<JSONObject> queue = new ArrayDeque<>(); Queue<JSONObject> queue = new ArrayDeque<>();
// treeData = treeData.getJSONArray(0); // 结构兼容
for (int i = 0; i < treeData.size(); i++) { for (int i = 0; i < treeData.size(); i++) {
JSONObject rootObj = treeData.getJSONObject(i); JSONObject rootObj = treeData.getJSONObject(i);
queue.add(rootObj); queue.add(rootObj);
@ -97,5 +98,56 @@ public class DsCatService {
return leafArray; return leafArray;
} }
/**
*
* @return
*/
public JSONArray getDSProductCatTreeNotLeafArray() {
JSONArray nodeArray = new JSONArray();
JSONArray treeData = getDSProductCatTree();
Queue<JSONObject> queue = new ArrayDeque<>();
// treeData = treeData.getJSONArray(0); // 结构兼容
for (int i = 0; i < treeData.size(); i++) {
JSONObject rootObj = treeData.getJSONObject(i);
queue.add(rootObj);
}
while (!queue.isEmpty()) {
JSONObject frontObj = queue.poll();
if (frontObj == null) {
break;
}
JSONObject childsObj = frontObj.getJSONObject("childs");
if (childsObj != null) {
JSONObject node = new JSONObject();
node.put("name", frontObj.getString("name"));
node.put("cid", frontObj.getString("cid"));
nodeArray.add(node);
for (Object child : childsObj.values()) {
JSONObject jsonObject = (JSONObject) child;
queue.add(jsonObject);
}
}
}
return nodeArray;
}
/**
*
* @return
*/
public JSONArray getDSProductTopCatArray() {
JSONArray nodeArray = new JSONArray();
JSONArray treeData = getDSProductCatTree();
// treeData = treeData.getJSONArray(0); // 结构兼容
for (int i = 0; i < treeData.size(); i++) {
JSONObject rootObj = treeData.getJSONObject(i);
nodeArray.add(rootObj);
}
return nodeArray;
}
} }

@ -41,11 +41,16 @@ public class GetRecommendProductListService extends SPIBaseService implements Ex
getAuthCode(); getAuthCode();
GetRecommendProductListRequestDTO requestDTO = req.getData(); GetRecommendProductListRequestDTO requestDTO = req.getData();
Integer pageSize = requestDTO.getPageSize();
if (pageSize == null) {
pageSize = 0;
}
JSONArray productArray = new JSONArray(); JSONArray productArray = new JSONArray();
try { try {
// 1688类目树 // 1688类目列表
JSONArray dsCateLeafArray = dsCatService.getDSProductCatTreeLeafArray(); JSONArray dsCateLeafArray = dsCatService.getDSProductTopCatArray();
// 获取商家抖店类目列表 // 获取商家抖店类目列表
List<Category> categoryList = categoryService.getAllLeafProductCatListFromTos(shopId.intValue(), false); List<Category> categoryList = categoryService.getAllLeafProductCatListFromTos(shopId.intValue(), false);
@ -53,12 +58,12 @@ public class GetRecommendProductListService extends SPIBaseService implements Ex
if (ObjectUtil.isNotEmpty(dsCateLeafArray) && ObjectUtil.isNotEmpty(dsCateLeafArray)) { if (ObjectUtil.isNotEmpty(dsCateLeafArray) && ObjectUtil.isNotEmpty(dsCateLeafArray)) {
final int eachCateProductChooseCount = 3; final int eachCateProductChooseCount = 3;
int productCnt = 0;
int categoryIndex = 0; int categoryIndex = 0;
while (productCnt < requestDTO.getPageSize() && categoryIndex < categoryList.size()) { HashSet<String> sourceItemIdSet = new HashSet<>();
while (productArray.size() < pageSize && categoryIndex < categoryList.size()) {
Category category = categoryList.get(categoryIndex); Category category = categoryList.get(categoryIndex);
String categoryName = category.getCategoryName(); String categoryName = category.getCategoryName();
// categoryName="女装";
double maxPercent = 0; double maxPercent = 0;
String maxPercentName = ""; String maxPercentName = "";
String maxPercentCid = ""; String maxPercentCid = "";
@ -67,16 +72,19 @@ public class GetRecommendProductListService extends SPIBaseService implements Ex
String dsCateName = dsCateLeaf.getString("name"); String dsCateName = dsCateLeaf.getString("name");
String dsCateCid = dsCateLeaf.getString("cid"); String dsCateCid = dsCateLeaf.getString("cid");
double percent = StringUtils.getJaroWinklerDistance(categoryName, dsCateName); double percent = StringUtils.getJaroWinklerDistance(categoryName, dsCateName);
maxPercent = Math.max(maxPercent, percent); if (percent > maxPercent) {
maxPercent = percent;
maxPercentName = dsCateName; maxPercentName = dsCateName;
maxPercentCid = dsCateCid; maxPercentCid = dsCateCid;
} }
log.info(dsCateName + " " + percent);
}
// 匹配到的最终类目每个查询N个 // 匹配到的最终类目每个查询N个
HashMap<String, Object> params = new HashMap<>(); HashMap<String, Object> params = new HashMap<>();
// params.put("keyword",fields.getKeyword()); // params.put("keyword",fields.getKeyword());
// params.put("topCid",fields.getTopCid()); params.put("topCid", maxPercentCid);
params.put("cid", maxPercentCid); // params.put("cid", maxPercentCid);
params.put("sort", "saleCntDesc"); params.put("sort", "saleCntDesc");
// params.put("ruleIds", fields.getRuleIds()); // params.put("ruleIds", fields.getRuleIds());
params.put("isHideMoved", 1); params.put("isHideMoved", 1);
@ -86,15 +94,21 @@ public class GetRecommendProductListService extends SPIBaseService implements Ex
log.info(params.toString()); log.info(params.toString());
JSONObject resObj = null; JSONObject resObj = null;
String res = null; String res = null;
List<Object> products = new LinkedList<>();
try { try {
res = dsJsonRequestTemplate.execute("/move/search_choiceness_source_item", params); res = dsJsonRequestTemplate.execute("/move/search_choiceness_source_item", params);
resObj = JSON.parseObject(res); resObj = JSON.parseObject(res);
if (resObj.get("result").equals("success")) { if (resObj.get("result").equals("success")) {
JSONArray sourceItems = resObj.getJSONArray("sourceItems"); JSONArray sourceItems = resObj.getJSONArray("sourceItems");
productArray.addAll(sourceItems); if (ObjectUtil.isNotEmpty(sourceItems)) {
productCnt += sourceItems.size(); for (int i = 0; i < sourceItems.size(); ++i) {
JSONObject sourceItem = sourceItems.getJSONObject(i);
String sourceItemId = sourceItem.getString("sourceItemId");
if (!sourceItemIdSet.contains(sourceItemId)) {
productArray.add(sourceItem);
sourceItemIdSet.add(sourceItemId);
}
}
}
} }
} catch (Exception e) { } catch (Exception e) {
log.error("/move/search_choiceness_source_item request error", e); log.error("/move/search_choiceness_source_item request error", e);
@ -110,7 +124,7 @@ public class GetRecommendProductListService extends SPIBaseService implements Ex
} }
Map retMap = new HashMap(); Map retMap = new HashMap();
retMap.put("products", productArray); retMap.put("products", productArray.subList(0, Math.min(pageSize, productArray.size())));
return R.ok(Ret.success(retMap)); return R.ok(Ret.success(retMap));
} }
} }

Loading…
Cancel
Save