SetFeeService.cs 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Threading;
  6. using MySystem.MainModels;
  7. using Library;
  8. using LitJson;
  9. namespace MySystem
  10. {
  11. /// <summary>
  12. /// 设置机具费率标记并推送消息
  13. /// </summary>
  14. public class SetFeeService
  15. {
  16. public readonly static SetFeeService Instance = new SetFeeService();
  17. private SetFeeService()
  18. { }
  19. public void Start()
  20. {
  21. Thread th = new Thread(doSomething);
  22. th.IsBackground = true;
  23. th.Start();
  24. }
  25. public void doSomething()
  26. {
  27. DataTable dt = CustomerSqlConn.dtable("select Id from PosMachinesTwo where BrandId in (1,3) and BindingState=1 and BindingTime<'" + DateTime.Now.AddDays(-90).ToString("yyyy-MM-dd") + " 00:00:00' and UpFeeFlag=0", Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString());
  28. foreach(DataRow dr in dt.Rows)
  29. {
  30. RedisDbconn.Instance.AddList("JkFeeQueue", dr["Id"].ToString());
  31. }
  32. dt = CustomerSqlConn.dtable("select Id from PosMachinesTwo where BrandId in (1,3) and BindingState=1 and BindingTime<'" + DateTime.Now.AddDays(-90).ToString("yyyy-MM-dd") + " 00:00:00' and DownFeeFlag=1", Library.ConfigurationManager.AppSettings["SqlConnStr"].ToString());
  33. foreach(DataRow dr in dt.Rows)
  34. {
  35. RedisDbconn.Instance.AddList("JkFeeQueue", dr["Id"].ToString());
  36. }
  37. dt.Dispose();
  38. dt.Clear();
  39. while (true)
  40. {
  41. string content = RedisDbconn.Instance.RPop<string>("JkFeeQueue");
  42. if (!string.IsNullOrEmpty(content))
  43. {
  44. try
  45. {
  46. int PosId = int.Parse(content);
  47. WebCMSEntities db = new WebCMSEntities();
  48. PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == PosId);
  49. if(pos != null)
  50. {
  51. PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == pos.BindMerchantId);
  52. if(mer != null)
  53. {
  54. Utils.WriteLog("KqMerNo:" + mer.KqMerNo + ";PosSn:" + pos.PosSn + ";", "金控机具费率设置日志");
  55. string result = PublicImportDataService.Instance.SetFee(mer.KqMerNo, pos.PosSn, 0.63M);
  56. Utils.WriteLog(result, "金控机具费率设置日志");
  57. JsonData obj = JsonMapper.ToObject(result);
  58. if (obj["code"].ToString() == "000000")
  59. {
  60. Utils.WriteLog(PublicImportDataService.Instance.Decrypt(obj["data"].ToString()), "金控机具费率设置日志");
  61. }
  62. Utils.WriteLog("\n\n", "金控机具费率设置日志");
  63. }
  64. }
  65. db.Dispose();
  66. Thread.Sleep(100);
  67. }
  68. catch (Exception ex)
  69. {
  70. Utils.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "金控机具费率设置异常");
  71. }
  72. }
  73. else
  74. {
  75. Thread.Sleep(60000);
  76. }
  77. }
  78. }
  79. }
  80. }