Эх сурвалжийг харах

Merge remote-tracking branch 'origin/master'

liu.shiyi 1 жил өмнө
parent
commit
b085fd54d4

+ 38 - 1
DataRoom/dataroom-core/src/main/java/com/gccloud/dataroom/core/module/biz/component/service/impl/BizComponentServiceImpl.java

@@ -11,6 +11,7 @@ import com.gccloud.dataroom.core.utils.CodeGenerateUtils;
 import com.gccloud.common.exception.GlobalException;
 import com.gccloud.common.vo.PageVO;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.exception.ExceptionUtils;
 import org.springframework.stereotype.Service;
@@ -165,7 +166,7 @@ public class BizComponentServiceImpl extends ServiceImpl<DataRoomBizComponentDao
             FileOutputStream outputStream = new FileOutputStream(filePath);
             outputStream.write(imageBytes);
             outputStream.close();
-            log.info("大屏封面保存至:{}", filePath);
+            log.info("组业务件封面保存至:{}", filePath);
         } catch (IOException e) {
             log.error(ExceptionUtils.getStackTrace(e));
         }
@@ -178,16 +179,52 @@ public class BizComponentServiceImpl extends ServiceImpl<DataRoomBizComponentDao
         if (copyFrom == null) {
             throw new GlobalException("源业务组件不存在");
         }
+        String oldCode = copyFrom.getCode();
         copyFrom.setId(null);
         copyFrom.setName(copyFrom.getName() + "_复制");
         while(this.checkName(null, copyFrom.getName())) {
             copyFrom.setName(copyFrom.getName() + "_复制");
         }
         copyFrom.setCode(CodeGenerateUtils.generate("bizComponent"));
+        boolean copy = this.copyCoverPicture(oldCode, copyFrom.getCode());
+        if (!copy) {
+            copyFrom.setCoverPicture(null);
+        } else {
+            copyFrom.setCoverPicture("cover" + File.separator + copyFrom.getCode() + ".png");
+        }
         this.save(copyFrom);
         return copyFrom.getCode();
     }
 
+
+    /**
+     * 复制封面文件
+     * @param oldFileName
+     * @param newFileName
+     * @return
+     */
+    private boolean copyCoverPicture(String oldFileName, String newFileName) {
+        if (StringUtils.isBlank(oldFileName)) {
+            return false;
+        }
+        String basePath = bigScreenConfig.getFile().getBasePath() + File.separator;
+        String oldFile = basePath + "cover" + File.separator + oldFileName + ".png";
+        // 检查文件是否存在
+        File file = new File(oldFile);
+        if (!file.exists() || !file.isFile()) {
+            return false;
+        }
+        // 复制一份
+        String newFilePath = basePath + "cover" + File.separator + newFileName + ".png";
+        try {
+            FileUtils.copyFile(file, new File(newFilePath));
+            return true;
+        } catch (IOException e) {
+            log.error(ExceptionUtils.getStackTrace(e));
+        }
+        return false;
+    }
+
     @Override
     public void delete(String id) {
         if (StringUtils.isBlank(id)) {

+ 10 - 5
DataRoom/dataroom-core/src/main/java/com/gccloud/dataroom/core/module/chart/controller/ChartDataController.java

@@ -17,10 +17,7 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.http.MediaType;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
 import java.util.List;
@@ -61,7 +58,7 @@ public class ChartDataController {
     }
 
     @PostMapping("/chart")
-    @ApiOperation(value = "图表数据", position = 10, notes = "获取指定图表的数据(通过配置)", produces = MediaType.APPLICATION_JSON_VALUE)
+    @ApiOperation(value = "图表数据", position = 20, notes = "获取指定图表的数据(通过配置)", produces = MediaType.APPLICATION_JSON_VALUE)
     public R<ChartDataVO> getChartData(@RequestBody ChartDataSearchDTO chartDataSearchDTO) {
         PageEntity pageEntity = pageService.getByCode(chartDataSearchDTO.getPageCode());
         AssertUtils.isTrue(pageEntity != null, "页面不存在");
@@ -70,6 +67,14 @@ public class ChartDataController {
         return getChartData(chartDataSearchDTO, config, chart);
     }
 
+    @GetMapping("/mock/{type}")
+    @ApiOperation(value = "图表模拟数据", position = 30, notes = "获取指定类型的图表模拟数据", produces = MediaType.APPLICATION_JSON_VALUE)
+    public R<ChartDataVO> getMockData(@PathVariable String type) {
+        ChartDataVO mockData = ChartMockData.getMockData(type);
+        return R.success(mockData);
+    }
+
+
     /**
      * 获取图表数据
      * @param chartDataSearchDTO

+ 37 - 0
DataRoom/dataroom-core/src/main/java/com/gccloud/dataroom/core/module/manage/service/impl/DataRoomPageServiceImpl.java

@@ -25,6 +25,7 @@ import com.gccloud.common.vo.PageVO;
 import com.google.common.collect.Lists;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.exception.ExceptionUtils;
 import org.springframework.stereotype.Service;
@@ -143,6 +144,35 @@ public class DataRoomPageServiceImpl extends ServiceImpl<DataRoomPageDao, PageEn
         return fileUrl;
     }
 
+
+    /**
+     * 复制封面文件
+     * @param oldFileName
+     * @param newFileName
+     * @return
+     */
+    private boolean copyCoverPicture(String oldFileName, String newFileName) {
+        if (StringUtils.isBlank(oldFileName)) {
+            return false;
+        }
+        String basePath = bigScreenConfig.getFile().getBasePath() + File.separator;
+        String oldFile = basePath + "cover" + File.separator + oldFileName + ".png";
+        // 检查文件是否存在
+        File file = new File(oldFile);
+        if (!file.exists() || !file.isFile()) {
+            return false;
+        }
+        // 复制一份
+        String newFilePath = basePath + "cover" + File.separator + newFileName + ".png";
+        try {
+            FileUtils.copyFile(file, new File(newFilePath));
+            return true;
+        } catch (IOException e) {
+            log.error(ExceptionUtils.getStackTrace(e));
+        }
+        return false;
+    }
+
     @Override
     public String addByTemplate(DataRoomPageDTO bigScreenPageDTO) {
         if (StringUtils.isBlank(bigScreenPageDTO.getPageTemplateId())) {
@@ -270,6 +300,7 @@ public class DataRoomPageServiceImpl extends ServiceImpl<DataRoomPageDao, PageEn
     public String copy(PageEntity screenEntity) {
         DataRoomPageDTO config = (DataRoomPageDTO) screenEntity.getConfig();
         screenEntity.setId(null);
+        String oldCode = screenEntity.getCode();
         screenEntity.setCode(CodeGenerateUtils.generate(screenEntity.getType()));
         int i = 1;
         String oldName = screenEntity.getName();
@@ -283,6 +314,12 @@ public class DataRoomPageServiceImpl extends ServiceImpl<DataRoomPageDao, PageEn
         for (Chart chart : chartList) {
             chart.setCode(CodeGenerateUtils.generate(chart.getType() == null ? "chart" : chart.getType()));
         }
+        boolean copy = this.copyCoverPicture(oldCode, screenEntity.getCode());
+        if (!copy) {
+            screenEntity.setCoverPicture(null);
+        } else {
+            screenEntity.setCoverPicture("cover" + File.separator + screenEntity.getCode() + ".png");
+        }
         this.save(screenEntity);
         dataRoomExtendClient.afterAdd(screenEntity.getCode());
         return screenEntity.getCode();