yanghb
2024-12-17 1287337fd0b0c156ec79712f9a600ebeffefe3a6
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
package com.zzg.web.controller.system;
 
import cn.hutool.core.util.StrUtil;
import com.zzg.common.core.domain.AjaxResult;
import com.zzg.system.domain.SysLayer;
import com.zzg.system.domain.vo.SysLayerVo;
import com.zzg.system.service.system.ISysLayerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import java.util.List;
 
/**
 * 图层管理接口
 */
@Api(tags = "图层管理")
@RestController
@RequestMapping("/layer")
public class SysLayerController {
    @Resource
    ISysLayerService sysLayerService;
 
    @ApiOperation(value = "添加图层")
    @PostMapping(value = "/addLayer")
    public AjaxResult addLayer(@RequestBody SysLayer layer) {
        if (layer == null) {
            throw new RuntimeException("获取数据失败");
        }
        if (layer.getName().contains("-")) {
            return AjaxResult.error("");
        }
 
        sysLayerService.save(layer);
        return AjaxResult.success(layer);
    }
 
    @ApiOperation(value = "更新图层")
    @PostMapping(value = "/updateLayer")
    public AjaxResult updateLayer(@RequestBody SysLayer layer) {
        if (layer == null) {
            throw new RuntimeException("");
        }
        if (StringUtils.isEmpty(StringUtils.trim(layer.getId().toString()))) {
            return AjaxResult.error("");
        }
 
        if (StringUtils.isEmpty(StrUtil.trim(layer.getName()))) {
            return AjaxResult.error("");
        }
        if (layer.getName().contains("-")) {
            return AjaxResult.error("");
        }
        try {
            sysLayerService.updateById(layer);
        } catch (DataIntegrityViolationException e) {
            throw new RuntimeException("");
        }
        return AjaxResult.success(layer);
    }
 
    @ApiOperation(value = "删除图层")
    @DeleteMapping(value = "/delLayer/{id}")
    public AjaxResult delLayer(@NotEmpty(message = "id不为空") @PathVariable String id) {
        try {
            sysLayerService.delLayer(id);
        } catch (Exception e) {
            return AjaxResult.error(e.getMessage());
        }
        return AjaxResult.success("删除成功");
    }
 
    /**
     * 图层树
     */
    @GetMapping("/layerTree")
    @ApiOperation(value = "获取图层树")
    public AjaxResult getLayerTree() {
        List<SysLayerVo> layerTreeList = sysLayerService.getLayerTree();
        return AjaxResult.success(layerTreeList);
    }
 
}