fix 校验Property是否为空,解决将序列化当作字段bug

This commit is contained in:
cxc 2024-12-19 09:15:09 +08:00
parent 51cc4ed9df
commit 4c17b0a003
2 changed files with 14 additions and 4 deletions

View File

@ -114,8 +114,10 @@ public class LambdaInsertWrapper<T> extends AbstractChainWrapper<T> implements
String key = entry.getKey(); String key = entry.getKey();
Object value = entry.getValue(); Object value = entry.getValue();
String tk = propertyCache.functionToPropertyMap.get(key); String tk = propertyCache.functionToPropertyMap.get(key);
if (StringUtils.isNotEmpty(tk)) {
GsonUtil.put(jsonObject,tk,value); GsonUtil.put(jsonObject,tk,value);
} }
}
if(conversionCache.isAutoID()){ if(conversionCache.isAutoID()){
GsonUtil.put(jsonObject,pk,IdWorkerUtils.nextId()); GsonUtil.put(jsonObject,pk,IdWorkerUtils.nextId());

View File

@ -676,6 +676,9 @@ public class LambdaUpdateWrapper<T> extends AbstractChainWrapper<T> implements W
public MilvusResp<UpsertResp> update(T entity) throws MilvusException { public MilvusResp<UpsertResp> update(T entity) throws MilvusException {
// 获取主键字段 // 获取主键字段
String primaryKeyField = CollectionToPrimaryCache.collectionToPrimary.get(collectionName); String primaryKeyField = CollectionToPrimaryCache.collectionToPrimary.get(collectionName);
if (StringUtils.isNotEmpty(primaryKeyField)) {
throw new MilvusException("not find primary key", 400);
}
// 将实体转换为属性映射 // 将实体转换为属性映射
Map<String, Object> propertiesMap = getPropertiesMap(entity); Map<String, Object> propertiesMap = getPropertiesMap(entity);
PropertyCache propertyCache = conversionCache.getPropertyCache(); PropertyCache propertyCache = conversionCache.getPropertyCache();
@ -695,9 +698,12 @@ public class LambdaUpdateWrapper<T> extends AbstractChainWrapper<T> implements W
hasPrimaryKey = true; hasPrimaryKey = true;
primaryKeyValue = value; primaryKeyValue = value;
} }
// 校验是否为空
if (StringUtils.isNotEmpty(tableNameColumn)) {
// 添加到更新对象 // 添加到更新对象
GsonUtil.put(updateObject,tableNameColumn, value); GsonUtil.put(updateObject,tableNameColumn, value);
} }
}
// 检查是否需要构建查询条件 // 检查是否需要构建查询条件
boolean needBuildQuery = !hasPrimaryKey; boolean needBuildQuery = !hasPrimaryKey;
if (hasPrimaryKey) { if (hasPrimaryKey) {
@ -783,8 +789,10 @@ public class LambdaUpdateWrapper<T> extends AbstractChainWrapper<T> implements W
Object value = entry.getValue(); Object value = entry.getValue();
// 根据PropertyCache转换属性名 // 根据PropertyCache转换属性名
String tk = propertyCache.functionToPropertyMap.get(key); String tk = propertyCache.functionToPropertyMap.get(key);
if (StringUtils.isNotEmpty(tk)) {
GsonUtil.put(jsonObject,tk, value); GsonUtil.put(jsonObject,tk, value);
} }
}
// 检查是否包含主键 // 检查是否包含主键
if (!jsonObject.has(pk)) { if (!jsonObject.has(pk)) {
throw new MilvusException("not find primary key", 400); throw new MilvusException("not find primary key", 400);