SetFeeFlagService.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 < 3)
  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. var date = DateTime.Now.AddDays(-178);
  38. var posList = db.PosMachinesTwo.Where(m => m.Status > -1 && m.BindingTime <= date && m.BindingState == 1 && m.UpFeeFlag == 0).ToList();
  39. //循环修改机具费率调升标记
  40. //统计需要推送消息的用户Id
  41. foreach (var item in posList)
  42. {
  43. string info = "{\"RecordId\":\"\",\"PosId\":\"" + item.Id + "\",\"Fee\": \"" + 0.63 + "\",\"Kind\": \"" + 1 + "\",\"OpMan\": \""+"系统"+"\"}";
  44. RedisDbconn.Instance.AddList("SetDepositQueue", info);
  45. }
  46. }
  47. }
  48. catch (Exception ex)
  49. {
  50. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "机具费率标记设置异常");
  51. }
  52. }
  53. Thread.Sleep(1200000);
  54. }
  55. }
  56. }
  57. }