kimi
2020-05-27 2893347bf72477c4d108e8589a0f61e3e97a990c
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
package com.highdatas.mdm.controller;
 
 
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.highdatas.mdm.entity.SysViewLogic;
import com.highdatas.mdm.entity.SysViewLogicmap;
import com.highdatas.mdm.pojo.CodeMsg;
import com.highdatas.mdm.pojo.Result;
import com.highdatas.mdm.service.ISysViewLogicService;
import com.highdatas.mdm.service.ISysViewLogicmapService;
import com.highdatas.mdm.util.Constant;
import com.highdatas.mdm.util.DbUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
 
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author kimi
 * @since 2020-04-22
 */
@RestController
@RequestMapping("/sysView/logic")
public class SysViewLogicController {
    @Autowired
    ISysViewLogicService logicService;
    @Autowired
    ISysViewLogicmapService logicmapService;
 
    /**
     *
     * @description:  获取视图逻辑转换列表
     * @return: 逻辑转换列表
     *
     */
    @RequestMapping(value = "/all", method = RequestMethod.GET)
    public Result getList()  {
        //获取可有的列表
        List<SysViewLogic> aciveLogic = logicService.selectList(new EntityWrapper<SysViewLogic>().eq("active", true));
        return Result.success(aciveLogic);
    }
 
    /**
     *
     * @description:  获取视图已经使用的逻辑列表
     * @param parentId 视图id
     * @return: 视图已经使用的逻辑列表
     *
     */
    @RequestMapping(value = "/allmap/{parentId}", method = RequestMethod.GET)
    public Result allmap(@PathVariable String parentId)  {
        //视图已经使用的逻辑列表
        List<SysViewLogicmap> aciveLogic = logicmapService.selectList(new EntityWrapper<SysViewLogicmap>().eq(Constant.PARENT_ID, parentId));
        return Result.success(aciveLogic);
    }
 
    /**
     *
     * @description:  更新视图已经使用的逻辑列表
     * @param parentId 视图id
     * @return: 是否更新成功已经使用的逻辑列表
     *
     */
    @RequestMapping(value = "/updateMaps/{parentId}", method = RequestMethod.POST)
    public Result updateMaps(@PathVariable String parentId, @RequestBody List<SysViewLogicmap> logicmaps)  {
        //删除原来的mapping关系
        boolean delete = logicmapService.delete(new EntityWrapper<SysViewLogicmap>().eq(Constant.PARENT_ID, parentId));
        boolean insert = false;
        //循环创建新的字段和逻辑的mapping关系
        for (SysViewLogicmap logicmap : logicmaps) {
            insert = logicmap.setId(DbUtils.getUUID()).setParentId(parentId).insert();
            if (!insert) {
                return Result.error(CodeMsg.INSERT_ERROR);
            }
        }
        return Result.success(null);
 
    }
    /**
     *
     * @description:  添加视图已经使用的逻辑
     * @return: 是否添加成功
     *
     */
    @RequestMapping(value = "/addmap", method = RequestMethod.POST)
    public Result addmap(@RequestBody SysViewLogicmap logicmap)  {
        //添加一条逻辑转换关系
        boolean insert = logicmap.setId(DbUtils.getUUID()).insert();
        if (insert) {
            return Result.success(insert);
        } else {
            return Result.error(CodeMsg.INSERT_ERROR);
        }
    }
    /**
     *
     * @description:  删除视图已经使用的逻辑
     * @param id mapping 关系的id
     * @return: 是否删除成功
     *
     */
    @RequestMapping(value = "/deletemap/{id}", method = RequestMethod.POST)
    public Result deletemap(@PathVariable String id)  {
        //通过id 删除mapping关系
        boolean delete = logicmapService.deleteById(id);
        if (delete) {
            return Result.success(CodeMsg.DELETE_SUCCESS);
        } else {
            return Result.success(CodeMsg.DELETE_ERROR);
        }
    }
    /**
     *
     * @description:  更新视图已经使用的逻辑
     * @return: 是否更新成功
     *
     */
    @RequestMapping(value = "/updatemap", method = RequestMethod.POST)
    public Result updatemap(@RequestBody SysViewLogicmap logicmap)  {
        String id = logicmap.getId();
        //判断id是否存在
        if (StringUtils.isEmpty(id)) {
            return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED);
        }
        //更新记录
        boolean insert = logicmap.updateById();
        if (insert) {
            return Result.success(insert);
        } else {
            return Result.error(CodeMsg.INSERT_ERROR);
        }
    }
    /**
     *
     * @description:  添加系统中可以使用的逻辑转换类型
     * @return: 是否添加成功
     *
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public Result add(@RequestBody SysViewLogic logic)  {
        //添加记录
        boolean insert = logic.setId(DbUtils.getUUID()).insert();
        if (insert) {
            return Result.success(insert);
        } else {
            return Result.error(CodeMsg.INSERT_ERROR);
        }
    }
 
    /**
     *
     * @description:  更新系统中可以使用的逻辑转换类型
     * @return: 是否更新成功
     *
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public Result update(@RequestBody SysViewLogic logic)  {
        String id = logic.getId();
        //判断id是否存在
        if (StringUtils.isEmpty(id)) {
            return Result.error(CodeMsg.ERROR_PARAMS_NOT_MATHED);
        }
        //更新记录
        boolean b = logic.updateById();
        if (b) {
            return Result.success(logic);
        } else {
            return Result.error(CodeMsg.UPDATE_ERROR);
        }
    }
 
}