SetFeeFlagService.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 < 19)
  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 = db.KqProducts.Where(m => m.Status > 0 && m.PosPrice > 0).ToList().Select(m => m.Id).ToList();
  38. BrandIds.Remove(14);
  39. BrandIds.Remove(18);
  40. BrandIds.Remove(19);
  41. BrandIds.Remove(20);
  42. BrandIds.Remove(21);
  43. BrandIds.Remove(23);
  44. BrandIds.Remove(24);
  45. BrandIds.Remove(25);
  46. BrandIds.Remove(26);
  47. var date = DateTime.Now.AddDays(-85);
  48. bool op = true;
  49. int StartId = 0;
  50. while(op)
  51. {
  52. var posList = db.PosMachinesTwo.Select(m => new { m.Id, m.Status, m.BindingState, m.BindingTime, m.UpFeeFlag, m.DownFeeFlag, m.BrandId }).Where(m => m.Id > StartId && m.Status > -1 && m.BindingTime <= date && m.BindingState == 1 && m.UpFeeFlag == 0 && m.DownFeeFlag == 0 && BrandIds.Contains(m.BrandId)).OrderBy(m => m.Id).Take(100).ToList();
  53. function.WriteLog(DateTime.Now.ToString(), "85天提前通知创客费率调升");
  54. function.WriteLog(posList.Count.ToString(), "85天提前通知创客费率调升");
  55. if(posList.Count > 0)
  56. {
  57. //循环修改机具费率调升标记
  58. //统计需要推送消息的用户Id
  59. foreach (var item in posList)
  60. {
  61. function.WriteLog(item.Id.ToString(), "85天提前通知创客费率调升");
  62. string info = "{\"RecordId\":\"\",\"PosId\":\"" + item.Id + "\",\"Fee\": \"" + 0.63 + "\",\"Kind\": \"0\",\"OpMan\": \"" + "系统" + "\"}";
  63. RedisDbconn.Instance.AddList("SetDepositQueue", info);
  64. StartId = item.Id;
  65. }
  66. }
  67. else
  68. {
  69. op = false;
  70. }
  71. }
  72. db.Dispose();
  73. }
  74. }
  75. catch (Exception ex)
  76. {
  77. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "机具费率标记设置异常");
  78. }
  79. }
  80. Thread.Sleep(800000);
  81. }
  82. }
  83. }
  84. }