コード例 #1
0
        public bool InitStatParams(DataStatParamInfo DataStatParam, DataStoreTableInfo DataStoreItem)
        {
            int             res = 0;
            QueryResultBase QueryResultObject = new QueryResultBase();

            dataStatParam = DataStatParam;
            dataStoreItem = DataStoreItem;



            mysqlCnn = new MySqlConnectHelper(Conn);



            if (mysqlCnn.OpenConnect() == false)
            {
                LoggerManager.Log.Info("MySql连接对象创建失败!\n");
                return(false);
            }

            String DbName = $"`[iot]-[{DataStatParam.CompanyCode}]`";

            res = mysqlCnn.SelectDB(DbName);


            //MySqlDataReader companyReader = MySqlHelper.ExecuteReader(Conn, CommandType.Text, "select * from companyinfo", null);

            return(true);
        }
コード例 #2
0
        private void AnalyzeMonthSpliteSql(DataQueryParamObject DataQueryParam, DataStoreTableInfo DataStoreItem)
        {
            DateTime dtStart = Convert.ToDateTime(DataQueryParam.StartDate);
            DateTime dtEnd   = Convert.ToDateTime(DataQueryParam.EndDate);

            int Months = (dtEnd.Year - dtStart.Year) * 12 + (dtEnd.Month - dtStart.Month) + 1;

            int StartMonth = dtStart.Month;
            int currYear   = dtStart.Year;

            string QueryTableNamePrex = $"[datastore]-[{ DataQueryParam.DeviceCode}]-[{ DataQueryParam.TableName}]";

            for (int i = 0; i < Months; i++)
            {
                StatQueryCondition tempQueryCondition = new StatQueryCondition();
                string             startDate;
                string             endDate;


                string QueryTableNameSuffix = $"-{dtStart.Year}-{dtStart.ToString("MM")}";
                string tempQueryTableName   = QueryTableNamePrex + QueryTableNameSuffix;

                tempQueryCondition.TableName = tempQueryTableName;



                if (i == 0)
                {
                    startDate = $"{dtStart.Year}-{dtStart.Month}-{dtStart.Day} {dtStart.Hour}:{dtStart.Minute}:{dtStart.Second}";
                }
                else
                {
                    startDate = $"{dtStart.Year}-{dtStart.Month}-01 00:00:00";
                }

                if (i == (Months - 1))
                {
                    endDate = $"{dtStart.Year}-{dtStart.Month}-{dtEnd.Day} {dtEnd.Hour}:{dtEnd.Minute}:{dtEnd.Second}";
                }
                else
                {
                    DateTime d1 = new DateTime(dtStart.Year, dtStart.Month, 1);
                    DateTime d2 = d1.AddMonths(1).AddDays(-1);

                    endDate = $"{dtStart.Year}-{dtStart.Month}-{d2.Day} 23:59:59";
                }


                dtStart = dtStart.AddMonths(1);

                tempQueryCondition.StartDate = DataQueryParam.StartDate;
                tempQueryCondition.EndDate   = DataQueryParam.EndDate;

                //tempQueryCondition.SelectCondition = $"between '{startDate}' and '{endDate}'";
                statConditionList.Add(tempQueryCondition);
            }

            return;
        }
コード例 #3
0
        private void AnalyzeDaySpliteSql(DataStatParamInfo DataQueryParam, DataStoreTableInfo DataStoreItem)
        {
            DateTime dtStart = Convert.ToDateTime(DataQueryParam.StartDate);
            DateTime dtEnd   = Convert.ToDateTime(DataQueryParam.EndDate);

            DateTime d3   = Convert.ToDateTime(string.Format("{0}-{1}-{2}", dtStart.Year, dtStart.Month, dtStart.Day));
            DateTime d4   = Convert.ToDateTime(string.Format("{0}-{1}-{2}", dtEnd.Year, dtEnd.Month, dtEnd.Day));
            int      days = (d4 - d3).Days;

            int StartMonth = dtStart.Month;
            int currYear   = dtStart.Year;

            string QueryTableNamePrex = $"[datastore]-[{ DataQueryParam.DeviceCode}]-[{ DataQueryParam.TableName}]";

            for (int i = 0; i < days; i++)
            {
                StatQueryCondition tempQueryCondition = new StatQueryCondition();
                string             startDate;
                string             endDate;

                if (i == 0)
                {
                    startDate = $"{dtStart.Year}-{dtStart.Month}-{dtStart.Day} {dtStart.Hour}:{dtStart.Minute}:{dtStart.Second}";
                }
                else
                {
                    startDate = $"{dtStart.Year}-{dtStart.Month}-{dtStart.Day} 00:00:00";
                }

                if (i == (days - 1))
                {
                    endDate = $"{dtEnd.Year}-{dtEnd.Month}-{dtEnd.Day} {dtEnd.Hour}:{dtEnd.Minute}:{dtEnd.Second}";
                }
                else
                {
                    endDate = $"{dtStart.Year}-{dtStart.Month}-{dtStart.Day} 23:59:59";
                }


                string QueryTableNameSuffix = $"-{dtStart.Year}-{dtStart.Month}-{dtStart.Day}";
                string tempQueryTableName   = QueryTableNamePrex + QueryTableNameSuffix;

                tempQueryCondition.StartDate = startDate;
                tempQueryCondition.EndDate   = endDate;

                //tempQueryCondition.SelectCondition = $"between '{startDate}'and '{endDate}'";
                tempQueryCondition.TableName = tempQueryTableName;

                dtStart.AddDays(1);
            }



            return;
        }
コード例 #4
0
        public void InitQueryParams(DataQueryParamObject DataQueryParam, DataStoreTableInfo DataStoreItem)
        {
            int             res = 0;
            QueryResultBase QueryResultObject = new QueryResultBase();

            dataQueryParam = DataQueryParam;
            dataStoreItem  = DataStoreItem;

            mysqlCnn = MySqlConnectPoolHelper.getPool().getConnection();

            String DbName = $"`[iot]-[{DataQueryParam.CompanyCode}]`";

            res = mysqlCnn.SelectDB(DbName);
        }
コード例 #5
0
        private void AnalyzeDefaultSpliteSql(DataQueryParamObject DataQueryParam, DataStoreTableInfo DataStoreItem)
        {
            DateTime dtStart = Convert.ToDateTime(DataQueryParam.StartDate);
            DateTime dtEnd   = Convert.ToDateTime(DataQueryParam.EndDate);

            QueryCondition tempQueryCondition = new QueryCondition();

            tempQueryCondition.TableName       = $"[datastore]-[{ DataQueryParam.DeviceCode}]-[{ DataQueryParam.TableName}]";
            tempQueryCondition.SelectCondition = $"between '{DataQueryParam.StartDate}' and '{DataQueryParam.EndDate}'";
            queryConditionList.Add(tempQueryCondition);


            return;
        }
コード例 #6
0
        public QueryResultBase HandleStatInterface(DataStatParamInfo dataStatParam)
        {
            QueryResultBase QueryResultObject = new QueryResultBase();

            DataStoreTableInfo DataStoreConfigItem = CompanyManagerHelper.GetDeviceDataStoreConfigItem(
                dataStatParam.CompanyCode, dataStatParam.DeviceCode, dataStatParam.TableName);

            if (DataStoreConfigItem == null)
            {
                //QueryResultObject = new QueryResultBase();

                QueryResultObject.ResultCode = QueryResultCodeEnum.QUERY_ERROR_NO_DATA_STORE_CONFIG;
                QueryResultObject.QueryData  = null;
            }
            else
            {
                switch (dataStatParam.DataType)
                {
                case DATA_TYPE.DATA_SUM:

                    break;

                case DATA_TYPE.DATA_CUSTOM_ACC:
                    QueryResultObject = new QueryResultBase();
                    StatAlgorithm statAlogrithmObject = new StatAlgorithm();

                    if (statAlogrithmObject.InitStatParams(dataStatParam, DataStoreConfigItem) == true)
                    {
                        QueryResultObject = statAlogrithmObject.GetStatRecordsetData();
                    }
                    else
                    {
                        QueryResultObject.ResultCode = QueryResultCodeEnum.QUERY_ERROR_NO_DATA_STORE_CONFIG;
                        QueryResultObject.QueryData  = null;
                    }

                    break;

                default:
                    break;
                }
            }



            return(QueryResultObject);
        }
コード例 #7
0
        public bool InitializeDataStoreManager()
        {
            String cmdSQL = $"select * from `datastoreconfig` where CompanyCode = '{_deviceInfo.CompanyCode}' and DeviceCode = '{_deviceInfo.DeviceCode}'";

            MySqlDataReader dataStoreConfigReader = MySqlHelper.ExecuteReader(Conn, CommandType.Text, cmdSQL, null);

            while (dataStoreConfigReader.Read())
            {
                DataStoreTableInfo  dataStoreTableItem  = new DataStoreTableInfo();
                DataStoreConfigInfo dataStoreConfigItem = new DataStoreConfigInfo();

                dataStoreTableItem.TableName       = (string)dataStoreConfigReader["DefaultTableName"];
                dataStoreTableItem.SpliteTableType = (SPLITE_TABLE_TYPE)(int)dataStoreConfigReader["SpliteType"];
                string fieldInfoJson = (string)dataStoreConfigReader["FieldInfo"];

                dataStoreTableItem.FieldList = JsonConvert.DeserializeObject <DataStoreFieldInfo[]>(fieldInfoJson);


                dataStoreConfigItem.TableInfo = dataStoreTableItem;

                dataStoreConfigItem.CompanyCode  = (string)dataStoreConfigReader["CompanyCode"];
                dataStoreConfigItem.DeviceCode   = (string)dataStoreConfigReader["DeviceCode"];
                dataStoreConfigItem.SaveInterval = (int)dataStoreConfigReader["SaveInterval"];
                dataStoreConfigItem.StoreTime    = (int)dataStoreConfigReader["StoreTime"];
                //dataStoreConfigItem.DataType = (string)dataStoreConfigReader["DataType"];
                dataStoreConfigItem.StoreCondition = dataStoreConfigReader["StoreCondition"].ToString();
                dataStoreConfigItem.BufferTime     = (int)dataStoreConfigReader["BufferTime"];
                dataStoreConfigItem.BufferSize     = (int)dataStoreConfigReader["BufferSize"];


                _deviceDataStoreManager.AddDataStoreItem(dataStoreConfigItem);

                _DataStoreMap.Add(dataStoreTableItem.TableName, dataStoreTableItem);
            }

            return(true);
        }
コード例 #8
0
        public QueryResultBase HandleQueryInterfaceExtend(DataQueryParamObject dataQueryParam)
        {
            QueryResultBase QueryResultObject = null;

            DataStoreTableInfo DataStoreConfigItem = CompanyManagerHelper.GetDeviceDataStoreConfigItem(
                dataQueryParam.CompanyCode, dataQueryParam.DeviceCode, dataQueryParam.TableName);

            if (DataStoreConfigItem == null)
            {
                QueryResultObject = new QueryResultBase();

                QueryResultObject.ResultCode = QueryResultCodeEnum.QUERY_ERROR_NO_DATA_STORE_CONFIG;
                QueryResultObject.QueryData  = null;

                return(QueryResultObject);
            }
            else
            {
                switch (dataQueryParam.DataQueryType)
                {
                case DATA_QUERY_TYPE.HISTORY_QUERY:
                    QueryAlgorithm HistoryQueryObject = new QueryAlgorithm();
                    HistoryQueryObject.InitQueryParams(dataQueryParam, DataStoreConfigItem);
                    QueryResultObject = HistoryQueryObject.GetQueryRecordsetData(true);
                    HistoryQueryObject.ClearMySQLCnn();
                    break;

                default:
                    break;
                }
            }



            return(QueryResultObject);
        }
コード例 #9
0
        public List <StatQueryCondition> GetStatSqlList(DataStatParamInfo DataStatParam, DataStoreTableInfo DataStoreItem)
        {
            switch (DataStoreItem.SpliteTableType)
            {
            case SPLITE_TABLE_TYPE.SPLITE_DEFAULT:
                AnalyzeDefaultSpliteSql(DataStatParam, DataStoreItem);
                break;

            case SPLITE_TABLE_TYPE.SPLITE_MONTH:
                AnalyzeMonthSpliteSql(DataStatParam, DataStoreItem);
                break;

            case SPLITE_TABLE_TYPE.SPLITE_YEAR:
                break;

            default:
                break;
            }

            return(statConditionList);
        }
コード例 #10
0
        private string[] AnalyzeYearSpliteSql(DataQueryParamObject DataQueryParam, DataStoreTableInfo DataStoreItem)
        {
            string[] querySqlList = null;

            return(querySqlList);
        }