| | |
| | | import com.ruoyi.system.vo.asset.InventoryTaskTabVO; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.context.annotation.Lazy; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | |
| | | @Override |
| | | public IPage<AssetInventoryTaskVO> getInventoryTaskPage(AssertInventoryQuery query) { |
| | | // 1. 构建Lambda查询条件 |
| | | LambdaQueryWrapper<AssetInventoryTask> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.like(StringUtils.isNotBlank(query.getTaskName()), |
| | | AssetInventoryTask::getTaskName, query.getTaskName()) |
| | | .eq(AssetInventoryTask::getDisabled, false) |
| | | .orderByDesc(AssetInventoryTask::getCreateTime); |
| | | // 数据权限:超级管理员/资产管理部查看所有数据,其他部门查看当前及下级部门的数据 |
| | | Long userId = SecurityUtils.getUserId(); |
| | | boolean isAdmin = SecurityUtils.isAdmin(userId); |
| | | |
| | | if (!isAdmin) { |
| | | try { |
| | | // 获取当前用户的部门名称 |
| | | String deptName = sysUserService.selectUserById(userId).getDeptName(); |
| | | |
| | | // 非超级管理员且非资产管理部,设置部门权限 |
| | | if (!AssetDeptConstant.ASSET_INVENTORY_DEPT_NAMES.contains(deptName)) { |
| | | query.setDeptId(Integer.valueOf(SecurityUtils.getLoginUser().getDeptId())); |
| | | } |
| | | } catch (Exception e) { |
| | | // 如果获取部门信息失败,默认设置部门权限 |
| | | try { |
| | | query.setDeptId(Integer.valueOf(SecurityUtils.getLoginUser().getDeptId())); |
| | | } catch (Exception ex) { |
| | | // ignore parse, leave null if cannot parse |
| | | } |
| | | } |
| | | } |
| | | // 2. 构建分页对象 |
| | | Page<AssetInventoryTask> page = new Page<>(query.getPageNum(), query.getPageSize()); |
| | | |
| | | // 3. 执行分页查询 |
| | | IPage<AssetInventoryTask> taskPage = this.page(page, wrapper); |
| | | IPage<AssetInventoryTaskVO> taskPage = this.baseMapper.getPageList(page, query); |
| | | |
| | | // 4. 收集部门ID并去重 |
| | | List<Integer> deptIds = taskPage.getRecords().stream() |
| | | .map(AssetInventoryTask::getDeptId) |
| | | .filter(Objects::nonNull) |
| | | .distinct() |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 5. 批量查询部门信息 |
| | | List<TDept> depts = deptIds.isEmpty() ? |
| | | Collections.emptyList() : |
| | | deptService.listByIds(deptIds); |
| | | |
| | | // 6. 构建部门ID->名称的映射Map |
| | | Map<Integer, String> deptNameMap = depts.stream() |
| | | .collect(Collectors.toMap(TDept::getId, TDept::getDeptName)); |
| | | |
| | | // 7. 使用BeanUtil.copyToList转换VO并填充部门名称 |
| | | List<AssetInventoryTaskVO> voList = BeanUtil.copyToList(taskPage.getRecords(), AssetInventoryTaskVO.class); |
| | | voList.forEach(vo -> { |
| | | if (vo.getDeptId() != null) { |
| | | vo.setDeptName(deptNameMap.get(vo.getDeptId())); |
| | | } |
| | | }); |
| | | |
| | | // 8. 构建返回的分页结果 |
| | | IPage<AssetInventoryTaskVO> resultPage = new Page<>(taskPage.getCurrent(), taskPage.getSize(), taskPage.getTotal()); |
| | | resultPage.setRecords(voList); |
| | | |
| | | return resultPage; |
| | | return taskPage; |
| | | } |
| | | |
| | | @Override |
| | |
| | | // 数据权限:超级管理员/资产管理部、董事长、总经理查看所有数据,其他部门查看当前及下级部门的数据 |
| | | Long userId = SecurityUtils.getUserId(); |
| | | boolean isAdmin = SecurityUtils.isAdmin(userId); |
| | | boolean hasNoPermission = isAdmin; |
| | | boolean hasNoPermission = false; |
| | | if (!isAdmin) { |
| | | try { |
| | | // 获取当前用户的部门名称 |
| | |
| | | |
| | | @Override |
| | | public IPage<AssetMainInventoryVO> getListByTaskId(InventoryTaskQuery query) { |
| | | // 数据权限:超级管理员/资产管理部、董事长、总经理查看所有数据,其他部门查看当前及下级部门的数据 |
| | | Long userId = SecurityUtils.getUserId(); |
| | | boolean isAdmin = SecurityUtils.isAdmin(userId); |
| | | query.setHasNoPermission(Boolean.FALSE); |
| | | query.setUserId(userId); |
| | | if (!isAdmin) { |
| | | try { |
| | | // 获取当前用户的部门名称 |
| | | String deptName = sysUserService.selectUserById(userId).getDeptName(); |
| | | query.setDeptName(deptName); |
| | | // 非超级管理员且非资产管理部,设置部门权限 |
| | | if (!AssetDeptConstant.ASSET_INVENTORY_DEPT_NAMES.contains(deptName)) { |
| | | query.setHasNoPermission(Boolean.TRUE); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("获取当前登录用户部门信息异常", e); |
| | | // 如果获取部门信息失败 |
| | | } |
| | | } |
| | | return baseMapper.getAssetMainInventoryPageList(new Page<>(query.getPageNum(), query.getPageSize()), query); |
| | | } |
| | | |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void saveInventory(List<AssetInventoryTaskItemUpdateDTO> dtoList) { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | Map<Integer, AssetInventoryTaskItemUpdateDTO> dtoMap = dtoList.stream() |
| | | .collect(Collectors.toMap(AssetInventoryTaskItemUpdateDTO::getAssetInventoryTaskItemId, dto -> dto)); |
| | | List<AssetInventoryTaskItem> assetInventoryTaskItems = assetInventoryTaskItemService.listByIds(dtoMap.keySet()); |
| | | |
| | | if (!Integer.valueOf(userId.intValue()).equals(assetInventoryTaskItems.get(0).getUserId())) { |
| | | throw new ServiceException("保存失败,只有指定人员可以操作"); |
| | | } |
| | | for (AssetInventoryTaskItem assetInventoryTaskItem : assetInventoryTaskItems) { |
| | | AssetInventoryTaskItemUpdateDTO dto = dtoMap.get(assetInventoryTaskItem.getId()); |
| | | assetInventoryTaskItem.setResultStatus(dto.getResultStatus()); |