Administrator
2023-06-19 49588f5a462ae7425e7eb030438a35fd80c246fa
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
package com.gk.firework.Controller;
 
import com.alibaba.fastjson.JSONObject;
import com.gk.firework.Domain.*;
import com.gk.firework.Domain.Utils.*;
import com.gk.firework.Service.*;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.*;
 
@Api(tags = "数据字典接口")
@RestController
public class DictionaryController {
    @Autowired
    DictionaryTypeService dictionaryTypeService;
    @Autowired
    DictionaryItemService dictionaryItemService;
 
 
    @Autowired
    UserService userService;
    @Autowired
    RoleService roleService;
    @Autowired
    UserRolesService userRolesService;
    @Autowired
    RolePermissionsService rolePermissionsService;
    @Autowired
    ExcelExportService excelExportService;
    @Autowired
    DistrictService districtService;
    @Autowired
    UserRolesService userRolesInfoService;
 
    @GetMapping("/dictionary-types")
    @ApiOperation(value = "获取数据字典类型",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageIndex",value = "当前页码"),
            @ApiImplicitParam(name = "pageSize",value = "每页行数"),
            @ApiImplicitParam(name = "name",value = "名称"),
    })
    public Msg getDictionaryTypeInfo(@RequestParam(defaultValue = "0") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize, String name){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
 
        PageInfo pageInfo = new PageInfo(pageIndex, pageSize);
        HashMap<String, Object> condition = new HashMap<String, Object>();
 
        if (StringUtils.isNotBlank(name)) {
            condition.put("name", name.trim());
        }
 
        pageInfo.setCondition(condition);
        dictionaryTypeService.selectDataGrid(pageInfo);
        msg.setResult(pageInfo);
        return msg;
    }
 
    @PostMapping("/adddictionary-types")
    @ApiOperation(value = "添加数据字典类型",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code",value = "编码",required = true),
            @ApiImplicitParam(name = "text",value = "名称",required = true),
            @ApiImplicitParam(name = "description",value = "备注"),
            @ApiImplicitParam(name = "operator",value = "操作人"),
    })
    public Msg addDiactionaryTypeInfo(@RequestBody JSONObject jsonObject){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        String code = jsonObject.getString("code");
        String text = jsonObject.getString("text");
        String operator = jsonObject.getString("operator");
        DictionaryTypeInfo dictionaryExistCode = dictionaryTypeService.selctByCode(code);
        if (dictionaryExistCode != null){
            msg.setCode("999");
            msg.setMessage("编码已存在");
            return msg;
        }
        DictionaryTypeInfo dictionaryExistText = dictionaryTypeService.selctByText(text);
        if (dictionaryExistText != null){
            msg.setCode("999");
            msg.setMessage("名称已存在");
            return msg;
        }
        DictionaryTypeInfo dictionaryTypeInfo = new DictionaryTypeInfo();
        dictionaryTypeInfo.setCode(code);
        dictionaryTypeInfo.setStatus((byte)1);
        dictionaryTypeInfo.setText(text);
        dictionaryTypeInfo.setCreatedby(operator);
        dictionaryTypeInfo.setCreateddate(new Date());
        dictionaryTypeInfo.setModifiedby(operator);
        dictionaryTypeInfo.setModifieddate(new Date());
        dictionaryTypeInfo.setDescription(jsonObject.getString("description"));
        dictionaryTypeService.save(dictionaryTypeInfo);
        return msg;
    }
 
    @PostMapping("/putdictionary-types")
    @ApiOperation(value = "修改字典类型",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "id",required = true),
            @ApiImplicitParam(name = "code",value = "编码",required = true),
            @ApiImplicitParam(name = "text",value = "名称",required = true),
            @ApiImplicitParam(name = "description",value = "备注"),
            @ApiImplicitParam(name = "operator",value = "操作人"),
    })
    public Msg putDiactionaryTypefo(@RequestBody JSONObject jsonObject){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        Long id = jsonObject.getLong("id");
        String code = jsonObject.getString("code");
        String text = jsonObject.getString("text");
        String operator = jsonObject.getString("operator");
        List<DictionaryTypeInfo> dictionaryTypes = dictionaryTypeService.selectExistInfo(id,code,null);
        if (dictionaryTypes.size() > 0){
            msg.setCode("999");
            msg.setMessage("编码重复");
            return msg;
        }
        List<DictionaryTypeInfo> dictionaryTypeInfoList = dictionaryTypeService.selectExistInfo(id,null,text);
        if (dictionaryTypeInfoList.size() > 0){
            msg.setCode("999");
            msg.setMessage("名称重复");
            return msg;
        }
        DictionaryTypeInfo dictionaryTypeInfo = new DictionaryTypeInfo();
        dictionaryTypeInfo.setId(jsonObject.getLong("id"));
        dictionaryTypeInfo.setCode(code);
        dictionaryTypeInfo.setText(text);
        dictionaryTypeInfo.setModifiedby(operator);
        dictionaryTypeInfo.setModifieddate(new Date());
        dictionaryTypeInfo.setDescription(jsonObject.getString("description"));
        dictionaryTypeService.updateById(dictionaryTypeInfo);
        return msg;
 
    }
 
    @PostMapping("/deldictionary-types")
    @ApiOperation(value = "删除字典类型", notes = "删除字典类型", response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name = "id",value = "id",required = true),
            @ApiImplicitParam(paramType="body",name = "lastmodifiedby",value = "更新人"),
 
    })
    public Msg delDiactionaryTypeInfo(@ApiParam(value = "id,lastmodifiedby")
                             @RequestBody JSONObject jsonObject){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        DictionaryTypeInfo dictionaryTypeInfo = new DictionaryTypeInfo();
        dictionaryTypeInfo.setId(jsonObject.getLong("id"));
        dictionaryTypeInfo.setModifiedby(jsonObject.getString("lastmodifiedby"));
        dictionaryTypeInfo.setModifieddate(new Date());
        dictionaryTypeInfo.setStatus((byte)0);
        dictionaryTypeService.updateById(dictionaryTypeInfo);
        return msg;
    }
 
    @GetMapping("/dictionary-items")
    @ApiOperation(value = "获取数据字典详情",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageIndex",value = "当前页码"),
            @ApiImplicitParam(name = "pageSize",value = "每页行数"),
            @ApiImplicitParam(name = "name",value = "名称"),
            @ApiImplicitParam(name = "dictionaryTypeId",value = "字典类型id"),
    })
    public Msg getDiactionaryItemInfo(@RequestParam(defaultValue = "0") Integer pageIndex, @RequestParam(defaultValue = "10") Integer pageSize,
                                      String name,Long dictionaryTypeId){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
 
        PageInfo pageInfo = new PageInfo(pageIndex, pageSize);
        HashMap<String, Object> condition = new HashMap<String, Object>();
 
        if (StringUtils.isNotBlank(name)) {
            condition.put("name", name.trim());
        }
 
        if (dictionaryTypeId != null){
            condition.put("dictionaryTypeId",dictionaryTypeId);
        }
 
        pageInfo.setCondition(condition);
        dictionaryItemService.selectDataGrid(pageInfo);
        msg.setResult(pageInfo);
        return msg;
    }
 
    @GetMapping("/dictionaryAllItems")
    @ApiOperation(value = "获取数据字典详情",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dictionaryType",value = "字典类型名称"),
    })
    public Msg getDiactionaryItemInfo(String dictionaryType){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
 
        List<DictionaryItemInfo> dictionaryItems = dictionaryItemService.selectByType(dictionaryType);
        msg.setResult(dictionaryItems);
        return msg;
    }
 
    @PostMapping("/adddictionary-items")
    @ApiOperation(value = "添加数据字典详情",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "text",value = "字典标签",required = true),
            @ApiImplicitParam(name = "value",value = "字典值",required = true),
            @ApiImplicitParam(name = "description",value = "备注"),
            @ApiImplicitParam(name = "dictionaryTypeId",value = "类型id"),
            @ApiImplicitParam(name = "operator",value = "操作人"),
            @ApiImplicitParam(name = "sort",value = "序号"),
            @ApiImplicitParam(name = "status",value = "状态"),
    })
    public Msg addDiactionaryItemInfo(@RequestBody JSONObject jsonObject){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        String value = jsonObject.getString("value");
        String text = jsonObject.getString("text");
        String operator = jsonObject.getString("operator");
        Long typeid = jsonObject.getLong("dictionaryTypeId");
        if (typeid == null){
            msg.setCode("999");
            msg.setMessage("未选择字典类型");
            return msg;
        }
        DictionaryItemInfo dictionaryExistCode = dictionaryItemService.selctByText(text);
        if (dictionaryExistCode != null){
            msg.setCode("999");
            msg.setMessage("字典标签已存在");
            return msg;
        }
        DictionaryItemInfo dictionaryExistText = dictionaryItemService.selctByValue(value);
        if (dictionaryExistText != null){
            msg.setCode("999");
            msg.setMessage("字典值已存在");
            return msg;
        }
        DictionaryItemInfo dictionaryItemInfo = new DictionaryItemInfo();
        dictionaryItemInfo.setTypeid(typeid);
        dictionaryItemInfo.setValue(value);
        dictionaryItemInfo.setStatus(jsonObject.getByte("status"));
        dictionaryItemInfo.setText(text);
        dictionaryItemInfo.setSort(jsonObject.getInteger("sort"));
        dictionaryItemInfo.setCreatedby(operator);
        dictionaryItemInfo.setCreateddate(new Date());
        dictionaryItemInfo.setModifiedby(operator);
        dictionaryItemInfo.setModifieddate(new Date());
        dictionaryItemInfo.setDescription(jsonObject.getString("description"));
        dictionaryItemService.save(dictionaryItemInfo);
        return msg;
    }
 
    @PostMapping("/putdictionary-items")
    @ApiOperation(value = "修改字典详情",response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "id",required = true),
            @ApiImplicitParam(name = "text",value = "字典标签",required = true),
            @ApiImplicitParam(name = "value",value = "字典值",required = true),
            @ApiImplicitParam(name = "description",value = "备注"),
            @ApiImplicitParam(name = "operator",value = "操作人"),
            @ApiImplicitParam(name = "sort",value = "序号"),
            @ApiImplicitParam(name = "status",value = "状态"),
    })
    public Msg putDiactionaryItemfo(@RequestBody JSONObject jsonObject){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        Long id = jsonObject.getLong("id");
 
        String value = jsonObject.getString("value");
        String text = jsonObject.getString("text");
        String operator = jsonObject.getString("operator");
 
        List<DictionaryTypeInfo> dictionaryTypes = dictionaryItemService.selectExistInfo(id,value,null);
        if (dictionaryTypes.size() > 0){
            msg.setCode("999");
            msg.setMessage("字典值重复");
            return msg;
        }
        List<DictionaryTypeInfo> dictionaryTypeInfoList = dictionaryItemService.selectExistInfo(id,null,text);
        if (dictionaryTypeInfoList.size() > 0){
            msg.setCode("999");
            msg.setMessage("字典标签重复");
            return msg;
        }
 
        DictionaryItemInfo dictionaryItemInfo = new DictionaryItemInfo();
        dictionaryItemInfo.setId(id);
        dictionaryItemInfo.setValue(value);
        dictionaryItemInfo.setStatus(jsonObject.getByte("status"));
        dictionaryItemInfo.setText(text);
        dictionaryItemInfo.setSort(jsonObject.getInteger("sort"));
        dictionaryItemInfo.setModifiedby(operator);
        dictionaryItemInfo.setModifieddate(new Date());
        dictionaryItemInfo.setDescription(jsonObject.getString("description"));
        dictionaryItemService.updateById(dictionaryItemInfo);
        return msg;
    }
 
    @PostMapping("/deldictionary-items")
    @ApiOperation(value = "删除字典详情", notes = "删除字典详情", response = Msg.class)
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query",name = "id",value = "id",required = true),
            @ApiImplicitParam(paramType="body",name = "lastmodifiedby",value = "更新人"),
 
    })
    public Msg delDiactionaryItemInfo(@ApiParam(value = "id,lastmodifiedby")
                                      @RequestBody JSONObject jsonObject){
        Msg msg = new Msg();
        msg.setCode("200");
        msg.setMessage("success");
        DictionaryItemInfo dictionaryTypeInfo = new DictionaryItemInfo();
        dictionaryTypeInfo.setId(jsonObject.getLong("id"));
        dictionaryItemService.removeById(dictionaryTypeInfo);
        return msg;
    }
 
 
}