|
@@ -19,8 +19,9 @@ import com.cdf.httpClient.response.cdf.CdfProductListResponse;
|
|
|
import com.cdf.httpClient.response.cdf.CdfProductVo;
|
|
|
import com.cdf.service.IFdkkUserService;
|
|
|
import com.cdf.service.IHotRelationService;
|
|
|
+import com.cdf.util.FileUtils;
|
|
|
import com.cdf.util.JwtUtil;
|
|
|
-import com.fdkankan.fyun.oss.UploadToOssUtil;
|
|
|
+import com.cdf.util.UploadToOssUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -30,9 +31,8 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.UUID;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class FdkkSceneEditService {
|
|
@@ -42,6 +42,10 @@ public class FdkkSceneEditService {
|
|
|
private String bucket;
|
|
|
@Value("${fdkk.hot-path}")
|
|
|
private String hotPath;
|
|
|
+ @Value("${fdkk.hot-cdf-path}")
|
|
|
+ private String hotCdfPath;
|
|
|
+ @Value("${fdkk.hot-local-path}")
|
|
|
+ private String hotLocalPath;
|
|
|
@Resource
|
|
|
private FdkkClient fdkkClient;
|
|
|
@Resource
|
|
@@ -70,6 +74,9 @@ public class FdkkSceneEditService {
|
|
|
List<String> relationIds = fdkkHotData.getRelationIds();
|
|
|
String sid = fdkkHotData.getSid();
|
|
|
Integer type = fdkkHotData.getHotType();
|
|
|
+ if(type == null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
HotRelation hotRelation = new HotRelation();
|
|
|
hotRelation.setHotId(sid);
|
|
|
hotRelation.setHotType(type);
|
|
@@ -77,7 +84,7 @@ public class FdkkSceneEditService {
|
|
|
hotRelation.setRelationIds(JSONArray.toJSONString(relationIds));
|
|
|
}
|
|
|
hotRelation.setNum(fdkkHotRequest.getNum());
|
|
|
- hotRelation.setContent(fdkkHotData.getContent());
|
|
|
+ hotRelation.setContent(fdkkHotData.getHotContent());
|
|
|
hotRelationService.saveOrUpdate(hotRelation);
|
|
|
}
|
|
|
return fdkkResponse;
|
|
@@ -103,7 +110,7 @@ public class FdkkSceneEditService {
|
|
|
return jsonObject;
|
|
|
}
|
|
|
|
|
|
- public JSONArray getHotJson(String num, String token) {
|
|
|
+ public JSONArray getHotJson(String num) {
|
|
|
String data = uploadToOssUtil.getObjectContent(bucket, String.format(hotPath, num));
|
|
|
if(StringUtils.isBlank(data)){
|
|
|
throw new BusinessException(ResultCode.NOT_RECORD);
|
|
@@ -112,6 +119,14 @@ public class FdkkSceneEditService {
|
|
|
return getProductByJsonObj(tags);
|
|
|
}
|
|
|
|
|
|
+ public JSONArray getCdfHotJson(String num) {
|
|
|
+ String data = uploadToOssUtil.getObjectContent(bucket, String.format(hotCdfPath, num));
|
|
|
+ if(StringUtils.isBlank(data)){
|
|
|
+ throw new BusinessException(ResultCode.NOT_RECORD);
|
|
|
+ }
|
|
|
+ return JSONObject.parseArray(data);
|
|
|
+ }
|
|
|
+
|
|
|
private JSONArray getProductByJsonObj(JSONArray tags){
|
|
|
for (Object obj : tags) {
|
|
|
JSONObject tag = (JSONObject) obj;
|
|
@@ -121,9 +136,12 @@ public class FdkkSceneEditService {
|
|
|
continue;
|
|
|
}
|
|
|
tag.put("hotType",hotRelation.getHotType());
|
|
|
- //0商品,1优惠劵,2第三方跳转,3瀑布流
|
|
|
+ //0商品,1优惠劵,2第三方跳转,3瀑布流 ,场景关联
|
|
|
+ if(hotRelation.getHotType() == null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
if(hotRelation.getHotType() == 1 || hotRelation.getHotType() == 2){
|
|
|
- tag.put("hotJumpUrl", hotRelation.getContent());
|
|
|
+ tag.put("hotContent", hotRelation.getContent());
|
|
|
continue;
|
|
|
}
|
|
|
String relationIds = hotRelation.getRelationIds();
|
|
@@ -131,41 +149,43 @@ public class FdkkSceneEditService {
|
|
|
continue;
|
|
|
}
|
|
|
JSONArray jsonArray = JSONObject.parseArray(relationIds);
|
|
|
- List<CdfProductVo> products = new ArrayList<>();
|
|
|
+ List<CdfProduct> products = new ArrayList<>();
|
|
|
for (Object o : jsonArray) {
|
|
|
String productId = (String) o;
|
|
|
CdfProductListRequest param = new CdfProductListRequest();
|
|
|
param.setKeyword(productId);
|
|
|
+ CdfProductListResponse productList = cdfClient.getProductList(param);
|
|
|
+ if(productList == null || productList.getSearchResult()==null || productList.getSearchResult().getType()!=0){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
CdfProductVo cdfProductVo = cdfClient.getProductById(productId);
|
|
|
if(cdfProductVo == null || cdfProductVo.getState()==null || cdfProductVo.getState()!=0){
|
|
|
continue;
|
|
|
}
|
|
|
- products.add(cdfProductVo);
|
|
|
+ List<CdfProduct> list = productList.getList();
|
|
|
+ for (CdfProduct cdfProduct : list) {
|
|
|
+ cdfProduct.setSkus(cdfProductVo.getSkus());
|
|
|
+ }
|
|
|
+ products.addAll(list);
|
|
|
}
|
|
|
if(products.size() >0){
|
|
|
tag.put("products",products);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
return tags;
|
|
|
}
|
|
|
|
|
|
|
|
|
- public void publicScene(FdkkHotRequest fdkkHotRequest, String token) {
|
|
|
- FdkkResponse fdkkResponse = fdkkClient.scenePublicScene(fdkkHotRequest.getNum(),getFdkkToken(token));
|
|
|
+ public void publicScene(FdkkHotRequest fdkkHotRequest, String token) throws Exception {
|
|
|
+ FdkkResponse fdkkResponse = fdkkClient.scenePublicScene(new SceneRequest(fdkkHotRequest.getNum()),getFdkkToken(token));
|
|
|
if(fdkkResponse.getCode() !=0){
|
|
|
throw new BusinessException(fdkkResponse.getCode(),fdkkResponse.getMsg());
|
|
|
}
|
|
|
- String content = uploadToOssUtil.getObjectContent(bucket, String.format(hotPath, fdkkHotRequest.getNum()));
|
|
|
- JSONArray jsonArray = JSONObject.parseArray(content);
|
|
|
- if(jsonArray == null){
|
|
|
- return ;
|
|
|
- }
|
|
|
- for (Object obj : jsonArray) {
|
|
|
- JSONObject jsonObject= (JSONObject) obj;
|
|
|
- String sid = jsonObject.getString("sid");
|
|
|
- HotRelation hotRelation = hotRelationService.getById(sid);
|
|
|
- jsonObject.put("hotRelation",hotRelation);
|
|
|
- }
|
|
|
+ JSONArray hotJson = getHotJson(fdkkHotRequest.getNum());
|
|
|
+ String path = String.format(hotLocalPath, fdkkHotRequest.getNum());
|
|
|
+ FileUtils.writeFile(path, hotJson.toJSONString());
|
|
|
+ uploadToOssUtil.upload(path,String.format(hotCdfPath, fdkkHotRequest.getNum()));
|
|
|
}
|
|
|
|
|
|
public FdkkResponse uploadFiles(FdkkUploadRequest fdkkUploadRequest, MultipartFile files, String token) throws IOException {
|