using dodohold.core; using CSRedis; using System.Data; namespace molilian.core { public partial class TkLogCore { static string promotion_img_key = "queue:promotion:img"; public static int task_insert_promotion_img_logs(IDbConnection connection, IDbTransaction transaction, int limit, CSRedisClient redis) { int total = 0; for (int i = 0; i < limit; i++) { var data = redis.LPop(promotion_img_key); if (data == null) break; if (data.success) { data.similarPromotion = string.Empty; data.promotionImg = string.Empty; } connection.Insert(data); total++; } return total; } public static async Task PromotionImgLogAsync(PromotionQueryDTO response) { try { var ts = DateTime.Now - response.create_time; response.elapsedTime = (int)ts.TotalMilliseconds; _ = RedisHelper.RPushAsync(promotion_img_key, response); //using var connection = DBContext.GetOpenConnection(); //connection.Insert(response); savePromotionCache(response.accountId, response.accountName, response.success, response.message, response.reason); } catch (Exception ex) { } } private static void savePromotionCache(int accountId, string accountName, bool success, string message, string reason) { savePromotionAccountCache("all", success, message, reason); savePromotionAccountCache($"{accountId}", success, message, reason); } private static void savePromotionAccountCache(string accountName, bool success, string message, string reason) { RedisHelper.IncrBy($":promotion_total:{accountName}:{DateTime.Now:yyyyMM}"); RedisHelper.IncrBy($":promotion_total:{accountName}:{DateTime.Now:yyyyMMdd}"); RedisHelper.IncrBy($":promotion_total:{accountName}:{DateTime.Now:yyyyMMddHH}"); string result = success ? "success" : "fail"; RedisHelper.IncrBy($":promotion_total:{accountName}:{result}:{DateTime.Now:yyyyMM}"); RedisHelper.IncrBy($":promotion_total:{accountName}:{result}:{DateTime.Now:yyyyMMdd}"); RedisHelper.IncrBy($":promotion_total:{accountName}:{result}:{DateTime.Now:yyyyMMddHH}"); if (!string.IsNullOrEmpty(message)) { RedisHelper.SAdd($":promotion_total:{accountName}:message:{DateTime.Now:yyyyMM}", message); RedisHelper.SAdd($":promotion_total:{accountName}:message:{DateTime.Now:yyyyMMdd}", message); RedisHelper.SAdd($":promotion_total:{accountName}:message:{DateTime.Now:yyyyMMddHH}", message); RedisHelper.IncrBy($":promotion_total:{accountName}:{message}:{DateTime.Now:yyyyMM}"); RedisHelper.IncrBy($":promotion_total:{accountName}:{message}:{DateTime.Now:yyyyMMdd}"); RedisHelper.IncrBy($":promotion_total:{accountName}:{message}:{DateTime.Now:yyyyMMddHH}"); RedisHelper.IncrBy($":promotion_total:{accountName}:message:{message}:{DateTime.Now:yyyyMM}"); RedisHelper.IncrBy($":promotion_total:{accountName}:message:{message}:{DateTime.Now:yyyyMMdd}"); RedisHelper.IncrBy($":promotion_total:{accountName}:message:{message}:{DateTime.Now:yyyyMMddHH}"); } if (!string.IsNullOrEmpty(reason)) { RedisHelper.SAdd($":promotion_total:{accountName}:reason:{DateTime.Now:yyyyMM}", reason); RedisHelper.SAdd($":promotion_total:{accountName}:reason:{DateTime.Now:yyyyMMdd}", reason); RedisHelper.SAdd($":promotion_total:{accountName}:reason:{DateTime.Now:yyyyMMddHH}", reason); RedisHelper.IncrBy($":promotion_total:{accountName}:{reason}:{DateTime.Now:yyyyMM}"); RedisHelper.IncrBy($":promotion_total:{accountName}:{reason}:{DateTime.Now:yyyyMMdd}"); RedisHelper.IncrBy($":promotion_total:{accountName}:{reason}:{DateTime.Now:yyyyMMddHH}"); RedisHelper.IncrBy($":promotion_total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMM}"); RedisHelper.IncrBy($":promotion_total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMMdd}"); RedisHelper.IncrBy($":promotion_total:{accountName}:reason:{reason}:{DateTime.Now:yyyyMMddHH}"); } } } }