23
lige
2023-12-11 c7e8b28a453bf85fb78c1f09a6d613ecef9ea240
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package com.ltkj.web.controller.barcode;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ltkj.common.core.domain.AjaxResult;
import com.ltkj.common.core.page.TableDataInfo;
import com.ltkj.hosp.domain.*;
import com.ltkj.hosp.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * @Company: 西安路泰科技有限公司
 * @Author: lige
 * @Date: 2023/2/16 11:22
 */
@Api(tags = "批量打印条码")
@RestController
@RequestMapping("/code/print")
public class PrintBarCodeController {
    @Resource
    private ITjCustomerService tjCustomerService;
    @Autowired
    private ITjOrderService tjOrderService;
    @Autowired
    private ITjOrderDetailService tjOrderDetailService;
    @Resource
    private TjProConsumablesService proConsumablesService;
    @Resource
    private ITjConsumablesService consumablesService;
    @Value("${path.filePath}")
    private String value;
    /**
     * 打印条码
     */
    @GetMapping("/printCode")
    @ApiOperation(value = "打印条码")
    public AjaxResult printCode(@ApiParam(value = "体检号")String tjNumber) {
        LambdaQueryWrapper<TjOrder> wq = new LambdaQueryWrapper<>();
        wq.eq(TjOrder::getTjNumber, tjNumber);
        TjOrder tjOrder = tjOrderService.getOne(wq);
 
        if (tjOrder!=null){
            LambdaQueryWrapper<TjCustomer> wq1 = new LambdaQueryWrapper<>();
            wq1.eq(TjCustomer::getCusId, tjOrder.getUserId());
            TjCustomer one = tjCustomerService.getOne(wq1);
 
            //查到项目详情  判断每个项目的耗材  去重 is_calculation为Y的打印 且拿到耗材名称
            LambdaQueryWrapper<TjOrderDetail> wq2 = new LambdaQueryWrapper<>();
            wq2.eq(TjOrderDetail::getOrderId, tjOrder.getOrderId());
            List<TjOrderDetail> list = tjOrderDetailService.list(wq2);
 
            List<TjProConsumables> list1=new ArrayList<>();
            for (TjOrderDetail tjOrderDetail : list) {
                LambdaQueryWrapper<TjProConsumables> wq3 = new LambdaQueryWrapper<>();
                wq3.eq(TjProConsumables::getProId, tjOrderDetail.getProId());
                List<TjProConsumables> list2 = proConsumablesService.list(wq3);
                for (TjProConsumables tjProConsumables : list2) {
                    list1.add(tjProConsumables);
                }
            }
            List<TjProConsumables> collect = list1.stream().distinct().collect(Collectors.toList());
            if (collect.size()==0){
                return AjaxResult.success("该体检号无抽血项目!");
            }
            //纵向拼接用
            //List<String> pac=new ArrayList<>();
            for (TjProConsumables tjProConsumables : collect) {
                TjConsumables tjConsumables = consumablesService.selectTjConsumablesById(tjProConsumables.getConsumablesId());
                if ("Y".equals(tjConsumables.getIsCalculation())){
                    try {
                        BufferedImage image = BarCodeUtils.getBarCodeWithWords(tjNumber+tjConsumables.getId(), tjNumber, one.getCusName(), tjConsumables.getMakings());
                        ImageIO.write(image, "jpg", new File(value+"\\"+tjNumber+tjConsumables.getMakings()+".jpg"));
                        //pac.add(value+tjNumber+tjConsumables.getMakings()+".jpg"); //纵向拼接用
                        //BarCodeUtils.barCodePrint(image,250,150,250,150); //纵向拼接用
                    } catch (IOException e) {
                        e.printStackTrace();
                        return AjaxResult.error();
                    }
                }
            }
            //纵向拼接
            //String[] title = pac.toArray(new String[pac.size()]);
            //joinImageListVertical(title,"jpg","E:\\mycode\\2023-2\\2.16\\"+tjNumber+".jpg");
            //识别条码内容
            //String s = QRCodeUtils.deEncodeByPath("E:\\mycode\\2023-2\\2.16\\10001230128175552红盖子抽血管.jpg");
            //System.out.println(s);
            return AjaxResult.success("条码已生成!在文件夹下:"+value);
        }
        return AjaxResult.error("该体检号无效!");
 
    }
 
 
    /**
     * 根据图片识别条码
     */
    @GetMapping("/GetByCode")
    @ApiOperation(value = "根据图片识别条码")
    public AjaxResult GetByCode(String path) {
        path=value+"10001230306223716蓝色头盖管.jpg";
        //识别条码
        String s = QRCodeUtils.deEncodeByPath(path);
        return AjaxResult.success(s);
    }
 
 
    /**
     * 纵向拼接一组(多张)图像
     * @param pics        将要拼接的图像数组
     * @param type    写入图像类型
     * @param dst_pic    写入图像路径
     * @return
     */
    public static boolean joinImageListVertical(String[] pics, String type, String dst_pic) {
        try {
            int len = pics.length;
            if (len < 1) {
                System.out.println("pics len < 1");
                return false;
            }
            File[] src = new File[len];
            BufferedImage[] images = new BufferedImage[len];
            int[][] imageArrays = new int[len][];
            for (int i = 0; i < len; i++) {
                //System.out.println(i);
                src[i] = new File(pics[i]);
                images[i] = ImageIO.read(src[i]);
                int width = images[i].getWidth();
                int height = images[i].getHeight();
                imageArrays[i] = new int[width * height];// 从图片中读取RGB
                imageArrays[i] = images[i].getRGB(0, 0, width, height,  imageArrays[i], 0, width);
            }
 
            int dst_height = 0;
            int dst_width = images[0].getWidth();
            for (int i = 0; i < images.length; i++) {
                dst_width = dst_width > images[i].getWidth() ? dst_width : images[i].getWidth();
                dst_height += images[i].getHeight();
            }
            //System.out.println(dst_width);
            //System.out.println(dst_height);
            if (dst_height < 1) {
                System.out.println("dst_height < 1");
                return false;
            }
            /*
             * 生成新图片
             */
            BufferedImage ImageNew = new BufferedImage(dst_width, dst_height,  BufferedImage.TYPE_INT_RGB);
            int height_i = 0;
            for (int i = 0; i < images.length; i++) {
                ImageNew.setRGB(0, height_i, dst_width, images[i].getHeight(),  imageArrays[i], 0, dst_width);
                height_i += images[i].getHeight();
            }
            File outFile = new File(dst_pic);
            ImageIO.write(ImageNew, type, outFile);// 写图片
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
 
}