fix:数据保存填充租户id

V0.5.x
xiwa 2024-03-16 15:46:00 +08:00
parent 8ab1ffab38
commit b47756096d
2 changed files with 22 additions and 6 deletions

View File

@ -2,10 +2,15 @@ package cc.iotkit.data.dao;
import cc.iotkit.common.api.PageRequest;
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.data.ICommonData;
import cc.iotkit.data.model.BaseEntity;
import cc.iotkit.data.util.PageBuilder;
import cc.iotkit.model.Id;
import cc.iotkit.model.TenantModel;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import org.springframework.data.domain.Example;
@ -55,6 +60,9 @@ public interface IJPACommData<T extends Id<ID>, ID> extends ICommonData<T, ID> {
BeanUtil.copyProperties(tbData, dbObj, CopyOptions.create().ignoreNullValue());
tbData = dbObj;
}
if (tbData instanceof TenantAware) {
((TenantAware) tbData).setTenantId(TenantHelper.getTenantId());
}
Object o = getBaseRepository().save(tbData);
return (T) MapstructUtils.convert(o, getTClass());

View File

@ -7,6 +7,7 @@ import cc.iotkit.common.exception.BizException;
import cc.iotkit.common.oss.core.OssClient;
import cc.iotkit.common.oss.entity.UploadResult;
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.utils.MapstructUtils;
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.util.ObjectUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
@ -33,6 +35,7 @@ import java.util.List;
*
* @author Lion Li
*/
@Slf4j
@RequiredArgsConstructor
@Service
public class SysOssServiceImpl implements ISysOssService {
@ -81,7 +84,7 @@ public class SysOssServiceImpl implements ISysOssService {
@Override
public SysOssVo upload(MultipartFile file) {
String originalFileName = file.getOriginalFilename();
if(originalFileName ==null){
if (originalFileName == null) {
throw new BizException("文件名为空,获取失败");
}
String suffix = StringUtils.substring(originalFileName, originalFileName.lastIndexOf("."), originalFileName.length());
@ -124,11 +127,16 @@ public class SysOssServiceImpl implements ISysOssService {
* @return oss UrlOSS
*/
private SysOssVo matchingUrl(SysOssVo oss) {
OssClient storage = OssFactory.instance(oss.getService());
// 仅修改桶类型为 private 的URL临时URL时长为120s
if (AccessPolicyType.PRIVATE == storage.getAccessPolicy()) {
oss.setUrl(storage.getPrivateUrl(oss.getFileName(), 120));
try {
OssClient storage = OssFactory.instance(oss.getService());
// 仅修改桶类型为 private 的URL临时URL时长为120s
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;
}
}