Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
聂康
local-rnr-fp
Commits
015d4257
Commit
015d4257
authored
Jun 17, 2025
by
kang.nie@inzymeits.com
Browse files
初始化代码
parent
bd38ff8b
Pipeline
#3108
failed with stages
in 0 seconds
Changes
404
Pipelines
1
Show whitespace changes
Inline
Side-by-side
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/fp/util/SnowflakeIdWorker.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.fp.util
;
import
java.lang.management.ManagementFactory
;
import
java.lang.management.RuntimeMXBean
;
import
java.net.NetworkInterface
;
import
java.net.SocketException
;
import
java.util.Enumeration
;
/**
* @className: SnowflakeIdWorker
* @description: 雪花算法
* @author: jk
* @date: 2022/8/2 10:40
* @version: 1.0
**/
public
class
SnowflakeIdWorker
{
//初始时间值
private
final
static
long
twepoch
=
12888349746579L
;
// 机器标识位数
private
final
static
long
workerIdBits
=
5L
;
// 数据中心标识位数
private
final
static
long
datacenterIdBits
=
5L
;
// 毫秒内自增位数
private
final
static
long
sequenceBits
=
12L
;
// 机器ID偏左移12位
private
final
static
long
workerIdShift
=
sequenceBits
;
// 数据中心ID左移17位
private
final
static
long
datacenterIdShift
=
sequenceBits
+
workerIdBits
;
// 时间毫秒左移22位
private
final
static
long
timestampLeftShift
=
sequenceBits
+
workerIdBits
+
datacenterIdBits
;
//sequence掩码,确保sequnce不会超出上限
private
final
static
long
sequenceMask
=
-
1L
^
(-
1L
<<
sequenceBits
);
//上次时间戳
private
static
long
lastTimestamp
=
-
1L
;
//序列
private
long
sequence
=
0L
;
//服务器ID
private
long
workerId
=
1L
;
private
static
long
workerMask
=
-
1L
^
(-
1L
<<
workerIdBits
);
//进程编码
private
long
processId
=
1L
;
private
static
long
processMask
=
-
1L
^
(-
1L
<<
datacenterIdBits
);
private
static
SnowflakeIdWorker
snowFlake
=
null
;
static
{
snowFlake
=
new
SnowflakeIdWorker
();
}
public
static
long
nextId
(){
return
snowFlake
.
getNextId
();
}
private
SnowflakeIdWorker
()
{
//获取机器编码
this
.
workerId
=
this
.
getMachineNum
();
//获取进程编码
RuntimeMXBean
runtimeMXBean
=
ManagementFactory
.
getRuntimeMXBean
();
this
.
processId
=
Long
.
valueOf
(
runtimeMXBean
.
getName
().
split
(
"@"
)[
0
]).
longValue
();
//避免编码超出最大值
this
.
workerId
=
workerId
&
workerMask
;
this
.
processId
=
processId
&
processMask
;
}
public
long
getNextId
()
{
//获取时间戳
long
timestamp
=
timeGen
();
//如果时间戳小于上次时间戳则报错
if
(
timestamp
<
lastTimestamp
)
{
try
{
throw
new
Exception
(
"Clock moved backwards. Refusing to generate id for "
+
(
lastTimestamp
-
timestamp
)
+
" milliseconds"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
//如果时间戳与上次时间戳相同
if
(
lastTimestamp
==
timestamp
)
{
// 当前毫秒内,则+1,与sequenceMask确保sequence不会超出上限
sequence
=
(
sequence
+
1
)
&
sequenceMask
;
if
(
sequence
==
0
)
{
// 当前毫秒内计数满了,则等待下一秒
timestamp
=
tilNextMillis
(
lastTimestamp
);
}
}
else
{
sequence
=
0
;
}
lastTimestamp
=
timestamp
;
// ID偏移组合生成最终的ID,并返回ID
long
nextId
=
((
timestamp
-
twepoch
)
<<
timestampLeftShift
)
|
(
processId
<<
datacenterIdShift
)
|
(
workerId
<<
workerIdShift
)
|
sequence
;
return
nextId
;
}
/**
* 再次获取时间戳直到获取的时间戳与现有的不同
* @param lastTimestamp
* @return 下一个时间戳
*/
private
long
tilNextMillis
(
final
long
lastTimestamp
)
{
long
timestamp
=
this
.
timeGen
();
while
(
timestamp
<=
lastTimestamp
)
{
timestamp
=
this
.
timeGen
();
}
return
timestamp
;
}
private
long
timeGen
()
{
return
System
.
currentTimeMillis
();
}
/**
* 获取机器编码
* @return
*/
private
long
getMachineNum
(){
long
machinePiece
;
StringBuilder
sb
=
new
StringBuilder
();
Enumeration
<
NetworkInterface
>
e
=
null
;
try
{
e
=
NetworkInterface
.
getNetworkInterfaces
();
}
catch
(
SocketException
e1
)
{
e1
.
printStackTrace
();
}
while
(
e
.
hasMoreElements
())
{
NetworkInterface
ni
=
e
.
nextElement
();
sb
.
append
(
ni
.
toString
());
}
machinePiece
=
sb
.
toString
().
hashCode
();
return
machinePiece
;
}
}
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/fp/util/ZTSecurityUtil.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.fp.util
;
import
com.alibaba.fastjson.JSONObject
;
import
java.io.UnsupportedEncodingException
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Collections
;
import
java.util.LinkedList
;
import
java.util.List
;
/**
* @author zealot
* @date 2021/7/29
*/
public
class
ZTSecurityUtil
{
private
static
final
String
ENCODING
=
"UTF-8"
;
public
static
String
toString
(
byte
[]
bytes
)
{
try
{
return
new
String
(
bytes
,
ENCODING
);
}
catch
(
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
public
static
byte
[]
toBytes
(
String
str
)
{
try
{
return
str
.
getBytes
(
ENCODING
);
}
catch
(
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
public
static
String
toHexString
(
byte
[]
b
)
{
StringBuilder
sb
=
new
StringBuilder
();
for
(
byte
value
:
b
)
{
String
hex
=
Integer
.
toHexString
(
value
&
0xFF
);
if
(
hex
.
length
()
==
1
)
{
hex
=
'0'
+
hex
;
}
sb
.
append
(
hex
);
}
return
sb
.
toString
();
}
public
static
byte
[]
hexStringToByte
(
String
s
)
{
if
(
s
==
null
||
s
.
equals
(
""
))
{
return
null
;
}
s
=
s
.
replace
(
" "
,
""
);
byte
[]
baKeyword
=
new
byte
[
s
.
length
()
/
2
];
for
(
int
i
=
0
;
i
<
baKeyword
.
length
;
i
++)
{
try
{
baKeyword
[
i
]
=
(
byte
)
(
0xff
&
Integer
.
parseInt
(
s
.
substring
(
i
*
2
,
i
*
2
+
2
),
16
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
return
baKeyword
;
}
public
static
String
hexStringToString
(
String
s
)
{
if
(
s
==
null
||
s
.
equals
(
""
))
{
return
null
;
}
s
=
s
.
replace
(
" "
,
""
);
byte
[]
baKeyword
=
new
byte
[
s
.
length
()
/
2
];
for
(
int
i
=
0
;
i
<
baKeyword
.
length
;
i
++)
{
try
{
baKeyword
[
i
]
=
(
byte
)
(
0xff
&
Integer
.
parseInt
(
s
.
substring
(
i
*
2
,
i
*
2
+
2
),
16
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
try
{
s
=
new
String
(
baKeyword
,
StandardCharsets
.
UTF_8
);
}
catch
(
Exception
e1
)
{
e1
.
printStackTrace
();
}
return
s
;
}
/**
* 将map格式化成key1=value1&key2=value2……(其中按自然排序)
*/
public
static
String
naturalSortingKV
(
JSONObject
json
)
{
StringBuilder
sb
=
new
StringBuilder
();
List
<
String
>
list
=
new
LinkedList
<>();
json
.
forEach
((
k
,
v
)
->
list
.
add
(
"&"
+
k
+
"="
+
v
));
Collections
.
sort
(
list
);
// 自然排序
list
.
forEach
(
sb:
:
append
);
return
sb
.
substring
(
1
);
}
}
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/fp/util/ZipUtils.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.fp.util
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.*
;
import
java.util.Enumeration
;
import
java.util.List
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipFile
;
import
java.util.zip.ZipOutputStream
;
/**
* @author hxin
* @date 2022/6/7 15:32
*/
public
class
ZipUtils
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
ZipUtils
.
class
);
private
static
final
int
BUFFER_SIZE
=
2
*
1024
;
/**
* 压缩成ZIP 方法1
* @param srcDir 压缩文件夹路径
* @param out 压缩文件输出流
* @param KeepDirStructure 是否保留原来的目录结构,true:保留目录结构;
* false:所有文件跑到压缩包根目录下(注意:不保留目录结构可能会出现同名文件,会压缩失败)
* @throws RuntimeException 压缩失败会抛出运行时异常
*/
public
static
void
toZip
(
String
srcDir
,
OutputStream
out
,
boolean
KeepDirStructure
)
{
long
start
=
System
.
currentTimeMillis
();
ZipOutputStream
zos
=
null
;
try
{
zos
=
new
ZipOutputStream
(
out
);
File
sourceFile
=
new
File
(
srcDir
);
compress
(
sourceFile
,
zos
,
sourceFile
.
getName
(),
KeepDirStructure
);
long
end
=
System
.
currentTimeMillis
();
log
.
info
(
"压缩完成,耗时:"
+
(
end
-
start
)
+
" ms"
);
}
catch
(
Exception
e
)
{
log
.
error
(
"zip error from ZipUtils"
,
e
);
}
finally
{
if
(
zos
!=
null
){
try
{
//输出流一定要按顺序关闭,先关闭ZipOutputStream 在关闭OutputStream,不然有问题!!!
zos
.
close
();
out
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
/**
* 压缩成ZIP 方法2
* @param srcFiles 需要压缩的文件列表
* @param out 压缩文件输出流
* @throws RuntimeException 压缩失败会抛出运行时异常
*/
public
static
void
toZip
(
List
<
File
>
srcFiles
,
OutputStream
out
){
long
start
=
System
.
currentTimeMillis
();
ZipOutputStream
zos
=
null
;
try
{
zos
=
new
ZipOutputStream
(
out
);
for
(
File
srcFile
:
srcFiles
)
{
byte
[]
buf
=
new
byte
[
BUFFER_SIZE
];
zos
.
putNextEntry
(
new
ZipEntry
(
srcFile
.
getName
()));
int
len
;
FileInputStream
in
=
new
FileInputStream
(
srcFile
);
while
((
len
=
in
.
read
(
buf
))
!=
-
1
){
zos
.
write
(
buf
,
0
,
len
);
}
zos
.
closeEntry
();
in
.
close
();
}
long
end
=
System
.
currentTimeMillis
();
log
.
info
(
"压缩完成,耗时:"
+
(
end
-
start
)
+
" ms"
);
}
catch
(
Exception
e
)
{
log
.
error
(
"ZipUtils toZip error "
,
e
);
}
finally
{
if
(
zos
!=
null
){
try
{
zos
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
/**
* 递归压缩方法
* @param sourceFile 源文件
* @param zos zip输出流
* @param name 压缩后的名称
* @param KeepDirStructure 是否保留原来的目录结构,true:保留目录结构;
* false:所有文件跑到压缩包根目录下(注意:不保留目录结构可能会出现同名文件,会压缩失败)
* @throws Exception
*/
private
static
void
compress
(
File
sourceFile
,
ZipOutputStream
zos
,
String
name
,
boolean
KeepDirStructure
)
throws
Exception
{
byte
[]
buf
=
new
byte
[
BUFFER_SIZE
];
if
(
sourceFile
.
isFile
()){
// 向zip输出流中添加一个zip实体,构造器中name为zip实体的文件的名字
zos
.
putNextEntry
(
new
ZipEntry
(
name
));
// copy文件到zip输出流中
int
len
;
FileInputStream
in
=
new
FileInputStream
(
sourceFile
);
while
((
len
=
in
.
read
(
buf
))
!=
-
1
){
zos
.
write
(
buf
,
0
,
len
);
}
// Complete the entry
zos
.
closeEntry
();
in
.
close
();
}
else
{
File
[]
listFiles
=
sourceFile
.
listFiles
();
if
(
listFiles
==
null
||
listFiles
.
length
==
0
){
// 需要保留原来的文件结构时,需要对空文件夹进行处理
if
(
KeepDirStructure
){
// 空文件夹的处理
zos
.
putNextEntry
(
new
ZipEntry
(
name
+
"/"
));
// 没有文件,不需要文件的copy
zos
.
closeEntry
();
}
}
else
{
for
(
File
file
:
listFiles
)
{
// 判断是否需要保留原来的文件结构
if
(
KeepDirStructure
)
{
// 注意:file.getName()前面需要带上父文件夹的名字加一斜杠,
// 不然最后压缩包中就不能保留原来的文件结构,即:所有文件都跑到压缩包根目录下了
compress
(
file
,
zos
,
name
+
"/"
+
file
.
getName
(),
KeepDirStructure
);
}
else
{
compress
(
file
,
zos
,
file
.
getName
(),
KeepDirStructure
);
}
}
}
}
}
/***
* 删除指定文件夹下所有文件
* @param file 文件夹完整绝对路径-对象
* @return
*/
public
static
void
deleteDir
(
File
file
){
if
(!
file
.
exists
())
{
return
;
}
//判断是否为文件夹
if
(
file
.
isDirectory
()){
//获取该文件夹下的子文件夹
File
[]
files
=
file
.
listFiles
();
//循环子文件夹重复调用delete方法
for
(
int
i
=
0
;
i
<
files
.
length
;
i
++)
{
deleteDir
(
files
[
i
]);
}
}
//若为空文件夹或者文件删除,File类的删除方法
file
.
delete
();
}
/**
* 解压zip
* @param srcFile
* @param destDirPath
* @throws RuntimeException
*/
public
static
void
unZip
(
File
srcFile
,
String
destDirPath
)
{
long
start
=
System
.
currentTimeMillis
();
// 判断源文件是否存在
if
(!
srcFile
.
exists
())
{
log
.
error
(
srcFile
.
getPath
()
+
"所指文件不存在"
);
}
// 开始解压
ZipFile
zipFile
=
null
;
try
{
zipFile
=
new
ZipFile
(
srcFile
);
Enumeration
<?>
entries
=
zipFile
.
entries
();
while
(
entries
.
hasMoreElements
())
{
ZipEntry
entry
=
(
ZipEntry
)
entries
.
nextElement
();
log
.
info
(
"解压"
+
entry
.
getName
());
// 如果是文件夹,就创建个文件夹
if
(
entry
.
isDirectory
())
{
String
dirPath
=
destDirPath
+
"/"
+
entry
.
getName
();
File
dir
=
new
File
(
dirPath
);
dir
.
mkdirs
();
}
else
{
// 如果是文件,就先创建一个文件,然后用io流把内容copy过去
File
targetFile
=
new
File
(
destDirPath
+
"/"
+
entry
.
getName
());
// 保证这个文件的父文件夹必须要存在
if
(!
targetFile
.
getParentFile
().
exists
()){
targetFile
.
getParentFile
().
mkdirs
();
}
targetFile
.
createNewFile
();
// 将压缩文件内容写入到这个文件中
InputStream
is
=
zipFile
.
getInputStream
(
entry
);
FileOutputStream
fos
=
new
FileOutputStream
(
targetFile
);
int
len
;
byte
[]
buf
=
new
byte
[
BUFFER_SIZE
];
while
((
len
=
is
.
read
(
buf
))
!=
-
1
)
{
fos
.
write
(
buf
,
0
,
len
);
}
// 关流顺序,先打开的后关闭
fos
.
close
();
is
.
close
();
}
}
long
end
=
System
.
currentTimeMillis
();
log
.
info
(
"解压完成,耗时:"
+
(
end
-
start
)
+
" ms"
);
}
catch
(
Exception
e
)
{
log
.
error
(
"ZipUtils unZip error "
,
e
);
}
finally
{
if
(
zipFile
!=
null
){
try
{
zipFile
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
public
static
byte
[]
inputStream2byteArr
(
InputStream
input
)
{
ByteArrayOutputStream
output
=
new
ByteArrayOutputStream
();
try
{
byte
[]
buffer
=
new
byte
[
1024
*
2
];
int
n
=
0
;
while
(
(
n
=
input
.
read
(
buffer
))
!=
-
1
)
{
output
.
write
(
buffer
,
0
,
n
);
}
return
output
.
toByteArray
();
}
catch
(
IOException
e
)
{
log
.
error
(
"inputStream2byteArr error "
,
e
);
}
finally
{
try
{
output
.
close
();
}
catch
(
IOException
e
)
{
log
.
error
(
"inputStream2byteArr close error "
,
e
);
}
}
return
null
;
}
public
static
void
byte2file
(
String
path
,
byte
[]
data
)
{
try
{
//FileOutputStream outputStream = new FileOutputStream(path);
BufferedOutputStream
outputStream
=
new
BufferedOutputStream
(
new
FileOutputStream
(
path
));
outputStream
.
write
(
data
);
outputStream
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
public
static
byte
[]
readByteFromFile
(
String
pathName
)
{
File
file
=
new
File
(
pathName
);
ByteArrayOutputStream
out
=
null
;
BufferedInputStream
in
=
null
;
try
{
in
=
new
BufferedInputStream
(
new
FileInputStream
(
file
));
out
=
new
ByteArrayOutputStream
(
1024
*
2
);
byte
[]
temp
=
new
byte
[
1024
*
2
];
int
size
=
0
;
while
((
size
=
in
.
read
(
temp
))
!=
-
1
)
{
out
.
write
(
temp
,
0
,
size
);
}
byte
[]
content
=
out
.
toByteArray
();
return
content
;
}
catch
(
IOException
e
)
{
log
.
error
(
"readByteFromFile error "
,
e
);
}
finally
{
try
{
in
.
close
();
out
.
close
();
}
catch
(
IOException
e
)
{
log
.
error
(
"readByteFromFile close error "
,
e
);
}
}
return
null
;
}
// public static void main(String[] args) throws Exception {
// String filePath = "D:\\static\\temporary";
// String zipPath = "D:\\ccc.zip";
// /** 测试压缩方法1 */
// FileOutputStream fos1 = new FileOutputStream(new File(zipPath));
// ZipUtils.toZip(filePath, fos1,true);
//
// /** 测试压缩方法2 */
// List<File> fileList = new ArrayList<>();
// fileList.add(new File("D:\\test1.txt"));
// fileList.add(new File("D:\\test222.txt"));
// FileOutputStream fos2 = new FileOutputStream(new File("D:\\test.zip"));
// ZipUtils.toZip(fileList, fos2);
// }
}
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/project/constant/ProjectConstant.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.project.constant
;
/**
* @author stayAnd
* @date 2022/4/7
*/
public
class
ProjectConstant
{
/**
* 项目业务 服务的url
*/
public
static
final
String
PROJECT_SERVICE_URL
=
"http://project-service"
;
}
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/project/constant/SignConstants.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.project.constant
;
/**
* 签名静态属性
*/
public
class
SignConstants
{
/**应用ID的key名称*/
public
final
static
String
APP_ID
=
"APPID"
;
/**随机数key*/
public
final
static
String
NONCE_STR
=
"NONCE_STR"
;
/**时间戳key*/
public
final
static
String
TIMESTAMP
=
"TIMESTAMP"
;
/**版本key*/
public
final
static
String
VERSION
=
"VERSION"
;
/**签名key*/
public
final
static
String
SIGN
=
"SIGN"
;
}
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/project/context/VinCardContext.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.project.context
;
import
com.cusc.nirvana.user.rnr.project.handler.VinCardHandler
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.Resource
;
import
java.util.Map
;
/**
* @author stayAnd
* @date 2022/4/8
*/
@Component
public
class
VinCardContext
{
@Resource
private
Map
<
String
,
VinCardHandler
>
map
;
@Value
(
"${vin.card.name:internalVinCardHandler}"
)
private
String
vinCardHandlerName
;
public
VinCardHandler
getVinCardHandler
(){
VinCardHandler
vinCardHandler
=
map
.
get
(
vinCardHandlerName
);
if
(
null
==
vinCardHandler
)
{
//throw exception
}
return
vinCardHandler
;
}
}
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/project/dto/ProjectCardExistRequestDTO.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.project.dto
;
import
lombok.Data
;
/**
* @author yubo
* @since 2022-04-18 15:03
*/
@Data
public
class
ProjectCardExistRequestDTO
{
//iccid
private
String
iccid
;
}
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/project/dto/ProjectCardExistResponseDTO.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.project.dto
;
import
lombok.Data
;
/**
* iccid卡是否存在DTO
* @author yubo
* @since 2022-04-18 15:01
*/
@Data
public
class
ProjectCardExistResponseDTO
{
//是否存在
private
boolean
exist
;
}
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/project/dto/ProjectVinCardRequestDTO.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.project.dto
;
import
lombok.Data
;
import
lombok.experimental.Accessors
;
import
java.util.List
;
/**
* @author stayAnd
* @date 2022/4/7
* 请求 项目服务 根据vin码查询iccid的请求
*/
@Data
@Accessors
(
chain
=
true
)
public
class
ProjectVinCardRequestDTO
{
private
List
<
String
>
vins
;
}
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/project/dto/ProjectVinCardResponseDTO.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.project.dto
;
import
lombok.Data
;
import
lombok.experimental.Accessors
;
import
java.util.List
;
/**
* @author stayAnd
* @date 2022/4/7
*/
@Data
@Accessors
(
chain
=
true
)
public
class
ProjectVinCardResponseDTO
{
private
List
<
ProjectVinCardInfoDTO
>
rels
;
@Data
@Accessors
(
chain
=
true
)
public
static
class
ProjectVinCardInfoDTO
{
private
String
vin
;
private
List
<
String
>
iccids
;
}
}
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/project/handler/CuscVinCardHandler.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.project.handler
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.rnr.fp.dto.VehicleCardDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.VinCardInfoDTO
;
import
com.cusc.nirvana.user.rnr.fp.util.RnrFpRestTemplateUtils
;
import
com.cusc.nirvana.user.rnr.project.dto.ProjectCardExistRequestDTO
;
import
com.cusc.nirvana.user.rnr.project.dto.ProjectCardExistResponseDTO
;
import
com.cusc.nirvana.user.rnr.project.dto.ProjectVinCardRequestDTO
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.web.client.RestTemplate
;
import
javax.annotation.Resource
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
* @author stayAnd
* @date 2022/4/8
*/
@Slf4j
public
abstract
class
CuscVinCardHandler
implements
VinCardHandler
{
@Resource
protected
RestTemplate
balancedRestTemplateRnrFp
;
protected
VinCardInfoDTO
queryVinCard
(
String
url
,
String
vin
)
{
List
<
VehicleCardDTO
>
list
=
queryVinCardFromProjectService
(
url
,
Collections
.
singletonList
(
vin
));
VinCardInfoDTO
vinCardInfoDTO
=
new
VinCardInfoDTO
();
vinCardInfoDTO
.
setVin
(
vin
);
List
<
String
>
iccids
=
list
.
stream
().
filter
(
dto
->
dto
.
getVin
().
equals
(
vin
)).
map
(
dto
->
dto
.
getIccid
()).
collect
(
Collectors
.
toList
());
vinCardInfoDTO
.
setIccidList
(
iccids
);
return
vinCardInfoDTO
;
}
protected
List
<
VinCardInfoDTO
>
queryVinCardList
(
String
url
,
List
<
String
>
vinList
)
{
List
<
VehicleCardDTO
>
vehicleCardDTOS
=
queryVinCardFromProjectService
(
url
,
vinList
);
Map
<
String
,
VinCardInfoDTO
>
vehicleCardDTOMap
=
new
HashMap
<>();
for
(
VehicleCardDTO
vehicleCardDTO
:
vehicleCardDTOS
)
{
if
(!
vehicleCardDTOMap
.
containsKey
(
vehicleCardDTO
.
getVin
())){
VinCardInfoDTO
vinCardInfoDTO
=
new
VinCardInfoDTO
();
vinCardInfoDTO
.
setVin
(
vehicleCardDTO
.
getVin
());
vinCardInfoDTO
.
setIccidList
(
new
ArrayList
<>());
vehicleCardDTOMap
.
put
(
vehicleCardDTO
.
getVin
(),
vinCardInfoDTO
);
}
vehicleCardDTOMap
.
get
(
vehicleCardDTO
.
getVin
()).
getIccidList
().
add
(
vehicleCardDTO
.
getIccid
());
}
return
new
ArrayList
<>(
vehicleCardDTOMap
.
values
());
}
protected
Response
<
ProjectCardExistResponseDTO
>
isCardExist
(
String
url
,
String
iccid
)
{
ProjectCardExistRequestDTO
requestDTO
=
new
ProjectCardExistRequestDTO
();
requestDTO
.
setIccid
(
iccid
);
return
RnrFpRestTemplateUtils
.
postForResponse
(
balancedRestTemplateRnrFp
,
url
,
requestDTO
,
ProjectCardExistResponseDTO
.
class
);
}
private
List
<
VehicleCardDTO
>
queryVinCardFromProjectService
(
String
url
,
List
<
String
>
vinList
){
Response
<
List
<
VehicleCardDTO
>>
response
=
RnrFpRestTemplateUtils
.
postForResponseList
(
balancedRestTemplateRnrFp
,
url
,
new
ProjectVinCardRequestDTO
().
setVins
(
vinList
),
VehicleCardDTO
.
class
);
if
(!
response
.
isSuccess
()
||
response
.
getData
()
==
null
)
{
return
Collections
.
emptyList
();
}
return
response
.
getData
();
}
}
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/project/handler/VinCardHandler.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.project.handler
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.rnr.fp.dto.VinCardInfoDTO
;
import
com.cusc.nirvana.user.rnr.project.dto.ProjectCardExistResponseDTO
;
import
java.util.List
;
/**
* @author stayAnd
* @date 2022/4/7
*/
public
interface
VinCardHandler
{
/**
* 根据vin码查询iccid
*
* @param vin vin
* @return
*/
VinCardInfoDTO
queryCardByVin
(
String
vin
);
/**
* 批量根据vin码查询iccid
*
* @param vinList vin 列表
* @return
*/
List
<
VinCardInfoDTO
>
queryCardByVinList
(
List
<
String
>
vinList
);
/**
* 校验卡是否存在
*
* @param iccid
* @return
*/
Response
<
ProjectCardExistResponseDTO
>
isCardExist
(
String
iccid
);
}
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/project/handler/impl/InternalVinCardHandler.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.project.handler.impl
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.rnr.fp.dto.VinCardDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.VinCardInfoDTO
;
import
com.cusc.nirvana.user.rnr.fp.dto.VinCardVerityResult
;
import
com.cusc.nirvana.user.rnr.fp.dto.VinIccidDTO
;
import
com.cusc.nirvana.user.rnr.fp.service.ISimVehicleRelService
;
import
com.cusc.nirvana.user.rnr.project.constant.ProjectConstant
;
import
com.cusc.nirvana.user.rnr.project.dto.ProjectCardExistResponseDTO
;
import
com.cusc.nirvana.user.rnr.project.handler.CuscVinCardHandler
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
* @author stayAnd
* @date 2022/4/8
*/
@Service
@Slf4j
public
class
InternalVinCardHandler
extends
CuscVinCardHandler
{
@Autowired
private
ISimVehicleRelService
simVehicleRelService
;
@Override
public
VinCardInfoDTO
queryCardByVin
(
String
vin
)
{
VinCardInfoDTO
vinCardInfoDTO
=
new
VinCardInfoDTO
();
List
<
String
>
iccids
=
new
ArrayList
<>();
vinCardInfoDTO
.
setVin
(
vin
);
Response
<
List
<
VinIccidDTO
>>
iccidByVin
=
this
.
simVehicleRelService
.
getIccidByVin
(
vin
);
if
(
iccidByVin
.
isSuccess
()){
List
<
VinIccidDTO
>
list
=
iccidByVin
.
getData
();
iccids
=
list
.
stream
().
filter
(
dto
->
dto
.
getVin
().
equals
(
vin
)).
map
(
dto
->
dto
.
getIccid
()).
collect
(
Collectors
.
toList
());
}
log
.
info
(
"通过vin查询iccid,{},{}"
,
vin
,
iccids
);
vinCardInfoDTO
.
setIccidList
(
iccids
);
return
vinCardInfoDTO
;
}
@Override
public
List
<
VinCardInfoDTO
>
queryCardByVinList
(
List
<
String
>
vinList
)
{
List
<
VinCardInfoDTO
>
list
=
new
ArrayList
<>();
if
(!
vinList
.
isEmpty
()){
List
<
String
>
collect
=
vinList
.
stream
().
distinct
().
collect
(
Collectors
.
toList
());
for
(
String
vin
:
collect
)
{
VinCardInfoDTO
vinCardInfoDTO
=
this
.
queryCardByVin
(
vin
);
list
.
add
(
vinCardInfoDTO
);
}
}
return
list
;
}
@Override
public
Response
<
ProjectCardExistResponseDTO
>
isCardExist
(
String
iccid
)
{
return
isCardExist
(
ProjectConstant
.
PROJECT_SERVICE_URL
+
"/project/api/v1/sim/is-exist"
,
iccid
);
}
}
local-rnr-fp-server/src/main/java/com/cusc/nirvana/user/rnr/project/handler/impl/OpenApiVinCardHandler.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr.project.handler.impl
;
import
com.cusc.nirvana.common.result.Response
;
import
com.cusc.nirvana.user.rnr.fp.dto.VinCardInfoDTO
;
import
com.cusc.nirvana.user.rnr.project.dto.ProjectCardExistResponseDTO
;
import
com.cusc.nirvana.user.rnr.project.handler.CuscVinCardHandler
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
java.util.List
;
/**
* @author stayAnd
* @date 2022/4/8
*/
@Component
public
class
OpenApiVinCardHandler
extends
CuscVinCardHandler
{
@Value
(
"${openApiUrl:1}"
)
private
String
openApiUrl
;
@Override
public
VinCardInfoDTO
queryCardByVin
(
String
vin
)
{
return
queryVinCard
(
openApiUrl
+
"/vehicle/iccid/rels"
,
vin
);
}
@Override
public
List
<
VinCardInfoDTO
>
queryCardByVinList
(
List
<
String
>
vinList
)
{
return
queryVinCardList
(
openApiUrl
+
"/vehicle/iccid/rels"
,
vinList
);
}
@Override
public
Response
<
ProjectCardExistResponseDTO
>
isCardExist
(
String
iccid
)
{
return
isCardExist
(
openApiUrl
+
"/project/api/v1/sim/is-exist"
,
iccid
);
}
}
local-rnr-fp-server/src/main/resources/bootstrap-prod.yml
0 → 100644
View file @
015d4257
spring
:
cloud
:
nacos
:
config
:
server-addr
:
10.179.71.33:8848,10.179.71.81:8848,10.179.71.221:8848
username
:
nacos
password
:
nacos
namespace
:
92bf8770-8770-4326-a20e-2ed8b17a559e
group
:
DEFAULT_GROUP
file-extension
:
yml
discovery
:
server-addr
:
10.179.71.33:8848,10.179.71.81:8848,10.179.71.221:8848
namespace
:
92bf8770-8770-4326-a20e-2ed8b17a559e
username
:
nacos
password
:
nacos
group
:
DEFAULT_GROUP
local-rnr-fp-server/src/main/resources/bootstrap.yml
0 → 100644
View file @
015d4257
spring
:
application
:
name
:
local-rnr-fp
local-rnr-fp-server/src/main/resources/font/simhei.ttf
0 → 100644
View file @
015d4257
File added
local-rnr-fp-server/src/main/resources/font/simkai.ttf
0 → 100644
View file @
015d4257
File added
local-rnr-fp-server/src/main/resources/font/simsun.ttc
0 → 100644
View file @
015d4257
File added
local-rnr-fp-server/src/test/java/com/cusc/nirvana/user/rnr/FileTest.java
0 → 100644
View file @
015d4257
package
com.cusc.nirvana.user.rnr
;
import
com.alibaba.excel.EasyExcel
;
import
com.alibaba.excel.context.AnalysisContext
;
import
com.alibaba.excel.event.AnalysisEventListener
;
import
com.alibaba.fastjson.JSONObject
;
import
com.cache.CacheFactory
;
import
com.cusc.nirvana.user.rnr.fp.LocalRnrFpApplication
;
import
com.cusc.nirvana.user.rnr.fp.controller.RnrController
;
import
com.cusc.nirvana.user.rnr.fp.dto.LivenessCodeRequestDTO
;
import
com.cusc.nirvana.user.rnr.fp.service.IFileService
;
import
com.cusc.nirvana.user.rnr.fp.service.IRnrService
;
import
com.cusc.nirvana.user.rnr.mg.dto.RnrRelationDTO
;
import
com.cusc.nirvana.user.util.CuscStringUtils
;
import
com.cusc.nirvana.user.util.crypt.CryptKeyUtil
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.http.*
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
org.springframework.web.client.RestTemplate
;
import
javax.annotation.Resource
;
import
java.io.ByteArrayInputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.util.*
;
/**
* @author stayAnd
* @date 2022/4/18
*/
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
classes
=
LocalRnrFpApplication
.
class
)
public
class
FileTest
{
@Resource
private
CacheFactory
cacheFactory
;
@Resource
private
RnrController
rnrController
;
@Test
public
void
aaa
()
throws
Exception
{
LivenessCodeRequestDTO
rq
=
new
LivenessCodeRequestDTO
();
rq
.
setSerialNumber
(
CuscStringUtils
.
generateUuid
());
rq
.
setTenantNo
(
"testRnr2"
);
rnrController
.
getLivenessCode
(
rq
);
}
@Resource
@Qualifier
(
"noBalanceRestTemplateRnrFp"
)
private
RestTemplate
noBalanceRestTemplateRnrFp
;
@Resource
private
IFileService
fileService
;
@Test
public
void
testDownFile
()
throws
Exception
{
String
url
=
"http://10.166.0.26:20914/file/download/283c1000000000000260867"
;
final
ResponseEntity
<
byte
[]>
response
=
noBalanceRestTemplateRnrFp
.
getForEntity
(
url
,
byte
[].
class
);
byte
[]
result
=
response
.
getBody
();
ContentDisposition
contentDisposition
=
response
.
getHeaders
().
getContentDisposition
();
String
s
=
Base64
.
getEncoder
().
encodeToString
(
result
);
System
.
out
.
println
(
"data:image/png;base64,"
+
s
);
}
@Test
public
void
testUpLoadFile
()
throws
Exception
{
/*File file = new File("/Users/stayand/Desktop/template.xlsx");
FileInputStream fileInputStream = new FileInputStream(file);
byte[] bytes = new byte[(int) file.length()];
fileInputStream.read(bytes);
fileInputStream.close();
String base64 = Base64.getEncoder().encodeToString(bytes);
String uuid = fileService.upLoadFileBase64(base64, file.getName());
System.out.println(uuid);*/
}
@Resource
private
IRnrService
rnrService
;
@Test
public
void
testRnr
(){
String
json
=
"{\n"
+
" \"cardList\": [\n"
+
" {\n"
+
" \"creator\": \"1502905532594b5cb9f6cd4126f80d77\",\n"
+
" \"currPage\": 1,\n"
+
" \"iccid\": \"67856998760984300000\",\n"
+
" \"iotId\": \"LGG3D4D17JZ012211\",\n"
+
" \"operator\": \"1502905532594b5cb9f6cd4126f80d77\",\n"
+
" \"orderId\": \"bfd71ab3b5094bb886e19263adedf2bf\",\n"
+
" \"pageSize\": 10,\n"
+
" \"rnrId\": \"ae71b3ad0067405bbf064382ce180329\",\n"
+
" \"tenantNo\": \"38\",\n"
+
" \"uuid\": \"1995348014664a7aa01d2da79f9142c0\"\n"
+
" }\n"
+
" ],\n"
+
" \"info\": {\n"
+
" \"certAddress\": \"安徽省池州市东至县胜利镇姜东村26号\",\n"
+
" \"certNumber\": \"342921199106064515\",\n"
+
" \"certType\": \"IDCARD\",\n"
+
" \"contactAddress\": \"南京市江宁区\",\n"
+
" \"creator\": \"1502905532594b5cb9f6cd4126f80d77\",\n"
+
" \"currPage\": 1,\n"
+
" \"fullName\": \"陈迎\",\n"
+
" \"gender\": 1,\n"
+
" \"isCompany\": 0,\n"
+
" \"isSecondHandCar\": 0,\n"
+
" \"isTrust\": 0,\n"
+
" \"operator\": \"1502905532594b5cb9f6cd4126f80d77\",\n"
+
" \"pageSize\": 10,\n"
+
" \"phone\": \"13965036751\",\n"
+
" \"rnrStatus\": 0,\n"
+
" \"serial_number\": \"1eeae354139546908b792036a5b3933c\",\n"
+
" \"tenantNo\": \"38\",\n"
+
" \"uuid\": \"ae71b3ad0067405bbf064382ce180329\"\n"
+
" },\n"
+
" \"isSecondHandCar\": 0,\n"
+
" \"isTrust\": 0,\n"
+
" \"order\": {\n"
+
" \"auditType\": 0,\n"
+
" \"autoRnr\": true,\n"
+
" \"creator\": \"1502905532594b5cb9f6cd4126f80d77\",\n"
+
" \"currPage\": 1,\n"
+
" \"isBatchOrder\": 0,\n"
+
" \"operator\": \"1502905532594b5cb9f6cd4126f80d77\",\n"
+
" \"orderSource\": \"PORTAL\",\n"
+
" \"orderStatus\": 0,\n"
+
" \"orderType\": 1,\n"
+
" \"pageSize\": 10,\n"
+
" \"rnrId\": \"ae71b3ad0067405bbf064382ce180329\",\n"
+
" \"sendWorkOrder\": false,\n"
+
" \"serialNumber\": \"1eeae354139546908b792036a5b3933c\",\n"
+
" \"tenantNo\": \"38\",\n"
+
" \"uuid\": \"bfd71ab3b5094bb886e19263adedf2bf\"\n"
+
" },\n"
+
" \"rnrFileList\": [\n"
+
" {\n"
+
" \"creator\": \"1502905532594b5cb9f6cd4126f80d77\",\n"
+
" \"currPage\": 1,\n"
+
" \"fileSystemId\": \"f1ff1000000000000260863\",\n"
+
" \"fileType\": 1,\n"
+
" \"liaisonId\": \"0\",\n"
+
" \"operator\": \"1502905532594b5cb9f6cd4126f80d77\",\n"
+
" \"pageSize\": 10,\n"
+
" \"rnrId\": \"ae71b3ad0067405bbf064382ce180329\",\n"
+
" \"tenantNo\": \"38\",\n"
+
" \"uuid\": \"513cee2ba684469d90e929a94ad7552a\"\n"
+
" },\n"
+
" {\n"
+
" \"creator\": \"1502905532594b5cb9f6cd4126f80d77\",\n"
+
" \"currPage\": 1,\n"
+
" \"fileSystemId\": \"283c1000000000000260867\",\n"
+
" \"fileType\": 2,\n"
+
" \"liaisonId\": \"0\",\n"
+
" \"operator\": \"1502905532594b5cb9f6cd4126f80d77\",\n"
+
" \"pageSize\": 10,\n"
+
" \"rnrId\": \"ae71b3ad0067405bbf064382ce180329\",\n"
+
" \"tenantNo\": \"38\",\n"
+
" \"uuid\": \"63cea09d6bbc42f29ea5f23ff8e37adc\"\n"
+
" },\n"
+
" {\n"
+
" \"creator\": \"1502905532594b5cb9f6cd4126f80d77\",\n"
+
" \"currPage\": 1,\n"
+
" \"fileSystemId\": \"c8241000000000000260868\",\n"
+
" \"fileType\": 6,\n"
+
" \"liaisonId\": \"0\",\n"
+
" \"operator\": \"1502905532594b5cb9f6cd4126f80d77\",\n"
+
" \"pageSize\": 10,\n"
+
" \"rnrId\": \"ae71b3ad0067405bbf064382ce180329\",\n"
+
" \"tenantNo\": \"38\",\n"
+
" \"uuid\": \"7c039e8e0b9e494dab25080c1aeeda86\"\n"
+
" }\n"
+
" ],\n"
+
" \"tenantNo\": \"38\"\n"
+
"}"
;
RnrRelationDTO
rnrRelationDTO
=
JSONObject
.
parseObject
(
json
,
RnrRelationDTO
.
class
);
rnrService
.
checkPersonData
(
"ae71b3ad0067405bbf064382ce180329"
,
"57407e06-24b4-4c2e-9bcc-308570c631b2"
,
rnrRelationDTO
);
}
@Test
public
void
testExcel
(){
String
fileId
=
"e7d21000000000000450013"
;
String
url
=
"http://10.166.0.26:20914/file/download/"
+
fileId
;
final
ResponseEntity
<
byte
[]>
response
=
noBalanceRestTemplateRnrFp
.
getForEntity
(
url
,
byte
[].
class
);
byte
[]
result
=
response
.
getBody
();
EasyExcel
.
read
(
new
ByteArrayInputStream
(
result
),
TestData
.
class
,
new
AnalysisEventListener
<
TestData
>(){
@Override
public
void
invoke
(
TestData
o
,
AnalysisContext
analysisContext
)
{
System
.
out
.
println
(
JSONObject
.
toJSONString
(
o
));
}
@Override
public
void
doAfterAllAnalysed
(
AnalysisContext
analysisContext
)
{
System
.
out
.
println
(
"end"
);
}
}).
sheet
().
doReadSync
();;
}
@Test
public
void
decryptByBase64
(){
String
s
=
CryptKeyUtil
.
decryptByBase64
(
"UkGq7K7w449fvfJO8d0RUrh6pr6Bw0tDzYgpcxQGAcY="
);
System
.
out
.
println
(
s
);
}
}
Prev
1
…
16
17
18
19
20
21
Next
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