2025-12-31 18:10:10 +08:00
|
|
|
|
package com.senmesh.sfile.service.impl;
|
|
|
|
|
|
|
2026-01-06 16:37:39 +08:00
|
|
|
|
import com.senmesh.common.exception.util.Assert;
|
2026-01-05 16:35:46 +08:00
|
|
|
|
import com.senmesh.common.util.RandomUtils;
|
2025-12-31 18:10:10 +08:00
|
|
|
|
import com.senmesh.common.util.UserContextHolder;
|
|
|
|
|
|
import com.senmesh.sfile.constant.FileStatusEnum;
|
|
|
|
|
|
import com.senmesh.sfile.constant.RootTypeEnum;
|
|
|
|
|
|
import com.senmesh.sfile.dto.ExpandUserFileCreateDTO;
|
|
|
|
|
|
import com.senmesh.sfile.dto.ShareUserFileCreateDTO;
|
2026-01-06 16:37:39 +08:00
|
|
|
|
import com.senmesh.sfile.dto.UserFileDTO;
|
|
|
|
|
|
import com.senmesh.sfile.dto.UserFileQueryDTO;
|
2026-11-01 20:29:31 +08:00
|
|
|
|
import com.senmesh.sfile.service.FileSecurityService;
|
2025-12-31 18:10:10 +08:00
|
|
|
|
import com.senmesh.sfile.service.ShareUserFileService;
|
|
|
|
|
|
import com.senmesh.sfile.service.UserFileService;
|
2026-01-06 16:37:39 +08:00
|
|
|
|
import java.util.List;
|
2025-12-31 18:10:10 +08:00
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 分享用户文件ServiceImpl
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Service
|
|
|
|
|
|
public class ShareUserFileServiceImpl implements ShareUserFileService {
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private UserFileService userFileService;
|
|
|
|
|
|
|
2026-11-01 20:29:31 +08:00
|
|
|
|
@Autowired
|
|
|
|
|
|
private FileSecurityService fileSecurityService;
|
|
|
|
|
|
|
2025-12-31 18:10:10 +08:00
|
|
|
|
@Override
|
|
|
|
|
|
@Transactional
|
|
|
|
|
|
public Long create(ShareUserFileCreateDTO createDTO) {
|
|
|
|
|
|
Long userFileId = createDTO.getUserFileId();
|
|
|
|
|
|
Long userId = UserContextHolder.getExistLoginUserId();
|
|
|
|
|
|
Integer validDays = createDTO.getValidDays();
|
|
|
|
|
|
|
2026-11-01 20:29:31 +08:00
|
|
|
|
// MeshSafe安全检测校验:单文件不通过直接拦截;文件夹确认跳过时仅分享通过的内容
|
|
|
|
|
|
List<Long> excludeIds = fileSecurityService.resolveShareExclusions(
|
|
|
|
|
|
userFileId, Boolean.TRUE.equals(createDTO.getOnlyPassed()), "分享");
|
|
|
|
|
|
|
2025-12-31 18:10:10 +08:00
|
|
|
|
// 根据有效天数计算过期时间
|
|
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
|
|
calendar.setTime(new Date());
|
|
|
|
|
|
calendar.add(Calendar.DAY_OF_MONTH, validDays);
|
|
|
|
|
|
Date endTime = calendar.getTime();
|
|
|
|
|
|
|
2026-01-05 16:35:46 +08:00
|
|
|
|
// 生成随机6位数字访问码
|
|
|
|
|
|
String accessCode = RandomUtils.nextSixVerificationCode();
|
|
|
|
|
|
|
2025-12-31 18:10:10 +08:00
|
|
|
|
// 调用UserFileService的重载create方法,根据普通文件创建分享文件
|
|
|
|
|
|
ExpandUserFileCreateDTO expandCreateDTO = ExpandUserFileCreateDTO.builder()
|
|
|
|
|
|
.userFileId(userFileId)
|
|
|
|
|
|
.userId(userId)
|
|
|
|
|
|
.rootType(RootTypeEnum.SHARE.getType())
|
|
|
|
|
|
.fileStatus(FileStatusEnum.NORMAL.getStatus())
|
2026-01-05 16:35:46 +08:00
|
|
|
|
.accessCode(accessCode)
|
2025-12-31 18:10:10 +08:00
|
|
|
|
.endTime(endTime)
|
2026-11-01 20:29:31 +08:00
|
|
|
|
.excludeFileIds(excludeIds)
|
2025-12-31 18:10:10 +08:00
|
|
|
|
.build();
|
2026-01-05 16:35:46 +08:00
|
|
|
|
return userFileService.create(expandCreateDTO).getFolder().getId();
|
2025-12-31 18:10:10 +08:00
|
|
|
|
}
|
2026-01-06 16:37:39 +08:00
|
|
|
|
|
|
|
|
|
|
@Override
|
2026-01-10 21:46:51 +08:00
|
|
|
|
public List<UserFileDTO> list(Long id, String accessCode, Long parentId) {
|
2026-01-06 16:37:39 +08:00
|
|
|
|
UserFileDTO userFileDTO = userFileService.findOne(UserFileQueryDTO.builder()
|
|
|
|
|
|
.id(id)
|
|
|
|
|
|
.rootType(RootTypeEnum.SHARE.getType())
|
|
|
|
|
|
.build());
|
|
|
|
|
|
Assert.isTrue(userFileDTO.getAccessCode().equals(accessCode), "访问码不正确");
|
|
|
|
|
|
|
|
|
|
|
|
return userFileService.list(UserFileQueryDTO.builder()
|
|
|
|
|
|
.rootType(RootTypeEnum.SHARE.getType())
|
|
|
|
|
|
.pathLike(userFileDTO.getPath())
|
2026-01-10 21:46:51 +08:00
|
|
|
|
.parentId(parentId)
|
2026-01-06 16:37:39 +08:00
|
|
|
|
.build());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-12-31 18:10:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
|