SetFeeFlagService.cs 3.8 KB

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