This is an automated email from the ASF dual-hosted git repository.

dockerzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/inlong.git


The following commit(s) were added to refs/heads/master by this push:
     new e85406305 [INLONG-7586][Manager] Fix the audit information in the 
database cannot be obtained after being updated (#7587)
e85406305 is described below

commit e85406305d305f8ca21b70ffc2b7c26cceb5313e
Author: fuweng11 <[email protected]>
AuthorDate: Tue Mar 14 09:51:15 2023 +0800

    [INLONG-7586][Manager] Fix the audit information in the database cannot be 
obtained after being updated (#7587)
---
 .../inlong/manager/dao/mapper/AuditBaseEntityMapper.java  |  2 ++
 .../src/main/resources/mappers/AuditBaseEntityMapper.xml  | 13 +++++++++++++
 .../manager/service/core/impl/AuditServiceImpl.java       | 15 ++++++++++-----
 3 files changed, 25 insertions(+), 5 deletions(-)

diff --git 
a/inlong-manager/manager-dao/src/main/java/org/apache/inlong/manager/dao/mapper/AuditBaseEntityMapper.java
 
b/inlong-manager/manager-dao/src/main/java/org/apache/inlong/manager/dao/mapper/AuditBaseEntityMapper.java
index 8ab30c2c1..d1eb93a4a 100644
--- 
a/inlong-manager/manager-dao/src/main/java/org/apache/inlong/manager/dao/mapper/AuditBaseEntityMapper.java
+++ 
b/inlong-manager/manager-dao/src/main/java/org/apache/inlong/manager/dao/mapper/AuditBaseEntityMapper.java
@@ -34,4 +34,6 @@ public interface AuditBaseEntityMapper {
 
     AuditBaseEntity selectByType(@Param("type") String type);
 
+    AuditBaseEntity selectByTypeAndIsSent(@Param("type") String type, 
@Param("isSent") Integer isSent);
+
 }
diff --git 
a/inlong-manager/manager-dao/src/main/resources/mappers/AuditBaseEntityMapper.xml
 
b/inlong-manager/manager-dao/src/main/resources/mappers/AuditBaseEntityMapper.xml
index 8586ab43a..6746071e7 100644
--- 
a/inlong-manager/manager-dao/src/main/resources/mappers/AuditBaseEntityMapper.xml
+++ 
b/inlong-manager/manager-dao/src/main/resources/mappers/AuditBaseEntityMapper.xml
@@ -61,5 +61,18 @@
             </if>
         </where>
     </select>
+    <select id="selectByTypeAndIsSent" 
resultType="org.apache.inlong.manager.dao.entity.AuditBaseEntity">
+        select
+        <include refid="Base_Column_List"/>
+        from audit_base
+        <where>
+            <if test="type != null and type != ''">
+                and type = #{type, jdbcType=VARCHAR}
+            </if>
+            <if test="isSent != null and isSent != ''">
+                and is_sent = #{isSent,jdbcType=INTEGER}
+            </if>
+        </where>
+    </select>
 
 </mapper>
diff --git 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/impl/AuditServiceImpl.java
 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/impl/AuditServiceImpl.java
index cd1305e84..5ba805875 100644
--- 
a/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/impl/AuditServiceImpl.java
+++ 
b/inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/impl/AuditServiceImpl.java
@@ -25,7 +25,6 @@ import 
org.apache.inlong.manager.common.enums.AuditQuerySource;
 import org.apache.inlong.manager.common.enums.ClusterType;
 import org.apache.inlong.manager.common.enums.ErrorCodeEnum;
 import org.apache.inlong.manager.common.enums.TimeStaticsDim;
-import org.apache.inlong.manager.common.exceptions.BusinessException;
 import org.apache.inlong.manager.common.util.Preconditions;
 import org.apache.inlong.manager.dao.entity.AuditBaseEntity;
 import org.apache.inlong.manager.dao.entity.StreamSinkEntity;
@@ -64,7 +63,6 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.PostConstruct;
-
 import java.math.BigDecimal;
 import java.sql.Connection;
 import java.sql.ResultSet;
@@ -160,9 +158,16 @@ public class AuditServiceImpl implements AuditService {
             return null;
         }
         AuditBaseEntity auditBaseEntity = isSent ? auditSentItemMap.get(type) 
: auditReceivedItemMap.get(type);
-        if (auditBaseEntity == null) {
-            throw new 
BusinessException(ErrorCodeEnum.AUDIT_ID_TYPE_NOT_SUPPORTED,
-                    
String.format(ErrorCodeEnum.AUDIT_ID_TYPE_NOT_SUPPORTED.getMessage(), type));
+        if (auditBaseEntity != null) {
+            return auditBaseEntity.getAuditId();
+        }
+        auditBaseEntity = auditBaseMapper.selectByTypeAndIsSent(type, isSent ? 
1 : 0);
+        Preconditions.expectNotNull(auditBaseEntity, 
ErrorCodeEnum.AUDIT_ID_TYPE_NOT_SUPPORTED,
+                
String.format(ErrorCodeEnum.AUDIT_ID_TYPE_NOT_SUPPORTED.getMessage(), type));
+        if (isSent) {
+            auditSentItemMap.put(type, auditBaseEntity);
+        } else {
+            auditReceivedItemMap.put(type, auditBaseEntity);
         }
         return auditBaseEntity.getAuditId();
     }

Reply via email to