Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
indicators
Overview
Overview
Details
Activity
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
zhangkb
indicators
Commits
8495a010
Commit
8495a010
authored
Jun 08, 2020
by
张祺
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加配置项管理功能
parent
25eeac76
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
684 additions
and
2 deletions
+684
-2
ConfigInfoCtrl.java
...m/keymobile/indicators/api/indicators/ConfigInfoCtrl.java
+100
-0
SecurityConfig.java
...in/java/com/keymobile/indicators/conf/SecurityConfig.java
+2
-2
Constants.java
...ain/java/com/keymobile/indicators/constant/Constants.java
+76
-0
CacheException.java
...va/com/keymobile/indicators/exception/CacheException.java
+32
-0
BaseModel.java
...java/com/keymobile/indicators/model/entity/BaseModel.java
+44
-0
ConfigInfo.java
...ava/com/keymobile/indicators/model/entity/ConfigInfo.java
+47
-0
ConfigInfoRepository.java
...cators/persistence/hyindicators/ConfigInfoRepository.java
+10
-0
ConfigInfoService.java
...a/com/keymobile/indicators/service/ConfigInfoService.java
+53
-0
RedisCacheService.java
...a/com/keymobile/indicators/service/RedisCacheService.java
+243
-0
ConfigInfoServiceImpl.java
...mobile/indicators/service/impl/ConfigInfoServiceImpl.java
+77
-0
RedisCacheServiceImpl.java
...mobile/indicators/service/impl/RedisCacheServiceImpl.java
+0
-0
No files found.
src/main/java/com/keymobile/indicators/api/indicators/ConfigInfoCtrl.java
0 → 100644
View file @
8495a010
package
com
.
keymobile
.
indicators
.
api
.
indicators
;
import
com.keymobile.indicators.constant.Constants
;
import
com.keymobile.indicators.model.entity.ConfigInfo
;
import
com.keymobile.indicators.result.Result
;
import
com.keymobile.indicators.service.ConfigInfoService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiParam
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.Date
;
@RestController
@RequestMapping
(
"/configInfo"
)
@Api
(
value
=
"配置项管理"
,
tags
=
{
"配置项管理接口"
})
public
class
ConfigInfoCtrl
{
@Autowired
private
ConfigInfoService
configInfoService
;
/**
* 添加配置项信息
* @param configInfo
* @return
*/
@PostMapping
(
"createConfigInfo"
)
@ApiOperation
(
value
=
"添加配置项信息"
,
notes
=
"添加配置项信息"
)
public
ConfigInfo
addConfigInfo
(
@RequestBody
ConfigInfo
configInfo
,
@RequestParam
(
"userId"
)
String
userId
)
{
Date
now
=
new
Date
();
configInfo
.
setUpdater
(
userId
);
configInfo
.
setCreator
(
userId
);
configInfo
.
setCreateTime
(
now
);
configInfo
.
setUpdateTime
(
now
);
configInfo
.
setDataState
(
Constants
.
DATA_STATE_A
);
return
configInfoService
.
createConfigInfo
(
configInfo
);
}
/**
* 修改配置项信息
* @param configInfo
* @return
*/
@PostMapping
(
"updateConfigInfo"
)
@ApiOperation
(
value
=
"修改配置项信息"
,
notes
=
"修改配置项信息"
)
public
ConfigInfo
updateConfigInfo
(
@RequestBody
ConfigInfo
configInfo
,
@RequestParam
(
"userId"
)
String
userId
)
{
ConfigInfo
tmp
=
configInfoService
.
getConfigInfoById
(
configInfo
.
getId
());
tmp
.
setCfDesc
(
configInfo
.
getCfDesc
());
tmp
.
setCfValue
(
configInfo
.
getCfValue
());
tmp
.
setModule
(
configInfo
.
getModule
());
Date
now
=
new
Date
();
tmp
.
setUpdater
(
userId
);
tmp
.
setUpdateTime
(
now
);
return
configInfoService
.
updateInfo
(
tmp
);
}
/**
* 查询配置项信息
* @param page
* @param size
* @param keyword
* @return
*/
@PostMapping
(
"queryConfigInfo"
)
@ApiOperation
(
value
=
"查询配置项信息"
,
notes
=
"查询配置项信息"
)
public
Page
<
ConfigInfo
>
queryConfigInfo
(
@ApiParam
(
example
=
"1"
,
value
=
"页数,从1开始"
)
@RequestParam
(
"page"
)
int
page
,
@ApiParam
(
example
=
"10"
)
@RequestParam
(
"size"
)
int
size
,
@RequestParam
(
value
=
"keyword"
,
required
=
false
)
String
keyword
)
{
PageRequest
pageRequest
=
PageRequest
.
of
(
page
-
1
,
size
,
Sort
.
by
(
Sort
.
Order
.
desc
(
"update_time"
)));
return
configInfoService
.
queryPageInfo
(
pageRequest
,
keyword
);
}
/**
* 查询单个查询配置项信息
* @param id
* @return
*/
@PostMapping
(
"getConfigInfoById"
)
@ApiOperation
(
value
=
"查询单个配置项信息"
,
notes
=
"查询单个配置项信息"
)
public
ConfigInfo
getConfigInfoById
(
@RequestParam
(
"id"
)
String
id
)
{
return
configInfoService
.
getConfigInfoById
(
id
);
}
/**
* 刷新配置项缓存
* @return
* @throws Exception
*/
@ApiOperation
(
value
=
"刷新配置项缓存"
)
@PostMapping
(
"refreshConfigCache"
)
public
Result
refreshConfigCache
()
{
configInfoService
.
refreshCache
();
return
Result
.
genOkResult
();
}
}
src/main/java/com/keymobile/indicators/conf/SecurityConfig.java
View file @
8495a010
...
...
@@ -42,8 +42,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
@Override
public
void
configure
(
AuthenticationManagerBuilder
auth
)
throws
Exception
{
auth
.
jdbcAuthentication
().
usersByUsernameQuery
(
USERSQUERY
).
authoritiesByUsernameQuery
(
ROLESQUERY
)
.
dataSource
(
dataSource
).
passwordEncoder
(
new
SHA1PasswordEncoder
());
//
auth.jdbcAuthentication().usersByUsernameQuery(USERSQUERY).authoritiesByUsernameQuery(ROLESQUERY)
//
.dataSource(dataSource).passwordEncoder(new SHA1PasswordEncoder());
}
@Override
...
...
src/main/java/com/keymobile/indicators/constant/Constants.java
0 → 100644
View file @
8495a010
package
com
.
keymobile
.
indicators
.
constant
;
/**
* 数据标准常量定义
*/
public
class
Constants
{
/** collection Name */
/** collection Name */
/**
* 英文分隔符;
*/
public
static
final
String
SEP_NOUN
=
";"
;
/**
* 英文分隔符.
*/
public
static
final
String
SEP_DOT
=
"."
;
/**
* 分隔符/
*/
public
static
final
String
SEP
=
"/"
;
/**
* N
*/
public
static
final
String
N
=
"N"
;
/**
* Y
*/
public
static
final
String
Y
=
"Y"
;
/**
* 申请状态-草稿
*/
public
static
final
int
APPLY_STATE_DRAFT
=
1
;
/**
* 申请状态-审核中
*/
public
static
final
int
APPLY_STATE_AUDITING
=
2
;
/**
* 申请状态-已通过
*/
public
static
final
int
APPLY_STATE_PASSED
=
3
;
/**
* 申请状态-已拒绝
*/
public
static
final
int
APPLY_STATE_REJECTED
=
4
;
/**
* 申请状态-部分通过
*/
public
static
final
int
APPLY_STATE_PART_PASSED
=
5
;
/**
* 正常
*/
public
static
final
int
DATA_STATE_A
=
1
;
/**
* 停用、废止
*/
public
static
final
int
DATA_STATE_S
=
2
;
/**
* 删除
*/
public
static
final
int
DATA_STATE_X
=
3
;
}
src/main/java/com/keymobile/indicators/exception/CacheException.java
0 → 100644
View file @
8495a010
package
com
.
keymobile
.
indicators
.
exception
;
/**
* CacheException
*/
public
class
CacheException
extends
RuntimeException
{
/**
* 序列化
*/
private
static
final
long
serialVersionUID
=
3168507428069884251L
;
public
CacheException
()
{
super
();
}
public
CacheException
(
String
message
)
{
super
(
message
);
}
public
CacheException
(
String
message
,
Throwable
cause
)
{
super
(
message
,
cause
);
}
public
CacheException
(
Throwable
cause
)
{
super
(
cause
);
}
public
CacheException
(
Exception
ex
,
String
message
)
{
super
(
message
,
ex
);
}
}
src/main/java/com/keymobile/indicators/model/entity/BaseModel.java
0 → 100644
View file @
8495a010
package
com
.
keymobile
.
indicators
.
model
.
entity
;
import
lombok.Data
;
import
org.springframework.data.mongodb.core.mapping.Field
;
import
java.util.Date
;
/**
* 基础对象
* @author Jamky
*/
@Data
public
abstract
class
BaseModel
{
/**
* 数据状态
*/
@Field
(
"data_state"
)
private
Integer
dataState
;
/**
* 创建者
*/
private
String
creator
;
/**
* 更新人
*/
private
String
updater
;
/**
* 创建时间
*/
@Field
(
"update_time"
)
private
Date
updateTime
;
/**
* 创建时间
*/
@Field
(
"create_time"
)
private
Date
createTime
;
}
src/main/java/com/keymobile/indicators/model/entity/ConfigInfo.java
0 → 100644
View file @
8495a010
package
com
.
keymobile
.
indicators
.
model
.
entity
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.mongodb.core.mapping.Document
;
import
org.springframework.data.mongodb.core.mapping.Field
;
import
java.io.Serializable
;
/**
* 配置项对象
*/
@Data
@Document
(
collection
=
"config_info"
)
public
class
ConfigInfo
extends
BaseModel
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
-
1342692388985985805L
;
/**
* 配置项ID
*/
@Id
@ApiModelProperty
(
value
=
"配置项key,不能重复"
,
required
=
true
)
private
String
id
;
/**
* 配置项的值
*/
@ApiModelProperty
(
value
=
"配置项的值"
,
required
=
true
)
@Field
(
"cf_value"
)
private
String
cfValue
;
/**
* 配置项描述
*/
@ApiModelProperty
(
value
=
"配置项描述"
)
@Field
(
"cf_desc"
)
private
String
cfDesc
;
/**
* 配置项所属模块
*/
@ApiModelProperty
(
value
=
"配置项所属模块"
)
@Field
(
"module"
)
private
String
module
;
}
src/main/java/com/keymobile/indicators/persistence/hyindicators/ConfigInfoRepository.java
0 → 100644
View file @
8495a010
package
com
.
keymobile
.
indicators
.
persistence
.
hyindicators
;
import
com.keymobile.indicators.model.entity.ConfigInfo
;
import
org.springframework.data.mongodb.repository.MongoRepository
;
/**
* 配置项数据层接口
*/
public
interface
ConfigInfoRepository
extends
MongoRepository
<
ConfigInfo
,
String
>
{
}
src/main/java/com/keymobile/indicators/service/ConfigInfoService.java
0 → 100644
View file @
8495a010
package
com
.
keymobile
.
indicators
.
service
;
import
com.keymobile.indicators.model.entity.ConfigInfo
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
/**
* 配置项管理服务接口
*/
public
interface
ConfigInfoService
{
/**
* 根据id获取配置项
* @param id
* @return
*/
ConfigInfo
getConfigInfoById
(
String
id
);
/**
* 创建配置项信息
* @param config 要保存的Model
*/
ConfigInfo
createConfigInfo
(
ConfigInfo
config
);
/**
* 修改配置项信息
* @param config 要修改的Model
* @throws Exception
*/
ConfigInfo
updateInfo
(
ConfigInfo
config
);
/**
* 根据id获取配置项
* @param id
* @return
*/
void
deleteConfigById
(
String
id
);
/**
* 分页查询
* @param page 请求参数
* @param keyword
* @return 返回之后的Model
*/
Page
<
ConfigInfo
>
queryPageInfo
(
Pageable
page
,
String
keyword
);
/**
* 刷新缓存
*/
void
refreshCache
();
}
src/main/java/com/keymobile/indicators/service/RedisCacheService.java
0 → 100644
View file @
8495a010
package
com
.
keymobile
.
indicators
.
service
;
import
com.keymobile.indicators.exception.CacheException
;
import
java.util.Collection
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.concurrent.TimeUnit
;
/**
* Redis相关服务操作
*/
public
interface
RedisCacheService
{
/**
* 设置值
*
* @param key
* 键
* @param value
* 值
* @param seconds
* 到期时间秒数
*/
public
void
set
(
String
key
,
Object
value
,
int
seconds
);
/**
* 设置值
*
* @param key
* 键
* @param value
* 值
*/
public
void
set
(
String
key
,
Object
value
);
/**
* 设置到期值
*
* @param key
* 键
* @param seconds
* 到期时间秒数
*/
public
void
expire
(
String
key
,
int
seconds
);
/**
* 获取值
*
* @param key
* 键
* @return
*/
public
Object
get
(
String
key
);
/**
* 批量获取值
*
* @param keys
* @return
*/
public
Map
<
String
,
Object
>
getBulk
(
List
<
String
>
keys
);
/**
* 检测值是否存在
*
* @param key
* 键
* @return
*/
public
boolean
exists
(
String
key
);
/**
* 删除值
*
* @param key
* 键
*/
public
void
delete
(
String
key
);
/**
* 计数器
*
* @throws CacheException
*/
public
Long
incrBy
(
String
key
,
long
val
);
/**
* 计数器
*
* @throws CacheException
*/
public
Long
incr
(
String
key
);
/**
* 设置对象过期时间
*
* @param key 缓存key
* @param interval 过期时间
* @param unit 时间单位
* @throws CacheException
*/
public
void
expire
(
String
key
,
int
interval
,
TimeUnit
unit
);
/**
* 添加对象到缓存
*
* @param key 缓存key
* @param value 缓存对象
* @param minutes 过期时间
* @throws CacheException
*/
public
void
add
(
String
key
,
Object
value
,
int
minutes
)
throws
CacheException
;
/**
* 添加对象到缓存
*
* @param key 缓存key
* @param value 缓存对象
* @throws CacheException
*/
public
void
add
(
String
key
,
Object
value
)
throws
CacheException
;
/**
* 添加集合到缓存
*
* @param key 缓存key
* @param values 缓存对象
* @throws CacheException
*/
public
void
addList
(
String
key
,
Collection
<
Object
>
values
)
throws
CacheException
;
/**
* 添加集合到缓存
*
* @param key 缓存key
* @param values 缓存对象
* @param minutes 过期时间
* @throws CacheException
*/
public
void
addList
(
String
key
,
Collection
<
Object
>
values
,
int
minutes
)
throws
CacheException
;
/**
* 添加对象到缓存集合中
*
* @param key 缓存key
* @param value 缓存对象
* @throws CacheException
*/
public
void
addOneToList
(
String
key
,
Object
value
)
throws
CacheException
;
/**
* 获取缓存列表
*
* @param key 缓存key
* @return
* @throws CacheException
*/
public
List
<
Object
>
getList
(
String
key
)
throws
CacheException
;
/**
* 获取列表
*
* @param key
* @return
* @throws CacheException
*/
public
Object
getListFirstOne
(
String
key
)
throws
CacheException
;
/**
* 获得缓存数量
*
* @param keyPrefix key前缀
* @return
* @throws CacheException
*/
public
long
getCountLike
(
String
keyPrefix
)
throws
CacheException
;
/**
* 删除缓存
*
* @param key 缓存key
* @throws CacheException
*/
public
void
remove
(
String
key
)
throws
CacheException
;
/**
* 模糊删除缓存
*
* @param keyPrefix 缓存前缀
* @throws CacheException
*/
public
void
removeLike
(
String
keyPrefix
)
throws
CacheException
;
/**
* 获取列表元素个数
*
* @param key
* @return
* @throws CacheException
*/
public
Long
getListSize
(
String
key
)
throws
CacheException
;
/**
* 从缓存列表中获取指定个数的元素(从左到右),并将这些元素从缓存列表中移除
*
* @param key 缓存key
* @param offset 偏移
* @return
* @throws CacheException
*/
public
List
<
Object
>
popList
(
String
key
,
int
offset
)
throws
CacheException
;
/**
* 同时将多个 field-value (域-值)对设置到哈希表 key 中。
*
* @param key
* @param value
* @throws CacheException
*/
@SuppressWarnings
(
"rawtypes"
)
public
void
hmset
(
String
key
,
Map
value
)
throws
CacheException
;
/**
* @param key
* @param value
* @throws CacheException
*/
public
boolean
hasKey
(
String
key
,
String
value
)
throws
CacheException
;
/**
* @param key
* @param value
* @throws CacheException
*/
public
List
<
Object
>
hget
(
String
key
,
List
<
Object
>
value
)
throws
CacheException
;
public
Set
<
Object
>
hgetAllKeys
(
String
key
);
Boolean
lock
(
String
key
,
Object
value
,
int
minutes
)
throws
CacheException
;
public
long
getExpire
(
String
key
);
}
src/main/java/com/keymobile/indicators/service/impl/ConfigInfoServiceImpl.java
0 → 100644
View file @
8495a010
package
com
.
keymobile
.
indicators
.
service
.
impl
;
import
com.keymobile.indicators.model.entity.ConfigInfo
;
import
com.keymobile.indicators.persistence.hyindicators.ConfigInfoRepository
;
import
com.keymobile.indicators.service.ConfigInfoService
;
import
com.keymobile.indicators.service.RedisCacheService
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Example
;
import
org.springframework.data.domain.ExampleMatcher
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.stereotype.Component
;
import
java.util.Optional
;
@Component
public
class
ConfigInfoServiceImpl
implements
ConfigInfoService
{
private
static
final
String
CACHE_CONFIG_KEY_PRE
=
"cfg"
;
@Autowired
private
ConfigInfoRepository
configInfoRepository
;
@Autowired
private
RedisCacheService
redisCacheService
;
@Override
public
ConfigInfo
getConfigInfoById
(
String
id
)
{
ConfigInfo
info
=
(
ConfigInfo
)
redisCacheService
.
get
(
CACHE_CONFIG_KEY_PRE
+
id
);
if
(
info
==
null
)
{
Optional
<
ConfigInfo
>
opt
=
configInfoRepository
.
findById
(
id
);
if
(
opt
.
isPresent
())
{
info
=
opt
.
get
();
redisCacheService
.
add
(
CACHE_CONFIG_KEY_PRE
+
id
,
info
);
}
}
return
info
;
}
@Override
public
ConfigInfo
createConfigInfo
(
ConfigInfo
config
)
{
return
configInfoRepository
.
insert
(
config
);
}
@Override
public
ConfigInfo
updateInfo
(
ConfigInfo
config
)
{
config
=
configInfoRepository
.
save
(
config
);
this
.
refreshCache
();
return
config
;
}
@Override
public
void
deleteConfigById
(
String
id
)
{
configInfoRepository
.
deleteById
(
id
);
this
.
refreshCache
();
}
@Override
public
Page
<
ConfigInfo
>
queryPageInfo
(
Pageable
page
,
String
keyword
)
{
if
(
StringUtils
.
isNotBlank
(
keyword
))
{
ExampleMatcher
exampleMatcher
=
ExampleMatcher
.
matching
()
.
withMatcher
(
"_id"
,
ExampleMatcher
.
GenericPropertyMatchers
.
contains
())
.
withMatcher
(
"cf_desc"
,
ExampleMatcher
.
GenericPropertyMatchers
.
contains
())
.
withMatcher
(
"cf_value"
,
ExampleMatcher
.
GenericPropertyMatchers
.
contains
());
ConfigInfo
config
=
new
ConfigInfo
();
return
configInfoRepository
.
findAll
(
Example
.
of
(
config
,
exampleMatcher
),
page
);
}
else
{
return
configInfoRepository
.
findAll
(
page
);
}
}
@Override
public
void
refreshCache
()
{
redisCacheService
.
removeLike
(
CACHE_CONFIG_KEY_PRE
);
}
}
src/main/java/com/keymobile/indicators/service/impl/RedisCacheServiceImpl.java
0 → 100644
View file @
8495a010
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