Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
Z
zh-mes-device-data-process
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
耿迪迪
zh-mes-device-data-process
Commits
80e7b759
Commit
80e7b759
authored
Jun 06, 2025
by
耿迪迪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
产品扫码解析接口
parent
7d1d945b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
158 additions
and
0 deletions
+158
-0
ProduceCodeRules.java
src/main/java/com/zehong/constant/ProduceCodeRules.java
+27
-0
ScanCodeResultController.java
.../java/com/zehong/controller/ScanCodeResultController.java
+27
-0
ProduceScanCodeResultService.java
...java/com/zehong/service/ProduceScanCodeResultService.java
+14
-0
ProduceScanCodeResultServiceImpl.java
...zehong/service/impl/ProduceScanCodeResultServiceImpl.java
+90
-0
No files found.
src/main/java/com/zehong/constant/ProduceCodeRules.java
0 → 100644
View file @
80e7b759
package
com
.
zehong
.
constant
;
/**
* 产品扫码规则
*/
public
enum
ProduceCodeRules
{
/**
* 产品编码
*/
PRODUCECODE
(
"PROD\\d{14}"
),
/**
* 设备码
*/
DEVICECODE
(
"PCBA\\d{14}"
);
private
String
regex
;
ProduceCodeRules
(
String
regex
)
{
this
.
regex
=
regex
;
}
public
String
getRegex
()
{
return
regex
;
}
}
src/main/java/com/zehong/controller/ScanCodeResultController.java
View file @
80e7b759
package
com
.
zehong
.
controller
;
import
com.zehong.entity.AjaxResult
;
import
com.zehong.service.ProduceScanCodeResultService
;
import
com.zehong.service.ScanCodeResultService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
...
...
@@ -17,11 +18,37 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping
(
"/scan"
)
public
class
ScanCodeResultController
extends
BaseController
{
/**
* pcba扫码接口
*/
@Autowired
private
ScanCodeResultService
scanCodeResultService
;
/**
* 产品扫码接口
*/
@Autowired
private
ProduceScanCodeResultService
produceScanCodeResultService
;
/**
* pcba 扫码结果
* @param message 扫码信息
* @return
*/
@PostMapping
(
"/scanCode"
)
public
AjaxResult
scanCode
(
@RequestBody
String
message
)
{
return
toAjax
(
scanCodeResultService
.
scanCodeResult
(
message
));
}
/**
* 产品扫码结果
* @param message 扫码信息
* @return
*/
@PostMapping
(
"/produceScanCode"
)
public
AjaxResult
produceScanCode
(
@RequestBody
String
message
)
{
return
toAjax
(
produceScanCodeResultService
.
produceScanCodeResult
(
message
));
}
}
src/main/java/com/zehong/service/ProduceScanCodeResultService.java
0 → 100644
View file @
80e7b759
package
com
.
zehong
.
service
;
/**
* 产品扫码结果
*/
public
interface
ProduceScanCodeResultService
{
/**
* 产品扫码结果
* @param message 扫码信息
* @return
*/
int
produceScanCodeResult
(
String
message
);
}
src/main/java/com/zehong/service/impl/ProduceScanCodeResultServiceImpl.java
0 → 100644
View file @
80e7b759
package
com
.
zehong
.
service
.
impl
;
import
com.baomidou.dynamic.datasource.annotation.DS
;
import
com.zehong.constant.ProduceCodeRules
;
import
com.zehong.service.ProduceScanCodeResultService
;
import
com.zehong.utils.RedisCache
;
import
com.zehong.utils.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
/**
* 产品扫码结果
*/
@Service
@DS
(
"mes"
)
public
class
ProduceScanCodeResultServiceImpl
implements
ProduceScanCodeResultService
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
ProduceScanCodeResultServiceImpl
.
class
);
@Autowired
private
RedisCache
redisCache
;
/**
* 产品扫码规则
*/
private
final
Map
<
String
,
Pattern
>
produceRules
=
new
HashMap
<>();
{
for
(
ProduceCodeRules
rule:
ProduceCodeRules
.
values
()){
produceRules
.
put
(
rule
.
name
(),
Pattern
.
compile
(
rule
.
getRegex
()));
}
}
/**
* 产品扫码结果
* @param message 扫码信息
* @return int
*/
@Override
public
int
produceScanCodeResult
(
String
message
){
log
.
info
(
"扫码结果字符串========="
+
message
);
Map
<
String
,
Object
>
result
=
analysisProduceMessage
(
message
);
return
addProduceDevice
(
result
);
}
/**
* 解析产品信息
* @param message 扫码信息
* @return Map<String,Object>
*/
private
Map
<
String
,
Object
>
analysisProduceMessage
(
String
message
){
Map
<
String
,
Object
>
result
=
new
HashMap
<>();
for
(
Map
.
Entry
<
String
,
Pattern
>
rule
:
produceRules
.
entrySet
()){
List
<
String
>
codes
=
new
ArrayList
<>();
Matcher
m
=
rule
.
getValue
().
matcher
(
message
);
while
(
m
.
find
()){
String
code
=
m
.
group
();
codes
.
add
(
code
);
message
=
message
.
replace
(
code
,
""
);
}
if
(!
CollectionUtils
.
isEmpty
(
codes
))
result
.
put
(
rule
.
getKey
(),
codes
);
}
//扫描设备码
if
(
StringUtils
.
isNotEmpty
(
message
))
result
.
put
(
"deviceCode"
,
message
);
return
result
;
}
/**
* 新增产品设备
* @param result 解析结果
* @return int
*/
private
int
addProduceDevice
(
Map
<
String
,
Object
>
result
){
return
0
;
}
}
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