From 9a9b747962cc00801d8cce4137d1e123d556a79b Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期六, 02 十一月 2024 16:59:59 +0800
Subject: [PATCH] 修复iotdb大批插入数据问题

---
 collect/src/main/java/com/qianwen/mdc/collect/service/DeviceStateService.java |   38 ++++++--------------------------------
 1 files changed, 6 insertions(+), 32 deletions(-)

diff --git a/collect/src/main/java/com/qianwen/mdc/collect/service/DeviceStateService.java b/collect/src/main/java/com/qianwen/mdc/collect/service/DeviceStateService.java
index 15eaad5..a59fce6 100644
--- a/collect/src/main/java/com/qianwen/mdc/collect/service/DeviceStateService.java
+++ b/collect/src/main/java/com/qianwen/mdc/collect/service/DeviceStateService.java
@@ -94,9 +94,7 @@
 			
 			Tablet tablet = new Tablet(deviceId, schemas);
 			
-			
 			states = entry.getValue();
-			tablet.rowSize = states.size();
 			DeviceState state;
 			
 			
@@ -104,9 +102,10 @@
 			//int currentIdx = 0;
 		
 				
-			int tblIndex = 0;
+			int tblIndex = -1;
 			for(int i=0; i < states.size(); i++) {
 				state = states.get(i);
+				tblIndex = tablet.rowSize++;
 				tablet.addTimestamp(tblIndex, state.getTime());
 				tablet.addValue("workstation_id", tblIndex, state.getWorkstationId());
 				tablet.addValue("value_collect", tblIndex, state.getValueCollect());
@@ -128,7 +127,7 @@
 				tablet.addValue("is_deleted", tblIndex, state.getIsDeleted());
 				tablet.addValue("employee_id", tblIndex, state.getEmployeeId());
 				
-				tblIndex++;
+				//tblIndex++;
 				
 				if(tblIndex >= MAX_COUNT) {
 					try {
@@ -136,49 +135,24 @@
 						this.iotdbConfig.getSessionPool().insertAlignedTablet(tablet);
 						log.info("淇濆瓨璁惧鐘舵�佸畬鎴�");
 						tablet.reset();
-						tblIndex = 0;
+						tblIndex = -1;
 					} catch (Exception e) {
 						log.error("淇濆瓨鍥哄畾鐐规暟鎹紓甯�",e);
 					} 
 				}
 			}
 			
-			if(tblIndex > 0) {
+			if(tablet.rowSize > 0) {
 				try {
 					//姣忎釜宸ヤ綅鎵归噺鎻掑叆涓�娆℃暟鎹�
 					this.iotdbConfig.getSessionPool().insertAlignedTablet(tablet);
 					log.info("淇濆瓨璁惧鐘舵�佸畬鎴�2");
 					tablet.reset();
-					tblIndex = 0;
+					//tblIndex = -1;
 				} catch (Exception e) {
 					log.error("淇濆瓨鍥哄畾鐐规暟鎹紓甯�",e);
 				} 
 			}
-			
-			/*
-			for(int i=0;i<states.size();i++) {
-				state = states.get(i);
-				tablet.addTimestamp(i, state.getTime());
-				tablet.addValue("workstation_id", i, state.getWorkstationId());
-				tablet.addValue("value_collect", i, state.getValueCollect());
-				
-				tablet.addValue("calendar_code", i, state.getCalendarCode());
-				tablet.addValue("factory_year", i, state.getFactoryYear());
-				tablet.addValue("factory_month", i, state.getFactoryMonth());
-				tablet.addValue("factory_week", i, state.getFactoryWeek());
-				tablet.addValue("factory_date", i, state.getFactoryDate());
-				tablet.addValue("shift_index", i, state.getShiftIndex());
-				tablet.addValue("shift_time_type", i, state.getShiftTimeType());
-				tablet.addValue("wcs", i, state.getWcs());
-				tablet.addValue("rps", i, state.getRps());
-				tablet.addValue("is_fix_point", i, state.getIsFixPoint());
-				tablet.addValue("is_sync", i, state.getIsSync());
-				tablet.addValue("is_plan", i, state.getIsPlan());
-				tablet.addValue("feedback_point_type", i, state.getFeedbackPointType());
-				tablet.addValue("feedback_id", i, state.getFeedbackId());
-				tablet.addValue("is_deleted", i, state.getIsDeleted());
-				tablet.addValue("employee_id", i, state.getEmployeeId());
-			}*/
 			
 			
 		}

--
Gitblit v1.9.3