|
@@ -0,0 +1,153 @@
|
|
|
+package com.cdf.controller;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.cdf.aop.SysLog;
|
|
|
+import com.cdf.common.ResultCode;
|
|
|
+import com.cdf.common.ResultData;
|
|
|
+import com.cdf.entity.FdkkUser;
|
|
|
+import com.cdf.entity.HotRelation;
|
|
|
+import com.cdf.exception.BusinessException;
|
|
|
+import com.cdf.httpClient.client.FdkkClient;
|
|
|
+import com.cdf.httpClient.request.FdkkHotData;
|
|
|
+import com.cdf.httpClient.request.FdkkHotRequest;
|
|
|
+import com.cdf.httpClient.request.FdkkUploadRequest;
|
|
|
+import com.cdf.httpClient.response.FdkkResponse;
|
|
|
+import com.cdf.service.IFdkkUserService;
|
|
|
+import com.cdf.service.IHotRelationService;
|
|
|
+import com.cdf.util.JwtUtil;
|
|
|
+import com.dtflys.forest.annotation.JSONBody;
|
|
|
+import com.fdkankan.fyun.oss.UploadToOssUtil;
|
|
|
+import com.google.gson.JsonObject;
|
|
|
+import jdk.nashorn.internal.parser.Token;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+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.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.UUID;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/service/scene/edit")
|
|
|
+public class FdkkSceneEditController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private UploadToOssUtil uploadToOssUtil;
|
|
|
+ @Value("${oss.bucket}")
|
|
|
+ private String bucket;
|
|
|
+ @Value("${fdkk.hot-path}")
|
|
|
+ private String hotPath;
|
|
|
+ @Resource
|
|
|
+ private FdkkClient fdkkClient;
|
|
|
+ @Autowired
|
|
|
+ private IFdkkUserService fdkkUserService;
|
|
|
+ @Autowired
|
|
|
+ private IHotRelationService hotRelationService;
|
|
|
+
|
|
|
+ @PostMapping("/tag/save")
|
|
|
+ @SysLog("/热点新增编辑")
|
|
|
+ public FdkkResponse save(@RequestBody FdkkHotRequest fdkkHotRequest, @RequestHeader String token){
|
|
|
+ Integer userId = JwtUtil.getId(token);
|
|
|
+ FdkkUser fdkkUser = fdkkUserService.getById(userId);
|
|
|
+ FdkkResponse fdkkResponse = fdkkClient.hotSave(fdkkHotRequest, fdkkUser.getToken());
|
|
|
+ if(fdkkResponse.getCode() != 0){
|
|
|
+ throw new BusinessException(fdkkResponse.getCode(),fdkkResponse.getMsg());
|
|
|
+ }
|
|
|
+ List<FdkkHotData> hotDataList = fdkkHotRequest.getHotDataList();
|
|
|
+ for (FdkkHotData fdkkHotData : hotDataList) {
|
|
|
+ List<Integer> relationIds = fdkkHotData.getRelationIds();
|
|
|
+ String sid = fdkkHotData.getSid();
|
|
|
+ Integer type = fdkkHotData.getHotType();
|
|
|
+ HotRelation hotRelation = new HotRelation();
|
|
|
+ hotRelation.setHotId(sid);
|
|
|
+ hotRelation.setHotType(type);
|
|
|
+ hotRelation.setRelationIds(JSONArray.toJSONString(relationIds));
|
|
|
+ hotRelation.setNum(fdkkHotRequest.getNum());
|
|
|
+ hotRelationService.saveOrUpdate(hotRelation);
|
|
|
+ }
|
|
|
+ return fdkkResponse;
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/tag/delete")
|
|
|
+ @SysLog("/热点删除")
|
|
|
+ public ResultData delete(@RequestBody FdkkHotRequest fdkkHotRequest, @RequestHeader String token){
|
|
|
+ Integer userId = JwtUtil.getId(token);
|
|
|
+ FdkkUser fdkkUser = fdkkUserService.getById(userId);
|
|
|
+ FdkkResponse fdkkResponse = fdkkClient.hotDelete(fdkkHotRequest, fdkkUser.getToken());
|
|
|
+ if(fdkkResponse.getCode() !=0){
|
|
|
+ throw new BusinessException(fdkkResponse.getCode(),fdkkResponse.getMsg());
|
|
|
+ }
|
|
|
+ hotRelationService.removeByIds(fdkkHotRequest.getSidList());
|
|
|
+ return ResultData.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @PostMapping("/tag/list")
|
|
|
+ public ResultData list (@RequestParam(required = false) String num,@RequestHeader String token){
|
|
|
+ Integer userId = JwtUtil.getId(token);
|
|
|
+ FdkkUser fdkkUser = fdkkUserService.getById(userId);
|
|
|
+ FdkkResponse fdkkResponse = fdkkClient.hotList(num, fdkkUser.getToken());
|
|
|
+ if(fdkkResponse.getCode() !=0){
|
|
|
+ throw new BusinessException(fdkkResponse.getCode(),fdkkResponse.getMsg());
|
|
|
+ }
|
|
|
+ JSONArray tags = JSONObject.parseObject(JSONObject.toJSONString(fdkkResponse.getData())).getJSONArray("tags");
|
|
|
+ for (Object obj : tags) {
|
|
|
+ JSONObject tag = (JSONObject) obj;
|
|
|
+ String sid = tag.getString("sid");
|
|
|
+ HotRelation hotRelation = hotRelationService.getById(sid);
|
|
|
+ String relationIds = hotRelation.getRelationIds();
|
|
|
+ }
|
|
|
+
|
|
|
+ return ResultData.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("publicScene")
|
|
|
+ public ResultData scenePublicScene(@RequestBody FdkkHotRequest fdkkHotRequest ,@RequestHeader String token){
|
|
|
+ Integer userId = JwtUtil.getId(token);
|
|
|
+ FdkkUser fdkkUser = fdkkUserService.getById(userId);
|
|
|
+ FdkkResponse fdkkResponse = fdkkClient.scenePublicScene(fdkkHotRequest.getNum(), fdkkUser.getToken());
|
|
|
+ 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 ResultData.ok();
|
|
|
+ }
|
|
|
+ for (Object obj : jsonArray) {
|
|
|
+ JSONObject jsonObject= (JSONObject) obj;
|
|
|
+ String sid = jsonObject.getString("sid");
|
|
|
+ HotRelation hotRelation = hotRelationService.getById(sid);
|
|
|
+ jsonObject.put("hotRelation",hotRelation);
|
|
|
+ }
|
|
|
+ return ResultData.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/upload/files")
|
|
|
+ public ResultData uploadFiles(FdkkUploadRequest fdkkUploadRequest, MultipartFile files,@RequestHeader String token) throws IOException {
|
|
|
+ Integer userId = JwtUtil.getId(token);
|
|
|
+ FdkkUser fdkkUser = fdkkUserService.getById(userId);
|
|
|
+ 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,fdkkUser.getToken());
|
|
|
+ if(fdkkResponse.getCode() !=0){
|
|
|
+ throw new BusinessException(fdkkResponse.getCode(),fdkkResponse.getMsg());
|
|
|
+ }
|
|
|
+ return ResultData.ok(fdkkResponse.getMsg(),fdkkResponse.getData());
|
|
|
+ }
|
|
|
+
|
|
|
+}
|