提交 8b304e28 authored 作者: 孙洁清's avatar 孙洁清

Merge branch 'lj-project' of git.yfzx.zjtys.com.cn:912-system/monitor/inspect into lj-project

# Conflicts: # src/main/java/com/zjty/inspect/utils/DocumentWordUtil.java
上级 b70fdcf7
......@@ -34,6 +34,8 @@ public class MvcConfig extends WebMvcConfigurationSupport {
.addResourceLocations("classpath:/META-INF/resources/webjars/");
registry.addResourceHandler("/static/**")
.addResourceLocations("classpath:/static/");
registry.addResourceHandler("/doc/**")
.addResourceLocations("file:./ins/doc/");
}
@Override
......
......@@ -4,18 +4,21 @@ import com.alibaba.fastjson.JSON;
import com.zjty.inspect.aop.AuthAnnotation;
import com.zjty.inspect.entity.*;
import com.zjty.inspect.service.EvaluationService;
import com.zjty.inspect.utils.ExcelUtil;
import com.zjty.inspect.utils.WpsUtil;
import com.zjty.inspect.utils.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.objects.annotations.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.InputStreamResource;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
......@@ -164,12 +167,35 @@ public class EvaluationController {
@ApiImplicitParam(name="danjia",value = "单价"),
@ApiImplicitParam(name="yusuan",value = "总预算金额"),
@ApiImplicitParam(name="gong",value = "工作量"),
@ApiImplicitParam(name="ewai",value = "额外申请")
@ApiImplicitParam(name="ewai",value = "额外申请"),
@ApiImplicitParam(name="agree",value = "0不同意 1同意")
})
@PostMapping("/downloadWps")
public ResponseEntity download(@RequestBody Download download){
// return ResponseEntity.ok("http://120.55.57.35:12345/static/uplaods/a36b17568d4e466dacf9f088a29b4dbc.docx");
// return ResponseEntity.ok("http://120.55.57.35:8078/static/defult.docx");
return ResponseEntity.ok("http://120.55.57.35:12345/static/uplaods/9800449e60d549568f4f0ddeb1974300.docx");
Evaluation evaluation = evaluationService.findById(download.getId());
Map<String, String> wps = WpsUtil.createWps(evaluation);
wps.put("danjia",download.getDanjia());
wps.put("yusuan",download.getYusuan());
wps.put("gong",download.getGong());
wps.put("ewai",download.getEwai());
Double aDouble = Double.valueOf(download.getDanjia());
BigDecimal b1 = BigDecimal.valueOf(aDouble);
BigDecimal b2 = BigDecimal.valueOf(1.5);
double v = b1.subtract(b2).doubleValue();
String format = new DecimalFormat("0.00").format(v);
wps.put("rgcz",format);
if(download.getAgree().equals("1")) {
wps.put("agree", "同意");
}else{
wps.put("agree", "不同意");
}
String w = FreeMakerUtils.parseTpl("报告模板", wps);
if(w==null){
return ResponseEntity.status(500).build();
}
return ResponseEntity.ok(w);
// return ResponseEntity.ok("http://192.168.1.104:8078/static/defult.docx");
}
}
......@@ -13,5 +13,6 @@ public class Download {
private String yusuan;//总预算金额
private String gong;//工作量
private String ewai;//额外申请
private String agree;//0不同意 1同意
}
......@@ -465,19 +465,7 @@ public class DocumentWordUtil {
" </w:sectPr>";
}
public static String tableTile(String technologyName,String strategy){
return " <w:p>\n" +
" <w:pPr>\n" +
" <w:tabs>\n" +
" <w:tab w:val=\"left\" w:pos=\"5422\"/>\n" +
" </w:tabs>\n" +
" </w:pPr>\n" +
" <w:r><w:rPr><w:rFonts w:hint=\"fareast\"/></w:rPr><w:t>关键技术:"+technologyName+"</w:t></w:r><w:r>\n" +
" <w:rPr>\n" +
" <w:rFonts w:hint=\"fareast\"/>\n" +
" </w:rPr>\n" +
" <w:tab/>\n" +
" </w:r>\n" +
" <w:r><w:rPr><w:rFonts w:hint=\"fareast\"/></w:rPr><w:t>替换策略:"+strategy+"</w:t></w:r></w:p>"+"<w:tbl>\n" +
return "<w:p><w:pPr><w:tabs><w:tab w:val=\"left\" w:pos=\"5422\"/></w:tabs></w:pPr><w:r><w:rPr><w:rFonts w:hint=\"fareast\"/></w:rPr><w:t>关键技术:"+technologyName+"</w:t></w:r><w:r><w:rPr><w:rFonts w:hint=\"fareast\"/></w:rPr><w:tab/></w:r><w:r><w:rPr><w:rFonts w:hint=\"fareast\"/></w:rPr><w:t>替换策略:"+strategy+"</w:t></w:r></w:p>"+"<w:tbl>\n" +
" <w:tblPr>\n" +
" <w:tblStyle w:val=\"a13\"/>\n" +
" <w:tblW w:w=\"0\" w:type=\"auto\"/>\n" +
......
package com.zjty.inspect.utils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
@Slf4j
public class DownloadFileUtil {
public static final String separator = File.separator;
/**
* 下载样表
* @param filePath 文件上级目录
* @param fileName 文件名
* @param newName 下载的展示文件名
* @return 响应
*/
public static ResponseEntity<InputStreamResource> download(String filePath, String newName) {
// String route = "static" + separator + "templates" + separator;
String path = null;
ResponseEntity<InputStreamResource> response = null;
try {
// path = fileName;
ClassPathResource classPathResource = new ClassPathResource(filePath);
InputStream inputStream = classPathResource.getInputStream();
//File file = new File(path);
HttpHeaders headers = new HttpHeaders();
headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
headers.add("Content-Disposition",
"attachment; filename="
+ new String(newName.getBytes("gbk"), "iso8859-1") + ".xlsx");
headers.add("Pragma", "no-cache");
headers.add("Expires", "0");
response = ResponseEntity.ok().headers(headers)
.contentType(MediaType.parseMediaType("application/octet-stream"))
.body(new InputStreamResource(inputStream));
} catch (FileNotFoundException e1) {
log.error("找不到指定的文件", e1);
} catch (IOException e) {
log.error("获取不到文件流", e);
}
return response;
}
}
......@@ -12,22 +12,20 @@ public class FreeMakerUtils {
public static String parseTpl(String viewName, Map params) {
Configuration cfg = SpringContextHolder.getBean(Configuration.class);
String html = null;
Template t = null;
try {
t = cfg.getTemplate(viewName + ".ftl");
createWord(t,params);
// html = FreeMarkerTemplateUtils.processTemplateIntoString(t, params);
// System.out.println(html);
String word = createWord(t, params);
return "/doc/"+word;
} catch (Exception e) {
e.printStackTrace();
}
return html;
return null;
}
public static String createWord(Template template, Map<String, List<TechnologyContent>> dataMap){
try {
//文件路径
String filePath= "E://doc";
String filePath= "./ins/doc/";
//文件名称
String fileName = System.currentTimeMillis()+".doc";
......@@ -48,6 +46,7 @@ public class FreeMakerUtils {
// 关闭流
out.flush();
out.close();
return fileName;
}catch (Exception e){
e.printStackTrace();
}
......
......@@ -264,7 +264,7 @@ public class WpsUtil {
ProgramDifficulty programDifficulty = difficultyAssessment.getProgramDifficulty();
keyValue.put("programDifficultyDifficulty",String.valueOf(programDifficulty.getDifficulty()));
keyValue.put("programDifficultyLoad",String.valueOf(programDifficulty.getLoad()));
FreeMakerUtils.parseTpl("报告模板",keyValue);
return keyValue;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论