| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513 |
- using Aspose.Words;
- using AutoMapper;
- using EyeSoft.Extensions;
- using Microsoft.Extensions.Logging;
- using Newtonsoft.Json;
- using NPOI.SS.Formula.Functions;
- using OASystem.Domain;
- using OASystem.Domain.Dtos.Groups;
- using OASystem.Domain.Entities.Groups;
- using OASystem.Domain.Entities.Resource;
- using OASystem.Domain.ViewModels.Groups;
- using OASystem.Domain.ViewModels.Statistics;
- using Org.BouncyCastle.Asn1.X500;
- using System;
- using System.Diagnostics;
- using System.Drawing;
- using System.Reflection;
- using System.Runtime.Intrinsics.Arm;
- using System.Text.RegularExpressions;
- namespace OASystem.Infrastructure.Repositories.Groups
- {
- /// <summary>
- /// 团组流程总览表仓储
- /// </summary>
- public class ProcessOverviewRepository : BaseRepository<Grp_ProcessOverview, Grp_ProcessOverview>
- {
- private readonly IMapper _mapper;
- private readonly DelegationInfoRepository _groupRep;
- private readonly ILogger<ProcessOverviewRepository> _logger;
- public ProcessOverviewRepository(SqlSugarClient sqlSugar, IMapper mapper, ILogger<ProcessOverviewRepository> logger, DelegationInfoRepository groupRep) : base(sqlSugar)
- {
- _mapper = mapper;
- _groupRep = groupRep;
- _logger = logger;
- }
- #region 团组流程
- /// <summary>
- /// 基础数据初始化-团组流程
- /// </summary>
- /// <param name="groupId"></param>
- /// <param name="currUserId"></param>
- /// <returns></returns>
- public async Task<List<Grp_ProcessOverview>> ProcessDataInitAsync(int groupId, int currUserId, List<string> visaCountries)
- {
- var processs = new List<Grp_ProcessOverview>();
- // 团组验证
- var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(g => g.Id == groupId);
- if (groupInfo == null) return processs;
- // 流程验证
- var existingProcesses = await _sqlSugar.Queryable<Grp_ProcessOverview>()
- .Where(p => p.IsDel == 0 && p.GroupId == groupId)
- .ToListAsync();
- if (existingProcesses.Any()) return processs;
- //基础数据
- var users = await GetUersAsync();
- var custInfo = _sqlSugar.Queryable<Grp_TourClientList>()
- .Where(c => c.DiId == groupId && c.IsDel == 0)
- .OrderByDescending(c => c.CreateTime)
- .First();
- var airTripCodeInfo = _sqlSugar.Queryable<Air_TicketBlackCode>()
- .Where(x => x.IsDel == 0 && x.DiId == groupId)
- .OrderByDescending(x => x.CreateTime)
- .First();
- var backListInfo = _sqlSugar.Queryable<Grp_InvertedList>().Where(x => x.DiId == groupId && x.IsDel == 0).First();
- #region 商邀报批流程
- var oa_proc = GroupProcessType.Invitation;
- var oaNode1 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, oa_proc, 1);
- var oaNode2 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, oa_proc, 2);
- var oaNode3 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, oa_proc, 3);
- var oaNode4 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, oa_proc, 4);
- var oaNode5 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, oa_proc, 5);
- var oaNode6 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, oa_proc, 6);
- var oaNode7 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, oa_proc, 7);
- processs.Add(
- Grp_ProcessOverview.Create(groupId, 1, oa_proc, ProcessStatus.InProgress, currUserId,
- new List<Grp_ProcessNode>()
- {
- Grp_ProcessNode.Create(1, oaNode1.NodeName,oaNode1.NodeTips,ProcessStatus.InProgress, true,false,false,false,currUserId,oaNode1.PromptPerson.Select(x => x.Id).ToList()),
- Grp_ProcessNode.Create(2, oaNode2.NodeName,oaNode2.NodeTips, ProcessStatus.InProgress, false,false,false,false,currUserId,oaNode2.PromptPerson.Select(x => x.Id).ToList()),
- Grp_ProcessNode.Create(3, oaNode3.NodeName,oaNode3.NodeTips,ProcessStatus.InProgress, false,false,false,false, currUserId ,oaNode3.PromptPerson.Select(x => x.Id).ToList()),
- Grp_ProcessNode.Create(4, oaNode4.NodeName,oaNode4.NodeTips,ProcessStatus.InProgress, false,false,false,false, currUserId,oaNode4.PromptPerson.Select(x => x.Id).ToList()),
- Grp_ProcessNode.Create(5, oaNode5.NodeName,oaNode5.NodeTips,ProcessStatus.InProgress, false,false,false,true, currUserId,oaNode5.PromptPerson.Select(x => x.Id).ToList()),
- Grp_ProcessNode.Create(6, oaNode6.NodeName,oaNode6.NodeTips,ProcessStatus.InProgress, false,false,false,true, currUserId,oaNode6.PromptPerson.Select(x => x.Id).ToList()),
- Grp_ProcessNode.Create(7, oaNode7.NodeName,oaNode7.NodeTips,ProcessStatus.InProgress, false,false,true,false, currUserId,oaNode7.PromptPerson.Select(x => x.Id).ToList()),
- }
- ));
- #endregion
- #region 签证流程
- var visa_proc = GroupProcessType.Visa;
- //单独处理签证流程节点
- var visaNodes = new List<Grp_ProcessNode>();
- if (visaCountries != null && visaCountries.Count > 0)
- {
- var visaDefualtNodes = new List<VisaProcessNode>();
- for (int i = 1; i < visaCountries.Count + 1; i++)
- {
- visaDefualtNodes.Add(VisaProcessNode.Info(i, visaCountries[i - 1].ToString()));
- }
- var visaNode1 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, visa_proc, 1);
- var visaNode2 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, visa_proc, 2);
- visaNodes.Add(Grp_ProcessNode.Create(1, visaNode1.NodeName, visaNode1.NodeTips, ProcessStatus.InProgress, true, false, false, false, currUserId, visaNode1.PromptPerson.Select(x => x.Id).ToList(), JsonConvert.SerializeObject(visaDefualtNodes)));
- visaNodes.Add(Grp_ProcessNode.Create(2, visaNode2.NodeName, visaNode2.NodeTips, ProcessStatus.InProgress, false, false, true, false, currUserId, visaNode2.PromptPerson.Select(x => x.Id).ToList()));
- }
- processs.Add(Grp_ProcessOverview.Create(groupId, 2, visa_proc, ProcessStatus.UnStarted, currUserId, visaNodes));
- #endregion
- #region 机票流程
- var air_proc = GroupProcessType.AirTicket;
- var airNode1 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, air_proc, 1);
- var airNode2 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, air_proc, 2);
- var airNode3 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, air_proc, 3);
- var airNode4 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, air_proc, 4);
- var airNode5 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, air_proc, 5);
- var airNode6 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, air_proc, 6);
- var airNode7 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, air_proc, 7);
- var airNode8 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, air_proc, 8);
- processs.Add(
- Grp_ProcessOverview.Create(groupId, 3, air_proc, ProcessStatus.InProgress, currUserId,
- new List<Grp_ProcessNode>()
- {
- Grp_ProcessNode.Create(1, airNode1.NodeName, airNode1.NodeTips, ProcessStatus.InProgress, true,false,false,false, currUserId ,airNode1.PromptPerson.Select(x => x.Id).ToList()),
- Grp_ProcessNode.Create(2, airNode2.NodeName, airNode2.NodeTips, ProcessStatus.InProgress, false,false,false,false,currUserId ,airNode2.PromptPerson.Select(x => x.Id).ToList() ),
- Grp_ProcessNode.Create(3, airNode3.NodeName, airNode3.NodeTips, ProcessStatus.InProgress, false,false,false,false, currUserId ,airNode3.PromptPerson.Select(x => x.Id).ToList()),
- Grp_ProcessNode.Create(4, airNode4.NodeName, airNode4.NodeTips, ProcessStatus.InProgress, false,false,false,false, currUserId ,airNode4.PromptPerson.Select(x => x.Id).ToList()),
- Grp_ProcessNode.Create(5, airNode5.NodeName, airNode5.NodeTips, ProcessStatus.InProgress, false,false,false,false, currUserId ,airNode5.PromptPerson.Select(x => x.Id).ToList()),
- Grp_ProcessNode.Create(6, airNode6.NodeName, airNode6.NodeTips, ProcessStatus.InProgress, false,false,false,false,currUserId ,airNode6.PromptPerson.Select(x => x.Id).ToList()),
- Grp_ProcessNode.Create(7, airNode7.NodeName, airNode7.NodeTips, ProcessStatus.InProgress, false,false,true,false, currUserId ,airNode7.PromptPerson.Select(x => x.Id).ToList()),
- Grp_ProcessNode.Create(8, airNode8.NodeName, airNode8.NodeTips, ProcessStatus.InProgress, false,false,true,false, currUserId ,airNode8.PromptPerson.Select(x => x.Id).ToList())
- }
- )
- );
- #endregion
- #region 酒店流程
- var hotel_proc = GroupProcessType.Hotel;
- var hotelNode1 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, hotel_proc, 1);
- var hotelNode2 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, hotel_proc, 2);
- var hotelNode3 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, hotel_proc, 3);
- var hotelNode4 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, hotel_proc, 4);
- var hotelNode5 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, hotel_proc, 5);
- processs.Add(
- Grp_ProcessOverview.Create(groupId, 4, hotel_proc, ProcessStatus.InProgress, currUserId,
- new List<Grp_ProcessNode>()
- {
- Grp_ProcessNode.Create(1, hotelNode1.NodeName, hotelNode1.NodeTips, ProcessStatus.InProgress, true, false, false, false, currUserId, hotelNode1.PromptPerson.Select(x => x.Id).ToList()),
- Grp_ProcessNode.Create(2, hotelNode2.NodeName, hotelNode2.NodeTips, ProcessStatus.InProgress, false, false, false,false, currUserId, hotelNode2.PromptPerson.Select(x => x.Id).ToList()),
- Grp_ProcessNode.Create(3, hotelNode3.NodeName, hotelNode3.NodeTips, ProcessStatus.InProgress,false, false, false,false, currUserId, hotelNode3.PromptPerson.Select(x => x.Id).ToList()),
- Grp_ProcessNode.Create(4, hotelNode4.NodeName, hotelNode4.NodeTips, ProcessStatus.InProgress, false, false, false,false,currUserId, hotelNode4.PromptPerson.Select(x => x.Id).ToList()),
- Grp_ProcessNode.Create(5, hotelNode5.NodeName, hotelNode5.NodeTips, ProcessStatus.InProgress, false, false, true,false, currUserId, hotelNode5.PromptPerson.Select(x => x.Id).ToList()),
- }
- )
- );
- #endregion
- #region 地接流程
- var op_proc = GroupProcessType.LocalGuide;
- var opNode1 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, op_proc, 1);
- var opNode2 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, op_proc, 2);
- var opNode3 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, op_proc, 3);
- var opNode4 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, op_proc, 4);
- var opNode5 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, op_proc, 5);
- var opNode6 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, op_proc, 6);
- var opNode7 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, op_proc, 7);
- processs.Add(
- Grp_ProcessOverview.Create(groupId, 5, op_proc, ProcessStatus.InProgress, currUserId,
- new List<Grp_ProcessNode>()
- {
- Grp_ProcessNode.Create(1, opNode1.NodeName, opNode1.NodeTips, ProcessStatus.InProgress, true, false, false,false, currUserId, opNode1.PromptPerson.Select(x => x.Id).ToList()),
- Grp_ProcessNode.Create(2, opNode2.NodeName, opNode2.NodeTips, ProcessStatus.InProgress, false, false, false,false, currUserId, opNode2.PromptPerson.Select(x => x.Id).ToList()),
- Grp_ProcessNode.Create(3, opNode3.NodeName, opNode3.NodeTips, ProcessStatus.InProgress, false, false, false, false, currUserId, opNode3.PromptPerson.Select(x => x.Id).ToList()),
- Grp_ProcessNode.Create(4, opNode4.NodeName, opNode4.NodeTips, ProcessStatus.InProgress, false, false, false,false, currUserId, opNode4.PromptPerson.Select(x => x.Id).ToList()),
- Grp_ProcessNode.Create(5, opNode5.NodeName, opNode5.NodeTips, ProcessStatus.InProgress, false, false, false,false, currUserId, opNode5.PromptPerson.Select(x => x.Id).ToList()),
- Grp_ProcessNode.Create(6, opNode6.NodeName, opNode6.NodeTips, ProcessStatus.InProgress, false, false, false,false, currUserId, opNode6.PromptPerson.Select(x => x.Id).ToList()),
- Grp_ProcessNode.Create(7, opNode7.NodeName, opNode7.NodeTips, ProcessStatus.InProgress, false, false, true, false, currUserId, opNode7.PromptPerson.Select(x => x.Id).ToList())
- }
- )
- );
- #endregion
- #region 费用结算流程
- var fee_proc = GroupProcessType.FeeSettle;
- var feeNode1 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, fee_proc, 1);
- var feeNode2 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, fee_proc, 2);
- var feeNode3 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, fee_proc, 3);
- var feeNode4 = GetNodeDetailsByProcAndNode(groupInfo, users, custInfo, airTripCodeInfo, backListInfo, fee_proc, 4);
- processs.Add(
- Grp_ProcessOverview.Create(groupId, 6, fee_proc, ProcessStatus.InProgress, currUserId,
- new List<Grp_ProcessNode>()
- {
- Grp_ProcessNode.Create(1, feeNode1.NodeName, feeNode1.NodeTips, ProcessStatus.InProgress, true, true, false,false,currUserId, feeNode1.PromptPerson.Select(x => x.Id).ToList()),
- Grp_ProcessNode.Create(2, feeNode2.NodeName, feeNode2.NodeTips, ProcessStatus.InProgress, false, false, false,false,currUserId, feeNode2.PromptPerson.Select(x => x.Id).ToList()),
- Grp_ProcessNode.Create(3, feeNode3.NodeName, feeNode3.NodeTips, ProcessStatus.InProgress, false, false, false,false,currUserId, feeNode3.PromptPerson.Select(x => x.Id).ToList()),
- Grp_ProcessNode.Create(4, feeNode4.NodeName, feeNode4.NodeTips, ProcessStatus.InProgress, false, false, false,false, currUserId , feeNode4.PromptPerson.Select(x => x.Id).ToList()),
- }
- )
- );
- #endregion
- return processs;
- }
- /// <summary>
- /// 团组流程初始化
- /// </summary>
- /// <param name="request">创建流程请求参数</param>
- /// <returns>创建的流程信息</returns>
- public async Task<Result> ProcessInitAsync(int groupId, int currUserId)
- {
- //团组验证
- var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(g => g.Id == groupId);
- if (groupInfo == null)
- {
- return new Result { Code = 400, Msg = "团组不存在" };
- }
- // 检查是否已存在流程
- var existingProcesses = await _sqlSugar.Queryable<Grp_ProcessOverview>()
- .Where(p => p.IsDel == 0 && p.GroupId == groupId)
- .ToListAsync();
- if (existingProcesses.Any())
- {
- return new Result { Code = 400, Msg = "该团组的流程已存在" };
- }
- //处理签证国家
- var visaCountries = _groupRep.GroupSplitCountry(groupInfo.VisitCountry);
- // 定义默认的流程节点
- var processs = await ProcessDataInitAsync(groupId, currUserId, visaCountries);
- _sqlSugar.BeginTran();
- foreach (var item in processs)
- {
- var processId = await _sqlSugar.Insertable(item).ExecuteReturnIdentityAsync();
- if (processId < 1)
- {
- _sqlSugar.RollbackTran();
- return new Result { Code = 400, Msg = "团组流程进度总览表添加失败!" };
- }
- item.Id = processId;
- // 记录流程日志
- await LogProcessOpAsync(null, item, "Create", currUserId);
- var nodes = item.Nodes.Select((nodeDto, index) => new Grp_ProcessNode
- {
- ProcessId = processId,
- NodeName = nodeDto.NodeName,
- NodeOrder = nodeDto.NodeOrder,
- OverallStatus = nodeDto.OverallStatus,
- NodeDescTips = nodeDto.NodeDescTips,
- OpUserList = nodeDto.OpUserList,
- //Country = nodeDto.Country,
- IsCurrent = nodeDto.IsCurrent,
- IsAssist = nodeDto.IsAssist,
- IsPart = nodeDto.IsPart,
- IsFileUp = nodeDto.IsFileUp,
- Remark = nodeDto.Remark
- }).ToList();
- var nodeIds = await _sqlSugar.Insertable(nodes).ExecuteCommandAsync();
- if (nodeIds < 1)
- {
- _sqlSugar.RollbackTran();
- return new Result { Code = 400, Msg = "团组流程进度流程节点添加失败!" };
- }
- //设置节点ID
- nodes = await _sqlSugar.Queryable<Grp_ProcessNode>().Where(x => x.IsDel == 0 && x.ProcessId == processId).ToListAsync();
- //记录节点日志
- foreach (var node in nodes)
- {
- await LogNodeOpAsync(null, node, "Create", currUserId);
- }
- }
- _sqlSugar.CommitTran();
- return new Result { Code = 200, Msg = "添加成功!" }; ;
- }
- /// <summary>
- /// 获取团组的所有流程及节点详情
- /// </summary>
- /// <param name="request">创建流程请求参数</param>
- /// <returns>创建的流程信息</returns>
- public async Task<Result> ProcessesDetailsAsync(int groupId)
- {
- //团组验证
- var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(g => g.Id == groupId);
- if (groupInfo == null)
- {
- return new Result { Code = 400, Msg = "团组不存在" };
- }
- // 检查是否已存在流程
- var existingProcesses = await _sqlSugar.Queryable<Grp_ProcessOverview>().Where(p => p.IsDel == 0 && p.GroupId == groupId).ToListAsync();
- if (!existingProcesses.Any())
- {
- //新建团组流程
- var res = await ProcessInitAsync(groupId, 4);
- if (res.Code != 200)
- {
- return res;
- }
- }
- //基础数据
- var opUsers = await GetUersAsync();
- var custInfo = _sqlSugar.Queryable<Grp_TourClientList>()
- .Where(c => c.DiId == groupId && c.IsDel == 0)
- .OrderByDescending(c => c.CreateTime)
- .First();
- var airTripCodeInfo = _sqlSugar.Queryable<Air_TicketBlackCode>()
- .Where(x => x.IsDel == 0 && x.DiId == groupId)
- .OrderByDescending(x => x.CreateTime)
- .First();
- var backListInfo = _sqlSugar.Queryable<Grp_InvertedList>().Where(x => x.DiId == groupId && x.IsDel == 0).First();
- var users = await _sqlSugar.Queryable<Sys_Users>().Select(x => new { x.Id, x.CnName }).ToListAsync();
- var processData = await _sqlSugar.Queryable<Grp_ProcessOverview>()
- .Where(p => p.GroupId == groupId && p.IsDel == 0)
- .Mapper(
- p => p.Nodes,
- p => p.Nodes.First().ProcessId
- )
- .ToListAsync();
- // 预先构建用户字典,提升查询性能
- var userDict = users.ToDictionary(u => u.Id, u => u.CnName);
- var processes = processData.Select(p =>
- {
- var orderedNodes = p.Nodes.Where(x => x.IsDel == 0).OrderBy(n => n.NodeOrder).ToList();
- var totalNodes = orderedNodes.Count;
- return new ProcessDetailsView()
- {
- Id = p.Id,
- GroupId = p.GroupId,
- ProcessType = p.ProcessType,
- ProcessName = p.ProcessType.GetEnumDescription(),
- Nodes = orderedNodes.Select((n, index) =>
- {
- var isLastNode = index == totalNodes - 1;
- var isSecondLastNode = index == totalNodes - 2;
- var isFifthStep = index == 4;
- // 计算按钮状态
- bool isEnaAssistBtn = p.ProcessType == GroupProcessType.FeeSettle && n.NodeOrder == 1;
- // 文件上传按钮启用规则
- bool isEnaFileUpBtn = false;
- // 是否参与按钮启用
- bool isEnaPartBtn = false;
- // 规则1:商邀流程第五步启用参与按钮
- if (p.ProcessType == GroupProcessType.Invitation && isFifthStep)
- {
- isEnaPartBtn = true;
- }
- // 规则2:机票流程倒数第二步启用上传按钮
- else if (p.ProcessType == GroupProcessType.AirTicket && isSecondLastNode)
- {
- isEnaFileUpBtn = true;
- }
- // 规则3:默认流程节点最后一步启用上传按钮
- else if (isLastNode && p.ProcessType != GroupProcessType.FeeSettle)
- {
- isEnaFileUpBtn = true;
- }
- // 处理签证子节点
- List<VisaProcessNode> visaSubNodes = new();
- if (p.ProcessType == GroupProcessType.Visa && n.NodeOrder == 1)
- {
- visaSubNodes = JsonConvert.DeserializeObject<List<VisaProcessNode>>(n.Remark ?? "[]")
- ?? new List<VisaProcessNode>();
- }
- // 获取操作人姓名
- string operatorName = "-";
- if (n.Operator.HasValue && userDict.TryGetValue(n.Operator.Value, out var name))
- {
- operatorName = name;
- }
- string nodeTipsMsg = GetNodeDetailsByProcAndNode(groupInfo, opUsers, custInfo, airTripCodeInfo, backListInfo, p.ProcessType, n.NodeOrder)?.NodeTips;
- return new ProcessNodeDetailsView()
- {
- Id = n.Id,
- ProcessId = n.ProcessId,
- NodeOrder = n.NodeOrder,
- NodeName = n.NodeName,
- OverallStatus = n.OverallStatus,
- StatusText = n.OverallStatus.GetEnumDescription(),
- Operator = operatorName,
- OpeateTime = n.OperationTime?.ToString("yyyy-MM-dd HH:mm:ss") ?? "-",
- ActualDone = n.ActualDone?.ToString("yyyy-MM-dd HH:mm:ss") ?? "",
- OpUserList = n.OpUserList, //可操作用户列表
- NodeDescTips = nodeTipsMsg,
- IsEnaAssistBtn = isEnaAssistBtn, // 是否启用财务流程首节点协助按钮
- IsAssist = n.IsAssist, // 财务流程首节点 存储值
- IsEnaFileUpBtn = isEnaFileUpBtn, // 是否启用上传文件按钮
- IsFileUp = n.IsFileUp, // 上传文件节点 存储值
- IsEnaPartBtn = isEnaPartBtn, // 是否启用参与按钮
- IsPart = n.IsPart, // 参与按钮 存储值
- VisaSubNodes = visaSubNodes, // 签证节点类型使用
- Remark = n.Remark
- };
- }).ToList()
- };
- }).ToList();
- return new Result { Code = 200, Data = processes, Msg = "查询成功!" };
- }
- /// <summary>
- /// 指定日期增加工作日
- /// </summary>
- /// <param name="startDate"></param>
- /// <param name="days"></param>
- /// <returns></returns>
- private static DateTime AddWeekdays(DateTime startDate, int days)
- {
- DateTime currentDate = startDate;
- if (days >= 0)
- {
- while (days > 0)
- {
- currentDate = currentDate.AddDays(1);
- DayOfWeek day = currentDate.DayOfWeek;
- if (day != DayOfWeek.Saturday && day != DayOfWeek.Sunday)
- {
- days--;
- }
- }
- }
- else
- {
- days = Math.Abs(days);
- while (days > 0)
- {
- currentDate = currentDate.AddDays(-1);
- DayOfWeek day = currentDate.DayOfWeek;
- if (day != DayOfWeek.Saturday && day != DayOfWeek.Sunday)
- {
- days--;
- }
- }
- }
- return currentDate;
- }
- /// <summary>
- /// 团组流程单节点详情
- /// </summary>
- /// <param name="groupInfo"></param>
- /// <param name="users"></param>
- /// <param name="custInfo"></param>
- /// <param name="airTripCodeInfo"></param>
- /// <param name="backListInfo"></param>
- /// <returns></returns>
- public static GroupProcFullNodeDetails GetNodeDetailsByProcAndNode(
- Grp_DelegationInfo groupInfo,
- List<NodeOpUserInfo> users,
- Grp_TourClientList custInfo,
- Air_TicketBlackCode airTripCodeInfo,
- Grp_InvertedList backListInfo,
- GroupProcessType procType,
- int nodeOrder
- )
- {
- return GetNodeDetails(
- groupInfo,
- users,
- custInfo,
- airTripCodeInfo,
- backListInfo
- ).FirstOrDefault(x => x.ProcType == procType && x.NodeOrder == nodeOrder);
- }
- /// <summary>
- /// 团组流程节点详情计算
- /// </summary>
- /// <param name="groupInfo"></param>
- /// <param name="users"></param>
- /// <param name="custInfo"></param>
- /// <param name="airTripCodeInfo"></param>
- /// <param name="backListInfo"></param>
- /// <returns></returns>
- public static List<GroupProcFullNodeDetails> GetNodeDetails(
- Grp_DelegationInfo groupInfo,
- List<NodeOpUserInfo> users,
- Grp_TourClientList custInfo,
- Air_TicketBlackCode airTripCodeInfo,
- Grp_InvertedList backListInfo
- )
- {
- var nodeDetails = new List<GroupProcFullNodeDetails>();
- int groupId = groupInfo.Id;
- string groupName = groupInfo.TeamName;
- groupInfo.VisitDate = groupInfo.VisitDate.AddDays(1); //第二天开始计算
- #region 商邀
- var oa_proc = GroupProcessType.Invitation;
- //用户可操作权限
- var oa_users = NodeOpUserTpl(users)[oa_proc];
- //1. 完成基础请示、报批日程初稿”,4个工作日(仍需根据客户意见和联系情况及时修改补充所需其他材料,例如印证文件、成果表等,直至终稿)
- DateTime? xy_timeBase1 = null;
- if (groupInfo.Step == 1 || groupInfo.Step == 2)
- {
- if (groupInfo.StepOperationTime.HasValue) xy_timeBase1 = groupInfo.StepOperationTime.Value;
- }
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, oa_proc, 1, xy_timeBase1, 4, true, oa_users)
- );
- //2. 7个工作日,所有报批机构前部联系,邀请机构一个国家不少于4家进行重点对接(4家机构中,其中3家机构需有效对接,其中1家可为付费机构备选))
- DateTime? xy_timeBase2 = groupInfo.VisitDate;
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, oa_proc, 2, xy_timeBase2, 7, true, oa_users)
- );
- //3. 10个工作日,根据最新情况,联系公务机构1/3取得回应;邀请机构基本明确。
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, oa_proc, 3, null, 0, true, oa_users)
- );
- //4. 正式名单下放后2周内(含非工作日)。如团组前期准备时间已经较长,则按客户要求尽快提供。 加急团组备注特殊情况。
- DateTime? xy_timeBase4 = null;
- if (custInfo != null) xy_timeBase4 = custInfo.CreateTime;
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, oa_proc, 4, xy_timeBase4, 14, false, oa_users)
- );
- //5. 团组出发前,5个工作日完成所有公务确认工作。
- DateTime? xy_timeBase5 = groupInfo.VisitDate.AddDays(-1); //时间倒推,调整回原始出发日期
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, oa_proc, 5, xy_timeBase5, -5, true, oa_users)
- );
- //6.
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, oa_proc, 6, null, 0, true, oa_users)
- );
- //7. 如果需要上传请在团组结束前完成
- DateTime? xy_timeBase7 = groupInfo.VisitEndDate;
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, oa_proc, 7, xy_timeBase7, 0, true, oa_users)
- );
- #endregion
- #region 签证
- var visa_proc = GroupProcessType.Visa;
- //用户可操作权限
- var visa_users = NodeOpUserTpl(users)[visa_proc];
- //1.
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, visa_proc, 1, null, 0, true, visa_users)
- );
- //2. 按进度实际签证办理落实情况,团组出发前上传票据。
- DateTime? qz_timeBase2 = groupInfo.VisitDate;
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, visa_proc, 2, qz_timeBase2, 7, true, visa_users)
- );
- #endregion
- #region 机票
- var air_proc = GroupProcessType.AirTicket;
- //用户可操作权限
- var air_users = NodeOpUserTpl(users)[air_proc];
- //1. 建团后打勾确认出团的时候开始24小时内。
- DateTime? air_timeBase1 = null;
- if (groupInfo.Step == 1 || groupInfo.Step == 2)
- {
- if (groupInfo.StepOperationTime.HasValue) air_timeBase1 = groupInfo.StepOperationTime.Value;
- }
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, air_proc, 1, air_timeBase1, 0, true, air_users)
- );
- //2.
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, visa_proc, 2, null, 0, true, visa_users)
- );
- //3. 完成机票采购确认(含预算核对、出票确认等)
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, visa_proc, 3, null, 0, true, visa_users)
- );
- //4.
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, visa_proc, 4, null, 0, true, visa_users)
- );
- //5. 团组出发前2个工作日
- DateTime? air_timeBase5 = groupInfo.VisitDate;
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, visa_proc, 5, air_timeBase5, -2, true, visa_users)
- );
- //6.
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, visa_proc, 6, null, 2, true, visa_users)
- );
- //7. 机票蓝联打票及上传机票超支费用账单,团组归国后5个工作日内
- DateTime? air_timeBase7 = groupInfo.VisitEndDate;
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, visa_proc, 7, air_timeBase7, 5, true, visa_users)
- );
- //8. 团组归国后10个工作日内 *按机票报价*0.999折扣出具机票报销蓝联、行程单及机票说明
- DateTime? air_timeBase8 = groupInfo.VisitEndDate;
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, visa_proc, 8, air_timeBase8, 10, true, visa_users)
- );
- #endregion
- #region 酒店
- var hotel_proc = GroupProcessType.Hotel;
- //用户可操作权限
- var hotel_users = NodeOpUserTpl(users)[hotel_proc];
- //1. 筛选并按照预算标准,对目标酒店进行询价、比价、谈价 \r\n2. 建团后打勾确认出团的时候开始2个工作日。
- DateTime? hotel_timeBase1 = null;
- if (groupInfo.Step == 1 || groupInfo.Step == 2)
- {
- if (groupInfo.StepOperationTime.HasValue) hotel_timeBase1 = groupInfo.StepOperationTime.Value;
- }
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, hotel_proc, 1, hotel_timeBase1, 2, true, hotel_users)
- );
- //2.
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, hotel_proc, 2, null, 0, true, hotel_users)
- );
- //3.
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, hotel_proc, 3, null, 0, true, hotel_users)
- );
- //4. 团组出发前2个工作日
- DateTime? hotel_timeBase4 = groupInfo.VisitDate;
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, hotel_proc, 4, hotel_timeBase4, -2, true, hotel_users)
- );
- //5. 团组结束后5个工作日内
- DateTime? hotel_timeBase5 = groupInfo.VisitEndDate;
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, hotel_proc, 5, hotel_timeBase5, 5, true, hotel_users)
- );
- #endregion
- #region 地接
- var dj_proc = GroupProcessType.LocalGuide;
- //用户可操作权限
- var dj_users = NodeOpUserTpl(users)[dj_proc];
- //1. 机票行程代码最后一段录入后1个工作日内。
- DateTime? dj_timeBase1 = null;
- if (airTripCodeInfo != null) dj_timeBase1 = airTripCodeInfo.CreateTime;
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, dj_proc, 1, dj_timeBase1, 1, true, dj_users)
- );
- //2. 团组出行前20个工作日
- DateTime? dj_timeBase2 = groupInfo.VisitDate;
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, dj_proc, 2, dj_timeBase2, -20, true, dj_users)
- );
- //3. 上一步往后3个工作日内
- DateTime? dj_timeBase3 = groupInfo.VisitDate;
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, dj_proc, 3, dj_timeBase3, -17, true, dj_users)
- );
- //4. 上一步往后2个工作日内
- DateTime? dj_timeBase4 = groupInfo.VisitDate;
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, dj_proc, 4, dj_timeBase4, -15, true, dj_users)
- );
- //5. 1.制定最终《行程单》及《出行手册》 \r\n2. 倒推表里开行前会 -3天。
- DateTime? dj_timeBase5 = null;
- if (backListInfo != null)
- {
- if (DateTime.TryParse(backListInfo.PreTripMeetingDt, out DateTime dateTime))
- {
- dj_timeBase5 = dateTime;
- }
- }
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, dj_proc, 5, dj_timeBase5, -3, true, dj_users)
- );
- //6.
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, dj_proc, 6, null, 0, true, dj_users)
- );
- //7. 团组归国后5个工作日内) *上传最终报批行程,确定城市间交通最终版报价分配;地接账单(清楚标注超时及其他项超支费用)、地接交通费用原始票据、城市间交通明细表;
- DateTime? dj_timeBase7 = groupInfo.VisitEndDate;
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, dj_proc, 7, dj_timeBase7, 5, true, dj_users)
- );
- #endregion
- #region 费用计算
- var fyjs_proc = GroupProcessType.FeeSettle;
- //用户可操作权限
- var fyjsfyjs_users = NodeOpUserTpl(users)[fyjs_proc];
- //1.
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, fyjs_proc, 1, null, 0, true, fyjsfyjs_users)
- );
- //2.
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, fyjs_proc, 2, null, 0, true, fyjsfyjs_users)
- );
- //3. 团组归国后12个工作日内
- DateTime? fyjs_timeBase3 = groupInfo.VisitEndDate;
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, fyjs_proc, 3, fyjs_timeBase3, 12, true, fyjsfyjs_users)
- );
- //4.
- nodeDetails.Add(
- GroupProcFullNodeDetails.Create(groupId, groupName, fyjs_proc, 4, null, 0, true, fyjsfyjs_users)
- );
- #endregion
- return nodeDetails;
- }
- #region 计算所有团时间节点基础数据
- /// <summary>
- /// 团组流程 - 数据初始化 ALL
- /// </summary>
- /// <param name="groupId"></param>
- /// <param name="currUserId"></param>
- /// <returns></returns>
- public async Task<List<GroupProcFullNodeDetails>> GetGroupAllProcessNodeInfoAsync()
- {
- var processs = new List<GroupProcFullNodeDetails>();
- var groupInfos = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.IsDel == 0).ToListAsync();
- if (groupInfos.Any())
- {
- var groupIds = groupInfos.Select(x => x.Id).ToList();
- //基础数据
- var opUsers = await GetUersAsync();
- var custInfos = await _sqlSugar.Queryable<Grp_TourClientList>()
- .Where(x => x.IsDel == 0 && groupIds.Contains( x.DiId))
- .OrderByDescending(c => c.CreateTime)
- .ToListAsync();
- var airTripCodeInfos = await _sqlSugar.Queryable<Air_TicketBlackCode>()
- .Where(x => x.IsDel == 0 && groupIds.Contains(x.DiId))
- .OrderByDescending(x => x.CreateTime)
- .ToListAsync();
- var backListInfos = await _sqlSugar.Queryable<Grp_InvertedList>().Where(x => x.IsDel == 0 && groupIds.Contains(x.DiId)).ToListAsync();
- foreach (var groupInfo in groupInfos)
- {
- var custInfo = custInfos.FirstOrDefault(x => x.DiId == groupInfo.Id);
- var airTripCodeInfo = airTripCodeInfos.FirstOrDefault(x => x.DiId == groupInfo.Id);
- var backListInfo = backListInfos.FirstOrDefault(x => x.DiId == groupInfo.Id);
- var groupNodeDetails = GetNodeDetails(
- groupInfo,
- opUsers,
- custInfo,
- airTripCodeInfo,
- backListInfo
- );
- processs.AddRange(groupNodeDetails);
- }
- }
- return processs;
- }
- /// <summary>
- /// 获取用户信息
- /// </summary>
- /// <returns></returns>
- public async Task<List<NodeOpUserInfo>> GetUersAsync()
- {
- return await _sqlSugar.Queryable<Sys_Users>()
- .LeftJoin<Sys_Company>((u, c) => u.CompanyId == c.Id)
- .LeftJoin<Sys_Department>((u, c, d) => u.DepId == d.Id)
- .LeftJoin<Sys_JobPost>((u, c, d, jp) => u.JobPostId == jp.Id)
- .Where((u, c, d, jp) => u.IsDel == 0)
- .Select((u, c, d, jp) => new NodeOpUserInfo()
- {
- Id = u.Id,
- CnName = u.CnName,
- CompanyId = u.CompanyId,
- CompanyName = c.CompanyName,
- DepId = u.DepId,
- DepName = d.DepName,
- JobPostId = u.JobPostId,
- JobName = jp.JobName,
- QiyeChatUserId = u.QiyeChatUserId,
- })
- .ToListAsync();
- }
- /// <summary>
- /// 节点可操作人员
- /// </summary>
- /// <returns></returns>
- public static Dictionary<GroupProcessType, List<UserAndQiWeiUserIdView>> NodeOpUserTpl(List<NodeOpUserInfo> users)
- {
- var result = new Dictionary<GroupProcessType, List<UserAndQiWeiUserIdView>>();
- var defaultJobNames = new List<string>()
- {
- "OP主管"
- };
- #region 商邀报批流程
- //节点可操作用户列表
- var oaJobNames = new List<string>() {
- "商邀主管",
- "商邀"
- };
- var oaNodeOpUsers = users.Where(u =>
- u.JobName != null && oaJobNames.Contains(u.JobName)
- )
- .Select(u => new UserAndQiWeiUserIdView() { Id = u.Id, Name = u.CnName, QiyeChatUserId = u.QiyeChatUserId })
- .ToList();
- result.Add(GroupProcessType.Invitation, oaNodeOpUsers);
- #endregion
- #region 签证流程
- //节点可操作用户列表
- var visaNodeOpUsers = users.Where(u =>
- u.JobName != null && u.JobName.Contains("签证")
- )
- .Select(u => new UserAndQiWeiUserIdView() { Id = u.Id, Name = u.CnName, QiyeChatUserId = u.QiyeChatUserId })
- .ToList();
- result.Add(GroupProcessType.Visa, visaNodeOpUsers);
- #endregion
- #region 机票流程
- //节点可操作用户列表
- var airNodeOpJobNames = new List<string>() {
- "机票"
- };
- airNodeOpJobNames.AddRange(defaultJobNames);
- var airNodeOpUsers = users.Where(u =>
- u.JobName != null && airNodeOpJobNames.Contains(u.JobName)
- )
- .Select(u => new UserAndQiWeiUserIdView() { Id = u.Id, Name = u.CnName, QiyeChatUserId = u.QiyeChatUserId })
- .ToList();
- result.Add(GroupProcessType.AirTicket, airNodeOpUsers);
- #endregion
- #region 酒店流程
- //节点可操作用户列表
- var hotelNodeOpJobNames = new List<string>() { "酒店" };
- hotelNodeOpJobNames.AddRange(defaultJobNames);
- var hotelNodeOpUsers = users.Where(u =>
- u.JobName != null && hotelNodeOpJobNames.Contains(u.JobName)
- )
- .Select(u => new UserAndQiWeiUserIdView() { Id = u.Id, Name = u.CnName, QiyeChatUserId = u.QiyeChatUserId })
- .ToList();
- result.Add(GroupProcessType.Hotel, hotelNodeOpUsers);
- #endregion
- #region 地接流程
- //节点可操作用户列表
- var opNodeOpJobNames = new List<string>() { "OP" };
- opNodeOpJobNames.AddRange(defaultJobNames);
- var opNodeOpUsers = users.Where(u =>
- u.JobName != null && opNodeOpJobNames.Contains(u.JobName)
- )
- .Select(u => new UserAndQiWeiUserIdView() { Id = u.Id, Name = u.CnName, QiyeChatUserId = u.QiyeChatUserId })
- .ToList();
- result.Add(GroupProcessType.LocalGuide, opNodeOpUsers);
- #endregion
- #region 费用结算流程
- //节点可操作用户列表
- var feeNodeOpUsers = users.Where(u =>
- u.JobName != null && u.JobName.Contains("会计") && u.CnName.Equals("曾艳")
- )
- .Select(u => new UserAndQiWeiUserIdView() { Id = u.Id, Name = u.CnName, QiyeChatUserId = u.QiyeChatUserId })
- .ToList();
- result.Add(GroupProcessType.FeeSettle, feeNodeOpUsers);
- #endregion
- return result;
- }
- public class NodeOpUserInfo
- {
- public int Id { get; set; }
- public string CnName { get; set; }
- public int CompanyId { get; set; }
- public string CompanyName { get; set; }
- public int DepId { get; set; }
- public string DepName { get; set; }
- public int JobPostId { get; set; }
- public string JobName { get; set; }
- public string QiyeChatUserId { get; set; }
- }
- public class GroupProcFullNodeDetails
- {
- public int GroupId { get; set; }
- public string GroupName { get; set; }
- /// <summary>
- /// 流程类型
- /// </summary>
- public GroupProcessType ProcType { get; set; }
- /// <summary>
- /// 流程顺序
- /// </summary>
- public int ProcOrder
- {
- get
- {
- return (int)ProcType;
- }
- }
- public int NodeOrder { get; set; }
- public string NodeName
- {
- get
- {
- return ProcType switch
- {
- GroupProcessType.Invitation => NodeOrder switch
- {
- 1 => "初期报批文字材料",
- 2 => "第一轮对接",
- 3 => "第二轮对接",
- 4 => "取得邀请函",
- 5 => "公务等事项确认",
- 6 => "公务邀请数据有效录入",
- 7 => "文件上传",
- _ => ""
- },
- GroupProcessType.Visa => NodeOrder switch
- {
- 1 => "签证信息",
- 2 => "票据上传(明细表、费用票据、保单及超支费用账单)",
- _ => ""
- },
- GroupProcessType.AirTicket => NodeOrder switch
- {
- 1 => "初步拟定航程方案及价格",
- 2 => "机票占位、续位",
- 3 => "完成机票采购确认",
- 4 => "进行出票操作并核查信息",
- 5 => "机票已出",
- 6 => "完成机票选座",
- 7 => "票据上传(机票超支费用账单)",
- 8 => "票据上传",
- _ => ""
- },
- GroupProcessType.Hotel => NodeOrder switch
- {
- 1 => "按照预算,询价、比价、谈价",
- 2 => "获取酒店确认函与入住名单核对",
- 3 => "预订酒店并录入OA",
- 4 => "行前再次确认酒店相关情况",
- 5 => "行程结束后整理酒店发票与结算",
- _ => ""
- },
- GroupProcessType.LocalGuide => NodeOrder switch
- {
- 1 => "根据机票方案出框架行程",
- 2 => "联系并询价地接相关的供应商",
- 3 => "提交供应商报价及比价表",
- 4 => "执行采购流程",
- 5 => "制定最终行程单及出行手册",
- 6 => "送机",
- 7 => "最终版报批行程、票据上传",
- _ => ""
- },
- GroupProcessType.FeeSettle => NodeOrder switch
- {
- 1 => "城市间交通报批金额核定",
- 2 => "团组城市间交通及国际机票数据分配的合理性核对",
- 3 => "整理统计相关财务资料给到各单位",
- 4 => "费用结算完毕",
- _ => ""
- },
- _ => ""
- };
- }
- }
- public string NodeTips
- {
- get
- {
- string msg = string.Empty;
- string promptMessage = GetPromptMessage();
- switch (ProcType)
- {
- case GroupProcessType.Invitation:
- switch (NodeOrder)
- {
- case 1:
- msg = "“完成基础请示、报批日程初稿”,4个工作日(仍需根据客户意见和联系情况及时修改补充所需其他材料,例如印证文件、成果表等,直至终稿)";
- break;
- case 2:
- msg = "7个工作日,所有报批机构前部联系,邀请机构一个国家不少于4家进行重点对接(4家机构中,其中3家机构需有效对接,其中1家可为付费机构备选)";
- break;
- case 3:
- msg = "10个工作日,根据最新情况,联系公务机构1/3取得回应;邀请机构基本明确。";
- break;
- case 4:
- msg = "正式名单下放后2周内(含非工作日)。如团组前期准备时间已经较长,则按客户要求尽快提供。 加急团组备注特殊情况。";
- break;
- case 5:
- msg = "团组出发前,5个工作日完成所有公务确认工作。";
- break;
- case 6:
- break;
- case 7:
- msg = "如果需要上传请在团组结束前完成";
- break;
- }
- break;
- case GroupProcessType.Visa:
- switch (NodeOrder)
- {
- case 1:
- break;
- case 2:
- msg = "按进度实际签证办理落实情况,团组出发前上传票据。";
- break;
- }
- break;
- case GroupProcessType.AirTicket:
- switch (NodeOrder)
- {
- case 1:
- msg = "建团后打勾确认出团的时候开始24小时内。";
- break;
- case 2:
- break;
- case 3:
- msg = "完成机票采购确认(含预算核对、出票确认等)";
- break;
- case 4:
- break;
- case 5:
- msg = "团组出发前2个工作日";
- break;
- case 6:
- break;
- case 7:
- msg = "机票蓝联打票及上传机票超支费用账单,团组归国后5个工作日内";
- break;
- case 8:
- msg = "1. 票据上传(机票报销蓝联、行程单及机票说明) \r\n 2. 团组归国后10个工作日内 *按机票报价*0.999折扣出具机票报销蓝联、行程单及机票说明";
- break;
- }
- break;
- case GroupProcessType.Hotel:
- switch (NodeOrder)
- {
- case 1:
- msg = "1. 筛选并按照预算标准,对目标酒店进行询价、比价、谈价 \r\n2. 建团后打勾确认出团的时候开始2个工作日。";
- break;
- case 2:
- break;
- case 3:
- break;
- case 4:
- msg = "1.行前再次确认酒店订单、付款状态及入住安排 \r\n 2.团组出发前2个工作日";
- break;
- case 5:
- Days = 5;
- msg = "1.行程结束后整理酒店发票(含超支费用发票)与结算 \r\n 2.团组结束后5个工作日内";
- break;
- }
- break;
- case GroupProcessType.LocalGuide:
- switch (NodeOrder)
- {
- case 1:
- msg = "机票行程代码最后一段录入后1个工作日内。";
- break;
- case 2:
- msg = "1.联系并询价地接、餐厅、用车、景点等供应商 \r\n 2. 团组出行前20个工作日";
- break;
- case 3:
- msg = "上一步往后3个工作日内";
- break;
- case 4:
- msg = "上一步往后2个工作日内";
- break;
- case 5:
- msg = "1.制定最终《行程单》及《出行手册》 \r\n2. 倒推表里开行前会 -3天。";
- break;
- case 6:
- break;
- case 7:
- msg = "团组归国后5个工作日内 *上传最终报批行程,确定城市间交通最终版报价分配;地接账单(清楚标注超时及其他项超支费用)、地接交通费用原始票据、城市间交通明细表;";
- break;
- }
- break;
- case GroupProcessType.FeeSettle:
- switch (NodeOrder)
- {
- case 1:
- msg = "团组报批前";
- break;
- case 2:
- msg = "团组报批前三公费用表";
- break;
- case 3:
- msg = "1.整理统计团组超支费用、三公报销资料给到各单位 \r\n 2. 团组归国后12个工作日内";
- break;
- case 4:
- break;
- }
- break;
- }
- if (!string.IsNullOrEmpty(promptMessage))
- {
- msg = $"{promptMessage}({msg})";
- }
- return msg;
- }
- }
- /// <summary>
- /// 提示时间 - 基数
- /// </summary>
- public DateTime? PromptTimeBase { get; set; }
- /// <summary>
- /// 提前提醒天数
- /// </summary>
- public int Days { get; set; }
- /// <summary>
- /// 是否是工作日
- /// true 工作日 false 自然日
- /// </summary>
- public bool IsWorkday { get; set; } = false;
- /// <summary>
- /// 提示时间
- /// </summary>
- public DateTime? PromptTime
- {
- get
- {
- DateTime? dt = null;
- if (PromptTimeBase.HasValue)
- {
- if (IsWorkday)
- {
- dt = AddWeekdays(PromptTimeBase.Value, Days);
- }
- else
- {
- dt = PromptTimeBase.Value.AddDays(Days);
- }
- }
- return dt;
- }
- }
- /// <summary>
- /// 提示人
- /// </summary>
- public List<UserAndQiWeiUserIdView> PromptPerson { get; set; }
- public GroupProcFullNodeDetails() { }
- public static GroupProcFullNodeDetails Create(int groupId, string groupName, GroupProcessType procType, int nodeOrder, DateTime? promptTimeBase,
- int days, bool isWorkday, List<UserAndQiWeiUserIdView> promptPerson)
- {
- return new GroupProcFullNodeDetails
- {
- GroupId = groupId,
- GroupName = groupName,
- ProcType = procType,
- NodeOrder = nodeOrder,
- PromptTimeBase = promptTimeBase,
- Days = days,
- IsWorkday = isWorkday,
- PromptPerson = promptPerson
- };
- }
- private string GetPromptMessage()
- {
- if (PromptTime.HasValue)
- {
- return $"请于{PromptTime.Value:yyyy年MM月dd日}内完成该项工作";
- }
- return string.Empty;
- }
- }
-
- public class UserAndQiWeiUserIdView
- {
- public int Id { get; set; }
- public string Name { get; set; }
- public string QiyeChatUserId { get; set; }
- }
- #endregion
- #region 状态变更 可操作任意节点 进行中<-->已完成 双向变更
- /// <summary>
- /// 更新节点状态(支持任意节点状态变更,无需处理当前节点)
- /// </summary>
- /// <param name="nodeId"></param>
- /// <param name="currUserId"></param>
- /// <param name="targetStatus"></param>
- /// <returns></returns>
- public async Task<Result> UpdateNodeStatusSimpleAsync(int nodeId, int currUserId, ProcessStatus targetStatus = ProcessStatus.Completed)
- {
- try
- {
- var result = await _sqlSugar.Ado.UseTranAsync(async () =>
- {
- // 1. 获取节点和流程信息
- var node = await _sqlSugar.Queryable<Grp_ProcessNode>()
- .FirstAsync(n => n.Id == nodeId && n.IsDel == 0);
- if (node == null) return new Result { Code = StatusCodes.Status400BadRequest, Msg = "当前节点不存在或已被删除。" };
- // 2. 用户权限验证
- if (!HasNodeOperationPermission(node, currUserId))
- {
- return new Result { Code = StatusCodes.Status400BadRequest, Msg = "当前用户没有操作此节点的权限." };
- }
- var process = await _sqlSugar.Queryable<Grp_ProcessOverview>()
- .FirstAsync(p => p.Id == node.ProcessId && p.IsDel == 0);
- if (process == null) return new Result { Code = StatusCodes.Status400BadRequest, Msg = "关联的流程不存在。" };
- // 3. 检查是否重复操作
- if (node.OverallStatus == targetStatus)
- {
- return new Result { Code = StatusCodes.Status400BadRequest, Msg = $"当前节点已为{GetStatusDescription(targetStatus)}状态,无需重复操作。。" };
- }
- // 4. 存储更新前的值
- var nodeBefore = CloneNode(node);
- var processBefore = CloneProcess(process);
- // 5. 更新节点状态
- node.OverallStatus = targetStatus;
- node.Operator = currUserId;
- node.OperationTime = DateTime.Now;
- // 6. 保存节点更新
- await _sqlSugar.Updateable(node)
- .UpdateColumns(n => new
- {
- n.OverallStatus,
- n.Operator,
- n.OperationTime
- })
- .ExecuteCommandAsync();
- // 7. 更新流程状态(基于所有节点的状态计算)
- await UpdateProcessOverallStatusAsync(process, currUserId);
- // 8. 记录日志
- await LogNodeOpAsync(nodeBefore, node, "Update", currUserId);
- await LogProcessOpAsync(processBefore, process, "Update", currUserId);
- return new Result { Code = StatusCodes.Status200OK, Msg = "操作成功。" };
- });
- return result.IsSuccess ? result.Data : new Result
- {
- Code = StatusCodes.Status500InternalServerError,
- Msg = result.ErrorMessage
- };
- }
- catch (BusinessException ex)
- {
- return new Result { Code = StatusCodes.Status400BadRequest, Msg = ex.Message };
- }
- catch (Exception ex)
- {
- return new Result { Code = StatusCodes.Status500InternalServerError, Msg = "系统错误,请稍后重试" };
- }
- }
- /// <summary>
- /// 更新流程整体状态(根据所有节点状态计算)
- /// </summary>
- /// <param name="process"></param>
- /// <param name="currUserId"></param>
- /// <returns></returns>
- private async Task UpdateProcessOverallStatusAsync(Grp_ProcessOverview process, int currUserId)
- {
- // 获取所有节点
- var allNodes = await _sqlSugar.Queryable<Grp_ProcessNode>()
- .Where(n => n.ProcessId == process.Id && n.IsDel == 0)
- .ToListAsync();
- // 统计节点状态
- int totalCount = allNodes.Count;
- int completedCount = allNodes.Count(n => n.OverallStatus == ProcessStatus.Completed);
- int inProgressCount = allNodes.Count(n => n.OverallStatus == ProcessStatus.InProgress);
- // 判断流程状态
- ProcessStatus newProcessStatus;
- if (completedCount == totalCount)
- {
- // 所有节点都已完成
- newProcessStatus = ProcessStatus.Completed;
- process.EndTime = DateTime.Now;
- }
- else if (inProgressCount > 0 || completedCount > 0)
- {
- // 有节点进行中或已完成
- newProcessStatus = ProcessStatus.InProgress;
- process.EndTime = null;
- }
- else
- {
- // 所有节点都未开始
- newProcessStatus = ProcessStatus.UnStarted;
- process.EndTime = null;
- }
- // 更新流程状态(只有状态变化时才更新)
- if (process.OverallStatus != newProcessStatus)
- {
- process.OverallStatus = newProcessStatus;
- process.UpdatedUserId = currUserId;
- process.UpdatedTime = DateTime.Now;
- await _sqlSugar.Updateable(process)
- .UpdateColumns(p => new
- {
- p.OverallStatus,
- p.EndTime,
- p.UpdatedUserId,
- p.UpdatedTime
- })
- .ExecuteCommandAsync();
- }
- }
- /// <summary>
- /// 验证用户是否有操作节点的权限
- /// </summary>
- private static bool HasNodeOperationPermission(Grp_ProcessNode node, int userId)
- {
- // 如果 OpUserList 为空或 null,表示不限制权限
- if (node.OpUserList == null || node.OpUserList.Count == 0)
- {
- return true;
- }
- // 检查当前用户是否在权限列表中
- return node.OpUserList.Contains(userId);
- }
- /// <summary>
- /// 克隆节点对象
- /// </summary>
- /// <param name="node"></param>
- /// <returns></returns>
- private static Grp_ProcessNode CloneNode(Grp_ProcessNode node)
- {
- return new Grp_ProcessNode()
- {
- Id = node.Id,
- ProcessId = node.ProcessId,
- NodeName = node.NodeName,
- NodeOrder = node.NodeOrder,
- OverallStatus = node.OverallStatus,
- Operator = node.Operator,
- OperationTime = node.OperationTime,
- IsCurrent = node.IsCurrent,
- };
- }
- /// <summary>
- /// 克隆流程对象
- /// </summary>
- /// <param name="process"></param>
- /// <returns></returns>
- private static Grp_ProcessOverview CloneProcess(Grp_ProcessOverview process)
- {
- return new Grp_ProcessOverview()
- {
- Id = process.Id,
- GroupId = process.GroupId,
- ProcessOrder = process.ProcessOrder,
- ProcessType = process.ProcessType,
- OverallStatus = process.OverallStatus,
- StartTime = process.StartTime,
- EndTime = process.EndTime,
- UpdatedUserId = process.UpdatedUserId,
- UpdatedTime = process.UpdatedTime
- };
- }
- #endregion
- #region 状态变更 流程导向
- /// <summary>
- /// 更新节点状态
- /// </summary>
- public async Task<Result> UpdateNodeStatusAsync(int nodeId, int currUserId, ProcessStatus processStatus = ProcessStatus.Completed)
- {
- try
- {
- // 使用事务确保数据一致性
- var result = await _sqlSugar.Ado.UseTranAsync(async () =>
- {
- // 1. 获取并验证节点
- var node = await _sqlSugar.Queryable<Grp_ProcessNode>()
- .FirstAsync(n => n.Id == nodeId && n.IsDel == 0)
- ?? throw new BusinessException("当前节点不存在或已被删除。");
- // 2. 获取流程信息
- var process = await _sqlSugar.Queryable<Grp_ProcessOverview>()
- .FirstAsync(p => p.Id == node.ProcessId && p.IsDel == 0)
- ?? throw new BusinessException("关联的流程不存在。");
- // 3. 验证节点操作
- ValidateNodeOperation(node, processStatus);
- // 4. 存储更新前的值
- var nodeBefore = new Grp_ProcessNode()
- {
- Id = node.Id,
- ProcessId = node.ProcessId,
- NodeName = node.NodeName,
- NodeOrder = node.NodeOrder,
- OverallStatus = node.OverallStatus,
- Operator = node.Operator,
- OperationTime = node.OperationTime,
- IsCurrent = node.IsCurrent,
- };
- var processBefore = new Grp_ProcessOverview()
- {
- Id = process.Id,
- GroupId = process.GroupId,
- ProcessOrder = process.ProcessOrder,
- ProcessType = process.ProcessType,
- OverallStatus = process.OverallStatus,
- StartTime = process.StartTime,
- EndTime = process.EndTime,
- UpdatedUserId = process.UpdatedUserId,
- UpdatedTime = process.UpdatedTime
- };
- // 5. 处理特殊状态流转逻辑
- if (node.OverallStatus == ProcessStatus.Completed && processStatus == ProcessStatus.InProgress)
- {
- // 从已完成回退到进行中
- await HandleRollbackToInProgressAsync(node, process, currUserId);
- }
- else
- {
- // 正常状态更新
- await HandleNormalStatusUpdateAsync(node, process, processStatus, currUserId);
- }
- // 6. 记录日志
- await LogNodeOpAsync(nodeBefore, node, "Update", currUserId);
- await LogProcessOpAsync(processBefore, process, "Update", currUserId);
- return new Result { Code = StatusCodes.Status200OK, Msg = "操作成功。" };
- });
- return result.IsSuccess ? result.Data : new Result
- {
- Code = StatusCodes.Status500InternalServerError,
- Msg = result.ErrorMessage
- };
- }
- catch (BusinessException ex)
- {
- return new Result { Code = StatusCodes.Status400BadRequest, Msg = ex.Message };
- }
- catch (Exception ex)
- {
- return new Result { Code = StatusCodes.Status500InternalServerError, Msg = "系统错误,请稍后重试" };
- }
- }
- /// <summary>
- /// 处理从已完成回退到进行中的逻辑
- /// </summary>
- private async Task HandleRollbackToInProgressAsync(Grp_ProcessNode node, Grp_ProcessOverview process, int currUserId)
- {
- // 1. 检查是否可以回退
- if (process.OverallStatus == ProcessStatus.Completed && process.ProcessType != GroupProcessType.Invitation)
- {
- throw new BusinessException("整个流程已完成,无法回退单个节点状态。");
- }
- // 2. 取消其他当前节点,设置当前节点为当前节点
- await ClearOtherCurrentNodesAsync(node.ProcessId, node.Id, currUserId);
- // 3. 更新节点状态
- node.OverallStatus = ProcessStatus.InProgress;
- node.Operator = currUserId;
- node.OperationTime = DateTime.Now;
- node.IsCurrent = true;
- await _sqlSugar.Updateable(node)
- .UpdateColumns(n => new
- {
- n.OverallStatus,
- n.Operator,
- n.OperationTime,
- n.IsCurrent
- })
- .ExecuteCommandAsync();
- // 4. 更新流程状态为进行中(如果已完成的流程回退)
- if (process.OverallStatus == ProcessStatus.Completed)
- {
- process.OverallStatus = ProcessStatus.InProgress;
- process.EndTime = null; // 清空完成时间
- process.UpdatedUserId = currUserId;
- process.UpdatedTime = DateTime.Now;
- await _sqlSugar.Updateable(process)
- .UpdateColumns(p => new
- {
- p.OverallStatus,
- p.EndTime,
- p.UpdatedUserId,
- p.UpdatedTime
- })
- .ExecuteCommandAsync();
- }
- }
- /// <summary>
- /// 处理正常状态更新逻辑
- /// </summary>
- private async Task HandleNormalStatusUpdateAsync(Grp_ProcessNode node, Grp_ProcessOverview process, ProcessStatus newStatus, int currUserId)
- {
- // 1. 更新节点基础信息
- node.OverallStatus = newStatus;
- node.Operator = currUserId;
- node.OperationTime = DateTime.Now;
- // 2. 根据新状态处理节点和流程逻辑
- if (newStatus == ProcessStatus.InProgress)
- {
- // 设置为进行中:需要成为当前节点
- await ClearOtherCurrentNodesAsync(node.ProcessId, node.Id, currUserId);
- node.IsCurrent = true;
- // 更新流程状态为进行中
- process.OverallStatus = ProcessStatus.InProgress;
- process.UpdatedUserId = currUserId;
- process.UpdatedTime = DateTime.Now;
- }
- else if (newStatus == ProcessStatus.Completed)
- {
- // 设置为已完成:取消当前节点状态
- node.IsCurrent = false;
- // 如果是当前节点完成,需要处理流程流转
- if (node.IsCurrent || process.ProcessType == GroupProcessType.Invitation)
- {
- await HandleNodeCompletionAsync(node, process, currUserId);
- }
- else
- {
- // 非当前节点完成,检查流程状态
- await CheckAndUpdateProcessStatusAsync(process, currUserId);
- }
- }
- else if (newStatus == ProcessStatus.UnStarted)
- {
- // 重置为未开始:取消当前节点状态
- node.IsCurrent = false;
- // 更新流程状态
- await CheckAndUpdateProcessStatusAsync(process, currUserId);
- }
- // 3. 保存节点更新
- await _sqlSugar.Updateable(node)
- .UpdateColumns(n => new
- {
- n.OverallStatus,
- n.Operator,
- n.OperationTime,
- n.IsCurrent
- })
- .ExecuteCommandAsync();
- // 4. 保存流程更新
- await _sqlSugar.Updateable(process)
- .UpdateColumns(p => new
- {
- p.OverallStatus,
- p.EndTime,
- p.UpdatedUserId,
- p.UpdatedTime
- })
- .ExecuteCommandAsync();
- }
- /// <summary>
- /// 处理节点完成后的流程流转(替代原来的 ProcessCurrentNodeCompletionAsync)
- /// </summary>
- private async Task HandleNodeCompletionAsync(Grp_ProcessNode currentNode, Grp_ProcessOverview process, int currUserId)
- {
- // 1. 获取所有节点
- var allNodes = await _sqlSugar.Queryable<Grp_ProcessNode>()
- .Where(x => x.IsDel == 0 && x.ProcessId == currentNode.ProcessId)
- .ToListAsync();
- // 2. 商邀流程特殊处理
- if (process.ProcessType == GroupProcessType.Invitation)
- {
- int completedCount = allNodes.Count(n => n.OverallStatus == ProcessStatus.Completed);
- int nodeCount = allNodes.Count;
- if (completedCount == nodeCount) // 所有节点完成
- {
- process.OverallStatus = ProcessStatus.Completed;
- process.EndTime = DateTime.Now;
- }
- else if (completedCount > 0)
- {
- process.OverallStatus = ProcessStatus.InProgress;
- }
- }
- else
- {
- // 3. 普通流程:查找下一个节点
- var nextNode = allNodes
- .Where(n => n.NodeOrder == currentNode.NodeOrder + 1)
- .FirstOrDefault();
- if (nextNode != null)
- {
- // 激活下一个节点
- var nextNodeBefore = new Grp_ProcessNode()
- {
- Id = nextNode.Id,
- ProcessId = nextNode.ProcessId,
- NodeName = nextNode.NodeName,
- NodeOrder = nextNode.NodeOrder,
- OverallStatus = nextNode.OverallStatus,
- Operator = nextNode.Operator,
- OperationTime = nextNode.OperationTime,
- IsCurrent = nextNode.IsCurrent,
- };
- nextNode.IsCurrent = true;
- nextNode.OverallStatus = ProcessStatus.InProgress;
- nextNode.Operator = currUserId;
- nextNode.OperationTime = DateTime.Now;
- await _sqlSugar.Updateable(nextNode)
- .UpdateColumns(n => new
- {
- n.IsCurrent,
- n.OverallStatus,
- n.Operator,
- n.OperationTime
- })
- .ExecuteCommandAsync();
- await LogNodeOpAsync(nextNodeBefore, nextNode, "Start", currUserId);
- process.OverallStatus = ProcessStatus.InProgress;
- }
- else
- {
- // 没有下一个节点,流程完成
- process.OverallStatus = ProcessStatus.Completed;
- process.EndTime = DateTime.Now;
- }
- }
- process.UpdatedUserId = currUserId;
- process.UpdatedTime = DateTime.Now;
- }
- /// <summary>
- /// 清除其他当前节点
- /// </summary>
- private async Task ClearOtherCurrentNodesAsync(int processId, int currentNodeId, int currUserId)
- {
- var otherCurrentNodes = await _sqlSugar.Queryable<Grp_ProcessNode>()
- .Where(n => n.ProcessId == processId
- && n.Id != currentNodeId
- && n.IsCurrent
- && n.IsDel == 0)
- .ToListAsync();
- foreach (var otherNode in otherCurrentNodes)
- {
- var before = new Grp_ProcessNode()
- {
- Id = otherNode.Id,
- ProcessId = otherNode.ProcessId,
- NodeName = otherNode.NodeName,
- NodeOrder = otherNode.NodeOrder,
- OverallStatus = otherNode.OverallStatus,
- Operator = otherNode.Operator,
- OperationTime = otherNode.OperationTime,
- IsCurrent = otherNode.IsCurrent,
- };
- otherNode.IsCurrent = false;
- await _sqlSugar.Updateable(otherNode)
- .UpdateColumns(n => new { n.IsCurrent })
- .ExecuteCommandAsync();
- await LogNodeOpAsync(before, otherNode, "Update", currUserId);
- }
- }
- /// <summary>
- /// 检查并更新流程状态
- /// </summary>
- private async Task CheckAndUpdateProcessStatusAsync(Grp_ProcessOverview process, int currUserId)
- {
- // 获取所有节点状态
- var allNodes = await _sqlSugar.Queryable<Grp_ProcessNode>()
- .Where(x => x.IsDel == 0 && x.ProcessId == process.Id)
- .ToListAsync();
- int totalCount = allNodes.Count;
- int completedCount = allNodes.Count(n => n.OverallStatus == ProcessStatus.Completed);
- int inProgressCount = allNodes.Count(n => n.OverallStatus == ProcessStatus.InProgress);
- // 更新流程状态
- if (completedCount == totalCount)
- {
- process.OverallStatus = ProcessStatus.Completed;
- process.EndTime = DateTime.Now;
- }
- else if (completedCount > 0 || inProgressCount > 0)
- {
- process.OverallStatus = ProcessStatus.InProgress;
- process.EndTime = null;
- }
- else
- {
- process.OverallStatus = ProcessStatus.UnStarted;
- process.EndTime = null;
- }
- process.UpdatedUserId = currUserId;
- process.UpdatedTime = DateTime.Now;
- }
- /// <summary>
- /// 验证节点操作权限
- /// </summary>
- private static void ValidateNodeOperation(Grp_ProcessNode node, ProcessStatus targetStatus)
- {
- // 验证状态流转是否合法
- if (node.OverallStatus == targetStatus)
- {
- throw new BusinessException($"当前节点已为{GetStatusDescription(targetStatus)}状态,无需重复操作。");
- }
- // 允许的流转规则:
- // 1. 未开始 → 进行中 → 已完成(正常流程)
- // 2. 已完成 → 进行中(回退操作)
- // 3. 进行中 → 未开始(重置操作)
- // 禁止的操作:已完成 → 未开始(需要先回到进行中)
- if (node.OverallStatus == ProcessStatus.Completed && targetStatus == ProcessStatus.UnStarted)
- {
- throw new BusinessException("已完成节点不可直接更改为未开始状态,请先更改为进行中状态。");
- }
- }
- private static string GetStatusDescription(ProcessStatus status)
- {
- return status switch
- {
- ProcessStatus.UnStarted => "未开始",
- ProcessStatus.InProgress => "进行中",
- ProcessStatus.Completed => "已完成",
- _ => "未知状态"
- };
- }
- #endregion
- /// <summary>
- /// 更新签证节点信息及状态
- /// </summary>
- /// <param name="dto">签证节点更新数据传输对象</param>
- /// <returns>操作结果</returns>
- public async Task<Result> UpdateVisaNodeDetailsAsync(GroupProcessUpdateVisaNodeDetailsDto dto)
- {
- // 1. 获取并验证节点和流程
- var node = await _sqlSugar.Queryable<Grp_ProcessNode>()
- .FirstAsync(n => n.Id == dto.NodeId && n.IsDel == 0)
- ?? throw new BusinessException("当前节点不存在或已被删除。");
- var process = await _sqlSugar.Queryable<Grp_ProcessOverview>()
- .FirstAsync(p => p.Id == node.ProcessId && p.IsDel == 0)
- ?? throw new BusinessException("当前流程不存在或已被删除。");
- if (process.ProcessType != GroupProcessType.Visa)
- {
- throw new BusinessException("当前流程节点不为签证流程,不可编辑。");
- }
- // 2. 检查签证子节点 字段信息是否全部填写
- var allSubNodesCompleted = dto.VisaSubNodes?.All(subNode => EntityExtensions.IsCompleted(subNode)) ?? false;
- // 2.1 存储更新前流程及节点信息
- var nodeBefore = new Grp_ProcessNode()
- {
- Id = node.Id,
- ProcessId = node.ProcessId,
- NodeName = node.NodeName,
- NodeOrder = node.NodeOrder,
- OverallStatus = node.OverallStatus,
- Operator = node.Operator,
- OperationTime = node.OperationTime,
- IsCurrent = node.IsCurrent,
- };
- var processBefore = new Grp_ProcessOverview()
- {
- Id = process.Id,
- GroupId = process.GroupId,
- ProcessOrder = process.ProcessOrder,
- ProcessType = process.ProcessType,
- OverallStatus = process.OverallStatus,
- StartTime = process.StartTime,
- EndTime = process.EndTime,
- UpdatedUserId = process.UpdatedUserId,
- UpdatedTime = process.UpdatedTime
- };
- // 3. 更新节点信息
- node.Remark = JsonConvert.SerializeObject(dto.VisaSubNodes);
- node.Operator = dto.CurrUserId;
- node.OperationTime = DateTime.Now;
- if (allSubNodesCompleted)
- {
- node.OverallStatus = ProcessStatus.Completed;
- process.OverallStatus = ProcessStatus.Completed;
- process.EndTime = DateTime.Now;
- process.UpdatedUserId = dto.CurrUserId;
- process.UpdatedTime = DateTime.Now;
- // 更新流程状态
- await _sqlSugar.Updateable(process)
- .UpdateColumns(p => new
- {
- p.OverallStatus,
- p.EndTime,
- p.UpdatedUserId,
- p.UpdatedTime
- })
- .ExecuteCommandAsync();
- //记录流程日志
- await LogProcessOpAsync(processBefore, process, "Update", dto.CurrUserId);
- }
- // 4. 保存节点更新
- await _sqlSugar.Updateable(node)
- .UpdateColumns(n => new
- {
- n.Remark,
- n.Operator,
- n.OperationTime,
- n.OverallStatus
- })
- .ExecuteCommandAsync();
- //记录节点日志
- await LogNodeOpAsync(nodeBefore, node, "Update", dto.CurrUserId);
- return new Result { Code = 200, Msg = "节点信息更新成功。" };
- }
- /// <summary>
- /// 更新节点信息及状态
- /// </summary>
- /// <param name="dto">更新节点信息及状态</param>
- /// <returns>操作结果</returns>
- public async Task<Result> SetActualDoneAsync(GroupProcessSetActualDoneDto dto)
- {
- int nodeId = dto.NodeId;
- var isDtNul = DateTime.TryParse(dto.ActualDone, out DateTime actualDone);
- int currUserId = dto.CurrUserId;
- bool isAssist = dto.IsAssist;
- bool isFileUp = dto.IsFileUp;
- bool isPart = dto.IsPart;
- // 1. 获取并验证节点和流程
- var node = await _sqlSugar.Queryable<Grp_ProcessNode>()
- .FirstAsync(n => n.Id == nodeId && n.IsDel == 0);
- if (node == null) return new Result { Code = 400, Msg = "当前节点不存在或已被删除。" };
- // 1.1. 用户权限验证
- if (!HasNodeOperationPermission(node, currUserId))
- {
- return new Result { Code = 400, Msg = "当前用户没有操作此节点的权限。" };
- }
- var process = await _sqlSugar.Queryable<Grp_ProcessOverview>()
- .FirstAsync(p => p.Id == node.ProcessId && p.IsDel == 0);
- if (process == null) return new Result { Code = 400, Msg = "当前流程不存在或已被删除。" };
- // 2.1 存储更新前流程及节点信息
- var nodeBefore = CloneNode(node);
- if (isDtNul)
- {
- node.ActualDone = actualDone;
- }
- else node.ActualDone = null;
- node.IsAssist = isAssist;
- node.IsFileUp = isFileUp;
- node.IsPart = isPart;
- node.Remark = dto.Remark;
- // 3. 保存节点更新
- await _sqlSugar.Updateable(node)
- .UpdateColumns(n => new
- {
- n.ActualDone,
- n.IsAssist,
- n.IsFileUp,
- n.IsPart,
- n.Remark,
- })
- .ExecuteCommandAsync();
- //记录节点日志
- await LogNodeOpAsync(nodeBefore, node, "Update", currUserId);
- //当前节点未完成则更改节点状态为已完成
- if (node.OverallStatus == ProcessStatus.InProgress && isDtNul)
- {
- var statusResult = await UpdateNodeStatusSimpleAsync(node.Id,dto.CurrUserId);
-
- //日志记录执行结果
- _logger.LogInformation($"团组流程设置完成时间:调用更改状态接口(SetActualDoneAsync -> UpdateNodeStatusAsync):[状态变更:进行中 -> 已完成] result: Code={statusResult.Code}, Msg={statusResult.Msg}");
- }
- //当前节点 实际完成时间设置为空且当前状态为已完成 则更改当前节点状态为进行中
- else if (node.OverallStatus == ProcessStatus.Completed && !isDtNul)
- {
- var statusResult = await UpdateNodeStatusSimpleAsync(node.Id, dto.CurrUserId, ProcessStatus.InProgress);
- //日志记录执行结果
- _logger.LogInformation($"团组流程设置完成时间调:用更改状态接口(SetActualDoneAsync -> UpdateNodeStatusAsync):[状态变更:已完成 -> 进行中] result: Code={statusResult.Code}, Msg={statusResult.Msg}");
- }
- return new Result { Code = 200, Msg = "设置成功。" };
- }
- #endregion
- #region 会务流程
- /// <summary>
- /// 设置节点流程模板
- /// </summary>
- /// <param name="groupId"></param>
- /// <param name="currUserId"></param>
- /// <returns></returns>
- public async Task<List<Grp_ConfProcessOverview>> DefaultConfProcessTemps(int groupId, int currUserId)
- {
- var temps = new List<Grp_ConfProcessOverview>();
- //团组验证
- var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(g => g.Id == groupId);
- if (groupInfo == null) return temps;
- //// 检查是否已存在流程
- //var existingProcesses = await _sqlSugar.Queryable<Grp_ConfProcessOverview>()
- // .Where(p => p.IsDel == 0 && p.GroupId == groupId)
- // .ToListAsync();
- //if (existingProcesses.Any()) return temps;
- var users = await _sqlSugar.Queryable<Sys_Users>()
- .LeftJoin<Sys_Company>((u, c) => u.CompanyId == c.Id)
- .LeftJoin<Sys_Department>((u, c, d) => u.DepId == d.Id)
- .LeftJoin<Sys_JobPost>((u, c, d, jp) => u.JobPostId == jp.Id)
- .Where((u, c, d, jp) => u.IsDel == 0)
- .Select((u, c, d, jp) => new {
- u.Id,
- u.CnName,
- u.CompanyId,
- c.CompanyName,
- u.DepId,
- d.DepName,
- u.JobPostId,
- jp.JobName,
- })
- .ToListAsync();
- //节点可操作用户列表
- var nodeOpUsers = users.Where(u =>
- u.JobName != null && u.DepName.Contains("策划部")
- ).Select(u => u.Id)
- .ToList();
- #region 会务流程
- //参与人 participators
- var defaultParticipators = new List<int>()
- {
- 213, //李新江
- };
- var defaultPorc1 = new List<Grp_ConfProcessNode>() {
- Grp_ConfProcessNode.Create(1,"方案/报价(含成本)","", ProcessStatus.InProgress,true,false, currUserId,defaultParticipators,nodeOpUsers),
- Grp_ConfProcessNode.Create(2,"项目前期比选/招投标相关文件","", ProcessStatus.InProgress,false,false, currUserId,defaultParticipators,nodeOpUsers),
- Grp_ConfProcessNode.Create(3,"参与投标","", ProcessStatus.InProgress,false,false, currUserId,defaultParticipators,nodeOpUsers),
- Grp_ConfProcessNode.Create(4,"拟定/签订合同","", ProcessStatus.InProgress,false,false, currUserId,defaultParticipators,nodeOpUsers),
- Grp_ConfProcessNode.Create(5,"场地预订/物料设计/对接活动所需的供应商/嘉宾邀约","", ProcessStatus.InProgress,false,false, currUserId,defaultParticipators,nodeOpUsers),
- Grp_ConfProcessNode.Create(6,"现场执行","", ProcessStatus.InProgress,false,false, currUserId,defaultParticipators,nodeOpUsers),
- Grp_ConfProcessNode.Create(7,"验收报告/决算表","", ProcessStatus.InProgress,false,false, currUserId,defaultParticipators,nodeOpUsers),
- Grp_ConfProcessNode.Create(8,"跟进项目收款","", ProcessStatus.InProgress,false,true, currUserId,defaultParticipators,nodeOpUsers),
- //Grp_ConfProcessNode.Create(9,"票据上传","该项目相关票据", ProcessStatus.InProgress,false,true, currUserId,defaultParticipators,nodeOpUsers),
- };
- temps.Add(Grp_ConfProcessOverview.Create(groupId, 1, ProcessStatus.InProgress, currUserId, defaultPorc1));
- var defaultPorc2 = new List<Grp_ConfProcessNode>() {
- Grp_ConfProcessNode.Create(1,"方案/报价(含成本)","", ProcessStatus.InProgress,true,false, currUserId,defaultParticipators,nodeOpUsers),
- Grp_ConfProcessNode.Create(2,"拟定/签订合同","", ProcessStatus.InProgress,false,false, currUserId,defaultParticipators,nodeOpUsers),
- Grp_ConfProcessNode.Create(3,"场地预订/物料设计/对接活动所需的供应商/嘉宾邀约","", ProcessStatus.InProgress,false,false, currUserId,defaultParticipators,nodeOpUsers),
- Grp_ConfProcessNode.Create(4,"现场执行","", ProcessStatus.InProgress,false,false, currUserId,defaultParticipators,nodeOpUsers),
- Grp_ConfProcessNode.Create(5,"验收报告/决算表","", ProcessStatus.InProgress,false,false, currUserId,defaultParticipators,nodeOpUsers),
- Grp_ConfProcessNode.Create(6,"跟进项目收款","", ProcessStatus.InProgress,false,true, currUserId,defaultParticipators,nodeOpUsers),
- //Grp_ConfProcessNode.Create(7,"票据上传","该项目相关票据", ProcessStatus.InProgress,false,true, currUserId,defaultParticipators,nodeOpUsers),
- };
- temps.Add(Grp_ConfProcessOverview.Create(groupId, 2, ProcessStatus.InProgress, currUserId, defaultPorc2));
- #endregion
- return temps;
- }
- /// <summary>
- /// 团组会务流程初始化
- /// </summary>
- /// <param name="groupId">团组Id</param>
- /// <param name="currUserId">当前用户Id</param>
- /// <param name="nodeTempId">节点模板Id</param>
- /// <returns>创建的流程信息</returns>
- public async Task<Result> ConfProcessInitAsync(int groupId, int currUserId,int nodeTempId = 1)
- {
- //团组验证
- var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(g => g.Id == groupId);
- if (groupInfo == null)
- {
- return new Result { Code = 400, Msg = "团组不存在" };
- }
- // 检查是否已存在流程
- var existingProcesses = await _sqlSugar.Queryable<Grp_ConfProcessOverview>()
- .Where(p => p.IsDel == 0 && p.GroupId == groupId)
- .ToListAsync();
- if (existingProcesses.Any())
- {
- return new Result { Code = 400, Msg = "团组会务流程已存在" };
- }
- // 定义默认的流程节点
- var temps = await DefaultConfProcessTemps(groupId, currUserId);
- if (temps == null || temps.Count < 1)
- return new Result { Code = 400, Msg = "团组会务默认流程不存在" };
- var process = temps.FirstOrDefault(x => x.ProcessOrder == nodeTempId);
- process.CreateUserId = currUserId;
- _sqlSugar.BeginTran();
- try
- {
- var processId = await _sqlSugar.Insertable(process).ExecuteReturnIdentityAsync();
- if (processId < 1)
- {
- _sqlSugar.RollbackTran();
- return new Result { Code = 400, Msg = "团组会务流程进度总览添加失败!" };
- }
- process.Id = processId;
- // 记录流程日志
- await LogConfProcessOpAsync(null, process, "Create", currUserId);
- var nodes = process.Nodes.Select((nodeDto, index) => new Grp_ConfProcessNode
- {
- ProcessId = processId,
- NodeName = nodeDto.NodeName,
- NodeOrder = nodeDto.NodeOrder,
- Participators = nodeDto.Participators,
- OpUserList = nodeDto.OpUserList,
- OverallStatus = nodeDto.OverallStatus,
- NodeDescTips = nodeDto.NodeDescTips,
- //Country = nodeDto.Country,
- IsCurrent = nodeDto.IsCurrent,
- IsFileUp = nodeDto.IsFileUp,
- Remark = nodeDto.Remark,
- CreateUserId = currUserId,
- }).ToList();
- var nodeIds = await _sqlSugar.Insertable(nodes).ExecuteCommandAsync();
- if (nodeIds < 1)
- {
- _sqlSugar.RollbackTran();
- return new Result { Code = 400, Msg = "团组流程进度流程节点添加失败!" };
- }
- //设置节点ID
- nodes = await _sqlSugar.Queryable<Grp_ConfProcessNode>().Where(x => x.IsDel == 0 && x.ProcessId == processId).ToListAsync();
- //记录节点日志
- foreach (var node in nodes)
- {
- await LogConfNodeOpAsync(null, node, "Create", currUserId);
- }
- _sqlSugar.CommitTran();
- return new Result { Code = 200, Msg = "添加成功!" };
- }
- catch (Exception ex)
- {
- _sqlSugar.RollbackTran();
- return new Result { Code = 500, Msg = $"操作失败!msg:{ex.Message}" };
- }
- }
- /// <summary>
- /// 获取团组会务流程及节点详情
- /// </summary>
- /// <param name="groupId">团组Id</param>
- /// <param name="currUserId">当前用户Id</param>
- /// <returns></returns>
- public async Task<Result> ConfProcessesDetailsAsync(int groupId, int currUserId = 4)
- {
- //团组验证
- var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(g => g.Id == groupId);
- if (groupInfo == null)
- {
- return new Result { Code = 400, Msg = "团组不存在" };
- }
- // 检查是否已存在流程
- var existingProcesses = await _sqlSugar.Queryable<Grp_ConfProcessOverview>()
- .Where(p => p.IsDel == 0 && p.GroupId == groupId)
- .ToListAsync();
- if (!existingProcesses.Any())
- {
- //新建团组流程
- var res = await ConfProcessInitAsync(groupId, currUserId);
- if (res.Code != 200)
- {
- return res;
- }
- }
- var users = await _sqlSugar.Queryable<Sys_Users>().Select(x => new { x.Id, x.CnName }).ToListAsync();
- var processData = await _sqlSugar.Queryable<Grp_ConfProcessOverview>()
- .Where(p => p.GroupId == groupId && p.IsDel == 0)
- .Mapper(p => p.Nodes, p => p.Nodes.First().ProcessId)
- .ToListAsync();
- // 预先构建用户字典,提升查询性能
- var userDict = users.ToDictionary(u => u.Id, u => u.CnName);
- bool isNodeTemplSwitchable = true;
- var processes = processData.Select(p =>
- {
- var orderedNodes = p.Nodes.OrderBy(n => n.NodeOrder).ToList();
- var totalNodes = orderedNodes.Count;
- isNodeTemplSwitchable = p.OverallStatus != ProcessStatus.Completed;
- return new ConfProcessOverInfoView()
- {
- Id = p.Id,
- GroupId = p.GroupId,
- ProcessType = p.ProcessType,
- ProcessName = p.ProcessType.GetEnumDescription(),
- Nodes = orderedNodes.Select((n, index) =>
- {
- var isLastNode = index == totalNodes - 1;
- // 文件上传按钮启用规则
- bool isEnaFileUpBtn = false;
- if (isLastNode)
- {
- isEnaFileUpBtn = true;
- }
- // 获取操作人姓名(使用字典提升性能)
- string operatorName = "-";
- if (n.Operator.HasValue && userDict.TryGetValue(n.Operator.Value, out var name))
- {
- operatorName = name;
- }
- return new ConfProcessNodeInfoView()
- {
- Id = n.Id,
- ProcessId = n.ProcessId,
- NodeOrder = n.NodeOrder,
- NodeName = n.NodeName,
- NodeDescTips = n.NodeDescTips,
- OverallStatus = n.OverallStatus,
- Participators = n.Participators,
- OpUserList = n.OpUserList,
- StatusText = n.OverallStatus.GetEnumDescription(),
- Operator = operatorName,
- OpeateTime = n.OperationTime?.ToString("yyyy-MM-dd HH:mm:ss") ?? "-",
- ActualDone = n.ActualDone?.ToString("yyyy-MM-dd HH:mm:ss") ?? "",
- IsEnaFileUpBtn = isEnaFileUpBtn,
- IsFileUp = n.IsFileUp, // 票据上传节点 存储值
- Remark = n.Remark
- };
- }).ToList()
- };
- }).ToList();
- var view = new ConfProcessOverInfo()
- {
- IsNodeTemplSwitchable = isNodeTemplSwitchable,
- ConfProcess = processes
- };
- return new Result { Code = 200, Data = view, Msg = "查询成功!" };
- }
- /// <summary>
- /// 更新节点模板
- /// </summary>
- /// <param name="groupId">团组Id</param>
- /// <param name="nodeTempId">节点模板Id</param>
- /// <param name="currUserId">当前用户Id</param>
- /// <returns></returns>
- public async Task<Result> ConfProcessChangeNodeTempSaveAsync(int groupId, int nodeTempId, int currUserId)
- {
- //节点模板id验证
- var nodeTempIds = new List<int>() { 1, 2 };
- if (!nodeTempIds.Contains(nodeTempId))
- {
- return new Result { Code = 400, Msg = "请传入有效的节点模板Id" };
- }
- //团组验证
- var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(g => g.Id == groupId);
- if (groupInfo == null)
- {
- return new Result { Code = 400, Msg = "团组不存在" };
- }
- _sqlSugar.BeginTran();
- try
- {
- // 检查是否已存在流程
- var existingProcesses = await _sqlSugar.Queryable<Grp_ConfProcessOverview>()
- .Where(p => p.IsDel == 0 && p.GroupId == groupId)
- .ToListAsync();
- if (existingProcesses.Any())
- {
- // 用户权限验证
- var firstNode = await _sqlSugar.Queryable<Grp_ConfProcessNode>().FirstAsync(x => x.IsDel == 0 && x.ProcessId == existingProcesses.FirstOrDefault().Id);
- if (!HasConfNodeOperationPermission(firstNode, currUserId))
- {
- return new Result { Code = 400, Msg = "当前用户没有操作此节点的权限。" };
- }
- //团组会流程完成 不可切换模板
- if (existingProcesses.Where(x => x.OverallStatus == ProcessStatus.Completed).ToList().Count > 0)
- {
- _sqlSugar.RollbackTran();
- return new Result { Code = 400, Msg = $"当前团组会务流程已完成,不可切换节点模板。" };
- }
- //删除 原有的节点模板
- var parentIds = existingProcesses.Select(x => x.Id).ToList();
- var updProcesses = await _sqlSugar.Updateable<Grp_ConfProcessOverview>()
- .SetColumns(x => x.DeleteUserId == currUserId)
- .SetColumns(x => x.DeleteTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
- .SetColumns(x => x.IsDel == 1)
- .Where(x => parentIds.Contains(x.Id))
- .ExecuteCommandAsync();
- var updProcessNodes = await _sqlSugar.Updateable<Grp_ConfProcessNode>()
- .SetColumns(x => x.DeleteUserId == currUserId)
- .SetColumns(x => x.DeleteTime == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
- .SetColumns(x => x.IsDel == 1)
- .Where(x => parentIds.Contains(x.ProcessId))
- .ExecuteCommandAsync();
- }
- //更新模板节点信息
- var result = await ConfProcessInitAsync(groupId,currUserId,nodeTempId);
- if (result.Code == 200)
- {
- var infoResult = await ConfProcessesDetailsAsync(groupId, currUserId);
- if (infoResult.Code == 200)
- {
- _sqlSugar.CommitTran();
- return infoResult;
- }
- }
- _sqlSugar.RollbackTran();
- return new Result { Code = 500, Msg = $"操作失败!Msg:{result.Msg}" };
- }
- catch (Exception ex)
- {
- _sqlSugar.RollbackTran();
- return new Result { Code = 500, Msg = $"操作失败!Msg:{ex.Message}" };
- }
- }
- #region 状态变更 可操作任意节点 进行中<-->已完成 双向变更
- /// <summary>
- /// 更新节点状态(支持任意节点状态变更,无需处理当前节点)
- /// </summary>
- /// <param name="nodeId"></param>
- /// <param name="currUserId"></param>
- /// <param name="targetStatus"></param>
- /// <returns></returns>
- public async Task<Result> UpdateConfNodeStatusSimpleAsync(int nodeId, int currUserId, ProcessStatus targetStatus = ProcessStatus.Completed)
- {
- try
- {
- var result = await _sqlSugar.Ado.UseTranAsync(async () =>
- {
- // 1. 获取节点和流程信息
- var node = await _sqlSugar.Queryable<Grp_ConfProcessNode>()
- .FirstAsync(n => n.Id == nodeId && n.IsDel == 0);
- if (node == null) return new Result { Code = StatusCodes.Status400BadRequest, Msg = "当前节点不存在或已被删除。" };
- // 2. 用户权限验证
- if (!HasConfNodeOperationPermission(node, currUserId))
- {
- return new Result { Code = StatusCodes.Status400BadRequest, Msg = "当前用户没有操作此节点的权限。" };
- }
- var process = await _sqlSugar.Queryable<Grp_ConfProcessOverview>()
- .FirstAsync(p => p.Id == node.ProcessId && p.IsDel == 0);
- if (process == null) return new Result { Code = StatusCodes.Status400BadRequest, Msg = "关联的流程不存在。" };
- // 3. 检查是否重复操作
- if (node.OverallStatus == targetStatus)
- {
- return new Result { Code = StatusCodes.Status400BadRequest, Msg = "当前节点已为{GetStatusDescription(targetStatus)}状态,无需重复操作。。" };
- }
- // 4. 存储更新前的值
- var nodeBefore = CloneConfNode(node);
- var processBefore = CloneConfProcess(process);
- // 5. 更新节点状态
- node.OverallStatus = targetStatus;
- node.Operator = currUserId;
- node.OperationTime = DateTime.Now;
- // 6. 保存节点更新
- await _sqlSugar.Updateable(node)
- .UpdateColumns(n => new
- {
- n.OverallStatus,
- n.Operator,
- n.OperationTime
- })
- .ExecuteCommandAsync();
- // 7. 更新流程状态(基于所有节点的状态计算)
- await UpdateConfProcessOverallStatusAsync(process, currUserId);
- // 8. 记录日志
- await LogConfNodeOpAsync(nodeBefore, node, "Update", currUserId);
- await LogConfProcessOpAsync(processBefore, process, "Update", currUserId);
- return new Result { Code = StatusCodes.Status200OK, Msg = "操作成功。" };
- });
- return result.IsSuccess ? result.Data : new Result
- {
- Code = StatusCodes.Status500InternalServerError,
- Msg = result.ErrorMessage
- };
- }
- catch (BusinessException ex)
- {
- return new Result { Code = StatusCodes.Status400BadRequest, Msg = ex.Message };
- }
- catch (Exception ex)
- {
- return new Result { Code = StatusCodes.Status500InternalServerError, Msg = "系统错误,请稍后重试" };
- }
- }
- /// <summary>
- /// 更新流程整体状态(根据所有节点状态计算)
- /// </summary>
- /// <param name="process"></param>
- /// <param name="currUserId"></param>
- /// <returns></returns>
- private async Task UpdateConfProcessOverallStatusAsync(Grp_ConfProcessOverview process, int currUserId)
- {
- // 获取所有节点
- var allNodes = await _sqlSugar.Queryable<Grp_ConfProcessNode>()
- .Where(n => n.ProcessId == process.Id && n.IsDel == 0)
- .ToListAsync();
- // 统计节点状态
- int totalCount = allNodes.Count;
- int completedCount = allNodes.Count(n => n.OverallStatus == ProcessStatus.Completed);
- int inProgressCount = allNodes.Count(n => n.OverallStatus == ProcessStatus.InProgress);
- // 判断流程状态
- ProcessStatus newProcessStatus;
- if (completedCount == totalCount)
- {
- // 所有节点都已完成
- newProcessStatus = ProcessStatus.Completed;
- process.EndTime = DateTime.Now;
- }
- else if (inProgressCount > 0 || completedCount > 0)
- {
- // 有节点进行中或已完成
- newProcessStatus = ProcessStatus.InProgress;
- process.EndTime = null;
- }
- else
- {
- // 所有节点都未开始
- newProcessStatus = ProcessStatus.UnStarted;
- process.EndTime = null;
- }
- // 更新流程状态(只有状态变化时才更新)
- if (process.OverallStatus != newProcessStatus)
- {
- process.OverallStatus = newProcessStatus;
- process.UpdatedUserId = currUserId;
- process.UpdatedTime = DateTime.Now;
- await _sqlSugar.Updateable(process)
- .UpdateColumns(p => new
- {
- p.OverallStatus,
- p.EndTime,
- p.UpdatedUserId,
- p.UpdatedTime
- })
- .ExecuteCommandAsync();
- }
- }
- /// <summary>
- /// 验证用户是否有操作节点的权限
- /// </summary>
- private static bool HasConfNodeOperationPermission(Grp_ConfProcessNode node, int userId)
- {
- // 如果 OpUserList 为空或 null,表示不限制权限
- if (node.OpUserList == null || node.OpUserList.Count == 0)
- {
- return true;
- }
- // 检查当前用户是否在权限列表中
- return node.OpUserList.Contains(userId);
- }
- /// <summary>
- /// 克隆节点对象
- /// </summary>
- /// <param name="node"></param>
- /// <returns></returns>
- private static Grp_ConfProcessNode CloneConfNode(Grp_ConfProcessNode node)
- {
- return new Grp_ConfProcessNode()
- {
- Id = node.Id,
- ProcessId = node.ProcessId,
- NodeName = node.NodeName,
- NodeDescTips = node.NodeDescTips,
- NodeOrder = node.NodeOrder,
- OverallStatus = node.OverallStatus,
- Participators = node.Participators,
- Operator = node.Operator,
- OperationTime = node.OperationTime,
- IsCurrent = node.IsCurrent,
- ActualDone = node.ActualDone,
- IsFileUp = node.IsFileUp,
- OpUserList = node.OpUserList,
- };
- }
- /// <summary>
- /// 克隆流程对象
- /// </summary>
- /// <param name="process"></param>
- /// <returns></returns>
- private static Grp_ConfProcessOverview CloneConfProcess(Grp_ConfProcessOverview process)
- {
- return new Grp_ConfProcessOverview()
- {
- Id = process.Id,
- GroupId = process.GroupId,
- ProcessOrder = process.ProcessOrder,
- ProcessType = process.ProcessType,
- OverallStatus = process.OverallStatus,
- StartTime = process.StartTime,
- EndTime = process.EndTime,
- UpdatedUserId = process.UpdatedUserId,
- UpdatedTime = process.UpdatedTime
- };
- }
- #endregion
- #region 更新节点状态 流程导向
- /// <summary>
- /// 更新团组会务流程节点状态
- /// </summary>
- /// <param name="nodeId">节点ID</param>
- /// <param name="currUserId">当前用户ID</param>
- /// <param name="processStatus">流程状态,默认为已完成</param>
- /// <returns>操作结果</returns>
- public async Task<Result> UpdateConfNodeStatusAsync(int nodeId, int currUserId, ProcessStatus processStatus = ProcessStatus.Completed)
- {
- try
- {
- // 使用事务确保数据一致性
- var result = await _sqlSugar.Ado.UseTranAsync(async () =>
- {
- // 1. 获取并验证节点
- var node = await _sqlSugar.Queryable<Grp_ConfProcessNode>()
- .FirstAsync(n => n.Id == nodeId && n.IsDel == 0) ?? throw new BusinessException("当前节点不存在或已被删除。");
- // 2. 获取流程信息,检查ProcessType
- var process = await _sqlSugar.Queryable<Grp_ConfProcessOverview>()
- .FirstAsync(p => p.Id == node.ProcessId && p.IsDel == 0) ?? throw new BusinessException("关联的流程不存在。");
- // 3. 节点操作验证
- ValidateConfNodeOperation(node, processStatus);
- // 4. 存储更新前的值
- var before = CloneConfNode(node);
- // 5. 更新节点状态
- node.OverallStatus = processStatus;
- node.Operator = currUserId;
- node.OperationTime = DateTime.Now;
- var updateCount = await _sqlSugar.Updateable(node)
- .UpdateColumns(n => new
- {
- n.OverallStatus,
- n.Operator,
- n.OperationTime
- })
- .ExecuteCommandAsync();
- if (updateCount == 0)
- {
- throw new BusinessException("节点状态更新失败。");
- }
- // 6. 记录节点日志
- await LogConfNodeOpAsync(before, node, "Update", currUserId);
- // 7. 如果是完成当前节点,处理流程流转
- if (processStatus == ProcessStatus.Completed)
- {
- await ConfProcessCurrentNodeCompletionAsync(node, currUserId);
- }
- return new Result { Code = StatusCodes.Status200OK, Msg = "操作成功。" };
- });
- return result.IsSuccess ? result.Data : new Result
- {
- Code = StatusCodes.Status500InternalServerError,
- Msg = result.ErrorMessage
- };
- }
- catch (BusinessException ex)
- {
- // 业务异常
- return new Result { Code = StatusCodes.Status400BadRequest, Msg = ex.Message };
- }
- catch (Exception ex)
- {
- // 系统异常
- return new Result { Code = StatusCodes.Status500InternalServerError, Msg = "系统错误,请稍后重试" };
- }
- }
- /// <summary>
- /// 验证会务流程节点操作权限
- /// </summary>
- /// <param name="node">流程节点</param>
- /// <param name="targetStatus">目标状态</param>
- private static void ValidateConfNodeOperation(Grp_ConfProcessNode node, ProcessStatus targetStatus)
- {
- // 验证节点是否已完成
- if (node.OverallStatus == ProcessStatus.Completed)
- {
- throw new BusinessException("当前节点已完成,不可重复操作。");
- }
- // 验证状态流转是否合法(可选)
- //if (targetStatus != ProcessStatus.Completed)
- //{
- // throw new BusinessException("未开始或者进行中的节点只能重新完成,不可进行其他操作。");
- //}
- // 验证是否尝试将已完成节点改为其他状态
- if (node.OverallStatus == ProcessStatus.Completed && targetStatus != ProcessStatus.Completed)
- {
- throw new BusinessException("已完成节点不可修改状态。");
- }
- }
- /// <summary>
- /// 处理当前会务流程节点完成后的流程流转
- /// </summary>
- private async Task ConfProcessCurrentNodeCompletionAsync(Grp_ConfProcessNode currentNode, int currUserId)
- {
- // 1. 获取流程信息
- var process = await _sqlSugar.Queryable<Grp_ConfProcessOverview>()
- .FirstAsync(p => p.Id == currentNode.ProcessId && p.IsDel == 0) ?? throw new BusinessException("关联的流程不存在。");
- var processBefore = new Grp_ConfProcessOverview()
- {
- Id = process.Id,
- GroupId = process.GroupId,
- ProcessOrder = process.ProcessOrder,
- ProcessType = process.ProcessType,
- OverallStatus = process.OverallStatus,
- StartTime = process.StartTime,
- EndTime = process.EndTime,
- UpdatedUserId = process.UpdatedUserId,
- UpdatedTime = process.UpdatedTime
- };
- // 2. 取消当前节点的当前状态
- var before = new Grp_ConfProcessNode()
- {
- Id = currentNode.Id,
- ProcessId = currentNode.ProcessId,
- NodeName = currentNode.NodeName,
- NodeOrder = currentNode.NodeOrder,
- OverallStatus = currentNode.OverallStatus,
- Operator = currentNode.Operator,
- OperationTime = currentNode.OperationTime,
- IsCurrent = currentNode.IsCurrent,
- };
- currentNode.IsCurrent = false;
- await _sqlSugar.Updateable(currentNode)
- .UpdateColumns(n => new { n.IsCurrent })
- .ExecuteCommandAsync();
- // 2.1 记录节点日志 取消当前节点状态
- await LogConfNodeOpAsync(before, currentNode, "Update", currUserId);
- // 3. 查找并激活下一个节点
- var nextNode = await _sqlSugar.Queryable<Grp_ConfProcessNode>()
- .Where(n => n.ProcessId == currentNode.ProcessId
- && n.NodeOrder == currentNode.NodeOrder + 1
- && n.IsDel == 0)
- .FirstAsync();
- if (nextNode != null)
- {
- var nextNodeBefore = new Grp_ConfProcessNode()
- {
- Id = nextNode.Id,
- ProcessId = nextNode.ProcessId,
- NodeName = nextNode.NodeName,
- NodeOrder = nextNode.NodeOrder,
- OverallStatus = nextNode.OverallStatus,
- Operator = nextNode.Operator,
- OperationTime = nextNode.OperationTime,
- IsCurrent = nextNode.IsCurrent,
- };
- // 激活下一个节点
- nextNode.IsCurrent = true;
- nextNode.OverallStatus = ProcessStatus.InProgress;
- var updateCount = await _sqlSugar.Updateable(nextNode)
- .UpdateColumns(n => new
- {
- n.IsCurrent,
- n.OverallStatus,
- n.Operator,
- n.OperationTime
- })
- .ExecuteCommandAsync();
- if (updateCount == 0)
- {
- throw new BusinessException("激活下一节点失败");
- }
- // 1.1 记录节点日志 激活下一节点当前节点状态
- await LogConfNodeOpAsync(nextNodeBefore, nextNode, "Start", currUserId);
- // 更新流程状态为进行中
- process.OverallStatus = ProcessStatus.InProgress;
- }
- else
- {
- // 下一节点不存在,整个流程完成
- process.OverallStatus = ProcessStatus.Completed;
- process.EndTime = DateTime.Now;
- }
- // 4. 更新流程信息
- process.UpdatedUserId = currUserId;
- process.UpdatedTime = DateTime.Now;
- var processUpdateCount = await _sqlSugar.Updateable(process)
- .UpdateColumns(p => new
- {
- p.OverallStatus,
- p.EndTime,
- p.UpdatedUserId,
- p.UpdatedTime
- })
- .ExecuteCommandAsync();
- if (processUpdateCount == 0)
- {
- throw new BusinessException("流程状态更新失败。");
- }
- //记录流程日志
- await LogConfProcessOpAsync(processBefore, process, "Update", currUserId);
- }
- #endregion
- /// <summary>
- /// 更新节点信息
- /// </summary>
- /// <param name="dto">更新节点信息</param>
- /// <returns>操作结果</returns>
- public async Task<Result> SetNodeInfoAsync(ConfProcessSetActualDoneDto dto)
- {
- //参与人验证
- if (dto.Participators?.Any() != true) return new Result { Code = 400, Msg = "参与人不能为空。" };
- var isDtNul = DateTime.TryParse(dto.ActualDone, out DateTime actualDone);
- //if (!isDtNul) throw new BusinessException("实际操作时间为空或者格式不对。");
- int nodeId = dto.NodeId;
- int currUserId = dto.CurrUserId;
- bool isFileUp = dto.IsFileUp;
- // 1. 获取并验证节点和流程
- var node = await _sqlSugar.Queryable<Grp_ConfProcessNode>()
- .FirstAsync(n => n.Id == nodeId && n.IsDel == 0);
- if (node == null) return new Result { Code = 400, Msg = "当前节点不存在或已被删除。" };
- // 1.2. 用户权限验证
- if (!HasConfNodeOperationPermission(node, currUserId)) return new Result { Code = 400, Msg = "当前用户没有操作此节点的权限。" };
- var process = await _sqlSugar.Queryable<Grp_ConfProcessOverview>()
- .FirstAsync(p => p.Id == node.ProcessId && p.IsDel == 0);
- if (process == null) return new Result { Code = 400, Msg = "当前流程不存在或已被删除。" };
- // 2.1 存储更新前流程及节点信息
- var nodeBefore = CloneConfNode(node);
- if (isDtNul) node.ActualDone = actualDone;
- else node.ActualDone = null;
- node.IsFileUp = isFileUp;
- node.Participators = dto.Participators;
- node.Remark = dto.Remark;
- // 3. 保存节点更新
- await _sqlSugar.Updateable(node)
- .UpdateColumns(n => new
- {
- n.ActualDone,
- n.Participators,
- n.IsFileUp,
- n.Remark
- })
- .ExecuteCommandAsync();
- //记录节点日志
- await LogConfNodeOpAsync(nodeBefore, node, "Update", currUserId);
- //当前节点未完成则更改节点状态为已完成
- if (node.OverallStatus == ProcessStatus.InProgress && isDtNul)
- {
- var statusResult = await UpdateConfNodeStatusSimpleAsync(node.Id, dto.CurrUserId);
- //日志记录执行结果
- _logger.LogInformation($"团组流程设置完成时间:调用更改状态接口(SetActualDoneAsync -> UpdateNodeStatusAsync):[状态变更:进行中 -> 已完成] result: Code={statusResult.Code}, Msg={statusResult.Msg}");
- }
- //当前节点 实际完成时间设置为空且当前状态为已完成 则更改当前节点状态为进行中
- else if (node.OverallStatus == ProcessStatus.Completed && !isDtNul)
- {
- var statusResult = await UpdateConfNodeStatusSimpleAsync(node.Id, dto.CurrUserId, ProcessStatus.InProgress);
- //日志记录执行结果
- _logger.LogInformation($"团组流程设置完成时间调:用更改状态接口(SetActualDoneAsync -> UpdateNodeStatusAsync):[状态变更:已完成 -> 进行中] result: Code={statusResult.Code}, Msg={statusResult.Msg}");
- }
- return new Result { Code = 200, Msg = "设置成功。" };
- }
- #endregion
- #region 操作日志
- #region 团组流程
- /// <summary>
- /// 记录流程操作日志
- /// </summary>
- /// <param name="before">操作前</param>
- /// <param name="after">操作后</param>
- /// <param name="opType">操作类型(Create - 创建、Update - 更新、Complete - 完成)</param>
- /// <param name="operId">操作人ID</param>
- /// <returns>异步任务</returns>
- public async Task LogProcessOpAsync(Grp_ProcessOverview? before, Grp_ProcessOverview? after, string opType, int operId)
- {
- var chgDetails = GetProcessChgDetails(before, after);
- var log = new Grp_ProcessLog
- {
- ProcessId = after?.Id ?? before?.Id,
- GroupId = after?.GroupId ?? before?.GroupId ?? 0,
- OpType = opType,
- OpDesc = GenerateProcessOpDesc(opType, before, after, chgDetails),
- BeforeData = before != null ? JsonConvert.SerializeObject(before, GetJsonSettings()) : null,
- AfterData = after != null ? JsonConvert.SerializeObject(after, GetJsonSettings()) : null,
- ChgFields = string.Join(",", chgDetails.Select(x => x.FieldName)),
- CreateUserId = operId
- };
- await _sqlSugar.Insertable(log).ExecuteCommandAsync();
- }
- /// <summary>
- /// 记录节点操作日志
- /// </summary>
- /// <param name="before">操作前</param>
- /// <param name="after">操作后</param>
- /// <param name="opType">操作类型(Create - 创建、Update - 更新、Start - 启动、Complete - 完成)</param>
- /// <param name="operId">操作人ID</param>
- /// <returns>异步任务</returns>
- public async Task LogNodeOpAsync(Grp_ProcessNode? before, Grp_ProcessNode? after, string opType, int operId)
- {
- var chgDetails = GetNodeChgDetails(before, after);
- var log = new Grp_ProcessLog
- {
- NodeId = after?.Id ?? before?.Id,
- ProcessId = after?.ProcessId ?? before?.ProcessId,
- GroupId = 0, // 通过流程ID关联获取
- OpType = opType,
- OpDesc = GenerateNodeOpDesc(opType, before, after, chgDetails),
- BeforeData = before != null ? JsonConvert.SerializeObject(before, GetJsonSettings()) : null,
- AfterData = after != null ? JsonConvert.SerializeObject(before, GetJsonSettings()) : null,
- ChgFields = string.Join(",", chgDetails.Select(x => x.FieldName)),
- CreateUserId = operId
- };
- await _sqlSugar.Insertable(log).ExecuteCommandAsync();
- }
- /// <summary>
- /// 获取流程变更详情
- /// </summary>
- /// <param name="before">变更前</param>
- /// <param name="after">变更后</param>
- /// <returns>变更详情</returns>
- private List<FieldChgDetail> GetProcessChgDetails(Grp_ProcessOverview before, Grp_ProcessOverview after)
- {
- var chgDetails = new List<FieldChgDetail>();
- if (before == null || after == null) return chgDetails;
- var props = typeof(Grp_ProcessOverview).GetProperties(BindingFlags.Public | BindingFlags.Instance)
- .Where(p => p.CanRead && p.CanWrite && !IsExclField(p.Name));
- foreach (var prop in props)
- {
- var beforeVal = prop.GetValue(before);
- var afterVal = prop.GetValue(after);
- if (!Equals(beforeVal, afterVal))
- {
- chgDetails.Add(new FieldChgDetail
- {
- FieldName = prop.Name,
- BeforeValue = FormatVal(beforeVal),
- AfterValue = FormatVal(afterVal)
- });
- }
- }
- return chgDetails;
- }
- /// <summary>
- /// 获取节点变更详情
- /// </summary>
- /// <param name="before">变更前</param>
- /// <param name="after">变更后</param>
- /// <returns>变更详情</returns>
- private List<FieldChgDetail> GetNodeChgDetails(Grp_ProcessNode before, Grp_ProcessNode after)
- {
- var chgDetails = new List<FieldChgDetail>();
- if (before == null || after == null) return chgDetails;
- var props = typeof(Grp_ProcessNode).GetProperties(BindingFlags.Public | BindingFlags.Instance)
- .Where(p => p.CanRead && p.CanWrite && !IsExclField(p.Name));
- foreach (var prop in props)
- {
- var beforeVal = prop.GetValue(before);
- var afterVal = prop.GetValue(after);
- if (!Equals(beforeVal, afterVal))
- {
- chgDetails.Add(new FieldChgDetail
- {
- FieldName = prop.Name,
- BeforeValue = FormatVal(beforeVal),
- AfterValue = FormatVal(afterVal)
- });
- }
- }
- return chgDetails;
- }
- /// <summary>
- /// 生成流程操作描述
- /// </summary>
- /// <param name="opType">操作类型</param>
- /// <param name="before">操作前</param>
- /// <param name="after">操作后</param>
- /// <param name="chgDetails">变更详情</param>
- /// <returns>操作描述</returns>
- private string GenerateProcessOpDesc(string opType, Grp_ProcessOverview before,
- Grp_ProcessOverview after, List<FieldChgDetail> chgDetails)
- {
- var processType = after?.ProcessType ?? before?.ProcessType;
- var processName = GetProcessTypeName(processType);
- if (!chgDetails.Any())
- {
- return opType switch
- {
- "Create" => $"创建流程:{processName}",
- "Update" => $"更新流程:{processName} - 无变更",
- "Start" => $"启动流程:{processName}",
- "Complete" => $"完成流程:{processName}",
- "Delete" => $"删除流程:{processName}",
- _ => $"{opType}:{processName}"
- };
- }
- var chgDesc = string.Join("; ", chgDetails.Select(x =>
- $"{GetFieldDisplayName(x.FieldName)} ({x.BeforeValue} -> {x.AfterValue})"));
- return $"{GetOpTypeDisplay(opType)}:{processName} - {chgDesc}";
- }
- /// <summary>
- /// 生成节点操作描述
- /// </summary>
- /// <param name="opType">操作类型</param>
- /// <param name="before">操作前</param>
- /// <param name="after">操作后</param>
- /// <param name="chgDetails">变更详情</param>
- /// <returns>操作描述</returns>
- private string GenerateNodeOpDesc(string opType, Grp_ProcessNode before,
- Grp_ProcessNode after, List<FieldChgDetail> chgDetails)
- {
- var nodeName = after?.NodeName ?? before?.NodeName;
- if (!chgDetails.Any())
- {
- return opType switch
- {
- "Create" => $"创建节点:{nodeName}",
- "Update" => $"更新节点:{nodeName} - 无变更",
- "Start" => $"启动节点:{nodeName}",
- "Complete" => $"完成节点:{nodeName}",
- //"Delete" => $"删除节点:{nodeName}",
- _ => $"{opType}:{nodeName}"
- };
- }
- var chgDesc = string.Join("; ", chgDetails.Select(x =>
- $"{GetFieldDisplayName(x.FieldName)} ({x.BeforeValue} -> {x.AfterValue})"));
- return $"{GetOpTypeDisplay(opType)}:{nodeName} - {chgDesc}";
- }
- /// <summary>
- /// 获取流程类型名称
- /// </summary>
- /// <param name="processType">流程类型</param>
- /// <returns>流程名称</returns>
- private static string GetProcessTypeName(GroupProcessType? processType)
- {
- return processType switch
- {
- GroupProcessType.Invitation => "商邀报批",
- GroupProcessType.Visa => "签证",
- GroupProcessType.AirTicket => "机票",
- GroupProcessType.Hotel => "酒店",
- GroupProcessType.LocalGuide => "地接",
- GroupProcessType.FeeSettle => "费用结算",
- _ => "未知流程"
- };
- }
- /// <summary>
- /// 获取流程日志
- /// </summary>
- /// <param name="processId">流程ID</param>
- /// <returns>日志列表</returns>
- public async Task<List<Grp_ProcessLog>> GetProcessLogsAsync(int processId)
- {
- return await _sqlSugar.Queryable<Grp_ProcessLog>()
- .Where(x => x.ProcessId == processId)
- .OrderByDescending(x => x.CreateTime)
- .ToListAsync();
- }
- /// <summary>
- /// 获取团组流程日志
- /// </summary>
- /// <param name="groupId">团组ID</param>
- /// <returns>日志列表</returns>
- public async Task<List<Grp_ProcessLog>> GetGroupLogsAsync(int groupId)
- {
- return await _sqlSugar.Queryable<Grp_ProcessLog>()
- .Where(x => x.GroupId == groupId)
- .OrderByDescending(x => x.CreateTime)
- .ToListAsync();
- }
- #endregion
- #region 会务流程
- /// <summary>
- /// 记录会务流程操作日志
- /// </summary>
- /// <param name="before">操作前</param>
- /// <param name="after">操作后</param>
- /// <param name="opType">操作类型(Create - 创建、Update - 更新、Complete - 完成)</param>
- /// <param name="operId">操作人ID</param>
- /// <returns>异步任务</returns>
- public async Task LogConfProcessOpAsync(Grp_ConfProcessOverview? before, Grp_ConfProcessOverview? after, string opType, int operId)
- {
- var chgDetails = GetConfProcessChgDetails(before, after);
- var log = new Grp_ConfProcessLog
- {
- ProcessId = after?.Id ?? before?.Id,
- GroupId = after?.GroupId ?? before?.GroupId ?? 0,
- OpType = opType,
- OpDesc = GenerateConfProcessOpDesc(opType, before, after, chgDetails),
- BeforeData = before != null ? JsonConvert.SerializeObject(before, GetJsonSettings()) : null,
- AfterData = after != null ? JsonConvert.SerializeObject(after, GetJsonSettings()) : null,
- ChgFields = string.Join(",", chgDetails.Select(x => x.FieldName)),
- CreateUserId = operId
- };
- await _sqlSugar.Insertable(log).ExecuteCommandAsync();
- }
- /// <summary>
- /// 记录会务节点操作日志
- /// </summary>
- /// <param name="before">操作前</param>
- /// <param name="after">操作后</param>
- /// <param name="opType">操作类型(Create - 创建、Update - 更新、Start - 启动、Complete - 完成)</param>
- /// <param name="operId">操作人ID</param>
- /// <returns>异步任务</returns>
- public async Task LogConfNodeOpAsync(Grp_ConfProcessNode? before, Grp_ConfProcessNode? after, string opType, int operId)
- {
- var chgDetails = GetConfNodeChgDetails(before, after);
- var log = new Grp_ConfProcessLog
- {
- NodeId = after?.Id ?? before?.Id,
- ProcessId = after?.ProcessId ?? before?.ProcessId,
- GroupId = 0, // 通过流程ID关联获取
- OpType = opType,
- OpDesc = GenerateConfNodeOpDesc(opType, before, after, chgDetails),
- BeforeData = before != null ? JsonConvert.SerializeObject(before, GetJsonSettings()) : null,
- AfterData = after != null ? JsonConvert.SerializeObject(before, GetJsonSettings()) : null,
- ChgFields = string.Join(",", chgDetails.Select(x => x.FieldName)),
- CreateUserId = operId
- };
- await _sqlSugar.Insertable(log).ExecuteCommandAsync();
- }
- /// <summary>
- /// 获取流程变更详情
- /// </summary>
- /// <param name="before">变更前</param>
- /// <param name="after">变更后</param>
- /// <returns>变更详情</returns>
- private static List<FieldChgDetail> GetConfProcessChgDetails(Grp_ConfProcessOverview before, Grp_ConfProcessOverview after)
- {
- var chgDetails = new List<FieldChgDetail>();
- if (before == null || after == null) return chgDetails;
- var props = typeof(Grp_ConfProcessOverview).GetProperties(BindingFlags.Public | BindingFlags.Instance)
- .Where(p => p.CanRead && p.CanWrite && !IsExclField(p.Name));
- foreach (var prop in props)
- {
- var beforeVal = prop.GetValue(before);
- var afterVal = prop.GetValue(after);
- if (!Equals(beforeVal, afterVal))
- {
- chgDetails.Add(new FieldChgDetail
- {
- FieldName = prop.Name,
- BeforeValue = FormatVal(beforeVal),
- AfterValue = FormatVal(afterVal)
- });
- }
- }
- return chgDetails;
- }
- /// <summary>
- /// 获取节点变更详情
- /// </summary>
- /// <param name="before">变更前</param>
- /// <param name="after">变更后</param>
- /// <returns>变更详情</returns>
- private static List<FieldChgDetail> GetConfNodeChgDetails(Grp_ConfProcessNode before, Grp_ConfProcessNode after)
- {
- var chgDetails = new List<FieldChgDetail>();
- if (before == null || after == null) return chgDetails;
- var props = typeof(Grp_ConfProcessNode).GetProperties(BindingFlags.Public | BindingFlags.Instance)
- .Where(p => p.CanRead && p.CanWrite && !IsExclField(p.Name));
- foreach (var prop in props)
- {
- var beforeVal = prop.GetValue(before);
- var afterVal = prop.GetValue(after);
- if (!Equals(beforeVal, afterVal))
- {
- chgDetails.Add(new FieldChgDetail
- {
- FieldName = prop.Name,
- BeforeValue = FormatVal(beforeVal),
- AfterValue = FormatVal(afterVal)
- });
- }
- }
- return chgDetails;
- }
- /// <summary>
- /// 生成流程操作描述
- /// </summary>
- /// <param name="opType">操作类型</param>
- /// <param name="before">操作前</param>
- /// <param name="after">操作后</param>
- /// <param name="chgDetails">变更详情</param>
- /// <returns>操作描述</returns>
- private static string GenerateConfProcessOpDesc(string opType, Grp_ConfProcessOverview before,
- Grp_ConfProcessOverview after, List<FieldChgDetail> chgDetails)
- {
- var processType = after?.ProcessType ?? before?.ProcessType;
- var processName = GetConfProcessTypeName(processType);
- if (!chgDetails.Any())
- {
- return opType switch
- {
- "Create" => $"创建流程:{processName}",
- "Update" => $"更新流程:{processName} - 无变更",
- "Start" => $"启动流程:{processName}",
- "Complete" => $"完成流程:{processName}",
- "Delete" => $"删除流程:{processName}",
- _ => $"{opType}:{processName}"
- };
- }
- var chgDesc = string.Join("; ", chgDetails.Select(x =>
- $"{GetFieldDisplayName(x.FieldName)} ({x.BeforeValue} -> {x.AfterValue})"));
- return $"{GetOpTypeDisplay(opType)}:{processName} - {chgDesc}";
- }
- /// <summary>
- /// 生成节点操作描述
- /// </summary>
- /// <param name="opType">操作类型</param>
- /// <param name="before">操作前</param>
- /// <param name="after">操作后</param>
- /// <param name="chgDetails">变更详情</param>
- /// <returns>操作描述</returns>
- private static string GenerateConfNodeOpDesc(string opType, Grp_ConfProcessNode before,
- Grp_ConfProcessNode after, List<FieldChgDetail> chgDetails)
- {
- var nodeName = after?.NodeName ?? before?.NodeName;
- if (!chgDetails.Any())
- {
- return opType switch
- {
- "Create" => $"创建节点:{nodeName}",
- "Update" => $"更新节点:{nodeName} - 无变更",
- "Start" => $"启动节点:{nodeName}",
- "Complete" => $"完成节点:{nodeName}",
- //"Delete" => $"删除节点:{nodeName}",
- _ => $"{opType}:{nodeName}"
- };
- }
- var chgDesc = string.Join("; ", chgDetails.Select(x =>
- $"{GetFieldDisplayName(x.FieldName)} ({x.BeforeValue} -> {x.AfterValue})"));
- return $"{GetOpTypeDisplay(opType)}:{nodeName} - {chgDesc}";
- }
- /// <summary>
- /// 获取流程类型名称
- /// </summary>
- /// <param name="processType">流程类型</param>
- /// <returns>流程名称</returns>
- private static string GetConfProcessTypeName(ConfProcessType? processType)
- {
- return processType switch
- {
- ConfProcessType.Conference => "会务",
- _ => "未知流程"
- };
- }
- /// <summary>
- /// 获取会务流程日志
- /// </summary>
- /// <param name="processId">流程ID</param>
- /// <returns>日志列表</returns>
- public async Task<List<Grp_ConfProcessLog>> GetConfProcessLogsAsync(int processId)
- {
- return await _sqlSugar.Queryable<Grp_ConfProcessLog>()
- .Where(x => x.ProcessId == processId)
- .OrderByDescending(x => x.CreateTime)
- .ToListAsync();
- }
- /// <summary>
- /// 获取团组会务流程日志
- /// </summary>
- /// <param name="groupId">团组ID</param>
- /// <returns>日志列表</returns>
- public async Task<List<Grp_ConfProcessLog>> GetGroupConfLogsAsync(int groupId)
- {
- return await _sqlSugar.Queryable<Grp_ConfProcessLog>()
- .Where(x => x.GroupId == groupId)
- .OrderByDescending(x => x.CreateTime)
- .ToListAsync();
- }
- #endregion
- #region 日志私有方法
- /// <summary>
- /// 获取JSON序列化设置
- /// </summary>
- /// <returns>JSON设置</returns>
- private static JsonSerializerSettings GetJsonSettings()
- {
- return new JsonSerializerSettings
- {
- ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
- NullValueHandling = NullValueHandling.Ignore,
- DateFormatString = "yyyy-MM-dd HH:mm:ss",
- Formatting = Formatting.None
- };
- }
- /// <summary>
- /// 获取操作类型显示
- /// </summary>
- /// <param name="opType">操作类型</param>
- /// <returns>显示名称</returns>
- private static string GetOpTypeDisplay(string opType)
- {
- return opType switch
- {
- "Create" => "创建",
- "Update" => "更新",
- "Start" => "启动",
- "Complete" => "完成",
- "Delete" => "删除",
- "StatusChg" => "状态变更",
- _ => opType
- };
- }
- /// <summary>
- /// 获取字段显示名称
- /// </summary>
- /// <param name="fieldName">字段名</param>
- /// <returns>显示名称</returns>
- private static string GetFieldDisplayName(string fieldName)
- {
- return fieldName switch
- {
- "OverallStatus" => "状态",
- "ProcessOrder" => "流程顺序",
- "StartTime" => "开始时间",
- "EndTime" => "结束时间",
- "UpdatedUserId" => "更新人",
- "UpdatedTime" => "更新时间",
- "NodeOrder" => "节点顺序",
- "NodeName" => "节点名称",
- "NodeDescTips" => "节点描述提示",
- "IsCurrent" => "当前节点",
- "Participator" => "参与人",
- "Operator" => "操作人",
- "OperationTime" => "操作时间",
- "ActualDone" => "实际完成时间",
- "IsFileUp" => "是否上传文件(签证、机票、酒店、地接 流程结尾节点使用)",
- "IsAssist" => "是否协助(财务流程首节点使用)",
- "IsPart" => "是否参与(商邀 第五步使用)",
- _ => fieldName
- };
- }
- /// <summary>
- /// 格式化值显示
- /// </summary>
- /// <param name="value">值</param>
- /// <returns>格式化值</returns>
- private static string FormatVal(object value)
- {
- if (value == null) return "空";
- if (value is ProcessStatus status)
- {
- return status switch
- {
- ProcessStatus.UnStarted => "未开始",
- ProcessStatus.InProgress => "进行中",
- ProcessStatus.Completed => "已完成",
- _ => status.ToString()
- };
- }
- if (value is bool boolVal) return boolVal ? "是" : "否";
- if (value is DateTime dateVal) return dateVal.ToString("yyyy-MM-dd HH:mm");
- var strVal = value.ToString();
- return string.IsNullOrEmpty(strVal) ? "空" : strVal;
- }
- /// <summary>
- /// 检查是否排除字段
- /// </summary>
- /// <param name="fieldName">字段名</param>
- /// <returns>是否排除</returns>
- private static bool IsExclField(string fieldName)
- {
- var exclFields = new List<string>
- {
- "Id", "CreateTime", "CreateUserId", "Nodes", "Process" // 导航属性
- };
- return exclFields.Contains(fieldName);
- }
- #endregion
- #endregion
- }
- }
|