瀏覽代碼

部门查询url调整

谭斌 2 年之前
父節點
當前提交
1382169794

+ 17 - 13
authorize-api-service/src/main/java/com/xy/service/impl/SysDeptServiceImpl.java

@@ -8,6 +8,7 @@ import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.xy.dto.CommonIdDto;
 import com.xy.dto.SysDeptDto;
 import com.xy.dto.SysDeptListDto;
 import com.xy.entity.SysDept;
@@ -27,7 +28,9 @@ import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
 
 import javax.validation.Valid;
 import java.util.*;
@@ -95,13 +98,12 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
             }
         }
 
-
         return R.ok(saveOrUpdate(sysDept));
     }
 
- 
+
     @ApiOperation(value = "系统部门树下拉列表", notes = "系统部门树下拉列表")
-    @GetMapping("tree/list")
+    @PostMapping("tree/list")
     public R<List<Tree<Long>>> deptTreeList(@Valid @RequestBody SysDeptListDto sysDeptListDto) {
         Long sysId = sysDeptListDto.getSysId();
         String deptName = sysDeptListDto.getName();
@@ -114,17 +116,18 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
     }
 
     @ApiOperation(value = "根据ID获取部门信息", notes = "根据ID获取部门信息")
-    @GetMapping("{id}")
-    public R<SysDeptVo> getById(@PathVariable("id") Long id) {
-        SysDept sysDept = super.getById(id);
+    @GetMapping("getById")
+    public R<SysDeptVo> getById(@Valid @RequestBody CommonIdDto commonIdDto) {
+        SysDept sysDept = super.getById(commonIdDto.getId());
         SysDeptVo sysRoleVo = copy(SysDeptVo.class, sysDept);
         return R.ok(sysRoleVo);
     }
 
     @ApiOperation(value = "删除部门", notes = "删除部门")
-    @DeleteMapping("{id}")
+    @PostMapping("deleteById")
     @Transactional(rollbackFor = Exception.class)
-    public R<Boolean> deleteById(@PathVariable("id") Long id) {
+    public R<Boolean> deleteById(@Valid @RequestBody CommonIdDto commonIdDto) {
+        Long id = commonIdDto.getId();
         // 级联删除部门
         List<Long> idList = sysDeptRelationService
                 .list(Wrappers.<SysDeptRelation>query().lambda().eq(SysDeptRelation::getAncestor, id)).stream()
@@ -144,13 +147,14 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
     }
 
     @ApiOperation(value = "获取指定部门部门树", notes = "获取指定部门部门树")
-    @GetMapping("deptTree/{id}")
-    public R<List<Tree<Long>>> getDeptTreeById(@PathVariable("id") Long deptId) {
+    @PostMapping("getDeptTreeById")
+    public R<List<Tree<Long>>> getDeptTreeById(@Valid @RequestBody CommonIdDto commonIdDto) {
+        Long id = commonIdDto.getId();
         List<Long> descendantIdList = sysDeptRelationService
-                .list(Wrappers.<SysDeptRelation>query().lambda().eq(SysDeptRelation::getAncestor, deptId)).stream()
+                .list(Wrappers.<SysDeptRelation>query().lambda().eq(SysDeptRelation::getAncestor, id)).stream()
                 .map(SysDeptRelation::getDescendant).collect(Collectors.toList());
         List<SysDept> deptList = baseMapper.selectBatchIds(descendantIdList);
-        Optional<SysDept> dept = deptList.stream().filter(item -> item.getId() == deptId).findFirst();
+        Optional<SysDept> dept = deptList.stream().filter(item -> item.getId() == id).findFirst();
         return R.ok(getDeptTree(deptList, dept.isPresent() ? dept.get().getParentId() : 0L));
     }
 

+ 22 - 0
authorize-api/src/main/java/com/xy/dto/CommonIdDto.java

@@ -0,0 +1,22 @@
+package com.xy.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.experimental.Accessors;
+
+import javax.validation.constraints.NotNull;
+
+@Data
+@ApiModel("删除DTO")
+@Accessors(chain = true)
+public class CommonIdDto {
+
+
+    /**
+     * id
+     */
+    @NotNull(message = "ID不可为空")
+    @ApiModelProperty(value = "ID", required = true)
+    private Long id;
+}