|
|
|
@ -17,6 +17,7 @@ import com.ms.api.service.CategoryService;
|
|
|
|
|
import com.ms.api.tool.DsJsonRequestTemplate;
|
|
|
|
|
import com.ms.dal.entity.Category;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
@ -40,60 +41,76 @@ public class GetRecommendProductListService extends SPIBaseService implements Ex
|
|
|
|
|
getAuthCode();
|
|
|
|
|
|
|
|
|
|
GetRecommendProductListRequestDTO requestDTO = req.getData();
|
|
|
|
|
|
|
|
|
|
// 1688类目树
|
|
|
|
|
JSONArray arrayData = dsCatService.getDSProductCatTree();
|
|
|
|
|
|
|
|
|
|
// 获取商家抖店类目列表
|
|
|
|
|
List<Category> categoryList = categoryService.getAllLeafProductCatListFromTos(shopId.intValue(), false);
|
|
|
|
|
Collections.shuffle(categoryList);
|
|
|
|
|
|
|
|
|
|
int productCnt = 0;
|
|
|
|
|
int categoryIndex = 0;
|
|
|
|
|
while (productCnt < requestDTO.getPageSize()) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
categoryIndex++;
|
|
|
|
|
JSONArray productArray = new JSONArray();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// 1688类目树
|
|
|
|
|
JSONArray dsCateLeafArray = dsCatService.getDSProductCatTreeLeafArray();
|
|
|
|
|
|
|
|
|
|
// 获取商家抖店类目列表
|
|
|
|
|
List<Category> categoryList = categoryService.getAllLeafProductCatListFromTos(shopId.intValue(), false);
|
|
|
|
|
Collections.shuffle(categoryList);
|
|
|
|
|
|
|
|
|
|
if (ObjectUtil.isNotEmpty(dsCateLeafArray) && ObjectUtil.isNotEmpty(dsCateLeafArray)) {
|
|
|
|
|
final int eachCateProductChooseCount = 3;
|
|
|
|
|
int productCnt = 0;
|
|
|
|
|
int categoryIndex = 0;
|
|
|
|
|
while (productCnt < requestDTO.getPageSize() && categoryIndex < categoryList.size()) {
|
|
|
|
|
Category category = categoryList.get(categoryIndex);
|
|
|
|
|
String categoryName = category.getCategoryName();
|
|
|
|
|
|
|
|
|
|
double maxPercent = 0;
|
|
|
|
|
String maxPercentName = "";
|
|
|
|
|
String maxPercentCid = "";
|
|
|
|
|
for (int i = 0; i < dsCateLeafArray.size(); ++i) {
|
|
|
|
|
JSONObject dsCateLeaf = dsCateLeafArray.getJSONObject(i);
|
|
|
|
|
String dsCateName = dsCateLeaf.getString("name");
|
|
|
|
|
String dsCateCid = dsCateLeaf.getString("cid");
|
|
|
|
|
double percent = StringUtils.getJaroWinklerDistance(categoryName, dsCateName);
|
|
|
|
|
maxPercent = Math.max(maxPercent, percent);
|
|
|
|
|
maxPercentName = dsCateName;
|
|
|
|
|
maxPercentCid = dsCateCid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 匹配到的最终类目,每个查询N个
|
|
|
|
|
HashMap<String, Object> params = new HashMap<>();
|
|
|
|
|
// params.put("keyword",fields.getKeyword());
|
|
|
|
|
// params.put("topCid",fields.getTopCid());
|
|
|
|
|
params.put("cid", maxPercentCid);
|
|
|
|
|
params.put("sort", "saleCntDesc");
|
|
|
|
|
// params.put("ruleIds", fields.getRuleIds());
|
|
|
|
|
params.put("isHideMoved", 1);
|
|
|
|
|
params.put("pageNo", 1);
|
|
|
|
|
params.put("pageSize", eachCateProductChooseCount);
|
|
|
|
|
params.put("authCode", authCode);
|
|
|
|
|
log.info(params.toString());
|
|
|
|
|
JSONObject resObj = null;
|
|
|
|
|
String res = null;
|
|
|
|
|
List<Object> products = new LinkedList<>();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
res = dsJsonRequestTemplate.execute("/move/search_choiceness_source_item", params);
|
|
|
|
|
resObj = JSON.parseObject(res);
|
|
|
|
|
if (resObj.get("result").equals("success")) {
|
|
|
|
|
JSONArray sourceItems = resObj.getJSONArray("sourceItems");
|
|
|
|
|
productArray.addAll(sourceItems);
|
|
|
|
|
productCnt += sourceItems.size();
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("/move/search_choiceness_source_item request error", e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
categoryIndex++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Collections.shuffle(productArray);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("getRecommendProductList error", e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// HashMap<String, Object> params = new HashMap<>();
|
|
|
|
|
//// params.put("keyword",fields.getKeyword());
|
|
|
|
|
//// params.put("topCid",fields.getTopCid());
|
|
|
|
|
// params.put("cid",fields.getCid());
|
|
|
|
|
// params.put("sort", "saleCntDesc");
|
|
|
|
|
//// params.put("ruleIds", fields.getRuleIds());
|
|
|
|
|
// params.put("isHideMoved", 1);
|
|
|
|
|
// params.put("pageNo",requestDTO.getPageNo());
|
|
|
|
|
// params.put("pageSize",requestDTO.getPageSize());
|
|
|
|
|
// params.put("authCode",authCode);
|
|
|
|
|
// log.info(params.toString());
|
|
|
|
|
// JSONObject resObj = null;
|
|
|
|
|
// String res = null;
|
|
|
|
|
// List<Object> products = new LinkedList<>();
|
|
|
|
|
//
|
|
|
|
|
// try {
|
|
|
|
|
// res = dsJsonRequestTemplate.execute("/move/search_choiceness_source_item", params);
|
|
|
|
|
// resObj = JSON.parseObject(res);
|
|
|
|
|
// if (resObj.get("result").equals("success")) {
|
|
|
|
|
// log.info("resObj::"+resObj.toString());
|
|
|
|
|
// Map result = new HashMap();
|
|
|
|
|
// List<Object> sourceItems = new ArrayList<>();
|
|
|
|
|
// JSONArray sourceItemjson = resObj.getJSONArray("sourceItems");
|
|
|
|
|
// if (!ObjectUtil.isEmpty(sourceItemjson)) {
|
|
|
|
|
// sourceItems = sourceItemjson;
|
|
|
|
|
// }
|
|
|
|
|
// result.put("result", resObj.getString("result"));
|
|
|
|
|
// result.put("sourceItems", sourceItems);
|
|
|
|
|
// result.put("total", resObj.getInteger("total"));
|
|
|
|
|
// res = JSON.toJSONString(result);
|
|
|
|
|
// }
|
|
|
|
|
// } catch (Exception e) {
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
// log.error(e.getMessage());
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return R.ok(Ret.success());
|
|
|
|
|
Map retMap = new HashMap();
|
|
|
|
|
retMap.put("products", productArray);
|
|
|
|
|
return R.ok(Ret.success(retMap));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|