mitao
13 小时以前 d4e4dc4a180cea919dfc86a1a3e5af0abe8b6d36
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/AssetInventoryTaskServiceImpl.java
@@ -198,33 +198,25 @@
        if (!isAdmin) {
            try {
                // 获取当前用户的部门名称
                String deptName = sysUserService.selectUserById(userId).getDept().getDeptName();
                String deptName = sysUserService.selectUserById(userId).getDeptName();
                // 非超级管理员且非资产管理部,设置部门权限
                if (!AssetDeptConstant.ASSET_INVENTORY_DEPT_NAMES.contains(deptName)) {
                    hasNoPermission =  true;
                }
            } catch (Exception e) {
                log.error("获取当前登录用户部门信息异常", e);
                // 如果获取部门信息失败
            }
        }
        // 1. 查询所有有效的盘点任务,支持筛选条件
        LambdaQueryWrapper<AssetInventoryTask> taskWrapper = new LambdaQueryWrapper<>();
        taskWrapper.eq(AssetInventoryTask::getDisabled, false)
                .ne(AssetInventoryTask::getStatus, AssetInventoryTaskStatusEnum.CANCELED.getCode())
                   .orderByDesc(AssetInventoryTask::getCreateTime);
        taskWrapper.ne(AssetInventoryTask::getStatus, AssetInventoryTaskStatusEnum.CANCELED.getCode())
                .orderByDesc(AssetInventoryTask::getCreateTime);
        // 按部门筛选
        if (hasNoPermission) {
            //没有权限,根据盘点人查询任务列表
            taskWrapper.apply("EXISTS (SELECT 1 FROM asset_inventory_task_item item WHERE item.inventory_task_id = id AND item.user_id = {0})", Math.toIntExact(userId));
        }
        try {
            SysUser currentUser = SecurityUtils.getLoginUser().getUser();
            taskWrapper.eq(AssetInventoryTask::getUserId, Math.toIntExact(currentUser.getUserId()));
        } catch (Exception e) {
            // 如果获取用户信息失败,不应用筛选条件
            log.warn("获取当前用户信息失败,不应用'我的任务'筛选条件", e);
            taskWrapper.apply("EXISTS (SELECT 1 FROM asset_inventory_task_item item WHERE item.inventory_task_id = asset_inventory_task.id AND item.user_id = {0})", Math.toIntExact(userId));
        }
        List<AssetInventoryTask> tasks = this.list(taskWrapper);