|
|
@@ -7,18 +7,17 @@ import cn.reghao.jutil.jdk.result.ResultStatus;
|
|
|
import cn.reghao.oss.api.dto.ObjectChannel;
|
|
|
import cn.reghao.oss.sdk.model.constant.ObjectScope;
|
|
|
import cn.reghao.oss.sdk.model.constant.ObjectType;
|
|
|
-import cn.reghao.tnb.common.auth.UserContext;
|
|
|
import cn.reghao.tnb.file.app.db.mapper.UploadChannelMapper;
|
|
|
+import cn.reghao.tnb.file.app.db.repository.ChannelRepository;
|
|
|
import cn.reghao.tnb.file.app.model.constant.UploadChannelType;
|
|
|
import cn.reghao.tnb.file.app.model.dto.UploadChannelDto;
|
|
|
import cn.reghao.tnb.file.app.model.po.UploadChannel;
|
|
|
import cn.reghao.tnb.file.app.model.po.UserNode;
|
|
|
import cn.reghao.tnb.file.app.model.vo.UploadChannelInfo;
|
|
|
+import cn.reghao.tnb.file.app.model.vo.UserNodeInfo;
|
|
|
import cn.reghao.tnb.file.app.rpc.StoreServiceWrapper;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -33,15 +32,17 @@ public class UploadChannelService {
|
|
|
private final UserNodeService userNodeService;
|
|
|
private final StoreServiceWrapper storeServiceWrapper;
|
|
|
private final StoreConfigService storeConfigService;
|
|
|
+ private final ChannelRepository channelRepository;
|
|
|
|
|
|
public UploadChannelService(ByteConverter byteConverter, UploadChannelMapper uploadChannelMapper,
|
|
|
UserNodeService userNodeService, StoreServiceWrapper storeServiceWrapper,
|
|
|
- StoreConfigService storeConfigService) {
|
|
|
+ StoreConfigService storeConfigService, ChannelRepository channelRepository) {
|
|
|
this.byteConverter = byteConverter;
|
|
|
this.uploadChannelMapper = uploadChannelMapper;
|
|
|
this.userNodeService = userNodeService;
|
|
|
this.storeServiceWrapper = storeServiceWrapper;
|
|
|
this.storeConfigService = storeConfigService;
|
|
|
+ this.channelRepository = channelRepository;
|
|
|
}
|
|
|
|
|
|
public synchronized Result addObjectChannel(UploadChannelDto uploadChannelDto) throws Exception {
|
|
|
@@ -60,30 +61,20 @@ public class UploadChannelService {
|
|
|
|
|
|
int channelCode = getNextChannelCode(createBy);
|
|
|
uploadChannel = new UploadChannel(channelCode, uploadChannelDto, (int) createBy);
|
|
|
- createUploadChannel(uploadChannel);
|
|
|
+ channelRepository.createUploadChannel(uploadChannel);
|
|
|
return Result.success();
|
|
|
}
|
|
|
|
|
|
- public void createUploadChannel(int ossUser, int userNodeId) {
|
|
|
- Arrays.asList(UploadChannelType.values()).forEach(uploadChannelType -> {
|
|
|
- try {
|
|
|
+ public void initUploadChannel() throws Exception {
|
|
|
+ int ossUser = storeConfigService.getLocalOssUser();
|
|
|
+ List<UserNodeInfo> list = userNodeService.getUserNodes(ossUser);
|
|
|
+ if (list.size() == 1 && uploadChannelMapper.findByCreateBy(ossUser).isEmpty()) {
|
|
|
+ int userNodeId = list.get(0).getUserNodeId();
|
|
|
+ for (UploadChannelType uploadChannelType : UploadChannelType.values()) {
|
|
|
UploadChannel uploadChannel = new UploadChannel(userNodeId, uploadChannelType, ossUser);
|
|
|
- createUploadChannel(uploadChannel);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ channelRepository.createUploadChannel(uploadChannel);
|
|
|
}
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public void createUploadChannel(UploadChannel uploadChannel) throws Exception {
|
|
|
- uploadChannelMapper.save(uploadChannel);
|
|
|
-
|
|
|
- int userNodeId = uploadChannel.getUserNodeId();
|
|
|
- String prefix = uploadChannel.getPrefix();
|
|
|
- int scope = uploadChannel.getScope();
|
|
|
- int ossUser = storeConfigService.getLocalOssUser();
|
|
|
- storeServiceWrapper.createChannel(userNodeId, prefix, scope, ossUser);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private int getNextChannelCode(long createBy) {
|