public static BatchWriteRowResponseForOneTable GetNewBatchWriteRowResponseForOneTable()
        {
            var item = new BatchWriteRowResponseForOneTable
            {
                Responses = new List <BatchWriteRowResponseItem>()
            };

            return(item);
        }
        public static BatchWriteRowResponseForOneTable GetNewBatchWriteRowResponseForOneTable()
        {
            var item = new BatchWriteRowResponseForOneTable();

            item.PutResponses    = new List <BatchWriteRowResponseItem>();
            item.DeleteResponses = new List <BatchWriteRowResponseItem>();
            item.UpdateResponses = new List <BatchWriteRowResponseItem>();
            return(item);
        }
Ejemplo n.º 3
0
        public void TableStoreAddLocation(DataRowCollection drs)
        {
            if (drs.Count == 0)
            {
                return;
            }
            int           batchCount = 0;
            int           i          = 0;
            List <string> list       = new List <string>();//存储批量上传的主键字符串,用于判断批量上传数据中是否有重复

            try
            {
                RowChanges rowChanges = new RowChanges();
                foreach (DataRow dr in drs)
                {
                    var primaryKey = new PrimaryKey();
                    primaryKey.Add("d", new ColumnValue(Convert.ToInt64(dr["device_code"])));
                    primaryKey.Add("s", new ColumnValue(TimeHelper.ConvertDateTimeToInt(Convert.ToDateTime(dr["startTime"]))));

                    string primarykey = dr["device_code"].ToString() + ";" + dr["startTime"].ToString();
                    if (list.Contains(primarykey))
                    {
                        log.Info("发现重复记录" + primarykey + "数据库记录:");
                        continue;
                    }
                    list.Add(primarykey);
                    var attribute = new AttributeColumns();
                    attribute.Add("e", new ColumnValue(TimeHelper.ConvertDateTimeToInt(Convert.ToDateTime(dr["endTime"]))));
                    //行驶数据
                    attribute.Add("r", new ColumnValue(ByteIntHelper.GetRouteByte(dr["startLongitude"], dr["startLatitude"], dr["endLongitude"], dr["endLatitude"], dr["drivingTime"], dr["mileage"], dr["topSpeed"])));
                    //行驶时长统计
                    attribute.Add("ds", new ColumnValue(ByteIntHelper.GetDurationstatsByte(dr["speedingTime"], dr["highSpeedTime"], dr["mediumSpeedTime"], dr["lowSpeedTime"], dr["idleTime"])));
                    //事件次数统计
                    attribute.Add("es", new ColumnValue(ByteIntHelper.GetEventStatsByte(dr["rapidAccelerationTimes"], dr["rapidDecelerationTimes"], dr["sharpTurnTimes"])));

                    rowChanges.AddPut(new Condition(RowExistenceExpectation.IGNORE), primaryKey, attribute);
                    batchCount++;
                    i++;
                    if (batchCount == 200)//200行数据进行批量提交一次
                    {
                        batchRequest.Add("Route", rowChanges);
                        BatchWriteRowResponse batchWriteRowResponse = oTSClient.BatchWriteRow(batchRequest);
                        foreach (var item in batchWriteRowResponse.TableRespones)
                        {
                            BatchWriteRowResponseForOneTable bwrfo        = item.Value;
                            BatchWriteRowResponseItem        responseItem = bwrfo.PutResponses[0];
                            bool aa = responseItem.IsOK;
                        }
                        rowChanges   = new RowChanges();
                        batchRequest = new BatchWriteRowRequest();
                        batchCount   = 0;
                        list         = new List <string>();
                        log.Info(i + "批量提交成功");
                    }
                }
                if (rowChanges.PutOperations.Count > 0)
                {
                    batchRequest.Add("Route", rowChanges);
                    oTSClient.BatchWriteRow(batchRequest);
                    log.Info(i + "批量提交成功");
                }
                batchRequest = new BatchWriteRowRequest();
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
            }
        }