SetFeeFlagService.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Threading;
  6. using MySystem.Models;
  7. using Library;
  8. namespace MySystem
  9. {
  10. /// <summary>
  11. /// 设置机具费率标记并推送消息
  12. /// </summary>
  13. public class SetFeeFlagService
  14. {
  15. public readonly static SetFeeFlagService Instance = new SetFeeFlagService();
  16. private SetFeeFlagService()
  17. { }
  18. public void Start()
  19. {
  20. Thread th = new Thread(doSomething);
  21. th.IsBackground = true;
  22. th.Start();
  23. }
  24. public void doSomething()
  25. {
  26. while (true)
  27. {
  28. if (DateTime.Now.Hour > 0 && DateTime.Now.Hour < 4)
  29. {
  30. try
  31. {
  32. string check = function.ReadInstance("/Fee/check" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt");
  33. if (string.IsNullOrEmpty(check))
  34. {
  35. function.WritePage("/Fee/", "check" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", DateTime.Now.ToString("HH:mm:ss"));
  36. WebCMSEntities db = new WebCMSEntities();
  37. List<int> BrandIds = new List<int>();
  38. BrandIds.Add(1);
  39. BrandIds.Add(2);
  40. BrandIds.Add(3);
  41. BrandIds.Add(4);
  42. BrandIds.Add(5);
  43. BrandIds.Add(7);
  44. var date = DateTime.Now.AddDays(-118);
  45. bool op = true;
  46. int StartId = 0;
  47. while(op)
  48. {
  49. var posList = db.PosMachinesTwo.Select(m => new { m.Id, m.Status, m.BindingState, m.BindingTime, m.UpFeeFlag, m.BrandId }).Where(m => m.Id > StartId && m.Status > -1 && m.BindingTime <= date && m.BindingState == 1 && m.UpFeeFlag == 0 && BrandIds.Contains(m.BrandId)).OrderBy(m => m.Id).Take(100).ToList();
  50. function.WriteLog(DateTime.Now.ToString(), "118天提前通知创客费率调升");
  51. function.WriteLog(posList.Count.ToString(), "118天提前通知创客费率调升");
  52. if(posList.Count > 0)
  53. {
  54. //循环修改机具费率调升标记
  55. //统计需要推送消息的用户Id
  56. foreach (var item in posList)
  57. {
  58. function.WriteLog(item.Id.ToString(), "118天提前通知创客费率调升");
  59. string info = "{\"RecordId\":\"\",\"PosId\":\"" + item.Id + "\",\"Fee\": \"" + 0.63 + "\",\"Kind\": \"0\",\"OpMan\": \""+"系统"+"\"}";
  60. RedisDbconn.Instance.AddList("SetDepositQueue", info);
  61. StartId = item.Id;
  62. }
  63. }
  64. else
  65. {
  66. op = false;
  67. }
  68. }
  69. db.Dispose();
  70. }
  71. }
  72. catch (Exception ex)
  73. {
  74. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "机具费率标记设置异常");
  75. }
  76. }
  77. Thread.Sleep(800000);
  78. }
  79. }
  80. }
  81. }