Commit 8cb23f81 authored by qinhu's avatar qinhu

1.报告导出新模板

2.excel转pdf
parent 90a286f8
...@@ -138,7 +138,29 @@ ...@@ -138,7 +138,29 @@
<version>2.8.5</version> <version>2.8.5</version>
</dependency> </dependency>
<dependency>
<groupId>com.aspose</groupId> <!--自定义-->
<artifactId>words</artifactId> <!--自定义-->
<version>1.0</version> <!--自定义-->
<scope>system</scope> <!--system,类似provided,需要显式提供依赖的jar以后,Maven就不会在Repository中查找它-->
<systemPath>${basedir}/lib/words.jar</systemPath> <!--项目根目录下的lib文件夹下-->
</dependency>
<!-- https://mvnrepository.com/artifact/com.aspose/aspose-slides -->
<dependency>
<groupId>com.aspose</groupId> <!--自定义-->
<artifactId>sliders</artifactId> <!--自定义-->
<version>1.0</version> <!--自定义-->
<scope>system</scope> <!--system,类似provided,需要显式提供依赖的jar以后,Maven就不会在Repository中查找它-->
<systemPath>${basedir}/lib/aspose.slides-15.9.0.jar</systemPath> <!--项目根目录下的lib文件夹下-->
</dependency>
<dependency>
<groupId>com.aspose</groupId> <!--自定义-->
<artifactId>cells</artifactId> <!--自定义-->
<version>1.0</version> <!--自定义-->
<scope>system</scope> <!--system,类似provided,需要显式提供依赖的jar以后,Maven就不会在Repository中查找它-->
<systemPath>${basedir}/lib/aspose-cells-8.5.2.jar</systemPath> <!--项目根目录下的lib文件夹下-->
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -61,6 +61,12 @@ public class EntityEnclosureController { ...@@ -61,6 +61,12 @@ public class EntityEnclosureController {
} else { } else {
return BaseResponse.errorMsg("登录信息失效"); return BaseResponse.errorMsg("登录信息失效");
} }
if (!extName.equals(".pdf")) {
String pdfPath = FastDFSUtils.conventAndUpload(file.getInputStream(), fileName);
map.put("pdfPath", pdfPath);
} else {
map.put("pdfPath", filePath);
}
String picUrl = filePath; String picUrl = filePath;
map.put("fileUrl", picUrl); map.put("fileUrl", picUrl);
map.put("fileName", fileName); map.put("fileName", fileName);
...@@ -95,7 +101,7 @@ public class EntityEnclosureController { ...@@ -95,7 +101,7 @@ public class EntityEnclosureController {
map.put("fileUrl", picUrl); map.put("fileUrl", picUrl);
map.put("fileName", fileName); map.put("fileName", fileName);
map.put("extName", extName); map.put("extName", extName);
map.put("pdfPath", filePath);
return BaseResponse.okData(map); return BaseResponse.okData(map);
} catch (Exception e) { } catch (Exception e) {
logger.error(e.toString()); logger.error(e.toString());
...@@ -127,6 +133,12 @@ public class EntityEnclosureController { ...@@ -127,6 +133,12 @@ public class EntityEnclosureController {
mapSub.put("fileUrl", picUrl); mapSub.put("fileUrl", picUrl);
mapSub.put("fileName", fileName); mapSub.put("fileName", fileName);
mapSub.put("extName", extName); mapSub.put("extName", extName);
if (!extName.equals(".pdf")) {
String pdfPath = FastDFSUtils.conventAndUpload(file.getInputStream(), fileName);
mapSub.put("pdfPath", pdfPath);
} else {
mapSub.put("pdfPath", filePath);
}
filePathList.add(mapSub); filePathList.add(mapSub);
} }
} else { } else {
......
package cn.wise.sc.cement.business.controller; package cn.wise.sc.cement.business.controller;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.wise.sc.cement.business.entity.EntityEnclosure; import cn.wise.sc.cement.business.entity.EntityEnclosure;
import cn.wise.sc.cement.business.model.BaseResponse; import cn.wise.sc.cement.business.model.BaseResponse;
import cn.wise.sc.cement.business.model.FileExt; import cn.wise.sc.cement.business.model.FileExt;
...@@ -38,6 +40,8 @@ import org.springframework.web.multipart.MultipartFile; ...@@ -38,6 +40,8 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
...@@ -113,11 +117,20 @@ public class ReportController { ...@@ -113,11 +117,20 @@ public class ReportController {
beanParams.put("sampleNum", rts.getSampleNum()); beanParams.put("sampleNum", rts.getSampleNum());
beanParams.put("sampleNames", set2String(rts.getSampleNames())); beanParams.put("sampleNames", set2String(rts.getSampleNames()));
beanParams.put("teamNames", set2String(rts.getTeamNames())); beanParams.put("teamNames", set2String(rts.getTeamNames()));
beanParams.put("methodNames", set2StringN(rts.getMethodNames()));
beanParams.put("equipmentNames", set2StringN(rts.getEquipmentNames()));
beanParams.put("projectName", rts.getProjectName()); beanParams.put("projectName", rts.getProjectName());
beanParams.put("printDate", rts.getPrintDate()); beanParams.put("printDate", rts.getPrintDate());
beanParams.put("year", DateUtil.year(DateUtil.date()));
beanParams.put("month",DateUtil.month(DateUtil.date()));
beanParams.put("day",DateUtil.today());
beanParams.put("reportNo", StrUtil.isEmpty(rts.getReportNo())?"":rts.getReportNo());
beanParams.put("firstMethodName",getFirstSet(rts.getMethodNames()));
beanParams.put("firstEquipment",getFirstSet(rts.getEquipmentNames()));
beanParams.put("methodNames", moveFirst(rts.getMethodNames()));
beanParams.put("equipmentNames", moveFirst(rts.getEquipmentNames()));
//六元素导出 //六元素导出
List<SixElementReport> list = iEntrustService.getSampleSixElementCheck(entrustId); List<SixElementReport> list = iEntrustService.getSampleSixElementCheck(entrustId);
...@@ -136,25 +149,25 @@ public class ReportController { ...@@ -136,25 +149,25 @@ public class ReportController {
list1.forEach(this::initMapStr2AlongPro); list1.forEach(this::initMapStr2AlongPro);
beanParams.put("list3", list1); beanParams.put("list3", list1);
WordUtil.writeWordReport(rts.getProjectName() + "(报告)", "report.ftl", WordUtil.writeWordReport(rts.getProjectName() + "(报告)", "report_new.ftl",
beanParams, response, FileExt.EXCL); beanParams, response, FileExt.EXCL);
} }
@PostMapping("/upload") @PostMapping("/upload")
@ApiOperation("上传报告") @ApiOperation("上传报告")
public BaseResponse<Boolean> uploadReport(@RequestBody SampleHandleEnclosureQuery query){ public BaseResponse<Boolean> uploadReport(@RequestBody SampleHandleEnclosureQuery query) {
Assert.notNull(query.getId(),"委托id不能为空!"); Assert.notNull(query.getId(), "委托id不能为空!");
QueryWrapper<EntityEnclosure> qw = new QueryWrapper(); QueryWrapper<EntityEnclosure> qw = new QueryWrapper();
qw.eq("entity_type",5); qw.eq("entity_type", 5);
qw.eq("entity_id",query.getId()); qw.eq("entity_id", query.getId());
if (FileExt.EXCL.getName().equals(query.getExtName()) || if (FileExt.EXCL.getName().equals(query.getExtName()) ||
FileExt.EXCLX.getName().equals(query.getExtName())){ FileExt.EXCLX.getName().equals(query.getExtName())) {
EntityEnclosure one = iEntityEnclosureService.getOne(qw); EntityEnclosure one = iEntityEnclosureService.getOne(qw);
if (BeanUtil.isEmpty(one)){ if (BeanUtil.isEmpty(one)) {
EntityEnclosure entityEnclosure = new EntityEnclosure(); EntityEnclosure entityEnclosure = new EntityEnclosure();
entityEnclosure.setEntityId(query.getId()); entityEnclosure.setEntityId(query.getId());
entityEnclosure.setExtName(query.getExtName()); entityEnclosure.setExtName(query.getExtName());
...@@ -163,9 +176,10 @@ public class ReportController { ...@@ -163,9 +176,10 @@ public class ReportController {
entityEnclosure.setEnclosureUrl(query.getEnclosureUrl()); entityEnclosure.setEnclosureUrl(query.getEnclosureUrl());
entityEnclosure.setAlias(query.getAlias()); entityEnclosure.setAlias(query.getAlias());
entityEnclosure.setEntityType(5); entityEnclosure.setEntityType(5);
entityEnclosure.setPdfUrl(query.getPdfUrl());
iEntityEnclosureService.save(entityEnclosure); iEntityEnclosureService.save(entityEnclosure);
return BaseResponse.okData(true); return BaseResponse.okData(true);
}else { } else {
one.setAlias(query.getAlias()); one.setAlias(query.getAlias());
one.setEnclosureUrl(query.getEnclosureUrl()); one.setEnclosureUrl(query.getEnclosureUrl());
one.setExtName(query.getExtName()); one.setExtName(query.getExtName());
...@@ -173,7 +187,7 @@ public class ReportController { ...@@ -173,7 +187,7 @@ public class ReportController {
iEntityEnclosureService.updateById(one); iEntityEnclosureService.updateById(one);
return BaseResponse.okData(true); return BaseResponse.okData(true);
} }
}else { } else {
return BaseResponse.errorMsg("文件类型只能是excel!"); return BaseResponse.errorMsg("文件类型只能是excel!");
} }
...@@ -214,6 +228,26 @@ public class ReportController { ...@@ -214,6 +228,26 @@ public class ReportController {
sixElement.setSo3(countResultMap.getOrDefault(SixElementKey.SO3.getKey(), "0")); sixElement.setSo3(countResultMap.getOrDefault(SixElementKey.SO3.getKey(), "0"));
} }
private String getFirstSet(Set<String> set){
Iterator<String> iterator = set.iterator();
if (iterator.hasNext()){
return iterator.next();
}
return "";
}
private static Set<String> moveFirst(Set<String> set){
Set<String> newSet = new HashSet<>(set.size());
Iterator<String> iterator = set.iterator();
if (iterator.hasNext()) {
String next = iterator.next();
newSet.addAll(set);
newSet.remove(next);
return newSet;
}
return null;
}
private void initMapStr2AlongPro(IndustrialReport industrialReport) { private void initMapStr2AlongPro(IndustrialReport industrialReport) {
String countResult = industrialReport.getCountResults(); String countResult = industrialReport.getCountResults();
List<SixElementReport.Element> list = JSON.parseArray(countResult, SixElementReport.Element.class); List<SixElementReport.Element> list = JSON.parseArray(countResult, SixElementReport.Element.class);
...@@ -254,5 +288,4 @@ public class ReportController { ...@@ -254,5 +288,4 @@ public class ReportController {
} }
} }
...@@ -60,6 +60,9 @@ public class EntityEnclosure implements Serializable { ...@@ -60,6 +60,9 @@ public class EntityEnclosure implements Serializable {
@ApiModelProperty("扩展名") @ApiModelProperty("扩展名")
private String extName; private String extName;
@ApiModelProperty("pdf路径")
private String pdfUrl;
public interface EntityType { public interface EntityType {
int HEAD = 0; int HEAD = 0;
int EQUIPMENT_TEST = 3; int EQUIPMENT_TEST = 3;
......
...@@ -59,4 +59,7 @@ public class SampleHandleEnclosure implements Serializable { ...@@ -59,4 +59,7 @@ public class SampleHandleEnclosure implements Serializable {
@ApiModelProperty("扩展名") @ApiModelProperty("扩展名")
private String extName; private String extName;
@ApiModelProperty("pdf路径")
private String pdfUrl;
} }
...@@ -21,4 +21,6 @@ public class SampleHandleEnclosureQuery { ...@@ -21,4 +21,6 @@ public class SampleHandleEnclosureQuery {
@ApiModelProperty("路径") @ApiModelProperty("路径")
private String enclosureUrl; private String enclosureUrl;
@ApiModelProperty("pdf路径")
private String pdfUrl;
} }
\ No newline at end of file
...@@ -58,4 +58,7 @@ public class SampleHandleEnclosureVo { ...@@ -58,4 +58,7 @@ public class SampleHandleEnclosureVo {
@ApiModelProperty("扩展名") @ApiModelProperty("扩展名")
private String extName; private String extName;
@ApiModelProperty("pdf地址")
private String pdfUrl;
} }
...@@ -199,7 +199,7 @@ public class EntrustServiceImpl extends ServiceImpl<EntrustMapper, Entrust> impl ...@@ -199,7 +199,7 @@ public class EntrustServiceImpl extends ServiceImpl<EntrustMapper, Entrust> impl
if(entityEnclosureList != null && entityEnclosureList.size()>0 ){ if(entityEnclosureList != null && entityEnclosureList.size()>0 ){
EntityEnclosure entityEnclosure = entityEnclosureList.get(0); EntityEnclosure entityEnclosure = entityEnclosureList.get(0);
entrustVo.setAlias(entityEnclosure.getAlias()); entrustVo.setAlias(entityEnclosure.getAlias());
entrustVo.setEnclosureUrl(entityEnclosure.getEnclosureUrl()); entrustVo.setEnclosureUrl(entityEnclosure.getPdfUrl());
entrustVo.setExtName(entityEnclosure.getExtName()); entrustVo.setExtName(entityEnclosure.getExtName());
} }
} }
...@@ -1284,6 +1284,7 @@ public class EntrustServiceImpl extends ServiceImpl<EntrustMapper, Entrust> impl ...@@ -1284,6 +1284,7 @@ public class EntrustServiceImpl extends ServiceImpl<EntrustMapper, Entrust> impl
sampleHandleEnclosure.setEnclosureUrl(query.getEnclosureUrl()) sampleHandleEnclosure.setEnclosureUrl(query.getEnclosureUrl())
.setExtName(query.getExtName()) .setExtName(query.getExtName())
.setUpdateTime(LocalDateTime.now()) .setUpdateTime(LocalDateTime.now())
.setPdfUrl(query.getPdfUrl())
.setStatus(1); .setStatus(1);
if (StringUtils.isEmpty(query.getEnclosureUrl())) { if (StringUtils.isEmpty(query.getEnclosureUrl())) {
sampleHandleEnclosure.setStatus(2); //上传失败 sampleHandleEnclosure.setStatus(2); //上传失败
......
package cn.wise.sc.cement.business.util;
import cn.hutool.core.io.file.FileReader;
import cn.wise.sc.cement.business.util.dfs.FastDFSUtils;
import com.aspose.cells.SaveFormat;
import com.aspose.cells.Workbook;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
/**
* @author neo.shu
* @since 2020/9/10 20:38
*/
public class Word2PdfUtil {
public static void main(String[] args) {
try {
long time = System.currentTimeMillis();
File file = new File("D:\\JavaProject\\tianjin-cement\\cement-business\\src\\main\\resources\\检测报告模板(最新).xls");
Workbook document = new Workbook(new FileInputStream(file));
//pdf路径
File outputFile = new File("temp-" + System.currentTimeMillis() + ".pdf");
//操作文档保存
document.save(outputFile.getAbsolutePath(), SaveFormat.PDF);
FileReader fileReader = new FileReader(outputFile.getAbsolutePath());
String filePath = FastDFSUtils.uploadPic(fileReader.readBytes(), outputFile.getName(), file.length());
long time1 = System.currentTimeMillis();
System.out.println((time1 - time) / 1000);
System.out.println(filePath);
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
package cn.wise.sc.cement.business.util.dfs; package cn.wise.sc.cement.business.util.dfs;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.file.FileReader;
import com.aspose.cells.SaveFormat;
import com.aspose.cells.Workbook;
import com.aspose.words.Document;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import org.csource.common.MyException; import org.csource.common.MyException;
import org.csource.common.NameValuePair; import org.csource.common.NameValuePair;
import org.csource.fastdfs.*; import org.csource.fastdfs.*;
import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
...@@ -174,4 +181,26 @@ public class FastDFSUtils { ...@@ -174,4 +181,26 @@ public class FastDFSUtils {
} }
} }
public static String conventAndUpload(InputStream inputStream, String filename) {
File outputFile = new File(filename + ".pdf");
String filePath = "";
try {
Workbook document = new Workbook(inputStream);
//pdf路径
//操作文档保存
document.save(outputFile.getAbsolutePath(), SaveFormat.PDF);
FileReader fileReader = new FileReader(outputFile.getAbsolutePath());
filePath = uploadPic(fileReader.readBytes(), outputFile.getName(), outputFile.length());
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
//删除创建的输出文件
FileUtil.del(outputFile);
return filePath;
}
}
} }
\ No newline at end of file
...@@ -4,7 +4,7 @@ fastdfs.charset=UTF-8 ...@@ -4,7 +4,7 @@ fastdfs.charset=UTF-8
fastdfs.http.tracker_http_port=8888 fastdfs.http.tracker_http_port=8888
fastdfs.http.anti_steal_token=no fastdfs.http.anti_steal_token=no
fastdfs.http.secret_key=FastDFS1234567890 fastdfs.http.secret_key=FastDFS1234567890
fastdfs.tracker_servers=localhost:22122 fastdfs.tracker_servers=192.168.110.85:22122
#fastdfs.tracker_servers=localhost:22122 #fastdfs.tracker_servers=localhost:22122
...@@ -20448,7 +20448,7 @@ ...@@ -20448,7 +20448,7 @@
</Cell> </Cell>
</Row> </Row>
</#list> </#list>
<#-- 六元素2--end--> <#--六元素2--end-->
</Table> </Table>
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel"> <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
<PageSetup> <PageSetup>
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment