ProductionOrdersApplicationService.cs 109 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.Entity;
  4. using System.Diagnostics;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Text.RegularExpressions;
  8. using System.Threading.Tasks;
  9. using Abp.Application.Services.Dto;
  10. using Abp.Auditing;
  11. using Abp.Authorization;
  12. using Abp.Domain.Repositories;
  13. using Abp.Domain.Uow;
  14. using Abp.Extensions;
  15. using Abp.Timing;
  16. using Abp.UI;
  17. using Castle.Components.DictionaryAdapter;
  18. using IwbZero.AppServiceBase;
  19. using IwbZero.Auditing;
  20. using IwbZero.Helper;
  21. using IwbZero.IdentityFramework;
  22. using IwbZero.Setting;
  23. using JetBrains.Annotations;
  24. using Microsoft.AspNet.Identity;
  25. using Newtonsoft.Json;
  26. using NPOI.HSSF.UserModel;
  27. using ShwasherSys.Authorization.Permissions;
  28. using ShwasherSys.BaseSysInfo;
  29. using ShwasherSys.BasicInfo.OutFactory;
  30. using ShwasherSys.Common;
  31. using ShwasherSys.CompanyInfo;
  32. using ShwasherSys.Lambda;
  33. using ShwasherSys.ProductionOrderInfo.Dto;
  34. using ShwasherSys.ProductInfo;
  35. using ShwasherSys.ProductStoreInfo;
  36. using ShwasherSys.ProductStoreInfo.Dto;
  37. using ShwasherSys.SemiProductStoreInfo;
  38. using ShwasherSys.SemiProductStoreInfo.Dto;
  39. using ShwasherSys.RmStore;
  40. using LambdaExpType = ShwasherSys.Lambda.LambdaExpType;
  41. using LambdaFieldType = ShwasherSys.Lambda.LambdaFieldType;
  42. using LambdaObject = ShwasherSys.Lambda.LambdaObject;
  43. using ShwasherSys.BaseSysInfo.States;
  44. using ShwasherSys.Common.Dto;
  45. using ShwasherSys.Order;
  46. using ShwasherSys.ProductionOrderInfo.Dto.BindOrder;
  47. namespace ShwasherSys.ProductionOrderInfo
  48. {
  49. [AbpAuthorize, AuditLog("半成品排产出入库维护")]
  50. public class ProductionOrdersAppService : ShwasherAsyncCrudAppService<ProductionOrder, ProductionOrderDto, int, PagedRequestDto, ProductionOrderCreateDto, ProductionOrderUpdateDto>
  51. , IProductionOrdersAppService
  52. {
  53. protected IRepository<CurrentRmStoreHouse,string> CrsRepository { get; }
  54. protected IRepository<RmEnterStore,string> ErsRepository { get; }
  55. protected IRepository<RmOutStore,string> OrsRepository { get; }
  56. protected IRepository<EmployeeWorkPerformance> PerformanceRepository { get; }
  57. protected IRepository<BusinessLog> LogRepository;
  58. protected IRepository<ProductionLog> ProductLogRepository;
  59. protected IRepository<SemiEnterStore> SemiEnterStoreRepository;
  60. protected IRepository<ViewSemiEnterStore> ViewSemiEnterStoreRepository;
  61. protected IRepository<SemiOutStore> SemiOutStoreRepository;
  62. protected IRepository<CurrentSemiStoreHouse> CurrentSemiStoreHouseRepository;
  63. protected IRepository<ViewSemiOutStore> ViewSemiOutStoreRepository;
  64. protected IRepository<SemiProducts, string> SemiProductRepository;
  65. protected IRepository<OutFactory,string> OutFactoryRepository;
  66. protected IRepository<ViewProductOutStore> ViewProductOutStoreRepository { get; }
  67. protected IRepository<ProductOutStore> ProductOutStoreRepository { get; }
  68. protected IRepository<Product,string> ProductRepository { get; }
  69. protected IRepository<CurrentProductStoreHouse> CurrentProductStoreHouseRepository { get; }
  70. protected ICommonAppService CommonAppService { get; }
  71. protected IStatesAppService StatesAppService;
  72. protected IRepository<OrderProduction> OrderProductionRepository { get; }
  73. protected IRepository<ViewOrderItems> ViewOrderItemsRepository { get; }
  74. public ProductionOrdersAppService(IRepository<ProductionOrder, int> repository, IRepository<BusinessLog> logRepository, IRepository<SemiEnterStore> semiEnterStoreRepository, IRepository<SemiOutStore> semiOutStoreRepository, IRepository<ViewSemiEnterStore> viewSemiEnterStoreRepository, IRepository<CurrentSemiStoreHouse> currentSemiStoreHouseRepository, IRepository<ViewSemiOutStore> viewSemiOutStoreRepository, IRepository<SemiProducts, string> semiProductRepository, IRepository<OutFactory, string> outFactoryRepository, IRepository<ProductionLog> productLogRepository, IRepository<EmployeeWorkPerformance> performanceRepository, IRepository<RmOutStore, string> orsRepository, IRepository<RmEnterStore, string> ersRepository, IRepository<CurrentRmStoreHouse, string> crsRepository, ICommonAppService commonAppService, IRepository<ViewProductOutStore> viewProductOutStoreRepository, IRepository<ProductOutStore> productOutStoreRepository, IRepository<CurrentProductStoreHouse> currentProductStoreHouseRepository, IRepository<Product, string> productRepository, IStatesAppService statesAppService, IIwbSettingManager settingManager, IRepository<OrderProduction> orderProductionRepository, IRepository<ViewOrderItems> viewOrderItemsRepository) : base(repository, "ProductionOrderNo")
  75. {
  76. LogRepository = logRepository;
  77. SemiEnterStoreRepository = semiEnterStoreRepository;
  78. SemiOutStoreRepository = semiOutStoreRepository;
  79. ViewSemiEnterStoreRepository = viewSemiEnterStoreRepository;
  80. CurrentSemiStoreHouseRepository = currentSemiStoreHouseRepository;
  81. ViewSemiOutStoreRepository = viewSemiOutStoreRepository;
  82. SemiProductRepository = semiProductRepository;
  83. OutFactoryRepository = outFactoryRepository;
  84. ProductLogRepository = productLogRepository;
  85. PerformanceRepository = performanceRepository;
  86. OrsRepository = orsRepository;
  87. ErsRepository = ersRepository;
  88. CrsRepository = crsRepository;
  89. CommonAppService = commonAppService;
  90. ViewProductOutStoreRepository = viewProductOutStoreRepository;
  91. ProductOutStoreRepository = productOutStoreRepository;
  92. CurrentProductStoreHouseRepository = currentProductStoreHouseRepository;
  93. ProductRepository = productRepository;
  94. StatesAppService = statesAppService;
  95. OrderProductionRepository = orderProductionRepository;
  96. ViewOrderItemsRepository = viewOrderItemsRepository;
  97. SettingManager = settingManager;
  98. }
  99. protected override bool KeyIsAuto { get; set; } = false;
  100. protected override string GetPermissionName { get; set; } = PermissionNames.PagesProductionInfoProductionOrderMg;
  101. protected override string GetAllPermissionName { get; set; } = PermissionNames.PagesProductionInfoProductionOrderMg;
  102. protected override string CreatePermissionName { get; set; } = PermissionNames.PagesProductionInfoProductionOrderMgCreate;
  103. protected override string UpdatePermissionName { get; set; } = PermissionNames.PagesProductionInfoProductionOrderMgUpdate;
  104. protected override string DeletePermissionName { get; set; } = PermissionNames.PagesProductionInfoProductionOrderMgDelete;
  105. #region 排产单
  106. [DisableAuditing]
  107. public override async Task<PagedResultDto<ProductionOrderDto>> GetAll(PagedRequestDto input)
  108. {
  109. var result = GetAllData(input.SearchList);
  110. var totalCount = await AsyncQueryableExecuter.CountAsync(result);
  111. result = result.OrderByDescending(i => i.TimeCreated);
  112. string pattern = ProductModelSearch.GetModelGreaterOneReg(input.SearchList);
  113. List<ProductionOrderDto> entity;
  114. //检查查询条件中带有规格且多个分割条件的
  115. if (!pattern.IsNullOrEmpty())
  116. {
  117. var es = result.ToList();
  118. es = es.Where(f => f.Model != null && Regex.IsMatch(f.Model, pattern)).ToList();
  119. totalCount = es.Count;
  120. entity = es.Skip(input.SkipCount).Take(input.MaxResultCount).ToList();
  121. }
  122. else
  123. {
  124. result = result.Skip(input.SkipCount).Take(input.MaxResultCount);
  125. entity = result.ToList();
  126. }
  127. //result = result.Skip(input.SkipCount).Take(input.MaxResultCount);
  128. //var entity = result.ToList();
  129. var dtos = new PagedResultDto<ProductionOrderDto>(
  130. totalCount,
  131. entity
  132. );
  133. return dtos;
  134. }
  135. private IQueryable<ProductionOrderDto> GetAllData(List<MultiSearchDto> input)
  136. {
  137. CheckGetAllPermission();
  138. bool hasEnd = false;
  139. var query = Repository.GetAll();
  140. var outFacQuery = OutFactoryRepository.GetAll();
  141. var result = from u in query
  142. join s in SemiProductRepository.GetAll() on u.SemiProductNo equals s.Id into l
  143. from luq in l.DefaultIfEmpty()
  144. join o in outFacQuery on u.OutsourcingFactory equals o.Id into j
  145. from oj in j.DefaultIfEmpty()
  146. select new ProductionOrderDto
  147. {
  148. Model = luq.Model ?? "",
  149. CarNo = u.CarNo,
  150. EnterQuantity = u.EnterQuantity,
  151. Id = u.Id,
  152. ProductionType = u.ProductionType,
  153. OutsourcingFactory = u.OutsourcingFactory,
  154. CreatorUserId = u.CreatorUserId,
  155. IsChecked = u.IsChecked,
  156. IsLock = u.IsLock,
  157. Material = luq.Material ?? "",
  158. PartNo = luq.PartNo ?? "",
  159. PlanProduceDate = u.PlanProduceDate,
  160. RawMaterials = u.RawMaterials,
  161. SurfaceColor = luq.SurfaceColor ?? "",
  162. Rigidity = luq.Rigidity ?? "",
  163. Remark = u.Remark,
  164. UserIDLastMod = u.UserIDLastMod,
  165. TimeCreated = u.TimeCreated,
  166. TimeLastMod = u.TimeLastMod,
  167. Size = u.Size,
  168. ProcessingType = u.ProcessingType,
  169. ProcessingLevel = u.ProcessingLevel,
  170. SourceProductionOrderNo = u.SourceProductionOrderNo,
  171. StoveNo = u.StoveNo,
  172. Quantity = u.Quantity,
  173. ProductionOrderNo = u.ProductionOrderNo,
  174. ProductionOrderStatus = u.ProductionOrderStatus,
  175. SemiProductNo = u.SemiProductNo,
  176. SemiProductName = luq.SemiProductName,
  177. KgWeight = u.KgWeight,
  178. OutsourcingFactoryName = oj.OutFactoryName,
  179. EnterDate = u.EnterDate,
  180. InspectDate = u.InspectDate,
  181. HasExported = u.HasExported,
  182. MaxQuantity = u.MaxQuantity
  183. };
  184. //逻辑删除也同时显示出来
  185. //var property = typeof(ProductionOrder).GetProperty("IsLock");
  186. //if (property != null)
  187. //{
  188. // LambdaObject objLambdaObject = new LambdaObject()
  189. // {
  190. // FieldType = LambdaFieldType.S,
  191. // FieldName = "IsLock",
  192. // FieldValue = "N",
  193. // ExpType = LambdaExpType.Equal
  194. // };
  195. // var expIsLock = objLambdaObject.GetExp<ProductionOrderDto>();
  196. // result = result.Where(expIsLock);
  197. //}
  198. if (input != null && input.Count > 0)
  199. {
  200. List<LambdaObject> objList = new List<LambdaObject>();
  201. foreach (var o in input)
  202. {
  203. if (o.KeyWords.IsNullOrEmpty())
  204. continue;
  205. object keyWords = o.KeyWords;
  206. //检查查询条件中带有规格且多个分割条件的
  207. ProductModelSearch.CheckModelGreaterOneFilter(o, ref keyWords);
  208. objList.Add(new LambdaObject
  209. {
  210. FieldType = (LambdaFieldType)o.FieldType,
  211. FieldName = o.KeyField,
  212. FieldValue = keyWords,
  213. ExpType = (LambdaExpType)o.ExpType
  214. });
  215. if (o.KeyField?.ToLower() == "productionorderstatus" && o.KeyWords == ProductionOrderStatusEnum.End.ToInt() + "")
  216. {
  217. hasEnd = true;
  218. }
  219. }
  220. var exp = objList.GetExp<ProductionOrderDto>();
  221. result = exp!=null? result.Where(exp):result;
  222. }
  223. if (!hasEnd)
  224. {
  225. var endState = ProductionOrderStatusEnum.End.ToInt();
  226. result = result.Where(a => (a.ProductionOrderStatus != endState));
  227. }
  228. return result;
  229. }
  230. private string GetProductionOrderStatus(string p,int? isCheck,bool hasExported=false)
  231. {
  232. var stateDtos = StatesAppService.GetStateList("ProductionOrders", "ProductionOrderStatus",i=>i.CodeValue==p);
  233. var state = stateDtos.First();
  234. string result = state.DisplayValue;
  235. if (p == "4")
  236. {
  237. result += (isCheck??0)>0 ? "-已检验" : "-待检验";
  238. }
  239. result += hasExported ? "-已导出" : "";
  240. return result;
  241. }
  242. public async Task<string> ExportListToExcel(List<MultiSearchDto> input)
  243. {
  244. var result = GetAllData(input);
  245. result = result.OrderByDescending(i => i.TimeCreated);
  246. string pattern = ProductModelSearch.GetModelGreaterOneReg(input);
  247. List<ProductionOrderDto> entity = result.ToList();
  248. //检查查询条件中带有规格且多个分割条件的
  249. if (!pattern.IsNullOrEmpty())
  250. {
  251. entity = entity.Where(f => f.Model != null && Regex.IsMatch(f.Model, pattern)).ToList();
  252. }
  253. // List<ProductionOrderDto> entity = result.ToList();
  254. List<ProductionOrderExcelDto> r = new List<ProductionOrderExcelDto>();
  255. try
  256. {
  257. foreach (var t in entity)
  258. {
  259. ProductionOrderExcelDto e = new ProductionOrderExcelDto();
  260. e.ProductionOrderNo = t.ProductionOrderNo;
  261. e.PartNo = t.PartNo;
  262. e.SemiProductName = t.SemiProductName;
  263. e.Model = t.Model;
  264. e.Quantity = t.Quantity+"";
  265. e.TimeCreated = (t.TimeCreated ?? DateTime.Now).ToString("yyyy-MM-dd");
  266. e.ProductionOrderStatus = GetProductionOrderStatus(t.ProductionOrderStatus + "",
  267. t.IsChecked ?? 0, t.HasExported);
  268. e.Remark = t.Remark;
  269. e.Rigidity = t.Rigidity;
  270. e.SurfaceColor = t.SurfaceColor;
  271. e.Material = t.Material;
  272. e.KgWeight = t.KgWeight+"";
  273. e.PlanProduceDate = (t.PlanProduceDate ?? DateTime.Now).ToString("yyyy-MM-dd");
  274. e.EnterDate = (t.EnterDate ?? DateTime.Now).ToString("yyyy-MM-dd");
  275. e.OutsourcingFactoryName = t.OutsourcingFactoryName;
  276. e.ProcessingType = StatesAppService.GetDisplayValue("ProductionOrders", "ProcessingType",
  277. t.ProcessingType.ToString());
  278. e.SemiProductNo = t.SemiProductNo;
  279. r.Add(e);
  280. }
  281. string downloadUrl =await SettingManager.GetSettingValueAsync("SYSTEMDOWNLOADPATH");
  282. string lcFilePath = System.Web.HttpRuntime.AppDomainAppPath +"\\"+
  283. downloadUrl;
  284. var exportEntity = new Dictionary<string, string>()
  285. {
  286. {"ProductionOrderNo", "订单流水号"},
  287. {"PartNo", "零件号"},
  288. {"SemiProductName", "名称"},
  289. {"Model", "规格"},
  290. {"Quantity", "排产数量"},
  291. {"TimeCreated", "创建时间"},
  292. {"ProductionOrderStatus", "生产状态"},
  293. {"Remark", "备注"},
  294. {"Rigidity", "硬度"},
  295. {"SurfaceColor", "表色"},
  296. {"Material", "材质"},
  297. {"KgWeight", "千件重"},
  298. {"PlanProduceDate", "计划完成时间"},
  299. {"EnterDate", "入库时间"},
  300. {"OutsourcingFactoryName", "外协厂商"},
  301. {"ProcessingType", "加工类型"},
  302. {"SemiProductNo", "产品编码"},
  303. };
  304. string lcResultFileName = ExcelHelper.EntityListToExcel2003(exportEntity, r, "sheet", lcFilePath);
  305. return Path.Combine(downloadUrl, lcResultFileName);
  306. }
  307. catch (Exception ex)
  308. {
  309. Console.WriteLine(ex);
  310. // throw;
  311. }
  312. return "";
  313. }
  314. private ProductionOrderDto TrunProductionOrderDto(ProductionOrder p,SemiProducts s)
  315. {
  316. var productionOrderDto = MapToEntityDto(p);
  317. productionOrderDto.Model = s.Model ?? "";
  318. productionOrderDto.Material = s.Material ?? "";
  319. productionOrderDto.PartNo = s.PartNo ?? "";
  320. productionOrderDto.SurfaceColor = s.SurfaceColor ?? "";
  321. productionOrderDto.Rigidity = s.Rigidity ?? "";
  322. /*var productionOrderDto = new ProductionOrderDto(p)
  323. {
  324. Model = s.Model ?? "",
  325. Material = s.Material ?? "",
  326. PartNo = s.PartNo ?? "",
  327. SurfaceColor = s.SurfaceColor ?? "",
  328. Rigidity = s.Rigidity ?? "",
  329. };*/
  330. return productionOrderDto;
  331. }
  332. /// <summary>
  333. /// 获取新建排产单的编号
  334. /// </summary>
  335. /// <returns></returns>
  336. [DisableAuditing]
  337. public async Task<string> GetNewProductionOrderNo()
  338. {
  339. return await GetNewProductionOrderNo(0);
  340. }
  341. /// <summary>
  342. /// 获取新建排产单(外购单)的编号
  343. /// </summary>
  344. /// <returns></returns>
  345. [DisableAuditing]
  346. public async Task<string> GetNewProductionOrderNo(int isOutsourcing)
  347. {
  348. CheckGetAllPermission();
  349. string lcRetVal;
  350. DateTime loTiem = DateTime.Parse(DateTime.Now.Year + "-" + DateTime.Now.Month + "-01");
  351. //loTiem = loTiem.AddSeconds(-1);
  352. var orders = (await Repository.GetAllListAsync(i => i.TimeCreated >= loTiem && i.ProcessingLevel == "1")).OrderByDescending(i => i.Id).ToList();
  353. var orderNo = orders.FirstOrDefault()?.ProductionOrderNo;
  354. if (!string.IsNullOrEmpty(orderNo))
  355. {
  356. var liTempNo = Convert.ToInt32(orderNo.Substring(3, 4));
  357. liTempNo++;
  358. lcRetVal = liTempNo.ToString();
  359. while (lcRetVal.Length < 4)
  360. {
  361. lcRetVal = "0" + lcRetVal;
  362. }
  363. }
  364. else
  365. {
  366. lcRetVal = "0001";
  367. }
  368. DateTime loDate = DateTime.Today;
  369. //string lcMonth = liMonth < 10 ? liMonth + "" : Convert.ToString(liMonth, 16);
  370. lcRetVal = loDate.Date.Year + GetMonthString(isOutsourcing) + lcRetVal;
  371. lcRetVal = lcRetVal.Substring(2, lcRetVal.Length - 2);
  372. return lcRetVal;
  373. }
  374. /// <summary>
  375. /// 转换月份
  376. /// </summary>
  377. /// <param name="isOutsourcing"></param>
  378. /// <returns></returns>
  379. private string GetMonthString(int isOutsourcing)
  380. {
  381. DateTime loDate = DateTime.Today;
  382. int liMonth = loDate.Date.Month;
  383. if (isOutsourcing == 0)
  384. {
  385. return liMonth < 10 ? liMonth + "" : Convert.ToString(liMonth, 16).ToUpper();
  386. }
  387. string[] scource = {"", "G", "H", "W", "J", "K", "L", "M", "N", "T", "P","Q","R"};
  388. return scource[liMonth];
  389. }
  390. /// <summary>
  391. /// 工厂生产和外购编码互换
  392. /// </summary>
  393. /// <returns></returns>
  394. private string SwapOrderNo(string preOrderNo)
  395. {
  396. string[] source2 = { "G", "H", "W", "J", "K", "L", "M", "N", "T", "P", "Q", "R" };
  397. string[] source1 = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C" };
  398. var m = preOrderNo.Substring(2, 1);
  399. if (string.IsNullOrEmpty(m))
  400. {
  401. return "";
  402. }
  403. int index1 = Array.IndexOf(source1, m);
  404. int index2 = Array.IndexOf(source2, m);
  405. m = index1 > -1 ? source2[index1] : source1[index2];
  406. preOrderNo = preOrderNo.Substring(0, 2) + m + preOrderNo.Substring(3, 4);
  407. return preOrderNo;
  408. }
  409. [AbpAuthorize(PermissionNames.PagesProductionInfoProductionOrderMgUpdate), AuditLog("变更排产状态")]
  410. public async Task<ProductionOrderDto> ChangeProductionOrderStatus(ChangeProductionOrderStatusDto input)
  411. {
  412. var entity = await Repository.FirstOrDefaultAsync(a => a.Id == input.Id);
  413. if (entity.ProductionOrderStatus > ProductionOrderStatusEnum.Producting.ToInt()&&entity.ProductionOrderStatus!= ProductionOrderStatusEnum.HangUp.ToInt() && entity.ProductionOrderStatus != ProductionOrderStatusEnum.Audited.ToInt() && entity.IsChecked==0)
  414. {
  415. CheckErrors(IwbIdentityResult.Failed("排产单已进行入库,不可进行更改!"));
  416. }
  417. //审核时进行绑定订单明细校验
  418. if (input.ProductionOrderStatus == ProductionOrderStatusEnum.Audited.ToInt())
  419. {
  420. var os = QueryOrderItemByPoNo(entity.ProductionOrderNo);
  421. if (!os.Any())
  422. {
  423. CheckErrors(IwbIdentityResult.Failed("排产单未绑定订单明细!"));
  424. }
  425. }
  426. entity.ProductionOrderStatus = input.ProductionOrderStatus;
  427. //ProductionOrderLogs loLogs = new ProductionOrderLogs()
  428. //{
  429. // ProductionOrderNo = loProductionOrder.ProductionOrderNo,
  430. // CreatorUserId = AbpSession.UserName,
  431. // OperatorTitle = $"排产单:{loProductionOrder.ProductionOrderNo} 状态变更",
  432. // OperatorConent = $"排产单:{loProductionOrder.ProductionOrderNo} 状态变更为{input.ProductionOrderStatus}",
  433. // TimeCreated = Clock.Now
  434. //};
  435. //await ProductionOrderLogRepository.InsertAsync(loLogs);
  436. entity = await Repository.UpdateAsync(entity);
  437. BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半产品排产",
  438. $"排产单状态变更为[{(ProductionOrderStatusEnum)input.ProductionOrderStatus}]",
  439. entity.ProductionOrderNo);
  440. return MapToEntityDto(entity);
  441. }
  442. [AbpAuthorize(PermissionNames.PagesProductionInfoProductionOrderMgUpdate), AuditLog("排产进入已入库状态状态")]
  443. public async Task<ProductionOrderDto> ConfirmEnterStore(ConfirmEnterStoreDto input)
  444. {
  445. var entity = await Repository.FirstOrDefaultAsync(a => a.Id == input.Id);
  446. if (entity.ProductionOrderStatus != ProductionOrderStatusEnum.Storeing.ToInt())
  447. {
  448. CheckErrors(IwbIdentityResult.Failed("排查单未进行入库操作!"));
  449. }
  450. entity.ProductionOrderStatus = ProductionOrderStatusEnum.EnterStore.ToInt();
  451. //ProductionOrderLogs loLogs = new ProductionOrderLogs()
  452. //{
  453. // ProductionOrderNo = loProductionOrder.ProductionOrderNo,
  454. // CreatorUserId = AbpSession.UserName,
  455. // OperatorTitle = $"排产单:{loProductionOrder.ProductionOrderNo} 状态变更",
  456. // OperatorConent = $"排产单:{loProductionOrder.ProductionOrderNo} 状态变更为{input.ProductionOrderStatus}",
  457. // TimeCreated = Clock.Now
  458. //};
  459. //await ProductionOrderLogRepository.InsertAsync(loLogs);
  460. entity.EnterDate = Clock.Now;
  461. entity = await Repository.UpdateAsync(entity);
  462. if (string.IsNullOrEmpty(input.CurrentRmHouseId))
  463. {
  464. BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半产品排产",
  465. $"排产单状态变更为[{ProductionOrderStatusEnum.EnterStore}]。");
  466. }
  467. else
  468. {
  469. var rmCurrent= await CreateRwStore(input, entity.ProductionOrderNo);
  470. BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半产品排产确认入库(车间生产)",$"排产单状态变更为[{ProductionOrderStatusEnum.EnterStore}]。原材料[{rmCurrent.RmProductNo}],领用{input.TotalQuantity}kg,剩余{input.LaveQuantity}kg,使用后库存:{rmCurrent.Quantity}kg",entity.ProductionOrderNo);
  471. }
  472. return MapToEntityDto(entity);
  473. }
  474. /// <summary>
  475. /// 生成原材料出入库记录
  476. /// </summary>
  477. /// <param name="input"></param>
  478. /// <param name="productOrderNo"></param>
  479. /// <returns></returns>
  480. private async Task<CurrentRmStoreHouse> CreateRwStore(ConfirmEnterStoreDto input,string productOrderNo)
  481. {
  482. var current = await CrsRepository.FirstOrDefaultAsync(a => a.Id == input.CurrentRmHouseId);
  483. if (current == null)
  484. {
  485. CheckErrors(IwbIdentityResult.Failed("未查询到库存记录!"));
  486. return null;
  487. }
  488. if (current.Quantity < 0 || (current.Quantity- current.FreezeQuantity - input.TotalQuantity + input.LaveQuantity) < 0)
  489. {
  490. CheckErrors(IwbIdentityResult.Failed("库存不足!"));
  491. return null;
  492. }
  493. current.Quantity = current.Quantity - input.TotalQuantity + input.LaveQuantity;
  494. await CrsRepository.UpdateAsync(current);
  495. var date = DateTime.Now;
  496. var oStore = new RmOutStore
  497. {
  498. Id = Guid.NewGuid().ToString("N"),
  499. CurrentRmStoreHouseNo = current.Id,
  500. IsConfirm= true,
  501. ProductionOrderNo = productOrderNo,
  502. ProductBatchNum = current.ProductBatchNum,
  503. RmProductNo = current.RmProductNo,
  504. ApplyStatus = RmEnterOutStatusEnum.Stored.ToInt(),
  505. CreateSourceType = CreateSourceType.Normal.ToInt(),
  506. StoreHouseId = current.StoreHouseId,
  507. ActualQuantity = input.TotalQuantity,
  508. Quantity = input.TotalQuantity,
  509. ApplyOutDate = date,
  510. AuditUser = AbpSession.UserName,
  511. AuditDate = date,
  512. OutStoreDate = date,
  513. OutStoreUser = AbpSession.UserName,
  514. };
  515. await OrsRepository.InsertAsync(oStore);
  516. if (input.LaveQuantity > 0)
  517. {
  518. var eStore = new RmEnterStore
  519. {
  520. Id = Guid.NewGuid().ToString("N"),
  521. ProductionOrderNo = productOrderNo,
  522. ProductBatchNum = current.ProductBatchNum,
  523. RmProductNo = current.RmProductNo,
  524. ApplyStatus = RmEnterOutStatusEnum.Stored.ToInt(),
  525. CreateSourceType = CreateSourceType.Normal.ToInt(),
  526. StoreHouseId = current.StoreHouseId,
  527. StoreLocationNo = current.StoreLocationNo,
  528. ApplyQuantity = input.LaveQuantity,
  529. Quantity = input.LaveQuantity,
  530. ApplyEnterDate = date,
  531. AuditUser = AbpSession.UserName,
  532. AuditDate = date,
  533. EnterStoreDate = date,
  534. EnterStoreUser = AbpSession.UserName,
  535. };
  536. await ErsRepository.InsertAsync(eStore);
  537. }
  538. return current;
  539. }
  540. [AbpAuthorize(PermissionNames.PagesProductionInfoProductionOrderMgCreate), AuditLog("创建排产单")]
  541. public override async Task<ProductionOrderDto> Create(ProductionOrderCreateDto input)
  542. {
  543. var entity = await Repository.FirstOrDefaultAsync(a => a.ProductionOrderNo == input.ProductionOrderNo);
  544. if (entity != null)
  545. {
  546. CheckErrors(IwbIdentityResult.Failed("排产单号已存在,请稍后再试!"));
  547. return null;
  548. }
  549. var dto = await base.Create(input);
  550. BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半产品排产",
  551. $"创建排产单,信息为:[{dto.Obj2String()}]",
  552. dto.ProductionOrderNo);
  553. return dto;
  554. }
  555. [AbpAuthorize(PermissionNames.PagesProductionInfoProductionOrderMgUpdate), AuditLog("修改排产单")]
  556. public override async Task<ProductionOrderDto> Update(ProductionOrderUpdateDto input)
  557. {
  558. CheckUpdatePermission();
  559. var entity = await Repository.FirstOrDefaultAsync(a => a.Id == input.Id);
  560. if (entity.ProductionOrderStatus > ProductionOrderStatusEnum.Producting.ToInt()&& entity.ProductionOrderStatus != ProductionOrderStatusEnum.Audited.ToInt())
  561. {
  562. CheckErrors(IwbIdentityResult.Failed("排产单已进行入库,不可进行修改!"));
  563. }
  564. MapToEntity(input, entity);
  565. entity.TimeLastMod = Clock.Now;
  566. entity.UserIDLastMod = AbpSession.UserId + "";
  567. entity= await Repository.UpdateAsync(entity);
  568. BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半产品排产",
  569. $"修改排产单,信息为:[{entity.Obj2String()}]",
  570. entity.ProductionOrderNo);
  571. return MapToEntityDto(entity);
  572. }
  573. [AbpAuthorize(PermissionNames.PagesProductionInfoProductionOrderMgDelete), AuditLog("删除排产单")]
  574. public override async Task Delete(EntityDto<int> input)
  575. {
  576. CheckDeletePermission();
  577. var entity = await Repository.FirstOrDefaultAsync(a => a.Id == input.Id);
  578. if (entity.ProductionOrderStatus > ProductionOrderStatusEnum.Producting.ToInt()&&entity.ProductionOrderStatus!=ProductionOrderStatusEnum.Audited.ToInt())
  579. {
  580. CheckErrors(IwbIdentityResult.Failed("排产单已进行入库,不可进行删除!"));
  581. }
  582. entity.IsLock = "Y";
  583. entity=await Repository.UpdateAsync(entity);
  584. BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半产品排产",
  585. $"删除排产单,信息为:[{entity.Obj2String()}]",
  586. entity.ProductionOrderNo);
  587. }
  588. /// <summary>
  589. /// 创建外协排产单
  590. /// </summary>
  591. /// <param name="input"></param>
  592. /// <returns></returns>
  593. [AbpAuthorize(PermissionNames.PagesProductionInfoProductionOrderMgCreate), AuditLog("创建外协排产单")]
  594. public async Task<ProductionOrderDto> CreateOutProductionOrder(CreateOutProductionOrderDto input)
  595. {
  596. string sourceProductionOrderNo = input.SourceProductionOrderNo;
  597. string processType = input.ProcessingType;
  598. string processTypeNo = input.ProcessingTypeNo;
  599. string productionOrderNo = GetOutProductionOrderNo(sourceProductionOrderNo, processType, processTypeNo);
  600. var isExistObj = Repository.FirstOrDefault(i => i.ProductionOrderNo == productionOrderNo);
  601. if (isExistObj != null)
  602. {
  603. throw new UserFriendlyException("该流转单编号已存在!同一批次产品入库分两次外协加工,编号不能重复填写!");
  604. }
  605. if (input.IsReplating == 1)
  606. {
  607. var outStore = await ProductOutStoreRepository.FirstOrDefaultAsync(a => a.Id == input.OutStoreId);
  608. outStore.IsClose = true;
  609. outStore.IsConfirm = true;
  610. await ProductOutStoreRepository.UpdateAsync(outStore);
  611. var currentStore = await CurrentProductStoreHouseRepository.FirstOrDefaultAsync(a =>
  612. a.CurrentProductStoreHouseNo == outStore.CurrentProductStoreHouseNo);
  613. currentStore.FreezeQuantity -= outStore.Quantity;
  614. currentStore.Quantity -= outStore.Quantity;
  615. await CurrentProductStoreHouseRepository.UpdateAsync(currentStore);
  616. }
  617. else
  618. {
  619. var semiOutStore = await SemiOutStoreRepository.FirstOrDefaultAsync(a => a.Id == input.OutStoreId);
  620. semiOutStore.IsClose = true;
  621. await SemiOutStoreRepository.UpdateAsync(semiOutStore);
  622. }
  623. var semiProduct = await SemiProductRepository.FirstOrDefaultAsync(a => a.Id == input.SemiProductNo);
  624. ProductionOrderCreateDto objOrderCreateDto = new ProductionOrderCreateDto()
  625. {
  626. Material = semiProduct.Material,
  627. ProductionOrderNo = productionOrderNo,
  628. ProcessingLevel = "2",
  629. OutsourcingFactory = input.OutsourcingFactory,
  630. PlanProduceDate = input.PlanProduceDate,
  631. Model = semiProduct.Model,
  632. Quantity = input.Quantity,
  633. SurfaceColor = semiProduct.SurfaceColor,
  634. ProductionOrderStatus = ProductionOrderStatusEnum.Start.ToInt(),
  635. ProcessingType = processType,
  636. SourceProductionOrderNo = sourceProductionOrderNo,
  637. SemiProductNo = input.SemiProductNo,
  638. Rigidity = semiProduct.Rigidity,
  639. Remark = input.Remark,
  640. };
  641. //返镀标识
  642. if (input.IsReplating == 1)
  643. {
  644. objOrderCreateDto.Remark = $"[返镀]{objOrderCreateDto.Remark}";
  645. }
  646. var dto = await CreateEntity(objOrderCreateDto);
  647. BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半产品排产",
  648. $"创建外协排产单[{dto.Id}],信息为:[{input.Obj2String()}]",
  649. dto.ProductionOrderNo, dto.SourceProductionOrderNo);
  650. return dto;
  651. }
  652. [AbpAuthorize(PermissionNames.PagesProductionInfoOutProductionOrderMgUpdate), AuditLog("修改外协排产单")]
  653. public async Task<ProductionOrderDto> UpdateOutProductionOrder(UpdateOutProductionOrderDto input)
  654. {
  655. //string productionOrderNo = GetOutProductionOrderNo(input.SourceProductionOrderNo, input.ProcessingType, input.ProcessingTypeNo);
  656. var entity = Repository.FirstOrDefault(i => i.ProductionOrderNo == input.ProductionOrderNo);
  657. if (entity == null)
  658. {
  659. throw new UserFriendlyException("该流转单编号不存在!");
  660. }
  661. //var semiProduct =await SemiProductRepository.FirstOrDefaultAsync(a=>a.Id == input.SemiProductNo);
  662. entity.Quantity = input.Quantity;
  663. entity.PlanProduceDate = input.PlanProduceDate;
  664. entity.TimeLastMod = Clock.Now;
  665. entity.UserIDLastMod = AbpSession.UserName;
  666. entity.Remark = input.Remark;
  667. entity.KgWeight = input.KgWeight??0;
  668. entity.OutsourcingFactory = input.OutsourcingFactory;
  669. entity.SemiProductNo = input.SemiProductNo;
  670. entity = await Repository.UpdateAsync(entity);
  671. BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半产品排产",
  672. $"修改外协排产单[{entity.Id}],信息为:[{input.Obj2String()}]",
  673. entity.ProductionOrderNo, entity.SourceProductionOrderNo);
  674. return MapToEntityDto(entity);
  675. }
  676. [AbpAuthorize(PermissionNames.PagesProductionInfoOutProductionOrderMgDelete), AuditLog("删除外协排产单")]
  677. public async Task DeleteOutProductionOrder(EntityDto<int> input)
  678. {
  679. //string productionOrderNo = GetOutProductionOrderNo(input.SourceProductionOrderNo, input.ProcessingType, input.ProcessingTypeNo);
  680. var entity = Repository.FirstOrDefault(i => i.Id == input.Id);
  681. if (entity == null)
  682. {
  683. throw new UserFriendlyException("该流转单编号不存在!");
  684. }
  685. if (entity.ProductionOrderStatus >= ProductionOrderStatusEnum.Producting.ToInt()&& entity.ProductionOrderStatus!= ProductionOrderStatusEnum.Audited.ToInt())
  686. {
  687. CheckErrors(IwbIdentityResult.Failed("排产单已进行入库,不可进行删除!"));
  688. }
  689. entity.IsLock = "Y";
  690. await Repository.UpdateAsync(entity);
  691. BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半产品排产",
  692. $"删除外协排产单[{entity.Id}]",
  693. entity.ProductionOrderNo, entity.SourceProductionOrderNo);
  694. }
  695. private string GetOutProductionOrderNo(string sourceProductionOrderNo, string processType,
  696. string processTypeNo)
  697. {
  698. string resultNo = sourceProductionOrderNo.Length > 7
  699. ? sourceProductionOrderNo
  700. : sourceProductionOrderNo + "0000";
  701. if (processType == ProductionOrderProcessTypeEnum.HeatTreatment.ToInt() + "")
  702. {
  703. resultNo = resultNo.Substring(0, resultNo.Length - 2) + processTypeNo;
  704. }
  705. else if (processType == ProductionOrderProcessTypeEnum.SurfaceTreatment.ToInt() + "")
  706. {
  707. string lastTwoLength = resultNo.Substring(resultNo.Length - 2, 2);
  708. resultNo = resultNo.Substring(0, resultNo.Length - 4) + processTypeNo + lastTwoLength;
  709. }
  710. return resultNo;
  711. }
  712. //[AbpAuthorize(PermissionNames.PagesProductionInfoProductionOrderMgUpdate), AuditLog("关联订单明细")]
  713. public async Task BindOrderItems(BindOrdersDto input)
  714. {
  715. string itemIds = input.OrderItemIds;
  716. string[] items = itemIds.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries);
  717. foreach (string itemId in items)
  718. {
  719. int.TryParse(itemId, out int it);
  720. var isExist = OrderProductionRepository.FirstOrDefault(i =>
  721. i.OrderItemId == it && i.ProductionOrderNo == input.ProductionOrderNo);
  722. if (isExist != null)
  723. {
  724. continue;
  725. }
  726. await OrderProductionRepository.InsertAsync(new OrderProduction()
  727. {OrderItemId = it, ProductionOrderNo = input.ProductionOrderNo});
  728. }
  729. }
  730. // [AbpAuthorize(PermissionNames.PagesProductionInfoProductionOrderMgUpdate), AuditLog("关联订单明细")]
  731. public async Task UnBindOrderItems(BindOrdersDto input)
  732. {
  733. string itemIds = input.OrderItemIds;
  734. string[] items = itemIds.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  735. foreach (string itemId in items)
  736. {
  737. int.TryParse(itemId, out int it);
  738. var isExist = OrderProductionRepository.FirstOrDefault(i =>
  739. i.OrderItemId == it && i.ProductionOrderNo == input.ProductionOrderNo);
  740. if (isExist != null)
  741. {
  742. await OrderProductionRepository.DeleteAsync(i =>
  743. i.OrderItemId == it && i.ProductionOrderNo == input.ProductionOrderNo);
  744. }
  745. }
  746. }
  747. public List<ViewOrderItems> QueryOrderItemByPoNo(string productionOrderNo)
  748. {
  749. var entities = OrderProductionRepository.GetAllList(i => i.ProductionOrderNo == productionOrderNo);
  750. var its = entities.Select(i => i.OrderItemId);
  751. var rs = ViewOrderItemsRepository.GetAllList(i => its.Contains(i.Id));
  752. return rs;
  753. }
  754. #endregion
  755. #region 半成品入库
  756. [AbpAuthorize(PermissionNames.PagesProductionInfoProductionEnterStoreApplyMg), DisableAuditing]
  757. public PagedResultDto<ViewSemiEnterStore> GetSemiEnterStoreApply(PagedRequestDto input)
  758. {
  759. var query = ViewSemiEnterStoreRepository.GetAll();
  760. if (input.SearchList != null && input.SearchList.Count > 0)
  761. {
  762. List<LambdaObject> objList = new List<LambdaObject>();
  763. foreach (var o in input.SearchList)
  764. {
  765. if (o.KeyWords.IsNullOrEmpty())
  766. continue;
  767. object keyWords = o.KeyWords;
  768. //检查查询条件中带有规格且多个分割条件的
  769. ProductModelSearch.CheckModelGreaterOneFilter(o, ref keyWords);
  770. objList.Add(new LambdaObject
  771. {
  772. FieldType = (LambdaFieldType)o.FieldType,
  773. FieldName = o.KeyField,
  774. FieldValue = keyWords,
  775. ExpType = (LambdaExpType)o.ExpType
  776. });
  777. }
  778. var exp = objList.GetExp<ViewSemiEnterStore>();
  779. query = query.Where(exp);
  780. }
  781. var totalCount = query.Count();
  782. query = query.OrderByDescending(i => i.TimeCreated);
  783. string pattern = ProductModelSearch.GetModelGreaterOneReg(input.SearchList);
  784. List<ViewSemiEnterStore> entities;
  785. //检查查询条件中带有规格且多个分割条件的
  786. if (!pattern.IsNullOrEmpty())
  787. {
  788. var es = query.ToList();
  789. es = es.Where(f => f.Model != null && Regex.IsMatch(f.Model, pattern)).ToList();
  790. totalCount = es.Count;
  791. entities = es.Skip(input.SkipCount).Take(input.MaxResultCount).ToList();
  792. }
  793. else
  794. {
  795. query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
  796. entities = query.ToList();
  797. }
  798. //query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
  799. //var entities = query.ToList();
  800. var dtos = new PagedResultDto<ViewSemiEnterStore>(
  801. totalCount, entities
  802. );
  803. return dtos;
  804. }
  805. /// <summary>
  806. /// 获取当前排查单申请中数量+成功入库数量(千件数量)
  807. /// </summary>
  808. /// <param name="input"></param>
  809. /// <returns></returns>
  810. private decimal SumEnterStoreQuantity(ProductionOrder input)
  811. {
  812. string applyStatus = EnterStoreApplyStatusEnum.Applying.ToInt() + "",
  813. auditedStatus = EnterStoreApplyStatusEnum.Audited.ToInt() + "",
  814. enterStoredStatus = EnterStoreApplyStatusEnum.EnterStored.ToInt() + "",
  815. checkedStatus = EnterStoreApplyStatusEnum.Checked.ToInt() + "";
  816. var enterLogs = SemiEnterStoreRepository.GetAll().Where(i =>
  817. i.ProductionOrderNo == input.ProductionOrderNo &&
  818. (i.ApplyStatus == applyStatus ||
  819. i.ApplyStatus == auditedStatus ||
  820. i.ApplyStatus == enterStoredStatus ||
  821. i.ApplyStatus == checkedStatus));
  822. decimal result = 0;
  823. if (enterLogs.Any())
  824. {
  825. foreach (var log in enterLogs)
  826. {
  827. result += (log.ApplyStatus == enterStoredStatus ? log.ActualQuantity : log.Quantity) / (input.KgWeight <= 0 ? 1 : input.KgWeight);
  828. }
  829. }
  830. return result;
  831. }
  832. private bool CheckEnterStoreQuantity(ProductionOrder input,decimal enterQuantity,decimal kw)
  833. {
  834. ////已经申请入库数量
  835. //var hasQuantity = SumEnterStoreQuantity(input);
  836. ////最多可入库数量上浮百分之20
  837. //var productQuantity =(double) (input.Quantity * (input.KgWeight <= 0 ? 1 : input.KgWeight)) * 1.2;
  838. //if ((double)(hasQuantity + enterQuantity) > productQuantity)
  839. //{
  840. // return false;
  841. //}
  842. //return true;
  843. //已经申请入库数量
  844. var hasQuantity = SumEnterStoreQuantity(input);
  845. //最多可入库数量上浮百分之20
  846. var productQuantity = (input.MaxQuantity>= input.Quantity)? (double)input.MaxQuantity:(double) (input.Quantity) * 1.2;
  847. if ((double)(hasQuantity + enterQuantity/ (kw <= 0 ? 1 : kw)) > productQuantity)
  848. {
  849. return false;
  850. }
  851. return true;
  852. }
  853. public async Task<bool> CheckEnterStoreQuantity(CreateEnterStoreApplyDto input)
  854. {
  855. var loProductionOrder = await Repository.FirstOrDefaultAsync(a => a.Id == input.Id);
  856. if (!CheckEnterStoreQuantity(loProductionOrder, input.EnterStoreQuantity, input.KgWeight))
  857. {
  858. //CheckErrors(IwbIdentityResult.Failed("申请中数量+成功入库数量, 不能大于等于排产单计划总数量的上限数量!"));
  859. return false;
  860. }
  861. return true;
  862. }
  863. /// <summary>
  864. /// 半成品入库申请
  865. /// </summary>
  866. /// <param name="input"></param>
  867. /// <returns></returns>
  868. [AbpAuthorize(PermissionNames.PagesProductionInfoProductionOrderMgUpdate), AuditLog("创建入库申请")]
  869. public async Task<SemiEnterStoreDto> CreateEnterStoreApply(CreateEnterStoreApplyDto input)
  870. {
  871. string errMsg = "";
  872. var loProductionOrder = await Repository.FirstOrDefaultAsync(a => a.Id == input.Id);
  873. if (!CheckEnterStoreQuantity(loProductionOrder, input.EnterStoreQuantity, input.KgWeight))
  874. {
  875. //CheckErrors(IwbIdentityResult.Failed("申请中数量+成功入库数量, 不能大于等于排产单计划总数量的上限数量!"));
  876. errMsg = "申请中数量+成功入库数量, 已经大于等于排产单计划总数量的上限数量!";
  877. }
  878. loProductionOrder.ProductionOrderStatus = ProductionOrderStatusEnum.Storeing.ToInt();
  879. loProductionOrder.KgWeight = input.KgWeight;
  880. //loProductionOrder.ProductionOrderStatus = ProductionOrderStatusEnum.Producting.ToInt();
  881. var applySource = loProductionOrder.ProcessingLevel == "1"
  882. ? (loProductionOrder.ProductionType == "0"
  883. ? EnterStoreApplySourceEnum.InnerCar
  884. : EnterStoreApplySourceEnum.Out)
  885. : EnterStoreApplySourceEnum.OutProduct;
  886. SemiEnterStore entity = new SemiEnterStore
  887. {
  888. ApplyEnterDate = Clock.Now,
  889. ApplySource =applySource.ToInt().ToString(),
  890. ApplyStatus = EnterStoreApplyStatusEnum.Applying.ToInt().ToString(),
  891. ProductionOrderNo = loProductionOrder.ProductionOrderNo,
  892. SemiProductNo = loProductionOrder.SemiProductNo,
  893. Quantity = input.EnterStoreQuantity,
  894. ActualQuantity = 0,
  895. AuditDate = Clock.Now,
  896. AuditUser = AbpSession.UserName,
  897. TimeCreated = Clock.Now,
  898. CreatorUserId = AbpSession.UserName,
  899. TimeLastMod = Clock.Now,
  900. UserIDLastMod = AbpSession.UserName,
  901. Remark = input.Remark,
  902. StoreHouseId = input.StoreHouseId,
  903. KgWeight = input.KgWeight,
  904. };
  905. await SemiEnterStoreRepository.InsertAsync(entity);
  906. if (loProductionOrder.ProductionType == "0" &&
  907. input.ProductUser != null && input.ProductUser.Any())
  908. {
  909. if (string.IsNullOrEmpty(input.CarNo))
  910. {
  911. CheckErrors(IwbIdentityResult.Failed("车号不能为空,请检查后再试。"));
  912. }
  913. if (string.IsNullOrEmpty(loProductionOrder.CarNo))
  914. {
  915. loProductionOrder.CarNo = input.CarNo;
  916. }
  917. else if (input.CarNo!=loProductionOrder.CarNo)
  918. {
  919. CheckErrors(IwbIdentityResult.Failed("车号与上一次入库不一致,请检查后再试。"));
  920. }
  921. await CreateProductionLog(input, loProductionOrder.ProductionOrderNo);
  922. }
  923. await Repository.UpdateAsync(loProductionOrder);
  924. BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半成品入库",
  925. $"创建半成品入库申请[{entity.Id}],信息为:[{input.Obj2String()}]",
  926. entity.ProductionOrderNo);
  927. var result = ObjectMapper.Map<SemiEnterStoreDto>(entity);
  928. result.ErrorMsg = errMsg;
  929. return result;
  930. }
  931. private async Task CreateProductionLog(CreateEnterStoreApplyDto input,string productOrderNo)
  932. {
  933. int index= await GetLogIndex(productOrderNo);
  934. decimal q1 = Math.Round(input.EnterStoreQuantity / input.ProductUser.Count,2),
  935. q2 = Math.Round(input.EnterStoreQuantity2 / input.ProductUser.Count,2);
  936. foreach (var user in input.ProductUser)
  937. {
  938. index++;
  939. string logNo = $"{productOrderNo}-{index}";
  940. var log = new ProductionLog()
  941. {
  942. ProductionNo = logNo,
  943. ProductOrderNo = productOrderNo,
  944. QuantityWeight = q1,
  945. QuantityPcs = q2,
  946. KgWeight = input.KgWeight,
  947. CarNo = input.CarNo,
  948. EmployeeId = user,
  949. };
  950. await ProductLogRepository.InsertAsync(log);
  951. var p = new EmployeeWorkPerformance()
  952. {
  953. PerformanceNo =await WorkTypeDefinition.GetPerformanceNo(PerformanceRepository, WorkTypeDefinition.Product),
  954. ProductOrderNo = productOrderNo,
  955. RelatedNo = logNo,
  956. EmployeeId = user,
  957. WorkType = WorkTypeDefinition.Product,
  958. Performance = q2,
  959. PerformanceUnit = "千件",
  960. PerformanceDesc =
  961. $"{q2}千件,总重:{q1}kg,千件重:{input.KgWeight}",
  962. };
  963. await PerformanceRepository.InsertAsync(p);
  964. await CurrentUnitOfWork.SaveChangesAsync();
  965. }
  966. }
  967. private async Task<int> GetLogIndex(string productOrderNo)
  968. {
  969. var log = await ProductLogRepository.GetAll().Where(a => a.ProductionNo.Contains(productOrderNo + "-")).OrderByDescending(a=>a.CreationTime).FirstOrDefaultAsync();
  970. if (log==null)
  971. {
  972. return 0;
  973. }
  974. var no = log.ProductionNo.Substring(log.ProductionNo.IndexOf("-", StringComparison.Ordinal) + 1);
  975. return Convert.ToInt32(no);
  976. }
  977. /// <summary>
  978. /// 确认入库数量(by yue.)
  979. /// </summary>
  980. /// <param name="input"></param>
  981. /// <returns></returns>
  982. [AbpAuthorize(PermissionNames.PagesProductionInfoProductionEnterStoreApplyMgConfirm), AuditLog("确认入库申请")]
  983. public async Task<SemiEnterStoreDto> ConfirmSemiEnterStoreQuantity(EntityDto<int> input)
  984. {
  985. var entity = await SemiEnterStoreRepository.FirstOrDefaultAsync(a => a.Id == input.Id);
  986. if (entity.ApplyStatus == EnterStoreApplyStatusEnum.EnterStored.ToInt() + "")
  987. {
  988. CheckErrors(IwbIdentityResult.Failed("已入库不能再操作!"));
  989. }
  990. if (entity.ApplyStatus != EnterStoreApplyStatusEnum.Checked.ToInt() + "")
  991. {
  992. CheckErrors(IwbIdentityResult.Failed("还未检验,不能入库!"));
  993. }
  994. entity.ApplyStatus = EnterStoreApplyStatusEnum.EnterStored.ToInt() + "";
  995. var date = Clock.Now;
  996. entity.EnterStoreDate = date;
  997. entity.EnterStoreUser = AbpSession.UserName;
  998. await SemiEnterStoreRepository.UpdateAsync(entity);
  999. var currentStore = CurrentSemiStoreHouseRepository.GetAll().FirstOrDefault(i => i.ProductionOrderNo == entity.ProductionOrderNo&& i.StoreHouseId==entity.StoreHouseId&&i.StoreLocationNo==entity.StoreLocationNo);
  1000. if (currentStore != null)
  1001. {
  1002. var isCanUpdate =
  1003. CommonAppService.CheckStoreRecordCanUpdate(currentStore.CurrentSemiStoreHouseNo, 2);
  1004. if (!isCanUpdate)
  1005. CheckErrors(IwbIdentityResult.Failed("该库存处于退货或者正在盘点状态,不可进行出入库更新!"));
  1006. currentStore.ActualQuantity += entity.ActualQuantity;
  1007. currentStore.TimeLastMod = date;
  1008. currentStore.UserIDLastMod = AbpSession.UserName;
  1009. currentStore.KgWeight = entity.KgWeight;
  1010. await CurrentSemiStoreHouseRepository.UpdateAsync(currentStore);
  1011. }
  1012. else
  1013. {
  1014. string lcJson = JsonConvert.SerializeObject(entity);
  1015. currentStore = lcJson.GetModel<CurrentSemiStoreHouse>();
  1016. var isCanUpdate =
  1017. CommonAppService.CheckStoreCanUpdateByLocationNo(currentStore.StoreLocationNo, 2);
  1018. if (!isCanUpdate)
  1019. CheckErrors(IwbIdentityResult.Failed("该库位正在盘点状态,不可进行出入库更新!"));
  1020. currentStore.CurrentSemiStoreHouseNo = Guid.NewGuid().ToString("N");
  1021. currentStore.TimeCreated = date;
  1022. currentStore.UserIDLastMod = AbpSession.UserName;
  1023. currentStore.ActualQuantity = entity.ActualQuantity;
  1024. currentStore.FreezeQuantity = 0;
  1025. await CurrentSemiStoreHouseRepository.InsertAsync(currentStore);
  1026. }
  1027. //取消确认入库自动变更排查单状态
  1028. /*var productionOrder =
  1029. await Repository.FirstOrDefaultAsync(a => a.ProductionOrderNo == entity.ProductionOrderNo);
  1030. if (productionOrder == null)
  1031. {
  1032. CheckErrors(IwbIdentityResult.Failed("未发现排产单!"));
  1033. return null;
  1034. }
  1035. productionOrder.ProductionOrderStatus = ProductionOrderStatusEnum.EnterStore.ToInt();
  1036. await Repository.UpdateAsync(productionOrder);*/
  1037. BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半成品入库",
  1038. $"确认半成品入库数量[{entity.Id}],排产单入库信息:[确认数量:{entity.ActualQuantity},库存:{currentStore.ActualQuantity},冻结:{currentStore.FreezeQuantity}]。",
  1039. entity.ProductionOrderNo);
  1040. return ObjectMapper.Map<SemiEnterStoreDto>(entity);
  1041. }
  1042. /// <summary>
  1043. /// 取消入库申请(by yue.)
  1044. /// </summary>
  1045. /// <param name="input"></param>
  1046. /// <returns></returns>
  1047. [AbpAuthorize(PermissionNames.PagesProductionInfoProductionEnterStoreApplyMgCancel), AuditLog("取消入库申请")]
  1048. public async Task<SemiEnterStoreDto> CancelSemiEnterStoreApplyStatus(EntityDto<int> input)
  1049. {
  1050. var entity = await SemiEnterStoreRepository.FirstOrDefaultAsync(a => a.Id == input.Id);
  1051. if (entity.ApplyStatus == EnterStoreApplyStatusEnum.EnterStored.ToInt() + "")
  1052. {
  1053. CheckErrors(IwbIdentityResult.Failed("已入库不能再操作!"));
  1054. }
  1055. entity.ApplyStatus = EnterStoreApplyStatusEnum.Canceled.ToInt() + "";
  1056. await SemiEnterStoreRepository.UpdateAsync(entity);
  1057. BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半成品入库",
  1058. $"取消半成品入库申请[{entity.Id}]",
  1059. entity.ProductionOrderNo);
  1060. return ObjectMapper.Map<SemiEnterStoreDto>(entity);
  1061. }
  1062. /// <summary>
  1063. /// 关闭入库申请 (by yue.)
  1064. /// </summary>
  1065. /// <param name="input"></param>
  1066. /// <returns></returns>
  1067. [AbpAuthorize(PermissionNames.PagesProductionInfoProductionEnterStoreApplyMgClose), AuditLog("关闭入库申请")]
  1068. public async Task<SemiEnterStoreDto> CloseEnterStoreApply(EntityDto<int> input)
  1069. {
  1070. var entity = await SemiEnterStoreRepository.FirstOrDefaultAsync(a => a.Id == input.Id);
  1071. entity.IsClose = true;
  1072. //var productionOrder =
  1073. // await Repository.FirstOrDefaultAsync(a => a.ProductionOrderNo == entity.ProductionOrderNo);
  1074. //if (productionOrder == null)
  1075. //{
  1076. // CheckErrors(IwbIdentityResult.Failed("未发现排产单!"));
  1077. // return null;
  1078. //}
  1079. //if (productionOrder.ProductionOrderStatus != ProductionOrderStatusEnum.EnterStore.ToInt()&& productionOrder.ProductionOrderStatus != ProductionOrderStatusEnum.End.ToInt())
  1080. //{
  1081. // productionOrder.ProductionOrderStatus = ProductionOrderStatusEnum.Producting.ToInt();
  1082. //}
  1083. //await Repository.UpdateAsync(productionOrder);
  1084. BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半成品入库",
  1085. $"关闭半成品入库申请[{entity.Id}]",
  1086. entity.ProductionOrderNo);
  1087. await SemiEnterStoreRepository.UpdateAsync(entity);
  1088. return ObjectMapper.Map<SemiEnterStoreDto>(entity);
  1089. }
  1090. /// <summary>
  1091. /// 恢复入库申请(by yue.)
  1092. /// </summary>
  1093. /// <param name="input"></param>
  1094. /// <returns></returns>
  1095. [AbpAuthorize(PermissionNames.PagesProductionInfoProductionEnterStoreApplyMgRecovery), AuditLog("恢复入库申请")]
  1096. public async Task<SemiEnterStoreDto> RecoverySemiEnterStoreApplyStatus(EntityDto<int> input)
  1097. {
  1098. var entity = await SemiEnterStoreRepository.FirstOrDefaultAsync(a => a.Id == input.Id);
  1099. if (entity.ApplyStatus == EnterStoreApplyStatusEnum.EnterStored.ToInt() + "")
  1100. {
  1101. CheckErrors(IwbIdentityResult.Failed("已入库不能再操作!"));
  1102. }
  1103. entity.ApplyStatus = EnterStoreApplyStatusEnum.Applying.ToInt() + "";
  1104. await SemiEnterStoreRepository.UpdateAsync(entity);
  1105. BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半成品入库",
  1106. $"恢复半成品入库申请[{entity.Id}]",
  1107. entity.ProductionOrderNo);
  1108. return ObjectMapper.Map<SemiEnterStoreDto>(entity);
  1109. }
  1110. [AbpAuthorize(PermissionNames.PagesProductionInfoProductionEnterStoreApplyMgUpdate), AuditLog("修改入库申请")]
  1111. public async Task<SemiEnterStoreDto> UpdateEnterStoreApply(UpdateSemiEnterStoreDto input)
  1112. {
  1113. var entity = await SemiEnterStoreRepository.FirstOrDefaultAsync(a => a.Id == input.Id);
  1114. #region 增加入口数量限制检验
  1115. //var productOrder = Repository.FirstOrDefault(i => i.ProductionOrderNo == entity.ProductionOrderNo);
  1116. //if (productOrder != null)
  1117. //{
  1118. // var sumQuantity = SumEnterStoreQuantity(productOrder);
  1119. // sumQuantity = sumQuantity - (entity.Quantity / (entity.KgWeight <= 0 ? 1 : entity.KgWeight)) + (input.Quantity / (input.KgWeight <= 0 ? 1 : input.KgWeight));
  1120. // var maxQuantity = (productOrder.MaxQuantity >= productOrder.Quantity) ? (double)productOrder.MaxQuantity : (double)(productOrder.Quantity) * 1.2;
  1121. // if ((double)sumQuantity > maxQuantity)
  1122. // {
  1123. // CheckErrors(IwbIdentityResult.Failed("申请中数量+成功入库数量, 不能大于等于排产单计划总数量的上限数量!"));
  1124. // }
  1125. //}
  1126. #endregion
  1127. entity.Quantity = input.Quantity;
  1128. entity.KgWeight = input.KgWeight;
  1129. await SemiEnterStoreRepository.UpdateAsync(entity);
  1130. BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半成品入库",
  1131. $"修改半成品入库申请数量[{entity.Id}],数量修改为[{input.Quantity}],千斤重修改为[{input.KgWeight}]",
  1132. entity.ProductionOrderNo);
  1133. return ObjectMapper.Map<SemiEnterStoreDto>(entity);
  1134. }
  1135. #endregion
  1136. #region 半成品出库
  1137. [DisableAuditing,AbpAuthorize(PermissionNames.PagesProductionInfoProductionOutStoreApplyMg)]
  1138. public PagedResultDto<ViewSemiOutStore> GetSemiOutStoreApply(PagedRequestDto input)
  1139. {
  1140. int type = OutStoreApplyTypeEnum.OutAssistant.ToInt();
  1141. var query = ViewSemiOutStoreRepository.GetAll().Where(a => a.ApplyTypes== type);
  1142. if (input.SearchList != null && input.SearchList.Count > 0)
  1143. {
  1144. List<LambdaObject> objList = new List<LambdaObject>();
  1145. foreach (var o in input.SearchList)
  1146. {
  1147. if (o.KeyWords.IsNullOrEmpty())
  1148. continue;
  1149. object keyWords = o.KeyWords;
  1150. //检查查询条件中带有规格且多个分割条件的
  1151. ProductModelSearch.CheckModelGreaterOneFilter(o, ref keyWords);
  1152. objList.Add(new LambdaObject
  1153. {
  1154. FieldType = (LambdaFieldType)o.FieldType,
  1155. FieldName = o.KeyField,
  1156. FieldValue = keyWords,
  1157. ExpType = (LambdaExpType)o.ExpType
  1158. });
  1159. }
  1160. var exp = objList.GetExp<ViewSemiOutStore>();
  1161. query = query.Where(exp);
  1162. }
  1163. var totalCount = query.Count();
  1164. query = query.OrderByDescending(i => i.TimeCreated);
  1165. string pattern = ProductModelSearch.GetModelGreaterOneReg(input.SearchList);
  1166. List<ViewSemiOutStore> entities;
  1167. //检查查询条件中带有规格且多个分割条件的
  1168. if (!pattern.IsNullOrEmpty())
  1169. {
  1170. var es = query.ToList();
  1171. es = es.Where(f => f.Model != null && Regex.IsMatch(f.Model, pattern)).ToList();
  1172. totalCount = es.Count;
  1173. entities = es.Skip(input.SkipCount).Take(input.MaxResultCount).ToList();
  1174. }
  1175. else
  1176. {
  1177. query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
  1178. entities = query.ToList();
  1179. }
  1180. //query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
  1181. //var entities = query.ToList();
  1182. var dtos = new PagedResultDto<ViewSemiOutStore>(
  1183. totalCount, entities
  1184. );
  1185. return dtos;
  1186. }
  1187. [DisableAuditing,AbpAuthorize(PermissionNames.PagesProductionInfoProductionOutStoreApplyMg)]
  1188. public ViewSemiOutStore GetSemiOutStoreApplyById(int id)
  1189. {
  1190. var outStore = ViewSemiOutStoreRepository.Get(id);
  1191. return outStore;
  1192. }
  1193. /// <summary>
  1194. /// 半成品出库申请
  1195. /// </summary>
  1196. /// <param name="input"></param>
  1197. /// <returns></returns>
  1198. [AbpAuthorize(PermissionNames.PagesProductionInfoProductionOutStoreApplyMgCreate), AuditLog("创建出库申请")]
  1199. public async Task<SemiOutStoreDto> CreateOutStoreApply(SemiOutStoreCreateDto input)
  1200. {
  1201. var currentStore =
  1202. CurrentSemiStoreHouseRepository.FirstOrDefault(i =>
  1203. i.CurrentSemiStoreHouseNo == input.CurrentSemiStoreHouseNo);
  1204. if (currentStore == null)
  1205. {
  1206. CheckErrors(IwbIdentityResult.Failed("未发现库存!"));
  1207. return null;
  1208. }
  1209. #region 检查是否可出入库
  1210. var isCanUpdate =
  1211. CommonAppService.CheckStoreRecordCanUpdate(currentStore.CurrentSemiStoreHouseNo, 2);
  1212. if (!isCanUpdate)
  1213. CheckErrors(IwbIdentityResult.Failed("该库存处于退货或者正在盘点状态,不可进行出入库更新!"));
  1214. #endregion
  1215. var canUseQuantit = currentStore.ActualQuantity - currentStore.FreezeQuantity;
  1216. if (canUseQuantit < input.Quantity)
  1217. {
  1218. CheckErrors(IwbIdentityResult.Failed("可用库存量不够,请检查出库数量!"));
  1219. return null;
  1220. }
  1221. currentStore.ActualQuantity -= input.Quantity;
  1222. await CurrentSemiStoreHouseRepository.UpdateAsync(currentStore);
  1223. input.ApplyOutDate = Clock.Now;
  1224. var entity = ObjectMapper.Map<SemiOutStore>(input);
  1225. entity.ApplyOutStoreSource = OutStoreApplyTypeEnum.OutAssistant.ToInt() + "";
  1226. entity.ApplyTypes = OutStoreApplyTypeEnum.OutAssistant.ToInt();
  1227. entity.ApplyStatus = OutStoreApplyStatusEnum.OutStored.ToInt() + "";
  1228. entity.IsConfirm = true;
  1229. entity.AuditDate = Clock.Now;
  1230. entity.AuditUser = AbpSession.UserName;
  1231. entity.ActualQuantity = input.Quantity;
  1232. entity.TimeCreated = Clock.Now;
  1233. entity.CreatorUserId = AbpSession.UserName;
  1234. entity.TimeLastMod = Clock.Now;
  1235. entity.UserIDLastMod = AbpSession.UserName;
  1236. int id = await SemiOutStoreRepository.InsertAndGetIdAsync(entity);
  1237. BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半成品出库",
  1238. $"创建出库申请(外协加工)[{entity.Id}],信息为:[{entity.Obj2String()}]",
  1239. entity.ProductionOrderNo);
  1240. var dto=ObjectMapper.Map<SemiOutStoreDto>(entity);
  1241. dto.Id = id;
  1242. return dto;
  1243. }
  1244. ///// <summary>
  1245. ///// 半成品出库申请
  1246. ///// </summary>
  1247. ///// <param name="input"></param>
  1248. ///// <returns></returns>
  1249. //[AbpAuthorize(PermissionNames.PagesProductionInfoProductionOutStoreApplyMgCreate), AuditLog("创建出库申请")]
  1250. //public async Task<SemiOutStoreDto> CreateOutStoreApply(SemiOutStoreCreateDto input)
  1251. //{
  1252. // var currentStore =
  1253. // CurrentSemiStoreHouseRepository.FirstOrDefault(i =>
  1254. // i.CurrentSemiStoreHouseNo == input.CurrentSemiStoreHouseNo);
  1255. // if (currentStore == null)
  1256. // {
  1257. // CheckErrors(IwbIdentityResult.Failed("未发现库存!"));
  1258. // return null;
  1259. // }
  1260. // var canUseQuantit = currentStore.ActualQuantity - currentStore.FreezeQuantity;
  1261. // if (canUseQuantit < input.Quantity)
  1262. // {
  1263. // CheckErrors(IwbIdentityResult.Failed("可用库存量不够,请检查出库数量!"));
  1264. // return null;
  1265. // }
  1266. // currentStore.FreezeQuantity += input.Quantity;
  1267. // await CurrentSemiStoreHouseRepository.UpdateAsync(currentStore);
  1268. // input.ApplyOutDate = Clock.Now;
  1269. // var entity = ObjectMapper.Map<SemiOutStore>(input);
  1270. // entity.ApplyOutStoreSource = OutStoreApplyTypeEnum.OutAssistant.ToInt() + "";
  1271. // entity.ApplyTypes = OutStoreApplyTypeEnum.OutAssistant.ToInt();
  1272. // entity.IsConfirm = false;
  1273. // entity.AuditDate = Clock.Now;
  1274. // entity.AuditUser = AbpSession.UserName;
  1275. // entity.ActualQuantity = 0;
  1276. // entity.TimeCreated = Clock.Now;
  1277. // entity.CreatorUserId = AbpSession.UserName;
  1278. // entity.TimeLastMod = Clock.Now;
  1279. // entity.UserIDLastMod = AbpSession.UserName;
  1280. // entity = await SemiOutStoreRepository.InsertAsync(entity);
  1281. // BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半成品出库",
  1282. // $"创建出库申请(外协加工)[{entity.Id}],信息为:[{entity.Obj2String()}]",
  1283. // entity.ProductionOrderNo);
  1284. // return ObjectMapper.Map<SemiOutStoreDto>(entity);
  1285. //}
  1286. [AbpAuthorize(PermissionNames.PagesProductionInfoProductionOutStoreApplyMgUpdate), AuditLog("修改出库申请")]
  1287. public async Task<SemiOutStoreDto> UpdateOutStoreApply(SemiOutStoreUpdateDto input)
  1288. {
  1289. var entity = await SemiOutStoreRepository.FirstOrDefaultAsync(a => a.Id == input.Id);
  1290. if (entity.ApplyStatus == OutStoreApplyStatusEnum.Audited + ""|| entity.ApplyStatus == OutStoreApplyStatusEnum.OutStored + "")
  1291. {
  1292. CheckErrors(IwbIdentityResult.Failed("出库申请已处理,不可操作!"));
  1293. return null;
  1294. }
  1295. var currentStore =
  1296. CurrentSemiStoreHouseRepository.FirstOrDefault(i =>
  1297. i.CurrentSemiStoreHouseNo == input.CurrentSemiStoreHouseNo);
  1298. if (currentStore == null)
  1299. {
  1300. CheckErrors(IwbIdentityResult.Failed("未发现库存!"));
  1301. return null;
  1302. }
  1303. if (entity.ApplyStatus == OutStoreApplyStatusEnum.Applying.ToInt()+"")
  1304. {
  1305. var canUseQuantit = currentStore.ActualQuantity + entity.Quantity - currentStore.FreezeQuantity;
  1306. if (canUseQuantit < input.Quantity)
  1307. {
  1308. CheckErrors(IwbIdentityResult.Failed("可用库存量不够,请检查出库数量!"));
  1309. return null;
  1310. }
  1311. currentStore.FreezeQuantity -= entity.Quantity;
  1312. currentStore.FreezeQuantity += input.Quantity;
  1313. await CurrentSemiStoreHouseRepository.UpdateAsync(currentStore);
  1314. entity.Quantity = input.Quantity;
  1315. }
  1316. entity.TimeLastMod = Clock.Now;
  1317. entity.UserIDLastMod = AbpSession.UserName;
  1318. entity.Remark = input.Remark;
  1319. await SemiOutStoreRepository.UpdateAsync(entity);
  1320. BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半成品出库",
  1321. $"修改半成品出库申请数量[{entity.Id}],[数量修改为{input.Quantity},冻结数量:{currentStore.FreezeQuantity},库存数量:{currentStore.ActualQuantity}]",
  1322. entity.ProductionOrderNo);
  1323. return ObjectMapper.Map<SemiOutStoreDto>(entity);
  1324. }
  1325. /// <summary>
  1326. /// 确认出库数量(by yue.)
  1327. /// </summary>
  1328. /// <param name="input"></param>
  1329. /// <returns></returns>
  1330. [AbpAuthorize(PermissionNames.PagesProductionInfoProductionEnterStoreApplyMgConfirm), AuditLog("确认出库申请")]
  1331. public async Task<SemiOutStoreDto> ConfirmSemiOutStoreQuantity(EntityDto<int> input)
  1332. {
  1333. var entity =await SemiOutStoreRepository.FirstOrDefaultAsync(a => a.Id == input.Id);
  1334. #region 检查是否可出入库
  1335. var isCanUpdate =
  1336. CommonAppService.CheckStoreRecordCanUpdate(entity.CurrentSemiStoreHouseNo, 2);
  1337. if (!isCanUpdate)
  1338. CheckErrors(IwbIdentityResult.Failed("该库存处于退货或者正在盘点状态,不可进行出入库更新!"));
  1339. #endregion
  1340. if (entity.ApplyStatus == OutStoreApplyStatusEnum.OutStored.ToInt() + "")
  1341. {
  1342. CheckErrors(IwbIdentityResult.Failed("已出库不能再操作!"));
  1343. }
  1344. entity.ApplyStatus = OutStoreApplyStatusEnum.OutStored.ToInt() + "";
  1345. entity.IsConfirm = true;
  1346. var date = Clock.Now;
  1347. entity.OutStoreDate = date;
  1348. entity.OutStoreUser = AbpSession.UserName;
  1349. await SemiOutStoreRepository.UpdateAsync(entity);
  1350. var currentStore = await
  1351. CurrentSemiStoreHouseRepository.FirstOrDefaultAsync(i =>
  1352. i.CurrentSemiStoreHouseNo == entity.CurrentSemiStoreHouseNo);
  1353. if (currentStore == null)
  1354. {
  1355. CheckErrors(IwbIdentityResult.Failed("未发现库存!"));
  1356. return null;
  1357. }
  1358. currentStore.FreezeQuantity -= entity.ActualQuantity;
  1359. currentStore.ActualQuantity -= entity.ActualQuantity;
  1360. await CurrentSemiStoreHouseRepository.UpdateAsync(currentStore);
  1361. BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半成品出库",
  1362. $"确认半成品出库数量[{entity.Id}],[出库数量:{entity.ActualQuantity},冻结数量:{currentStore.FreezeQuantity},库存数量:{currentStore.ActualQuantity}]",
  1363. entity.ProductionOrderNo);
  1364. return ObjectMapper.Map<SemiOutStoreDto>(entity);
  1365. }
  1366. /// <summary>
  1367. /// 取消出库申请(by yue.)
  1368. /// </summary>
  1369. /// <param name="input"></param>
  1370. /// <returns></returns>
  1371. [AbpAuthorize(PermissionNames.PagesProductionInfoProductionOutStoreApplyMgCancel), AuditLog("取消出库申请")]
  1372. public async Task<SemiOutStoreDto> CancelSemiOutStoreApplyStatus(EntityDto<int> input)
  1373. {
  1374. var entity = await SemiOutStoreRepository.FirstOrDefaultAsync(a => a.Id == input.Id);
  1375. var currentStore =
  1376. CurrentSemiStoreHouseRepository.FirstOrDefault(i =>
  1377. i.CurrentSemiStoreHouseNo == entity.CurrentSemiStoreHouseNo);
  1378. if (currentStore == null)
  1379. {
  1380. CheckErrors(IwbIdentityResult.Failed("未发现库存!"));
  1381. return null;
  1382. }
  1383. currentStore.FreezeQuantity -= entity.Quantity;
  1384. await CurrentSemiStoreHouseRepository.UpdateAsync(currentStore);
  1385. entity.ApplyStatus = OutStoreApplyStatusEnum.Canceled.ToInt() + "";
  1386. await SemiOutStoreRepository.UpdateAsync(entity);
  1387. BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半成品出库",
  1388. $"取消半成品出库申请[{entity.Id}]",
  1389. entity.ProductionOrderNo);
  1390. return ObjectMapper.Map<SemiOutStoreDto>(entity);
  1391. }
  1392. /// <summary>
  1393. /// 关闭出库申请 (by yue.)
  1394. /// </summary>
  1395. /// <param name="input"></param>
  1396. /// <returns></returns>
  1397. [AbpAuthorize(PermissionNames.PagesProductionInfoProductionOutStoreApplyMgClose), AuditLog("关闭出库申请")]
  1398. public async Task<SemiOutStoreDto> CloseOutStoreApply(EntityDto<int> input)
  1399. {
  1400. var entity = await SemiOutStoreRepository.FirstOrDefaultAsync(a => a.Id == input.Id);
  1401. entity.IsClose = true;
  1402. await SemiOutStoreRepository.UpdateAsync(entity);
  1403. BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半成品出库",
  1404. $"关闭半成品出库申请[{entity.Id}]",
  1405. entity.ProductionOrderNo);
  1406. return ObjectMapper.Map<SemiOutStoreDto>(entity);
  1407. }
  1408. /// <summary>
  1409. /// 恢复出库申请(by yue.)
  1410. /// </summary>
  1411. /// <param name="input"></param>
  1412. /// <returns></returns>
  1413. [AbpAuthorize(PermissionNames.PagesProductionInfoProductionOutStoreApplyMgRecovery),AuditLog("恢复出库申请")]
  1414. public async Task<SemiOutStoreDto> RecoverySemiOutStoreApplyStatus(EntityDto<int> input)
  1415. {
  1416. var entity = await SemiOutStoreRepository.FirstOrDefaultAsync(a => a.Id == input.Id);
  1417. var currentStore =
  1418. CurrentSemiStoreHouseRepository.FirstOrDefault(i =>
  1419. i.CurrentSemiStoreHouseNo == entity.CurrentSemiStoreHouseNo);
  1420. if (currentStore == null)
  1421. {
  1422. CheckErrors(IwbIdentityResult.Failed("未发现库存!"));
  1423. return null;
  1424. }
  1425. if (currentStore.ActualQuantity- currentStore.FreezeQuantity < entity.Quantity)
  1426. {
  1427. CheckErrors(IwbIdentityResult.Failed("可用库存量不够,请检查出库数量!"));
  1428. return null;
  1429. }
  1430. currentStore.FreezeQuantity += entity.Quantity;
  1431. await CurrentSemiStoreHouseRepository.UpdateAsync(currentStore);
  1432. entity.ApplyStatus = OutStoreApplyStatusEnum.Applying.ToInt() + "";
  1433. await SemiOutStoreRepository.UpdateAsync(entity);
  1434. BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半成品出库",
  1435. $"恢复半成品出库申请[{entity.Id}]",
  1436. entity.ProductionOrderNo);
  1437. return ObjectMapper.Map<SemiOutStoreDto>(entity);
  1438. }
  1439. #endregion
  1440. #region 成品改镀
  1441. [DisableAuditing, AbpAuthorize(PermissionNames.PagesProductionInfoRePlatingOutStoreApplyMg)]
  1442. public PagedResultDto<ViewProductOutStore> GetRePlatingOutStoreApply(PagedRequestDto input)
  1443. {
  1444. int type = OutStoreApplyTypeEnum.RePlating.ToInt();
  1445. var query = ViewProductOutStoreRepository.GetAll().Where(a => a.ApplyOutStoreSourceType == type);
  1446. if (input.SearchList != null && input.SearchList.Count > 0)
  1447. {
  1448. List<LambdaObject> objList = new List<LambdaObject>();
  1449. foreach (var o in input.SearchList)
  1450. {
  1451. if (o.KeyWords.IsNullOrEmpty())
  1452. continue;
  1453. object keyWords = o.KeyWords;
  1454. //检查查询条件中带有规格且多个分割条件的
  1455. ProductModelSearch.CheckModelGreaterOneFilter(o, ref keyWords);
  1456. objList.Add(new LambdaObject
  1457. {
  1458. FieldType = (LambdaFieldType)o.FieldType,
  1459. FieldName = o.KeyField,
  1460. FieldValue = keyWords,
  1461. ExpType = (LambdaExpType)o.ExpType
  1462. });
  1463. }
  1464. var exp = objList.GetExp<ViewProductOutStore>();
  1465. query = query.Where(exp);
  1466. }
  1467. var totalCount = query.Count();
  1468. query = query.OrderByDescending(i => i.TimeCreated);
  1469. string pattern = ProductModelSearch.GetModelGreaterOneReg(input.SearchList);
  1470. List<ViewProductOutStore> entities;
  1471. //检查查询条件中带有规格且多个分割条件的
  1472. if (!pattern.IsNullOrEmpty())
  1473. {
  1474. var es = query.ToList();
  1475. es = es.Where(f => f.Model != null && Regex.IsMatch(f.Model, pattern)).ToList();
  1476. totalCount = es.Count;
  1477. entities = es.Skip(input.SkipCount).Take(input.MaxResultCount).ToList();
  1478. }
  1479. else
  1480. {
  1481. query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
  1482. entities = query.ToList();
  1483. }
  1484. //query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
  1485. //var entities = query.ToList();
  1486. var dtos = new PagedResultDto<ViewProductOutStore>(
  1487. totalCount, entities
  1488. );
  1489. return dtos;
  1490. }
  1491. [AbpAuthorize(PermissionNames.PagesProductionInfoRePlatingOutStoreApplyMgCancel), AuditLog("拒绝成品改镀出库申请")]
  1492. public async Task<ProductOutStoreDto> CancelFinishOutStoreApply(EntityDto<int> input)
  1493. {
  1494. var entity = await ProductOutStoreRepository.FirstOrDefaultAsync(a => a.Id == input.Id);
  1495. entity.IsClose = true;
  1496. entity.ApplyStatus = OutStoreApplyStatusEnum.Refused.ToInt();
  1497. await ProductOutStoreRepository.UpdateAsync(entity);
  1498. var currentStore = await CurrentProductStoreHouseRepository.FirstOrDefaultAsync(a =>
  1499. a.CurrentProductStoreHouseNo == entity.CurrentProductStoreHouseNo);
  1500. currentStore.FreezeQuantity -= entity.Quantity;//释放冻结
  1501. await CurrentProductStoreHouseRepository.UpdateAsync(currentStore);
  1502. BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "成品出库",
  1503. $"关闭成品出库申请[{entity.Id}]",
  1504. entity.ProductionOrderNo);
  1505. return ObjectMapper.Map<ProductOutStoreDto>(entity);
  1506. }
  1507. [AbpAuthorize(PermissionNames.PagesProductionInfoRePlatingOutStoreApplyMgExport), AuditLog("导出改镀出库申请")]
  1508. public async Task<string> RePlatingExportApply(EntityDto<int> input)
  1509. {
  1510. var entity = await ProductOutStoreRepository.FirstOrDefaultAsync(a => a.Id == input.Id);
  1511. if (entity == null)
  1512. {
  1513. CheckErrors(IwbIdentityResult.Failed("未查询到排产单信息。"));
  1514. return null;
  1515. }
  1516. var productEntity = ProductRepository.Get(entity.ProductNo);
  1517. string path = AppDomain.CurrentDomain.BaseDirectory + "Resources/ProductionOrderTemplate/RePlatingBillTemplate.xls";
  1518. var work = ExcelHelper.CreateWorkBook03(path);
  1519. var sheet1 = work.GetSheet("Sheet1");
  1520. sheet1.GenerateCell(3, 5).SetCellValue(entity.ProductionOrderNo);
  1521. sheet1.GenerateCell(4, 2).SetCellValue($"{productEntity.PartNo}");
  1522. sheet1.GenerateCell(4, 5).SetCellValue(productEntity.ProductName);
  1523. sheet1.GenerateCell(5, 2).SetCellValue(productEntity.Material);
  1524. sheet1.GenerateCell(5, 4).SetCellValue(productEntity.Rigidity);
  1525. sheet1.GenerateCell(5, 6).SetCellValue(productEntity.Model);
  1526. sheet1.GenerateCell(6, 2).SetCellValue(productEntity.SurfaceColor + "");
  1527. sheet1.GenerateCell(9, 1).SetCellValue($"日期:{Clock.Now:yyyy-MM-dd}");
  1528. var savePath = "Download/Excel/ProductionOrder";
  1529. var fileName = $"改镀单[{entity.Id}]-{Clock.Now:yyyyMMddHHmmss}.xls";
  1530. var result = work.SaveWorkBook($"{AppDomain.CurrentDomain.BaseDirectory}{savePath}", fileName);
  1531. if (!result.IsNullOrEmpty())
  1532. {
  1533. CheckErrors(IwbIdentityResult.Failed(result));
  1534. return null;
  1535. }
  1536. return $"{savePath}/{fileName}";
  1537. }
  1538. #endregion
  1539. #region 数据统计
  1540. /// <summary>
  1541. /// 统计排查单不合格入库
  1542. /// </summary>
  1543. /// <param name="productionOrderNo"></param>
  1544. /// <returns></returns>
  1545. public async Task<EnterFailureRateDto> QueryEnterFailureRate(string productionOrderNo)
  1546. {
  1547. EnterFailureRateDto result = new EnterFailureRateDto();
  1548. var es = await SemiEnterStoreRepository.GetAllListAsync(a => a.ProductionOrderNo == productionOrderNo);
  1549. if (es.Any())
  1550. {
  1551. decimal total = es.Sum(i => i.Quantity);
  1552. decimal unCheckedQuantity = es.Where(i=>i.ApplyStatus == EnterStoreApplyStatusEnum.UnChecked.ToInt() + "").Sum(i => i.Quantity);
  1553. result.ApplyTotalEnterQuantity = total;
  1554. result.FailureQuantity = unCheckedQuantity;
  1555. }
  1556. return result;
  1557. }
  1558. /// <summary>
  1559. /// 生产统计
  1560. /// </summary>
  1561. /// <param name="input"></param>
  1562. /// <returns></returns>
  1563. public async Task<ProductionReportDto> QueryProductionReport(QueryProductionReportDto input)
  1564. {
  1565. var startDate = input.Year.GetDateByType(input.Month,out var endDate ,out var dateStr);
  1566. //查询指定周期员工生产日志
  1567. var query = ProductLogRepository.GetAllIncluding(a => a.EmployeeInfo)
  1568. .Where(a => a.CreationTime >= startDate && a.CreationTime < endDate).OrderBy(a=>a.CreationTime);
  1569. IQueryable<ProductionReportItem> itemQuery = input.EmployeeId != null
  1570. ?
  1571. //查询指定员工的统计(关联半成品入库视图获取半成品信息)
  1572. query.Where(a => a.EmployeeId == input.EmployeeId)
  1573. .Join(ViewSemiEnterStoreRepository.GetAll(),
  1574. a => a.ProductOrderNo, s => s.ProductionOrderNo, (a, s) => new ProductionReportItem()
  1575. {
  1576. ProductDate = a.CreationTime,
  1577. ProductionOrderNo = a.ProductOrderNo,
  1578. ProductNo = s.SemiProductNo,
  1579. ProductName = s.SemiProductName,
  1580. CarNo = a.CarNo,
  1581. PartNo = s.PartNo,
  1582. Model = s.Model,
  1583. Material = s.Material,
  1584. SurfaceColor = s.SurfaceColor,
  1585. Rigidity = s.Rigidity,
  1586. KgQuantity = a.QuantityWeight,
  1587. PcsQuantity = a.QuantityPcs,
  1588. KgWeight = a.KgWeight,
  1589. EmployeeId = a.EmployeeId,
  1590. EmployeeNo = a.EmployeeInfo.No,
  1591. EmployeeName = a.EmployeeInfo.Name
  1592. }).Distinct()
  1593. :
  1594. // 查询所有员工的统计
  1595. query.Select(a => new ProductionReportItem()
  1596. {
  1597. ProductDate= a.CreationTime,
  1598. ProductionOrderNo = a.ProductOrderNo,
  1599. ProductNo = a.ProductionNo,
  1600. KgQuantity = a.QuantityWeight,
  1601. PcsQuantity = a.QuantityPcs,
  1602. KgWeight = a.KgWeight,
  1603. EmployeeId = a.EmployeeId,
  1604. EmployeeNo = a.EmployeeInfo.No,
  1605. EmployeeName = a.EmployeeInfo.Name
  1606. });
  1607. var items = await itemQuery.ToListAsync();
  1608. var dto = new ProductionReportDto(dateStr, items,input.EmployeeId);
  1609. return dto;
  1610. }
  1611. /// <summary>
  1612. /// 外购统计
  1613. /// </summary>
  1614. /// <param name="input"></param>
  1615. /// <returns></returns>
  1616. public async Task<ProductionReportDto> QueryOutsourcingReport(QueryProductionReportDto input)
  1617. {
  1618. var startDate = input.Year.GetDateByType(input.Month,out var endDate ,out var dateStr);
  1619. //查询外购的排产单进行统计(不是新建状态的)
  1620. var query = Repository.GetAll().Where(a => a.TimeCreated >= startDate && a.TimeCreated < endDate && a.ProductionType=="1" && a.ProductionOrderStatus!=1).OrderBy(a=>a.TimeCreated);
  1621. //联合查询半成品信息
  1622. IQueryable<ProductionReportItem> itemQuery = from a in query
  1623. join sp in SemiProductRepository.GetAll() on a.SemiProductNo equals sp.Id into l
  1624. from s in l.DefaultIfEmpty()
  1625. select new ProductionReportItem()
  1626. {
  1627. ProductDate = a.TimeCreated,
  1628. ProductionOrderNo = a.ProductionOrderNo,
  1629. ProductNo = s.Id,
  1630. ProductName = s.SemiProductName,
  1631. PartNo = s.PartNo,
  1632. Model = s.Model,
  1633. Material = s.Material,
  1634. SurfaceColor = s.SurfaceColor,
  1635. Rigidity = s.Rigidity,
  1636. KgQuantity = a.Quantity * a.KgWeight,
  1637. PcsQuantity = a.Quantity,
  1638. KgWeight = a.KgWeight,
  1639. };
  1640. var items = await itemQuery.ToListAsync();
  1641. var dto = new ProductionReportDto(dateStr, items,0);
  1642. return dto;
  1643. }
  1644. /// <summary>
  1645. /// 导出外购报表
  1646. /// </summary>
  1647. /// <param name="input"></param>
  1648. /// <returns></returns>
  1649. public async Task<string> ExportOutsourcingReport(QueryProductionReportDto input)
  1650. {
  1651. var startDate = input.Year.GetDateByType(input.Month,out var endDate ,out var dateStr);
  1652. var dto = await QueryOutsourcingReport(input);
  1653. if (dto.Items == null || !dto.Items.Any())
  1654. {
  1655. CheckErrors(IwbIdentityResult.Failed("未查询采购信息。"));
  1656. return null;
  1657. }
  1658. string path = AppDomain.CurrentDomain.BaseDirectory + "Resources/ProductionOrderTemplate/OutsourcingReport.xls";
  1659. var work = ExcelHelper.CreateWorkBook03(path);
  1660. var sheet1 = work.GetSheet("Sheet1");
  1661. sheet1.GenerateCell(2, 10).SetCellValue(dateStr);
  1662. int index = 4, count = dto.Items.Count;
  1663. sheet1.InsertRows(index, count-1);
  1664. foreach (var item in dto.Items)
  1665. {
  1666. sheet1.GenerateCell(index, 1).SetValue<int>(index - 3);
  1667. sheet1.GenerateCell(index, 2).SetValue(item.ProductionOrderNo);
  1668. sheet1.GenerateCell(index, 3).SetValue(item.ProductName);
  1669. sheet1.GenerateCell(index, 4).SetValue(item.PartNo);
  1670. sheet1.GenerateCell(index, 5).SetValue(item.Model);
  1671. sheet1.GenerateCell(index, 6).SetValue<decimal>(item.PcsQuantity);
  1672. sheet1.GenerateCell(index, 7).SetValue<decimal>(item.KgWeight);
  1673. sheet1.GenerateCell(index, 8).SetValue<decimal>(item.KgQuantity);
  1674. sheet1.GenerateCell(index, 9).SetValue<DateTime>(item.ProductDate);
  1675. sheet1.GenerateCell(index, 10).SetValue(item.Material);
  1676. sheet1.GenerateCell(index, 11).SetValue(item.SurfaceColor);
  1677. index++;
  1678. }
  1679. sheet1.GenerateCell(index, 2).SetValue($"总重量:{dto.KgTotal} kg");
  1680. sheet1.GenerateCell(index, 4).SetValue($"总件数:{dto.PcsTotal} 千件");
  1681. var savePath = "Download/Excel/ProductionOrder/OutsourcingReport";
  1682. var fileName = $"采购统计-{dateStr}-{Clock.Now:yyMMddHHmmss}.xls";
  1683. var result = work?.SaveWorkBook($"{AppDomain.CurrentDomain.BaseDirectory}{savePath}", fileName);
  1684. if (!result.IsNullOrEmpty())
  1685. {
  1686. //CheckErrors(IwbIdentityResult.Failed(result));
  1687. return null;
  1688. }
  1689. return $"/{savePath}/{fileName}";
  1690. }
  1691. #endregion
  1692. #region ExcelExport
  1693. [AbpAuthorize(PermissionNames.PagesProductionInfoProductionOrderMgExport), AuditLog("导出排产单Excel")]
  1694. public async Task<string> ExcelExport(ExportDto input)
  1695. {
  1696. var entity = await Repository.FirstOrDefaultAsync(a => a.Id == input.Id);
  1697. if (entity == null)
  1698. {
  1699. CheckErrors(IwbIdentityResult.Failed("未查询到排产单信息。"));
  1700. return null;
  1701. }
  1702. var semi = await SemiProductRepository.FirstOrDefaultAsync(a => a.Id == entity.SemiProductNo);
  1703. if (semi == null)
  1704. {
  1705. CheckErrors(IwbIdentityResult.Failed("未查询到排产单中半成品信息。"));
  1706. return null;
  1707. }
  1708. string path = AppDomain.CurrentDomain.BaseDirectory + "Resources/ProductionOrderTemplate/ProductionOrderTemplate.xls";
  1709. var work = ExcelHelper.CreateWorkBook03(path);
  1710. var sheet1 = work.GetSheet("Template1");
  1711. sheet1.GenerateCell(2, 10).SetCellValue(entity.ProductionOrderNo);
  1712. sheet1.GenerateCell(4, 11).SetCellValue($"{entity.ProductionOrderNo}{Clock.Now:MMdd}");
  1713. sheet1.GenerateCell(5, 4).SetCellValue(semi.PartNo);
  1714. sheet1.GenerateCell(5, 7).SetCellValue(semi.SemiProductName);
  1715. sheet1.GenerateCell(5, 11).SetCellValue(semi.Model);
  1716. sheet1.GenerateCell(6, 4).SetCellValue(semi.Material);
  1717. sheet1.GenerateCell(6, 11).SetCellValue(entity.Quantity + "");
  1718. sheet1.GenerateCell(8, 4).SetCellValue(semi.ProductDesc);
  1719. sheet1.GenerateCell(8, 11).SetCellValue(semi.Rigidity);
  1720. sheet1.GenerateCell(21, 7).SetCellValue(semi.SurfaceColor);
  1721. var sheet2 = work.GetSheet("Template2");
  1722. sheet2.GenerateCell(1, 17).SetCellValue(entity.ProductionOrderNo);
  1723. sheet2.GenerateCell(3, 16).SetCellValue($"{entity.ProductionOrderNo}{Clock.Now:MMdd}");
  1724. sheet2.GenerateCell(4, 3).SetCellValue(semi.PartNo);
  1725. sheet2.GenerateCell(4, 9).SetCellValue(semi.SemiProductName);
  1726. sheet2.GenerateCell(4, 16).SetCellValue(semi.Model);
  1727. sheet2.GenerateCell(5, 3).SetCellValue(semi.Material);
  1728. sheet2.GenerateCell(7, 3).SetCellValue(semi.ProductDesc);
  1729. var sheet3 = work.GetSheet("Template3");
  1730. sheet3.GenerateCell(2, 10).SetCellValue(entity.ProductionOrderNo);
  1731. sheet3.GenerateCell(4, 4).SetCellValue(semi.PartNo);
  1732. sheet3.GenerateCell(4, 11).SetCellValue($"{entity.ProductionOrderNo}{Clock.Now:MMdd}");
  1733. //sheet3.GenerateCell(5, 4).SetCellValue(semi.PartNo);
  1734. sheet3.GenerateCell(5, 7).SetCellValue(semi.SemiProductName);
  1735. sheet3.GenerateCell(5, 11).SetCellValue(semi.Model);
  1736. sheet3.GenerateCell(6, 4).SetCellValue(semi.Material);
  1737. sheet3.GenerateCell(6, 11).SetCellValue(entity.Quantity + "");
  1738. sheet3.GenerateCell(8, 4).SetCellValue(semi.ProductDesc);
  1739. sheet3.GenerateCell(8, 11).SetCellValue(semi.Rigidity);
  1740. var savePath= "Download/Excel/ProductionOrder";
  1741. var fileName = $"排产单[{entity.ProductionOrderNo}]-{Clock.Now:yyyyMMddHHmmss}.xls";
  1742. var result= work.SaveWorkBook($"{AppDomain.CurrentDomain.BaseDirectory}{savePath}", fileName);
  1743. if (!result.IsNullOrEmpty())
  1744. {
  1745. CheckErrors(IwbIdentityResult.Failed(result));
  1746. return null;
  1747. }
  1748. entity.HasExported = true;
  1749. await Repository.UpdateAsync(entity);
  1750. return $"/{savePath}/{fileName}";
  1751. }
  1752. //[AbpAuthorize(PermissionNames.PagesProductionInfoOutProductionOrderMgExportOut), AuditLog("导出外协排产单Excel")]
  1753. //public async Task<string> ExcelExportOut(EntityDto<string> input)
  1754. //{
  1755. // string selectIds = input.Id;
  1756. // var ids = selectIds.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries);
  1757. // if (!ids.Any())
  1758. // {
  1759. // CheckErrors(IwbIdentityResult.Failed("未查询到排产单信息."));
  1760. // return null;
  1761. // }
  1762. // // List<ProductionOrder> sheetProductionOrders = new List<ProductionOrder>();
  1763. // Dictionary<string, List<ProductionOrder>> dicSheet = new Dictionary<string, List<ProductionOrder>>();
  1764. // foreach (var id in ids)
  1765. // {
  1766. // int.TryParse(id, out int enId);
  1767. // var entity = await Repository.FirstOrDefaultAsync(a => a.Id == enId);
  1768. // if (entity == null)
  1769. // {
  1770. // CheckErrors(IwbIdentityResult.Failed("未查询到排产单信息。"));
  1771. // return null;
  1772. // }
  1773. // if (entity.ProcessingLevel == "1" && entity.ProductionOrderStatus == ProductionOrderStatusEnum.Start.ToInt())
  1774. // {
  1775. // CheckErrors(IwbIdentityResult.Failed("存在排产单未确认审核,不可导出!"));
  1776. // return null;
  1777. // }
  1778. // string enKey = entity.OutsourcingFactory + "@@" + entity.ProcessingType;
  1779. // if (dicSheet.ContainsKey(enKey))
  1780. // {
  1781. // dicSheet[enKey].Add(entity);
  1782. // }
  1783. // else
  1784. // {
  1785. // List<ProductionOrder> productionOrders = new List<ProductionOrder>();
  1786. // productionOrders.Add(entity);
  1787. // dicSheet.Add(enKey, productionOrders);
  1788. // }
  1789. // entity.HasExported = true;
  1790. // await Repository.UpdateAsync(entity);
  1791. // }
  1792. // string path3 = AppDomain.CurrentDomain.BaseDirectory + "Resources/ProductionOrderTemplate/HotProcess.xls";
  1793. // string path2 = AppDomain.CurrentDomain.BaseDirectory + "Resources/ProductionOrderTemplate/SurfaceColorProcess.xls";
  1794. // //List<string> savePathList = new List<string>();
  1795. // string cSavePath = "Download/Excel/ProductionOrder";
  1796. // string fileDir= "Out" + DateTime.Now.ToString("yyMMddHHmmss") + "-" + new Random().Next(1000);
  1797. // var savePath = "Download/Excel/ProductionOrder/"+ fileDir;
  1798. // foreach (var ds in dicSheet)
  1799. // {
  1800. // string[] ot = ds.Key.Split("@@");
  1801. // string type = ot[1];
  1802. // string outFactoryId = ds.Value[0].OutsourcingFactory;
  1803. // var outFactory = await OutFactoryRepository.FirstOrDefaultAsync(a => a.Id == outFactoryId);
  1804. // HSSFWorkbook work = null;
  1805. // if (type == "2")
  1806. // {
  1807. // work = ExcelHelper.CreateWorkBook03(path2);
  1808. // var sheet1 = work.GetSheet("Sheet1");
  1809. // sheet1.GenerateCell(4, 8).SetCellValue("单号:"+DateTime.Now.ToString("yyMMddHHmmss")+new Random().Next(1000));
  1810. // sheet1.GenerateCell(7, 2).SetCellValue(outFactory?.OutFactoryName);
  1811. // sheet1.GenerateCell(7, 9).SetCellValue(outFactory?.Address);
  1812. // sheet1.GenerateCell(8, 2).SetCellValue(outFactory?.Telephone);
  1813. // sheet1.GenerateCell(8, 9).SetCellValue(outFactory?.LinkMan);
  1814. // int index = 1;
  1815. // foreach (var e in ds.Value)
  1816. // {
  1817. // var semi = await SemiProductRepository.FirstOrDefaultAsync(a => a.Id == e.SemiProductNo);
  1818. // sheet1.GenerateCell(10+index, 1).SetCellValue(index);
  1819. // sheet1.GenerateCell(10 + index, 2).SetCellValue(semi?.PartNo);
  1820. // sheet1.GenerateCell(10 + index, 3).SetCellValue(semi?.SemiProductName);
  1821. // sheet1.GenerateCell(10 + index, 4).SetCellValue(semi?.Model);
  1822. // sheet1.GenerateCell(10 + index, 7).SetCellValue(semi?.SurfaceColor);
  1823. // sheet1.GenerateCell(10 + index, 11).SetCellValue(e?.ProductionOrderNo);
  1824. // index++;
  1825. // }
  1826. // }
  1827. // else if (type == "3")
  1828. // {
  1829. // work = ExcelHelper.CreateWorkBook03(path3);
  1830. // var sheet1 = work.GetSheet("Sheet1");
  1831. // sheet1.GenerateCell(4, 8).SetCellValue("单号:" + DateTime.Now.ToString("yyMMddHHmmss") + new Random().Next(1000));
  1832. // sheet1.GenerateCell(7, 2).SetCellValue(outFactory?.OutFactoryName);
  1833. // sheet1.GenerateCell(7, 9).SetCellValue(outFactory?.Address);
  1834. // sheet1.GenerateCell(8, 2).SetCellValue(outFactory?.Telephone);
  1835. // sheet1.GenerateCell(8, 9).SetCellValue(outFactory?.LinkMan);
  1836. // int index = 1;
  1837. // foreach (var e in ds.Value)
  1838. // {
  1839. // var semi = await SemiProductRepository.FirstOrDefaultAsync(a => a.Id == e.SemiProductNo);
  1840. // sheet1.GenerateCell(10 + index, 1).SetCellValue(index);
  1841. // sheet1.GenerateCell(10 + index, 2).SetCellValue(semi?.PartNo);
  1842. // sheet1.GenerateCell(10 + index, 3).SetCellValue(semi?.SemiProductName);
  1843. // sheet1.GenerateCell(10 + index, 4).SetCellValue(semi?.Model);
  1844. // sheet1.GenerateCell(10 + index, 6).SetCellValue(semi?.Material);
  1845. // sheet1.GenerateCell(10 + index, 8).SetCellValue(semi?.SurfaceColor);
  1846. // sheet1.GenerateCell(10 + index, 10).SetCellValue(semi?.Rigidity);
  1847. // sheet1.GenerateCell(10 + index, 11).SetCellValue(e?.ProductionOrderNo);
  1848. // index++;
  1849. // }
  1850. // }
  1851. // var fileName = $"外协排产单[{ ds.Value[0].ProductionOrderNo}]-{Clock.Now:HHmmss}.xls";
  1852. // //string lcPath = $"{AppDomain.CurrentDomain.BaseDirectory}{savePath}" + "\\" + fileName;
  1853. // var result = work?.SaveWorkBook($"{AppDomain.CurrentDomain.BaseDirectory}{savePath}", fileName);
  1854. // if (!result.IsNullOrEmpty())
  1855. // {
  1856. // CheckErrors(IwbIdentityResult.Failed(result));
  1857. // return null;
  1858. // }
  1859. // //savePathList.Add(lcPath);
  1860. // }
  1861. // ZipHelper.ZipDirectory($"{AppDomain.CurrentDomain.BaseDirectory}{savePath}", $"{AppDomain.CurrentDomain.BaseDirectory}{cSavePath}/{fileDir}.zip" );
  1862. // return $"/{cSavePath}/{fileDir}.zip";
  1863. //}
  1864. [AbpAuthorize(PermissionNames.PagesProductionInfoOutProductionOrderMgExportOut), AuditLog("导出外协排产单Excel")]
  1865. public async Task<string> ExcelExportOut(EntityDto<string> input)
  1866. {
  1867. string selectIds = input.Id;
  1868. var ids = selectIds.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  1869. if (!ids.Any())
  1870. {
  1871. CheckErrors(IwbIdentityResult.Failed("未查询到排产单信息."));
  1872. return null;
  1873. }
  1874. // List<ProductionOrder> sheetProductionOrders = new List<ProductionOrder>();
  1875. Dictionary<string, List<ProductionOrder>> dicSheet = new Dictionary<string, List<ProductionOrder>>();
  1876. foreach (var id in ids)
  1877. {
  1878. int.TryParse(id, out int enId);
  1879. var entity = await Repository.FirstOrDefaultAsync(a => a.Id == enId);
  1880. if (entity == null)
  1881. {
  1882. CheckErrors(IwbIdentityResult.Failed("未查询到排产单信息。"));
  1883. return null;
  1884. }
  1885. if (entity.ProcessingLevel == "1" && entity.ProductionOrderStatus == ProductionOrderStatusEnum.Start.ToInt())
  1886. {
  1887. CheckErrors(IwbIdentityResult.Failed("存在排产单未确认审核,不可导出!"));
  1888. return null;
  1889. }
  1890. string enKey = entity.OutsourcingFactory + "@@" + entity.ProcessingType;
  1891. if (dicSheet.ContainsKey(enKey))
  1892. {
  1893. dicSheet[enKey].Add(entity);
  1894. }
  1895. else
  1896. {
  1897. List<ProductionOrder> productionOrders = new List<ProductionOrder>();
  1898. productionOrders.Add(entity);
  1899. dicSheet.Add(enKey, productionOrders);
  1900. }
  1901. entity.HasExported = true;
  1902. await Repository.UpdateAsync(entity);
  1903. }
  1904. string path3 = AppDomain.CurrentDomain.BaseDirectory + "Resources/ProductionOrderTemplate/HotProcess_v2.xls";
  1905. string path2 = AppDomain.CurrentDomain.BaseDirectory + "Resources/ProductionOrderTemplate/SurfaceColorProcess_v2.xls";
  1906. //List<string> savePathList = new List<string>();
  1907. string cSavePath = "Download/Excel/ProductionOrder";
  1908. string fileDir = "Out" + DateTime.Now.ToString("yyMMddHHmmss") + "-" + new Random().Next(1000);
  1909. var savePath = "Download/Excel/ProductionOrder/" + fileDir;
  1910. foreach (var ds in dicSheet)
  1911. {
  1912. string[] ot = ds.Key.Split("@@");
  1913. string type = ot[1];
  1914. string outFactoryId = ds.Value[0].OutsourcingFactory;
  1915. var outFactory = await OutFactoryRepository.FirstOrDefaultAsync(a => a.Id == outFactoryId);
  1916. HSSFWorkbook work = null;
  1917. if (type == "2")
  1918. {
  1919. work = ExcelHelper.CreateWorkBook03(path2);
  1920. var sheet1 = work.GetSheet("Sheet1");
  1921. sheet1.GenerateCell(2, 8).SetCellValue("单号:" + DateTime.Now.ToString("yyMMddHHmmss") + new Random().Next(1000));
  1922. sheet1.GenerateCell(5, 2).SetCellValue(outFactory?.OutFactoryName);
  1923. sheet1.GenerateCell(5, 8).SetCellValue(outFactory?.Address);
  1924. sheet1.GenerateCell(6, 2).SetCellValue(outFactory?.Telephone);
  1925. sheet1.GenerateCell(6, 8).SetCellValue(outFactory?.LinkMan);
  1926. sheet1.GenerateCell(7, 1).SetCellValue("开单日期:" + DateTime.Now.ToString("yyyy-MM-dd"));
  1927. int index = 0;
  1928. sheet1.InsertRows(10, ds.Value.Count>1 ? ds.Value.Count-1:0);
  1929. foreach (var e in ds.Value)
  1930. {
  1931. var semi = await SemiProductRepository.FirstOrDefaultAsync(a => a.Id == e.SemiProductNo);
  1932. sheet1.GenerateCell(10 + index, 1).SetCellValue(index+1);
  1933. //sheet1.GenerateCell(10 + index, 2).SetCellValue(semi?.PartNo);
  1934. sheet1.GenerateCell(10 + index, 2).SetCellValue(semi?.SemiProductName);
  1935. sheet1.GenerateCell(10 + index, 3).SetCellValue(semi?.Model);
  1936. sheet1.GenerateCell(10 + index, 4).SetCellValue(semi?.Rigidity);
  1937. sheet1.GenerateCell(10 + index, 5).SetCellValue("人工填写");
  1938. sheet1.MergedRegion(10 + index, 10 + index, 7, 9);
  1939. sheet1.GenerateCell(10 + index, 7).SetCellValue(semi?.SurfaceColor);
  1940. sheet1.GenerateCell(10 + index, 10).SetCellValue("人工填写");
  1941. sheet1.GenerateCell(10 + index, 11).SetCellValue(e?.SemiProductNo);
  1942. sheet1.GenerateCell(10 + index, 12).SetCellValue(e?.ProductionOrderNo);
  1943. index++;
  1944. }
  1945. sheet1.GenerateCell(10 + index, 10).SetCellValue("发货日期:" + DateTime.Now.ToString("yyyy-MM-dd"));
  1946. }
  1947. else if (type == "3")
  1948. {
  1949. work = ExcelHelper.CreateWorkBook03(path3);
  1950. var sheet1 = work.GetSheet("Sheet1");
  1951. sheet1.GenerateCell(2, 5).SetCellValue("单号:" + DateTime.Now.ToString("yyMMddHHmmss") + new Random().Next(1000));
  1952. sheet1.GenerateCell(5, 2).SetCellValue(outFactory?.OutFactoryName);
  1953. sheet1.GenerateCell(5, 6).SetCellValue(outFactory?.Address);
  1954. sheet1.GenerateCell(6, 2).SetCellValue(outFactory?.Telephone);
  1955. sheet1.GenerateCell(6, 6).SetCellValue(outFactory?.LinkMan);
  1956. sheet1.GenerateCell(7, 1).SetCellValue("开单日期/热处理批次号:"+ DateTime.Now.ToString("yyyyMMdd"));
  1957. int index = 0;
  1958. sheet1.InsertRows(10, ds.Value.Count > 1 ? ds.Value.Count - 1 : 0);
  1959. foreach (var e in ds.Value)
  1960. {
  1961. var semi = await SemiProductRepository.FirstOrDefaultAsync(a => a.Id == e.SemiProductNo);
  1962. sheet1.GenerateCell(10 + index, 1).SetCellValue(index+1);
  1963. //sheet1.GenerateCell(10 + index, 2).SetCellValue(semi?.PartNo);
  1964. sheet1.GenerateCell(10 + index, 2).SetCellValue(semi?.SemiProductName);
  1965. sheet1.GenerateCell(10 + index, 3).SetCellValue(semi?.Model);
  1966. sheet1.GenerateCell(10 + index, 5).SetCellValue(semi?.Material);
  1967. sheet1.GenerateCell(10 + index, 7).SetCellValue(semi?.Rigidity);
  1968. sheet1.GenerateCell(10 + index, 8).SetCellValue("芯部要达到");
  1969. sheet1.GenerateCell(10 + index, 9).SetCellValue(e?.ProductionOrderNo);
  1970. index++;
  1971. }
  1972. sheet1.GenerateCell(10 + index, 8).SetCellValue("发货日期:" + DateTime.Now.ToString("yyyy-MM-dd"));
  1973. }
  1974. var fileName = $"外协排产单[{ ds.Value[0].ProductionOrderNo}]-{Clock.Now:HHmmss}.xls";
  1975. //string lcPath = $"{AppDomain.CurrentDomain.BaseDirectory}{savePath}" + "\\" + fileName;
  1976. var result = work?.SaveWorkBook($"{AppDomain.CurrentDomain.BaseDirectory}{savePath}", fileName);
  1977. if (!result.IsNullOrEmpty())
  1978. {
  1979. CheckErrors(IwbIdentityResult.Failed(result));
  1980. return null;
  1981. }
  1982. //savePathList.Add(lcPath);
  1983. }
  1984. ZipHelper.ZipDirectory($"{AppDomain.CurrentDomain.BaseDirectory}{savePath}", $"{AppDomain.CurrentDomain.BaseDirectory}{cSavePath}/{fileDir}.zip");
  1985. return $"/{cSavePath}/{fileDir}.zip";
  1986. }
  1987. #endregion
  1988. /// <summary>
  1989. /// 变更排产单类型
  1990. /// </summary>
  1991. /// <param name="input"></param>
  1992. /// <returns></returns>
  1993. public async Task<ProductionOrderDto> UpdateProductionType(ProductionTypeUpdateDto input)
  1994. {
  1995. var entity =await Repository.GetAsync(input.Id);
  1996. if (entity == null)
  1997. {
  1998. CheckErrors(IdentityResult.Failed("为查询到相应的排产单!"));
  1999. }
  2000. var arrWg = new string[]
  2001. {
  2002. ((int)ProductionOrderTypeEnum.OutFinish).ToString(),
  2003. ((int)ProductionOrderTypeEnum.RemovalProcess).ToString()
  2004. };
  2005. string preProductionType = entity.ProductionType;
  2006. string preProductionOrderNo = entity.ProductionOrderNo;
  2007. //类型一致,不更新
  2008. if (preProductionType == input.ProductionType)
  2009. {
  2010. return ObjectMapper.Map<ProductionOrderDto>(entity);
  2011. }
  2012. //更新单号
  2013. var newNo = SwapOrderNo(entity.ProductionOrderNo);
  2014. //如果类型变更是在外购成品和去料加工之间互换的,编号不做更新
  2015. if (arrWg.Contains(preProductionType) && arrWg.Contains(input.ProductionType))
  2016. {
  2017. newNo = preProductionOrderNo;
  2018. }
  2019. if (newNo.IsNullOrEmpty())
  2020. {
  2021. CheckErrors(IdentityResult.Failed("排产单号更新失败!"));
  2022. }
  2023. entity.ProductionOrderNo = newNo;
  2024. entity.ProductionType = input.ProductionType;
  2025. entity.TimeLastMod = Clock.Now;
  2026. entity.UserIDLastMod = AbpSession.UserId + "";
  2027. entity = await Repository.UpdateAsync(entity);
  2028. BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半产品排产单类型变更",
  2029. $"修改外协排产单[{entity.Id}],信息为:[{entity.Obj2String()}]",
  2030. $"原编号{preProductionOrderNo},原类型{preProductionType}", $"新编号{newNo},新类型{input.ProductionType}");
  2031. return MapToEntityDto(entity);
  2032. }
  2033. }
  2034. }