Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
Z
zhmes-agecal
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
耿迪迪
zhmes-agecal
Commits
630fa641
Commit
630fa641
authored
Dec 02, 2025
by
wanghao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1 标定柜子 序号调整
parent
48a46e91
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
18 deletions
+69
-18
CalibrationResultEventHandler.java
...ong/system/netty/event/CalibrationResultEventHandler.java
+69
-18
No files found.
zhmes-agecal-system/src/main/java/com/zehong/system/netty/event/CalibrationResultEventHandler.java
View file @
630fa641
...
...
@@ -36,8 +36,13 @@ public class CalibrationResultEventHandler {
@Resource
private
IPalletDeviceUploadHistoryService
palletDeviceUploadHistoryService
;
// 格式: /@A1_1/0/0.0/ 或 /@A2_1/0/0.0/ 或 /@A3_1/0/0.0/
private
static
final
Pattern
DEVICE_PATTERN
=
Pattern
.
compile
(
"/@(A[1-4])_(\\d+)/([^/]+)/([^/]+)"
);
// 格式: /@A1_1/0/0.0/ 或 /@B2_1/0/0.0/ 或 /@C3_1/0/0.0/
// 支持任意大写字母后跟数字的设备标识符,如 A1, B2, C3, D4 等
private
static
final
Pattern
DEVICE_PATTERN
=
Pattern
.
compile
(
"/@([A-Z]\\d+)_(\\d+)/([^/]+)/([^/]+)"
);
// 如果您需要支持多位字母的设备标识符(如 AB1, ABC2 等),可以使用以下正则表达式:
// private static final Pattern DEVICE_PATTERN = Pattern.compile("/@([A-Z]+\\d+)_(\\d+)/([^/]+)/([^/]+)");
@Resource
private
IPalletDeviceBindingService
palletDeviceBindingService
;
...
...
@@ -129,21 +134,21 @@ public class CalibrationResultEventHandler {
String
trayCode
=
parseTrayCode
(
message
);
if
(
StringUtils
.
isBlank
(
trayCode
))
{
log
.
error
(
"无法从消息中解析出托盘号: {}"
,
message
);
log
.
info
(
"无法从消息中解析出托盘号: {}"
,
message
);
return
new
ArrayList
<>();
}
List
<
PalletDeviceBinding
>
palletDeviceBindings
=
palletDeviceBindingService
.
listByTrayCode
(
trayCode
);
if
(
palletDeviceBindings
.
isEmpty
())
{
log
.
warn
(
"未找到托盘号 {} 绑定的设备"
,
trayCode
);
log
.
info
(
"未找到托盘号 {} 绑定的设备"
,
trayCode
);
return
new
ArrayList
<>();
}
// 根据message 处理 标定浓度值 标定状态
List
<
DeviceData
>
deviceDataList
=
parseDeviceData
(
message
);
if
(
deviceDataList
.
isEmpty
())
{
log
.
warn
(
"消息中未包含有效的设备数据: {}"
,
message
);
log
.
info
(
"消息中未包含有效的设备数据: {}"
,
message
);
return
palletDeviceBindings
;
}
...
...
@@ -159,7 +164,7 @@ public class CalibrationResultEventHandler {
/**
* 阶段一:解析托盘号
* 消息格式: @00012346/@A1_1/0/0.0/@
A1_2/0/0.0/@A1
_3/0/0.0/
* 消息格式: @00012346/@A1_1/0/0.0/@
B2_2/0/0.0/@C3
_3/0/0.0/
*/
private
String
parseTrayCode
(
String
message
)
{
if
(
StringUtils
.
isBlank
(
message
)
||
!
message
.
startsWith
(
"@"
))
{
...
...
@@ -177,7 +182,7 @@ public class CalibrationResultEventHandler {
// 提取托盘号(去掉开头的@)
return
message
.
substring
(
1
,
endIndex
);
}
catch
(
Exception
e
)
{
log
.
error
(
"解析托盘号失败: {}"
,
message
,
e
);
log
.
info
(
"解析托盘号失败: {}"
,
message
,
e
);
return
null
;
}
}
...
...
@@ -199,9 +204,11 @@ public class CalibrationResultEventHandler {
while
(
deviceMatcher
.
find
())
{
try
{
String
sequenceStr
=
deviceMatcher
.
group
(
1
);
// 顺序号
String
statusStr
=
deviceMatcher
.
group
(
2
);
// 标定状态
String
valueStr
=
deviceMatcher
.
group
(
3
);
// 标定值
// 修改后:group(1) 是设备标识符(如A1, B2, C3等),group(2) 是顺序号
String
deviceType
=
deviceMatcher
.
group
(
1
);
// 设备类型,如A1, B2, C3等
String
sequenceStr
=
deviceMatcher
.
group
(
2
);
// 顺序号
String
statusStr
=
deviceMatcher
.
group
(
3
);
// 标定状态
String
valueStr
=
deviceMatcher
.
group
(
4
);
// 标定值
// 解析数据
Integer
sequenceNumber
=
parseInt
(
sequenceStr
);
...
...
@@ -209,21 +216,22 @@ public class CalibrationResultEventHandler {
if
(
sequenceNumber
!=
null
)
{
DeviceData
deviceData
=
new
DeviceData
();
deviceData
.
setDeviceType
(
deviceType
);
// 存储设备类型(如果需要)
deviceData
.
setSequenceNumber
(
sequenceNumber
);
deviceData
.
setCalibrationStatus
(
statusStr
);
deviceData
.
setCalibrationValue
(
calibrationValue
);
deviceDataList
.
add
(
deviceData
);
log
.
debug
(
"解析到设备数据:
顺序号={}, 状态={}, 值={}"
,
sequenceNumber
,
statusStr
,
calibrationValue
);
log
.
info
(
"解析到设备数据: 设备类型={},
顺序号={}, 状态={}, 值={}"
,
deviceType
,
sequenceNumber
,
statusStr
,
calibrationValue
);
}
}
catch
(
Exception
e
)
{
log
.
warn
(
"解析设备数据失败,跳过此设备: {}"
,
deviceMatcher
.
group
(),
e
);
log
.
info
(
"解析设备数据失败,跳过此设备: {}"
,
deviceMatcher
.
group
(),
e
);
}
}
}
catch
(
Exception
e
)
{
log
.
error
(
"解析设备数据列表失败: {}"
,
message
,
e
);
log
.
info
(
"解析设备数据列表失败: {}"
,
message
,
e
);
}
return
deviceDataList
;
...
...
@@ -240,7 +248,7 @@ public class CalibrationResultEventHandler {
try
{
return
Integer
.
parseInt
(
str
.
trim
());
}
catch
(
NumberFormatException
e
)
{
log
.
warn
(
"解析整数失败: {}"
,
str
,
e
);
log
.
info
(
"解析整数失败: {}"
,
str
,
e
);
return
null
;
}
}
...
...
@@ -255,7 +263,7 @@ public class CalibrationResultEventHandler {
try
{
return
new
BigDecimal
(
str
.
trim
());
}
catch
(
NumberFormatException
e
)
{
log
.
warn
(
"解析BigDecimal失败: {}"
,
str
,
e
);
log
.
info
(
"解析BigDecimal失败: {}"
,
str
,
e
);
return
null
;
}
}
...
...
@@ -296,7 +304,7 @@ public class CalibrationResultEventHandler {
// 可以添加其他字段的更新,比如更新时间等
binding
.
setUpdateTime
(
new
Date
());
log
.
debug
(
"更新设备绑定: 顺序号={}, 托盘号={}, 状态={}, 值={}"
,
log
.
info
(
"更新设备绑定: 顺序号={}, 托盘号={}, 状态={}, 值={}"
,
sequenceNumber
,
binding
.
getfTrayCode
(),
deviceData
.
getCalibrationStatus
(),
deviceData
.
getCalibrationValue
());
...
...
@@ -401,4 +409,47 @@ public class CalibrationResultEventHandler {
return
history
;
}
/**
* 设备数据内部类(如果需要存储设备类型,可以扩展此类)
*/
private
static
class
DeviceData
{
private
String
deviceType
;
// 设备类型,如A1, B2, C3等
private
Integer
sequenceNumber
;
// 顺序号
private
String
calibrationStatus
;
// 标定状态
private
BigDecimal
calibrationValue
;
// 标定值
// getter 和 setter 方法
public
String
getDeviceType
()
{
return
deviceType
;
}
public
void
setDeviceType
(
String
deviceType
)
{
this
.
deviceType
=
deviceType
;
}
public
Integer
getSequenceNumber
()
{
return
sequenceNumber
;
}
public
void
setSequenceNumber
(
Integer
sequenceNumber
)
{
this
.
sequenceNumber
=
sequenceNumber
;
}
public
String
getCalibrationStatus
()
{
return
calibrationStatus
;
}
public
void
setCalibrationStatus
(
String
calibrationStatus
)
{
this
.
calibrationStatus
=
calibrationStatus
;
}
public
BigDecimal
getCalibrationValue
()
{
return
calibrationValue
;
}
public
void
setCalibrationValue
(
BigDecimal
calibrationValue
)
{
this
.
calibrationValue
=
calibrationValue
;
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment