BatchRechargingJobGetService.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using Dapper;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using XYY.Core.Standard.Data.Infrastructure;
  6. namespace XYY.Service.JobManage
  7. {
  8. public interface IBatchRechargingJobGetService : IJobGetService<ExpressFeechargesModel>
  9. {
  10. }
  11. public class BatchRechargingJobGetService : IBatchRechargingJobGetService
  12. {
  13. IUnitOfWork unitOfWork;
  14. public BatchRechargingJobGetService(IUnitOfWork unitOfWork)
  15. {
  16. this.unitOfWork = unitOfWork;
  17. }
  18. public List<BaseJobModel<ExpressFeechargesModel>> GetAndSendJobs()
  19. {
  20. DateTime start = DateTime.Now.AddDays(-7), end = DateTime.Now;
  21. int[] sealUserId = new int[] { 846, 1314 };
  22. string sql = @"select Width,Height,Length,IsResidential,
  23. CustomerId,
  24. ReceiverCountryCode as CountryCode,
  25. ChannelId as ExpressId,
  26. CreateOrderChannelId as PublicExpressId,
  27. OPWeight as BillingWeight,a.Id as OrderId,
  28. receivetime as AccountingDate,
  29. receivetime as TransactionTime,
  30. case when customerid = 683 then ActualWeight/1000.0 else OPWeight/1000.0 end as BillingWeight,
  31. SystemNo as BillNo,
  32. 0 as SettlementAmount,
  33. TrackingNumber,
  34. b.GoodsDeclareFee as GoodsDeclared,
  35. b.GoodsDeclaredCurreny,
  36. '全程派送运费' as BillType,
  37. '支出' as IncomeOrESxpense,
  38. case when IOSS ='' or IOSS is null then 0 else 1 end as HasIOSS,
  39. ReceiverZipCode as ZipCode,
  40. c.BranchCompanyId as BranchCompanyCustomerId,
  41. a.IsOnline,
  42. a.TrackingNumber
  43. from Order_Order(nolock)a
  44. left join User_Customer c on a.CustomerId=c.Id
  45. outer apply (select sum(DeclareFee * Quantity) as GoodsDeclareFee,max(DeclareCurrency)as GoodsDeclaredCurreny from Order_OrderGoods(nolock) where OrderId=a.Id )b
  46. where ReceiveTime between @start and @end and SealUserId in @sealUserId";
  47. var list = this.unitOfWork.Connection.Query<ExpressFeechargesModel>(sql, new { start = start, end = end, sealUserId = sealUserId }, this.unitOfWork.Transaction);
  48. return list.Select(x => new BaseJobModel<ExpressFeechargesModel>
  49. {
  50. Data = x,
  51. JobModelId = Guid.NewGuid().ToString(),
  52. JobType = "Recharging",
  53. Key1 = x.BillNo,
  54. Key2 = null,
  55. StartTime = DateTime.Now,
  56. }).ToList();
  57. }
  58. }
  59. }