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 com.ltkj.system.service.ISysConfigService; 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.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Base64; 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; @Autowired private ISysConfigService configService; /** * 打印条码 */ @GetMapping("/printCode") @ApiOperation(value = "打印条码") public AjaxResult printCode(@ApiParam(value = "体检号")String tjNumber) { LambdaQueryWrapper wq = new LambdaQueryWrapper<>(); wq.eq(TjOrder::getTjNumber, tjNumber); TjOrder tjOrder = tjOrderService.getOne(wq); String value = configService.selectConfigByKey("path_filePath"); if (tjOrder!=null){ LambdaQueryWrapper wq1 = new LambdaQueryWrapper<>(); wq1.eq(TjCustomer::getCusId, tjOrder.getUserId()); TjCustomer one = tjCustomerService.getOne(wq1); //查到项目详情 判断每个项目的耗材 去重 is_calculation为Y的打印 且拿到耗材名称 // LambdaQueryWrapper wq2 = new LambdaQueryWrapper<>(); // wq2.eq(TjOrderDetail::getOrderId, tjOrder.getOrderId()); // List list = tjOrderDetailService.list(wq2); List list = tjOrderDetailService.getCaiYangDengJi(tjOrder.getOrderId()); // List list1=new ArrayList<>(); // for (TjOrderDetail tjOrderDetail : list) { // LambdaQueryWrapper wq3 = new LambdaQueryWrapper<>(); // wq3.eq(TjProConsumables::getProId, tjOrderDetail.getProId()); // List list2 = proConsumablesService.list(wq3); // for (TjProConsumables tjProConsumables : list2) { // list1.add(tjProConsumables); // } // } // List collect = list1.stream().distinct().collect(Collectors.toList()); if (list.isEmpty()){ return AjaxResult.success("该体检号无抽血项目!"); } try { BufferedImage image = BarCodeUtils.getBarCodeWithWords(tjNumber, tjNumber, one.getCusName(),null); // ImageIO.write(image, "jpg", new File(value+"\\"+one.getCusName()+tjNumber+".jpg")); ByteArrayOutputStream out=new ByteArrayOutputStream(); ImageIO.write(image,"jpg",out); byte[] bytes = out.toByteArray(); String encodedToString = Base64.getEncoder().encodeToString(bytes); return AjaxResult.success("条码已生成!在文件夹下:"+value,encodedToString); } catch (IOException e) { e.printStackTrace(); return AjaxResult.error(); } } 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; } }