Commit 42ee8357 authored by 周昊's avatar 周昊

1、修改pc端导出项目风险清单表excel列表

2、修改pc端导出风险告知卡图片
parent 7f366b42
...@@ -132,18 +132,22 @@ public class RiskPlanController extends BaseController ...@@ -132,18 +132,22 @@ public class RiskPlanController extends BaseController
RiskNotificationExportWordDto exportWordDto = riskPlanInherentListService.getRiskNotificationExportWordDto(inherentId); RiskNotificationExportWordDto exportWordDto = riskPlanInherentListService.getRiskNotificationExportWordDto(inherentId);
Map<String, Object> dataMap = Convert.convert(Map.class, exportWordDto); Map<String, Object> dataMap = Convert.convert(Map.class, exportWordDto);
WordUtil word = new WordUtil(); dataMap.put("title", "风险告知卡");
word.exportWord(request, response,dataMap,"风险告知卡"); dataMap.put("path", "D:/ruoyi/uploadPath/upload/");
// 数据填装至模板,保存文件
String name = WordUtil.createDoc(dataMap, "word.ftl");
// word导出
WordUtil.responseDownloadFile(request, response, "D:/ruoyi/uploadPath/upload/", name);
} }
/** /**
* 导出项目风险清单表 * 导出项目风险清单表
*/ */
@PostMapping("/exportExcel/InherentList/{inherentId}") @PostMapping("/exportExcel/InherentList/{planId}")
public void export(@PathVariable Long inherentId, HttpServletResponse response) { public void export(@PathVariable Long planId, HttpServletResponse response) {
try { try {
List<RiskInherentListExportDto> dtos = riskPlanInherentListService.getPlanInherentListByPlanId(inherentId); List<RiskInherentListExportDto> dtos = riskPlanInherentListService.getPlanInherentListByPlanId(planId);
riskPlanInherentListService.exportPlanInherentList(response,dtos); riskPlanInherentListService.exportPlanInherentList(response,dtos);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
......
...@@ -59,6 +59,5 @@ public class RiskNotificationExportWordDto { ...@@ -59,6 +59,5 @@ public class RiskNotificationExportWordDto {
/** /**
* 应急措施 * 应急措施
*/ */
@TableField("measures_emergency")
private String measuresEmergency; private String measuresEmergency;
} }
...@@ -16,6 +16,7 @@ import com.censoft.censoftrongtong.mapper.RiskPlanTaskMapper; ...@@ -16,6 +16,7 @@ import com.censoft.censoftrongtong.mapper.RiskPlanTaskMapper;
import com.censoft.censoftrongtong.service.IRiskPlanInherentListService; import com.censoft.censoftrongtong.service.IRiskPlanInherentListService;
import com.censoft.censoftrongtong.service.IRiskPlanTaskService; import com.censoft.censoftrongtong.service.IRiskPlanTaskService;
import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.WordUtil;
import com.ruoyi.system.service.ISysUploadFileService; import com.ruoyi.system.service.ISysUploadFileService;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.Workbook;
...@@ -29,6 +30,7 @@ import java.io.IOException; ...@@ -29,6 +30,7 @@ import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -235,7 +237,11 @@ public class RiskPlanInherentListServiceImpl ...@@ -235,7 +237,11 @@ public class RiskPlanInherentListServiceImpl
@Override @Override
public RiskNotificationExportWordDto getRiskNotificationExportWordDto(Long inherentId) { public RiskNotificationExportWordDto getRiskNotificationExportWordDto(Long inherentId) {
return riskPlanInherentListMapper.getRiskNotificationExportWordDto(inherentId); RiskNotificationExportWordDto dto = riskPlanInherentListMapper.getRiskNotificationExportWordDto(inherentId);
if (StrUtil.isNotBlank(dto.getSafetyWarningSigns())){
dto.setSafetyWarningSigns(WordUtil.getImageStr("D:\\ruoyi\\uploadPath\\upload\\警告标志\\"+dto.getSafetyWarningSigns()+".png"));
}
return dto;
} }
@Override @Override
......
...@@ -423,7 +423,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -423,7 +423,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
LEFT JOIN risk_plan_inherent_list rpil ON rpil.room_id = lr.id LEFT JOIN risk_plan_inherent_list rpil ON rpil.room_id = lr.id
LEFT JOIN risk_plan_existing_list rpel ON rpel.inherent_id = rpil.id LEFT JOIN risk_plan_existing_list rpel ON rpel.inherent_id = rpil.id
WHERE WHERE
rp.id = #{planId} -- rp.id = #{planId}
AND rpil.id IS NOT NULL rpil.plan_id = #{planId}
AND rpil.id IS NOT NULL
GROUP BY rpel.id
</select> </select>
</mapper> </mapper>
\ No newline at end of file
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -3,84 +3,146 @@ package com.ruoyi.common.utils; ...@@ -3,84 +3,146 @@ package com.ruoyi.common.utils;
import freemarker.template.Configuration; import freemarker.template.Configuration;
import freemarker.template.Template; import freemarker.template.Template;
import freemarker.template.TemplateException; import freemarker.template.TemplateException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import sun.misc.BASE64Encoder;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.*; import java.io.*;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import static freemarker.template.Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS;
/** /**
* @author 笑小枫 * @created: 2020/10/16 16:49
* @date 2022/7/27 * @author: winston
* @see <a href="https://www.xiaoxiaofeng.com">https://www.xiaoxiaofeng.com</a> * @description: 导出Word工具类
*/ */
@Component
public class WordUtil { public class WordUtil {
private final Configuration configuration; @Autowired
private static Logger logger = LogManager.getLogger(WordUtil.class);
/**
* 模板路径
*/
private static final String FTL_FP = "/templates/ftl/";
public WordUtil() { private static Configuration configuration = null;
configuration = new Configuration(DEFAULT_INCOMPATIBLE_IMPROVEMENTS); static {
configuration.setDefaultEncoding("UTF-8"); configuration = new Configuration();
//设置默认的编码
configuration.setDefaultEncoding("utf-8");
} }
public void createWord(Map<String, Object> dataMap, String templateName, String fileName) { /**
// 模板文件所在路径 * @param dataMap 数据库数据
configuration.setClassForTemplateLoading(this.getClass(), "/templates"); * @param ftl 替换的模板
Template t = null; * @return
* @throws IOException
*/
public static String createDoc(Map dataMap, String ftl) throws IOException {
configuration.setClassForTemplateLoading(WordUtil.class, FTL_FP);
String path = (String) dataMap.get("path");
Template template = null;
try { try {
// 获取模板文件 // yxkj.ftl为要装载的模板
t = configuration.getTemplate(templateName, "UTF-8"); template = configuration.getTemplate(ftl);
template.setEncoding("utf-8");
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
// 导出文件
File outFile = new File(fileName); // 输出文档路径及名称
try (Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), StandardCharsets.UTF_8))) { String fileName = dataMap.get("title") + ".doc";
if (t != null) {
// 将填充数据填入模板文件并输出到目标文件 File outFile = new File(path + fileName);
t.process(dataMap, out); Writer out = null;
} try {
} catch (IOException | TemplateException e1) { out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), "utf-8"));
e1.printStackTrace(); } catch (Exception e1) {
logger.error(e1);
fileName = "";
}
try {
template.process(dataMap, out);
out.close();
} catch (TemplateException e2) {
logger.error(e2);
fileName = "";
} catch (IOException e) {
logger.error(e);
fileName = "";
} }
return fileName;
} }
public void exportWord(HttpServletRequest request, HttpServletResponse response,Map<String, Object> dataMap,String exportName) throws IOException { /**
// 1.创建临时文件夹 * 通用文件下载方法
String rootPath = request.getSession().getServletContext().getRealPath("/"); *
String fileName = UUID.randomUUID().toString().replace("-", ""); * @param response
* @param filePath 文件绝对路径
// 加载word中的数据信息 * this.getClass().getClassLoader().getResource("file").getPath
WordUtil word = new WordUtil(); * ();
* @param fileName 文件名
word.createWord(dataMap, "word.xml", rootPath + "/" + fileName + ".doc"); * @throws IOException
*/
response.setCharacterEncoding("utf-8"); public static void responseDownloadFile(HttpServletRequest request, HttpServletResponse response, String filePath, String fileName) throws IOException {
response.setContentType("application/msword"); // 读到流中
// 设置浏览器以下载的方式处理该文件名 InputStream inStream = new FileInputStream(filePath + fileName);
response.setHeader("Content-Disposition", "attachment;filename=".concat(String.valueOf(URLEncoder.encode(exportName + ".doc", "UTF-8"))));
String agent = request.getHeader("User-Agent").toUpperCase();
File file = new File(rootPath + "/" + fileName + ".doc"); String encodedfileName = "";
try (InputStream fin = new FileInputStream(file); // IE
ServletOutputStream out = response.getOutputStream()) { if (agent.indexOf("MSIE") != -1 || agent.indexOf("TRIDENT") != -1) {
// 缓冲区 encodedfileName = URLEncoder.encode(fileName, "utf-8");
byte[] buffer = new byte[512]; // 谷歌或火狐
int bytesToRead; } else if (agent.indexOf("CHROME") != -1 || agent.indexOf("FIREFOX") != -1) {
// 通过循环将读入的Word文件的内容输出到浏览器中 encodedfileName = new String(fileName.getBytes("utf-8"), "ISO8859-1");
while ((bytesToRead = fin.read(buffer)) != -1) { } else {
out.write(buffer, 0, bytesToRead); encodedfileName = new String(fileName.getBytes("utf-8"), "ISO8859-1");
} }
// 设置输出的格式
response.reset();
response.setContentType("bin");
response.addHeader("Content-Disposition", "attachment; filename=\"" + encodedfileName + "\"");
// 循环取出流中的数据
byte[] b = new byte[100];
int len;
while ((len = inStream.read(b)) > 0) {
response.getOutputStream().write(b, 0, len);
}
inStream.close();
}
public static String getImageStr(String imgFile) {
InputStream in = null;
byte[] data = null;
try {
in = new FileInputStream(imgFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
data = new byte[in.available()];
//注:FileInputStream.available()方法可以从输入流中阻断由下一个方法调用这个输入流中读取的剩余字节数
in.read(data);
in.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} finally {
// 删除临时文件
file.delete();
} }
BASE64Encoder encoder = new BASE64Encoder();
return encoder.encode(data);
}
public static void main(String[] args) {
System.out.println(getImageStr("C:/aqpt/uploadPath/upload/signature/20220114095137.png"));
} }
} }
...@@ -111,7 +111,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter ...@@ -111,7 +111,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
// 过滤请求 // 过滤请求
.authorizeRequests() .authorizeRequests()
// 对于登录login 注册register 验证码captchaImage 允许匿名访问 // 对于登录login 注册register 验证码captchaImage 允许匿名访问
.antMatchers("/login","/app-api/login","/app-api/risk/plan/test", "/register", "/captchaImage").permitAll() .antMatchers("/login","/app-api/login", "/register", "/captchaImage").permitAll()
// 静态资源,可匿名访问 // 静态资源,可匿名访问
.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll() .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
.antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll() .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()
......
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