孔祥富
2021-03-07 14c2d7fc17595c86e7fe70f2d25f93a7d2c0a635
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
package cc.mrbird.febs.server.system.controller;
 
import cc.mrbird.febs.common.core.entity.FebsResponse;
import cc.mrbird.febs.common.core.entity.QueryRequest;
import cc.mrbird.febs.common.core.entity.system.Dic;
import cc.mrbird.febs.common.core.entity.system.DicItem;
import cc.mrbird.febs.common.core.exception.FebsException;
import cc.mrbird.febs.common.core.utils.FebsUtil;
import cc.mrbird.febs.server.system.service.IDicItemService;
import cc.mrbird.febs.server.system.service.IDicService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
 
/**
 * name:Dicitem
 * package:cc.mrbird.febs.server.system.controller
 * description:数据字典项控制器
 *
 * @author luoyibo
 * @date 2021-02-02 11:29:37
 * @since JDK1.8
 */
@Slf4j
@Validated
@RestController
@RequestMapping("dicItem")
@RequiredArgsConstructor
public class DiciIemController {
 
    private final IDicItemService dicitemService;
 
    private final IDicService dicService;
 
    @GetMapping
    public FebsResponse getAllDicitems(DicItem dicitem) {
        return new FebsResponse().data(dicitemService.findDicItems(dicitem));
    }
 
    @GetMapping(value = "/type/{dictType}")
    public FebsResponse dictType(@PathVariable String dictType) {
        DicItem dicItem = new DicItem();
        dicItem.setDicCode(dictType);
        return new FebsResponse().data(dicitemService.findDicItems(dicItem));
    }
    @GetMapping(value = "/types/{dictType}")
    public List<DicItem> dictTypes(@PathVariable String dictType) {
        DicItem dicItem = new DicItem();
        dicItem.setDicCode(dictType);
        return dicitemService.findDicItems(dicItem);
    }
    @GetMapping("list")
    public FebsResponse dicitemList(QueryRequest request, DicItem dicitem) {
        Map<String, Object> dataTable = FebsUtil.getDataTable(this.dicitemService.findDicItems(request, dicitem));
        return new FebsResponse().data(dataTable);
    }
 
    @PostMapping
    public void addDicItem(@Valid DicItem dicitem) throws FebsException {
        try {
            Dic byId = dicService.getById(dicitem.getDicId());
            dicitem.setDicCode(byId.getDicCode());
            this.dicitemService.createDicItem(dicitem);
        } catch (Exception e) {
            String message = "新增数据字典项失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }
 
    @DeleteMapping
    public void deleteDicItem(DicItem dicitem) throws FebsException {
        try {
            this.dicitemService.deleteDicItem(dicitem);
        } catch (Exception e) {
            String message = "删除数据字典项失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }
 
    @DeleteMapping("{ids}")
    public void logicDeleteDicItem(@PathVariable("ids") String ids) throws FebsException {
        try {
            this.dicitemService.logicDelDicItem(ids);
        } catch (Exception e) {
            String message = "逻辑删除数据字典项失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }
 
    @PutMapping
 
    public void updateDicItem(DicItem dicitem) throws FebsException {
        try {
            Dic byId = dicService.getById(dicitem.getDicId());
            dicitem.setDicCode(byId.getDicCode());
            this.dicitemService.updateDicItem(dicitem);
        } catch (Exception e) {
            String message = "修改数据字典项失败";
            log.error(message, e);
            throw new FebsException(message);
        }
    }
}