ny
23 小时以前 b6f169fe43a2b13f351aefc152374fc7f0bc8cb7
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
package jnpf.base.controller;
 
 
import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import jnpf.base.Page;
import jnpf.base.controller.SuperController;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import jnpf.constant.MsgCode;
import jnpf.exception.DataException;
import jnpf.util.JsonUtil;
import jnpf.base.ActionResult;
import jnpf.base.vo.ListVO;
import jnpf.base.model.dictionarytype.*;
import jnpf.base.entity.DictionaryTypeEntity;
import jnpf.base.service.DictionaryTypeService;
import jnpf.util.RandomUtil;
import jnpf.util.StringUtil;
import jnpf.util.treeutil.SumTree;
import jnpf.util.treeutil.TreeDotUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import jakarta.validation.Valid;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 * 字典分类
 *
 * @author JNPF开发平台组
 * @version V3.1.0
 * @copyright 引迈信息技术有限公司(https://www.jnpfsoft.com)
 * @date 2019年9月27日 上午9:18
 */
@Tag(name = "数据字典分类", description = "DictionaryType")
@RestController
@RequestMapping("/DictionaryType")
public class DictionaryTypeController extends SuperController<DictionaryTypeService, DictionaryTypeEntity> {
 
    @Autowired
    private DictionaryTypeService dictionaryTypeService;
 
    /**
     * 获取字典分类
     *
     * @return
     */
    @Operation(summary = "获取字典分类")
    @GetMapping
    public ActionResult<ListVO<DictionaryTypeListVO>> list() {
        List<DictionaryTypeEntity> data = dictionaryTypeService.getList();
        List<DictionaryTypeModel> voListVO = JsonUtil.getJsonToList(data, DictionaryTypeModel.class);
        voListVO.forEach(vo -> {
            if (StringUtil.isNotEmpty(vo.getCategory()) && "1".equals(vo.getCategory()) && "-1".equals(vo.getParentId())) {
                vo.setCategory("系统");
                vo.setParentId("1");
            } else if (StringUtil.isNotEmpty(vo.getCategory()) && "0".equals(vo.getCategory()) && "-1".equals(vo.getParentId())) {
                vo.setCategory("业务");
                vo.setParentId("0");
            }
        });
        List<SumTree<DictionaryTypeModel>> sumTrees = TreeDotUtils.convertListToTreeDot(voListVO);
        List<DictionaryTypeListVO> list = JsonUtil.getJsonToList(sumTrees, DictionaryTypeListVO.class);
 
        DictionaryTypeListVO parentVO = new DictionaryTypeListVO();
        parentVO.setFullName("系统字典");
        parentVO.setChildren(new ArrayList<>());
        parentVO.setId("1");
        DictionaryTypeListVO parentVO1 = new DictionaryTypeListVO();
        parentVO1.setFullName("业务字典");
        parentVO1.setChildren(new ArrayList<>());
        parentVO1.setId("0");
 
        list.forEach(vo -> {
            if ("系统".equals(vo.getCategory())) {
                List<DictionaryTypeListVO> children = parentVO.getChildren();
                children.add(vo);
                parentVO.setHasChildren(true);
            }else {
                List<DictionaryTypeListVO> children = parentVO1.getChildren();
                children.add(vo);
                parentVO1.setHasChildren(true);
            }
        });
        List<DictionaryTypeListVO> listVo = new ArrayList<>();
        listVo.add(parentVO1);
        listVo.add(parentVO);
 
        ListVO<DictionaryTypeListVO> vo = new ListVO<>();
        vo.setList(listVo);
        return ActionResult.success(vo);
    }
 
 
    /**
     * 获取字典分类
     *
     * @param id 主键
     * @return
     */
    @Operation(summary = "获取所有字典分类下拉框列表")
    @Parameter(name = "id", description = "主键", required = true)
    @GetMapping("/Selector/{id}")
    public ActionResult<ListVO<DictionaryTypeListVO>> selectorTreeView(@PathVariable("id") String id) {
        List<DictionaryTypeEntity> data = dictionaryTypeService.getList();
        if (!"0".equals(id)) {
            data.remove(dictionaryTypeService.getInfo(id));
        }
        List<DictionaryTypeModel> voListVO = JsonUtil.getJsonToList(data, DictionaryTypeModel.class);
        voListVO.forEach(vo -> {
            if (StringUtil.isNotEmpty(vo.getCategory()) && "1".equals(vo.getCategory()) && "-1".equals(vo.getParentId())) {
                vo.setCategory("系统");
                vo.setParentId("1");
            } else if (StringUtil.isNotEmpty(vo.getCategory()) && "0".equals(vo.getCategory()) && "-1".equals(vo.getParentId())) {
                vo.setCategory("业务");
                vo.setParentId("0");
            }
        });
        List<SumTree<DictionaryTypeModel>> sumTrees = TreeDotUtils.convertListToTreeDot(voListVO);
        List<DictionaryTypeListVO> list = JsonUtil.getJsonToList(sumTrees, DictionaryTypeListVO.class);
 
        DictionaryTypeListVO parentVO = new DictionaryTypeListVO();
        parentVO.setFullName("系统字典");
        parentVO.setChildren(new ArrayList<>());
        parentVO.setId("1");
        DictionaryTypeListVO parentVO1 = new DictionaryTypeListVO();
        parentVO1.setFullName("业务字典");
        parentVO1.setChildren(new ArrayList<>());
        parentVO1.setId("0");
 
        list.forEach(vo -> {
            if ("系统".equals(vo.getCategory())) {
                List<DictionaryTypeListVO> children = parentVO.getChildren();
                children.add(vo);
                parentVO.setHasChildren(true);
            }else {
                List<DictionaryTypeListVO> children = parentVO1.getChildren();
                children.add(vo);
                parentVO1.setHasChildren(true);
            }
        });
        List<DictionaryTypeListVO> listVo = new ArrayList<>();
        listVo.add(parentVO1);
        listVo.add(parentVO);
 
        ListVO<DictionaryTypeListVO> vo = new ListVO<>();
        vo.setList(listVo);
        return ActionResult.success(vo);
    }
 
    /**
     * 获取字典分类信息
     *
     * @param id 主键值
     * @return
     */
    @Operation(summary = "获取字典分类信息")
    @Parameter(name = "id", description = "主键", required = true)
    @GetMapping("/{id}")
    public ActionResult<DictionaryTypeInfoVO> info(@PathVariable("id") String id) throws DataException {
        DictionaryTypeEntity entity = dictionaryTypeService.getInfo(id);
        if ("-1".equals(entity.getParentId())) {
            entity.setParentId(String.valueOf(entity.getCategory()));
        }
        DictionaryTypeInfoVO vo = JsonUtil.getJsonToBeanEx(entity, DictionaryTypeInfoVO.class);
        return ActionResult.success(vo);
    }
 
    /**
     * 添加字典分类
     *
     * @param dictionaryTypeCrForm 实体对象
     * @return
     */
    @Operation(summary = "添加字典分类")
    @Parameter(name = "dictionaryTypeCrForm", description = "实体对象", required = true)
    @SaCheckPermission("sysData.dictionary")
    @PostMapping
    public ActionResult create(@RequestBody @Valid DictionaryTypeCrForm dictionaryTypeCrForm) {
        DictionaryTypeEntity entity = JsonUtil.getJsonToBean(dictionaryTypeCrForm, DictionaryTypeEntity.class);
        if ("0".equals(entity.getParentId()) || "1".equals(entity.getParentId())) {
            entity.setCategory(Integer.parseInt(entity.getParentId()));
            entity.setParentId("-1");
        } else {
            DictionaryTypeEntity entity1 = dictionaryTypeService.getInfo(dictionaryTypeCrForm.getParentId());
            entity.setCategory(entity1.getCategory());
        }
        if (dictionaryTypeService.isExistByFullName(entity.getFullName(), entity.getId())) {
            return ActionResult.fail(MsgCode.EXIST001.get());
        }
        if (dictionaryTypeService.isExistByEnCode(entity.getEnCode(), entity.getId())) {
            return ActionResult.fail(MsgCode.EXIST002.get());
        }
        dictionaryTypeService.create(entity);
        return ActionResult.success(MsgCode.SU001.get());
    }
 
    /**
     * 修改字典分类
     *
     * @param dictionaryTypeUpForm 实体对象
     * @param id                   主键值
     * @return
     */
    @Operation(summary = "修改字典分类")
    @Parameters({
            @Parameter(name = "id", description = "主键值", required = true),
            @Parameter(name = "dictionaryTypeUpForm", description = "实体对象", required = true)
    })
    @SaCheckPermission("sysData.dictionary")
    @PutMapping("/{id}")
    public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid DictionaryTypeUpForm dictionaryTypeUpForm) {
        DictionaryTypeEntity entity = JsonUtil.getJsonToBean(dictionaryTypeUpForm, DictionaryTypeEntity.class);
        if ("0".equals(entity.getParentId()) || "1".equals(entity.getParentId())) {
            entity.setCategory(Integer.parseInt(entity.getParentId()));
            entity.setParentId("-1");
        } else {
            DictionaryTypeEntity entity1 = dictionaryTypeService.getInfo(dictionaryTypeUpForm.getParentId());
            entity.setCategory(entity1.getCategory());
        }
        if (dictionaryTypeService.isExistByFullName(entity.getFullName(), id)) {
            return ActionResult.fail(MsgCode.EXIST001.get());
        }
        if (dictionaryTypeService.isExistByEnCode(entity.getEnCode(), id)) {
            return ActionResult.fail(MsgCode.EXIST002.get());
        }
        boolean flag = dictionaryTypeService.update(id, entity);
        if (!flag) {
            return ActionResult.success(MsgCode.FA002.get());
        }
        return ActionResult.success(MsgCode.SU004.get());
    }
 
    /**
     * 删除字典分类
     *
     * @param id 主键值
     * @return
     */
    @Operation(summary = "删除字典分类")
    @Parameters({
            @Parameter(name = "id", description = "主键值", required = true)
    })
    @SaCheckPermission("sysData.dictionary")
    @DeleteMapping("/{id}")
    public ActionResult delete(@PathVariable("id") String id) {
        DictionaryTypeEntity entity = dictionaryTypeService.getInfo(id);
        if (entity != null) {
            boolean isOk = dictionaryTypeService.delete(entity);
            if (isOk) {
                return ActionResult.success(MsgCode.SU003.get());
            } else {
                return ActionResult.fail(MsgCode.SYS014.get());
            }
        }
        return ActionResult.fail(MsgCode.FA003.get());
    }
 
}