| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301 |
- 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 NPOI.SS.Formula.Functions;
- 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.CompanyInfo.MoldInfo.Dto;
- using ShwasherSys.Order;
- using ShwasherSys.ProductionOrderInfo.Dto.BindMold;
- using ShwasherSys.ProductionOrderInfo.Dto.BindOrder;
- using ShwasherSys.Migrations;
- 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; }
- protected IRepository<Mold> MoldRepository { get; }
- protected IRepository<MoldProductionRecord,long> MoldProductionRecordRepository { get; }
- protected IRepository<DeviceMgPlan> DeviceMgPlanRepository { 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, IRepository<Mold> moldRepository, IRepository<MoldProductionRecord, long> moldProductionRecordRepository, IRepository<DeviceMgPlan> deviceMgPlanRepository) : 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;
- MoldRepository = moldRepository;
- MoldProductionRecordRepository = moldProductionRecordRepository;
- DeviceMgPlanRepository = deviceMgPlanRepository;
- }
- 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,
- MaxQuantity = u.MaxQuantity
- };
- //逻辑删除也同时显示出来
- //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];
- }
- /// <summary>
- /// 工厂生产和外购编码互换
- /// </summary>
- /// <returns></returns>
- private string SwapOrderNo(string preOrderNo)
- {
- string[] source2 = { "G", "H", "W", "J", "K", "L", "M", "N", "T", "P", "Q", "R" };
- string[] source1 = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C" };
- var m = preOrderNo.Substring(2, 1);
- if (string.IsNullOrEmpty(m))
- {
- return "";
- }
- int index1 = Array.IndexOf(source1, m);
- int index2 = Array.IndexOf(source2, m);
- m = index1 > -1 ? source2[index1] : source1[index2];
- preOrderNo = preOrderNo.Substring(0, 2) + m + preOrderNo.Substring(3, 4);
- return preOrderNo;
- }
- [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
- /// <summary>
- /// 变更排产单类型
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- public async Task<ProductionOrderDto> UpdateProductionType(ProductionTypeUpdateDto input)
- {
- var entity =await Repository.GetAsync(input.Id);
- if (entity == null)
- {
- CheckErrors(IdentityResult.Failed("为查询到相应的排产单!"));
- }
- var arrWg = new string[]
- {
- ((int)ProductionOrderTypeEnum.OutFinish).ToString(),
- ((int)ProductionOrderTypeEnum.RemovalProcess).ToString()
- };
- string preProductionType = entity.ProductionType;
- string preProductionOrderNo = entity.ProductionOrderNo;
- //类型一致,不更新
- if (preProductionType == input.ProductionType)
- {
- return ObjectMapper.Map<ProductionOrderDto>(entity);
- }
- //更新单号
- var newNo = SwapOrderNo(entity.ProductionOrderNo);
- //如果类型变更是在外购成品和去料加工之间互换的,编号不做更新
- if (arrWg.Contains(preProductionType) && arrWg.Contains(input.ProductionType))
- {
- newNo = preProductionOrderNo;
- }
- if (newNo.IsNullOrEmpty())
- {
- CheckErrors(IdentityResult.Failed("排产单号更新失败!"));
- }
- entity.ProductionOrderNo = newNo;
- entity.ProductionType = input.ProductionType;
- entity.TimeLastMod = Clock.Now;
- entity.UserIDLastMod = AbpSession.UserId + "";
- entity = await Repository.UpdateAsync(entity);
- BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半产品排产单类型变更",
- $"修改外协排产单[{entity.Id}],信息为:[{entity.Obj2String()}]",
- $"原编号{preProductionOrderNo},原类型{preProductionType}", $"新编号{newNo},新类型{input.ProductionType}");
- return MapToEntityDto(entity);
- }
- #region 绑定模具
- public async Task<ProductionOrderDto> SelectMoldStart(SelectMoldStartDto input)
- {
- var entity = await Repository.FirstOrDefaultAsync(a => a.Id == input.Id);
- entity.ProductionOrderStatus = ProductionOrderStatusEnum.Producting.ToInt();
- if (!string.IsNullOrEmpty(input.DeviceNo))
- {
- await BindMold(input, entity);
- }
- entity = await Repository.UpdateAsync(entity);
- BusinessLogTypeEnum.SStore.WriteLog(LogRepository, "半产品排产",
- $"排产单状态变更为[{(ProductionOrderStatusEnum)entity.ProductionOrderStatus}]",
- entity.ProductionOrderNo);
- return MapToEntityDto(entity);
- }
- //目前模具使用次数只做增加,不做删除减少
- private async Task BindMold(SelectMoldStartDto input,ProductionOrder order)
- {
- var mold =await MoldRepository.FirstOrDefaultAsync(i => i.No == input.DeviceNo);
- if (mold == null)
- CheckErrors(IdentityResult.Failed("模具信息查询失败!"));
- // var moldProductionRecord = await MoldProductionRecordRepository.FirstOrDefaultAsync(i=>i.ProductionOrderNo== order.ProductionOrderNo);
- // if (moldProductionRecord != null)
- // {
- // CheckErrors(IdentityResult.Failed("排产单已经编辑过模具!"));
- // }
- var mgPlan = await DeviceMgPlanRepository.FirstOrDefaultAsync(i=>i.DeviceNo==input.DeviceNo&&i.PlanType==1);
- if (mgPlan != null)
- {
- mgPlan.NumberOfUsers = mgPlan.NumberOfUsers + Convert.ToInt32(order.Quantity * 1000);
- await DeviceMgPlanRepository.UpdateAsync(mgPlan);
- }
- else
- {
- mgPlan = new DeviceMgPlan()
- {
- No = await MaintainTypeDefinition.GetDeviceMgPlanNo(DeviceMgPlanRepository, 1),
- Name = "",
- ExpireDate = DateTime.MaxValue,
- MaintenanceCycle = mold.MaintenanceCycle,
- MaintenanceDate = DateTime.Now,
- PlanType = 1,
- DeviceNo = input.DeviceNo,
- NumberOfUsers = Convert.ToInt32(order.Quantity * 1000)
- };
- await DeviceMgPlanRepository.InsertAsync(mgPlan);
- }
- //await MoldProductionRecordRepository.DeleteAsync(i => i.ProductionOrderNo == order.ProductionOrderNo);
- MoldProductionRecord record = new MoldProductionRecord()
- {
- ProductionOrderNo = input.ProductionOrderNo,
- MoldNo = input.DeviceNo,
- Quantity = Convert.ToInt32(order.Quantity * 1000)
- };
- await MoldProductionRecordRepository.InsertAsync(record);
- }
- public async Task<ProductionOrderDto> SelectMold(SelectMoldStartDto input)
- {
- var entity = await Repository.FirstOrDefaultAsync(a => a.Id == input.Id);
- await BindMold(input, entity);
- return MapToEntityDto(entity);
- }
- public async Task<MoldDto> GetMoldRecord(string productionOrderNo)
- {
- var moldProductionRecords = await MoldProductionRecordRepository.GetAllListAsync(a => a.ProductionOrderNo == productionOrderNo);
- var mrs = moldProductionRecords.OrderByDescending(i=>i.CreationTime);
- var moldProductionRecord = mrs.FirstOrDefault();
- if (moldProductionRecord != null)
- {
- var mold = await MoldRepository.FirstOrDefaultAsync(i => i.No == moldProductionRecord.MoldNo);
- return ObjectMapper.Map<MoldDto>(mold);
- }
- return new MoldDto();
- }
- #endregion
- }
- }
|