bihuisong преди 1 година
родител
ревизия
98761df49b

+ 22 - 3
src/main/java/com/sooka/sponest/dataexchange/exchange/controller/ExchangeController.java

@@ -2,6 +2,10 @@ package com.sooka.sponest.dataexchange.exchange.controller;
 
 
 import com.alibaba.fastjson.JSONObject;
+import com.ruoyi.common.core.utils.file.FilePrefixUtils;
+import com.ruoyi.system.api.RemoteFileService;
+import com.ruoyi.system.api.domain.SysFile;
+import com.sooka.sponest.dataexchange.util.spring.SpringUtils;
 import org.springframework.beans.factory.annotation.Value;
 import com.ruoyi.common.core.domain.R;
 import com.ruoyi.common.redis.service.RedisService;
@@ -14,9 +18,12 @@ import com.sooka.sponest.dataexchange.remoteapi.service.center.event.RemoteEvent
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Controller;
+import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
@@ -67,7 +74,19 @@ public class ExchangeController {
     @PostMapping("/straightPushData")
     @ResponseBody
     public R<?> dataCheck(@RequestBody DataExchangeEntity dataExchangeEntity) {
-        if (StringUtils.isNotEmpty(SecurityUtils.getToken())) {
+        List<String> pictureList = new ArrayList<>();
+        if (StringUtils.isNotEmpty(SecurityUtils.getToken()) && !CollectionUtils.isEmpty(dataExchangeEntity.getEventPicture())) {
+            for (String picture : dataExchangeEntity.getEventPicture()) {
+                if (!"image".equals(FilePrefixUtils.getUrlSuffix(picture))) {
+                    log.error("事件图片必须为图片格式---{}", dataExchangeEntity);
+                    return R.fail("事件图片必须为图片格式");
+                } else {
+                    MultipartFile multipartFile = FilePrefixUtils.urlToMultipartFile(picture, System.currentTimeMillis() + ".jpg");
+                    SysFile sysFile = SpringUtils.getBean(RemoteFileService.class).upload(multipartFile).getData();
+                    pictureList.add(sysFile.getUrl());
+                }
+            }
+            dataExchangeEntity.setPictureUrlList(pictureList);
             R<?> result = remoteEventBaseService.saveDataExchangeEntity(dataExchangeEntity);
             if (result.getCode() == 200) {
                 return R.ok("推送成功");
@@ -75,7 +94,7 @@ public class ExchangeController {
                 return R.fail(result.getMsg());
             }
         } else {
-            return R.fail("token验证失败");
+            return R.fail("推送失败");
         }
     }
 
@@ -98,7 +117,7 @@ public class ExchangeController {
     public R<?> pushData(@RequestBody DataExchangeEntity dataExchangeEntity) {
         // TODO: 2024/1/9 0009 待修改
         JSONObject jsonObject = new JSONObject();
-        jsonObject.put("",dataExchangeEntity);
+        jsonObject.put("", dataExchangeEntity);
         try {
             RestUtil.post(url, jsonObject);
         } catch (Exception e) {

+ 7 - 1
src/main/java/com/sooka/sponest/dataexchange/exchange/domian/DataExchangeEntity.java

@@ -3,6 +3,8 @@ package com.sooka.sponest.dataexchange.exchange.domian;
 
 import lombok.Data;
 
+import java.util.List;
+
 @Data
 public class DataExchangeEntity {
 
@@ -23,7 +25,11 @@ public class DataExchangeEntity {
 
     private String eventLatitude;
 
-    private String eventPicture;
+    private List<String> eventPicture;
 
+    /**
+     * 本地上传之后的图片url
+     */
+    private List<String> pictureUrlList;
 
 }