Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
smf-core
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 34946857
由
hc
编写于
2024-06-26 17:32:45 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
1. 接口参数校验规则
2. 代码优化
1 个父辈
44213e31
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
235 行增加
和
34 行删除
pom.xml
src/main/java/com/neotel/smfcore/custom/luxsan/api/LuxsanApi.java
src/main/java/com/neotel/smfcore/custom/luxsan/api/bean/request/GetBoxNGsnListRequest.java
src/main/java/com/neotel/smfcore/custom/luxsan/common/constants/BusinessConst.java
src/main/java/com/neotel/smfcore/custom/luxsan/common/json/IJsonRule.java
src/main/java/com/neotel/smfcore/custom/luxsan/common/json/impl/DataResultJsonRule.java
src/main/java/com/neotel/smfcore/custom/luxsan/common/util/RequestURLUtil.java
src/main/java/com/neotel/smfcore/custom/luxsan/factory_c/wipstor/controller/LineController.java
pom.xml
查看文件 @
3494685
...
@@ -266,6 +266,11 @@
...
@@ -266,6 +266,11 @@
<artifactId>
log4j-jul
</artifactId>
<artifactId>
log4j-jul
</artifactId>
<version>
2.17.0
</version>
<version>
2.17.0
</version>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-validation
</artifactId>
</dependency>
</dependencies>
</dependencies>
...
@@ -338,4 +343,4 @@
...
@@ -338,4 +343,4 @@
</plugins>
</plugins>
</build>
</build>
</project>
\ No newline at end of file
\ No newline at end of file
</project>
src/main/java/com/neotel/smfcore/custom/luxsan/api/LuxsanApi.java
查看文件 @
3494685
...
@@ -17,15 +17,14 @@ import com.neotel.smfcore.custom.luxsan.api.bean.request.*;
...
@@ -17,15 +17,14 @@ import com.neotel.smfcore.custom.luxsan.api.bean.request.*;
import
com.neotel.smfcore.custom.luxsan.api.bean.result.*
;
import
com.neotel.smfcore.custom.luxsan.api.bean.result.*
;
import
com.neotel.smfcore.custom.luxsan.api.bean.util.LuxsanApiResult
;
import
com.neotel.smfcore.custom.luxsan.api.bean.util.LuxsanApiResult
;
import
com.neotel.smfcore.custom.luxsan.api.enums.LuxsanApiEnum
;
import
com.neotel.smfcore.custom.luxsan.api.enums.LuxsanApiEnum
;
import
com.neotel.smfcore.custom.luxsan.common.constants.BusinessConst
;
import
com.neotel.smfcore.custom.luxsan.common.util.RequestURLUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.util.Arrays
;
import
java.util.*
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
@Slf4j
@Slf4j
@Service
@Service
...
@@ -1006,39 +1005,45 @@ public class LuxsanApi extends DefaultSmfApiListener {
...
@@ -1006,39 +1005,45 @@ public class LuxsanApi extends DefaultSmfApiListener {
}
}
}
}
public
static
List
<
GetBoxNGResult
>
getBoxNGsnList
(
GetBoxNGsnListRequest
request
)
{
public
static
List
<
GetBoxNGResult
>
getBoxNGsnList
(
Map
request
)
throws
ApiException
{
return
RequestURLUtil
.
request
(
BusinessConst
.
DATA_RESULT_TYPE
,
request
,
BusinessConst
.
POST_METHOD
,
getBoxNGsnListUrl
,
GetBoxNGResult
.
class
);
}
public
static
List
<
GetBoxNGResult
>
getBoxNGsnList
(
GetBoxNGsnListRequest
request
)
throws
ApiException
{
log
.
info
(
"getBoxNGsnList接口请求参数为:"
+
JSON
.
toJSONString
(
request
));
log
.
info
(
"getBoxNGsnList接口请求参数为:"
+
JSON
.
toJSONString
(
request
));
String
resultStr
=
null
;
String
resultStr
=
null
;
// 调用外部接口
try
{
try
{
resultStr
=
HttpHelper
.
postJson
(
getBoxNGsnListUrl
,
request
);
resultStr
=
HttpHelper
.
postJson
(
getBoxNGsnListUrl
,
request
);
log
.
info
(
"getBoxNGsnList接口返回结果为:"
+
resultStr
);
}
catch
(
Exception
e
)
{
JSONObject
resultJson
=
JsonUtil
.
toObj
(
resultStr
,
JSONObject
.
class
);
log
.
error
(
String
.
format
(
"接口请求失败[%s]"
,
getBoxNGsnListUrl
));
if
(
resultJson
!=
null
)
{
throw
new
ValidateException
(
"smfcore.api.error"
,
"接口请求失败[{0}]"
,
new
String
[]{
getBoxNGsnListUrl
});
if
(
resultJson
.
getString
(
"data"
)
!=
null
)
{
}
JSONObject
dataJson
=
resultJson
.
getJSONObject
(
"data"
);
log
.
info
(
"getBoxNGsnList接口返回结果为:"
+
resultStr
);
if
(
dataJson
.
get
(
"result"
)
!=
null
&&
!
dataJson
.
getBoolean
(
"result"
))
{
JSONObject
resultJson
=
JsonUtil
.
toObj
(
resultStr
,
JSONObject
.
class
);
String
errorMessage
=
(
String
)
dataJson
.
get
(
"message"
);
String
data
=
resultJson
.
getString
(
"data"
);
if
(
StringUtils
.
isEmpty
(
errorMessage
))
{
if
(
StringUtils
.
isEmpty
(
data
))
{
errorMessage
=
""
;
throw
new
ApiException
(
String
.
format
(
"接口返回内容有误[%s]"
,
getBoxNGsnListUrl
));
}
}
log
.
error
(
String
.
format
(
"接口请求失败[%s],失败原因[%s]"
,
getBoxNGsnListUrl
,
errorMessage
));
JSONObject
dataJson
=
resultJson
.
getJSONObject
(
"data"
);
throw
new
ValidateException
(
"smfcore.api.error"
,
"接口请求失败[{0}],失败原因[{1}]"
,
new
String
[]{
"getBoxNGsnList"
,
errorMessage
});
// 远程接口返回的数据错误
}
else
{
if
(
dataJson
.
get
(
"result"
)
!=
null
&&
!
dataJson
.
getBoolean
(
"result"
))
{
JSONArray
arrayData
=
dataJson
.
getJSONArray
(
"data"
);
String
errorMessage
=
(
String
)
dataJson
.
get
(
"message"
);
System
.
out
.
println
(
arrayData
);
if
(
StringUtils
.
isEmpty
(
errorMessage
))
{
List
<
GetBoxNGResult
>
resultList
=
JSONObject
.
parseArray
(
JSONArray
.
toJSONString
(
arrayData
),
GetBoxNGResult
.
class
);
errorMessage
=
""
;
if
(
resultList
!=
null
&&
!
resultList
.
isEmpty
())
{
}
return
resultList
;
log
.
error
(
String
.
format
(
"接口请求失败[%s],失败原因[%s]"
,
getBoxNGsnListUrl
,
errorMessage
));
}
throw
new
ApiException
(
String
.
format
(
"smfcore.api.error 接口请求失败[%s],失败原因[%s]"
,
getBoxNGsnListUrl
,
errorMessage
));
}
}
else
{
}
JSONArray
arrayData
=
dataJson
.
getJSONArray
(
"data"
);
System
.
out
.
println
(
arrayData
);
List
<
GetBoxNGResult
>
resultList
=
JSONObject
.
parseArray
(
JSONArray
.
toJSONString
(
arrayData
),
GetBoxNGResult
.
class
);
if
(
resultList
!=
null
&&
!
resultList
.
isEmpty
())
{
return
resultList
;
}
else
{
return
new
ArrayList
<>();
}
}
}
catch
(
ApiException
e
)
{
log
.
error
(
String
.
format
(
"接口请求失败[%s]"
,
e
.
getMessage
()));
throw
new
ValidateException
(
"smfcore.api.error"
,
"接口请求失败[{0}]"
,
new
String
[]{
e
.
getMessage
()});
}
}
log
.
error
(
String
.
format
(
"接口请求失败[%s]"
,
getBoxNGsnListUrl
));
throw
new
ValidateException
(
"smfcore.api.error"
,
"[{0}]数据获取失败"
,
new
String
[]{
"getBoxNGsnList"
});
}
}
...
...
src/main/java/com/neotel/smfcore/custom/luxsan/api/bean/request/GetBoxNGsnListRequest.java
查看文件 @
3494685
package
com
.
neotel
.
smfcore
.
custom
.
luxsan
.
api
.
bean
.
request
;
package
com
.
neotel
.
smfcore
.
custom
.
luxsan
.
api
.
bean
.
request
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
javax.validation.constraints.NotBlank
;
/**
/**
* 获取料箱ngsn列表
* 获取料箱ngsn列表
*/
*/
@Data
@Data
@AllArgsConstructor
@NoArgsConstructor
public
class
GetBoxNGsnListRequest
{
public
class
GetBoxNGsnListRequest
{
/**
/**
* 机种
* 机种
*/
*/
@NotBlank
(
message
=
"机种不能为空"
)
private
String
model
;
private
String
model
;
/**
/**
* 料箱号
* 料箱号
*/
*/
@NotBlank
(
message
=
"料箱号不能为空"
)
private
String
carton_id
;
private
String
carton_id
;
}
}
src/main/java/com/neotel/smfcore/custom/luxsan/common/constants/BusinessConst.java
0 → 100644
查看文件 @
3494685
package
com
.
neotel
.
smfcore
.
custom
.
luxsan
.
common
.
constants
;
public
class
BusinessConst
{
/*================ HTTP类型 ==========================*/
public
static
String
GET_METHOD
=
"GET"
;
public
static
String
POST_METHOD
=
"POST"
;
/*================ 解析外部接口类型规则 ==========================*/
/**
* result为 true 时才代表data可用
* eg:
* {
* "code": 1,
* "message": "success",
* "data": {
* "result": "false",
* "message": "箱号中未获取到符合要求的SN信息",
* "data": ""
* },
* "timestamp": 1719205385950,
* "executeTime": 90
* }
*
* {
* "code": 1,
* "message": "success",
* "data": {
* "result": "true",
* "message": "success",
* "data": [{
* "SN": "SN1",
* "NGREASON": "test",
* "ROW": 1,
* "COLUMN": 1
* }, {
* "SN": "SN2",
* "NGREASON": "test",
* "ROW": 15,
* "COLUMN": 23
* }, {
* "SN": "SN3",
* "NGREASON": "test",
* "ROW": 15,
* "COLUMN": 24
* }]
* },
* "timestamp": 1719194526321,
* "executeTime": 20
* }
*/
public
static
String
DATA_RESULT_TYPE
=
"DataResult"
;
}
src/main/java/com/neotel/smfcore/custom/luxsan/common/json/IJsonRule.java
0 → 100644
查看文件 @
3494685
package
com
.
neotel
.
smfcore
.
custom
.
luxsan
.
common
.
json
;
import
com.neotel.smfcore.common.exception.ApiException
;
import
java.util.List
;
import
java.util.Map
;
/**
* 解析外部接口返回的json规则
*/
public
interface
IJsonRule
{
String
getType
();
List
request
(
Map
request
,
String
httpMethod
,
String
url
,
Class
<?>
returnType
)
throws
ApiException
;
}
src/main/java/com/neotel/smfcore/custom/luxsan/common/json/impl/DataResultJsonRule.java
0 → 100644
查看文件 @
3494685
package
com
.
neotel
.
smfcore
.
custom
.
luxsan
.
common
.
json
.
impl
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.neotel.smfcore.common.exception.ApiException
;
import
com.neotel.smfcore.common.exception.ValidateException
;
import
com.neotel.smfcore.common.utils.HttpHelper
;
import
com.neotel.smfcore.common.utils.JsonUtil
;
import
com.neotel.smfcore.common.utils.StringUtils
;
import
com.neotel.smfcore.custom.luxsan.common.constants.BusinessConst
;
import
com.neotel.smfcore.custom.luxsan.common.json.IJsonRule
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Service
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
@Slf4j
@Service
public
class
DataResultJsonRule
implements
IJsonRule
{
@Override
public
String
getType
()
{
return
BusinessConst
.
DATA_RESULT_TYPE
;
}
@Override
public
List
request
(
Map
request
,
String
httpMethod
,
String
url
,
Class
<?>
returnType
)
throws
ApiException
{
log
.
info
(
String
.
format
(
"[%s]接口请求参数为:"
+
JSON
.
toJSONString
(
request
),
url
));
String
resultStr
=
null
;
// 调用外部接口
try
{
if
(
StringUtils
.
isEmpty
(
httpMethod
))
{
throw
new
ApiException
(
"500: 代码错误"
);
}
switch
(
httpMethod
.
toUpperCase
())
{
case
"GET"
:
resultStr
=
HttpHelper
.
sendGet
(
url
);
break
;
case
"POST"
:
resultStr
=
HttpHelper
.
postJson
(
url
,
request
);
break
;
default
:
if
(
StringUtils
.
isEmpty
(
httpMethod
))
{
throw
new
ApiException
(
"500: 代码错误"
);
}
}
}
catch
(
Exception
e
)
{
log
.
error
(
String
.
format
(
"接口请求失败[%s]"
,
url
));
throw
new
ValidateException
(
"smfcore.api.error"
,
"接口请求失败[{0}]"
,
new
String
[]{
url
});
}
log
.
info
(
String
.
format
(
"[%s]接口返回结果为:"
+
resultStr
,
url
));
JSONObject
resultJson
=
JsonUtil
.
toObj
(
resultStr
,
JSONObject
.
class
);
String
data
=
resultJson
.
getString
(
"data"
);
if
(
StringUtils
.
isEmpty
(
data
))
{
throw
new
ApiException
(
String
.
format
(
"[%s]接口返回内容有误"
,
url
));
}
JSONObject
dataJson
=
resultJson
.
getJSONObject
(
"data"
);
// 远程接口返回的数据错误
if
(
dataJson
.
get
(
"result"
)
!=
null
&&
!
dataJson
.
getBoolean
(
"result"
))
{
String
errorMessage
=
(
String
)
dataJson
.
get
(
"message"
);
if
(
StringUtils
.
isEmpty
(
errorMessage
))
{
errorMessage
=
""
;
}
log
.
error
(
String
.
format
(
"接口请求失败[%s],失败原因[%s]"
,
url
,
errorMessage
));
throw
new
ApiException
(
String
.
format
(
"smfcore.api.error 接口请求失败[%s],失败原因[%s]"
,
url
,
errorMessage
));
}
else
{
JSONArray
arrayData
=
dataJson
.
getJSONArray
(
"data"
);
List
resultList
=
JSONObject
.
parseArray
(
JSONArray
.
toJSONString
(
arrayData
),
returnType
);
System
.
out
.
println
(
arrayData
);
if
(
resultList
!=
null
&&
!
resultList
.
isEmpty
())
{
return
resultList
;
}
else
{
return
new
ArrayList
<>();
}
}
}
}
src/main/java/com/neotel/smfcore/custom/luxsan/common/util/RequestURLUtil.java
0 → 100644
查看文件 @
3494685
package
com
.
neotel
.
smfcore
.
custom
.
luxsan
.
common
.
util
;
import
com.neotel.smfcore.common.exception.ApiException
;
import
com.neotel.smfcore.custom.luxsan.common.json.IJsonRule
;
import
org.springframework.stereotype.Component
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
@Component
public
class
RequestURLUtil
{
private
static
Map
<
String
,
IJsonRule
>
iJsonRuleMap
=
new
HashMap
<>();
public
RequestURLUtil
(
List
<
IJsonRule
>
iJsonRules
)
{
for
(
IJsonRule
iJsonRule
:
iJsonRules
)
{
iJsonRuleMap
.
put
(
iJsonRule
.
getType
(),
iJsonRule
);
}
}
public
static
List
request
(
String
type
,
Map
request
,
String
httpMethod
,
String
url
,
Class
<?>
returnType
)
throws
ApiException
{
IJsonRule
iJsonRule
=
iJsonRuleMap
.
get
(
type
);
List
res
=
iJsonRule
.
request
(
request
,
httpMethod
,
url
,
returnType
);
return
res
;
}
}
src/main/java/com/neotel/smfcore/custom/luxsan/factory_c/wipstor/controller/LineController.java
查看文件 @
3494685
...
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
...
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Lists
;
import
com.neotel.smfcore.common.bean.ReelLockPosInfo
;
import
com.neotel.smfcore.common.bean.ReelLockPosInfo
;
import
com.neotel.smfcore.common.bean.ResultBean
;
import
com.neotel.smfcore.common.bean.ResultBean
;
import
com.neotel.smfcore.common.exception.ApiException
;
import
com.neotel.smfcore.common.utils.ReelLockPosUtil
;
import
com.neotel.smfcore.common.utils.ReelLockPosUtil
;
import
com.neotel.smfcore.common.utils.StringUtils
;
import
com.neotel.smfcore.common.utils.StringUtils
;
import
com.neotel.smfcore.core.barcode.service.manager.IBarcodeManager
;
import
com.neotel.smfcore.core.barcode.service.manager.IBarcodeManager
;
...
@@ -43,6 +44,7 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -43,6 +44,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.data.domain.Sort
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.data.mongodb.core.query.Criteria
;
import
org.springframework.data.mongodb.core.query.Criteria
;
import
org.springframework.data.mongodb.core.query.Query
;
import
org.springframework.data.mongodb.core.query.Query
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
...
@@ -346,9 +348,13 @@ public class LineController {
...
@@ -346,9 +348,13 @@ public class LineController {
@ApiOperation
(
"ng料出库"
)
@ApiOperation
(
"ng料出库"
)
@RequestMapping
(
"/getBoxNGsnList"
)
@RequestMapping
(
"/getBoxNGsnList"
)
@AnonymousAccess
@AnonymousAccess
public
ResultBean
getBoxNGsnList
(
@
RequestBody
GetBoxNGsnListRequest
result
)
{
public
ResultBean
getBoxNGsnList
(
@
Validated
@RequestBody
GetBoxNGsnListRequest
result
)
throws
ApiException
{
log
.
info
(
"机种["
+
result
.
getModel
()+
"]和CartonId:"
+
result
.
getCarton_id
());
log
.
info
(
"机种["
+
result
.
getModel
()+
"]和CartonId:"
+
result
.
getCarton_id
());
List
<
GetBoxNGResult
>
boxNGsnList
=
LuxsanApi
.
getBoxNGsnList
(
result
);
// List<GetBoxNGResult> boxNGsnList = LuxsanApi.getBoxNGsnList(result);
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"model"
,
result
.
getModel
());
map
.
put
(
"carton_id"
,
result
.
getCarton_id
());
List
<
GetBoxNGResult
>
boxNGsnList
=
LuxsanApi
.
getBoxNGsnList
(
map
);
return
ResultBean
.
newOkResult
(
boxNGsnList
);
return
ResultBean
.
newOkResult
(
boxNGsnList
);
}
}
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论