Authored by zhichao

fix:容量视图基本信息左侧图存入库

@@ -74,31 +74,4 @@ public class ReportDashboardController { @@ -74,31 +74,4 @@ public class ReportDashboardController {
74 return ResponseBean.builder().data(reportDashboardService.getChartData(dto)).build(); 74 return ResponseBean.builder().data(reportDashboardService.getChartData(dto)).build();
75 } 75 }
76 76
77 -  
78 - /**  
79 - * 导出大屏  
80 - *  
81 - * @param reportCode  
82 - * @return  
83 - */  
84 - @GetMapping("/export")  
85 - @Permission(code = "export", name = "导出大屏")  
86 - public ResponseEntity<byte[]> exportDashboard(HttpServletRequest request, HttpServletResponse response, @RequestParam("reportCode") String reportCode, @RequestParam(value = "showDataSet", required = false, defaultValue = "1") Integer showDataSet) {  
87 - return reportDashboardService.exportDashboard(request, response, reportCode, showDataSet);  
88 - }  
89 -  
90 - /**  
91 - * 导入大屏  
92 - *  
93 - * @param file 导入的zip文件  
94 - * @param reportCode  
95 - * @return  
96 - */  
97 - @PostMapping("/import/{reportCode}")  
98 - @Permission(code = "import", name = "导入大屏")  
99 - public ResponseBean importDashboard(@RequestParam("file") MultipartFile file, @PathVariable("reportCode") String reportCode) {  
100 - reportDashboardService.importDashboard(file, reportCode);  
101 - return ResponseBean.builder().build();  
102 - }  
103 -  
104 } 77 }
@@ -40,22 +40,4 @@ public interface ReportDashboardService extends GaeaBaseService<ReportDashboardP @@ -40,22 +40,4 @@ public interface ReportDashboardService extends GaeaBaseService<ReportDashboardP
40 * @return 40 * @return
41 */ 41 */
42 Object getChartData(ChartDto dto); 42 Object getChartData(ChartDto dto);
43 -  
44 -  
45 - /**  
46 - * 导出大屏,zip文件  
47 - * @param request  
48 - * @param response  
49 - * @param reportCode  
50 - * @return  
51 - */  
52 - ResponseEntity<byte[]> exportDashboard(HttpServletRequest request, HttpServletResponse response, String reportCode, Integer showDataSet);  
53 -  
54 - /**  
55 - * 导入大屏zip  
56 - * @param file  
57 - * @param reportCode  
58 - * @return  
59 - */  
60 - void importDashboard(MultipartFile file, String reportCode);  
61 } 43 }
@@ -70,9 +70,6 @@ public class ReportDashboardServiceImpl implements ReportDashboardService, Initi @@ -70,9 +70,6 @@ public class ReportDashboardServiceImpl implements ReportDashboardService, Initi
70 @Autowired 70 @Autowired
71 private DataSetService dataSetService; 71 private DataSetService dataSetService;
72 72
73 - @Autowired  
74 - private GaeaFileService gaeaFileService;  
75 -  
76 @Value("${customer.file.downloadPath:''}") 73 @Value("${customer.file.downloadPath:''}")
77 private String fileDownloadPath; 74 private String fileDownloadPath;
78 75
@@ -111,7 +108,6 @@ public class ReportDashboardServiceImpl implements ReportDashboardService, Initi @@ -111,7 +108,6 @@ public class ReportDashboardServiceImpl implements ReportDashboardService, Initi
111 value.setCollapse(StringUtils.isNotBlank(reportDashboardWidget.getCollapse()) ? JSONObject.parseObject(reportDashboardWidget.getCollapse()) : new JSONObject()); 108 value.setCollapse(StringUtils.isNotBlank(reportDashboardWidget.getCollapse()) ? JSONObject.parseObject(reportDashboardWidget.getCollapse()) : new JSONObject());
112 109
113 //实时数据的替换 110 //实时数据的替换
114 - analysisData(value);  
115 reportDashboardWidgetDto.setType(reportDashboardWidget.getType()); 111 reportDashboardWidgetDto.setType(reportDashboardWidget.getType());
116 reportDashboardWidgetDto.setValue(value); 112 reportDashboardWidgetDto.setValue(value);
117 reportDashboardWidgetDto.setOptions(JSONObject.parseObject(reportDashboardWidget.getOptions())); 113 reportDashboardWidgetDto.setOptions(JSONObject.parseObject(reportDashboardWidget.getOptions()));
@@ -196,203 +192,6 @@ public class ReportDashboardServiceImpl implements ReportDashboardService, Initi @@ -196,203 +192,6 @@ public class ReportDashboardServiceImpl implements ReportDashboardService, Initi
196 // return getTarget(chartType).transform(dto, result.getData()); 192 // return getTarget(chartType).transform(dto, result.getData());
197 } 193 }
198 194
199 - /**  
200 - * 导出大屏,zip文件  
201 - *  
202 - * @param request  
203 - * @param response  
204 - * @param reportCode  
205 - * @return  
206 - */  
207 - @Override  
208 - public ResponseEntity<byte[]> exportDashboard(HttpServletRequest request, HttpServletResponse response, String reportCode, Integer showDataSet) {  
209 - String userAgent = request.getHeader("User-Agent");  
210 - boolean isIeBrowser = userAgent.indexOf("MSIE") > 0;  
211 -  
212 - ReportDashboardObjectDto detail = getDetail(reportCode);  
213 - List<ReportDashboardWidgetDto> widgets = detail.getDashboard().getWidgets();  
214 - detail.setWidgets(widgets);  
215 - detail.getDashboard().setWidgets(null);  
216 -  
217 -  
218 - //1.组装临时目录,/app/disk/upload/zip/临时文件夹  
219 - String path = dictPath + ZIP_PATH + UuidUtil.generateShortUuid();  
220 -  
221 - //将涉及到的图片保存下来(1.背景图,2.组件为图片的)  
222 - String backgroundImage = detail.getDashboard().getBackgroundImage();  
223 - zipLoadImage(backgroundImage, path);  
224 - detail.getWidgets().stream().filter(reportDashboardWidgetDto -> "widget-image".equals(reportDashboardWidgetDto.getType())).forEach(reportDashboardWidgetDto -> {  
225 - String imageAddress = reportDashboardWidgetDto.getValue().getSetup().getString("imageAdress");  
226 - zipLoadImage(imageAddress, path);  
227 - });  
228 -  
229 - //showDataSet == 0 代表不包含数据集  
230 - if (0 == showDataSet) {  
231 - detail.getWidgets().forEach(reportDashboardWidgetDto -> {  
232 - ReportDashboardWidgetValueDto value = reportDashboardWidgetDto.getValue();  
233 - JSONObject data = value.getData();  
234 - if (null != data && data.containsKey("dataType")) {  
235 - reportDashboardWidgetDto.getValue().getData().put("dataType", "staticData");  
236 - }  
237 - });  
238 - }  
239 -  
240 -  
241 - //2.将大屏设计到的json文件保存  
242 - String jsonPath = path + "/" + JSON_PATH;  
243 - FileUtil.WriteStringToFile(jsonPath, JSONObject.toJSONString(detail));  
244 -  
245 -  
246 - //将path文件夹打包zip  
247 - String zipPath = path + ".zip";  
248 - FileUtil.compress(path, zipPath);  
249 -  
250 -  
251 - File file = new File(zipPath);  
252 - ResponseEntity.BodyBuilder builder = ResponseEntity.ok();  
253 - builder.contentLength(file.length());  
254 - //application/octet-stream 二进制数据流(最常见的文件下载)  
255 - builder.contentType(MediaType.APPLICATION_OCTET_STREAM);  
256 - if (isIeBrowser) {  
257 - builder.header("Content-Disposition", "attachment; filename=" + reportCode + ".zip");  
258 - } else {  
259 - builder.header("Content-Disposition", "attacher; filename*=UTF-8''" + reportCode + ".zip");  
260 - }  
261 -  
262 - ResponseEntity<byte[]> body = builder.body(FileUtils.readFileToByteArray(file));  
263 -  
264 - //删除zip文件  
265 - file.delete();  
266 - //删除path临时文件夹  
267 - FileUtil.delete(path);  
268 - log.info("删除临时文件:{},{}", zipPath, path);  
269 -  
270 - return body;  
271 - }  
272 -  
273 - /**  
274 - * 导入大屏zip  
275 - *  
276 - * @param file  
277 - * @param reportCode  
278 - * @return  
279 - */  
280 - @Override  
281 - @Transactional(rollbackFor = Exception.class)  
282 - public void importDashboard(MultipartFile file, String reportCode) {  
283 - log.info("导入开始,{}", reportCode);  
284 - //1.组装临时目录,/app/disk/upload/zip/临时文件夹  
285 - String path = dictPath + ZIP_PATH + UuidUtil.generateShortUuid();  
286 - //2.解压  
287 - FileUtil.decompress(file, path);  
288 - // path/uuid/  
289 - File parentPath = new File(path);  
290 - //获取打包的第一层目录  
291 - File firstFile = parentPath.listFiles()[0];  
292 -  
293 - File[] files = firstFile.listFiles();  
294 -  
295 - //定义map  
296 - Map<String, String> fileMap = new HashMap<>();  
297 - String content = "";  
298 -  
299 - for (int i = 0; i < files.length; i++) {  
300 - File childFile = files[i];  
301 - if (JSON_PATH.equals(childFile.getName())) {  
302 - //json文件  
303 - content = FileUtil.readFile(childFile);  
304 - } else if ("image".equals(childFile.getName())) {  
305 - File[] imageFiles = childFile.listFiles();  
306 - //所有需要上传的图片  
307 - for (File imageFile : imageFiles) {  
308 - //查看是否存在此image  
309 - String fileName = imageFile.getName().split("\\.")[0];  
310 - //根据fileId,从gaea_file中读出filePath  
311 - LambdaQueryWrapper<GaeaFile> queryWrapper = Wrappers.lambdaQuery();  
312 - queryWrapper.eq(GaeaFile::getFileId, fileName);  
313 - GaeaFile gaeaFile = gaeaFileService.selectOne(queryWrapper);  
314 - if (null == gaeaFile) {  
315 - GaeaFile upload = gaeaFileService.upload(imageFile, fileName);  
316 - log.info("存入图片: {}", upload.getFilePath());  
317 - fileMap.put(fileName, upload.getUrlPath());  
318 - }  
319 - }  
320 - }  
321 -  
322 - }  
323 -  
324 -  
325 - //解析cotent  
326 - ReportDashboardObjectDto detail = JSONObject.parseObject(content, ReportDashboardObjectDto.class);  
327 - //将涉及到的图片路径替换(1.背景图,2.组件为图片的)  
328 - String backgroundImage = detail.getDashboard().getBackgroundImage();  
329 - detail.getDashboard().setBackgroundImage(replaceUrl(backgroundImage, fileMap));  
330 - detail.getWidgets().stream().filter(reportDashboardWidgetDto -> "widget-image".equals(reportDashboardWidgetDto.getType())).forEach(reportDashboardWidgetDto -> {  
331 - String imageAddress = reportDashboardWidgetDto.getValue().getSetup().getString("imageAdress");  
332 - String address = replaceUrl(imageAddress, fileMap);  
333 - reportDashboardWidgetDto.getValue().getSetup().put("imageAdress", address);  
334 - reportDashboardWidgetDto.getOptions().getJSONArray("setup").getJSONObject(4).put("value", address);  
335 - });  
336 - //将新的大屏编码赋值  
337 - detail.setReportCode(reportCode);  
338 -  
339 - //解析结束,删除临时文件夹  
340 - FileUtil.delete(path);  
341 -  
342 - log.info("解析成功,开始存入数据库...");  
343 - insertDashboard(detail);  
344 - }  
345 -  
346 -  
347 - private String replaceUrl(String imageAddress, Map<String, String> fileMap) {  
348 - if (StringUtils.isBlank(imageAddress)) {  
349 - return "";  
350 - }  
351 - String fileId = imageAddress.substring(imageAddress.trim().length() - 36);  
352 - String orDefault = fileMap.getOrDefault(fileId, null);  
353 - if (StringUtils.isBlank(orDefault)) {  
354 - return imageAddress;  
355 - }  
356 - return orDefault;  
357 - }  
358 -  
359 - /**  
360 - * 将大屏涉及到的图片存入指定文件夹  
361 - *  
362 - * @param imageAddress  
363 - * @param path  
364 - */  
365 - private void zipLoadImage(String imageAddress, String path) {  
366 - //http://10.108.26.197:9095/file/download/1d9bcd35-82a1-4f08-9465-b66b930b6a8d  
367 - if (imageAddress.trim().startsWith(fileDownloadPath)) {  
368 - //以fileDownloadPath为前缀的代表为上传的图片  
369 - String fileName = imageAddress.substring(fileDownloadPath.length() + 1);  
370 - //根据fileId,从gaea_file中读出filePath  
371 - LambdaQueryWrapper<GaeaFile> queryWrapper = Wrappers.lambdaQuery();  
372 - queryWrapper.eq(GaeaFile::getFileId, fileName);  
373 - GaeaFile gaeaFile = gaeaFileService.selectOne(queryWrapper);  
374 - if (null != gaeaFile) {  
375 - String fileType = gaeaFile.getFileType();  
376 - path = path + "/image/" + fileName + "." + fileType;  
377 - //path = /app/disk/upload/zip/UUID/image  
378 -  
379 - //原始文件的路径  
380 - String filePath = gaeaFile.getFilePath();  
381 - FileUtil.copyFileUsingFileChannels(filePath, path);  
382 - }  
383 - }  
384 -  
385 - }  
386 -  
387 - public ChartStrategy getTarget(String type) {  
388 - for (String s : queryServiceImplMap.keySet()) {  
389 - if (s.contains(type)) {  
390 - return queryServiceImplMap.get(s);  
391 - }  
392 - }  
393 - throw BusinessExceptionBuilder.build(ResponseCode.RULE_CONTENT_NOT_EXIST);  
394 - }  
395 -  
396 @Override 195 @Override
397 public void afterPropertiesSet() { 196 public void afterPropertiesSet() {
398 Map<String, ChartStrategy> beanMap = applicationContext.getBeansOfType(ChartStrategy.class); 197 Map<String, ChartStrategy> beanMap = applicationContext.getBeansOfType(ChartStrategy.class);
@@ -407,26 +206,6 @@ public class ReportDashboardServiceImpl implements ReportDashboardService, Initi @@ -407,26 +206,6 @@ public class ReportDashboardServiceImpl implements ReportDashboardService, Initi
407 this.applicationContext = applicationContext; 206 this.applicationContext = applicationContext;
408 } 207 }
409 208
410 -  
411 - /**  
412 - * 解析图层数据  
413 - *  
414 - * @param dto  
415 - */  
416 - public void analysisData(ReportDashboardWidgetValueDto dto) {  
417 -// if (StringUtils.isBlank(reportDashboardWidgetDto.getSetCode())) {  
418 -// return;  
419 -// }  
420 -// DataSetDto dto = new DataSetDto();  
421 -// dto.setSetCode(reportDashboardWidgetDto.getSetCode());  
422 -// if (reportDashboardWidgetDto.getContextData() != null && reportDashboardWidgetDto.getContextData().size() > 0) {  
423 -// dto.setContextData(reportDashboardWidgetDto.getContextData());  
424 -// }  
425 -// OriginalDataDto data = dataSetService.getData(dto);  
426 -// reportDashboardWidgetDto.setData(JSONObject.toJSONString(data.getData()));  
427 - }  
428 -  
429 -  
430 public List<JSONObject> buildTimeLine(List<JSONObject> data, ChartDto dto) { 209 public List<JSONObject> buildTimeLine(List<JSONObject> data, ChartDto dto) {
431 Map<String, String> chartProperties = dto.getChartProperties(); 210 Map<String, String> chartProperties = dto.getChartProperties();
432 if (null == chartProperties || chartProperties.size() < 1) { 211 if (null == chartProperties || chartProperties.size() < 1) {
1 package com.anjiplus.template.gaea.business.modules.file.entity; 1 package com.anjiplus.template.gaea.business.modules.file.entity;
2 2
  3 +import com.baomidou.mybatisplus.annotation.TableField;
3 import com.baomidou.mybatisplus.annotation.TableName; 4 import com.baomidou.mybatisplus.annotation.TableName;
4 import com.anji.plus.gaea.curd.entity.GaeaBaseEntity; 5 import com.anji.plus.gaea.curd.entity.GaeaBaseEntity;
5 import io.swagger.annotations.ApiModelProperty; 6 import io.swagger.annotations.ApiModelProperty;
@@ -23,12 +24,12 @@ public class GaeaFile extends GaeaBaseEntity implements Serializable { @@ -23,12 +24,12 @@ public class GaeaFile extends GaeaBaseEntity implements Serializable {
23 @ApiModelProperty(value = "文件类型") 24 @ApiModelProperty(value = "文件类型")
24 private String fileType; 25 private String fileType;
25 26
26 - @ApiModelProperty(value = "文件路径")  
27 - private String filePath; 27 + @ApiModelProperty(value = "文件名称")
  28 + private String fileName;
28 29
29 - @ApiModelProperty(value = "url路径") 30 + @ApiModelProperty(value = "url地址")
30 private String urlPath; 31 private String urlPath;
31 32
32 - @ApiModelProperty(value = "内容说明")  
33 - private String fileInstruction; 33 + @ApiModelProperty(value = "文件")
  34 + private String file;
34 } 35 }
@@ -22,29 +22,10 @@ public interface GaeaFileService extends GaeaBaseService<GaeaFileParam, GaeaFile @@ -22,29 +22,10 @@ public interface GaeaFileService extends GaeaBaseService<GaeaFileParam, GaeaFile
22 * 文件上传 22 * 文件上传
23 * 23 *
24 * @param multipartFile 文件 24 * @param multipartFile 文件
25 - * @param file 文件  
26 - * @param customFileName 自定义文件名,默认给null  
27 - * @return  
28 - */  
29 - GaeaFile upload(MultipartFile multipartFile, File file, String customFileName);  
30 -  
31 - /**  
32 - * 文件上传  
33 - *  
34 - * @param multipartFile 文件  
35 * @return 25 * @return
36 */ 26 */
37 GaeaFile upload(MultipartFile multipartFile); 27 GaeaFile upload(MultipartFile multipartFile);
38 28
39 -  
40 - /**  
41 - * 文件上传  
42 - *  
43 - * @param file 二选一  
44 - * @param customFileName 自定义文件名  
45 - * @return  
46 - */  
47 - GaeaFile upload(File file, String customFileName);  
48 /** 29 /**
49 * 根据fileId显示图片或者下载文件 30 * 根据fileId显示图片或者下载文件
50 * 31 *
@@ -24,15 +24,13 @@ import org.springframework.stereotype.Service; @@ -24,15 +24,13 @@ import org.springframework.stereotype.Service;
24 import org.springframework.transaction.annotation.Transactional; 24 import org.springframework.transaction.annotation.Transactional;
25 import org.springframework.transaction.interceptor.TransactionAspectSupport; 25 import org.springframework.transaction.interceptor.TransactionAspectSupport;
26 import org.springframework.web.multipart.MultipartFile; 26 import org.springframework.web.multipart.MultipartFile;
  27 +import sun.misc.BASE64Encoder;
27 28
28 import javax.servlet.http.HttpServletRequest; 29 import javax.servlet.http.HttpServletRequest;
29 import javax.servlet.http.HttpServletResponse; 30 import javax.servlet.http.HttpServletResponse;
30 import java.io.File; 31 import java.io.File;
31 import java.net.URLEncoder; 32 import java.net.URLEncoder;
32 -import java.util.ArrayList;  
33 -import java.util.Arrays;  
34 -import java.util.List;  
35 -import java.util.UUID; 33 +import java.util.*;
36 import java.util.stream.Collectors; 34 import java.util.stream.Collectors;
37 35
38 /** 36 /**
@@ -45,15 +43,9 @@ import java.util.stream.Collectors; @@ -45,15 +43,9 @@ import java.util.stream.Collectors;
45 @Slf4j 43 @Slf4j
46 public class GaeaFileServiceImpl implements GaeaFileService { 44 public class GaeaFileServiceImpl implements GaeaFileService {
47 45
48 - @Value("${customer.file.dist-path:''}")  
49 - private String dictPath;  
50 -  
51 @Value("${customer.file.white-list:''}") 46 @Value("${customer.file.white-list:''}")
52 private String whiteList; 47 private String whiteList;
53 48
54 - @Value("${customer.file.excelSuffix:''}")  
55 - private String excelSuffix;  
56 -  
57 @Value("${customer.file.downloadPath:''}") 49 @Value("${customer.file.downloadPath:''}")
58 private String fileDownloadPath; 50 private String fileDownloadPath;
59 51
@@ -65,18 +57,20 @@ public class GaeaFileServiceImpl implements GaeaFileService { @@ -65,18 +57,20 @@ public class GaeaFileServiceImpl implements GaeaFileService {
65 return gaeaFileMapper; 57 return gaeaFileMapper;
66 } 58 }
67 59
68 - 60 + /**
  61 + * 文件上传
  62 + *
  63 + * @param multipartFile 文件
  64 + * @return
  65 + */
69 @Override 66 @Override
70 - @Transactional(rollbackFor = Exception.class)  
71 - public GaeaFile upload(MultipartFile multipartFile, File file, String customFileName) { 67 + public GaeaFile upload(MultipartFile multipartFile) {
72 try { 68 try {
73 - String fileName = "";  
74 - if (null != multipartFile) {  
75 - fileName = multipartFile.getOriginalFilename();  
76 - }else {  
77 - fileName = file.getName(); 69 + if (multipartFile == null){
  70 + throw new RuntimeException("文件不能为空");
78 } 71 }
79 72
  73 + String fileName = multipartFile.getOriginalFilename();
80 if (StringUtils.isBlank(fileName)) { 74 if (StringUtils.isBlank(fileName)) {
81 throw BusinessExceptionBuilder.build(ResponseCode.FILE_EMPTY_FILENAME); 75 throw BusinessExceptionBuilder.build(ResponseCode.FILE_EMPTY_FILENAME);
82 } 76 }
@@ -90,36 +84,14 @@ public class GaeaFileServiceImpl implements GaeaFileService { @@ -90,36 +84,14 @@ public class GaeaFileServiceImpl implements GaeaFileService {
90 throw BusinessExceptionBuilder.build(ResponseCode.FILE_SUFFIX_UNSUPPORTED); 84 throw BusinessExceptionBuilder.build(ResponseCode.FILE_SUFFIX_UNSUPPORTED);
91 } 85 }
92 // 生成文件唯一性标识 86 // 生成文件唯一性标识
93 - String fileId;  
94 - if (StringUtils.isBlank(customFileName)) {  
95 - fileId = UUID.randomUUID().toString();  
96 - } else {  
97 - fileId = customFileName;  
98 - }  
99 - String newFileName = fileId + suffixName;  
100 - // 本地文件保存路径  
101 - String filePath = dictPath + newFileName;  
102 - String urlPath = fileDownloadPath + "/" + fileId;  
103 -  
104 GaeaFile gaeaFile = new GaeaFile(); 87 GaeaFile gaeaFile = new GaeaFile();
105 - gaeaFile.setFilePath(filePath); 88 + String fileId = UUID.randomUUID().toString();
106 gaeaFile.setFileId(fileId); 89 gaeaFile.setFileId(fileId);
107 - gaeaFile.setUrlPath(urlPath); 90 + gaeaFile.setFile(new BASE64Encoder().encode(multipartFile.getBytes()));
  91 + gaeaFile.setFileName(fileInstruction);
108 gaeaFile.setFileType(suffixName.replace(".", "")); 92 gaeaFile.setFileType(suffixName.replace(".", ""));
109 - gaeaFile.setFileInstruction(fileInstruction); 93 + gaeaFile.setUrlPath(fileDownloadPath + "/" + fileId);
110 gaeaFileMapper.insert(gaeaFile); 94 gaeaFileMapper.insert(gaeaFile);
111 -  
112 - //写文件 将文件保存/app/dictPath/upload/下  
113 - java.io.File dest = new java.io.File(dictPath + newFileName);  
114 - java.io.File parentFile = dest.getParentFile();  
115 - if (!parentFile.exists()) {  
116 - parentFile.mkdirs();  
117 - }  
118 - if (null != multipartFile) {  
119 - multipartFile.transferTo(dest);  
120 - }else {  
121 - FileUtil.copyFileUsingFileChannels(file, dest);  
122 - }  
123 // 将完整的http访问路径返回 95 // 将完整的http访问路径返回
124 return gaeaFile; 96 return gaeaFile;
125 } catch (Exception e) { 97 } catch (Exception e) {
@@ -129,29 +101,6 @@ public class GaeaFileServiceImpl implements GaeaFileService { @@ -129,29 +101,6 @@ public class GaeaFileServiceImpl implements GaeaFileService {
129 } 101 }
130 } 102 }
131 103
132 - /**  
133 - * 文件上传  
134 - *  
135 - * @param multipartFile 文件  
136 - * @return  
137 - */  
138 - @Override  
139 - public GaeaFile upload(MultipartFile multipartFile) {  
140 - return upload(multipartFile, null, null);  
141 - }  
142 -  
143 - /**  
144 - * 文件上传  
145 - *  
146 - * @param file 文件  
147 - * @param customFileName 自定义文件名  
148 - * @return  
149 - */  
150 - @Override  
151 - public GaeaFile upload(File file, String customFileName) {  
152 - return upload(null, file, customFileName);  
153 - }  
154 -  
155 @Override 104 @Override
156 public ResponseEntity<byte[]> download(HttpServletRequest request, HttpServletResponse response, String fileId) { 105 public ResponseEntity<byte[]> download(HttpServletRequest request, HttpServletResponse response, String fileId) {
157 try { 106 try {
@@ -165,17 +114,12 @@ public class GaeaFileServiceImpl implements GaeaFileService { @@ -165,17 +114,12 @@ public class GaeaFileServiceImpl implements GaeaFileService {
165 throw BusinessExceptionBuilder.build(ResponseCode.FILE_ONT_EXSIT); 114 throw BusinessExceptionBuilder.build(ResponseCode.FILE_ONT_EXSIT);
166 } 115 }
167 //解析文件路径、文件名和后缀 116 //解析文件路径、文件名和后缀
168 - String filePath = gaeaFile.getFilePath();  
169 - if (StringUtils.isBlank(filePath)) {  
170 - throw BusinessExceptionBuilder.build(ResponseCode.FILE_ONT_EXSIT);  
171 - }  
172 - String filename = filePath.substring(filePath.lastIndexOf(File.separator));  
173 - String fileSuffix = filename.substring(filename.lastIndexOf(".")); 117 + byte[] decode = Base64.getMimeDecoder().decode(gaeaFile.getFile());
  118 + String filename = gaeaFile.getFileName();
  119 + String fileSuffix = "." + gaeaFile.getFileType();
174 120
175 //根据文件后缀来判断,是显示图片\视频\音频,还是下载文件 121 //根据文件后缀来判断,是显示图片\视频\音频,还是下载文件
176 - File file = new File(filePath);  
177 ResponseEntity.BodyBuilder builder = ResponseEntity.ok(); 122 ResponseEntity.BodyBuilder builder = ResponseEntity.ok();
178 - builder.contentLength(file.length());  
179 if (StringPatternUtil.stringMatchIgnoreCase(fileSuffix, "(.png|.jpg|.jpeg|.bmp|.gif|.icon)")) { 123 if (StringPatternUtil.stringMatchIgnoreCase(fileSuffix, "(.png|.jpg|.jpeg|.bmp|.gif|.icon)")) {
180 builder.cacheControl(CacheControl.noCache()).contentType(MediaType.IMAGE_PNG); 124 builder.cacheControl(CacheControl.noCache()).contentType(MediaType.IMAGE_PNG);
181 } else if (StringPatternUtil.stringMatchIgnoreCase(fileSuffix, "(.flv|.swf|.mkv|.avi|.rm|.rmvb|.mpeg|.mpg|.ogg|.ogv|.mov|.wmv|.mp4|.webm|.wav|.mid|.mp3|.aac)")) { 125 } else if (StringPatternUtil.stringMatchIgnoreCase(fileSuffix, "(.flv|.swf|.mkv|.avi|.rm|.rmvb|.mpeg|.mpg|.ogg|.ogv|.mov|.wmv|.mp4|.webm|.wav|.mid|.mp3|.aac)")) {
@@ -190,33 +134,10 @@ public class GaeaFileServiceImpl implements GaeaFileService { @@ -190,33 +134,10 @@ public class GaeaFileServiceImpl implements GaeaFileService {
190 builder.header("Content-Disposition", "attacher; filename*=UTF-8''" + filename); 134 builder.header("Content-Disposition", "attacher; filename*=UTF-8''" + filename);
191 } 135 }
192 } 136 }
193 - return builder.body(FileUtils.readFileToByteArray(file)); 137 + return builder.body(decode);
194 } catch (Exception e) { 138 } catch (Exception e) {
195 log.error("file download error: {}", e); 139 log.error("file download error: {}", e);
196 return null; 140 return null;
197 } 141 }
198 } 142 }
199 -  
200 - /**  
201 - * 批处理操作后续处理  
202 - * 删除本地已经存在的文件  
203 - *  
204 - * @param entities  
205 - * @param operationEnum 操作类型  
206 - * @throws BusinessException 阻止程序继续执行或回滚事务  
207 - */  
208 - @Override  
209 - public void processBatchAfterOperation(List<GaeaFile> entities, BaseOperationEnum operationEnum) throws BusinessException {  
210 - if (operationEnum.equals(BaseOperationEnum.DELETE_BATCH)) {  
211 - // 删除本地文件  
212 - entities.forEach(gaeaFile -> {  
213 - String filePath = gaeaFile.getFilePath();  
214 - File file = new File(filePath);  
215 - if (file.exists()) {  
216 - file.delete();  
217 - }  
218 - });  
219 - }  
220 -  
221 - }  
222 } 143 }
@@ -58,17 +58,6 @@ public class ReportExcelController extends GaeaBaseController<ReportExcelParam, @@ -58,17 +58,6 @@ public class ReportExcelController extends GaeaBaseController<ReportExcelParam,
58 return ResponseBean.builder().data(result).build(); 58 return ResponseBean.builder().data(result).build();
59 } 59 }
60 60
61 -  
62 - @PostMapping("/exportExcel")  
63 - @Permission(code = "export", name = "导出")  
64 - @GaeaAuditLog(pageTitle = "报表导出")  
65 - public ResponseBean exportExcel(@RequestBody ReportExcelDto reportExcelDto) {  
66 -  
67 - return ResponseBean.builder().code(ResponseCode.SUCCESS_CODE)  
68 - .data(reportExcelService.exportExcel(reportExcelDto))  
69 - .message("导出成功,请稍后在文件管理中查看").build();  
70 - }  
71 -  
72 // @PostMapping("/exportPdf") 61 // @PostMapping("/exportPdf")
73 // public ResponseBean exportPdf(@RequestBody ReportExcelDto reportExcelDto) { 62 // public ResponseBean exportPdf(@RequestBody ReportExcelDto reportExcelDto) {
74 // reportExcelService.exportPdf(reportExcelDto); 63 // reportExcelService.exportPdf(reportExcelDto);
@@ -29,15 +29,4 @@ public interface ReportExcelService extends GaeaBaseService<ReportExcelParam, Re @@ -29,15 +29,4 @@ public interface ReportExcelService extends GaeaBaseService<ReportExcelParam, Re
29 * @return 29 * @return
30 */ 30 */
31 ReportExcelDto preview(ReportExcelDto reportExcelDto); 31 ReportExcelDto preview(ReportExcelDto reportExcelDto);
32 -  
33 -  
34 - /**  
35 - * 导出为excel  
36 - *  
37 - * @param reportExcelDto  
38 - * @return  
39 - */  
40 - Boolean exportExcel(ReportExcelDto reportExcelDto);  
41 -  
42 -// Boolean exportPdf(ReportExcelDto reportExcelDto);  
43 } 32 }
@@ -128,41 +128,6 @@ public class ReportExcelServiceImpl implements ReportExcelService { @@ -128,41 +128,6 @@ public class ReportExcelServiceImpl implements ReportExcelService {
128 return reportExcelDto; 128 return reportExcelDto;
129 } 129 }
130 130
131 - @Override  
132 - public Boolean exportExcel(ReportExcelDto reportExcelDto) {  
133 - String reportCode = reportExcelDto.getReportCode();  
134 - String exportType = reportExcelDto.getExportType();  
135 - logger.error("导出...");  
136 - if (exportType.equals(ExportTypeEnum.GAEA_TEMPLATE_EXCEL.getCodeValue())) {  
137 - ReportExcelDto report = detailByReportCode(reportCode);  
138 - reportExcelDto.setJsonStr(report.getJsonStr());  
139 - String jsonStr = analysisReportData(reportExcelDto);  
140 - List<JSONObject> lists=(List<JSONObject> ) JSON.parse(jsonStr);  
141 - OutputStream out;  
142 - try {  
143 - String fileId = UUID.randomUUID().toString();  
144 - String filePath = dictPath + File.separator + fileId + ".xlsx";  
145 - String urlPath = fileDownloadPath + java.io.File.separator + fileId;  
146 -  
147 - GaeaFile gaeaFile = new GaeaFile();  
148 - gaeaFile.setFilePath(filePath);  
149 - gaeaFile.setFileId(fileId);  
150 - gaeaFile.setUrlPath(urlPath);  
151 - gaeaFile.setFileType("xlsx");  
152 - gaeaFile.setFileInstruction(reportCode + ".xlsx");  
153 -  
154 - out = new FileOutputStream(filePath);  
155 - XlsUtil.exportXlsFile(out, true, lists);  
156 -  
157 - gaeaFileMapper.insert(gaeaFile);  
158 - logger.info("导出成功:{}", gaeaFile);  
159 - } catch (IOException e) {  
160 - logger.error("导出失败", e);  
161 - }  
162 - }  
163 - return true;  
164 - }  
165 -  
166 /** 131 /**
167 * 解析报表数据,动态插入列表数据和对象数据 132 * 解析报表数据,动态插入列表数据和对象数据
168 */ 133 */
@@ -182,67 +147,6 @@ public class ReportExcelServiceImpl implements ReportExcelService { @@ -182,67 +147,6 @@ public class ReportExcelServiceImpl implements ReportExcelService {
182 } 147 }
183 148
184 /** 149 /**
185 - * 解析单sheet data  
186 - *  
187 - * @param dbObject  
188 - */  
189 - private void analysisSheet(JSONObject dbObject, String setParma) {  
190 - //data是一个二维数组  
191 - if (dbObject.containsKey("data") && null != dbObject.get("data")) {  
192 - List<JSONArray> data = (List<JSONArray>) dbObject.get("data");  
193 -  
194 -  
195 - //行  
196 - for (int r = 0; r < data.size(); r++) {  
197 - JSONArray jsonArray = data.get(r);  
198 - //列  
199 - for (int c = 0; c < jsonArray.size(); c++) {  
200 - //单元格  
201 - JSONObject cell = jsonArray.getJSONObject(c);  
202 - if (null != cell && cell.containsKey("v") && StringUtils.isNotBlank(cell.getString("v"))) {  
203 - String v = cell.getString("v");  
204 - DataSetDto dataSet = getDataSet(v, setParma);  
205 - if (null != dataSet) {  
206 - OriginalDataDto originalDataDto = dataSetService.getData(dataSet);  
207 - if (null != originalDataDto.getData()) {  
208 - if (originalDataDto.getData().size() == 1) {  
209 - //对象  
210 - JSONObject jsonObject = originalDataDto.getData().get(0);  
211 - String fieldLabel = jsonObject.getString(dataSet.getFieldLabel());  
212 -  
213 - String replace = v.replace("#{".concat(dataSet.getSetCode()).concat(".").concat(dataSet.getFieldLabel()).concat("}"), fieldLabel);  
214 - dbObject.getJSONArray("data").getJSONArray(r).getJSONObject(c).put("v", replace);  
215 - dbObject.getJSONArray("data").getJSONArray(r).getJSONObject(c).put("m", replace);  
216 -  
217 - } else {  
218 - //集合  
219 - JSONObject jsonObject = originalDataDto.getData().get(0);  
220 - String fieldLabel = jsonObject.getString(dataSet.getFieldLabel());  
221 -  
222 - String replace = v.replace("#{".concat(dataSet.getSetCode()).concat(".").concat(dataSet.getFieldLabel()).concat("}"), fieldLabel);  
223 - dbObject.getJSONArray("data").getJSONArray(r).getJSONObject(c).put("v", replace);  
224 - dbObject.getJSONArray("data").getJSONArray(r).getJSONObject(c).put("m", replace);  
225 - }  
226 - }  
227 -  
228 - }  
229 - }  
230 -  
231 -  
232 -  
233 - }  
234 - }  
235 -  
236 -  
237 - System.out.println("aaaa");  
238 -  
239 -  
240 - }  
241 -  
242 -  
243 - }  
244 -  
245 - /**  
246 * 解析单sheet celldata 150 * 解析单sheet celldata
247 * 151 *
248 * @param dbObject 152 * @param dbObject