Merge branch 'dev-V0.5.0' into V0.5.x
commit
050ddb6000
|
@ -2,10 +2,16 @@ package cc.iotkit.data.dao;
|
||||||
|
|
||||||
import cc.iotkit.common.api.PageRequest;
|
import cc.iotkit.common.api.PageRequest;
|
||||||
import cc.iotkit.common.api.Paging;
|
import cc.iotkit.common.api.Paging;
|
||||||
|
import cc.iotkit.common.tenant.dao.TenantAware;
|
||||||
|
import cc.iotkit.common.tenant.entiry.BaseTenantEntity;
|
||||||
|
import cc.iotkit.common.tenant.helper.TenantHelper;
|
||||||
import cc.iotkit.common.utils.MapstructUtils;
|
import cc.iotkit.common.utils.MapstructUtils;
|
||||||
|
import cc.iotkit.common.utils.StringUtils;
|
||||||
import cc.iotkit.data.ICommonData;
|
import cc.iotkit.data.ICommonData;
|
||||||
|
import cc.iotkit.data.model.BaseEntity;
|
||||||
import cc.iotkit.data.util.PageBuilder;
|
import cc.iotkit.data.util.PageBuilder;
|
||||||
import cc.iotkit.model.Id;
|
import cc.iotkit.model.Id;
|
||||||
|
import cc.iotkit.model.TenantModel;
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.bean.copier.CopyOptions;
|
import cn.hutool.core.bean.copier.CopyOptions;
|
||||||
import org.springframework.data.domain.Example;
|
import org.springframework.data.domain.Example;
|
||||||
|
@ -55,6 +61,17 @@ public interface IJPACommData<T extends Id<ID>, ID> extends ICommonData<T, ID> {
|
||||||
BeanUtil.copyProperties(tbData, dbObj, CopyOptions.create().ignoreNullValue());
|
BeanUtil.copyProperties(tbData, dbObj, CopyOptions.create().ignoreNullValue());
|
||||||
tbData = dbObj;
|
tbData = dbObj;
|
||||||
}
|
}
|
||||||
|
if (tbData instanceof TenantAware) {
|
||||||
|
String sourceTid = null;
|
||||||
|
if (data instanceof TenantModel) {
|
||||||
|
sourceTid = ((TenantModel) data).getTenantId();
|
||||||
|
}
|
||||||
|
String tenantId = TenantHelper.getTenantId();
|
||||||
|
//未指定租户id,使用当前用户所属租户id
|
||||||
|
if (StringUtils.isBlank(sourceTid) && tenantId != null) {
|
||||||
|
((TenantAware) tbData).setTenantId(tenantId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Object o = getBaseRepository().save(tbData);
|
Object o = getBaseRepository().save(tbData);
|
||||||
return (T) MapstructUtils.convert(o, getTClass());
|
return (T) MapstructUtils.convert(o, getTClass());
|
||||||
|
|
|
@ -7,6 +7,7 @@ import cc.iotkit.common.exception.BizException;
|
||||||
import cc.iotkit.common.oss.core.OssClient;
|
import cc.iotkit.common.oss.core.OssClient;
|
||||||
import cc.iotkit.common.oss.entity.UploadResult;
|
import cc.iotkit.common.oss.entity.UploadResult;
|
||||||
import cc.iotkit.common.oss.enumd.AccessPolicyType;
|
import cc.iotkit.common.oss.enumd.AccessPolicyType;
|
||||||
|
import cc.iotkit.common.oss.exception.OssException;
|
||||||
import cc.iotkit.common.oss.factory.OssFactory;
|
import cc.iotkit.common.oss.factory.OssFactory;
|
||||||
import cc.iotkit.common.utils.MapstructUtils;
|
import cc.iotkit.common.utils.MapstructUtils;
|
||||||
import cc.iotkit.common.utils.SpringUtils;
|
import cc.iotkit.common.utils.SpringUtils;
|
||||||
|
@ -19,6 +20,7 @@ import cc.iotkit.system.service.ISysOssService;
|
||||||
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.convert.Convert;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
@ -33,6 +35,7 @@ import java.util.List;
|
||||||
*
|
*
|
||||||
* @author Lion Li
|
* @author Lion Li
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@Service
|
@Service
|
||||||
public class SysOssServiceImpl implements ISysOssService {
|
public class SysOssServiceImpl implements ISysOssService {
|
||||||
|
@ -81,7 +84,7 @@ public class SysOssServiceImpl implements ISysOssService {
|
||||||
@Override
|
@Override
|
||||||
public SysOssVo upload(MultipartFile file) {
|
public SysOssVo upload(MultipartFile file) {
|
||||||
String originalFileName = file.getOriginalFilename();
|
String originalFileName = file.getOriginalFilename();
|
||||||
if(originalFileName ==null){
|
if (originalFileName == null) {
|
||||||
throw new BizException("文件名为空,获取失败");
|
throw new BizException("文件名为空,获取失败");
|
||||||
}
|
}
|
||||||
String suffix = StringUtils.substring(originalFileName, originalFileName.lastIndexOf("."), originalFileName.length());
|
String suffix = StringUtils.substring(originalFileName, originalFileName.lastIndexOf("."), originalFileName.length());
|
||||||
|
@ -124,11 +127,16 @@ public class SysOssServiceImpl implements ISysOssService {
|
||||||
* @return oss 匹配Url的OSS对象
|
* @return oss 匹配Url的OSS对象
|
||||||
*/
|
*/
|
||||||
private SysOssVo matchingUrl(SysOssVo oss) {
|
private SysOssVo matchingUrl(SysOssVo oss) {
|
||||||
OssClient storage = OssFactory.instance(oss.getService());
|
try {
|
||||||
// 仅修改桶类型为 private 的URL,临时URL时长为120s
|
OssClient storage = OssFactory.instance(oss.getService());
|
||||||
if (AccessPolicyType.PRIVATE == storage.getAccessPolicy()) {
|
// 仅修改桶类型为 private 的URL,临时URL时长为120s
|
||||||
oss.setUrl(storage.getPrivateUrl(oss.getFileName(), 120));
|
if (AccessPolicyType.PRIVATE == storage.getAccessPolicy()) {
|
||||||
|
oss.setUrl(storage.getPrivateUrl(oss.getFileName(), 120));
|
||||||
|
}
|
||||||
|
return oss;
|
||||||
|
} catch (OssException e) {
|
||||||
|
log.error("matchingUrl error", e);
|
||||||
|
return new SysOssVo();
|
||||||
}
|
}
|
||||||
return oss;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue