xiaochen 2 سال پیش
والد
کامیت
e1cd5cf9ce

+ 10 - 7
build.gradle

@@ -32,16 +32,19 @@ dependencies {
     implementation 'cn.hutool:hutool-captcha:5.8.5'
     implementation 'org.springframework.boot:spring-boot-starter-aop'
     implementation 'org.springframework.boot:spring-boot-starter-data-redis:2.5.4'
+    //接口调用
+    implementation 'org.apache.httpcomponents:httpclient:4.5.2'
+    implementation 'org.iherus:qrext4j:1.3.0'
+    implementation 'cn.afterturn:easypoi-base:4.0.0'
+    implementation 'cn.afterturn:easypoi-web:4.0.0'
+    implementation 'cn.afterturn:easypoi-annotation:4.0.0'
 //    implementation 'com.google.zxing:core:3.5.1'
 //    implementation 'com.google.zxing:javase:3.5.1'
-//    implementation 'org.iherus:qrext4j:1.3.1'
-//    implementation 'cn.afterturn:easypoi-base:4.4.0'
-//    implementation 'cn.afterturn:easypoi-web:4.4.0'
-//    implementation 'cn.afterturn:easypoi-annotation:4.4.0'
+    //打印
+    implementation 'com.jacob:jacob:1.10'
+
     //excel导入导出
-    implementation 'org.apache.poi:poi-ooxml:3.16'
-    //接口调用
-    implementation 'org.apache.httpcomponents:httpclient:4.5.2'
+    implementation 'org.apache.poi:poi-ooxml:4.0.0'
     //redisson锁
     implementation 'org.redisson:redisson:3.16.8'
     implementation fileTree(dir:'lib',includes:['*jar'])

+ 74 - 29
src/main/java/com/tld/controller/WebPrintController.java

@@ -1,35 +1,40 @@
-//package com.tld.controller;
-//
-//
+package com.tld.controller;
+
+
 //import com.google.zxing.client.j2se.MatrixToImageWriter;
-//import com.google.zxing.common.BitMatrix;
+import cn.afterturn.easypoi.excel.annotation.Excel;
+import com.google.zxing.common.BitMatrix;
 //import com.tld.util.MyQRUtils;
 //import org.apache.commons.logging.Log;
 //import org.apache.commons.logging.LogFactory;
-//import org.springframework.ui.Model;
-//import org.springframework.web.bind.annotation.PostMapping;
-//import org.springframework.web.bind.annotation.RequestMapping;
-//import org.springframework.web.bind.annotation.RestController;
-////
-//import javax.servlet.http.HttpServletRequest;
-//import javax.servlet.http.HttpServletResponse;
-//import java.io.File;
-//import java.io.IOException;
-//import java.io.OutputStream;
-//import java.nio.file.Path;
-//import java.util.ArrayList;
-//import java.util.HashMap;
-//import java.util.List;
-//import java.util.Map;
+import com.tld.excel.ExcelUtil;
+import com.tld.model.Print;
+import org.apache.poi.hpsf.Variant;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import sun.plugin.com.Dispatch;
 //
-///**
-// * 打印二维码
-// */
-//@RestController
-//@RequestMapping("/Printer")
-//public class WebPrintController {
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.file.Path;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 打印二维码
+ */
+@RestController
+@RequestMapping("/Printer")
+public class WebPrintController {
 //    private static final Log logger = LogFactory.getLog(MyQRUtils.class);
-//
+
 //    /**
 //     * 二维码预览页面
 //     * @param model
@@ -113,6 +118,46 @@
 //                            }
 //                     }
 //     }
-//
-//
-//}
+
+    /**
+     生成Excel文件
+     */
+    @PostMapping("/showEWMImage")
+    public String  showImageByType(HttpServletRequest request, HttpServletResponse response){
+        ArrayList<Print> print = new ArrayList<>();
+        for (int i = 0; i < 10; i++) {
+            Print print1 = new Print();
+            print1.setId("1");
+            print1.setEarTag("二维码");
+            print.add(print1);
+        }
+        String fileName = "打印二维码" ;
+        ExcelUtil.writeExcel(response,fileName,ExcelUtil.exportPicture(print));
+        return "操作成功";
+    }
+
+    /**
+     * 打印Excel文件
+     */
+    public void  printFileAction(){
+
+    }
+
+    /**
+
+     判断文件是否存在.
+     @param filePath 文件路径
+     @return
+     */
+    private static boolean fileExist(String filePath){
+        boolean flag = false;
+        try {
+            File file = new File(filePath);
+            flag = file.exists();
+        }catch (Exception e) {
+            e.printStackTrace();
+        }
+        return flag;
+    }
+
+}

+ 123 - 0
src/main/java/com/tld/excel/ExcelUtil.java

@@ -0,0 +1,123 @@
+package com.tld.excel;
+
+import cn.afterturn.easypoi.excel.ExcelExportUtil;
+import cn.afterturn.easypoi.excel.entity.ExportParams;
+import com.tld.model.Print;
+import com.tld.model.PrintModel;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.iherus.codegen.qrcode.QrcodeGenerator;
+import org.iherus.codegen.qrcode.SimpleQrcodeGenerator;
+
+import javax.imageio.ImageIO;
+import javax.servlet.http.HttpServletResponse;
+import java.awt.image.BufferedImage;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * excel工具类
+ */
+public class ExcelUtil {
+
+    /**
+     * 导出excel
+     *
+     * @param response HttpServletResponse
+     * @param fileName 文件名字
+     * @param workbook 通过exportPicture()方法获取
+     * @author zhy
+     */
+    public static void writeExcel(HttpServletResponse response, String fileName, Workbook workbook) {
+        // 判断数据
+        if (workbook == null) {
+            System.out.println("错误!");
+        }
+        // 重置响应对象
+        response.reset();
+        try {
+            OutputStream outputStream = getOutputStream(fileName, response);
+            BufferedOutputStream bufferedOutPut = new BufferedOutputStream(outputStream);
+            workbook.write(bufferedOutPut);
+            bufferedOutPut.flush();
+            bufferedOutPut.close();
+            outputStream.close();
+        } catch (IOException e) {
+            System.out.println(e.getMessage());
+        }
+    }
+
+    /**
+     * 导出文件时为Writer生成OutputStream
+     *
+     * @param fileName 文件名字
+     * @param response response
+     * @return 输出流
+     * @author zhy
+     */
+    private static OutputStream getOutputStream(String fileName, HttpServletResponse response) {
+        try {
+            fileName = URLEncoder.encode(fileName, "UTF-8");
+            response.setContentType("application/vnd.ms-excel");
+            response.setCharacterEncoding("utf8");
+            response.setHeader("Content-Disposition", "attachment; filename=" + fileName + ".xls");
+            response.setHeader("Pragma", "public");
+            response.setHeader("Cache-Control", "no-store");
+            response.addHeader("Cache-Control", "max-age=0");
+
+            response.setHeader("Content-disposition", "attachment;filename=" + fileName+ ".xls;filename*=utf-8''"+fileName+".xls"); //兼容不同浏览器的中文乱码问题
+            response.setContentType("application/msexcel");// 定义输出类型
+            response.setCharacterEncoding("UTF-8");//
+
+            return response.getOutputStream();
+        } catch (IOException e) {
+            System.out.println("导出excel表格失败!");
+        }
+        return null;
+    }
+
+    /**
+     * 获取Workbook对象
+     *
+     * @param pigList    excel中添加的数据
+     * @return 文件下载
+     */
+    public static Workbook exportPicture(List<Print> pigList) {
+        List<PrintModel> list = new ArrayList<>();
+        pigList.forEach(item -> {
+            PrintModel e = new PrintModel();
+            e.setEarTag(item.getEarTag());
+            String s = item.getEarTag();
+
+            QrcodeGenerator generate = new SimpleQrcodeGenerator().generate( s);
+            BufferedImage image = generate.getImage();
+            byte[] pngs = imageToBytes(image);
+            e.setQrCode(pngs);
+            list.add(e);
+        });
+        return ExcelExportUtil.exportExcel(new ExportParams(), PrintModel.class, list);
+    }
+
+    /**
+     * BufferedImage转byte[]
+     *
+     * @param bImage BufferedImage对象
+     * @return byte[]
+     */
+    private static byte[] imageToBytes(BufferedImage bImage) {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        try {
+            ImageIO.write(bImage, "png", out);
+        } catch (IOException e) {
+            System.out.println(e.getMessage());
+        }
+        return out.toByteArray();
+    }
+
+}

+ 16 - 0
src/main/java/com/tld/model/Print.java

@@ -0,0 +1,16 @@
+package com.tld.model;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * 打印实体类
+ */
+@Data
+public class Print implements Serializable {
+
+    private String id;
+
+    private String earTag;
+}

+ 17 - 0
src/main/java/com/tld/model/PrintModel.java

@@ -0,0 +1,17 @@
+package com.tld.model;
+
+import cn.afterturn.easypoi.excel.annotation.Excel;
+import cn.afterturn.easypoi.excel.annotation.ExcelTarget;
+import lombok.Data;
+
+/**
+ * 打印导出excel数据模板
+ */
+@ExcelTarget(value = "slaughterDataModel")
+@Data
+public class PrintModel implements java.io.Serializable {
+    @Excel(name = "信息", height = 40, width = 30)
+    private String earTag;
+    @Excel(name = "二维码", type = 2, width = 20, height = 40, imageType = 2)
+    private byte[] qrCode;
+}

+ 4 - 3
src/main/java/com/tld/service/impl/AskGoodsServiceImpl.java

@@ -271,10 +271,10 @@ public class AskGoodsServiceImpl implements AskGoodsService {
                     JSONObject strJson = new JSONObject();
                     //父表
                     strJson.put("GIReqBillID", mapList.get(0).get("askGoodsId").toString());//要货单id
-                    strJson.put("WMSID", mapList.get(0).get("askGoodsId").toString());//出库单id
+                    strJson.put("WMSID", mapList.get(0).get("id").toString());//出库单id
                     strJson.put("WMSCode", mapList.get(0).get("removalCode").toString());//出库单编号
-                    strJson.put("WareHouse", warehouseWhere);//仓库ID1
-                    strJson.put("SourceBillDate", mapList.get(0).get("removalCode").toString());//业务日期1
+                    strJson.put("WareHouse", warehouseWhere);//仓库ID
+                    strJson.put("SourceBillDate",DateUtil.dateConversion(mapList.get(0).get("scrq").toString()));//业务日期
                     strJson.put("sourceType", mapList.get(0).get("sourceType").toString());//来源类型
                     strJson.put("moveType", mapList.get(0).get("moveType").toString());//移动类型
                     strJson.put("IsRed", 0);//是否红单1
@@ -301,6 +301,7 @@ public class AskGoodsServiceImpl implements AskGoodsService {
             System.out.println(returnData);
             HttpClientUtil httpClientUtil1 = new HttpClientUtil();
             Map<String, Object> result = httpClientUtil1.doPost("http://42.159.85.29:52480/cwbase/sg/V1/ERP/TELD/DEVTEST/API_WMS_PurInStock/CreatePurInStock", returnData);
+
             if (Integer.parseInt(result.get("msg").toString()) != 200) {
                 //如果失败存入报错信息跟数据
                 Error error = new Error()

+ 4 - 1
src/main/java/com/tld/service/impl/WarehousingServiceImpl.java

@@ -45,6 +45,9 @@ public class WarehousingServiceImpl implements WarehousingService {
     //库存
     @Autowired
     private StorageLocationMapper storageLocationMapper;
+    //库存
+    @Autowired
+    private DictionaryMapper dictionaryMapper;
 
     @Override
     public Map<String, Object> getRecommend(String wllbCode, String suppId, String num, String unique, String producDate) {
@@ -245,7 +248,7 @@ public class WarehousingServiceImpl implements WarehousingService {
                 strJson.put("PurOrderID", returnWarehousing.getOrderNumber());//采购单id
                 strJson.put("WMSID", returnWarehousing.getId());//入库单id
                 strJson.put("WMSCode", returnWarehousing.getStorageCode());//入库单编号
-                strJson.put("WareHouse", "e7f6bff1-e6ab-49e7-9");//仓库id
+                strJson.put("WareHouse", dictionaryMapper.getWarehouse(returnWarehousing.getStorageLocationCode()));//仓库id
                 strJson.put("SourceBillDate", DateUtil.dateConversion(returnWarehousing.getScrq()));//业务日期
                 strJson.put("SourceType", returnWarehousing.getSourceType());//来源类型
                 strJson.put("MoveType", returnWarehousing.getMoveType());//移动类型

+ 2 - 1
src/main/resources/mapper/AskGoodsMapper.xml

@@ -243,7 +243,8 @@
             document_id as askGoodsId,
             removal_code as removalCode,
             source_type as sourceType,
-            move_type as moveType
+            move_type as moveType,
+            scrq
         from tld_return_gs_removal where document_id = #{removalCode}
     </select>
     <!-- 查询字表回传数据 -->