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 StoreApplyHelper { public readonly static StoreApplyHelper Instance = new StoreApplyHelper(); private StoreApplyHelper() { } public void Start() { Thread th = new Thread(DoWorks); th.IsBackground = true; th.Start(); } private void DoWorks() { while (true) { WebCMSEntities db = new WebCMSEntities(); try { if(DateTime.Now.Day == 1 && DateTime.Now.Hour > 0 && DateTime.Now.Hour < 3) { string check = function.ReadInstance("/StoreApply/" + DateTime.Now.ToString("yyyyMM") + ".txt"); if(string.IsNullOrEmpty(check)) { function.WritePage("/StoreApply/", DateTime.Now.ToString("yyyyMM") + ".txt", DateTime.Now.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); } } public void StartEverTime() { Thread th = new Thread(StartEverTimeDo); th.IsBackground = true; th.Start(); } private void StartEverTimeDo() { while (true) { WebCMSEntities db = new WebCMSEntities(); try { string data = RedisDbconn.Instance.Get("StoreApplyQueue"); if(!string.IsNullOrEmpty(data)) { JsonData jsonObj = JsonMapper.ToObject(data); if(jsonObj["Kind"].ToString() == "1") { int OrderId = int.Parse(jsonObj["Data"]["OrderId"].ToString()); Orders order = db.Orders.FirstOrDefault(m => m.Id == OrderId); if(order != null) { decimal TotalPrice = order.TotalPrice; UserAccount account = db.UserAccount.FirstOrDefault(); } } 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); } } }