TemplateConfigurationParametersServiceImpl.java
13.1 KB
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
package com.lhcredit.project.business.templateConfigurationParameters.service;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import com.lhcredit.common.utils.StringUtils;
import com.lhcredit.project.business.frontDept.domain.FrontDept;
import com.lhcredit.project.business.frontDept.service.IFrontDeptService;
import com.lhcredit.project.system.dict.domain.DictData;
import com.lhcredit.project.system.dict.service.DictDataServiceImpl;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;
import com.lhcredit.project.business.templateConfigurationParameters.mapper.TemplateConfigurationParametersMapper;
import com.lhcredit.project.business.templateConfigurationParameters.domain.TemplateConfigurationParameters;
import com.lhcredit.common.utils.text.Convert;
import javax.annotation.Resource;
/**
* 模版配置参数 服务层实现
*
* @author lhcredit
* @date 2025-04-01
*/
@Service
public class TemplateConfigurationParametersServiceImpl implements ITemplateConfigurationParametersService {
@Resource
private TemplateConfigurationParametersMapper templateConfigurationParametersMapper;
@Resource
private IFrontDeptService frontDeptService;
@Autowired
private DictDataServiceImpl dictDataService;
@Autowired
private CacheManager cacheManager;
/**
* 查询模版配置参数信息
*
* @param id 模版配置参数ID
* @return 模版配置参数信息
*/
@Override
public TemplateConfigurationParameters selectTemplateConfigurationParametersById(String id) {
return templateConfigurationParametersMapper.selectTemplateConfigurationParametersById(id);
}
/**
* 查询模版配置参数列表
*
* @param templateConfigurationParameters 模版配置参数信息
* @return 模版配置参数集合
*/
@Override
public List<TemplateConfigurationParameters> selectTemplateConfigurationParametersList(TemplateConfigurationParameters templateConfigurationParameters) {
return templateConfigurationParametersMapper.selectTemplateConfigurationParametersList(templateConfigurationParameters);
}
/**
* 字段转换
* @param templateConfigurationParameters 模版配置参数信息
* @return 模版配置参数信息
*/
@Override
public TemplateConfigurationParameters changeModel(TemplateConfigurationParameters templateConfigurationParameters) {
// //这里写各字段转换逻辑
// if(templateConfigurationParameters!=null){
// if(StringUtils.isNotEmpty(templateConfigurationParameters.getXXX())){
// templateConfigurationParameters.setXXX(templateConfigurationParameters.getXXX());
// }
// }
return templateConfigurationParameters;
}
/**
* 列表转换
*
* @param templateConfigurationParametersList 模版配置参数集合
* @return 模版配置参数集合
*/
@Override
public List<TemplateConfigurationParameters> changeModel(List<TemplateConfigurationParameters> templateConfigurationParametersList) {
List<TemplateConfigurationParameters> result = new ArrayList<TemplateConfigurationParameters>();
if (templateConfigurationParametersList.size() > 0) {
for (TemplateConfigurationParameters templateConfigurationParameters:templateConfigurationParametersList){
result.add(changeModel(templateConfigurationParameters));
}
}
return result;
}
/**
* 新增模版配置参数
*
* @param templateConfigurationParameters 模版配置参数信息
* @return 结果
*/
@Override
public int insertTemplateConfigurationParameters(TemplateConfigurationParameters templateConfigurationParameters) {
return templateConfigurationParametersMapper.insertTemplateConfigurationParameters(templateConfigurationParameters);
}
/**
* 修改模版配置参数
*
* @param templateConfigurationParameters 模版配置参数信息
* @return 结果
*/
@Override
public int updateTemplateConfigurationParameters(TemplateConfigurationParameters templateConfigurationParameters) {
return templateConfigurationParametersMapper.updateTemplateConfigurationParameters(templateConfigurationParameters);
}
/**
* 删除模版配置参数对象
*
* @param ids 需要删除的数据ID
* @return 结果
*/
@Override
public int deleteTemplateConfigurationParametersByIds(String ids) {
return templateConfigurationParametersMapper.deleteTemplateConfigurationParametersByIds(Convert.toStrArray(ids));
}
/**
* 根据orgId查询 下单时 模板配置信息
*
* @param orgId
* @return
*/
@Override
public List<TemplateConfigurationParameters> getTempConfParamsByOrg(Long orgId,String dictType){
// 递归查询机构模板配置信息 根据orgID 关联查询 后台配置的 报告模板配置
TemplateConfigurationParameters parameters = new TemplateConfigurationParameters();
parameters.setOrgId(orgId);
// parameters.setChecked("Y");
List<TemplateConfigurationParameters> templateConfigurationParameters = recursiveGetTemplateConfigurationParameters(parameters);
if (CollectionUtils.isEmpty(templateConfigurationParameters)) {
return null;
}
//委托类型
List<DictData> entrustTypeDicts = dictDataService.selectDictDataByType("entrust_type");
Map<String, DictData> entrustTypeMap = entrustTypeDicts.stream().collect(Collectors.toMap(DictData::getDictValue, Function.identity()));
//找出 翻译类型数据 client_type = null ,reportTranslationType 不是空的 数据, 并按照 typeId + clientId 为key 分组
Map<String, List<TemplateConfigurationParameters>> translateMap = templateConfigurationParameters.stream().filter(te -> te.getClientType() == null && StringUtils.isNotEmpty(te.getReportTranslationType())).collect(Collectors.groupingBy(te -> getTempOnlyKey(te)));
//处理 返回结果的结构, 筛选出 用户选中的模板。
Map<Long, List<TemplateConfigurationParameters>> paramsMap = templateConfigurationParameters.stream().filter(tem -> StringUtils.isNotEmpty(tem.getChecked()) && tem.getChecked().equals("Y")).collect(Collectors.groupingBy(TemplateConfigurationParameters::getTypeId));
ArrayList<TemplateConfigurationParameters> result = new ArrayList<>();
paramsMap.forEach((typeId,temParamList)->{
//非定制模板,直接按照 typeid 进行分类
TemplateConfigurationParameters conf = new TemplateConfigurationParameters();
/*TemplateConfigurationParameters para = temParamList.get(0);
//普通报告模板类型名称
conf.setTypeName(para.getTypeName());
//普通报告模板类型id
conf.setTypeId(typeId);
conf.setTemplateConfigurationParametersList(temParamList);
//设置 委托类型名称
temParamList.forEach(te ->{
DictData dictData = entrustTypeMap.get(te.getClientType());
te.setTypeName(dictData.getDictLabel());
});
//设置 翻译数据
List<TemplateConfigurationParameters> list = translateMap.get(typeId.toString());
if (CollectionUtils.isNotEmpty(list))
temParamList.add(list.get(0));*/
//定制模板 需要特殊处理,在按照typeId分类的基础上,还需再按照 clientId进行细分
if (typeId == -11){
//定义 定制模板的类型 list
ArrayList<TemplateConfigurationParameters> clientTempConfList = new ArrayList<>();
Map<Integer, List<TemplateConfigurationParameters>> clientTmpMap = temParamList.stream().collect(Collectors.groupingBy(TemplateConfigurationParameters::getClientId));
clientTmpMap.forEach((ctId,ctList)->{
TemplateConfigurationParameters ctConf = new TemplateConfigurationParameters();
ctConf.setClientId(ctId);
//模板类型id
ctConf.setTypeId(typeId);
//模板名称
String typeName = ctList.get(0).getTypeName();
ctConf.setTypeName(typeName);
//设置 委托类型
ctList.forEach(te->{
DictData dictData = entrustTypeMap.get(te.getClientType());
te.setTypeName(dictData.getDictLabel());
});
//翻译类型
TemplateConfigurationParameters p = ctList.get(0);
List<TemplateConfigurationParameters> list1 = translateMap.get(getTempOnlyKey(p));
if (CollectionUtils.isNotEmpty(list1))
ctList.add(list1.get(0));
//定制模板 list
ctConf.setTemplateConfigurationParametersList(ctList);
clientTempConfList.add(ctConf);
});
// conf.setTypeName("定制报告");
conf.setTypeName(dictDataService.selectDictLabel(dictType, typeId.toString()));
conf.setTypeId(typeId);
conf.setTemplateConfigurationParametersList(clientTempConfList);
}else {
TemplateConfigurationParameters para = temParamList.get(0);
//普通报告模板类型名称
// conf.setTypeName(para.getTypeName());
conf.setTypeName(dictDataService.selectDictLabel(dictType, typeId.toString()));
//普通报告模板类型id
conf.setTypeId(typeId);
conf.setTemplateConfigurationParametersList(temParamList);
//设置 委托类型名称
temParamList.forEach(te ->{
DictData dictData = entrustTypeMap.get(te.getClientType());
te.setTypeName(dictData.getDictLabel());
});
//设置 翻译数据
List<TemplateConfigurationParameters> list = translateMap.get(typeId.toString());
if (CollectionUtils.isNotEmpty(list))
temParamList.add(list.get(0));
}
result.add(conf);
});
/*Cache cache = cacheManager.getCache("dict");
if (cache != null){
String s = cache.get("dict_key_value_report_type_-4", String.class);
System.out.println(s);
}*/
return result;
}
@Override
public List<TemplateConfigurationParameters> selectTemplateConfigurationParametersClientIds(String ids) {
return templateConfigurationParametersMapper.selectTemplateConfigurationParametersClientIds(Convert.toStrArray(ids));
}
@Override
public List<TemplateConfigurationParameters> recursiveGetTemplateConfigurationParameters(TemplateConfigurationParameters parameters) {
List<TemplateConfigurationParameters> templateConfigurationParameters = templateConfigurationParametersMapper.selectTemplateConfigurationParametersList(parameters);
if (CollectionUtils.isEmpty(templateConfigurationParameters)) {
// 获取上级部门
FrontDept frontDept = frontDeptService.selectFrontDeptById(parameters.getOrgId());
if (Objects.nonNull(frontDept) && frontDept.getParentId() != 0L) {
// 递归查询上级部门
parameters.setOrgId(frontDept.getParentId());
return recursiveGetTemplateConfigurationParameters(parameters);
} else {
// 上级部门为空,返回空列表
return Collections.emptyList();
}
}
return templateConfigurationParameters;
}
@Override
public int updateTemplateConfigurationParametersNameAndStatus(TemplateConfigurationParameters parameters) {
return templateConfigurationParametersMapper.updateTemplateConfigurationParametersNameAndStatus(parameters);
}
private static String getTempOnlyKey(TemplateConfigurationParameters templateConf){
String key = templateConf.getTypeId().toString();
if (templateConf.getTypeId() == -11 && templateConf.getClientId() !=null){
key = key + "_"+ templateConf.getClientId().toString();
}
return key;
}
/**
* 根据orgId 查询配置模板
* @param orgId
* @return
*/
public List<TemplateConfigurationParameters> selectTempConfParamsByOrg(Long orgId){
//根据orgID 关联查询 模板配置
TemplateConfigurationParameters parameters = new TemplateConfigurationParameters();
parameters.setOrgId(orgId);
return templateConfigurationParametersMapper.selectTemplateConfigurationParametersList(parameters);
}
}