lyh
2025-01-16 1d84a3c62eeee429f7d7d6339bcf9b504a9d7277
lxzn-module-dnc/src/main/java/org/jeecg/modules/dnc/controller/DepartmentController.java
@@ -3,12 +3,18 @@
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.*;
@@ -144,4 +150,70 @@
            list = Collections.emptyList();
        return new QueryListResponseResult<>(CommonCode.SUCCESS, list);
    }
    @AutoLog(value = "DNC部门管理-获取树结构")
    @ApiOperation(value = "DNC部门管理-获取树结构", notes = "DNC部门管理-获取树结构")
    @GetMapping("/load/queryTreeList")
    public QueryListResponseResult<CommonJsonTree> queryTreeList() {
        List<CommonJsonTree> tree = departmentService.loadTree();
        if(tree == null)
            tree = Collections.emptyList();
        return new QueryListResponseResult(CommonCode.SUCCESS, tree);
    }
    /**
     * 查询数据 查出所有部门,并以树结构数据格式响应给前端
     *
     * @return
     */
    @GetMapping(value = "/queryTreeList")
    public Result<List<DepartmentTreeModel>> queryTreeList(@RequestParam(name = "ids", required = false) String ids) {
        Result<List<DepartmentTreeModel>> result = new Result<>();
        try {
            // 从内存中读取
//         List<SysDepartTreeModel> list =FindsDepartsChildrenUtil.getSysDepartTreeList();
//         if (CollectionUtils.isEmpty(list)) {
//            list = sysDepartService.queryTreeList();
//         }
            if(oConvertUtils.isNotEmpty(ids)){
                List<DepartmentTreeModel> departList = departmentService.queryTreeList(ids);
                result.setResult(departList);
            }else{
                List<DepartmentTreeModel> list = departmentService.queryTreeList();
                result.setResult(list);
            }
            result.setSuccess(true);
        } catch (Exception e) {
            log.error(e.getMessage(),e);
        }
        return result;
    }
    /**
     * <p>
     * 部门搜索功能方法,根据关键字模糊搜索相关部门
     * </p>
     *
     * @param keyWord
     * @return
     */
    @RequestMapping(value = "/searchBy", method = RequestMethod.GET)
    public Result<List<DepartmentTreeModel>> searchBy(@RequestParam(name = "keyWord", required = true) String keyWord,@RequestParam(name = "myDeptSearch", required = false) String myDeptSearch) {
        Result<List<DepartmentTreeModel>> result = new Result<List<DepartmentTreeModel>>();
        //部门查询,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<DepartmentTreeModel> 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;
    }
}