| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138 |
- using System;
- using System.Collections.Generic;
- using System.Data.Entity;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using Abp.Application.Services.Dto;
- using Abp.Auditing;
- using Abp.Authorization;
- using Abp.Domain.Repositories;
- using Abp.Domain.Uow;
- using Abp.Extensions;
- using Abp.Timing;
- using Abp.UI;
- using Castle.Components.DictionaryAdapter;
- using IwbZero.AppServiceBase;
- using IwbZero.Auditing;
- using IwbZero.Helper;
- using IwbZero.IdentityFramework;
- using IwbZero.Setting;
- using JetBrains.Annotations;
- using Microsoft.AspNet.Identity;
- using Newtonsoft.Json;
- using NPOI.HSSF.UserModel;
- using ShwasherSys.Authorization.Permissions;
- using ShwasherSys.BaseSysInfo;
- using ShwasherSys.BasicInfo.OutFactory;
- using ShwasherSys.Common;
- using ShwasherSys.CompanyInfo;
- using ShwasherSys.Lambda;
- using ShwasherSys.ProductionOrderInfo.Dto;
- using ShwasherSys.ProductInfo;
- using ShwasherSys.ProductStoreInfo;
- using ShwasherSys.ProductStoreInfo.Dto;
- using ShwasherSys.SemiProductStoreInfo;
- using ShwasherSys.SemiProductStoreInfo.Dto;
- using ShwasherSys.RmStore;
- using LambdaExpType = ShwasherSys.Lambda.LambdaExpType;
- using LambdaFieldType = ShwasherSys.Lambda.LambdaFieldType;
- using LambdaObject = ShwasherSys.Lambda.LambdaObject;
- using ShwasherSys.BaseSysInfo.States;
- using ShwasherSys.Common.Dto;
- using ShwasherSys.Order;
- using ShwasherSys.ProductionOrderInfo.Dto.BindOrder;
- namespace ShwasherSys.ProductionOrderInfo
- {
- [AbpAuthorize, AuditLog("半成品排产出入库维护")]
- public class ProductionOrdersAppService : ShwasherAsyncCrudAppService<ProductionOrder, ProductionOrderDto, int, PagedRequestDto, ProductionOrderCreateDto, ProductionOrderUpdateDto>
- , IProductionOrdersAppService
- {
- protected IRepository<CurrentRmStoreHouse,string> CrsRepository { get; }
- protected IRepository<RmEnterStore,string> ErsRepository { get; }
- protected IRepository<RmOutStore,string> OrsRepository { get; }
- protected IRepository<EmployeeWorkPerformance> PerformanceRepository { get; }
- protected IRepository<BusinessLog> LogRepository;
- protected IRepository<ProductionLog> ProductLogRepository;
- protected IRepository<SemiEnterStore> SemiEnterStoreRepository;
- protected IRepository<ViewSemiEnterStore> ViewSemiEnterStoreRepository;
- protected IRepository<SemiOutStore> SemiOutStoreRepository;
- protected IRepository<CurrentSemiStoreHouse> CurrentSemiStoreHouseRepository;
- protected IRepository<ViewSemiOutStore> ViewSemiOutStoreRepository;
- protected IRepository<SemiProducts, string> SemiProductRepository;
- protected IRepository<OutFactory,string> OutFactoryRepository;
- protected IRepository<ViewProductOutStore> ViewProductOutStoreRepository { get; }
- protected IRepository<ProductOutStore> ProductOutStoreRepository { get; }
- protected IRepository<Product,string> ProductRepository { get; }
- protected IRepository<CurrentProductStoreHouse> CurrentProductStoreHouseRepository { get; }
- protected ICommonAppService CommonAppService { get; }
- protected IStatesAppService StatesAppService;
- protected IRepository<OrderProduction> OrderProductionRepository { get; }
- protected IRepository<ViewOrderItems> ViewOrderItemsRepository { get; }
- 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")
- {
- LogRepository = logRepository;
- SemiEnterStoreRepository = semiEnterStoreRepository;
- SemiOutStoreRepository = semiOutStoreRepository;
- ViewSemiEnterStoreRepository = viewSemiEnterStoreRepository;
- CurrentSemiStoreHouseRepository = currentSemiStoreHouseRepository;
- ViewSemiOutStoreRepository = viewSemiOutStoreRepository;
- SemiProductRepository = semiProductRepository;
- OutFactoryRepository = outFactoryRepository;
- ProductLogRepository = productLogRepository;
- PerformanceRepository = performanceRepository;
- OrsRepository = orsRepository;
- ErsRepository = ersRepository;
- CrsRepository = crsRepository;
- CommonAppService = commonAppService;
- ViewProductOutStoreRepository = viewProductOutStoreRepository;
- ProductOutStoreRepository = productOutStoreRepository;
- CurrentProductStoreHouseRepository = currentProductStoreHouseRepository;
- ProductRepository = productRepository;
- StatesAppService = statesAppService;
- OrderProductionRepository = orderProductionRepository;
- ViewOrderItemsRepository = viewOrderItemsRepository;
- SettingManager = settingManager;
- }
- protected override bool KeyIsAuto { get; set; } = false;
- protected override string GetPermissionName { get; set; } = PermissionNames.PagesProductionInfoProductionOrderMg;
- protected override string GetAllPermissionName { get; set; } = PermissionNames.PagesProductionInfoProductionOrderMg;
- protected override string CreatePermissionName { get; set; } = PermissionNames.PagesProductionInfoProductionOrderMgCreate;
- protected override string UpdatePermissionName { get; set; } = PermissionNames.PagesProductionInfoProductionOrderMgUpdate;
- protected override string DeletePermissionName { get; set; } = PermissionNames.PagesProductionInfoProductionOrderMgDelete;
- #region 排产单
- [DisableAuditing]
- public override async Task<PagedResultDto<ProductionOrderDto>> GetAll(PagedRequestDto input)
- {
- var result = GetAllData(input.SearchList);
- var totalCount = await AsyncQueryableExecuter.CountAsync(result);
- result = result.OrderByDescending(i => i.TimeCreated);
- string pattern = ProductModelSearch.GetModelGreaterOneReg(input.SearchList);
- List<ProductionOrderDto> entity;
- //检查查询条件中带有规格且多个分割条件的
- if (!pattern.IsNullOrEmpty())
- {
- var es = result.ToList();
- es = es.Where(f => f.Model != null && Regex.IsMatch(f.Model, pattern)).ToList();
- totalCount = es.Count;
- entity = es.Skip(input.SkipCount).Take(input.MaxResultCount).ToList();
- }
- else
- {
- result = result.Skip(input.SkipCount).Take(input.MaxResultCount);
- entity = result.ToList();
- }
- //result = result.Skip(input.SkipCount).Take(input.MaxResultCount);
- //var entity = result.ToList();
- var dtos = new PagedResultDto<ProductionOrderDto>(
- totalCount,
- entity
- );
- return dtos;
- }
- private IQueryable<ProductionOrderDto> GetAllData(List<MultiSearchDto> input)
- {
- CheckGetAllPermission();
- bool hasEnd = false;
- var query = Repository.GetAll();
- var outFacQuery = OutFactoryRepository.GetAll();
-
- var result = from u in query
- join s in SemiProductRepository.GetAll() on u.SemiProductNo equals s.Id into l
- from luq in l.DefaultIfEmpty()
- join o in outFacQuery on u.OutsourcingFactory equals o.Id into j
- from oj in j.DefaultIfEmpty()
- select new ProductionOrderDto
- {
- Model = luq.Model ?? "",
- CarNo = u.CarNo,
- EnterQuantity = u.EnterQuantity,
- Id = u.Id,
- ProductionType = u.ProductionType,
- OutsourcingFactory = u.OutsourcingFactory,
- CreatorUserId = u.CreatorUserId,
- IsChecked = u.IsChecked,
- IsLock = u.IsLock,
- Material = luq.Material ?? "",
- PartNo = luq.PartNo ?? "",
- PlanProduceDate = u.PlanProduceDate,
- RawMaterials = u.RawMaterials,
- SurfaceColor = luq.SurfaceColor ?? "",
- Rigidity = luq.Rigidity ?? "",
- Remark = u.Remark,
- UserIDLastMod = u.UserIDLastMod,
- TimeCreated = u.TimeCreated,
- TimeLastMod = u.TimeLastMod,
- Size = u.Size,
- ProcessingType = u.ProcessingType,
- ProcessingLevel = u.ProcessingLevel,
- SourceProductionOrderNo = u.SourceProductionOrderNo,
- StoveNo = u.StoveNo,
- Quantity = u.Quantity,
- ProductionOrderNo = u.ProductionOrderNo,
- ProductionOrderStatus = u.ProductionOrderStatus,
- SemiProductNo = u.SemiProductNo,
- SemiProductName = luq.SemiProductName,
- KgWeight = u.KgWeight,
- OutsourcingFactoryName = oj.OutFactoryName,
- EnterDate = u.EnterDate,
- InspectDate = u.InspectDate,
- HasExported = u.HasExported
- };
- //逻辑删除也同时显示出来
- //var property = typeof(ProductionOrder).GetProperty("IsLock");
- //if (property != null)
- //{
- // LambdaObject objLambdaObject = new LambdaObject()
- // {
- // FieldType = LambdaFieldType.S,
- // FieldName = "IsLock",
- // FieldValue = "N",
- // ExpType = LambdaExpType.Equal
- // };
- // var expIsLock = objLambdaObject.GetExp<ProductionOrderDto>();
- // result = result.Where(expIsLock);
- //}
- if (input != null && input.Count > 0)
- {
- List<LambdaObject> objList = new List<LambdaObject>();
- foreach (var o in input)
- {
- if (o.KeyWords.IsNullOrEmpty())
- continue;
- object keyWords = o.KeyWords;
- //检查查询条件中带有规格且多个分割条件的
- ProductModelSearch.CheckModelGreaterOneFilter(o, ref keyWords);
- objList.Add(new LambdaObject
- {
- FieldType = (LambdaFieldType)o.FieldType,
- FieldName = o.KeyField,
- FieldValue = keyWords,
- ExpType = (LambdaExpType)o.ExpType
- });
- if (o.KeyField?.ToLower() == "productionorderstatus" && o.KeyWords == ProductionOrderStatusEnum.End.ToInt() + "")
- {
- hasEnd = true;
- }
- }
- var exp = objList.GetExp<ProductionOrderDto>();
- result = exp!=null? result.Where(exp):result;
- }
- if (!hasEnd)
- {
- var endState = ProductionOrderStatusEnum.End.ToInt();
- result = result.Where(a => (a.ProductionOrderStatus != endState));
- }
-
- return result;
- }
- private string GetProductionOrderStatus(string p,int? isCheck,bool hasExported=false)
- {
- var stateDtos = StatesAppService.GetStateList("ProductionOrders", "ProductionOrderStatus",i=>i.CodeValue==p);
- var state = stateDtos.First();
- string result = state.DisplayValue;
- if (p == "4")
- {
- result += (isCheck??0)>0 ? "-已检验" : "-待检验";
- }
- result += hasExported ? "-已导出" : "";
- return result;
- }
-
- public async Task<string> ExportListToExcel(List<MultiSearchDto> input)
- {
- var result = GetAllData(input);
- result = result.OrderByDescending(i => i.TimeCreated);
- string pattern = ProductModelSearch.GetModelGreaterOneReg(input);
- List<ProductionOrderDto> entity = result.ToList();
- //检查查询条件中带有规格且多个分割条件的
- if (!pattern.IsNullOrEmpty())
- {
- entity = entity.Where(f => f.Model != null && Regex.IsMatch(f.Model, pattern)).ToList();
- }
- // List<ProductionOrderDto> entity = result.ToList();
- List<ProductionOrderExcelDto> r = new List<ProductionOrderExcelDto>();
- try
- {
- foreach (var t in entity)
- {
- ProductionOrderExcelDto e = new ProductionOrderExcelDto();
- e.ProductionOrderNo = t.ProductionOrderNo;
- e.PartNo = t.PartNo;
- e.SemiProductName = t.SemiProductName;
- e.Model = t.Model;
- e.Quantity = t.Quantity+"";
- e.TimeCreated = (t.TimeCreated ?? DateTime.Now).ToString("yyyy-MM-dd");
- e.ProductionOrderStatus = GetProductionOrderStatus(t.ProductionOrderStatus + "",
- t.IsChecked ?? 0, t.HasExported);
- e.Remark = t.Remark;
- e.Rigidity = t.Rigidity;
- e.SurfaceColor = t.SurfaceColor;
- e.Material = t.Material;
- e.KgWeight = t.KgWeight+"";
- e.PlanProduceDate = (t.PlanProduceDate ?? DateTime.Now).ToString("yyyy-MM-dd");
- e.EnterDate = (t.EnterDate ?? DateTime.Now).ToString("yyyy-MM-dd");
- e.OutsourcingFactoryName = t.OutsourcingFactoryName;
- e.ProcessingType = StatesAppService.GetDisplayValue("ProductionOrders", "ProcessingType",
- t.ProcessingType.ToString());
- e.SemiProductNo = t.SemiProductNo;
- r.Add(e);
- }
- string downloadUrl =await SettingManager.GetSettingValueAsync("SYSTEMDOWNLOADPATH");
- string lcFilePath = System.Web.HttpRuntime.AppDomainAppPath +"\\"+
- downloadUrl;
- var exportEntity = new Dictionary<string, string>()
- {
- {"ProductionOrderNo", "订单流水号"},
- {"PartNo", "零件号"},
- {"SemiProductName", "名称"},
- {"Model", "规格"},
- {"Quantity", "排产数量"},
- {"TimeCreated", "创建时间"},
- {"ProductionOrderStatus", "生产状态"},
- {"Remark", "备注"},
- {"Rigidity", "硬度"},
- {"SurfaceColor", "表色"},
- {"Material", "材质"},
- {"KgWeight", "千件重"},
- {"PlanProduceDate", "计划完成时间"},
- {"EnterDate", "入库时间"},
- {"OutsourcingFactoryName", "外协厂商"},
- {"ProcessingType", "加工类型"},
- {"SemiProductNo", "产品编码"},
- };
- string lcResultFileName = ExcelHelper.EntityListToExcel2003(exportEntity, r, "sheet", lcFilePath);
- return Path.Combine(downloadUrl, lcResultFileName);
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex);
- // throw;
- }
- return "";
- }
- private ProductionOrderDto TrunProductionOrderDto(ProductionOrder p,SemiProducts s)
- {
- var productionOrderDto = MapToEntityDto(p);
- productionOrderDto.Model = s.Model ?? "";
- productionOrderDto.Material = s.Material ?? "";
- productionOrderDto.PartNo = s.PartNo ?? "";
- productionOrderDto.SurfaceColor = s.SurfaceColor ?? "";
- productionOrderDto.Rigidity = s.Rigidity ?? "";
- /*var productionOrderDto = new ProductionOrderDto(p)
- {
- Model = s.Model ?? "",
- Material = s.Material ?? "",
- PartNo = s.PartNo ?? "",
- SurfaceColor = s.SurfaceColor ?? "",
- Rigidity = s.Rigidity ?? "",
- };*/
- return productionOrderDto;
- }
- /// <summary>
- /// 获取新建排产单的编号
- /// </summary>
- /// <returns></returns>
- [DisableAuditing]
- public async Task<string> GetNewProductionOrderNo()
- {
- return await GetNewProductionOrderNo(0);
- }
- /// <summary>
- /// 获取新建排产单(外购单)的编号
- /// </summary>
- /// <returns></returns>
- [DisableAuditing]
- public async Task<string> GetNewProductionOrderNo(int isOutsourcing)
- {
-
- CheckGetAllPermission();
- string lcRetVal;
- DateTime loTiem = DateTime.Parse(DateTime.Now.Year + "-" + DateTime.Now.Month + "-01");
- //loTiem = loTiem.AddSeconds(-1);
- var orders = (await Repository.GetAllListAsync(i => i.TimeCreated >= loTiem && i.ProcessingLevel == "1")).OrderByDescending(i => i.Id).ToList();
- var orderNo = orders.FirstOrDefault()?.ProductionOrderNo;
- if (!string.IsNullOrEmpty(orderNo))
- {
- var liTempNo = Convert.ToInt32(orderNo.Substring(3, 4));
- liTempNo++;
- lcRetVal = liTempNo.ToString();
- while (lcRetVal.Length < 4)
- {
- lcRetVal = "0" + lcRetVal;
- }
- }
- else
- {
- lcRetVal = "0001";
- }
- DateTime loDate = DateTime.Today;
- //string lcMonth = liMonth < 10 ? liMonth + "" : Convert.ToString(liMonth, 16);
- lcRetVal = loDate.Date.Year + GetMonthString(isOutsourcing) + lcRetVal;
- lcRetVal = lcRetVal.Substring(2, lcRetVal.Length - 2);
- return lcRetVal;
- }
- /// <summary>
- /// 转换月份
- /// </summary>
- /// <param name="isOutsourcing"></param>
- /// <returns></returns>
- private string GetMonthString(int isOutsourcing)
- {
- DateTime loDate = DateTime.Today;
- int liMonth = loDate.Date.Month;
- if (isOutsourcing == 0)
- {
- return liMonth < 10 ? liMonth + "" : Convert.ToString(liMonth, 16).ToUpper();
- }
- string[] scource = {"", "G", "H", "W", "J", "K", "L", "M", "N", "T", "P","Q","R"};
- return scource[liMonth];
- }
- [AbpAuthorize(PermissionNames.PagesProductionInfoProductionOrderMgUpdate), AuditLog("变更排产状态")]
- public async Task<ProductionOrderDto> ChangeProductionOrderStatus(ChangeProductionOrderStatusDto input)
- {
- var entity = await Repository.FirstOrDefaultAsync(a => a.Id == input.Id);
- if (entity.ProductionOrderStatus > ProductionOrderStatusEnum.Producting.ToInt()&&entity.ProductionOrderStatus!= ProductionOrderStatusEnum.HangUp.ToInt() && entity.ProductionOrderStatus != ProductionOrderStatusEnum.Audited.ToInt() && entity.IsChecked==0)
- {
- CheckErrors(IwbIdentityResult.Failed("排产单已进行入库,不可进行更改!"));
- }
- //审核时进行绑定订单明细校验
- if (input.ProductionOrderStatus == ProductionOrderStatusEnum.Audited.ToInt())
- {
- var os = QueryOrderItemByPoNo(entity.ProductionOrderNo);
- if (!os.Any())
- {
- CheckErrors(IwbIdentityResult.Failed("排产单未绑定订单明细!"));
- }
- }
-
- entity.ProductionOrderStatus = input.ProductionOrderStatus;
- //ProductionOrderLogs loLogs = new ProductionOrderLogs()
- //{
- // ProductionOrderNo = loProductionOrder.ProductionOrderNo,
- // CreatorUserId = AbpSession.UserName,
- // OperatorTitle = $"排产单:{loProductionOrder.ProductionOrderNo} 状态变更",
- // OperatorConent = $"排产单:{loProductionOrder.ProductionOrderNo} 状态变更为{input.ProductionOrderStatus}",
- // TimeCreated = Clock.Now
- //};
- //await ProductionOrderLogRepository.InsertAsync(loLogs);
- entity = await Repository.UpdateAsync(entity);
- BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半产品排产",
- $"排产单状态变更为[{(ProductionOrderStatusEnum)input.ProductionOrderStatus}]",
- entity.ProductionOrderNo);
- return MapToEntityDto(entity);
- }
- [AbpAuthorize(PermissionNames.PagesProductionInfoProductionOrderMgUpdate), AuditLog("排产进入已入库状态状态")]
- public async Task<ProductionOrderDto> ConfirmEnterStore(ConfirmEnterStoreDto input)
- {
- var entity = await Repository.FirstOrDefaultAsync(a => a.Id == input.Id);
- if (entity.ProductionOrderStatus != ProductionOrderStatusEnum.Storeing.ToInt())
- {
- CheckErrors(IwbIdentityResult.Failed("排查单未进行入库操作!"));
- }
- entity.ProductionOrderStatus = ProductionOrderStatusEnum.EnterStore.ToInt();
- //ProductionOrderLogs loLogs = new ProductionOrderLogs()
- //{
- // ProductionOrderNo = loProductionOrder.ProductionOrderNo,
- // CreatorUserId = AbpSession.UserName,
- // OperatorTitle = $"排产单:{loProductionOrder.ProductionOrderNo} 状态变更",
- // OperatorConent = $"排产单:{loProductionOrder.ProductionOrderNo} 状态变更为{input.ProductionOrderStatus}",
- // TimeCreated = Clock.Now
- //};
- //await ProductionOrderLogRepository.InsertAsync(loLogs);
- entity.EnterDate = Clock.Now;
- entity = await Repository.UpdateAsync(entity);
- if (string.IsNullOrEmpty(input.CurrentRmHouseId))
- {
- BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半产品排产",
- $"排产单状态变更为[{ProductionOrderStatusEnum.EnterStore}]。");
- }
- else
- {
- var rmCurrent= await CreateRwStore(input, entity.ProductionOrderNo);
- BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半产品排产确认入库(车间生产)",$"排产单状态变更为[{ProductionOrderStatusEnum.EnterStore}]。原材料[{rmCurrent.RmProductNo}],领用{input.TotalQuantity}kg,剩余{input.LaveQuantity}kg,使用后库存:{rmCurrent.Quantity}kg",entity.ProductionOrderNo);
- }
- return MapToEntityDto(entity);
- }
- /// <summary>
- /// 生成原材料出入库记录
- /// </summary>
- /// <param name="input"></param>
- /// <param name="productOrderNo"></param>
- /// <returns></returns>
- private async Task<CurrentRmStoreHouse> CreateRwStore(ConfirmEnterStoreDto input,string productOrderNo)
- {
-
-
- var current = await CrsRepository.FirstOrDefaultAsync(a => a.Id == input.CurrentRmHouseId);
- if (current == null)
- {
- CheckErrors(IwbIdentityResult.Failed("未查询到库存记录!"));
- return null;
- }
- if (current.Quantity < 0 || (current.Quantity- current.FreezeQuantity - input.TotalQuantity + input.LaveQuantity) < 0)
- {
- CheckErrors(IwbIdentityResult.Failed("库存不足!"));
- return null;
- }
- current.Quantity = current.Quantity - input.TotalQuantity + input.LaveQuantity;
- await CrsRepository.UpdateAsync(current);
- var date = DateTime.Now;
- var oStore = new RmOutStore
- {
- Id = Guid.NewGuid().ToString("N"),
- CurrentRmStoreHouseNo = current.Id,
- IsConfirm= true,
- ProductionOrderNo = productOrderNo,
- ProductBatchNum = current.ProductBatchNum,
- RmProductNo = current.RmProductNo,
- ApplyStatus = RmEnterOutStatusEnum.Stored.ToInt(),
- CreateSourceType = CreateSourceType.Normal.ToInt(),
- StoreHouseId = current.StoreHouseId,
- ActualQuantity = input.TotalQuantity,
- Quantity = input.TotalQuantity,
- ApplyOutDate = date,
- AuditUser = AbpSession.UserName,
- AuditDate = date,
- OutStoreDate = date,
- OutStoreUser = AbpSession.UserName,
- };
- await OrsRepository.InsertAsync(oStore);
- if (input.LaveQuantity > 0)
- {
- var eStore = new RmEnterStore
- {
- Id = Guid.NewGuid().ToString("N"),
- ProductionOrderNo = productOrderNo,
- ProductBatchNum = current.ProductBatchNum,
- RmProductNo = current.RmProductNo,
- ApplyStatus = RmEnterOutStatusEnum.Stored.ToInt(),
- CreateSourceType = CreateSourceType.Normal.ToInt(),
- StoreHouseId = current.StoreHouseId,
- StoreLocationNo = current.StoreLocationNo,
- ApplyQuantity = input.LaveQuantity,
- Quantity = input.LaveQuantity,
- ApplyEnterDate = date,
- AuditUser = AbpSession.UserName,
- AuditDate = date,
- EnterStoreDate = date,
- EnterStoreUser = AbpSession.UserName,
- };
- await ErsRepository.InsertAsync(eStore);
- }
- return current;
- }
- [AbpAuthorize(PermissionNames.PagesProductionInfoProductionOrderMgCreate), AuditLog("创建排产单")]
- public override async Task<ProductionOrderDto> Create(ProductionOrderCreateDto input)
- {
- var entity = await Repository.FirstOrDefaultAsync(a => a.ProductionOrderNo == input.ProductionOrderNo);
- if (entity != null)
- {
- CheckErrors(IwbIdentityResult.Failed("排产单号已存在,请稍后再试!"));
- return null;
- }
- var dto = await base.Create(input);
- BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半产品排产",
- $"创建排产单,信息为:[{dto.Obj2String()}]",
- dto.ProductionOrderNo);
- return dto;
- }
- [AbpAuthorize(PermissionNames.PagesProductionInfoProductionOrderMgUpdate), AuditLog("修改排产单")]
- public override async Task<ProductionOrderDto> Update(ProductionOrderUpdateDto input)
- {
- CheckUpdatePermission();
- var entity = await Repository.FirstOrDefaultAsync(a => a.Id == input.Id);
- if (entity.ProductionOrderStatus > ProductionOrderStatusEnum.Producting.ToInt()&& entity.ProductionOrderStatus != ProductionOrderStatusEnum.Audited.ToInt())
- {
- CheckErrors(IwbIdentityResult.Failed("排产单已进行入库,不可进行修改!"));
- }
- MapToEntity(input, entity);
- entity.TimeLastMod = Clock.Now;
- entity.UserIDLastMod = AbpSession.UserId + "";
- entity= await Repository.UpdateAsync(entity);
- BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半产品排产",
- $"修改排产单,信息为:[{entity.Obj2String()}]",
- entity.ProductionOrderNo);
- return MapToEntityDto(entity);
- }
- [AbpAuthorize(PermissionNames.PagesProductionInfoProductionOrderMgDelete), AuditLog("删除排产单")]
- public override async Task Delete(EntityDto<int> input)
- {
- CheckDeletePermission();
- var entity = await Repository.FirstOrDefaultAsync(a => a.Id == input.Id);
- if (entity.ProductionOrderStatus > ProductionOrderStatusEnum.Producting.ToInt()&&entity.ProductionOrderStatus!=ProductionOrderStatusEnum.Audited.ToInt())
- {
- CheckErrors(IwbIdentityResult.Failed("排产单已进行入库,不可进行删除!"));
- }
-
- entity.IsLock = "Y";
- entity=await Repository.UpdateAsync(entity);
- BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半产品排产",
- $"删除排产单,信息为:[{entity.Obj2String()}]",
- entity.ProductionOrderNo);
- }
- /// <summary>
- /// 创建外协排产单
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [AbpAuthorize(PermissionNames.PagesProductionInfoProductionOrderMgCreate), AuditLog("创建外协排产单")]
- public async Task<ProductionOrderDto> CreateOutProductionOrder(CreateOutProductionOrderDto input)
- {
- string sourceProductionOrderNo = input.SourceProductionOrderNo;
- string processType = input.ProcessingType;
- string processTypeNo = input.ProcessingTypeNo;
- string productionOrderNo = GetOutProductionOrderNo(sourceProductionOrderNo, processType, processTypeNo);
- var isExistObj = Repository.FirstOrDefault(i => i.ProductionOrderNo == productionOrderNo);
- if (isExistObj != null)
- {
- throw new UserFriendlyException("该流转单编号已存在!同一批次产品入库分两次外协加工,编号不能重复填写!");
- }
- if (input.IsReplating == 1)
- {
- var outStore = await ProductOutStoreRepository.FirstOrDefaultAsync(a => a.Id == input.OutStoreId);
- outStore.IsClose = true;
- outStore.IsConfirm = true;
- await ProductOutStoreRepository.UpdateAsync(outStore);
- var currentStore = await CurrentProductStoreHouseRepository.FirstOrDefaultAsync(a =>
- a.CurrentProductStoreHouseNo == outStore.CurrentProductStoreHouseNo);
- currentStore.FreezeQuantity -= outStore.Quantity;
- currentStore.Quantity -= outStore.Quantity;
- await CurrentProductStoreHouseRepository.UpdateAsync(currentStore);
- }
- else
- {
- var semiOutStore = await SemiOutStoreRepository.FirstOrDefaultAsync(a => a.Id == input.OutStoreId);
- semiOutStore.IsClose = true;
- await SemiOutStoreRepository.UpdateAsync(semiOutStore);
- }
-
- var semiProduct = await SemiProductRepository.FirstOrDefaultAsync(a => a.Id == input.SemiProductNo);
- ProductionOrderCreateDto objOrderCreateDto = new ProductionOrderCreateDto()
- {
- Material = semiProduct.Material,
- ProductionOrderNo = productionOrderNo,
- ProcessingLevel = "2",
- OutsourcingFactory = input.OutsourcingFactory,
- PlanProduceDate = input.PlanProduceDate,
- Model = semiProduct.Model,
- Quantity = input.Quantity,
- SurfaceColor = semiProduct.SurfaceColor,
- ProductionOrderStatus = ProductionOrderStatusEnum.Start.ToInt(),
- ProcessingType = processType,
- SourceProductionOrderNo = sourceProductionOrderNo,
- SemiProductNo = input.SemiProductNo,
- Rigidity = semiProduct.Rigidity,
- Remark = input.Remark,
- };
- //返镀标识
- if (input.IsReplating == 1)
- {
- objOrderCreateDto.Remark = $"[返镀]{objOrderCreateDto.Remark}";
- }
- var dto = await CreateEntity(objOrderCreateDto);
- BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半产品排产",
- $"创建外协排产单[{dto.Id}],信息为:[{input.Obj2String()}]",
- dto.ProductionOrderNo, dto.SourceProductionOrderNo);
- return dto;
- }
- [AbpAuthorize(PermissionNames.PagesProductionInfoOutProductionOrderMgUpdate), AuditLog("修改外协排产单")]
- public async Task<ProductionOrderDto> UpdateOutProductionOrder(UpdateOutProductionOrderDto input)
- {
- //string productionOrderNo = GetOutProductionOrderNo(input.SourceProductionOrderNo, input.ProcessingType, input.ProcessingTypeNo);
- var entity = Repository.FirstOrDefault(i => i.ProductionOrderNo == input.ProductionOrderNo);
- if (entity == null)
- {
- throw new UserFriendlyException("该流转单编号不存在!");
- }
- //var semiProduct =await SemiProductRepository.FirstOrDefaultAsync(a=>a.Id == input.SemiProductNo);
- entity.Quantity = input.Quantity;
- entity.PlanProduceDate = input.PlanProduceDate;
- entity.TimeLastMod = Clock.Now;
- entity.UserIDLastMod = AbpSession.UserName;
- entity.Remark = input.Remark;
- entity.KgWeight = input.KgWeight??0;
- entity.OutsourcingFactory = input.OutsourcingFactory;
- entity.SemiProductNo = input.SemiProductNo;
- entity = await Repository.UpdateAsync(entity);
- BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半产品排产",
- $"修改外协排产单[{entity.Id}],信息为:[{input.Obj2String()}]",
- entity.ProductionOrderNo, entity.SourceProductionOrderNo);
- return MapToEntityDto(entity);
- }
- [AbpAuthorize(PermissionNames.PagesProductionInfoOutProductionOrderMgDelete), AuditLog("删除外协排产单")]
- public async Task DeleteOutProductionOrder(EntityDto<int> input)
- {
- //string productionOrderNo = GetOutProductionOrderNo(input.SourceProductionOrderNo, input.ProcessingType, input.ProcessingTypeNo);
- var entity = Repository.FirstOrDefault(i => i.Id == input.Id);
- if (entity == null)
- {
- throw new UserFriendlyException("该流转单编号不存在!");
- }
- if (entity.ProductionOrderStatus >= ProductionOrderStatusEnum.Producting.ToInt()&& entity.ProductionOrderStatus!= ProductionOrderStatusEnum.Audited.ToInt())
- {
- CheckErrors(IwbIdentityResult.Failed("排产单已进行入库,不可进行删除!"));
- }
- entity.IsLock = "Y";
- await Repository.UpdateAsync(entity);
- BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半产品排产",
- $"删除外协排产单[{entity.Id}]",
- entity.ProductionOrderNo, entity.SourceProductionOrderNo);
- }
- private string GetOutProductionOrderNo(string sourceProductionOrderNo, string processType,
- string processTypeNo)
- {
- string resultNo = sourceProductionOrderNo.Length > 7
- ? sourceProductionOrderNo
- : sourceProductionOrderNo + "0000";
- if (processType == ProductionOrderProcessTypeEnum.HeatTreatment.ToInt() + "")
- {
- resultNo = resultNo.Substring(0, resultNo.Length - 2) + processTypeNo;
- }
- else if (processType == ProductionOrderProcessTypeEnum.SurfaceTreatment.ToInt() + "")
- {
- string lastTwoLength = resultNo.Substring(resultNo.Length - 2, 2);
- resultNo = resultNo.Substring(0, resultNo.Length - 4) + processTypeNo + lastTwoLength;
- }
- return resultNo;
- }
- //[AbpAuthorize(PermissionNames.PagesProductionInfoProductionOrderMgUpdate), AuditLog("关联订单明细")]
- public async Task BindOrderItems(BindOrdersDto input)
- {
- string itemIds = input.OrderItemIds;
- string[] items = itemIds.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries);
- foreach (string itemId in items)
- {
- int.TryParse(itemId, out int it);
- var isExist = OrderProductionRepository.FirstOrDefault(i =>
- i.OrderItemId == it && i.ProductionOrderNo == input.ProductionOrderNo);
- if (isExist != null)
- {
- continue;
- }
- await OrderProductionRepository.InsertAsync(new OrderProduction()
- {OrderItemId = it, ProductionOrderNo = input.ProductionOrderNo});
- }
- }
- // [AbpAuthorize(PermissionNames.PagesProductionInfoProductionOrderMgUpdate), AuditLog("关联订单明细")]
- public async Task UnBindOrderItems(BindOrdersDto input)
- {
- string itemIds = input.OrderItemIds;
- string[] items = itemIds.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
- foreach (string itemId in items)
- {
- int.TryParse(itemId, out int it);
- var isExist = OrderProductionRepository.FirstOrDefault(i =>
- i.OrderItemId == it && i.ProductionOrderNo == input.ProductionOrderNo);
- if (isExist != null)
- {
- await OrderProductionRepository.DeleteAsync(i =>
- i.OrderItemId == it && i.ProductionOrderNo == input.ProductionOrderNo);
- }
-
- }
- }
- public List<ViewOrderItems> QueryOrderItemByPoNo(string productionOrderNo)
- {
- var entities = OrderProductionRepository.GetAllList(i => i.ProductionOrderNo == productionOrderNo);
- var its = entities.Select(i => i.OrderItemId);
- var rs = ViewOrderItemsRepository.GetAllList(i => its.Contains(i.Id));
- return rs;
- }
-
- #endregion
- #region 半成品入库
- [AbpAuthorize(PermissionNames.PagesProductionInfoProductionEnterStoreApplyMg), DisableAuditing]
- public PagedResultDto<ViewSemiEnterStore> GetSemiEnterStoreApply(PagedRequestDto input)
- {
- var query = ViewSemiEnterStoreRepository.GetAll();
- if (input.SearchList != null && input.SearchList.Count > 0)
- {
- List<LambdaObject> objList = new List<LambdaObject>();
- foreach (var o in input.SearchList)
- {
- if (o.KeyWords.IsNullOrEmpty())
- continue;
- object keyWords = o.KeyWords;
- //检查查询条件中带有规格且多个分割条件的
- ProductModelSearch.CheckModelGreaterOneFilter(o, ref keyWords);
- objList.Add(new LambdaObject
- {
- FieldType = (LambdaFieldType)o.FieldType,
- FieldName = o.KeyField,
- FieldValue = keyWords,
- ExpType = (LambdaExpType)o.ExpType
- });
- }
- var exp = objList.GetExp<ViewSemiEnterStore>();
- query = query.Where(exp);
- }
- var totalCount = query.Count();
- query = query.OrderByDescending(i => i.TimeCreated);
- string pattern = ProductModelSearch.GetModelGreaterOneReg(input.SearchList);
- List<ViewSemiEnterStore> entities;
- //检查查询条件中带有规格且多个分割条件的
- if (!pattern.IsNullOrEmpty())
- {
- var es = query.ToList();
- es = es.Where(f => f.Model != null && Regex.IsMatch(f.Model, pattern)).ToList();
- totalCount = es.Count;
- entities = es.Skip(input.SkipCount).Take(input.MaxResultCount).ToList();
- }
- else
- {
- query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
- entities = query.ToList();
- }
- //query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
- //var entities = query.ToList();
- var dtos = new PagedResultDto<ViewSemiEnterStore>(
- totalCount, entities
- );
- return dtos;
- }
- /// <summary>
- /// 获取当前排查单申请中数量+成功入库数量(千件数量)
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- private decimal SumEnterStoreQuantity(ProductionOrder input)
- {
- string applyStatus = EnterStoreApplyStatusEnum.Applying.ToInt() + "",
- auditedStatus = EnterStoreApplyStatusEnum.Audited.ToInt() + "",
- enterStoredStatus = EnterStoreApplyStatusEnum.EnterStored.ToInt() + "",
- checkedStatus = EnterStoreApplyStatusEnum.Checked.ToInt() + "";
- var enterLogs = SemiEnterStoreRepository.GetAll().Where(i =>
- i.ProductionOrderNo == input.ProductionOrderNo &&
- (i.ApplyStatus == applyStatus ||
- i.ApplyStatus == auditedStatus ||
- i.ApplyStatus == enterStoredStatus ||
- i.ApplyStatus == checkedStatus));
- decimal result = 0;
- if (enterLogs.Any())
- {
- foreach (var log in enterLogs)
- {
- result += (log.ApplyStatus == enterStoredStatus ? log.ActualQuantity : log.Quantity) / (input.KgWeight <= 0 ? 1 : input.KgWeight);
- }
- }
- return result;
- }
- private bool CheckEnterStoreQuantity(ProductionOrder input,decimal enterQuantity,decimal kw)
- {
- ////已经申请入库数量
- //var hasQuantity = SumEnterStoreQuantity(input);
- ////最多可入库数量上浮百分之20
- //var productQuantity =(double) (input.Quantity * (input.KgWeight <= 0 ? 1 : input.KgWeight)) * 1.2;
- //if ((double)(hasQuantity + enterQuantity) > productQuantity)
- //{
- // return false;
- //}
- //return true;
- //已经申请入库数量
- var hasQuantity = SumEnterStoreQuantity(input);
- //最多可入库数量上浮百分之20
- var productQuantity = (input.MaxQuantity>= input.Quantity)? (double)input.MaxQuantity:(double) (input.Quantity) * 1.2;
- if ((double)(hasQuantity + enterQuantity/ (kw <= 0 ? 1 : kw)) > productQuantity)
- {
- return false;
- }
- return true;
- }
- public async Task<bool> CheckEnterStoreQuantity(CreateEnterStoreApplyDto input)
- {
- var loProductionOrder = await Repository.FirstOrDefaultAsync(a => a.Id == input.Id);
- if (!CheckEnterStoreQuantity(loProductionOrder, input.EnterStoreQuantity, input.KgWeight))
- {
- //CheckErrors(IwbIdentityResult.Failed("申请中数量+成功入库数量, 不能大于等于排产单计划总数量的上限数量!"));
- return false;
- }
- return true;
- }
-
- /// <summary>
- /// 半成品入库申请
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [AbpAuthorize(PermissionNames.PagesProductionInfoProductionOrderMgUpdate), AuditLog("创建入库申请")]
- public async Task<SemiEnterStoreDto> CreateEnterStoreApply(CreateEnterStoreApplyDto input)
- {
- string errMsg = "";
- var loProductionOrder = await Repository.FirstOrDefaultAsync(a => a.Id == input.Id);
- if (!CheckEnterStoreQuantity(loProductionOrder, input.EnterStoreQuantity, input.KgWeight))
- {
- //CheckErrors(IwbIdentityResult.Failed("申请中数量+成功入库数量, 不能大于等于排产单计划总数量的上限数量!"));
- errMsg = "申请中数量+成功入库数量, 已经大于等于排产单计划总数量的上限数量!";
- }
- loProductionOrder.ProductionOrderStatus = ProductionOrderStatusEnum.Storeing.ToInt();
- loProductionOrder.KgWeight = input.KgWeight;
- //loProductionOrder.ProductionOrderStatus = ProductionOrderStatusEnum.Producting.ToInt();
- var applySource = loProductionOrder.ProcessingLevel == "1"
- ? (loProductionOrder.ProductionType == "0"
- ? EnterStoreApplySourceEnum.InnerCar
- : EnterStoreApplySourceEnum.Out)
- : EnterStoreApplySourceEnum.OutProduct;
- SemiEnterStore entity = new SemiEnterStore
- {
- ApplyEnterDate = Clock.Now,
- ApplySource =applySource.ToInt().ToString(),
- ApplyStatus = EnterStoreApplyStatusEnum.Applying.ToInt().ToString(),
- ProductionOrderNo = loProductionOrder.ProductionOrderNo,
- SemiProductNo = loProductionOrder.SemiProductNo,
- Quantity = input.EnterStoreQuantity,
- ActualQuantity = 0,
- AuditDate = Clock.Now,
- AuditUser = AbpSession.UserName,
- TimeCreated = Clock.Now,
- CreatorUserId = AbpSession.UserName,
- TimeLastMod = Clock.Now,
- UserIDLastMod = AbpSession.UserName,
- Remark = input.Remark,
- StoreHouseId = input.StoreHouseId,
- KgWeight = input.KgWeight,
- };
- await SemiEnterStoreRepository.InsertAsync(entity);
- if (loProductionOrder.ProductionType == "0" &&
- input.ProductUser != null && input.ProductUser.Any())
- {
- if (string.IsNullOrEmpty(input.CarNo))
- {
- CheckErrors(IwbIdentityResult.Failed("车号不能为空,请检查后再试。"));
- }
- if (string.IsNullOrEmpty(loProductionOrder.CarNo))
- {
- loProductionOrder.CarNo = input.CarNo;
- }
- else if (input.CarNo!=loProductionOrder.CarNo)
- {
- CheckErrors(IwbIdentityResult.Failed("车号与上一次入库不一致,请检查后再试。"));
- }
- await CreateProductionLog(input, loProductionOrder.ProductionOrderNo);
- }
- await Repository.UpdateAsync(loProductionOrder);
- BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半成品入库",
- $"创建半成品入库申请[{entity.Id}],信息为:[{input.Obj2String()}]",
- entity.ProductionOrderNo);
- var result = ObjectMapper.Map<SemiEnterStoreDto>(entity);
- result.ErrorMsg = errMsg;
- return result;
- }
- private async Task CreateProductionLog(CreateEnterStoreApplyDto input,string productOrderNo)
- {
- int index= await GetLogIndex(productOrderNo);
- decimal q1 = Math.Round(input.EnterStoreQuantity / input.ProductUser.Count,2),
- q2 = Math.Round(input.EnterStoreQuantity2 / input.ProductUser.Count,2);
- foreach (var user in input.ProductUser)
- {
- index++;
- string logNo = $"{productOrderNo}-{index}";
- var log = new ProductionLog()
- {
- ProductionNo = logNo,
- ProductOrderNo = productOrderNo,
- QuantityWeight = q1,
- QuantityPcs = q2,
- KgWeight = input.KgWeight,
- CarNo = input.CarNo,
- EmployeeId = user,
- };
- await ProductLogRepository.InsertAsync(log);
- var p = new EmployeeWorkPerformance()
- {
- PerformanceNo =await WorkTypeDefinition.GetPerformanceNo(PerformanceRepository, WorkTypeDefinition.Product),
- ProductOrderNo = productOrderNo,
- RelatedNo = logNo,
- EmployeeId = user,
- WorkType = WorkTypeDefinition.Product,
- Performance = q2,
- PerformanceUnit = "千件",
- PerformanceDesc =
- $"{q2}千件,总重:{q1}kg,千件重:{input.KgWeight}",
- };
- await PerformanceRepository.InsertAsync(p);
- await CurrentUnitOfWork.SaveChangesAsync();
- }
- }
- private async Task<int> GetLogIndex(string productOrderNo)
- {
- var log = await ProductLogRepository.GetAll().Where(a => a.ProductionNo.Contains(productOrderNo + "-")).OrderByDescending(a=>a.CreationTime).FirstOrDefaultAsync();
- if (log==null)
- {
- return 0;
- }
- var no = log.ProductionNo.Substring(log.ProductionNo.IndexOf("-", StringComparison.Ordinal) + 1);
- return Convert.ToInt32(no);
- }
-
- /// <summary>
- /// 确认入库数量(by yue.)
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [AbpAuthorize(PermissionNames.PagesProductionInfoProductionEnterStoreApplyMgConfirm), AuditLog("确认入库申请")]
- public async Task<SemiEnterStoreDto> ConfirmSemiEnterStoreQuantity(EntityDto<int> input)
- {
- var entity = await SemiEnterStoreRepository.FirstOrDefaultAsync(a => a.Id == input.Id);
- if (entity.ApplyStatus == EnterStoreApplyStatusEnum.EnterStored.ToInt() + "")
- {
- CheckErrors(IwbIdentityResult.Failed("已入库不能再操作!"));
- }
- if (entity.ApplyStatus != EnterStoreApplyStatusEnum.Checked.ToInt() + "")
- {
- CheckErrors(IwbIdentityResult.Failed("还未检验,不能入库!"));
- }
-
- entity.ApplyStatus = EnterStoreApplyStatusEnum.EnterStored.ToInt() + "";
- var date = Clock.Now;
- entity.EnterStoreDate = date;
- entity.EnterStoreUser = AbpSession.UserName;
- await SemiEnterStoreRepository.UpdateAsync(entity);
- var currentStore = CurrentSemiStoreHouseRepository.GetAll().FirstOrDefault(i => i.ProductionOrderNo == entity.ProductionOrderNo&& i.StoreHouseId==entity.StoreHouseId&&i.StoreLocationNo==entity.StoreLocationNo);
- if (currentStore != null)
- {
- var isCanUpdate =
- CommonAppService.CheckStoreRecordCanUpdate(currentStore.CurrentSemiStoreHouseNo, 2);
- if (!isCanUpdate)
- CheckErrors(IwbIdentityResult.Failed("该库存处于退货或者正在盘点状态,不可进行出入库更新!"));
- currentStore.ActualQuantity += entity.ActualQuantity;
- currentStore.TimeLastMod = date;
- currentStore.UserIDLastMod = AbpSession.UserName;
- currentStore.KgWeight = entity.KgWeight;
- await CurrentSemiStoreHouseRepository.UpdateAsync(currentStore);
- }
- else
- {
- string lcJson = JsonConvert.SerializeObject(entity);
- currentStore = lcJson.GetModel<CurrentSemiStoreHouse>();
- var isCanUpdate =
- CommonAppService.CheckStoreCanUpdateByLocationNo(currentStore.StoreLocationNo, 2);
- if (!isCanUpdate)
- CheckErrors(IwbIdentityResult.Failed("该库位正在盘点状态,不可进行出入库更新!"));
- currentStore.CurrentSemiStoreHouseNo = Guid.NewGuid().ToString("N");
- currentStore.TimeCreated = date;
- currentStore.UserIDLastMod = AbpSession.UserName;
- currentStore.ActualQuantity = entity.ActualQuantity;
- currentStore.FreezeQuantity = 0;
- await CurrentSemiStoreHouseRepository.InsertAsync(currentStore);
- }
- //取消确认入库自动变更排查单状态
- /*var productionOrder =
- await Repository.FirstOrDefaultAsync(a => a.ProductionOrderNo == entity.ProductionOrderNo);
- if (productionOrder == null)
- {
- CheckErrors(IwbIdentityResult.Failed("未发现排产单!"));
- return null;
- }
- productionOrder.ProductionOrderStatus = ProductionOrderStatusEnum.EnterStore.ToInt();
- await Repository.UpdateAsync(productionOrder);*/
- BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半成品入库",
- $"确认半成品入库数量[{entity.Id}],排产单入库信息:[确认数量:{entity.ActualQuantity},库存:{currentStore.ActualQuantity},冻结:{currentStore.FreezeQuantity}]。",
- entity.ProductionOrderNo);
- return ObjectMapper.Map<SemiEnterStoreDto>(entity);
- }
-
- /// <summary>
- /// 取消入库申请(by yue.)
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [AbpAuthorize(PermissionNames.PagesProductionInfoProductionEnterStoreApplyMgCancel), AuditLog("取消入库申请")]
- public async Task<SemiEnterStoreDto> CancelSemiEnterStoreApplyStatus(EntityDto<int> input)
- {
- var entity = await SemiEnterStoreRepository.FirstOrDefaultAsync(a => a.Id == input.Id);
- if (entity.ApplyStatus == EnterStoreApplyStatusEnum.EnterStored.ToInt() + "")
- {
- CheckErrors(IwbIdentityResult.Failed("已入库不能再操作!"));
- }
- entity.ApplyStatus = EnterStoreApplyStatusEnum.Canceled.ToInt() + "";
- await SemiEnterStoreRepository.UpdateAsync(entity);
-
- BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半成品入库",
- $"取消半成品入库申请[{entity.Id}]",
- entity.ProductionOrderNo);
- return ObjectMapper.Map<SemiEnterStoreDto>(entity);
- }
- /// <summary>
- /// 关闭入库申请 (by yue.)
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [AbpAuthorize(PermissionNames.PagesProductionInfoProductionEnterStoreApplyMgClose), AuditLog("关闭入库申请")]
- public async Task<SemiEnterStoreDto> CloseEnterStoreApply(EntityDto<int> input)
- {
- var entity = await SemiEnterStoreRepository.FirstOrDefaultAsync(a => a.Id == input.Id);
- entity.IsClose = true;
- //var productionOrder =
- // await Repository.FirstOrDefaultAsync(a => a.ProductionOrderNo == entity.ProductionOrderNo);
- //if (productionOrder == null)
- //{
- // CheckErrors(IwbIdentityResult.Failed("未发现排产单!"));
- // return null;
- //}
- //if (productionOrder.ProductionOrderStatus != ProductionOrderStatusEnum.EnterStore.ToInt()&& productionOrder.ProductionOrderStatus != ProductionOrderStatusEnum.End.ToInt())
- //{
- // productionOrder.ProductionOrderStatus = ProductionOrderStatusEnum.Producting.ToInt();
- //}
- //await Repository.UpdateAsync(productionOrder);
-
- BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半成品入库",
- $"关闭半成品入库申请[{entity.Id}]",
- entity.ProductionOrderNo);
- await SemiEnterStoreRepository.UpdateAsync(entity);
- return ObjectMapper.Map<SemiEnterStoreDto>(entity);
- }
- /// <summary>
- /// 恢复入库申请(by yue.)
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [AbpAuthorize(PermissionNames.PagesProductionInfoProductionEnterStoreApplyMgRecovery), AuditLog("恢复入库申请")]
- public async Task<SemiEnterStoreDto> RecoverySemiEnterStoreApplyStatus(EntityDto<int> input)
- {
- var entity = await SemiEnterStoreRepository.FirstOrDefaultAsync(a => a.Id == input.Id);
- if (entity.ApplyStatus == EnterStoreApplyStatusEnum.EnterStored.ToInt() + "")
- {
- CheckErrors(IwbIdentityResult.Failed("已入库不能再操作!"));
- }
- entity.ApplyStatus = EnterStoreApplyStatusEnum.Applying.ToInt() + "";
- await SemiEnterStoreRepository.UpdateAsync(entity);
- BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半成品入库",
- $"恢复半成品入库申请[{entity.Id}]",
- entity.ProductionOrderNo);
- return ObjectMapper.Map<SemiEnterStoreDto>(entity);
- }
-
- [AbpAuthorize(PermissionNames.PagesProductionInfoProductionEnterStoreApplyMgUpdate), AuditLog("修改入库申请")]
- public async Task<SemiEnterStoreDto> UpdateEnterStoreApply(UpdateSemiEnterStoreDto input)
- {
-
- var entity = await SemiEnterStoreRepository.FirstOrDefaultAsync(a => a.Id == input.Id);
- #region 增加入口数量限制检验
- //var productOrder = Repository.FirstOrDefault(i => i.ProductionOrderNo == entity.ProductionOrderNo);
- //if (productOrder != null)
- //{
- // var sumQuantity = SumEnterStoreQuantity(productOrder);
- // sumQuantity = sumQuantity - (entity.Quantity / (entity.KgWeight <= 0 ? 1 : entity.KgWeight)) + (input.Quantity / (input.KgWeight <= 0 ? 1 : input.KgWeight));
- // var maxQuantity = (productOrder.MaxQuantity >= productOrder.Quantity) ? (double)productOrder.MaxQuantity : (double)(productOrder.Quantity) * 1.2;
- // if ((double)sumQuantity > maxQuantity)
- // {
- // CheckErrors(IwbIdentityResult.Failed("申请中数量+成功入库数量, 不能大于等于排产单计划总数量的上限数量!"));
- // }
- //}
- #endregion
- entity.Quantity = input.Quantity;
- entity.KgWeight = input.KgWeight;
- await SemiEnterStoreRepository.UpdateAsync(entity);
- BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半成品入库",
- $"修改半成品入库申请数量[{entity.Id}],数量修改为[{input.Quantity}],千斤重修改为[{input.KgWeight}]",
- entity.ProductionOrderNo);
- return ObjectMapper.Map<SemiEnterStoreDto>(entity);
- }
- #endregion
- #region 半成品出库
- [DisableAuditing,AbpAuthorize(PermissionNames.PagesProductionInfoProductionOutStoreApplyMg)]
- public PagedResultDto<ViewSemiOutStore> GetSemiOutStoreApply(PagedRequestDto input)
- {
- int type = OutStoreApplyTypeEnum.OutAssistant.ToInt();
- var query = ViewSemiOutStoreRepository.GetAll().Where(a => a.ApplyTypes== type);
- if (input.SearchList != null && input.SearchList.Count > 0)
- {
- List<LambdaObject> objList = new List<LambdaObject>();
- foreach (var o in input.SearchList)
- {
- if (o.KeyWords.IsNullOrEmpty())
- continue;
- object keyWords = o.KeyWords;
- //检查查询条件中带有规格且多个分割条件的
- ProductModelSearch.CheckModelGreaterOneFilter(o, ref keyWords);
- objList.Add(new LambdaObject
- {
- FieldType = (LambdaFieldType)o.FieldType,
- FieldName = o.KeyField,
- FieldValue = keyWords,
- ExpType = (LambdaExpType)o.ExpType
- });
-
- }
- var exp = objList.GetExp<ViewSemiOutStore>();
- query = query.Where(exp);
- }
- var totalCount = query.Count();
- query = query.OrderByDescending(i => i.TimeCreated);
- string pattern = ProductModelSearch.GetModelGreaterOneReg(input.SearchList);
- List<ViewSemiOutStore> entities;
- //检查查询条件中带有规格且多个分割条件的
- if (!pattern.IsNullOrEmpty())
- {
- var es = query.ToList();
- es = es.Where(f => f.Model != null && Regex.IsMatch(f.Model, pattern)).ToList();
- totalCount = es.Count;
- entities = es.Skip(input.SkipCount).Take(input.MaxResultCount).ToList();
- }
- else
- {
- query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
- entities = query.ToList();
- }
- //query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
- //var entities = query.ToList();
- var dtos = new PagedResultDto<ViewSemiOutStore>(
- totalCount, entities
- );
- return dtos;
- }
-
- [DisableAuditing,AbpAuthorize(PermissionNames.PagesProductionInfoProductionOutStoreApplyMg)]
- public ViewSemiOutStore GetSemiOutStoreApplyById(int id)
- {
- var outStore = ViewSemiOutStoreRepository.Get(id);
- return outStore;
- }
- /// <summary>
- /// 半成品出库申请
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [AbpAuthorize(PermissionNames.PagesProductionInfoProductionOutStoreApplyMgCreate), AuditLog("创建出库申请")]
- public async Task<SemiOutStoreDto> CreateOutStoreApply(SemiOutStoreCreateDto input)
- {
- var currentStore =
- CurrentSemiStoreHouseRepository.FirstOrDefault(i =>
- i.CurrentSemiStoreHouseNo == input.CurrentSemiStoreHouseNo);
- if (currentStore == null)
- {
- CheckErrors(IwbIdentityResult.Failed("未发现库存!"));
- return null;
- }
- #region 检查是否可出入库
- var isCanUpdate =
- CommonAppService.CheckStoreRecordCanUpdate(currentStore.CurrentSemiStoreHouseNo, 2);
- if (!isCanUpdate)
- CheckErrors(IwbIdentityResult.Failed("该库存处于退货或者正在盘点状态,不可进行出入库更新!"));
- #endregion
- var canUseQuantit = currentStore.ActualQuantity - currentStore.FreezeQuantity;
- if (canUseQuantit < input.Quantity)
- {
- CheckErrors(IwbIdentityResult.Failed("可用库存量不够,请检查出库数量!"));
- return null;
- }
- currentStore.ActualQuantity -= input.Quantity;
- await CurrentSemiStoreHouseRepository.UpdateAsync(currentStore);
- input.ApplyOutDate = Clock.Now;
- var entity = ObjectMapper.Map<SemiOutStore>(input);
- entity.ApplyOutStoreSource = OutStoreApplyTypeEnum.OutAssistant.ToInt() + "";
- entity.ApplyTypes = OutStoreApplyTypeEnum.OutAssistant.ToInt();
- entity.ApplyStatus = OutStoreApplyStatusEnum.OutStored.ToInt() + "";
- entity.IsConfirm = true;
- entity.AuditDate = Clock.Now;
- entity.AuditUser = AbpSession.UserName;
- entity.ActualQuantity = input.Quantity;
- entity.TimeCreated = Clock.Now;
- entity.CreatorUserId = AbpSession.UserName;
- entity.TimeLastMod = Clock.Now;
- entity.UserIDLastMod = AbpSession.UserName;
- int id = await SemiOutStoreRepository.InsertAndGetIdAsync(entity);
- BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半成品出库",
- $"创建出库申请(外协加工)[{entity.Id}],信息为:[{entity.Obj2String()}]",
- entity.ProductionOrderNo);
- var dto=ObjectMapper.Map<SemiOutStoreDto>(entity);
- dto.Id = id;
- return dto;
- }
-
- ///// <summary>
- ///// 半成品出库申请
- ///// </summary>
- ///// <param name="input"></param>
- ///// <returns></returns>
- //[AbpAuthorize(PermissionNames.PagesProductionInfoProductionOutStoreApplyMgCreate), AuditLog("创建出库申请")]
- //public async Task<SemiOutStoreDto> CreateOutStoreApply(SemiOutStoreCreateDto input)
- //{
- // var currentStore =
- // CurrentSemiStoreHouseRepository.FirstOrDefault(i =>
- // i.CurrentSemiStoreHouseNo == input.CurrentSemiStoreHouseNo);
- // if (currentStore == null)
- // {
- // CheckErrors(IwbIdentityResult.Failed("未发现库存!"));
- // return null;
- // }
- // var canUseQuantit = currentStore.ActualQuantity - currentStore.FreezeQuantity;
- // if (canUseQuantit < input.Quantity)
- // {
- // CheckErrors(IwbIdentityResult.Failed("可用库存量不够,请检查出库数量!"));
- // return null;
- // }
- // currentStore.FreezeQuantity += input.Quantity;
- // await CurrentSemiStoreHouseRepository.UpdateAsync(currentStore);
- // input.ApplyOutDate = Clock.Now;
- // var entity = ObjectMapper.Map<SemiOutStore>(input);
- // entity.ApplyOutStoreSource = OutStoreApplyTypeEnum.OutAssistant.ToInt() + "";
- // entity.ApplyTypes = OutStoreApplyTypeEnum.OutAssistant.ToInt();
- // entity.IsConfirm = false;
- // entity.AuditDate = Clock.Now;
- // entity.AuditUser = AbpSession.UserName;
- // entity.ActualQuantity = 0;
- // entity.TimeCreated = Clock.Now;
- // entity.CreatorUserId = AbpSession.UserName;
- // entity.TimeLastMod = Clock.Now;
- // entity.UserIDLastMod = AbpSession.UserName;
- // entity = await SemiOutStoreRepository.InsertAsync(entity);
- // BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半成品出库",
- // $"创建出库申请(外协加工)[{entity.Id}],信息为:[{entity.Obj2String()}]",
- // entity.ProductionOrderNo);
- // return ObjectMapper.Map<SemiOutStoreDto>(entity);
- //}
-
- [AbpAuthorize(PermissionNames.PagesProductionInfoProductionOutStoreApplyMgUpdate), AuditLog("修改出库申请")]
- public async Task<SemiOutStoreDto> UpdateOutStoreApply(SemiOutStoreUpdateDto input)
- {
- var entity = await SemiOutStoreRepository.FirstOrDefaultAsync(a => a.Id == input.Id);
- if (entity.ApplyStatus == OutStoreApplyStatusEnum.Audited + ""|| entity.ApplyStatus == OutStoreApplyStatusEnum.OutStored + "")
- {
- CheckErrors(IwbIdentityResult.Failed("出库申请已处理,不可操作!"));
- return null;
- }
- var currentStore =
- CurrentSemiStoreHouseRepository.FirstOrDefault(i =>
- i.CurrentSemiStoreHouseNo == input.CurrentSemiStoreHouseNo);
- if (currentStore == null)
- {
- CheckErrors(IwbIdentityResult.Failed("未发现库存!"));
- return null;
- }
- if (entity.ApplyStatus == OutStoreApplyStatusEnum.Applying.ToInt()+"")
- {
- var canUseQuantit = currentStore.ActualQuantity + entity.Quantity - currentStore.FreezeQuantity;
- if (canUseQuantit < input.Quantity)
- {
- CheckErrors(IwbIdentityResult.Failed("可用库存量不够,请检查出库数量!"));
- return null;
- }
- currentStore.FreezeQuantity -= entity.Quantity;
- currentStore.FreezeQuantity += input.Quantity;
- await CurrentSemiStoreHouseRepository.UpdateAsync(currentStore);
- entity.Quantity = input.Quantity;
- }
- entity.TimeLastMod = Clock.Now;
- entity.UserIDLastMod = AbpSession.UserName;
- entity.Remark = input.Remark;
- await SemiOutStoreRepository.UpdateAsync(entity);
- BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半成品出库",
- $"修改半成品出库申请数量[{entity.Id}],[数量修改为{input.Quantity},冻结数量:{currentStore.FreezeQuantity},库存数量:{currentStore.ActualQuantity}]",
- entity.ProductionOrderNo);
- return ObjectMapper.Map<SemiOutStoreDto>(entity);
- }
- /// <summary>
- /// 确认出库数量(by yue.)
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [AbpAuthorize(PermissionNames.PagesProductionInfoProductionEnterStoreApplyMgConfirm), AuditLog("确认出库申请")]
- public async Task<SemiOutStoreDto> ConfirmSemiOutStoreQuantity(EntityDto<int> input)
- {
- var entity =await SemiOutStoreRepository.FirstOrDefaultAsync(a => a.Id == input.Id);
- #region 检查是否可出入库
- var isCanUpdate =
- CommonAppService.CheckStoreRecordCanUpdate(entity.CurrentSemiStoreHouseNo, 2);
- if (!isCanUpdate)
- CheckErrors(IwbIdentityResult.Failed("该库存处于退货或者正在盘点状态,不可进行出入库更新!"));
- #endregion
- if (entity.ApplyStatus == OutStoreApplyStatusEnum.OutStored.ToInt() + "")
- {
- CheckErrors(IwbIdentityResult.Failed("已出库不能再操作!"));
- }
- entity.ApplyStatus = OutStoreApplyStatusEnum.OutStored.ToInt() + "";
- entity.IsConfirm = true;
- var date = Clock.Now;
- entity.OutStoreDate = date;
- entity.OutStoreUser = AbpSession.UserName;
- await SemiOutStoreRepository.UpdateAsync(entity);
- var currentStore = await
- CurrentSemiStoreHouseRepository.FirstOrDefaultAsync(i =>
- i.CurrentSemiStoreHouseNo == entity.CurrentSemiStoreHouseNo);
- if (currentStore == null)
- {
- CheckErrors(IwbIdentityResult.Failed("未发现库存!"));
- return null;
- }
- currentStore.FreezeQuantity -= entity.ActualQuantity;
- currentStore.ActualQuantity -= entity.ActualQuantity;
- await CurrentSemiStoreHouseRepository.UpdateAsync(currentStore);
- BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半成品出库",
- $"确认半成品出库数量[{entity.Id}],[出库数量:{entity.ActualQuantity},冻结数量:{currentStore.FreezeQuantity},库存数量:{currentStore.ActualQuantity}]",
- entity.ProductionOrderNo);
- return ObjectMapper.Map<SemiOutStoreDto>(entity);
- }
- /// <summary>
- /// 取消出库申请(by yue.)
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [AbpAuthorize(PermissionNames.PagesProductionInfoProductionOutStoreApplyMgCancel), AuditLog("取消出库申请")]
- public async Task<SemiOutStoreDto> CancelSemiOutStoreApplyStatus(EntityDto<int> input)
- {
- var entity = await SemiOutStoreRepository.FirstOrDefaultAsync(a => a.Id == input.Id);
- var currentStore =
- CurrentSemiStoreHouseRepository.FirstOrDefault(i =>
- i.CurrentSemiStoreHouseNo == entity.CurrentSemiStoreHouseNo);
- if (currentStore == null)
- {
- CheckErrors(IwbIdentityResult.Failed("未发现库存!"));
- return null;
- }
- currentStore.FreezeQuantity -= entity.Quantity;
- await CurrentSemiStoreHouseRepository.UpdateAsync(currentStore);
- entity.ApplyStatus = OutStoreApplyStatusEnum.Canceled.ToInt() + "";
- await SemiOutStoreRepository.UpdateAsync(entity);
-
- BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半成品出库",
- $"取消半成品出库申请[{entity.Id}]",
- entity.ProductionOrderNo);
- return ObjectMapper.Map<SemiOutStoreDto>(entity);
- }
- /// <summary>
- /// 关闭出库申请 (by yue.)
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [AbpAuthorize(PermissionNames.PagesProductionInfoProductionOutStoreApplyMgClose), AuditLog("关闭出库申请")]
- public async Task<SemiOutStoreDto> CloseOutStoreApply(EntityDto<int> input)
- {
- var entity = await SemiOutStoreRepository.FirstOrDefaultAsync(a => a.Id == input.Id);
- entity.IsClose = true;
- await SemiOutStoreRepository.UpdateAsync(entity);
- BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半成品出库",
- $"关闭半成品出库申请[{entity.Id}]",
- entity.ProductionOrderNo);
- return ObjectMapper.Map<SemiOutStoreDto>(entity);
- }
- /// <summary>
- /// 恢复出库申请(by yue.)
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [AbpAuthorize(PermissionNames.PagesProductionInfoProductionOutStoreApplyMgRecovery),AuditLog("恢复出库申请")]
- public async Task<SemiOutStoreDto> RecoverySemiOutStoreApplyStatus(EntityDto<int> input)
- {
- var entity = await SemiOutStoreRepository.FirstOrDefaultAsync(a => a.Id == input.Id);
- var currentStore =
- CurrentSemiStoreHouseRepository.FirstOrDefault(i =>
- i.CurrentSemiStoreHouseNo == entity.CurrentSemiStoreHouseNo);
- if (currentStore == null)
- {
- CheckErrors(IwbIdentityResult.Failed("未发现库存!"));
- return null;
- }
- if (currentStore.ActualQuantity- currentStore.FreezeQuantity < entity.Quantity)
- {
- CheckErrors(IwbIdentityResult.Failed("可用库存量不够,请检查出库数量!"));
- return null;
- }
- currentStore.FreezeQuantity += entity.Quantity;
- await CurrentSemiStoreHouseRepository.UpdateAsync(currentStore);
- entity.ApplyStatus = OutStoreApplyStatusEnum.Applying.ToInt() + "";
- await SemiOutStoreRepository.UpdateAsync(entity);
-
- BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半成品出库",
- $"恢复半成品出库申请[{entity.Id}]",
- entity.ProductionOrderNo);
- return ObjectMapper.Map<SemiOutStoreDto>(entity);
- }
- #endregion
- #region 成品改镀
- [DisableAuditing, AbpAuthorize(PermissionNames.PagesProductionInfoRePlatingOutStoreApplyMg)]
- public PagedResultDto<ViewProductOutStore> GetRePlatingOutStoreApply(PagedRequestDto input)
- {
- int type = OutStoreApplyTypeEnum.RePlating.ToInt();
- var query = ViewProductOutStoreRepository.GetAll().Where(a => a.ApplyOutStoreSourceType == type);
- if (input.SearchList != null && input.SearchList.Count > 0)
- {
- List<LambdaObject> objList = new List<LambdaObject>();
- foreach (var o in input.SearchList)
- {
- if (o.KeyWords.IsNullOrEmpty())
- continue;
- object keyWords = o.KeyWords;
- //检查查询条件中带有规格且多个分割条件的
- ProductModelSearch.CheckModelGreaterOneFilter(o, ref keyWords);
- objList.Add(new LambdaObject
- {
- FieldType = (LambdaFieldType)o.FieldType,
- FieldName = o.KeyField,
- FieldValue = keyWords,
- ExpType = (LambdaExpType)o.ExpType
- });
- }
- var exp = objList.GetExp<ViewProductOutStore>();
- query = query.Where(exp);
- }
- var totalCount = query.Count();
- query = query.OrderByDescending(i => i.TimeCreated);
- string pattern = ProductModelSearch.GetModelGreaterOneReg(input.SearchList);
- List<ViewProductOutStore> entities;
- //检查查询条件中带有规格且多个分割条件的
- if (!pattern.IsNullOrEmpty())
- {
- var es = query.ToList();
- es = es.Where(f => f.Model != null && Regex.IsMatch(f.Model, pattern)).ToList();
- totalCount = es.Count;
- entities = es.Skip(input.SkipCount).Take(input.MaxResultCount).ToList();
- }
- else
- {
- query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
- entities = query.ToList();
- }
- //query = query.Skip(input.SkipCount).Take(input.MaxResultCount);
- //var entities = query.ToList();
- var dtos = new PagedResultDto<ViewProductOutStore>(
- totalCount, entities
- );
- return dtos;
- }
- [AbpAuthorize(PermissionNames.PagesProductionInfoRePlatingOutStoreApplyMgCancel), AuditLog("拒绝成品改镀出库申请")]
- public async Task<ProductOutStoreDto> CancelFinishOutStoreApply(EntityDto<int> input)
- {
- var entity = await ProductOutStoreRepository.FirstOrDefaultAsync(a => a.Id == input.Id);
- entity.IsClose = true;
- entity.ApplyStatus = OutStoreApplyStatusEnum.Refused.ToInt();
- await ProductOutStoreRepository.UpdateAsync(entity);
- var currentStore = await CurrentProductStoreHouseRepository.FirstOrDefaultAsync(a =>
- a.CurrentProductStoreHouseNo == entity.CurrentProductStoreHouseNo);
- currentStore.FreezeQuantity -= entity.Quantity;//释放冻结
- await CurrentProductStoreHouseRepository.UpdateAsync(currentStore);
- BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "成品出库",
- $"关闭成品出库申请[{entity.Id}]",
- entity.ProductionOrderNo);
- return ObjectMapper.Map<ProductOutStoreDto>(entity);
- }
- [AbpAuthorize(PermissionNames.PagesProductionInfoRePlatingOutStoreApplyMgExport), AuditLog("导出改镀出库申请")]
- public async Task<string> RePlatingExportApply(EntityDto<int> input)
- {
- var entity = await ProductOutStoreRepository.FirstOrDefaultAsync(a => a.Id == input.Id);
-
- if (entity == null)
- {
- CheckErrors(IwbIdentityResult.Failed("未查询到排产单信息。"));
- return null;
- }
- var productEntity = ProductRepository.Get(entity.ProductNo);
- string path = AppDomain.CurrentDomain.BaseDirectory + "Resources/ProductionOrderTemplate/RePlatingBillTemplate.xls";
- var work = ExcelHelper.CreateWorkBook03(path);
-
- var sheet1 = work.GetSheet("Sheet1");
- sheet1.GenerateCell(3, 5).SetCellValue(entity.ProductionOrderNo);
- sheet1.GenerateCell(4, 2).SetCellValue($"{productEntity.PartNo}");
- sheet1.GenerateCell(4, 5).SetCellValue(productEntity.ProductName);
- sheet1.GenerateCell(5, 2).SetCellValue(productEntity.Material);
- sheet1.GenerateCell(5, 4).SetCellValue(productEntity.Rigidity);
- sheet1.GenerateCell(5, 6).SetCellValue(productEntity.Model);
- sheet1.GenerateCell(6, 2).SetCellValue(productEntity.SurfaceColor + "");
- sheet1.GenerateCell(9, 1).SetCellValue($"日期:{Clock.Now:yyyy-MM-dd}");
- var savePath = "Download/Excel/ProductionOrder";
- var fileName = $"改镀单[{entity.Id}]-{Clock.Now:yyyyMMddHHmmss}.xls";
- var result = work.SaveWorkBook($"{AppDomain.CurrentDomain.BaseDirectory}{savePath}", fileName);
- if (!result.IsNullOrEmpty())
- {
- CheckErrors(IwbIdentityResult.Failed(result));
- return null;
- }
- return $"{savePath}/{fileName}";
- }
- #endregion
- #region 数据统计
- /// <summary>
- /// 统计排查单不合格入库
- /// </summary>
- /// <param name="productionOrderNo"></param>
- /// <returns></returns>
- public async Task<EnterFailureRateDto> QueryEnterFailureRate(string productionOrderNo)
- {
- EnterFailureRateDto result = new EnterFailureRateDto();
- var es = await SemiEnterStoreRepository.GetAllListAsync(a => a.ProductionOrderNo == productionOrderNo);
- if (es.Any())
- {
- decimal total = es.Sum(i => i.Quantity);
- decimal unCheckedQuantity = es.Where(i=>i.ApplyStatus == EnterStoreApplyStatusEnum.UnChecked.ToInt() + "").Sum(i => i.Quantity);
- result.ApplyTotalEnterQuantity = total;
- result.FailureQuantity = unCheckedQuantity;
- }
- return result;
- }
- /// <summary>
- /// 生产统计
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- public async Task<ProductionReportDto> QueryProductionReport(QueryProductionReportDto input)
- {
- var startDate = input.Year.GetDateByType(input.Month,out var endDate ,out var dateStr);
- //查询指定周期员工生产日志
- var query = ProductLogRepository.GetAllIncluding(a => a.EmployeeInfo)
- .Where(a => a.CreationTime >= startDate && a.CreationTime < endDate).OrderBy(a=>a.CreationTime);
- IQueryable<ProductionReportItem> itemQuery = input.EmployeeId != null
- ?
- //查询指定员工的统计(关联半成品入库视图获取半成品信息)
- query.Where(a => a.EmployeeId == input.EmployeeId)
- .Join(ViewSemiEnterStoreRepository.GetAll(),
- a => a.ProductOrderNo, s => s.ProductionOrderNo, (a, s) => new ProductionReportItem()
- {
- ProductDate = a.CreationTime,
- ProductionOrderNo = a.ProductOrderNo,
- ProductNo = s.SemiProductNo,
- ProductName = s.SemiProductName,
- CarNo = a.CarNo,
- PartNo = s.PartNo,
- Model = s.Model,
- Material = s.Material,
- SurfaceColor = s.SurfaceColor,
- Rigidity = s.Rigidity,
- KgQuantity = a.QuantityWeight,
- PcsQuantity = a.QuantityPcs,
- KgWeight = a.KgWeight,
- EmployeeId = a.EmployeeId,
- EmployeeNo = a.EmployeeInfo.No,
- EmployeeName = a.EmployeeInfo.Name
- }).Distinct()
- :
- // 查询所有员工的统计
- query.Select(a => new ProductionReportItem()
- {
- ProductDate= a.CreationTime,
- ProductionOrderNo = a.ProductOrderNo,
- ProductNo = a.ProductionNo,
- KgQuantity = a.QuantityWeight,
- PcsQuantity = a.QuantityPcs,
- KgWeight = a.KgWeight,
- EmployeeId = a.EmployeeId,
- EmployeeNo = a.EmployeeInfo.No,
- EmployeeName = a.EmployeeInfo.Name
- });
- var items = await itemQuery.ToListAsync();
- var dto = new ProductionReportDto(dateStr, items,input.EmployeeId);
- return dto;
- }
- /// <summary>
- /// 外购统计
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- public async Task<ProductionReportDto> QueryOutsourcingReport(QueryProductionReportDto input)
- {
- var startDate = input.Year.GetDateByType(input.Month,out var endDate ,out var dateStr);
-
- //查询外购的排产单进行统计(不是新建状态的)
- var query = Repository.GetAll().Where(a => a.TimeCreated >= startDate && a.TimeCreated < endDate && a.ProductionType=="1" && a.ProductionOrderStatus!=1).OrderBy(a=>a.TimeCreated);
-
- //联合查询半成品信息
- IQueryable<ProductionReportItem> itemQuery = from a in query
- join sp in SemiProductRepository.GetAll() on a.SemiProductNo equals sp.Id into l
- from s in l.DefaultIfEmpty()
- select new ProductionReportItem()
- {
- ProductDate = a.TimeCreated,
- ProductionOrderNo = a.ProductionOrderNo,
- ProductNo = s.Id,
- ProductName = s.SemiProductName,
- PartNo = s.PartNo,
- Model = s.Model,
- Material = s.Material,
- SurfaceColor = s.SurfaceColor,
- Rigidity = s.Rigidity,
- KgQuantity = a.Quantity * a.KgWeight,
- PcsQuantity = a.Quantity,
- KgWeight = a.KgWeight,
- };
- var items = await itemQuery.ToListAsync();
- var dto = new ProductionReportDto(dateStr, items,0);
- return dto;
- }
- /// <summary>
- /// 导出外购报表
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- public async Task<string> ExportOutsourcingReport(QueryProductionReportDto input)
- {
- var startDate = input.Year.GetDateByType(input.Month,out var endDate ,out var dateStr);
- var dto = await QueryOutsourcingReport(input);
- if (dto.Items == null || !dto.Items.Any())
- {
- CheckErrors(IwbIdentityResult.Failed("未查询采购信息。"));
- return null;
- }
- string path = AppDomain.CurrentDomain.BaseDirectory + "Resources/ProductionOrderTemplate/OutsourcingReport.xls";
- var work = ExcelHelper.CreateWorkBook03(path);
- var sheet1 = work.GetSheet("Sheet1");
- sheet1.GenerateCell(2, 10).SetCellValue(dateStr);
- int index = 4, count = dto.Items.Count;
- sheet1.InsertRows(index, count-1);
- foreach (var item in dto.Items)
- {
- sheet1.GenerateCell(index, 1).SetValue<int>(index - 3);
- sheet1.GenerateCell(index, 2).SetValue(item.ProductionOrderNo);
- sheet1.GenerateCell(index, 3).SetValue(item.ProductName);
- sheet1.GenerateCell(index, 4).SetValue(item.PartNo);
- sheet1.GenerateCell(index, 5).SetValue(item.Model);
- sheet1.GenerateCell(index, 6).SetValue<decimal>(item.PcsQuantity);
- sheet1.GenerateCell(index, 7).SetValue<decimal>(item.KgWeight);
- sheet1.GenerateCell(index, 8).SetValue<decimal>(item.KgQuantity);
- sheet1.GenerateCell(index, 9).SetValue<DateTime>(item.ProductDate);
- sheet1.GenerateCell(index, 10).SetValue(item.Material);
- sheet1.GenerateCell(index, 11).SetValue(item.SurfaceColor);
- index++;
- }
- sheet1.GenerateCell(index, 2).SetValue($"总重量:{dto.KgTotal} kg");
- sheet1.GenerateCell(index, 4).SetValue($"总件数:{dto.PcsTotal} 千件");
- var savePath = "Download/Excel/ProductionOrder/OutsourcingReport";
- var fileName = $"采购统计-{dateStr}-{Clock.Now:yyMMddHHmmss}.xls";
- var result = work?.SaveWorkBook($"{AppDomain.CurrentDomain.BaseDirectory}{savePath}", fileName);
- if (!result.IsNullOrEmpty())
- {
- //CheckErrors(IwbIdentityResult.Failed(result));
- return null;
- }
- return $"/{savePath}/{fileName}";
- }
-
- #endregion
- #region ExcelExport
- [AbpAuthorize(PermissionNames.PagesProductionInfoProductionOrderMgExport), AuditLog("导出排产单Excel")]
- public async Task<string> ExcelExport(ExportDto input)
- {
- var entity = await Repository.FirstOrDefaultAsync(a => a.Id == input.Id);
- if (entity == null)
- {
- CheckErrors(IwbIdentityResult.Failed("未查询到排产单信息。"));
- return null;
- }
- var semi = await SemiProductRepository.FirstOrDefaultAsync(a => a.Id == entity.SemiProductNo);
- if (semi == null)
- {
- CheckErrors(IwbIdentityResult.Failed("未查询到排产单中半成品信息。"));
- return null;
- }
- string path = AppDomain.CurrentDomain.BaseDirectory + "Resources/ProductionOrderTemplate/ProductionOrderTemplate.xls";
- var work = ExcelHelper.CreateWorkBook03(path);
- var sheet1 = work.GetSheet("Template1");
- sheet1.GenerateCell(2, 10).SetCellValue(entity.ProductionOrderNo);
- sheet1.GenerateCell(4, 11).SetCellValue($"{entity.ProductionOrderNo}{Clock.Now:MMdd}");
- sheet1.GenerateCell(5, 4).SetCellValue(semi.PartNo);
- sheet1.GenerateCell(5, 7).SetCellValue(semi.SemiProductName);
- sheet1.GenerateCell(5, 11).SetCellValue(semi.Model);
- sheet1.GenerateCell(6, 4).SetCellValue(semi.Material);
- sheet1.GenerateCell(6, 11).SetCellValue(entity.Quantity + "");
- sheet1.GenerateCell(8, 4).SetCellValue(semi.ProductDesc);
- sheet1.GenerateCell(8, 11).SetCellValue(semi.Rigidity);
- sheet1.GenerateCell(21, 7).SetCellValue(semi.SurfaceColor);
- var sheet2 = work.GetSheet("Template2");
- sheet2.GenerateCell(1, 17).SetCellValue(entity.ProductionOrderNo);
- sheet2.GenerateCell(3, 16).SetCellValue($"{entity.ProductionOrderNo}{Clock.Now:MMdd}");
- sheet2.GenerateCell(4, 3).SetCellValue(semi.PartNo);
- sheet2.GenerateCell(4, 9).SetCellValue(semi.SemiProductName);
- sheet2.GenerateCell(4, 16).SetCellValue(semi.Model);
- sheet2.GenerateCell(5, 3).SetCellValue(semi.Material);
- sheet2.GenerateCell(7, 3).SetCellValue(semi.ProductDesc);
- var sheet3 = work.GetSheet("Template3");
- sheet3.GenerateCell(2, 10).SetCellValue(entity.ProductionOrderNo);
- sheet3.GenerateCell(4, 4).SetCellValue(semi.PartNo);
- sheet3.GenerateCell(4, 11).SetCellValue($"{entity.ProductionOrderNo}{Clock.Now:MMdd}");
- //sheet3.GenerateCell(5, 4).SetCellValue(semi.PartNo);
- sheet3.GenerateCell(5, 7).SetCellValue(semi.SemiProductName);
- sheet3.GenerateCell(5, 11).SetCellValue(semi.Model);
- sheet3.GenerateCell(6, 4).SetCellValue(semi.Material);
- sheet3.GenerateCell(6, 11).SetCellValue(entity.Quantity + "");
- sheet3.GenerateCell(8, 4).SetCellValue(semi.ProductDesc);
- sheet3.GenerateCell(8, 11).SetCellValue(semi.Rigidity);
- var savePath= "Download/Excel/ProductionOrder";
- var fileName = $"排产单[{entity.ProductionOrderNo}]-{Clock.Now:yyyyMMddHHmmss}.xls";
- var result= work.SaveWorkBook($"{AppDomain.CurrentDomain.BaseDirectory}{savePath}", fileName);
- if (!result.IsNullOrEmpty())
- {
- CheckErrors(IwbIdentityResult.Failed(result));
- return null;
- }
- entity.HasExported = true;
- await Repository.UpdateAsync(entity);
- return $"/{savePath}/{fileName}";
- }
- //[AbpAuthorize(PermissionNames.PagesProductionInfoOutProductionOrderMgExportOut), AuditLog("导出外协排产单Excel")]
- //public async Task<string> ExcelExportOut(EntityDto<string> input)
- //{
- // string selectIds = input.Id;
- // var ids = selectIds.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries);
- // if (!ids.Any())
- // {
- // CheckErrors(IwbIdentityResult.Failed("未查询到排产单信息."));
- // return null;
- // }
- // // List<ProductionOrder> sheetProductionOrders = new List<ProductionOrder>();
- // Dictionary<string, List<ProductionOrder>> dicSheet = new Dictionary<string, List<ProductionOrder>>();
- // foreach (var id in ids)
- // {
- // int.TryParse(id, out int enId);
- // var entity = await Repository.FirstOrDefaultAsync(a => a.Id == enId);
- // if (entity == null)
- // {
- // CheckErrors(IwbIdentityResult.Failed("未查询到排产单信息。"));
- // return null;
- // }
- // if (entity.ProcessingLevel == "1" && entity.ProductionOrderStatus == ProductionOrderStatusEnum.Start.ToInt())
- // {
- // CheckErrors(IwbIdentityResult.Failed("存在排产单未确认审核,不可导出!"));
- // return null;
- // }
- // string enKey = entity.OutsourcingFactory + "@@" + entity.ProcessingType;
- // if (dicSheet.ContainsKey(enKey))
- // {
- // dicSheet[enKey].Add(entity);
- // }
- // else
- // {
- // List<ProductionOrder> productionOrders = new List<ProductionOrder>();
- // productionOrders.Add(entity);
- // dicSheet.Add(enKey, productionOrders);
- // }
-
- // entity.HasExported = true;
- // await Repository.UpdateAsync(entity);
- // }
- // string path3 = AppDomain.CurrentDomain.BaseDirectory + "Resources/ProductionOrderTemplate/HotProcess.xls";
- // string path2 = AppDomain.CurrentDomain.BaseDirectory + "Resources/ProductionOrderTemplate/SurfaceColorProcess.xls";
- // //List<string> savePathList = new List<string>();
- // string cSavePath = "Download/Excel/ProductionOrder";
- // string fileDir= "Out" + DateTime.Now.ToString("yyMMddHHmmss") + "-" + new Random().Next(1000);
- // var savePath = "Download/Excel/ProductionOrder/"+ fileDir;
- // foreach (var ds in dicSheet)
- // {
- // string[] ot = ds.Key.Split("@@");
- // string type = ot[1];
- // string outFactoryId = ds.Value[0].OutsourcingFactory;
- // var outFactory = await OutFactoryRepository.FirstOrDefaultAsync(a => a.Id == outFactoryId);
- // HSSFWorkbook work = null;
- // if (type == "2")
- // {
- // work = ExcelHelper.CreateWorkBook03(path2);
-
- // var sheet1 = work.GetSheet("Sheet1");
- // sheet1.GenerateCell(4, 8).SetCellValue("单号:"+DateTime.Now.ToString("yyMMddHHmmss")+new Random().Next(1000));
- // sheet1.GenerateCell(7, 2).SetCellValue(outFactory?.OutFactoryName);
- // sheet1.GenerateCell(7, 9).SetCellValue(outFactory?.Address);
- // sheet1.GenerateCell(8, 2).SetCellValue(outFactory?.Telephone);
- // sheet1.GenerateCell(8, 9).SetCellValue(outFactory?.LinkMan);
- // int index = 1;
- // foreach (var e in ds.Value)
- // {
- // var semi = await SemiProductRepository.FirstOrDefaultAsync(a => a.Id == e.SemiProductNo);
- // sheet1.GenerateCell(10+index, 1).SetCellValue(index);
- // sheet1.GenerateCell(10 + index, 2).SetCellValue(semi?.PartNo);
- // sheet1.GenerateCell(10 + index, 3).SetCellValue(semi?.SemiProductName);
- // sheet1.GenerateCell(10 + index, 4).SetCellValue(semi?.Model);
- // sheet1.GenerateCell(10 + index, 7).SetCellValue(semi?.SurfaceColor);
- // sheet1.GenerateCell(10 + index, 11).SetCellValue(e?.ProductionOrderNo);
- // index++;
- // }
- // }
- // else if (type == "3")
- // {
- // work = ExcelHelper.CreateWorkBook03(path3);
- // var sheet1 = work.GetSheet("Sheet1");
-
- // sheet1.GenerateCell(4, 8).SetCellValue("单号:" + DateTime.Now.ToString("yyMMddHHmmss") + new Random().Next(1000));
- // sheet1.GenerateCell(7, 2).SetCellValue(outFactory?.OutFactoryName);
- // sheet1.GenerateCell(7, 9).SetCellValue(outFactory?.Address);
- // sheet1.GenerateCell(8, 2).SetCellValue(outFactory?.Telephone);
- // sheet1.GenerateCell(8, 9).SetCellValue(outFactory?.LinkMan);
- // int index = 1;
- // foreach (var e in ds.Value)
- // {
- // var semi = await SemiProductRepository.FirstOrDefaultAsync(a => a.Id == e.SemiProductNo);
- // sheet1.GenerateCell(10 + index, 1).SetCellValue(index);
- // sheet1.GenerateCell(10 + index, 2).SetCellValue(semi?.PartNo);
- // sheet1.GenerateCell(10 + index, 3).SetCellValue(semi?.SemiProductName);
- // sheet1.GenerateCell(10 + index, 4).SetCellValue(semi?.Model);
- // sheet1.GenerateCell(10 + index, 6).SetCellValue(semi?.Material);
- // sheet1.GenerateCell(10 + index, 8).SetCellValue(semi?.SurfaceColor);
- // sheet1.GenerateCell(10 + index, 10).SetCellValue(semi?.Rigidity);
- // sheet1.GenerateCell(10 + index, 11).SetCellValue(e?.ProductionOrderNo);
- // index++;
- // }
- // }
- // var fileName = $"外协排产单[{ ds.Value[0].ProductionOrderNo}]-{Clock.Now:HHmmss}.xls";
- // //string lcPath = $"{AppDomain.CurrentDomain.BaseDirectory}{savePath}" + "\\" + fileName;
- // var result = work?.SaveWorkBook($"{AppDomain.CurrentDomain.BaseDirectory}{savePath}", fileName);
- // if (!result.IsNullOrEmpty())
- // {
- // CheckErrors(IwbIdentityResult.Failed(result));
- // return null;
- // }
- // //savePathList.Add(lcPath);
- // }
- // ZipHelper.ZipDirectory($"{AppDomain.CurrentDomain.BaseDirectory}{savePath}", $"{AppDomain.CurrentDomain.BaseDirectory}{cSavePath}/{fileDir}.zip" );
-
- // return $"/{cSavePath}/{fileDir}.zip";
- //}
- [AbpAuthorize(PermissionNames.PagesProductionInfoOutProductionOrderMgExportOut), AuditLog("导出外协排产单Excel")]
- public async Task<string> ExcelExportOut(EntityDto<string> input)
- {
- string selectIds = input.Id;
- var ids = selectIds.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
- if (!ids.Any())
- {
- CheckErrors(IwbIdentityResult.Failed("未查询到排产单信息."));
- return null;
- }
- // List<ProductionOrder> sheetProductionOrders = new List<ProductionOrder>();
- Dictionary<string, List<ProductionOrder>> dicSheet = new Dictionary<string, List<ProductionOrder>>();
- foreach (var id in ids)
- {
- int.TryParse(id, out int enId);
- var entity = await Repository.FirstOrDefaultAsync(a => a.Id == enId);
- if (entity == null)
- {
- CheckErrors(IwbIdentityResult.Failed("未查询到排产单信息。"));
- return null;
- }
- if (entity.ProcessingLevel == "1" && entity.ProductionOrderStatus == ProductionOrderStatusEnum.Start.ToInt())
- {
- CheckErrors(IwbIdentityResult.Failed("存在排产单未确认审核,不可导出!"));
- return null;
- }
- string enKey = entity.OutsourcingFactory + "@@" + entity.ProcessingType;
- if (dicSheet.ContainsKey(enKey))
- {
- dicSheet[enKey].Add(entity);
- }
- else
- {
- List<ProductionOrder> productionOrders = new List<ProductionOrder>();
- productionOrders.Add(entity);
- dicSheet.Add(enKey, productionOrders);
- }
- entity.HasExported = true;
- await Repository.UpdateAsync(entity);
- }
- string path3 = AppDomain.CurrentDomain.BaseDirectory + "Resources/ProductionOrderTemplate/HotProcess_v2.xls";
- string path2 = AppDomain.CurrentDomain.BaseDirectory + "Resources/ProductionOrderTemplate/SurfaceColorProcess_v2.xls";
- //List<string> savePathList = new List<string>();
- string cSavePath = "Download/Excel/ProductionOrder";
- string fileDir = "Out" + DateTime.Now.ToString("yyMMddHHmmss") + "-" + new Random().Next(1000);
- var savePath = "Download/Excel/ProductionOrder/" + fileDir;
- foreach (var ds in dicSheet)
- {
- string[] ot = ds.Key.Split("@@");
- string type = ot[1];
- string outFactoryId = ds.Value[0].OutsourcingFactory;
- var outFactory = await OutFactoryRepository.FirstOrDefaultAsync(a => a.Id == outFactoryId);
- HSSFWorkbook work = null;
- if (type == "2")
- {
- work = ExcelHelper.CreateWorkBook03(path2);
- var sheet1 = work.GetSheet("Sheet1");
- sheet1.GenerateCell(2, 8).SetCellValue("单号:" + DateTime.Now.ToString("yyMMddHHmmss") + new Random().Next(1000));
- sheet1.GenerateCell(5, 2).SetCellValue(outFactory?.OutFactoryName);
- sheet1.GenerateCell(5, 8).SetCellValue(outFactory?.Address);
- sheet1.GenerateCell(6, 2).SetCellValue(outFactory?.Telephone);
- sheet1.GenerateCell(6, 8).SetCellValue(outFactory?.LinkMan);
- sheet1.GenerateCell(7, 1).SetCellValue("开单日期:" + DateTime.Now.ToString("yyyy-MM-dd"));
- int index = 0;
- sheet1.InsertRows(10, ds.Value.Count>1 ? ds.Value.Count-1:0);
- foreach (var e in ds.Value)
- {
- var semi = await SemiProductRepository.FirstOrDefaultAsync(a => a.Id == e.SemiProductNo);
- sheet1.GenerateCell(10 + index, 1).SetCellValue(index+1);
- //sheet1.GenerateCell(10 + index, 2).SetCellValue(semi?.PartNo);
- sheet1.GenerateCell(10 + index, 2).SetCellValue(semi?.SemiProductName);
- sheet1.GenerateCell(10 + index, 3).SetCellValue(semi?.Model);
- sheet1.GenerateCell(10 + index, 4).SetCellValue(semi?.Rigidity);
- sheet1.GenerateCell(10 + index, 5).SetCellValue("人工填写");
- sheet1.MergedRegion(10 + index, 10 + index, 7, 9);
- sheet1.GenerateCell(10 + index, 7).SetCellValue(semi?.SurfaceColor);
- sheet1.GenerateCell(10 + index, 10).SetCellValue("人工填写");
- sheet1.GenerateCell(10 + index, 11).SetCellValue(e?.SemiProductNo);
- sheet1.GenerateCell(10 + index, 12).SetCellValue(e?.ProductionOrderNo);
- index++;
- }
- sheet1.GenerateCell(10 + index, 10).SetCellValue("发货日期:" + DateTime.Now.ToString("yyyy-MM-dd"));
- }
- else if (type == "3")
- {
- work = ExcelHelper.CreateWorkBook03(path3);
- var sheet1 = work.GetSheet("Sheet1");
- sheet1.GenerateCell(2, 5).SetCellValue("单号:" + DateTime.Now.ToString("yyMMddHHmmss") + new Random().Next(1000));
- sheet1.GenerateCell(5, 2).SetCellValue(outFactory?.OutFactoryName);
- sheet1.GenerateCell(5, 6).SetCellValue(outFactory?.Address);
- sheet1.GenerateCell(6, 2).SetCellValue(outFactory?.Telephone);
- sheet1.GenerateCell(6, 6).SetCellValue(outFactory?.LinkMan);
- sheet1.GenerateCell(7, 1).SetCellValue("开单日期/热处理批次号:"+ DateTime.Now.ToString("yyyyMMdd"));
- int index = 0;
- sheet1.InsertRows(10, ds.Value.Count > 1 ? ds.Value.Count - 1 : 0);
- foreach (var e in ds.Value)
- {
- var semi = await SemiProductRepository.FirstOrDefaultAsync(a => a.Id == e.SemiProductNo);
- sheet1.GenerateCell(10 + index, 1).SetCellValue(index+1);
- //sheet1.GenerateCell(10 + index, 2).SetCellValue(semi?.PartNo);
- sheet1.GenerateCell(10 + index, 2).SetCellValue(semi?.SemiProductName);
- sheet1.GenerateCell(10 + index, 3).SetCellValue(semi?.Model);
- sheet1.GenerateCell(10 + index, 5).SetCellValue(semi?.Material);
- sheet1.GenerateCell(10 + index, 7).SetCellValue(semi?.Rigidity);
- sheet1.GenerateCell(10 + index, 8).SetCellValue("芯部要达到");
- sheet1.GenerateCell(10 + index, 9).SetCellValue(e?.ProductionOrderNo);
- index++;
- }
- sheet1.GenerateCell(10 + index, 8).SetCellValue("发货日期:" + DateTime.Now.ToString("yyyy-MM-dd"));
- }
- var fileName = $"外协排产单[{ ds.Value[0].ProductionOrderNo}]-{Clock.Now:HHmmss}.xls";
- //string lcPath = $"{AppDomain.CurrentDomain.BaseDirectory}{savePath}" + "\\" + fileName;
- var result = work?.SaveWorkBook($"{AppDomain.CurrentDomain.BaseDirectory}{savePath}", fileName);
- if (!result.IsNullOrEmpty())
- {
- CheckErrors(IwbIdentityResult.Failed(result));
- return null;
- }
- //savePathList.Add(lcPath);
- }
- ZipHelper.ZipDirectory($"{AppDomain.CurrentDomain.BaseDirectory}{savePath}", $"{AppDomain.CurrentDomain.BaseDirectory}{cSavePath}/{fileDir}.zip");
- return $"/{cSavePath}/{fileDir}.zip";
- }
- #endregion
- }
- }
|