李旭东
2023-11-03 a07b4b6ff1c98dcf81338bb45d59308db7c058a9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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);
            }
        }
    }
 
 
}