|
@@ -14,10 +14,12 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
+import java.awt.*;
|
|
|
import java.awt.image.BufferedImage;
|
|
|
import java.io.*;
|
|
|
import java.net.URL;
|
|
|
import java.util.*;
|
|
|
+import java.util.List;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
|
/**
|
|
@@ -47,7 +49,7 @@ public class UploadServiceImpl implements UploadService {
|
|
|
int index = originalFilename.lastIndexOf(".");
|
|
|
String extName = originalFilename.substring(index);
|
|
|
String filePath = "/mnt/newdatadrive/data/runtime/jar-instance/zplma/tempFile/";
|
|
|
- if ("dev".equals(active)){
|
|
|
+ if ("dev".equals(active)) {
|
|
|
filePath = "D:\\WorkSpace\\file\\tempImport\\";
|
|
|
}
|
|
|
filePath += randomStr + extName;
|
|
@@ -87,16 +89,17 @@ public class UploadServiceImpl implements UploadService {
|
|
|
|
|
|
/**
|
|
|
* 创建图片压缩包
|
|
|
+ *
|
|
|
* @param fileMap
|
|
|
- * @param type 1机构授权牌,2设备授权牌,3机构二维码,4设备二维码,5资料库图片压缩包
|
|
|
+ * @param type 1机构授权牌,2设备授权牌,3机构二维码,4设备二维码,5资料库图片压缩包
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
@Override
|
|
|
- public String createImageZip(Map<String,List<UploadFilePo>> fileMap, Integer type) throws Exception {
|
|
|
+ public String createImageZip(Map<String, List<UploadFilePo>> fileMap, Integer type) throws Exception {
|
|
|
String randomStr = UUID.randomUUID().toString();
|
|
|
String filePath = "/mnt/newdatadrive/data/runtime/jar-instance/zplma/tempImage/";
|
|
|
- if ("dev".equals(active)){
|
|
|
+ if ("dev".equals(active)) {
|
|
|
filePath = "D:\\uploadZip\\";
|
|
|
}
|
|
|
// 压缩文件夹上层临时文件夹路径
|
|
@@ -187,9 +190,55 @@ public class UploadServiceImpl implements UploadService {
|
|
|
UploadFilePo file = fileList.get(i);
|
|
|
String fileUrl = file.getFileUrl();
|
|
|
String fileName = file.getFileName();
|
|
|
- BufferedImage qrCodeImage = ImageUtils.createQrCode(fileUrl, QrCodeSize.LARGE);
|
|
|
+ BufferedImage qrCodeImage = ImageUtils.createQrCode(fileUrl, QrCodeSize.MLARGE);
|
|
|
String tempFilePath = filePath + "/" + fileName;
|
|
|
- ImageUtils.transferBufferdImage(qrCodeImage, tempFilePath, "png");
|
|
|
+ // 加载背景图片
|
|
|
+ BufferedImage backgroundImage = ImageIO.read(new File("/mnt/newdatadrive/data/runtime/jar-instance/zplma/background.png"));
|
|
|
+ // 设置文字
|
|
|
+ String title = file.getAuthName() + "正品授权";
|
|
|
+ String bottom = file.getFileName();
|
|
|
+ // 计算二维码和文字的位置
|
|
|
+ int qrCodeX = (backgroundImage.getWidth() - qrCodeImage.getWidth()) / 2;
|
|
|
+ int qrCodeY = (backgroundImage.getHeight() - qrCodeImage.getHeight()) / 2 + 25;
|
|
|
+ // 文字距离图片顶部的距离,可以根据需要调整
|
|
|
+ int textY = 30;
|
|
|
+ // 创建新图片,使用背景图片的尺寸
|
|
|
+ BufferedImage finalImage = new BufferedImage(backgroundImage.getWidth(), backgroundImage.getHeight(), BufferedImage.TYPE_INT_RGB);
|
|
|
+ // 获取Graphics2D对象进行绘制
|
|
|
+ Graphics2D g2d = finalImage.createGraphics();
|
|
|
+ // 抗锯齿
|
|
|
+ g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
|
|
+ g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
|
|
|
+ g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
|
|
+ // 绘制背景图片
|
|
|
+ g2d.drawImage(backgroundImage, 0, 0, null);
|
|
|
+ // 绘制二维码
|
|
|
+ g2d.drawImage(qrCodeImage, qrCodeX, qrCodeY, null);
|
|
|
+ // 设置字体和颜色 字体大小可根据需要调整
|
|
|
+ g2d.setFont(new Font("微软雅黑", Font.BOLD, 20));
|
|
|
+ g2d.setColor(Color.WHITE);
|
|
|
+ // 绘制文字 如果抬头或者底部字数大于14,需要手动计算换行
|
|
|
+ if (title.length() > 14) {
|
|
|
+ // 计算文字的X坐标,使其居中显示
|
|
|
+ FontMetrics metrics = g2d.getFontMetrics();
|
|
|
+ String first = title.substring(0, 14);
|
|
|
+ String second = title.substring(14);
|
|
|
+ int textX = (finalImage.getWidth() - metrics.stringWidth(first)) / 2;
|
|
|
+ int textS = (finalImage.getWidth() - metrics.stringWidth(second)) / 2;
|
|
|
+ g2d.drawString(first, textX, textY);
|
|
|
+ g2d.drawString(second, textS, textY + 20);
|
|
|
+ int textB = (finalImage.getWidth() - metrics.stringWidth(bottom)) / 2;
|
|
|
+ g2d.drawString(bottom, textB, 370);
|
|
|
+ } else {
|
|
|
+ // 计算文字的X坐标,使其居中显示
|
|
|
+ FontMetrics metrics = g2d.getFontMetrics();
|
|
|
+ int textX = (finalImage.getWidth() - metrics.stringWidth(title)) / 2;
|
|
|
+ g2d.drawString(title, textX, textY);
|
|
|
+ g2d.drawString(bottom, textX, 370);
|
|
|
+ }
|
|
|
+ ImageUtils.transferBufferdImage(finalImage, tempFilePath, "png");
|
|
|
+ // 清理资源
|
|
|
+ g2d.dispose();
|
|
|
}
|
|
|
} else if (4 == type) {
|
|
|
// 设备二维码
|
|
@@ -206,9 +255,52 @@ public class UploadServiceImpl implements UploadService {
|
|
|
UploadFilePo file = fileList.get(i);
|
|
|
String fileUrl = file.getFileUrl();
|
|
|
String fileName = file.getFileName();
|
|
|
- BufferedImage qrCodeImage = ImageUtils.createQrCode(fileUrl, QrCodeSize.LARGE);
|
|
|
+ BufferedImage qrCodeImage = ImageUtils.createQrCode(fileUrl, QrCodeSize.MLARGE);
|
|
|
+ // 0位置仪器名称 1位置sn码
|
|
|
+ String[] split = fileName.split("-");
|
|
|
+ // 加载背景图片
|
|
|
+ BufferedImage backgroundImage = ImageIO.read(new File("/mnt/newdatadrive/data/runtime/jar-instance/zplma/snback.png"));
|
|
|
+ // 设置文字
|
|
|
+ String text = split[0];
|
|
|
+ String bot = "";
|
|
|
+ if (split[1].length() < 3) {
|
|
|
+ bot = "仪器SN码:" + split[1] + "******" + split[1];
|
|
|
+ } else {
|
|
|
+ bot = "仪器SN码:" + split[1].substring(0, 2) + "******" + split[1].substring(0, 3);
|
|
|
+ }
|
|
|
+ // 计算二维码和文字的位置
|
|
|
+ int qrCodeX = (backgroundImage.getWidth() - qrCodeImage.getWidth()) / 2;
|
|
|
+ int qrCodeY = (backgroundImage.getHeight() - qrCodeImage.getHeight()) / 2 + 58;
|
|
|
+ // 文字距离图片顶部的距离,可以根据需要调整
|
|
|
+ int textY = 30;
|
|
|
+ // 创建新图片,使用背景图片的尺寸
|
|
|
+ BufferedImage finalImage = new BufferedImage(backgroundImage.getWidth(), backgroundImage.getHeight(), BufferedImage.TYPE_INT_RGB);
|
|
|
+ // 获取Graphics2D对象进行绘制
|
|
|
+ Graphics2D g2d = finalImage.createGraphics();
|
|
|
+ // 抗锯齿
|
|
|
+ g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
|
|
+ g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
|
|
|
+ g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
|
|
+ // 绘制背景图片
|
|
|
+ g2d.drawImage(backgroundImage, 0, 0, null);
|
|
|
+ // 绘制二维码
|
|
|
+ g2d.drawImage(qrCodeImage, qrCodeX, qrCodeY, null);
|
|
|
+ // 设置字体和颜色 字体大小可根据需要调整
|
|
|
+ g2d.setFont(new Font("微软雅黑", Font.BOLD, 20));
|
|
|
+ g2d.setColor(Color.WHITE);
|
|
|
+ // 计算文字的X坐标,使其居中显示
|
|
|
+ FontMetrics metrics = g2d.getFontMetrics();
|
|
|
+ int textX = (finalImage.getWidth() - metrics.stringWidth(text)) / 2;
|
|
|
+ g2d.drawString(text, textX, textY);
|
|
|
+ // 设置字体和颜色 字体大小可根据需要调整
|
|
|
+ g2d.setFont(new Font("微软雅黑", Font.BOLD, 14));
|
|
|
+ Color customColor = new Color(27, 163, 240);
|
|
|
+ g2d.setColor(customColor);
|
|
|
+ int textB = (finalImage.getWidth() - metrics.stringWidth(bot)) / 2 + 33;
|
|
|
+ g2d.drawString(bot, textB, 90);
|
|
|
String tempFilePath = filePath + "/" + fileName;
|
|
|
- ImageUtils.transferBufferdImage(qrCodeImage, tempFilePath, "png");
|
|
|
+ ImageUtils.transferBufferdImage(finalImage, tempFilePath, "png");
|
|
|
+ g2d.dispose();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -220,7 +312,7 @@ public class UploadServiceImpl implements UploadService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public String saveFileByUrl(String url,String fileName) throws Exception {
|
|
|
+ public String saveFileByUrl(String url, String fileName) throws Exception {
|
|
|
InputStream input = new URL(url).openStream();
|
|
|
File file = inputStreamToFile(input, fileName);
|
|
|
String filePath = System.getProperty("java.io.tmpdir") + File.separator + fileName;
|
|
@@ -234,10 +326,10 @@ public class UploadServiceImpl implements UploadService {
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 工具类
|
|
|
+ * 工具类
|
|
|
* inputStream 转 File
|
|
|
*/
|
|
|
- public static File inputStreamToFile(InputStream ins, String name) throws Exception{
|
|
|
+ public static File inputStreamToFile(InputStream ins, String name) throws Exception {
|
|
|
// File file = new File(System.getProperty("java.io.tmpdir") + File.separator + name);
|
|
|
File file = new File("D:\\uploadZip\\机构二维码\\" + File.separator + name);
|
|
|
if (file.exists()) {
|