1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package com.yiboshi.science.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yiboshi.arch.exception.BusinessException;
import com.yiboshi.science.base.BaseServiceImpl;
import com.yiboshi.science.dao.SystemSetDAO;
import com.yiboshi.science.entity.SystemParameter;
import com.yiboshi.science.entity.SystemSet;
import com.yiboshi.science.enumeration.CommonEnum;
import com.yiboshi.science.param.dto.SystemSetDTO;
import com.yiboshi.science.param.query.SystemSetQueryVO;
import com.yiboshi.science.service.SystemSetService;
import com.yiboshi.science.utils.RedisKey;
import com.yiboshi.science.utils.RedisUtils;
import com.yiboshi.science.utils.SystemSetKey;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
* 配置表 Service 实现类
*
* @author lkl
* @version 2021-08-26
*/
@Service
@AllArgsConstructor
public class SystemSetServiceImpl extends BaseServiceImpl<SystemSetDAO, SystemSetQueryVO, SystemSetDTO, SystemSet> implements SystemSetService {
private RedisUtils redisUtils;
@Override
protected void setCriteriaForQuery(SystemSetQueryVO vo, QueryWrapper<SystemSetQueryVO> criteria) {
if (Objects.nonNull(vo.getName())) {
criteria.eq("name", vo.getName());
}
if (Objects.nonNull(vo.getValue())) {
criteria.eq("value", vo.getValue());
}
if (Objects.nonNull(vo.getDescription())) {
criteria.eq("description", vo.getDescription());
}
}
/**
* 根据Key 获取设置信息
*
* @param Key
* @return
*/
@Override
public String getByKey(String Key) {
List<SystemSet> list = getList();
if (null == list)
return null;
list = list.stream().filter(e -> e.getName().equals(Key)).collect(Collectors.toList());
if (null != list && list.size() > 0)
return list.stream().findFirst().get().getValue();
else{
return getValueByKey(Key);
}
}
@Transactional
public String save(Map<String, Object> map) {
String SMSApiUrl = "";
String loginType = "";
String projType = "";
if (!map.containsKey("SMSApiUrl"))
throw new BusinessException("参数错误");
if (!map.containsKey("loginType"))
throw new BusinessException("参数错误");
if (!map.containsKey("projType"))
throw new BusinessException("参数错误");
SMSApiUrl = (String) map.get("SMSApiUrl");
loginType = (String) map.get("loginType");
projType = (String) map.get("projType");
if (Objects.nonNull(SMSApiUrl)) {
SystemSet set=getBykey(SystemSetKey.SMSApiUrl);
if(null!=set){
set.setValue(SMSApiUrl);
this.update(set);
}
else{
set=new SystemSet();
set.setName(SystemSetKey.SMSApiUrl);
set.setValue(SMSApiUrl);
this.insert(set);
}
}
if (Objects.nonNull(loginType)) {
SystemSet set=getBykey(SystemSetKey.LoginType);
if(null!=set){
set.setValue(loginType);
this.update(set);
}
else{
set=new SystemSet();
set.setName(SystemSetKey.LoginType);
set.setValue(loginType);
this.insert(set);
}
}
if (Objects.nonNull(projType)) {
SystemSet set=getBykey(SystemSetKey.SysProjectType);
if(null!=set){
set.setValue(projType);
this.update(set);
}
else{
set=new SystemSet();
set.setName(SystemSetKey.SysProjectType);
set.setValue(projType);
this.insert(set);
}
}
redisUtils.del(RedisKey.SystemSetList);
return "ok";
}
private SystemSet getBykey(String key) {
SystemSet set = new SystemSet();
set.setName(key);
set = this.getEntity(set);
if (null != set)
return set;
return null;
}
private String getValueByKey(String key) {
SystemSet set = new SystemSet();
set.setName(key);
set = this.getEntity(set);
if (null != set)
return set.getValue();
return null;
}
/**
* 获取系统设置列表
*
* @return
*/
public List<SystemSet> getList() {
List<SystemSet> list;
Object obj = redisUtils.get(RedisKey.SystemSetList);
if (null != obj)
list = (List<SystemSet>) redisUtils.get(RedisKey.SystemSetList);
else {
list = this.entityList(new SystemSet());
redisUtils.set(RedisKey.SystemSetList, list, 7, TimeUnit.DAYS);
}
return list;
}
}