Commit d1cbeeae authored by suhuiguang's avatar suhuiguang

1.安全管理报表

2.二维码工具类
parent 6f7e8a74
...@@ -50,5 +50,10 @@ ...@@ -50,5 +50,10 @@
<groupId>com.yeejoin</groupId> <groupId>com.yeejoin</groupId>
<artifactId>amos-component-rule</artifactId> <artifactId>amos-component-rule</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>javase</artifactId>
<version>3.3.0</version>
</dependency>
</dependencies> </dependencies>
</project> </project>
...@@ -3,14 +3,19 @@ package com.yeejoin.equipmanage.common.utils; ...@@ -3,14 +3,19 @@ package com.yeejoin.equipmanage.common.utils;
import com.google.zxing.BarcodeFormat; import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType; import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter; import com.google.zxing.MultiFormatWriter;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix; import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import org.apache.commons.lang3.StringUtils;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Base64;
import java.util.Date; import java.util.Date;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Random; import java.util.Random;
...@@ -19,117 +24,206 @@ import java.util.concurrent.locks.ReentrantLock; ...@@ -19,117 +24,206 @@ import java.util.concurrent.locks.ReentrantLock;
/** /**
* 二维码工具类 * 二维码工具类
* @author Administrator
* *
* @author Administrator
*/ */
public class QRCodeUtil { 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; private static int randomNumForQrCode;
/**
*
* <pre>
* 根据当前记录ID生成QRCode
* </pre>
*
* @return
*/
public static String generateQRCode(Date dateCreated, String pointNo)
{
return String.valueOf(dateCreated.getTime() + pointNo);
}
/**
* <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等导出图片 * 生成临时的qrCode
* *
* @param content * @return
* @return */
*/ public static String temporaryQrCode() {
public static byte[] generateQRCodeImageByteData(String content) { long qrCode = -1 * System.currentTimeMillis();
ByteArrayOutputStream out = new ByteArrayOutputStream(); qrCode += (long) (random.nextDouble() * 10000000);
try { return String.valueOf(qrCode);
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); * 根据二维码信息,生成二维码图片 用户excel,word等导出图片
BitMatrix bitMatrix = new MultiFormatWriter().encode( *
/*PREFIX_EQUIPMENT + */content * @param content
, BarcodeFormat.QR_CODE * @return
, QRCODE_SIZE */
, QRCODE_SIZE, public static byte[] generateQRCodeImageByteData(String content) {
hints); ByteArrayOutputStream out = new ByteArrayOutputStream();
int width = bitMatrix.getWidth(); try {
int height = bitMatrix.getHeight(); Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>();
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
for (int x = 0; x < width; x++) { hints.put(EncodeHintType.CHARACTER_SET, CHARSET);
for (int y = 0; y < height; y++) { hints.put(EncodeHintType.MARGIN, 1);
image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF); BitMatrix bitMatrix = new MultiFormatWriter().encode(
} /*PREFIX_EQUIPMENT + */content
} , BarcodeFormat.QR_CODE
ImageIO.write(image, "png", out); , QRCODE_SIZE
return out.toByteArray(); , QRCODE_SIZE,
} catch (Exception e) { hints);
e.printStackTrace(); int width = bitMatrix.getWidth();
} finally { int height = bitMatrix.getHeight();
try { BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
out.close(); for (int x = 0; x < width; x++) {
} catch (IOException e) { for (int y = 0; y < height; y++) {
e.printStackTrace(); image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF);
} }
} }
return null; 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; package com.yeejoin.equipmanage.common.utils;
import java.io.BufferedReader; import com.aspose.words.License;
import java.io.ByteArrayInputStream; import com.aspose.words.SaveFormat;
import java.io.ByteArrayOutputStream; import freemarker.template.Configuration;
import java.io.File; import freemarker.template.Template;
import java.io.FileInputStream; import org.springframework.core.io.support.PropertiesLoaderUtils;
import java.io.FileNotFoundException; import sun.misc.BASE64Encoder;
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 javax.servlet.ServletOutputStream; 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.net.URLEncoder;
import java.util.Map;
import java.util.Properties;
import org.apache.commons.fileupload.FileItem; public class WordTemplateUtils {
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;
import com.aspose.words.License;
import com.aspose.words.SaveFormat;
import com.itextpdf.text.pdf.BaseFont;
import freemarker.cache.ClassTemplateLoader; private static String fileUploadDir;
import freemarker.template.Configuration;
import freemarker.template.Template;
import sun.misc.BASE64Encoder;
public class WordTemplateUtils { private Configuration configuration;
private static WordTemplateUtils wordTemplateUtils;
private static String fileUploadDir;
private WordTemplateUtils() {
private Configuration configuration = null; configuration = new Configuration();
private static WordTemplateUtils wordTemplateUtils;
private WordTemplateUtils() {
configuration = new Configuration();
configuration.setDefaultEncoding("utf-8"); configuration.setDefaultEncoding("utf-8");
} }
public static synchronized WordTemplateUtils getInstance(){ public static synchronized WordTemplateUtils getInstance() {
if(wordTemplateUtils == null){ if (wordTemplateUtils == null) {
//添加你的内容 //添加你的内容
Properties props; Properties props;
try { try {
props = PropertiesLoaderUtils.loadAllProperties("application-dev.properties"); props = PropertiesLoaderUtils.loadAllProperties("application-dev.properties");
fileUploadDir = (String) props.get("file.uploadUrl"); fileUploadDir = (String) props.get("file.uploadUrl");
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
wordTemplateUtils = new WordTemplateUtils(); wordTemplateUtils = new WordTemplateUtils();
} }
return wordTemplateUtils; return wordTemplateUtils;
} }
public void exportMillCertificateWord(HttpServletRequest request, HttpServletResponse response, Map map,
String title, String ftlFile) throws IOException { public void exportMillCertificateWord(HttpServletRequest request, HttpServletResponse response, Map map,
URL resourcePath = this.getClass().getClassLoader().getResource("ftl"); String title, String ftlFile) throws IOException {
Resource resource = new ClassPathResource("ftl");// 配置路径 /config.xml
configuration.setClassForTemplateLoading(this.getClass(), "/ftl"); configuration.setClassForTemplateLoading(this.getClass(), "/ftl");
// InputStream is = resource.getInputStream(); Template freemarkerTemplate = configuration.getTemplate(ftlFile, "UTF-8");
// InputStreamReader isr = new InputStreamReader(is); File file = null;
// BufferedReader br = new BufferedReader(isr); InputStream fin = null;
// String data = null; ServletOutputStream out = null;
// while((data = br.readLine()) != null) { try {
// //System.out.println(data); // 调用工具类的createDoc方法生成Word文档
// } file = createDoc(map, freemarkerTemplate);
// br.close(); fin = new FileInputStream(file);
// isr.close();
// is.close(); response.setCharacterEncoding("utf-8");
//String path = ResourceUtils.getURL("classpath:").getPath(); response.setContentType("application/msword");
//System.out.println(path); // 设置浏览器以下载的方式处理该文件名
//configuration.setDirectoryForTemplateLoading(new File(path)); String fileName = (StringUtil.isNotEmpty(title) ? title : FileUtil.getUUID()) + ".doc";
// configuration.setTemplateLoader(new ClassTemplateLoader( response.setHeader("Content-Disposition",
// this.getClass().getClassLoader(), "/ftl")); "attachment;filename=".concat(String.valueOf(URLEncoder.encode(fileName, "UTF-8"))));
Template freemarkerTemplate = configuration.getTemplate(ftlFile,"UTF-8");
File file = null; out = response.getOutputStream();
InputStream fin = null; // 缓冲区
ServletOutputStream out = null; byte[] buffer = new byte[512];
try { int bytesToRead = -1;
// 调用工具类的createDoc方法生成Word文档 // 通过循环将读入的Word文件的内容输出到浏览器中
file = createDoc(map, freemarkerTemplate); while ((bytesToRead = fin.read(buffer)) != -1) {
fin = new FileInputStream(file); out.write(buffer, 0, bytesToRead);
}
response.setCharacterEncoding("utf-8"); } finally {
response.setContentType("application/msword"); if (fin != null) {
// 设置浏览器以下载的方式处理该文件名 fin.close();
String fileName = (StringUtil.isNotEmpty(title) ? title : FileUtil.getUUID()) + ".doc"; }
response.setHeader("Content-Disposition", if (out != null) {
"attachment;filename=".concat(String.valueOf(URLEncoder.encode(fileName, "UTF-8")))); out.close();
}
out = response.getOutputStream(); if (file != null) {
file.delete();
byte[] buffer = new byte[512]; // 缓冲区 }// 删除临时文件
int bytesToRead = -1; }
// 通过循环将读入的Word文件的内容输出到浏览器中 }
while ((bytesToRead = fin.read(buffer)) != -1) {
out.write(buffer, 0, bytesToRead); public File getWordFileItem(Map map, String title, String ftlFile) throws IOException {
}
} 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");
configuration.setClassForTemplateLoading(this.getClass(), "/ftl"); configuration.setClassForTemplateLoading(this.getClass(), "/ftl");
Template freemarkerTemplate = configuration.getTemplate(ftlFile,"UTF-8"); Template freemarkerTemplate = configuration.getTemplate(ftlFile, "UTF-8");
FileItemFactory factory = new DiskFileItemFactory(16, null); File file = null;
String textFieldName = "file"; File filepdf = new File("sellPlan.pdf");
InputStream fin = null;
File file = null; OutputStream os = null;
File filepdf = new File("sellPlan.pdf"); try {
int bytesRead = 0; // 调用工具类的createDoc方法生成Word文档
byte[] buffer = new byte[10 * 1024 * 1024]; file = createDoc(map, freemarkerTemplate);
InputStream fin = null; fin = new FileInputStream(file);
OutputStream os = null; os = new FileOutputStream(filepdf);
try { wordTopdfByAspose(fin, os);
// 调用工具类的createDoc方法生成Word文档
file = createDoc(map, freemarkerTemplate);
fin = new FileInputStream(file);
os = new FileOutputStream(filepdf);
wordTopdfByAspose(fin, os);
return filepdf; return filepdf;
} finally { } finally {
if (fin != null){ if (fin != null) {
fin.close();} fin.close();
if (os != null){ }
os.close();} if (os != null) {
if (file != null){ os.close();
file.delete(); }// 删除临时文件 }
} 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; private static File createDoc(Map<?, ?> dataMap, Template template) {
try { String name = "sellPlan.doc";
// 这个地方不能使用FileWriter因为需要指定编码类型否则生成的Word文档会因为有无法识别的编码而无法打开 File f = new File(name);
Writer w = new OutputStreamWriter(new FileOutputStream(f), "utf-8"); Template t = template;
t.process(dataMap, w); try {
w.close(); // 这个地方不能使用FileWriter因为需要指定编码类型否则生成的Word文档会因为有无法识别的编码而无法打开
} catch (Exception ex) { Writer w = new OutputStreamWriter(new FileOutputStream(f), "utf-8");
ex.printStackTrace(); t.process(dataMap, w);
throw new RuntimeException(ex); w.close();
} } catch (Exception ex) {
return f; ex.printStackTrace();
} throw new RuntimeException(ex);
}
public boolean wordTopdfByAspose(InputStream inputStream, OutputStream outputStream) { return f;
// 验证License 若不验证则转化出的pdf文档会有水印产生 }
if (!getLicense()) {
public boolean wordTopdfByAspose(InputStream inputStream, OutputStream outputStream) {
// 验证License 若不验证则转化出的pdf文档会有水印产生
if (!getLicense()) {
return false; return false;
} }
try { try {
// 将源文件保存在com.aspose.words.Document中,具体的转换格式依靠里面的save方法 // 将源文件保存在com.aspose.words.Document中,具体的转换格式依靠里面的save方法
com.aspose.words.Document doc = new com.aspose.words.Document(inputStream); 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); doc.save(outputStream, SaveFormat.PDF);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return false; return false;
}finally { } finally {
if (outputStream != null) { if (outputStream != null) {
try { try {
outputStream.flush(); outputStream.flush();
...@@ -201,52 +155,55 @@ public class WordTemplateUtils { ...@@ -201,52 +155,55 @@ public class WordTemplateUtils {
} }
return true; return true;
} }
// 官方文档的要求 无需理会 // 官方文档的要求 无需理会
public static boolean getLicense() { public static boolean getLicense() {
boolean result = false; boolean result = false;
try { 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>"; 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()); ByteArrayInputStream is = new ByteArrayInputStream(s.getBytes());
License aposeLic = new License(); License aposeLic = new License();
aposeLic.setLicense(is); aposeLic.setLicense(is);
result = true; result = true;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return result; return result;
} }
// 获得图片的base64码
@SuppressWarnings("deprecation") /**
public String getImageBase(String src) { * 获得图片的base64码
if (src == null || src == "") { * @param src 图片路径
return ""; * @return String
} */
if (StringUtil.isNotEmpty(src)) { @SuppressWarnings("deprecation")
src = src.replaceAll("\\.\\.", ""); public String getImageBase(String src) {
} if (!StringUtil.isNotEmpty(src)) {
String fileName = fileUploadDir + src; return "";
File file = new File(fileName); }
if (!file.exists()) { src = src.replaceAll("\\.\\.", "");
return ""; String fileName = fileUploadDir + src;
} File file = new File(fileName);
InputStream in = null; if (!file.exists()) {
byte[] data = null; return "";
try { }
in = new FileInputStream(file); InputStream in = null;
} catch (FileNotFoundException e1) { byte[] data = null;
e1.printStackTrace(); try {
} in = new FileInputStream(file);
try { } catch (FileNotFoundException e1) {
data = new byte[in.available()]; e1.printStackTrace();
in.read(data); }
in.close(); try {
} catch (IOException e) { data = new byte[in.available()];
e.printStackTrace(); in.read(data);
} in.close();
BASE64Encoder encoder = new BASE64Encoder(); } catch (IOException e) {
return encoder.encode(data); e.printStackTrace();
} }
BASE64Encoder encoder = new BASE64Encoder();
return encoder.encode(data);
}
} }
...@@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; ...@@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.controller.BaseController; import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.equipmanage.common.dto.AnalysisReportLogDto; import com.yeejoin.equipmanage.common.dto.AnalysisReportLogDto;
import com.yeejoin.equipmanage.service.IFireAutoSysManageReportService; import com.yeejoin.equipmanage.service.IFireAutoSysManageReportService;
import com.yeejoin.equipmanage.service.IFirePatrolReportService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
...@@ -38,7 +37,7 @@ public class FireAutoSysManageReportController extends BaseController { ...@@ -38,7 +37,7 @@ public class FireAutoSysManageReportController extends BaseController {
@ApiOperation(value = "下载报表", notes = "下载报表") @ApiOperation(value = "下载报表", notes = "下载报表")
@GetMapping(value = "/download") @GetMapping(value = "/download")
@TycloudOperation(ApiLevel = UserType.PUBLIC, needAuth = false) @TycloudOperation(ApiLevel = UserType.AGENCY)
public void download(HttpServletRequest request, HttpServletResponse response, public void download(HttpServletRequest request, HttpServletResponse response,
@ApiParam(value = "换流站编码", required = true) @RequestParam String stationCode, @ApiParam(value = "换流站编码", required = true) @RequestParam String stationCode,
@ApiParam(value = "开始日期", required = true) @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate, @ApiParam(value = "开始日期", required = true) @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
...@@ -48,7 +47,7 @@ public class FireAutoSysManageReportController extends BaseController { ...@@ -48,7 +47,7 @@ public class FireAutoSysManageReportController extends BaseController {
@ApiOperation(value = "预览报表", notes = "预览报表") @ApiOperation(value = "预览报表", notes = "预览报表")
@GetMapping(value = "/preview") @GetMapping(value = "/preview")
@TycloudOperation(ApiLevel = UserType.PUBLIC) @TycloudOperation(ApiLevel = UserType.AGENCY)
public String preview( public String preview(
@ApiParam(value = "换流站编码", required = true) @RequestParam String stationCode, @ApiParam(value = "换流站编码", required = true) @RequestParam String stationCode,
@ApiParam(value = "开始日期", required = true) @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate, @ApiParam(value = "开始日期", required = true) @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
...@@ -59,7 +58,7 @@ public class FireAutoSysManageReportController extends BaseController { ...@@ -59,7 +58,7 @@ public class FireAutoSysManageReportController extends BaseController {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ApiOperation(value = "所有站查询列表", notes = "所有站查询列表") @ApiOperation(value = "所有站查询列表", notes = "所有站查询列表")
@GetMapping(value = "/allPage") @GetMapping(value = "/allPage")
@TycloudOperation(ApiLevel = UserType.PUBLIC) @TycloudOperation(ApiLevel = UserType.AGENCY)
public IPage<AnalysisReportLogDto> allPage(Page page, @RequestParam Integer reportType, 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 startDate,
@ApiParam(value = "结束日期") @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate, @ApiParam(value = "结束日期") @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate,
......
...@@ -277,6 +277,7 @@ public class FilePatrolReportServiceImpl implements IFirePatrolReportService { ...@@ -277,6 +277,7 @@ public class FilePatrolReportServiceImpl implements IFirePatrolReportService {
*/ */
public static StandardChartTheme createChartTheme(String fontName) { public static StandardChartTheme createChartTheme(String fontName) {
StandardChartTheme theme = new StandardChartTheme("unicode") { StandardChartTheme theme = new StandardChartTheme("unicode") {
@Override
public void apply(JFreeChart chart) { public void apply(JFreeChart chart) {
chart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING, chart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
...@@ -379,9 +380,10 @@ public class FilePatrolReportServiceImpl implements IFirePatrolReportService { ...@@ -379,9 +380,10 @@ public class FilePatrolReportServiceImpl implements IFirePatrolReportService {
WordTemplateUtils instance = WordTemplateUtils.getInstance(); WordTemplateUtils instance = WordTemplateUtils.getInstance();
Map<String, Object> map = getWordMap(code, startDate, endDate); Map<String, Object> map = getWordMap(code, startDate, endDate);
String urlString=""; String urlString="";
File filepdf = null;
try { try {
//instance.pdfCreate(map, (String) map.get("document_number"), WordTemplateTypeEum.firePatrolReport.getTemplateFile()); //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); //MultipartFile multipartFile = new CommonsMultipartFile(item);
filepdf.getAbsolutePath(); filepdf.getAbsolutePath();
// File file = new File("F:\\application-dev.yml"); // File file = new File("F:\\application-dev.yml");
...@@ -396,6 +398,10 @@ public class FilePatrolReportServiceImpl implements IFirePatrolReportService { ...@@ -396,6 +398,10 @@ public class FilePatrolReportServiceImpl implements IFirePatrolReportService {
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} finally {
if(filepdf != null){
filepdf.delete();
}
} }
return urlString; return urlString;
} }
......
...@@ -259,8 +259,9 @@ public class FireAutoSysManageReportServiceImpl implements IFireAutoSysManageRep ...@@ -259,8 +259,9 @@ public class FireAutoSysManageReportServiceImpl implements IFireAutoSysManageRep
WordTemplateUtils instance = WordTemplateUtils.getInstance(); WordTemplateUtils instance = WordTemplateUtils.getInstance();
Map<String, Object> map = getWordMap(code, startDate, endDate); Map<String, Object> map = getWordMap(code, startDate, endDate);
String urlString = ""; String urlString = "";
File filePdf = null;
try { 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)); MultipartFile multipartFile = new MyByteArrayMultipartFile("file", "file.pdf", "application/pdf", file2byte(filePdf));
FeignClientResult<Map<String, String>> result = Systemctl.fileStorageClient.updateCommonFile(multipartFile); FeignClientResult<Map<String, String>> result = Systemctl.fileStorageClient.updateCommonFile(multipartFile);
if (result != null) { if (result != null) {
...@@ -270,6 +271,10 @@ public class FireAutoSysManageReportServiceImpl implements IFireAutoSysManageRep ...@@ -270,6 +271,10 @@ public class FireAutoSysManageReportServiceImpl implements IFireAutoSysManageRep
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} finally {
if(filePdf != null){
filePdf.delete();
}
} }
return urlString; 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