SycnMerchantInfoService.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using MySystem.PxcModels;
  5. using Library;
  6. using LitJson;
  7. namespace MySystem
  8. {
  9. public class SycnMerchantInfoService
  10. {
  11. public readonly static SycnMerchantInfoService Instance = new SycnMerchantInfoService();
  12. private SycnMerchantInfoService()
  13. { }
  14. public void Start(JobMqMsg jobInfo)
  15. {
  16. string content = "";
  17. try
  18. {
  19. string OrderString = jobInfo.OrderString;
  20. if (OrderString.StartsWith("Sp:") && OrderString.EndsWith(":Sycn"))
  21. {
  22. string TableName = OrderString.Split(':')[1];
  23. string Msg = "";
  24. bool op = true;
  25. while (op)
  26. {
  27. string data = RedisDbconn.Instance.RPop<string>(TableName);
  28. if(!string.IsNullOrEmpty(data))
  29. {
  30. Dictionary<string, string> dic = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(data);
  31. if (TableName.StartsWith("kq_"))
  32. {
  33. ProfitHelper.Instance.StartListenMerchantDo(dic, true);
  34. }
  35. else
  36. {
  37. ProfitHelper.Instance.StartListenMerchantDo(dic);
  38. }
  39. }
  40. else
  41. {
  42. op = false;
  43. }
  44. }
  45. jobInfo.Status = Msg == "success" ? 1 : 0;
  46. jobInfo.Msg = Msg == "success" ? "执行完成" : Msg;
  47. RabbitMQClient.Instance.SendMsg(Newtonsoft.Json.JsonConvert.SerializeObject(jobInfo), "SycnTableDataBack");
  48. }
  49. }
  50. catch (Exception ex)
  51. {
  52. if (!string.IsNullOrEmpty(content))
  53. {
  54. Dictionary<string, string> data = new Dictionary<string, string>();
  55. data.Add("ErrTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  56. data.Add("ErrMsg", ex.ToString());
  57. function.WriteLog(Newtonsoft.Json.JsonConvert.SerializeObject(data), "public_err");
  58. }
  59. else
  60. {
  61. function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "public_service");
  62. }
  63. }
  64. }
  65. }
  66. }