Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sample-form-platform
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
赵啸非
sample-form-platform
Commits
78d23419
Commit
78d23419
authored
Jun 21, 2023
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加设备相关信息
parent
da46842c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
336 additions
and
0 deletions
+336
-0
sample-form-manager/src/main/java/com/mortals/xhx/busiz/web/DeviceCallbackController.java
...a/com/mortals/xhx/busiz/web/DeviceCallbackController.java
+214
-0
sample-form-manager/src/main/java/com/mortals/xhx/common/key/ErrorCode.java
...r/src/main/java/com/mortals/xhx/common/key/ErrorCode.java
+122
-0
No files found.
sample-form-manager/src/main/java/com/mortals/xhx/busiz/web/DeviceCallbackController.java
0 → 100644
View file @
78d23419
package
com.mortals.xhx.busiz.web
;
import
com.alibaba.fastjson.JSONObject
;
import
com.mortals.framework.annotation.UnAuth
;
import
com.mortals.framework.common.Rest
;
import
com.mortals.framework.exception.AppException
;
import
com.mortals.xhx.common.code.DeviceMethodEnum
;
import
com.mortals.xhx.common.code.DeviceStatusEnum
;
import
com.mortals.xhx.common.code.YesNoEnum
;
import
com.mortals.xhx.common.pdu.device.DeviceReq
;
import
com.mortals.xhx.module.device.model.DeviceEntity
;
import
com.mortals.xhx.module.device.model.DeviceQuery
;
import
com.mortals.xhx.module.device.service.DeviceService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.Date
;
import
static
com
.
mortals
.
xhx
.
common
.
key
.
ErrorCode
.*;
@RestController
@Slf4j
@RequestMapping
(
"/api/device"
)
public
class
DeviceCallbackController
{
@Autowired
private
DeviceService
deviceService
;
@PostMapping
(
"callback"
)
@UnAuth
public
Rest
<
String
>
callback
(
@RequestBody
DeviceReq
req
)
{
log
.
info
(
"【设备接收】【请求体】--> "
+
JSONObject
.
toJSONString
(
req
));
StringBuilder
message
=
new
StringBuilder
();
message
.
append
(
String
.
format
(
"【外部请求】类型【%s】 内容:%s"
,
DeviceMethodEnum
.
getByValue
(
req
.
getReceiveMethod
()).
getDesc
(),
JSONObject
.
toJSONString
(
req
)));
try
{
switch
(
DeviceMethodEnum
.
getByValue
(
req
.
getReceiveMethod
()))
{
case
ADD:
deviceAdd
(
req
);
break
;
case
UPDATE:
deviceUpdate
(
req
);
break
;
case
DEL:
deviceDel
(
req
);
break
;
case
ACTIVE:
deviceActive
(
req
);
break
;
case
ENABLED:
deviceEnabled
(
req
);
break
;
case
STOP:
deviceStop
(
req
);
break
;
case
ONLINE:
deviceOnline
(
req
);
break
;
case
OFFLINE:
deviceOffline
(
req
);
break
;
}
}
catch
(
Exception
e
)
{
log
.
error
(
"接收数据失败"
,
e
);
Rest
.
fail
(
e
.
getMessage
());
}
return
Rest
.
ok
();
}
private
void
deviceAdd
(
DeviceReq
req
)
throws
AppException
{
log
.
info
(
"【设备新增】【请求体】--> "
+
JSONObject
.
toJSONString
(
req
));
//根据设备编码查询设备
DeviceEntity
deviceEntity
=
deviceService
.
selectOne
(
new
DeviceQuery
().
deviceCode
(
req
.
getDeviceCode
()));
if
(!
ObjectUtils
.
isEmpty
(
deviceEntity
))
{
throw
new
AppException
(
DEVICE_CODE_IS_EXIST
,
DEVICE_CODE_IS_EXIST_CONTENT
);
}
deviceEntity
=
new
DeviceEntity
();
deviceEntity
.
initAttrValue
();
deviceEntity
.
setDeviceName
(
req
.
getDeviceName
());
deviceEntity
.
setDeviceCode
(
req
.
getDeviceCode
());
deviceEntity
.
setDeviceMac
(
req
.
getDeviceCode
());
deviceEntity
.
setSiteId
(
req
.
getSiteId
());
deviceEntity
.
setSiteCode
(
req
.
getSiteCode
());
deviceEntity
.
setSiteName
(
req
.
getSiteName
());
deviceEntity
.
setProductCode
(
req
.
getProductCode
());
deviceEntity
.
setIp
(
req
.
getIp
());
deviceEntity
.
setPort
(
req
.
getPort
());
deviceEntity
.
setLeadingOfficial
(
req
.
getLeadingOfficial
());
deviceEntity
.
setLeadingOfficialTelephone
(
req
.
getLeadingOfficialTelephone
());
deviceEntity
.
setDeviceRemark
(
req
.
getDeviceRemark
());
deviceEntity
.
setCreateUserId
(
1L
);
deviceEntity
.
setCreateTime
(
new
Date
());
deviceService
.
save
(
deviceEntity
);
}
private
void
deviceUpdate
(
DeviceReq
req
)
throws
AppException
{
log
.
info
(
"【设备更新或新增】【请求体】--> "
+
JSONObject
.
toJSONString
(
req
));
//根据设备编码查询设备
DeviceEntity
deviceEntity
=
deviceService
.
selectOne
(
new
DeviceQuery
().
deviceCode
(
req
.
getDeviceCode
()));
if
(
ObjectUtils
.
isEmpty
(
deviceEntity
))
{
//不存在设备 则新增
this
.
deviceAdd
(
req
);
}
else
{
log
.
info
(
"设备更新~"
);
deviceEntity
.
setDeviceName
(
req
.
getDeviceName
());
deviceEntity
.
setDeviceCode
(
req
.
getDeviceCode
());
deviceEntity
.
setDeviceMac
(
req
.
getDeviceCode
());
deviceEntity
.
setSiteId
(
req
.
getSiteId
());
deviceEntity
.
setSiteCode
(
req
.
getSiteCode
());
deviceEntity
.
setSiteName
(
req
.
getSiteName
());
deviceEntity
.
setProductCode
(
req
.
getProductCode
());
deviceEntity
.
setIp
(
req
.
getIp
());
deviceEntity
.
setPort
(
req
.
getPort
());
deviceEntity
.
setDeviceRemark
(
req
.
getDeviceRemark
());
deviceEntity
.
setUpdateUserId
(
1L
);
deviceEntity
.
setUpdateTime
(
new
Date
());
deviceEntity
.
setLeadingOfficial
(
req
.
getLeadingOfficial
());
deviceService
.
update
(
deviceEntity
);
}
}
private
void
deviceDel
(
DeviceReq
req
)
throws
AppException
{
log
.
info
(
"【设备删除】【请求体】--> "
+
JSONObject
.
toJSONString
(
req
));
//根据设备编码查询设备
DeviceEntity
deviceEntity
=
checkDeviceExist
(
req
);
deviceService
.
remove
(
new
Long
[]{
deviceEntity
.
getId
()},
null
);
}
private
void
deviceActive
(
DeviceReq
req
)
throws
AppException
{
log
.
info
(
"【设备激活】【请求体】--> "
+
JSONObject
.
toJSONString
(
req
));
//根据设备编码查询设备
DeviceEntity
deviceEntity
=
checkDeviceExist
(
req
);
if
(
deviceEntity
.
getDeviceStatus
()
>
DeviceStatusEnum
.
未激活
.
getValue
())
{
throw
new
AppException
(
"当前设备已激活!"
);
}
deviceEntity
.
setDeviceStatus
(
DeviceStatusEnum
.
离线
.
getValue
());
deviceEntity
.
setUpdateTime
(
new
Date
());
deviceEntity
.
setUpdateUserId
(
1L
);
deviceService
.
update
(
deviceEntity
);
}
private
void
deviceEnabled
(
DeviceReq
req
)
throws
AppException
{
log
.
info
(
"【设备启用】【请求体】--> "
+
JSONObject
.
toJSONString
(
req
));
//根据设备编码查询设备
DeviceEntity
deviceEntity
=
checkDeviceExist
(
req
);
deviceEntity
.
setEnabled
(
YesNoEnum
.
YES
.
getValue
());
deviceEntity
.
setUpdateTime
(
new
Date
());
deviceEntity
.
setUpdateUserId
(
1L
);
deviceEntity
.
setUpdateTime
(
new
Date
());
deviceEntity
.
setUpdateUserId
(
1L
);
deviceService
.
update
(
deviceEntity
);
}
private
void
deviceStop
(
DeviceReq
req
)
throws
AppException
{
log
.
info
(
"【设备停用】【请求体】--> "
+
JSONObject
.
toJSONString
(
req
));
DeviceEntity
deviceEntity
=
checkDeviceExist
(
req
);
deviceEntity
.
setEnabled
(
YesNoEnum
.
NO
.
getValue
());
deviceEntity
.
setUpdateTime
(
new
Date
());
deviceEntity
.
setUpdateUserId
(
1L
);
deviceEntity
.
setUpdateTime
(
new
Date
());
deviceEntity
.
setUpdateUserId
(
1L
);
deviceService
.
update
(
deviceEntity
);
}
private
void
deviceOnline
(
DeviceReq
req
)
throws
AppException
{
log
.
info
(
"【设备上线】【请求体】--> "
+
JSONObject
.
toJSONString
(
req
));
DeviceEntity
deviceEntity
=
checkDeviceExist
(
req
);
deviceEntity
.
setDeviceStatus
(
DeviceStatusEnum
.
在线
.
getValue
());
deviceEntity
.
setUpdateTime
(
new
Date
());
deviceEntity
.
setUpdateUserId
(
1L
);
deviceEntity
.
setUpdateTime
(
new
Date
());
deviceEntity
.
setUpdateUserId
(
1L
);
deviceService
.
update
(
deviceEntity
);
}
private
void
deviceOffline
(
DeviceReq
req
)
throws
AppException
{
log
.
info
(
"【设备离线】【请求体】--> "
+
JSONObject
.
toJSONString
(
req
));
DeviceEntity
deviceEntity
=
checkDeviceExist
(
req
);
deviceEntity
.
setDeviceStatus
(
DeviceStatusEnum
.
离线
.
getValue
());
deviceEntity
.
setUpdateTime
(
new
Date
());
deviceEntity
.
setUpdateUserId
(
1L
);
deviceEntity
.
setUpdateTime
(
new
Date
());
deviceEntity
.
setUpdateUserId
(
1L
);
deviceService
.
update
(
deviceEntity
);
}
private
DeviceEntity
checkDeviceExist
(
DeviceReq
req
)
{
if
(
ObjectUtils
.
isEmpty
(
req
.
getDeviceCode
()))
{
throw
new
AppException
(
DEVICE_CODE_IS_EMPTY
,
DEVICE_CODE_IS_EMPTY_CONTENT
);
}
DeviceEntity
deviceEntity
=
deviceService
.
selectOne
(
new
DeviceQuery
().
deviceCode
(
req
.
getDeviceCode
()));
if
(
ObjectUtils
.
isEmpty
(
deviceEntity
))
{
throw
new
AppException
(
DEVICE_NOT_EXIST
,
DEVICE_NOT_EXIST_CONTENT
);
}
return
deviceEntity
;
}
}
sample-form-manager/src/main/java/com/mortals/xhx/common/key/ErrorCode.java
0 → 100644
View file @
78d23419
package
com.mortals.xhx.common.key
;
/**
* 错误码
*
* @author: zxfei
* @date: 2022/5/12 14:56
*/
public
interface
ErrorCode
{
public
static
final
int
STATUS_MS_EXCEPTION
=
500
;
public
static
final
int
STATUS_VALIDATE_EXCEPTION
=
420
;
public
static
final
int
STATUS_UNCHECKED_EXCEPTION
=
605
;
public
static
final
int
STATUS_TOKEN_NULL_EXCEPTION
=
604
;
public
static
final
int
STATUS_CODE_SUCCESS
=
0
;
public
static
final
int
STATUS_CODE_WARN
=
1
;
public
static
final
int
STATUS_CODE_ERROR
=
2
;
public
static
final
int
STATUS_CODE_INFO
=
3
;
public
static
final
int
STATUS_CODE_TOKEN_EXPIRED
=
4
;
public
static
final
int
STATUS_CODE_FATAL
=
5
;
public
static
final
int
STATUS_CODE_TRADE_PWD_NOT_SET
=
6
;
public
static
final
int
STATUS_ACCOUNT_LOCKED
=
7
;
public
static
final
int
STATUS_TRADE_PWD_OVER_THREE_TIME
=
8
;
public
static
final
int
STATUS_TRADE_PWD_ERROR
=
9
;
public
static
final
int
STATUS_EMPTY_PWD_ERROR
=
10
;
public
static
final
int
STATUS_TEL_NOT_RGI_ERROR
=
11
;
public
static
final
int
STATUS_TEL_ALREADY_REGI
=
12
;
public
static
final
int
STATUS_SAFETY_RISK
=
13
;
public
static
final
int
STATUS_LOGIN_CODE
=
15
;
public
static
final
int
BOOK_FAKUAN_CODE
=
16
;
public
static
final
String
ERROR_TRADE_PWD_OVER_THREE_TIME
=
"支付密码错误,请15分钟后再试"
;
public
static
final
String
ERROR_TRADE_PWD_ERROR
=
"支付密码错误,请重试"
;
public
static
final
String
ERROR_EMPTY_PWD_ERROR
=
"请设置登录密码"
;
public
static
final
String
ERROR_TEL_NOT_RGI
=
"该号码未注册"
;
public
static
final
String
ERROR_USERNAME_OR_PASSWORD
=
"用户名或者密码错误"
;
public
static
final
String
ERROR_TRADE_PWD
=
"交易密码错误"
;
public
static
final
String
ERROR_FORBIDDEN_OPER
=
"非法操作"
;
public
static
final
String
ERROR_TRADE_PWD_NOT_SET
=
"非法操作"
;
public
static
final
String
ERROR_NOT_REAL_NAME_AUTH
=
"您未实名认证,禁止该操作"
;
public
static
final
String
ERROR_INTERNAL_SERVER_ERROR
=
"服务器内部错误"
;
public
static
final
String
ERROR_UNAUTHORIZED
=
"token不正确或已过期"
;
public
static
final
String
ERROR_TOKEN_IS_NULL
=
"token不能为空"
;
public
static
final
String
ERROR_MISS_SERVLET
=
"服务不存在"
;
public
static
final
String
ERROR_CAPTCHA_OFTEN
=
"验证码已发送"
;
public
static
final
String
ERROR_CAPTCHA_WRONG
=
"验证码错误"
;
public
static
final
String
ERROR_TEL_ALREADY_REGI
=
"该手机号已被注册"
;
public
static
final
String
ERROR_CODE_DUPLICATE_KEY
=
"重复添加信息(含部分)"
;
public
static
final
String
ERROR_NOT_EXITS
=
"对应记录不存在"
;
public
static
final
String
ERROR_STATUS_CATEGORY
=
"状态错误"
;
public
static
final
String
ERROR_FRIEND_SHIP_ALREADY
=
"已经是你好友"
;
public
static
final
String
ERROR_FRIEND_SHIP_WAIT
=
"已向改好友发出邀请,等待接受"
;
public
static
final
String
ERROR_CODE_ACCOUNT_LOCKED
=
"账号被锁定,请联系客服"
;
public
static
final
String
WARN_ARGUMENT
=
"参数错误"
;
public
static
final
String
ERROR_USERNAME_EXIST
=
"该号码已被注册"
;
public
static
final
String
ERROR_SAFETY_RISK
=
"不在常用设备上登录"
;
public
static
final
String
INFO_TEL_BIND
=
"手机号码已经被绑定"
;
public
static
final
String
INFO_TEL_FORMAT_WRONG
=
"手机号码格式不正确"
;
public
static
final
String
ERROR_NOT_FOUND
=
"404 not found"
;
public
static
final
String
DISABLED
=
"该账号已被封禁,如有疑问请联系平台"
;
public
static
final
String
DATENULL
=
"缺少参数"
;
public
static
final
String
ERRDATE
=
"无效参数"
;
public
static
final
String
ERRSTAE
=
"状态异常"
;
public
static
final
String
EXTDATE
=
"参数异常"
;
public
static
final
String
NUMEXE
=
"账号异常"
;
public
static
final
String
CAPDON
=
"资产已被冻结,如有疑问请联系平台"
;
public
static
final
String
CONOTS
=
"操作失败"
;
public
static
final
String
OK
=
"成功!"
;
public
static
final
String
TOKENX
=
"身份验证失败,请重新登录"
;
public
static
final
String
CAPNOT
=
"充值余额不足请充值"
;
public
static
final
String
SYSNOT
=
"系统繁忙,请稍后再试..."
;
public
static
final
String
NOWER
=
"没有权限"
;
public
static
final
String
PAGEDATA
=
"分页参数不能为空"
;
public
static
final
String
CARADD_MEMBERS
=
"该司机已有绑定车辆,不能绑定多个"
;
public
static
final
int
DEVICE_CODE_IS_EMPTY
=
1001
;
public
static
final
String
DEVICE_CODE_IS_EMPTY_CONTENT
=
"当前设备编码为空!"
;
public
static
final
int
DEVICE_CODE_IS_EXIST
=
1002
;
public
static
final
String
DEVICE_CODE_IS_EXIST_CONTENT
=
"当前设备编码已存在!"
;
public
static
final
int
PRODUCT_IS_EMPTY
=
1003
;
public
static
final
String
PRODUCT_IS_EMPTY_CONTENT
=
"所属产品编码不存在!"
;
public
static
final
int
DEVICE_UNACTIVE
=
1004
;
public
static
final
String
DEVICE_UNACTIVE_CONTENT
=
"当前设备未激活,请在后台配置后再激活!"
;
public
static
final
int
PLATFORM_IS_EMPTY
=
1005
;
public
static
final
String
PLATFORM_IS_EMPTY_CONTENT
=
"当前设备编码不存在!"
;
public
static
final
int
PLATFORM_UNEXIST
=
1006
;
public
static
final
String
PLATFORM_UNEXIST_CONTENT
=
"当前设备所属产品平台未配置,请在后台配置后再激活!"
;
public
static
final
int
SITEID_IS_EMPTY
=
1007
;
public
static
final
String
SITEID_IS_EMPTY_CONTENT
=
"站点ID为空!"
;
public
static
final
int
DEVICE_CONFIG_IS_EMPTY
=
1008
;
public
static
final
String
DEVICE_CONFIG_IS_EMPTY_CONTENT
=
"设备创建,请完善设备配置信息!"
;
public
static
final
int
DEVICE_NOT_EXIST
=
1009
;
public
static
final
String
DEVICE_NOT_EXIST_CONTENT
=
"当前设备不存在!"
;
public
static
final
int
TOKEN_AUTH_FAIL
=
1010
;
public
static
final
String
TOKEN_AUTH_FAIL_CONTENT
=
"token认证失败!"
;
public
static
final
int
ERROR_TOKEN_EXPIRED
=
9001
;
public
static
final
String
ERROR_TOKEN_EXPIRED_CONTENT
=
"用户登录过期,请重新登录!"
;
public
static
final
int
ERROR_TOKEN_UNAUTHORIZED
=
9002
;
public
static
final
String
ERROR_TOKEN_UNAUTHORIZED_CONTENT
=
"token不正确或已过期"
;
public
static
final
int
ERROR_USER_OPERATION
=
9009
;
public
static
final
String
ERROR_USER_OPERATION_CONTENT
=
"用户无该操作权限!"
;
}
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