CustomTemplateController.java
10.7 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
package com.lhcredit.project.business.customTemplate.controller;
import java.util.*;
import java.util.stream.Collectors;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.lhcredit.common.utils.StreamUtils;
import com.lhcredit.common.utils.StringUtils;
import com.lhcredit.common.utils.security.ShiroUtils;
import com.lhcredit.common.utils.text.Convert;
import com.lhcredit.project.business.frontDept.domain.FrontDept;
import com.lhcredit.project.business.frontDept.service.IFrontDeptService;
import com.lhcredit.project.business.frontUser.domain.FrontUser;
import com.lhcredit.project.business.frontUser.service.IFrontUserService;
import com.lhcredit.project.business.reportMake.reportTemp.WebTempConfig;
import com.lhcredit.project.business.templateConfiguration.domain.TemplateConfiguration;
import com.lhcredit.project.business.templateConfiguration.mapper.TemplateConfigurationMapper;
import com.lhcredit.project.business.templateConfiguration.service.ITemplateConfigurationService;
import com.lhcredit.project.business.templateConfigurationParameters.domain.TemplateConfigurationParameters;
import com.lhcredit.project.business.templateConfigurationParameters.service.ITemplateConfigurationParametersService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.lhcredit.framework.aspectj.lang.annotation.Log;
import com.lhcredit.framework.aspectj.lang.enums.BusinessType;
import com.lhcredit.project.business.customTemplate.domain.CustomTemplate;
import com.lhcredit.project.business.customTemplate.service.ICustomTemplateService;
import com.lhcredit.framework.web.controller.BaseController;
import com.lhcredit.framework.web.page.TableDataInfo;
import com.lhcredit.framework.web.domain.AjaxResult;
import com.lhcredit.common.utils.poi.ExcelUtil;
/**
* 定制模版信息操作处理
*
* @author lhcredit
* @date 2025-04-08
*/
@Controller
@RequestMapping("/business/customTemplate")
public class CustomTemplateController extends BaseController {
private String prefix = "business/customTemplate";
@Autowired
private ICustomTemplateService customTemplateService;
@Autowired
private IFrontDeptService frontDeptService;
@Autowired
private TemplateConfigurationMapper templateConfigurationMapper;
@Autowired
private ITemplateConfigurationParametersService templateConfigurationParametersService;
@RequiresPermissions("business:customTemplate:view")
@GetMapping()
public String customTemplate() {
return prefix + "/customTemplate";
}
/**
* 查询定制模版列表
*/
@RequiresPermissions("business:customTemplate:list")
@PostMapping("/addTemplate")
@ResponseBody
public AjaxResult addTemplate(@RequestBody String json) {
JSONObject jsonObject = JSONObject.parseObject(json);
String name = jsonObject.getString("name");
Integer orgId = jsonObject.getInteger("orgId");
CustomTemplate customTemplate=new CustomTemplate();
customTemplate.setStatus(jsonObject.getInteger("status"));
customTemplate.setOrgId(orgId);
customTemplate.setTName(name);
customTemplate.setCreateTime(new Date());
customTemplateService.insertCustomTemplate(customTemplate);
JSONArray data = jsonObject.getJSONArray("arrayContents");
List<WebTempConfig.TemplateConfig> javaList = data.toJavaList(WebTempConfig.TemplateConfig.class);
TemplateConfiguration templateConfiguration=new TemplateConfiguration();
//更新主表模版 id
return customTemplateService.addTempLate(javaList, customTemplate.getId());
}
/**
* 查询定制模版列表
*/
@RequiresPermissions("business:customTemplate:list")
@PostMapping("/updateTemplate")
@ResponseBody
public AjaxResult updateTemplate(@RequestBody String json) {
JSONObject jsonObject = JSONObject.parseObject(json);
String name = jsonObject.getString("name");
Integer orgId = jsonObject.getInteger("orgId");
CustomTemplate customTemplate=new CustomTemplate();
customTemplate.setOrgId(orgId);
customTemplate.setTName(name);
customTemplate.setId(jsonObject.getInteger("id"));
customTemplate.setStatus(jsonObject.getInteger("status"));
TemplateConfiguration templateConfiguration=new TemplateConfiguration();
//更新主表模版 id
templateConfiguration.setOrgId(Long.valueOf(orgId));
List<TemplateConfiguration> templateConfigurations = templateConfigurationMapper.selectTemplateConfigurationList(templateConfiguration);
templateConfiguration = StreamUtils.of(templateConfigurations).filter(f -> StringUtils.isNotEmpty(f.getClientId()) && f.getClientId().contains(customTemplate.getId().toString())).getFirst();
Set<Long> collect=new HashSet<>();
if (null!=templateConfiguration&&StringUtils.isNotEmpty(templateConfiguration.getClientId())){
collect = Arrays.stream(templateConfiguration.getClientId().split(",")).map(Long::valueOf).collect(Collectors.toSet());
if (customTemplate.getStatus()==0){
collect.add(Long.valueOf(customTemplate.getId()));
templateConfiguration.setClientId(collect.stream().map(m->m.toString()).collect(Collectors.joining(",")));
}else{
collect.remove(Long.valueOf(customTemplate.getId()));
templateConfiguration.setClientId(collect.stream().map(m->m.toString()).collect(Collectors.joining(",")));
}
templateConfigurationMapper.updateTemplateConfiguration(templateConfiguration);
TemplateConfigurationParameters templateConfigurationParameters=new TemplateConfigurationParameters();
templateConfigurationParameters.setClientId(customTemplate.getId());
templateConfigurationParameters.setTypeName(customTemplate.getTName());
templateConfigurationParameters.setStatus(customTemplate.getStatus());
templateConfigurationParametersService.updateTemplateConfigurationParametersNameAndStatus(templateConfigurationParameters);
}
customTemplate.setCreateTime(new Date());
customTemplateService.updateCustomTemplate(customTemplate);
JSONArray data = jsonObject.getJSONArray("arrayContents");
List<WebTempConfig.TemplateConfig> javaList = data.toJavaList(WebTempConfig.TemplateConfig.class);
return customTemplateService.addTempLate(javaList, customTemplate.getId());
}
/**
* 查询定制模版列表
*/
@RequiresPermissions("business:customTemplate:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(CustomTemplate customTemplate) {
startPage();
List<CustomTemplate> list = customTemplateService.selectCustomTemplateList(customTemplate);
TableDataInfo rspData = new TableDataInfo();
rspData.setCode(2000);
rspData.setTotal(new PageInfo(list).getTotal());
for (CustomTemplate template : list) {
FrontDept parentDept = frontDeptService.getParentDept(Long.valueOf(template.getOrgId()));
template.setOrgName(parentDept.getDeptName());
}
rspData.setRows(list);
return rspData;
}
/**
* 导出定制模版列表
*/
@RequiresPermissions("business:customTemplate:export")
@Log(title = "定制模版", businessType = BusinessType.EXPORT)
@PostMapping("/export")
@ResponseBody
public AjaxResult export(CustomTemplate customTemplate) {
List<CustomTemplate> list = customTemplateService.selectCustomTemplateList(customTemplate);
ExcelUtil<CustomTemplate> util = new ExcelUtil<CustomTemplate>(CustomTemplate. class);
return util.exportExcel(list, "customTemplate");
}
/**
* 新增定制模版
*/
@GetMapping("/add")
public String add(ModelMap mmap) {
List<WebTempConfig.TemplateConfig> modelConfig = WebTempConfig.getModelConfig();
mmap.put("modelConfig", modelConfig);
return prefix + "/add";
}
/**
* 新增保存定制模版
*/
@RequiresPermissions("business:customTemplate:add")
@Log(title = "定制模版", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(@RequestBody CustomTemplate customTemplate) {
customTemplate.setCreateBy(ShiroUtils.getLoginName());
customTemplate.setCreateTime(new Date());
customTemplate.setUpdateBy(ShiroUtils.getLoginName());
customTemplate.setUpdateTime(new Date());
return toAjax(customTemplateService.insertCustomTemplate(customTemplate));
}
/**
* 修改定制模版
*/
@GetMapping("/edit/{id}")
public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
CustomTemplate customTemplate =customTemplateService.selectCustomTemplateById(id);
FrontDept parentDept = frontDeptService.getParentDept(Long.valueOf(customTemplate.getOrgId()));
customTemplate.setOrgName(parentDept.getDeptName());
mmap.put("customTemplate", customTemplate);
return prefix + "/edit";
}
/**
* 修改保存定制模版
*/
@RequiresPermissions("business:customTemplate:edit")
@Log(title = "定制模版", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(CustomTemplate customTemplate) {
customTemplate.setUpdateBy(ShiroUtils.getLoginName());
customTemplate.setUpdateTime(new Date());
return toAjax(customTemplateService.updateCustomTemplate(customTemplate));
}
/**
* 删除定制模版
*/
@RequiresPermissions("business:customTemplate:remove")
@Log(title = "定制模版", businessType = BusinessType.DELETE)
@PostMapping("/remove")
@ResponseBody
public AjaxResult remove(String ids) {
List<TemplateConfigurationParameters> clientIds = templateConfigurationParametersService.selectTemplateConfigurationParametersClientIds(ids);
if (!clientIds.isEmpty()) {
return new AjaxResult(AjaxResult.Type.NODATA,"该模版已被使用,无法删除");
}
return toAjax(customTemplateService.deleteCustomTemplateByIds(ids));
}
/**
* 根据机构id查询定制模版
*/
@GetMapping("/getByOrgId/{orgId}")
@ResponseBody
public AjaxResult getByOrgId(@PathVariable("orgId") Integer orgId) {
List<CustomTemplate> customTemplate = customTemplateService.getByOrgId(orgId);
return AjaxResult.success();
}
}