Browse Source

修改批量插入tablestore工具类的bug

tanzhongran 3 years ago
parent
commit
95af899ae6

+ 3 - 1
abi-cloud-qr-platform-common/src/main/java/com/abi/task/common/tablestore/TableStorePlusUtils.java

@@ -70,7 +70,6 @@ public class TableStorePlusUtils {
                 //主键的值
                 String primaryKeyVal = null;
 
-
                 //column列表  循环放入字段
                 Field[] fields = entity.getClass().getDeclaredFields();
                 for (Field field : fields) {
@@ -88,6 +87,9 @@ public class TableStorePlusUtils {
                         primaryKeyVal = (String) fieldValue;
                         continue;
                     }
+                    if(fieldValue==null){
+                        continue;
+                    }
                     //放入table的column
                     Column column = null;
                     if (fieldValue instanceof String) {

+ 1 - 5
abi-cloud-qr-platform-common/src/main/java/com/abi/task/common/utils/TableStoreUtils.java

@@ -129,11 +129,7 @@ public class TableStoreUtils {
         BatchWriteRowRequest batchWriteRowRequest = new BatchWriteRowRequest();
         //构造rowPutChange
         for(int i=0;i<pkValueList.size();i++){
-            String pkValue = pkValueList.get(0);
-            List<Column> columns = columnsList.get(0);
-            RowPutChange rowPutChange = buildRowPutChange(primaryKeyName, pkValue, tableName, columns);
-            //添加属性列
-            rowPutChange.addColumns(columns);
+            RowPutChange rowPutChange = buildRowPutChange(primaryKeyName, pkValueList.get(i), tableName, columnsList.get(i));
             //添加到batch操作中。
             batchWriteRowRequest.addRowChange(rowPutChange);
         }

+ 7 - 7
abi-cloud-qr-platform-server/src/test/java/com/abi/qms/platform/TableStorePlusTest.java

@@ -29,13 +29,13 @@ public class TableStorePlusTest {
         entity.setIsDog(false);
 
         DemoEntity entity2 = new DemoEntity();
-        entity.setQrCode("10293827182716");
-        entity.setActName("活动2");
-        entity.setPayAmount(990.12);
-        entity.setCurrentTime(LocalDateTime.now());
-        entity.setUserId(10001L);
-        entity.setActiveCount(33);
-        entity.setIsDog(false);
+        entity2.setQrCode("10293827182716");
+        entity2.setActName("活动2");
+        entity2.setPayAmount(990.12);
+        entity2.setCurrentTime(LocalDateTime.now());
+        entity2.setUserId(10001L);
+        entity2.setActiveCount(33);
+        entity2.setIsDog(false);
 
         tableStorePlusUtils.putRow(Arrays.asList(entity,entity2));
     }