Ejemplo n.º 1
0
        public int TranslateMinToWdDb(int devid, string targetStatCode, int taskIndex)
        {
            var dev = GetTargetDevice(devid);

            Console.WriteLine($"获取到的设备信息:{dev.Id},- {dev.DevCode} - {dev.OuterCode} - {dev.StatId}");

            if (LastRecordId == -1)
            {
                GetLastRecordOutId(devid);
            }

            Console.WriteLine($"最后一次记录的ID号:{LastRecordId}");

            var stat = _statList.First(obj => obj.Id.ToString() == dev.StatId);

            Console.WriteLine($"工地相关信息:{stat.Id} - {stat.StatCode}");

            var mysqlData = _mySqlContext.sensor_data_min.Where(obj => obj.StatCode == targetStatCode && obj.ID > LastRecordId)
                            .ToList();

            Console.WriteLine($"一共还有{mysqlData.Count}条记录要转换。");

            var count = 0;

            if (mysqlData.Any())
            {
                foreach (var sensorDataMin in mysqlData)
                {
                    var sqlData = new T_ESMin
                    {
                        DB            = sensorDataMin.DB,
                        TP            = sensorDataMin.TP * 10,
                        DevId         = dev.Id,
                        StatCode      = sensorDataMin.ID,
                        StatId        = int.Parse(dev.StatId),
                        Country       = stat.Country.ToString(),
                        Rain          = 0,
                        DataStatus    = "N",
                        WindDirection = sensorDataMin.WindDirection,
                        WindSpeed     = sensorDataMin.WindSpeed,
                        Temperature   = sensorDataMin.Temperature,
                        Airpressure   = sensorDataMin.AirPressure,
                        UpdateTime    = sensorDataMin.DataTime,
                        Humidity      = sensorDataMin.Humidity
                    };

                    LastRecordId = sensorDataMin.ID;
                    _sqlContext.T_ESMin.Add(sqlData);
                    count += _sqlContext.SaveChanges();
                    Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss fff")}:当前任务号:{taskIndex}保存数据成功。当前第{count}条,共{mysqlData.Count}条。");
                }
            }

            return(count);
        }
Ejemplo n.º 2
0
 public void AddNewData(emsData data, int statId, int devId, string country, int?statCodeUp)
 {
     using (var context = new EsMonitorModels())
     {
         var newData = new T_ESMin
         {
             TP            = data.dust,
             DB            = data.noise,
             Temperature   = data.temperature,
             Humidity      = data.humidity,
             WindDirection = data.windDirection,
             WindSpeed     = data.windSpeed,
             Airpressure   = 0,
             DevId         = devId,
             StatId        = statId,
             Country       = country,
             StatCode      = statCodeUp,
             DataStatus    = "N"
         };
         context.EsMin.Add(newData);
         context.SaveChanges();
     }
 }