推荐商品

20230922-ljl-fixBug
wangchaoxu 1 year ago
parent fb578dea3b
commit 10995b7cb4

@ -0,0 +1,9 @@
package com.ms.api.dto.move;
import lombok.Data;
@Data
public class GetRecommendProductListRequestDTO {
private Integer pageNo;
private Integer pageSize;
}

@ -0,0 +1,65 @@
package com.ms.api.biz;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ms.api.common.Ret;
import com.ms.api.paas.StorageService;
import com.ms.api.tool.DsJsonRequestTemplate;
import com.ms.api.tool.MoveTool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
@Component
@Slf4j
public class DsCatService {
// @Autowired
// private CategoryService categoryService;
@Autowired
private DsJsonRequestTemplate dsJsonRequestTemplate;
@Autowired
private StorageService storageService;
public JSONArray getDSProductCatTree() {
HashMap<String, Object> params = new HashMap<>();
String res = null;
JSONObject resObj = null;
String tosPath = MoveTool.getAllProductCatTreeOssPath();
JSONArray arrayData = null;
try {
Ret getTosContentRet = storageService.getContent(tosPath);
if (getTosContentRet.getResult().equals("success")) {
arrayData = JSONObject.parseArray(getTosContentRet.getData().get("data").toString());
} else {
try {
res = dsJsonRequestTemplate.execute("/move/search_ds_product_cat_tree", params);
log.info(res);
resObj = JSON.parseObject(res);
if (resObj.get("result").equals("success")) {
JSONObject cateTree = resObj.getJSONObject("cateTree");
arrayData = new JSONArray();
arrayData.add(cateTree.values());
try {
storageService.uploadContent(tosPath, JSONObject.toJSONString(arrayData));
} catch (Exception e) {
log.error("商品类目TOS写入操作过程异常", e);
}
}
} catch (Exception e) {
e.printStackTrace();
log.error("strerror2:", e);
}
}
} catch (Exception e) {
log.error("商品类目TOS读取操作过程异常", e);
}
return arrayData;
}
}

@ -0,0 +1,99 @@
package com.ms.api.spi.move;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
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.DsCatService;
import com.ms.api.common.R;
import com.ms.api.common.Ret;
import com.ms.api.common.SPIBaseService;
import com.ms.api.dto.move.GetRecommendProductListRequestDTO;
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.springframework.beans.factory.annotation.Autowired;
import java.util.*;
@ExtensionService("getRecommendProductList")
@Slf4j
public class GetRecommendProductListService extends SPIBaseService implements ExtensionServiceHandler<GetRecommendProductListRequestDTO, Ret> {
@Autowired
private DsJsonRequestTemplate dsJsonRequestTemplate;
@Autowired
private DsCatService dsCatService;
@Autowired
private CategoryService categoryService;
@Override
public BaseResponse<Ret> handle(BaseRequest<GetRecommendProductListRequestDTO> req) {
initHandle(req);
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++;
}
// 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());
}
}

@ -1,29 +1,20 @@
package com.ms.api.spi.move; package com.ms.api.spi.move;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jinritemai.cloud.base.api.BaseRequest; import com.jinritemai.cloud.base.api.BaseRequest;
import com.jinritemai.cloud.base.api.BaseResponse; import com.jinritemai.cloud.base.api.BaseResponse;
import com.jinritemai.cloud.base.api.ExtensionService; import com.jinritemai.cloud.base.api.ExtensionService;
import com.jinritemai.cloud.base.api.ExtensionServiceHandler; import com.jinritemai.cloud.base.api.ExtensionServiceHandler;
import com.ms.api.biz.DsCatService;
import com.ms.api.common.R; import com.ms.api.common.R;
import com.ms.api.common.Ret; import com.ms.api.common.Ret;
import com.ms.api.common.SPIBaseService; import com.ms.api.common.SPIBaseService;
import com.ms.api.dto.move.SearchDSProductCatTreeRequestDTO; import com.ms.api.dto.move.SearchDSProductCatTreeRequestDTO;
import com.ms.api.paas.StorageService;
import com.ms.api.tool.DsJsonRequestTemplate;
import com.ms.api.common.UniqueKeyMultiValueMap;
import com.ms.api.tool.MoveTool;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.MultiValueMap;
import java.io.*; import java.util.HashMap;
import java.net.URL; import java.util.Map;
import java.sql.Array;
import java.util.*;
/** /**
* *
@ -35,10 +26,7 @@ import java.util.*;
public class SearchDSProductCatTreeService extends SPIBaseService implements ExtensionServiceHandler<SearchDSProductCatTreeRequestDTO, Ret> { public class SearchDSProductCatTreeService extends SPIBaseService implements ExtensionServiceHandler<SearchDSProductCatTreeRequestDTO, Ret> {
@Autowired @Autowired
private DsJsonRequestTemplate dsJsonRequestTemplate; private DsCatService dsCatService;
@Autowired
private StorageService storageService;
@Override @Override
public BaseResponse<Ret> handle(BaseRequest<SearchDSProductCatTreeRequestDTO> req) { public BaseResponse<Ret> handle(BaseRequest<SearchDSProductCatTreeRequestDTO> req) {
@ -48,37 +36,7 @@ public class SearchDSProductCatTreeService extends SPIBaseService implements Ext
// ----逻辑校验---- // ----逻辑校验----
// ----业务处理---- // ----业务处理----
HashMap<String, Object> params = new HashMap<>(); JSONArray arrayData = dsCatService.getDSProductCatTree();
String res = null;
JSONObject resObj = null;
String tosPath = MoveTool.getAllProductCatTreeOssPath();
List<Object> arrayData = null;
try {
Ret getTosContentRet = storageService.getContent(tosPath);
if (getTosContentRet.getResult().equals("success")) {
arrayData = JSONObject.parseArray(getTosContentRet.getData().get("data").toString());
} else {
try {
res = dsJsonRequestTemplate.execute("/move/search_ds_product_cat_tree", params);
log.info(res);
resObj = JSON.parseObject(res);
if (resObj.get("result").equals("success")) {
JSONObject cateTree = resObj.getJSONObject("cateTree");
arrayData = new ArrayList<>(cateTree.values());
try {
storageService.uploadContent(tosPath, JSONObject.toJSONString(arrayData));
} catch (Exception e) {
log.error("商品类目TOS写入操作过程异常", e);
}
}
} catch (Exception e) {
e.printStackTrace();
log.error("strerror2:" + e);
}
}
} catch (Exception e) {
log.error("商品类目TOS读取操作过程异常", e);
}
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
result.put("data", arrayData.toString()); result.put("data", arrayData.toString());

Loading…
Cancel
Save