From 2283b4a50d1ec832f958a925e1e30d85d49cbd0f Mon Sep 17 00:00:00 2001 From: Gdk666 <763366136@qq.com> Date: Sun, 16 Oct 2022 19:26:23 +0800 Subject: [PATCH] FIX Data truncation: Data too long for column 'tp_id' at row (#738) (#804) * add BeanUtilTest test case * add BeanUtilTest test case * add BeanUtilTest test case * add ClassUtilTest test case * add ConfigExecutorTest test case * Revert "add ConfigExecutorTest test case" This reverts commit ffc00ff4 * add ConfigExecutorTest test case * add EnvUtilTest test case * add ConfigExecutorTest test case * add Md5ConfigUtilTest test case * Revert "add Md5ConfigUtilTest test case" This reverts commit ee949adc * add Md5ConfigUtilTest test case * Revert "add Md5ConfigUtilTest test case" This reverts commit ed638916 * add Md5ConfigUtilTest test case * FIX Data truncation: Data too long for column 'tp_id' at row (#738) * FIX Data truncation: Data too long for column 'tp_id' at row (#738) --- .../config/service/ConfigCacheService.java | 17 +++++++++++++++++ .../service/biz/impl/HisRunDataServiceImpl.java | 14 +++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/service/ConfigCacheService.java b/hippo4j-config/src/main/java/cn/hippo4j/config/service/ConfigCacheService.java index edeb7ef2..825d5097 100644 --- a/hippo4j-config/src/main/java/cn/hippo4j/config/service/ConfigCacheService.java +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/service/ConfigCacheService.java @@ -68,6 +68,23 @@ public class ConfigCacheService { return Objects.equals(contentMd5, md5); } + /** + * check TpId. + * + * @param groupKey + * @param tpId + * @param clientIdentify + * @return + */ + public static boolean checkTpId(String groupKey, String tpId, String clientIdentify) { + Map cacheItemMap = Optional.ofNullable(CLIENT_CONFIG_CACHE.get(groupKey)).orElse(new HashMap<>()); + CacheItem cacheItem; + if (CollectionUtil.isNotEmpty(cacheItemMap) && (cacheItem = cacheItemMap.get(clientIdentify)) != null) { + return Objects.equals(tpId, cacheItem.configAllInfo.getTpId()); + } + return Boolean.FALSE; + } + /** * Get Md5. * diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/HisRunDataServiceImpl.java b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/HisRunDataServiceImpl.java index 1c4c93af..3e97ef57 100644 --- a/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/HisRunDataServiceImpl.java +++ b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/HisRunDataServiceImpl.java @@ -32,6 +32,7 @@ import cn.hippo4j.config.model.biz.monitor.MonitorActiveRespDTO; import cn.hippo4j.config.model.biz.monitor.MonitorQueryReqDTO; import cn.hippo4j.config.model.biz.monitor.MonitorRespDTO; import cn.hippo4j.config.monitor.QueryMonitorExecuteChoose; +import cn.hippo4j.config.service.ConfigCacheService; import cn.hippo4j.config.service.biz.HisRunDataService; import cn.hippo4j.common.toolkit.BeanUtil; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -150,11 +151,14 @@ public class HisRunDataServiceImpl extends ServiceImpl { HisRunDataInfo hisRunDataInfo = BeanUtil.convert(each, HisRunDataInfo.class); String[] parseKey = GroupKey.parseKey(each.getGroupKey()); - hisRunDataInfo.setTpId(parseKey[0]); - hisRunDataInfo.setItemId(parseKey[1]); - hisRunDataInfo.setTenantId(parseKey[2]); - hisRunDataInfo.setInstanceId(parseKey[3]); - hisRunDataInfos.add(hisRunDataInfo); + boolean checkFlag = ConfigCacheService.checkTpId(each.getGroupKey(), parseKey[0], parseKey[3]); + if (checkFlag) { + hisRunDataInfo.setTpId(parseKey[0]); + hisRunDataInfo.setItemId(parseKey[1]); + hisRunDataInfo.setTenantId(parseKey[2]); + hisRunDataInfo.setInstanceId(parseKey[3]); + hisRunDataInfos.add(hisRunDataInfo); + } }); this.saveBatch(hisRunDataInfos); }