PrePosRingService.cs 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System;
  2. using System.Collections.Generic;
  3. using Library;
  4. using LitJson;
  5. using System.Linq;
  6. using System.Data;
  7. using System.Threading;
  8. using MySystem.PxcModels;
  9. namespace MySystem
  10. {
  11. public class PrePosRingService
  12. {
  13. public readonly static PrePosRingService Instance = new PrePosRingService();
  14. private PrePosRingService()
  15. { }
  16. public void Start()
  17. {
  18. Thread th = new Thread(dosomething);
  19. th.IsBackground = true;
  20. th.Start();
  21. }
  22. public void dosomething()
  23. {
  24. while (true)
  25. {
  26. try
  27. {
  28. if(DateTime.Now.Hour > 3 && DateTime.Now.Hour < 19)
  29. {
  30. string chk = function.ReadInstance("/PrePosRing/" + DateTime.Now.ToString("yyyyMMdd") + ".txt");
  31. if(string.IsNullOrEmpty(chk))
  32. {
  33. function.WritePage("/PrePosRing/", "" + DateTime.Now.ToString("yyyyMMdd") + ".txt", DateTime.Now.ToString());
  34. PrePosRing();
  35. PrePosRingForExpired();
  36. }
  37. }
  38. }
  39. catch (Exception ex)
  40. {
  41. function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "预发机提醒异常");
  42. }
  43. Thread.Sleep(300000);
  44. }
  45. }
  46. //已确认状态的预发机25天至29天未完成申请时每天一次弹窗提醒预发创客
  47. private void PrePosRing()
  48. {
  49. WebCMSEntities db = new WebCMSEntities();
  50. DateTime start = DateTime.Parse(DateTime.Now.AddDays(-29).ToString("yyyy-MM-dd") + " 00:00:00");
  51. DateTime end = DateTime.Parse(DateTime.Now.AddDays(-24).ToString("yyyy-MM-dd") + " 00:00:00");
  52. var PrePosList = db.PreSendStockDetail.Where(m => m.ApplyFlag == 0 && m.CreateDate >= start && m.CreateDate < end && m.Status >= 0 && m.Status <= 1).ToList();
  53. foreach(var Pos in PrePosList)
  54. {
  55. Dictionary<string, string> Item = new Dictionary<string, string>();
  56. Item.Add("SnNo", Pos.SnNo);
  57. Item.Add("PreDate", Pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss"));
  58. string value = Newtonsoft.Json.JsonConvert.SerializeObject(Item);
  59. RedisDbconn.Instance.AddList("PrePosRing:" + DateTime.Now.ToString("yyyyMMdd") + ":" + Pos.ToUserId, value);
  60. int ExpireTime = 60 * 60 * 25;
  61. RedisDbconn.Instance.SetExpire("PrePosRing:" + DateTime.Now.ToString("yyyyMMdd") + ":" + Pos.ToUserId, ExpireTime);
  62. }
  63. db.Dispose();
  64. }
  65. //20日前对预发机超30天未完成申请的创客每天新增一次弹窗
  66. private void PrePosRingForExpired()
  67. {
  68. if(DateTime.Now.Day >= 15 && DateTime.Now.Day < 20)
  69. {
  70. WebCMSEntities db = new WebCMSEntities();
  71. DateTime end = DateTime.Parse(DateTime.Now.AddDays(-29).ToString("yyyy-MM-dd") + " 00:00:00");
  72. var PrePosList = db.PreSendStockDetail.Where(m => m.ApplyFlag == 0 && m.CreateDate < end && m.Status >= 0 && m.Status <= 1).ToList();
  73. foreach(var Pos in PrePosList)
  74. {
  75. Dictionary<string, string> Item = new Dictionary<string, string>();
  76. Item.Add("SnNo", Pos.SnNo);
  77. Item.Add("PreDate", Pos.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss"));
  78. string value = Newtonsoft.Json.JsonConvert.SerializeObject(Item);
  79. RedisDbconn.Instance.AddList("PrePosRingForExpired:" + DateTime.Now.ToString("yyyyMMdd") + ":" + Pos.ToUserId, value);
  80. int ExpireTime = 60 * 60 * 25;
  81. RedisDbconn.Instance.SetExpire("PrePosRingForExpired:" + DateTime.Now.ToString("yyyyMMdd") + ":" + Pos.ToUserId, ExpireTime);
  82. }
  83. db.Dispose();
  84. }
  85. }
  86. }
  87. }