package org.jeecg.modules.dnc.controller; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.apache.shiro.SecurityUtils; import org.jeecg.common.api.vo.Result; import org.jeecg.common.aspect.annotation.AutoLog; import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.system.vo.LoginUser; import org.jeecg.common.util.oConvertUtils; import org.jeecg.modules.dnc.request.DepartmentRequest; import org.jeecg.modules.dnc.response.*; import org.jeecg.modules.dnc.service.IDepartmentService; import org.jeecg.modules.dnc.ucenter.Department; import org.jeecg.modules.system.entity.SysUser; import org.jeecg.modules.system.model.SysDepartTreeModel; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.Collections; import java.util.List; @Slf4j @Api(tags = "DNC部门管理") @RestController @RequestMapping("/ucenter/depart") public class DepartmentController { @Autowired private IDepartmentService departmentService; @AutoLog(value = "DNC部门管理-添加部门信息") @ApiOperation(value = "DNC部门管理-添加部门信息", notes = "DNC部门管理-添加部门信息") @PostMapping("/add") public ResponseResult addDepartment(@RequestBody Department department) { boolean b = departmentService.addDepartment(department); if(b) { return new ResponseResult(CommonCode.SUCCESS); } return new ResponseResult(CommonCode.FAIL); } @AutoLog(value = "DNC部门管理-修改部门") @ApiOperation(value = "DNC部门管理-修改部门", notes = "DNC部门管理-修改部门") @PutMapping("/edit/{id}") public ResponseResult editDepartment(@PathVariable("id") String id,@RequestBody Department department) { boolean b = departmentService.editDepartment(id,department); if(b) { return new ResponseResult(CommonCode.SUCCESS); } return new ResponseResult(CommonCode.FAIL); } @AutoLog(value = "DNC部门管理-分页查询") @ApiOperation(value = "DNC部门管理-分页查询", notes = "DNC部门管理-分页查询") @GetMapping("/find/page/{page}/{size}") public QueryPageResponseResult findPageList(@PathVariable("page") int page, @PathVariable("size") int size, DepartmentRequest departmentRequest) { return departmentService.findPageList(page,size,departmentRequest); } @AutoLog(value = "DNC部门管理-获取所有列表,按层级") @ApiOperation(value = "DNC部门管理-获取所有列表,按层级", notes = "DNC部门管理-获取所有列表,按层级") @GetMapping("/load/tree") public QueryListResponseResult loadTree() { List tree = departmentService.loadTree(); if(tree == null) tree = Collections.emptyList(); return new QueryListResponseResult(CommonCode.SUCCESS, tree); } @AutoLog(value = "DNC部门管理-删除 部门") @ApiOperation(value = "DNC部门管理-删除 部门", notes = "DNC部门管理-删除 部门") @DeleteMapping("/delete") public ResponseResult deleteDepartment(@RequestParam("id") String id) { boolean b = departmentService.deleteDepartmentById(id); if(b) { return new ResponseResult(CommonCode.SUCCESS); } return new ResponseResult(CommonCode.FAIL); } @AutoLog(value = "DNC部门管理-获取用户未分配的部门列表") @ApiOperation(value = "DNC部门管理-获取用户未分配的部门列表", notes = "DNC部门管理-获取用户未分配的部门列表") @GetMapping("/perm/select/non/{userId}") public QueryListResponseResult getUserNonPermDepart(@PathVariable("userId") String userId) { List list = departmentService.getUserNonPermDepart(userId); if(list == null) list = Collections.emptyList(); return new QueryListResponseResult<>(CommonCode.SUCCESS, list); } @AutoLog(value = "DNC部门管理-获取用户已分配的部门列表") @ApiOperation(value = "DNC部门管理-获取用户已分配的部门列表", notes = "DNC部门管理-获取用户已分配的部门列表") @GetMapping("/perm/select/{userId}") public QueryListResponseResult getUserPermDepart(@PathVariable("userId") String userId) { List list = departmentService.getUserPermDepart(userId); if(list == null) list = Collections.emptyList(); return new QueryListResponseResult<>(CommonCode.SUCCESS, list); } @AutoLog(value = "DNC部门管理-获取部门未指定的审批人") @ApiOperation(value = "DNC部门管理-获取部门未指定的审批人", notes = "DNC部门管理-获取部门未指定的审批人") @GetMapping("/approve/select/non/{departId}") public QueryListResponseResult getUserNonApproveDepart(@PathVariable("departId") String departId) { List list = departmentService.getUserNonApproveDepart(departId); if(list == null) list = Collections.emptyList(); return new QueryListResponseResult<>(CommonCode.SUCCESS, list); } @AutoLog(value = "DNC部门管理-获取部门已指定的审批人") @ApiOperation(value = "DNC部门管理-获取部门已指定的审批人", notes = "DNC部门管理-获取部门已指定的审批人") @GetMapping("/approve/select/{departId}") public QueryListResponseResult getUserApproveDepart(@PathVariable("departId") String departId) { List list = departmentService.getUserApproveDepart(departId); if(list == null) list = Collections.emptyList(); return new QueryListResponseResult<>(CommonCode.SUCCESS, list); } @AutoLog(value = "DNC部门管理-增加部门审批人") @ApiOperation(value = "DNC部门管理-增加部门审批人", notes = "DNC部门管理-增加部门审批人") @PostMapping("/assign/add/approve/user/{departId}/{relativeFlag}") public ResponseResult assignAddApproveUser(@PathVariable("departId") String departId, @PathVariable("relativeFlag") Integer relativeFlag, @RequestBody String[] userIds) { boolean b = departmentService.assignAddApproveUser(departId, relativeFlag, userIds); if(b) { return new ResponseResult(CommonCode.SUCCESS); } return new ResponseResult(CommonCode.FAIL); } @AutoLog(value = "DNC部门管理-移除部门审批人") @ApiOperation(value = "DNC部门管理-移除部门审批人", notes = "DNC部门管理-移除部门审批人") @PostMapping("/assign/remove/approve/user/{departId}/{relativeFlag}") public ResponseResult assignRemoveApproveUser(@PathVariable("departId") String departId, @PathVariable("relativeFlag") Integer relativeFlag, @RequestBody String[] userIds) { boolean b = departmentService.assignRemoveApproveUser(departId, relativeFlag, userIds); if(b) { return new ResponseResult(CommonCode.SUCCESS); } return new ResponseResult(CommonCode.FAIL); } @AutoLog(value = "DNC部门管理-获取部门List") @ApiOperation(value = "DNC部门管理-获取部门List", notes = "DNC部门管理-获取部门List") @GetMapping("/list/all") public QueryListResponseResult getDepartList() { List list = departmentService.list(); if(list == null) list = Collections.emptyList(); return new QueryListResponseResult<>(CommonCode.SUCCESS, list); } @AutoLog(value = "DNC部门管理-获取树结构") @ApiOperation(value = "DNC部门管理-获取树结构", notes = "DNC部门管理-获取树结构") @GetMapping("/load/queryTreeList") public QueryListResponseResult queryTreeList() { List tree = departmentService.loadTree(); if(tree == null) tree = Collections.emptyList(); return new QueryListResponseResult(CommonCode.SUCCESS, tree); } /** * 查询数据 查出所有部门,并以树结构数据格式响应给前端 * * @return */ @GetMapping(value = "/queryTreeList") public Result> queryTreeList(@RequestParam(name = "ids", required = false) String ids) { Result> result = new Result<>(); try { // 从内存中读取 // List list =FindsDepartsChildrenUtil.getSysDepartTreeList(); // if (CollectionUtils.isEmpty(list)) { // list = sysDepartService.queryTreeList(); // } if(oConvertUtils.isNotEmpty(ids)){ List departList = departmentService.queryTreeList(ids); result.setResult(departList); }else{ List list = departmentService.queryTreeList(); result.setResult(list); } result.setSuccess(true); } catch (Exception e) { log.error(e.getMessage(),e); } return result; } /** *

* 部门搜索功能方法,根据关键字模糊搜索相关部门 *

* * @param keyWord * @return */ @RequestMapping(value = "/searchBy", method = RequestMethod.GET) public Result> searchBy(@RequestParam(name = "keyWord", required = true) String keyWord,@RequestParam(name = "myDeptSearch", required = false) String myDeptSearch) { Result> result = new Result>(); //部门查询,myDeptSearch为1时为我的部门查询,登录用户为上级时查只查负责部门下数据 LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal(); String departIds = null; if(oConvertUtils.isNotEmpty(user.getUserIdentity()) && user.getUserIdentity().equals( CommonConstant.USER_IDENTITY_2 )){ departIds = user.getDepartIds(); } List treeList = this.departmentService.searchByKeyWord(keyWord,myDeptSearch,departIds); if (treeList == null || treeList.size() == 0) { result.setSuccess(false); result.setMessage("未查询匹配数据!"); return result; } result.setResult(treeList); return result; } }