SycnMerchantTradeService.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Collections.Generic;
  3. using Library;
  4. using LitJson;
  5. using System.Linq;
  6. using System.Data;
  7. using System.Threading;
  8. using MySystem.PxcModels;
  9. namespace MySystem
  10. {
  11. public class SycnMerchantTradeService
  12. {
  13. public readonly static SycnMerchantTradeService Instance = new SycnMerchantTradeService();
  14. private SycnMerchantTradeService()
  15. { }
  16. public void Start()
  17. {
  18. Thread th = new Thread(StartDo);
  19. th.IsBackground = true;
  20. th.Start();
  21. }
  22. public void StartDo()
  23. {
  24. while (true)
  25. {
  26. try
  27. {
  28. string content = RedisDbconn.Instance.RPop<string>("SycnMerchantTradeQueue");
  29. if(!string.IsNullOrEmpty(content))
  30. {
  31. function.WriteLog("content:" + content, "同步商户交易额");
  32. JsonData jsonObj = JsonMapper.ToObject(content);
  33. int OldPosId = int.Parse(function.CheckInt(jsonObj["OldPosId"].ToString()));
  34. int NewPosId = int.Parse(function.CheckInt(jsonObj["NewPosId"].ToString()));
  35. if(OldPosId != NewPosId)
  36. {
  37. CustomerSqlConn.op("update PosMerchantTradeSummay set MerchantId=" + NewPosId + " where MerchantId=" + OldPosId, MysqlConn.SqlConnStr);
  38. }
  39. Thread.Sleep(500);
  40. }
  41. else
  42. {
  43. Thread.Sleep(60000);
  44. }
  45. }
  46. catch (Exception ex)
  47. {
  48. function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "同步商户交易额异常");
  49. Thread.Sleep(300000);
  50. }
  51. }
  52. }
  53. }
  54. }