SystemController.cs 182 KB

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