SystemController.cs 212 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493
  1. using Aspose.Cells;
  2. using NPOI.HPSF;
  3. using NPOI.POIFS.Crypt;
  4. using OASystem.API.OAMethodLib;
  5. using OASystem.API.OAMethodLib.DeepSeekAPI;
  6. using OASystem.API.OAMethodLib.GenericSearch;
  7. using OASystem.Domain.AesEncryption;
  8. using OASystem.Domain.Attributes;
  9. using OASystem.Domain.Entities;
  10. using OASystem.Domain.Entities.Customer;
  11. using OASystem.Domain.Entities.Financial;
  12. using OASystem.Domain.Entities.Groups;
  13. using System.Collections;
  14. using System.ComponentModel;
  15. using System.Data;
  16. using System.Dynamic;
  17. using System.Linq;
  18. using static OASystem.API.OAMethodLib.GeneralMethod;
  19. using static OASystem.API.OAMethodLib.JWTHelper;
  20. using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
  21. namespace OASystem.API.Controllers
  22. {
  23. /// <summary>
  24. /// 系统设置
  25. /// </summary>
  26. //[Authorize]
  27. [Route("api/[controller]/[action]")]
  28. public class SystemController : ControllerBase
  29. {
  30. private readonly CompanyRepository _syscomRep;
  31. private readonly DepartmentRepository _sysDepRep;
  32. private readonly UsersRepository _userRep;
  33. private readonly IMapper _mapper;
  34. private readonly IConfiguration _config;
  35. private readonly SqlSugarClient _sqlSugar;
  36. private readonly MessageRepository _messageRep;
  37. private readonly SetDataRepository _setDataRepository;
  38. private readonly SystemMenuPermissionRepository _SystemMenuPermissionRepository;
  39. private readonly CompanyRepository _CompanyRepository;
  40. private readonly PageFunctionPermissionRepository _PageFunctionPermissionRepository;
  41. private readonly SystemMenuAndFunctionRepository _SystemMenuAndFunctionRepository;
  42. private readonly JobPostAuthorityRepository _JobPostAuthorityRepository;
  43. private readonly JobPostRepository _jobRep;
  44. private readonly SetDataTypeRepository _setDataTypeRep;
  45. private readonly UserAuthorityRepository _UserAuthorityRepository;
  46. private readonly List<int> _operationTypeList = new() { 1, 2, 3, 4, 5 }; //操作通知所属类型
  47. private readonly List<int> _taskTypeList = new() { 6 };//任务通知 TaskNotification
  48. private readonly ApprovalProcessRepository _approvalProcessRep;
  49. private readonly IDeepSeekService _deepSeek;
  50. private readonly DynamicSearchService<Fin_DailyFeePayment> _dailyFeeSearchService;
  51. private readonly DynamicSearchService<Grp_DelegationInfo> _groupSearchService;
  52. public SystemController(
  53. CompanyRepository syscom,
  54. DepartmentRepository sysDepRep,
  55. UsersRepository userRep,
  56. IMapper mapper, IConfiguration config,
  57. SqlSugarClient sqlSugar,
  58. SetDataRepository setDataRepository,
  59. CompanyRepository companyRepository,
  60. SystemMenuPermissionRepository systemMenuPermissionRepository,
  61. PageFunctionPermissionRepository pageFunctionPermissionRepository,
  62. SystemMenuAndFunctionRepository systemMenuAndFunctionRepository,
  63. JobPostAuthorityRepository jobPostAuthorityRepository,
  64. JobPostRepository jobRep,
  65. UserAuthorityRepository userAuthorityRepository,
  66. MessageRepository messageRep,
  67. SetDataTypeRepository setDataTypeRep,
  68. ApprovalProcessRepository approvalProcessRep,
  69. IDeepSeekService deepSeek,
  70. DynamicSearchService<Fin_DailyFeePayment> dailyFeeSearchService,
  71. DynamicSearchService<Grp_DelegationInfo> groupSearchService
  72. )
  73. {
  74. _syscomRep = syscom;
  75. _sysDepRep = sysDepRep;
  76. _messageRep = messageRep;
  77. _userRep = userRep;
  78. _mapper = mapper;
  79. _sqlSugar = sqlSugar;
  80. _setDataRepository = setDataRepository;
  81. _CompanyRepository = companyRepository;
  82. _SystemMenuPermissionRepository = systemMenuPermissionRepository;
  83. _PageFunctionPermissionRepository = pageFunctionPermissionRepository;
  84. _SystemMenuAndFunctionRepository = systemMenuAndFunctionRepository;
  85. _JobPostAuthorityRepository = jobPostAuthorityRepository;
  86. _UserAuthorityRepository = userAuthorityRepository;
  87. _jobRep = jobRep;
  88. _setDataTypeRep = setDataTypeRep;
  89. _config = config;
  90. _approvalProcessRep = approvalProcessRep;
  91. _deepSeek = deepSeek;
  92. _dailyFeeSearchService = dailyFeeSearchService;
  93. _groupSearchService = groupSearchService;
  94. }
  95. #region ALL OA 多词条搜索
  96. /// <summary>
  97. /// 日付信息 单字段(申请原因)关键字输入提示
  98. /// </summary>
  99. /// <param name="keyword">关键字</param>
  100. /// <param name="auditType">审核类型 0 全部 1 张总未审核</param>
  101. /// <returns></returns>
  102. [HttpGet]
  103. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  104. public async Task<IActionResult> DailyFeeKeywordSearch(string keyword,int auditType)
  105. {
  106. try
  107. {
  108. // 验证请求参数
  109. if (string.IsNullOrEmpty(keyword))
  110. {
  111. return Ok(JsonView(true, $"暂无数据!"));
  112. }
  113. var searchFilters = new List<SearchFilter>()
  114. {
  115. new(){Field = "IsDel",Operator="eq",Value="0" }
  116. };
  117. //张总未审核过滤
  118. if (auditType == 1)
  119. {
  120. searchFilters.Add(new() { Field = "MAudit", Operator = "eq", Value = "0" });
  121. }
  122. var searchRequest = new DynamicSearchRequest
  123. {
  124. Keyword = keyword,
  125. RequireAllSingleChars = true,
  126. PageIndex = 1,
  127. PageSize = 999999,
  128. FieldWeights = new Dictionary<string, int>
  129. {
  130. { "Instructions", 10 }
  131. },
  132. Filters = searchFilters,
  133. OrderBy = "CreateTime",
  134. //ReturnFields = new List<string>() { "TeamName", "ClientUnit", "ClientName" }
  135. };
  136. // 验证字段配置
  137. var validation = _dailyFeeSearchService.ValidateFieldConfig(
  138. searchRequest.FieldWeights,
  139. searchRequest.ReturnFields);
  140. if (!validation.IsValid)
  141. {
  142. return Ok(JsonView(true, $"暂无数据!{validation.Message}"));
  143. }
  144. var result = await _dailyFeeSearchService.SearchAsync(searchRequest);
  145. if (result.Success)
  146. {
  147. var data = new List<dynamic>();
  148. foreach (var item in result.Items)
  149. {
  150. data.Add(new
  151. {
  152. item.Data.Instructions,
  153. });
  154. }
  155. return Ok(JsonView(true, result.Message, data, data.Count));
  156. }
  157. return Ok(JsonView(true, result.Message));
  158. }
  159. catch (Exception ex)
  160. {
  161. return Ok(JsonView(true, $"搜索服务暂时不可用!"));
  162. }
  163. }
  164. #endregion
  165. #region 消息
  166. /// <summary>
  167. /// 获取消息列表-整合版
  168. /// </summary>
  169. /// <param name="dto"></param>
  170. /// <returns></returns>
  171. [HttpPost]
  172. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  173. public async Task<IActionResult> PsotMsgPageList(MsgDto dto)
  174. {
  175. var msgData = await _messageRep.GetMsgList(dto);
  176. return msgData.Code != 0 ? Ok(JsonView(false, msgData.Msg)) : Ok(JsonView(msgData.Data));
  177. }
  178. #region 消息列表 - 分开
  179. /// <summary>
  180. /// 系统消息
  181. /// 消息类型 2024-03-06 14:37
  182. /// </summary>
  183. /// <param name="dto"></param>
  184. /// <returns></returns>
  185. [HttpPost]
  186. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  187. public async Task<IActionResult> PotsMsgTypeData(MsgTypeDto dto)
  188. {
  189. if (dto.PortType < 1 || dto.PortType > 3)
  190. return Ok(JsonView(false, MsgTips.Port));
  191. if (dto.UserId < 1)
  192. return Ok(JsonView(false, "请输入有效的UserId参数。"));
  193. var msgData = await _messageRep.PotsMsgTypeData(dto);
  194. return msgData.Code != 0 ? Ok(JsonView(400, msgData.Msg, new string[] { })) : Ok(JsonView(true, msgData.Msg, msgData.Data));
  195. }
  196. /// <summary>
  197. /// 系统消息
  198. /// 消息List 2024-03-06 14:54
  199. /// </summary>
  200. /// <param name="dto"></param>
  201. /// <returns></returns>
  202. [HttpPost]
  203. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  204. public async Task<IActionResult> PotsMessagePageList(PotsMessagePageListDto dto)
  205. {
  206. #region 参数验证
  207. if (dto.PortType < 1 || dto.PortType > 3)
  208. return Ok(JsonView(false, MsgTips.Port));
  209. var typeData = await _sqlSugar.Queryable<Sys_SetData>().Where(it => it.STid == 77).Select(it => it.Id).ToListAsync();
  210. if (typeData.Count < 0)
  211. return Ok(JsonView(false, "消息类型不存在"));
  212. if (!typeData.Contains(dto.Type))
  213. return Ok(JsonView(false, "请输入有效的Type参数。1021 团组操作通知 1020 任务操作通知 "));
  214. if (dto.UserId < 1)
  215. return Ok(JsonView(false, "请输入有效的UserId参数。"));
  216. if (dto.ReadStatus < 1 || dto.ReadStatus > 3)
  217. return Ok(JsonView(false, "请输入有效的ReadStatus参数。1 全部(包含已读/未读) 2 未读 3 已读"));
  218. #endregion
  219. //userId
  220. string msgSqlWhere = $" And smra.ReadableUId = {dto.UserId}";
  221. //消息类型
  222. string typeStr = "";
  223. List<NotificationTypeView> messageTypeViews = AppSettingsHelper.Get<NotificationTypeView>("MessageNotificationType");
  224. if (dto.Type == 1020) //任务操作通知
  225. {
  226. typeStr = String.Join(",", messageTypeViews.Where(it => it.TypeId == 1020).FirstOrDefault().MsgTypeIds.ToList());
  227. }
  228. else if (dto.Type == 1021)//团组操作通知
  229. {
  230. typeStr = String.Join(",", messageTypeViews.Where(it => it.TypeId == 1021).FirstOrDefault().MsgTypeIds.ToList());
  231. }
  232. else if (dto.Type == 1022)//公告通知
  233. {
  234. typeStr = String.Join(",", messageTypeViews.Where(it => it.TypeId == 1022).FirstOrDefault().MsgTypeIds.ToList());
  235. }
  236. if (!string.IsNullOrEmpty(typeStr))
  237. {
  238. msgSqlWhere += $" And sm.Type In ({typeStr})";
  239. }
  240. //是否已读处理 1 全部(包含已读/未读) 2 未读 3 已读
  241. msgSqlWhere += dto.ReadStatus switch
  242. {
  243. 2 => " And smra.IsRead = 0",
  244. 3 => " And smra.IsRead = 1",
  245. _ => ""
  246. };
  247. string msgSql = string.Format(@"Select * From(
  248. Select row_number() over(order by sm.ReleaseTime Desc) as RowNumber,
  249. sm.Id,sm.Type,sm.Title,sm.Content,sd.DepName issuerDep,su.CnName issuerUser,
  250. sm.ReleaseTime,smra.ReadableUId,smra.IsRead,sm.DiId,sm.Param
  251. From Sys_Message sm
  252. Inner Join Sys_MessageReadAuth smra On sm.Id = smra.MsgId
  253. Inner Join Sys_Users su On sm.IssuerId = su.Id
  254. Inner Join Sys_Department sd On su.DepId = sd.Id
  255. Inner Join Sys_Users suAuth On smra.ReadableUId = suAuth.Id
  256. Where sm.IsDel = 0
  257. And smra.IsDel = 0 {0}
  258. ) Temp", msgSqlWhere);
  259. try
  260. {
  261. RefAsync<int> totalCount = 0;
  262. var data = await _sqlSugar.SqlQueryable<MessageListView>(msgSql).ToPageListAsync(dto.PageIndex, dto.PageSize, totalCount);
  263. return Ok(JsonView(true, "操作成功!", data, totalCount));
  264. }
  265. catch (Exception ex)
  266. {
  267. return Ok(JsonView(false, ex.Message));
  268. }
  269. }
  270. /// <summary>
  271. /// 系统消息
  272. /// 获取消息未读条数
  273. /// </summary>
  274. /// <param name="dto"></param>
  275. /// <returns></returns>
  276. [HttpPost]
  277. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  278. public async Task<IActionResult> PotsMessageUnreadTotalCount(PotsMessageUnreadTotalCountDto dto)
  279. {
  280. #region 参数验证
  281. if (dto.UserId < 1)
  282. return Ok(JsonView(false, "请输入有效的UserId参数。"));
  283. #endregion
  284. try
  285. {
  286. #region 限制人员登录
  287. var userInfo = await _sqlSugar
  288. .Queryable<Sys_Users>()
  289. .Where((u) => u.Id == dto.UserId)
  290. .Select((u) => new
  291. {
  292. CnName = u.CnName
  293. })
  294. .FirstAsync();
  295. var noLoginAuth = _config.GetSection("NoLoginAuth").Get<List<string>>();
  296. if (noLoginAuth.Any())
  297. {
  298. if (noLoginAuth.Contains(userInfo.CnName)) return Ok(JsonView(204, "NO ACCESS!!", ""));
  299. }
  300. //其他市场部人员 限制登录时间段
  301. //var currentDateTime = DateTime.Now;
  302. //var startTime = DateTime.Parse(_config["ApiAccessTime:StartTime"]);
  303. //var endTime = DateTime.Parse(_config["ApiAccessTime:EndTime"]);
  304. //if (currentDateTime < startTime && currentDateTime > endTime) return Ok(JsonView(204, "NO ACCESS!!", ""));
  305. #endregion
  306. int messageUnReadCount = await _messageRep.GetUnReadCount(dto.UserId);
  307. int announcementUnReadCount = await _messageRep.GetAnnouncementUnReadCount(dto.UserId);
  308. return Ok(JsonView(true, "操作成功!", new { messageUnReadCount = messageUnReadCount, announcementUnReadCount = announcementUnReadCount }));
  309. }
  310. catch (Exception ex)
  311. {
  312. return Ok(JsonView(false, ex.Message));
  313. }
  314. }
  315. #endregion
  316. /// <summary>
  317. /// 获取消息详细信息
  318. /// </summary>
  319. /// <param name="dto"></param>
  320. /// <returns></returns>
  321. [HttpPost]
  322. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  323. public async Task<IActionResult> PostMsgInfo(MsgInfoDto dto)
  324. {
  325. if (dto.PortType < 1 || dto.PortType > 3)
  326. return Ok(JsonView(false, MsgTips.Port));
  327. var msgData = await _messageRep.GetMsgInfo(dto);
  328. return msgData.Code != 0 ? Ok(JsonView(false, msgData.Msg)) : Ok(JsonView(true, "操作成功!", msgData.Data));
  329. }
  330. /// <summary>
  331. /// 消息设置已读
  332. /// </summary>
  333. /// <param name="dto"></param>
  334. /// <returns></returns>
  335. [HttpPost]
  336. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  337. public async Task<IActionResult> SetMessageRead(MsgSetReadDto dto)
  338. {
  339. var msgData = await _messageRep.SetMsgRead(dto);
  340. return msgData.Code != 0 ? Ok(JsonView(false, msgData.Msg)) : Ok(JsonView(true));
  341. }
  342. /// <summary>
  343. /// 消息 删除
  344. /// </summary>
  345. /// <param name="dto"></param>
  346. /// <returns></returns>
  347. [HttpPost]
  348. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  349. public async Task<IActionResult> DeleMsg(MsgDeleteDto dto)
  350. {
  351. var msgData = await _messageRep.DelMsg(dto);
  352. return msgData.Code != 0 ? Ok(JsonView(false, msgData.Msg)) : Ok(JsonView(true));
  353. }
  354. #endregion
  355. #region 数据类型资料
  356. /// <summary>
  357. /// 根据类型查询数据
  358. /// </summary>
  359. /// <param name="dto"></param>
  360. /// <returns></returns>
  361. [HttpPost]
  362. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  363. public async Task<IActionResult> QuerySetData(SetDataDto dto)
  364. {
  365. try
  366. {
  367. if (dto.DataType == 0)
  368. {
  369. return Ok(JsonView(false, "请传类型Id!"));
  370. }
  371. var setData = _setDataRepository.QueryDto<Sys_SetData, SetDataView>(s => s.STid == dto.DataType && s.IsDel == 0).ToList();
  372. if (setData.Count == 0)
  373. {
  374. return Ok(JsonView(false, "暂无数据!"));
  375. }
  376. return Ok(JsonView(true, "查询成功!", setData));
  377. }
  378. catch (Exception ex)
  379. {
  380. return Ok(JsonView(false, "程序错误!"));
  381. }
  382. }
  383. /// <summary>
  384. /// 根据类型查询数据(Array)
  385. /// </summary>
  386. /// <returns></returns>
  387. [HttpPost]
  388. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  389. public IActionResult QuerySetDataInitByArr(QuerySetDataInitByArr Dto)
  390. {
  391. if (Dto.DataTypeArr == null || !Dto.DataTypeArr.Any())
  392. {
  393. return Ok(JsonView(false, "请传入有效的类型数组!"));
  394. }
  395. var DbQuery = _setDataRepository.QueryDto<Sys_SetData, SetDataView>(s => Dto.DataTypeArr.Contains(s.STid)).ToList();
  396. var GroupResult = DbQuery.GroupBy(x => x.STid).Select(x => new
  397. {
  398. key = x.Key,
  399. Arr = x.ToList()
  400. });
  401. return Ok(JsonView(true, "查询成功!", GroupResult));
  402. }
  403. /// <summary>
  404. /// 数据类型表查询
  405. /// </summary>
  406. /// <param name="dto"></param>
  407. /// <returns></returns>
  408. [HttpPost]
  409. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  410. public async Task<IActionResult> QuerySetDataType(SetDataTypeDto dto)
  411. {
  412. try
  413. {
  414. Result setDataType = await _setDataTypeRep.QuerySetDataType(dto);
  415. if (setDataType.Code == 0)
  416. {
  417. return Ok(JsonView(true, "查询成功", setDataType.Data));
  418. }
  419. else
  420. {
  421. return Ok(JsonView(false, setDataType.Msg));
  422. }
  423. }
  424. catch (Exception)
  425. {
  426. return Ok(JsonView(false, "程序错误!"));
  427. }
  428. }
  429. /// <summary>
  430. /// 数据类型表操作(Status:1.新增,2.修改)
  431. /// </summary>
  432. /// <param name="dto"></param>
  433. /// <returns></returns>
  434. [HttpPost]
  435. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  436. public async Task<IActionResult> OperationSetDataType(OperationSetDataTypeDto dto)
  437. {
  438. if (dto == null || string.IsNullOrEmpty(dto.Name))
  439. {
  440. return Ok(JsonView(false, "请检查类型名称是否填写!"));
  441. }
  442. try
  443. {
  444. Result result = await _setDataTypeRep.OperationSetDataType(dto);
  445. if (result.Code != 0)
  446. {
  447. return Ok(JsonView(false, result.Msg));
  448. }
  449. return Ok(JsonView(true, result.Msg));
  450. }
  451. catch (Exception ex)
  452. {
  453. return Ok(JsonView(false, "程序错误!"));
  454. }
  455. }
  456. /// <summary>
  457. /// 数据类型表操作删除
  458. /// </summary>
  459. /// <param name="dto"></param>
  460. /// <returns></returns>
  461. [HttpPost]
  462. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  463. public async Task<IActionResult> DelSetDataType(DelSetDataTypeDto dto)
  464. {
  465. if (dto == null || dto.Id <= 0)
  466. return Ok(JsonView(false, "请传入有效的Id参数!"));
  467. if (dto == null || dto.DeleteUserId <= 0)
  468. return Ok(JsonView(false, "请传入有效的DeleteUserId参数!"));
  469. try
  470. {
  471. var res = await _setDataTypeRep.SoftDeleteByIdAsync<Sys_SetDataType>(dto.Id.ToString(), dto.DeleteUserId);
  472. if (!res)
  473. {
  474. return Ok(JsonView(false, "删除失败"));
  475. }
  476. return Ok(JsonView(true, "删除成功!"));
  477. }
  478. catch (Exception ex)
  479. {
  480. return Ok(JsonView(false, "程序错误!"));
  481. }
  482. }
  483. #endregion
  484. #region 数据类型板块
  485. /// <summary>
  486. /// 数据类型板块表查询
  487. /// </summary>
  488. /// <param name="dto"></param>
  489. /// <returns></returns>
  490. [HttpPost]
  491. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  492. public async Task<IActionResult> QuerySetDataInfo(SetDataIDto dto)
  493. {
  494. try
  495. {
  496. Result setData = await _setDataRepository.QuerySetData(dto);
  497. if (setData.Code == 0)
  498. {
  499. return Ok(JsonView(true, "查询成功", setData.Data));
  500. }
  501. else
  502. {
  503. return Ok(JsonView(false, setData.Msg));
  504. }
  505. }
  506. catch (Exception)
  507. {
  508. return Ok(JsonView(false, "程序错误!"));
  509. throw;
  510. }
  511. }
  512. /// <summary>
  513. /// 数据类型板块表操作(Status:1.新增,2.修改)
  514. /// </summary>
  515. /// <param name="dto"></param>
  516. /// <returns></returns>
  517. [HttpPost]
  518. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  519. public async Task<IActionResult> OperationSetData(OperationSetDataDto dto)
  520. {
  521. if (string.IsNullOrEmpty(dto.Name)) return Ok(JsonView(false, "请检查板块名称是否填写!"));
  522. Result result = await _setDataRepository.OperationSetData(dto);
  523. if (result.Code != 0)
  524. {
  525. return Ok(JsonView(false, result.Msg));
  526. }
  527. return Ok(JsonView(true, result.Msg));
  528. }
  529. /// <summary>
  530. /// 数据类型表操作删除
  531. /// </summary>
  532. /// <param name="dto"></param>
  533. /// <returns></returns>
  534. [HttpPost]
  535. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  536. public async Task<IActionResult> DelSetData(DelSetDataDto dto)
  537. {
  538. try
  539. {
  540. var res = await _setDataRepository.SoftDeleteByIdAsync<Sys_SetData>(dto.Id.ToString(), dto.DeleteUserId);
  541. if (!res)
  542. {
  543. return Ok(JsonView(false, "删除失败"));
  544. }
  545. return Ok(JsonView(true, "删除成功!"));
  546. }
  547. catch (Exception ex)
  548. {
  549. return Ok(JsonView(false, "程序错误!"));
  550. throw;
  551. }
  552. }
  553. #endregion
  554. #region 企业操作
  555. /// <summary>
  556. /// 查询企业数据
  557. /// </summary>
  558. /// <param name="dto"></param>
  559. /// <returns></returns>
  560. [HttpPost]
  561. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  562. public async Task<IActionResult> getCompanyList(DtoBase dto)
  563. {
  564. if (dto.PortType == 1)
  565. {
  566. var CompanyDataResult = _CompanyRepository.GetCompanyData();
  567. if (CompanyDataResult.Code != 0)
  568. {
  569. return Ok(JsonView(CompanyDataResult.Msg));
  570. }
  571. List<CompanyView> companyListView = _mapper.Map<List<CompanyView>>(CompanyDataResult.Data);
  572. for (int i = 0; i < companyListView.Count; i++)
  573. {
  574. if (companyListView[i].ParentCompanyId != 0)
  575. {
  576. companyListView[i].ParentCompanyName = companyListView.Find(x => x.Id == companyListView[i].ParentCompanyId).CompanyName;
  577. }
  578. if (companyListView[i].ContactUserId != 0)
  579. {
  580. var user = _userRep.QueryDto<Sys_Users, UserInfoWebView>(x => x.Id == companyListView[i].ContactUserId).ToList();
  581. if (user.Count != 0)
  582. {
  583. companyListView[i].ContactUserName = user[0].CnName;
  584. }
  585. }
  586. }
  587. return Ok(JsonView(true, "查询成功!", companyListView));
  588. }
  589. else if (dto.PortType == 2)
  590. {
  591. var CompanyDataResult = _CompanyRepository.GetCompanyData();
  592. if (CompanyDataResult.Code != 0)
  593. {
  594. return Ok(JsonView(CompanyDataResult.Msg));
  595. }
  596. return Ok(JsonView(true, "查询成功!", CompanyDataResult.Data));
  597. }
  598. else if (dto.PortType == 3)
  599. {
  600. return Ok(JsonView(false, "暂无数据!"));
  601. }
  602. else
  603. {
  604. return Ok(JsonView(false, "暂无数据!"));
  605. }
  606. }
  607. /// <summary>
  608. /// 添加企业数据
  609. /// </summary>
  610. /// <param name="dto"></param>
  611. /// <returns></returns>
  612. [HttpPost]
  613. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  614. public async Task<IActionResult> AddCompany(AddCompanyDto dto)
  615. {
  616. if (string.IsNullOrWhiteSpace(dto.CompanyName) || dto.CreateUserId == 0 || string.IsNullOrWhiteSpace(dto.CompanyCode))
  617. {
  618. return Ok(JsonView(false, "请检查信息是否输入完整!"));
  619. }
  620. else if (string.IsNullOrWhiteSpace(dto.Tel))
  621. {
  622. return Ok(JsonView(false, "请检查联系方式是否输入正确!"));
  623. }
  624. else
  625. {
  626. Sys_Company _Company = _mapper.Map<Sys_Company>(dto);
  627. Result data = await _syscomRep.AddCompany(_Company);
  628. if (data.Code != 0)
  629. {
  630. return Ok(JsonView(false, "添加失败!"));
  631. }
  632. return Ok(JsonView(true, "添加成功"));
  633. }
  634. }
  635. /// <summary>
  636. /// 企业修改
  637. /// </summary>
  638. /// <param name="dto"></param>
  639. /// <returns></returns>
  640. [HttpPost]
  641. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  642. public async Task<IActionResult> EditCompany(EditCompanyDto dto)
  643. {
  644. if (string.IsNullOrWhiteSpace(dto.CompanyName) || string.IsNullOrWhiteSpace(dto.CompanyCode) || string.IsNullOrWhiteSpace(dto.Address) || dto.ContactUserId == 0)
  645. {
  646. return Ok(JsonView(false, "请检查信息是否输入完整!"));
  647. }
  648. else if (string.IsNullOrWhiteSpace(dto.Tel))
  649. {
  650. return Ok(JsonView(false, "请检查联系方式是否输入正确!"));
  651. }
  652. else
  653. {
  654. bool res = await _syscomRep.UpdateAsync(a => a.Id == dto.Id, a => new Sys_Company
  655. {
  656. CompanyName = dto.CompanyName,
  657. CompanyCode = dto.CompanyCode,
  658. Address = dto.Address,
  659. ParentCompanyId = dto.ParentCompanyId,
  660. Tel = dto.Tel,
  661. ContactUserId = dto.ContactUserId,
  662. Remark = dto.Remark,
  663. });
  664. if (!res) { return Ok(JsonView(false, "修改失败")); }
  665. return Ok(JsonView(true, "修改成功!"));
  666. }
  667. }
  668. /// <summary>
  669. /// 企业删除
  670. /// </summary>
  671. /// <param name="dto"></param>
  672. /// <returns></returns>
  673. [HttpPost]
  674. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  675. public async Task<IActionResult> DelCompany(DelCompanyDto dto)
  676. {
  677. bool res = await _syscomRep.SoftDeleteAsync<Sys_Company>(dto.Id.ToString());
  678. if (!res) { return Ok(JsonView(false, "删除失败")); }
  679. return Ok(JsonView(true, "删除成功"));
  680. }
  681. #endregion
  682. #region 部门操作
  683. /// <summary>
  684. /// 查询部门数据
  685. /// </summary>
  686. /// <param name="dto"></param>
  687. /// <returns></returns>
  688. [HttpPost]
  689. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  690. public async Task<IActionResult> QueryDepartmentList(DepartmentDto dto)
  691. {
  692. if (dto.PortType == 1)
  693. {
  694. if (dto.CompanyId != 0)
  695. {
  696. var result = _sysDepRep.QueryDto<Sys_Department, DepartmentIView>(s => s.CompanyId == dto.CompanyId).ToList();
  697. if (result.Count == 0)
  698. {
  699. return Ok(JsonView(false, "暂无数据!"));
  700. }
  701. int resultCount = result.Count;
  702. for (int i = 0; i < resultCount; i++)
  703. {
  704. if (result[i].ParentDepId != 0)
  705. {
  706. result[i].ParentDepName = result.Find(x => x.Id == result[i].ParentDepId).ParentDepName;
  707. }
  708. var company = _sysDepRep.QueryDto<Sys_Company, CompanyView>(s => s.Id == result[i].CompanyId).ToList();
  709. if (company.Count != 0)
  710. {
  711. result[i].CompanyName = company[0].CompanyName;
  712. }
  713. }
  714. return Ok(JsonView(true, "查询成功!", result));
  715. }
  716. else
  717. {
  718. var result = _sysDepRep.QueryDto<Sys_Department, DepartmentIView>(s => s.IsDel <= 1).ToList();
  719. if (result.Count == 0)
  720. {
  721. return Ok(JsonView(false, "暂无数据!"));
  722. }
  723. for (int i = 0; i < result.Count; i++)
  724. {
  725. if (result[i].ParentDepId != 0)
  726. {
  727. result[i].ParentDepName = result.Find(x => x.Id == result[i].ParentDepId).ParentDepName;
  728. }
  729. var company = _sysDepRep.QueryDto<Sys_Company, CompanyView>(s => s.Id == result[i].CompanyId).ToList();
  730. if (company.Count != 0)
  731. {
  732. result[i].CompanyName = company[0].CompanyName;
  733. }
  734. }
  735. return Ok(JsonView(true, "查询成功!", result));
  736. }
  737. }
  738. else if (dto.PortType == 2)
  739. {
  740. var result = _sysDepRep.QueryDto<Sys_Department, DepartmentIView>(s => s.CompanyId == dto.CompanyId).ToList();
  741. if (result.Count == 0)
  742. {
  743. return Ok(JsonView(400, "暂无数据!", new List<string>()));
  744. }
  745. return Ok(JsonView(true, "查询成功!", result));
  746. }
  747. else if (dto.PortType == 3)
  748. {
  749. }
  750. else
  751. {
  752. }
  753. return Ok(JsonView(false, "暂无数据!"));
  754. }
  755. /// <summary>
  756. /// 部门添加
  757. /// </summary>
  758. /// <param name="dto"></param>
  759. /// <returns></returns>
  760. [HttpPost]
  761. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  762. public async Task<IActionResult> AddDepartment(AddDepartmentDto dto)
  763. {
  764. try
  765. {
  766. if (dto.CreateUserId == 0 || string.IsNullOrWhiteSpace(dto.DepName) || dto.CompanyId == 0 || string.IsNullOrWhiteSpace(dto.DepCode))
  767. {
  768. return Ok(JsonView(false, "请检查信息是否输入完整!"));
  769. }
  770. else
  771. {
  772. Sys_Department _Department = _mapper.Map<Sys_Department>(dto);
  773. int id = await _sysDepRep.AddAsyncReturnId(_Department);
  774. if (id == 0)
  775. {
  776. return Ok(JsonView(false, "添加失败!"));
  777. }
  778. return Ok(JsonView(true, "添加成功!", new { Id = id }));
  779. }
  780. }
  781. catch (Exception)
  782. {
  783. return Ok(JsonView(false, "程序错误!"));
  784. throw;
  785. }
  786. }
  787. /// <summary>
  788. /// 部门修改
  789. /// </summary>
  790. /// <param name="dto"></param>
  791. /// <returns></returns>
  792. [HttpPost]
  793. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  794. public async Task<IActionResult> EditDepartment(EditDepartmentDto dto)
  795. {
  796. try
  797. {
  798. if (dto.Id == 0 || string.IsNullOrWhiteSpace(dto.DepName) || dto.CompanyId == 0 || string.IsNullOrWhiteSpace(dto.DepCode))
  799. {
  800. return Ok(JsonView(false, "请检查信息是否输入完整!"));
  801. }
  802. else
  803. {
  804. bool res = await _sysDepRep.UpdateAsync<Sys_Department>(a => a.Id == dto.Id, a => new Sys_Department
  805. {
  806. CompanyId = dto.CompanyId,
  807. DepCode = dto.DepCode,
  808. DepName = dto.DepName,
  809. ParentDepId = dto.ParentDepId,
  810. Remark = dto.Remark,
  811. });
  812. if (!res)
  813. {
  814. return Ok(JsonView(false, "修改失败!"));
  815. }
  816. return Ok(JsonView(true, "修改成功!"));
  817. }
  818. }
  819. catch (Exception)
  820. {
  821. return Ok(JsonView(false, "程序错误!"));
  822. throw;
  823. }
  824. }
  825. /// <summary>
  826. /// 部门删除
  827. /// </summary>
  828. /// <param name="dto"></param>
  829. /// <returns></returns>
  830. [HttpPost]
  831. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  832. public async Task<IActionResult> DelDepartment(DelDepartmentDto dto)
  833. {
  834. try
  835. {
  836. if (dto.Id == 0)
  837. {
  838. return Ok(JsonView(-1, "请检查信息是否输入完整!", string.Empty));
  839. }
  840. else
  841. {
  842. bool res = await _sysDepRep.SoftDeleteAsync<Sys_Department>(dto.Id.ToString());
  843. if (!res)
  844. {
  845. return Ok(JsonView(false, "删除失败!"));
  846. }
  847. return Ok(JsonView(true, "删除成功!"));
  848. }
  849. }
  850. catch (Exception)
  851. {
  852. return Ok(JsonView(false, "程序错误!"));
  853. }
  854. }
  855. #endregion
  856. #region 岗位板块
  857. /// <summary>
  858. /// 岗位查询
  859. /// </summary>
  860. /// <param name="dto"></param>
  861. /// <returns></returns>
  862. [HttpPost]
  863. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  864. public async Task<IActionResult> QueryJobPost(QueryJobPostDto dto)
  865. {
  866. try
  867. {
  868. if (dto.PortType == 1)
  869. {
  870. string sqlWhere = string.Empty;
  871. if (dto.CompanyId != 0)
  872. {
  873. sqlWhere += string.Format(@" And jp.CompanyId={0}", dto.CompanyId);
  874. }
  875. if (dto.DepId != 0)
  876. {
  877. sqlWhere += string.Format(@" And jp.DepId={0}", dto.DepId);
  878. }
  879. sqlWhere += string.Format(@" And jp.IsDel={0}", 0);
  880. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  881. {
  882. Regex r = new Regex("And");
  883. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  884. }
  885. List<Sys_JobPostI> jobList = await _jobRep.QueryJobPost(sqlWhere);
  886. List<JobPostView> List = _mapper.Map<List<JobPostView>>(jobList);
  887. if (jobList.Count == 0)
  888. {
  889. return Ok(JsonView(false, "暂无数据!"));
  890. }
  891. return Ok(JsonView(true, "查询成功!", jobList));
  892. }
  893. else if (dto.PortType == 2)
  894. {
  895. var result = _jobRep.QueryDto<Sys_JobPost, JobPostView>(s => s.CompanyId == dto.CompanyId && s.DepId == dto.DepId).ToList();
  896. if (result.Count == 0)
  897. {
  898. return Ok(JsonView(false, "暂无数据!"));
  899. }
  900. return Ok(JsonView(true, "查询成功!", result));
  901. }
  902. else if (dto.PortType == 3)
  903. {
  904. return Ok(JsonView(false, "暂无数据!"));
  905. }
  906. else
  907. {
  908. return Ok(JsonView(false, "暂无数据!"));
  909. }
  910. }
  911. catch (Exception ex)
  912. {
  913. return Ok(JsonView(false, "程序错误!"));
  914. throw;
  915. }
  916. }
  917. /// <summary>
  918. /// 添加岗位
  919. /// </summary>
  920. /// <param name="dto"></param>
  921. /// <returns></returns>
  922. [HttpPost]
  923. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  924. public async Task<IActionResult> AddJobPost(AddJobPostDto dto)
  925. {
  926. try
  927. {
  928. Sys_JobPost sys_Job = _mapper.Map<Sys_JobPost>(dto);
  929. int id = await _jobRep.AddAsyncReturnId(sys_Job);
  930. if (id == 0)
  931. {
  932. return Ok(JsonView(false, "添加失败"));
  933. }
  934. return Ok(JsonView(true, "添加成功", new { Id = id }));
  935. }
  936. catch (Exception ex)
  937. {
  938. return Ok(JsonView(false, "程序错误!"));
  939. throw;
  940. }
  941. }
  942. /// <summary>
  943. /// 修改岗位
  944. /// </summary>
  945. /// <param name="dto"></param>
  946. /// <returns></returns>
  947. [HttpPost]
  948. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  949. public async Task<IActionResult> EditJobPost(EditJobPostDto dto)
  950. {
  951. try
  952. {
  953. bool res = await _jobRep.UpdateAsync<Sys_JobPost>(a => a.Id == dto.Id, a => new Sys_JobPost
  954. {
  955. CompanyId = dto.CompanyId,
  956. DepId = dto.DepId,
  957. JobName = dto.JobName,
  958. Remark = dto.Remark,
  959. });
  960. if (!res)
  961. {
  962. return Ok(JsonView(false, "修改失败"));
  963. }
  964. return Ok(JsonView(true, "修改成功"));
  965. }
  966. catch (Exception ex)
  967. {
  968. return Ok(JsonView(false, "程序错误!"));
  969. throw;
  970. }
  971. }
  972. /// <summary>
  973. /// 删除岗位
  974. /// </summary>
  975. /// <param name="dto"></param>
  976. /// <returns></returns>
  977. [HttpPost]
  978. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  979. public async Task<IActionResult> DelJobPost(DelJobPostDto dto)
  980. {
  981. try
  982. {
  983. bool res = await _jobRep.SoftDeleteAsync<Sys_JobPost>(dto.Id.ToString());
  984. if (!res)
  985. {
  986. return Ok(JsonView(false, "删除失败!"));
  987. }
  988. return Ok(JsonView(true, "删除成功"));
  989. }
  990. catch (Exception)
  991. {
  992. return Ok(JsonView(false, "程序错误!"));
  993. throw;
  994. }
  995. }
  996. #endregion
  997. #region 用户操作
  998. ///// <summary>
  999. ///// 用户表指定字段加密
  1000. ///// </summary>
  1001. ///// <param name="dto"></param>
  1002. ///// <returns></returns>
  1003. //[HttpPost]
  1004. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1005. //public async Task<IActionResult> UserBatchEncryption()
  1006. //{
  1007. // var items = await _sqlSugar.Queryable<Sys_Users>().Select(x => new Sys_Users() { Id = x.Id, Phone = x.Phone, UrgentPhone = x.UrgentPhone, IDCard = x.IDCard }).ToListAsync();
  1008. // foreach (var item in items) EncryptionProcessor.EncryptProperties(item);
  1009. // var updItems = await _sqlSugar.Updateable(items).UpdateColumns(x => new { x.Phone, x.UrgentPhone, x.IDCard }).ExecuteCommandAsync();
  1010. // return Ok(JsonView(updItems));
  1011. //}
  1012. /// <summary>
  1013. /// 查询所有员工名称
  1014. /// </summary>
  1015. /// <param name="dto"></param>
  1016. /// <returns></returns>
  1017. [HttpPost]
  1018. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1019. public async Task<IActionResult> GetUserNameList(DtoBase dto)
  1020. {
  1021. var result = _userRep.GetUserNameList(dto.PortType);
  1022. if (result.Result.Code != 0)
  1023. {
  1024. return Ok(JsonView(false, "暂无数据!"));
  1025. }
  1026. return Ok(JsonView(true, "查询成功!", result.Result.Data));
  1027. }
  1028. /// <summary>
  1029. /// 查询所有员工(web)
  1030. /// </summary>
  1031. /// <param name="dto"></param>
  1032. /// <returns></returns>
  1033. [HttpPost]
  1034. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1035. public async Task<IActionResult> GetUserList(DtoBase dto)
  1036. {
  1037. var result = _userRep.GetUserList(dto.PortType, string.Empty);
  1038. if (result.Result.Code != 0)
  1039. {
  1040. return Ok(JsonView(false, "暂无数据!"));
  1041. }
  1042. return Ok(JsonView(true, "查询成功!", result.Result.Data));
  1043. }
  1044. /// <summary>
  1045. /// 查询用户数据
  1046. /// </summary>
  1047. /// <param name="dto"></param>
  1048. /// <returns></returns>
  1049. [HttpPost]
  1050. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1051. public async Task<IActionResult> QueryUserList(UserDto dto)
  1052. {
  1053. string sqlWhere = string.Format(" Where su.IsDel = 0 ");
  1054. if (dto.CompanyId != 0)
  1055. {
  1056. sqlWhere += string.Format(@" And su.CompanyId={0}", dto.CompanyId);
  1057. }
  1058. if (dto.DepId != 0)
  1059. {
  1060. sqlWhere += string.Format(@" And su.DepId={0}", dto.DepId);
  1061. }
  1062. if (dto.JobPostId != 0)
  1063. {
  1064. sqlWhere += string.Format(@" And su.JobPostId={0}", dto.JobPostId);
  1065. }
  1066. List<UserInfo> _userList = await _userRep.QueryUser(sqlWhere);
  1067. if (_userList.Count == 0)
  1068. {
  1069. return Ok(JsonView(400, "暂无数据!", new List<String>()));
  1070. }
  1071. foreach (var item in _userList) EncryptionProcessor.DecryptProperties(item);
  1072. List<UserInfoWebView> userList = _mapper.Map<List<UserInfoWebView>>(_userList);
  1073. return Ok(JsonView(true, "查询成功!", userList));
  1074. }
  1075. /// <summary>
  1076. /// 员工信息 个人详细信息
  1077. /// </summary>
  1078. /// <returns></returns>
  1079. [HttpPost]
  1080. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1081. public async Task<IActionResult> UserInfo(UserInfoDto dto)
  1082. {
  1083. if (dto.Id < 1) return Ok(JsonView(false, "请选择有效的userId!"));
  1084. if (dto.PortType < 1 || dto.PortType > 3) return Ok(JsonView(false, MsgTips.Port));
  1085. var _view = await _sqlSugar.Queryable<Sys_Users>()
  1086. .Where(x => x.IsDel == 0 && x.Id == dto.Id)
  1087. .FirstAsync();
  1088. //解密
  1089. EncryptionProcessor.DecryptProperties(_view);
  1090. var data = new
  1091. {
  1092. _view.Id,
  1093. _view.CnName,
  1094. _view.EnName,
  1095. _view.Number,
  1096. _view.CompanyId,
  1097. _view.DepId,
  1098. _view.JobPostId,
  1099. _view.Password,
  1100. _view.Sex,
  1101. _view.Ext,
  1102. _view.Phone,
  1103. _view.UrgentPhone,
  1104. _view.Email,
  1105. _view.Address,
  1106. _view.Edate,
  1107. //_view.Seniority,
  1108. _view.Birthday,
  1109. _view.IDCard,
  1110. _view.StartWorkDate,
  1111. _view.GraduateInstitutions,
  1112. _view.Professional,
  1113. _view.Education,
  1114. _view.TheOrAdultEducation,
  1115. _view.MaritalStatus,
  1116. _view.HomeAddress,
  1117. _view.UsePeriod,
  1118. _view.WorkExperience,
  1119. _view.Certificate,
  1120. //_view.QiyeChatUserId,
  1121. _view.Remark
  1122. };
  1123. return Ok(JsonView(true, "操作成功!", data));
  1124. }
  1125. /// <summary>
  1126. /// 员工信息 All信息修改
  1127. /// </summary>
  1128. /// <returns></returns>
  1129. [HttpPost]
  1130. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1131. public async Task<IActionResult> EditUserInfo(EditUserInfoDto _dto)
  1132. {
  1133. EditUserInfoDtoValidator validator = new EditUserInfoDtoValidator();
  1134. var validatorRes = await validator.ValidateAsync(_dto);
  1135. if (!validatorRes.IsValid)
  1136. {
  1137. var errors = new StringBuilder();
  1138. foreach (var error in validatorRes.Errors) errors.AppendLine(error.ErrorMessage);
  1139. return Ok(JsonView(false, errors.ToString()));
  1140. }
  1141. var userInfo = _mapper.Map<Sys_Users>(_dto);
  1142. if (_dto.CurrUserId < 1) return Ok(JsonView(false, "暂无修改权限!"));
  1143. //修改权限验证 指定人员 信息部门(4)和人事部刘一茹( 230)、赖红燕(309)
  1144. List<int> userIds = new List<int>() {
  1145. 4 ,//管理员
  1146. 5 ,//杨俊霄
  1147. 117 ,//人事审核号
  1148. 208 ,//雷怡
  1149. 230 ,//刘一茹
  1150. 233 ,//刘华举
  1151. 234 ,//蒋金辰
  1152. 235 ,//袁榕烽
  1153. 309 ,//赖红燕
  1154. };
  1155. if (!userIds.Contains(_dto.CurrUserId)) return Ok(JsonView(false, "暂无修改权限!"));
  1156. //加密
  1157. EncryptionProcessor.EncryptProperties(userInfo);
  1158. var res = await _sqlSugar.Updateable(userInfo)
  1159. .IgnoreColumns(x => new
  1160. {
  1161. x.QiyeChatUserId,
  1162. x.Rdate,
  1163. x.Seniority,
  1164. x.HrAudit,
  1165. x.CreateUserId,
  1166. x.CreateTime,
  1167. x.DeleteUserId,
  1168. x.DeleteTime,
  1169. x.IsDel
  1170. })
  1171. .Where(x => x.Id == _dto.Id)
  1172. .ExecuteCommandAsync();
  1173. if (res > 0) return Ok(JsonView(true, "操作成功!"));
  1174. return Ok(JsonView(false, "操作失败!"));
  1175. }
  1176. /// <summary>
  1177. /// 修改用户信息(上级修改/分配 公司、部门、岗位、工号等信息)
  1178. /// </summary>
  1179. /// <param name="dto"></param>
  1180. /// <returns></returns>
  1181. [HttpPost]
  1182. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1183. public async Task<IActionResult> EditUser(EditUserDto dto)
  1184. {
  1185. if (dto.CurrUserId < 1) return Ok(JsonView(false, "暂无修改权限!"));
  1186. //修改权限验证 指定人员 信息部门(4)和人事部刘一茹( 230)、赖红燕(309)
  1187. var userIds = new List<int>() {
  1188. 4 ,//管理员
  1189. 5 ,//杨俊霄
  1190. 117 ,//人事审核号
  1191. 208 ,//雷怡
  1192. 230 ,//刘一茹
  1193. 233 ,//刘华举
  1194. 234 ,//蒋金辰
  1195. 235 ,//袁榕烽
  1196. 309 ,//赖红燕
  1197. };
  1198. if (!userIds.Contains(dto.CurrUserId)) return Ok(JsonView(false, "暂无修改权限!"));
  1199. bool res = await _userRep.UpdateAsync<Sys_Users>(a => a.Id == dto.Id, a => new Sys_Users
  1200. {
  1201. Number = dto.Number,
  1202. CompanyId = dto.CompanyId,
  1203. DepId = dto.DepId,
  1204. JobPostId = dto.JobPostId,
  1205. Ext = dto.Ext,
  1206. UsePeriod = dto.UsePeriod,
  1207. //HrAudit = dto.HrAudit
  1208. });
  1209. if (!res)
  1210. {
  1211. return Ok(JsonView(false, "修改失败!"));
  1212. }
  1213. return Ok(JsonView(true, "修改成功!"));
  1214. }
  1215. /// <summary>
  1216. /// 修改用户信息(登录用户修改个人信息)
  1217. /// </summary>
  1218. /// <param name="dto"></param>
  1219. /// <returns></returns>
  1220. [HttpPost]
  1221. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1222. public async Task<IActionResult> EditMyUser(EditMyUserDto dto)
  1223. {
  1224. if (string.IsNullOrWhiteSpace(dto.CnName) ||
  1225. string.IsNullOrWhiteSpace(dto.Address) ||
  1226. string.IsNullOrWhiteSpace(dto.IDCard) ||
  1227. dto.Sex != 0 && dto.Sex != 1 ||
  1228. string.IsNullOrWhiteSpace(dto.MaritalStatus) ||
  1229. string.IsNullOrWhiteSpace(dto.HomeAddress) ||
  1230. dto.Birthday >= DateTime.Now.AddYears(-1))
  1231. {
  1232. return Ok(JsonView(false, "请完善你的个人信息!"));
  1233. }
  1234. else if (string.IsNullOrWhiteSpace(dto.GraduateInstitutions) ||
  1235. string.IsNullOrWhiteSpace(dto.Professional) ||
  1236. dto.Education == 0 ||
  1237. string.IsNullOrWhiteSpace(dto.GraduateInstitutions))
  1238. {
  1239. return Ok(JsonView(false, "请完善你的学历信息!"));
  1240. }
  1241. else if (string.IsNullOrWhiteSpace(dto.Phone) ||
  1242. string.IsNullOrWhiteSpace(dto.UrgentPhone) ||
  1243. string.IsNullOrWhiteSpace(dto.Email))
  1244. {
  1245. return Ok(JsonView(false, "请检查联系方式、紧急联系人及邮箱输写是否正确!"));
  1246. }
  1247. else
  1248. {
  1249. //指定字段加密
  1250. var phone = AesEncryptionHelper.Encrypt(dto.Phone);
  1251. var urgentPhone = AesEncryptionHelper.Encrypt(dto.UrgentPhone);
  1252. var IDCard = AesEncryptionHelper.Encrypt(dto.IDCard);
  1253. bool res = await _userRep.UpdateAsync<Sys_Users>(a => a.Id == dto.Id, a => new Sys_Users
  1254. {
  1255. CnName = dto.CnName,
  1256. EnName = dto.EnName,
  1257. Sex = dto.Sex,
  1258. Phone = phone,
  1259. UrgentPhone = urgentPhone,
  1260. Email = dto.Email,
  1261. Address = dto.Address,
  1262. Edate = dto.Edate,
  1263. Birthday = dto.Birthday,
  1264. IDCard = IDCard,
  1265. GraduateInstitutions = dto.GraduateInstitutions,
  1266. Professional = dto.Professional,
  1267. Education = dto.Education,
  1268. TheOrAdultEducation = dto.TheOrAdultEducation,
  1269. MaritalStatus = dto.MaritalStatus,
  1270. HomeAddress = dto.HomeAddress,
  1271. WorkExperience = dto.WorkExperience,
  1272. Certificate = dto.Certificate
  1273. });
  1274. if (!res)
  1275. {
  1276. return Ok(JsonView(false, "修改失败!"));
  1277. }
  1278. return Ok(JsonView(true, "修改成功!"));
  1279. }
  1280. }
  1281. /// <summary>
  1282. /// 删除用户信息
  1283. /// 即为离职
  1284. /// </summary>
  1285. /// <param name="dto"></param>
  1286. /// <returns></returns>
  1287. [HttpPost]
  1288. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1289. public async Task<IActionResult> PostUserDelById(UserDelDto dto)
  1290. {
  1291. if (dto == null)
  1292. {
  1293. return Ok(JsonView(false, "参数不能为空!"));
  1294. }
  1295. var _Users = _sqlSugar.Queryable<Sys_Users>().First(a => a.IsDel == 0 && a.Id == dto.Id);
  1296. if (_Users != null)
  1297. {
  1298. var sys_UsersList = _sqlSugar.Queryable<Sys_Users>().Where(a => a.IsDel == 0 && a.CompanyId == _Users.CompanyId).ToList();
  1299. if (sys_UsersList.Count == 1)
  1300. {
  1301. return Ok(JsonView(false, "该人员为公司最后一位,不可删除!"));
  1302. }
  1303. }
  1304. bool res = await _userRep.UpdateAsync<Sys_Users>(a => a.Id == dto.Id, a => new Sys_Users
  1305. {
  1306. IsDel = 1,
  1307. DeleteUserId = dto.OperateUserId,
  1308. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  1309. Rdate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  1310. });
  1311. if (!res)
  1312. {
  1313. return Ok(JsonView(false, "操作失败!"));
  1314. }
  1315. return Ok(JsonView(true, "操作成功!"));
  1316. }
  1317. /// <summary>
  1318. /// 员工信息
  1319. /// 人事审核
  1320. /// </summary>
  1321. /// <param name="dto"></param>
  1322. /// <returns></returns>
  1323. [HttpPost]
  1324. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1325. public async Task<IActionResult> PersonnelAudit(PersonnelAuditDto dto)
  1326. {
  1327. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数!"));
  1328. if (dto.Id < 1) return Ok(JsonView(false, "请传入有效的Id参数!"));
  1329. if (dto.IsAudit < 1 || dto.IsAudit > 2) return Ok(JsonView(false, "请传入有效的IsAudit参数!1:通过 2拒绝"));
  1330. bool res = await _userRep.UpdateAsync<Sys_Users>(a => a.Id == dto.Id, a => new Sys_Users { HrAudit = dto.IsAudit });
  1331. if (res)
  1332. {
  1333. //审核成功添加员工基础页面权限
  1334. var userData = _sqlSugar.Queryable<Sys_Users>().Where(it => it.Id == dto.Id).First();
  1335. int depId = 0, postId = 0;
  1336. if (userData != null) { depId = userData.DepId; postId = userData.JobPostId; }
  1337. bool s = DefaultPostAuth(depId, postId, dto.Id, dto.UserId);
  1338. string str = $"基础页面权限添加失败!";
  1339. if (s) str = $"基础页面权限添加成功!";
  1340. return Ok(JsonView(true, $"操作成功!{str}"));
  1341. }
  1342. return Ok(JsonView(false, "操作失败!"));
  1343. }
  1344. /// <summary>
  1345. /// 部门查询员工
  1346. /// </summary>
  1347. /// <param name="dto"></param>
  1348. /// <returns></returns>
  1349. [HttpPost]
  1350. public IActionResult QueryUserByDepart(QueryUserByDepartDto dto)
  1351. {
  1352. var jw = JsonView(false);
  1353. if (dto.DepartId < 1)
  1354. {
  1355. jw.Msg = "请传入正确的部门id";
  1356. return Ok(jw);
  1357. }
  1358. string sql = $@"SELECT * FROM Sys_Users su WHERE su.JobPostId in (SELECT id FROM Sys_JobPost sj WHERE sj.IsDel = 0 AND sj.DepId = {dto.DepartId} )
  1359. AND su.IsDel = 0 ";
  1360. var result = _sqlSugar.SqlQueryable<Sys_Users>(sql).Select(x => new
  1361. {
  1362. x.Id,
  1363. x.CnName,
  1364. x.EnName
  1365. }).ToList();
  1366. jw.Data = result;
  1367. jw.Code = 200;
  1368. jw.Msg = "获取成功!";
  1369. return Ok(jw);
  1370. }
  1371. #endregion
  1372. #region 权限模块
  1373. /// <summary>
  1374. /// 权限数据页面初始化
  1375. /// </summary>
  1376. /// <param name="dto"></param>
  1377. /// <returns></returns>
  1378. //[Authorize]
  1379. [HttpPost]
  1380. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1381. public async Task<IActionResult> GetAuth(AuthDto dto)
  1382. {
  1383. Result result = new Result();
  1384. //模块数据
  1385. var setDataResult = await _setDataRepository.GetSySDefultModule();
  1386. if (setDataResult.Code != 0)
  1387. {
  1388. return Ok(JsonView(setDataResult.Msg));
  1389. }
  1390. //操作方式
  1391. var PageOperation = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, Sys_PageFunctionPermission>(x => x.IsEnable == 1).ToList();
  1392. //获取所有关联页面
  1393. var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  1394. //页面数据
  1395. var SystemMenuPermissionData = _SystemMenuPermissionRepository.QueryDto<Sys_SystemMenuPermission, SystemMenuPermissionView>(x => x.Mid == dto.moduleId && x.IsEnable == 1).ToList();
  1396. if (SystemMenuPermissionData == null || SystemMenuPermissionData.Count() == 0)
  1397. {
  1398. return Ok(JsonView("暂无数据"));
  1399. }
  1400. ArrayList viewData = new ArrayList();
  1401. //组合页面数据
  1402. foreach (var item in SystemMenuPermissionData)
  1403. {
  1404. ArrayList ids = new ArrayList();
  1405. foreach (var viewop in PageOperation)
  1406. {
  1407. var op = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.SmId == item.Id && x.FId == viewop.Id);
  1408. if (op != null)
  1409. {
  1410. ids.Add(viewop.Id);
  1411. }
  1412. }
  1413. viewData.Add(new
  1414. {
  1415. Id = item.Id,
  1416. Mid = item.Mid,
  1417. Name = item.Name,
  1418. SystemMenuCode = item.SystemMenuCode,
  1419. opList = ids,
  1420. selList = new string[0]
  1421. });
  1422. }
  1423. //公司数据
  1424. var CompanyDataResult = _CompanyRepository.GetCompanyData();
  1425. if (CompanyDataResult.Code != 0)
  1426. {
  1427. return Ok(JsonView(CompanyDataResult.Msg));
  1428. }
  1429. result.Code = 0;
  1430. result.Msg = "成功!";
  1431. var Dyresult = new
  1432. {
  1433. setDataResult = setDataResult.Data,
  1434. CompanyDataResult = CompanyDataResult.Data,
  1435. SystemMenuPermissionData = viewData,
  1436. PageOperation = PageOperation,
  1437. };
  1438. return Ok(JsonView(200, "成功!", Dyresult));
  1439. }
  1440. /// <summary>
  1441. /// 获取职务权限
  1442. /// </summary>
  1443. /// <param name="dto"></param>
  1444. /// <returns></returns>
  1445. [HttpPost]
  1446. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1447. public IActionResult QueryJobAuth(QueryJobAuthDto dto)
  1448. {
  1449. //选中的操作权限
  1450. var DBdata = _JobPostAuthorityRepository.QueryDto<Sys_JobPostAuthority, JobPostAuthorityView>(x => x.JpId == dto.jobid).ToList();
  1451. var SystemMenuPermissionData = _SystemMenuPermissionRepository.QueryDto<Sys_SystemMenuPermission, SystemMenuPermissionView>(x => x.Mid == dto.moduleId).ToList();
  1452. if (SystemMenuPermissionData == null || SystemMenuPermissionData.Count() == 0)
  1453. {
  1454. return Ok(JsonView("暂无数据"));
  1455. }
  1456. //所有操作
  1457. var PageOperation = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, Sys_PageFunctionPermission>().ToList();
  1458. //获取所有关联页面
  1459. var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  1460. ArrayList viewData = new ArrayList();
  1461. //组合页面数据
  1462. foreach (var item in SystemMenuPermissionData)
  1463. {
  1464. ArrayList ids = new ArrayList();
  1465. foreach (var viewop in PageOperation)
  1466. {
  1467. var op = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.SmId == item.Id && x.FId == viewop.Id);
  1468. if (op != null)
  1469. {
  1470. ids.Add(viewop.Id);
  1471. }
  1472. }
  1473. //获取本职务的页面拥有的权限
  1474. var DBwhere = DBdata.Where(x => x.SmId == item.Id && x.JpId == dto.jobid).ToList();
  1475. viewData.Add(new
  1476. {
  1477. Id = item.Id,
  1478. Mid = item.Mid,
  1479. Name = item.Name,
  1480. SystemMenuCode = item.SystemMenuCode,
  1481. opList = ids,
  1482. selList = DBwhere.Select(x => x.FId)
  1483. });
  1484. }
  1485. return Ok(JsonView(200, "成功!", viewData));
  1486. }
  1487. /// <summary>
  1488. /// 保存岗位权限
  1489. /// </summary>
  1490. /// <param name="dto"></param>
  1491. /// <returns></returns>
  1492. [HttpPost]
  1493. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1494. public async Task<IActionResult> SaveJobAuth(SaveJobDto dto)
  1495. {
  1496. //获取所有关联页面
  1497. var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  1498. var RemoveJobPostAuthList = _SystemMenuAndFunctionRepository._sqlSugar.SqlQueryable<Sys_JobPostAuthority>($@"
  1499. select a.* from Sys_JobPostAuthority a, Sys_SetData b ,Sys_SystemMenuPermission c
  1500. where a.SmId = c.Id and c.Mid = b.Id and JpId = {dto.Jpid} and c.Mid ={dto.modulId}
  1501. ").ToList();
  1502. List<Sys_JobPostAuthority> adds = new List<Sys_JobPostAuthority>();
  1503. foreach (var item in dto.Savejobs)
  1504. {
  1505. foreach (var fid in item.FIds)
  1506. {
  1507. var whereobj = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.FId == fid && x.SmId == item.SmId);
  1508. if (whereobj != null)
  1509. {
  1510. adds.Add(new Sys_JobPostAuthority
  1511. {
  1512. CreateTime = DateTime.Now,
  1513. CreateUserId = dto.UserId,
  1514. FId = fid,
  1515. JpId = dto.Jpid,
  1516. SmId = item.SmId
  1517. });
  1518. }
  1519. }
  1520. }
  1521. _JobPostAuthorityRepository.BeginTran();
  1522. try
  1523. { //删除岗位
  1524. bool isdel = await _JobPostAuthorityRepository.DeletesAsync<Sys_JobPostAuthority>(RemoveJobPostAuthList);
  1525. int UpRows = _JobPostAuthorityRepository.Adds<Sys_JobPostAuthority>(adds);
  1526. //获取所有职位员工
  1527. var jobUserAll = await QueryUserList(new UserDto { PortType = 2, JobPostId = dto.Jpid });
  1528. List<UserInfoWebView> users = null;
  1529. var QueryUserListApiResult = (((jobUserAll as OkObjectResult).Value) as OASystem.Domain.ViewModels.JsonView);
  1530. if (QueryUserListApiResult != null)
  1531. {
  1532. if (QueryUserListApiResult.Code == 200)
  1533. {
  1534. users = QueryUserListApiResult.Data as List<UserInfoWebView>;
  1535. }
  1536. }
  1537. if (users != null && users.Count > 0)
  1538. {
  1539. List<Sys_UserAuthority> userAuth = null;
  1540. var uids = string.Join(',', users.Select(x => x.Id)).TrimEnd(',');
  1541. var RemoveUserAuthorityListAndTemp = _UserAuthorityRepository._sqlSugar.SqlQueryable<Sys_UserAuthority>($@"
  1542. select a.* from Sys_UserAuthority a, Sys_SetData b ,Sys_SystemMenuPermission c
  1543. where a.SmId = c.Id and c.Mid = b.Id and uid in ({uids}) and c.Mid = {dto.modulId} and IsTemp = 1
  1544. ").ToList();
  1545. foreach (var user in users)
  1546. {
  1547. //删除个人级岗位权限
  1548. isdel = await _UserAuthorityRepository.DeletesAsync<Sys_UserAuthority>
  1549. (RemoveUserAuthorityListAndTemp.FindAll(x => x.UId == user.Id));
  1550. userAuth = adds.Select(x => new Sys_UserAuthority
  1551. {
  1552. CreateTime = DateTime.Now,
  1553. CreateUserId = dto.UserId,
  1554. FId = x.FId,
  1555. SmId = x.SmId,
  1556. UId = user.Id,
  1557. IsTemp = 1,
  1558. }).ToList();
  1559. //添加个人级别岗位
  1560. int AddRows = _UserAuthorityRepository.Adds<Sys_UserAuthority>(userAuth);
  1561. }
  1562. }
  1563. }
  1564. catch (Exception ex)
  1565. {
  1566. _JobPostAuthorityRepository.RollbackTran();
  1567. return Ok(JsonView("系统错误!"));
  1568. }
  1569. _JobPostAuthorityRepository.CommitTran();
  1570. return Ok(JsonView(200, "成功", new { }));
  1571. }
  1572. /// <summary>
  1573. /// 获取员工权限
  1574. /// </summary>
  1575. /// <param name="dto"></param>
  1576. /// <returns></returns>
  1577. [HttpPost]
  1578. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1579. public IActionResult QueryUserAuth(QueryUserAuthDto dto)
  1580. {
  1581. //选中的员工操作权限
  1582. var DBdata = _UserAuthorityRepository.QueryDto<Sys_UserAuthority, UserAuthorityView>(x => x.UId == dto.Userid).ToList();
  1583. var SystemMenuPermissionData = _SystemMenuPermissionRepository.QueryDto<Sys_SystemMenuPermission, SystemMenuPermissionView>(x => x.Mid == dto.moduleId).ToList();
  1584. if (SystemMenuPermissionData == null || SystemMenuPermissionData.Count() == 0)
  1585. {
  1586. return Ok(JsonView("暂无数据"));
  1587. }
  1588. //所有操作
  1589. var PageOperation = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, Sys_PageFunctionPermission>(x => x.IsEnable == 1).ToList();
  1590. //获取所有关联页面
  1591. var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  1592. ArrayList viewData = new ArrayList();
  1593. //组合页面数据
  1594. foreach (var item in SystemMenuPermissionData)
  1595. {
  1596. ArrayList ids = new ArrayList();
  1597. foreach (var viewop in PageOperation)
  1598. {
  1599. var op = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.SmId == item.Id && x.FId == viewop.Id);
  1600. if (op != null)
  1601. {
  1602. ids.Add(viewop.Id);
  1603. }
  1604. }
  1605. //获取本员工拥有的权限
  1606. var DBwhere = DBdata.Where(x => x.SmId == item.Id && x.UId == dto.Userid).ToList();
  1607. viewData.Add(new
  1608. {
  1609. Id = item.Id,
  1610. Mid = item.Mid,
  1611. Name = item.Name,
  1612. SystemMenuCode = item.SystemMenuCode,
  1613. opList = ids,
  1614. selList = DBwhere.Select(x => x.FId)
  1615. });
  1616. }
  1617. return Ok(JsonView(200, "成功!", viewData));
  1618. }
  1619. /// <summary>
  1620. /// 根据Id获取员工所有移动端查看权限
  1621. /// </summary>
  1622. /// <param name="dto"></param>
  1623. /// <returns></returns>
  1624. [HttpPost]
  1625. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1626. public IActionResult QueryUserAuthByUserId(QueryUserAuthByUserIdDto dto)
  1627. {
  1628. string sql = string.Format(@" Select sd1.Id as ModuleId,sd1.Name as ModuleName,sm.Id as MenuId,sm.Name as MenuName From Sys_UserAuthority as u With(Nolock)
  1629. Inner Join Sys_SystemMenuPermission as sm With(Nolock) On u.SmId = sm.Id
  1630. Inner Join Sys_SetData as sd1 With(Nolock) On sm.Mid = sd1.Id
  1631. Where u.IsDel = 0 And sm.IsDel = 0
  1632. And u.UId = {0} And u.FId = 1 ", dto.UserId);
  1633. List<SystemModule_UserAuthSqlView> _dataSource = _sqlSugar.SqlQueryable<SystemModule_UserAuthSqlView>(sql).ToList();
  1634. List<SystemModule_UserAuthView> result = new List<SystemModule_UserAuthView>();
  1635. foreach (SystemModule_UserAuthSqlView item in _dataSource)
  1636. {
  1637. if (result.FirstOrDefault(s => s.ModuleId == item.ModuleId) == null)
  1638. {
  1639. List<SystemModule_UserAuthSqlView> tempList = _dataSource.Where(s => s.ModuleId == item.ModuleId).ToList();
  1640. List<SystemMenu_UserAuthView> menuList = new List<SystemMenu_UserAuthView>();
  1641. foreach (SystemModule_UserAuthSqlView item2 in tempList)
  1642. {
  1643. SystemMenu_UserAuthView menu = new SystemMenu_UserAuthView() { MenuId = item2.MenuId, MenuName = item2.MenuName };
  1644. menuList.Add(menu);
  1645. }
  1646. SystemModule_UserAuthView module = new SystemModule_UserAuthView() { MenuList = menuList, ModuleId = item.ModuleId, ModuleName = item.ModuleName };
  1647. result.Add(module);
  1648. }
  1649. }
  1650. return Ok(JsonView(200, "成功!", result));
  1651. }
  1652. /// <summary>
  1653. /// 保存员工权限
  1654. /// </summary>
  1655. /// <param name="dto"></param>
  1656. /// <returns></returns>
  1657. [HttpPost]
  1658. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1659. public async Task<IActionResult> SaveUserAuth(SaveUserDto dto)
  1660. {
  1661. //获取所有关联页面
  1662. var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  1663. //获取用户当前模块所有启用页面
  1664. var userpageList = _SystemMenuPermissionRepository._sqlSugar.SqlQueryable<Sys_UserAuthority>($@"
  1665. select a.* from Sys_UserAuthority a, Sys_SetData b ,Sys_SystemMenuPermission c
  1666. where a.SmId = c.Id and c.Mid = b.Id and uid = {dto.uid} and c.Mid ={dto.Modulid}
  1667. ").ToList();
  1668. List<Sys_UserAuthority> adds = new List<Sys_UserAuthority>();
  1669. foreach (var item in dto.Savejobs)
  1670. {
  1671. foreach (var fid in item.FIds)
  1672. {
  1673. var whereobj = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.FId == fid && x.SmId == item.SmId);
  1674. if (whereobj != null)
  1675. {
  1676. adds.Add(new Sys_UserAuthority
  1677. {
  1678. CreateTime = DateTime.Now,
  1679. CreateUserId = dto.UserId,
  1680. FId = fid,
  1681. UId = dto.uid,
  1682. SmId = item.SmId,
  1683. IsTemp = 0
  1684. });
  1685. }
  1686. }
  1687. }
  1688. _JobPostAuthorityRepository.BeginTran();
  1689. try
  1690. {
  1691. List<Sys_UserAuthority> userAuth = null;
  1692. //删除个人级岗位权限
  1693. bool isdel = await _UserAuthorityRepository.DeletesAsync<Sys_UserAuthority>(userpageList);
  1694. userAuth = adds.Select(x => new Sys_UserAuthority
  1695. {
  1696. CreateTime = DateTime.Now,
  1697. CreateUserId = dto.UserId,
  1698. FId = x.FId,
  1699. SmId = x.SmId,
  1700. UId = dto.uid,
  1701. IsTemp = 0,
  1702. }).ToList();
  1703. //添加个人级别岗位
  1704. int AddRows = _UserAuthorityRepository.Adds<Sys_UserAuthority>(userAuth);
  1705. }
  1706. catch (Exception ex)
  1707. {
  1708. _JobPostAuthorityRepository.RollbackTran();
  1709. return Ok(JsonView("系统错误!"));
  1710. }
  1711. _JobPostAuthorityRepository.CommitTran();
  1712. return Ok(JsonView(200, "成功", new { }));
  1713. }
  1714. #endregion
  1715. #region 页面配置
  1716. /// <summary>
  1717. /// 页面配置界面数据初始化
  1718. /// </summary>
  1719. /// <returns></returns>
  1720. //[Authorize]
  1721. [HttpPost]
  1722. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1723. public async Task<IActionResult> PageConfigInit()
  1724. {
  1725. ArrayList arr = new ArrayList();
  1726. var viewList = await _setDataRepository.GetSetDataAndPageInfoBySTId();
  1727. if (viewList.Code != 0)
  1728. {
  1729. return Ok(JsonView(viewList.Msg));
  1730. }
  1731. var ModList = await _setDataRepository.GetSySDefultModule();
  1732. return Ok(JsonView(new
  1733. {
  1734. viewList,
  1735. ModList,
  1736. }));
  1737. }
  1738. [HttpPost]
  1739. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1740. public async Task<IActionResult> EditPageInfo(SetDataAndPageInfoDto dto)
  1741. {
  1742. JsonView view = null;
  1743. _SystemMenuPermissionRepository.BeginTran();
  1744. var istrue = await _SystemMenuPermissionRepository.UpdateAsync(x => x.Id == dto.Pageid, x => new Sys_SystemMenuPermission
  1745. {
  1746. AndroidUrl = dto.AndroidUrl,
  1747. CreateTime = DateTime.Now,
  1748. Icon = dto.Icon,
  1749. IosUrl = dto.IosUrl,
  1750. Name = dto.PageName,
  1751. PhoneIsEnable = dto.PagePhoneIsEnable,
  1752. CreateUserId = dto.UserId,
  1753. IsDel = 0,
  1754. IsEnable = dto.PageIsEnable,
  1755. Mid = dto.Modulid,
  1756. Remark = dto.PageRemark,
  1757. SystemMenuCode = dto.SystemMenuCode,
  1758. WebUrl = dto.WebUrl,
  1759. });
  1760. if (istrue)
  1761. {
  1762. //删除页面绑定的操作后重新绑定
  1763. await _SystemMenuAndFunctionRepository.DeleteAsync(x => x.SmId == dto.Pageid);
  1764. List<Sys_SystemMenuAndFunction> binFun = new List<Sys_SystemMenuAndFunction>();
  1765. foreach (var item in dto.FunArr)
  1766. {
  1767. binFun.Add(new Sys_SystemMenuAndFunction
  1768. {
  1769. CreateTime = DateTime.Now,
  1770. CreateUserId = dto.UserId,
  1771. FId = item,
  1772. SmId = dto.Pageid,
  1773. IsDel = 0,
  1774. });
  1775. }
  1776. int number = _SystemMenuAndFunctionRepository.Adds<Sys_SystemMenuAndFunction>(binFun);
  1777. view = JsonView(istrue);
  1778. _SystemMenuPermissionRepository.CommitTran();
  1779. }
  1780. else
  1781. {
  1782. _SystemMenuPermissionRepository.RollbackTran();
  1783. view = JsonView("添加失败");
  1784. }
  1785. return Ok(view);
  1786. }
  1787. /// <summary>
  1788. /// 添加一个页面
  1789. /// </summary>
  1790. /// <param name="dto"></param>
  1791. /// <returns></returns>
  1792. [HttpPost]
  1793. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1794. public async Task<IActionResult> AddPageInfo(SetDataAndPageInfoDto dto)
  1795. {
  1796. JsonView view = null;
  1797. _SystemMenuPermissionRepository.BeginTran();
  1798. int number = await _SystemMenuPermissionRepository.AddAsyncReturnId(new Sys_SystemMenuPermission
  1799. {
  1800. AndroidUrl = dto.AndroidUrl,
  1801. CreateTime = DateTime.Now,
  1802. Icon = dto.Icon,
  1803. IosUrl = dto.IosUrl,
  1804. Name = dto.PageName,
  1805. PhoneIsEnable = dto.PagePhoneIsEnable,
  1806. CreateUserId = dto.UserId,
  1807. IsDel = 0,
  1808. IsEnable = dto.PageIsEnable,
  1809. Mid = dto.Modulid,
  1810. Remark = dto.PageRemark,
  1811. SystemMenuCode = dto.SystemMenuCode,
  1812. WebUrl = dto.WebUrl,
  1813. });
  1814. List<Sys_SystemMenuAndFunction> binFun = new List<Sys_SystemMenuAndFunction>();
  1815. foreach (var item in dto.FunArr)
  1816. {
  1817. binFun.Add(new Sys_SystemMenuAndFunction
  1818. {
  1819. CreateTime = DateTime.Now,
  1820. CreateUserId = dto.UserId,
  1821. FId = item,
  1822. SmId = number,
  1823. IsDel = 0,
  1824. });
  1825. }
  1826. number = _SystemMenuAndFunctionRepository.Adds<Sys_SystemMenuAndFunction>(binFun);
  1827. if (number > 0)
  1828. {
  1829. view = JsonView(number);
  1830. _SystemMenuPermissionRepository.CommitTran();
  1831. }
  1832. else
  1833. {
  1834. _SystemMenuPermissionRepository.RollbackTran();
  1835. view = JsonView("添加失败");
  1836. }
  1837. return Ok(view);
  1838. }
  1839. /// <summary>
  1840. /// 删除页面
  1841. /// </summary>
  1842. /// <param></param>
  1843. /// <returns></returns>
  1844. [HttpPost]
  1845. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1846. public async Task<IActionResult> DelPageInfo(List<SystemMenuDelDto> Dto)
  1847. {
  1848. JsonView view = new JsonView();
  1849. if (Dto.Count > 0)
  1850. {
  1851. try
  1852. {
  1853. _SystemMenuPermissionRepository.BeginTran();
  1854. bool istrue = false;
  1855. foreach (var item in Dto)
  1856. {
  1857. istrue = await _SystemMenuPermissionRepository.SoftDeleteAsync(item.Pageid.ToString());
  1858. if (!istrue)
  1859. {
  1860. throw new Exception("修改失败");
  1861. }
  1862. }
  1863. view.Code = 200;
  1864. view.Msg = "删除成功!";
  1865. view.Data = istrue;
  1866. _SystemMenuPermissionRepository.CommitTran();
  1867. }
  1868. catch (Exception)
  1869. {
  1870. _SystemMenuPermissionRepository.RollbackTran();
  1871. }
  1872. }
  1873. return Ok(JsonView(view));
  1874. }
  1875. /// <summary>
  1876. /// 获取页面绑定的操作
  1877. /// </summary>
  1878. /// <param name="Dto"></param>
  1879. /// <returns></returns>
  1880. [HttpPost]
  1881. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1882. public async Task<IActionResult> QueryPageFunById(PageFunDto Dto)
  1883. {
  1884. //页面与操作关联表
  1885. var pageAndFunList = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  1886. //页面功能表
  1887. var pageFunList = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, Sys_PageFunctionPermission>(x => x.IsEnable == 1).ToList();
  1888. ArrayList arr = new ArrayList();
  1889. foreach (var item in pageFunList)
  1890. {
  1891. var FindVal = pageAndFunList.Find(x => x.SmId == Dto.Pageid && x.FId == item.Id);
  1892. if (FindVal == null)
  1893. {
  1894. arr.Add(new
  1895. {
  1896. id = item.Id,
  1897. name = item.FunctionName,
  1898. value = false
  1899. });
  1900. }
  1901. else
  1902. {
  1903. arr.Add(new
  1904. {
  1905. id = item.Id,
  1906. name = item.FunctionName,
  1907. value = true
  1908. });
  1909. }
  1910. }
  1911. return Ok(JsonView(arr));
  1912. }
  1913. #endregion
  1914. #region 页面操作
  1915. /// <summary>
  1916. /// 操作权限功能表
  1917. /// </summary>
  1918. /// <returns></returns>
  1919. [HttpPost]
  1920. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1921. public async Task<IActionResult> PageFunInit()
  1922. {
  1923. var PageFunInit = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, PageFunctionPermissionView>().ToList();
  1924. if (PageFunInit == null)
  1925. {
  1926. return Ok(JsonView(false, "暂无数据!"));
  1927. }
  1928. return Ok(JsonView(true, "查询成功!", PageFunInit));
  1929. }
  1930. /// <summary>
  1931. /// 操作权限功能表操作(Status 1:添加,2:编辑)
  1932. /// </summary>
  1933. /// <returns></returns>
  1934. [HttpPost]
  1935. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1936. public async Task<IActionResult> OperationFun(OperationFunInitDta dto)
  1937. {
  1938. Result result = await _PageFunctionPermissionRepository.OperationFunInit(dto);
  1939. if (result.Code != 0)
  1940. {
  1941. return Ok(JsonView(false, result.Msg));
  1942. }
  1943. return Ok(JsonView(true, result.Msg));
  1944. }
  1945. /// <summary>
  1946. /// 删除功能
  1947. /// </summary>
  1948. /// <param name="dto"></param>
  1949. /// <returns></returns>
  1950. [HttpPost]
  1951. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1952. public async Task<IActionResult> DelFun(DelFunInitDta dto)
  1953. {
  1954. var res = await _PageFunctionPermissionRepository.SoftDeleteByIdAsync<Sys_PageFunctionPermission>(dto.Id.ToString(), dto.DeleteUserId);
  1955. if (!res)
  1956. {
  1957. return Ok(JsonView(false, "删除失败"));
  1958. }
  1959. return Ok(JsonView(true, "删除成功!"));
  1960. }
  1961. #endregion
  1962. #region 各部门首页消息提示
  1963. /// <summary>
  1964. /// 部门首页消息提示
  1965. /// </summary>
  1966. /// <returns></returns>
  1967. [HttpGet("{portType}")]
  1968. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1969. public async Task<IActionResult> DepartmentHomePageMessagePrompts(int portType)
  1970. {
  1971. var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
  1972. if (currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
  1973. var department = currUserInfo.Department;
  1974. if (portType < 1 || portType > 3) return Ok(JsonView(false, MsgTips.Port));
  1975. if (portType == 1 || portType == 2 || portType == 3) // web
  1976. {
  1977. //固定查询时间(当前月的上月)
  1978. var lastMoth = DateTime.Now.AddMonths(-1);
  1979. var (startDate, endDate) = CommonFun.GetMonthStartAndEndDates(lastMoth.Year, lastMoth.Month);
  1980. var startDateTime = Convert.ToDateTime(startDate.ToString("yyyy-MM-dd 00:00:00"));
  1981. var endDateTime = Convert.ToDateTime(endDate.ToString("yyyy-MM-dd 23:59:59"));
  1982. //固定查询时间(本年)
  1983. var currStartDate = Convert.ToDateTime($"{DateTime.Now.Year}-01-01 00:00:00");
  1984. var currEntDate = Convert.ToDateTime($"{DateTime.Now.Year}-12-31 23:59:59");
  1985. if (department.Equals("总经办")) //总经办
  1986. {
  1987. //1、资料数据(市场部客户资源、op地接导游、op地接车数据、商邀数据、团组收款数据)数据提示Range(固定上个月) -- Add
  1988. #region 市场部客户资源
  1989. //1.1 市场部客户资源
  1990. var users = await _sqlSugar.Queryable<Sys_Users>()
  1991. .LeftJoin<Sys_Department>((u, d) => u.DepId == d.Id)
  1992. .Where((u, d) => u.IsDel == 0 && (d.DepName.Contains("市场部") || u.Id == 21))
  1993. .Select((u, d) => new { u.Id, u.CnName })
  1994. .ToListAsync();
  1995. var marketData = await _sqlSugar.Queryable<Crm_NewClientData>()
  1996. .LeftJoin<Sys_Users>((ncd, u) => ncd.CreateUserId == u.Id)
  1997. .Where((ncd, u) => ncd.IsDel == 0 && ncd.CreateTime >= startDateTime && ncd.CreateTime <= endDateTime)
  1998. .Select((ncd, u) => new
  1999. {
  2000. Area = ncd.Location,
  2001. ncd.Client,
  2002. ncd.Contact,
  2003. ncd.Job,
  2004. Tel = ncd.Telephone,
  2005. ncd.CreateUserId,
  2006. CreatleUserName = u.CnName,
  2007. ncd.CreateTime,
  2008. })
  2009. .ToListAsync();
  2010. foreach (var item in marketData) EncryptionProcessor.DecryptProperties(item);
  2011. var marketDataGroup = marketData.GroupBy(x => x.CreateUserId).Select(g => new { CreateUserId = g.Key, Items = g.ToList(), Count = g.Count() });
  2012. var marketData2 = new List<dynamic>();
  2013. foreach (var user in users)
  2014. {
  2015. var userMarketData = marketDataGroup.FirstOrDefault(x => user.Id == x.CreateUserId);
  2016. if (userMarketData != null)
  2017. {
  2018. marketData2.Add(new
  2019. {
  2020. uId = user.Id,
  2021. name = user.CnName,
  2022. count = userMarketData.Count,
  2023. msgTips = $"上月新增市场客户资源共{userMarketData.Count}条",
  2024. userMarketData = userMarketData.Items
  2025. });
  2026. }
  2027. else
  2028. {
  2029. marketData2.Add(new
  2030. {
  2031. uId = user.Id,
  2032. name = user.CnName,
  2033. count = 0,
  2034. msgTips = $"上月新增市场客户资源共{0}条",
  2035. userMarketData = new List<dynamic>() { },
  2036. });
  2037. }
  2038. }
  2039. var marketData1 = new
  2040. {
  2041. msgTips = $"上月新增市场客户资源共{marketData.Count}条",
  2042. Data = marketData2,
  2043. };
  2044. #endregion
  2045. #region op地接导游
  2046. //1.2 op地接导游
  2047. var opTourGuideData = await _sqlSugar.Queryable<Res_LocalGuideData>()
  2048. .LeftJoin<Sys_Users>((lgd, u) => lgd.CreateUserId == u.Id)
  2049. .Where((lgd, u) => lgd.IsDel == 0 && lgd.CreateTime >= startDateTime && lgd.CreateTime <= endDateTime)
  2050. .Select((lgd, u) => new
  2051. {
  2052. Area = lgd.UnitArea,
  2053. Client = lgd.UnitName,
  2054. lgd.Contact,
  2055. Job = "",
  2056. Tel = lgd.ContactTel,
  2057. lgd.CreateUserId,
  2058. CreatleUserName = u.CnName,
  2059. lgd.CreateTime,
  2060. })
  2061. .ToListAsync();
  2062. foreach (var item in opTourGuideData) EncryptionProcessor.DecryptProperties(item);
  2063. var opTourGuideDataGroups = opTourGuideData.GroupBy(x => x.CreateUserId)
  2064. .Select(g => new
  2065. {
  2066. uId = g.Key,
  2067. name = g.ToList().FirstOrDefault()?.CreatleUserName ?? "-",
  2068. msgTips = $"上月新增OP地接导游资源共{g.Count()}条",
  2069. userTourGuideData = g.ToList(),
  2070. Count = g.Count()
  2071. });
  2072. var opTourGuideData1 = new
  2073. {
  2074. msgTips = $"上月新增OP地接导游资源共{opTourGuideData.Count}条",
  2075. Data = opTourGuideDataGroups,
  2076. };
  2077. #endregion
  2078. #region op车数据
  2079. //1.3 op车数据
  2080. var opCarData = await _sqlSugar.Queryable<Res_CarData>()
  2081. .LeftJoin<Sys_Users>((cd, u) => cd.CreateUserId == u.Id)
  2082. .Where((cd, u) => cd.IsDel == 0 && cd.CreateTime >= startDateTime && cd.CreateTime <= endDateTime)
  2083. .Select((cd, u) => new CarDataMsgTipsView()
  2084. {
  2085. Area = cd.UnitArea,
  2086. Client = cd.UnitName,
  2087. Contact = cd.Contact,
  2088. Job = "",
  2089. Tel = cd.ContactTel,
  2090. CreateUserId = cd.CreateUserId,
  2091. CreatleUserName = u.CnName,
  2092. CreateTime = cd.CreateTime,
  2093. })
  2094. .ToListAsync();
  2095. foreach (var item in opCarData) EncryptionProcessor.DecryptProperties(item);
  2096. var opCarDataGroups = opCarData.GroupBy(x => x.CreateUserId)
  2097. .Select(g => new
  2098. {
  2099. uId = g.Key,
  2100. name = g.ToList().FirstOrDefault()?.CreatleUserName ?? "-",
  2101. msgTips = $"上月新增OP地接车资源共{g.Count()}条",
  2102. userTourGuideData = g.ToList(),
  2103. Count = g.Count()
  2104. });
  2105. var opCarData1 = new
  2106. {
  2107. msgTips = $"上月新增OP地接车资源共{opCarData.Count}条",
  2108. Data = opCarDataGroups,
  2109. };
  2110. #endregion
  2111. #region 商邀数据
  2112. //1.4 商邀数据
  2113. var invitationData = await _sqlSugar.Queryable<Res_InvitationOfficialActivityData>()
  2114. .LeftJoin<Sys_Users>((ioa, u) => ioa.CreateUserId == u.Id)
  2115. .Where((ioa, u) => ioa.IsDel == 0 && ioa.CreateTime >= startDateTime && ioa.CreateTime <= endDateTime)
  2116. .Select((ioa, u) => new
  2117. {
  2118. //Area = string.Format("{0}{1}", ioa.Country, !string.IsNullOrEmpty(ioa.City) ? "" : "-" + ioa.City),
  2119. Area = string.Format("{0}{1}", ioa.Country, ioa.City),
  2120. Client = ioa.UnitName,
  2121. ioa.Contact,
  2122. ioa.Job,
  2123. ioa.Tel,
  2124. ioa.CreateUserId,
  2125. CreatleUserName = u.CnName,
  2126. ioa.CreateTime,
  2127. })
  2128. .ToListAsync();
  2129. var invitationGroups = invitationData.GroupBy(x => x.CreateUserId)
  2130. .Select(g => new
  2131. {
  2132. uId = g.Key,
  2133. name = g.ToList().FirstOrDefault()?.CreatleUserName ?? "-",
  2134. msgTips = $"上月新增商邀资源共{g.Count()}条",
  2135. userTourGuideData = g.ToList(),
  2136. Count = g.Count()
  2137. });
  2138. var invitationData1 = new
  2139. {
  2140. msgTips = $"上月新增商邀资源共{invitationData.Count}条",
  2141. Data = invitationGroups,
  2142. };
  2143. #endregion
  2144. #region 团组收款数据
  2145. //1.5 团组收款数据
  2146. var groupCollectionData = await _sqlSugar.Queryable<Fin_ForeignReceivables>()
  2147. .LeftJoin<Sys_Users>((fr, u) => fr.CreateUserId == u.Id)
  2148. .LeftJoin<Grp_DelegationInfo>((fr, u, di) => fr.Diid == di.Id)
  2149. .LeftJoin<Sys_SetData>((fr, u, di, sd) => fr.Currency == sd.Id)
  2150. .Where((fr, u, di, sd) => fr.IsDel == 0 && fr.CreateTime >= startDateTime && fr.CreateTime <= endDateTime)
  2151. .Select((fr, u, di, sd) => new
  2152. {
  2153. fr.PriceName,
  2154. fr.Price,
  2155. fr.Count,
  2156. fr.Unit,
  2157. fr.ItemSumPrice,
  2158. Currency = sd.Name,
  2159. GroupName = di.TeamName,
  2160. fr.CreateUserId,
  2161. CreateUserName = u.CnName,
  2162. fr.CreateTime,
  2163. })
  2164. .ToListAsync();
  2165. var groupCollectionGroups = groupCollectionData.GroupBy(x => x.CreateUserId)
  2166. .Select(g => new
  2167. {
  2168. uId = g.Key,
  2169. name = g.ToList().FirstOrDefault()?.CreateUserName ?? "-",
  2170. msgTips = $"上月累计团组收款共{g.Count()}条",
  2171. userTourGuideData = g.ToList(),
  2172. Count = g.Count()
  2173. });
  2174. var groupCollectionData2 = new
  2175. {
  2176. msgTips = $"上月累计团组收款共{groupCollectionData.Count}条",
  2177. Data = groupCollectionGroups,
  2178. };
  2179. #endregion
  2180. var materialData = new
  2181. {
  2182. marketData = marketData1,
  2183. opTourGuideData = opTourGuideData1,
  2184. opCarData = opCarData1,
  2185. invitationData = invitationData1,
  2186. groupCollectionData = groupCollectionData2
  2187. };
  2188. //2、费用未审核(日付申请未审核数据、团组费用未审核数据)费用提示Range(固定本年)
  2189. #region 日付申请未审核数据
  2190. var dailyPaymentData = await _sqlSugar.Queryable<Fin_DailyFeePayment>()
  2191. .LeftJoin<Sys_Users>((dfp, u) => dfp.CreateUserId == u.Id)
  2192. .Where(dfp => dfp.IsDel == 0 &&
  2193. dfp.MAudit == 0 &&
  2194. dfp.CreateTime >= currStartDate &&
  2195. dfp.CreateTime <= currEntDate
  2196. )
  2197. .OrderBy(dfp => dfp.CreateTime, OrderByType.Desc)
  2198. //.OrderBy(dfp => dfp.FAudit, OrderByType.Desc)
  2199. .Select((dfp, u) => new
  2200. {
  2201. id = dfp.Id,
  2202. amountName = dfp.Instructions,
  2203. amount = dfp.SumPrice,
  2204. fAuditStatus = dfp.FAudit == 1 ? "审核通过" :
  2205. dfp.FAudit == 2 ? "审核未通过" : "未审核",
  2206. fAuditDate = dfp.FAuditDate,
  2207. dfp.CreateUserId,
  2208. CreateUserName = u.CnName,
  2209. dfp.CreateTime
  2210. })
  2211. .ToListAsync();
  2212. var dailyPaymentGroups = dailyPaymentData.GroupBy(x => x.CreateUserId)
  2213. .Select(g => new
  2214. {
  2215. uId = g.Key,
  2216. name = g.ToList().FirstOrDefault()?.CreateUserName ?? "-",
  2217. msgTips = $"本年有{g.Count()}条未审核日常付款申请条",
  2218. userTourGuideData = g.ToList(),
  2219. Count = g.Count()
  2220. });
  2221. var dailyPaymentData1 = new
  2222. {
  2223. msgTips = $"本年有{dailyPaymentData.Count()}条未审核日常付款申请条",
  2224. Data = dailyPaymentGroups,
  2225. };
  2226. #endregion
  2227. #region 团组费用未审核数据
  2228. var groupPaymentData = await _sqlSugar.Queryable<Grp_CreditCardPayment>()
  2229. .LeftJoin<Grp_DelegationInfo>((ccp, di) => ccp.DIId == di.Id)
  2230. .Where((ccp, di) => ccp.IsDel == 0 &&
  2231. ccp.IsAuditGM == 0 &&
  2232. ccp.CreateTime >= currStartDate &&
  2233. ccp.CreateTime <= currEntDate
  2234. )
  2235. .Select((ccp, di) => new
  2236. {
  2237. ccp.Id,
  2238. ccp.DIId,
  2239. GroupName = di.TeamName,
  2240. ccp.CreateTime,
  2241. })
  2242. .ToListAsync();
  2243. var groupPaymentGroups = groupPaymentData.GroupBy(x => x.DIId)
  2244. .Select(g => new
  2245. {
  2246. uId = g.Key,
  2247. name = g.ToList().FirstOrDefault()?.GroupName ?? "-",
  2248. msgTips = $"本年有{g.Count()}条未审核团组费用申请条",
  2249. userTourGuideData = g.ToList(),
  2250. Count = g.Count()
  2251. });
  2252. var groupPaymentData1 = new
  2253. {
  2254. msgTips = $"本年有{groupPaymentData.Count()}条未审核团组费用申请条",
  2255. Data = groupPaymentGroups,
  2256. };
  2257. #endregion
  2258. var feeUnAuditData = new
  2259. {
  2260. dailyPaymentData = dailyPaymentData1,
  2261. groupPaymentData = groupPaymentData1
  2262. };
  2263. return Ok(JsonView(new { materialData = materialData, feeUnAuditData = feeUnAuditData }));
  2264. }
  2265. else if (department.Equals("国交部"))//国交部
  2266. {
  2267. #region 团组费用录入提示
  2268. /*
  2269. * 名称:团组费用录入提示
  2270. * 描述:团组费用录入提醒(根据团组结束时间 - 3天 如果对应的数据表里没有这个团组的费用信息)
  2271. * 条件:时间范围不限制、 根据团组结束时间 - 3天 == 当前天数
  2272. */
  2273. var groupModlue = new List<int>() {
  2274. 76, //酒店预订
  2275. 79, //车/导游地接
  2276. 80, //签证
  2277. 81, //邀请/公务活动
  2278. //82, //团组客户保险
  2279. 85, //机票预订
  2280. 98, //其他款项
  2281. //285 ,//收款退还
  2282. //1015,//超支费用
  2283. };
  2284. var crrDate = DateTime.Now.ToString("yyyy-MM-dd");
  2285. var groupModlueData = await _sqlSugar.Queryable<Sys_SetData>().Where(x => groupModlue.Contains(x.Id)).ToListAsync();
  2286. var groupFeeData = await _sqlSugar.Queryable<Sys_SetData>()
  2287. .LeftJoin<Grp_CreditCardPayment>((sd, ccp) => sd.Id == ccp.CTable)
  2288. .LeftJoin<Grp_DelegationInfo>((sd, ccp, di) => ccp.DIId == di.Id)
  2289. .Where((sd, ccp, di) => ccp.IsDel == 0 &&
  2290. di.IsDel == 0 &&
  2291. groupModlue.Contains(ccp.CTable) &&
  2292. di.VisitEndDate.AddDays(-3).ToString("yyyy-MM-dd").Equals(crrDate)
  2293. )
  2294. .GroupBy((sd, ccp, di) => new { di.Id, di.TeamName, ccp.CTable, sd.Name }) //可以多字段
  2295. .Select((sd, ccp, di) => new
  2296. {
  2297. diId = di.Id,
  2298. groupName = di.TeamName,
  2299. groupType = ccp.CTable,
  2300. groupTypeName = sd.Name,
  2301. //userId = ccp.CreateUserId,
  2302. count = SqlFunc.AggregateCount(ccp.CTable),
  2303. })
  2304. .ToListAsync();
  2305. var groupFeeData1 = groupFeeData.GroupBy(x => x.diId);
  2306. var groupNotFilledFeeData = new List<dynamic>();
  2307. foreach (var groupFee in groupFeeData1)
  2308. {
  2309. var diId = groupFee.Key;
  2310. var addData = groupFeeData.Where(x => x.diId == diId).Select(x => x.groupType).ToList();
  2311. if (addData.Count < 1) continue;
  2312. var unAddData = groupModlue.Except(addData).ToList();
  2313. if (unAddData.Count < 1) continue;
  2314. foreach (var typeId in unAddData)
  2315. {
  2316. groupNotFilledFeeData.Add(new
  2317. {
  2318. diId = diId,
  2319. groupName = groupFee.FirstOrDefault()?.groupName ?? "-",
  2320. groupType = typeId,
  2321. groupTypeName = groupModlueData.Find(x => x.Id == typeId)?.Name ?? "-",
  2322. count = 0
  2323. });
  2324. }
  2325. }
  2326. #endregion
  2327. #region 日付申请 -- 未审核数据
  2328. var depUserData = await _sqlSugar.Queryable<Sys_Users>()
  2329. .LeftJoin<Sys_Department>((u, d) => u.DepId == d.Id)
  2330. .LeftJoin<Sys_JobPost>((u, d, jp) => u.JobPostId == jp.Id)
  2331. .Where((u, d, jp) => u.IsDel == 0 && d.DepName.Contains("国交部"))
  2332. .Select((u, d, jp) => new
  2333. {
  2334. u.Id,
  2335. u.CnName,
  2336. u.DepId,
  2337. d.DepName,
  2338. u.JobPostId,
  2339. jp.JobName
  2340. })
  2341. .ToListAsync();
  2342. var depUserData1 = depUserData.Select(x => x.Id).ToList();
  2343. var unAuditDailyFeeData = await _sqlSugar.Queryable<Fin_DailyFeePayment>()
  2344. .LeftJoin<Sys_Users>((dfp, u) => dfp.CreateUserId == u.Id)
  2345. .Where((dfp, u) => dfp.IsDel == 0 &&
  2346. depUserData1.Contains(dfp.CreateUserId) &&
  2347. dfp.MAudit == 0 &&
  2348. dfp.CreateTime >= currStartDate &&
  2349. dfp.CreateTime <= currEntDate
  2350. )
  2351. .Select((dfp, u) => new
  2352. {
  2353. id = dfp.Id,
  2354. amountName = dfp.Instructions,
  2355. amount = dfp.SumPrice,
  2356. fAuditStatus = dfp.FAudit == 1 ? "审核通过" :
  2357. dfp.FAudit == 2 ? "审核未通过" : "未审核",
  2358. fAuditDate = dfp.FAuditDate,
  2359. dfp.CreateUserId,
  2360. CreateUserName = u.CnName,
  2361. dfp.CreateTime
  2362. })
  2363. .ToArrayAsync();
  2364. #endregion
  2365. var jobs = new List<string>() { "经理", "主管" };
  2366. if (jobs.Contains(currUserInfo.Role)) //经理、主管
  2367. {
  2368. #region 经理、主管
  2369. //经理、主管(部门下所有人员) --> 日付(-:未审核提示)、团组费用录入提醒(根据团组结束时间-3天 如果对应的数据表里没有这个团组的费用信息)
  2370. var dailyPaymentData = new
  2371. {
  2372. msgTips = $"本年有{unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2373. Data = new
  2374. {
  2375. uId = currUserInfo.UserId,
  2376. name = currUserInfo.UserName,
  2377. msgTips = $"本年有{unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2378. userTourGuideData = unAuditDailyFeeData,
  2379. Count = unAuditDailyFeeData.Count()
  2380. }
  2381. };
  2382. var groupNotFilledFeeDataAll = groupNotFilledFeeData
  2383. .GroupBy(x => x.diId)
  2384. .Select(g => new
  2385. {
  2386. uId = g.Key,
  2387. name = g.ToList().FirstOrDefault()?.groupName ?? "-",
  2388. msgTips = $"-",
  2389. hotelFeeData = g.Select(x1 => new
  2390. {
  2391. x1.groupType,
  2392. x1.groupTypeName
  2393. }).ToList(),
  2394. Count = g.Count()
  2395. })
  2396. .ToList();
  2397. var groupNotFillEdFeeData1 = new
  2398. {
  2399. msgTips = $"今天有{groupNotFilledFeeDataAll.Count()}个团组费用未填写",
  2400. Data = groupNotFilledFeeDataAll,
  2401. };
  2402. #endregion
  2403. return Ok(JsonView(new { groupNotFillEdFeeData = groupNotFillEdFeeData1, dailyPaymentData = dailyPaymentData }));
  2404. }
  2405. else if (currUserInfo.Role.Equals("计调"))//计调
  2406. {
  2407. #region 计调
  2408. //计调(myself) --> 暂定
  2409. return Ok(JsonView(false, "国交部-->计调岗位消息提示正在开发中......"));
  2410. #endregion
  2411. }
  2412. else if (currUserInfo.Role.Equals("机票"))//机票
  2413. {
  2414. #region 机票
  2415. //机票(myself) --> 日付(-:未审核提示)、机票费用(-:未录入提示)
  2416. var airTicket_unAuditDailyFeeData = unAuditDailyFeeData.Where(x => x.CreateUserId == currUserInfo.UserId).ToList();
  2417. var dailyPaymentData = new
  2418. {
  2419. msgTips = $"本年有{airTicket_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2420. Data = new
  2421. {
  2422. uId = currUserInfo.UserId,
  2423. name = currUserInfo.UserName,
  2424. msgTips = $"本年有{airTicket_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2425. userTourGuideData = airTicket_unAuditDailyFeeData,
  2426. Count = airTicket_unAuditDailyFeeData.Count()
  2427. }
  2428. };
  2429. var airTicket_groupNotFilledData = groupNotFilledFeeData
  2430. .Where(x => x.groupType == 85)
  2431. .GroupBy(x => x.diId)
  2432. .Select(g => new
  2433. {
  2434. uId = g.Key,
  2435. name = g.ToList().FirstOrDefault()?.groupName ?? "-",
  2436. msgTips = $"-",
  2437. airTicketFeeData = g.Select(x1 => new
  2438. {
  2439. x1.groupType,
  2440. x1.groupTypeName
  2441. }).ToList(),
  2442. Count = g.Count()
  2443. })
  2444. .ToList();
  2445. var groupNotFillEdFeeData1 = new
  2446. {
  2447. msgTips = $"今天有{airTicket_groupNotFilledData.Count()}个团组费用未填写",
  2448. Data = airTicket_groupNotFilledData,
  2449. };
  2450. #endregion
  2451. return Ok(JsonView(new { groupNotFillEdFeeData = groupNotFillEdFeeData1, dailyPaymentData = dailyPaymentData }));
  2452. }
  2453. else if (currUserInfo.Role.Equals("酒店"))//酒店
  2454. {
  2455. #region 酒店
  2456. //酒店(myself) --> 日付(-:未审核提示)、酒店费用(-:未录入提示)
  2457. var hotle_unAuditDailyFeeData = unAuditDailyFeeData.Where(x => x.CreateUserId == currUserInfo.UserId).ToList();
  2458. var dailyPaymentData = new
  2459. {
  2460. msgTips = $"本年有{hotle_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2461. Data = new
  2462. {
  2463. uId = currUserInfo.UserId,
  2464. name = currUserInfo.UserName,
  2465. msgTips = $"本年有{hotle_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2466. hotelFeeData = hotle_unAuditDailyFeeData,
  2467. Count = hotle_unAuditDailyFeeData.Count()
  2468. }
  2469. };
  2470. var hotel_groupNotFilledData = groupNotFilledFeeData
  2471. .Where(x => x.groupType == 76)
  2472. .GroupBy(x => x.diId)
  2473. .Select(g => new
  2474. {
  2475. uId = g.Key,
  2476. name = g.ToList().FirstOrDefault()?.groupName ?? "-",
  2477. msgTips = $"-",
  2478. hotelFeeData = g.Select(x1 => new
  2479. {
  2480. x1.groupType,
  2481. x1.groupTypeName
  2482. }).ToList(),
  2483. Count = g.Count()
  2484. })
  2485. .ToList();
  2486. var groupNotFillEdFeeData1 = new
  2487. {
  2488. msgTips = $"今天有{hotel_groupNotFilledData.Count()}个团组费用未填写",
  2489. Data = hotel_groupNotFilledData,
  2490. };
  2491. #endregion
  2492. return Ok(JsonView(new { groupNotFillEdFeeData = groupNotFillEdFeeData1, dailyPaymentData = dailyPaymentData }));
  2493. }
  2494. else if (currUserInfo.Role.Equals("签证"))//签证
  2495. {
  2496. #region 签证
  2497. //签证(myself) --> 日付(-:未审核提示)、签证费用(-:未录入提示)
  2498. var visa_unAuditDailyFeeData = unAuditDailyFeeData.Where(x => x.CreateUserId == currUserInfo.UserId).ToList();
  2499. var dailyPaymentData = new
  2500. {
  2501. msgTips = $"本年有{visa_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2502. Data = new
  2503. {
  2504. uId = currUserInfo.UserId,
  2505. name = currUserInfo.UserName,
  2506. msgTips = $"本年有{visa_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2507. visaFeeData = visa_unAuditDailyFeeData,
  2508. Count = visa_unAuditDailyFeeData.Count()
  2509. }
  2510. };
  2511. var visa_groupNotFilledData = groupNotFilledFeeData
  2512. .Where(x => x.groupType == 80)
  2513. .GroupBy(x => x.diId)
  2514. .Select(g => new
  2515. {
  2516. uId = g.Key,
  2517. name = g.ToList().FirstOrDefault()?.groupName ?? "-",
  2518. msgTips = $"-",
  2519. airTicketFeeData = g.Select(x1 => new
  2520. {
  2521. x1.groupType,
  2522. x1.groupTypeName
  2523. }).ToList(),
  2524. Count = g.Count()
  2525. })
  2526. .ToList();
  2527. var groupNotFillEdFeeData1 = new
  2528. {
  2529. msgTips = $"今天有{visa_groupNotFilledData.Count()}个团组费用未填写",
  2530. Data = visa_groupNotFilledData,
  2531. };
  2532. #endregion
  2533. return Ok(JsonView(new { groupNotFillEdFeeData = groupNotFillEdFeeData1, dailyPaymentData = dailyPaymentData }));
  2534. }
  2535. else if (currUserInfo.Role.Equals("商邀"))//商邀
  2536. {
  2537. #region 商邀
  2538. //商邀(myself) --> 日付(-:未审核提示)、商邀费用(-:未录入提示)、(公务、翻译人)(-:新增提示)
  2539. //日付
  2540. var in_unAuditDailyFeeData = unAuditDailyFeeData.Where(x => x.CreateUserId == currUserInfo.UserId).ToList();
  2541. var dailyPaymentData = new
  2542. {
  2543. msgTips = $"本年有{in_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2544. Data = new
  2545. {
  2546. uId = currUserInfo.UserId,
  2547. name = currUserInfo.UserName,
  2548. msgTips = $"本年有{in_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2549. visaFeeData = in_unAuditDailyFeeData,
  2550. Count = in_unAuditDailyFeeData.Count()
  2551. }
  2552. };
  2553. //团组未录入费用
  2554. var in_groupNotFilledData = groupNotFilledFeeData
  2555. .Where(x => x.groupType == 81)
  2556. .GroupBy(x => x.diId)
  2557. .Select(g => new
  2558. {
  2559. uId = g.Key,
  2560. name = g.ToList().FirstOrDefault()?.groupName ?? "-",
  2561. msgTips = $"-",
  2562. airTicketFeeData = g.Select(x1 => new
  2563. {
  2564. x1.groupType,
  2565. x1.groupTypeName
  2566. }).ToList(),
  2567. Count = g.Count()
  2568. })
  2569. .ToList();
  2570. var groupNotFillEdFeeData1 = new
  2571. {
  2572. msgTips = $"今天有{in_groupNotFilledData.Count()}个团组费用未填写",
  2573. Data = in_groupNotFilledData,
  2574. };
  2575. //商邀 - 基础数据
  2576. var invitationData = await _sqlSugar.Queryable<Res_InvitationOfficialActivityData>()
  2577. .LeftJoin<Sys_Users>((ioa, u) => ioa.CreateUserId == u.Id)
  2578. .Where((ioa, u) => ioa.IsDel == 0 && ioa.CreateTime >= startDateTime && ioa.CreateTime <= endDateTime)
  2579. .Select((ioa, u) => new
  2580. {
  2581. //Area = string.Format("{0}{1}", ioa.Country, !string.IsNullOrEmpty(ioa.City) ? "" : "-" + ioa.City),
  2582. Area = string.Format("{0}{1}", ioa.Country, ioa.City),
  2583. Client = ioa.UnitName,
  2584. ioa.Contact,
  2585. ioa.Job,
  2586. ioa.Tel,
  2587. ioa.CreateUserId,
  2588. CreatleUserName = u.CnName,
  2589. ioa.CreateTime,
  2590. })
  2591. .ToListAsync();
  2592. var invitationGroups = invitationData.GroupBy(x => x.CreateUserId)
  2593. .Select(g => new
  2594. {
  2595. uId = g.Key,
  2596. name = g.ToList().FirstOrDefault()?.CreatleUserName ?? "-",
  2597. msgTips = $"上月新增商邀资源共{g.Count()}条",
  2598. userTourGuideData = g.ToList(),
  2599. Count = g.Count()
  2600. });
  2601. var invitationData1 = new
  2602. {
  2603. msgTips = $"上月新增商邀资源共{invitationData.Count}条",
  2604. Data = invitationGroups,
  2605. };
  2606. #endregion
  2607. return Ok(JsonView(new { groupNotFillEdFeeData = groupNotFillEdFeeData1, dailyPaymentData = dailyPaymentData, invitationData = invitationData }));
  2608. }
  2609. else if (currUserInfo.Role.Equals("OP"))//OP
  2610. {
  2611. #region OP
  2612. //OP(myself) --> 日付(-:未审核提示)、OP费用(-:未录入提示)、(导游、车)资源信息(-:新增提示)
  2613. //日付
  2614. var in_unAuditDailyFeeData = unAuditDailyFeeData.Where(x => x.CreateUserId == currUserInfo.UserId).ToList();
  2615. var dailyPaymentData = new
  2616. {
  2617. msgTips = $"本年有{in_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2618. Data = new
  2619. {
  2620. uId = currUserInfo.UserId,
  2621. name = currUserInfo.UserName,
  2622. msgTips = $"本年有{in_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2623. visaFeeData = in_unAuditDailyFeeData,
  2624. Count = in_unAuditDailyFeeData.Count()
  2625. }
  2626. };
  2627. //OP - 团组未录入费用
  2628. var in_groupNotFilledData = groupNotFilledFeeData
  2629. .Where(x => x.groupType == 79)
  2630. .GroupBy(x => x.diId)
  2631. .Select(g => new
  2632. {
  2633. uId = g.Key,
  2634. name = g.ToList().FirstOrDefault()?.groupName ?? "-",
  2635. msgTips = $"-",
  2636. airTicketFeeData = g.Select(x1 => new
  2637. {
  2638. x1.groupType,
  2639. x1.groupTypeName
  2640. }).ToList(),
  2641. Count = g.Count()
  2642. })
  2643. .ToList();
  2644. var groupNotFillEdFeeData1 = new
  2645. {
  2646. msgTips = $"今天有{in_groupNotFilledData.Count()}个团组费用未填写",
  2647. Data = in_groupNotFilledData,
  2648. };
  2649. #region op地接导游
  2650. //1.2 op地接导游
  2651. var opTourGuideData = await _sqlSugar.Queryable<Res_LocalGuideData>()
  2652. .LeftJoin<Sys_Users>((lgd, u) => lgd.CreateUserId == u.Id)
  2653. .Where((lgd, u) => lgd.IsDel == 0 && lgd.CreateTime >= startDateTime && lgd.CreateTime <= endDateTime)
  2654. .Select((lgd, u) => new
  2655. {
  2656. Area = lgd.UnitArea,
  2657. Client = lgd.UnitName,
  2658. lgd.Contact,
  2659. Job = "",
  2660. Tel = lgd.ContactTel,
  2661. lgd.CreateUserId,
  2662. CreatleUserName = u.CnName,
  2663. lgd.CreateTime,
  2664. })
  2665. .ToListAsync();
  2666. foreach (var item in opTourGuideData) EncryptionProcessor.DecryptProperties(item);
  2667. var opTourGuideDataGroups = opTourGuideData.GroupBy(x => x.CreateUserId)
  2668. .Select(g => new
  2669. {
  2670. uId = g.Key,
  2671. name = g.ToList().FirstOrDefault()?.CreatleUserName ?? "-",
  2672. msgTips = $"上月新增OP地接导游资源共{g.Count()}条",
  2673. userTourGuideData = g.ToList(),
  2674. Count = g.Count()
  2675. });
  2676. var opTourGuideData1 = new
  2677. {
  2678. msgTips = $"上月新增OP地接导游资源共{opTourGuideData.Count}条",
  2679. Data = opTourGuideDataGroups,
  2680. };
  2681. #endregion
  2682. #region op车数据
  2683. //1.3 op车数据
  2684. var opCarData = await _sqlSugar.Queryable<Res_CarData>()
  2685. .LeftJoin<Sys_Users>((cd, u) => cd.CreateUserId == u.Id)
  2686. .Where((cd, u) => cd.IsDel == 0 && cd.CreateTime >= startDateTime && cd.CreateTime <= endDateTime)
  2687. .Select((cd, u) => new
  2688. {
  2689. Area = cd.UnitArea,
  2690. Client = cd.UnitName,
  2691. cd.Contact,
  2692. Job = "",
  2693. Tel = cd.ContactTel,
  2694. cd.CreateUserId,
  2695. CreatleUserName = u.CnName,
  2696. cd.CreateTime,
  2697. })
  2698. .ToListAsync();
  2699. var opCarDataGroups = opCarData.GroupBy(x => x.CreateUserId)
  2700. .Select(g => new
  2701. {
  2702. uId = g.Key,
  2703. name = g.ToList().FirstOrDefault()?.CreatleUserName ?? "-",
  2704. msgTips = $"上月新增OP地接车资源共{g.Count()}条",
  2705. userTourGuideData = g.ToList(),
  2706. Count = g.Count()
  2707. });
  2708. var opCarData1 = new
  2709. {
  2710. msgTips = $"上月新增OP地接车资源共{opCarData.Count}条",
  2711. Data = opCarDataGroups,
  2712. };
  2713. #endregion
  2714. #endregion
  2715. return Ok(JsonView(new
  2716. {
  2717. groupNotFillEdFeeData = groupNotFillEdFeeData1,
  2718. dailyPaymentData = dailyPaymentData,
  2719. CarData = opCarData1,
  2720. TourGuideData = opTourGuideData
  2721. }));
  2722. }
  2723. return Ok(JsonView(false, "国交部消息提示正在开发中......"));
  2724. }
  2725. else if (department.Equals("财务部"))//总经办
  2726. {
  2727. #region 团组收款数据
  2728. var groupCollectionData = await _sqlSugar.Queryable<Fin_ForeignReceivables>()
  2729. .LeftJoin<Sys_Users>((fr, u) => fr.CreateUserId == u.Id)
  2730. .LeftJoin<Grp_DelegationInfo>((fr, u, di) => fr.Diid == di.Id)
  2731. .LeftJoin<Sys_SetData>((fr, u, di, sd) => fr.Currency == sd.Id)
  2732. .Where((fr, u, di, sd) => fr.IsDel == 0 && fr.CreateTime >= startDateTime && fr.CreateTime <= endDateTime)
  2733. .Select((fr, u, di, sd) => new
  2734. {
  2735. fr.PriceName,
  2736. fr.Price,
  2737. fr.Count,
  2738. fr.Unit,
  2739. fr.ItemSumPrice,
  2740. Currency = sd.Name,
  2741. GroupName = di.TeamName,
  2742. fr.CreateUserId,
  2743. CreateUserName = u.CnName,
  2744. fr.CreateTime,
  2745. })
  2746. .ToListAsync();
  2747. var groupCollectionGroups = groupCollectionData.GroupBy(x => x.CreateUserId)
  2748. .Select(g => new
  2749. {
  2750. uId = g.Key,
  2751. name = g.ToList().FirstOrDefault()?.CreateUserName ?? "-",
  2752. msgTips = $"上月累计团组收款共{g.Count()}条",
  2753. userTourGuideData = g.ToList(),
  2754. Count = g.Count()
  2755. });
  2756. var groupCollectionData1 = new
  2757. {
  2758. msgTips = $"上月累计团组收款共{groupCollectionData.Count}条",
  2759. Data = groupCollectionGroups,
  2760. };
  2761. #endregion
  2762. #region 日付申请未审核数据
  2763. var dailyPaymentData = await _sqlSugar.Queryable<Fin_DailyFeePayment>()
  2764. .LeftJoin<Sys_Users>((dfp, u) => dfp.CreateUserId == u.Id)
  2765. .Where(dfp => dfp.IsDel == 0 &&
  2766. dfp.MAudit == 0 &&
  2767. dfp.CreateTime >= currStartDate &&
  2768. dfp.CreateTime <= currEntDate
  2769. )
  2770. .OrderBy(dfp => dfp.CreateTime, OrderByType.Desc)
  2771. //.OrderBy(dfp => dfp.FAudit, OrderByType.Desc)
  2772. .Select((dfp, u) => new
  2773. {
  2774. id = dfp.Id,
  2775. amountName = dfp.Instructions,
  2776. amount = dfp.SumPrice,
  2777. fAuditStatus = dfp.FAudit == 1 ? "审核通过" :
  2778. dfp.FAudit == 2 ? "审核未通过" : "未审核",
  2779. fAuditDate = dfp.FAuditDate,
  2780. dfp.CreateUserId,
  2781. CreateUserName = u.CnName,
  2782. dfp.CreateTime
  2783. })
  2784. .ToListAsync();
  2785. var dailyPaymentGroups = dailyPaymentData.GroupBy(x => x.CreateUserId)
  2786. .Select(g => new
  2787. {
  2788. uId = g.Key,
  2789. name = g.ToList().FirstOrDefault()?.CreateUserName ?? "-",
  2790. msgTips = $"本年有{g.Count()}条未审核日常付款申请条",
  2791. userTourGuideData = g.ToList(),
  2792. Count = g.Count()
  2793. });
  2794. var dailyPaymentData1 = new
  2795. {
  2796. msgTips = $"本年有{dailyPaymentData.Count()}条未审核日常付款申请条",
  2797. Data = dailyPaymentGroups,
  2798. };
  2799. #endregion
  2800. return Ok(JsonView(new { groupCollectionData = groupCollectionData1, dailyPaymentData = dailyPaymentData1 }));
  2801. }
  2802. return Ok(JsonView(false, "其余部门消息提示正在开发者中......"));
  2803. }
  2804. return Ok(JsonView(false));
  2805. }
  2806. #endregion
  2807. #region backups
  2808. /// <summary>
  2809. /// 数据库备份
  2810. /// </summary>
  2811. /// <returns></returns>
  2812. [HttpGet]
  2813. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2814. public async Task<IActionResult> SQLServerBackups()
  2815. {
  2816. var now = DateTime.Now;
  2817. var folderPath = $"D:\\数据备份\\{now.ToString("yyyyMMdd")}\\SQLServerBackups";
  2818. if (!Directory.Exists(folderPath)) Directory.CreateDirectory(folderPath);
  2819. //string backupFilePath = $"{folderPath}\\database_backup_OA2014DB_{now.ToString("yyyyMMddHHmmss")}.bat";
  2820. //var backupSql = $"BACKUP DATABASE [OA2014] TO DISK='{backupFilePath}'";
  2821. //Console.WriteLine($"原生备份开始执行");
  2822. //_sqlSugar.ChangeDatabase(DBEnum.OA2014DB);
  2823. //await _sqlSugar.Ado.ExecuteCommandAsync(backupSql);
  2824. //Console.WriteLine($"原生备份成功,文件已生成到:{backupFilePath}");
  2825. //string backupFilePath = $"{folderPath}\\database_backup_OA2014DB_{now.ToString("yyyyMMddHHmmss")}.sql";
  2826. //var backupSql = $"BACKUP DATABASE [OA2014] TO DISK='{backupFilePath}'";
  2827. //Console.WriteLine($"原生备份开始执行");
  2828. //_sqlSugar.ChangeDatabase(DBEnum.OA2014DB);
  2829. //using (StreamWriter writer = new StreamWriter(backupFilePath))
  2830. //{
  2831. // // 获取所有表名
  2832. // var tables = _sqlSugar.Ado.GetDataTable("SELECT name FROM sys.tables").AsEnumerable();
  2833. // foreach (var tableRow in tables)
  2834. // {
  2835. // var tableName = tableRow.Field<string>("name");
  2836. // // 获取表结构的 SQL
  2837. // var createTableSql = _sqlSugar.Ado.GetDataTable($@"
  2838. // SELECT OBJECT_DEFINITION(OBJECT_ID('{tableName}')) AS CreateTableSql").Rows[0][0];
  2839. // writer.WriteLine(createTableSql);
  2840. // writer.WriteLine();
  2841. // // 获取表数据并生成 INSERT 脚本
  2842. // var data = _sqlSugar.Queryable<dynamic>().AS(tableName) .ToList();
  2843. // foreach (var item in data)
  2844. // {
  2845. // var properties = item.GetType().GetProperties();
  2846. // var values = new List<string>();
  2847. // foreach (var prop in properties)
  2848. // {
  2849. // var value = prop.GetValue(item);
  2850. // values.Add(value == null ? "NULL" : $"'{value}'");
  2851. // }
  2852. // var insertSql = $"INSERT INTO {tableName} VALUES ({string.Join(", ", values)});";
  2853. // writer.WriteLine(insertSql);
  2854. // }
  2855. // }
  2856. //}
  2857. //Console.WriteLine($"数据库备份成功,SQL 脚本已生成到:{backupFilePath}");
  2858. return Ok(JsonView(false));
  2859. }
  2860. #endregion
  2861. #region 动态读取excel并去重
  2862. /// <summary>
  2863. /// 客户名单excel导入
  2864. /// </summary>
  2865. /// <returns></returns>
  2866. [HttpPost]
  2867. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2868. public async Task<IActionResult> DynamicReadExcel(IFormFile file )
  2869. {
  2870. // 检查文件是否为空
  2871. if (file == null || file.Length == 0)
  2872. {
  2873. return BadRequest("No file uploaded.");
  2874. }
  2875. // 保存文件到服务器
  2876. var uploadsFolder = Path.Combine(Directory.GetCurrentDirectory(), "File");
  2877. if (!Directory.Exists(uploadsFolder))
  2878. {
  2879. Directory.CreateDirectory(uploadsFolder);
  2880. }
  2881. var filePath = Path.Combine(uploadsFolder, file.FileName);
  2882. using (var stream = new FileStream(filePath, FileMode.Create))
  2883. {
  2884. await file.CopyToAsync(stream);
  2885. }
  2886. Workbook workbook = new Workbook(filePath);
  2887. // 获取第一个工作表
  2888. Worksheet worksheet = workbook.Worksheets[0];
  2889. // 获取表头(第一行作为列名)
  2890. int headerRowIndex = 0; // 假设第一行是表头
  2891. Row headerRow = worksheet.Cells.Rows[headerRowIndex];
  2892. int colCount = worksheet.Cells.MaxDataColumn + 1;
  2893. // 动态存储列名
  2894. var clients = new List<Crm_NewClientData>();
  2895. var lvData = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 33).ToList();
  2896. // 遍历数据行(从第二行开始)
  2897. int rowCount = worksheet.Cells.MaxDataRow + 1;
  2898. for (int row = headerRowIndex + 1; row < rowCount; row++)
  2899. {
  2900. var cellVal1 = worksheet.Cells[row, 0].Value; //序号
  2901. var cellVal2 = worksheet.Cells[row, 1].Value; //单位名称
  2902. var cellVal3 = worksheet.Cells[row, 2].Value; //出访次数
  2903. int count = !string.IsNullOrEmpty(cellVal3?.ToString()) ? int.Parse(cellVal3?.ToString()) : 0;
  2904. var rowData = new Crm_NewClientData() {
  2905. Number = count,
  2906. Client = cellVal2?.ToString().Trim(),//单位名称
  2907. };
  2908. clients.Add(rowData); // 将当前行数据添加到集合中
  2909. }
  2910. if (clients.Any())
  2911. {
  2912. var clientArr = clients.Select(x => x.Client).ToList();
  2913. var clientDatas = _sqlSugar.Queryable<Crm_NewClientData>().Where(x => x.IsDel == 0)
  2914. .ToList()
  2915. .Select(x => new { id = x.Id, client = AesEncryptionHelper.Decrypt(x.Client), remark = AesEncryptionHelper.Decrypt(x.Remark) });
  2916. var clientDatas1 = clientDatas.Where(x => clientArr.Contains(x.client)).ToList();
  2917. var updates = new List<Crm_NewClientData>();
  2918. foreach (var item in clientDatas1)
  2919. {
  2920. string newRemark = item.remark;
  2921. var str = clients.FirstOrDefault(x => x.Client.Equals(item.client))?.Number ?? 0;
  2922. if (str > 0)
  2923. {
  2924. newRemark += $"\r\n2025年拟出访次数{str}次";
  2925. }
  2926. updates.Add(new Crm_NewClientData() {
  2927. Id = item.id,
  2928. Remark = AesEncryptionHelper.Encrypt(newRemark)
  2929. });
  2930. }
  2931. if (updates.Any())
  2932. {
  2933. //加密后更改
  2934. var update = _sqlSugar.Updateable(updates).UpdateColumns(it => new {
  2935. //it.Client,
  2936. it.Remark,
  2937. //it.Phone,
  2938. //it.Address,
  2939. // it.Location,
  2940. }).ExecuteCommand();
  2941. if (update > 0)
  2942. {
  2943. return Ok(JsonView(true, $"数据加密成功!加密条数:{update}"));
  2944. }
  2945. }
  2946. }
  2947. return Ok(JsonView(false));
  2948. }
  2949. /// <summary>
  2950. /// 客户数据加密
  2951. /// </summary>
  2952. /// <returns></returns>
  2953. [HttpGet]
  2954. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2955. public async Task<IActionResult> DynamicReadExcel1()
  2956. {
  2957. // 动态存储列名
  2958. var clients = await _sqlSugar.Queryable<Crm_NewClientData>().Where(x => x.IsDel == 0 && x.Id > 6789).ToListAsync();
  2959. if (clients.Any())
  2960. {
  2961. foreach (var item in clients)
  2962. {
  2963. item.Weight = AesEncryptionHelper.Encrypt("391");
  2964. //Encrypted
  2965. //EncryptionProcessor.EncryptProperties(item);
  2966. }
  2967. //加密后更改
  2968. var update = _sqlSugar.Updateable(clients).UpdateColumns(it => new {
  2969. //it.Client,
  2970. it.Weight,
  2971. //it.Phone,
  2972. //it.Address,
  2973. // it.Location,
  2974. }).ExecuteCommand();
  2975. if (update > 0)
  2976. {
  2977. return Ok(JsonView(true,$"数据加密成功!加密条数:{update}"));
  2978. }
  2979. }
  2980. return Ok(JsonView(false));
  2981. }
  2982. /// <summary>
  2983. /// 数库事务异常测试
  2984. /// </summary>
  2985. /// <returns></returns>
  2986. [HttpGet]
  2987. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  2988. public async Task<IActionResult> TransactionExTest()
  2989. {
  2990. _sqlSugar.BeginTran();
  2991. var a1 = new List<dynamic>();
  2992. var a2 = a1[0].ToString();
  2993. _sqlSugar.RollbackTran();
  2994. return Ok(JsonView(false));
  2995. }
  2996. /// <summary>
  2997. /// 数据测试
  2998. /// </summary>
  2999. /// <returns></returns>
  3000. [HttpGet]
  3001. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3002. public async Task<IActionResult> TransactionExTest1()
  3003. {
  3004. var groupIds = await _sqlSugar.Queryable<Grp_DelegationInfo>()
  3005. .Where(x => x.IsDel == 0)
  3006. .Where(x => x.VisitDate >= Convert.ToDateTime("2025-01-01 00:00:00") && x.VisitDate <= Convert.ToDateTime("2025-12-31 23:59:59"))
  3007. .Select(x => x.Id)
  3008. .ToListAsync();
  3009. var datas = new List<View1>();
  3010. foreach (var id in groupIds)
  3011. {
  3012. var sql = @"
  3013. SELECT
  3014. dac.DiId,
  3015. CASE ntf.City
  3016. WHEN '全部城市' THEN ntf.Country + ' -> 全部城市'
  3017. WHEN '其他城市' THEN ntf.Country + ' -> 其他城市'
  3018. ELSE ntf.Country + ' -> ' + ntf.City
  3019. END as City
  3020. FROM Grp_DayAndCost dac
  3021. LEFT JOIN grp_NationalTravelFee ntf ON dac.NationalTravelFeeId = ntf.Id
  3022. WHERE dac.IsDel = 0
  3023. AND dac.DiId = @DiId
  3024. GROUP BY
  3025. dac.DiId,
  3026. CASE ntf.City
  3027. WHEN '全部城市' THEN ntf.Country + ' -> 全部城市'
  3028. WHEN '其他城市' THEN ntf.Country + ' -> 其他城市'
  3029. ELSE ntf.Country + ' -> ' + ntf.City
  3030. END";
  3031. var data = await _sqlSugar.Ado.SqlQueryAsync<View1>(sql, new { DiId = id });
  3032. datas.AddRange(data);
  3033. }
  3034. var view = datas.GroupBy(x => x.City)
  3035. .Select(x => new
  3036. {
  3037. x.Key,
  3038. Count = x.Count()
  3039. })
  3040. .OrderByDescending(x => x.Count)
  3041. .Skip(1)
  3042. .Take(20)
  3043. .ToList();
  3044. return Ok(JsonView(view));
  3045. }
  3046. private class View1 {
  3047. public int DiId { get; set; }
  3048. public string City { get; set; }
  3049. }
  3050. #endregion
  3051. #region 审批模板
  3052. /// <summary>
  3053. /// 审批模板 - 创建模板
  3054. /// </summary>
  3055. /// <returns></returns>
  3056. [HttpPost]
  3057. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3058. public async Task<IActionResult> AuditTempCreate()
  3059. {
  3060. //领用-其他物品
  3061. //var result = await _approvalProcessRep.CreateAuditTemplate(ApprovalProcessDto.AuditTempOtherGoods());
  3062. //领用-贵重物品
  3063. var result = await _approvalProcessRep.CreateAuditTemplateAsync(ApprovalProcessDto.AuditTempValuableGoods());
  3064. return Ok(JsonView(result));
  3065. }
  3066. #endregion
  3067. #region 资料相关Excel 导入
  3068. /// <summary>
  3069. /// excel导入 策划部供应商资料
  3070. /// </summary>
  3071. /// <param name="file"></param>
  3072. /// <param name="currUserId">录入人userId</param>
  3073. /// <returns></returns>
  3074. [HttpPost]
  3075. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3076. public async Task<IActionResult> ExcelImportMediaSupplier(IFormFile file, [FromQuery] int currUserId = 258)
  3077. {
  3078. // 检查文件是否为空
  3079. if (file == null || file.Length == 0)
  3080. {
  3081. return Ok(JsonView(false, "请选择文件!"));
  3082. }
  3083. // 文件签名验证
  3084. var perExtensions = new[] { ".xls", ".xlsx" };
  3085. Dictionary<string, List<byte[]>> fileSignature = CommonFun.FileSignature;
  3086. fileSignature = fileSignature.Where(pair => perExtensions.Contains(pair.Key)).ToDictionary(pair => pair.Key, pair => pair.Value);
  3087. // 文件扩展名验证
  3088. var ext = Path.GetExtension(file.FileName).ToLowerInvariant();
  3089. if (string.IsNullOrEmpty(ext) || !fileSignature.ContainsKey(ext))
  3090. {
  3091. return Ok(JsonView(false, "不支持的文件类型!"));
  3092. }
  3093. using (var memoryStream = new MemoryStream())
  3094. {
  3095. await file.CopyToAsync(memoryStream);
  3096. // 检查文件签名
  3097. var fileData = memoryStream.ToArray();
  3098. var signatures = fileSignature[ext];
  3099. bool signatureValid = signatures.Any(signature =>
  3100. fileData.Take(signature.Length).SequenceEqual(signature));
  3101. if (!signatureValid)
  3102. {
  3103. return Ok(JsonView(false, "文件内容与类型不匹配!"));
  3104. }
  3105. }
  3106. // 保存文件到服务器
  3107. var uploadsFolder = @$"D:\FTP\File\OA2023\Office\Excel\MediaSupplierExcelImportFile";
  3108. if (!Directory.Exists(uploadsFolder))
  3109. {
  3110. Directory.CreateDirectory(uploadsFolder);
  3111. }
  3112. var fileName = CommonFun.ValidFileName(file.Name);
  3113. var filePath = Path.Combine(uploadsFolder, fileName);
  3114. using (var stream = new FileStream(filePath, FileMode.Create))
  3115. {
  3116. await file.CopyToAsync(stream);
  3117. }
  3118. Workbook workbook = new Workbook(filePath);
  3119. // 获取第一个工作表
  3120. Worksheet worksheet = workbook.Worksheets[0];
  3121. // 获取表头(第一行作为列名)
  3122. int headerRowIndex = 0;
  3123. Row headerRow = worksheet.Cells.Rows[headerRowIndex];
  3124. int colCount = worksheet.Cells.MaxDataColumn + 1;
  3125. // 动态存储列名
  3126. var datas = new List<Res_MediaSuppliers>();
  3127. var typeDatas = await _sqlSugar.Queryable<Sys_SetData>()
  3128. .Where(x => x.IsDel == 0 && x.STid == 21)
  3129. .Select(x => new { x.Id, Text = x.Name })
  3130. .ToListAsync();
  3131. // 遍历数据行(从第二行开始)
  3132. int rowCount = worksheet.Cells.MaxDataRow + 1;
  3133. var msgs = new StringBuilder();
  3134. for (int row = headerRowIndex + 2; row < rowCount; row++)
  3135. {
  3136. var cellVal1 = worksheet.Cells[row, 0].Value; //序号
  3137. var cellVal2 = worksheet.Cells[row, 1].Value; //供应商类型
  3138. var cellVal3 = worksheet.Cells[row, 2].Value; //地区
  3139. var cellVal4 = worksheet.Cells[row, 3].Value; //城市
  3140. var cellVal5 = worksheet.Cells[row, 4].Value; //单位名称
  3141. var cellVal6 = worksheet.Cells[row, 5].Value; //单位联系人
  3142. var cellVal7 = worksheet.Cells[row, 6].Value; //性别
  3143. var cellVal8 = worksheet.Cells[row, 7].Value; //联系电话
  3144. var cellVal9 = worksheet.Cells[row, 8].Value; //电子邮件
  3145. var cellVal10 = worksheet.Cells[row, 9].Value; //单位缩写
  3146. var cellVal11 = worksheet.Cells[row, 10].Value; //职位
  3147. var cellVal12 = worksheet.Cells[row, 11].Value; //传真号码
  3148. var cellVal13 = worksheet.Cells[row, 12].Value; //微信
  3149. var cellVal14 = worksheet.Cells[row, 13].Value; //单位地址
  3150. var cellVal15 = worksheet.Cells[row, 14].Value; //备注
  3151. int typeId = typeDatas.FirstOrDefault(x => x.Text == cellVal2?.ToString())?.Id ?? 0;
  3152. if (typeId < 1)
  3153. {
  3154. var name = cellVal5?.ToString() ?? $"序号:{cellVal1?.ToString() ?? "-"}";
  3155. msgs.AppendLine($"[{name}]未设置供应商类型!请手动录入!!!");
  3156. continue;
  3157. }
  3158. var rowData = new Res_MediaSuppliers()
  3159. {
  3160. TypeId = typeId,
  3161. Privince = cellVal3?.ToString() ?? "",
  3162. City = cellVal4?.ToString() ?? "",
  3163. UnitName = cellVal5?.ToString() ?? "",
  3164. Contact = cellVal6?.ToString() ?? "",
  3165. Sex = string.IsNullOrEmpty(cellVal7?.ToString() ?? "") ? -1 : cellVal7.ToString().Equals("男") ? 0 : 1,
  3166. Tel = cellVal8?.ToString() ?? "",
  3167. Email = cellVal9?.ToString() ?? "",
  3168. UnitAbbreviation = cellVal10?.ToString() ?? "",
  3169. Post = cellVal11?.ToString() ?? "",
  3170. Fax = cellVal12?.ToString() ?? "",
  3171. WeChat = cellVal13?.ToString() ?? "",
  3172. UnitAddress = cellVal14?.ToString() ?? "",
  3173. Remark = cellVal15?.ToString() ?? "",
  3174. CreateUserId = currUserId
  3175. };
  3176. datas.Add(rowData); // 将当前行数据添加到集合中
  3177. }
  3178. if (datas.Any())
  3179. {
  3180. var insert = await _sqlSugar.Insertable(datas).ExecuteCommandAsync();
  3181. if (insert > 0)
  3182. {
  3183. return Ok(JsonView(true, $"导入成功!count:{insert} warningMsg:{msgs.ToString()}"));
  3184. }
  3185. }
  3186. return Ok(JsonView(false, "excel导入失败!"));
  3187. }
  3188. /// <summary>
  3189. /// excel导入 op地接供应商资料收集模板
  3190. /// </summary>
  3191. /// <returns></returns>
  3192. [HttpPost]
  3193. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3194. public async Task<IActionResult> CarDataSouceExcelTemp()
  3195. {
  3196. var url = $"http://132.232.92.186:24/Office/Excel/CarDataSouceImportFile/op地接供应商资料收集模板.xlsx";
  3197. return Ok(JsonView(true, url));
  3198. }
  3199. /// <summary>
  3200. /// excel导入 车公司资料
  3201. /// </summary>
  3202. /// <param name="file"></param>
  3203. /// <param name="currUserId">录入人userId</param>
  3204. /// <returns></returns>
  3205. [HttpPost]
  3206. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3207. public async Task<IActionResult> ExcelImportCarDataSouce(IFormFile file, [FromQuery] int currUserId = 208)
  3208. {
  3209. // 检查文件是否为空
  3210. if (file == null || file.Length == 0)
  3211. {
  3212. return Ok(JsonView(false, "请选择文件!"));
  3213. }
  3214. // 文件签名验证
  3215. var perExtensions = new[] { ".xls", ".xlsx" };
  3216. Dictionary<string, List<byte[]>> fileSignature = CommonFun.FileSignature;
  3217. fileSignature = fileSignature.Where(pair => perExtensions.Contains(pair.Key)).ToDictionary(pair => pair.Key, pair => pair.Value);
  3218. // 文件扩展名验证
  3219. var ext = Path.GetExtension(file.FileName).ToLowerInvariant();
  3220. if (string.IsNullOrEmpty(ext) || !fileSignature.ContainsKey(ext))
  3221. {
  3222. return Ok(JsonView(false, "不支持的文件类型!"));
  3223. }
  3224. using (var memoryStream = new MemoryStream())
  3225. {
  3226. await file.CopyToAsync(memoryStream);
  3227. // 检查文件签名
  3228. var fileData = memoryStream.ToArray();
  3229. var signatures = fileSignature[ext];
  3230. bool signatureValid = signatures.Any(signature =>
  3231. fileData.Take(signature.Length).SequenceEqual(signature));
  3232. if (!signatureValid)
  3233. {
  3234. return Ok(JsonView(false, "文件内容与类型不匹配!"));
  3235. }
  3236. }
  3237. // 保存文件到服务器
  3238. var uploadsFolder = @$"D:\FTP\File\OA2023\Office\Excel\CarDataSouceImportFile";
  3239. if (!Directory.Exists(uploadsFolder))
  3240. {
  3241. Directory.CreateDirectory(uploadsFolder);
  3242. }
  3243. var fileName = CommonFun.ValidFileName(file.Name);
  3244. var filePath = Path.Combine(uploadsFolder, fileName);
  3245. using (var stream = new FileStream(filePath, FileMode.Create))
  3246. {
  3247. await file.CopyToAsync(stream);
  3248. }
  3249. Workbook workbook = new Workbook(filePath);
  3250. // 获取第一个工作表
  3251. Worksheet worksheet = workbook.Worksheets[0];
  3252. // 获取表头(第一行作为列名)
  3253. int headerRowIndex = 0;
  3254. Row headerRow = worksheet.Cells.Rows[headerRowIndex];
  3255. int colCount = worksheet.Cells.MaxDataColumn + 1;
  3256. // 动态存储列名
  3257. var datas = new List<Res_CarData>();
  3258. // 遍历数据行(从第三行开始)
  3259. int rowCount = worksheet.Cells.MaxDataRow + 1;
  3260. var msgs = new StringBuilder();
  3261. for (int row = headerRowIndex + 2; row < rowCount; row++)
  3262. {
  3263. var cellVal1 = worksheet.Cells[row, 0].Value; //地区
  3264. var cellVal2 = worksheet.Cells[row, 1].Value; //公司名称
  3265. var cellVal3 = worksheet.Cells[row, 2].Value; //公司地址
  3266. var cellVal4 = worksheet.Cells[row, 3].Value; //联系人
  3267. var cellVal5 = worksheet.Cells[row, 4].Value; //联系电话
  3268. var cellVal6 = worksheet.Cells[row, 5].Value; //电子邮箱
  3269. var cellVal7 = worksheet.Cells[row, 6].Value; //其他信息
  3270. var dtTimeNoew = DateTime.Now;
  3271. var rowData = new Res_CarData()
  3272. {
  3273. UnitArea = cellVal1?.ToString() ?? "",
  3274. UnitName = cellVal2?.ToString() ?? "",
  3275. Address = cellVal3?.ToString() ?? "",
  3276. Contact = cellVal4?.ToString() ?? "",
  3277. ContactTel = cellVal5?.ToString() ?? "",
  3278. ContactEmail = cellVal6?.ToString() ?? "",
  3279. OtherInfo = cellVal7?.ToString() ?? "",
  3280. LastUpdateTime = dtTimeNoew,
  3281. LastUpdateUserId = currUserId,
  3282. CreateTime = dtTimeNoew,
  3283. CreateUserId = currUserId,
  3284. Remark = $"excel导入添加!"
  3285. };
  3286. EncryptionProcessor.EncryptProperties(rowData);
  3287. datas.Add(rowData);
  3288. }
  3289. if (datas.Any())
  3290. {
  3291. var insert = await _sqlSugar.Insertable(datas).ExecuteCommandAsync();
  3292. if (insert > 0)
  3293. {
  3294. return Ok(JsonView(true, $"导入成功!count:{insert} warningMsg:{msgs.ToString()}"));
  3295. }
  3296. }
  3297. return Ok(JsonView(false, "excel导入失败!"));
  3298. }
  3299. /// <summary>
  3300. /// excel导入 世运会成本预算明细Excel
  3301. /// </summary>
  3302. /// <param name="file"></param>
  3303. /// <param name="currUserId">录入人userId</param>
  3304. /// <returns></returns>
  3305. [HttpPost]
  3306. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3307. public async Task<IActionResult> ExcelImportGamesBudgetDataSouce(IFormFile file, [FromQuery] int currUserId = 208)
  3308. {
  3309. // 检查文件是否为空
  3310. if (file == null || file.Length == 0)
  3311. {
  3312. return Ok(JsonView(false, "请选择文件!"));
  3313. }
  3314. // 文件签名验证
  3315. var perExtensions = new[] { ".xls", ".xlsx" };
  3316. Dictionary<string, List<byte[]>> fileSignature = CommonFun.FileSignature;
  3317. fileSignature = fileSignature.Where(pair => perExtensions.Contains(pair.Key)).ToDictionary(pair => pair.Key, pair => pair.Value);
  3318. // 文件扩展名验证
  3319. var ext = Path.GetExtension(file.FileName).ToLowerInvariant();
  3320. if (string.IsNullOrEmpty(ext) || !fileSignature.ContainsKey(ext))
  3321. {
  3322. return Ok(JsonView(false, "不支持的文件类型!"));
  3323. }
  3324. using (var memoryStream = new MemoryStream())
  3325. {
  3326. await file.CopyToAsync(memoryStream);
  3327. // 检查文件签名
  3328. var fileData = memoryStream.ToArray();
  3329. var signatures = fileSignature[ext];
  3330. bool signatureValid = signatures.Any(signature =>
  3331. fileData.Take(signature.Length).SequenceEqual(signature));
  3332. if (!signatureValid)
  3333. {
  3334. return Ok(JsonView(false, "文件内容与类型不匹配!"));
  3335. }
  3336. }
  3337. // 保存文件到服务器
  3338. var uploadsFolder = @$"D:\FTP\File\OA2023\Office\Excel\CarDataSouceImportFile";
  3339. if (!Directory.Exists(uploadsFolder))
  3340. {
  3341. Directory.CreateDirectory(uploadsFolder);
  3342. }
  3343. var fileName = CommonFun.ValidFileName(file.Name);
  3344. var filePath = Path.Combine(uploadsFolder, fileName);
  3345. using (var stream = new FileStream(filePath, FileMode.Create))
  3346. {
  3347. await file.CopyToAsync(stream);
  3348. }
  3349. Workbook workbook = new Workbook(filePath);
  3350. // 获取第一个工作表
  3351. Worksheet worksheet = workbook.Worksheets[0];
  3352. // 获取表头(第一行作为列名)
  3353. int headerRowIndex = 0;
  3354. Row headerRow = worksheet.Cells.Rows[headerRowIndex];
  3355. int colCount = worksheet.Cells.MaxDataColumn + 1;
  3356. // 动态存储列名
  3357. var datas = new List<Grp_GamesBudgetMaster>();
  3358. // 遍历数据行(从第3行开始)
  3359. int rowCount = worksheet.Cells.MaxDataRow + 1;
  3360. var msgs = new StringBuilder();
  3361. for (int row = headerRowIndex + 2; row < rowCount; row++)
  3362. {
  3363. var cellVal0 = worksheet.Cells[row, 0].Value; //直属父级
  3364. var cellVal1 = worksheet.Cells[row, 1].Value; //工作项目
  3365. var cellVal2 = worksheet.Cells[row, 2].Value; //测算内容
  3366. var cellVal3 = worksheet.Cells[row, 3].Value; //数量
  3367. var cellVal4 = worksheet.Cells[row, 4].Value; //单位
  3368. var cellVal5 = worksheet.Cells[row, 5].Value; //单价(元)
  3369. var cellVal6 = worksheet.Cells[row, 6].Value; //周期-时间
  3370. var cellVal7 = worksheet.Cells[row, 7].Value; //周期-单位
  3371. var cellVal8 = worksheet.Cells[row, 8].Value; //项费用合计
  3372. var cellVal9 = worksheet.Cells[row, 9].Value; //说明
  3373. var cellVal10 = worksheet.Cells[row, 10].Value; //备注
  3374. var dtTimeNoew = DateTime.Now;
  3375. decimal.TryParse(cellVal3?.ToString(), out decimal quantity);
  3376. decimal.TryParse(cellVal5?.ToString(), out decimal unitPrice);
  3377. decimal.TryParse(cellVal8?.ToString(), out decimal itemTotal);
  3378. int.TryParse(cellVal6?.ToString(), out int cycleTime);
  3379. var rowData = new Grp_GamesBudgetMaster()
  3380. {
  3381. T0 = cellVal0?.ToString() ?? "",
  3382. ProjectWork = cellVal1?.ToString() ?? "",
  3383. CalculationContent = cellVal2?.ToString() ?? "",
  3384. Quantity = quantity,
  3385. Unit = cellVal4?.ToString() ?? "",
  3386. UnitPrice = unitPrice,
  3387. CycleTime = cycleTime,
  3388. CycleUnit = cellVal7?.ToString() ?? "",
  3389. ItemTotal = itemTotal,
  3390. Specification = cellVal9?.ToString() ?? "",
  3391. LastUpdateTime = dtTimeNoew.ToString("yyyy-MM-dd HH:mm:ss"),
  3392. LastUpdateUserId = currUserId,
  3393. CreateTime = dtTimeNoew,
  3394. CreateUserId = currUserId,
  3395. Remark = cellVal10?.ToString() ?? ""
  3396. };
  3397. datas.Add(rowData);
  3398. }
  3399. if (datas.Any())
  3400. {
  3401. var insert = await _sqlSugar.Insertable(datas).ExecuteCommandAsync();
  3402. if (insert > 0)
  3403. {
  3404. return Ok(JsonView(true, $"导入成功!count:{insert} warningMsg:{msgs.ToString()}"));
  3405. }
  3406. }
  3407. return Ok(JsonView(false, "excel导入失败!"));
  3408. }
  3409. /// <summary>
  3410. /// excel导入 签证费用标准
  3411. /// </summary>
  3412. /// <param name="file"></param>
  3413. /// <param name="currUserId">录入人userId</param>
  3414. /// <returns></returns>
  3415. [HttpPost]
  3416. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3417. public async Task<IActionResult> ExcelImportVisaFeeStandard(IFormFile file, [FromQuery] int currUserId = 208)
  3418. {
  3419. // 检查文件是否为空
  3420. if (file == null || file.Length == 0)
  3421. {
  3422. return Ok(JsonView(false, "请选择文件!"));
  3423. }
  3424. // 文件签名验证
  3425. var perExtensions = new[] { ".xls", ".xlsx" };
  3426. Dictionary<string, List<byte[]>> fileSignature = CommonFun.FileSignature;
  3427. fileSignature = fileSignature.Where(pair => perExtensions.Contains(pair.Key)).ToDictionary(pair => pair.Key, pair => pair.Value);
  3428. // 文件扩展名验证
  3429. var ext = Path.GetExtension(file.FileName).ToLowerInvariant();
  3430. if (string.IsNullOrEmpty(ext) || !fileSignature.ContainsKey(ext))
  3431. {
  3432. return Ok(JsonView(false, "不支持的文件类型!"));
  3433. }
  3434. using (var memoryStream = new MemoryStream())
  3435. {
  3436. await file.CopyToAsync(memoryStream);
  3437. // 检查文件签名
  3438. var fileData = memoryStream.ToArray();
  3439. var signatures = fileSignature[ext];
  3440. bool signatureValid = signatures.Any(signature =>
  3441. fileData.Take(signature.Length).SequenceEqual(signature));
  3442. if (!signatureValid)
  3443. {
  3444. return Ok(JsonView(false, "文件内容与类型不匹配!"));
  3445. }
  3446. }
  3447. // 保存文件到服务器
  3448. var uploadsFolder = @$"D:\FTP\File\OA2023\Office\Excel\CarDataSouceImportFile";
  3449. if (!Directory.Exists(uploadsFolder))
  3450. {
  3451. Directory.CreateDirectory(uploadsFolder);
  3452. }
  3453. var fileName = CommonFun.ValidFileName(file.Name);
  3454. var filePath = Path.Combine(uploadsFolder, fileName);
  3455. using (var stream = new FileStream(filePath, FileMode.Create))
  3456. {
  3457. await file.CopyToAsync(stream);
  3458. }
  3459. var workbook = new Workbook(filePath);
  3460. // 获取第一个工作表
  3461. Worksheet worksheet = workbook.Worksheets[0]; // 因公护照签证费用标准
  3462. Worksheet worksheet1 = workbook.Worksheets[1]; // 因私护照签证费用标准
  3463. var oldVisaFeeStandards = await _sqlSugar.Queryable<Res_CountryFeeCost>()
  3464. .Where(x => x.IsDel == 0)
  3465. .ToListAsync();
  3466. // 获取表头(第一行作为列名)
  3467. int headerRowIndex = 0;
  3468. Row headerRow = worksheet.Cells.Rows[headerRowIndex];
  3469. int colCount = worksheet.Cells.MaxDataColumn + 1;
  3470. // 动态存储列名
  3471. var datas = new List<VisaFeeStandardInfoView>();
  3472. // 遍历数据行(从第3行开始)
  3473. int rowCount = worksheet.Cells.MaxDataRow + 1;
  3474. var msgs = new StringBuilder();
  3475. for (int row = headerRowIndex + 1; row < rowCount; row++)
  3476. {
  3477. var cellVal0 = worksheet.Cells[row, 0].Value; //国家
  3478. var cellVal1 = worksheet.Cells[row, 1].Value; //公务护照免签
  3479. var cellVal2 = worksheet.Cells[row, 2].Value; //公务护照签证费
  3480. var cellVal3 = worksheet.Cells[row, 3].Value; //公务护照签证代办费
  3481. var cellVal4 = worksheet.Cells[row, 4].Value; //公务普通护照免签
  3482. var cellVal5 = worksheet.Cells[row, 5].Value; //公务普通护照签证费
  3483. var cellVal6 = worksheet.Cells[row, 6].Value; //公务普通护照代办费
  3484. var cellVal7 = worksheet.Cells[row, 7].Value; //云南代办费
  3485. var cellVal8 = worksheet.Cells[row, 8].Value; //贵州代办费
  3486. var cellVal9 = worksheet.Cells[row, 9].Value; //重庆代办费
  3487. var cellVal10 = worksheet.Cells[row, 10].Value; //重庆外办出入境证明费用
  3488. var cellVal11 = worksheet.Cells[row, 11].Value; //送签地点
  3489. var cellVal12 = worksheet.Cells[row, 12].Value; //办理时间(工作日)
  3490. var dtTimeNoew = DateTime.Now;
  3491. var isVisaExemptionLargeVal = cellVal1?.ToString() == "是"; //公务护照免签
  3492. _ = decimal.TryParse(cellVal2?.ToString(), out decimal largeVisaPrice); //公务护照签证费
  3493. _ = decimal.TryParse(cellVal3?.ToString(), out decimal largeAgencyFee); //公务护照签证代办费
  3494. var isVisaExemptionSmallVal = cellVal4?.ToString() == "是" ? true : false; //公务普通护照免签
  3495. _ = decimal.TryParse(cellVal5?.ToString(), out decimal smallVisaPrice); //公务普通护照签证费
  3496. _ = decimal.TryParse(cellVal6?.ToString(), out decimal smallAgencyFee); //公务普通护照签证代办费
  3497. _ = decimal.TryParse(cellVal7?.ToString(), out decimal yunNanAgencyFee); //云南代办费
  3498. _ = decimal.TryParse(cellVal8?.ToString(), out decimal guiZhouAgencyFee); //贵州代办费
  3499. _ = decimal.TryParse(cellVal9?.ToString(), out decimal chongQingAgencyFee); //重庆代办费
  3500. string countryName = cellVal0?.ToString() ?? "";
  3501. string continent=string.Empty,
  3502. remark =string.Empty;
  3503. var oldDataInfo = oldVisaFeeStandards.FirstOrDefault(x => x.VisaFeeType == 0 && x.VisaCountry == countryName);
  3504. if (oldDataInfo != null)
  3505. {
  3506. continent = oldDataInfo.VisaContinent;
  3507. remark = oldDataInfo.VisaPriceDesc;
  3508. }
  3509. var detailsList = new List<VisaFeeStandardDetails>() {
  3510. new(){
  3511. ProvinceId = 122,
  3512. ProvinceName = "四川",
  3513. VisaAddress = cellVal11?.ToString() ?? "",
  3514. VisaTime = cellVal12?.ToString() ?? "0",
  3515. IsVisaExemptionLarge = isVisaExemptionLargeVal,
  3516. LargeVisaPrice = largeVisaPrice,
  3517. LargeAgencyFee = largeAgencyFee,
  3518. IsVisaExemptionSmall = isVisaExemptionSmallVal,
  3519. SmallVisaPrice = smallVisaPrice,
  3520. SmallAgencyFee = smallAgencyFee,
  3521. Remark = remark,
  3522. },
  3523. new(){
  3524. ProvinceId = 103,
  3525. ProvinceName = "重庆",
  3526. SmallAgencyFee = chongQingAgencyFee,
  3527. NormExtFee = 40.00M,
  3528. UrgExtFee = 140.00M,
  3529. },
  3530. new(){
  3531. ProvinceId = 108,
  3532. ProvinceName = "贵州",
  3533. SmallAgencyFee = guiZhouAgencyFee,
  3534. },
  3535. new(){
  3536. ProvinceId = 132,
  3537. ProvinceName = "云南",
  3538. SmallAgencyFee = yunNanAgencyFee,
  3539. },
  3540. };
  3541. var rowData = new VisaFeeStandardInfoView()
  3542. {
  3543. Continent = continent,
  3544. Country = countryName,
  3545. FeeType = 0,
  3546. VisaFees = detailsList
  3547. };
  3548. datas.Add(rowData);
  3549. }
  3550. // 获取表头(第一行作为列名)
  3551. int headerRowIndex1 = 0;
  3552. Row headerRow1 = worksheet1.Cells.Rows[headerRowIndex1];
  3553. int colCount1 = worksheet1.Cells.MaxDataColumn + 1;
  3554. // 遍历数据行(从第3行开始)
  3555. int rowCount1 = worksheet1.Cells.MaxDataRow + 1;
  3556. for (int row = headerRowIndex1 + 1; row < rowCount1; row++)
  3557. {
  3558. var cellVal0 = worksheet1.Cells[row, 0].Value; //国家
  3559. var cellVal1 = worksheet1.Cells[row, 1].Value; //普通护照免签
  3560. var cellVal2 = worksheet1.Cells[row, 2].Value; //签证费
  3561. var cellVal3 = worksheet1.Cells[row, 3].Value; //送签地点
  3562. var cellVal4 = worksheet1.Cells[row, 4].Value; //办理时间(工作日)
  3563. var dtTimeNoew = DateTime.Now;
  3564. var isVisaExemptionSmallVal = cellVal1?.ToString() == "是"; //普通护照免签
  3565. _ = decimal.TryParse(cellVal2?.ToString(), out decimal smallVisaPrice); //普通护照签证费
  3566. string countryName = cellVal0?.ToString() ?? "";
  3567. string continent = string.Empty;
  3568. var oldDataInfo = oldVisaFeeStandards.FirstOrDefault(x => x.VisaFeeType == 1 && x.VisaCountry == countryName);
  3569. if (oldDataInfo != null)
  3570. {
  3571. continent = oldDataInfo.VisaContinent;
  3572. }
  3573. var detailsList = new List<VisaFeeStandardDetails>() {
  3574. new(){
  3575. ProvinceId = 122,
  3576. ProvinceName = "四川",
  3577. VisaAddress = cellVal3?.ToString() ?? "",
  3578. VisaTime = cellVal4?.ToString() ?? "0",
  3579. IsVisaExemptionSmall = isVisaExemptionSmallVal,
  3580. SmallVisaPrice = smallVisaPrice,
  3581. }
  3582. };
  3583. var rowData = new VisaFeeStandardInfoView()
  3584. {
  3585. Continent = continent,
  3586. Country = countryName,
  3587. FeeType = 1,
  3588. VisaFees = detailsList
  3589. };
  3590. datas.Add(rowData);
  3591. }
  3592. if (datas.Any())
  3593. {
  3594. _sqlSugar.BeginTran();
  3595. try
  3596. {
  3597. foreach (var item in datas)
  3598. {
  3599. var now = DateTime.Now;
  3600. var visaFeeStandard = _mapper.Map<Res_VisaFeeStandard>(item);
  3601. visaFeeStandard.LastUpdateTime = now;
  3602. visaFeeStandard.LastUpdateUserId = currUserId;
  3603. visaFeeStandard.CreateTime = now;
  3604. visaFeeStandard.CreateUserId = currUserId;
  3605. var insertId = await _sqlSugar.Insertable(visaFeeStandard).ExecuteReturnIdentityAsync();
  3606. if (insertId < 1)
  3607. {
  3608. _sqlSugar.RollbackTran();
  3609. return Ok(JsonView(false, "excel导入失败!"));
  3610. }
  3611. var visaFeeStandardDetails = _mapper.Map<List<Res_VisaFeeStandardDetails>>(item.VisaFees);
  3612. visaFeeStandardDetails.ForEach(x => {
  3613. x.ParentId = insertId;
  3614. x.CreateUserId = currUserId;
  3615. x.CreateTime = now;
  3616. });
  3617. var insertSubId = await _sqlSugar.Insertable(visaFeeStandardDetails).ExecuteCommandAsync();
  3618. if (insertSubId < 1)
  3619. {
  3620. _sqlSugar.RollbackTran();
  3621. return Ok(JsonView(false, "excel导入失败!"));
  3622. }
  3623. }
  3624. _sqlSugar.CommitTran();
  3625. return Ok(JsonView(true, $"excel导入成功!Total:{datas.Count}"));
  3626. }
  3627. catch (Exception ex)
  3628. {
  3629. _sqlSugar.RollbackTran();
  3630. return Ok(JsonView(false, ex.Message));
  3631. }
  3632. }
  3633. return Ok(JsonView(false, "excel导入失败!"));
  3634. }
  3635. #endregion
  3636. #region 资料导出Excel
  3637. /// <summary>
  3638. /// excel导出 策划部供应商资料
  3639. /// </summary>
  3640. /// <returns></returns>
  3641. [HttpPost]
  3642. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3643. public async Task<IActionResult> ExcelDownloadMediaSupplier()
  3644. {
  3645. var datas = await _sqlSugar.Queryable<Res_MediaSuppliers>().Where(x => x.IsDel == 0).ToListAsync();
  3646. //解密
  3647. var dataView = new List<MediaSupplierExcel>();
  3648. foreach (var item in datas)
  3649. {
  3650. EncryptionProcessor.DecryptProperties(item);
  3651. var typeName = await _sqlSugar.Queryable<Sys_SetData>()
  3652. .Where(x => x.IsDel == 0 && x.Id == item.TypeId)
  3653. .Select(x => x.Name)
  3654. .FirstAsync();
  3655. var createUserName = await _sqlSugar.Queryable<Sys_Users>()
  3656. .Where(x => x.Id == item.CreateUserId)
  3657. .Select(x => x.CnName)
  3658. .FirstAsync();
  3659. dataView.Add(new MediaSupplierExcel
  3660. {
  3661. Id = item.Id,
  3662. TypeName = typeName,
  3663. Privince = item.Privince,
  3664. City = item.City,
  3665. UnitName = item.UnitName,
  3666. UnitAbbreviation = item.UnitAbbreviation,
  3667. UnitAddress = item.UnitAddress,
  3668. Contact = item.Contact,
  3669. Sex = item.Sex,
  3670. Post = item.Post,
  3671. Tel = item.Tel,
  3672. Email = item.Email,
  3673. Fax = item.Fax,
  3674. CreateTime = item.CreateTime,
  3675. CrateUserName = createUserName
  3676. });
  3677. }
  3678. var exportResult = await GeneralMethod.ExportToExcel<MediaSupplierExcel>(dataView, "策划部供应商资料");
  3679. return Ok(JsonView(exportResult));
  3680. }
  3681. private class MediaSupplierExcel
  3682. {
  3683. public int Id { get; set; }
  3684. /// <summary>
  3685. /// 类型
  3686. /// </summary>
  3687. public string TypeName { get; set; }
  3688. /// <summary>
  3689. /// 供应商Type(设置数据外键编号)
  3690. /// </summary>
  3691. public int TypeId { get; set; }
  3692. /// <summary>
  3693. /// 省份
  3694. /// </summary>
  3695. public string Privince { get; set; }
  3696. /// <summary>
  3697. /// 城市
  3698. /// </summary>
  3699. public string City { get; set; }
  3700. /// <summary>
  3701. /// 单位名称
  3702. /// </summary>
  3703. public string UnitName { get; set; }
  3704. /// <summary>
  3705. /// 单位缩写
  3706. /// </summary>
  3707. public string UnitAbbreviation { get; set; }
  3708. /// <summary>
  3709. /// 单位地址
  3710. /// </summary>
  3711. public string UnitAddress { get; set; }
  3712. /// <summary>
  3713. /// 单位联系人
  3714. /// </summary>
  3715. public string Contact { get; set; }
  3716. /// <summary>
  3717. /// 联系人性别
  3718. /// </summary>
  3719. public int Sex { get; set; }
  3720. /// <summary>
  3721. /// 性别
  3722. /// </summary>
  3723. public string SexRole
  3724. {
  3725. get
  3726. {
  3727. if (Sex == 0) return "男";
  3728. else if (Sex == 1) return "女";
  3729. return "";
  3730. }
  3731. }
  3732. /// <summary>
  3733. /// 联系人职位
  3734. /// </summary>
  3735. public string Post { get; set; }
  3736. /// <summary>
  3737. /// 联系人电话
  3738. /// </summary>
  3739. public string Tel { get; set; }
  3740. /// <summary>
  3741. /// 联系人邮箱
  3742. /// </summary>
  3743. public string Email { get; set; }
  3744. /// <summary>
  3745. /// 联系人微信
  3746. /// </summary>
  3747. public string WeChat { get; set; }
  3748. /// <summary>
  3749. /// 传真
  3750. /// </summary>
  3751. public string Fax { get; set; }
  3752. /// <summary>
  3753. /// 创建人
  3754. /// </summary>
  3755. public string CrateUserName { get; set; }
  3756. /// <summary>
  3757. /// 创建时间
  3758. /// </summary>
  3759. public DateTime CreateTime { get; set; } = DateTime.Now;
  3760. /// <summary>
  3761. /// 备注
  3762. /// </summary>
  3763. public string Remark { get; set; }
  3764. }
  3765. /// <summary>
  3766. /// excel导出 车供应商资料
  3767. /// </summary>
  3768. /// <returns></returns>
  3769. [HttpPost]
  3770. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3771. public async Task<IActionResult> ExcelDownloadCar()
  3772. {
  3773. var datas = await _sqlSugar.Queryable<Res_CarData>().Where(x => x.IsDel == 0).ToListAsync();
  3774. var dataView = new List<CarDataExcel>();
  3775. var userInfos = await _sqlSugar.Queryable<Sys_Users>()
  3776. .Select(x => new { x.Id, x.CnName })
  3777. .ToListAsync();
  3778. foreach (var item in datas)
  3779. {
  3780. //解密
  3781. EncryptionProcessor.DecryptProperties(item);
  3782. var createUserName = userInfos.Find(x => x.Id == item.CreateUserId)?.CnName ?? "-";
  3783. var lastUpdateUserName = userInfos.Find(x => x.Id == item.LastUpdateUserId)?.CnName ?? "-";
  3784. dataView.Add(new CarDataExcel
  3785. {
  3786. Id = item.Id,
  3787. UnitArea = item.UnitArea,
  3788. UnitName = item.UnitName,
  3789. Address = item.Address,
  3790. Contact = item.Contact,
  3791. ContactTel = item.ContactTel,
  3792. ContactEmail = item.ContactEmail,
  3793. ContactFax = item.ContactFax,
  3794. CarDes = item.CarDes,
  3795. OtherInfo = item.OtherInfo,
  3796. Score = item.Score,
  3797. QualificationScore = item.QualificationScore,
  3798. CarAgeScore = item.CarAgeScore,
  3799. CleanImgScore = item.CleanImgScore,
  3800. SmellScore = item.SmellScore,
  3801. WaterPaperScore = item.WaterPaperScore,
  3802. HardwareScore = item.HardwareScore,
  3803. SafetyScore = item.SafetyScore,
  3804. DrivingAgeScore = item.DrivingAgeScore,
  3805. Remark = item.Remark,
  3806. LastUpdateTime = item.LastUpdateTime,
  3807. LastUpdateUserName = lastUpdateUserName,
  3808. CreateTime = item.CreateTime,
  3809. CrateUserName = createUserName
  3810. });
  3811. }
  3812. var exportResult = await GeneralMethod.ExportToExcel<CarDataExcel>(dataView, "车公司资料");
  3813. return Ok(JsonView(exportResult));
  3814. }
  3815. private class CarDataExcel
  3816. {
  3817. public int Id { get; set; }
  3818. /// <summary>
  3819. /// 区域
  3820. /// </summary>
  3821. public string UnitArea { get; set; }
  3822. /// <summary>
  3823. /// 公司名称
  3824. /// </summary>
  3825. public string UnitName { get; set; }
  3826. /// <summary>
  3827. /// 地址
  3828. /// </summary>
  3829. public string Address { get; set; }
  3830. /// <summary>
  3831. /// 联系人
  3832. /// </summary>
  3833. public string Contact { get; set; }
  3834. /// <summary>
  3835. /// 联系人手机号
  3836. /// </summary>
  3837. public string ContactTel { get; set; }
  3838. /// <summary>
  3839. /// 联系人邮箱
  3840. /// </summary>
  3841. public string ContactEmail { get; set; }
  3842. /// <summary>
  3843. /// 联系人传真
  3844. /// </summary>
  3845. public string ContactFax { get; set; }
  3846. /// <summary>
  3847. /// 车描述
  3848. /// </summary>
  3849. public string CarDes { get; set; }
  3850. ///// <summary>
  3851. ///// 车图片路径
  3852. ///// 存储多个 使用/r/n
  3853. ///// </summary>
  3854. //public string CarPicPaths { get; set; }
  3855. /// <summary>
  3856. /// 其他信息
  3857. /// </summary>
  3858. public string OtherInfo { get; set; }
  3859. /// <summary>
  3860. /// 服务评分
  3861. /// </summary>
  3862. public int Score { get; set; }
  3863. /// <summary>
  3864. /// 相关的车辆资质
  3865. /// A B C 选择
  3866. /// </summary>
  3867. public string QualificationScore { get; set; }
  3868. /// <summary>
  3869. /// 车辆2-4年新,VIP及以上需要2年新
  3870. /// A B C 选择
  3871. /// </summary>
  3872. public string CarAgeScore { get; set; }
  3873. /// <summary>
  3874. /// 车身干净,无文字图片等
  3875. /// A B C 选择
  3876. /// </summary>
  3877. public string CleanImgScore { get; set; }
  3878. /// <summary>
  3879. /// 车内整洁、无异味
  3880. /// A B C 选择
  3881. /// </summary>
  3882. public string SmellScore { get; set; }
  3883. /// <summary>
  3884. /// 提前备水,纸巾等
  3885. /// A B C 选择
  3886. /// </summary>
  3887. public string WaterPaperScore { get; set; }
  3888. /// <summary>
  3889. /// 车辆配置高(皮座椅等)
  3890. /// A B C 选择
  3891. /// </summary>
  3892. public string HardwareScore { get; set; }
  3893. /// <summary>
  3894. /// 时间概念强
  3895. /// A B C 选择
  3896. /// </summary>
  3897. public string TimeScore { get; set; }
  3898. /// <summary>
  3899. /// 安全意识高
  3900. /// A B C 选择
  3901. /// </summary>
  3902. public string SafetyScore { get; set; }
  3903. /// <summary>
  3904. /// 司机驾龄时间长,提前熟悉路线
  3905. /// A B C 选择
  3906. /// </summary>
  3907. public string DrivingAgeScore { get; set; }
  3908. /// <summary>
  3909. /// 最后更新者Id
  3910. /// </summary>
  3911. public int LastUpdateUserId { get; set; }
  3912. /// <summary>
  3913. /// 最后更新者
  3914. /// </summary>
  3915. public string? LastUpdateUserName { get; set; }
  3916. /// <summary>
  3917. /// 最后更新时间
  3918. /// </summary>
  3919. public DateTime LastUpdateTime { get; set; }
  3920. /// <summary>
  3921. /// 创建人
  3922. /// </summary>
  3923. public string CrateUserName { get; set; }
  3924. /// <summary>
  3925. /// 创建时间
  3926. /// </summary>
  3927. public DateTime CreateTime { get; set; } = DateTime.Now;
  3928. /// <summary>
  3929. /// 备注
  3930. /// </summary>
  3931. public string Remark { get; set; }
  3932. }
  3933. /// <summary>
  3934. /// excel导出 导游地接
  3935. /// </summary>
  3936. /// <returns></returns>
  3937. [HttpPost]
  3938. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  3939. public async Task<IActionResult> ExcelDownloadLocalGuide()
  3940. {
  3941. var datas = await _sqlSugar.Queryable<Res_LocalGuideData>().Where(x => x.IsDel == 0).ToListAsync();
  3942. var dataView = new List<LocalGuideDataExcel>();
  3943. var userInfos = await _sqlSugar.Queryable<Sys_Users>()
  3944. .Select(x => new { x.Id, x.CnName })
  3945. .ToListAsync();
  3946. foreach (var item in datas)
  3947. {
  3948. //解密
  3949. EncryptionProcessor.DecryptProperties(item);
  3950. var createUserName = userInfos.Find(x => x.Id == item.CreateUserId)?.CnName ?? "-";
  3951. var lastUpdateUserName = userInfos.Find(x => x.Id == item.LastUpdateUserId)?.CnName ?? "-";
  3952. dataView.Add(new LocalGuideDataExcel
  3953. {
  3954. Id = item.Id,
  3955. UnitArea = item.UnitArea,
  3956. UnitName = item.UnitName,
  3957. Address = item.Address,
  3958. Contact = item.Contact,
  3959. ContactTel = item.ContactTel,
  3960. ContactEmail = item.ContactEmail,
  3961. ContactFax = item.ContactFax,
  3962. OtherInfo = item.OtherInfo,
  3963. Score = item.Score,
  3964. SuitScore = item.SuitScore,
  3965. ServeScore = item.ServeScore,
  3966. TalkProScore = item.TalkProScore,
  3967. TimeScore = item.TimeScore,
  3968. FitScore = item.FitScore,
  3969. StrainScore = item.StrainScore,
  3970. LocalAndChineseScore = item.LocalAndChineseScore,
  3971. StaffType = item.StaffType,
  3972. Remark = item.Remark,
  3973. LastUpdateTime = item.LastUpdateTime,
  3974. LastUpdateUserName = lastUpdateUserName,
  3975. CreateTime = item.CreateTime,
  3976. CrateUserName = createUserName
  3977. });
  3978. }
  3979. var exportResult = await GeneralMethod.ExportToExcel<LocalGuideDataExcel>(dataView, "导游地接资料");
  3980. return Ok(JsonView(exportResult));
  3981. }
  3982. private class LocalGuideDataExcel
  3983. {
  3984. public int Id { get; set; }
  3985. /// <summary>
  3986. /// 区域
  3987. /// </summary>
  3988. public string UnitArea { get; set; }
  3989. /// <summary>
  3990. /// 公司名称
  3991. /// </summary>
  3992. public string UnitName { get; set; }
  3993. /// <summary>
  3994. /// 地址
  3995. /// </summary>
  3996. public string Address { get; set; }
  3997. /// <summary>
  3998. /// 联系人
  3999. /// </summary>
  4000. public string Contact { get; set; }
  4001. /// <summary>
  4002. /// 联系人手机号
  4003. /// </summary>
  4004. public string ContactTel { get; set; }
  4005. /// <summary>
  4006. /// 联系人邮箱
  4007. /// </summary>
  4008. public string ContactEmail { get; set; }
  4009. /// <summary>
  4010. /// 联系人传真
  4011. /// </summary>
  4012. public string ContactFax { get; set; }
  4013. /// <summary>
  4014. /// 其他信息
  4015. /// </summary>
  4016. public string OtherInfo { get; set; }
  4017. /// <summary>
  4018. /// 服务评分
  4019. /// </summary>
  4020. public int Score { get; set; }
  4021. /// <summary>
  4022. /// 着装得体
  4023. /// A B C 选择
  4024. /// </summary>
  4025. public string SuitScore { get; set; }
  4026. /// <summary>
  4027. /// 服务意识强度
  4028. /// A B C 选择
  4029. /// </summary>
  4030. public string ServeScore { get; set; }
  4031. /// <summary>
  4032. /// 讲解水平专业
  4033. /// A B C 选择
  4034. /// </summary>
  4035. public string TalkProScore { get; set; }
  4036. /// <summary>
  4037. /// 时间概念强度
  4038. /// A B C 选择
  4039. /// </summary>
  4040. public string TimeScore { get; set; }
  4041. /// <summary>
  4042. /// 配合能力强,服从安排
  4043. /// A B C 选择
  4044. /// </summary>
  4045. public string FitScore { get; set; }
  4046. /// <summary>
  4047. /// 应变能力强
  4048. /// A B C 选择
  4049. /// </summary>
  4050. public string StrainScore { get; set; }
  4051. /// <summary>
  4052. /// 当地语言和中文表达流畅
  4053. /// A B C 选择
  4054. /// </summary>
  4055. public string LocalAndChineseScore { get; set; }
  4056. /// <summary>
  4057. /// 导游地接的类型:0公司1私人
  4058. /// </summary>
  4059. [SugarColumn(IsNullable = true, ColumnDataType = "int")]
  4060. public int StaffType { get; set; }
  4061. public string StaffTypeLabel { get{
  4062. if (StaffType == 1) return "私人";
  4063. else if (StaffType == 0) return "公司";
  4064. return "-";
  4065. } }
  4066. /// 最后更新者Id
  4067. /// </summary>
  4068. public int LastUpdateUserId { get; set; }
  4069. /// <summary>
  4070. /// 最后更新者
  4071. /// </summary>
  4072. public string? LastUpdateUserName { get; set; }
  4073. /// <summary>
  4074. /// 最后更新时间
  4075. /// </summary>
  4076. public DateTime LastUpdateTime { get; set; }
  4077. /// <summary>
  4078. /// 创建人
  4079. /// </summary>
  4080. public string CrateUserName { get; set; }
  4081. /// <summary>
  4082. /// 创建时间
  4083. /// </summary>
  4084. public DateTime CreateTime { get; set; } = DateTime.Now;
  4085. /// <summary>
  4086. /// 备注
  4087. /// </summary>
  4088. public string Remark { get; set; }
  4089. }
  4090. /// <summary>
  4091. /// excel导出 客户资料 (YQY)
  4092. /// </summary>
  4093. /// <returns></returns>
  4094. [HttpPost]
  4095. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  4096. public async Task<IActionResult> ExcelDownloadClientYQY()
  4097. {
  4098. var yqyClientIds = new List<int>() {
  4099. 2468,
  4100. 2539,
  4101. 2345,
  4102. 2322,
  4103. 2685,
  4104. 6066,
  4105. 2531,
  4106. 2293,
  4107. 2339,
  4108. 2631,
  4109. 2485,
  4110. 2359,
  4111. 2551,
  4112. 6630,
  4113. 2645,
  4114. 6481,
  4115. 2522,
  4116. 6587,
  4117. 2402,
  4118. 2365,
  4119. 2353,
  4120. 6550,
  4121. 2565,
  4122. 2316,
  4123. 2608,
  4124. 6664,
  4125. 2419,
  4126. 2396,
  4127. 6687,
  4128. 2465,
  4129. 2442,
  4130. 6478,
  4131. 2471,
  4132. 6432,
  4133. 2342,
  4134. 2542,
  4135. 2588,
  4136. 2333,
  4137. 2582,
  4138. 2488,
  4139. 2482,
  4140. 2634,
  4141. 2880,
  4142. 2574,
  4143. 2883,
  4144. 2382,
  4145. 6057,
  4146. 6578,
  4147. 6627,
  4148. 6063,
  4149. 2356,
  4150. 2611,
  4151. 2605,
  4152. 2462,
  4153. 2313,
  4154. 2466,
  4155. 2297,
  4156. 2391,
  4157. 2589,
  4158. 2380,
  4159. 6659,
  4160. 2629,
  4161. 6613,
  4162. 2483,
  4163. 2477,
  4164. 2643,
  4165. 6064,
  4166. 2569,
  4167. 2669,
  4168. 2620,
  4169. 2520,
  4170. 6648,
  4171. 2320,
  4172. 2663,
  4173. 6585,
  4174. 2463,
  4175. 2314,
  4176. 2609,
  4177. 2586,
  4178. 2371,
  4179. 2540,
  4180. 2417,
  4181. 2772,
  4182. 2517,
  4183. 2494,
  4184. 2580,
  4185. 6908,
  4186. 6622,
  4187. 6668,
  4188. 2285,
  4189. 2486,
  4190. 6439,
  4191. 2523,
  4192. 2646,
  4193. 6061,
  4194. 2603,
  4195. 2403,
  4196. 6055,
  4197. 2305,
  4198. 2411,
  4199. 6617,
  4200. 2372,
  4201. 2541,
  4202. 6780,
  4203. 2303,
  4204. 2518,
  4205. 2495,
  4206. 6431,
  4207. 2627,
  4208. 2426,
  4209. 2687,
  4210. 2286,
  4211. 2529,
  4212. 2635,
  4213. 6663,
  4214. 2581,
  4215. 2406,
  4216. 2475,
  4217. 6654,
  4218. 6554,
  4219. 2661,
  4220. 6683,
  4221. 2612,
  4222. 2363,
  4223. 2538,
  4224. 2492,
  4225. 2515,
  4226. 2369,
  4227. 2352,
  4228. 2469,
  4229. 2323,
  4230. 2300,
  4231. 2398,
  4232. 6528,
  4233. 2592,
  4234. 6067,
  4235. 6906,
  4236. 2392,
  4237. 2784,
  4238. 2678,
  4239. 2684,
  4240. 2584,
  4241. 6912,
  4242. 2621,
  4243. 2289,
  4244. 2552,
  4245. 2452,
  4246. 6651,
  4247. 2521,
  4248. 2644,
  4249. 2615,
  4250. 6053,
  4251. 6588,
  4252. 2315,
  4253. 2309,
  4254. 2409,
  4255. 2301,
  4256. 2633,
  4257. 2610,
  4258. 2516,
  4259. 2441,
  4260. 2393,
  4261. 6429,
  4262. 2639,
  4263. 2284,
  4264. 6907,
  4265. 2673,
  4266. 6669,
  4267. 2622,
  4268. 6440,
  4269. 6583,
  4270. 2453,
  4271. 2524,
  4272. 2596,
  4273. 6652,
  4274. 6775,
  4275. 6054,
  4276. 2318,
  4277. 2659,
  4278. 6589,
  4279. 2410,
  4280. 2891,
  4281. 6480,
  4282. 2390,
  4283. 2473,
  4284. 6065,
  4285. 6612,
  4286. 2630,
  4287. 2381,
  4288. 2530,
  4289. 2484,
  4290. 2407,
  4291. 2599,
  4292. 2527,
  4293. 2670,
  4294. 2570,
  4295. 6778,
  4296. 6586,
  4297. 2613,
  4298. 2364,
  4299. };
  4300. var datas = await _sqlSugar.Queryable<Crm_NewClientData>().Where(x => x.IsDel == 0 && yqyClientIds.Contains(x.Id)).ToListAsync();
  4301. //解密
  4302. var dataView = new List<Crm_NewClientDataView>();
  4303. foreach (var item in datas)
  4304. {
  4305. EncryptionProcessor.DecryptProperties(item);
  4306. var area = await _sqlSugar.Queryable<Sys_SetData>()
  4307. .Where(x => x.IsDel == 0 && x.Id == item.Lvlid)
  4308. .Select(x => x.Name)
  4309. .FirstAsync();
  4310. var sex = item.Gender switch {
  4311. 0 => "男",
  4312. 1 => "女",
  4313. _ => "未设置"
  4314. };
  4315. var category = await _sqlSugar.Queryable<Sys_SetData>()
  4316. .Where(x => x.IsDel == 0 && x.Id == item.Category)
  4317. .Select(x => x.Name)
  4318. .FirstAsync();
  4319. var lastUpdateUserName = await _sqlSugar.Queryable<Sys_Users>()
  4320. .Where(x => x.Id == item.LastUpdateUserId)
  4321. .Select(x => x.CnName)
  4322. .FirstAsync();
  4323. dataView.Add(new Crm_NewClientDataView
  4324. {
  4325. Id = item.Id,
  4326. Area = area,
  4327. Client = item.Client,
  4328. Weight = item.Weight,
  4329. ClientShort = item.ClientShort,
  4330. Contact = item.Contact,
  4331. Sex = sex,
  4332. Passport = item.Passport,
  4333. PassportDate = item.PassportDate,
  4334. Job = item.Job,
  4335. Telephone = item.Telephone,
  4336. Phone = item.Phone,
  4337. Email = item.Email,
  4338. Location = item.Location,
  4339. Address = item.Address,
  4340. Birthday = item.Birthday,
  4341. OtherInfo = item.OtherInfo,
  4342. Wechat = item.Wechat,
  4343. Category = category,
  4344. LastUpdateUserName = lastUpdateUserName,
  4345. LastUpdateTime = item.LastUpdateTime,
  4346. });
  4347. }
  4348. var exportResult = await GeneralMethod.ExportToExcel<Crm_NewClientDataView>(dataView, "客户资料资料(YQY)", "客户资料资料(YQY)");
  4349. return Ok(JsonView(exportResult));
  4350. }
  4351. /// <summary>
  4352. /// excel导出 客户资料 (ZQ)
  4353. /// </summary>
  4354. /// <returns></returns>
  4355. [HttpPost]
  4356. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  4357. public async Task<IActionResult> ExcelDownloadClientZQ()
  4358. {
  4359. var yqyClientIds = new List<int>() {
  4360. 5763,
  4361. 5764,
  4362. 5765,
  4363. 5766,
  4364. 5767,
  4365. 5768,
  4366. 5769,
  4367. 5770,
  4368. 5771,
  4369. 5781,
  4370. 5782,
  4371. 5783,
  4372. 5784,
  4373. 5785,
  4374. 5786,
  4375. 5787,
  4376. 5788,
  4377. 5789,
  4378. 5790,
  4379. 5801,
  4380. 5802,
  4381. 5803,
  4382. 5804,
  4383. 5805,
  4384. 5806,
  4385. 5807,
  4386. 5808,
  4387. 5809,
  4388. 5810,
  4389. 5821,
  4390. 5822,
  4391. 5823,
  4392. 5824,
  4393. 5825,
  4394. 5826,
  4395. 5827,
  4396. 5828,
  4397. 5829,
  4398. 5830,
  4399. 5841,
  4400. 5842,
  4401. 5843,
  4402. 5844,
  4403. 5845,
  4404. 5846,
  4405. 5847,
  4406. 5848,
  4407. 5849,
  4408. 5850,
  4409. 5861,
  4410. 5862,
  4411. 2572,
  4412. 2575,
  4413. 6593,
  4414. 2366,
  4415. 2433,
  4416. 2436,
  4417. 6660,
  4418. 2548,
  4419. 2619,
  4420. 4114,
  4421. 2385,
  4422. 6200,
  4423. 2583,
  4424. 2903,
  4425. 2412,
  4426. 2839,
  4427. 2384,
  4428. 2681,
  4429. 2877,
  4430. 6632,
  4431. 6645,
  4432. 2388,
  4433. 2354,
  4434. 2373,
  4435. 2375,
  4436. 6682,
  4437. 2470,
  4438. 2432,
  4439. 2472,
  4440. 2379,
  4441. 2290,
  4442. 2431,
  4443. 2434,
  4444. 2585,
  4445. 2580,
  4446. 2586,
  4447. 2599,
  4448. 6652,
  4449. 2584,
  4450. 2608,
  4451. 2541,
  4452. 6583,
  4453. 6053,
  4454. 2588,
  4455. 2540,
  4456. 2589,
  4457. 6617,
  4458. 6780,
  4459. 6664,
  4460. 6439,
  4461. 6630,
  4462. 2634,
  4463. 2565,
  4464. 2552,
  4465. 2592,
  4466. 2345,
  4467. 6063,
  4468. 2359,
  4469. 6054,
  4470. 6627,
  4471. 2352,
  4472. 2391,
  4473. 6550,
  4474. 2468,
  4475. 2471,
  4476. 2685,
  4477. 2639,
  4478. 2333,
  4479. 2629,
  4480. 2610,
  4481. 2645,
  4482. 2477,
  4483. 2315,
  4484. 2316,
  4485. 2323,
  4486. 2880,
  4487. 2772,
  4488. 6654,
  4489. 6065,
  4490. 2530,
  4491. 6651,
  4492. 2453,
  4493. 2615,
  4494. 2409,
  4495. 2284,
  4496. 2406,
  4497. 2570,
  4498. 2542,
  4499. 2419,
  4500. 2452,
  4501. 6554,
  4502. 2417,
  4503. 2465,
  4504. 2475,
  4505. 2611,
  4506. 2393,
  4507. 2411,
  4508. 6528,
  4509. 2390,
  4510. 2687,
  4511. 2466,
  4512. 2301,
  4513. 2380,
  4514. 2527,
  4515. 6683,
  4516. 6480,
  4517. 6481,
  4518. 2784,
  4519. 2678,
  4520. 2643,
  4521. 2669,
  4522. 2486,
  4523. 2492,
  4524. 2300,
  4525. 2673,
  4526. 6586,
  4527. 6588,
  4528. 2891,
  4529. 2520,
  4530. 2521,
  4531. 6778,
  4532. 6669,
  4533. 6668,
  4534. 6663,
  4535. 6659,
  4536. 2551,
  4537. 2369,
  4538. 6648,
  4539. 2441,
  4540. 2883,
  4541. 2630,
  4542. 2631,
  4543. 2633,
  4544. 2635,
  4545. 2613,
  4546. 2469,
  4547. 2605,
  4548. 2342,
  4549. 6429,
  4550. 2398,
  4551. 2402,
  4552. 2403,
  4553. 2646,
  4554. 2314,
  4555. 2309,
  4556. 2320,
  4557. 2627,
  4558. 2612,
  4559. 2463,
  4560. 6578,
  4561. 6061,
  4562. 2396,
  4563. 2371,
  4564. 2365,
  4565. 2286,
  4566. 2313,
  4567. 2372,
  4568. 2353,
  4569. 2356,
  4570. 2407,
  4571. 2381,
  4572. 2644,
  4573. 6622,
  4574. 2297,
  4575. 2609,
  4576. 2620,
  4577. 2473,
  4578. 6432,
  4579. 6067,
  4580. 2410,
  4581. 2322,
  4582. 2621,
  4583. 2289,
  4584. 6066,
  4585. 2303,
  4586. 2495,
  4587. 2426,
  4588. 6057,
  4589. 2603,
  4590. 2582,
  4591. 2285,
  4592. 2318,
  4593. 2293,
  4594. 2622,
  4595. 2462,
  4596. 6055,
  4597. 2488,
  4598. 6440,
  4599. 2659,
  4600. 2515,
  4601. 6906,
  4602. 6587,
  4603. 6907,
  4604. 2523,
  4605. 2529,
  4606. 2539,
  4607. 2516,
  4608. 6912,
  4609. 2663,
  4610. 6478,
  4611. 2538,
  4612. 2522,
  4613. 2531,
  4614. 2485,
  4615. 2484,
  4616. 6589,
  4617. 6064,
  4618. 2483,
  4619. 6612,
  4620. 6613,
  4621. 6585,
  4622. 2517,
  4623. 2684,
  4624. 2574,
  4625. 2339,
  4626. 2524,
  4627. 2670,
  4628. 2569,
  4629. 2596,
  4630. 2518,
  4631. 2494,
  4632. 2305,
  4633. 2392,
  4634. 6775,
  4635. 2482,
  4636. 6687,
  4637. 6431,
  4638. 2363,
  4639. 6908,
  4640. 2382,
  4641. 2364,
  4642. 2442,
  4643. 2661,
  4644. 2581,
  4645. 2576,
  4646. };
  4647. var datas = await _sqlSugar.Queryable<Crm_NewClientData>().Where(x => x.IsDel == 0 && yqyClientIds.Contains(x.Id)).ToListAsync();
  4648. //解密
  4649. var dataView = new List<Crm_NewClientDataView>();
  4650. foreach (var item in datas)
  4651. {
  4652. EncryptionProcessor.DecryptProperties(item);
  4653. var area = await _sqlSugar.Queryable<Sys_SetData>()
  4654. .Where(x => x.IsDel == 0 && x.Id == item.Lvlid)
  4655. .Select(x => x.Name)
  4656. .FirstAsync();
  4657. var sex = item.Gender switch
  4658. {
  4659. 0 => "男",
  4660. 1 => "女",
  4661. _ => "未设置"
  4662. };
  4663. var category = await _sqlSugar.Queryable<Sys_SetData>()
  4664. .Where(x => x.IsDel == 0 && x.Id == item.Category)
  4665. .Select(x => x.Name)
  4666. .FirstAsync();
  4667. var lastUpdateUserName = await _sqlSugar.Queryable<Sys_Users>()
  4668. .Where(x => x.Id == item.LastUpdateUserId)
  4669. .Select(x => x.CnName)
  4670. .FirstAsync();
  4671. dataView.Add(new Crm_NewClientDataView
  4672. {
  4673. Id = item.Id,
  4674. Area = area,
  4675. Client = item.Client,
  4676. Weight = item.Weight,
  4677. ClientShort = item.ClientShort,
  4678. Contact = item.Contact,
  4679. Sex = sex,
  4680. Passport = item.Passport,
  4681. PassportDate = item.PassportDate,
  4682. Job = item.Job,
  4683. Telephone = item.Telephone,
  4684. Phone = item.Phone,
  4685. Email = item.Email,
  4686. Location = item.Location,
  4687. Address = item.Address,
  4688. Birthday = item.Birthday,
  4689. OtherInfo = item.OtherInfo,
  4690. Wechat = item.Wechat,
  4691. Category = category,
  4692. LastUpdateUserName = lastUpdateUserName,
  4693. LastUpdateTime = item.LastUpdateTime,
  4694. });
  4695. }
  4696. var exportResult = await GeneralMethod.ExportToExcel<Crm_NewClientDataView>(dataView, "客户资料资料(ZQ)", "客户资料资料(ZQ)");
  4697. return Ok(JsonView(exportResult));
  4698. }
  4699. /// <summary>
  4700. /// 新客户资料表
  4701. /// </summary>
  4702. public class Crm_NewClientDataView : EntityBase
  4703. {
  4704. private int number;
  4705. private string client;
  4706. private string weight;
  4707. private string clientshort;
  4708. private string contact;
  4709. private int gender;
  4710. private string passport;
  4711. private DateTime? passportDate;
  4712. private string job;
  4713. private string telephone;
  4714. private string phone;
  4715. private string email;
  4716. private string location;
  4717. private string address;
  4718. private string birthday;
  4719. private string otherinfo;
  4720. private string wechat;
  4721. private string category;
  4722. private int predele;
  4723. private int finlishedDele;
  4724. private string lastUpdateUserName;
  4725. private DateTime lastUpdateTime;
  4726. private string area;
  4727. private string sex;
  4728. /// <summary>
  4729. /// 序号
  4730. /// </summary>
  4731. public int Number { get => number; set => number = value; }
  4732. /// <summary>
  4733. /// 客户区域
  4734. /// </summary>
  4735. public string Area { get => area; set => area = value; }
  4736. /// <summary>
  4737. /// 客户单位
  4738. /// </summary>
  4739. public string Client { get => client; set => client = value; }
  4740. /// <summary>
  4741. /// 权重
  4742. /// </summary>
  4743. public string Weight { get => weight; set => weight = value; }
  4744. /// <summary>
  4745. /// 客户单位简写
  4746. /// </summary>
  4747. public string ClientShort { get => clientshort; set => clientshort = value; }
  4748. /// <summary>
  4749. /// 联系人
  4750. /// </summary>
  4751. public string Contact { get => contact; set => contact = value; }
  4752. /// <summary>
  4753. /// 联系人性别
  4754. /// </summary>
  4755. public string Sex { get => sex; set => sex = value; }
  4756. /// <summary>
  4757. /// 护照
  4758. /// </summary>
  4759. public string Passport { get => passport; set => passport = value; }
  4760. /// <summary>
  4761. /// 护照日期
  4762. /// </summary>
  4763. public DateTime? PassportDate { get => passportDate; set => passportDate = value; }
  4764. /// <summary>
  4765. /// 职位
  4766. /// </summary>
  4767. [Encrypted]
  4768. public string Job { get => job; set => job = value; }
  4769. /// <summary>
  4770. /// 联系手机号
  4771. /// </summary>
  4772. [Encrypted]
  4773. public string Telephone { get => telephone; set => telephone = value; }
  4774. /// <summary>
  4775. /// 联系座机号
  4776. /// </summary>
  4777. [Encrypted]
  4778. public string Phone { get => phone; set => phone = value; }
  4779. /// <summary>
  4780. /// 邮件
  4781. /// </summary>
  4782. [Encrypted]
  4783. public string Email { get => email; set => email = value; }
  4784. /// <summary>
  4785. /// 所属区域(所在城市)
  4786. /// </summary>
  4787. public string Location { get => location; set => location = value; }
  4788. /// <summary>
  4789. /// 地址
  4790. /// </summary>
  4791. public string Address { get => address; set => address = value; }
  4792. /// <summary>
  4793. /// 生日
  4794. /// </summary>
  4795. public string Birthday { get => birthday; set => birthday = value; }
  4796. /// <summary>
  4797. /// 其他信息
  4798. /// </summary>
  4799. public string OtherInfo { get => otherinfo; set => otherinfo = value; }
  4800. /// <summary>
  4801. /// 微信
  4802. /// </summary>
  4803. public string Wechat { get => wechat; set => wechat = value; }
  4804. /// <summary>
  4805. /// 分类
  4806. /// </summary>
  4807. public string Category { get => category; set => category = value; }
  4808. /// <summary>
  4809. /// 预计出团
  4810. /// </summary>
  4811. public int PreDele { get => predele; set => predele = value; }
  4812. /// <summary>
  4813. /// 已出团
  4814. /// </summary>
  4815. public int FinlishedDele { get => finlishedDele; set => finlishedDele = value; }
  4816. /// <summary>
  4817. /// 最后更新者Id
  4818. /// </summary>
  4819. public string LastUpdateUserName { get => lastUpdateUserName; set => lastUpdateUserName = value; }
  4820. /// <summary>
  4821. /// 最后更新时间
  4822. /// </summary>
  4823. public DateTime LastUpdateTime { get => lastUpdateTime; set => lastUpdateTime = value; }
  4824. }
  4825. #endregion
  4826. #region DeepSeek 测试
  4827. /// <summary>
  4828. /// DeepSeek Chat 测试
  4829. /// </summary>
  4830. /// <returns></returns>
  4831. [HttpGet]
  4832. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  4833. public async Task<IActionResult> DeepSeekChatTest()
  4834. {
  4835. string question = "请根据以下数据分析用户绩效:外出打卡信息:[{\"userid\":\"ChenXiaoLong\",\"groupname\":\"重庆公司\",\"checkin_type\":\"外出打卡\",\"exception_type\":\"\",\"checkin_time\":1756783746,\"checkin_time_dt\":\"2025-09-02T11:29:06+08:00\",\"location_title\":\"重庆商务职业学院\",\"location_detail\":\"重庆市沙坪坝区大学城中路81号\",\"wifiname\":\"\",\"notes\":\"\",\"wifimac\":\"\",\"mediaids\":[\"WWME_IJgBCQAAtS1mJ3DrdXjEX26tMWIiVQ\"],\"lat\":29636815,\"lng\":106310562,\"deviceid\":\"4e7878b87ea6a15d\",\"sch_checkin_time\":0,\"sch_checkin_time_dt\":\"1970-01-01T08:00:00+08:00\",\"groupid\":6,\"schedule_id\":0,\"timeline_id\":0},{\"userid\":\"ChenXiaoLong\",\"groupname\":\"重庆公司\",\"checkin_type\":\"外出打卡\",\"exception_type\":\"\",\"checkin_time\":1757057563,\"checkin_time_dt\":\"2025-09-05T15:32:43+08:00\",\"location_title\":\"玉马路\",\"location_detail\":\"重庆市重庆市南岸区玉马路\",\"wifiname\":\"\",\"notes\":\"\",\"wifimac\":\"\",\"mediaids\":[\"WWME_IJgBCQAAsBgFYa0yUdhHUEyWdS7YHA\"],\"lat\":29487287,\"lng\":106641173,\"deviceid\":\"4e7878b87ea6a15d\",\"sch_checkin_time\":0,\"sch_checkin_time_dt\":\"1970-01-01T08:00:00+08:00\",\"groupid\":6,\"schedule_id\":0,\"timeline_id\":0},{\"userid\":\"ChenXiaoLong\",\"groupname\":\"重庆公司\",\"checkin_type\":\"外出打卡\",\"exception_type\":\"\",\"checkin_time\":1757905698,\"checkin_time_dt\":\"2025-09-15T11:08:18+08:00\",\"location_title\":\"重庆市南岸区人民政府外事办公室\",\"location_detail\":\"重庆市南岸区广福大道12号行政中心B区3号楼13楼\",\"wifiname\":\"\",\"notes\":\"\",\"wifimac\":\"\",\"mediaids\":[\"WWME_IJgBCQAA_EzFYYtBDh-qlP6Fv3CBqg\"],\"lat\":29497430,\"lng\":106643893,\"deviceid\":\"4e7878b87ea6a15d\",\"sch_checkin_time\":0,\"sch_checkin_time_dt\":\"1970-01-01T08:00:00+08:00\",\"groupid\":6,\"schedule_id\":0,\"timeline_id\":0},{\"userid\":\"ChenXiaoLong\",\"groupname\":\"重庆公司\",\"checkin_type\":\"外出打卡\",\"exception_type\":\"\",\"checkin_time\":1758005516,\"checkin_time_dt\":\"2025-09-16T14:51:56+08:00\",\"location_title\":\"重庆经济技术开发区\",\"location_detail\":\"重庆市南岸区通江大道\",\"wifiname\":\"\",\"notes\":\"\",\"wifimac\":\"\",\"mediaids\":[\"WWME_IJgBCQAA6YRkLQC_338TIngtZDBaow\"],\"lat\":29532226,\"lng\":106671598,\"deviceid\":\"4e7878b87ea6a15d\",\"sch_checkin_time\":0,\"sch_checkin_time_dt\":\"1970-01-01T08:00:00+08:00\",\"groupid\":6,\"schedule_id\":0,\"timeline_id\":0},{\"userid\":\"ChenXiaoLong\",\"groupname\":\"重庆公司\",\"checkin_type\":\"外出打卡\",\"exception_type\":\"\",\"checkin_time\":1758009181,\"checkin_time_dt\":\"2025-09-16T15:53:01+08:00\",\"location_title\":\"重庆市南岸区商务委员会\",\"location_detail\":\"重庆市南岸区茶园广福大道行政中心B区2号楼1201室\",\"wifiname\":\"\",\"notes\":\"\",\"wifimac\":\"\",\"mediaids\":[\"WWME_IJgBCQAAl0jNUj3SSKu1-S9lL5evNQ\"],\"lat\":29496290,\"lng\":106644165,\"deviceid\":\"4e7878b87ea6a15d\",\"sch_checkin_time\":0,\"sch_checkin_time_dt\":\"1970-01-01T08:00:00+08:00\",\"groupid\":6,\"schedule_id\":0,\"timeline_id\":0},{\"userid\":\"ChenXiaoLong\",\"groupname\":\"重庆公司\",\"checkin_type\":\"外出打卡\",\"exception_type\":\"\",\"checkin_time\":1758426677,\"checkin_time_dt\":\"2025-09-21T11:51:17+08:00\",\"location_title\":\"重庆市城投金卡信息产业(集团)股份有限公司\",\"location_detail\":\"重庆市南岸区通江大道221号\",\"wifiname\":\"\",\"notes\":\"\",\"wifimac\":\"\",\"mediaids\":[\"WWME_IJgBCQAAGaq58r4s6m0EOiLVrpYBKA\"],\"lat\":29473784,\"lng\":106632510,\"deviceid\":\"4e7878b87ea6a15d\",\"sch_checkin_time\":0,\"sch_checkin_time_dt\":\"1970-01-01T08:00:00+08:00\",\"groupid\":6,\"schedule_id\":0,\"timeline_id\":0},{\"userid\":\"ChenXiaoLong\",\"groupname\":\"重庆公司\",\"checkin_type\":\"外出打卡\",\"exception_type\":\"\",\"checkin_time\":1758512376,\"checkin_time_dt\":\"2025-09-22T11:39:36+08:00\",\"location_title\":\"重庆市璧山区人民政府\",\"location_detail\":\"重庆市璧山区登云路登云公园南门西250米路北\",\"wifiname\":\"\",\"notes\":\"\",\"wifimac\":\"\",\"mediaids\":[\"WWME_IJgBCQAAr9X-4yIF7AuiYiPcyAF-ig\"],\"lat\":29577470,\"lng\":106204940,\"deviceid\":\"4e7878b87ea6a15d\",\"sch_checkin_time\":0,\"sch_checkin_time_dt\":\"1970-01-01T08:00:00+08:00\",\"groupid\":6,\"schedule_id\":0,\"timeline_id\":0},{\"userid\":\"ChenXiaoLong\",\"groupname\":\"重庆公司\",\"checkin_type\":\"外出打卡\",\"exception_type\":\"\",\"checkin_time\":1758523406,\"checkin_time_dt\":\"2025-09-22T14:43:26+08:00\",\"location_title\":\"重庆商务职业学院\",\"location_detail\":\"重庆市沙坪坝区大学城中路81号\",\"wifiname\":\"\",\"notes\":\"\",\"wifimac\":\"\",\"mediaids\":[\"WWME_IJgBCQAAAdwjWOUkRos7y2sgtMbenQ\"],\"lat\":29636815,\"lng\":106310562,\"deviceid\":\"4e7878b87ea6a15d\",\"sch_checkin_time\":0,\"sch_checkin_time_dt\":\"1970-01-01T08:00:00+08:00\",\"groupid\":6,\"schedule_id\":0,\"timeline_id\":0},{\"userid\":\"ChenXiaoLong\",\"groupname\":\"重庆公司\",\"checkin_type\":\"外出打卡\",\"exception_type\":\"\",\"checkin_time\":1758523633,\"checkin_time_dt\":\"2025-09-22T14:47:13+08:00\",\"location_title\":\"大学城北一路\",\"location_detail\":\"重庆市重庆市沙坪坝区大学城北一路\",\"wifiname\":\"\",\"notes\":\"\",\"wifimac\":\"\",\"mediaids\":[\"WWME_IJgBCQAAzlAxBKvG6jsl5OQDbyMw7Q\"],\"lat\":29629184,\"lng\":106318865,\"deviceid\":\"4e7878b87ea6a15d\",\"sch_checkin_time\":0,\"sch_checkin_time_dt\":\"1970-01-01T08:00:00+08:00\",\"groupid\":6,\"schedule_id\":0,\"timeline_id\":0},{\"userid\":\"ChenXiaoLong\",\"groupname\":\"重庆公司\",\"checkin_type\":\"外出打卡\",\"exception_type\":\"\",\"checkin_time\":1758850498,\"checkin_time_dt\":\"2025-09-26T09:34:58+08:00\",\"location_title\":\"重庆市南岸区商务委员会\",\"location_detail\":\"重庆市南岸区茶园广福大道行政中心B区2号楼1201室\",\"wifiname\":\"\",\"notes\":\"\",\"wifimac\":\"\",\"mediaids\":[\"WWME_IJgBCQAAuNqoUATiXb0AV5NA5844wg\"],\"lat\":29496290,\"lng\":106644165,\"deviceid\":\"4e7878b87ea6a15d\",\"sch_checkin_time\":0,\"sch_checkin_time_dt\":\"1970-01-01T08:00:00+08:00\",\"groupid\":6,\"schedule_id\":0,\"timeline_id\":0},{\"userid\":\"ChenXiaoLong\",\"groupname\":\"重庆公司\",\"checkin_type\":\"外出打卡\",\"exception_type\":\"\",\"checkin_time\":1758851257,\"checkin_time_dt\":\"2025-09-26T09:47:37+08:00\",\"location_title\":\"重庆市城投金卡信息产业(集团)股份有限公司\",\"location_detail\":\"重庆市南岸区通江大道221号\",\"wifiname\":\"\",\"notes\":\"\",\"wifimac\":\"\",\"mediaids\":[\"WWME_IJgBCQAAVhzS9FfW_p6kL9-hZRTpMQ\"],\"lat\":29473784,\"lng\":106632510,\"deviceid\":\"4e7878b87ea6a15d\",\"sch_checkin_time\":0,\"sch_checkin_time_dt\":\"1970-01-01T08:00:00+08:00\",\"groupid\":6,\"schedule_id\":0,\"timeline_id\":0},{\"userid\":\"ChenXiaoLong\",\"groupname\":\"重庆公司\",\"checkin_type\":\"外出打卡\",\"exception_type\":\"\",\"checkin_time\":1758872464,\"checkin_time_dt\":\"2025-09-26T15:41:04+08:00\",\"location_title\":\"中共南岸区委党校\",\"location_detail\":\"重庆市南岸区通江大道208号\",\"wifiname\":\"\",\"notes\":\"\",\"wifimac\":\"\",\"mediaids\":[\"WWME_IJgBCQAAG7HCv_Gr-P6lvtXjg1-JRg\"],\"lat\":29481675,\"lng\":106638495,\"deviceid\":\"4e7878b87ea6a15d\",\"sch_checkin_time\":0,\"sch_checkin_time_dt\":\"1970-01-01T08:00:00+08:00\",\"groupid\":6,\"schedule_id\":0,\"timeline_id\":0},{\"userid\":\"ChenXiaoLong\",\"groupname\":\"重庆公司\",\"checkin_type\":\"外出打卡\",\"exception_type\":\"\",\"checkin_time\":1758874662,\"checkin_time_dt\":\"2025-09-26T16:17:42+08:00\",\"location_title\":\"重庆市南岸区社会主义学院教学楼\",\"location_detail\":\"重庆市南岸区通江大道\",\"wifiname\":\"\",\"notes\":\"\",\"wifimac\":\"\",\"mediaids\":[\"WWME_IJgBCQAA_EovAON6J8RLpiPeP6uWiw\"],\"lat\":29481117,\"lng\":106638212,\"deviceid\":\"4e7878b87ea6a15d\",\"sch_checkin_time\":0,\"sch_checkin_time_dt\":\"1970-01-01T08:00:00+08:00\",\"groupid\":6,\"schedule_id\":0,\"timeline_id\":0},{\"userid\":\"ChenXiaoLong\",\"groupname\":\"重庆公司\",\"checkin_type\":\"外出打卡\",\"exception_type\":\"\",\"checkin_time\":1758960136,\"checkin_time_dt\":\"2025-09-27T16:02:16+08:00\",\"location_title\":\"重庆建筑工程职业学院(东站校区)\",\"location_detail\":\"重庆市南岸区茶园大道289号\",\"wifiname\":\"\",\"notes\":\"\",\"wifimac\":\"\",\"mediaids\":[\"WWME_IJgBCQAAaFBF6cF5labOLzM_2upXOw\"],\"lat\":29511169,\"lng\":106698654,\"deviceid\":\"4e7878b87ea6a15d\",\"sch_checkin_time\":0,\"sch_checkin_time_dt\":\"1970-01-01T08:00:00+08:00\",\"groupid\":6,\"schedule_id\":0,\"timeline_id\":0},{\"userid\":\"ChenXiaoLong\",\"groupname\":\"重庆公司\",\"checkin_type\":\"外出打卡\",\"exception_type\":\"\",\"checkin_time\":1759136160,\"checkin_time_dt\":\"2025-09-29T16:56:00+08:00\",\"location_title\":\"中德职业教育西部中职示范基地\",\"location_detail\":\"重庆市南岸区丁香路与同景路交叉口正东方向159米左右\",\"wifiname\":\"\",\"notes\":\"\",\"wifimac\":\"\",\"mediaids\":[\"WWME_IJgBCQAA3B5o3KAgAGfCR4llqSUeag\"],\"lat\":29501191,\"lng\":106657884,\"deviceid\":\"4e7878b87ea6a15d\",\"sch_checkin_time\":0,\"sch_checkin_time_dt\":\"1970-01-01T08:00:00+08:00\",\"groupid\":6,\"schedule_id\":0,\"timeline_id\":0}]请根据以上数据分析用户绩效,按照一个月拜访20个客户的标准给出是否合格,并给出分析报告。";
  4836. return Ok(JsonView(await _deepSeek.ChatAsync(question)));
  4837. }
  4838. private class clientView
  4839. {
  4840. public int Id { get; set; }
  4841. public string LastName { get; set; }
  4842. public string FirstName { get; set; }
  4843. }
  4844. /// <summary>
  4845. /// DeepSeek Chat 测试
  4846. /// </summary>
  4847. /// <returns></returns>
  4848. [HttpGet]
  4849. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  4850. public async Task<IActionResult> ClientInfo(string name )
  4851. {
  4852. var clientInfos = await _sqlSugar.Queryable<Crm_DeleClient>()
  4853. .Where(x => x.IsDel == 0)
  4854. .Select(x => new clientView { Id = x.Id, LastName = x.LastName })
  4855. .ToListAsync();
  4856. foreach (var item in clientInfos)
  4857. {
  4858. item.LastName = AesEncryptionHelper.Decrypt(item.LastName);
  4859. }
  4860. var searchIds = clientInfos.Where(x => x.LastName.Contains(name)).Select(x => x.Id).ToList();
  4861. var view = await _sqlSugar.Queryable<Crm_DeleClient>()
  4862. .Where(x => x.IsDel == 0)
  4863. .Where(x => searchIds.Contains(x.Id))
  4864. .Select(x => new clientView { Id = x.Id, LastName = x.LastName, FirstName = x.FirstName })
  4865. .ToListAsync();
  4866. foreach (var item in view)
  4867. {
  4868. item.LastName = AesEncryptionHelper.Decrypt(item.LastName);
  4869. item.FirstName = AesEncryptionHelper.Decrypt(item.FirstName);
  4870. }
  4871. return Ok(JsonView(view));
  4872. }
  4873. #endregion
  4874. }
  4875. }