Example #1
0
        public static ICollection <tbl_sp_troneItem> GetRowsById(Shotgun.Database.IBaseDataClass2 dBase, IEnumerable <int> ids)
        {
            if (ids.Count() == 1)
            {
                var m = GetRowById(dBase, ids.First());
                if (m == null)
                {
                    return(null);
                }
                return(new tbl_sp_troneItem[] { m });
            }

            var data = _cache.GetCacheData(true);

            if (data != null)
            {
                lock (_cache.SyncRoot)
                {
                    return((from item in data where ids.Contains(item.id) select item).ToArray());
                }
            }

            var q = LightDataModel.tbl_sp_troneItem.GetQueries(dBase);

            q.Filter.AndFilters.Add(tbl_sp_troneItem.Fields.PrimaryKey, ids);
            q.PageSize = int.MaxValue;
            var rlt = q.GetDataList();

            foreach (var item in rlt)
            {
                _cache.InsertItem(item);
            }
            return(rlt);
        }
Example #2
0
 void ICPPushModel.SetHidden(Shotgun.Database.IBaseDataClass2 dBase, tbl_trone_orderItem tCfg)
 {
     this.syn_flag       = 0;
     this.trone_order_id = tCfg.id;
     this.cp_id          = tCfg.cp_id;
     dBase.SaveData(this);
 }
Example #3
0
        internal static SpTroneCountInfo LoadFromDbase(Shotgun.Database.IBaseDataClass2 dBase, int spTroneId, bool isMonth)
        {
            var cmd = dBase.Command();
            var sql = "select count(0),sum(trone.price)*100 from daily_log.tbl_mr_{0:yyyyMM} mr"
                      + " left join daily_config.tbl_trone trone on trone.id=mr.trone_id where mr.sp_trone_id={1}";

            if (!isMonth)
            {
                sql += " and mr_date='{0:yyyy-MM-dd}'";
            }

            cmd.CommandText = string.Format(sql, DateTime.Today, spTroneId);
            using (cmd)
            {
                using (var rd = dBase.ExecuteReader(cmd))
                {
                    var info = new SpTroneCountInfo();
                    info.SpTroneId = spTroneId;
                    if (!rd.Read())
                    {
                        info.Count = int.Parse(rd.GetValue(0).ToString());
                        info.Sum   = int.Parse(rd.GetValue(1).ToString());
                    }
                    return(info);
                }
            }
        }
Example #4
0
        public static tbl_cp_trone_rateItem QueryBySpTroneId(Shotgun.Database.IBaseDataClass2 dBase, int spTroneId, int cpId)
        {
            var m = _cache.FindFirstData(e => e.sp_trone_id == spTroneId && e.cp_id == cpId);

            if (m != null)
            {
                return(m);
            }

            var q = GetQueries(dBase);

            q.Filter.AndFilters.Add(Fields.cp_id, cpId);
            q.Filter.AndFilters.Add(Fields.sp_trone_id, spTroneId);
            m = q.GetRowByFilters();
            if (m != null)
            {
                _cache.InsertItem(m);
            }
            else
            {
                _cache.InsertItem(m = new tbl_cp_trone_rateItem()
                {
                    cp_id = cpId, sp_trone_id = spTroneId
                });
            }
            return(m);
        }
Example #5
0
 /// <summary>
 /// 创建推送任务(不阻塞,后台自动推送)
 /// </summary>
 /// <returns></returns>
 public bool DoAgain()
 {
     if (_lastInstance != null)
     {
         return(false);
     }
     _lastInstance = this;
     _lastLog      = this.logFile;
     ThreadPool.QueueUserWorkItem(
         e =>
     {
         try
         {
             dBase = new Shotgun.Database.DBDriver().CreateDBase();
             syncCore();
         }
         catch (Exception ex)
         {
             WriteLog("处理错误!" + ex.ToString());
         }
         finally
         {
             _lastInstance = null;
             ((IDisposable)dBase).Dispose();
         }
     });
     return(true);
 }
Example #6
0
        /// <summary>
        /// 根据userId查找指定的行,返回所有字段
        /// </summary>
        /// <param name="dBase"></param>
        /// <param name="userId">主键值</param>
        /// <param name="fields">返回字段</param>
        /// <returns></returns>
        public static tbl_cpItem GetRowByUserId(Shotgun.Database.IBaseDataClass2 dBase, int userId, string[] fields)
        {
            var q = GetQueries(dBase);

            q.Fields = fields;
            q.Filter.AndFilters.Add(Fields.user_id, userId);
            return(q.GetRowByFilters());
        }
Example #7
0
        /// <summary>
        /// 根据主键查找指定的行,返回指定字段
        /// </summary>
        /// <param name="dBase"></param>
        /// <param name="id">主键值</param>
        /// <param name="fields">返回字段</param>
        /// <returns></returns>
        public static tbl_zyl_detailItem GetRowById(Shotgun.Database.IBaseDataClass2 dBase, int id, string[] fields)
        {
            var q = GetQueries(dBase);

            q.Fields = fields;
            q.Filter.AndFilters.Add(identifyField, id);
            return(q.GetRowByFilters());
        }
Example #8
0
 tbl_cp_mrItem ICPPushModel.SetPushed(Shotgun.Database.IBaseDataClass2 dBase, tbl_trone_orderItem tCfg)
 {
     this.syn_flag       = 1;
     this.trone_order_id = tCfg.id;
     this.cp_id          = tCfg.cp_id;
     dBase.SaveData(this);
     return(this.CopyToCP());
 }
Example #9
0
        /// <summary>
        /// 更新用户每日计费信息
        /// </summary>
        /// <param name="dBase"></param>
        /// <param name="troneId"></param>
        /// <param name="customId"></param>
        /// <param name="mrDate"></param>
        private static void UpdateUserLimit(Shotgun.Database.IBaseDataClass2 dBase, int troneId, string customId, DateTime mrDate)
        {
            var key = CustomFeeModel.GetIdKey(customId, troneId, mrDate);
            var m   = cache.GetDataByIdx(key);

            if (m != null)
            {//找到用户计费缓存数据
                Shotgun.Library.SimpleLogRecord.WriteLog("api_userlimit_update",
                                                         string.Format("customid:{0},troneId:{1},Count:{2} +1", customId, troneId, m.Count));
                lock (m)
                    m.Count++;
                return;
            }
            var  trone   = LightDataModel.tbl_troneItem.GetRowById(dBase, troneId);
            var  spTrone = LightDataModel.tbl_sp_troneItem.GetRowById(dBase, trone.sp_trone_id);
            var  data    = cache.GetCacheData(false);
            bool iFound  = false;

            if (data != null)
            {
                lock (cache.SyncRoot)
                {
                    foreach (var item in data)
                    {
                        if (item.SpToneId == spTrone.id && item.Id == key)
                        {
                            iFound = true;
                            break;
                        }
                    }
                }
            }
            if (iFound)//用户的缓存已经加载,但没有此通道计费情况
            {
                m          = new CustomFeeModel();
                m.SpToneId = spTrone.id;
                m.TroneId  = trone.id;
                m.Date     = mrDate.Date;
                m.Count    = 1;
                m.Fee      = decimal.ToInt32(trone.price * 100);
                cache.InsertItem(m);
                Shotgun.Library.SimpleLogRecord.WriteLog("api_userlimit_update",
                                                         string.Format("customid:{0},troneId:{1}, found other trone!", customId, troneId));
                return;
            }
            else
            {
                Shotgun.Library.SimpleLogRecord.WriteLog("api_userlimit_update",
                                                         string.Format("customid:{0},troneId:{1},not found!", customId, troneId));
            }
            //无缓存数据时,无需任何处理
            //因为在通道计算时,无缓存数据时,会主动从数据库读取最新信息
            //LoadFromDBase(dBase, spTrone.id, customId);
        }
Example #10
0
        /// <summary>
        /// 根据SP_trone_id找出对应的配置数据
        /// </summary>
        /// <param name="dBase"></param>
        /// <param name="spTroneId"></param>
        /// <returns></returns>
        public static tbl_sp_trone_apiItem GetRowByTroneId(Shotgun.Database.IBaseDataClass2 dBase, int TroneId)
        {
            var sql = "select * from tbl_sp_trone_api where id in ( select trone_api_id from tbl_sp_trone where id in(select sp_trone_id from tbl_trone where id="
                      + TroneId + ")) limit 1 ";
            var l = GetQueries(dBase);

            var ms = l.GetDataListBySql(sql);

            if (ms == null || ms.Count == 0)
            {
                return(null);
            }
            return(ms[0]);
        }
Example #11
0
        public static tbl_cp_push_urlItem GetRowByIdWithCache(Shotgun.Database.IBaseDataClass2 dBase, int id)
        {
            var m = cache.GetDataByIdx(id);

            if (m != null)
            {
                return(m);
            }
            m = GetRowById(dBase, id, null);
            if (m != null)
            {
                cache.InsertItem(m);
            }
            return(m);
        }
Example #12
0
        /// <summary>
        /// 根据主键查找指定的行,返回指定字段
        /// </summary>
        /// <param name="dBase"></param>
        /// <param name="id">主键值</param>
        /// <param name="fields">返回字段</param>
        /// <returns></returns>
        public static tbl_cp_trone_rateItem GetRowById(Shotgun.Database.IBaseDataClass2 dBase, int id, string[] fields)
        {
            var m = _cache.GetDataByIdx(id);

            if (m != null)
            {
                return(m);
            }

            var q = GetQueries(dBase);

            //q.Fields = fields;
            q.Filter.AndFilters.Add(identifyField, id);
            m = q.GetRowByFilters();
            _cache.InsertItem(m);
            return(m);
        }
Example #13
0
        public static void UpdateDayLimit(Shotgun.Database.IBaseDataClass2 dBase, int spTroneId, int cpId, decimal amount)
        {
            var m = LightDataModel.tbl_day_month_limitItem.GetOrCreateItem(dBase, spTroneId, cpId);

            m.cur_day_amount += amount;
            PushDayLimit(spTroneId, cpId, amount);
            try
            {
                dBase.SaveData(m);
            }
#if !DEBUG
            catch
            {
            }
#endif
            finally { }
        }
        public static tbl_trone_paycodeItem QueryPayCodeByTroneId(Shotgun.Database.IBaseDataClass2 dBase, int troneId)
        {
            var data = cache.FindFirstData(e => e.trone_id == troneId);

            if (data != null)
            {
                return(data);
            }

            var q = GetQueries(dBase);

            q.Filter.AndFilters.Add(Fields.trone_id, troneId);
            data = q.GetRowByFilters();
            if (data != null)
            {
                cache.InsertItem(data);
            }
            return(data);
        }
        public static tbl_sp_api_urlItem QueryById(Shotgun.Database.IBaseDataClass2 dBase, int id)
        {
            var m = cache.GetDataByIdx(id);

            if (m != null)
            {
                return(m);
            }

            var q = GetQueries(dBase);

            m = q.GetRowById(id);

            if (m == null)
            {
                return(null);
            }
            cache.InsertItem(m);
            return(m);
        }
        public static tbl_sp_api_urlItem QueryByVirtualPage(Shotgun.Database.IBaseDataClass2 dBase, string virtualPage)
        {
            var m = cache.FindFirstData(e => virtualPage.Equals(e.virtual_page, StringComparison.OrdinalIgnoreCase));

            if (m != null)
            {
                return(m.Disable ? null : m);
            }

            var q = GetQueries(dBase);

            q.Filter.AndFilters.Add(Fields.virtual_page, virtualPage);
            m = q.GetRowByFilters();
            if (m == null)
            {
                return(null);
            }
            cache.InsertItem(m);
            return(m.Disable ? null : m);
        }
Example #17
0
        /// <summary>
        /// 计算用户的日月限信息
        /// </summary>
        /// <param name="customId">为空时,表示整个通道</param>
        /// <returns>始终不为空</returns>
        public static CustomLimitInfo QueryLimit(Shotgun.Database.IBaseDataClass2 dBase, int spTroneId, string customId)
        {
            if (string.IsNullOrEmpty(customId))
            {
                customId = null;//保证一致信息,string.empty => null
            }
            var data = cache.GetCacheData(false);
            IEnumerable <CustomFeeModel> cfm = null;

            if (data != null)
            {
                lock (cache.SyncRoot)
                    cfm = data.Where(e => e.SpToneId == spTroneId && customId == e.CustomId).ToList();
            }
            if (cfm == null || cfm.Count() == 0)
            {
                cfm = LoadFromDBase(dBase, spTroneId, customId);
            }
            var cli = new CustomLimitInfo()
            {
                CustomId = customId
            };
            var today = DateTime.Today;

            foreach (var cf in cfm)
            {
                if (cf.Date >= today)
                {
                    cli.DayCount  += cf.Count;
                    cli.DayAmount += cf.TotalFee;
                }
                else
                {
                    cli.MonthCount  += cf.Count;
                    cli.MonthAmount += cf.TotalFee;
                }
            }
            cli.MonthAmount += cli.DayAmount;
            cli.MonthCount  += cli.DayCount;
            return(cli);
        }
Example #18
0
        /// <summary>
        /// 根据 mr_id 获取虚拟 daily对像(仅主键,其它数据为空)
        /// </summary>
        /// <param name="dBase"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static tbl_mr_dailyItem GetVRDaily(Shotgun.Database.IBaseDataClass2 dBase, tbl_mrItem mr)
        {
            if (!mr.mr_date.Equals(DateTime.Today))
            {
                return(null);
            }
            var q = tbl_mr_dailyItem.GetQueries(dBase);

            q.Schema = C_Schema;
            q.Filter.AndFilters.Add(tbl_mr_dailyItem.Fields.mr_id, mr.id);
            var idObj = q.ExecuteScalar(tbl_mr_dailyItem.Fields.PrimaryKey);

            if (idObj == null)
            {
                return(null);
            }
            return(new tbl_mr_dailyItem()
            {
                id = (int)idObj
            });
        }
Example #19
0
        public static IEnumerable <tbl_trone_orderItem> QueryByTroneIdWithCache(Shotgun.Database.IBaseDataClass2 dBase, int troneId)
        {
            IEnumerable <tbl_trone_orderItem> lst = null;
            var t = cache.GetCacheData(true);

            if (t != null)
            {
                lock (cache.SyncRoot)
                {
                    lst = from item in t where !item.disable && item.trone_id == troneId select item;
                    return(lst.ToArray());
                }
            }

#if DEBUG
            if (isWinform)
            {
                Console.WriteLine("QueryByTroneIdWithCache from database:troneId {0} ", troneId);
            }
            else
#endif
            Shotgun.Library.SimpleLogRecord.WriteLog("Cache2Sql", string.Format("QueryByTroneIdWithCache from database:troneId {0} ", troneId));

            var l = LightDataModel.tbl_trone_orderItem.GetQueries(dBase);
            l.Filter.AndFilters.Add(LightDataModel.tbl_trone_orderItem.Fields.trone_id, troneId);
            l.Filter.AndFilters.Add(LightDataModel.tbl_trone_orderItem.Fields.disable, 0);
            l.PageSize = int.MaxValue;
            lst        = l.GetDataList();
            if (lst == null || lst.Count() == 0)
            {
                return(lst);
            }
            foreach (var m in lst)
            {
                cache.InsertItem(m);
            }
            return(lst);
        }
Example #20
0
 /// <summary>
 /// 根据主键查找指定的行,返回所有字段
 /// </summary>
 /// <param name="dBase"></param>
 /// <param name="id">主键值</param>
 /// <returns></returns>
 public static tbl_phone_locateItem GetRowById(Shotgun.Database.IBaseDataClass2 dBase, int id)
 {
     return(GetRowById(dBase, id, null));
 }
Example #21
0
        static IEnumerable <CustomFeeModel> LoadFromDBase(Shotgun.Database.IBaseDataClass2 dBase, int spTroneId, string customId)
        {
            var trones = LightDataModel.tbl_troneItem.GetTroneIdsBySptroneId(dBase, spTroneId);

            if (trones.Count() == 0)
            {
                return new CustomFeeModel[] { }
            }
            ;
            string sql;

            if (string.IsNullOrEmpty(customId))
            {//整个通道信息
                sql = string.Format("SELECT trone_id,fee_date= current_Date() isToday , sum(count)  FROM daily_log.tbl_custom_fee_count "
                                    + " where trone_id in({0}) "
                                    + " group by trone_id,isToday",
                                    string.Join(",", trones.Select(e => e.id)), DateTime.Today);
            }
            else
            {//用户计费信息
                sql = string.Format("SELECT trone_id,fee_date= current_Date() isToday , sum(count)  FROM daily_log.tbl_custom_fee_count "
                                    + " where trone_id in({0}) and custom_id='{1}'"
                                    + " group by trone_id,isToday",
                                    string.Join(",", trones.Select(e => e.id)), dBase.SqlEncode(customId));
            }


            var cmd = dBase.Command();

            cmd.CommandText = sql;
            System.Data.IDataReader dr  = null;
            List <CustomFeeModel>   rlt = new List <CustomFeeModel>();

            try
            {
                dr = dBase.ExecuteReader(cmd);
                while (dr.Read())
                {
                    var m = new CustomFeeModel();
                    m.CustomId = customId;
                    m.SpToneId = spTroneId;
                    m.TroneId  = dr.GetInt32(0);
                    m.Date     = dr.GetBoolean(1) ? DateTime.Today : DateTime.Today.AddDays(-1);
                    m.Count    = dr.GetInt32(2);
                    m.Fee      = decimal.ToInt32(100 * trones.First(e => e.id == m.TroneId).price);
                    rlt.Add(m);
                    cache.InsertItem(m);
                }
            }
            finally
            {
                if (dr != null)
                {
                    dr.Dispose();
                }
                cmd.Dispose();
            }
            if (rlt.Count == 0)
            {//表示该用户,日月限缓存已经建立
                var trone = trones.First();
                var m     = new CustomFeeModel();
                m.CustomId = customId;
                m.SpToneId = spTroneId;
                m.TroneId  = trone.id;
                m.Date     = DateTime.Today;
                m.Count    = 0;
                m.Fee      = decimal.ToInt32(100 * trone.price);
                rlt.Add(m);
                cache.InsertItem(m);
            }
            return(rlt);
        }
Example #22
0
 /// <summary>
 /// 更新通道每日计费信息
 /// </summary>
 /// <param name="dBase"></param>
 /// <param name="troneId"></param>
 /// <param name="customId"></param>
 /// <param name="mrDate"></param>
 private static void UpdateMonthLimit(Shotgun.Database.IBaseDataClass2 dBase, int troneId, DateTime mrDate)
 {
     UpdateUserLimit(dBase, troneId, null, mrDate);
 }
Example #23
0
 /// <summary>
 /// 根据主键查找指定的行,返回所有字段
 /// </summary>
 /// <param name="dBase"></param>
 /// <param name="id">主键值</param>
 /// <returns></returns>
 public static tbl_mobile_white_listItem GetRowById(Shotgun.Database.IBaseDataClass2 dBase, int id)
 {
     return(GetRowById(dBase, id, null));
 }
Example #24
0
 /// <summary>
 /// 创建一个新的查询器
 /// </summary>
 public static Shotgun.Model.List.DynamicTableList <tbl_moItem> GetQueries(Shotgun.Database.IBaseDataClass2 dBase)
 {
     return(new Shotgun.Model.List.DynamicTableList <tbl_moItem>(dBase, SCHEMA, FIX_TABLE_NAME));
 }
 /// <summary>
 /// 根据主键查找指定的行,返回所有字段
 /// </summary>
 /// <param name="dBase"></param>
 /// <param name="id">主键值</param>
 /// <returns></returns>
 public static tbl_request_logItem GetRowById(Shotgun.Database.IBaseDataClass2 dBase, int id)
 {
     return(GetRowById(dBase, id, null));
 }
 /// <summary>
 /// 根据主键查找指定的行,返回所有字段
 /// </summary>
 /// <param name="dBase"></param>
 /// <param name="id">主键值</param>
 /// <returns></returns>
 public static tbl_custom_fee_countItem GetRowById(Shotgun.Database.IBaseDataClass2 dBase, int id)
 {
     return(GetRowById(dBase, id, null));
 }
Example #27
0
 /// <summary>
 /// 创建一个新的查询器
 /// </summary>
 public static Shotgun.Model.List.LightDataQueries <tbl_zyl_detailItem> GetQueries(Shotgun.Database.IBaseDataClass2 dBase)
 {
     return(new Shotgun.Model.List.LightDataQueries <tbl_zyl_detailItem>(tableName, identifyField, dBase));
 }
Example #28
0
 /// <summary>
 /// 根据主键查找指定的行,返回所有字段
 /// </summary>
 /// <param name="dBase"></param>
 /// <param name="id">主键值</param>
 /// <returns></returns>
 public static tbl_trone_paycodeItem GetRowById(Shotgun.Database.IBaseDataClass2 dBase, int id)
 {
     return(GetRowById(dBase, id, null));
 }
Example #29
0
 /// <summary>
 /// 根据主键查找指定的行,返回所有字段
 /// </summary>
 /// <param name="dBase"></param>
 /// <param name="id">主键值</param>
 /// <returns></returns>
 public static tbl_zyl_detailItem GetRowById(Shotgun.Database.IBaseDataClass2 dBase, int id)
 {
     return(GetRowById(dBase, id, null));
 }
Example #30
0
 public static void UpdateLimit(Shotgun.Database.IBaseDataClass2 dBase, int troneId, string customId, DateTime mrDate)
 {
     UpdateUserLimit(dBase, troneId, customId, mrDate);
     UpdateMonthLimit(dBase, troneId, mrDate);
 }