提交 fa3d44b1 authored 作者: zhoushaopan's avatar zhoushaopan

fix(二维码模块): 修改了传输的数据类型

修改了传输的数据类型
上级 66ad9046
......@@ -7,6 +7,7 @@ import com.google.zxing.common.HybridBinarizer;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import com.google.zxing.qrcode.decoder.Version;
import com.google.zxing.qrcode.encoder.QRCode;
import lombok.extern.slf4j.Slf4j;
import javax.imageio.ImageIO;
import java.awt.*;
......@@ -23,11 +24,12 @@ import java.util.Random;
* @author zsp
* @create 2022/4/27 13:19
*/
@Slf4j
public class QRCodeUtil {
private static final String CHARSET = "utf-8";
private static final String FORMAT = "JPG";
// 二维码尺寸
private static final int QRCODE_SIZE = 400;
private static final int QRCODE_SIZE = 500;
// LOGO宽度
private static final int LOGO_WIDTH = 60;
// LOGO高度
......@@ -39,10 +41,10 @@ public class QRCodeUtil {
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
hints.put(EncodeHintType.CHARACTER_SET, CHARSET);
hints.put(EncodeHintType.MARGIN, 1);
QRCode qrCode = new QRCode();
qrCode.setVersion(Version.getVersionForNumber(30));
// QRCode qrCode = new QRCode();
// qrCode.setVersion(Version.getVersionForNumber(20));
// qrCode.setVersion(Version.getVersionForNumber(35));
hints.put(EncodeHintType.QR_VERSION,qrCode.getVersion());
// hints.put(EncodeHintType.QR_VERSION,qrCode.getVersion());
BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, QRCODE_SIZE, QRCODE_SIZE,
hints);
......@@ -58,7 +60,7 @@ public class QRCodeUtil {
return image;
}
// 插入图片
QRCodeUtil.insertImage(image, logoPath, needCompress);
// QRCodeUtil.insertImage(image, logoPath, needCompress);
return image;
}
......
package com.tykj.dev.misc.qrcode;
import com.tykj.dev.misc.exception.ApiException;
import com.tykj.dev.misc.qrcode.vo.DeviceCodeVO;
import com.tykj.dev.misc.qrcode.vo.TaskData;
import com.tykj.dev.misc.utils.JacksonUtil;
import lombok.extern.slf4j.Slf4j;
......@@ -10,6 +11,7 @@ import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
......@@ -32,6 +34,18 @@ public class QrCodeBillUtil {
* 创建工具类
*/
public List<String> createCode(TaskData taskData){
//重新定义数据结构
List<DeviceCodeVO> deviceLibraries = taskData.getDeviceLibraries();
Map<String, List<DeviceCodeVO>> map =
deviceLibraries.stream().collect(Collectors.groupingBy(deviceCodeVO -> deviceCodeVO.getModel() + "," + deviceCodeVO.getName()));
map.forEach((k,v)->{
v.forEach(d -> {
d.setName(null);
d.setModel(null);
});
});
taskData.setMap(map);
taskData.setDeviceLibraries(null);
String join = JacksonUtil.toJSon(taskData);
List<String> code = getCodeNum(join);
log.info("code:{}",code);
......@@ -72,7 +86,7 @@ public class QrCodeBillUtil {
}
log.info("排序后的数据格式:{}",collect);
if (!flag){
throw new ApiException("没有扫完");
throw new ApiException("没有扫完,请重新扫描");
}
String json = GZIPUtils.uncompressToString(deviceDataUtil.getCompleteString());
//解析
......@@ -91,7 +105,7 @@ public class QrCodeBillUtil {
String s = GZIPUtils.compress(data);
log.info("压缩和加密之后的长度:{}",s.length());
//然后截取
return QrStringSplitUtil.stringToList2(s, 900);
return QrStringSplitUtil.stringToList2(s, 450);
}
}
......@@ -5,6 +5,7 @@ import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* @author zsp
......@@ -31,4 +32,6 @@ public class TaskData {
List<DeviceCodeVO> deviceLibraries;
Map<String, List<DeviceCodeVO>> map;
}
......@@ -115,7 +115,6 @@ public class DailyCheckBillServiceImpl implements DailyCheckBillService {
@Override
public DailyCheckBill addDayBill(DailyCheckSaveVo dailyCheckSaveVo) {
//当前登录的用户ID
Integer currentUserId = userUtils.getCurrentUserId();
Integer taskId = dailyCheckSaveVo.getTaskId();
//业务id
Integer id = dailyCheckSaveVo.getId();
......@@ -135,7 +134,6 @@ public class DailyCheckBillServiceImpl implements DailyCheckBillService {
@Override
public DailyCheckBill updateBill(DailyCheckUpdateVo dailyCheckUpdateVo) {
Integer currentUserId = userUtils.getCurrentUserId();
TaskBto taskBto = taskService.get(dailyCheckUpdateVo.getTaskId());
TaskBto taskBto1 = taskService.moveToSpecial(taskBto, StatusEnum.WAIT_CHECK_FILE);
Integer id = dailyCheckUpdateVo.getId();
......@@ -214,7 +212,19 @@ public class DailyCheckBillServiceImpl implements DailyCheckBillService {
List<String> codeList = parseQrCodeVO.getCodeList();
//总的装备集合 返回给前端
TaskData taskData = qrCodeBillUtil.parseCode(codeList);
List<DeviceCodeVO> deviceLibraryList = taskData.getDeviceLibraries();
//还原数据
Map<String, List<DeviceCodeVO>> map = taskData.getMap();
map.forEach((k,v)->{
List<DeviceCodeVO> deviceCodeVOS = map.get(k);
deviceCodeVOS.forEach(deviceCodeVO -> {
String[] split = k.split(",");
deviceCodeVO.setModel(split[0]);
deviceCodeVO.setName(split[1]);
});
deviceLibraryList.addAll(deviceCodeVOS);
});
List<DeviceLibrary> deviceLibraries = new ArrayList<>();
if (taskData != null) {
//判断是不是当天的任务
......@@ -226,7 +236,6 @@ public class DailyCheckBillServiceImpl implements DailyCheckBillService {
log.info("任务时间:{}",taskDate);
throw new ApiException("扫描任务与当前的任务时间不一致");
}
List<DeviceCodeVO> deviceLibraryList = taskData.getDeviceLibraries();
//0 缺失
List<DeviceCodeVO> libraryList =
deviceLibraryList.stream().filter(deviceCodeVO -> deviceCodeVO.getCheckResult() == 0).collect(Collectors.toList());
......@@ -283,9 +292,7 @@ public class DailyCheckBillServiceImpl implements DailyCheckBillService {
if (!b){
throw new ApiException("与检查设备不匹配");
}
}
}
return deviceLibraries;
}
......@@ -428,16 +435,16 @@ public class DailyCheckBillServiceImpl implements DailyCheckBillService {
}
private static boolean usingStream(List<Integer> list, List<Integer> list1) {
List<String> newlist = new ArrayList<>(list.size());
List<String> newList = new ArrayList<>(list.size());
List<String> newList1 = new ArrayList<>(list1.size());
for (Integer myInt : list) {
newlist.add(String.valueOf(myInt));
newList.add(String.valueOf(myInt));
}
for (Integer myInt1 : list1) {
newList1.add(String.valueOf(myInt1));
}
/** 先将集合转成stream流进行排序然后转成字符串进行比较 */
return newlist.stream().sorted().collect(Collectors.joining())
return newList.stream().sorted().collect(Collectors.joining())
.equals(newList1.stream().sorted().collect(Collectors.joining()));
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论