SetFeeFlagService.cs 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 < 8)
  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. BrandIds.Add(8);
  45. BrandIds.Add(9);
  46. BrandIds.Add(10);
  47. BrandIds.Add(11);
  48. var date = DateTime.Now.AddDays(-118);
  49. bool op = true;
  50. int StartId = 0;
  51. while(op)
  52. {
  53. 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();
  54. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "118天提前通知创客费率调升");
  55. LogHelper.Instance.WriteLog(posList.Count.ToString(), "118天提前通知创客费率调升");
  56. if(posList.Count > 0)
  57. {
  58. //循环修改机具费率调升标记
  59. //统计需要推送消息的用户Id
  60. foreach (var item in posList)
  61. {
  62. LogHelper.Instance.WriteLog(item.Id.ToString(), "118天提前通知创客费率调升");
  63. string info = "{\"RecordId\":\"\",\"PosId\":\"" + item.Id + "\",\"Fee\": \"" + 0.63 + "\",\"Kind\": \"0\",\"OpMan\": \""+"系统"+"\"}";
  64. RedisDbconn.Instance.AddList("SetDepositQueue", info);
  65. StartId = item.Id;
  66. }
  67. }
  68. else
  69. {
  70. op = false;
  71. }
  72. }
  73. db.Dispose();
  74. }
  75. }
  76. catch (Exception ex)
  77. {
  78. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "机具费率标记设置异常");
  79. }
  80. }
  81. Thread.Sleep(800000);
  82. }
  83. }
  84. }
  85. }