Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
李苗
/
Vion-DevOps
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 16c47491
authored
Sep 10, 2024
by
HlQ
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[add] 字典管理相关接口更新
1 parent
737cb2cc
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
96 additions
and
15 deletions
src/main/java/vion/controller/DictionaryController.java
src/main/java/vion/dto/DictionaryDTO.java
src/main/java/vion/model/Dictionary.java
src/main/java/vion/service/IDictionaryService.java
src/main/java/vion/service/IDictionaryTypeService.java
src/main/java/vion/service/impl/DictionaryServiceImpl.java
src/main/java/vion/service/impl/DictionaryTypeServiceImpl.java
src/main/java/vion/controller/DictionaryController.java
View file @
16c4749
...
...
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import
io.github.linpeilie.Converter
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.dromara.hutool.core.lang.Assert
;
import
org.springframework.web.bind.annotation.*
;
import
vion.dto.DictionaryDTO
;
import
vion.dto.DictionaryTypeDTO
;
...
...
@@ -23,56 +24,83 @@ public class DictionaryController {
private
final
IDictionaryTypeService
dictionaryTypeService
;
private
final
Converter
converter
;
@GetMapping
(
"/dictionary
s
"
)
@GetMapping
(
"/dictionary"
)
@SaCheckPermission
(
value
=
"dict:list"
,
orRole
=
"admin"
)
public
Page
<
Dictionary
>
getDictionaryList
(
DictionaryDTO
data
)
{
return
dictionaryService
.
lambdaQuery
(
converter
.
convert
(
data
,
Dictionary
.
class
))
.
page
(
Page
.
of
(
data
.
getPageNum
(),
data
.
getPageSize
()));
}
@GetMapping
(
"/dictionary"
)
@GetMapping
(
"/dictionary
/{id}
"
)
@SaCheckPermission
(
value
=
"dict:query"
,
orRole
=
"admin"
)
public
Object
getDictionaryById
(
Long
id
)
{
public
Dictionary
getDictionaryById
(
@PathVariable
Long
id
)
{
return
dictionaryService
.
getById
(
id
);
}
@PostMapping
(
"/dictionary"
)
@SaCheckPermission
(
value
=
"dict:editAndSave"
,
orRole
=
"admin"
)
public
String
saveOrUpdateDictionary
(
@RequestBody
DictionaryDTO
data
)
{
Dictionary
dictionary
=
converter
.
convert
(
data
,
Dictionary
.
class
);
return
dictionaryService
.
saveOrUpdate
(
dictionary
)
?
"成功"
:
"失败"
;
@SaCheckPermission
(
value
=
"dict:save"
,
orRole
=
"admin"
)
public
String
save
(
@RequestBody
DictionaryDTO
data
)
{
return
dictionaryService
.
save
(
data
);
}
@PostMapping
(
"/dictionary/{id}"
)
@SaCheckPermission
(
value
=
"dict:edit"
,
orRole
=
"admin"
)
public
String
update
(
@PathVariable
Long
id
,
@RequestBody
DictionaryDTO
data
)
{
data
.
setId
(
id
);
return
dictionaryService
.
update
(
data
);
}
@DeleteMapping
(
"/dictionary/{id}"
)
@SaCheckPermission
(
value
=
"dict:remove"
,
orRole
=
"admin"
)
public
String
remove
(
@PathVariable
Long
id
,
@RequestBody
DictionaryDTO
data
)
{
Assert
.
notNull
(
data
.
getType
(),
"字典项 type 不能为空"
);
Assert
.
notNull
(
data
.
getKey
(),
"字典项 key 不能为空"
);
data
.
setId
(
id
);
return
dictionaryService
.
remove
(
id
,
data
);
}
@GetMapping
(
"/dictionaryType
s
"
)
@GetMapping
(
"/dictionaryType"
)
@SaCheckPermission
(
value
=
"dict:type:list"
,
orRole
=
"admin"
)
public
Page
<
DictionaryType
>
getDictionaryTypeList
(
DictionaryTypeDTO
data
)
{
return
dictionaryTypeService
.
lambdaQuery
(
converter
.
convert
(
data
,
DictionaryType
.
class
))
.
page
(
Page
.
of
(
data
.
getPageNum
(),
data
.
getPageSize
()));
}
@GetMapping
(
"/dictionaryType"
)
@GetMapping
(
"/dictionaryType
/{id}
"
)
@SaCheckPermission
(
value
=
"dict:type:query"
,
orRole
=
"admin"
)
public
Object
getDictionaryTypeById
(
@RequestParam
Integer
id
)
{
public
DictionaryType
getDictionaryTypeById
(
@PathVariable
Long
id
)
{
return
dictionaryTypeService
.
getById
(
id
);
}
@PostMapping
(
"/dictionaryType"
)
@SaCheckPermission
(
value
=
"dict:type:editAndSave"
,
orRole
=
"admin"
)
public
String
saveOrUpdateDictionaryType
(
@RequestBody
DictionaryTypeDTO
data
)
{
@SaCheckPermission
(
value
=
"dict:type:save"
,
orRole
=
"admin"
)
public
String
saveDictionaryType
(
@RequestBody
DictionaryTypeDTO
data
)
{
DictionaryType
dictionaryType
=
converter
.
convert
(
data
,
DictionaryType
.
class
);
return
dictionaryTypeService
.
save
(
dictionaryType
)
?
"成功"
:
"失败"
;
}
@PostMapping
(
"/dictionaryType/{id}"
)
@SaCheckPermission
(
value
=
"dict:type:edit"
,
orRole
=
"admin"
)
public
String
updateDictionaryType
(
@PathVariable
Long
id
,
@RequestBody
DictionaryTypeDTO
data
)
{
data
.
setId
(
id
);
DictionaryType
dictionaryType
=
converter
.
convert
(
data
,
DictionaryType
.
class
);
return
dictionaryTypeService
.
saveOrUpdate
(
dictionaryType
)
?
"成功"
:
"失败"
;
return
dictionaryTypeService
.
updateById
(
dictionaryType
)
?
"成功"
:
"失败"
;
}
@DeleteMapping
(
"/dictionaryType/{id}"
)
@SaCheckPermission
(
value
=
"dict:type:remove"
,
orRole
=
"admin"
)
public
String
removeDictionaryType
(
@PathVariable
Long
id
,
@RequestBody
DictionaryTypeDTO
data
)
{
Assert
.
notNull
(
data
.
getType
(),
"字典 type 不能为空"
);
return
dictionaryTypeService
.
remove
(
id
,
data
);
}
/**
* 同步字典到 Redis
* 目前字典接口未使用,添加字典和字典项是直接在数据库中添加的,所以需要手动同步到 Redis
*
* @return java.lang.String
*/
@GetMapping
(
"/dict/sync"
)
@SaCheckPermission
(
value
=
"dict:sync"
,
orRole
=
"admin"
)
// todo 未加权限
public
String
syncDict
()
{
dictionaryService
.
syncDict
();
return
"同步成功"
;
...
...
src/main/java/vion/dto/DictionaryDTO.java
View file @
16c4749
...
...
@@ -9,6 +9,7 @@ public class DictionaryDTO extends BaseDTO {
private
Long
id
;
private
String
type
;
private
Long
typeId
;
private
Integer
key
;
private
String
value
;
private
String
remark
;
...
...
src/main/java/vion/model/Dictionary.java
View file @
16c4749
...
...
@@ -21,6 +21,7 @@ public class Dictionary {
@TableId
(
value
=
"id"
,
type
=
IdType
.
AUTO
)
private
Long
id
;
private
String
type
;
private
Long
typeId
;
private
Integer
key
;
private
String
value
;
private
String
remark
;
...
...
src/main/java/vion/service/IDictionaryService.java
View file @
16c4749
package
vion
.
service
;
import
com.github.yulichang.base.MPJBaseService
;
import
vion.dto.DictionaryDTO
;
import
vion.model.Dictionary
;
public
interface
IDictionaryService
extends
MPJBaseService
<
Dictionary
>
{
String
save
(
DictionaryDTO
data
);
String
update
(
DictionaryDTO
data
);
String
remove
(
Long
id
,
DictionaryDTO
data
);
void
syncDict
();
}
src/main/java/vion/service/IDictionaryTypeService.java
View file @
16c4749
package
vion
.
service
;
import
com.github.yulichang.base.MPJBaseService
;
import
vion.dto.DictionaryTypeDTO
;
import
vion.model.DictionaryType
;
public
interface
IDictionaryTypeService
extends
MPJBaseService
<
DictionaryType
>
{
String
remove
(
Long
id
,
DictionaryTypeDTO
data
);
}
src/main/java/vion/service/impl/DictionaryServiceImpl.java
View file @
16c4749
package
vion
.
service
.
impl
;
import
com.github.yulichang.base.MPJBaseServiceImpl
;
import
io.github.linpeilie.Converter
;
import
lombok.RequiredArgsConstructor
;
import
org.dromara.hutool.core.lang.Opt
;
import
org.redisson.api.RedissonClient
;
import
org.springframework.stereotype.Service
;
import
vion.constant.RedisKeyEnum
;
import
vion.dto.DictionaryDTO
;
import
vion.mapper.DictionaryMapper
;
import
vion.model.Dictionary
;
import
vion.service.IDictionaryService
;
...
...
@@ -17,6 +19,30 @@ import java.util.stream.Collectors;
public
class
DictionaryServiceImpl
extends
MPJBaseServiceImpl
<
DictionaryMapper
,
Dictionary
>
implements
IDictionaryService
{
private
final
RedissonClient
redissonClient
;
private
final
Converter
converter
;
@Override
public
String
save
(
DictionaryDTO
data
)
{
Dictionary
dictionary
=
converter
.
convert
(
data
,
Dictionary
.
class
);
redissonClient
.
getMap
(
RedisKeyEnum
.
DICT_PREFIX
.
getVal
()
+
RedisKeyEnum
.
getValByKey
(
dictionary
.
getType
()))
.
put
(
dictionary
.
getKey
(),
dictionary
.
getValue
());
return
this
.
save
(
dictionary
)
?
"成功"
:
"失败"
;
}
@Override
public
String
update
(
DictionaryDTO
data
)
{
Dictionary
dictionary
=
converter
.
convert
(
data
,
Dictionary
.
class
);
redissonClient
.
getMap
(
RedisKeyEnum
.
DICT_PREFIX
.
getVal
()
+
RedisKeyEnum
.
getValByKey
(
dictionary
.
getType
()))
.
put
(
dictionary
.
getKey
(),
dictionary
.
getValue
());
return
this
.
updateById
(
dictionary
)
?
"成功"
:
"失败"
;
}
@Override
public
String
remove
(
Long
id
,
DictionaryDTO
data
)
{
redissonClient
.
getMap
(
RedisKeyEnum
.
DICT_PREFIX
.
getVal
()
+
RedisKeyEnum
.
getValByKey
(
data
.
getType
()))
.
remove
(
data
.
getKey
());
return
this
.
removeById
(
id
)
?
"成功"
:
"失败"
;
}
@Override
public
void
syncDict
()
{
...
...
src/main/java/vion/service/impl/DictionaryTypeServiceImpl.java
View file @
16c4749
package
vion
.
service
.
impl
;
import
com.github.yulichang.base.MPJBaseServiceImpl
;
import
lombok.RequiredArgsConstructor
;
import
org.redisson.api.RedissonClient
;
import
org.springframework.stereotype.Service
;
import
vion.constant.RedisKeyEnum
;
import
vion.dto.DictionaryTypeDTO
;
import
vion.mapper.DictionaryTypeMapper
;
import
vion.model.DictionaryType
;
import
vion.service.IDictionaryTypeService
;
@Service
@RequiredArgsConstructor
public
class
DictionaryTypeServiceImpl
extends
MPJBaseServiceImpl
<
DictionaryTypeMapper
,
DictionaryType
>
implements
IDictionaryTypeService
{
private
final
RedissonClient
redissonClient
;
@Override
public
String
remove
(
Long
id
,
DictionaryTypeDTO
data
)
{
redissonClient
.
getMap
(
RedisKeyEnum
.
DICT_PREFIX
.
getVal
()
+
RedisKeyEnum
.
getValByKey
(
data
.
getType
())).
delete
();
return
this
.
removeById
(
id
)
?
"成功"
:
"失败"
;
}
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment