From 16b704d18a875d1fb63827aaa507790ba2bef5be Mon Sep 17 00:00:00 2001 From: 44323 <443237572@qq.com> Date: 星期二, 23 四月 2024 11:44:13 +0800 Subject: [PATCH] JK最终代码提交 --- guns-management/src/main/java/com/stylefeng/guns/modular/code/controller/SysDeptController.java | 78 ++++++++++++++++++++++++++------------- 1 files changed, 52 insertions(+), 26 deletions(-) diff --git a/guns-management/src/main/java/com/stylefeng/guns/modular/code/controller/SysDeptController.java b/guns-management/src/main/java/com/stylefeng/guns/modular/code/controller/SysDeptController.java index 83ba14a..42fd01f 100644 --- a/guns-management/src/main/java/com/stylefeng/guns/modular/code/controller/SysDeptController.java +++ b/guns-management/src/main/java/com/stylefeng/guns/modular/code/controller/SysDeptController.java @@ -1,25 +1,33 @@ package com.stylefeng.guns.modular.code.controller; +import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; 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.dto.DeptQuery; import com.stylefeng.guns.modular.system.model.Dept; +import com.stylefeng.guns.modular.system.model.User; import com.stylefeng.guns.modular.system.service.IDeptService; +import com.stylefeng.guns.modular.system.service.IUserService; import com.stylefeng.guns.modular.system.util.ResultUtil; -import com.stylefeng.guns.modular.system.warpper.DeptWarpper; +import com.stylefeng.guns.modular.system.vo.DeptVO; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; +import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; -import javax.xml.transform.Result; +import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.Map; @@ -35,58 +43,76 @@ @GetMapping(value = "/list") @ApiOperation(value = "列表", tags = {"后台-部门管理"}) @ResponseBody - public Object list(String name) { - List<Map<String, Object>> list = this.deptService.list(name); - return list; + public ResultUtil<PageInfo<Dept>> getList(DeptQuery req) { +// PageHelper.startPage(req.getPageNum(),req.getPageSize()); + List<Dept> depts = deptService.getList(req); + PageInfo<Dept> info=new PageInfo<>(depts); + return ResultUtil.success(info); } @DataSource(name = "dataSourceGuns") - @BussinessLog(value = "添加部门", key = "simplename", dict = DeptDict.class) @ApiOperation(value = "添加部门", tags = {"后台-部门管理"}) @PostMapping(value = "/add") @ResponseBody + public ResultUtil add(Dept dept) { - if (ToolUtil.isOneEmpty(dept, dept.getSimplename())) { - throw new GunsException(BizExceptionEnum.REQUEST_NULL); - } //完善pids,根据pid拿到pid的pids + dept.setPid(0); deptSetPids(dept); + dept.setInsertTime(new Date()); + dept.setSimplename(dept.getFullname()); this.deptService.insert(dept); return ResultUtil.success("添加成功"); - } - @DataSource(name = "dataSourceBiz") @GetMapping(value = "/tree") - @ApiOperation(value = "获取部门树", tags = {"后台-部门管理"}) + @ApiOperation(value = "获取部下拉框", tags = {"后台-部门管理"}) @ResponseBody - public List<ZTreeNode> tree() { + public List<Dept> tree() { List<ZTreeNode> tree = this.deptService.tree(); tree.add(ZTreeNode.createParent()); - return tree; + + return deptService.selectList(null); +// return tree; + } + @Autowired + private IUserService userService; + @DeleteMapping ("/delete") + @ResponseBody + @ApiOperation(value = "删除部门", tags = {"后台-部门管理"}) + public ResultUtil delete(String ids) { + String[] split = ids.split(","); + for (String id : split) { + List<User> users = userService.selectList(new EntityWrapper<User>().eq("deptid",Integer.valueOf(id))); + if (!users.isEmpty()){ + return ResultUtil.error("当前部门已绑定用户,无法删除"); + } + deptService.deleteById(Integer.valueOf(id)); + } + return ResultUtil.success("删除成功"); } - @DataSource(name = "dataSourceBiz") @GetMapping ("pre/edit/{deptId}") public Dept deptUpdate(@PathVariable Integer deptId, Model model) { Dept dept = deptService.selectById(deptId); - return dept; + 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); + @ApiImplicitParams({ + @ApiImplicitParam(value = "部门id", name = "id"), + @ApiImplicitParam(value = "部门名称", name = "fullname"), + }) + public ResultUtil update(Integer id,String fullname ) { + Dept dept1 = deptService.selectById(id); + dept1.setFullname(fullname); + dept1.setSimplename(fullname); + deptService.updateById(dept1); return ResultUtil.success("修改成功"); } -- Gitblit v1.7.1