|
|
@@ -2,20 +2,16 @@ package cn.reghao.oss.console.app.service;
|
|
|
|
|
|
import cn.reghao.jutil.jdk.converter.ByteConverter;
|
|
|
import cn.reghao.jutil.jdk.converter.ByteType;
|
|
|
-import cn.reghao.jutil.jdk.result.Result;
|
|
|
import cn.reghao.oss.console.app.model.dto.ChannelProcessDto;
|
|
|
import cn.reghao.oss.api.dto.ObjectChannel;
|
|
|
import cn.reghao.oss.console.account.service.UserContext;
|
|
|
import cn.reghao.oss.console.app.db.repository.UploadChannelRepository;
|
|
|
import cn.reghao.oss.console.app.model.dto.ChannelScopeDto;
|
|
|
-import cn.reghao.oss.console.app.model.dto.UploadChannelDto;
|
|
|
import cn.reghao.oss.console.app.model.po.StoreNode;
|
|
|
import cn.reghao.oss.console.app.model.po.UploadChannel;
|
|
|
import cn.reghao.oss.console.app.model.po.UserNode;
|
|
|
import cn.reghao.oss.console.app.model.vo.UploadChannelVo;
|
|
|
-import cn.reghao.oss.console.store.rpc.StoreRpcService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -30,64 +26,18 @@ public class UploadChannelService {
|
|
|
private final UploadChannelRepository uploadChannelRepository;
|
|
|
private final UserNodeService userNodeService;
|
|
|
private final StoreNodeService storeNodeService;
|
|
|
- private final StoreRpcService storeRpcService;
|
|
|
|
|
|
public UploadChannelService(UploadChannelRepository uploadChannelRepository, UserNodeService userNodeService,
|
|
|
- StoreNodeService storeNodeService, StoreRpcService storeRpcService) {
|
|
|
+ StoreNodeService storeNodeService) {
|
|
|
this.uploadChannelRepository = uploadChannelRepository;
|
|
|
this.userNodeService = userNodeService;
|
|
|
this.storeNodeService = storeNodeService;
|
|
|
- this.storeRpcService = storeRpcService;
|
|
|
- }
|
|
|
-
|
|
|
- @Transactional(rollbackFor = Exception.class)
|
|
|
- public synchronized Result add(UploadChannelDto uploadChannelDto) {
|
|
|
- int createBy = UserContext.getUser().getId();
|
|
|
- int nodeId = uploadChannelDto.getNodeId();
|
|
|
- UserNode userNode = userNodeService.getUserNode(nodeId, createBy);
|
|
|
- if (userNode == null) {
|
|
|
- return Result.fail(String.format("store_node with id %s not exist", nodeId));
|
|
|
- }
|
|
|
-
|
|
|
- //int createBy = 410;
|
|
|
- String channelPrefix = uploadChannelDto.getChannelPrefix();
|
|
|
- UploadChannel uploadChannel = uploadChannelRepository.findByPrefixAndCreateByAndNodeId(channelPrefix, createBy, nodeId);
|
|
|
- if (uploadChannel != null) {
|
|
|
- return Result.fail(String.format("channel_prefix %s exist", channelPrefix));
|
|
|
- }
|
|
|
-
|
|
|
- uploadChannel = uploadChannelRepository.findByPrefixAndNodeId(channelPrefix, nodeId);
|
|
|
- if (uploadChannel != null) {
|
|
|
- return Result.fail(String.format("someone has already created channel_prefix %s", channelPrefix));
|
|
|
- }
|
|
|
-
|
|
|
- int channelId = getNextChannelId(createBy);
|
|
|
- uploadChannel = new UploadChannel(channelId, uploadChannelDto, createBy);
|
|
|
- uploadChannelRepository.save(uploadChannel);
|
|
|
-
|
|
|
- String domain = userNode.getDomain();
|
|
|
- String name = uploadChannel.getName();
|
|
|
- long maxSize = uploadChannel.getMaxSize();
|
|
|
- int fileType = uploadChannel.getFileType();
|
|
|
- boolean seturl = uploadChannel.getSeturl();
|
|
|
- int scope = uploadChannel.getScope();
|
|
|
- ObjectChannel channel = new ObjectChannel(channelId, name, channelPrefix, maxSize, fileType, seturl, scope, domain, createBy);
|
|
|
-
|
|
|
- StoreNode storeNode = storeNodeService.getById(nodeId);
|
|
|
- storeRpcService.createChannel(storeNode, createBy, channel);
|
|
|
- return Result.success();
|
|
|
- }
|
|
|
-
|
|
|
- private int getNextChannelId(int userId) {
|
|
|
- int channelId = 101;
|
|
|
- int total = uploadChannelRepository.countByCreateBy(userId);
|
|
|
- return channelId + total;
|
|
|
}
|
|
|
|
|
|
public void updateScope(ChannelScopeDto channelScopeDto) {
|
|
|
int id = channelScopeDto.getId();
|
|
|
int newScope = channelScopeDto.getNewScope();
|
|
|
- UploadChannel uploadChannel = uploadChannelRepository.findById(id).orElse(null);
|
|
|
+ UploadChannel uploadChannel = uploadChannelRepository.getOne(id);
|
|
|
if (uploadChannel != null) {
|
|
|
int currentScope = uploadChannel.getScope();
|
|
|
if (currentScope != newScope) {
|
|
|
@@ -99,20 +49,19 @@ public class UploadChannelService {
|
|
|
|
|
|
public void updateSeturl(ChannelProcessDto channelProcessDto) {
|
|
|
int id = channelProcessDto.getId();
|
|
|
- UploadChannel uploadChannel = uploadChannelRepository.findById(id).orElse(null);
|
|
|
+ UploadChannel uploadChannel = uploadChannelRepository.getOne(id);
|
|
|
if (uploadChannel != null) {
|
|
|
boolean seturl = channelProcessDto.getSeturl();
|
|
|
boolean current = uploadChannel.getSeturl();
|
|
|
if (seturl != current) {
|
|
|
uploadChannel.setSeturl(seturl);
|
|
|
uploadChannelRepository.save(uploadChannel);
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public List<UploadChannelVo> getUploadChannels() {
|
|
|
- int loginUser = UserContext.getUser().getId();
|
|
|
+ int loginUser = UserContext.getUserId();
|
|
|
List<UploadChannel> page = uploadChannelRepository.findByCreateBy(loginUser);
|
|
|
List<UploadChannelVo> list = page.stream().map(uploadChannel -> {
|
|
|
long maxSize = uploadChannel.getMaxSize();
|
|
|
@@ -127,7 +76,7 @@ public class UploadChannelService {
|
|
|
}
|
|
|
|
|
|
public UploadChannel getUploadChannel(int id) {
|
|
|
- return uploadChannelRepository.findById(id).orElse(null);
|
|
|
+ return uploadChannelRepository.getOne(id);
|
|
|
}
|
|
|
|
|
|
public UploadChannel getByChannelIdAndCreateBy(int channelId, int createBy) {
|