Explorar el Código

Merge remote-tracking branch 'origin/master'

wangweiyu hace 4 años
padre
commit
34cbb1c785

+ 5 - 0
src/main/java/com/aoyang/tms/service/impl/WorkerServiceImpl.java

@@ -216,6 +216,11 @@ public class WorkerServiceImpl implements WorkerService {
                 //2.订单完成状态
                 workOrder.setOrderStatus(WorkOrderEnum.COMPLETED.orderStatus());
                 workOrder.setCompleteTime(LocalDateTime.now());
+                workOrder.setWeightingListNo(workOrderParam.getWeightingListNo());
+                workOrder.setWeightingListUrl(workOrderParam.getWeightingListUrl());
+                workOrder.setPiWeight(workOrderParam.getPiWeight());
+                workOrder.setMaoWeight(workOrderParam.getMaoWeight());
+                workOrder.setJingWeight(workOrderParam.getJingWeight());
                 workOrderService.updateById(workOrder);
 
                 //3.更新行车周期中的净重

+ 9 - 8
src/main/java/com/aoyang/tms/util/Picture.java

@@ -17,30 +17,31 @@ import org.apache.poi.util.IOUtils;
 public class Picture {
     public static void main(String[] args) throws Exception {
         /* Create a Workbook and Worksheet */
-        XSSFWorkbook my_workbook = new XSSFWorkbook();
-        XSSFSheet my_sheet = my_workbook.createSheet("MyLogo");
+        FileInputStream inputstream = new FileInputStream(new File("D:\\2.xlsx"));
+        XSSFWorkbook wb = new XSSFWorkbook(inputstream);
+        XSSFSheet sheet = wb.getSheetAt(0);//获取第一个sheet
         /* Read input PNG / JPG Image into FileInputStream Object*/
         InputStream my_banner_image = new FileInputStream("d:\\1.png");
         /* Convert picture to be added into a byte array */
         byte[] bytes = IOUtils.toByteArray(my_banner_image);
         /* Add Picture to Workbook, Specify picture type as PNG and Get an Index */
-        int my_picture_id = my_workbook.addPicture(bytes, Workbook.PICTURE_TYPE_PNG);
+        int my_picture_id = wb.addPicture(bytes, Workbook.PICTURE_TYPE_PNG);
         /* Close the InputStream. We are ready to attach the image to workbook now */
         my_banner_image.close();
         /* Create the drawing container */
-        XSSFDrawing drawing = my_sheet.createDrawingPatriarch();
+        XSSFDrawing drawing = sheet.createDrawingPatriarch();
         /* Create an anchor point */
         XSSFClientAnchor my_anchor = new XSSFClientAnchor();
         /* Define top left corner, and we can resize picture suitable from there */
-        my_anchor.setCol1(2);
-        my_anchor.setRow1(1);
+        my_anchor.setCol1(6);
+        my_anchor.setRow1(43);
         /* Invoke createPicture and pass the anchor point and ID */
         XSSFPicture my_picture = drawing.createPicture(my_anchor, my_picture_id);
         /* Call resize method, which resizes the image */
         my_picture.resize();
         /* Write changes to the workbook */
-        FileOutputStream out = new FileOutputStream(new File("D:\\日志.xlsx"));
-        my_workbook.write(out);
+        FileOutputStream out = new FileOutputStream(new File("D:\\3.xlsx"));
+        wb.write(out);
         out.close();
 
     }

+ 0 - 150
src/main/java/com/aoyang/tms/util/WriteImgUtil.java

@@ -1,150 +0,0 @@
-package com.aoyang.tms.util;
-
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
-import org.apache.poi.xssf.usermodel.XSSFDrawing;
-import org.apache.poi.xssf.usermodel.XSSFSheet;
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
-
-import javax.imageio.ImageIO;
-import java.awt.image.BufferedImage;
-import java.io.*;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @Description: Excel插入图片工具类
- * @Author guoyong
- * @Date 2022/4/26 13:52
- * @Version 1.0
- */
-
-public class WriteImgUtil {
-
-    /**
-     * 写入图片到Excel指定的位置
-     *
-     * @param patriarch 画图的顶级管理器,一个sheet只能获取一次,多次插入图片请使用同一个patriarch对象
-     * @param wb        HSSFWorkbook对象
-     * @param filepath  图片文件路径
-     * @param cellPoint 自定义的对象,指定要插入图片的坐标(x, y)
-     * @return cellPoint 自定义的对象,返回下一个要插入图片的坐标(x, y)
-     * @throws IOException
-     */
-    public static void whiteImg(XSSFDrawing patriarch, XSSFWorkbook wb, String filepath, CellPoint cellPoint) throws IOException {
-
-        ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
-        BufferedImage bufferImg = ImageIO.read(new File(filepath));
-        ImageIO.write(bufferImg, filepath.substring(filepath.lastIndexOf(".") + 1), byteArrayOut);
-
-        // 起点坐标
-        int x1 = cellPoint.getRow1();
-        int y1 = cellPoint.getCol1();
-        // 终点坐标
-        int x2 = cellPoint.getRow2();
-        int y2 = cellPoint.getCol2();
-        // anchor主要用于设置图片的属性
-        XSSFClientAnchor anchor1 = new XSSFClientAnchor(0, 0, 0, 0, (short) x1, y1, (short) x2, y2);
-        // 插入图片
-        int index = wb.addPicture(byteArrayOut.toByteArray(), XSSFWorkbook.PICTURE_TYPE_PICT);
-        patriarch.createPicture(anchor1, index);
-    }
-
-
-    public static class CellPoint {
-        // 起点横坐标
-        private int row1;
-        // 起点纵坐标
-        private int col1;
-        // 终点横坐标
-        private int row2;
-        // 终点纵坐标
-        private int col2;
-
-        public CellPoint(int row1, int col1, int row2, int col2) {
-            this.row1 = row1;
-            this.col1 = col1;
-            this.row2 = row2;
-            this.col2 = col2;
-        }
-
-        public int getRow1() {
-            return row1;
-        }
-
-        public void setRow1(int row1) {
-            this.row1 = row1;
-        }
-
-        public int getCol1() {
-            return col1;
-        }
-
-        public void setCol1(int col1) {
-            this.col1 = col1;
-        }
-
-        public int getRow2() {
-            return row2;
-        }
-
-        public void setRow2(int row2) {
-            this.row2 = row2;
-        }
-
-        public int getCol2() {
-            return col2;
-        }
-
-        public void setCol2(int col2) {
-            this.col2 = col2;
-        }
-    }
-
-    /**
-     * * 插入图片到指定excel
-     *
-     * @param file       待插入excel文件
-     * @param sheetIndex 待插入excel的Sheet序号(从0开始)
-     * @param map        key: 待插入图片路径  value: 图片在excel中的坐标
-     * @return
-     * @Date: 2020/11/28 10:09
-     */
-    public static void addImageToExcel(File file, Integer sheetIndex, Map<String, CellPoint> map) {
-        FileOutputStream fileOut = null;
-        try {
-            FileInputStream inputstream = new FileInputStream(file);
-            XSSFWorkbook wb = new XSSFWorkbook(inputstream);
-            XSSFSheet sheet1 = wb.getSheetAt(sheetIndex);
-            // 画图的顶级管理器,一个sheet只能获取一个(一定要注意这点)
-            XSSFDrawing patriarch = sheet1.createDrawingPatriarch();
-            for (Map.Entry<String, CellPoint> entry : map.entrySet()) {
-                String key = entry.getKey(); // 图片路径
-                CellPoint point = entry.getValue(); // 图片插入坐标
-                whiteImg(patriarch, wb, key, point);
-            }
-            fileOut = new FileOutputStream(file);
-            // 写入excel文件
-            wb.write(fileOut);
-        } catch (Exception e) {
-            e.printStackTrace();
-        } finally {
-            if (fileOut != null) {
-                try {
-                    fileOut.close();
-                } catch (IOException e) {
-                    e.printStackTrace();
-                }
-            }
-        }
-    }
-
-
-    public static void main(String[] args) throws IOException {
-        Map<String, CellPoint> map = new HashMap<>();
-        map.put("D:\\1.png", new CellPoint(46, 3, 48, 4));
-        addImageToExcel(new File("D:\\日志.xlsx"), 0, map);
-        System.out.println("ok");
-    }
-
-}