YWLogService.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using Ant.Core.Utils;
  2. using Central.Control.WebApi.DbEntity;
  3. using Central.Control.WebApi.EFDbContext;
  4. using Central.Control.WebApi.Enum;
  5. using Central.Control.WebApi.Log4net;
  6. using Central.Control.WebApi.Service.Interface;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Web;
  11. namespace Central.Control.WebApi.Service
  12. {
  13. /// <summary>
  14. /// 业务日志相关
  15. /// </summary>
  16. public class YWLogService: IYWLogService
  17. {
  18. private readonly IDbContext _dbContent;
  19. private readonly ILog4NetHelper _log4NetHelper;
  20. /// <summary>
  21. ///
  22. /// </summary>
  23. /// <param name="dbContent"></param>
  24. /// <param name="log4NetHelper"></param>
  25. public YWLogService(
  26. IDbContext dbContent,
  27. ILog4NetHelper log4NetHelper)
  28. {
  29. _dbContent = dbContent;
  30. _log4NetHelper = log4NetHelper;
  31. }
  32. /// <summary>
  33. /// 写入订单日志
  34. /// </summary>
  35. /// <param name="orderId"></param>
  36. /// <param name="title"></param>
  37. /// <param name="content"></param>
  38. /// <param name="opreater"></param>
  39. public void WriteOrderLog(string orderId, string title, string content, string opreater)
  40. {
  41. try
  42. {
  43. if (content == null) content = string.Empty;
  44. YW_OrderLog orderLog = new YW_OrderLog()
  45. {
  46. Id = IdGenerator.NewId(),
  47. OrderId = orderId ?? string.Empty,
  48. Title = title ?? string.Empty,
  49. Content = content.Length >= 500 ? content.Substring(0, 499) : content,
  50. CreateBY = opreater ?? string.Empty
  51. };
  52. _dbContent.Set<YW_OrderLog>().Add(orderLog);
  53. _dbContent.SaveChanges();
  54. }
  55. catch (Exception ee)
  56. {
  57. _log4NetHelper.Error("[写入订单日志WriteOrderLogAsync]", ee);
  58. }
  59. }
  60. /// <summary>
  61. /// 写入支付回写日志
  62. /// </summary>
  63. /// <param name="paySerialId">支付流水号</param>
  64. /// <param name="outTradeNo">外部订单号</param>
  65. /// <param name="payWay">支付类型</param>
  66. /// <param name="payResponse">回写原始内容</param>
  67. public void WritePayCallLog(string paySerialId, string outTradeNo, PayWayEnum payWay, string payResponse)
  68. {
  69. try
  70. {
  71. YW_PayCallLog payCallLog = new YW_PayCallLog()
  72. {
  73. Id = IdGenerator.NewId(),
  74. PaySerialId = paySerialId ?? string.Empty,
  75. OutTradeNo = outTradeNo ?? string.Empty,
  76. PayWay = payWay,
  77. PayResponse = payResponse ?? string.Empty,
  78. CreateBY = "支付回写"
  79. };
  80. _dbContent.Set<YW_PayCallLog>().Add(payCallLog);
  81. _dbContent.SaveChanges();
  82. }
  83. catch (Exception ee)
  84. {
  85. _log4NetHelper.Error("[写入支付回写日志WritePayCallLog]", ee);
  86. }
  87. }
  88. /// <summary>
  89. /// 写入订单流程信息
  90. /// </summary>
  91. /// <param name="orderId"></param>
  92. /// <param name="deviceId"></param>
  93. /// <param name="orderStatus"></param>
  94. /// <param name="message"></param>
  95. /// <param name="opreater"></param>
  96. public void WriteOrderProcess(string orderId, string deviceId, OrderStatusEnum orderStatus, string message, string opreater)
  97. {
  98. try
  99. {
  100. YW_OrderProcess orderProcess = new YW_OrderProcess()
  101. {
  102. Id = IdGenerator.NewId(),
  103. OrderId = orderId,
  104. DeviceId = deviceId,
  105. CurrentOrderStatus = orderStatus,
  106. Message = message,
  107. CreateBY = opreater
  108. };
  109. _dbContent.Set<YW_OrderProcess>().Add(orderProcess);
  110. _dbContent.SaveChanges();
  111. }
  112. catch (Exception ee)
  113. {
  114. _log4NetHelper.Error("[写入订单流程WriteOrderProcess]", ee);
  115. }
  116. }
  117. }
  118. }