package com.ruoyi.management.controller;
|
|
|
import com.ruoyi.common.core.web.page.PageInfo;
|
import com.ruoyi.common.core.web.domain.AjaxResult;
|
import com.ruoyi.management.domain.SysDept;
|
import com.ruoyi.management.dto.DeptQuery;
|
import com.ruoyi.management.service.ISysDeptService;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* <p>
|
* 部门表 前端控制器
|
* </p>
|
*
|
* @author 无关风月
|
* @since 2024-04-26
|
*/
|
@Controller
|
@RequestMapping("/base/dept")
|
public class SysDeptController {
|
@Autowired
|
private ISysDeptService deptService;
|
|
|
@GetMapping(value = "/list")
|
@ApiOperation(value = "列表", tags = {"后台-部门管理"})
|
@ResponseBody
|
public AjaxResult<PageInfo<SysDept>> getList(DeptQuery req) {
|
PageInfo<SysDept> res = new PageInfo<>(req.getPageNumber(), req.getPageSize());
|
List<SysDept> depts = deptService.getList(req);
|
res.setRecords(depts);
|
return AjaxResult.success(res);
|
}
|
@ApiOperation(value = "添加部门", tags = {"后台-部门管理"})
|
@PostMapping(value = "/add")
|
@ResponseBody
|
public AjaxResult add(SysDept dept) {
|
//完善pids,根据pid拿到pid的pids
|
dept.setParentId(0L);
|
deptSetPids(dept);
|
dept.setCreateTime(new Date());
|
dept.setDeptName(dept.getDeptName());
|
deptService.save(dept);
|
return AjaxResult.success("添加成功");
|
}
|
private void deptSetPids(SysDept dept) {
|
if (dept.getParentId()== null || dept.getParentId() == 0L) {
|
dept.setParentId(0L);
|
dept.setAncestors("0");
|
} else {
|
long pid = dept.getParentId();
|
SysDept temp = deptService.getById(pid);
|
String pids = temp.getAncestors();
|
dept.setParentId(pid);
|
dept.setAncestors(pids + "" + pid + ",");
|
}
|
}
|
}
|