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 layerTreeList = sysLayerService.getLayerTree(); return AjaxResult.success(layerTreeList); } }