Ejemplo n.º 1
0
        /// <summary>
        /// 获取渠道关键词回复内容
        /// </summary>
        /// <param name="channelId">渠道id</param>
        /// <param name="keyword">关键词</param>
        /// <param name="preKeywordContextId">上一关键词id</param>
        /// <returns></returns>
        public static async Task <KeywordReplyDetailEntity> GetKeywordReplyAsync(int channelId, string keyword, int preKeywordContextId = -1)
        {
            try
            {
                var redisKey         = string.Format("{0}_{1}_{2}", channelId, keyword, preKeywordContextId);
                var replyDetailCache = await RedisHelper.StringGetAsync <KeywordReplyDetailEntity>(redisKey);

                if (replyDetailCache == null || replyDetailCache.KeywordContextId <= 0)
                {
                    var sql             = @"SELECT a.* FROM KeywordReplyDetail a
                                        JOIN ChannelKeywordRelation b ON a.KeywordContextId=b.KeywordContextId
                                        WHERE b.ChannelId=@ChannelId
                                        ORDER BY a.LastModifyTime DESC";
                    var keywordEntities = await DapperDBHelper.QueryAsync <KeywordReplyDetailEntity>(sql, new { ChannelId = channelId });

                    if (keywordEntities.Count() > 0)
                    {
                        replyDetailCache = keywordEntities.SingleOrDefault();
                        var setResult = await RedisHelper.StringSetAsync(redisKey, replyDetailCache, TimeSpan.FromHours(1.0));
                    }
                }
                return(replyDetailCache);
            }
            catch (Exception ex)
            {
                ex.WriteExceptionLog("获取渠道关键词回复内容出错");
            }
            return(new KeywordReplyDetailEntity());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Update操作
        /// </summary>
        /// <param name="data">带更新字段</param>
        /// <param name="condition">更新条件</param>
        /// <param name="commandTimeout"></param>
        /// <returns></returns>
        public async Task <int> UpdateAsync(dynamic data, dynamic condition, int?commandTimeout = null)
        {
            var sql = BuildUpdateSql(data, condition, out DynamicParameters parameters);

            var result = await DapperDBHelper.ExecuteAsync(sql, param : parameters, commandTimeout : commandTimeout);

            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 查询方法
        /// </summary>
        /// <param name="condition"></param>
        /// <param name="columns"></param>
        /// <param name="isOr"></param>
        /// <param name="commandTimeout"></param>
        /// <returns></returns>
        public async Task <IEnumerable <T> > QueryListAsync(dynamic condition, string columns = "*", bool isOr = false, int?commandTimeout = null)
        {
            object obj;
            var    sql = BuildQuerySql(condition, out obj, columns, isOr);

            var result = await DapperDBHelper.QueryAsync <T>(sql, obj, commandTimeout);

            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 查询方法
        /// </summary>
        /// <param name="condition"></param>
        /// <param name="columns"></param>
        /// <param name="isOr"></param>
        /// <param name="commandTimeout"></param>
        /// <returns></returns>
        public IEnumerable <T> QueryList(dynamic condition, string columns = "*", bool isOr = false, int?commandTimeout = null)
        {
            object obj;
            var    sql = BuildQuerySql(condition, out obj, columns, isOr);

            var result = DapperDBHelper.Query <T>(sql, param: obj, commandTimeout: commandTimeout);

            return(result);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// The Execute
 /// </summary>
 /// <param name="sql">The sql<see cref="string"/></param>
 /// <param name="param">The param<see cref="object"/></param>
 /// <param name="timeout">The timeout<see cref="int?"/></param>
 /// <returns>The <see cref="int"/></returns>
 public int Execute(string sql, object param, int?timeout = null)
 {
     return(DapperDBHelper.Execute(sql, param: param, commandTimeout: timeout));
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Insert操作
        /// </summary>
        /// <param name="data">要插入的字段</param>
        /// <param name="commandTimeout"></param>
        /// <returns></returns>
        public async Task <long> InsertAsync(dynamic data, int?commandTimeout = null)
        {
            var sql = BuildInsertSql(data, out object obj);

            return(await DapperDBHelper.InsertAsync(sql, param : obj, commandTimeout : commandTimeout));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Insert操作
        /// </summary>
        /// <param name="data">要插入的字段</param>
        /// <param name="commandTimeout"></param>
        /// <returns></returns>
        public int Insert(dynamic data, int?commandTimeout = null)
        {
            var sql = BuildInsertSql(data, out object obj);

            return(DapperDBHelper.Insert(sql, param: obj, commandTimeout: commandTimeout));
        }