Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
D
device-back
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
1
议题
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Matrix
device-back
Commits
48b0757a
提交
48b0757a
authored
4月 26, 2021
作者:
133
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[rfid] 代码待h提交
上级
4af60f3a
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
130 行增加
和
47 行删除
+130
-47
RfidChangeLog.java
...in/java/com/tykj/dev/rfid/entity/domin/RfidChangeLog.java
+1
-2
SplitStringInfo.java
...ain/java/com/tykj/dev/rfid/entity/vo/SplitStringInfo.java
+21
-0
RfidServiceImpl.java
.../java/com/tykj/dev/rfid/service/impl/RfidServiceImpl.java
+108
-45
没有找到文件。
dev-rfid/src/main/java/com/tykj/dev/rfid/entity/domin/RfidChangeLog.java
浏览文件 @
48b0757a
...
...
@@ -31,8 +31,6 @@ import java.util.Date;
@Where
(
clause
=
"delete_tag = 0"
)
@ApiModel
(
"RFID修改日志"
)
public
class
RfidChangeLog
{
/**
* 主键id
*/
...
...
@@ -114,6 +112,7 @@ public class RfidChangeLog {
@ApiModelProperty
(
value
=
"区块链记录id"
)
private
String
recordId
;
public
RfidChangeLog
(
Integer
deviceId
,
String
unit
,
Integer
userAId
,
Integer
userBId
,
String
oldCardId
,
String
newCardId
,
Integer
rfidChangeBillId
,
Integer
validTag
)
{
this
.
deviceId
=
deviceId
;
this
.
unit
=
unit
;
...
...
dev-rfid/src/main/java/com/tykj/dev/rfid/entity/vo/SplitStringInfo.java
0 → 100644
浏览文件 @
48b0757a
package
com
.
tykj
.
dev
.
rfid
.
entity
.
vo
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
/**
* @author HuangXiahao
* @version V1.0
* @class SplitStringInfo
* @packageName com.tykj.dev.rfid.entity.vo
**/
@Data
@AllArgsConstructor
@NoArgsConstructor
public
class
SplitStringInfo
{
private
String
splitString
;
private
Integer
stringLineNumber
;
}
dev-rfid/src/main/java/com/tykj/dev/rfid/service/impl/RfidServiceImpl.java
浏览文件 @
48b0757a
...
...
@@ -6,6 +6,7 @@ import com.tykj.dev.misc.exception.ApiException;
import
com.tykj.dev.misc.utils.ResultUtil
;
import
com.tykj.dev.rfid.entity.vo.RfidCreateVo
;
import
com.tykj.dev.rfid.entity.vo.RfidPrintVo
;
import
com.tykj.dev.rfid.entity.vo.SplitStringInfo
;
import
com.tykj.dev.rfid.service.RfidService
;
import
com.zebra.sdk.comm.Connection
;
import
com.zebra.sdk.comm.ConnectionException
;
...
...
@@ -25,6 +26,7 @@ import java.io.FileOutputStream;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.regex.Pattern
;
/**
* 描述:用于调用RFID打印机打印标签
...
...
@@ -36,6 +38,8 @@ import java.util.List;
@Slf4j
public
class
RfidServiceImpl
implements
RfidService
{
private
static
final
int
RFID_MAX_LENGTH
=
24
;
private
static
final
int
RFID_LINE_LENGTH
=
24
;
private
static
final
Integer
DEFAULT_USB_INDEX
=
0
;
private
static
ZebraPrinter
printer
;
@Resource
...
...
@@ -86,7 +90,7 @@ public class RfidServiceImpl implements RfidService {
@Override
public
boolean
printString
(
String
makeNumber
,
String
deviceNumber
,
String
content
)
{
try
{
Connection
connection
=
new
TcpConnection
(
"1
0.153.4.16
"
,
6101
);
Connection
connection
=
new
TcpConnection
(
"1
92.168.000.222
"
,
6101
);
connection
.
open
();
printer
=
ZebraPrinterFactory
.
getInstance
(
connection
);
String
demoFile
=
createDemoFile
(
printer
.
getPrinterControlLanguage
(),
makeNumber
,
deviceNumber
,
content
,
60
,
55
);
...
...
@@ -98,70 +102,43 @@ public class RfidServiceImpl implements RfidService {
}
catch
(
IOException
e
)
{
throw
new
ApiException
(
ResultUtil
.
failed
(
"生成打印文件失败"
));
}
return
true
;
}
/**
* @param pl 打印机语言
* @param content 打印内容
* @param str1 空格一
* @param str2 空格二
* @param rfidContent 标签数据区内容
* @param marginLeft 标签左边距
* @param marginTop 标签顶部边距
* @return 拼接成功的打印机ZPL
* @throws IOException IO错误
*/
private
String
createDemoFile
(
PrinterLanguage
pl
,
String
makeNumber
,
String
deviceNumber
,
String
content
,
int
marginLeft
,
int
marginTop
)
throws
IOException
{
private
static
String
createDemoFile
(
PrinterLanguage
pl
,
String
rfidContent
,
String
str1
,
String
str2
,
int
marginLeft
,
int
marginTop
)
throws
IOException
{
if
(!
checkRFID
(
rfidContent
)){
throw
new
ApiException
(
""
);
}
File
tmpFile
=
File
.
createTempFile
(
"TEST_ZEBRA"
,
"LBL"
);
FileOutputStream
os
=
new
FileOutputStream
(
tmpFile
);
byte
[]
configLabel
=
null
;
SplitStringInfo
deviceNumberSplit
=
spiltLineString
(
str1
,
null
);
SplitStringInfo
contentSplit
=
spiltLineString
(
str2
,
deviceNumberSplit
.
getStringLineNumber
());
//补零
rfidContent
=
completeRfidStr
(
rfidContent
);
if
(
pl
==
PrinterLanguage
.
ZPL
)
{
configLabel
=
(
"^XA\n"
+
// "~SD25\n" +
"^CW1,E:SIMSUN.FNT"
+
"~TA000\n"
+
"~JSN\n"
+
"^LT0\n"
+
"^MD30\n"
+
"^MNW\n"
+
"^MTT\n"
+
"^PON\n"
+
"^PMN\n"
+
"^LH0,0\n"
+
"^JMA\n"
+
"^PR6,6\n"
+
"~SD15\n"
+
"^JUS\n"
+
"^LRN\n"
+
"^CI28\n"
+
"^PA0,1,1,0\n"
+
"^XZ\n"
+
"^XA\n"
+
"^MMT\n"
+
"^PW428\n"
+
"^LL264\n"
+
"^LS0\n"
+
"\n"
+
"^FS"
+
"^RS,B30\n"
+
"^RFW,H\n"
+
"^FD"
+
c
ontent
+
"\n"
+
"^FS"
+
"^FD"
+
rfidC
ontent
+
"\n"
+
"^FS
\n
"
+
"^LH"
+
marginLeft
+
","
+
marginTop
+
"\n"
+
// "^A1N,22,,E:SIM000.FNT^FR^FD\n" +
// "^LH"+marginLeft+",+"+marginTop +
// "^FDxx测试^FS\n" +
"^A1N,25,,E:SIM000.FNT^FR^FD\n"
+
"^FO0,0^FD生产号:"
+
makeNumber
+
"^FS\n"
+
"^A1N,25,,E:SIM000.FNT^FR^FD\n"
+
"^FO0,30^FD装备号:"
+
deviceNumber
+
"^FS\n"
+
"^A1N,25,,E:SIM000.FNT^FR^FD\n"
+
"^FO0,60^FD表面号:^FS"
+
"^A1N,25,,E:SIM000.FNT^FR^FD\n"
+
"^FO0,90^FD"
+
content
+
"^FS"
+
deviceNumberSplit
.
getSplitString
()+
contentSplit
.
getSplitString
()+
"^PQ1,0,1,Y\n"
+
"^XZ\n"
+
"^XZ"
).
getBytes
();
}
os
.
write
(
configLabel
);
...
...
@@ -170,6 +147,90 @@ public class RfidServiceImpl implements RfidService {
return
tmpFile
.
getAbsolutePath
();
}
public
static
String
completeRfidStr
(
String
rfidStr
){
int
needCompleteLength
=
RFID_MAX_LENGTH
-
rfidStr
.
length
();
StringBuilder
stringBuilder
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
needCompleteLength
;
i
++)
{
stringBuilder
.
append
(
"0"
);
}
return
stringBuilder
.
append
(
rfidStr
).
toString
().
toUpperCase
();
}
/**
* 计算RFID每行的ZPL
* @param content
* @return
*/
public
static
SplitStringInfo
spiltLineString
(
String
content
,
Integer
firstLine
){
//中文占两个字符,使用正则匹配所有的非字符并将lenght*2
StringBuilder
resultStringBuild
=
new
StringBuilder
();
Integer
line
=
firstLine
!=
null
?
firstLine:
0
;
int
totalLine
=
getLineNum
(
content
,
RFID_LINE_LENGTH
);
for
(
int
i
=
0
;
i
<
totalLine
;
i
++)
{
String
cutedStr
=
cutStr
(
content
,
RFID_LINE_LENGTH
);
resultStringBuild
.
append
(
"^A1N,25,,E:SIM000.FNT^FR^FD\n^FO0,"
+
line
*
30
+
"^FD"
+
cutedStr
+
"^FS\n"
);
content
=
content
.
substring
(
cutedStr
.
length
());
line
=
line
+
1
;
}
return
new
SplitStringInfo
(
resultStringBuild
.
toString
(),
line
);
}
public
static
int
getLineNum
(
String
str
,
int
cutLength
){
int
changedStrLenght
=
str
.
replaceAll
(
"[^\\x00-\\xff]"
,
"**"
).
length
();
int
num
=
changedStrLenght
/
cutLength
;
if
(
changedStrLenght
%
cutLength
>
0
){
num
++;
}
return
num
;
}
public
static
String
cutStr
(
String
str
,
int
cutLength
){
int
strlen
=
str
.
length
();
int
chrlen
=
str
.
replaceAll
(
"[^\\x00-\\xff]"
,
"**"
).
length
();
if
(
chrlen
<=
cutLength
){
return
str
;
}
StringBuilder
stringBuilder
=
new
StringBuilder
();
for
(
int
i
=
0
,
j
=
0
;
i
<
strlen
;
i
++)
{
Character
chr
=
str
.
charAt
(
i
);
if
(
chr
<=
255
&&
chr
>=
0
){
j
++;
// ascii码为0-255,一个字符就是一个字节的长度
}
else
{
j
+=
2
;
}
if
(
j
<=
cutLength
){
// 当加上当前字符以后,如果总字节长度小于等于L,则将当前字符真实的+在result后
stringBuilder
.
append
(
chr
);
}
else
{
// 反之则说明result已经是不拆分字符的情况下最接近L的值了,直接返回
return
stringBuilder
.
toString
();
}
}
return
""
;
}
/**
* 校验RFID的格式
* @param rfidStr 写入标签的数据
* @return
*/
public
static
Boolean
checkRFID
(
String
rfidStr
){
int
length
=
rfidStr
.
length
();
if
(
length
>
24
){
return
false
;
}
String
pattern
=
"^[A-Z0-9]+"
;
return
Pattern
.
matches
(
pattern
,
rfidStr
);
}
public
static
void
main
(
String
[]
args
)
throws
ConnectionException
,
ZebraPrinterLanguageUnknownException
,
IOException
{
Connection
connection
=
new
TcpConnection
(
"192.168.0.222"
,
6101
);
connection
.
open
();
printer
=
ZebraPrinterFactory
.
getInstance
(
connection
);
String
demoFile
=
createDemoFile
(
printer
.
getPrinterControlLanguage
(),
"1234"
,
"装备号:xxxxxxxxxxxxxxxxxxxxxxxx"
,
"内容:ABCD"
,
60
,
80
);
printer
.
sendFileContents
(
demoFile
);
}
/**
* 描述:生成装备的RFID表面号
*
...
...
@@ -250,4 +311,6 @@ public class RfidServiceImpl implements RfidService {
return
stringBuffer
.
toString
();
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论