IOrderRepository.cs 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Threading.Tasks;
  5. using XYY.Core.Standard.Data.Infrastructure;
  6. using XYY.Model.Standard.Order;
  7. using System.Linq;
  8. using Dapper;
  9. using Microsoft.Extensions.Logging;
  10. using XYY.Data.Standard.Channel;
  11. using XYY.Common.Standard;
  12. using XYY.Model.Standard.Channel;
  13. using XYY.Model.Standard.Dto.order;
  14. using RestSharp.Extensions;
  15. using static XYY.Data.Standard.Order.OrderRepository;
  16. using Org.BouncyCastle.Bcpg;
  17. using IoC;
  18. namespace XYY.Data.Standard.Order
  19. {
  20. public interface IOrderRepository : IBaseRepository<Order_Order>
  21. {
  22. Task<int> GetNewId();
  23. /// <summary>
  24. /// 导入澳鹏订单
  25. /// </summary>
  26. /// <param name="orders">导入澳鹏订单</param>
  27. Task InputOrderAndGoods(List<OrderInputDto> order);
  28. Task<List<OrderConfimRequest>> GetWaitConfimOrders(int qty);
  29. [NonTrans]
  30. Task AddWinitLog(string winitOrderId, string transferNumber);
  31. [NonTrans]
  32. Task RemoveWinitLog(string winitOrderId, string transferNumber);
  33. [NonTrans]
  34. Task AddChannelOrderInfoRecord(int channelId, string channelOrderId, string transferNumber);
  35. [NonTrans]
  36. Task<string> GetChannelOrderInfoRecord(int channelId, string transferNumber);
  37. [NonTrans]
  38. Task<string> GetWinitOrderNo(string transferNumber, string SystemNo = "");
  39. Task<BagDeclareRequest> GetWaitBoxDeclareRequest(int channelId, string ladingBillNumber = null, string boxNumber = null);
  40. Task<List<BagDeclareRequest>> GetWaitBoxDeclareRequest(string[] serviceChannelCodeList);
  41. Task<IEnumerable<SysWarehouseFileLog>> GetWaitDownFile(int qty = 200);
  42. Task UpdateDownFile(List<SysWarehouseFileLog> transfernums);
  43. Task<PageResult<View_QueryOverCancelOrders>> QueryOverCancelOrders(QueryModel queryModel);
  44. Task<PageResult<BagDeclareLog>> GetBagDeclareLogs(QueryModel queryModel);
  45. Task<List<dynamic>> QueryCustomerData(string sql);
  46. Task<List<dynamic>> GetZZESBUpdateData(string lading);
  47. int GetPackagePrintQty(string customerOrderNo);
  48. Task SetUnusualNotTransfer(string trackingNumber, UnusualReasonType UnusualReasonType, bool IsReprocessing);
  49. Task AddChannelOrderInfoRecord(string FCOrderId, string transferNumber, int channelId);
  50. Task<OrderQtys> GetCustomerDraftOrderCount(QueryModel qm);
  51. Task<List<OrderQtys>> GetOrderQty(QueryModel qm);
  52. Task<PageResult<CustomerOrder>> GetCustomerOrderPager(QueryModel qm);
  53. Task<CustomerOrder> GetCustomerOrder(int id);
  54. Task<CustomerOrder> GetCustomerDraftOrder(int id);
  55. Task<PageResult<CustomerOrder>> GetCustomerDraftOrderList(QueryModel qm);
  56. Task<List<CustomerOrder>> GetCustomerOrderList(QueryModel queryModel);
  57. Task<IEnumerable<ServiceChannelCodeIdDto>> GetLadingBillServiceChannelCodes(string ladingBillNumber);
  58. Task UpdateTrackingNumber(List<UpdateDataDto> updateDatas);
  59. Task<List<Order_Order>> GetWaitSyncCustomerTracking(int qty = 30);
  60. Task<List<Order_CustomerAsyncTracking>> GetWaitAsyncZZESBData(int qty);
  61. Task UpdateEnd(List<int> ids);
  62. Task SetNextUpdate(List<Order_Order> noUpdateData);
  63. Task<List<Order_CustomerAsyncTracking>> GetWaitAsyncKTXESBData(int qty);
  64. Task InsertFirstToDB(List<Order_CustomerAsyncTracking> list);
  65. Task<List<Sys_Currency>> GetCurrencies();
  66. Task<IEnumerable<ServiceChannelCodeIdDto>> GetBoxServiceChannelCodes(string boxNumber);
  67. }
  68. public class Sys_Currency
  69. {
  70. /// <summary>
  71. /// 货币名称
  72. /// </summary>
  73. public string Name { get; set; }
  74. /// <summary>
  75. /// 描述
  76. /// </summary>
  77. public string Description { get; set; }
  78. /// <summary>
  79. /// 货币符号
  80. /// </summary>
  81. public string Symbol { get; set; }
  82. /// <summary>
  83. /// USD兑换率
  84. /// </summary>
  85. public decimal USDToExchangeRate { get; set; }
  86. /// <summary>
  87. /// RMB被兑换率
  88. /// </summary>
  89. public decimal ExchangeRateToRMB { get; set; }
  90. /// <summary>
  91. /// 中国银行汇率时间
  92. /// </summary>
  93. public DateTime? ExchangeRateToRMBTime { get; set; }
  94. /// <summary>
  95. /// 更新时间
  96. /// </summary>
  97. public DateTime? UpdateRateDate { get; set; }
  98. public bool IsEnable { get; set; }
  99. }
  100. public class OrderRepository : BaseRepository<Order_Order>, IOrderRepository
  101. {
  102. public class UpdateDataDto
  103. {
  104. public string TransferNumber
  105. {
  106. get; set;
  107. }
  108. public string CustomerOrderNo
  109. {
  110. get; set;
  111. }
  112. public int Id
  113. {
  114. get; set;
  115. }
  116. public string SystemNo
  117. {
  118. get; set;
  119. }
  120. public string TrackingNumber
  121. {
  122. get; set;
  123. }
  124. public DateTime ReceiveTime
  125. {
  126. get; set;
  127. }
  128. public int ChannelId
  129. {
  130. get; set;
  131. }
  132. public string ServiceOrderNumebr { get; set; }
  133. }
  134. private ILogger<OrderInputDto> _logger;
  135. private ILogistics_ChannelRepository _logisticsRepository;
  136. public OrderRepository(IUnitOfWork unitOfWork, ILogger<OrderInputDto> logger, ILogistics_ChannelRepository logisticsRepository) : base(unitOfWork)
  137. {
  138. _logger = logger;
  139. _logisticsRepository = logisticsRepository;
  140. }
  141. async Task<IEnumerable<ServiceChannelCodeIdDto>> IOrderRepository.GetLadingBillServiceChannelCodes(string ladingBillNumber)
  142. {
  143. string sql = @"select id as ChannelId,ServiceChannelCode from Logistics_Channel where id in(
  144. select b.ChannelId from Logistics_Box b inner join Logistics_BoxDetail bd
  145. on b.id=bd.BoxId
  146. where LadingBillNumber=@LadingBillNumber
  147. group by b.ChannelId)";
  148. var items = await _unitOfWork.QueryBySqlAsync<ServiceChannelCodeIdDto>(sql, commandTimeout: 120, param: new { LadingBillNumber = ladingBillNumber });
  149. return items;
  150. }
  151. async Task<IEnumerable<ServiceChannelCodeIdDto>> IOrderRepository.GetBoxServiceChannelCodes(string boxNumber)
  152. {
  153. string sql = @"select id as ChannelId,ServiceChannelCode from Logistics_Channel where id in(
  154. select b.ChannelId from Logistics_Box b inner join Logistics_BoxDetail bd
  155. on b.id=bd.BoxId
  156. where BoxNumber=@boxNumber
  157. group by b.ChannelId)";
  158. var items = await _unitOfWork.QueryBySqlAsync<ServiceChannelCodeIdDto>(sql, commandTimeout: 120, param: new { BoxNumber = boxNumber });
  159. return items;
  160. }
  161. [NonTrans]
  162. public async Task<List<Sys_Currency>> GetCurrencies()
  163. {
  164. string sql = "select * from Sys_Currency(nolock)";
  165. return (await _unitOfWork.QueryBySqlAsync<Sys_Currency>(sql)).ToList();
  166. }
  167. [NonTrans]
  168. async Task<List<BagDeclareRequest>> IOrderRepository.GetWaitBoxDeclareRequest(string[] serviceChannelCodeList)
  169. {
  170. List<BagDeclareRequest> resultList = new List<BagDeclareRequest>();
  171. foreach (var ServiceChannelCode in serviceChannelCodeList)
  172. {
  173. //由于渠道ServiceChannelCode 2041 与其他渠道重复,单独写渠道Id进行预报
  174. IEnumerable<Logistics_Channel> channels = null;
  175. if (ServiceChannelCode == "2041")
  176. {
  177. channels = await _logisticsRepository
  178. .QueryAsync(x => x.Id == 542);
  179. }
  180. else
  181. {
  182. channels = (await _logisticsRepository
  183. .QueryAsync(x => x.ServiceChannelCode == ServiceChannelCode)).OrderBy(x => x.ServiceChannelCode);
  184. }
  185. foreach (var channelId in channels)
  186. {
  187. BagDeclareRequest result = await ((IOrderRepository)this).GetWaitBoxDeclareRequest(channelId.Id);
  188. resultList.Add(result);
  189. }
  190. }
  191. return resultList;
  192. }
  193. async Task<BagDeclareRequest> IOrderRepository.GetWaitBoxDeclareRequest(int channelId, string ladingBillNumber, string boxNumber = null)
  194. {
  195. var channel = await _logisticsRepository.GetAsync(channelId);
  196. BagDeclareRequest bagDeclareRequest = new BagDeclareRequest();
  197. bagDeclareRequest.Channel = channel;
  198. string specifiedAwbCondition = null;
  199. if (string.IsNullOrWhiteSpace(ladingBillNumber) && string.IsNullOrEmpty(boxNumber))
  200. {
  201. //UBI-GB-Line 改为装箱预报
  202. if (channel.Id == 383)
  203. specifiedAwbCondition = " and isnull(b.IsConfim,0) =0 ";
  204. else
  205. specifiedAwbCondition = " and ''!=ISNULL(c.LadingBillNumber,'') and isnull(b.IsConfim,0) =0 ";
  206. }
  207. else if (!string.IsNullOrWhiteSpace(ladingBillNumber))
  208. {
  209. specifiedAwbCondition = $" and c.LadingBillNumber ='{ladingBillNumber}'";
  210. }
  211. else if (!string.IsNullOrEmpty(boxNumber))
  212. {
  213. specifiedAwbCondition += $"and c.boxnumber = '{boxNumber}' and isnull(b.IsConfim,0) =0 ";
  214. }
  215. string dateTime = DateTime.Now.AddMonths(-2).ToString_yyyyMMdd();
  216. string sql = $@"select a.Id as OrderId,a.ActualWeight as ActualWeight,a.ChannelId,e.Id,e.OriginPort as OriginPort,e.Destination as Port,A.ServicesOrderNo as ServiceNo,a.ReceiverCountryCode as CountryCode
  217. , case when a.CustomerId=294 and LEFT(a.TrackingNumber,3)='XYY' then a.TransferNumber else a.TrackingNumber end TrackingNumber
  218. ,c.BoxNumber,c.LadingBillNumber,b.Id as DetailId,a.OPWeight,a.OPWeight - isnull(d.Deduction,0) as Weight,a.CreateOrderChannelId,d.CreateChannelId,c.DestAirPort,c.OriginAirPort,c.UserBoxNumber,a.ServiceOrderNumber3 from Order_Order(nolock)a join Logistics_BoxDetail(nolock) b on a.id=b.OrderId
  219. join Logistics_Box(nolock) c on c.Id= b.BoxId
  220. left join Logistics_LadingBill(nolock) e on e.LadingBillNumber=c.LadingBillNumber and e.IsDeleted=0
  221. left join Weight_Adj(nolock) d on d.CreateChannelId=76
  222. and a.OPWeight between d.Start and d.[End]
  223. where 1=1 and a.ChannelId = {channelId} {specifiedAwbCondition} and c.CreateTime>'{dateTime}' ";
  224. /*Debug*/
  225. //写死一个数据做测试
  226. string testSql = @$"select 666 Id,'LAX' OriginPort,'LAX' Port,A.ServicesOrderNo as ServiceNo,a.ReceiverCountryCode as CountryCode, a.TrackingNumber,'zkltest0001' BoxNumber,'zkltest-0001' LadingBillNumber,666 as DetailId,500 OPWeight,600 Weight,a.CreateOrderChannelId,a.CreateOrderChannelId CreateChannelId,'lax' DestAirPort,'lax' OriginAirPort,a.ServiceOrderNumber3 from Order_Order(nolock)a
  227. where a.Id=223655811";
  228. var items = await _unitOfWork.QueryBySqlAsync<BoxDetailItem>(sql, commandTimeout: 180);
  229. if (channel.Id == 371)
  230. {
  231. foreach (var i in items)
  232. {
  233. i.Weight = i.OPWeight;
  234. i.ActualWeight = i.ActualWeight;
  235. }
  236. }
  237. if (channel.Id == 731)
  238. {
  239. //部分渠道预报取回下单申报信息
  240. int maxQty = 1000;
  241. int count = (int)Math.Ceiling(items.Count() / (decimal)maxQty);
  242. for (var i = 0; i < count; i++)
  243. {
  244. var l = items.Skip(i * maxQty).Take(maxQty);
  245. int[] arrays = l.Select(x => x.OrderId).ToArray();
  246. string goodsDeclareValSql = @"
  247. select a.Id as OrderId, isnull(sum(c.DeclareValue), sum(DeclareFee)) as DeclareValue,min(DeclareCurrency) as DeclareCurrency from Order_Order(nolock)a
  248. join Order_OrderGoods(nolock)b on a.Id = b.OrderId
  249. left join Order_ApiDeclaration(nolock)c on c.Guid=b.Guid
  250. where a.id in @ids
  251. group by a.id
  252. ";
  253. var declareVals = (await _unitOfWork.QueryBySqlAsync<OrderDeclareVal>(goodsDeclareValSql, null, new { ids = arrays })).ToList();
  254. foreach (var item in l)
  255. {
  256. var d = declareVals.First(x => x.OrderId == item.OrderId);
  257. item.DeclareCurrency = d.DeclareCurrency;
  258. item.DeclareValue = d.DeclareValue;
  259. }
  260. }
  261. }
  262. var dicts = items.GroupBy(x => new { x.CountryCode, x.BoxNumber })
  263. .ToDictionary(x => x.Key.BoxNumber, x => x.ToList());
  264. bagDeclareRequest.BatchDeclare = dicts;
  265. return bagDeclareRequest;
  266. }
  267. public class OrderDeclareVal
  268. {
  269. public int OrderId
  270. {
  271. get; set;
  272. }
  273. public decimal DeclareValue
  274. {
  275. get; set;
  276. }
  277. public string DeclareCurrency
  278. {
  279. get; set;
  280. }
  281. }
  282. [NonTrans]
  283. async Task<List<OrderConfimRequest>> IOrderRepository.GetWaitConfimOrders(int qty)
  284. {
  285. int[] IdList = new int[]{ 458,540,
  286. 539,
  287. 538,
  288. 537,
  289. 536,549,
  290. 550,565,579,580,574,700,
  291. 573,
  292. 572,
  293. 571,669,668,742,743,744,745};
  294. Dictionary<int[], int[]> customerDic = new Dictionary<int[], int[]>() { { new int[] { 1444 }, new int[] { 383 } } };
  295. int[] testList = new int[] { 742 };//测试用 and c.SystemNo='XYYEX0029375687YQ'
  296. // string sql = $@"
  297. //select top {qty} * from (
  298. //select top {qty} b.Id as BoxDetailId,c.ChannelId,
  299. // c.ServicesOrderNo,case when c.ChannelId=187 then c.TrackingNumber else c.ServicesOrderNo end as OrderNo,c.TrackingNumber,d.ServiceCode,c.ActualWeight as OPWeight from Logistics_Box(nolock) a
  300. // join Logistics_BoxDetail(nolock) b on a.Id=b.BoxId
  301. // join Order_Order(nolock) c on c.id= b.OrderId
  302. // join Logistics_Channel(nolock) d on d.Id = c.ChannelId
  303. // where
  304. // isnull( b.IsConfim ,0)=0 and a.IsDelivery=1 and c.ChannelId in @Id and c.ReceiveTime>'2022-12-06'
  305. //union
  306. //select top {qty} b.Id as BoxDetailId,c.ChannelId,
  307. // c.ServicesOrderNo,case when c.ChannelId=187 then c.TrackingNumber else c.ServicesOrderNo end as OrderNo,c.TrackingNumber,d.ServiceCode,c.ActualWeight as OPWeight from Logistics_Box(nolock) a
  308. // join Logistics_BoxDetail(nolock) b on a.Id=b.BoxId
  309. // join Order_Order(nolock) c on c.id= b.OrderId
  310. // join Logistics_Channel(nolock) d on d.Id = c.ChannelId
  311. // where
  312. // isnull( b.IsConfim ,0)=0 and a.IsDelivery=1 and c.CustomerId in @customerIds and a.ChannelId in @customerChannelId and c.ReceiveTime>'2022-12-06')t1";
  313. //4
  314. string dayAgo = DateTime.Now.AddDays(-4).ToString_yyyyMMdd();
  315. string sql = $@"select top {qty} b.Id as BoxDetailId,c.ChannelId,
  316. c.ServicesOrderNo,c.ServicesOrderNo as OrderNo,c.ServiceOrderNumber3,c.TrackingNumber,d.ServiceCode,c.ActualWeight as OPWeight from Logistics_Box(nolock) a
  317. left join Logistics_BoxDetail(nolock) b on a.Id=b.BoxId
  318. left join Order_Order(nolock) c on c.id= b.OrderId
  319. left join Logistics_Channel(nolock) d on d.Id = c.ChannelId
  320. where
  321. a.DeliveryTime>'{dayAgo}' and isnull( b.IsConfim ,0)=0 and b.Id>0 and a.IsDelivery=1 and a.ChannelId in @Id ";
  322. return (await _unitOfWork.QueryBySqlAsync<OrderConfimRequest>(sql, 300, new { Id = IdList, customerIds = customerDic.FirstOrDefault().Key, customerChannelId = customerDic.FirstOrDefault().Value })).ToList();
  323. }
  324. async Task<int> IOrderRepository.GetNewId()
  325. {
  326. string connText = _unitOfWork.ConnectionAddress;
  327. using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connText))
  328. {
  329. string sql = @"INSERT INTO SysNewID (TmpInt) OUTPUT inserted.ID Values(1); ";
  330. using (System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand(sql, conn))
  331. {
  332. try
  333. {
  334. conn.Open();
  335. var val = await command.ExecuteScalarAsync();
  336. try
  337. {
  338. int id = (int)val;
  339. return id;
  340. }
  341. catch
  342. {
  343. throw new Exception("标识生成失败");
  344. }
  345. }
  346. catch (Exception ex)
  347. {
  348. throw new Exception("标识列生成失败:" + ex.Message);
  349. }
  350. finally
  351. {
  352. conn.Close();
  353. }
  354. }
  355. }
  356. }
  357. /// <summary>
  358. /// 导入澳鹏订单
  359. /// </summary>
  360. /// <param name="orders">导入澳鹏订单</param>
  361. /// <returns></returns>
  362. async Task IOrderRepository.InputOrderAndGoods(List<OrderInputDto> orders)
  363. {
  364. try
  365. {
  366. List<Order_OrderGoods> bulkGoods = new List<Order_OrderGoods>();
  367. List<Logistics_BoxDetail> bulkBoxDetails = new List<Logistics_BoxDetail>();
  368. foreach (var order in orders)
  369. {
  370. try
  371. {
  372. if (!(await IsExistsAsync(x => x.CustomerOrderNo == order.CustomerOrderNo || x.TrackingNumber == order.TrackingNumber)))
  373. {
  374. var id = await InsertAsync(order);
  375. order.GoodsList.ForEach(x => x.OrderId = (int)id);
  376. bulkGoods.AddRange(order.GoodsList);
  377. Logistics_BoxDetail boxDetail = new Logistics_BoxDetail
  378. {
  379. BoxId = order.BoxId,
  380. OrderId = (int)id,
  381. TrackingNumber = order.TrackingNumber,
  382. TryAgainToSubmit = false,
  383. CreateTime = DateTime.Now,
  384. CreateUserName = "system"
  385. };
  386. }
  387. else
  388. {
  389. //已存在的不再重复导入
  390. _logger.LogWarning(order.TrackingNumber + ";" + order.CustomerOrderNo + "重复");
  391. }
  392. }
  393. catch (Exception ex)
  394. {
  395. _logger.LogError("单条错误:" + order.TrackingNumber + ";" + order.CustomerOrderNo);
  396. throw ex;
  397. }
  398. }
  399. await _unitOfWork.BulkToDBAsync<Order_OrderGoods>(bulkGoods);
  400. await _unitOfWork.BulkToDBAsync<Logistics_BoxDetail>(bulkBoxDetails);
  401. _logger.LogWarning("导入订单成功条数:" + orders.Count);
  402. }
  403. catch (Exception ex)
  404. {
  405. _logger.LogError(ex.Message, ex);
  406. throw ex;
  407. }
  408. }
  409. async Task IOrderRepository.AddWinitLog(string winitOrderId, string transferNumber)
  410. {
  411. string sql = @"insert WinitOrderInfo values(@winitOrderId,@transferNumber)";
  412. await _unitOfWork.Connection.ExecuteAsync(sql, new
  413. {
  414. winitOrderId = winitOrderId,
  415. transferNumber = transferNumber
  416. }, null, null, System.Data.CommandType.Text);
  417. }
  418. /// <summary>
  419. /// 添加一个渠道下单时的渠道单号与XYY转单号关系记录
  420. /// </summary>
  421. /// <param name="channelId"></param>
  422. /// <param name="channelOrderId"></param>
  423. /// <param name="transferNumber"></param>
  424. /// <returns></returns>
  425. async Task IOrderRepository.AddChannelOrderInfoRecord(int channelId, string channelOrderId, string transferNumber)
  426. {
  427. string sql = @"insert ChannelOrderInfoRecord values(@ChannelOrderId,@TransferNumber,@ChannelId,getdate())";
  428. await _unitOfWork.Connection.ExecuteAsync(sql, new
  429. {
  430. ChannelOrderId = channelOrderId,
  431. TransferNumber = transferNumber,
  432. ChannelId = channelId
  433. }, null, null, System.Data.CommandType.Text);
  434. }
  435. [NonTrans]
  436. async Task<string> IOrderRepository.GetChannelOrderInfoRecord(int channelId, string transferNumber)
  437. {
  438. string sql = "select top 1 ChannelOrderId from ChannelOrderInfoRecord(nolock) where transferNumber=@transferNumber and ChannelId=@channelId";
  439. return (await _unitOfWork.QueryBySqlAsync<string>(sql, null, new { transferNumber = transferNumber, channelId = channelId })).FirstOrDefault();
  440. }
  441. [NonTrans]
  442. async Task<string> IOrderRepository.GetWinitOrderNo(string transferNumber, string SystemNo = "")
  443. {
  444. string sql = "select top 1 WinitOrderId from WinitOrderInfo(nolock) where transferNumber=@transferNumber";
  445. if (!string.IsNullOrEmpty(SystemNo)) { sql += $" or transferNumber='{SystemNo}' "; }
  446. return (await _unitOfWork.QueryBySqlAsync<string>(sql, null, new { transferNumber = transferNumber })).FirstOrDefault();
  447. }
  448. int IOrderRepository.GetPackagePrintQty(string customerOrderNo)
  449. {
  450. using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(_unitOfWork.ConnectionAddress))
  451. {
  452. conn.Open();
  453. using (System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand("GetPackagePrintQty", conn))
  454. {
  455. try
  456. {
  457. command.CommandType = System.Data.CommandType.StoredProcedure;
  458. command.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CustomerOcrderNo", customerOrderNo));
  459. var val = command.ExecuteScalar();
  460. if (val == null || val == DBNull.Value)
  461. throw new Exception("数据服务出错");
  462. else
  463. return (int)val;
  464. }
  465. catch (Exception ex)
  466. {
  467. throw ex;
  468. }
  469. finally
  470. {
  471. conn.Close();
  472. }
  473. }
  474. };
  475. }
  476. async Task<IEnumerable<SysWarehouseFileLog>> IOrderRepository.GetWaitDownFile(int qty)
  477. {
  478. string sql = $@"select top {qty} * from SysWarehouseFileLog(nolock) where IsSysWarehouseFile=0 ";
  479. return await _unitOfWork.QueryBySqlAsync<SysWarehouseFileLog>(sql);
  480. }
  481. async Task IOrderRepository.UpdateDownFile(List<SysWarehouseFileLog> transfernums)
  482. {
  483. string sql = @"update SysWarehouseFileLog set IsSysWarehouseFile =1,UpdateTime=getdate() where Id in @Id";
  484. await _unitOfWork.ExecuteAsync(sql, new { Id = transfernums.Select(x => x.Id).ToList() });
  485. }
  486. async Task<PageResult<View_QueryOverCancelOrders>> IOrderRepository.QueryOverCancelOrders(QueryModel queryModel)
  487. {
  488. return await _unitOfWork.GetPagingListAsync<View_QueryOverCancelOrders>(queryModel);
  489. }
  490. async Task<List<dynamic>> IOrderRepository.QueryCustomerData(string sql)
  491. {
  492. return (await _unitOfWork.QueryBySqlAsync<dynamic>(sql)).ToList();
  493. }
  494. async Task<List<dynamic>> IOrderRepository.GetZZESBUpdateData(string lading)
  495. {
  496. IEnumerable<dynamic> enumerable = (await _unitOfWork.QueryBySqlAsync<dynamic>($@"select d.* from Order_Order(nolock)a
  497. join Logistics_BoxDetail(nolock)b on a.id = b.OrderId
  498. join Logistics_Box(nolock)c on c.id = b.BoxId
  499. left join ZZESBUpdateData(nolock) d on d.orderid = a.Id
  500. where c.LadingBillNumber = '{lading}'"));
  501. return new List<dynamic>(enumerable);
  502. }
  503. async Task IOrderRepository.SetUnusualNotTransfer(string trackingNumber, UnusualReasonType UnusualReasonType, bool IsReprocessing)
  504. {
  505. string sql = "SetOrderUnusualReason";
  506. await ExecuteSqlNotTransferAsync(sql, new { TrakcingNumber = trackingNumber, UnusualReason = UnusualReasonType.GetValue(), UserName = _unitOfWork.CurrentName, IsReprocessing = IsReprocessing });
  507. }
  508. async Task IOrderRepository.AddChannelOrderInfoRecord(string FCOrderId, string transferNumber, int channelId)
  509. {
  510. string sql = @"pro_addChannelOrderInfoRecord";
  511. await ExecuteSqlNotTransferAsync(sql, new
  512. {
  513. FCOrderId = FCOrderId,
  514. transferNumber = transferNumber,
  515. ChannelId = channelId
  516. });
  517. }
  518. async Task<PageResult<BagDeclareLog>> IOrderRepository.GetBagDeclareLogs(QueryModel queryModel)
  519. {
  520. var pageResult = await _unitOfWork.GetPagingListAsync<BagDeclareLog>(queryModel, 60);
  521. return pageResult;
  522. }
  523. #region 订单管理
  524. async Task<OrderQtys> IOrderRepository.GetCustomerDraftOrderCount(QueryModel qm)
  525. {
  526. string where = GetCustomerWhere(qm);
  527. string sql2 = "select count(0) Qty,10000 OrderStatus from Order_DraftOrder(nolock) where 1=1 " + where + "";
  528. return (await _unitOfWork.QueryBySqlAsync<OrderQtys>(sql2)).FirstOrDefault();
  529. }
  530. public string GetCustomerWhere(QueryModel qm)
  531. {
  532. //移除状态
  533. var status = qm.QueryParamer.FirstOrDefault(x => x.Filed == "OrderStatus");
  534. if (status != null)
  535. {
  536. qm.QueryParamer.Remove(status);
  537. }
  538. //修改批量查询方式
  539. var numbers = qm.QueryParamer.FirstOrDefault(x => x.Filed == "SearchNumberList");
  540. if (numbers != null)
  541. {
  542. numbers.Filed = "ReferenceNo";
  543. numbers.Method = "In";
  544. }
  545. var PostDSStatus = qm.QueryParamer.FirstOrDefault(x => x.Filed == "PostDSStatus");
  546. if (PostDSStatus != null)
  547. {
  548. qm.QueryParamer.Remove(PostDSStatus);
  549. }
  550. //修正查询条件
  551. var country = qm.QueryParamer.FirstOrDefault(x => x.Filed == "ReceiverCountryCode");
  552. if (country != null)
  553. {
  554. country.Filed = "CountryCode";
  555. }
  556. var channel = qm.QueryParamer.FirstOrDefault(x => x.Filed == "CreateOrderChannelId");
  557. if (channel != null)
  558. {
  559. channel.Filed = "ChannelId";
  560. }
  561. var receiveTime = qm.QueryParamer.Where(x => x.Filed == "ReceiveTime");
  562. if (receiveTime != null && receiveTime.Count() > 0)
  563. {
  564. qm.QueryParamer.RemoveAll(x => x.Filed == "ReceiveTime");
  565. }
  566. var IsOnline = qm.QueryParamer.FirstOrDefault(x => x.Filed == "IsOnline");
  567. if (IsOnline != null)
  568. {
  569. qm.QueryParamer.Remove(IsOnline);
  570. }
  571. var FullName = qm.QueryParamer.FirstOrDefault(x => x.Filed == "ReceiverName");
  572. if (FullName != null)
  573. {
  574. FullName.Filed = "FullName";
  575. }
  576. var MpsOrder = qm.QueryParamer.FirstOrDefault(x => x.Filed == "MpsOrderId");
  577. if (MpsOrder != null)
  578. {
  579. MpsOrder.Filed = "MoreThanOneTicket";
  580. MpsOrder.Method = "Eq";
  581. }
  582. return GetWhere(qm.QueryParamer) + " and Status<>1 and Status<>-1 ";
  583. }
  584. async Task<List<OrderQtys>> IOrderRepository.GetOrderQty(QueryModel qm)
  585. {
  586. if (!qm.QueryParamer.Exists(x => x.Filed == "SearchNumberList"))
  587. {
  588. string sql = "select count(0)Qty,OrderStatus from Order_Order(nolock) where 1=1" + GetWhere(qm.QueryParamer) + " group by OrderStatus";
  589. return (await _unitOfWork.QueryBySqlAsync<OrderQtys>(sql)).ToList();
  590. }
  591. else
  592. {
  593. string sql2 = GetSql2(qm);
  594. string whereString = GetCWhere(qm);
  595. sql2 += "\r\n select count(0)Qty,OrderStatus from #tempOrders where 1=1 " + whereString + " group by OrderStatus";
  596. return (await _unitOfWork.QueryBySqlAsync<OrderQtys>(sql2)).ToList();
  597. }
  598. }
  599. private string GetSql2(QueryModel qm)
  600. {
  601. var p = qm.QueryParamer.First(x => x.Filed == "SearchNumberList");
  602. qm.QueryParamer.Remove(p);
  603. var xml = string.Join("\r\n", p.Value.Split(',').Select(x => $"<NumberList><Number>{x}</Number></NumberList>"));
  604. string sql2 = @"
  605. if exists (select * from tempdb.dbo.sysobjects where id = object_id(N'tempdb..#temp_searchs') and type='U')
  606. drop table #temp_searchs
  607. if exists (select * from tempdb.dbo.sysobjects where id = object_id(N'tempdb..#tempOrders') and type='U')
  608. drop table #tempOrders
  609. DECLARE @idoc int
  610. DECLARE @doc varchar(max)
  611. SET @doc ='
  612. <ROOT>
  613. {0}
  614. </ROOT>'
  615. --Create an internal representation of the XML document.
  616. EXEC sp_xml_preparedocument @idoc OUTPUT, @doc
  617. -- SELECT stmt using OPENXML rowset provider
  618. select * into #temp_searchs
  619. FROM OPENXML (@idoc, '/ROOT/NumberList',2)
  620. WITH (Number nvarchar(64))
  621. select * into #tempOrders from (
  622. select * from Order_Order(nolock)
  623. join #temp_searchs(nolock) on Order_Order.CustomerOrderNo = #temp_searchs.Number
  624. union
  625. select * from Order_Order(nolock)
  626. join #temp_searchs(nolock) on Order_Order.TransferNumber = #temp_searchs.Number
  627. union
  628. select * from Order_Order(nolock)
  629. join #temp_searchs(nolock) on Order_Order.TrackingNumber = #temp_searchs.Number)zz
  630. ";
  631. return string.Format(sql2, xml);
  632. }
  633. public string GetCWhere(QueryModel queryModel)
  634. {
  635. string where = "";
  636. if (queryModel.QueryParamer != null && queryModel.QueryParamer.Any(x => x.Filed == "OrderStatus"))
  637. where += " and OrderStatus = " + queryModel.QueryParamer.First(x => x.Filed == "OrderStatus").Value;
  638. return where;
  639. }
  640. async Task<PageResult<CustomerOrder>> IOrderRepository.GetCustomerOrderPager(QueryModel qm)
  641. {
  642. PageResult<CustomerOrder> results = new PageResult<CustomerOrder>();
  643. if (!qm.QueryParamer.Exists(x => x.Filed == "SearchNumberList"))
  644. {
  645. var order = await _unitOfWork.GetPagingList2Async<Order_Order>(qm);
  646. results.Result = order.Result.CopyList<CustomerOrder>().ToList();
  647. results.TotalCount = order.TotalCount;
  648. }
  649. else
  650. {
  651. List<string> appendSearchNumberList = new List<string>();
  652. string[] SearchNumberList = qm.QueryParamer.First(x => x.Filed == "SearchNumberList").Value.Split(',');
  653. foreach (string s in SearchNumberList)
  654. {
  655. if (s.Contains("U000") && s.StartsWith("FBA"))
  656. {
  657. appendSearchNumberList.Add(s.Substring(0, s.Length - 7));
  658. }
  659. else
  660. {
  661. appendSearchNumberList.Add(s);
  662. }
  663. }
  664. qm.QueryParamer.First(x => x.Filed == "SearchNumberList").Value = String.Join(',', appendSearchNumberList.ToArray());
  665. string sql2 = GetSql2(qm) + @"
  666. select * from (
  667. select Row_Number()over(order by {0})rowId,Id from #tempOrders
  668. WHERE 1=1 {1}
  669. )T
  670. join Order_Order(nolock) b on t.Id = b.Id where rowId between {2} and {3};
  671. select count(0) from #tempOrders(nolock) WHERE 1=1 {1}
  672. ";
  673. string sortString = GetSortString(qm);
  674. string whereString = GetCWhere(qm);
  675. sql2 = string.Format(sql2, sortString, whereString, (qm.PageIndex - 1) * qm.PageSize + 1, qm.PageSize * qm.PageIndex);
  676. var grid = await _unitOfWork.Connection.QueryMultipleAsync(sql2, transaction: _unitOfWork.Transaction, commandTimeout: 600);
  677. results.Result = grid.Read<CustomerOrder>();
  678. results.TotalCount = grid.Read<int>().SingleOrDefault();
  679. }
  680. string sql = "select status as LatestLogisticsStatus , targettime as LatestLogisticsTime,LastMessage,OrderId as Id from Logistics_Trace(nolock) where OrderId in @OrderId ";
  681. var r = await _unitOfWork.QueryBySqlAsync<CustomerOrder>(sql, null, new { OrderId = results.Result.Select(x => x.Id).ToArray() });
  682. foreach (var item in results.Result)
  683. {
  684. var t = r.FirstOrDefault(x => x.Id == item.Id);
  685. if (t != null)
  686. {
  687. item.LastMessage = t.LastMessage;
  688. item.LatestLogisticsStatus = t.LatestLogisticsStatus;
  689. item.LatestLogisticsTime = t.LatestLogisticsTime;
  690. }
  691. }
  692. string sql4 = "select OrderId as Id,CustomerSettlement,BranchOfficeSettlement from Order_MpsOrder(nolock) where OrderId in @OrderId";
  693. var r3 = await _unitOfWork.QueryBySqlAsync<CustomerOrder>(sql4, null, new { OrderId = results.Result.Select(x => x.Id).ToArray() });
  694. foreach (var item in results.Result)
  695. {
  696. var t = r3.FirstOrDefault(x => x.Id == item.Id);
  697. if (t != null)
  698. {
  699. item.CustomerSettlement = t.CustomerSettlement;
  700. item.BranchOfficeSettlement = t.BranchOfficeSettlement;
  701. }
  702. }
  703. string sql3 = "select CFright,OrderId as Id from order_fee(nolock) where orderId in @OrderId";
  704. var r2 = await _unitOfWork.QueryBySqlAsync<CustomerOrder>(sql3, null, new { OrderId = results.Result.Select(x => x.Id).ToArray() });
  705. foreach (var item in results.Result)
  706. {
  707. var t = r2.FirstOrDefault(x => x.Id == item.Id);
  708. if (t != null)
  709. {
  710. item.CFright = t.CFright;
  711. }
  712. }
  713. results.PageIndex = qm.PageIndex;
  714. results.PageSize = qm.PageSize;
  715. return results;
  716. }
  717. private static string GetSortString(QueryModel qm)
  718. {
  719. string sortString = "Id";
  720. if (qm.QuerySort == null || qm.QuerySort.Count == 0)
  721. {
  722. }
  723. else
  724. {
  725. foreach (var item in qm.QuerySort)
  726. {
  727. sortString += " " + item.Field + " " + (item.IsDesc ? "DESC" : "") + ",";
  728. }
  729. sortString = sortString.TrimEnd(',');
  730. }
  731. return sortString;
  732. }
  733. async Task<CustomerOrder> IOrderRepository.GetCustomerOrder(int id)
  734. {
  735. Order_Order order = await GetAsync(id);
  736. var data = (await _unitOfWork.QueryBySqlAsync<Order_UnusualReason>("select top 1 UnusualReason from Order_UnusualReason(nolock) where OrderId =" + id)).FirstOrDefault();
  737. CustomerOrder dto = order.Copy<CustomerOrder>();
  738. if (data != null)
  739. {
  740. dto.UnusualReason = data.UnusualReason.ToString();
  741. }
  742. else
  743. {
  744. dto.UnusualReason = "无";
  745. }
  746. switch (dto.OrderStatus)
  747. {
  748. case 1:
  749. dto.StrOrderStatus = "待揽件";
  750. break;
  751. case 2:
  752. dto.StrOrderStatus = "处理中";
  753. break;
  754. case 3:
  755. dto.StrOrderStatus = "已出库";
  756. break;
  757. case 4:
  758. dto.StrOrderStatus = "已退件";
  759. break;
  760. case -1:
  761. dto.StrOrderStatus = "已取消";
  762. break;
  763. case 0:
  764. dto.StrOrderStatus = "已取消";
  765. break;
  766. case -2:
  767. dto.StrOrderStatus = "已取消";
  768. break;
  769. }
  770. //物流简码和服务商
  771. await GetTrackingShippingSerivce(dto);
  772. dto.Goods = (await _unitOfWork.QueryAsync<Order_OrderGoods>(x => x.OrderId == order.Id)).ToList();
  773. dto.FristTrackingLogs = (await _unitOfWork.QueryAsync<Logistics_TrackingLog>(x => x.OrderId == order.Id)).ToList();
  774. return dto;
  775. }
  776. public async Task GetTrackingShippingSerivce(CustomerOrder dto)
  777. {
  778. var allCodesSql = "select * from Logistics_ChannelFirstCode(nolock)";
  779. var allCodes = (await _unitOfWork.QueryBySqlAsync<dynamic>(allCodesSql)).ToList();
  780. allCodes.ForEach(x => x.FirstCode = (x.FirstCode as string).Replace("\r", "").Replace("\n", "").Trim());
  781. dynamic code = null;
  782. var codes = allCodes.Where(x => x.ChannelId == dto.ChannelId);
  783. if (codes.Count() == 1)
  784. {
  785. code = codes.First();
  786. }
  787. else if (codes.Count() > 1)
  788. {
  789. code = codes.Where(c => !string.IsNullOrEmpty(c.Regex) && (c.Regex as string).Split(',', ' ').Any(y => dto.TrackingNumber.StartsWith(y))).FirstOrDefault();
  790. }
  791. if (code != null)
  792. {
  793. dto.ShippingServiceName = code.FirstCode;
  794. dto.ShippingServiceUrl = code.Url;
  795. }
  796. }
  797. async Task<CustomerOrder> IOrderRepository.GetCustomerDraftOrder(int id)
  798. {
  799. string sql = @"select ReferenceNo as CustomerOrderNo,
  800. CountryCode as ReceiverCountryCode,
  801. b.Name as ChannelName,
  802. Weight as CustomerWeight,
  803. CodFee as CodFee,
  804. CodCurrency as CodCurrency,
  805. FullName as ReceiverName,
  806. Phone as ReceiverPhone,
  807. Email as ReceiverEmail,
  808. City as ReceiverCity,
  809. a.Id,
  810. State as ReceiverState,
  811. ZipCode as ReceiverZipCode,
  812. Street as ReceiverStreet,
  813. House as House,
  814. IOSS as IOSS,
  815. a.ErrorMessage,
  816. Status as DraftStatus,
  817. 0 as IsOnline from Order_DraftOrder(nolock)a
  818. left join Logistics_Public(nolock)b on a.ChannelCode=b.Code
  819. where a.id =" + id;
  820. var order = (await _unitOfWork.QueryBySqlAsync<CustomerOrder>(sql)).FirstOrDefault();
  821. order.HasIOSS = !string.IsNullOrEmpty(order.ioss);
  822. if (order.DraftStatus == 0)
  823. {
  824. order.StrDraftStatus = "待处理";
  825. }
  826. else
  827. {
  828. order.StrDraftStatus = "失败";
  829. }
  830. if (order == null)
  831. throw new Exception("未找到相关草稿订单");
  832. var goods = await _unitOfWork.QueryBySqlAsync<Order_OrderGoods>("select *,ProductNo as GoodsNumber from Order_DraftOrderGoods(nolock) where DraftOrderId=" + id);
  833. order.Goods = goods.ToList();
  834. return order;
  835. }
  836. async Task<PageResult<CustomerOrder>> IOrderRepository.GetCustomerDraftOrderList(QueryModel qm)
  837. {
  838. string where = GetCustomerWhere(qm);
  839. string sql = @"
  840. select
  841. b.Id,
  842. b.ErrorMessage,
  843. b.ReferenceNo as CustomerOrderNo,
  844. b.CountryCode as ReceiverCountryCode,
  845. b.CreateTime,
  846. b.FullName as ReceiverName,
  847. b.Weight as CustomerWeight,
  848. d.Name as ChannelName,
  849. b.Status as DraftStatus
  850. ,b.MoreThanOneTicket MpsOrderId
  851. from(
  852. select Row_Number() over(order by {0})rowId,Id from Order_DraftOrder
  853. WHERE 1 = 1 {1}
  854. )T
  855. join Order_DraftOrder(nolock) b on t.Id = b.Id
  856. left join Logistics_Public(nolock)d on d.Code = b.ChannelCode
  857. where rowId between {2}
  858. and {3};
  859. select count(0) from Order_DraftOrder(nolock) WHERE 1=1 {1}
  860. ";
  861. string sort = GetSortString(qm);
  862. sql = string.Format(sql, sort, where, (qm.PageIndex - 1) * qm.PageSize + 1, qm.PageSize * qm.PageIndex);
  863. var grid = await _unitOfWork.Connection.QueryMultipleAsync(sql, transaction: _unitOfWork.Transaction, commandTimeout: 600);
  864. var pr = new PageResult<CustomerOrder>();
  865. pr.Result = grid.Read<CustomerOrder>();
  866. pr.TotalCount = grid.Read<int>().SingleOrDefault();
  867. pr.PageIndex = qm.PageIndex;
  868. pr.PageSize = qm.PageSize;
  869. return pr;
  870. }
  871. async Task<List<CustomerOrder>> IOrderRepository.GetCustomerOrderList(QueryModel qm)
  872. {
  873. if (!qm.QueryParamer.Exists(x => x.Filed == "SearchNumberList"))
  874. {
  875. string where = GetWhere(qm.QueryParamer);
  876. return (await _unitOfWork.QueryBySqlAsync<CustomerOrder>("select * from CustomerOrder(nolock) where 1=1 " + where)).ToList();
  877. }
  878. else
  879. {
  880. string sql2 = GetSql2(qm);
  881. string whereString = GetCWhere(qm);
  882. sql2 += "\r\n select b.* from(select Id from #tempOrders where 1=1 " + whereString + " ) a join CustomerOrder(nolock)b on a.Id=b.Id";
  883. return (await _unitOfWork.QueryBySqlAsync<CustomerOrder>(sql2)).ToList();
  884. }
  885. }
  886. async Task IOrderRepository.UpdateTrackingNumber(List<UpdateDataDto> updateDatas)
  887. {
  888. StringBuilder sb = new StringBuilder();
  889. foreach (var item in updateDatas)
  890. {
  891. string serviceOrderNumebr = item.ServiceOrderNumebr;
  892. sb.AppendLine($"update order_order set TransferNumber='{item.TransferNumber}',trackingnumber = '{item.TrackingNumber}',SendOutTime='{item.ReceiveTime.ToString_yyyyMMddHHmmss()}'," +
  893. $"ServiceOrderNumber4='{serviceOrderNumebr}',ReceiveTime='{item.ReceiveTime.ToString_yyyyMMddHHmmss()}',OrderStatus=3 where Id = '{item.Id}'");
  894. if (!string.IsNullOrEmpty(item.ServiceOrderNumebr))
  895. {
  896. sb.AppendLine(@$" if (select count(0) from Order_ZZESBJJData(nolock) where SystemNo = '{item.SystemNo}')=0
  897. begin
  898. insert Order_ZZESBJJData(CreateTime,SystemNo,Weight,CountryCode,DownloadTime,TransferNumber,TrackingNumber)
  899. select getdate(),SystemNo,CustomerWeight,ReceiverCountryCode,'{item.ReceiveTime.ToString_yyyyMMddHHmmss()}','{item.TransferNumber}','{item.TrackingNumber}' from Order_Order (nolock) where Id = '{item.Id}'
  900. end");
  901. }
  902. //写入两条同步TASK
  903. }
  904. await _unitOfWork.ExecuteAsync(sb.ToString());
  905. }
  906. async Task<List<Order_Order>> IOrderRepository.GetWaitSyncCustomerTracking(int qty)
  907. {
  908. string sql = $@"
  909. select top 30 Id,SystemNo,CustomerOrderNo,TrackingNumber as TransferNumber,CreateTime,ChannelId from Order_Order(nolock)
  910. where CustomerId=1238 and orderstatus=1 and datediff(minute ,updatetime,getdate())>120
  911. and DATEDIFF(HOUR,CreateTime,getdate())>48 and trackingnumber like 'xyy%'
  912. and CreateTime>'2023-11-15'";
  913. var list = (await _unitOfWork.QueryBySqlAsync<Order_Order>(sql)).ToList();
  914. foreach (var item in list)
  915. {
  916. if (item.ChannelId == 461)
  917. {
  918. item.ServiceOrderNumber4 = "DWESB";
  919. }
  920. else
  921. {
  922. item.ServiceOrderNumber4 = string.Empty;
  923. }
  924. }
  925. return list;
  926. }
  927. /// <summary>
  928. /// 取待同步的轨迹(100条)
  929. /// </summary>
  930. /// <param name="qty"></param>
  931. /// <returns></returns>
  932. public async Task<List<Order_CustomerAsyncTracking>> GetWaitAsyncZZESBData(int qty)
  933. {
  934. string sql = $@"select top {qty} * from Order_CustomerAsyncTracking(nolock) where AnsycTime is null and OperTime<getdate() and ChannelId=227";
  935. return (await _unitOfWork.QueryBySqlAsync<Order_CustomerAsyncTracking>(sql)).ToList();
  936. }
  937. public async Task<List<Order_CustomerAsyncTracking>> GetWaitAsyncKTXESBData(int qty)
  938. {
  939. string sql = $@"select top {qty} * from Order_CustomerAsyncTracking(nolock) where AnsycTime is null and OperTime<getdate() and ChannelId=569";
  940. return (await _unitOfWork.QueryBySqlAsync<Order_CustomerAsyncTracking>(sql)).ToList();
  941. }
  942. public async Task InsertFirstToDB(List<Order_CustomerAsyncTracking> list)
  943. {
  944. string batchSql = "";
  945. foreach (var item in list)
  946. {
  947. batchSql +=
  948. $@"insert Logistics_TrackingLog(TriggerTime,Location,Status,CreateUserName,CreateTime,UpdateUserName,UpdateTime,Remark,TransferNumber,OrderId,StatusString)
  949. values('{item.OperTime}','{item.Loaction}',4,'admin',getdate(),null,null,null,'{item.TransferNumber}',{item.OrderId},'{item.Event}') ";
  950. }
  951. if (!string.IsNullOrEmpty(batchSql))
  952. {
  953. await _unitOfWork.ExecuteAsync(batchSql);
  954. }
  955. }
  956. public async Task UpdateEnd(List<int> ids)
  957. {
  958. await _unitOfWork.UpdateByConditionAsync<Order_CustomerAsyncTracking, bool>(x => x.Id.In(ids), new { AnsycTime = DateTime.Now });
  959. }
  960. public async Task SetNextUpdate(List<Order_Order> noUpdateData)
  961. {
  962. var ids = noUpdateData.Select(x => x.Id).ToList();
  963. string sql = @"update order_order set updatetime=getdate() where id in @ids";
  964. await _unitOfWork.ExecuteAsync(sql, new { ids });
  965. }
  966. public async Task RemoveWinitLog(string winitOrderId, string transferNumber)
  967. {
  968. string sql = @"delete WinitOrderInfo where WinitOrderId='" + winitOrderId + "'";
  969. await _unitOfWork.ExecuteAsync(sql);
  970. }
  971. #endregion
  972. }
  973. }