OrderItemsApplicationService.cs 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Text.RegularExpressions;
  9. using System.Threading.Tasks;
  10. using System.Web.UI.WebControls;
  11. using Abp.Application.Services.Dto;
  12. using Abp.Auditing;
  13. using Abp.Authorization;
  14. using Abp.Domain.Repositories;
  15. using Abp.Extensions;
  16. using Abp.Json;
  17. using Abp.Timing;
  18. using Abp.UI;
  19. using IwbZero.AppServiceBase;
  20. using IwbZero.Auditing;
  21. using IwbZero.IdentityFramework;
  22. using IwbZero.Setting;
  23. using ShwasherSys.Authorization.Permissions;
  24. using ShwasherSys.BaseSysInfo;
  25. using ShwasherSys.BaseSysInfo.States;
  26. using ShwasherSys.Common;
  27. using ShwasherSys.Common.Dto;
  28. using ShwasherSys.CustomerInfo;
  29. using ShwasherSys.EntityFramework;
  30. using ShwasherSys.Lambda;
  31. using ShwasherSys.Order.Dto;
  32. using ShwasherSys.OrderSendInfo;
  33. using ShwasherSys.ProductStoreInfo;
  34. namespace ShwasherSys.Order
  35. {
  36. [AbpAuthorize]
  37. public class OrderItemsAppService : ShwasherAsyncCrudAppService<OrderItem, OrderItemDto, int, PagedRequestDto, OrderItemCreateDto, OrderItemUpdateDto >, IOrderItemsAppService
  38. {
  39. protected IRepository<CustomerDefaultProduct> CustomerDefaultProductRepository;
  40. protected IRepository<OrderHeader, string> OrderHeaderRepository;
  41. protected IRepository<ViewOrderItems> ViewOrderItemsRepository;
  42. protected IRepository<OrderSend> OrderSendRepository;
  43. protected IStatesAppService StatesAppService;
  44. protected IRepository<ProductOutStore> ProductOutStoreRepository;
  45. protected IRepository<CurrentProductStoreHouse> CurrentProductStoreHouseRepository;
  46. protected IRepository<ViewBookedProductNum, string> ViewBookedProductNumRepository;
  47. protected IRepository<ViewCanProductStore, string> ViewCanProductStoreRepository;
  48. protected IRepository<BusinessLog> BusinessLogRepository;
  49. protected IRepository<OrderSendExceed> OrderSendExceedRepository;
  50. protected IRepository<ScheduleOrderSend> ScheduleOrderSendRepository;
  51. protected ICommonAppService CommonAppService { get; }
  52. protected IQueryAppService QueryAppService { get; }
  53. protected ISqlExecuter SqlExecuter { get; }
  54. public OrderItemsAppService(IRepository<OrderItem, int> repository, IRepository<CustomerDefaultProduct> customerDefaultProductRepository, IRepository<OrderHeader, string> orderHeaderRepository, IRepository<ViewOrderItems> viewOrderItemsRepository, IRepository<OrderSend> orderSendRepository, IIwbSettingManager settingManager, IRepository<ProductOutStore> productOutStoreRepository, IRepository<CurrentProductStoreHouse> currentProductStoreHouseRepository, IRepository<ViewBookedProductNum, string> viewBookedProductNumRepository, IRepository<ViewCanProductStore, string> viewCanProductStoreRepository, IRepository<BusinessLog> businessLogRepository, IStatesAppService statesAppService, ICommonAppService commonAppService, IRepository<OrderSendExceed> orderSendExceedRepository, ISqlExecuter sqlExecuter, IQueryAppService queryAppService, IRepository<ScheduleOrderSend> scheduleOrderSendRepository) : base(repository)
  55. {
  56. CustomerDefaultProductRepository = customerDefaultProductRepository;
  57. OrderHeaderRepository = orderHeaderRepository;
  58. ViewOrderItemsRepository = viewOrderItemsRepository;
  59. OrderSendRepository = orderSendRepository;
  60. ProductOutStoreRepository = productOutStoreRepository;
  61. CurrentProductStoreHouseRepository = currentProductStoreHouseRepository;
  62. ViewBookedProductNumRepository = viewBookedProductNumRepository;
  63. ViewCanProductStoreRepository = viewCanProductStoreRepository;
  64. BusinessLogRepository = businessLogRepository;
  65. StatesAppService = statesAppService;
  66. SettingManager = settingManager;
  67. CommonAppService = commonAppService;
  68. OrderSendExceedRepository = orderSendExceedRepository;
  69. SqlExecuter = sqlExecuter;
  70. QueryAppService = queryAppService;
  71. ScheduleOrderSendRepository = scheduleOrderSendRepository;
  72. }
  73. protected override string GetPermissionName { get; set; } = PermissionNames.PagesOrderInfoOrderMg;
  74. protected override string GetAllPermissionName { get; set; } = PermissionNames.PagesOrderInfoOrderMg;
  75. protected override string CreatePermissionName { get; set; } = PermissionNames.PagesOrderInfoOrderMgCreateOrderItem;
  76. protected override string UpdatePermissionName { get; set; } = PermissionNames.PagesOrderInfoOrderMgUpdateOrderItem;
  77. protected override string DeletePermissionName { get; set; } = PermissionNames.PagesOrderInfoOrderMgDeleteOrderItem;
  78. public override async Task<PagedResultDto<OrderItemDto>> GetAll(PagedRequestDto input)
  79. {
  80. CheckGetAllPermission();
  81. var query = CreateFilteredQuery(input);
  82. // CacheManager.GetCache(ShwasherConsts.EmployeeCache).GetAsync("",()=>ViewEmployeeRepository.GetAllList())
  83. if (input.SearchList != null && input.SearchList.Count > 0)
  84. {
  85. List<LambdaObject> objList = new List<LambdaObject>();
  86. foreach (var o in input.SearchList)
  87. {
  88. if (o.KeyWords.IsNullOrEmpty())
  89. continue;
  90. object keyWords = o.KeyWords;
  91. objList.Add(new LambdaObject
  92. {
  93. FieldType = (LambdaFieldType)o.FieldType,
  94. FieldName = o.KeyField,
  95. FieldValue = keyWords,
  96. ExpType = (LambdaExpType)o.ExpType
  97. });
  98. }
  99. var exp = objList.GetExp<OrderItem>();
  100. query = query.Where(exp);
  101. }
  102. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  103. query = ApplySorting(query, input);
  104. query = ApplyPaging(query, input);
  105. var entities = await AsyncQueryableExecuter.ToListAsync(query);
  106. var dtos = new PagedResultDto<OrderItemDto>(
  107. totalCount,
  108. entities.Select(MapToEntityDto).ToList()
  109. );
  110. return dtos;
  111. }
  112. [AbpAuthorize(PermissionNames.PagesOrderInfoNotCompleteOrderItem, PermissionNames.PagesOrderInfoOrderQueryMg)]
  113. public async Task<PagedResultDto<ViewOrderItems>> GetViewAll(PagedRequestDto input)
  114. {
  115. var query = ViewOrderItemsRepository.GetAll();
  116. if (input.SearchList != null && input.SearchList.Count > 0)
  117. {
  118. List<LambdaObject> objList = new List<LambdaObject>();
  119. foreach (var o in input.SearchList)
  120. {
  121. if (o.KeyWords.IsNullOrEmpty())
  122. continue;
  123. object keyWords = o.KeyWords;
  124. //检查查询条件中带有规格且多个分割条件的
  125. ProductModelSearch.CheckModelGreaterOneFilter(o, ref keyWords);
  126. objList.Add(new LambdaObject
  127. {
  128. FieldType = (LambdaFieldType)o.FieldType,
  129. FieldName = o.KeyField,
  130. FieldValue = keyWords,
  131. ExpType = (LambdaExpType)o.ExpType,
  132. });
  133. }
  134. var exp = objList.GetExp<ViewOrderItems>();
  135. query = query.Where(exp);
  136. }
  137. query = query.Where(i => i.IsLock != "Y");
  138. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  139. query = query.OrderByDescending(i => i.OrderNo);
  140. string pattern = ProductModelSearch.GetModelGreaterOneReg(input.SearchList);
  141. List<ViewOrderItems> entities;
  142. //检查查询条件中带有规格且多个分割条件的
  143. if (!pattern.IsNullOrEmpty())
  144. {
  145. var es = query.ToList();
  146. es = es.Where(f => f.Model != null && Regex.IsMatch(f.Model, pattern)).ToList();
  147. totalCount = es.Count;
  148. entities = es.Skip(input.SkipCount).Take(input.MaxResultCount).ToList();
  149. }
  150. else
  151. {
  152. query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
  153. entities = await AsyncQueryableExecuter.ToListAsync(query);
  154. }
  155. var dtos = new PagedResultDto<ViewOrderItems>(
  156. totalCount,
  157. entities
  158. );
  159. return dtos;
  160. }
  161. [AbpAuthorize(PermissionNames.PagesOrderInfoNotCompleteOrderItem, PermissionNames.PagesOrderInfoOrderQueryMg)]
  162. public async Task<PagedResultDto<ViewOrderItems>> GetViewAllNot(PagedRequestDto input)
  163. {
  164. var query = ViewOrderItemsRepository.GetAll();
  165. if (input.SearchList != null && input.SearchList.Count > 0)
  166. {
  167. List<LambdaObject> objList = new List<LambdaObject>();
  168. foreach (var o in input.SearchList)
  169. {
  170. if (o.KeyWords.IsNullOrEmpty())
  171. continue;
  172. object keyWords = o.KeyWords;
  173. //检查查询条件中带有规格且多个分割条件的
  174. ProductModelSearch.CheckModelGreaterOneFilter(o, ref keyWords);
  175. objList.Add(new LambdaObject
  176. {
  177. FieldType = (LambdaFieldType)o.FieldType,
  178. FieldName = o.KeyField,
  179. FieldValue = keyWords,
  180. ExpType = (LambdaExpType)o.ExpType,
  181. });
  182. }
  183. var exp = objList.GetExp<ViewOrderItems>();
  184. query = query.Where(exp);
  185. }
  186. query = query.Where(i => i.IsLock != "Y");
  187. var totalCount = await AsyncQueryableExecuter.CountAsync(query);
  188. query = query.OrderByDescending(i => i.SendDate).ThenBy(i=>i.ProductNo);
  189. string pattern = ProductModelSearch.GetModelGreaterOneReg(input.SearchList);
  190. List<ViewOrderItems> entities;
  191. //检查查询条件中带有规格且多个分割条件的
  192. if (!pattern.IsNullOrEmpty())
  193. {
  194. var es = query.ToList();
  195. es = es.Where(f => f.Model != null && Regex.IsMatch(f.Model, pattern)).ToList();
  196. totalCount = es.Count;
  197. entities = es.Skip(input.SkipCount).Take(input.MaxResultCount).ToList();
  198. }
  199. else
  200. {
  201. query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
  202. entities = await AsyncQueryableExecuter.ToListAsync(query);
  203. }
  204. //query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
  205. //var entities = await AsyncQueryableExecuter.ToListAsync(query);
  206. var dtos = new PagedResultDto<ViewOrderItems>(
  207. totalCount,
  208. entities
  209. );
  210. return dtos;
  211. }
  212. [AbpAuthorize(PermissionNames.PagesOrderInfoNotCompleteOrderItem, PermissionNames.PagesOrderInfoOrderQueryMg)]
  213. public async Task<string> ExportExcel(List<MultiSearchDtoExt> input)
  214. {
  215. var query = ViewOrderItemsRepository.GetAll();
  216. if (input != null && input.Count > 0)
  217. {
  218. List<LambdaObject> objList = new List<LambdaObject>();
  219. foreach (var o in input)
  220. {
  221. if (o.KeyWords.IsNullOrEmpty())
  222. continue;
  223. object keyWords = o.KeyWords;
  224. //检查查询条件中带有规格且多个分割条件的
  225. ProductModelSearch.CheckModelGreaterOneFilter(o, ref keyWords);
  226. var logicType = LogicType.And;
  227. if (o.LogicType == 1)
  228. {
  229. logicType = LogicType.Or;
  230. }
  231. objList.Add(new LambdaObject
  232. {
  233. FieldType = (LambdaFieldType)o.FieldType,
  234. FieldName = o.KeyField,
  235. FieldValue = keyWords,
  236. ExpType = (LambdaExpType)o.ExpType,
  237. LogicType = logicType
  238. });
  239. }
  240. var exp = objList.GetExp<ViewOrderItems>();
  241. query = query.Where(exp);
  242. }
  243. query = query.Where(i => i.IsLock != "Y");
  244. query = query.OrderByDescending(i => i.OrderNo);
  245. string pattern = ProductModelSearch.GetModelGreaterOneReg(input);
  246. List<ViewOrderItems> entities = await AsyncQueryableExecuter.ToListAsync(query);
  247. //检查查询条件中带有规格且多个分割条件的
  248. if (!pattern.IsNullOrEmpty())
  249. {
  250. entities = entities.Where(f => f.Model != null && Regex.IsMatch(f.Model, pattern)).ToList();
  251. }
  252. //var entities = await AsyncQueryableExecuter.ToListAsync(query);
  253. var r = entities.Select(i => new
  254. {
  255. i.OrderNo,
  256. OrderItemStatusName = StatesAppService.GetDisplayValue("OrderItems", "OrderItemStatusId", i.OrderItemStatusId.ToString()),
  257. i.CustomerName,
  258. i.Model,
  259. i.Rigidity,
  260. i.SurfaceColor,
  261. i.Material,
  262. i.PartNo,
  263. OrderDate = i.OrderDate?.ToString("yyy-MM-dd"),
  264. i.Quantity,
  265. IsPartSend = i.IsPartSend == "Y" ? "是" : "否",
  266. IsReport = i.IsReport == "Y" ? "需要" : "不需要",
  267. i.Price,
  268. i.AfterTaxPrice,
  269. i.TotalPrice,
  270. i.AfterTaxTotalPrice,
  271. i.IsSendQuantity,
  272. i.RemainingQuantity,
  273. i.OrderUnitName,
  274. i.StockNo,
  275. i.ProductNo,
  276. i.ProductName,
  277. SendDate = i.SendDate.ToString("yyy-MM-dd"),
  278. i.OrderItemDesc,
  279. i.SaleType,
  280. SaleTypeName= StatesAppService.GetDisplayValue("OrderHeader", "SaleType", i.SaleType.ToString()),
  281. i.CurrencyId
  282. }).ToList();
  283. string downloadUrl =await SettingManager.GetSettingValueAsync("SYSTEMDOWNLOADPATH");
  284. string lcFilePath = System.Web.HttpRuntime.AppDomainAppPath + "\\" +
  285. downloadUrl;
  286. var exportEntity = new Dictionary<string, string>()
  287. {
  288. {"OrderNo", "订单流水号"},
  289. {"StockNo", "客户订单号"},
  290. {"CustomerName", "客户"},
  291. { "OrderDate","订单日期"},
  292. {"PartNo", "零件号"},
  293. {"ProductName", "产品名称"},
  294. {"Model", "型号"},
  295. {"SurfaceColor", "表色"},
  296. {"Material", "材质"},
  297. {"Rigidity", "硬度"},
  298. {"Quantity", "数量"},
  299. {"IsSendQuantity", "已发数量"},
  300. {"RemainingQuantity", "剩余数"},
  301. {"SendDate", "送货日期"},
  302. {"SaleTypeName", "内销/外销"},
  303. {"IsReport", "检验报告"},
  304. {"IsPartSend", "部分送货"},
  305. {"OrderItemStatusName", "状态"},
  306. {"ProductNo", "产品编号"},
  307. {"OrderUnitName", "单位"},
  308. {"CurrencyId", "货币"},
  309. {"Price", "含税价"},
  310. {"AfterTaxPrice", "不含税价"},
  311. {"TotalPrice", "总价"},
  312. {"AfterTaxTotalPrice", "不含税总价"},
  313. {"OrderItemDesc", "备注"}
  314. };
  315. if (!PermissionChecker.IsGranted(PermissionNames.PagesOrderInfoOrderMgQueryOrderPrice))
  316. {
  317. exportEntity.Remove("TotalPrice");
  318. }
  319. string lcResultFileName = ExcelHelper.EntityListToExcel2003(exportEntity, r, "sheet", lcFilePath);
  320. return Path.Combine(downloadUrl, lcResultFileName);
  321. }
  322. public override async Task<OrderItemDto> Create(OrderItemCreateDto input)
  323. {
  324. CheckCreatePermission();
  325. var orderHeader = await OrderHeaderRepository.GetAsync(input.OrderNo);
  326. if (orderHeader.IsLock == "Y")
  327. {
  328. CheckErrors(IwbIdentityResult.Failed("订单已是删除状态,不可变更信息!详情请联系系统管理员!"));
  329. }
  330. #region 更新客户产品维护信息
  331. var customerDefaultProduct = CustomerDefaultProductRepository.GetAll().Where(i =>
  332. i.ProductNo == input.ProductNo && i.CustomerId == orderHeader.CustomerId)?.FirstOrDefault();
  333. CustomerDefaultProduct exist = !string.IsNullOrEmpty(input.PartNo) ? await CustomerDefaultProductRepository.FirstOrDefaultAsync(i => i.CustomerId == orderHeader.CustomerId && i.PartNo == input.PartNo) : null;
  334. if (customerDefaultProduct == null)
  335. {
  336. if (exist != null)
  337. {
  338. throw new UserFriendlyException($"零件号重复!该客户维护的产品{exist.ProductNo },已经使用了零件号{exist.PartNo}!");
  339. }
  340. customerDefaultProduct = new CustomerDefaultProduct()
  341. {
  342. CustomerId = orderHeader.CustomerId,
  343. ProductNo = input.ProductNo,
  344. PartNo = input.PartNo,
  345. Sequence = 1,
  346. TimeLastMod = Clock.Now
  347. };
  348. }
  349. else
  350. {
  351. if (exist != null && exist.Id != customerDefaultProduct.Id)
  352. {
  353. throw new UserFriendlyException($"零件号重复!该客户维护的产品{exist.ProductNo },已经使用了零件号{exist.PartNo}!");
  354. }
  355. customerDefaultProduct.PartNo = input.PartNo;
  356. customerDefaultProduct.Sequence = customerDefaultProduct.Sequence + 1;
  357. customerDefaultProduct.TimeLastMod = Clock.Now;
  358. }
  359. await CustomerDefaultProductRepository.InsertOrUpdateAsync(customerDefaultProduct);
  360. #endregion
  361. input.OrderItemStatusId = OrderItemStatusEnum.NewCreate.ToInt();
  362. input.SendDate ??= new DateTime(1900, 1, 1);
  363. var dto= await CreateEntity(input);
  364. //await CommonAppService.WriteShortMessage(AbpSession.UserName, SettingManager.GetSettingValue(ShwasherSettingNames.DINGDANLRMSG), "有新订单明细录入", $"新的订单明细录入成功,订单明细流水号为:{dto.Id},请注意查看,并及时跟踪!订单录入明细人为{AbpSession.UserName}");
  365. //await CommonAppService.WriteShortMessageByDep(AbpSession.UserName, SettingManager.GetSettingValue(ShwasherSettingNames.DINGDANLRMSG), "有新订单明细录入", $"新的订单明细录入成功,订单明细流水号为:{dto.Id},请注意查看,并及时跟踪!订单录入明细人为{AbpSession.UserName}", false);
  366. BusinessLogTypeEnum.OrderLog.WriteLog(BusinessLogRepository, "订单明细创建", $"订单明细创建成功!orderNo:{dto.OrderNo},itemId:{input},userName:{AbpSession.UserName}");
  367. return dto;
  368. }
  369. public override async Task<OrderItemDto> Update(OrderItemUpdateDto input)
  370. {
  371. CheckCreatePermission();
  372. var orderHeader = OrderHeaderRepository.Get(input.OrderNo);
  373. if (orderHeader.IsLock == "Y")
  374. {
  375. CheckErrors(IwbIdentityResult.Failed("订单已是删除状态,不可变更信息!详情请联系系统管理员!"));
  376. }
  377. var isHasSend = await CommonAppService.CheckOrderHasSend(orderHeader.Id);
  378. var itemEntity= await CheckOrderItem(input.Id);
  379. if (isHasSend)
  380. {
  381. CheckErrors(IwbIdentityResult.Failed("订单已存在发货记录,不可变更信息!详情请联系系统管理员!"));
  382. }
  383. if (input.SendDate==null)
  384. {
  385. input.SendDate= new DateTime(1900,1,1);
  386. }
  387. //var customerDefaultProduct = CustomerDefaultProductRepository.GetAll().Where(i =>
  388. // i.ProductNo == input.ProductNo && i.CustomerId == orderHeader.CustomerId)?.FirstOrDefault();
  389. //if (customerDefaultProduct == null)
  390. //{
  391. // customerDefaultProduct = new CustomerDefaultProduct()
  392. // {
  393. // CustomerId = orderHeader.CustomerId,
  394. // ProductNo = input.ProductNo,
  395. // Sequence = 1,
  396. // TimeLastMod = Clock.Now
  397. // };
  398. //}
  399. //else
  400. //{
  401. // customerDefaultProduct.Sequence = customerDefaultProduct.Sequence + 1;
  402. // customerDefaultProduct.TimeLastMod = Clock.Now;
  403. //}
  404. //CustomerDefaultProductRepository.InsertOrUpdate(customerDefaultProduct);
  405. //if (!string.IsNullOrEmpty(input.PartNo))
  406. //{
  407. // var customerDefaultProduct = CustomerDefaultProductRepository.GetAll().Where(i =>
  408. // i.ProductNo == input.ProductNo && i.CustomerId == orderHeader.CustomerId)?.FirstOrDefault();
  409. // var exist = CustomerDefaultProductRepository.FirstOrDefault(i => i.CustomerId == orderHeader.CustomerId && i.PartNo == input.PartNo);
  410. // if (customerDefaultProduct == null)
  411. // {
  412. // if (exist != null)
  413. // {
  414. // throw new UserFriendlyException($"零件号重复!该客户维护的产品{exist.ProductNo },已经使用了零件号{exist.PartNo}!");
  415. // }
  416. // customerDefaultProduct = new CustomerDefaultProduct()
  417. // {
  418. // CustomerId = orderHeader.CustomerId,
  419. // ProductNo = input.ProductNo,
  420. // PartNo = input.PartNo,
  421. // Sequence = 1,
  422. // TimeLastMod = Clock.Now
  423. // };
  424. // }
  425. // else
  426. // {
  427. // if (exist != null && exist.Id != customerDefaultProduct.Id)
  428. // {
  429. // throw new UserFriendlyException($"零件号重复!该客户维护的产品{exist.ProductNo },已经使用了零件号{exist.PartNo}!");
  430. // }
  431. // customerDefaultProduct.PartNo = input.PartNo;
  432. // customerDefaultProduct.Sequence = customerDefaultProduct.Sequence + 1;
  433. // customerDefaultProduct.TimeLastMod = Clock.Now;
  434. // }
  435. // CustomerDefaultProductRepository.InsertOrUpdate(customerDefaultProduct);
  436. //}
  437. #region 更新客户产品维护信息
  438. var customerDefaultProduct = CustomerDefaultProductRepository.GetAll().Where(i =>
  439. i.ProductNo == input.ProductNo && i.CustomerId == orderHeader.CustomerId)?.FirstOrDefault();
  440. CustomerDefaultProduct exist = !string.IsNullOrEmpty(input.PartNo) ? await CustomerDefaultProductRepository.FirstOrDefaultAsync(i => i.CustomerId == orderHeader.CustomerId && i.PartNo == input.PartNo) : null;
  441. if (customerDefaultProduct == null)
  442. {
  443. if (exist != null)
  444. {
  445. throw new UserFriendlyException($"零件号重复!该客户维护的产品{exist.ProductNo },已经使用了零件号{exist.PartNo}!");
  446. }
  447. customerDefaultProduct = new CustomerDefaultProduct()
  448. {
  449. CustomerId = orderHeader.CustomerId,
  450. ProductNo = input.ProductNo,
  451. PartNo = input.PartNo,
  452. Sequence = 1,
  453. TimeLastMod = Clock.Now
  454. };
  455. }
  456. else
  457. {
  458. if (exist != null && exist.Id != customerDefaultProduct.Id)
  459. {
  460. throw new UserFriendlyException($"零件号重复!该客户维护的产品{exist.ProductNo },已经使用了零件号{exist.PartNo}!");
  461. }
  462. customerDefaultProduct.PartNo = input.PartNo;
  463. customerDefaultProduct.Sequence = customerDefaultProduct.Sequence + 1;
  464. customerDefaultProduct.TimeLastMod = Clock.Now;
  465. }
  466. await CustomerDefaultProductRepository.InsertOrUpdateAsync(customerDefaultProduct);
  467. #endregion
  468. var prePrice = itemEntity.Price;
  469. var preQuantity = itemEntity.Quantity;
  470. var dto= await UpdateEntity(input);
  471. //await CommonAppService.WriteShortMessage(AbpSession.UserName, SettingManager.GetSettingValue(ShwasherSettingNames.DINGDANXGMSG), "订单明细信息修改", $"订单明细流水号为:{dto.Id},订单信息已变更,请注意查看,并及时跟踪!订单变更人为{AbpSession.UserName}");
  472. string sendMsgType = ShwasherSettingNames.DINGDANXGTOD;
  473. string changeInfo = "";
  474. if (preQuantity != input.Quantity)
  475. {
  476. sendMsgType = ShwasherSettingNames.DINGDANSLXGTOD;
  477. changeInfo = $"明细数量由{preQuantity}K -> {input.Quantity}K |";
  478. }
  479. if (prePrice != input.Price)
  480. {
  481. sendMsgType = ShwasherSettingNames.DINGDANJEXGTOD;
  482. changeInfo += $"明细单价由{prePrice} -> { input.Price}K |";
  483. }
  484. await CommonAppService.WriteShortMessageByDep(AbpSession.UserName, SettingManager.GetSettingValue(sendMsgType), "订单明细信息修改", $"订单(${orderHeader.Id})明细流水号为:{dto.Id},订单信息已变更({changeInfo}),请注意查看,并及时跟踪!订单变更人为{AbpSession.UserName}",false);//(itemEntity.OrderItemStatusId ??=0) != (OrderItemStatusEnum.NewCreate.ToInt())
  485. return dto;
  486. }
  487. public override async Task Delete(EntityDto<int> input)
  488. {
  489. CheckDeletePermission();
  490. var entity = await CheckOrderItem(input.Id);
  491. var orderHeader = await OrderHeaderRepository.FirstOrDefaultAsync(i => i.Id == entity.OrderNo);
  492. if (orderHeader.IsLock == "Y")
  493. {
  494. CheckErrors(IwbIdentityResult.Failed("订单已是删除状态,不可变更信息!详情请联系系统管理员!"));
  495. }
  496. var isHasSend = await CommonAppService.CheckOrderHasSend(entity.OrderNo);
  497. if (isHasSend)
  498. {
  499. CheckErrors(IwbIdentityResult.Failed("订单已存在发货记录,不可删除!详情请联系系统管理员!"));
  500. }
  501. BusinessLogTypeEnum.OrderLog.WriteLog(BusinessLogRepository, "订单明细删除", $"订单明细审核通过!orderNo:{entity.OrderNo},itemId:{input}");
  502. await Repository.DeleteAsync(input.Id);
  503. }
  504. #region 订单明细状态信息变更
  505. [AbpAuthorize(PermissionNames.PagesOrderInfoOrderStatusMgAuditItem), AuditLog("审核订单明细")]
  506. public async Task<OrderItem> Audit(EntityDto<int> input)
  507. {
  508. var orderItem = Repository.Get(input.Id);
  509. var orderHeader =await OrderHeaderRepository.FirstOrDefaultAsync(i => i.Id == orderItem.OrderNo);
  510. if (orderHeader.IsLock == "Y")
  511. {
  512. CheckErrors(IwbIdentityResult.Failed("订单已是删除状态,不可变更信息!详情请联系系统管理员!"));
  513. }
  514. orderItem.OrderItemStatusId = OrderItemStatusEnum.Audited.ToInt();
  515. orderItem.TimeLastMod = Clock.Now;
  516. orderItem.UserIDLastMod = AbpSession.UserName;
  517. BusinessLogTypeEnum.OrderLog.WriteLog(BusinessLogRepository, "订单明细审核", $"订单明细审核通过!{orderItem.Id}");
  518. return await Repository.UpdateAsync(orderItem);
  519. }
  520. [AbpAuthorize(PermissionNames.PagesOrderInfoOrderStatusMgAuditItem), AuditLog("审核所有订单明细")]
  521. public async Task<List<OrderItem>> AuditAllItems(EntityDto<string> input)
  522. {
  523. string[] arrIds = input.Id.Split(',');
  524. if (arrIds.Length > 0)
  525. {
  526. var orderFirstItem = Repository.Get(Convert.ToInt32(arrIds[0]));
  527. var orderHeader = await OrderHeaderRepository.FirstOrDefaultAsync(i => i.Id == orderFirstItem.OrderNo);
  528. if (orderHeader.IsLock == "Y")
  529. {
  530. CheckErrors(IwbIdentityResult.Failed("订单已是删除状态,不可变更信息!详情请联系系统管理员!"));
  531. }
  532. }
  533. List<OrderItem> alList = new List<OrderItem>();
  534. foreach (var arrId in arrIds)
  535. {
  536. var orderItem = Repository.Get(Convert.ToInt32(arrId));
  537. alList.Add(orderItem);
  538. orderItem.OrderItemStatusId = OrderItemStatusEnum.Audited.ToInt();
  539. orderItem.TimeLastMod = Clock.Now;
  540. orderItem.UserIDLastMod = AbpSession.UserName;
  541. BusinessLogTypeEnum.OrderLog.WriteLog(BusinessLogRepository, "订单明细审核", $"订单明细审核通过!{orderItem.Id}");
  542. await Repository.UpdateAsync(orderItem);
  543. }
  544. BusinessLogTypeEnum.OrderLog.WriteLog(BusinessLogRepository, "订单明细审核", $"订单明细审核通过!{alList.ToJsonString()}");
  545. return alList;
  546. }
  547. [AbpAuthorize(PermissionNames.PagesOrderInfoOrderStatusMgEndItem), AuditLog("结束订单明细")]
  548. public async Task<OrderItemEndCall> End(EntityDto<int> input)
  549. {
  550. var orderItem = Repository.Get(input.Id);
  551. orderItem.OrderItemStatusId = OrderItemStatusEnum.End.ToInt();
  552. orderItem.TimeLastMod = Clock.Now;
  553. orderItem.UserIDLastMod = AbpSession.UserName;
  554. BusinessLogTypeEnum.OrderLog.WriteLog(BusinessLogRepository, "订单明细结束", $"订单明细结束!{orderItem.ToJsonString()}");
  555. //int endstatus = OrderItemStatusEnum.End.ToInt();
  556. string lcOrderNo = orderItem.OrderNo;
  557. //var notEndItems = Repository.GetAllList(i =>
  558. //i.OrderNo == lcOrderNo && (i.OrderItemStatusId != endstatus||i.OrderItemStatusId ==null)&&i.Id != input.Id);
  559. OrderItemEndCall result = new OrderItemEndCall();
  560. var isHasExOrderItem = IsExOrderItem(lcOrderNo, input.Id);//是否有其它订单明细
  561. if (!isHasExOrderItem)
  562. {
  563. var order = OrderHeaderRepository.Get(lcOrderNo);
  564. order.OrderStatusId = OrderStatusEnum.Completed.ToInt();
  565. await OrderHeaderRepository.UpdateAsync(order);
  566. result.IsAllEnd = true;
  567. }
  568. else
  569. {
  570. if (IsExNotEndItem(lcOrderNo, input.Id)) //判断其它订单明细状态是否都是完成
  571. {
  572. var order = OrderHeaderRepository.Get(lcOrderNo);
  573. order.OrderStatusId = OrderStatusEnum.Completed.ToInt();
  574. await OrderHeaderRepository.UpdateAsync(order);
  575. result.IsAllEnd = true;
  576. }
  577. }
  578. result.OrderItem = await Repository.UpdateAsync(orderItem);
  579. return result;
  580. }
  581. /// <summary>
  582. /// 判断当前订单中是否有其它订单(true:有其它订单)
  583. /// </summary>
  584. /// <param name="pcOrderNo">订单号</param>
  585. /// <param name="piExOrderItemId">排除订单明细Id(如果值不为0,则排除传入订单明细Id,只判断当前订单中其它明细状态是否完成)</param>
  586. /// <param name="poExOrderItems">排除订单明细Id(如果值不为Null,则排除传入订单明细集合,只判断当前订单中其它明细状态是否完成)</param>
  587. /// <returns>true:有其它订单</returns>
  588. private bool IsExOrderItem(string pcOrderNo, int piExOrderItemId = 0, List<OrderItem> poExOrderItems = null)
  589. {
  590. bool lbRetval = false;
  591. var notItems = Repository.GetAllList(i =>
  592. i.OrderNo == pcOrderNo);
  593. if (piExOrderItemId != 0)
  594. {
  595. notItems = notItems.Where(i => i.Id != piExOrderItemId).ToList();
  596. }
  597. if (poExOrderItems != null && poExOrderItems.Any())
  598. {
  599. List<int> lcExOrderItemsId = poExOrderItems.Select(i => i.Id).ToList();
  600. notItems = notItems.Where(i => !lcExOrderItemsId.Contains(i.Id)).ToList();
  601. }
  602. if (notItems.Any())
  603. {
  604. lbRetval = true;
  605. }
  606. return lbRetval;
  607. }
  608. /// <summary>
  609. /// 判断当前订单中订单明细是否为都结束状态(true:其它订单明细都结束了)
  610. /// </summary>
  611. /// <param name="pcOrderNo">订单号</param>
  612. /// <param name="piExOrderItemId">排除订单明细Id(如果值不为0,则排除传入订单明细Id,只判断当前订单中其它明细状态是否完成)</param>
  613. /// <param name="poExOrderItems">排除订单明细Id(如果值不为Null,则排除传入订单明细集合,只判断当前订单中其它明细状态是否完成)</param>
  614. /// <returns>true:订单明细都结束了</returns>
  615. private bool IsExNotEndItem(string pcOrderNo, int piExOrderItemId = 0, List<OrderItem> poExOrderItems = null)
  616. {
  617. bool lbRetval = false;
  618. int endstatus = OrderItemStatusEnum.End.ToInt();
  619. int completeStatus = OrderItemStatusEnum.NegotiationComplete.ToInt();
  620. //过滤掉结束和协商完成的
  621. var notEndItems = Repository.GetAllList(i =>
  622. i.OrderNo == pcOrderNo && i.OrderItemStatusId != endstatus&&i.OrderItemStatusId!= completeStatus);
  623. if (piExOrderItemId != 0)
  624. {
  625. notEndItems = notEndItems.Where(i => i.Id != piExOrderItemId).ToList();
  626. }
  627. if (poExOrderItems != null && poExOrderItems.Any())
  628. {
  629. List<int> lcExOrderItemsId = poExOrderItems.Select(i => i.Id).ToList();
  630. notEndItems = notEndItems.Where(i => !lcExOrderItemsId.Contains(i.Id)).ToList();
  631. }
  632. if (!notEndItems.Any())
  633. {
  634. lbRetval = true;
  635. }
  636. return lbRetval;
  637. }
  638. [AbpAuthorize(PermissionNames.PagesOrderInfoOrderStatusMgChangeStatus), AuditLog("变更订单明细状态")]
  639. public async Task<List<OrderItem>> ChangeOrderItemStatus(ChangeOrderItemStatusDto input)
  640. {
  641. string ids = input.Id;
  642. if (string.IsNullOrEmpty(ids))
  643. {
  644. CheckErrors(IwbIdentityResult.Failed("未查询到修改的订单明细!"));
  645. return null;
  646. }
  647. var arr = ids.Split(',');
  648. StringBuilder sb = new StringBuilder();
  649. List<OrderItem> items = new List<OrderItem>();
  650. foreach (var id in arr)
  651. {
  652. var item = Repository.Get(Convert.ToInt32(id));
  653. sb.Append($"[ItemId:{item.Id},Status:{item.OrderItemStatusId}]");
  654. item.OrderItemStatusId = input.OrderItemStatusId;
  655. item.TimeLastMod = Clock.Now;
  656. item.UserIDLastMod = AbpSession.UserName;
  657. items.Add(item);
  658. await Repository.UpdateAsync(item);
  659. }
  660. BusinessLogTypeEnum.OrderLog.WriteLog(BusinessLogRepository, "订单明细状态修改", $"订单明细状态修改操作,订单明细:{sb.ToString()},变更状态为:{input.OrderItemStatusId}");
  661. return items;
  662. }
  663. /// <summary>
  664. /// 变更同一个订单的订单明细状态
  665. /// </summary>
  666. /// <param name="input"></param>
  667. /// <returns></returns>
  668. [AbpAuthorize(PermissionNames.PagesOrderInfoOrderStatusMgChangeStatus), AuditLog("变更订单明细状态")]
  669. public async Task<OrderItemsCallAndEnd> ChangeOrderItemStatusOnHeader(ChangeOrderItemStatusDto input)
  670. {
  671. string ids = input.Id;
  672. if (string.IsNullOrEmpty(ids))
  673. {
  674. CheckErrors(IwbIdentityResult.Failed("未查询到修改的订单明细!"));
  675. return null;
  676. }
  677. var arr = ids.Split(',');
  678. StringBuilder sb = new StringBuilder();
  679. List<OrderItem> items = new List<OrderItem>();
  680. foreach (var id in arr)
  681. {
  682. var item = Repository.Get(Convert.ToInt32(id));
  683. sb.Append($"[ItemId:{item.Id},Status:{item.OrderItemStatusId}]");
  684. item.OrderItemStatusId = input.OrderItemStatusId;
  685. item.TimeLastMod = Clock.Now;
  686. item.UserIDLastMod = AbpSession.UserName;
  687. items.Add(item);
  688. await Repository.UpdateAsync(item);
  689. }
  690. OrderItemsCallAndEnd loResult = new OrderItemsCallAndEnd();
  691. if (items.Any() && input.OrderItemStatusId == OrderItemStatusEnum.End.ToInt())
  692. {
  693. string lcOrderNo = items[0].OrderNo;
  694. var isHasExItems = IsExOrderItem(lcOrderNo, poExOrderItems: items);//是否有其它订单明细
  695. if (isHasExItems && IsExNotEndItem(items[0].OrderNo, poExOrderItems: items))//其它订单明细是否都结束了
  696. {
  697. var orderHeader = OrderHeaderRepository.Get(items[0].OrderNo);
  698. orderHeader.OrderStatusId = OrderStatusEnum.Completed.ToInt();
  699. loResult.IsAllEnd = true;
  700. await OrderHeaderRepository.UpdateAsync(orderHeader);
  701. }
  702. else if (!isHasExItems)
  703. {
  704. var orderHeader = OrderHeaderRepository.Get(items[0].OrderNo);
  705. orderHeader.OrderStatusId = OrderStatusEnum.Completed.ToInt();
  706. loResult.IsAllEnd = true;
  707. await OrderHeaderRepository.UpdateAsync(orderHeader);
  708. }
  709. }
  710. loResult.OrderItems = items;
  711. BusinessLogTypeEnum.OrderLog.WriteLog(BusinessLogRepository, "订单明细状态修改", $"订单明细状态修改操作,订单明细:{sb.ToString()},变更状态为:{input.OrderItemStatusId}");
  712. return loResult;
  713. }
  714. /// <summary>
  715. /// 变更同一个订单的订单明细是否库存配货完成状态
  716. /// </summary>
  717. /// <param name="input"></param>
  718. /// <returns></returns>
  719. [AbpAuthorize(PermissionNames.PagesOrderInfoOrderStatusMgChangeStatus), AuditLog("变更订单明细状态")]
  720. public async Task<OrderItemsCallAndEnd> ChangeOrderItemCompleteStoreStatus(ChangeOrderItemStoreCompleteStatusDto input)
  721. {
  722. string ids = input.Id;
  723. if (string.IsNullOrEmpty(ids))
  724. {
  725. CheckErrors(IwbIdentityResult.Failed("未查询到修改的订单明细!"));
  726. return null;
  727. }
  728. var arr = ids.Split(',');
  729. StringBuilder sb = new StringBuilder();
  730. List<OrderItem> items = new List<OrderItem>();
  731. foreach (var id in arr)
  732. {
  733. var item = Repository.Get(Convert.ToInt32(id));
  734. sb.Append($"[ItemId:{item.Id},Status:{item.OrderItemStatusId},StoreComplete:{input.OrderItemStoreCompleteState}]");
  735. item.StoreCompleteState = input.OrderItemStoreCompleteState;
  736. item.TimeLastMod = Clock.Now;
  737. item.UserIDLastMod = AbpSession.UserName;
  738. items.Add(item);
  739. await Repository.UpdateAsync(item);
  740. }
  741. OrderItemsCallAndEnd loResult = new OrderItemsCallAndEnd();
  742. loResult.OrderItems = items;
  743. BusinessLogTypeEnum.OrderLog.WriteLog(BusinessLogRepository, "订单明细状态修改", $"订单明细状态修改操作,订单明细:{sb.ToString()},货物到齐变更状态为:{input.OrderItemStoreCompleteState}");
  744. return loResult;
  745. }
  746. #endregion
  747. #region 订单明细信息变更
  748. [AbpAuthorize(PermissionNames.PagesOrderInfoOrderMgUpdateOrderItem),AuditLog("修改订单明细价格")]
  749. public async Task<OrderItem> ChangePrice(ChangeOrderItemInfoDto input)
  750. {
  751. if (!decimal.TryParse((await SettingManager.GetSettingValueAsync(ShwasherSettingNames.OrderItemPriceTaxRate)),
  752. out var rate))
  753. {
  754. CheckErrors(IwbIdentityResult.Failed("未查询到税率!"));
  755. }
  756. var orderItem = await CheckOrderItem(input.OrderItemNo);
  757. var orderHeader = await OrderHeaderRepository.FirstOrDefaultAsync(i => i.Id == orderItem.OrderNo);
  758. if (orderHeader.IsLock == "Y")
  759. {
  760. CheckErrors(IwbIdentityResult.Failed("订单已是删除状态,不可变更信息!详情请联系系统管理员!"));
  761. }
  762. decimal oldPrice = orderItem.Price;
  763. orderItem.Price = input.NewPrice;
  764. orderItem.AfterTaxPrice = Math.Round(input.NewPrice / (1 + rate / 100), 3);
  765. orderItem.TimeLastMod = Clock.Now;
  766. orderItem.UserIDLastMod = AbpSession.UserName;
  767. BusinessLogTypeEnum.OrderLog.WriteLog(BusinessLogRepository, "订单明细修改", $"修改订单明细价格,原价:{oldPrice}!{orderItem.ToJsonString()}");
  768. await CommonAppService.WriteShortMessageByDep(AbpSession.UserName, SettingManager.GetSettingValue(ShwasherSettingNames.DINGDANJEXGTOD), "订单明细价格变更", $"订单(${orderHeader.Id})明细流水号为:{orderItem.Id},订单税前价格由 {oldPrice} 变更为 {input.NewPrice} ,请注意查看,并及时跟踪!订单变更人为{AbpSession.UserName}", false);
  769. return await Repository.UpdateAsync(orderItem);
  770. //throw new System.NotImplementedException();
  771. }
  772. [AbpAuthorize(PermissionNames.PagesOrderInfoOrderMgUpdateOrderItem), AuditLog("修改订单明细税后价格")]
  773. public async Task<OrderItem> ChangeAfterTaxPrice(ChangeOrderItemInfoDto input)
  774. {
  775. if (!decimal.TryParse((await SettingManager.GetSettingValueAsync(ShwasherSettingNames.OrderItemPriceTaxRate)),
  776. out var rate))
  777. {
  778. CheckErrors(IwbIdentityResult.Failed("未查询到税率!"));
  779. }
  780. var orderItem = await CheckOrderItem(input.OrderItemNo);
  781. var orderHeader = await OrderHeaderRepository.FirstOrDefaultAsync(i => i.Id == orderItem.OrderNo);
  782. if (orderHeader.IsLock == "Y")
  783. {
  784. CheckErrors(IwbIdentityResult.Failed("订单已是删除状态,不可变更信息!详情请联系系统管理员!"));
  785. }
  786. decimal oldPrice = orderItem.AfterTaxPrice;
  787. orderItem.AfterTaxPrice = input.NewAfterTaxPrice;
  788. orderItem.Price = Math.Round(input.NewAfterTaxPrice * (1 + rate / 100), 3);
  789. orderItem.TimeLastMod = Clock.Now;
  790. orderItem.UserIDLastMod = AbpSession.UserName;
  791. BusinessLogTypeEnum.OrderLog.WriteLog(BusinessLogRepository, "订单明细修改", $"修改订单明细税后价格,原价:{oldPrice}!{orderItem.ToJsonString()}");
  792. await CommonAppService.WriteShortMessageByDep(AbpSession.UserName, SettingManager.GetSettingValue(ShwasherSettingNames.DINGDANJEXGTOD), "订单明细价格变更", $"订单(${orderHeader.Id})明细流水号为:{orderItem.Id},订单税后价格由 {oldPrice} 变更为 {input.NewAfterTaxPrice} ,请注意查看,并及时跟踪!订单变更人为{AbpSession.UserName}", false);
  793. return await Repository.UpdateAsync(orderItem);
  794. //throw new System.NotImplementedException();
  795. }
  796. [AbpAuthorize(PermissionNames.PagesOrderInfoOrderMgUpdateOrderItem), AuditLog("修改订单明细数量")]
  797. public async Task<OrderItem> ChangeQuantity(ChangeOrderItemInfoDto input)
  798. {
  799. var orderItem = await CheckOrderItem(input.OrderItemNo);
  800. var orderHeader = await OrderHeaderRepository.FirstOrDefaultAsync(i => i.Id == orderItem.OrderNo);
  801. if (orderHeader.IsLock == "Y")
  802. {
  803. CheckErrors(IwbIdentityResult.Failed("订单已是删除状态,不可变更信息!详情请联系系统管理员!"));
  804. }
  805. var oldQuantity = orderItem.Quantity;
  806. orderItem.Quantity = input.NewQuantity;
  807. orderItem.TimeLastMod = Clock.Now;
  808. orderItem.UserIDLastMod = AbpSession.UserName;
  809. BusinessLogTypeEnum.OrderLog.WriteLog(BusinessLogRepository, "订单明细修改(数量变更)", $"修改订单明细数量,原数量:{oldQuantity}!{orderItem.ToJsonString()}");
  810. await CommonAppService.WriteShortMessageByDep(AbpSession.UserName, SettingManager.GetSettingValue(ShwasherSettingNames.DINGDANSLXGTOD), "订单明细修改", $"订单(${orderHeader.Id})明细流水号为:{orderItem.Id},订单明细数量由 {oldQuantity} 变更为 {input.NewQuantity},请注意查看,并及时跟踪!订单变更人为{AbpSession.UserName}", false);
  811. return await Repository.UpdateAsync(orderItem);
  812. }
  813. //[AbpAuthorize(PermissionNames.PagesOrderInfoOrderMgUpdateOrderItem), AuditLog("修改订单明细发货日期")]
  814. //public async Task<OrderItem> ChangeSendDate(ChangeOrderItemInfoDto input)
  815. //{
  816. // var orderItem = await CheckOrderItem(input.OrderItemNo);
  817. // var orderHeader = await OrderHeaderRepository.FirstOrDefaultAsync(i => i.Id == orderItem.OrderNo);
  818. // if (orderHeader.IsLock == "Y")
  819. // {
  820. // CheckErrors(IwbIdentityResult.Failed("订单已是删除状态,不可变更信息!详情请联系系统管理员!"));
  821. // }
  822. // var oldSendDate = orderItem.SendDate;
  823. // orderItem.SendDate = input.NewSendDate;
  824. // orderItem.TimeLastMod = Clock.Now;
  825. // orderItem.UserIDLastMod = AbpSession.UserName;
  826. // BusinessLogTypeEnum.OrderLog.WriteLog(BusinessLogRepository, "订单明细修改(发货日期变更)", $"修改订单明细发货日期,原日期:{oldSendDate:yyyy-MM-dd}!{orderItem.ToJsonString()}");
  827. // await CommonAppService.WriteShortMessageByDep(AbpSession.UserName, SettingManager.GetSettingValue(ShwasherSettingNames.DINGDANXGTOD), "订单明细修改", $"订单(${orderHeader.Id})明细流水号为:{orderItem.Id},订单发货日期由 {oldSendDate:yyyy-MM-dd} 变更为 {input.NewSendDate:yyyy-MM-dd},请注意查看,并及时跟踪!订单变更人为{AbpSession.UserName}", false);
  828. // return await Repository.UpdateAsync(orderItem);
  829. //}
  830. [AbpAuthorize(PermissionNames.PagesOrderInfoOrderMgUpdateOrderItem), AuditLog("修改订单明细发货日期")]
  831. public async Task<OrderItem> ChangeSendDate(ChangeOrderItemSendDateInfoDto input)
  832. {
  833. var orderItem = await CheckOrderItem(input.OrderItemNo);
  834. var orderHeader = await OrderHeaderRepository.FirstOrDefaultAsync(i => i.Id == orderItem.OrderNo);
  835. if (orderHeader.IsLock == "Y")
  836. {
  837. CheckErrors(IwbIdentityResult.Failed("订单已是删除状态,不可变更信息!详情请联系系统管理员!"));
  838. }
  839. var oldSendDate = orderItem.SendDate;
  840. orderItem.SendDate = input.NewSendDate;
  841. orderItem.TimeLastMod = Clock.Now;
  842. orderItem.UserIDLastMod = AbpSession.UserName;
  843. //增加分批次发货日期提醒
  844. var inputSendDateWarns = input.SendDateWarns;
  845. if (inputSendDateWarns != null && inputSendDateWarns.Any())
  846. {
  847. //ScheduleOrderSendRepository.de
  848. await ExecSendWarn(inputSendDateWarns, input.OrderItemNo);
  849. }
  850. BusinessLogTypeEnum.OrderLog.WriteLog(BusinessLogRepository, "订单明细修改(发货日期变更)", $"修改订单明细发货日期,原日期:{oldSendDate:yyyy-MM-dd}!{orderItem.ToJsonString()}");
  851. await CommonAppService.WriteShortMessageByDep(AbpSession.UserName, SettingManager.GetSettingValue(ShwasherSettingNames.DINGDANXGTOD), "订单明细修改", $"订单(${orderHeader.Id})明细流水号为:{orderItem.Id},订单发货日期由 {oldSendDate:yyyy-MM-dd} 变更为 {input.NewSendDate:yyyy-MM-dd},请注意查看,并及时跟踪!订单变更人为{AbpSession.UserName}", false);
  852. return await Repository.UpdateAsync(orderItem);
  853. }
  854. private async Task ExecSendWarn(List<SendDateWarnDto> input,int orderItemId)
  855. {
  856. foreach (var sendDateWarnDto in input)
  857. {
  858. if (sendDateWarnDto.Id <= 0)
  859. {
  860. await ScheduleOrderSendRepository.InsertAsync(new ScheduleOrderSend()
  861. {
  862. OrderItemId = orderItemId,
  863. PlanDate = sendDateWarnDto.PlanDate,
  864. PlanQuantity = sendDateWarnDto.PlanQuantity,
  865. Remark = sendDateWarnDto.Remark,
  866. SendState = 0
  867. });
  868. }
  869. }
  870. }
  871. [AbpAuthorize(PermissionNames.PagesOrderInfoOrderMgUpdateOrderItem), AuditLog("删除分批次发货提醒")]
  872. public async Task DeleteSendDateWarns(int sendDateWarnId)
  873. {
  874. var item = await ScheduleOrderSendRepository.GetAsync(sendDateWarnId);
  875. if (item.SendState == 1)
  876. {
  877. CheckErrors(IwbIdentityResult.Failed("本次提醒已发货,不能删除!"));
  878. }
  879. await ScheduleOrderSendRepository.DeleteAsync(sendDateWarnId);
  880. }
  881. [AbpAuthorize(PermissionNames.PagesOrderInfoOrderMgUpdateOrderItem), AuditLog("分批次发货提醒修改订单明细发货日期")]
  882. public async Task<List<SendDateWarnDto>> GetSendDateWarns(int orderItemId)
  883. {
  884. var items =await ScheduleOrderSendRepository.GetAllListAsync(i=>i.OrderItemId==orderItemId);
  885. return ObjectMapper.Map<List<SendDateWarnDto>>(items);
  886. }
  887. private async Task<OrderItem> CheckOrderItem(int orderItemNo)
  888. {
  889. var orderItem = await Repository.FirstOrDefaultAsync(a => a.Id == orderItemNo);
  890. var orderHeader = await OrderHeaderRepository.FirstOrDefaultAsync(i => i.Id == orderItem.OrderNo);
  891. if (orderHeader.IsLock == "Y")
  892. {
  893. CheckErrors(IwbIdentityResult.Failed("订单已是删除状态,不可变更信息!详情请联系系统管理员!"));
  894. }
  895. if (orderItem == null)
  896. {
  897. CheckErrors(IwbIdentityResult.Failed( "未查询到订单明细。"));
  898. return null;
  899. }
  900. if (orderItem.OrderItemStatusId==OrderItemStatusEnum.Send.ToInt() )
  901. {
  902. CheckErrors(IwbIdentityResult.Failed( "已发货,不能操作。"));
  903. return null;
  904. }
  905. if (orderItem.OrderItemStatusId==OrderItemStatusEnum.End.ToInt() ||orderItem.OrderItemStatusId==OrderItemStatusEnum.NegotiationComplete.ToInt() ||orderItem.OrderItemStatusId==OrderItemStatusEnum.Delete.ToInt() )
  906. {
  907. CheckErrors(IwbIdentityResult.Failed( "已结束,不能操作。"));
  908. return null;
  909. }
  910. return orderItem;
  911. }
  912. #endregion
  913. #region 订单发货
  914. /// <summary>
  915. /// 订单明细发货
  916. /// </summary>
  917. /// <param name="input"></param>
  918. /// <returns></returns>
  919. [AbpAuthorize(PermissionNames.PagesOrderInfoOrderStatusMgSendItem), AuditLog("订单明细发货")]
  920. public async Task<OrderItem> SendOrderAction(SendOrderInfoDto input)
  921. {
  922. //OrderSendRepository
  923. var allSendQuantity = GetItemSend(input.Id);
  924. var orderItem = Repository.Get(input.Id);
  925. var orderHeader = await OrderHeaderRepository.FirstOrDefaultAsync(i => i.Id == orderItem.OrderNo);
  926. if (orderHeader.IsLock == "Y")
  927. {
  928. CheckErrors(IwbIdentityResult.Failed("订单已是删除状态,不可变更信息!详情请联系系统管理员!"));
  929. }
  930. var readySendAll = allSendQuantity + input.SendAllQuantity;
  931. if (readySendAll > orderItem.Quantity)
  932. {
  933. var exceedRate = ((readySendAll - orderItem.Quantity) / orderItem.Quantity) * 100;
  934. if (exceedRate > 5)
  935. {
  936. throw new UserFriendlyException("发货数量不能超过 订单明细总数量的5%!");
  937. }
  938. //throw new UserFriendlyException("发货数量不能超过 待发货总数量!");
  939. OrderSendExceedRepository.Insert(new OrderSendExceed()
  940. {
  941. OrderItemId = input.Id, ExceedQuantity = (readySendAll - orderItem.Quantity),
  942. OperatorMan = AbpSession.UserName,
  943. ProductNo = input.ProductNo,
  944. OrderNo = orderItem.OrderNo
  945. });
  946. }
  947. if ((allSendQuantity + input.SendAllQuantity) >= orderItem.Quantity)
  948. {
  949. orderItem.OrderItemStatusId = OrderItemStatusEnum.Send.ToInt();
  950. }
  951. foreach (var orderSendItemDto in input.SendItems)
  952. {
  953. if (await CommonAppService.CheckProductCanSendToCustomer(orderSendItemDto.ProductBatchNum,input.CustomerNo))
  954. {
  955. CheckErrors(IwbIdentityResult.Failed($"批次({orderSendItemDto.ProductBatchNum})不能发货给客户({input.CustomerNo}),请检查后再试..."));
  956. }
  957. var sendQuantiy = orderSendItemDto.SendQuantity;
  958. var avgQuantity = orderSendItemDto.AvgQuantity==0? sendQuantiy: orderSendItemDto.AvgQuantity;
  959. decimal packDecimal = 0;
  960. if (sendQuantiy <= avgQuantity)
  961. {
  962. packDecimal = 1;
  963. avgQuantity = sendQuantiy;
  964. }
  965. else
  966. {
  967. packDecimal = sendQuantiy / avgQuantity;
  968. }
  969. var currentProductStore = CurrentProductStoreHouseRepository.FirstOrDefault(i =>
  970. i.CurrentProductStoreHouseNo == orderSendItemDto.CurrentProductStoreHouseNo);
  971. //CurrentProductStoreHouse loOldCurrentProductStoreHouse = currentProductStore;//原库存记录
  972. decimal isCanSendQuantity = currentProductStore.Quantity - currentProductStore.FreezeQuantity;
  973. if (sendQuantiy > isCanSendQuantity)
  974. {
  975. CheckErrors(IwbIdentityResult.Failed("发货批次("+ currentProductStore.ProductionOrderNo+")库存数量不足,最多可发:"+ isCanSendQuantity+"千件"));
  976. }
  977. currentProductStore.FreezeQuantity += orderSendItemDto.SendQuantity;
  978. currentProductStore.TimeLastMod = Clock.Now;
  979. currentProductStore.UserIDLastMod = AbpSession.UserName;
  980. //currentProductStores.Add(currentProductStore);
  981. await CurrentProductStoreHouseRepository.UpdateAsync(currentProductStore);//更新库存的冻结数量
  982. var os = await OrderSendRepository.FirstOrDefaultAsync(i => i.OrderItemId == input.Id);
  983. decimal logisticsFee = 0, moldFee = 0, logisticsFeeAfterTax = 0, moldFeeAfterTax = 0;
  984. #region 磨具费和运费
  985. if (os == null)
  986. {
  987. logisticsFee = orderItem.LogisticsFee;
  988. moldFee = orderItem.MoldFee;
  989. moldFeeAfterTax = orderItem.MoldFeeAfterTax;
  990. logisticsFeeAfterTax = orderItem.LogisticsFeeAfterTax;
  991. }
  992. #endregion
  993. OrderSend orderSend = new OrderSend()
  994. {
  995. OrderItemId = input.Id,
  996. OrderUnitId = orderItem.OrderUnitId,
  997. SendDate = Clock.Now,
  998. SendQuantity = orderSendItemDto.SendQuantity,
  999. UserIDLastMod = AbpSession.UserName,
  1000. TimeLastMod = Clock.Now,
  1001. TimeCreated = Clock.Now,
  1002. QuantityPerPack = avgQuantity,
  1003. PackageCount = packDecimal,
  1004. ProductBatchNum = orderSendItemDto.ProductBatchNum,
  1005. StoreLocationNo = orderSendItemDto.StoreLocationNo,
  1006. CurrentProductStoreHouseNo = orderSendItemDto.CurrentProductStoreHouseNo,
  1007. CreatorUserId = AbpSession.UserName,
  1008. LogisticsFee = logisticsFee,
  1009. LogisticsFeeAfterTax = logisticsFeeAfterTax,
  1010. MoldFee = moldFee,
  1011. MoldFeeAfterTax = moldFeeAfterTax,
  1012. };
  1013. if (orderItem.ProductNo != input.ProductNo)
  1014. {
  1015. orderSend.Remark = $"替换发货,用编号:{input.ProductNo}替换{orderItem.ProductNo}";
  1016. }
  1017. this.LogError(orderSend.ToJsonString());
  1018. var sendId = OrderSendRepository.InsertAndGetId(orderSend); //添加发货记录
  1019. //库存变更逻辑,添加仓库出库申请
  1020. ProductOutStore loProductOutStore = new ProductOutStore
  1021. {
  1022. ApplyOutDate = Clock.Now,
  1023. ApplyStatus = OutStoreApplyStatusEnum.Applying.ToInt(),
  1024. StoreHouseId = 1,
  1025. IsClose = false,
  1026. CreatorUserId = AbpSession.UserName,
  1027. CurrentProductStoreHouseNo = orderSendItemDto.CurrentProductStoreHouseNo,
  1028. IsConfirm = false,
  1029. Quantity = orderSendItemDto.SendQuantity,
  1030. ProductionOrderNo = orderSendItemDto.ProductBatchNum ?? "",
  1031. ProductNo = input.ProductNo,
  1032. TimeLastMod = Clock.Now,
  1033. TimeCreated = Clock.Now,
  1034. UserIDLastMod = AbpSession.UserName,
  1035. OrderSendId = sendId,
  1036. ApplyOutStoreSourceType = OutStoreApplyTypeEnum.SendGood.ToInt()
  1037. };
  1038. await ProductOutStoreRepository.InsertAsync(loProductOutStore);
  1039. this.LogInfo($"订单明细发货操作,发货数量{sendQuantiy}!订单明细:{orderItem.ToJsonString()},库存记录变更:{currentProductStore.ToJsonString()}");
  1040. }
  1041. /*BusinessLogTypeEnum.OrderLog.WriteLog(BusinessLogRepository, "订单明细发货", $"订单明细发货操作,发货数量{sendQuantiy}!订单明细:{orderItem.ToJsonString()}原库存记录{loOldCurrentProductStoreHouse.ToJsonString()},库存记录变更:{currentProductStore.ToJsonString()}");*/
  1042. /*for (int i=0;i< currentProductStores.Count;i++)
  1043. {
  1044. BusinessLogTypeEnum.OrderLog.WriteLog(BusinessLogRepository, "订单明细发货", $"订单明细发货操作,发货数量{sendQuantiys[i]}!订单明细:{orderItem.ToJsonString()},库存记录变更:{currentProductStores[i].ToJsonString()}");
  1045. }*/
  1046. //如果存在分批次发货提醒
  1047. if (input.SendDateWarnId > 0)
  1048. {
  1049. var scheduleOrderSend = await ScheduleOrderSendRepository.GetAsync(input.SendDateWarnId);
  1050. if (scheduleOrderSend != null)
  1051. {
  1052. scheduleOrderSend.SendState = 1;
  1053. await ScheduleOrderSendRepository.UpdateAsync(scheduleOrderSend);
  1054. }
  1055. }
  1056. return await Repository.UpdateAsync(orderItem);//更新订单明细状态
  1057. }
  1058. #endregion
  1059. /// <summary>
  1060. /// 根据订单编号获取当前订单的订单明细
  1061. /// </summary>
  1062. /// <param name="pcOrderNo"></param>
  1063. /// <returns></returns>
  1064. [DisableAuditing]
  1065. public async Task<GetOrderItemDto> GetOrderItemsByOrderNo(string pcOrderNo)
  1066. {
  1067. var query = ViewOrderItemsRepository.GetAll().Where(i => i.OrderNo == pcOrderNo)?.OrderBy(i=>i.Id);
  1068. var entities = await AsyncQueryableExecuter.ToListAsync(query);
  1069. GetOrderItemDto lOrderItemDto = new GetOrderItemDto();
  1070. lOrderItemDto.IsAllSend = IsAllItemEnd(pcOrderNo);
  1071. lOrderItemDto.OrderItems = entities;
  1072. return lOrderItemDto;
  1073. }
  1074. /// <summary>
  1075. /// 判断一个订单所有订单明细是否都处于结束状态
  1076. /// </summary>
  1077. /// <param name="orderNo"></param>
  1078. /// <returns></returns>
  1079. [DisableAuditing]
  1080. public bool IsAllItemEnd(string orderNo)
  1081. {
  1082. bool lbRetval = true;
  1083. int endstatus = OrderItemStatusEnum.End.ToInt();
  1084. int negotiationComplete = OrderItemStatusEnum.NegotiationComplete.ToInt();
  1085. var result = Repository.GetAllList(i =>
  1086. i.OrderNo == orderNo && i.OrderItemStatusId != endstatus&&i.OrderItemStatusId!= negotiationComplete);
  1087. if (result.Any())
  1088. {
  1089. lbRetval = false;
  1090. }
  1091. /*else
  1092. {
  1093. var order = OrderHeaderRepository.Get(orderNo);
  1094. order.OrderStatusId = OrderStatusEnum.Completed.ToInt();
  1095. OrderHeaderRepository.UpdateAsync(order);
  1096. }*/
  1097. return lbRetval;
  1098. }
  1099. /// <summary>
  1100. /// 获取单个订单明细已发数量
  1101. /// </summary>
  1102. /// <param name="orderItemId"></param>
  1103. /// <returns></returns>
  1104. [DisableAuditing]
  1105. public decimal GetItemSend(int orderItemId)
  1106. {
  1107. var sendQuantity = OrderSendRepository.GetAll().Where(i => i.OrderItemId == orderItemId).Sum(i => (decimal?)i.SendQuantity) ?? 0;
  1108. return sendQuantity;
  1109. }
  1110. /// <summary>
  1111. /// 查询当前产品库存和被定数量
  1112. /// </summary>
  1113. /// <param name="input"></param>
  1114. /// <returns></returns>
  1115. public ViewQueryCurrentProductNum QueryCurrentProductNum(EntityDto<string> input)
  1116. {
  1117. ViewBookedProductNum entityBook = ViewBookedProductNumRepository.FirstOrDefault(input.Id);
  1118. ViewCanProductStore entityCan = ViewCanProductStoreRepository.FirstOrDefault(input.Id);
  1119. ViewQueryCurrentProductNum entity = new ViewQueryCurrentProductNum();
  1120. if (entityBook != null)
  1121. {
  1122. entity.Id = entityBook.Id;
  1123. entity.BookedQuantity = entityBook.BookedQuantity;
  1124. }
  1125. if (entityCan != null)
  1126. {
  1127. entity.Id = entityCan.Id;
  1128. entity.CanUserQuantity = entityCan.CanUserQuantity;
  1129. }
  1130. return entity;
  1131. }
  1132. public List<StatisticsItem> StatisticsItem(PagedRequestDto input)
  1133. {
  1134. string conn = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["Default"].ToString();
  1135. List<StatisticsItem> resultList = new List<StatisticsItem>();
  1136. using (var loSqlConn = new SqlConnection(conn))
  1137. {
  1138. using (loSqlConn.CreateCommand())
  1139. {
  1140. loSqlConn.Open();
  1141. string queryType = "", dataWhereSql = "where 1=1 and ( t.SaleType=1 or t.SaleType=2 )",sType="", currencyId="CNY";
  1142. if (input.SearchList != null && input.SearchList.Count > 0)
  1143. {
  1144. foreach (var searchDto in input.SearchList)
  1145. {
  1146. if (searchDto.KeyField == "stype")
  1147. {
  1148. sType = searchDto.KeyWords;
  1149. switch (searchDto.KeyWords)
  1150. {
  1151. case "1":
  1152. queryType = "t.CreateOrderDate";
  1153. break;
  1154. case "2":
  1155. queryType = "datepart(week,CreateOrderDate)";
  1156. break;
  1157. case "3":
  1158. queryType = "datepart(mm,CreateOrderDate)";
  1159. break;
  1160. case "4":
  1161. queryType = "datepart(qq,CreateOrderDate)";
  1162. break;
  1163. case "5":
  1164. queryType = "datepart(yyyy,CreateOrderDate)";
  1165. break;
  1166. }
  1167. }
  1168. if (searchDto.KeyField == "startDate" && !searchDto.KeyWords.IsNullOrEmpty())
  1169. {
  1170. dataWhereSql += " and t.CreateOrderDate>='" + searchDto.KeyWords + "' ";
  1171. }
  1172. if (searchDto.KeyField == "endDate" && !searchDto.KeyWords.IsNullOrEmpty())
  1173. {
  1174. dataWhereSql += " and t.CreateOrderDate<='" + searchDto.KeyWords + "' ";
  1175. }
  1176. if (searchDto.KeyField == "saleType" && !searchDto.KeyWords.IsNullOrEmpty())
  1177. {
  1178. if (Int16.Parse(searchDto.KeyWords) == 2)
  1179. {
  1180. currencyId = "USD";
  1181. dataWhereSql += " and t.CurrencyId ='USD' ";
  1182. }
  1183. else if (Int16.Parse(searchDto.KeyWords) == 1)
  1184. {
  1185. dataWhereSql += " and t.CurrencyId ='CNY' ";
  1186. }
  1187. }
  1188. if (searchDto.KeyField == "saleMan" && !searchDto.KeyWords.IsNullOrEmpty())
  1189. {
  1190. dataWhereSql += " and t.SaleMan ='"+ searchDto.KeyWords +"' ";
  1191. }
  1192. }
  1193. if (queryType.IsNullOrEmpty())
  1194. {
  1195. return resultList;
  1196. }
  1197. }
  1198. string lcSql =
  1199. $"select count(*) as OrderCount,sum(t.Price*t.Quantity) as TotalPrice,{queryType} as QueryValue from (select Convert(varchar(10),OrderDate,120) as CreateOrderDate,* from N_ViewOrderItems where IsLock!='Y') as t {dataWhereSql} group by {queryType} order by {queryType}";
  1200. SqlDataAdapter loDataAdapter = new SqlDataAdapter(lcSql, loSqlConn);
  1201. DataSet loDataSet = new DataSet(); // 创建DataSet
  1202. loDataAdapter.Fill(loDataSet, "OrderInfo");
  1203. DataTable loTable = loDataSet.Tables["OrderInfo"];
  1204. foreach (DataRow row in loTable.Rows)
  1205. {
  1206. StatisticsItem lDailyOrderInfo = new StatisticsItem();
  1207. /*lDailyOrderInfo.CustomerName = row["CustomerName"] + "";
  1208. lDailyOrderInfo.ProductName = row["ProductName"] + "";
  1209. lDailyOrderInfo.ProductNo = row["ProductNo"] + "";*/
  1210. lDailyOrderInfo.OrderCount = (int)row["OrderCount"];
  1211. lDailyOrderInfo.TotalPrice = Convert.ToDecimal(row["TotalPrice"]);
  1212. lDailyOrderInfo.QueryValue = row["QueryValue"];
  1213. lDailyOrderInfo.QueryUnit = sType;
  1214. lDailyOrderInfo.CurrencyId = currencyId;
  1215. resultList.Add(lDailyOrderInfo);
  1216. }
  1217. }
  1218. }
  1219. return resultList;
  1220. }
  1221. public async Task<LockOrderProductQuantity> GetCurrentProductLock(string productNo,string orderNo)
  1222. {
  1223. //int auditStatus = OrderItemStatusEnum.Audited.ToInt();
  1224. //int createStatus = OrderItemStatusEnum.NewCreate.ToInt();
  1225. //var orderItems =await Repository.GetAllListAsync(i =>
  1226. // i.ProductNo == productNo && (i.OrderItemStatusId == null || i.OrderItemStatusId == auditStatus ||
  1227. // i.OrderItemStatusId == createStatus)&&i.OrderNo == orderNo);
  1228. //var itemIds = orderItems.Select(i => i.Id).ToList();
  1229. //var sends = OrderSendRepository.GetAllList(i => itemIds.Contains(i.OrderItemId));
  1230. //LockOrderProductQuantity lockOrderProductQuantity = new LockOrderProductQuantity()
  1231. //{
  1232. // ProductNo = productNo,
  1233. // Quantity = orderItems.Sum(i=>i.Quantity) - sends.Sum(i=>i.SendQuantity)
  1234. //};
  1235. //return lockOrderProductQuantity;
  1236. int auditStatus = OrderItemStatusEnum.Audited.ToInt();
  1237. int createStatus = OrderItemStatusEnum.NewCreate.ToInt();
  1238. var orderItems = await Repository.GetAllListAsync(i =>
  1239. i.ProductNo == productNo && (i.OrderItemStatusId == null || i.OrderItemStatusId == auditStatus ||
  1240. i.OrderItemStatusId == createStatus)
  1241. &&i.IsLock=="N");
  1242. LockOrderProductQuantity lockOrderProductQuantity = new LockOrderProductQuantity()
  1243. {
  1244. ProductNo = productNo,
  1245. Quantity = orderItems.Sum(i => i.Quantity)
  1246. };
  1247. return lockOrderProductQuantity;
  1248. }
  1249. public async Task<CustomerDefaultProduct> GetDefaultPartNoByOrderNo(string orderNo, string productNo)
  1250. {
  1251. if (string.IsNullOrEmpty(orderNo) || string.IsNullOrEmpty(productNo))
  1252. {
  1253. CheckErrors(IwbIdentityResult.Failed("传入参数有误!"));
  1254. }
  1255. var orderHeader = await OrderHeaderRepository.FirstOrDefaultAsync(i => i.Id == orderNo);
  1256. var entity = await CustomerDefaultProductRepository.FirstOrDefaultAsync(i =>
  1257. i.CustomerId == orderHeader.CustomerId && i.ProductNo == productNo);
  1258. return entity;
  1259. }
  1260. #region orderProductProcess
  1261. public async Task<List<ProductionProcessDto>> QueryProductProcess(int orderItemId)
  1262. {
  1263. var entity = await QueryAppService.QueryOrderProductProcess(orderItemId);
  1264. List<ProductionProcessDto> result = new List<ProductionProcessDto>();
  1265. var pos = entity.ProductionOrderList;
  1266. var pas = entity.PackageApplyList;
  1267. if (pos != null)
  1268. {
  1269. foreach (var productionOrder in pos)
  1270. {
  1271. string pName = "";
  1272. if (productionOrder.ProcessingLevel == "1")
  1273. {
  1274. pName = productionOrder.ProductionType == "0"
  1275. ? "车间生产"
  1276. : "外购";
  1277. }
  1278. else
  1279. {
  1280. pName = productionOrder.ProcessingType == "2" ? "热处理" : "表面处理";
  1281. }
  1282. pName += $"({productionOrder.ProductionOrderNo})";
  1283. var status = productionOrder.ProductionOrderStatus == ProductionOrderStatusEnum.Start.ToInt()
  1284. ? "新建"
  1285. : (productionOrder.ProductionOrderStatus == ProductionOrderStatusEnum.Audited.ToInt() ? "已审核" :
  1286. productionOrder.ProductionOrderStatus == ProductionOrderStatusEnum.Producting.ToInt() ? "生产中" :
  1287. productionOrder.ProductionOrderStatus == ProductionOrderStatusEnum.Storeing.ToInt() ? "入库中" :
  1288. productionOrder.ProductionOrderStatus == ProductionOrderStatusEnum.EnterStore.ToInt() ? "已入库" :
  1289. productionOrder.ProductionOrderStatus == ProductionOrderStatusEnum.HangUp.ToInt() ? "挂起" :
  1290. productionOrder.ProductionOrderStatus == ProductionOrderStatusEnum.End.ToInt() ? "结束" : "");
  1291. result.Add(new ProductionProcessDto()
  1292. {
  1293. ProcessName = pName,
  1294. StartDate = productionOrder.TimeCreated,
  1295. CurrentStatus = status,
  1296. EndDate = productionOrder.ProductionOrderStatus == ProductionOrderStatusEnum.End.ToInt()
  1297. ? productionOrder.TimeLastMod
  1298. : null
  1299. });
  1300. }
  1301. }
  1302. if (pas != null)
  1303. {
  1304. foreach (var packageApply in pas)
  1305. {
  1306. string pName = $"包装({packageApply.ProductionOrderNo})";
  1307. var status = packageApply.ApplyStatus == PackageApplyStatusEnum.Applying.ToInt() + ""
  1308. ? "申请中"
  1309. : (packageApply.ApplyStatus == PackageApplyStatusEnum.Audited.ToInt() + "" ? "已审核" : "拒绝");
  1310. result.Add(new ProductionProcessDto()
  1311. {
  1312. ProcessName = pName,
  1313. StartDate = packageApply.ApplyDate,
  1314. CurrentStatus = status
  1315. });
  1316. }
  1317. }
  1318. return result.OrderByDescending(i=>i.StartDate).ToList();
  1319. }
  1320. #endregion
  1321. }
  1322. }