This is an automated email from the ASF dual-hosted git repository.
Aias00 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 6cb422f5ae fix: bind the ai proxy api key timestamps instead of the
MySQL-only NOW(3) (#6693) (#7178)
6cb422f5ae is described below
commit 6cb422f5aefb0079d8fdbd67cd18d115a985f8cb
Author: HY-love-sleep <[email protected]>
AuthorDate: Thu Sep 24 11:08:40 2026 +0800
fix: bind the ai proxy api key timestamps instead of the MySQL-only NOW(3)
(#6693) (#7178)
---
.../shenyu/admin/mapper/AiProxyApiKeyMapper.java | 4 ++-
.../service/impl/AiProxyApiKeyServiceImpl.java | 7 +++-
.../resources/mappers/ai-proxy-api-key-sqlmap.xml | 13 ++++----
.../service/impl/AiProxyApiKeyServiceImplTest.java | 39 ++++++++++++++++++++--
4 files changed, 53 insertions(+), 10 deletions(-)
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/AiProxyApiKeyMapper.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/AiProxyApiKeyMapper.java
index 20c11f4267..476734a799 100644
---
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/AiProxyApiKeyMapper.java
+++
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/mapper/AiProxyApiKeyMapper.java
@@ -25,6 +25,7 @@ import org.apache.shenyu.admin.model.vo.ProxyApiKeyVO;
import org.apache.shenyu.admin.validation.ExistProvider;
import java.io.Serializable;
+import java.sql.Timestamp;
import java.util.List;
/**
@@ -66,7 +67,8 @@ public interface AiProxyApiKeyMapper extends ExistProvider {
int updateSelective(ProxyApiKeyDO entity);
- int updateEnableBatch(@Param("idList") List<String> idList,
@Param("enabled") Boolean enabled);
+ int updateEnableBatch(@Param("idList") List<String> idList,
@Param("enabled") Boolean enabled,
+ @Param("dateUpdated") Timestamp dateUpdated);
int delete(String id);
diff --git
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/AiProxyApiKeyServiceImpl.java
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/AiProxyApiKeyServiceImpl.java
index c3d771800b..1d1c84afa9 100644
---
a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/AiProxyApiKeyServiceImpl.java
+++
b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/AiProxyApiKeyServiceImpl.java
@@ -48,6 +48,7 @@ import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
+import java.sql.Timestamp;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@@ -104,6 +105,9 @@ public class AiProxyApiKeyServiceImpl implements
AiProxyApiKeyService {
dto.setId(entity.getId());
dto.setProxyApiKey(entity.getProxyApiKey());
dto.setEnabled(entity.getEnabled());
+ final Timestamp now = new Timestamp(System.currentTimeMillis());
+ entity.setDateCreated(now);
+ entity.setDateUpdated(now);
final int rows = mapper.insert(entity);
publishChange(DataEventTypeEnum.CREATE, entity);
return rows;
@@ -117,6 +121,7 @@ public class AiProxyApiKeyServiceImpl implements
AiProxyApiKeyService {
if (Objects.isNull(entity) || StringUtils.isBlank(entity.getId())) {
return 0;
}
+ entity.setDateUpdated(new Timestamp(System.currentTimeMillis()));
int rows = mapper.updateSelective(entity);
publishChange(DataEventTypeEnum.UPDATE, entity);
return rows;
@@ -171,7 +176,7 @@ public class AiProxyApiKeyServiceImpl implements
AiProxyApiKeyService {
if (CollectionUtils.isEmpty(ids) || Objects.isNull(enabled)) {
return ShenyuResultMessage.PARAMETER_ERROR;
}
- int rows = mapper.updateEnableBatch(ids, enabled);
+ int rows = mapper.updateEnableBatch(ids, enabled, new
Timestamp(System.currentTimeMillis()));
if (rows > 0) {
final List<ProxyApiKeyDO> updated = mapper.selectByIds(ids);
if (Objects.nonNull(updated) && !updated.isEmpty()) {
diff --git
a/shenyu-admin/src/main/resources/mappers/ai-proxy-api-key-sqlmap.xml
b/shenyu-admin/src/main/resources/mappers/ai-proxy-api-key-sqlmap.xml
index 3fb7f42caf..73900e59de 100644
--- a/shenyu-admin/src/main/resources/mappers/ai-proxy-api-key-sqlmap.xml
+++ b/shenyu-admin/src/main/resources/mappers/ai-proxy-api-key-sqlmap.xml
@@ -129,7 +129,8 @@
INSERT INTO proxy_api_key_mapping (
id, proxy_api_key, description, enabled, namespace_id,
selector_id, date_created, date_updated
) VALUES (
- #{id}, #{proxyApiKey}, #{description}, #{enabled}, #{namespaceId},
#{selectorId}, NOW(3), NOW(3)
+ #{id}, #{proxyApiKey}, #{description}, #{enabled}, #{namespaceId},
#{selectorId},
+ #{dateCreated, jdbcType=TIMESTAMP}, #{dateUpdated,
jdbcType=TIMESTAMP}
)
</insert>
@@ -152,8 +153,8 @@
<if test="enabled != null">#{enabled},</if>
<if test="namespaceId != null">#{namespaceId},</if>
<if test="selectorId != null">#{selectorId},</if>
- NOW(3),
- NOW(3)
+ #{dateCreated, jdbcType=TIMESTAMP},
+ #{dateUpdated, jdbcType=TIMESTAMP}
</trim>
</insert>
@@ -166,7 +167,7 @@
enabled = #{enabled},
namespace_id = #{namespaceId},
selector_id = #{selectorId},
- date_updated = NOW(3)
+ date_updated = #{dateUpdated, jdbcType=TIMESTAMP}
WHERE id = #{id}
</update>
@@ -178,14 +179,14 @@
<if test="enabled != null">enabled = #{enabled},</if>
<if test="namespaceId != null">namespace_id = #{namespaceId},</if>
<if test="selectorId != null">selector_id = #{selectorId},</if>
- date_updated = NOW(3)
+ date_updated = #{dateUpdated, jdbcType=TIMESTAMP}
</set>
WHERE id = #{id}
</update>
<update id="updateEnableBatch">
UPDATE proxy_api_key_mapping
- SET enabled = #{enabled}, date_updated = NOW(3)
+ SET enabled = #{enabled}, date_updated = #{dateUpdated,
jdbcType=TIMESTAMP}
WHERE id IN
<foreach collection="idList" item="id" open="(" separator="," close=")">
#{id}
diff --git
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/impl/AiProxyApiKeyServiceImplTest.java
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/impl/AiProxyApiKeyServiceImplTest.java
index 5a61614c3b..11038dc81c 100644
---
a/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/impl/AiProxyApiKeyServiceImplTest.java
+++
b/shenyu-admin/src/test/java/org/apache/shenyu/admin/service/impl/AiProxyApiKeyServiceImplTest.java
@@ -34,6 +34,7 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.context.ApplicationEventPublisher;
+import java.sql.Timestamp;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -91,7 +92,7 @@ class AiProxyApiKeyServiceImplTest {
@Test
void testEnabledPublishesEvent() {
- when(mapper.updateEnableBatch(any(), any())).thenReturn(1);
+ when(mapper.updateEnableBatch(any(), any(), any())).thenReturn(1);
ProxyApiKeyDO e = new ProxyApiKeyDO();
e.setId("1");
e.setProxyApiKey("p");
@@ -178,4 +179,38 @@ class AiProxyApiKeyServiceImplTest {
service.delete(Collections.singletonList("1"));
verify(publisher, never()).publishEvent(any());
}
-}
\ No newline at end of file
+
+ @Test
+ void testCreateSetsTimestamps() {
+ ProxyApiKeyDTO dto = new ProxyApiKeyDTO();
+ dto.setNamespaceId("default");
+ when(mapper.insert(any())).thenReturn(1);
+ service.create(dto, "sel-1");
+ ArgumentCaptor<ProxyApiKeyDO> captor =
ArgumentCaptor.forClass(ProxyApiKeyDO.class);
+ verify(mapper).insert(captor.capture());
+ assertNotNull(captor.getValue().getDateCreated());
+ assertNotNull(captor.getValue().getDateUpdated());
+ }
+
+ @Test
+ void testUpdateSetsUpdatedTimestamp() {
+ ProxyApiKeyDTO dto = new ProxyApiKeyDTO();
+ dto.setId("id-1");
+ dto.setNamespaceId("default");
+ when(mapper.updateSelective(any())).thenReturn(1);
+ service.update(dto);
+ ArgumentCaptor<ProxyApiKeyDO> captor =
ArgumentCaptor.forClass(ProxyApiKeyDO.class);
+ verify(mapper).updateSelective(captor.capture());
+ assertNotNull(captor.getValue().getDateUpdated());
+ }
+
+ @Test
+ void testEnabledPassesUpdatedTimestamp() {
+ when(mapper.updateEnableBatch(any(), any(), any())).thenReturn(1);
+ when(mapper.selectByIds(any())).thenReturn(Collections.emptyList());
+ service.enabled(Collections.singletonList("1"), Boolean.TRUE);
+ ArgumentCaptor<Timestamp> captor =
ArgumentCaptor.forClass(Timestamp.class);
+ verify(mapper).updateEnableBatch(any(), any(), captor.capture());
+ assertNotNull(captor.getValue());
+ }
+}