门禁开门计费逻辑调整

This commit is contained in:
2023-12-06 10:00:43 +08:00
parent 07a648c3f5
commit 137a5f87ce
35 changed files with 509 additions and 392 deletions

View File

@@ -8,18 +8,11 @@ import com.ydd.framework.core.exception.ServiceException;
import com.ydd.oms.controller.OmsController;
import com.sv.entity.Device;
import com.ydd.oms.util.VenueBarcodeUtil;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.util.Units;
import org.apache.poi.xwpf.usermodel.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
/**
* Controller - 门禁设备
*
@@ -120,55 +113,4 @@ public class DeviceController extends OmsController {
return ResponseDTO.ok();
}
@RequestMapping(value = "/qrcode/print/{id}")
public void print(@PathVariable("id") Integer id, HttpServletResponse response) throws IOException, InvalidFormatException {
String documentPath = getDocument();
response.setHeader("Content-disposition","attachment; filename=venue.docx");
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("UTF-8");
OutputStream out = response.getOutputStream();
BufferedInputStream fin = new BufferedInputStream(new FileInputStream(documentPath));
try {
byte[] content = new byte[1024];
int length;
while ((length = fin.read(content, 0, content.length)) != -1) {
out.write(content, 0, length);
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
logger.info("文件下载失败", e.getMessage());
throw e;
} finally {
fin.close();
out.flush();
out.close();
}
}
private static String getDocument() throws IOException, InvalidFormatException {
String newFilePath = "/Users/limqhz/home/test/document.docx";
XWPFDocument document = new XWPFDocument();
XWPFParagraph paragraph = document.createParagraph();
paragraph.setAlignment(ParagraphAlignment.CENTER);
XWPFRun run = paragraph.createRun();
// 入场二维码
run.setText("入场二维码");
run.addBreak();
String imgFile = VenueBarcodeUtil.generateBarcode("jdoiawjdoiawioe1","202311161.jpg");
int imgFormat = XWPFDocument.PICTURE_TYPE_JPEG;
run.addPicture(new FileInputStream(imgFile), imgFormat, "image description",
Units.toEMU(200), Units.toEMU(200));
run.addBreak(BreakType.PAGE);
// 出场二维码
run.setText("出场二维码");
run.addBreak();
String imgFile2 = VenueBarcodeUtil.generateBarcode("jdoiawjdoiawioe2","202311162.jpg");
run.addPicture(new FileInputStream(imgFile2), imgFormat, "image description",
Units.toEMU(200), Units.toEMU(200));
// 保存文件
document.write(new FileOutputStream(newFilePath));
document.close();
return newFilePath;
}
}

View File

@@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.text.ParseException;
import java.util.List;
/**
* Controller - 场馆对应价格表
@@ -22,7 +23,7 @@ import java.text.ParseException;
public class VenuePriceController extends OmsController {
private final Logger logger = LoggerFactory.getLogger(VenuePriceController.class);
@Resource
private VenuePriceService venuePriceService;
@@ -67,8 +68,9 @@ public class VenuePriceController extends OmsController {
*/
@RequestMapping(value = "/venue/findPrice", method = RequestMethod.GET)
public ResponseDTO findPrice(@RequestParam("venueId") Integer venueId) {
venuePriceService.findPrice(venueId);
return ResponseDTO.ok().addAttribute("price",venuePriceService.findPrice(venueId));
List<VenuePrice> price = venuePriceService.findPrice(venueId);
System.out.println(price);
return ResponseDTO.ok().addAttribute("price", price);
}
}

View File

@@ -1,109 +0,0 @@
package com.ydd.oms.util;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import com.ydd.framework.core.exception.ServiceException;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Hashtable;
public class VenueBarcodeUtil {
private static final int BLACK = 0xFF000000;
private static final int WHITE = 0xFFFFFFFF;
private static final int margin = 0;
public static String generateBarcode(String barcodeValue,String fileName) {
try {
String geneFilePath = "/Users/limqhz/home/test/" + fileName;
makeBarcode(geneFilePath,barcodeValue);
return geneFilePath;
}catch (WriterException e) {
throw new ServiceException("生成二维码图片文件有问题");
}
}
private static void makeBarcode(String path, String barcodeValue) throws WriterException {
//二维码内容
String content = barcodeValue;
String format = "jpg";
int width = 200; // 二维码宽度
int height = 200;// 二维码高度
// 设置二维码矩阵的信息
BitMatrix bitMatrix = setBitMatrix(content, width, height);
// 设置输出流
OutputStream outStream = null;
try {
outStream = new FileOutputStream(new File(path));
// 目前 针对容错等级为H reduceWhiteArea 二维码空白区域的大小 根据实际情况设置,如果二维码内容长度不固定的话 需要自己根据实际情况计算reduceWhiteArea的大小
writeToFile(bitMatrix, format, outStream, 5);
outStream.close();
} catch (Exception e) {
e.printStackTrace();
}finally {
try {
outStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 设置生成二维码矩阵信息
* @param content 二维码图片内容
* @param width 二维码图片宽度
* @param height 二维码图片高度
* @throws WriterException
*/
private static BitMatrix setBitMatrix(String content, int width, int height) throws WriterException {
BitMatrix bitMatrix = null;
Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>();
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); // 指定编码方式,避免中文乱码
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); // 指定纠错等级 如果二维码里面的内容比较多的话推荐使用H 容错率30% 这样可以避免一些扫描不出来的问题
hints.put(EncodeHintType.MARGIN, margin); // 指定二维码四周白色区域大小 官方的这个方法目前没有没有作用默认设置为0
bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height, hints);
return bitMatrix;
}
/**
* @param matrix
* @param format
* @param outStream
* @param reduceWhiteArea 二维码空白区域设置
* @throws IOException
*/
private static void writeToFile(BitMatrix matrix, String format, OutputStream outStream, int reduceWhiteArea) throws IOException {
BufferedImage image = toBufferedImage(matrix, reduceWhiteArea);
ImageIO.write(image, format, outStream);
}
/**
*
* @param matrix
* @param reduceWhiteArea
* @return
*/
private static BufferedImage toBufferedImage(BitMatrix matrix, int reduceWhiteArea) {
int width = matrix.getWidth();
int height = matrix.getHeight();
BufferedImage image = new BufferedImage(width - 2 * reduceWhiteArea, height - 2 * reduceWhiteArea, BufferedImage.TYPE_3BYTE_BGR);
for (int x = reduceWhiteArea; x < width - reduceWhiteArea; x++) {
for (int y = reduceWhiteArea; y < height - reduceWhiteArea; y++) {
image.setRGB(x - reduceWhiteArea, y - reduceWhiteArea, matrix.get(x, y) ? BLACK : WHITE);
}
}
return image;
}
}