using System; using System.Collections.Generic; using System.Threading; using System.Linq; using System.Data; using MySystem; using MySystem.PxcModels; using Library; using LitJson; public class ResetSmallStoreHelper { public readonly static ResetSmallStoreHelper Instance = new ResetSmallStoreHelper(); private ResetSmallStoreHelper() { } public void Start() { Thread th = new Thread(DoWorks); th.IsBackground = true; th.Start(); } // 每月1号小分仓额度,额度为上个月实际发放的总分润 private void DoWorks() { while (true) { function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\n\n", "计算小分仓额度日志"); WebCMSEntities db = new WebCMSEntities(); OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString(); try { // if(DateTime.Now.Day == 1 && DateTime.Now.Hour > 0 && DateTime.Now.Hour < 3) // { string Month = DateTime.Now.AddMonths(-1).ToString("yyyyMM"); string check = function.ReadInstance("/ResetSmallStore/" + Month + ".txt"); if(string.IsNullOrEmpty(check)) { function.WritePage("/ResetSmallStore/", Month + ".txt", DateTime.Now.ToString()); DataTable dt = OtherMySqlConn.dtable("select UserId,sum(CreditTradeProfit+DebitNonTradeCapProfit+DebitTradeCapProfit) from ProfitRewardRecord where UserId>0 and TradeMonth='" + Month + "' group by UserId order by UserId"); function.WriteLog("总数" + dt.Rows.Count, "计算小分仓额度日志"); int index = 0; foreach(DataRow dr in dt.Rows) { index += 1; int UserId = int.Parse(function.CheckInt(dr["UserId"].ToString())); decimal ProfitAmount = decimal.Parse(function.CheckNum(dr[1].ToString())); UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId); if (account == null) { account = db.UserAccount.Add(new UserAccount() { Id = UserId, UserId = UserId, }).Entity; db.SaveChanges(); } account.ThisMonthPreAmount = ProfitAmount; account.ValidPreAmount = ProfitAmount; if(index % 200 == 0) { db.SaveChanges(); } function.WriteLog(index.ToString(), "计算小分仓额度日志"); } db.SaveChanges(); } // } } catch (Exception ex) { function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "计算小分仓额度异常"); } db.Dispose(); function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\n\n", "计算小分仓额度日志"); Thread.Sleep(60000); } } }