Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
ioc_sixiang_license
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zengtianlai3
ioc_sixiang_license
Commits
e93e63ce
Commit
e93e63ce
authored
Jun 14, 2022
by
zengtianlai3
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'm33' into 'master'
完善日志 See merge request
!26
parents
91d9ee19
4c09d235
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
148 additions
and
71 deletions
+148
-71
AlarmReadController.java
...a/iot/sixiang/license/controller/AlarmReadController.java
+4
-3
AlarmTypeController.java
...a/iot/sixiang/license/controller/AlarmTypeController.java
+0
-21
LoginController.java
.../java/iot/sixiang/license/controller/LoginController.java
+0
-15
SysOperLogController.java
.../iot/sixiang/license/controller/SysOperLogController.java
+57
-0
SysOperLog.java
.../src/main/java/iot/sixiang/license/entity/SysOperLog.java
+6
-8
AuthenticationInterceptor.java
...va/iot/sixiang/license/jwt/AuthenticationInterceptor.java
+1
-0
JwtFilter.java
license/src/main/java/iot/sixiang/license/jwt/JwtFilter.java
+5
-1
UserUtils.java
license/src/main/java/iot/sixiang/license/jwt/UserUtils.java
+23
-2
LogAspect.java
license/src/main/java/iot/sixiang/license/log/LogAspect.java
+8
-6
SysOperLogMapper.java
...ain/java/iot/sixiang/license/mapper/SysOperLogMapper.java
+5
-3
SysOperLogService.java
...n/java/iot/sixiang/license/service/SysOperLogService.java
+5
-3
SysOperLogServiceImpl.java
...t/sixiang/license/service/impl/SysOperLogServiceImpl.java
+29
-8
SysOperLogMapper.xml
license/src/main/resources/mapper/SysOperLogMapper.xml
+5
-1
No files found.
license/src/main/java/iot/sixiang/license/controller/AlarmReadController.java
View file @
e93e63ce
...
...
@@ -3,6 +3,7 @@ package iot.sixiang.license.controller;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
iot.sixiang.license.jwt.UserUtils
;
import
iot.sixiang.license.log.BusinessType
;
import
iot.sixiang.license.log.MyLog
;
import
iot.sixiang.license.model.BaseResult
;
...
...
@@ -22,7 +23,7 @@ import org.springframework.web.bind.annotation.RestController;
*/
@RestController
@RequestMapping
(
"/iot_license/alarm_read"
)
@Api
(
value
=
"告警
已读模块"
,
tags
=
{
"告警已读
模块"
})
@Api
(
value
=
"告警
模块"
,
tags
=
{
"告警
模块"
})
public
class
AlarmReadController
{
@Autowired
...
...
@@ -32,8 +33,8 @@ public class AlarmReadController {
@PostMapping
(
"read"
)
@MyLog
(
title
=
"将告警信息状态设为已读"
,
businessType
=
BusinessType
.
OTHER
)
public
BaseResult
readAlarm
(){
// int userId = jsonObject.getIntValue("userId"
);
int
userId
=
2147483647
;
String
id
=
UserUtils
.
getLoginUserId
(
);
int
userId
=
Integer
.
valueOf
(
id
)
;
boolean
res
=
alarmReadService
.
readAlarm
(
userId
);
if
(
res
)
{
return
BaseResult
.
success
();
...
...
license/src/main/java/iot/sixiang/license/controller/AlarmTypeController.java
deleted
100644 → 0
View file @
91d9ee19
package
iot
.
sixiang
.
license
.
controller
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* <p>
* 前端控制器
* </p>
*
* @author m33
* @since 2022-06-10
*/
@RestController
@RequestMapping
(
"/iot_license/alarm_type"
)
public
class
AlarmTypeController
{
}
license/src/main/java/iot/sixiang/license/controller/LoginController.java
View file @
e93e63ce
...
...
@@ -68,21 +68,6 @@ public class LoginController {
@ApiImplicitParam
(
name
=
"password"
,
value
=
"密码"
,
required
=
true
)
})
public
ResResult
logout
(
@RequestParam
(
"userName"
)
String
userName
,
@RequestParam
(
"password"
)
String
password
)
{
// @RequestBody JSONObject jsonObject
LoginUser
user
=
new
LoginUser
();
user
.
setUserName
(
userName
);
user
.
setPassword
(
password
);
for
(
LoginUser
dbUser
:
userMap
.
values
())
{
if
(
dbUser
.
getUserName
().
equals
(
user
.
getUserName
())
&&
dbUser
.
getPassword
().
equals
(
user
.
getPassword
()))
{
log
.
info
(
"登录成功!生成token!"
);
String
token
=
JwtUtil
.
createToken
(
dbUser
);
Map
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"authorization"
,
token
);
return
ResResult
.
success
().
record
(
map
);
}
}
return
ResResult
.
fail
().
msg
(
"用户名或密码错误"
);
}
}
license/src/main/java/iot/sixiang/license/controller/SysOperLogController.java
0 → 100644
View file @
e93e63ce
package
iot
.
sixiang
.
license
.
controller
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
iot.sixiang.license.entity.SysOperLog
;
import
iot.sixiang.license.log.BusinessType
;
import
iot.sixiang.license.log.MyLog
;
import
iot.sixiang.license.model.PageInfoModel
;
import
iot.sixiang.license.model.PageResult
;
import
iot.sixiang.license.service.SysOperLogService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.util.List
;
/**
* Created by m33 on 2022/6/14 13:54
*/
@RestController
@RequestMapping
(
"/iot_license/oper_log"
)
@Api
(
value
=
"日志模块"
,
tags
=
{
"日志模块"
})
public
class
SysOperLogController
{
@Autowired
private
SysOperLogService
sysOperLogService
;
/**
* 分页查询所有的oper_log
* @param pageNo
* @param pageSize
* @return
*/
@ApiOperation
(
value
=
"获取日志列表接口"
,
notes
=
"用于获取日志列表"
)
@GetMapping
(
"list"
)
@MyLog
(
title
=
"获取日志列表"
,
businessType
=
BusinessType
.
SELECT
)
@ApiImplicitParams
({
@ApiImplicitParam
(
name
=
"pageNo"
,
value
=
"当前在第几页"
,
required
=
true
,
dataType
=
"int"
),
@ApiImplicitParam
(
name
=
"pageSize"
,
value
=
"每页显示多少页"
,
required
=
true
,
dataType
=
"int"
)
})
public
PageResult
getOperLogList
(
@RequestParam
(
value
=
"pageNo"
,
defaultValue
=
"0"
)
int
pageNo
,
@RequestParam
(
value
=
"pageSize"
,
defaultValue
=
"0"
)
int
pageSize
)
{
PageInfoModel
<
SysOperLog
>
records
=
sysOperLogService
.
getOperLogList
(
pageNo
,
pageSize
);
int
total
=
records
.
getTotal
();
int
pages
=
total
/
pageSize
;
//pages为总页数
int
mod
=
total
%
pageSize
;
if
(
mod
!=
0
){
pages
=
pages
+
1
;
}
List
<
SysOperLog
>
result
=
records
.
getResult
();
return
new
PageResult
(
200
,
"查找成功"
,
pageNo
,
pages
,
total
,
result
);
}
}
license/src/main/java/iot/sixiang/license/entity/SysOperLog.java
View file @
e93e63ce
...
...
@@ -2,15 +2,13 @@ package iot.sixiang.license.entity;
import
com.baomidou.mybatisplus.annotation.IdType
;
import
com.baomidou.mybatisplus.annotation.TableId
;
import
java.time.LocalDateTime
;
import
java.io.Serializable
;
import
java.util.Date
;
import
lombok.Data
;
import
lombok.EqualsAndHashCode
;
import
lombok.experimental.Accessors
;
import
java.io.Serializable
;
import
java.util.Date
;
/**
* <p>
* 操作日志记录
...
...
@@ -30,7 +28,7 @@ public class SysOperLog implements Serializable {
* 日志主键
*/
@TableId
(
value
=
"id"
,
type
=
IdType
.
AUTO
)
private
Long
id
;
private
Integer
id
;
/**
* 模块标题
...
...
@@ -47,9 +45,9 @@ public class SysOperLog implements Serializable {
private
Integer
businessType
;
/**
*
方法
名称
*
路径
名称
*/
private
String
method
;
private
String
uri
;
/**
* 操作状态(0正常 1异常)
...
...
license/src/main/java/iot/sixiang/license/jwt/AuthenticationInterceptor.java
View file @
e93e63ce
...
...
@@ -24,5 +24,6 @@ public class AuthenticationInterceptor implements HandlerInterceptor {
public
void
afterCompletion
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
,
Exception
ex
)
throws
Exception
{
UserUtils
.
removeUser
();
UserUtils
.
removeUri
();
}
}
\ No newline at end of file
license/src/main/java/iot/sixiang/license/jwt/JwtFilter.java
View file @
e93e63ce
...
...
@@ -42,7 +42,11 @@ public class JwtFilter implements Filter {
String
token
=
request
.
getHeader
(
"authorization"
);
boolean
check
=
true
;
String
uri
=
request
.
getRequestURI
();
if
(
uri
.
contains
(
url1
)
||
uri
.
contains
(
url2
)
||
uri
.
contains
(
url3
)
||
uri
.
contains
(
url4
)
||
uri
.
contains
(
url7
)
||
uri
.
contains
(
url8
))
{
if
(
uri
.
contains
(
url1
)
||
uri
.
contains
(
url2
)
)
{
UserUtils
.
setUri
(
uri
);
}
check
=
false
;
}
if
(!
check
)
{
...
...
@@ -76,7 +80,7 @@ public class JwtFilter implements Filter {
LoginUser
loginUser
=
new
LoginUser
(
userId
,
userName
,
password
);
UserUtils
.
setLoginUser
(
loginUser
);
UserUtils
.
setUri
(
uri
);
filterChain
.
doFilter
(
request
,
response
);
}
}
...
...
license/src/main/java/iot/sixiang/license/jwt/UserUtils.java
View file @
e93e63ce
...
...
@@ -7,7 +7,9 @@ package iot.sixiang.license.jwt;
public
abstract
class
UserUtils
{
//线程变量,存放user实体类信息,即使是静态的与其他线程也是隔离的
private
static
ThreadLocal
<
LoginUser
>
userThreadLocal
=
new
ThreadLocal
<
LoginUser
>();
private
static
ThreadLocal
<
LoginUser
>
userThreadLocal
=
new
ThreadLocal
<>();
//线程变量,存放uri,即使是静态的与其他线程也是隔离的
private
static
ThreadLocal
<
String
>
uriThreadLocal
=
new
ThreadLocal
<>();
//从当前线程变量中获取用户信息
public
static
LoginUser
getLoginUser
()
{
...
...
@@ -34,8 +36,27 @@ public abstract class UserUtils {
userThreadLocal
.
set
(
user
);
}
//清除线程变量
//清除
userThreadLocal
线程变量
public
static
void
removeUser
()
{
userThreadLocal
.
remove
();
}
//为当前的线程变量赋值上uri信息
public
static
void
setUri
(
String
uri
)
{
uriThreadLocal
.
set
(
uri
);
}
/**
* 获取当前访问方法的uri
* @return
*/
public
static
String
getUri
()
{
String
uri
=
uriThreadLocal
.
get
();
return
uri
;
}
//清除uriThreadLocal线程变量
public
static
void
removeUri
()
{
uriThreadLocal
.
remove
();
}
}
license/src/main/java/iot/sixiang/license/log/LogAspect.java
View file @
e93e63ce
...
...
@@ -2,6 +2,8 @@ package iot.sixiang.license.log;
import
com.alibaba.fastjson.JSONObject
;
import
iot.sixiang.license.entity.SysOperLog
;
import
iot.sixiang.license.handler.IotLicenseException
;
import
iot.sixiang.license.jwt.UserUtils
;
import
iot.sixiang.license.service.SysOperLogService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
...
...
@@ -67,16 +69,16 @@ public class LogAspect {
operLog
.
setOperTime
(
new
Date
());
if
(
e
!=
null
)
{
operLog
.
setStatus
(
1
);
operLog
.
setErrorMsg
(
StringUtils
.
substring
(
e
.
getMessage
(),
0
,
2000
));
operLog
.
setErrorMsg
(
StringUtils
.
substring
(
((
IotLicenseException
)
e
).
getMsg
(),
0
,
2000
));
}
// 设置方法名称
String
className
=
joinPoint
.
getTarget
().
getClass
().
getName
();
String
methodName
=
joinPoint
.
getSignature
().
getName
(
);
operLog
.
setMethod
(
className
+
"."
+
methodName
+
"()"
);
String
uri
=
UserUtils
.
getUri
();
operLog
.
setUri
(
uri
);
//
operLog.setMethod(className + "." + methodName + "()");
// 处理设置注解上的参数
getControllerMethodDescription
(
joinPoint
,
controllerLog
,
operLog
);
// 保存数据库
sysOperLogService
.
addOperlog
(
operLog
.
getTitle
(),
operLog
.
getBusinessType
(),
operLog
.
get
Method
(),
operLog
.
getStatus
(),
operLog
.
getOptParam
(),
operLog
.
getErrorMsg
(),
operLog
.
getOperTime
());
sysOperLogService
.
addOperlog
(
operLog
.
getTitle
(),
operLog
.
getBusinessType
(),
operLog
.
get
Uri
(),
operLog
.
getStatus
(),
operLog
.
getOptParam
(),
operLog
.
getErrorMsg
(),
operLog
.
getOperTime
());
}
catch
(
Exception
exp
)
{
log
.
error
(
"==前置通知异常=="
);
log
.
error
(
"日志异常信息 {}"
,
exp
);
...
...
license/src/main/java/iot/sixiang/license/mapper/SysOperLogMapper.java
View file @
e93e63ce
package
iot
.
sixiang
.
license
.
mapper
;
import
iot.sixiang.license.entity.SysOperLog
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
iot.sixiang.license.entity.SysOperLog
;
import
java.time.LocalDateTime
;
import
java.util.Date
;
import
java.util.List
;
/**
* <p>
...
...
@@ -16,5 +16,7 @@ import java.util.Date;
*/
public
interface
SysOperLogMapper
extends
BaseMapper
<
SysOperLog
>
{
boolean
addOperlog
(
String
title
,
Integer
businessType
,
String
method
,
Integer
status
,
String
optParam
,
String
errorMsg
,
Date
operTime
);
boolean
addOperlog
(
String
title
,
Integer
businessType
,
String
uri
,
Integer
status
,
String
optParam
,
String
errorMsg
,
Date
operTime
);
List
<
SysOperLog
>
getOperLogList
();
}
license/src/main/java/iot/sixiang/license/service/SysOperLogService.java
View file @
e93e63ce
package
iot
.
sixiang
.
license
.
service
;
import
iot.sixiang.license.entity.SysOperLog
;
import
com.baomidou.mybatisplus.extension.service.IService
;
import
iot.sixiang.license.entity.SysOperLog
;
import
iot.sixiang.license.model.PageInfoModel
;
import
java.time.LocalDateTime
;
import
java.util.Date
;
/**
...
...
@@ -15,5 +15,7 @@ import java.util.Date;
* @since 2022-06-13
*/
public
interface
SysOperLogService
extends
IService
<
SysOperLog
>
{
boolean
addOperlog
(
String
title
,
Integer
businessType
,
String
method
,
Integer
status
,
String
optParam
,
String
errorMsg
,
Date
operTime
);
boolean
addOperlog
(
String
title
,
Integer
businessType
,
String
uri
,
Integer
status
,
String
optParam
,
String
errorMsg
,
Date
operTime
);
PageInfoModel
<
SysOperLog
>
getOperLogList
(
int
pageNo
,
int
pageSize
);
}
license/src/main/java/iot/sixiang/license/service/impl/SysOperLogServiceImpl.java
View file @
e93e63ce
package
iot
.
sixiang
.
license
.
service
.
impl
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
iot.sixiang.license.entity.Server
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
iot.sixiang.license.entity.SysOperLog
;
import
iot.sixiang.license.
mapper.ServerMapper
;
import
iot.sixiang.license.
handler.IotLicenseException
;
import
iot.sixiang.license.mapper.SysOperLogMapper
;
import
iot.sixiang.license.model.PageInfoModel
;
import
iot.sixiang.license.service.SysOperLogService
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
iot.sixiang.license.util.JsonUtil
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
java.time.LocalDateTime
;
import
java.util.ArrayList
;
import
java.util.Comparator
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
* <p>
...
...
@@ -30,8 +30,29 @@ public class SysOperLogServiceImpl extends ServiceImpl<SysOperLogMapper, SysOper
@Override
public
boolean
addOperlog
(
String
title
,
Integer
businessType
,
String
method
,
Integer
status
,
String
optParam
,
String
errorMsg
,
Date
operTime
)
{
return
sysOperLogMapper
.
addOperlog
(
title
,
businessType
,
method
,
status
,
optParam
,
errorMsg
,
operTime
);
public
boolean
addOperlog
(
String
title
,
Integer
businessType
,
String
uri
,
Integer
status
,
String
optParam
,
String
errorMsg
,
Date
operTime
)
{
return
sysOperLogMapper
.
addOperlog
(
title
,
businessType
,
uri
,
status
,
optParam
,
errorMsg
,
operTime
);
}
@Override
public
PageInfoModel
<
SysOperLog
>
getOperLogList
(
int
pageNo
,
int
pageSize
)
{
if
(
pageNo
==
0
)
{
throw
new
IotLicenseException
(
400
,
"pageNo不能为空"
);
}
if
(
pageSize
==
0
)
{
throw
new
IotLicenseException
(
400
,
"pageSize不能为空"
);
}
List
<
SysOperLog
>
records
=
sysOperLogMapper
.
getOperLogList
();
records
=
records
.
stream
().
sorted
(
Comparator
.
comparing
(
SysOperLog:
:
getId
)).
collect
(
Collectors
.
toList
());
List
<
SysOperLog
>
result
=
new
ArrayList
<>();
int
begin
=
(
pageNo
-
1
)
*
pageSize
;
if
(
begin
>=
0
&&
records
.
size
()
>
0
)
{
result
=
records
.
stream
().
skip
(
begin
).
limit
(
pageSize
).
collect
(
Collectors
.
toList
());
}
PageInfoModel
<
SysOperLog
>
objectPageInfoModel
=
new
PageInfoModel
<>();
objectPageInfoModel
.
setTotal
(
records
.
size
());
objectPageInfoModel
.
setResult
(
result
);
return
objectPageInfoModel
;
}
}
license/src/main/resources/mapper/SysOperLogMapper.xml
View file @
e93e63ce
...
...
@@ -2,6 +2,10 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"iot.sixiang.license.mapper.SysOperLogMapper"
>
<insert
id=
"addOperlog"
parameterType=
"iot.sixiang.license.entity.SysOperLog"
>
insert into sys_oper_log(title, business_type,
method, status, opt_param, error_msg, oper_time) values (#{title},#{businessType},#{method
},#{status},#{optParam},#{errorMsg},#{operTime})
insert into sys_oper_log(title, business_type,
uri, status, opt_param, error_msg, oper_time) values (#{title},#{businessType},#{uri
},#{status},#{optParam},#{errorMsg},#{operTime})
</insert>
<select
id=
"getOperLogList"
resultType=
"iot.sixiang.license.entity.SysOperLog"
>
select id, title, business_type, uri, status, opt_param, error_msg, oper_time from sys_oper_log
</select>
</mapper>
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