FileReadServiceImpl.java 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package com.wtkj.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.wtkj.entity.FileRead;
  4. import com.wtkj.mapper.FileReadMapper;
  5. import com.wtkj.service.IFileReadService;
  6. import lombok.AllArgsConstructor;
  7. import org.springblade.core.mp.base.BaseServiceImpl;
  8. import org.springblade.core.secure.utils.AuthUtil;
  9. import org.springblade.core.tool.api.R;
  10. import org.springblade.system.user.entity.User;
  11. import org.springblade.system.user.feign.IUserClient;
  12. import org.springframework.stereotype.Service;
  13. import org.springframework.util.CollectionUtils;
  14. import java.util.ArrayList;
  15. import java.util.List;
  16. import java.util.Set;
  17. import java.util.stream.Collectors;
  18. /**
  19. * @author Blizzard
  20. * @create at 2023-09-15 11:15
  21. * @describe
  22. */
  23. @Service
  24. @AllArgsConstructor
  25. public class FileReadServiceImpl extends BaseServiceImpl<FileReadMapper, FileRead> implements IFileReadService {
  26. private final IUserClient userClient;
  27. @Override
  28. public boolean readFile(FileRead read) {
  29. read.setUserId(AuthUtil.getUserId());
  30. return save(read);
  31. }
  32. @Override
  33. public List<FileRead> getByUser(Long userId) {
  34. return baseMapper.selectByFileIds(userId);
  35. }
  36. @Override
  37. public List<User> fileRead(String bladeFileId) {
  38. List<User> res = new ArrayList<>();
  39. List<Long> userIds = baseMapper.getReadUser(bladeFileId);
  40. if (!CollectionUtils.isEmpty(userIds)) {
  41. Set<User> users = userIds.stream().map(userClient::userInfoById).filter(userR1 -> userR1.isSuccess()).map(R::getData).collect(Collectors.toSet());
  42. res.addAll(users);
  43. }
  44. return res;
  45. }
  46. @Override
  47. public boolean isRead(String bladeFileId, Long userId) {
  48. boolean flag = false;
  49. LambdaQueryWrapper<FileRead> lqw = new LambdaQueryWrapper<>();
  50. lqw.eq(FileRead::getBladeFileId, bladeFileId);
  51. lqw.eq(FileRead::getUserId, userId);
  52. List<FileRead> list = this.list(lqw);
  53. if (!CollectionUtils.isEmpty(list)) {
  54. flag = true;
  55. }
  56. return flag;
  57. }
  58. }