|
@@ -19,6 +19,7 @@ import com.cdf.service.IHotRelationService;
|
|
import com.cdf.util.FileUtils;
|
|
import com.cdf.util.FileUtils;
|
|
import com.cdf.util.JwtUtil;
|
|
import com.cdf.util.JwtUtil;
|
|
import com.cdf.util.UploadToOssUtil;
|
|
import com.cdf.util.UploadToOssUtil;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -32,6 +33,7 @@ import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
|
|
+@Slf4j
|
|
public class FdkkSceneEditService {
|
|
public class FdkkSceneEditService {
|
|
@Resource
|
|
@Resource
|
|
private UploadToOssUtil uploadToOssUtil;
|
|
private UploadToOssUtil uploadToOssUtil;
|
|
@@ -51,18 +53,12 @@ public class FdkkSceneEditService {
|
|
private IFdkkUserService fdkkUserService;
|
|
private IFdkkUserService fdkkUserService;
|
|
@Autowired
|
|
@Autowired
|
|
private IHotRelationService hotRelationService;
|
|
private IHotRelationService hotRelationService;
|
|
|
|
+ @Autowired
|
|
|
|
+ FdkkSceneService fdkkSceneService;
|
|
|
|
|
|
- private String getFdkkToken(String token){
|
|
|
|
- Integer userId = JwtUtil.getId(token);
|
|
|
|
- FdkkUser fdkkUser = fdkkUserService.getById(userId);
|
|
|
|
- if(fdkkUser == null || StringUtils.isBlank(fdkkUser.getToken())){
|
|
|
|
- throw new BusinessException(ResultCode.NOT_FDKK_TOKEN);
|
|
|
|
- }
|
|
|
|
- return fdkkUser.getToken();
|
|
|
|
- }
|
|
|
|
|
|
|
|
public FdkkResponse saveTag(FdkkHotRequest fdkkHotRequest, String token) {
|
|
public FdkkResponse saveTag(FdkkHotRequest fdkkHotRequest, String token) {
|
|
- FdkkResponse fdkkResponse = fdkkClient.hotSave(fdkkHotRequest, getFdkkToken(token));
|
|
|
|
|
|
+ FdkkResponse fdkkResponse = fdkkClient.hotSave(fdkkHotRequest,fdkkSceneService.getFdkkToken(token));
|
|
if(fdkkResponse.getCode() != 0){
|
|
if(fdkkResponse.getCode() != 0){
|
|
throw new BusinessException(fdkkResponse.getCode(),fdkkResponse.getMsg());
|
|
throw new BusinessException(fdkkResponse.getCode(),fdkkResponse.getMsg());
|
|
}
|
|
}
|
|
@@ -88,7 +84,7 @@ public class FdkkSceneEditService {
|
|
}
|
|
}
|
|
|
|
|
|
public void deleteTag(FdkkHotRequest fdkkHotRequest, String token) {
|
|
public void deleteTag(FdkkHotRequest fdkkHotRequest, String token) {
|
|
- FdkkResponse fdkkResponse = fdkkClient.hotDelete(fdkkHotRequest,getFdkkToken(token));
|
|
|
|
|
|
+ FdkkResponse fdkkResponse = fdkkClient.hotDelete(fdkkHotRequest,fdkkSceneService.getFdkkToken(token));
|
|
if(fdkkResponse.getCode() !=0){
|
|
if(fdkkResponse.getCode() !=0){
|
|
throw new BusinessException(fdkkResponse.getCode(),fdkkResponse.getMsg());
|
|
throw new BusinessException(fdkkResponse.getCode(),fdkkResponse.getMsg());
|
|
}
|
|
}
|
|
@@ -97,7 +93,7 @@ public class FdkkSceneEditService {
|
|
|
|
|
|
|
|
|
|
public JSONObject getTagList(String num, String token) {
|
|
public JSONObject getTagList(String num, String token) {
|
|
- FdkkResponse fdkkResponse = fdkkClient.hotList(new SceneRequest(num), getFdkkToken(token));
|
|
|
|
|
|
+ FdkkResponse fdkkResponse = fdkkClient.hotList(new SceneRequest(num), fdkkSceneService.getFdkkToken(token));
|
|
if(fdkkResponse.getCode() !=0){
|
|
if(fdkkResponse.getCode() !=0){
|
|
throw new BusinessException(fdkkResponse.getCode(),fdkkResponse.getMsg());
|
|
throw new BusinessException(fdkkResponse.getCode(),fdkkResponse.getMsg());
|
|
}
|
|
}
|
|
@@ -124,14 +120,57 @@ public class FdkkSceneEditService {
|
|
return JSONObject.parseArray(data);
|
|
return JSONObject.parseArray(data);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ public void publicScene(FdkkHotRequest fdkkHotRequest, String token) throws Exception {
|
|
|
|
+ FdkkResponse fdkkResponse = fdkkClient.scenePublicScene(new SceneRequest(fdkkHotRequest.getNum()),fdkkSceneService.getFdkkToken(token));
|
|
|
|
+ if(fdkkResponse.getCode() !=0){
|
|
|
|
+ throw new BusinessException(fdkkResponse.getCode(),fdkkResponse.getMsg());
|
|
|
|
+ }
|
|
|
|
+ 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 {
|
|
|
|
+ String path = null;
|
|
|
|
+ if(files !=null && files.getSize() >0){
|
|
|
|
+ String fileName = files.getOriginalFilename();
|
|
|
|
+ assert fileName != null;
|
|
|
|
+ String prefix = fileName.substring(fileName.lastIndexOf("."));
|
|
|
|
+ File newFile = File.createTempFile(UUID.randomUUID().toString() ,prefix);
|
|
|
|
+ files.transferTo(newFile);
|
|
|
|
+ path = newFile.getPath();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ FdkkResponse fdkkResponse = fdkkClient.uploadFiles(fdkkUploadRequest,path,fdkkSceneService.getFdkkToken(token));
|
|
|
|
+ if(fdkkResponse.getCode() !=0){
|
|
|
|
+ throw new BusinessException(fdkkResponse.getCode(),fdkkResponse.getMsg());
|
|
|
|
+ }
|
|
|
|
+ return fdkkResponse;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
private JSONArray getProductByJsonObj(JSONArray tags){
|
|
private JSONArray getProductByJsonObj(JSONArray tags){
|
|
HashMap<String,JSONArray> resultMap = new HashMap<>(); //sid, productId array
|
|
HashMap<String,JSONArray> resultMap = new HashMap<>(); //sid, productId array
|
|
HashMap<Object,CdfProduct> productMap = new HashMap<>(); //productId cdf
|
|
HashMap<Object,CdfProduct> productMap = new HashMap<>(); //productId cdf
|
|
JSONArray requestArray = new JSONArray(); //productId all array
|
|
JSONArray requestArray = new JSONArray(); //productId all array
|
|
|
|
+
|
|
|
|
+ List<String> sidsList = new ArrayList<>();
|
|
|
|
+ HashMap<String,HotRelation> hotRelationMap = new HashMap<>();
|
|
for (Object obj : tags) {
|
|
for (Object obj : tags) {
|
|
JSONObject tag = (JSONObject) obj;
|
|
JSONObject tag = (JSONObject) obj;
|
|
String sid = tag.getString("sid");
|
|
String sid = tag.getString("sid");
|
|
- HotRelation hotRelation = hotRelationService.getById(sid);
|
|
|
|
|
|
+ sidsList.add(sid);
|
|
|
|
+ }
|
|
|
|
+ List<HotRelation> hotRelations = hotRelationService.listByIds(sidsList); //批量查询热点
|
|
|
|
+ for (HotRelation hotRelation : hotRelations) {
|
|
|
|
+ hotRelationMap.put(hotRelation.getHotId(),hotRelation);
|
|
|
|
+ }
|
|
|
|
+ for (Object obj : tags) {
|
|
|
|
+ JSONObject tag = (JSONObject) obj;
|
|
|
|
+ String sid = tag.getString("sid");
|
|
|
|
+ HotRelation hotRelation = hotRelationMap.get(sid);
|
|
if(hotRelation == null){
|
|
if(hotRelation == null){
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
@@ -182,33 +221,4 @@ public class FdkkSceneEditService {
|
|
}
|
|
}
|
|
return tags;
|
|
return tags;
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
- 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());
|
|
|
|
- }
|
|
|
|
- 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 {
|
|
|
|
- String path = null;
|
|
|
|
- if(files !=null && files.getSize() >0){
|
|
|
|
- String fileName = files.getOriginalFilename();
|
|
|
|
- String prefix = fileName.substring(fileName.lastIndexOf("."));
|
|
|
|
- File newFile = File.createTempFile(UUID.randomUUID().toString() ,prefix);
|
|
|
|
- files.transferTo(newFile);
|
|
|
|
- path = newFile.getPath();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- FdkkResponse fdkkResponse = fdkkClient.uploadFiles(fdkkUploadRequest,path,getFdkkToken(token));
|
|
|
|
- if(fdkkResponse.getCode() !=0){
|
|
|
|
- throw new BusinessException(fdkkResponse.getCode(),fdkkResponse.getMsg());
|
|
|
|
- }
|
|
|
|
- return fdkkResponse;
|
|
|
|
- }
|
|
|
|
}
|
|
}
|