houweiyu 4 年之前
父節點
當前提交
e4e25d46ff

+ 20 - 0
src/main/java/fcb/project/manager/base/entity/AuditRequestBean.java

@@ -0,0 +1,20 @@
+package fcb.project.manager.base.entity;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * 2 * @Author: Abner
+ * 3 * @Date: 2021/1/28 9:24
+ * 4
+ */
+
+@Data
+public class AuditRequestBean implements Serializable {
+
+    private  String id;
+    private Integer auditStatus;
+    private String auditRemark;
+
+}

+ 4 - 4
src/main/java/fcb/project/manager/base/utils/DataUtils.java

@@ -186,7 +186,7 @@ public class DataUtils {
     *
      * 根据上传的照片生成二维码
     * **/
-    public static boolean createQRCode(String url, String outPath, String logoPath) throws Exception {
+    public static boolean createQRCode(String url, String outPath, File logoPathFile) throws Exception {
         // 生成二维码
 
         int width = 300; // 二维码图片宽度 300
@@ -215,7 +215,7 @@ public class DataUtils {
         //File outputFile = new File("d:" + File.separator + "new-1.gif");//指定输出路径
         File outputFile = new File(outPath);//指定输出路径
         FileUtils.deleteFile(outPath);
-        return writeToFile(bitMatrix, format, outputFile, logoPath);
+        return writeToFile(bitMatrix, format, outputFile, logoPathFile);
     }
 
     public static BufferedImage toBufferedImage(BitMatrix matrix) {
@@ -231,11 +231,11 @@ public class DataUtils {
         return image;
     }
 
-    public static boolean writeToFile(BitMatrix matrix, String format, File file, String logoPath) throws IOException {
+    public static boolean writeToFile(BitMatrix matrix, String format, File file, File logoPathFile) throws IOException {
         BufferedImage image = toBufferedImage(matrix);
         //设置logo图标
         LogoConfig logoConfig = new LogoConfig();
-        image = logoConfig.LogoMatrix(image, logoPath);
+        image = logoConfig.LogoMatrix(image, logoPathFile);
 
         if(null == image){
             return false;

+ 6 - 7
src/main/java/fcb/project/manager/base/utils/LogoConfig.java

@@ -18,7 +18,7 @@ public class LogoConfig {
      * @throws IOException 
      * @author Administrator sangwenhao 
      */  
-     public BufferedImage LogoMatrix(BufferedImage matrixImage, String logoPath) throws IOException{
+     public BufferedImage LogoMatrix(BufferedImage matrixImage, File localFile) throws IOException{
          /** 
           * 读取二维码图片,并构建绘图对象 
           */  
@@ -29,20 +29,19 @@ public class LogoConfig {
          /**
           * 读取Logo图片
           */
-         if(logoPath == null){
+         if(localFile == null){
              URL url = this.getClass().getResource("logo.jpg");
              if(null != url){
-                 logoPath = url.getPath();
+                 localFile = new File(url.getPath());
              }
          }
-         if(null == logoPath){
+         if(!localFile.exists()){
+             log.info("{}文件不存在" , localFile.getAbsolutePath());
              return null;
          }
-
-         log.info("二维码源照片路径为:{}" , logoPath);
          BufferedImage logo = null;
          try {
-            logo = ImageIO.read(new File(logoPath));
+            logo = ImageIO.read(localFile);
          }catch (Exception e){
              log.info("读取二维码源文件出现异常:{}" , e);
              return null;

+ 276 - 0
src/main/java/fcb/project/manager/base/utils/QRCodeUtils.java

@@ -0,0 +1,276 @@
+package fcb.project.manager.base.utils;
+
+/**
+ * 2 * @Author: Abner
+ * 3 * @Date: 2021/1/27 21:35
+ * 4
+ */
+import java.awt.BasicStroke;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Image;
+import java.awt.Shape;
+import java.awt.geom.RoundRectangle2D;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.OutputStream;
+import java.util.Hashtable;
+import java.util.Random;
+
+import javax.imageio.ImageIO;
+
+import com.google.zxing.BarcodeFormat;
+import com.google.zxing.BinaryBitmap;
+import com.google.zxing.DecodeHintType;
+import com.google.zxing.EncodeHintType;
+import com.google.zxing.MultiFormatReader;
+import com.google.zxing.MultiFormatWriter;
+import com.google.zxing.Result;
+import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
+import com.google.zxing.common.BitMatrix;
+import com.google.zxing.common.HybridBinarizer;
+import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
+
+public class QRCodeUtils {
+    private static final String CHARSET = "utf-8";
+    private static final String FORMAT_NAME = "JPG";
+    // 二维码尺寸
+    private static final int QRCODE_SIZE = 300;
+    // LOGO宽度
+    private static final int WIDTH = 60;
+    // LOGO高度
+    private static final int HEIGHT = 60;
+
+    private static BufferedImage createImage(String content, String imgPath,
+                                             boolean needCompress) throws Exception {
+        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(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);
+            }
+        }
+        if (imgPath == null || "".equals(imgPath)) {
+            return image;
+        }
+        // 插入图片
+        QRCodeUtils.insertImage(image, imgPath, needCompress);
+        return image;
+    }
+
+    /**
+     * 插入LOGO
+     *
+     * @param source
+     *            二维码图片
+     * @param imgPath
+     *            LOGO图片地址
+     * @param needCompress
+     *            是否压缩
+     * @throws Exception
+     */
+    private static void insertImage(BufferedImage source, String imgPath,
+                                    boolean needCompress) throws Exception {
+        File file = new File(imgPath);
+        if (!file.exists()) {
+            System.err.println(""+imgPath+"   该文件不存在!");
+            return;
+        }
+        Image src = ImageIO.read(new File(imgPath));
+        int width = src.getWidth(null);
+        int height = src.getHeight(null);
+        if (needCompress) { // 压缩LOGO
+            if (width > WIDTH) {
+                width = WIDTH;
+            }
+            if (height > HEIGHT) {
+                height = HEIGHT;
+            }
+            Image image = src.getScaledInstance(width, height,
+                    Image.SCALE_SMOOTH);
+            BufferedImage tag = new BufferedImage(width, height,
+                    BufferedImage.TYPE_INT_RGB);
+            Graphics g = tag.getGraphics();
+            g.drawImage(image, 0, 0, null); // 绘制缩小后的图
+            g.dispose();
+            src = image;
+        }
+        // 插入LOGO
+        Graphics2D graph = source.createGraphics();
+        int x = (QRCODE_SIZE - width) / 2;
+        int y = (QRCODE_SIZE - height) / 2;
+        graph.drawImage(src, x, y, width, height, null);
+        Shape shape = new RoundRectangle2D.Float(x, y, width, width, 6, 6);
+        graph.setStroke(new BasicStroke(3f));
+        graph.draw(shape);
+        graph.dispose();
+    }
+
+    /**
+     * 生成二维码(内嵌LOGO)
+     *
+     * @param content
+     *            内容
+     * @param imgPath
+     *            LOGO地址
+     * @param destPath
+     *            存放目录
+     * @param needCompress
+     *            是否压缩LOGO
+     * @throws Exception
+     */
+    public static String encode(String content, String imgPath, String destPath,
+                                boolean needCompress) throws Exception {
+        BufferedImage image = QRCodeUtils.createImage(content, imgPath,
+                needCompress);
+        mkdirs(destPath);
+        String file = System.currentTimeMillis() +".jpg";
+        ImageIO.write(image, FORMAT_NAME, new File(destPath+"/"+file));
+        return file;
+    }
+
+    /**
+     * 当文件夹不存在时,mkdirs会自动创建多层目录,区别于mkdir.(mkdir如果父目录不存在则会抛出异常)
+     * @date 2013-12-11 上午10:16:36
+     * @param destPath 存放目录
+     */
+    public static void mkdirs(String destPath) {
+        File file =new File(destPath);
+        //当文件夹不存在时,mkdirs会自动创建多层目录,区别于mkdir.(mkdir如果父目录不存在则会抛出异常)
+        if (!file.exists() && !file.isDirectory()) {
+            file.mkdirs();
+        }
+    }
+
+    /**
+     * 生成二维码(内嵌LOGO)
+     *
+     * @param content
+     *            内容
+     * @param imgPath
+     *            LOGO地址
+     * @param destPath
+     *            存储地址
+     * @throws Exception
+     */
+    public static void encode(String content, String imgPath, String destPath)
+            throws Exception {
+        QRCodeUtils.encode(content, imgPath, destPath, false);
+    }
+
+    /**
+     * 生成二维码
+     *
+     * @param content
+     *            内容
+     * @param destPath
+     *            存储地址
+     * @param needCompress
+     *            是否压缩LOGO
+     * @throws Exception
+     */
+    public static void encode(String content, String destPath,
+                              boolean needCompress) throws Exception {
+        QRCodeUtils.encode(content, null, destPath, needCompress);
+    }
+
+    /**
+     * 生成二维码
+     *
+     * @param content
+     *            内容
+     * @param destPath
+     *            存储地址
+     * @throws Exception
+     */
+    public static void encode(String content, String destPath) throws Exception {
+        QRCodeUtils.encode(content, null, destPath, false);
+    }
+
+    /**
+     * 生成二维码(内嵌LOGO)
+     *
+     * @param content
+     *            内容
+     * @param imgPath
+     *            LOGO地址
+     * @param output
+     *            输出流
+     * @param needCompress
+     *            是否压缩LOGO
+     * @throws Exception
+     */
+    public static void encode(String content, String imgPath,
+                              OutputStream output, boolean needCompress) throws Exception {
+        BufferedImage image = QRCodeUtils.createImage(content, imgPath,
+                needCompress);
+        ImageIO.write(image, FORMAT_NAME, output);
+    }
+
+    /**
+     * 生成二维码
+     *
+     * @param content
+     *            内容
+     * @param output
+     *            输出流
+     * @throws Exception
+     */
+    public static void encode(String content, OutputStream output)
+            throws Exception {
+        QRCodeUtils.encode(content, null, output, false);
+    }
+
+    /**
+     * 解析二维码
+     *
+     * @param file
+     *            二维码图片
+     * @return
+     * @throws Exception
+     */
+    public static String decode(File file) throws Exception {
+        BufferedImage image;
+        image = ImageIO.read(file);
+        if (image == null) {
+            return null;
+        }
+        BufferedImageLuminanceSource source = new BufferedImageLuminanceSource(
+                image);
+        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
+        Result result;
+        Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
+        hints.put(DecodeHintType.CHARACTER_SET, CHARSET);
+        result = new MultiFormatReader().decode(bitmap, hints);
+        String resultStr = result.getText();
+        return resultStr;
+    }
+
+    /**
+     * 解析二维码
+     *
+     * @param path
+     *            二维码图片地址
+     * @return
+     * @throws Exception
+     */
+    public static String decode(String path) throws Exception {
+        return QRCodeUtils.decode(new File(path));
+    }
+
+    public static void main(String[] args) throws Exception {
+        String text = "http://www.baidu.com";  //这里设置自定义网站url
+        String logoPath = "C:\\Users\\4dage\\Desktop\\logo-file\\logo.jpg";
+        String destPath = "C:\\Users\\4dage\\Desktop\\logo-file";
+        System.out.println(QRCodeUtils.encode(text, logoPath, destPath, true));
+    }
+}

+ 17 - 16
src/main/java/fcb/project/manager/core/controller/AuditController.java

@@ -3,10 +3,7 @@ package fcb.project.manager.core.controller;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.metadata.IPage;
-import fcb.project.manager.base.entity.ContextTokenBean;
-import fcb.project.manager.base.entity.SceneRspBean;
-import fcb.project.manager.base.entity.TmAudit;
-import fcb.project.manager.base.entity.TmHouse;
+import fcb.project.manager.base.entity.*;
 import fcb.project.manager.base.enums.AuditStatus;
 import fcb.project.manager.base.enums.HouseStatus;
 import fcb.project.manager.base.service.custom.PanoService;
@@ -98,15 +95,19 @@ public class AuditController extends BaseController{
             @ApiImplicitParam(name = "auditRemark", value = "审核备注", paramType = "query", required = true, dataType = "String"),
     })
     @Transactional(rollbackFor = Exception.class)
-    public Result<Object> audit(String id , Integer auditStatus , String auditRemark , HttpServletRequest request){
+    public Result<Object> audit(@RequestBody AuditRequestBean auditRequestBean , HttpServletRequest request){
 
-        if(StringUtils.isBlank(id) || null == auditStatus){
+        if(null == auditRequestBean){
+            return Result.failure("请求体为空");
+        }
+        if(null == auditRequestBean.getId() || null == auditRequestBean.getAuditStatus()){
             return Result.failure("审核记录ID或者审核结果不能为空");
         }
-        if(AuditStatus.WAITING_AUDIT.getCode().compareTo(auditStatus) == 0){
-            return Result.failure("审核结构非法");
+        if(AuditStatus.AUDITED.getCode().compareTo(auditRequestBean.getAuditStatus()) != 0
+          && AuditStatus.REJECT.getCode().compareTo(auditRequestBean.getAuditStatus()) != 0){
+            return Result.failure("审核结果非法");
         }
-        TmAudit tmAudit = tmAuditService.getById(id);
+        TmAudit tmAudit = tmAuditService.getById(auditRequestBean.getId());
         if(null == tmAudit){
             return Result.failure("审核记录不存在");
         }
@@ -118,22 +119,22 @@ public class AuditController extends BaseController{
 
         //这里要先锁定当前审核记录
         tmAudit = null;
-        tmAudit = tmAuditService.selectForUpdate(id);
+        tmAudit = tmAuditService.selectForUpdate(auditRequestBean.getId());
         if(null == tmAudit){
-            log.info("更新审核状态环节,审核记录[{}]抢锁失败" , id);
+            log.info("更新审核状态环节,审核记录[{}]抢锁失败" , auditRequestBean.getId());
             return Result.failure("抢锁失败");
         }
         TmHouse dbHouse = tmHouseService.selectForUpdate(tmAudit.getVrId());
         if(null == dbHouse){
-            log.info("更新审核状态环节,审核记录[{}]抢锁失败" , id);
+            log.info("更新审核状态环节,审核记录[{}]抢锁失败" , auditRequestBean.getId());
             return Result.failure("抢锁失败");
         }
         if(HouseStatus.AUDITED.getCode().compareTo(dbHouse.getStatus()) == 0 &&
                 AuditStatus.AUDITED.getCode().compareTo(tmAudit.getAuditStatus()) == 0){
             return Result.failure("已经审通批过了,无需重复处理");
         }
-        tmAudit.setAuditStatus(auditStatus);
-        tmAudit.setAuditRemark(auditRemark);
+        tmAudit.setAuditStatus(auditRequestBean.getAuditStatus());
+        tmAudit.setAuditRemark(auditRequestBean.getAuditRemark());
         tmAudit.setAuditorId(tokenMap.getId());
         tmAudit.setAuditTime(LocalDateTime.now());
         tmAudit.setAuditorName(tokenMap.getNickName());
@@ -143,7 +144,7 @@ public class AuditController extends BaseController{
         }
         String auditResultStr = "";
         Map<String , Object> map = new HashMap<>();
-        if(AuditStatus.AUDITED.getCode().compareTo(auditStatus) == 0){
+        if(AuditStatus.AUDITED.getCode().compareTo(auditRequestBean.getAuditStatus()) == 0){
             auditResultStr = "审核通过";
             dbHouse.setStatus(HouseStatus.AUDITED.getCode());
             dbHouse.setOnline(1);
@@ -165,7 +166,7 @@ public class AuditController extends BaseController{
                 }
 
             }
-        }else if(AuditStatus.REJECT.getCode().compareTo(auditStatus) == 0){
+        }else if(AuditStatus.REJECT.getCode().compareTo(auditRequestBean.getAuditStatus()) == 0){
             auditResultStr = "审核不通过";
             dbHouse.setStatus(HouseStatus.REJECT.getCode());
         }

+ 22 - 5
src/main/java/fcb/project/manager/core/controller/HouseManagerController.java

@@ -31,6 +31,8 @@ import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
+import java.io.File;
+import java.io.IOException;
 import java.time.LocalDateTime;
 import java.util.HashMap;
 import java.util.Map;
@@ -164,8 +166,9 @@ public class HouseManagerController extends BaseController{
             String localPath = imageLocalPath + "logo.png";
             String outPutImageName = System.currentTimeMillis() + ".jpg";
             String outPutImageResultPath = imageLocalPath + outPutImageName;
+            File localPathFile = new File(localPath);
             try {
-                if(!DataUtils.createQRCode(totalVrUrl ,  outPutImageResultPath , localPath)){
+                if(!DataUtils.createQRCode(totalVrUrl ,  outPutImageResultPath , localPathFile)){
                     log.info("生成分享二维码失败");
                     return Result.failure("生成分享二维码失败");
                 }
@@ -216,15 +219,29 @@ public class HouseManagerController extends BaseController{
         if(StringUtils.isBlank(newFileName)){
             return Result.failure("获取文件后缀名失败");
         }
-        String downLoanVideoPath = FileUtils.parseFile(file, imageLocalPath  , newFileName);
-        log.info("照片文件已经下载到本地:{}", downLoanVideoPath);
-
+        String fullLocalImagePath = imageLocalPath.concat(newFileName);
+        log.info("照片文件下载到本地路径为:{}", fullLocalImagePath);
+        File totalFile = new File(fullLocalImagePath);
+        if(totalFile.exists()){
+            totalFile.delete();
+        }
+        try {
+            file.transferTo(totalFile);
+        } catch (IOException e) {
+            e.printStackTrace();
+            log.info("照片文件已经下载到本地出现异常:{}", e);
+            return Result.failure("下载文件出现异常");
+        }
+        if(!totalFile.exists()){
+            log.info("下载文件失败:{}" , fullLocalImagePath);
+            return Result.failure("上传文件失败");
+        }
         String totalVrUrl = outerSceneVrHost + sceneVrLink + tmHouse.getSceneNum() + "&prodId=" + tmHouse.getFcbHouseId()
                 + "&houseId=" + tmHouse.getId();
         String outPutImageName = System.currentTimeMillis() + ".jpg";
         String outPutImageResultPath = imageLocalPath + outPutImageName;
         try {
-            if(!DataUtils.createQRCode(totalVrUrl ,  outPutImageResultPath , downLoanVideoPath)){
+            if(!DataUtils.createQRCode(totalVrUrl ,  outPutImageResultPath , totalFile)){
                 return Result.failure("生成分享二维码失败");
             }
         } catch (Exception e) {