luo
2023-12-08 1300cd0e47d9f0890d972bafeba888d10395ed38
guns-management/src/main/java/com/stylefeng/guns/modular/code/controller/SysDeptController.java
@@ -2,18 +2,22 @@
import com.stylefeng.guns.core.common.annotion.BussinessLog;
import com.stylefeng.guns.core.common.constant.dictmap.DeptDict;
import com.stylefeng.guns.core.common.constant.factory.ConstantFactory;
import com.stylefeng.guns.core.common.exception.BizExceptionEnum;
import com.stylefeng.guns.core.exception.GunsException;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.core.mutidatasource.annotion.DataSource;
import com.stylefeng.guns.core.node.ZTreeNode;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.system.model.Dept;
import com.stylefeng.guns.modular.system.service.IDeptService;
import com.stylefeng.guns.modular.system.util.ResultUtil;
import com.stylefeng.guns.modular.system.warpper.DeptWarpper;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import javax.xml.transform.Result;
import java.util.List;
@@ -28,16 +32,18 @@
    @DataSource(name = "dataSourceBiz")
    @RequestMapping(value = "/list")
    @GetMapping(value = "/list")
    @ApiOperation(value = "列表", tags = {"后台-部门管理"})
    @ResponseBody
    public Object list(String condition) {
        List<Map<String, Object>> list = this.deptService.list(condition);
    public Object list(String name) {
        List<Map<String, Object>> list = this.deptService.list(name);
        return list;
    }
    @DataSource(name = "dataSourceGuns")
    @BussinessLog(value = "添加部门", key = "simplename", dict = DeptDict.class)
    @RequestMapping(value = "/add")
    @ApiOperation(value = "添加部门", tags = {"后台-部门管理"})
    @PostMapping(value = "/add")
    @ResponseBody
    public ResultUtil add(Dept dept) {
        if (ToolUtil.isOneEmpty(dept, dept.getSimplename())) {
@@ -50,6 +56,41 @@
    }
    @DataSource(name = "dataSourceBiz")
    @GetMapping(value = "/tree")
    @ApiOperation(value = "获取部门树", tags = {"后台-部门管理"})
    @ResponseBody
    public List<ZTreeNode> tree() {
        List<ZTreeNode> tree = this.deptService.tree();
        tree.add(ZTreeNode.createParent());
        return tree;
    }
    @DataSource(name = "dataSourceBiz")
    @GetMapping ("pre/edit/{deptId}")
    public Dept deptUpdate(@PathVariable Integer deptId, Model model) {
        Dept dept = deptService.selectById(deptId);
       return dept;
    }
    @DataSource(name = "dataSourceGuns")
    @BussinessLog(value = "修改部门", key = "simplename", dict = DeptDict.class)
    @ApiOperation(value = "修改部门", tags = {"后台-部门管理"})
    @PutMapping (value = "/update")
    @ResponseBody
    public ResultUtil update(Dept dept) {
        if (ToolUtil.isEmpty(dept) || dept.getId() == null) {
            throw new GunsException(BizExceptionEnum.REQUEST_NULL);
        }
        deptSetPids(dept);
        Dept dept1 = deptService.selectById(dept.getId());
        deptService.updateById(dept);
        return ResultUtil.success("修改成功");
    }
    private void deptSetPids(Dept dept) {
        if (ToolUtil.isEmpty(dept.getPid()) || dept.getPid().equals(0)) {
            dept.setPid(0);