|
@@ -35,6 +35,7 @@ import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.ddr.poi.html.HtmlRenderPolicy;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.File;
|
|
@@ -49,7 +50,8 @@ public class NoveltyExportReportService {
|
|
|
private final FileUtils fileUtils;
|
|
|
private final FileManagerService fileManagerService;
|
|
|
private final ReferencesService referencesService;
|
|
|
-
|
|
|
+ @Value("${FMSUrl}")
|
|
|
+ private String FMSUrl;
|
|
|
public String exportReport(Integer id) throws Exception {
|
|
|
LambdaQueryWrapper<NoveltyReportReferences> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
queryWrapper.eq(NoveltyReportReferences::getReportReferenceId, id);
|
|
@@ -69,7 +71,6 @@ public class NoveltyExportReportService {
|
|
|
// 根据模板id 获取模板
|
|
|
Integer tempalteId = noveltyReportReferences.getTemplateId();
|
|
|
|
|
|
-
|
|
|
//获取模板
|
|
|
NoveltyReportTemplate noveltyReportTemplate = noveltyReportTemplateService.getById(tempalteId);
|
|
|
String configureSource = noveltyReportTemplate.getTempleMessage();
|
|
@@ -79,15 +80,17 @@ public class NoveltyExportReportService {
|
|
|
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
|
|
|
- Object dataObject = JSONObject.parse(dataSource);
|
|
|
- map.put("cm", dataObject);
|
|
|
+ JSONObject jsonObject= this.loadReportData(dataSource,configureSource);
|
|
|
+
|
|
|
+ map.put("cm", jsonObject);
|
|
|
// 获取模板路径
|
|
|
String templateUrl = noveltyReportTemplate.getTemplatePath();
|
|
|
|
|
|
String templateFilePath = fileUtils.getPath(templateUrl);
|
|
|
|
|
|
//读取模板后保存生成word的地址
|
|
|
- String fileName = IdUtil.simpleUUID() + ".docx";
|
|
|
+ String name =noveltyReportTemplate.getTemplateName().replace("模板","报告");
|
|
|
+ String fileName = name + ".docx";
|
|
|
String directoryName = fileUtils.createDirectory();
|
|
|
|
|
|
String outPath = fileUtils.getSavePath(directoryName) + fileName;
|
|
@@ -122,10 +125,44 @@ public class NoveltyExportReportService {
|
|
|
case PoiPolicy.HTML:
|
|
|
configureBuilder.bind(key, htmlRenderPolicy);
|
|
|
break;
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|
|
|
Configure configure = configureBuilder.build();
|
|
|
return configure;
|
|
|
}
|
|
|
+
|
|
|
+ public JSONObject loadReportData(String dataSource,String configSource) {
|
|
|
+ JSONObject configObject = JSONObject.parseObject(configSource);
|
|
|
+ JSONObject dataObject =JSONObject.parseObject(dataSource);
|
|
|
+ for (Map.Entry<String, Object> entry : configObject.entrySet()) {
|
|
|
+ String key = entry.getKey();
|
|
|
+ JSONObject jsonObject = configObject.getJSONObject(key);
|
|
|
+ String type = jsonObject.getString("type");
|
|
|
+ switch (type) {
|
|
|
+ case PoiPolicy.PICTURE:
|
|
|
+ String[] keys= key.split("\\.");
|
|
|
+ JSONObject jsonObject1 =dataObject;
|
|
|
+ List<JSONObject> jsonObjectPics=new ArrayList<>();
|
|
|
+ for (int i=0;i<keys.length;i++){
|
|
|
+ if(i!=keys.length-1){
|
|
|
+ jsonObject1=jsonObject1.getJSONObject(keys[i]);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ jsonObjectPics =jsonObject1.getJSONArray(keys[i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(jsonObjectPics!=null){
|
|
|
+ jsonObjectPics.forEach(item->{
|
|
|
+ String value ="<img src='"+FMSUrl+"/fileManager/downloadFile?fileId="+item.get("url").toString()+"' style='width:150px;height:180px;object-fit: contain;' fit='contain'>";
|
|
|
+ item.put("url",value);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return dataObject;
|
|
|
+ }
|
|
|
}
|