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.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;
|
|
//钢筋笼打印添加
|
@PostMapping("/steelPrintInsert")
|
public BasicResult steelPrintInsert(@RequestBody Map<String,Object> values){
|
return steelPrintService.steelPrintInsert(values);
|
}
|
//钢筋笼打印列表
|
@PostMapping("/steelPrintList")
|
public BasicResult steelPrintList(@RequestBody Map<String,Object> 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 = "http://111.30.93.212:8089/pipe/#/scanDetail?num="+num;
|
content = "https://pipe.thhy-tj.com/pipe/#/scanDetail?bigDeviceId="+bigDeviceId;
|
//content = "http://192.168.0.99:8080/#/scanDetail?num="+num;
|
}else if (type == 2){
|
//content = "http://111.30.93.212:8089/pipe/#/ScanBear?num="+num;
|
content = "https://pipe.thhy-tj.com/pipe/#/ScanBear?num="+num;
|
//content = "http://192.168.0.99:8080/#/ScanBear?num="+num;
|
}else if(type == 3){
|
//content = "http://111.30.93.212:8089/pipe/#/massInfo?mouldId="+mouldId;
|
content = "https://pipe.thhy-tj.com/pipe/#/massInfo?mouldId="+mouldId;
|
//content = "http://192.168.0.99:8080/#/massInfo?mouldId="+mouldId;
|
}else if(type == 4){
|
//content = "http://111.30.93.212:8089/pipe/#/reinInfo?num="+num;
|
content = "https://pipe.thhy-tj.com/pipe/#/reinInfo?num="+num;
|
//content = "http://192.168.0.99:8080/#/reinInfo?num="+num;
|
}
|
}
|
System.out.println("steelProduceId=============="+steelProduceId);
|
// Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>();
|
// // 指定编码格式
|
// hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
|
// // 指定纠错级别(L--7%,M--15%,Q--25%,H--30%)
|
// hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
|
// // 编码内容,编码类型(这里指定为二维码),生成图片宽度,生成图片高度,设置参数
|
// BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, 200, 200, hints);
|
// //设置请求头
|
// response.setHeader("Content-Type","application/octet-stream");
|
// response.setHeader("Content-Disposition", "attachment;filename=" + "编码.png");
|
// OutputStream outputStream = response.getOutputStream();
|
// MatrixToImageWriter.writeToStream(bitMatrix, "png", outputStream);
|
// outputStream.flush();
|
// outputStream.close();
|
|
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);
|
}
|
}
|
}
|
|
|
}
|