提交 | 用户 | 时间
|
1ac2bc
|
1 |
package cn.stylefeng.guns.sys.modular.consts.service.impl; |
懒 |
2 |
|
|
3 |
import cn.stylefeng.guns.base.consts.ConstantsContext; |
|
4 |
import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory; |
|
5 |
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo; |
|
6 |
import cn.stylefeng.guns.sys.core.exception.enums.BizExceptionEnum; |
|
7 |
import cn.stylefeng.guns.sys.modular.consts.entity.SysConfig; |
|
8 |
import cn.stylefeng.guns.sys.modular.consts.mapper.SysConfigMapper; |
|
9 |
import cn.stylefeng.guns.sys.modular.consts.model.params.SysConfigParam; |
|
10 |
import cn.stylefeng.guns.sys.modular.consts.model.result.SysConfigResult; |
|
11 |
import cn.stylefeng.guns.sys.modular.consts.service.SysConfigService; |
|
12 |
import cn.stylefeng.roses.core.util.ToolUtil; |
|
13 |
import cn.stylefeng.roses.kernel.model.exception.ServiceException; |
|
14 |
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
15 |
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
16 |
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
17 |
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
18 |
import org.springframework.stereotype.Service; |
|
19 |
import org.springframework.transaction.annotation.Transactional; |
|
20 |
|
|
21 |
import java.io.Serializable; |
|
22 |
import java.util.List; |
|
23 |
|
|
24 |
import static cn.stylefeng.guns.base.consts.ConfigConstant.SYSTEM_CONSTANT_PREFIX; |
|
25 |
import static cn.stylefeng.guns.sys.core.exception.enums.BizExceptionEnum.ALREADY_CONSTANTS_ERROR; |
|
26 |
|
|
27 |
/** |
|
28 |
* <p> |
|
29 |
* 参数配置 服务实现类 |
|
30 |
* </p> |
|
31 |
* |
|
32 |
* @author stylefeng |
|
33 |
* @since 2019-06-20 |
|
34 |
*/ |
|
35 |
@Service |
|
36 |
public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig> implements SysConfigService { |
|
37 |
|
|
38 |
@Override |
|
39 |
@Transactional(rollbackFor = Exception.class) |
|
40 |
public void add(SysConfigParam param) { |
|
41 |
SysConfig entity = getEntity(param); |
|
42 |
|
|
43 |
//判断编码有没有重复 |
|
44 |
SysConfig sysConfig = new SysConfig(); |
|
45 |
sysConfig.setCode(entity.getCode()); |
|
46 |
List<SysConfig> list = this.list(new QueryWrapper<>(sysConfig)); |
|
47 |
if (list != null && list.size() > 0) { |
|
48 |
throw new ServiceException(ALREADY_CONSTANTS_ERROR); |
|
49 |
} |
|
50 |
|
|
51 |
//如果是字典类型 |
|
52 |
if (ToolUtil.isNotEmpty(param.getDictFlag()) |
|
53 |
&& param.getDictFlag().equalsIgnoreCase("Y")) { |
|
54 |
entity.setValue(param.getDictValue()); |
|
55 |
} |
|
56 |
|
|
57 |
this.save(entity); |
|
58 |
|
|
59 |
//添加字典context |
|
60 |
ConstantsContext.putConstant(entity.getCode(), entity.getValue()); |
|
61 |
} |
|
62 |
|
|
63 |
@Override |
|
64 |
@Transactional(rollbackFor = Exception.class) |
|
65 |
public void delete(SysConfigParam param) { |
|
66 |
|
|
67 |
//不能删除系统常量 |
|
68 |
SysConfig sysConfig = this.getById(param.getId()); |
|
69 |
if (sysConfig != null && sysConfig.getCode().startsWith(SYSTEM_CONSTANT_PREFIX)) { |
|
70 |
throw new ServiceException(BizExceptionEnum.SYSTEM_CONSTANT_ERROR); |
|
71 |
} |
|
72 |
|
|
73 |
this.removeById(getKey(param)); |
|
74 |
|
|
75 |
//删除字典context |
|
76 |
ConstantsContext.deleteConstant(sysConfig.getCode()); |
|
77 |
} |
|
78 |
|
|
79 |
@Override |
|
80 |
@Transactional(rollbackFor = Exception.class) |
|
81 |
public void update(SysConfigParam param) { |
|
82 |
SysConfig oldEntity = getOldEntity(param); |
|
83 |
SysConfig newEntity = getEntity(param); |
|
84 |
ToolUtil.copyProperties(newEntity, oldEntity); |
|
85 |
|
|
86 |
//如果是字典类型 |
|
87 |
if (ToolUtil.isNotEmpty(param.getDictFlag()) |
|
88 |
&& param.getDictFlag().equalsIgnoreCase("Y")) { |
|
89 |
newEntity.setValue(param.getDictValue()); |
|
90 |
} else { |
|
91 |
|
|
92 |
//如果是非字典,则标识位置为空 |
|
93 |
newEntity.setDictFlag("N"); |
|
94 |
} |
|
95 |
|
|
96 |
this.updateById(newEntity); |
|
97 |
|
|
98 |
//添加字典context |
|
99 |
ConstantsContext.putConstant(newEntity.getCode(), newEntity.getValue()); |
|
100 |
} |
|
101 |
|
|
102 |
@Override |
|
103 |
public SysConfigResult findBySpec(SysConfigParam param) { |
|
104 |
return null; |
|
105 |
} |
|
106 |
|
|
107 |
@Override |
|
108 |
public List<SysConfigResult> findListBySpec(SysConfigParam param) { |
|
109 |
return null; |
|
110 |
} |
|
111 |
|
|
112 |
@Override |
|
113 |
public LayuiPageInfo findPageBySpec(SysConfigParam param) { |
|
114 |
Page pageContext = getPageContext(); |
|
115 |
IPage page = this.baseMapper.customPageList(pageContext, param); |
|
116 |
return LayuiPageFactory.createPageInfo(page); |
|
117 |
} |
|
118 |
|
|
119 |
private Serializable getKey(SysConfigParam param) { |
|
120 |
return param.getId(); |
|
121 |
} |
|
122 |
|
|
123 |
private Page getPageContext() { |
|
124 |
return LayuiPageFactory.defaultPage(); |
|
125 |
} |
|
126 |
|
|
127 |
private SysConfig getOldEntity(SysConfigParam param) { |
|
128 |
return this.getById(getKey(param)); |
|
129 |
} |
|
130 |
|
|
131 |
private SysConfig getEntity(SysConfigParam param) { |
|
132 |
SysConfig entity = new SysConfig(); |
|
133 |
ToolUtil.copyProperties(param, entity); |
|
134 |
return entity; |
|
135 |
} |
|
136 |
|
|
137 |
} |