Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
smf-core
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit eab52fd3
由
LN
编写于
2023-03-20 09:23:18 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
20057:hotayi接口修改。增加登录验证接口
1 个父辈
bcf60dc8
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
95 行增加
和
2 行删除
src/main/java/com/neotel/smfcore/common/utils/HttpHelper.java
src/main/java/com/neotel/smfcore/core/api/SmfApi.java
src/main/java/com/neotel/smfcore/core/api/listener/BaseSmfApiListener.java
src/main/java/com/neotel/smfcore/core/api/listener/ISmfApiListener.java
src/main/java/com/neotel/smfcore/custom/hotayi20057/HotayiApi.java
src/main/java/com/neotel/smfcore/security/service/UserDetailsServiceImpl.java
src/main/java/com/neotel/smfcore/common/utils/HttpHelper.java
查看文件 @
eab52fd
...
...
@@ -341,6 +341,8 @@ public class HttpHelper {
}
try
{
HttpGet
httpGet
=
new
HttpGet
(
url
);
RequestConfig
requestConfig
=
RequestConfig
.
custom
().
setConnectTimeout
(
CONNECTION_TIMEOUT
).
build
();
httpGet
.
setConfig
(
requestConfig
);
httpGet
.
addHeader
(
"Content-Type"
,
"application/json;charset=utf-8"
);
CloseableHttpClient
httpClient
=
HttpClients
.
createDefault
();
CloseableHttpResponse
response
=
httpClient
.
execute
(
httpGet
);
...
...
src/main/java/com/neotel/smfcore/core/api/SmfApi.java
查看文件 @
eab52fd
package
com
.
neotel
.
smfcore
.
core
.
api
;
import
cn.hutool.core.util.ObjectUtil
;
import
com.google.common.collect.Lists
;
import
com.neotel.smfcore.common.exception.ValidateException
;
import
com.neotel.smfcore.common.init.MenuInit
;
...
...
@@ -63,6 +64,9 @@ public class SmfApi {
@Value
(
"${api.fetchInListUrl:}"
)
protected
String
fetchInListUrl
=
""
;
@Value
(
"${api.loginCheckUrl:}"
)
protected
String
loginCheckUrl
=
""
;
/**
* API名称
*/
...
...
@@ -84,7 +88,7 @@ public class SmfApi {
orderNotifyUrl
=
dataCache
.
getConfigCache
(
"api.orderNotifyUrl"
,
orderNotifyUrl
);
fetchInListUrl
=
dataCache
.
getConfigCache
(
"api.fetchInListUrl"
,
fetchInListUrl
);
fetchOrderUrl
=
dataCache
.
getConfigCache
(
"api.fetchOrderUrl"
,
fetchOrderUrl
);
loginCheckUrl
=
dataCache
.
getConfigCache
(
"api.loginCheckUrl"
,
loginCheckUrl
);
}
/**
...
...
@@ -220,7 +224,20 @@ public class SmfApi {
return
null
;
}
public
boolean
canLogin
(
String
username
,
String
pwd
)
throws
ValidateException
{
if
(
ObjectUtil
.
isNotEmpty
(
username
)
&&
ObjectUtil
.
isNotEmpty
(
pwd
))
{
if
(
isUrlExist
(
loginCheckUrl
))
{
for
(
ISmfApiListener
apiListener
:
apiListenerList
)
{
if
(
apiListener
.
isForThisApi
(
apiName
))
{
boolean
result
=
apiListener
.
canLogin
(
loginCheckUrl
,
username
,
pwd
);
return
result
;
}
}
}
}
return
true
;
}
/**
* 判断URL是否存在,如果不存在不需要进行发送
* @param url
...
...
src/main/java/com/neotel/smfcore/core/api/listener/BaseSmfApiListener.java
查看文件 @
eab52fd
...
...
@@ -106,6 +106,10 @@ public abstract class BaseSmfApiListener implements ISmfApiListener {
return
null
;
}
@Override
public
boolean
canLogin
(
String
loginCheckUrl
,
String
userName
,
String
pwd
)
throws
ValidateException
{
return
true
;
}
protected
String
getData
(
Map
<
String
,
Object
>
dataMap
,
String
dataKey
)
{
Object
data
=
dataMap
.
get
(
dataKey
);
if
(
data
==
null
)
{
...
...
src/main/java/com/neotel/smfcore/core/api/listener/ISmfApiListener.java
查看文件 @
eab52fd
...
...
@@ -55,4 +55,10 @@ public interface ISmfApiListener {
* @return
*/
LiteOrder
fetchOrder
(
String
url
,
String
orderNumber
,
String
username
);
/**
* 是否可以登陆
*/
boolean
canLogin
(
String
loginCheckUrl
,
String
userName
,
String
pwd
)
throws
ValidateException
;
}
src/main/java/com/neotel/smfcore/custom/hotayi20057/HotayiApi.java
查看文件 @
eab52fd
...
...
@@ -114,7 +114,12 @@ public class HotayiApi extends BaseSmfApiListener {
log
.
info
(
reelId
+
"入库验证M6,参数"
+
JsonUtil
.
toJsonStr
(
paramMap
));
String
result
=
HttpHelper
.
getJson
(
codeResolveUrl
,
paramMap
);
// "{ \"Info\": {\"MachineID\": \"00001\",\"IPAddress\": \"192.168.0.1\",\"MessageNo\": \"M5\"},\"Data\": {\"PartNo\": \"A005\",\"ExpireDate\": \"2022-01-01\",\"SerialNo\": \"A005$$A\"}}";
log
.
info
(
reelId
+
"入库验证返回"
+
result
);
result
=
result
.
replace
(
"\\\""
,
"\""
);
result
=
result
.
replace
(
"\"{"
,
"{"
);
result
=
result
.
replace
(
"}\""
,
"}"
);
log
.
info
(
reelId
+
"入库验证返回 处理后"
+
result
);
HotayiBean
hotayiBean
=
JsonUtil
.
toObj
(
result
,
HotayiBean
.
class
);
String
resultMsgNo
=
hotayiBean
.
getInfoItem
(
"MessageNo"
);
if
(
resultMsgNo
.
equals
(
"M90"
))
{
...
...
@@ -146,7 +151,12 @@ public class HotayiApi extends BaseSmfApiListener {
Date
expireDate
=
DateUtil
.
toDate
(
expireDateStr
,
"yyyy-MM-dd"
);
barcode
.
setExpireDate
(
expireDate
);
}
//默认设置重量=0
if
(
codeBean
.
getBarcode
()!=
null
)
{
barcode
.
setAmount
(
codeBean
.
getBarcode
().
getAmount
());
}
if
(
barcode
.
getAmount
()<=
0
){
barcode
.
setAmount
(
1
);
}
resolveComponent
(
barcode
);
barcode
=
barcodeManager
.
saveBarcode
(
barcode
);
return
barcode
;
...
...
@@ -157,6 +167,7 @@ public class HotayiApi extends BaseSmfApiListener {
}
}
@Override
public
void
inTaskStatusChange
(
String
inNotifyUrl
,
DataLog
task
)
{
String
requestParams
=
""
;
...
...
@@ -247,6 +258,56 @@ public class HotayiApi extends BaseSmfApiListener {
bean
.
addData
(
"Mode"
,
Mode
);
return
bean
;
}
private
HotayiBean
getM22Bean
(
String
UserName
,
String
pwd
,
String
MachineType
)
{
HotayiBean
bean
=
new
HotayiBean
();
bean
.
addInfo
(
"MachineID"
,
machineID
);
bean
.
addInfo
(
"IPAddress"
,
iPAddress
);
bean
.
addInfo
(
"MessageNo"
,
"M22"
);
bean
.
addData
(
"UserName"
,
UserName
+
pwd
);
bean
.
addData
(
"MachineType"
,
MachineType
);
return
bean
;
}
@Override
public
boolean
canLogin
(
String
loginCheckUrl
,
String
userName
,
String
pwd
)
throws
ValidateException
{
try
{
HotayiBean
m22Bean
=
getM22Bean
(
userName
,
pwd
,
"SMT Machine"
);
Map
<
String
,
Object
>
paramMap
=
new
HashMap
<>();
paramMap
.
put
(
"Info"
,
m22Bean
.
getInfo
());
paramMap
.
put
(
"Date"
,
m22Bean
.
getData
());
String
requestParams
=
JsonUtil
.
toJsonStr
(
paramMap
);
log
.
info
(
userName
+
"登陆验证M22,参数"
+
requestParams
);
String
result
=
HttpHelper
.
getJson
(
loginCheckUrl
,
paramMap
);
log
.
info
(
userName
+
"登陆验证M22 返回"
+
result
);
// ApiResult apiResult = JsonUtil.toObj(responseInfo, ApiResult.class);
result
=
result
.
replace
(
"\\\""
,
"\""
);
result
=
result
.
replace
(
"\"{"
,
"{"
);
result
=
result
.
replace
(
"}\""
,
"}"
);
log
.
info
(
userName
+
"登陆验证M22 处理后"
+
result
);
HotayiBean
hotayiBean
=
JsonUtil
.
toObj
(
result
,
HotayiBean
.
class
);
String
resultMsgNo
=
hotayiBean
.
getInfoItem
(
"MessageNo"
);
if
(
resultMsgNo
.
equals
(
"M90"
))
{
String
errorCode
=
hotayiBean
.
getDataItem
(
"ErrorCode"
);
String
errorMessage
=
hotayiBean
.
getDataItem
(
"ErrorMessage"
);
throw
new
ValidateException
(
"smfcore.mesApi.loginCheck.ng"
,
"NG: ["
+
errorCode
+
"]"
+
errorMessage
);
}
else
{
String
UserLevel
=
hotayiBean
.
getInfoItem
(
"UserLevel"
);
if
(
ObjectUtil
.
isNotEmpty
(
UserLevel
))
{
log
.
info
(
userName
+
"登陆验证M22 返回 UserLevel="
+
UserLevel
);
return
true
;
}
else
{
log
.
info
(
userName
+
"登陆验证M22 返回 UserLevel="
+
UserLevel
);
throw
new
ValidateException
(
"smfcore.mesApi.loginCheck.fail"
,
"MES Login fail "
);
}
}
}
catch
(
Exception
e
)
{
log
.
error
(
"登陆验证接口出错:"
+
e
.
getMessage
());
throw
new
ValidateException
(
"smfcore.mesApi.loginCheck.error"
,
"MES Login Error:"
+
e
.
getMessage
());
}
}
}
src/main/java/com/neotel/smfcore/security/service/UserDetailsServiceImpl.java
查看文件 @
eab52fd
...
...
@@ -18,6 +18,7 @@ package com.neotel.smfcore.security.service;
import
com.neotel.smfcore.common.exception.EntityNotFoundException
;
import
com.neotel.smfcore.common.exception.ValidateException
;
import
com.neotel.smfcore.common.utils.StringUtils
;
import
com.neotel.smfcore.core.api.SmfApi
;
import
com.neotel.smfcore.security.rest.bean.dto.JwtUserDto
;
import
com.neotel.smfcore.security.service.manager.IMenuManager
;
import
com.neotel.smfcore.security.service.manager.IUserManager
;
...
...
@@ -40,9 +41,11 @@ import java.util.stream.Collectors;
public
class
UserDetailsServiceImpl
implements
UserDetailsService
{
private
final
IUserManager
userManager
;
private
final
IMenuManager
menuManager
;
private
final
SmfApi
smfApi
;
@Override
public
JwtUserDto
loadUserByUsername
(
String
username
)
{
smfApi
.
canLogin
(
username
,
""
);
boolean
searchDb
=
true
;
JwtUserDto
jwtUserDto
=
null
;
if
(
searchDb
)
{
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论