提交 308cff5b authored 作者: zhoushaopan's avatar zhoushaopan

[二维码]修改

上级 c3a45dfc
...@@ -82,4 +82,7 @@ public interface TaskDao extends JpaRepository<Task, Integer>, JpaSpecificationE ...@@ -82,4 +82,7 @@ public interface TaskDao extends JpaRepository<Task, Integer>, JpaSpecificationE
List<Task> findAllByBusinessTypeAndCustomInfoAndBillStatus(Integer businessType,String customInfo,Integer billStatus); List<Task> findAllByBusinessTypeAndCustomInfoAndBillStatus(Integer businessType,String customInfo,Integer billStatus);
List<Task> findAllByBusinessTypeAndBillIdIn(Integer businessType,List<Integer> billIds); List<Task> findAllByBusinessTypeAndBillIdIn(Integer businessType,List<Integer> billIds);
//zsp
Task findByParentTaskId(Integer parentTaskId);
} }
...@@ -5,10 +5,17 @@ import com.google.zxing.client.j2se.BufferedImageLuminanceSource; ...@@ -5,10 +5,17 @@ import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.client.j2se.MatrixToImageWriter; import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix; import com.google.zxing.common.BitMatrix;
import com.google.zxing.common.HybridBinarizer; import com.google.zxing.common.HybridBinarizer;
import com.tykj.dev.device.task.repository.TaskDao;
import com.tykj.dev.device.task.service.TaskService;
import com.tykj.dev.device.task.subject.bto.TaskBto;
import com.tykj.dev.device.task.subject.domin.Task;
import com.tykj.dev.device.zxing.vo.ZxingTaskVo;
import javassist.NotFoundException; import javassist.NotFoundException;
import org.apache.tomcat.util.http.fileupload.FileUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.ResourceUtils; import org.springframework.util.ResourceUtils;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartRequest; import org.springframework.web.multipart.MultipartRequest;
...@@ -28,16 +35,19 @@ import java.util.UUID; ...@@ -28,16 +35,19 @@ import java.util.UUID;
* DATE:2021-7-20 * DATE:2021-7-20
* Author:zsp * Author:zsp
*/ */
@Service
public class ZXingUtil { public class ZXingUtil {
/** 二维码上传位置 */ /** 二维码上传位置 */
private static String codePath = "src/"; // private static String codePath = "src/";
/** 二维码宽度 */ /** 二维码宽度 */
private static Integer width = 50; private static Integer width = 100;
/** 二维码高度 */ /** 二维码高度 */
private static Integer height = 50; private static Integer height = 100;
@Autowired
private TaskDao taskDao;
/** /**
* 解析二维码 * 解析二维码
* *
...@@ -57,7 +67,7 @@ public class ZXingUtil { ...@@ -57,7 +67,7 @@ public class ZXingUtil {
// Result result = new MultiFormatReader().decode(bitmap, decodeHints); // Result result = new MultiFormatReader().decode(bitmap, decodeHints);
// return result.getText(); // return result.getText();
// } // }
public static String decode(MultipartFile file) throws IOException, com.google.zxing.NotFoundException { public ZxingTaskVo decode(MultipartFile file) throws IOException, com.google.zxing.NotFoundException {
BufferedImage bufferedImage = ImageIO.read(new FileInputStream((File)file)); BufferedImage bufferedImage = ImageIO.read(new FileInputStream((File)file));
LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage); LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage);
Binarizer binarizer = new HybridBinarizer(source); Binarizer binarizer = new HybridBinarizer(source);
...@@ -65,7 +75,12 @@ public class ZXingUtil { ...@@ -65,7 +75,12 @@ public class ZXingUtil {
HashMap<DecodeHintType, Object> decodeHints = new HashMap<DecodeHintType, Object>(); HashMap<DecodeHintType, Object> decodeHints = new HashMap<DecodeHintType, Object>();
decodeHints.put(DecodeHintType.CHARACTER_SET, "UTF-8"); decodeHints.put(DecodeHintType.CHARACTER_SET, "UTF-8");
Result result = new MultiFormatReader().decode(bitmap, decodeHints); Result result = new MultiFormatReader().decode(bitmap, decodeHints);
return result.getText(); ZxingTaskVo zxingTaskVo = null;
if (result.getText() != null){
Task task = taskDao.findByParentTaskId(Integer.valueOf(result.getText()));
zxingTaskVo = new ZxingTaskVo(task.getParentTaskId(), task.getId());
}
return zxingTaskVo;
} }
/** /**
...@@ -100,7 +115,6 @@ public class ZXingUtil { ...@@ -100,7 +115,6 @@ public class ZXingUtil {
InputStream in = null; InputStream in = null;
byte[] data = null; byte[] data = null;
// 读取图片字节数组 // 读取图片字节数组
try { try {
in = new FileInputStream(imgFile); in = new FileInputStream(imgFile);
...@@ -113,7 +127,6 @@ public class ZXingUtil { ...@@ -113,7 +127,6 @@ public class ZXingUtil {
} }
// 对字节数组Base64编码 // 对字节数组Base64编码
BASE64Encoder encoder = new BASE64Encoder(); BASE64Encoder encoder = new BASE64Encoder();
return encoder.encode(data);// 返回Base64编码过的字节数组字符串 return encoder.encode(data);// 返回Base64编码过的字节数组字符串
} }
......
package com.tykj.dev.device.zxing.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* DATE:2021-7-20
* Author:zsp
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ZxingTaskVo {
private Integer taskId;
private Integer childTaskId;
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论