Commit d1cbeeae authored by suhuiguang's avatar suhuiguang

1.安全管理报表

2.二维码工具类
parent 6f7e8a74
......@@ -50,5 +50,10 @@
<groupId>com.yeejoin</groupId>
<artifactId>amos-component-rule</artifactId>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>javase</artifactId>
<version>3.3.0</version>
</dependency>
</dependencies>
</project>
......@@ -3,14 +3,19 @@ package com.yeejoin.equipmanage.common.utils;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import org.apache.commons.lang3.StringUtils;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Base64;
import java.util.Date;
import java.util.Hashtable;
import java.util.Random;
......@@ -19,117 +24,206 @@ import java.util.concurrent.locks.ReentrantLock;
/**
* 二维码工具类
* @author Administrator
*
* @author Administrator
*/
public class QRCodeUtil {
private static Random random = new Random();
private static Random random = new Random();
private static final String CHARSET = "utf-8";
private static final String CHARSET = "utf-8";
private static final String PREFIX_EQUIPMENT = "AMOS#PATROL#01#"; //平台#子系统#分类编码#
private static final String PREFIX_EQUIPMENT = "AMOS#PATROL#01#"; //平台#子系统#分类编码#
private static final int QRCODE_SIZE = 45;
private static final int QRCODE_SIZE = 45;
private static int randomNumForQrCode;
/**
*
* <pre>
* 根据当前记录ID生成QRCode
* </pre>
*
* @return
*/
public static String generateQRCode(Date dateCreated, String pointNo)
{
return String.valueOf(dateCreated.getTime() + pointNo);
}
private static int randomNumForQrCode;
/**
* <pre>
* 根据当前记录ID生成QRCode
* </pre>
*
* @return
*/
public static String generateQRCode(Date dateCreated, String pointNo) {
return String.valueOf(dateCreated.getTime() + pointNo);
}
/**
*
* <pre>
* 生成QRCode
* </pre>
*
* @param id
* @return
*/
public static String generateQRCode()
{
String res;
//加锁生成随机数,保证自增后释放
Lock lock = new ReentrantLock();
lock.lock();
randomNumForQrCode+=1;
//return String.valueOf(dateCreated.getTime() + id);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
try {
res = simpleDateFormat.format(new Date(System.currentTimeMillis())).substring(5,8) + String.valueOf(IdWorker.getFlowIdWorkerInstance().nextId()).substring(0,10)+randomNumForQrCode;
}catch (Exception e){
Random random = new Random(System.currentTimeMillis());
String tmp = "";
for (int i=0; i<13; i++){
tmp += random.nextInt(10);
}
res = simpleDateFormat.format(new Date(System.currentTimeMillis())).substring(2,8) + tmp.substring(0,10)+randomNumForQrCode;
}finally {
lock.unlock();
}
return res;
}
/**
* <pre>
* 生成QRCode
* </pre>
*
* @param id
* @return
*/
public static String generateQRCode() {
String res;
//加锁生成随机数,保证自增后释放
Lock lock = new ReentrantLock();
lock.lock();
randomNumForQrCode += 1;
//return String.valueOf(dateCreated.getTime() + id);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
try {
res = simpleDateFormat.format(new Date(System.currentTimeMillis())).substring(5, 8) + String.valueOf(IdWorker.getFlowIdWorkerInstance().nextId()).substring(0, 10) + randomNumForQrCode;
} catch (Exception e) {
Random random = new Random(System.currentTimeMillis());
String tmp = "";
for (int i = 0; i < 13; i++) {
tmp += random.nextInt(10);
}
res = simpleDateFormat.format(new Date(System.currentTimeMillis())).substring(2, 8) + tmp.substring(0, 10) + randomNumForQrCode;
} finally {
lock.unlock();
}
return res;
}
/**
* 生成临时的qrCode
*
* @return
*/
public static String temporaryQrCode() {
long qrCode = -1 * System.currentTimeMillis();
qrCode += (long)(random.nextDouble() * 10000000);
return String.valueOf(qrCode);
}
/**
* 根据二维码信息,生成二维码图片 用户excel,word等导出图片
*
* @param content
* @return
*/
public static byte[] generateQRCodeImageByteData(String content) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>();
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
hints.put(EncodeHintType.CHARACTER_SET, CHARSET);
hints.put(EncodeHintType.MARGIN, 1);
BitMatrix bitMatrix = new MultiFormatWriter().encode(
/*PREFIX_EQUIPMENT + */content
, BarcodeFormat.QR_CODE
, QRCODE_SIZE
, QRCODE_SIZE,
hints);
int width = bitMatrix.getWidth();
int height = bitMatrix.getHeight();
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF);
}
}
ImageIO.write(image, "png", out);
return out.toByteArray();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
/**
* 生成临时的qrCode
*
* @return
*/
public static String temporaryQrCode() {
long qrCode = -1 * System.currentTimeMillis();
qrCode += (long) (random.nextDouble() * 10000000);
return String.valueOf(qrCode);
}
/**
* 根据二维码信息,生成二维码图片 用户excel,word等导出图片
*
* @param content
* @return
*/
public static byte[] generateQRCodeImageByteData(String content) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>();
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
hints.put(EncodeHintType.CHARACTER_SET, CHARSET);
hints.put(EncodeHintType.MARGIN, 1);
BitMatrix bitMatrix = new MultiFormatWriter().encode(
/*PREFIX_EQUIPMENT + */content
, BarcodeFormat.QR_CODE
, QRCODE_SIZE
, QRCODE_SIZE,
hints);
int width = bitMatrix.getWidth();
int height = bitMatrix.getHeight();
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF);
}
}
ImageIO.write(image, "png", out);
return out.toByteArray();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
/**
* 生成简单的二维码
*
* @param text 二维码内容
* @param width 二维码宽度
* @param height 二维码高度
* @return String 图片base64
*/
public static String genQrCodeBase64Png(String text, int width, int height) {
ByteArrayOutputStream outputStream;
Base64.Encoder encoder;
try {
QRCodeWriter qrCodeWriter = new QRCodeWriter();
BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, width, height);
outputStream = new ByteArrayOutputStream();
MatrixToImageWriter.writeToStream(bitMatrix, "PNG", outputStream);
encoder = Base64.getEncoder();
} catch (Exception e) {
throw new RuntimeException("二维码生成失败");
}
return encoder.encodeToString(outputStream.toByteArray());
}
/**
* 生成带文字说明的二维码
*
* @param text 二维码内容
* @param width 二维码宽度
* @param height 二维码高度
* @param word 二维码下方文字说明
* @param wordHeight 二维码下方文字高度
* @return String 图片base64
*/
public static String genQrCodeBase64PngWithWord(String text, int width, int height, String word, int wordHeight) {
ByteArrayOutputStream outputStream;
Base64.Encoder encoder;
try {
QRCodeWriter qrCodeWriter = new QRCodeWriter();
BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, width, height);
BufferedImage image = MatrixToImageWriter.toBufferedImage(bitMatrix);
BufferedImage outImage = null;
if (StringUtils.isNotBlank(word)) {
outImage = new BufferedImage(width, wordHeight, BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D outg = outImage.createGraphics();
// 画二维码到新的面板
outg.drawImage(image, 0, 0, image.getWidth(), image.getHeight(), null);
// 画文字到新的面板
outg.setColor(Color.BLACK);
// 字体、字型、字号
outg.setFont(new Font("微软雅黑", Font.PLAIN, 16));
int strWidth = outg.getFontMetrics().stringWidth(word);
int singleFd = outg.getFontMetrics().stringWidth("2");
int grow = width / singleFd - 1;
//长度过长就截取超出二维码宽度部分换行
if (strWidth > width) {
String serialNum1 = word.substring(0, grow);
String serialNum2 = word.substring(grow, word.length());
outg.drawString(serialNum1, 5, image.getHeight() + (outImage.getHeight() - image.getHeight()) / 2);
BufferedImage outImage2 = new BufferedImage(width, wordHeight, BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D outg2 = outImage2.createGraphics();
outg2.drawImage(outImage, 0, 0, outImage.getWidth(), outImage.getHeight(), null);
outg2.setColor(Color.BLACK);
// 字体、字型、字号
outg2.setFont(new Font("微软雅黑", Font.PLAIN, 16));
//参数:显示的内容、起始位置x、起始的y
outg2.drawString(serialNum2, 5, outImage.getHeight() + (outImage2.getHeight() - outImage.getHeight()) / 2);
outg2.dispose();
outImage2.flush();
outImage = outImage2;
} else {
// 画文字
outg.drawString(word, (width - strWidth) / 2, image.getHeight() + (outImage.getHeight() - image.getHeight()) / 3);
}
outg.dispose();
outImage.flush();
image.flush();
}
outputStream = new ByteArrayOutputStream();
ImageIO.write(outImage, "PNG", outputStream);
encoder = Base64.getEncoder();
} catch (Exception e) {
throw new RuntimeException("二维码生成失败");
}
return encoder.encodeToString(outputStream.toByteArray());
}
public static void main(String[] args) {
System.out.println(genQrCodeBase64Png("101",100,100));
System.out.println(genQrCodeBase64PngWithWord("101",100,100,"sd",100));
}
}
package com.yeejoin.equipmanage.common.utils;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import com.aspose.words.License;
import com.aspose.words.SaveFormat;
import freemarker.template.Configuration;
import freemarker.template.Template;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import sun.misc.BASE64Encoder;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
import java.util.Map;
import java.util.Properties;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.WordUtils;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.http.MediaType;
import org.springframework.util.ResourceUtils;
public class WordTemplateUtils {
import com.aspose.words.License;
import com.aspose.words.SaveFormat;
import com.itextpdf.text.pdf.BaseFont;
import freemarker.cache.ClassTemplateLoader;
import freemarker.template.Configuration;
import freemarker.template.Template;
import sun.misc.BASE64Encoder;
private static String fileUploadDir;
public class WordTemplateUtils {
private Configuration configuration;
private static String fileUploadDir;
private Configuration configuration = null;
private static WordTemplateUtils wordTemplateUtils;
private WordTemplateUtils() {
configuration = new Configuration();
private static WordTemplateUtils wordTemplateUtils;
private WordTemplateUtils() {
configuration = new Configuration();
configuration.setDefaultEncoding("utf-8");
}
public static synchronized WordTemplateUtils getInstance(){
if(wordTemplateUtils == null){
//添加你的内容
Properties props;
try {
props = PropertiesLoaderUtils.loadAllProperties("application-dev.properties");
fileUploadDir = (String) props.get("file.uploadUrl");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
wordTemplateUtils = new WordTemplateUtils();
}
public static synchronized WordTemplateUtils getInstance() {
if (wordTemplateUtils == null) {
//添加你的内容
Properties props;
try {
props = PropertiesLoaderUtils.loadAllProperties("application-dev.properties");
fileUploadDir = (String) props.get("file.uploadUrl");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
wordTemplateUtils = new WordTemplateUtils();
}
return wordTemplateUtils;
}
public void exportMillCertificateWord(HttpServletRequest request, HttpServletResponse response, Map map,
String title, String ftlFile) throws IOException {
URL resourcePath = this.getClass().getClassLoader().getResource("ftl");
Resource resource = new ClassPathResource("ftl");// 配置路径 /config.xml
public void exportMillCertificateWord(HttpServletRequest request, HttpServletResponse response, Map map,
String title, String ftlFile) throws IOException {
configuration.setClassForTemplateLoading(this.getClass(), "/ftl");
// InputStream is = resource.getInputStream();
// InputStreamReader isr = new InputStreamReader(is);
// BufferedReader br = new BufferedReader(isr);
// String data = null;
// while((data = br.readLine()) != null) {
// //System.out.println(data);
// }
// br.close();
// isr.close();
// is.close();
//String path = ResourceUtils.getURL("classpath:").getPath();
//System.out.println(path);
//configuration.setDirectoryForTemplateLoading(new File(path));
// configuration.setTemplateLoader(new ClassTemplateLoader(
// this.getClass().getClassLoader(), "/ftl"));
Template freemarkerTemplate = configuration.getTemplate(ftlFile,"UTF-8");
File file = null;
InputStream fin = null;
ServletOutputStream out = null;
try {
// 调用工具类的createDoc方法生成Word文档
file = createDoc(map, freemarkerTemplate);
fin = new FileInputStream(file);
response.setCharacterEncoding("utf-8");
response.setContentType("application/msword");
// 设置浏览器以下载的方式处理该文件名
String fileName = (StringUtil.isNotEmpty(title) ? title : FileUtil.getUUID()) + ".doc";
response.setHeader("Content-Disposition",
"attachment;filename=".concat(String.valueOf(URLEncoder.encode(fileName, "UTF-8"))));
out = response.getOutputStream();
byte[] buffer = new byte[512]; // 缓冲区
int bytesToRead = -1;
// 通过循环将读入的Word文件的内容输出到浏览器中
while ((bytesToRead = fin.read(buffer)) != -1) {
out.write(buffer, 0, bytesToRead);
}
} finally {
if (fin != null){
fin.close();}
if (out != null){
out.close();}
if (file != null){
file.delete(); }// 删除临时文件
}
}
public File getWordFileItem(Map map,String title,String ftlFile) throws IOException {
URL resourcePath = this.getClass().getClassLoader().getResource("ftl");
Template freemarkerTemplate = configuration.getTemplate(ftlFile, "UTF-8");
File file = null;
InputStream fin = null;
ServletOutputStream out = null;
try {
// 调用工具类的createDoc方法生成Word文档
file = createDoc(map, freemarkerTemplate);
fin = new FileInputStream(file);
response.setCharacterEncoding("utf-8");
response.setContentType("application/msword");
// 设置浏览器以下载的方式处理该文件名
String fileName = (StringUtil.isNotEmpty(title) ? title : FileUtil.getUUID()) + ".doc";
response.setHeader("Content-Disposition",
"attachment;filename=".concat(String.valueOf(URLEncoder.encode(fileName, "UTF-8"))));
out = response.getOutputStream();
// 缓冲区
byte[] buffer = new byte[512];
int bytesToRead = -1;
// 通过循环将读入的Word文件的内容输出到浏览器中
while ((bytesToRead = fin.read(buffer)) != -1) {
out.write(buffer, 0, bytesToRead);
}
} finally {
if (fin != null) {
fin.close();
}
if (out != null) {
out.close();
}
if (file != null) {
file.delete();
}// 删除临时文件
}
}
public File getWordFileItem(Map map, String title, String ftlFile) throws IOException {
configuration.setClassForTemplateLoading(this.getClass(), "/ftl");
Template freemarkerTemplate = configuration.getTemplate(ftlFile,"UTF-8");
FileItemFactory factory = new DiskFileItemFactory(16, null);
String textFieldName = "file";
File file = null;
File filepdf = new File("sellPlan.pdf");
int bytesRead = 0;
byte[] buffer = new byte[10 * 1024 * 1024];
InputStream fin = null;
OutputStream os = null;
try {
// 调用工具类的createDoc方法生成Word文档
file = createDoc(map, freemarkerTemplate);
fin = new FileInputStream(file);
os = new FileOutputStream(filepdf);
wordTopdfByAspose(fin, os);
Template freemarkerTemplate = configuration.getTemplate(ftlFile, "UTF-8");
File file = null;
File filepdf = new File("sellPlan.pdf");
InputStream fin = null;
OutputStream os = null;
try {
// 调用工具类的createDoc方法生成Word文档
file = createDoc(map, freemarkerTemplate);
fin = new FileInputStream(file);
os = new FileOutputStream(filepdf);
wordTopdfByAspose(fin, os);
return filepdf;
} finally {
if (fin != null){
fin.close();}
if (os != null){
os.close();}
if (file != null){
file.delete(); }// 删除临时文件
}
}
private static File createDoc(Map<?, ?> dataMap, Template template) {
String name = "sellPlan.doc";
File f = new File(name);
Template t = template;
try {
// 这个地方不能使用FileWriter因为需要指定编码类型否则生成的Word文档会因为有无法识别的编码而无法打开
Writer w = new OutputStreamWriter(new FileOutputStream(f), "utf-8");
t.process(dataMap, w);
w.close();
} catch (Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex);
}
return f;
}
public boolean wordTopdfByAspose(InputStream inputStream, OutputStream outputStream) {
// 验证License 若不验证则转化出的pdf文档会有水印产生
if (!getLicense()) {
} finally {
if (fin != null) {
fin.close();
}
if (os != null) {
os.close();
}
if (file != null) {
file.delete();
}// 删除临时文件
}
}
private static File createDoc(Map<?, ?> dataMap, Template template) {
String name = "sellPlan.doc";
File f = new File(name);
Template t = template;
try {
// 这个地方不能使用FileWriter因为需要指定编码类型否则生成的Word文档会因为有无法识别的编码而无法打开
Writer w = new OutputStreamWriter(new FileOutputStream(f), "utf-8");
t.process(dataMap, w);
w.close();
} catch (Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex);
}
return f;
}
public boolean wordTopdfByAspose(InputStream inputStream, OutputStream outputStream) {
// 验证License 若不验证则转化出的pdf文档会有水印产生
if (!getLicense()) {
return false;
}
try {
// 将源文件保存在com.aspose.words.Document中,具体的转换格式依靠里面的save方法
// 将源文件保存在com.aspose.words.Document中,具体的转换格式依靠里面的save方法
com.aspose.words.Document doc = new com.aspose.words.Document(inputStream);
// 全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF,EPUB, XPS, SWF 相互转换
// 全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF,EPUB, XPS, SWF 相互转换
doc.save(outputStream, SaveFormat.PDF);
} catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
return false;
}finally {
} finally {
if (outputStream != null) {
try {
outputStream.flush();
......@@ -201,52 +155,55 @@ public class WordTemplateUtils {
}
return true;
}
// 官方文档的要求 无需理会
public static boolean getLicense() {
boolean result = false;
try {
String s = "<License><Data><Products><Product>Aspose.Total for Java</Product><Product>Aspose.Words for Java</Product></Products><EditionType>Enterprise</EditionType><SubscriptionExpiry>20991231</SubscriptionExpiry><LicenseExpiry>20991231</LicenseExpiry><SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7</SerialNumber></Data><Signature>sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=</Signature></License>";
ByteArrayInputStream is = new ByteArrayInputStream(s.getBytes());
License aposeLic = new License();
aposeLic.setLicense(is);
result = true;
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
// 获得图片的base64码
@SuppressWarnings("deprecation")
public String getImageBase(String src) {
if (src == null || src == "") {
return "";
}
if (StringUtil.isNotEmpty(src)) {
src = src.replaceAll("\\.\\.", "");
}
String fileName = fileUploadDir + src;
File file = new File(fileName);
if (!file.exists()) {
return "";
}
InputStream in = null;
byte[] data = null;
try {
in = new FileInputStream(file);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
try {
data = new byte[in.available()];
in.read(data);
in.close();
} catch (IOException e) {
e.printStackTrace();
}
BASE64Encoder encoder = new BASE64Encoder();
return encoder.encode(data);
}
}
// 官方文档的要求 无需理会
public static boolean getLicense() {
boolean result = false;
try {
String s = "<License><Data><Products><Product>Aspose.Total for Java</Product><Product>Aspose.Words for Java</Product></Products><EditionType>Enterprise</EditionType><SubscriptionExpiry>20991231</SubscriptionExpiry><LicenseExpiry>20991231</LicenseExpiry><SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7</SerialNumber></Data><Signature>sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=</Signature></License>";
ByteArrayInputStream is = new ByteArrayInputStream(s.getBytes());
License aposeLic = new License();
aposeLic.setLicense(is);
result = true;
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
/**
* 获得图片的base64码
* @param src 图片路径
* @return String
*/
@SuppressWarnings("deprecation")
public String getImageBase(String src) {
if (!StringUtil.isNotEmpty(src)) {
return "";
}
src = src.replaceAll("\\.\\.", "");
String fileName = fileUploadDir + src;
File file = new File(fileName);
if (!file.exists()) {
return "";
}
InputStream in = null;
byte[] data = null;
try {
in = new FileInputStream(file);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
try {
data = new byte[in.available()];
in.read(data);
in.close();
} catch (IOException e) {
e.printStackTrace();
}
BASE64Encoder encoder = new BASE64Encoder();
return encoder.encode(data);
}
}
......@@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.equipmanage.common.dto.AnalysisReportLogDto;
import com.yeejoin.equipmanage.service.IFireAutoSysManageReportService;
import com.yeejoin.equipmanage.service.IFirePatrolReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
......@@ -38,7 +37,7 @@ public class FireAutoSysManageReportController extends BaseController {
@ApiOperation(value = "下载报表", notes = "下载报表")
@GetMapping(value = "/download")
@TycloudOperation(ApiLevel = UserType.PUBLIC, needAuth = false)
@TycloudOperation(ApiLevel = UserType.AGENCY)
public void download(HttpServletRequest request, HttpServletResponse response,
@ApiParam(value = "换流站编码", required = true) @RequestParam String stationCode,
@ApiParam(value = "开始日期", required = true) @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
......@@ -48,7 +47,7 @@ public class FireAutoSysManageReportController extends BaseController {
@ApiOperation(value = "预览报表", notes = "预览报表")
@GetMapping(value = "/preview")
@TycloudOperation(ApiLevel = UserType.PUBLIC)
@TycloudOperation(ApiLevel = UserType.AGENCY)
public String preview(
@ApiParam(value = "换流站编码", required = true) @RequestParam String stationCode,
@ApiParam(value = "开始日期", required = true) @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
......@@ -59,7 +58,7 @@ public class FireAutoSysManageReportController extends BaseController {
@SuppressWarnings("unchecked")
@ApiOperation(value = "所有站查询列表", notes = "所有站查询列表")
@GetMapping(value = "/allPage")
@TycloudOperation(ApiLevel = UserType.PUBLIC)
@TycloudOperation(ApiLevel = UserType.AGENCY)
public IPage<AnalysisReportLogDto> allPage(Page page, @RequestParam Integer reportType,
@ApiParam(value = "开始日期") @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
@ApiParam(value = "结束日期") @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate,
......
......@@ -277,6 +277,7 @@ public class FilePatrolReportServiceImpl implements IFirePatrolReportService {
*/
public static StandardChartTheme createChartTheme(String fontName) {
StandardChartTheme theme = new StandardChartTheme("unicode") {
@Override
public void apply(JFreeChart chart) {
chart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
......@@ -379,9 +380,10 @@ public class FilePatrolReportServiceImpl implements IFirePatrolReportService {
WordTemplateUtils instance = WordTemplateUtils.getInstance();
Map<String, Object> map = getWordMap(code, startDate, endDate);
String urlString="";
File filepdf = null;
try {
//instance.pdfCreate(map, (String) map.get("document_number"), WordTemplateTypeEum.firePatrolReport.getTemplateFile());
File filepdf = instance.getWordFileItem(map,(String) map.get("document_number"), WordTemplateTypeEum.firePatrolReport.getTemplateFile());
filepdf = instance.getWordFileItem(map,(String) map.get("document_number"), WordTemplateTypeEum.firePatrolReport.getTemplateFile());
//MultipartFile multipartFile = new CommonsMultipartFile(item);
filepdf.getAbsolutePath();
// File file = new File("F:\\application-dev.yml");
......@@ -396,6 +398,10 @@ public class FilePatrolReportServiceImpl implements IFirePatrolReportService {
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if(filepdf != null){
filepdf.delete();
}
}
return urlString;
}
......
......@@ -259,8 +259,9 @@ public class FireAutoSysManageReportServiceImpl implements IFireAutoSysManageRep
WordTemplateUtils instance = WordTemplateUtils.getInstance();
Map<String, Object> map = getWordMap(code, startDate, endDate);
String urlString = "";
File filePdf = null;
try {
File filePdf = instance.getWordFileItem(map, (String) map.get("document_number"), WordTemplateTypeEum.fireAutoSysManageReport.getTemplateFile());
filePdf = instance.getWordFileItem(map, "消防自动化综合管理报表", WordTemplateTypeEum.fireAutoSysManageReport.getTemplateFile());
MultipartFile multipartFile = new MyByteArrayMultipartFile("file", "file.pdf", "application/pdf", file2byte(filePdf));
FeignClientResult<Map<String, String>> result = Systemctl.fileStorageClient.updateCommonFile(multipartFile);
if (result != null) {
......@@ -270,6 +271,10 @@ public class FireAutoSysManageReportServiceImpl implements IFireAutoSysManageRep
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if(filePdf != null){
filePdf.delete();
}
}
return urlString;
}
......
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