...
|
...
|
@@ -70,9 +70,6 @@ public class ReportDashboardServiceImpl implements ReportDashboardService, Initi |
|
|
@Autowired
|
|
|
private DataSetService dataSetService;
|
|
|
|
|
|
@Autowired
|
|
|
private GaeaFileService gaeaFileService;
|
|
|
|
|
|
@Value("${customer.file.downloadPath:''}")
|
|
|
private String fileDownloadPath;
|
|
|
|
...
|
...
|
@@ -111,7 +108,6 @@ public class ReportDashboardServiceImpl implements ReportDashboardService, Initi |
|
|
value.setCollapse(StringUtils.isNotBlank(reportDashboardWidget.getCollapse()) ? JSONObject.parseObject(reportDashboardWidget.getCollapse()) : new JSONObject());
|
|
|
|
|
|
//实时数据的替换
|
|
|
analysisData(value);
|
|
|
reportDashboardWidgetDto.setType(reportDashboardWidget.getType());
|
|
|
reportDashboardWidgetDto.setValue(value);
|
|
|
reportDashboardWidgetDto.setOptions(JSONObject.parseObject(reportDashboardWidget.getOptions()));
|
...
|
...
|
@@ -196,203 +192,6 @@ public class ReportDashboardServiceImpl implements ReportDashboardService, Initi |
|
|
// return getTarget(chartType).transform(dto, result.getData());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 导出大屏,zip文件
|
|
|
*
|
|
|
* @param request
|
|
|
* @param response
|
|
|
* @param reportCode
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
public ResponseEntity<byte[]> exportDashboard(HttpServletRequest request, HttpServletResponse response, String reportCode, Integer showDataSet) {
|
|
|
String userAgent = request.getHeader("User-Agent");
|
|
|
boolean isIeBrowser = userAgent.indexOf("MSIE") > 0;
|
|
|
|
|
|
ReportDashboardObjectDto detail = getDetail(reportCode);
|
|
|
List<ReportDashboardWidgetDto> widgets = detail.getDashboard().getWidgets();
|
|
|
detail.setWidgets(widgets);
|
|
|
detail.getDashboard().setWidgets(null);
|
|
|
|
|
|
|
|
|
//1.组装临时目录,/app/disk/upload/zip/临时文件夹
|
|
|
String path = dictPath + ZIP_PATH + UuidUtil.generateShortUuid();
|
|
|
|
|
|
//将涉及到的图片保存下来(1.背景图,2.组件为图片的)
|
|
|
String backgroundImage = detail.getDashboard().getBackgroundImage();
|
|
|
zipLoadImage(backgroundImage, path);
|
|
|
detail.getWidgets().stream().filter(reportDashboardWidgetDto -> "widget-image".equals(reportDashboardWidgetDto.getType())).forEach(reportDashboardWidgetDto -> {
|
|
|
String imageAddress = reportDashboardWidgetDto.getValue().getSetup().getString("imageAdress");
|
|
|
zipLoadImage(imageAddress, path);
|
|
|
});
|
|
|
|
|
|
//showDataSet == 0 代表不包含数据集
|
|
|
if (0 == showDataSet) {
|
|
|
detail.getWidgets().forEach(reportDashboardWidgetDto -> {
|
|
|
ReportDashboardWidgetValueDto value = reportDashboardWidgetDto.getValue();
|
|
|
JSONObject data = value.getData();
|
|
|
if (null != data && data.containsKey("dataType")) {
|
|
|
reportDashboardWidgetDto.getValue().getData().put("dataType", "staticData");
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
|
|
|
//2.将大屏设计到的json文件保存
|
|
|
String jsonPath = path + "/" + JSON_PATH;
|
|
|
FileUtil.WriteStringToFile(jsonPath, JSONObject.toJSONString(detail));
|
|
|
|
|
|
|
|
|
//将path文件夹打包zip
|
|
|
String zipPath = path + ".zip";
|
|
|
FileUtil.compress(path, zipPath);
|
|
|
|
|
|
|
|
|
File file = new File(zipPath);
|
|
|
ResponseEntity.BodyBuilder builder = ResponseEntity.ok();
|
|
|
builder.contentLength(file.length());
|
|
|
//application/octet-stream 二进制数据流(最常见的文件下载)
|
|
|
builder.contentType(MediaType.APPLICATION_OCTET_STREAM);
|
|
|
if (isIeBrowser) {
|
|
|
builder.header("Content-Disposition", "attachment; filename=" + reportCode + ".zip");
|
|
|
} else {
|
|
|
builder.header("Content-Disposition", "attacher; filename*=UTF-8''" + reportCode + ".zip");
|
|
|
}
|
|
|
|
|
|
ResponseEntity<byte[]> body = builder.body(FileUtils.readFileToByteArray(file));
|
|
|
|
|
|
//删除zip文件
|
|
|
file.delete();
|
|
|
//删除path临时文件夹
|
|
|
FileUtil.delete(path);
|
|
|
log.info("删除临时文件:{},{}", zipPath, path);
|
|
|
|
|
|
return body;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 导入大屏zip
|
|
|
*
|
|
|
* @param file
|
|
|
* @param reportCode
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void importDashboard(MultipartFile file, String reportCode) {
|
|
|
log.info("导入开始,{}", reportCode);
|
|
|
//1.组装临时目录,/app/disk/upload/zip/临时文件夹
|
|
|
String path = dictPath + ZIP_PATH + UuidUtil.generateShortUuid();
|
|
|
//2.解压
|
|
|
FileUtil.decompress(file, path);
|
|
|
// path/uuid/
|
|
|
File parentPath = new File(path);
|
|
|
//获取打包的第一层目录
|
|
|
File firstFile = parentPath.listFiles()[0];
|
|
|
|
|
|
File[] files = firstFile.listFiles();
|
|
|
|
|
|
//定义map
|
|
|
Map<String, String> fileMap = new HashMap<>();
|
|
|
String content = "";
|
|
|
|
|
|
for (int i = 0; i < files.length; i++) {
|
|
|
File childFile = files[i];
|
|
|
if (JSON_PATH.equals(childFile.getName())) {
|
|
|
//json文件
|
|
|
content = FileUtil.readFile(childFile);
|
|
|
} else if ("image".equals(childFile.getName())) {
|
|
|
File[] imageFiles = childFile.listFiles();
|
|
|
//所有需要上传的图片
|
|
|
for (File imageFile : imageFiles) {
|
|
|
//查看是否存在此image
|
|
|
String fileName = imageFile.getName().split("\\.")[0];
|
|
|
//根据fileId,从gaea_file中读出filePath
|
|
|
LambdaQueryWrapper<GaeaFile> queryWrapper = Wrappers.lambdaQuery();
|
|
|
queryWrapper.eq(GaeaFile::getFileId, fileName);
|
|
|
GaeaFile gaeaFile = gaeaFileService.selectOne(queryWrapper);
|
|
|
if (null == gaeaFile) {
|
|
|
GaeaFile upload = gaeaFileService.upload(imageFile, fileName);
|
|
|
log.info("存入图片: {}", upload.getFilePath());
|
|
|
fileMap.put(fileName, upload.getUrlPath());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
//解析cotent
|
|
|
ReportDashboardObjectDto detail = JSONObject.parseObject(content, ReportDashboardObjectDto.class);
|
|
|
//将涉及到的图片路径替换(1.背景图,2.组件为图片的)
|
|
|
String backgroundImage = detail.getDashboard().getBackgroundImage();
|
|
|
detail.getDashboard().setBackgroundImage(replaceUrl(backgroundImage, fileMap));
|
|
|
detail.getWidgets().stream().filter(reportDashboardWidgetDto -> "widget-image".equals(reportDashboardWidgetDto.getType())).forEach(reportDashboardWidgetDto -> {
|
|
|
String imageAddress = reportDashboardWidgetDto.getValue().getSetup().getString("imageAdress");
|
|
|
String address = replaceUrl(imageAddress, fileMap);
|
|
|
reportDashboardWidgetDto.getValue().getSetup().put("imageAdress", address);
|
|
|
reportDashboardWidgetDto.getOptions().getJSONArray("setup").getJSONObject(4).put("value", address);
|
|
|
});
|
|
|
//将新的大屏编码赋值
|
|
|
detail.setReportCode(reportCode);
|
|
|
|
|
|
//解析结束,删除临时文件夹
|
|
|
FileUtil.delete(path);
|
|
|
|
|
|
log.info("解析成功,开始存入数据库...");
|
|
|
insertDashboard(detail);
|
|
|
}
|
|
|
|
|
|
|
|
|
private String replaceUrl(String imageAddress, Map<String, String> fileMap) {
|
|
|
if (StringUtils.isBlank(imageAddress)) {
|
|
|
return "";
|
|
|
}
|
|
|
String fileId = imageAddress.substring(imageAddress.trim().length() - 36);
|
|
|
String orDefault = fileMap.getOrDefault(fileId, null);
|
|
|
if (StringUtils.isBlank(orDefault)) {
|
|
|
return imageAddress;
|
|
|
}
|
|
|
return orDefault;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 将大屏涉及到的图片存入指定文件夹
|
|
|
*
|
|
|
* @param imageAddress
|
|
|
* @param path
|
|
|
*/
|
|
|
private void zipLoadImage(String imageAddress, String path) {
|
|
|
//http://10.108.26.197:9095/file/download/1d9bcd35-82a1-4f08-9465-b66b930b6a8d
|
|
|
if (imageAddress.trim().startsWith(fileDownloadPath)) {
|
|
|
//以fileDownloadPath为前缀的代表为上传的图片
|
|
|
String fileName = imageAddress.substring(fileDownloadPath.length() + 1);
|
|
|
//根据fileId,从gaea_file中读出filePath
|
|
|
LambdaQueryWrapper<GaeaFile> queryWrapper = Wrappers.lambdaQuery();
|
|
|
queryWrapper.eq(GaeaFile::getFileId, fileName);
|
|
|
GaeaFile gaeaFile = gaeaFileService.selectOne(queryWrapper);
|
|
|
if (null != gaeaFile) {
|
|
|
String fileType = gaeaFile.getFileType();
|
|
|
path = path + "/image/" + fileName + "." + fileType;
|
|
|
//path = /app/disk/upload/zip/UUID/image
|
|
|
|
|
|
//原始文件的路径
|
|
|
String filePath = gaeaFile.getFilePath();
|
|
|
FileUtil.copyFileUsingFileChannels(filePath, path);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public ChartStrategy getTarget(String type) {
|
|
|
for (String s : queryServiceImplMap.keySet()) {
|
|
|
if (s.contains(type)) {
|
|
|
return queryServiceImplMap.get(s);
|
|
|
}
|
|
|
}
|
|
|
throw BusinessExceptionBuilder.build(ResponseCode.RULE_CONTENT_NOT_EXIST);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void afterPropertiesSet() {
|
|
|
Map<String, ChartStrategy> beanMap = applicationContext.getBeansOfType(ChartStrategy.class);
|
...
|
...
|
@@ -407,26 +206,6 @@ public class ReportDashboardServiceImpl implements ReportDashboardService, Initi |
|
|
this.applicationContext = applicationContext;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 解析图层数据
|
|
|
*
|
|
|
* @param dto
|
|
|
*/
|
|
|
public void analysisData(ReportDashboardWidgetValueDto dto) {
|
|
|
// if (StringUtils.isBlank(reportDashboardWidgetDto.getSetCode())) {
|
|
|
// return;
|
|
|
// }
|
|
|
// DataSetDto dto = new DataSetDto();
|
|
|
// dto.setSetCode(reportDashboardWidgetDto.getSetCode());
|
|
|
// if (reportDashboardWidgetDto.getContextData() != null && reportDashboardWidgetDto.getContextData().size() > 0) {
|
|
|
// dto.setContextData(reportDashboardWidgetDto.getContextData());
|
|
|
// }
|
|
|
// OriginalDataDto data = dataSetService.getData(dto);
|
|
|
// reportDashboardWidgetDto.setData(JSONObject.toJSONString(data.getData()));
|
|
|
}
|
|
|
|
|
|
|
|
|
public List<JSONObject> buildTimeLine(List<JSONObject> data, ChartDto dto) {
|
|
|
Map<String, String> chartProperties = dto.getChartProperties();
|
|
|
if (null == chartProperties || chartProperties.size() < 1) {
|
...
|
...
|
|