LongYuFei 2 سال پیش
والد
کامیت
450027e6c9

+ 37 - 6
ruoyi-admin/src/main/java/com/ruoyi/web/controller/wx/AttachmngsController.java

@@ -2,14 +2,29 @@ package com.ruoyi.web.controller.wx;
 
 
 import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.utils.AddWatermarkUtil;
+import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.system.domain.AttachMngs;
 import com.ruoyi.system.service.IAttachMngsService;
+import org.apache.commons.compress.utils.IOUtils;
+import org.apache.commons.fileupload.FileItem;
+import org.apache.commons.fileupload.disk.DiskFileItemFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.MediaType;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.commons.CommonsMultipartFile;
 
+import javax.imageio.ImageIO;
 import javax.servlet.http.HttpServletRequest;
+import java.awt.*;
+import java.awt.font.FontRenderContext;
+import java.awt.font.TextLayout;
+import java.awt.geom.AffineTransform;
+import java.awt.image.BufferedImage;
+import java.io.*;
+import java.text.SimpleDateFormat;
+import java.util.Date;
 import java.util.Map;
 
 @RestController
@@ -22,18 +37,37 @@ public class AttachmngsController {
     /**
      * 上传图片
      *
-     * @param file 图片
+     * @param file      图片
+     * @param longitude 经度
+     * @param latitude  纬度
      * @return
      * @throws Exception
      */
     @PostMapping
     public AjaxResult updateAttachmngs(@RequestParam("avatarfile") MultipartFile file,
                                        @RequestParam("attachId") Long attachId,
+                                       @RequestParam("longitude") String longitude,
+                                       @RequestParam("latitude") String latitude,
+                                       @RequestParam("updateDate") String date,
                                        HttpServletRequest request) throws Exception {
         if (file.isEmpty()) {
             return AjaxResult.error("上传失败请重试1");
         }
-        byte[] bytes = file.getBytes();
+
+
+        System.out.println("水印时间");
+        System.out.println(date);
+
+        // 水印
+        String watermark = longitude + "," + latitude + "-" + date;
+        File file2 = AddWatermarkUtil.transferToFile(file);
+        // addWaterMark(file2, file2, watermark);
+        AddWatermarkUtil.waterPress(file2, file2, Color.GRAY, 16, watermark);
+
+        // 转二进制
+        byte[] bytes = AddWatermarkUtil.fileToTransfer(file2).getBytes();
+
+        // 存储到数据库
         AttachMngs attachMngs = new AttachMngs();
         attachMngs.setSysId(1L);
         attachMngs.setAttachId(attachId);
@@ -45,9 +79,6 @@ public class AttachmngsController {
             return AjaxResult.error("上传失败请重试2");
         }
 
-        // String fileName = file.getOriginalFilename();
-        // String suffixName = fileName.substring(fileName.lastIndexOf("."));
-
         // 拼接url
         String serverName = request.getServerName();
         int serverPort = request.getServerPort();
@@ -67,7 +98,7 @@ public class AttachmngsController {
         return toPrimitives(img);
     }
 
-    // byte[] to Byte[]
+
     private Byte[] toObjects(byte[] bytesPrim) {
         Byte[] bytes = new Byte[bytesPrim.length];
 

+ 4 - 3
ruoyi-admin/src/main/java/com/ruoyi/web/controller/wx/OrderBillsPlansController.java

@@ -4,6 +4,7 @@ import cn.hutool.http.server.HttpServerRequest;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.system.domain.TmsAttachMngs;
 import com.ruoyi.system.domain.vo.OrderBillsPlansVo;
+import com.ruoyi.system.domain.vo.TmsAttachMngsVo;
 import com.ruoyi.system.service.IOrderBillsPlansService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -114,12 +115,12 @@ public class OrderBillsPlansController {
 
     /**
      * 插入主库图片数据
-     * @param tmsAttachMngs
+     * @param tmsAttachMngsVo
      * @return
      */
     @PostMapping("/attach-mngs")
-    public AjaxResult insertAttachMngs(@RequestBody TmsAttachMngs tmsAttachMngs) {
-        return orderBillsPlansService.insertAttachMngs(tmsAttachMngs);
+    public AjaxResult insertAttachMngs(@RequestBody TmsAttachMngsVo tmsAttachMngsVo) {
+        return orderBillsPlansService.insertAttachMngs(tmsAttachMngsVo);
     }
 
     /**

+ 219 - 0
ruoyi-common/src/main/java/com/ruoyi/common/utils/AddWatermarkUtil.java

@@ -0,0 +1,219 @@
+package com.ruoyi.common.utils;
+
+import org.apache.commons.compress.utils.IOUtils;
+import org.apache.commons.fileupload.FileItem;
+import org.apache.commons.fileupload.disk.DiskFileItemFactory;
+import org.springframework.http.MediaType;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.commons.CommonsMultipartFile;
+
+import javax.imageio.ImageIO;
+import java.awt.*;
+import java.awt.font.FontRenderContext;
+import java.awt.font.TextLayout;
+import java.awt.geom.AffineTransform;
+import java.awt.image.BufferedImage;
+import java.io.*;
+
+/**
+ * @ProjectName: test
+ * @Package: com.test.utils
+ * @ClassName: MyTest
+ * @Author: ***
+ * @Description:
+ * @Date: 2020/10/29 11:48
+ * @Version: 1.0
+ */
+public class AddWatermarkUtil {
+    public static void waterPress(File srcImgFile, File outputFile,
+                                  Color markContentColor, int fontSize, String waterMarkContent) {
+        try {
+            String[] waterMarkContents = waterMarkContent.split("\\|\\|");
+            // 读取原图片信息
+            Image srcImg = ImageIO.read(srcImgFile);
+            int srcImgWidth = srcImg.getWidth(null);
+            int srcImgHeight = srcImg.getHeight(null);
+            // 加水印
+            BufferedImage bufImg = new BufferedImage(srcImgWidth, srcImgHeight, BufferedImage.TYPE_INT_RGB);
+            // 得到画笔对象
+            Graphics2D g = bufImg.createGraphics();
+            // 设置起点
+            g.drawImage(srcImg, 0, 0, srcImgWidth, srcImgHeight, null);
+            Font font = new Font("Default", Font.PLAIN, fontSize);
+            // 水印透明度
+            g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5F));
+            // 根据图片的背景设置水印颜色
+            g.setColor(markContentColor);
+            // 设置水印文字字体
+            g.setFont(font);
+            // 数组长度
+            int contentLength = waterMarkContents.length;
+            // 获取水印文字中最长的
+            int maxLength = 0;
+            for (int i = 0; i < contentLength; i++) {
+                int fontlen = getWatermarkLength(waterMarkContents[i], g);
+                if (maxLength < fontlen) {
+                    maxLength = fontlen;
+                }
+            }
+
+            for (int j = 0; j < contentLength; j++) {
+                waterMarkContent = waterMarkContents[j];
+                int tempX = 10;
+                int tempY = fontSize;
+                // 单字符长度
+                int tempCharLen = 0;
+                // 单行字符总长度临时计算
+                int tempLineLen = 0;
+                StringBuffer sb = new StringBuffer();
+                for (int i = 0; i < waterMarkContent.length(); i++) {
+                    char tempChar = waterMarkContent.charAt(i);
+                    tempCharLen = getCharLen(tempChar, g);
+                    tempLineLen += tempCharLen;
+                    if (tempLineLen >= srcImgWidth) {
+                        // 长度已经满一行,进行文字叠加
+                        g.drawString(sb.toString(), tempX, tempY);
+                        // 清空内容,重新追加
+                        sb.delete(0, sb.length());
+                        tempLineLen = 0;
+                    }
+                    // 追加字符
+                    sb.append(tempChar);
+                }
+                // 通过设置后两个输入参数给水印定位
+                g.drawString(sb.toString(), 20, srcImgHeight - (contentLength - j - 1) * tempY - 50);
+            }
+            g.dispose();
+
+            // 输出图片
+            // 释放资源
+            g.dispose();
+            ImageIO.write(bufImg, "PNG", outputFile);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public static int getCharLen(char c, Graphics2D g) {
+        return g.getFontMetrics(g.getFont()).charWidth(c);
+    }
+
+    /**
+     * 获取水印文字总长度
+     *
+     * @paramwaterMarkContent水印的文字
+     * @paramg
+     * @return水印文字总长度
+     */
+    public static int getWatermarkLength(String waterMarkContent, Graphics2D g) {
+        return g.getFontMetrics(g.getFont()).charsWidth(
+                waterMarkContent.toCharArray(), 0, waterMarkContent.length());
+    }
+
+    /**
+     * 添加倾斜水印
+     *
+     * @param inputFile  图片
+     * @param outputFile
+     * @param text
+     * @throws IOException
+     */
+    public static void addWaterMark(File inputFile, File outputFile, String text) throws IOException {
+        Image image = ImageIO.read(inputFile);
+        int imgWidth = image.getWidth(null);// 获取图片的宽
+        int imgHeight = image.getHeight(null);// 获取图片的高
+
+        int angel = 315;// 旋转角度
+        int xpadding = 40;// 每个水印水平间隔
+        int ypadding = 40;// 每个水印垂直间隔
+        int fontSize = 10;
+
+        BufferedImage bi = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_INT_ARGB);
+
+        Graphics2D g = bi.createGraphics();
+        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+
+        // 绘制原图片
+        float alpha = 1F;
+        AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha);
+        g.setComposite(ac);
+        g.drawImage(image, 0, 0, imgWidth, imgHeight, null);
+        g.setBackground(Color.BLACK);
+
+        // 开始绘制水印
+        // 水印字体
+        Font font = new Font("Default", Font.BOLD, fontSize);
+        g.setFont(font);
+        FontRenderContext frc = g.getFontRenderContext();
+        TextLayout tl = new TextLayout(text, font, frc);
+        // 水印串宽度
+        int stringWidth = g.getFontMetrics(g.getFont()).charsWidth(text.toCharArray(), 0, text.length());
+
+        // 旋转水印
+        // g.rotate(Math.toRadians(angel), (double) imgWidth / 2, (double) imgHeight / 2);
+        // 水印透明度
+        // g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5F));
+        // 字体色
+        g.setColor(Color.RED);
+
+        int x = -imgHeight / 2;
+        int y = -imgWidth / 2;
+
+        // 循环绘制
+        while (x < imgWidth + imgHeight / 2) {
+            y = -imgWidth / 2;
+            while (y < imgHeight + imgWidth / 2) {
+                Shape sha = tl.getOutline(AffineTransform.getTranslateInstance(x, y));
+                g.fill(sha);
+
+                y += ypadding;
+            }
+            x += stringWidth + xpadding;
+        }
+
+        // 释放资源
+        g.dispose();
+        ImageIO.write(bi, "PNG", outputFile);
+    }
+
+    /**
+     * MultipartFile 转 File
+     * @param multipartFile
+     * @return
+     */
+    public static File transferToFile(MultipartFile multipartFile) {
+        //选择用缓冲区来实现这个转换即使用java 创建的临时文件 使用 MultipartFile.transferto()方法 。
+        File file = null;
+        try {
+            String originalFilename = multipartFile.getOriginalFilename();
+            String[] filename = originalFilename.split("\\.");
+            file = File.createTempFile(filename[0], filename[1]);
+            multipartFile.transferTo(file);
+            file.deleteOnExit();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return file;
+    }
+
+    /**
+     * File 转 MultipartFile
+     * @param file
+     * @return
+     */
+    public static MultipartFile fileToTransfer(File file) {
+        FileItem item = new DiskFileItemFactory().createItem("file"
+                , MediaType.MULTIPART_FORM_DATA_VALUE
+                , true
+                , file.getName());
+        try (InputStream input = new FileInputStream(file);
+             OutputStream os = item.getOutputStream()) {
+            // 流转移
+            IOUtils.copy(input, os);
+        } catch (Exception e) {
+            throw new IllegalArgumentException("Invalid file: " + e, e);
+        }
+
+        return new CommonsMultipartFile(item);
+    }
+}

+ 3 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/LoadFeeItems.java

@@ -66,4 +66,7 @@ public class LoadFeeItems {
     // private String itemProp;
     private String auditType;
 
+    @TableField(jdbcType = JdbcType.VARCHAR)
+    private String remarks;
+
 }

+ 18 - 0
ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/TmsAttachMngsVo.java

@@ -0,0 +1,18 @@
+package com.ruoyi.system.domain.vo;
+
+import com.ruoyi.system.domain.TmsAttachMngs;
+import lombok.Data;
+
+@Data
+public class TmsAttachMngsVo extends TmsAttachMngs {
+
+    /**
+     * 订单号
+     */
+    private String orderNo;
+
+    /**
+     * 图片上传时间
+     */
+    private String date;
+}

+ 3 - 2
ruoyi-system/src/main/java/com/ruoyi/system/service/IOrderBillsPlansService.java

@@ -4,6 +4,7 @@ import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.system.domain.*;
 import com.ruoyi.system.domain.vo.ItemsVo;
 import com.ruoyi.system.domain.vo.OrderBillsPlansVo;
+import com.ruoyi.system.domain.vo.TmsAttachMngsVo;
 
 import javax.servlet.http.HttpServletRequest;
 import java.util.List;
@@ -65,10 +66,10 @@ public interface IOrderBillsPlansService {
 
     /**
      * 插入主库图片数据
-     * @param tmsAttachMngs
+     * @param tmsAttachMngsVo
      * @return
      */
-    AjaxResult insertAttachMngs(TmsAttachMngs tmsAttachMngs);
+    AjaxResult insertAttachMngs(TmsAttachMngsVo tmsAttachMngsVo);
 
     /**
      * 根据attachId在Tms库的AttachMngs表删除数据

+ 20 - 12
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/OrderBillsPlansServiceImpl.java

@@ -9,6 +9,7 @@ import com.ruoyi.system.domain.*;
 import com.ruoyi.system.domain.vo.ImgVo;
 import com.ruoyi.system.domain.vo.ItemsVo;
 import com.ruoyi.system.domain.vo.OrderBillsPlansVo;
+import com.ruoyi.system.domain.vo.TmsAttachMngsVo;
 import com.ruoyi.system.mapper.EmplsMapper;
 import com.ruoyi.system.mapper.OrderBillsPlansMapper;
 import com.ruoyi.system.service.IOrderBillsPlansService;
@@ -21,6 +22,8 @@ import java.beans.Transient;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
+import static com.alibaba.fastjson.JSONPatch.OperationType.replace;
+
 /**
  * 火烈鸟数据库
  */
@@ -242,8 +245,8 @@ public class OrderBillsPlansServiceImpl implements IOrderBillsPlansService {
 
         for (LoadFeeItems loadFeeItems : orderBillsPlansVo.getLoadFeeItemsList()) {
 
-            if (loadFeeItems.getAmt() == 0)
-                break;
+            // if (loadFeeItems.getAmt() == 0)
+            //     break;
 
             orderBillsPlansMapper.updateOrderBillsPlansBySysidEntityidLineno(loadFeeItems);
 
@@ -301,27 +304,32 @@ public class OrderBillsPlansServiceImpl implements IOrderBillsPlansService {
     /**
      * 插入主库图片数据
      *
-     * @param tmsAttachMngs
+     * @param tmsAttachMngsVo
      * @return
      */
     @Override
-    public AjaxResult insertAttachMngs(TmsAttachMngs tmsAttachMngs) {
+    public AjaxResult insertAttachMngs(TmsAttachMngsVo tmsAttachMngsVo) {
 
         // 查询最大的lineNo进行+1赋值
-        Long lineNo = orderBillsPlansMapper.getAttachMngsBySysIdEntityId(tmsAttachMngs);
+        Long lineNo = orderBillsPlansMapper.getAttachMngsBySysIdEntityId(tmsAttachMngsVo);
+
+        lineNo = lineNo == null ? 1L : lineNo + 1;
 
         String username = SecurityUtils.getLoginUser().getUsername();
         Object actId = redisCache.getCacheObject("sys_config:risk.actId");
-        tmsAttachMngs.setActId(Long.valueOf(actId.toString()));
-        String replace = UUID.randomUUID().toString().replace("-", "");
-        tmsAttachMngs.setAttachName(replace + ".jpg");
-        tmsAttachMngs.setLineNo(lineNo == null ? 1L : lineNo + 1);
-        tmsAttachMngs.setUserName(username);
+        tmsAttachMngsVo.setActId(Long.valueOf(actId.toString()));
+        String orderNo = tmsAttachMngsVo.getOrderNo();
+        String date = tmsAttachMngsVo.getDate();
+
+
+        tmsAttachMngsVo.setAttachName(orderNo + "-" + date + "-" + lineNo + ".jpg");
+        tmsAttachMngsVo.setLineNo(lineNo);
+        tmsAttachMngsVo.setUserName(username);
 
         // 插入照片表
-        Integer i = orderBillsPlansMapper.insertAttachMngs(tmsAttachMngs);
+        Integer i = orderBillsPlansMapper.insertAttachMngs(tmsAttachMngsVo);
         // 查询AttachtypeId返回前端在照片库中插入
-        Long attachId = orderBillsPlansMapper.getAttachMngsAttachtypeIdBySysIdAndEntityIdAndLineNo(tmsAttachMngs);
+        Long attachId = orderBillsPlansMapper.getAttachMngsAttachtypeIdBySysIdAndEntityIdAndLineNo(tmsAttachMngsVo);
         return AjaxResult.success(attachId);
     }
 

+ 10 - 9
ruoyi-system/src/main/resources/mapper/system/OrderBillsPlansMapper.xml

@@ -52,14 +52,15 @@
     <update id="updateOrderBillsPlansBySysidEntityidLineno">
 
         update LoadFeeItems
-        set Price  = #{amt},
-            Amt    = #{amt},
-            AMT1   = #{amt},
-            AMT2   = #{amt},
-            AMTORG = #{amt}
-
+        set Price   = #{amt},
+            Amt     = #{amt},
+            AMT1    = #{amt},
+            AMT2    = #{amt},
+            AMTORG  = #{amt},
+            remarks = #{remarks}
         where sysId = '1'
-          AND entityid = #{entityId} and lineno = #{lineNo}
+          AND entityid = #{entityId}
+          and lineno = #{lineNo}
     </update>
     <update id="updateLoadBillsByEntityID">
         update LoadBills
@@ -239,11 +240,11 @@
           and dr1.SysID = 1
     </select>
     <select id="getLoadFeeItemsByEntityId" resultType="com.ruoyi.system.domain.LoadFeeItems">
-        select l.itemid, l.amt, i.cName, i.itemProp, i.auditType, l.lineNo, l.entityid
+        select l.itemid, l.amt, i.cName, i.itemProp, i.auditType, l.lineNo, l.entityid, l.remarks
         from LoadFeeItems l
                  inner join Items i on l.ItemID = i.ItemID
         where l.sysid = 1
-          and l.entityId = #{entityId}  order by i.zorder
+          and l.entityId = #{entityId}  order by l.lineno
     </select>
     <select id="getAttachMngsBySysIdEntityId" resultType="java.lang.Long">
         select MAX(lineNo) from AttachMngs where sysId = #{loadBillsSysId} and entityId = #{loadBillsEntityId}