fix export bug
This commit is contained in:
parent
cebef1294d
commit
5e22ef0804
@ -106,7 +106,7 @@ public class RecordController {
|
||||
@GetMapping("/report")
|
||||
public void report(@RequestParam("uuid") String uuid, HttpServletResponse response) {
|
||||
// recordService.record2word(uuid, response);
|
||||
|
||||
recordService.report(uuid, response);
|
||||
}
|
||||
|
||||
@PutMapping("/metaData")
|
||||
|
@ -23,7 +23,7 @@ public enum AuthEnum {
|
||||
add("/project/project : DELETE");
|
||||
add("/project/record : DELETE");
|
||||
add("/project/record : PUT");
|
||||
|
||||
add("/record/report : GET");
|
||||
|
||||
add("/respondent/respondent : POST");
|
||||
add("/respondent/respondent : PUT");
|
||||
@ -72,6 +72,7 @@ public enum AuthEnum {
|
||||
add("/project/projectList : GET");
|
||||
add("/project/respondentCount : GET");
|
||||
add("/record/record2word : GET");
|
||||
add("/record/report : GET");
|
||||
|
||||
}}),
|
||||
MODIFY_PROJECT("修改项目的权限", new HashSet<String>() {{
|
||||
|
@ -10,6 +10,7 @@ import com.example.survey.enumeration.RecordStateEnum;
|
||||
import com.example.survey.enumeration.ResultEnum;
|
||||
import com.example.survey.exception.*;
|
||||
import com.example.survey.service.RecordService;
|
||||
import com.example.survey.util.DownloadUtil;
|
||||
import com.example.survey.util.ThreadWordUtil;
|
||||
import com.example.survey.util.WordUtil;
|
||||
import com.example.survey.vo.RecordDetailVO;
|
||||
@ -54,6 +55,9 @@ public class RecordServiceImpl implements RecordService {
|
||||
@Value("${file.url}")
|
||||
private String url;
|
||||
|
||||
@Value("${file.report}")
|
||||
private String report;
|
||||
|
||||
@Autowired
|
||||
private ThreadWordUtil threadWordUtil;
|
||||
|
||||
@ -309,8 +313,27 @@ public class RecordServiceImpl implements RecordService {
|
||||
|
||||
@Override
|
||||
public void report(String uuid, HttpServletResponse response) {
|
||||
// TODO Auto-generated method stub
|
||||
Record record = recordDao.getRecord(uuid);
|
||||
if (record == null) {
|
||||
throw new RecordException(ResultEnum.NOT_EXIST_RECORD);
|
||||
}
|
||||
|
||||
if(!record.getMetaDataType().equals(MetaDataTypeEnum.REPORT_TEMP.getValue())) {
|
||||
throw new RecordException(ResultEnum.NOT_EXIST_RECORD);
|
||||
}
|
||||
|
||||
if(!record.getState().equals(RecordStateEnum.REVIEWED.getValue())){
|
||||
throw new RecordException(ResultEnum.NOT_EXIST_RECORD);
|
||||
}
|
||||
|
||||
String path = this.report + record.getUuid() + ".docx";
|
||||
|
||||
try {
|
||||
DownloadUtil.downloadFile(path, response);
|
||||
} catch (IOException e) {
|
||||
response.setStatus(400);
|
||||
// response.clo
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,14 +25,22 @@ public class ThreadWordUtil implements Runnable {
|
||||
@Value("${file.path}")
|
||||
private String path;
|
||||
|
||||
@Value("${file.report}")
|
||||
private String report;
|
||||
|
||||
@Value("${file.template}")
|
||||
private String template;
|
||||
|
||||
|
||||
@Autowired
|
||||
private RecordDao recordDao;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if(record != null) {
|
||||
String templatePath = this.path + record.getMetaData().getName() + ".docx";
|
||||
String outputPath = this.path + record.getUuid() + ".docx";
|
||||
System.out.println("=========Start Export============");
|
||||
String templatePath = this.template + record.getMetaData().getName() + ".docx";
|
||||
String outputPath = this.report + record.getUuid() + ".docx";
|
||||
try{
|
||||
Map<String, Object> values = record.getValues();
|
||||
values.put("submit", record.getOperationList().get(0).getUser().getUsername());
|
||||
@ -51,10 +59,8 @@ public class ThreadWordUtil implements Runnable {
|
||||
|
||||
|
||||
public void start() {
|
||||
if (t == null) {
|
||||
t = new Thread(this, threadName);
|
||||
t.start();
|
||||
}
|
||||
t = new Thread(this, threadName);
|
||||
t.start();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -35,14 +35,13 @@ public class WordUtil {
|
||||
private HashMap<String, Method> key2methods;
|
||||
private Map<String, Object> values;
|
||||
private String outputPath;
|
||||
private File temp;
|
||||
|
||||
public WordUtil(Map<String, Object> values, String templatePath, String outputPath)
|
||||
throws FileNotFoundException, IOException, NoSuchMethodException, SecurityException {
|
||||
File temp = new File(UUID.randomUUID() + "t.docx");
|
||||
temp = new File(UUID.randomUUID() + "t.docx");
|
||||
this.outputPath = outputPath;
|
||||
FileUtils.copyFile(new File(templatePath), temp);
|
||||
// response.addHeader("Content-Disposition", "attachment;filename=" +
|
||||
// UUID.randomUUID().toString() + ".docx");
|
||||
OPCPackage pack = POIXMLDocument.openPackage(temp.getAbsolutePath());
|
||||
document = new CustomXWPFDocument(pack);
|
||||
this.values = values;
|
||||
@ -105,7 +104,7 @@ public class WordUtil {
|
||||
document.write(outputStream);
|
||||
outputStream.close();
|
||||
document.close();
|
||||
|
||||
FileUtils.forceDelete(temp);
|
||||
// XWPFTemplate template = XWPFTemplate.compile(templatePath,
|
||||
// configureBuilder.build()).render(values);
|
||||
// try (BufferedOutputStream os = new
|
||||
|
@ -18,3 +18,5 @@ spring:
|
||||
file:
|
||||
path: ./upload/
|
||||
url: /upload/
|
||||
report: ./report/
|
||||
template: ./template/
|
@ -1,7 +1,6 @@
|
||||
spring:
|
||||
data:
|
||||
mongodb:
|
||||
# uri: mongodb://cveo:cveo123456@120.78.177.67:27017/survey
|
||||
#创建索引
|
||||
auto-index-creation: true
|
||||
host: mongo
|
||||
@ -19,7 +18,8 @@ spring:
|
||||
file:
|
||||
path: ./data/upload/
|
||||
url: /upload/
|
||||
|
||||
report: ./data/report/
|
||||
template: ./data/template/
|
||||
# kafka:
|
||||
# bootstrap-servers: localhost:9092 # 指定kafka 代理地址,可以多个
|
||||
# producer: # 生产者
|
||||
|
Loading…
x
Reference in New Issue
Block a user