diff --git a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/IJPACommData.java b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/IJPACommData.java index f4f711ef..8fb67257 100644 --- a/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/IJPACommData.java +++ b/iot-dao/iot-data-serviceImpl-rdb/src/main/java/cc/iotkit/data/dao/IJPACommData.java @@ -2,10 +2,16 @@ 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.common.utils.StringUtils; 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 +61,17 @@ public interface IJPACommData, ID> extends ICommonData { BeanUtil.copyProperties(tbData, dbObj, CopyOptions.create().ignoreNullValue()); 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); return (T) MapstructUtils.convert(o, getTClass()); diff --git a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysOssServiceImpl.java b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysOssServiceImpl.java index 7f9e08ca..dc3cbc92 100644 --- a/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysOssServiceImpl.java +++ b/iot-module/iot-system/src/main/java/cc/iotkit/system/service/impl/SysOssServiceImpl.java @@ -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 匹配Url的OSS对象 */ 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; } }