You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.9 KiB

  1. using DTO;
  2. using HKCardOUT.Helper;
  3. using HKCardOUT.Logic;
  4. using HKCardOUT.Logic.Model;
  5. using Quartz;
  6. using S7.Net.Types;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Threading.Tasks;
  11. using XExten.Advance.LinqFramework;
  12. namespace HKCardOUT.QuartzUtil.Job
  13. {
  14. public class QuartzJob : IJob
  15. {
  16. private readonly object obj = new object();
  17. public async Task Execute(IJobExecutionContext context)
  18. {
  19. switch (context.JobDetail.Key.Group)
  20. {
  21. default:
  22. {
  23. var WaitSync = DbContext.Context.Queryable<SaleLog>().Where(t => t.IsSync == false&&t.State==true).ToList();
  24. List<SaleDto> dto = new List<SaleDto>();
  25. if (WaitSync.Count > 0)
  26. {
  27. HKLog.HKLogImport.WriteInfo($"订单推送执行,推送数量{WaitSync.Count},推送的卡号:【{string.Join(",", WaitSync.Select(t => t.CardNo))}】");
  28. foreach (var input in WaitSync)
  29. {
  30. var GateId = DataBus.StoreInfo.Devices.FirstOrDefault(t => t.Address.AsInt() == input.Location.AsInt())?.GateId;
  31. dto.Add(new SaleDto
  32. {
  33. CardNum = input.CardNo,
  34. GateId = GateId,
  35. Id = input.Id,
  36. CreateAt = input.CreateTime
  37. });
  38. }
  39. var db = DbContext.Context;
  40. try
  41. {
  42. lock (obj)
  43. {
  44. db.BeginTran();
  45. foreach (var item in dto)
  46. {
  47. var res = RemoteService.SyncSaleLogList(new List<SaleDto> { item });
  48. if (res)
  49. DbContext.Context.Updateable<SaleLog>().SetColumns(t => t.IsSync == true).Where(t => t.Id==item.Id).ExecuteCommand();
  50. else
  51. DbContext.Context.Updateable<SaleLog>().SetColumns(t => t.State==false).Where(t => t.Id == item.Id).ExecuteCommand();
  52. }
  53. db.CommitTran();
  54. }
  55. }
  56. catch (Exception)
  57. {
  58. db.RollbackTran();
  59. }
  60. }
  61. }
  62. break;
  63. }
  64. }
  65. }
  66. }