From b47756096d78bfd05bad7ab82efe631b153d2825 Mon Sep 17 00:00:00 2001 From: xiwa Date: Sat, 16 Mar 2024 15:46:00 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=E6=95=B0=E6=8D=AE=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E5=A1=AB=E5=85=85=E7=A7=9F=E6=88=B7id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cc/iotkit/data/dao/IJPACommData.java | 8 ++++++++ .../service/impl/SysOssServiceImpl.java | 20 +++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) 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..1ae68f3d 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,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, ID> extends ICommonData { 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()); 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; } } From 85a0ccedb5db3d33d7480b85043f563f4762ea79 Mon Sep 17 00:00:00 2001 From: xiwa Date: Mon, 18 Mar 2024 23:26:33 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=E6=95=B0=E6=8D=AE=E5=85=A5=E5=BA=93?= =?UTF-8?q?=E7=A7=9F=E6=88=B7id=E5=A1=AB=E5=85=85=E4=B8=8D=E6=AD=A3?= =?UTF-8?q?=E7=A1=AE=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/cc/iotkit/data/dao/IJPACommData.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 1ae68f3d..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 @@ -6,6 +6,7 @@ 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; @@ -61,7 +62,15 @@ public interface IJPACommData, ID> extends ICommonData { tbData = dbObj; } if (tbData instanceof TenantAware) { - ((TenantAware) tbData).setTenantId(TenantHelper.getTenantId()); + 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);