Ejemplo n.º 1
0
 public void UpdateDtuStatus(List <string> dtus)
 {
     try
     {
         List <string> sqlstrs   = new List <string>();
         string        cs        = ConfigurationManager.AppSettings["SecureCloud"];
         ISqlHelper    sqlHelper = SqlHelperFactory.Create(DbType.MSSQL, cs);
         foreach (string dtu in dtus)
         {
             DataSet ds =
                 sqlHelper.Query(string.Format("(select ID from T_DIM_REMOTE_DTU where REMOTE_DTU_NUMBER ='{0}')",
                                               dtu));
             if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
             {
                 this._log.InfoFormat("DTU {0} 不是一个有效的DTU", dtu);
             }
             else
             {
                 sqlstrs.Add(string.Format(
                                 "insert into T_DIM_DTU_STATUS (DtuId,Status,[Time]) values ({0},{1},'{2:yyyy-MM-dd HH:mm:ss.fff}')",
                                 (string.Format("(select ID from T_DIM_REMOTE_DTU where REMOTE_DTU_NUMBER ='{0}')",
                                                dtu)),
                                 0, DateTime.Now));
             }
         }
         if (sqlstrs.Count > 0)
         {
             sqlHelper.ExecuteSqlTran(sqlstrs);
         }
     }
     catch (Exception ex)
     {
         this._log.ErrorFormat("closed UpdateAllDtuStatus error: {0}", ex.Message);
     }
 }
Ejemplo n.º 2
0
        public int SaveDacResult(DACTaskResult result)
        {
            IList <SensorAcqResult> sresults = result.SensorResults;

            if (sresults == null || sresults.Count <= 0)
            {
                return(0);
            }
            var sqlCmds = new List <SqlCmdInfo>();

            foreach (SensorAcqResult sr in sresults)
            {
                ISensorData data = sr.Data;
                try
                {
                    // 2. 存储到对应的主题数据.
                    // 入原始数据
                    // 入主题数据表
                    if (data == null)
                    {
                        continue;
                    }
                    string themeSql = GenerateAddValueSql(sr);
                    if (!string.IsNullOrEmpty(themeSql))
                    {
                        sqlCmds.Add(new SqlCmdInfo(themeSql));
                    }
                }
                catch (Exception ex)
                {
                    Log.ErrorFormat("{0},产生SQL语句错误:" + ex.Message, sr.Sensor.SensorID);
                }
            }
            return(_helper.ExecuteSqlTran(sqlCmds));
        }
Ejemplo n.º 3
0
        public void UpdateAllDtuStatus()
        {
            try
            {
                string     cs        = ConfigurationManager.AppSettings["SecureCloud"];
                ISqlHelper sqlHelper = SqlHelperFactory.Create(DbType.MSSQL, cs);
                DataSet    ds        = sqlHelper.Query(@"
select DISTINCT 
         ds.[DtuId] 
        ,ds.[Status]
        ,ds.[Time]
        ,rd.REMOTE_DTU_NUMBER
        ,rd.ProductDtuId
from [T_DIM_DTU_STATUS] ds,[T_DIM_REMOTE_DTU] rd where ds.DtuId=rd.ID and rd.ProductDtuId =1 order by ds.[Time] desc ");
                if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
                {
                    return;
                }
                List <int> onlinedtus = (from r in ds.Tables[0].AsEnumerable()
                                         where r.Field <bool>("Status")
                                         orderby r.Field <DateTime>("Time") descending
                                         select r.Field <int>("DtuId")).ToList();
                List <string> sqls =
                    onlinedtus.Select(
                        i =>
                        string.Format(
                            "insert into T_DIM_DTU_STATUS (DtuId,Status,[Time]) values ({0},{1},'{2:yyyy-MM-dd HH:mm:ss.fff}')",
                            i, 0, DateTime.Now)).ToList();
                if (sqls.Count > 0)
                {
                    sqlHelper.ExecuteSqlTran(sqls);
                }
            }
            catch (Exception ex)
            {
                this._log.ErrorFormat("started UpdateAllDtuStatus error: {0}", ex.Message);
            }
        }
Ejemplo n.º 4
0
 public static int ExecuteSqlTran(List <String> SQLStringList)
 {
     return(IHelper.ExecuteSqlTran(SQLStringList));
 }
Ejemplo n.º 5
0
        public int SaveDacResult(DACTaskResult result)
        {
            IList <SensorAcqResult> sresults = result.SensorResults;

            if (sresults == null || sresults.Count <= 0)
            {
                return(0);
            }
            var sqlCmds = new List <SqlCmdInfo>();

            foreach (SensorAcqResult sr in sresults)
            {
                if (!sr.IsOK || sr.Data == null)
                {
                    continue;
                }
                ISensorData data = sr.Data;
                try
                {
                    if (data == null)
                    {
                        continue;
                    }

                    // 1. 存储到 T_DATA_ORIGINAL, Value 1/2/3/4 对应了主题中的属性值.
                    // 2. 存储到对应的主题数据.
                    // 入原始数据
                    if (sr.ErrorCode == (int)Errors.SUCCESS)
                    {
                        if (data.IsSaveDataOriginal)
                        {
                            ((BasicSensorData)data).IsSaveDataOriginal = false;
                            string rawValueSql = GenerateAddValueSql(RawDataTable, sr, GetStorageTime(result, sr));
                            if (!string.IsNullOrEmpty(rawValueSql))
                            {
                                sqlCmds.Add(new SqlCmdInfo(rawValueSql));
                            }
                        }
                        else
                        {
                            // 入主题数据表
                            if (data.ThemeValues.Any(d => d != null))
                            {
                                string themeSql = GenerateAddValueSql(sr.Sensor.FactorTypeTable, sr, GetStorageTime(result, sr));
                                if (!string.IsNullOrEmpty(themeSql))
                                {
                                    sqlCmds.Add(new SqlCmdInfo(themeSql));
                                }
                            }
                        }
                    }
                    else
                    {
                        FileService.Write(_errorPath,
                                          string.Format("Dtu[{3}-{4}] s:{5} - m:{0} - c:{1}, Error Code: {2}", sr.Sensor.ModuleNo,
                                                        sr.Sensor.ChannelNo, sr.ErrorCode, sr.Sensor.DtuID, sr.DtuCode, sr.Sensor.SensorID));
                    }
                }
                catch (Exception ex)
                {
                    Log.ErrorFormat("Dtu:{0}-{1} s:{2} - m{3} - c{4}, create SQL error:{5}", sr.Sensor.DtuID, sr.DtuCode,
                                    sr.Sensor.SensorID, sr.Sensor.ModuleNo,
                                    sr.Sensor.ChannelNo, ex.Message);
                }
            }
            return(_helper.ExecuteSqlTran(sqlCmds));
        }