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
c6ba21e2
Commit
c6ba21e2
authored
Jun 21, 2023
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加设备相关信息
parent
fa7b842e
Changes
12
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
2980 additions
and
1976 deletions
+2980
-1976
common-lib/src/main/java/com/mortals/xhx/common/pdu/device/DeviceReq.java
...ain/java/com/mortals/xhx/common/pdu/device/DeviceReq.java
+0
-1
sample-form-manager/db/add.sql
sample-form-manager/db/add.sql
+22
-0
sample-form-manager/src/main/java/com/mortals/xhx/base/framework/aspect/OperlogAspect.java
.../com/mortals/xhx/base/framework/aspect/OperlogAspect.java
+14
-9
sample-form-manager/src/main/java/com/mortals/xhx/common/code/DeviceMethodEnum.java
...in/java/com/mortals/xhx/common/code/DeviceMethodEnum.java
+72
-0
sample-form-manager/src/main/java/com/mortals/xhx/common/code/EnabledEnum.java
...rc/main/java/com/mortals/xhx/common/code/EnabledEnum.java
+65
-0
sample-form-manager/src/main/java/com/mortals/xhx/common/code/OperTypeEnum.java
...c/main/java/com/mortals/xhx/common/code/OperTypeEnum.java
+11
-12
sample-form-manager/src/main/java/com/mortals/xhx/module/device/model/DeviceEntity.java
...ava/com/mortals/xhx/module/device/model/DeviceEntity.java
+96
-321
sample-form-manager/src/main/java/com/mortals/xhx/module/device/model/DeviceQuery.java
...java/com/mortals/xhx/module/device/model/DeviceQuery.java
+1361
-814
sample-form-manager/src/main/java/com/mortals/xhx/module/device/service/DeviceService.java
.../com/mortals/xhx/module/device/service/DeviceService.java
+18
-0
sample-form-manager/src/main/java/com/mortals/xhx/module/device/service/impl/DeviceServiceImpl.java
...als/xhx/module/device/service/impl/DeviceServiceImpl.java
+70
-0
sample-form-manager/src/main/java/com/mortals/xhx/module/device/web/DeviceController.java
...a/com/mortals/xhx/module/device/web/DeviceController.java
+148
-12
sample-form-manager/src/main/resources/sqlmap/module/device/DeviceMapper.xml
.../src/main/resources/sqlmap/module/device/DeviceMapper.xml
+1103
-807
No files found.
common-lib/src/main/java/com/mortals/xhx/common/pdu/device/DeviceReq.java
View file @
c6ba21e2
package
com.mortals.xhx.common.pdu.device
;
package
com.mortals.xhx.common.pdu.device
;
import
com.fasterxml.jackson.databind.annotation.JsonDeserialize
;
import
lombok.Data
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.io.Serializable
;
...
...
sample-form-manager/db/add.sql
0 → 100644
View file @
c6ba21e2
-- ----------------------------
2023
-
06
-
21
-- ----------------------------
ALTER
TABLE
mortals_xhx_device
ADD
COLUMN
`deviceFirmId`
bigint
(
20
)
DEFAULT
NULL
COMMENT
'设备生产厂商ID'
AFTER
siteName
;
ALTER
TABLE
mortals_xhx_device
ADD
COLUMN
`deviceFirmname`
varchar
(
200
)
DEFAULT
NULL
COMMENT
'设备生产厂商名称'
AFTER
deviceFirmId
;
ALTER
TABLE
mortals_xhx_device
ADD
COLUMN
`ip`
varchar
(
64
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
DEFAULT
NULL
COMMENT
'设备访问ip'
AFTER
deviceFirmname
;
ALTER
TABLE
mortals_xhx_device
ADD
COLUMN
`port`
varchar
(
64
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
DEFAULT
NULL
COMMENT
'端口'
AFTER
ip
;
ALTER
TABLE
mortals_xhx_device
ADD
COLUMN
`enabled`
tinyint
(
2
)
DEFAULT
NULL
COMMENT
'启用状态 (0.停止,1.启用)'
AFTER
port
;
ALTER
TABLE
mortals_xhx_device
ADD
COLUMN
`deviceRemark`
varchar
(
256
)
CHARACTER
SET
utf8
COLLATE
utf8_general_ci
DEFAULT
NULL
COMMENT
'备注'
AFTER
enabled
;
ALTER
TABLE
mortals_xhx_device
ADD
COLUMN
`onlineTime`
datetime
DEFAULT
NULL
COMMENT
'最近上线时间'
AFTER
deviceRemark
;
ALTER
TABLE
mortals_xhx_device
ADD
COLUMN
`offlineTime`
datetime
DEFAULT
NULL
COMMENT
'最近离线时间'
AFTER
onlineTime
;
\ No newline at end of file
sample-form-manager/src/main/java/com/mortals/xhx/base/framework/aspect/OperlogAspect.java
View file @
c6ba21e2
...
@@ -4,8 +4,10 @@ import java.util.Date;
...
@@ -4,8 +4,10 @@ import java.util.Date;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
cn.hutool.core.util.StrUtil
;
import
com.mortals.framework.model.OperateLogPdu
;
import
com.mortals.framework.model.OperateLogPdu
;
import
com.mortals.framework.service.IMessageProduceService
;
import
com.mortals.framework.service.IMessageProduceService
;
import
com.mortals.xhx.common.code.OperTypeEnum
;
import
com.mortals.xhx.system.MessageProducer
;
import
com.mortals.xhx.system.MessageProducer
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.annotation.AfterReturning
;
import
org.aspectj.lang.annotation.AfterReturning
;
...
@@ -28,7 +30,7 @@ import com.mortals.xhx.base.system.oper.service.OperLogService;
...
@@ -28,7 +30,7 @@ import com.mortals.xhx.base.system.oper.service.OperLogService;
* 操作日志记录
* 操作日志记录
*/
*/
@Component
@Component
public
class
OperlogAspect
extends
FileLogServiceImpl
implements
ILogService
{
public
class
OperlogAspect
extends
FileLogServiceImpl
implements
ILogService
{
private
final
static
Logger
logger
=
LoggerFactory
.
getLogger
(
OperlogAspect
.
class
);
private
final
static
Logger
logger
=
LoggerFactory
.
getLogger
(
OperlogAspect
.
class
);
...
@@ -39,11 +41,19 @@ public class OperlogAspect extends FileLogServiceImpl implements ILogService {
...
@@ -39,11 +41,19 @@ public class OperlogAspect extends FileLogServiceImpl implements ILogService {
@Override
@Override
public
void
doHandlerLog
(
String
platformMark
,
Long
userId
,
String
userName
,
String
loginName
,
String
requestUrl
,
public
void
doHandlerLog
(
String
platformMark
,
Long
userId
,
String
userName
,
String
loginName
,
String
requestUrl
,
String
content
,
String
ip
,
Date
logDate
)
{
String
content
,
String
ip
,
Date
logDate
)
{
super
.
doHandlerLog
(
platformMark
,
userId
,
userName
,
loginName
,
requestUrl
,
content
,
ip
,
logDate
);
super
.
doHandlerLog
(
platformMark
,
userId
,
userName
,
loginName
,
requestUrl
,
content
,
ip
,
logDate
);
if
(
ObjectUtils
.
isEmpty
(
userId
))
return
;
operLogService
.
insertOperLog
(
ip
,
requestUrl
,
userId
,
userName
,
loginName
,
content
);
operLogService
.
insertOperLog
(
ip
,
requestUrl
,
userId
,
userName
,
loginName
,
content
);
int
operType
=
OperTypeEnum
.
OTHER
.
getValue
();
//判断内容包含
if
(
StrUtil
.
contains
(
content
,
"查询"
)
||
StrUtil
.
contains
(
content
,
"查看"
))
{
operType
=
OperTypeEnum
.
SEARCH
.
getValue
();
}
else
if
(
StrUtil
.
contains
(
content
,
"保存"
)
||
StrUtil
.
contains
(
content
,
"新增"
)
||
StrUtil
.
contains
(
content
,
"修改"
))
{
operType
=
OperTypeEnum
.
SAVE
.
getValue
();
}
else
if
(
StrUtil
.
contains
(
content
,
"删除"
))
{
operType
=
OperTypeEnum
.
DELETE
.
getValue
();
}
OperateLogPdu
operateLogPdu
=
new
OperateLogPdu
();
OperateLogPdu
operateLogPdu
=
new
OperateLogPdu
();
operateLogPdu
.
initAttrValue
();
operateLogPdu
.
initAttrValue
();
operateLogPdu
.
setIp
(
ip
);
operateLogPdu
.
setIp
(
ip
);
...
@@ -54,17 +64,13 @@ public class OperlogAspect extends FileLogServiceImpl implements ILogService {
...
@@ -54,17 +64,13 @@ public class OperlogAspect extends FileLogServiceImpl implements ILogService {
operateLogPdu
.
setPlatformMark
(
platformMark
);
operateLogPdu
.
setPlatformMark
(
platformMark
);
operateLogPdu
.
setLogDate
(
logDate
);
operateLogPdu
.
setLogDate
(
logDate
);
operateLogPdu
.
setContent
(
content
);
operateLogPdu
.
setContent
(
content
);
operateLogPdu
.
setOperType
(
1
);
operateLogPdu
.
setOperType
(
operType
);
messageProducer
.
syncOperSend
(
operateLogPdu
);
messageProducer
.
syncOperSend
(
operateLogPdu
);
}
}
@Override
@Override
public
void
doHandlerLog
(
String
platformMark
,
String
loginName
,
String
requestUrl
,
String
content
,
String
ip
)
{
public
void
doHandlerLog
(
String
platformMark
,
String
loginName
,
String
requestUrl
,
String
content
,
String
ip
)
{
// operLogService.insertOperLog(ip, requestUrl, null, "", loginName,
// content);
this
.
doHandlerLog
(
platformMark
,
null
,
""
,
loginName
,
requestUrl
,
content
,
ip
,
new
Date
());
this
.
doHandlerLog
(
platformMark
,
null
,
""
,
loginName
,
requestUrl
,
content
,
ip
,
new
Date
());
}
}
@Pointcut
(
"execution(public * com.mortals.xhx..*Controller.*(..))"
)
@Pointcut
(
"execution(public * com.mortals.xhx..*Controller.*(..))"
)
...
@@ -79,7 +85,6 @@ public class OperlogAspect extends FileLogServiceImpl implements ILogService {
...
@@ -79,7 +85,6 @@ public class OperlogAspect extends FileLogServiceImpl implements ILogService {
// url
// url
logger
.
info
(
"ip[{}]url[{}]"
,
request
.
getRemoteAddr
(),
request
.
getRequestURL
());
logger
.
info
(
"ip[{}]url[{}]"
,
request
.
getRemoteAddr
(),
request
.
getRequestURL
());
// 参数第1和第2个参数为HttpServletRequest request, HttpServletResponse
// 参数第1和第2个参数为HttpServletRequest request, HttpServletResponse
// response
if
(
joinPoint
.
getArgs
().
length
>
2
)
{
if
(
joinPoint
.
getArgs
().
length
>
2
)
{
logger
.
info
(
"args={}"
,
joinPoint
.
getArgs
()[
2
]);
logger
.
info
(
"args={}"
,
joinPoint
.
getArgs
()[
2
]);
}
else
{
}
else
{
...
...
sample-form-manager/src/main/java/com/mortals/xhx/common/code/DeviceMethodEnum.java
0 → 100644
View file @
c6ba21e2
package
com.mortals.xhx.common.code
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
/**
* 设备请求方式,1:新增,2:修改,3:删除,4:激活,5:启用,6:停用
*
* @author zxfei
*/
public
enum
DeviceMethodEnum
{
ADD
(
1
,
"新增"
),
UPDATE
(
2
,
"修改"
),
DEL
(
3
,
"删除"
),
ACTIVE
(
4
,
"激活"
),
ENABLED
(
5
,
"启用"
),
STOP
(
6
,
"停用"
),
ONLINE
(
7
,
"上线"
),
OFFLINE
(
8
,
"下线"
)
;
private
Integer
value
;
private
String
desc
;
DeviceMethodEnum
(
Integer
value
,
String
desc
)
{
this
.
value
=
value
;
this
.
desc
=
desc
;
}
public
Integer
getValue
()
{
return
this
.
value
;
}
public
String
getDesc
()
{
return
this
.
desc
;
}
public
static
DeviceMethodEnum
getByValue
(
Integer
value
)
{
for
(
DeviceMethodEnum
deviceTypeEnum
:
DeviceMethodEnum
.
values
())
{
if
(
deviceTypeEnum
.
getValue
()
==
value
)
{
return
deviceTypeEnum
;
}
}
return
null
;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public
static
Map
<
String
,
String
>
getEnumMap
(
Integer
...
eItem
)
{
Map
<
String
,
String
>
resultMap
=
new
LinkedHashMap
<>();
for
(
DeviceMethodEnum
item
:
DeviceMethodEnum
.
values
())
{
try
{
boolean
hasE
=
false
;
for
(
Integer
e
:
eItem
)
{
if
(
item
.
getValue
()
==
e
)
{
hasE
=
true
;
break
;
}
}
if
(!
hasE
)
{
resultMap
.
put
(
item
.
getValue
()
+
""
,
item
.
getDesc
());
}
}
catch
(
Exception
ex
)
{
}
}
return
resultMap
;
}
}
\ No newline at end of file
sample-form-manager/src/main/java/com/mortals/xhx/common/code/EnabledEnum.java
0 → 100644
View file @
c6ba21e2
package
com.mortals.xhx.common.code
;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
/**
* 启用状态 (0.停止,1.启用)枚举类
*
* @author zxfei
*/
public
enum
EnabledEnum
{
停止
(
0
,
"停止"
),
启用
(
1
,
"启用"
);
private
Integer
value
;
private
String
desc
;
EnabledEnum
(
Integer
value
,
String
desc
)
{
this
.
value
=
value
;
this
.
desc
=
desc
;
}
public
Integer
getValue
()
{
return
this
.
value
;
}
public
String
getDesc
()
{
return
this
.
desc
;
}
public
static
EnabledEnum
getByValue
(
Integer
value
)
{
for
(
EnabledEnum
enabledEnum
:
EnabledEnum
.
values
())
{
if
(
enabledEnum
.
getValue
()
==
value
)
{
return
enabledEnum
;
}
}
return
null
;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public
static
Map
<
String
,
String
>
getEnumMap
(
Integer
...
eItem
)
{
Map
<
String
,
String
>
resultMap
=
new
LinkedHashMap
<>();
for
(
EnabledEnum
item
:
EnabledEnum
.
values
())
{
try
{
boolean
hasE
=
false
;
for
(
Integer
e
:
eItem
)
{
if
(
item
.
getValue
()
==
e
)
{
hasE
=
true
;
break
;
}
}
if
(!
hasE
)
{
resultMap
.
put
(
item
.
getValue
()
+
""
,
item
.
getDesc
());
}
}
catch
(
Exception
ex
)
{
}
}
return
resultMap
;
}
}
\ No newline at end of file
sample-form-manager/src/main/java/com/mortals/xhx/common/code/OperTypeEnum.java
View file @
c6ba21e2
...
@@ -3,20 +3,19 @@ package com.mortals.xhx.common.code;
...
@@ -3,20 +3,19 @@ package com.mortals.xhx.common.code;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
/**
* Created by chendilin on 2018/3/7.
*/
public
enum
OperTypeEnum
{
public
enum
OperTypeEnum
{
SAVE
(
0
,
"添加"
),
SAVE
(
0
,
"添加"
),
UPDATE
(
1
,
"更新"
),
UPDATE
(
1
,
"更新"
),
DELETE
(
2
,
"删除"
),
DELETE
(
2
,
"删除"
),
OTHER
(-
1
,
"其它"
);
SEARCH
(
3
,
"查询"
),
OTHER
(-
1
,
"其它"
);
private
int
value
;
private
int
value
;
private
String
msg
;
private
String
msg
;
private
OperTypeEnum
(
int
value
,
String
msg
)
{
private
OperTypeEnum
(
int
value
,
String
msg
)
{
this
.
value
=
value
;
this
.
value
=
value
;
this
.
msg
=
msg
;
this
.
msg
=
msg
;
}
}
...
@@ -25,11 +24,11 @@ public enum OperTypeEnum {
...
@@ -25,11 +24,11 @@ public enum OperTypeEnum {
return
this
.
value
;
return
this
.
value
;
}
}
public
static
Map
<
String
,
String
>
getEnumMap
()
{
public
static
Map
<
String
,
String
>
getEnumMap
()
{
Map
<
String
,
String
>
resultMap
=
new
HashMap
<>();
Map
<
String
,
String
>
resultMap
=
new
HashMap
<>();
OperTypeEnum
[]
operTypeEnum
=
OperTypeEnum
.
values
();
OperTypeEnum
[]
operTypeEnum
=
OperTypeEnum
.
values
();
for
(
OperTypeEnum
typeEnum
:
operTypeEnum
)
{
for
(
OperTypeEnum
typeEnum
:
operTypeEnum
)
{
resultMap
.
put
(
String
.
valueOf
(
typeEnum
.
value
),
typeEnum
.
msg
);
resultMap
.
put
(
String
.
valueOf
(
typeEnum
.
value
),
typeEnum
.
msg
);
}
}
return
resultMap
;
return
resultMap
;
}
}
...
...
sample-form-manager/src/main/java/com/mortals/xhx/module/device/model/DeviceEntity.java
View file @
c6ba21e2
This diff is collapsed.
Click to expand it.
sample-form-manager/src/main/java/com/mortals/xhx/module/device/model/DeviceQuery.java
View file @
c6ba21e2
This diff is collapsed.
Click to expand it.
sample-form-manager/src/main/java/com/mortals/xhx/module/device/service/DeviceService.java
View file @
c6ba21e2
package
com.mortals.xhx.module.device.service
;
package
com.mortals.xhx.module.device.service
;
import
com.mortals.framework.model.Context
;
import
com.mortals.framework.service.ICRUDService
;
import
com.mortals.framework.service.ICRUDService
;
import
com.mortals.xhx.module.device.dao.DeviceDao
;
import
com.mortals.xhx.module.device.model.DeviceEntity
;
import
com.mortals.xhx.module.device.model.DeviceEntity
;
/**
/**
* DeviceService
* DeviceService
...
@@ -11,4 +13,20 @@ import com.mortals.xhx.module.device.model.DeviceEntity;
...
@@ -11,4 +13,20 @@ import com.mortals.xhx.module.device.model.DeviceEntity;
*/
*/
public
interface
DeviceService
extends
ICRUDService
<
DeviceEntity
,
Long
>{
public
interface
DeviceService
extends
ICRUDService
<
DeviceEntity
,
Long
>{
DeviceDao
getDao
();
/**
* 设备激活
* @param deviceCode
* @param context
*/
void
active
(
String
deviceCode
,
Context
context
);
/**
* 设备启用停用
* @param id
* @param context
*/
void
deviceEnabled
(
Long
id
,
Integer
status
,
Context
context
);
}
}
\ No newline at end of file
sample-form-manager/src/main/java/com/mortals/xhx/module/device/service/impl/DeviceServiceImpl.java
View file @
c6ba21e2
package
com.mortals.xhx.module.device.service.impl
;
package
com.mortals.xhx.module.device.service.impl
;
import
com.alibaba.fastjson.JSON
;
import
com.mortals.framework.common.Rest
;
import
com.mortals.framework.exception.AppException
;
import
com.mortals.framework.model.Context
;
import
com.mortals.framework.service.impl.AbstractCRUDServiceImpl
;
import
com.mortals.framework.service.impl.AbstractCRUDServiceImpl
;
import
com.mortals.xhx.common.code.DeviceMethodEnum
;
import
com.mortals.xhx.common.code.DeviceStatusEnum
;
import
com.mortals.xhx.common.code.EnabledEnum
;
import
com.mortals.xhx.common.pdu.LoginForm
;
import
com.mortals.xhx.common.pdu.device.DeviceReq
;
import
com.mortals.xhx.feign.device.IDeviceFeign
;
import
com.mortals.xhx.module.device.dao.DeviceDao
;
import
com.mortals.xhx.module.device.dao.DeviceDao
;
import
com.mortals.xhx.module.device.model.DeviceEntity
;
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
com.mortals.xhx.module.device.service.DeviceService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.ObjectUtils
;
import
java.util.Date
;
/**
/**
* DeviceService
* DeviceService
* 设备 service实现
* 设备 service实现
...
@@ -13,6 +31,58 @@ import org.springframework.stereotype.Service;
...
@@ -13,6 +31,58 @@ import org.springframework.stereotype.Service;
* @date 2023-02-25
* @date 2023-02-25
*/
*/
@Service
(
"deviceService"
)
@Service
(
"deviceService"
)
@Slf4j
public
class
DeviceServiceImpl
extends
AbstractCRUDServiceImpl
<
DeviceDao
,
DeviceEntity
,
Long
>
implements
DeviceService
{
public
class
DeviceServiceImpl
extends
AbstractCRUDServiceImpl
<
DeviceDao
,
DeviceEntity
,
Long
>
implements
DeviceService
{
@Autowired
private
IDeviceFeign
deviceFeign
;
@Value
(
"${token.loginName:'admin'}"
)
private
String
loginName
;
@Value
(
"${token.password:'admin'}"
)
private
String
password
;
@Override
public
void
active
(
String
deviceCode
,
Context
context
)
{
DeviceEntity
deviceEntity
=
this
.
selectOne
(
new
DeviceQuery
().
deviceCode
(
deviceCode
));
if
(
ObjectUtils
.
isEmpty
(
deviceEntity
))
throw
new
AppException
(
"当前设备不存在!"
);
if
(
deviceEntity
.
getDeviceStatus
()
>
DeviceStatusEnum
.
未激活
.
getValue
())
throw
new
AppException
(
"当前设备已激活!"
);
deviceEntity
.
setDeviceStatus
(
DeviceStatusEnum
.
离线
.
getValue
());
deviceEntity
.
setEnabled
(
EnabledEnum
.
启用
.
getValue
());
this
.
getDao
().
update
(
deviceEntity
);
String
token
=
getToken
();
DeviceReq
deviceReq
=
new
DeviceReq
();
deviceReq
.
setReceiveMethod
(
DeviceMethodEnum
.
ACTIVE
.
getValue
());
deviceReq
.
setDeviceCode
(
deviceCode
);
Rest
<
String
>
rest
=
deviceFeign
.
deviceCall
(
deviceReq
,
token
);
log
.
info
(
"激活结果:{}"
,
JSON
.
toJSONString
(
rest
));
}
@Override
public
void
deviceEnabled
(
Long
id
,
Integer
enabled
,
Context
context
)
{
DeviceEntity
deviceEntity
=
this
.
get
(
id
,
context
);
if
(
ObjectUtils
.
isEmpty
(
deviceEntity
))
throw
new
AppException
(
"当前设备不存在!"
);
deviceEntity
.
setEnabled
(
enabled
);
deviceEntity
.
setUpdateTime
(
new
Date
());
deviceEntity
.
setUpdateUserId
(
getContextUserId
(
context
));
this
.
getDao
().
update
(
deviceEntity
);
String
token
=
getToken
();
DeviceReq
deviceReq
=
new
DeviceReq
();
deviceReq
.
setReceiveMethod
(
DeviceMethodEnum
.
ENABLED
.
getValue
());
deviceReq
.
setDeviceCode
(
deviceEntity
.
getDeviceCode
());
Rest
<
String
>
rest
=
deviceFeign
.
deviceCall
(
deviceReq
,
token
);
log
.
info
(
"启用结果:{}"
,
JSON
.
toJSONString
(
rest
));
}
private
String
getToken
()
{
LoginForm
loginForm
=
new
LoginForm
();
loginForm
.
setLoginName
(
loginName
);
loginForm
.
setPassword
(
password
);
Rest
<
String
>
rest
=
deviceFeign
.
getToken
(
loginForm
);
String
token
=
rest
.
getData
();
return
token
;
}
}
}
\ No newline at end of file
sample-form-manager/src/main/java/com/mortals/xhx/module/device/web/DeviceController.java
View file @
c6ba21e2
package
com.mortals.xhx.module.device.web
;
package
com.mortals.xhx.module.device.web
;
import
com.alibaba.fastjson.JSON
;
import
com.mortals.framework.common.Rest
;
import
com.mortals.framework.exception.AppException
;
import
com.mortals.framework.web.BaseCRUDJsonBodyMappingController
;
import
com.mortals.framework.web.BaseCRUDJsonBodyMappingController
;
import
com.mortals.xhx.base.system.param.service.ParamService
;
import
com.mortals.xhx.base.system.param.service.ParamService
;
import
com.mortals.xhx.common.code.DeviceMethodEnum
;
import
com.mortals.xhx.common.code.EnabledEnum
;
import
com.mortals.xhx.common.pdu.LoginForm
;
import
com.mortals.xhx.common.pdu.device.DeviceReq
;
import
com.mortals.xhx.feign.device.IDeviceFeign
;
import
com.mortals.xhx.module.device.model.DeviceQuery
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.ObjectUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
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
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
com.mortals.framework.model.Context
;
import
com.mortals.framework.model.Context
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
com.mortals.framework.web.BaseCRUDJsonBodyMappingController
;
import
com.mortals.framework.web.BaseCRUDJsonBodyMappingController
;
import
com.mortals.xhx.module.device.model.DeviceEntity
;
import
com.mortals.xhx.module.device.model.DeviceEntity
;
import
com.mortals.xhx.module.device.service.DeviceService
;
import
com.mortals.xhx.module.device.service.DeviceService
;
import
org.apache.commons.lang3.ArrayUtils
;
import
org.apache.commons.lang3.ArrayUtils
;
import
com.mortals.framework.util.StringUtils
;
import
com.mortals.framework.util.StringUtils
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
static
com
.
mortals
.
framework
.
ap
.
SysConstains
.*;
import
static
com
.
mortals
.
framework
.
ap
.
SysConstains
.*;
/**
/**
*
* 设备
* 设备
*
*
* @author zxfei
* @author zxfei
* @date 2023-02-25
* @date 2023-02-25
*/
*/
@RestController
@RestController
@RequestMapping
(
"device"
)
@RequestMapping
(
"device"
)
public
class
DeviceController
extends
BaseCRUDJsonBodyMappingController
<
DeviceService
,
DeviceEntity
,
Long
>
{
@Slf4j
public
class
DeviceController
extends
BaseCRUDJsonBodyMappingController
<
DeviceService
,
DeviceEntity
,
Long
>
{
@Autowired
@Autowired
private
ParamService
paramService
;
private
ParamService
paramService
;
public
DeviceController
(){
@Autowired
super
.
setModuleDesc
(
"设备"
);
private
IDeviceFeign
deviceFeign
;
@Value
(
"${token.loginName:'admin'}"
)
private
String
loginName
;
@Value
(
"${token.password:'admin'}"
)
private
String
password
;
public
DeviceController
()
{
super
.
setModuleDesc
(
"设备"
);
}
}
@Override
@Override
protected
void
init
(
Map
<
String
,
Object
>
model
,
Context
context
)
{
protected
void
init
(
Map
<
String
,
Object
>
model
,
Context
context
)
{
this
.
addDict
(
model
,
"deviceSrc"
,
paramService
.
getParamBySecondOrganize
(
"Device"
,
"deviceSrc"
));
this
.
addDict
(
model
,
"deviceSrc"
,
paramService
.
getParamBySecondOrganize
(
"Device"
,
"deviceSrc"
));
this
.
addDict
(
model
,
"deviceStatus"
,
paramService
.
getParamBySecondOrganize
(
"Device"
,
"deviceStatus"
));
this
.
addDict
(
model
,
"deviceStatus"
,
paramService
.
getParamBySecondOrganize
(
"Device"
,
"deviceStatus"
));
this
.
addDict
(
model
,
"source"
,
paramService
.
getParamBySecondOrganize
(
"Device"
,
"source"
));
this
.
addDict
(
model
,
"source"
,
paramService
.
getParamBySecondOrganize
(
"Device"
,
"source"
));
this
.
addDict
(
model
,
"enabled"
,
EnabledEnum
.
getEnumMap
());
super
.
init
(
model
,
context
);
super
.
init
(
model
,
context
);
}
}
/**
* 设备激活
*/
@PostMapping
(
value
=
"active"
)
public
Rest
<
Void
>
deviceActive
(
@RequestBody
DeviceEntity
deviceEntity
)
{
log
.
info
(
"设备激活:{}"
,
deviceEntity
.
getDeviceCode
());
String
busiDesc
=
this
.
getModuleDesc
()
+
"设备激活"
;
Rest
<
Void
>
rest
=
Rest
.
ok
(
busiDesc
+
" 【成功】"
);
try
{
this
.
service
.
active
(
deviceEntity
.
getDeviceCode
(),
getContext
());
recordSysLog
(
request
,
busiDesc
+
" 【成功】"
);
}
catch
(
Exception
e
)
{
log
.
error
(
"设备激活消息"
,
e
);
rest
=
Rest
.
fail
(
super
.
convertException
(
e
));
}
return
rest
;
}
/**
* 设备启用停用
*/
@PostMapping
(
value
=
"enable"
)
public
String
deviceEnable
(
@RequestBody
DeviceEntity
deviceEntity
)
{
JSONObject
jsonObject
=
new
JSONObject
();
Map
<
String
,
Object
>
model
=
new
HashMap
<>();
String
busiDesc
=
this
.
getModuleDesc
()
+
"设备"
;
try
{
this
.
service
.
deviceEnabled
(
deviceEntity
.
getId
(),
deviceEntity
.
getEnabled
(),
getContext
());
recordSysLog
(
request
,
busiDesc
+
EnabledEnum
.
getByValue
(
deviceEntity
.
getEnabled
()).
getDesc
()
+
" 【成功】"
);
jsonObject
.
put
(
KEY_RESULT_DATA
,
model
);
jsonObject
.
put
(
KEY_RESULT_CODE
,
VALUE_RESULT_SUCCESS
);
}
catch
(
Exception
e
)
{
log
.
error
(
"设备启用停用消息"
,
e
);
jsonObject
.
put
(
KEY_RESULT_CODE
,
VALUE_RESULT_FAILURE
);
jsonObject
.
put
(
KEY_RESULT_MSG
,
super
.
convertException
(
e
));
}
return
jsonObject
.
toJSONString
();
}
@Override
protected
int
saveAfter
(
DeviceEntity
entity
,
Map
<
String
,
Object
>
model
,
Context
context
)
throws
AppException
{
if
(
ObjectUtils
.
isEmpty
(
entity
.
getUpdateTime
()))
{
String
token
=
getToken
();
DeviceReq
deviceReq
=
new
DeviceReq
();
deviceReq
.
setReceiveMethod
(
DeviceMethodEnum
.
ADD
.
getValue
());
deviceReq
.
setDeviceName
(
entity
.
getDeviceName
());
deviceReq
.
setDeviceCode
(
entity
.
getDeviceCode
());
deviceReq
.
setProductCode
(
entity
.
getProductCode
());
deviceReq
.
setIp
(
entity
.
getIp
());
deviceReq
.
setPort
(
entity
.
getPort
());
deviceReq
.
setSiteId
(
1L
);
deviceReq
.
setSiteCode
(
"511500000000-0001"
);
deviceReq
.
setSiteName
(
"宜宾市民中心"
);
deviceReq
.
setLeadingOfficial
(
entity
.
getLeadingOfficial
());
deviceReq
.
setLeadingOfficialTelephone
(
entity
.
getLeadingOfficialTelephone
());
deviceReq
.
setSource
(
1
);
deviceReq
.
setDeviceStatus
(
entity
.
getDeviceStatus
());
Rest
<
String
>
rest
=
deviceFeign
.
deviceCall
(
deviceReq
,
token
);
log
.
info
(
"添加结果:{}"
,
JSON
.
toJSONString
(
rest
));
}
else
{
String
token
=
getToken
();
DeviceReq
deviceReq
=
new
DeviceReq
();
deviceReq
.
setReceiveMethod
(
DeviceMethodEnum
.
UPDATE
.
getValue
());
deviceReq
.
setDeviceName
(
entity
.
getDeviceName
());
deviceReq
.
setDeviceCode
(
entity
.
getDeviceCode
());
deviceReq
.
setProductCode
(
entity
.
getProductCode
());
deviceReq
.
setIp
(
entity
.
getIp
());
deviceReq
.
setPort
(
entity
.
getPort
());
deviceReq
.
setSiteId
(
1L
);
deviceReq
.
setSiteCode
(
"511500000000-0001"
);
deviceReq
.
setSiteName
(
"宜宾市民中心"
);
deviceReq
.
setLeadingOfficial
(
entity
.
getLeadingOfficial
());
deviceReq
.
setLeadingOfficialTelephone
(
entity
.
getLeadingOfficialTelephone
());
deviceReq
.
setSource
(
1
);
deviceReq
.
setDeviceStatus
(
entity
.
getDeviceStatus
());
Rest
<
String
>
rest
=
deviceFeign
.
deviceCall
(
deviceReq
,
token
);
log
.
info
(
"更新结果:{}"
,
JSON
.
toJSONString
(
rest
));
}
return
super
.
saveAfter
(
entity
,
model
,
context
);
}
@Override
protected
void
deleteBefore
(
Long
[]
ids
,
Context
context
)
throws
AppException
{
super
.
deleteBefore
(
ids
,
context
);
String
token
=
getToken
();
DeviceQuery
deviceQuery
=
new
DeviceQuery
();
deviceQuery
.
setIdList
(
Arrays
.
asList
(
ids
));
List
<
DeviceEntity
>
deviceEntities
=
this
.
service
.
find
(
deviceQuery
,
context
);
for
(
DeviceEntity
entity
:
deviceEntities
)
{
DeviceReq
deviceReq
=
new
DeviceReq
();
deviceReq
.
setReceiveMethod
(
DeviceMethodEnum
.
DEL
.
getValue
());
deviceReq
.
setDeviceCode
(
entity
.
getDeviceCode
());
Rest
<
String
>
rest
=
deviceFeign
.
deviceCall
(
deviceReq
,
token
);
log
.
info
(
"删除结果:{}"
,
JSON
.
toJSONString
(
rest
));
}
}
private
String
getToken
()
{
LoginForm
loginForm
=
new
LoginForm
();
loginForm
.
setLoginName
(
loginName
);
loginForm
.
setPassword
(
password
);
Rest
<
String
>
rest
=
deviceFeign
.
getToken
(
loginForm
);
String
token
=
rest
.
getData
();
return
token
;
}
}
}
\ No newline at end of file
sample-form-manager/src/main/resources/sqlmap/module/device/DeviceMapper.xml
View file @
c6ba21e2
This diff is collapsed.
Click to expand it.
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