package com.thhy.materials.modules.biz.rebarprint.controller; import com.google.zxing.BarcodeFormat; import com.google.zxing.EncodeHintType; import com.google.zxing.MultiFormatWriter; import com.google.zxing.client.j2se.MatrixToImageWriter; import com.google.zxing.common.BitMatrix; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; import com.thhy.general.common.BasicResult; import com.thhy.materials.modules.biz.rebarprint.service.TSteelPrintService; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.imageio.ImageIO; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.awt.image.BufferedImage; import java.io.IOException; import java.io.OutputStream; import java.util.HashMap; import java.util.Map; @RestController @RequestMapping("/steelPrint") public class TSteelPrintController { @Resource private TSteelPrintService steelPrintService; @Value("${pipePrint.baseUrl}") private String baseUrl; @Value("${pipePrint.deviceInfoUrl}") private String deviceInfoUrl; @Value("${pipePrint.pipeHistoryInfoUrl}") private String pipeHistoryInfoUrl; @Value("${pipePrint.modelUrl}") private String modelUrl; @Value("${pipePrint.steelInfoUrl}") private String steelInfoUrl; //钢筋笼打印添加 @PostMapping("/steelPrintInsert") public BasicResult steelPrintInsert(@RequestBody Map values){ return steelPrintService.steelPrintInsert(values); } //钢筋笼打印列表 @PostMapping("/steelPrintList") public BasicResult steelPrintList(@RequestBody Map values){ return steelPrintService.steelPrintList(values); } //钢筋笼删除 @GetMapping("/steelPrintDel") public BasicResult steelPrintDel(@RequestParam String steelPrintId){ return steelPrintService.steelPrintDel(steelPrintId); } //钢筋打印 @GetMapping("/print") public BasicResult print(@RequestParam String steelPrintId){ return steelPrintService.print(steelPrintId); } @GetMapping("/test") public void dowanload(@RequestParam(required = false) String num ,@RequestParam(required = false) Integer type ,@RequestParam(required = false) String mouldId ,@RequestParam(required = false) String steelProduceId ,@RequestParam(required = false) String bigDeviceId , HttpServletRequest request , HttpServletResponse response) throws Exception { //type 1、设备 2、管片追溯 3、模具 4、钢筋笼 //二维码中包含的信息 String content = num; if (type != null){ if(type == 1){ content = baseUrl + deviceInfoUrl + bigDeviceId; }else if (type == 2){ content = baseUrl + pipeHistoryInfoUrl + num; }else if(type == 3){ content = baseUrl + modelUrl + mouldId; }else if(type == 4){ content = baseUrl + steelInfoUrl + num; } } System.out.println("steelProduceId=============="+steelProduceId); BufferedImage bufferedImage = ImageUtils.createQr(content); OutputStream outputStream = null; try { outputStream = response.getOutputStream(); ImageIO.write(bufferedImage,"jpg",outputStream); } catch (IOException e) { throw new RuntimeException(e); } finally { try { outputStream.close(); } catch (IOException e) { throw new RuntimeException(e); } } } }