李旭东
2023-11-08 8bb87e050d73924843552f73563469711c833d03
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
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<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 = 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);
            }
        }
    }
 
 
}