Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
guns-vip
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenjunxiong
guns-vip
Commits
823064e9
Commit
823064e9
authored
Apr 27, 2017
by
fsn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增字典的业务编写
parent
8f53b91a
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
181 additions
and
4 deletions
+181
-4
src/main/java/com/stylefeng/guns/common/constant/factory/MutiStrFactory.java
+61
-0
src/main/java/com/stylefeng/guns/common/exception/BizExceptionEnum.java
+5
-0
src/main/java/com/stylefeng/guns/modular/system/controller/DictController.java
+15
-4
src/main/java/com/stylefeng/guns/modular/system/service/IDictService.java
+18
-0
src/main/java/com/stylefeng/guns/modular/system/service/impl/DictServiceImpl.java
+58
-0
src/test/java/com/stylefeng/guns/system/DictTest.java
+24
-0
No files found.
src/main/java/com/stylefeng/guns/common/constant/factory/MutiStrFactory.java
0 → 100644
View file @
823064e9
package
com
.
stylefeng
.
guns
.
common
.
constant
.
factory
;
import
com.stylefeng.guns.core.support.StrKit
;
import
com.stylefeng.guns.core.util.ToolUtil
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* 组合字符串生产者
*
* @author fengshuonan
* @date 2017-04-27 16:42
*/
public
class
MutiStrFactory
{
/**
* 每个条目之间的分隔符
*/
public
static
final
String
ITEM_SPLIT
=
";"
;
/**
* 属性之间的分隔符
*/
public
static
final
String
ATTR_SPLIT
=
":"
;
/**
* 拼接字符串的key
*/
public
static
final
String
MUTI_STR_KEY
=
"KEY"
;
/**
* 拼接字符串的value
*/
public
static
final
String
MUTI_STR_VALUE
=
"VALUE"
;
/**
* 解析一个组合字符串(例如: "1:启用;2:禁用;3:冻结" 这样的字符串)
*
* @author fengshuonan
* @Date 2017/4/27 16:44
*/
public
static
List
<
Map
<
String
,
String
>>
parse
(
String
mutiString
){
if
(
ToolUtil
.
isEmpty
(
mutiString
)){
return
new
ArrayList
<>();
}
else
{
ArrayList
<
Map
<
String
,
String
>>
results
=
new
ArrayList
<>();
String
[]
items
=
StrKit
.
split
(
StrKit
.
removeSuffix
(
mutiString
,
ITEM_SPLIT
),
ITEM_SPLIT
);
for
(
String
item
:
items
)
{
String
[]
attrs
=
item
.
split
(
ATTR_SPLIT
);
HashMap
<
String
,
String
>
itemMap
=
new
HashMap
<>();
itemMap
.
put
(
MUTI_STR_KEY
,
attrs
[
0
]);
itemMap
.
put
(
MUTI_STR_VALUE
,
attrs
[
1
]);
results
.
add
(
itemMap
);
}
return
results
;
}
}
}
src/main/java/com/stylefeng/guns/common/exception/BizExceptionEnum.java
View file @
823064e9
...
@@ -7,6 +7,11 @@ package com.stylefeng.guns.common.exception;
...
@@ -7,6 +7,11 @@ package com.stylefeng.guns.common.exception;
*/
*/
public
enum
BizExceptionEnum
{
public
enum
BizExceptionEnum
{
/**
* 字典
*/
DICT_EXISTED
(
400
,
"字典已经存在"
),
/**
/**
* 文件上传
* 文件上传
...
...
src/main/java/com/stylefeng/guns/modular/system/controller/DictController.java
View file @
823064e9
...
@@ -6,6 +6,7 @@ import com.stylefeng.guns.common.annotion.log.BussinessLog;
...
@@ -6,6 +6,7 @@ import com.stylefeng.guns.common.annotion.log.BussinessLog;
import
com.stylefeng.guns.common.controller.BaseController
;
import
com.stylefeng.guns.common.controller.BaseController
;
import
com.stylefeng.guns.common.exception.BizExceptionEnum
;
import
com.stylefeng.guns.common.exception.BizExceptionEnum
;
import
com.stylefeng.guns.common.exception.BussinessException
;
import
com.stylefeng.guns.common.exception.BussinessException
;
import
com.stylefeng.guns.core.support.StrKit
;
import
com.stylefeng.guns.core.util.ToolUtil
;
import
com.stylefeng.guns.core.util.ToolUtil
;
import
com.stylefeng.guns.modular.system.dao.DictDao
;
import
com.stylefeng.guns.modular.system.dao.DictDao
;
import
com.stylefeng.guns.modular.system.warpper.DictWarpper
;
import
com.stylefeng.guns.modular.system.warpper.DictWarpper
;
...
@@ -18,6 +19,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
...
@@ -18,6 +19,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -69,15 +71,19 @@ public class DictController extends BaseController {
...
@@ -69,15 +71,19 @@ public class DictController extends BaseController {
/**
/**
* 新增字典
* 新增字典
* @param dictValues 格式例如 1:启用;2:禁用;3:冻结
*/
*/
@BussinessLog
(
"添加字典记录
"
)
@BussinessLog
(
value
=
"添加字典记录"
,
key
=
"dictName
"
)
@RequestMapping
(
value
=
"/add"
)
@RequestMapping
(
value
=
"/add"
)
@ResponseBody
@ResponseBody
public
Object
add
(
Dict
dict
)
{
public
Object
add
(
String
dictName
,
String
dictValues
)
{
if
(
ToolUtil
.
isOneEmpty
(
dict
,
dict
.
getName
()
))
{
if
(
ToolUtil
.
isOneEmpty
(
dict
Name
,
dictValues
))
{
throw
new
BussinessException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
BussinessException
(
BizExceptionEnum
.
REQUEST_NULL
);
}
}
return
this
.
dictMapper
.
insert
(
dict
);
return
SUCCESS_TIP
;
}
}
/**
/**
...
@@ -131,4 +137,9 @@ public class DictController extends BaseController {
...
@@ -131,4 +137,9 @@ public class DictController extends BaseController {
return
SUCCESS_TIP
;
return
SUCCESS_TIP
;
}
}
public
static
void
main
(
String
[]
args
){
String
[]
split
=
StrKit
.
split
(
"1:启用;2:禁用;3:冻结;"
,
";"
);
System
.
out
.
println
(
Arrays
.
toString
(
split
));
}
}
}
src/main/java/com/stylefeng/guns/modular/system/service/IDictService.java
0 → 100644
View file @
823064e9
package
com
.
stylefeng
.
guns
.
modular
.
system
.
service
;
/**
* 字典服务
*
* @author fengshuonan
* @date 2017-04-27 17:00
*/
public
interface
IDictService
{
/**
* 添加字典
*
* @author fengshuonan
* @Date 2017/4/27 17:01
*/
void
addDict
(
String
dictName
,
String
dictValues
);
}
src/main/java/com/stylefeng/guns/modular/system/service/impl/DictServiceImpl.java
0 → 100644
View file @
823064e9
package
com
.
stylefeng
.
guns
.
modular
.
system
.
service
.
impl
;
import
com.baomidou.mybatisplus.mapper.EntityWrapper
;
import
com.stylefeng.guns.common.constant.factory.MutiStrFactory
;
import
com.stylefeng.guns.common.exception.BizExceptionEnum
;
import
com.stylefeng.guns.common.exception.BussinessException
;
import
com.stylefeng.guns.modular.system.dao.DictDao
;
import
com.stylefeng.guns.modular.system.service.IDictService
;
import
com.stylefeng.guns.persistence.dao.DictMapper
;
import
com.stylefeng.guns.persistence.model.Dict
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.annotation.Resource
;
import
java.util.List
;
import
java.util.Map
;
@Service
@Transactional
public
class
DictServiceImpl
implements
IDictService
{
@Resource
DictDao
dictDao
;
@Resource
DictMapper
dictMapper
;
@Override
public
void
addDict
(
String
dictName
,
String
dictValues
)
{
//判断有没有该字典
List
<
Dict
>
dicts
=
dictMapper
.
selectList
(
new
EntityWrapper
<
Dict
>().
eq
(
"name"
,
dictName
).
and
().
eq
(
"pid"
,
0
));
if
(
dicts
!=
null
&&
dicts
.
size
()
>
0
){
throw
new
BussinessException
(
BizExceptionEnum
.
DICT_EXISTED
);
}
//解析dictValues
List
<
Map
<
String
,
String
>>
items
=
MutiStrFactory
.
parse
(
dictValues
);
//添加字典
Dict
dict
=
new
Dict
();
dict
.
setName
(
dictName
);
dict
.
setNum
(
0
);
dict
.
setPid
(
0
);
this
.
dictMapper
.
insert
(
dict
);
//添加字典条目
for
(
Map
<
String
,
String
>
item
:
items
)
{
String
num
=
item
.
get
(
MutiStrFactory
.
MUTI_STR_KEY
);
String
name
=
item
.
get
(
MutiStrFactory
.
MUTI_STR_VALUE
);
Dict
itemDict
=
new
Dict
();
itemDict
.
setPid
(
dict
.
getId
());
itemDict
.
setName
(
name
);
itemDict
.
setNum
(
Integer
.
valueOf
(
num
));
this
.
dictMapper
.
insert
(
itemDict
);
}
}
}
src/test/java/com/stylefeng/guns/system/DictTest.java
0 → 100644
View file @
823064e9
package
com
.
stylefeng
.
guns
.
system
;
import
com.stylefeng.guns.base.BaseTest
;
import
com.stylefeng.guns.modular.system.service.IDictService
;
import
org.junit.Test
;
import
javax.annotation.Resource
;
/**
* 字典服务测试
*
* @author fengshuonan
* @date 2017-04-27 17:05
*/
public
class
DictTest
extends
BaseTest
{
@Resource
IDictService
dictService
;
@Test
public
void
addTest
()
{
dictService
.
addDict
(
"测试"
,
"1:冻结;2:jiedong;3:接触"
);
}
}
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