整合demo逻辑
This commit is contained in:
@@ -27,6 +27,11 @@
|
||||
<artifactId>mv-code-reader-ctrl-wrapper</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<!-- Spring Boot 基础依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.klp.reader.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@TableName("scan_result")
|
||||
public class ScanResultEntity {
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
private String code;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.klp.reader.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.klp.reader.entity.ScanResultEntity;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface ScanResultMapper extends BaseMapper<ScanResultEntity> {
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.klp.reader.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.klp.reader.entity.ScanResultEntity;
|
||||
import com.klp.reader.mapper.ScanResultMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import MvCodeReaderCtrlWrapper.*;
|
||||
import MvCodeReaderCtrlWrapper.MvCodeReaderCtrl.*;
|
||||
import MvCodeReaderCtrlWrapper.MvCodeReaderCtrlDefine.*;
|
||||
|
||||
@Service
|
||||
public class ScannerService {
|
||||
private Handle hHandle;
|
||||
|
||||
@Autowired
|
||||
private ScanResultMapper scanResultMapper; // 你需要实现这个Mapper
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
ArrayList<MV_CODEREADER_DEVICE_INFO> stCamList = MvCodeReaderCtrl.MV_CODEREADER_EnumDevices();
|
||||
if (stCamList == null || stCamList.isEmpty()) {
|
||||
System.out.println("Find No Device!");
|
||||
return;
|
||||
}
|
||||
MV_CODEREADER_DEVICE_INFO deviceInfo = stCamList.get(0);
|
||||
try {
|
||||
hHandle = MvCodeReaderCtrl.MV_CODEREADER_CreateHandle(deviceInfo);
|
||||
} catch (ParameterException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
if (hHandle == null) {
|
||||
System.out.println("Create handle failed!");
|
||||
return;
|
||||
}
|
||||
int nRet = MvCodeReaderCtrl.MV_CODEREADER_OpenDevice(hHandle);
|
||||
if (nRet != 0) {
|
||||
System.out.println("Open Device fail! nRet[" + String.format("0x%x", nRet) + "]");
|
||||
return;
|
||||
}
|
||||
MvCodeReaderCtrl.MV_CODEREADER_RegisterImageCallBackEx2(hHandle, (pdata, stOutInfo) -> {
|
||||
handleScanResult(stOutInfo);
|
||||
return 0;
|
||||
});
|
||||
MvCodeReaderCtrl.MV_CODEREADER_StartGrabbing(hHandle);
|
||||
}
|
||||
|
||||
private void handleScanResult(MV_CODEREADER_IMAGE_OUT_INFO_EX2 stOutInfo) {
|
||||
for (int a = 0; a < stOutInfo.pstCodeListEx.nCodeNum; a++) {
|
||||
String code = stOutInfo.pstCodeListEx.stBcrInfoEx.get(a).chCode;
|
||||
// 保存到数据库
|
||||
ScanResultEntity entity = new ScanResultEntity();
|
||||
entity.setCode(code);
|
||||
scanResultMapper.insert(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void destroy() {
|
||||
if (hHandle != null) {
|
||||
MvCodeReaderCtrl.MV_CODEREADER_StopGrabbing(hHandle);
|
||||
MvCodeReaderCtrl.MV_CODEREADER_DestroyHandle(hHandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.klp.reader.ScanResultMapper">
|
||||
<!-- 通用CRUD由MyBatis-Plus自动实现,无需手写SQL -->
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user