SystemController.cs 127 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042
  1. using Aspose.Cells;
  2. using EyeSoft.Messanging;
  3. using Microsoft.EntityFrameworkCore.Metadata;
  4. using Microsoft.Extensions.Configuration.UserSecrets;
  5. using OASystem.Domain;
  6. using OASystem.Domain.Entities.Customer;
  7. using OASystem.Domain.Entities.Financial;
  8. using OASystem.Domain.Entities.Groups;
  9. using Org.BouncyCastle.Asn1.Cmp;
  10. using System.Collections;
  11. using static OASystem.API.OAMethodLib.GeneralMethod;
  12. using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
  13. using static QRCoder.PayloadGenerator;
  14. using static Quartz.Logging.OperationName;
  15. using static OASystem.API.OAMethodLib.JWTHelper;
  16. using System.Runtime.Intrinsics.Arm;
  17. using OASystem.Domain.Dtos.Statistics;
  18. using OASystem.Domain.AesEncryption;
  19. namespace OASystem.API.Controllers
  20. {
  21. /// <summary>
  22. /// 系统设置
  23. /// </summary>
  24. //[Authorize]
  25. [Route("api/[controller]/[action]")]
  26. public class SystemController : ControllerBase
  27. {
  28. private readonly CompanyRepository _syscomRep;
  29. private readonly DepartmentRepository _sysDepRep;
  30. private readonly UsersRepository _userRep;
  31. private readonly IMapper _mapper;
  32. private readonly SqlSugarClient _sqlSugar;
  33. private readonly MessageRepository _messageRep;
  34. private readonly SetDataRepository _setDataRepository;
  35. private readonly SystemMenuPermissionRepository _SystemMenuPermissionRepository;
  36. private readonly CompanyRepository _CompanyRepository;
  37. private readonly PageFunctionPermissionRepository _PageFunctionPermissionRepository;
  38. private readonly SystemMenuAndFunctionRepository _SystemMenuAndFunctionRepository;
  39. private readonly JobPostAuthorityRepository _JobPostAuthorityRepository;
  40. private readonly JobPostRepository _jobRep;
  41. private readonly SetDataTypeRepository _setDataTypeRep;
  42. private readonly UserAuthorityRepository _UserAuthorityRepository;
  43. private readonly List<int> _operationTypeList = new List<int>() { 1, 2, 3, 4, 5 }; //操作通知所属类型
  44. private readonly List<int> _taskTypeList = new List<int>() { 6 };//任务通知 TaskNotification
  45. public SystemController(
  46. CompanyRepository syscom,
  47. DepartmentRepository sysDepRep,
  48. UsersRepository userRep,
  49. IMapper mapper,
  50. SqlSugarClient sqlSugar,
  51. SetDataRepository setDataRepository,
  52. CompanyRepository companyRepository,
  53. SystemMenuPermissionRepository systemMenuPermissionRepository,
  54. PageFunctionPermissionRepository pageFunctionPermissionRepository,
  55. SystemMenuAndFunctionRepository systemMenuAndFunctionRepository,
  56. JobPostAuthorityRepository jobPostAuthorityRepository,
  57. JobPostRepository jobRep,
  58. UserAuthorityRepository userAuthorityRepository,
  59. MessageRepository messageRep,
  60. SetDataTypeRepository setDataTypeRep
  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. }
  79. #region 消息
  80. /// <summary>
  81. /// 获取消息列表-整合版
  82. /// </summary>
  83. /// <param name="dto"></param>
  84. /// <returns></returns>
  85. [HttpPost]
  86. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  87. public async Task<IActionResult> PsotMsgPageList(MsgDto dto)
  88. {
  89. var msgData = await _messageRep.GetMsgList(dto);
  90. if (msgData.Code != 0)
  91. {
  92. return Ok(JsonView(false, msgData.Msg));
  93. }
  94. return Ok(JsonView(msgData.Data));
  95. }
  96. #region 消息列表 - 分开
  97. /// <summary>
  98. /// 系统消息
  99. /// 消息类型 2024-03-06 14:37
  100. /// </summary>
  101. /// <param name="dto"></param>
  102. /// <returns></returns>
  103. [HttpPost]
  104. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  105. public async Task<IActionResult> PotsMsgTypeData(MsgTypeDto dto)
  106. {
  107. if (dto.PortType < 1 || dto.PortType > 3)
  108. {
  109. return Ok(JsonView(false, "请输入有效的PortType参数。1 Web 2 Android 3 IOS"));
  110. }
  111. if (dto.UserId < 1)
  112. {
  113. return Ok(JsonView(false, "请输入有效的UserId参数。"));
  114. }
  115. var msgData = await _messageRep.PotsMsgTypeData(dto);
  116. if (msgData.Code != 0)
  117. {
  118. return Ok(JsonView(400, msgData.Msg, new string[] { }));
  119. }
  120. return Ok(JsonView(true, msgData.Msg, msgData.Data));
  121. }
  122. /// <summary>
  123. /// 系统消息
  124. /// 消息List 2024-03-06 14:54
  125. /// </summary>
  126. /// <param name="dto"></param>
  127. /// <returns></returns>
  128. [HttpPost]
  129. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  130. public async Task<IActionResult> PotsMessagePageList(PotsMessagePageListDto dto)
  131. {
  132. #region 参数验证
  133. if (dto.PortType < 1 || dto.PortType > 3)
  134. {
  135. return Ok(JsonView(false, "请输入有效的PortType参数。1 Web 2 Android 3 IOS"));
  136. }
  137. var typeData = await _sqlSugar.Queryable<Sys_SetData>().Where(it => it.STid == 77).Select(it => it.Id).ToListAsync();
  138. if (typeData.Count < 0)
  139. {
  140. return Ok(JsonView(false, "消息类型不存在"));
  141. }
  142. if (!typeData.Contains(dto.Type))
  143. {
  144. return Ok(JsonView(false, "请输入有效的Type参数。1021 团组操作通知 1020 任务操作通知 "));
  145. }
  146. if (dto.UserId < 1)
  147. {
  148. return Ok(JsonView(false, "请输入有效的UserId参数。"));
  149. }
  150. if (dto.ReadStatus < 1 || dto.ReadStatus > 3)
  151. {
  152. return Ok(JsonView(false, "请输入有效的ReadStatus参数。1 全部(包含已读/未读) 2 未读 3 已读"));
  153. }
  154. #endregion
  155. //userId
  156. string msgSqlWhere = $" And smra.ReadableUId = {dto.UserId}";
  157. //消息类型
  158. string typeStr = "";
  159. List<NotificationTypeView> messageTypeViews = AppSettingsHelper.Get<NotificationTypeView>("MessageNotificationType");
  160. if (dto.Type == 1020) //任务操作通知
  161. {
  162. typeStr = String.Join(",", messageTypeViews.Where(it => it.TypeId == 1020).FirstOrDefault().MsgTypeIds.ToList());
  163. }
  164. else if (dto.Type == 1021)//团组操作通知
  165. {
  166. typeStr = String.Join(",", messageTypeViews.Where(it => it.TypeId == 1021).FirstOrDefault().MsgTypeIds.ToList());
  167. }
  168. else if (dto.Type == 1022)//公告通知
  169. {
  170. typeStr = String.Join(",", messageTypeViews.Where(it => it.TypeId == 1022).FirstOrDefault().MsgTypeIds.ToList());
  171. }
  172. if (!string.IsNullOrEmpty(typeStr))
  173. {
  174. msgSqlWhere += $" And sm.Type In ({typeStr})";
  175. }
  176. //是否已读处理 1 全部(包含已读/未读) 2 未读 3 已读
  177. if (dto.ReadStatus == 1) msgSqlWhere += "";
  178. else if (dto.ReadStatus == 2) msgSqlWhere += $" And smra.IsRead = {0}";
  179. else if (dto.ReadStatus == 3) msgSqlWhere += $" And smra.IsRead = {1}";
  180. string msgSql = string.Format(@"Select * From(
  181. Select row_number() over(order by sm.ReleaseTime Desc) as RowNumber,
  182. sm.Id,sm.Type,sm.Title,sm.Content,sd.DepName issuerDep,su.CnName issuerUser,
  183. sm.ReleaseTime,smra.ReadableUId,smra.IsRead,sm.DiId,sm.Param
  184. From Sys_Message sm
  185. Inner Join Sys_MessageReadAuth smra On sm.Id = smra.MsgId
  186. Inner Join Sys_Users su On sm.IssuerId = su.Id
  187. Inner Join Sys_Department sd On su.DepId = sd.Id
  188. Inner Join Sys_Users suAuth On smra.ReadableUId = suAuth.Id
  189. Where sm.IsDel = 0
  190. And smra.IsDel = 0 {0}
  191. ) Temp", msgSqlWhere);
  192. try
  193. {
  194. RefAsync<int> totalCount = 0;
  195. var data = await _sqlSugar.SqlQueryable<MessageListView>(msgSql).ToPageListAsync(dto.PageIndex, dto.PageSize, totalCount);
  196. return Ok(JsonView(true, "操作成功!", data, totalCount));
  197. }
  198. catch (Exception ex)
  199. {
  200. return Ok(JsonView(false, ex.Message));
  201. }
  202. }
  203. /// <summary>
  204. /// 系统消息
  205. /// 获取消息未读条数
  206. /// </summary>
  207. /// <param name="dto"></param>
  208. /// <returns></returns>
  209. [HttpPost]
  210. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  211. public async Task<IActionResult> PotsMessageUnreadTotalCount(PotsMessageUnreadTotalCountDto dto)
  212. {
  213. #region 参数验证
  214. if (dto.UserId < 1)
  215. {
  216. return Ok(JsonView(false, "请输入有效的UserId参数。"));
  217. }
  218. #endregion
  219. try
  220. {
  221. int messageUnReadCount = 0;
  222. int announcementUnReadCount = 0;
  223. var data = await _messageRep.GetUnReadCount(dto.UserId);
  224. if (data != null)
  225. {
  226. messageUnReadCount = data;
  227. }
  228. var data1 = await _messageRep.GetAnnouncementUnReadCount(dto.UserId);
  229. if (data1 != null)
  230. {
  231. announcementUnReadCount = data1;
  232. }
  233. return Ok(JsonView(true, "操作成功!", new { messageUnReadCount = messageUnReadCount, announcementUnReadCount = announcementUnReadCount }));
  234. }
  235. catch (Exception ex)
  236. {
  237. return Ok(JsonView(false, ex.Message));
  238. }
  239. }
  240. #endregion
  241. /// <summary>
  242. /// 获取消息详细信息
  243. /// </summary>
  244. /// <param name="dto"></param>
  245. /// <returns></returns>
  246. [HttpPost]
  247. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  248. public async Task<IActionResult> PostMsgInfo(MsgInfoDto dto)
  249. {
  250. if (dto.PortType < 1 || dto.PortType > 3)
  251. {
  252. return Ok(JsonView(false, "请输入有效的PortType参数。1 Web 2 Android 3 IOS"));
  253. }
  254. var msgData = await _messageRep.GetMsgInfo(dto);
  255. if (msgData.Code != 0)
  256. {
  257. return Ok(JsonView(false, msgData.Msg));
  258. }
  259. return Ok(JsonView(true, "操作成功!", msgData.Data));
  260. }
  261. /// <summary>
  262. /// 消息设置已读
  263. /// </summary>
  264. /// <param name="dto"></param>
  265. /// <returns></returns>
  266. [HttpPost]
  267. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  268. public async Task<IActionResult> SetMessageRead(MsgSetReadDto dto)
  269. {
  270. var msgData = await _messageRep.SetMsgRead(dto);
  271. if (msgData.Code != 0)
  272. {
  273. return Ok(JsonView(false, msgData.Msg));
  274. }
  275. return Ok(JsonView(true));
  276. }
  277. /// <summary>
  278. /// 消息 删除
  279. /// </summary>
  280. /// <param name="dto"></param>
  281. /// <returns></returns>
  282. [HttpPost]
  283. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  284. public async Task<IActionResult> DeleMsg(MsgDeleteDto dto)
  285. {
  286. var msgData = await _messageRep.DelMsg(dto);
  287. if (msgData.Code != 0)
  288. {
  289. return Ok(JsonView(false, msgData.Msg));
  290. }
  291. return Ok(JsonView(true));
  292. }
  293. #endregion
  294. #region 数据类型资料
  295. /// <summary>
  296. /// 根据类型查询数据
  297. /// </summary>
  298. /// <param name="dto"></param>
  299. /// <returns></returns>
  300. [HttpPost]
  301. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  302. public async Task<IActionResult> QuerySetData(SetDataDto dto)
  303. {
  304. try
  305. {
  306. if (dto.DataType == 0)
  307. {
  308. return Ok(JsonView(false, "请传类型Id!"));
  309. }
  310. var setData = _setDataRepository.QueryDto<Sys_SetData, SetDataView>(s => s.STid == dto.DataType && s.IsDel == 0).ToList();
  311. if (setData.Count == 0)
  312. {
  313. return Ok(JsonView(false, "暂无数据!"));
  314. }
  315. return Ok(JsonView(true, "查询成功!", setData));
  316. }
  317. catch (Exception ex)
  318. {
  319. return Ok(JsonView(false, "程序错误!"));
  320. throw;
  321. }
  322. }
  323. /// <summary>
  324. /// 根据类型查询数据(Array)
  325. /// </summary>
  326. /// <returns></returns>
  327. [HttpPost]
  328. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  329. public IActionResult QuerySetDataInitByArr(QuerySetDataInitByArr Dto)
  330. {
  331. var DbQuery = _setDataRepository.QueryDto<Sys_SetData, SetDataView>(s => Dto.DataTypeArr.Contains(s.STid)).ToList();
  332. var GroupResult = DbQuery.GroupBy(x => x.STid).Select(x => new
  333. {
  334. key = x.Key,
  335. Arr = x.ToList()
  336. });
  337. return Ok(JsonView(true, "查询成功!", GroupResult));
  338. }
  339. /// <summary>
  340. /// 数据类型表查询
  341. /// </summary>
  342. /// <param name="dto"></param>
  343. /// <returns></returns>
  344. [HttpPost]
  345. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  346. public async Task<IActionResult> QuerySetDataType(SetDataTypeDto dto)
  347. {
  348. try
  349. {
  350. Result setDataType = await _setDataTypeRep.QuerySetDataType(dto);
  351. if (setDataType.Code == 0)
  352. {
  353. return Ok(JsonView(true, "查询成功", setDataType.Data));
  354. }
  355. else
  356. {
  357. return Ok(JsonView(false, setDataType.Msg));
  358. }
  359. }
  360. catch (Exception)
  361. {
  362. return Ok(JsonView(false, "程序错误!"));
  363. throw;
  364. }
  365. }
  366. /// <summary>
  367. /// 数据类型表操作(Status:1.新增,2.修改)
  368. /// </summary>
  369. /// <param name="dto"></param>
  370. /// <returns></returns>
  371. [HttpPost]
  372. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  373. public async Task<IActionResult> OperationSetDataType(OperationSetDataTypeDto dto)
  374. {
  375. try
  376. {
  377. if (dto.Name == "")
  378. {
  379. return Ok(JsonView(false, "请检查类型名称是否填写!"));
  380. }
  381. Result result = await _setDataTypeRep.OperationSetDataType(dto);
  382. if (result.Code != 0)
  383. {
  384. return Ok(JsonView(false, result.Msg));
  385. }
  386. return Ok(JsonView(true, result.Msg));
  387. }
  388. catch (Exception ex)
  389. {
  390. return Ok(JsonView(false, "程序错误!"));
  391. throw;
  392. }
  393. }
  394. /// <summary>
  395. /// 数据类型表操作删除
  396. /// </summary>
  397. /// <param name="dto"></param>
  398. /// <returns></returns>
  399. [HttpPost]
  400. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  401. public async Task<IActionResult> DelSetDataType(DelSetDataTypeDto dto)
  402. {
  403. try
  404. {
  405. var res = await _setDataTypeRep.SoftDeleteByIdAsync<Sys_SetDataType>(dto.Id.ToString(), dto.DeleteUserId);
  406. if (!res)
  407. {
  408. return Ok(JsonView(false, "删除失败"));
  409. }
  410. return Ok(JsonView(true, "删除成功!"));
  411. }
  412. catch (Exception ex)
  413. {
  414. return Ok(JsonView(false, "程序错误!"));
  415. throw;
  416. }
  417. }
  418. #endregion
  419. #region 数据类型板块
  420. /// <summary>
  421. /// 数据类型板块表查询
  422. /// </summary>
  423. /// <param name="dto"></param>
  424. /// <returns></returns>
  425. [HttpPost]
  426. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  427. public async Task<IActionResult> QuerySetDataInfo(SetDataIDto dto)
  428. {
  429. try
  430. {
  431. Result setData = await _setDataRepository.QuerySetData(dto);
  432. if (setData.Code == 0)
  433. {
  434. return Ok(JsonView(true, "查询成功", setData.Data));
  435. }
  436. else
  437. {
  438. return Ok(JsonView(false, setData.Msg));
  439. }
  440. }
  441. catch (Exception)
  442. {
  443. return Ok(JsonView(false, "程序错误!"));
  444. throw;
  445. }
  446. }
  447. /// <summary>
  448. /// 数据类型板块表操作(Status:1.新增,2.修改)
  449. /// </summary>
  450. /// <param name="dto"></param>
  451. /// <returns></returns>
  452. [HttpPost]
  453. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  454. public async Task<IActionResult> OperationSetData(OperationSetDataDto dto)
  455. {
  456. try
  457. {
  458. if (dto.Name == "")
  459. {
  460. return Ok(JsonView(false, "请检查板块名称是否填写!"));
  461. }
  462. Result result = await _setDataRepository.OperationSetData(dto);
  463. if (result.Code != 0)
  464. {
  465. return Ok(JsonView(false, result.Msg));
  466. }
  467. return Ok(JsonView(true, result.Msg));
  468. }
  469. catch (Exception ex)
  470. {
  471. return Ok(JsonView(false, "程序错误!"));
  472. throw;
  473. }
  474. }
  475. /// <summary>
  476. /// 数据类型表操作删除
  477. /// </summary>
  478. /// <param name="dto"></param>
  479. /// <returns></returns>
  480. [HttpPost]
  481. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  482. public async Task<IActionResult> DelSetData(DelSetDataDto dto)
  483. {
  484. try
  485. {
  486. var res = await _setDataRepository.SoftDeleteByIdAsync<Sys_SetData>(dto.Id.ToString(), dto.DeleteUserId);
  487. if (!res)
  488. {
  489. return Ok(JsonView(false, "删除失败"));
  490. }
  491. return Ok(JsonView(true, "删除成功!"));
  492. }
  493. catch (Exception ex)
  494. {
  495. return Ok(JsonView(false, "程序错误!"));
  496. throw;
  497. }
  498. }
  499. #endregion
  500. #region 企业操作
  501. /// <summary>
  502. /// 查询企业数据
  503. /// </summary>
  504. /// <param name="dto"></param>
  505. /// <returns></returns>
  506. [HttpPost]
  507. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  508. public async Task<IActionResult> getCompanyList(DtoBase dto)
  509. {
  510. if (dto.PortType == 1)
  511. {
  512. var CompanyDataResult = _CompanyRepository.GetCompanyData();
  513. if (CompanyDataResult.Code != 0)
  514. {
  515. return Ok(JsonView(CompanyDataResult.Msg));
  516. }
  517. List<CompanyView> companyListView = _mapper.Map<List<CompanyView>>(CompanyDataResult.Data);
  518. for (int i = 0; i < companyListView.Count; i++)
  519. {
  520. if (companyListView[i].ParentCompanyId != 0)
  521. {
  522. companyListView[i].ParentCompanyName = companyListView.Find(x => x.Id == companyListView[i].ParentCompanyId).CompanyName;
  523. }
  524. if (companyListView[i].ContactUserId != 0)
  525. {
  526. var user = _userRep.QueryDto<Sys_Users, UserInfoWebView>(x => x.Id == companyListView[i].ContactUserId).ToList();
  527. if (user.Count != 0)
  528. {
  529. companyListView[i].ContactUserName = user[0].CnName;
  530. }
  531. }
  532. }
  533. return Ok(JsonView(true, "查询成功!", companyListView));
  534. }
  535. else if (dto.PortType == 2)
  536. {
  537. var CompanyDataResult = _CompanyRepository.GetCompanyData();
  538. if (CompanyDataResult.Code != 0)
  539. {
  540. return Ok(JsonView(CompanyDataResult.Msg));
  541. }
  542. return Ok(JsonView(true, "查询成功!", CompanyDataResult.Data));
  543. }
  544. else if (dto.PortType == 3)
  545. {
  546. return Ok(JsonView(false, "暂无数据!"));
  547. }
  548. else
  549. {
  550. return Ok(JsonView(false, "暂无数据!"));
  551. }
  552. }
  553. /// <summary>
  554. /// 添加企业数据
  555. /// </summary>
  556. /// <param name="dto"></param>
  557. /// <returns></returns>
  558. [HttpPost]
  559. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  560. public async Task<IActionResult> AddCompany(AddCompanyDto dto)
  561. {
  562. if (string.IsNullOrWhiteSpace(dto.CompanyName) || dto.CreateUserId == 0 || string.IsNullOrWhiteSpace(dto.CompanyCode))
  563. {
  564. return Ok(JsonView(false, "请检查信息是否输入完整!"));
  565. }
  566. else if (string.IsNullOrWhiteSpace(dto.Tel))
  567. {
  568. return Ok(JsonView(false, "请检查联系方式是否输入正确!"));
  569. }
  570. else
  571. {
  572. Sys_Company _Company = _mapper.Map<Sys_Company>(dto);
  573. Result data = await _syscomRep.AddCompany(_Company);
  574. if (data.Code != 0)
  575. {
  576. return Ok(JsonView(false, "添加失败!"));
  577. }
  578. return Ok(JsonView(true, "添加成功"));
  579. }
  580. }
  581. /// <summary>
  582. /// 企业修改
  583. /// </summary>
  584. /// <param name="dto"></param>
  585. /// <returns></returns>
  586. [HttpPost]
  587. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  588. public async Task<IActionResult> EditCompany(EditCompanyDto dto)
  589. {
  590. if (string.IsNullOrWhiteSpace(dto.CompanyName) || string.IsNullOrWhiteSpace(dto.CompanyCode) || string.IsNullOrWhiteSpace(dto.Address) || dto.ContactUserId == 0)
  591. {
  592. return Ok(JsonView(false, "请检查信息是否输入完整!"));
  593. }
  594. else if (string.IsNullOrWhiteSpace(dto.Tel))
  595. {
  596. return Ok(JsonView(false, "请检查联系方式是否输入正确!"));
  597. }
  598. else
  599. {
  600. bool res = await _syscomRep.UpdateAsync(a => a.Id == dto.Id, a => new Sys_Company
  601. {
  602. CompanyName = dto.CompanyName,
  603. CompanyCode = dto.CompanyCode,
  604. Address = dto.Address,
  605. ParentCompanyId = dto.ParentCompanyId,
  606. Tel = dto.Tel,
  607. ContactUserId = dto.ContactUserId,
  608. Remark = dto.Remark,
  609. });
  610. if (!res) { return Ok(JsonView(false, "修改失败")); }
  611. return Ok(JsonView(true, "修改成功!"));
  612. }
  613. }
  614. /// <summary>
  615. /// 企业删除
  616. /// </summary>
  617. /// <param name="dto"></param>
  618. /// <returns></returns>
  619. [HttpPost]
  620. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  621. public async Task<IActionResult> DelCompany(DelCompanyDto dto)
  622. {
  623. bool res = await _syscomRep.SoftDeleteAsync<Sys_Company>(dto.Id.ToString());
  624. if (!res) { return Ok(JsonView(false, "删除失败")); }
  625. return Ok(JsonView(true, "删除成功"));
  626. }
  627. #endregion
  628. #region 部门操作
  629. /// <summary>
  630. /// 查询部门数据
  631. /// </summary>
  632. /// <param name="dto"></param>
  633. /// <returns></returns>
  634. [HttpPost]
  635. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  636. public async Task<IActionResult> QueryDepartmentList(DepartmentDto dto)
  637. {
  638. try
  639. {
  640. if (dto.PortType == 1)
  641. {
  642. if (dto.CompanyId != 0)
  643. {
  644. var result = _sysDepRep.QueryDto<Sys_Department, DepartmentIView>(s => s.CompanyId == dto.CompanyId).ToList();
  645. if (result.Count == 0)
  646. {
  647. return Ok(JsonView(false, "暂无数据!"));
  648. }
  649. for (int i = 0; i < result.Count; i++)
  650. {
  651. if (result[i].ParentDepId != 0)
  652. {
  653. result[i].ParentDepName = result.Find(x => x.Id == result[i].ParentDepId).ParentDepName;
  654. }
  655. var company = _sysDepRep.QueryDto<Sys_Company, CompanyView>(s => s.Id == result[i].CompanyId).ToList();
  656. if (company.Count != 0)
  657. {
  658. result[i].CompanyName = company[0].CompanyName;
  659. }
  660. return Ok(JsonView(true, "查询成功!", result));
  661. }
  662. }
  663. else
  664. {
  665. var result = _sysDepRep.QueryDto<Sys_Department, DepartmentIView>(s => s.IsDel <= 1).ToList();
  666. if (result.Count == 0)
  667. {
  668. return Ok(JsonView(false, "暂无数据!"));
  669. }
  670. for (int i = 0; i < result.Count; i++)
  671. {
  672. if (result[i].ParentDepId != 0)
  673. {
  674. result[i].ParentDepName = result.Find(x => x.Id == result[i].ParentDepId).ParentDepName;
  675. }
  676. var company = _sysDepRep.QueryDto<Sys_Company, CompanyView>(s => s.Id == result[i].CompanyId).ToList();
  677. if (company.Count != 0)
  678. {
  679. result[i].CompanyName = company[0].CompanyName;
  680. }
  681. }
  682. return Ok(JsonView(true, "查询成功!", result));
  683. }
  684. return Ok(JsonView(false, "暂无数据!"));
  685. }
  686. else if (dto.PortType == 2)
  687. {
  688. var result = _sysDepRep.QueryDto<Sys_Department, DepartmentIView>(s => s.CompanyId == dto.CompanyId).ToList();
  689. if (result.Count == 0)
  690. {
  691. return Ok(JsonView(400, "暂无数据!", new List<string>()));
  692. }
  693. return Ok(JsonView(true, "查询成功!", result));
  694. }
  695. else if (dto.PortType == 3)
  696. {
  697. return Ok(JsonView(false, "暂无数据!"));
  698. }
  699. else
  700. {
  701. return Ok(JsonView(false, "暂无数据!"));
  702. }
  703. }
  704. catch (Exception ex)
  705. {
  706. return Ok(JsonView(false, "程序错误!"));
  707. throw;
  708. }
  709. }
  710. /// <summary>
  711. /// 部门添加
  712. /// </summary>
  713. /// <param name="dto"></param>
  714. /// <returns></returns>
  715. [HttpPost]
  716. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  717. public async Task<IActionResult> AddDepartment(AddDepartmentDto dto)
  718. {
  719. try
  720. {
  721. if (dto.CreateUserId == 0 || string.IsNullOrWhiteSpace(dto.DepName) || dto.CompanyId == 0 || string.IsNullOrWhiteSpace(dto.DepCode))
  722. {
  723. return Ok(JsonView(false, "请检查信息是否输入完整!"));
  724. }
  725. else
  726. {
  727. Sys_Department _Department = _mapper.Map<Sys_Department>(dto);
  728. int id = await _sysDepRep.AddAsyncReturnId(_Department);
  729. if (id == 0)
  730. {
  731. return Ok(JsonView(false, "添加失败!"));
  732. }
  733. return Ok(JsonView(true, "添加成功!", new { Id = id }));
  734. }
  735. }
  736. catch (Exception)
  737. {
  738. return Ok(JsonView(false, "程序错误!"));
  739. throw;
  740. }
  741. }
  742. /// <summary>
  743. /// 部门修改
  744. /// </summary>
  745. /// <param name="dto"></param>
  746. /// <returns></returns>
  747. [HttpPost]
  748. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  749. public async Task<IActionResult> EditDepartment(EditDepartmentDto dto)
  750. {
  751. try
  752. {
  753. if (dto.Id == 0 || string.IsNullOrWhiteSpace(dto.DepName) || dto.CompanyId == 0 || string.IsNullOrWhiteSpace(dto.DepCode))
  754. {
  755. return Ok(JsonView(false, "请检查信息是否输入完整!"));
  756. }
  757. else
  758. {
  759. bool res = await _sysDepRep.UpdateAsync<Sys_Department>(a => a.Id == dto.Id, a => new Sys_Department
  760. {
  761. CompanyId = dto.CompanyId,
  762. DepCode = dto.DepCode,
  763. DepName = dto.DepName,
  764. ParentDepId = dto.ParentDepId,
  765. Remark = dto.Remark,
  766. });
  767. if (!res)
  768. {
  769. return Ok(JsonView(false, "修改失败!"));
  770. }
  771. return Ok(JsonView(true, "修改成功!"));
  772. }
  773. }
  774. catch (Exception)
  775. {
  776. return Ok(JsonView(false, "程序错误!"));
  777. throw;
  778. }
  779. }
  780. /// <summary>
  781. /// 部门删除
  782. /// </summary>
  783. /// <param name="dto"></param>
  784. /// <returns></returns>
  785. [HttpPost]
  786. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  787. public async Task<IActionResult> DelDepartment(DelDepartmentDto dto)
  788. {
  789. try
  790. {
  791. if (dto.Id == 0)
  792. {
  793. return Ok(JsonView(-1, "请检查信息是否输入完整!", null));
  794. }
  795. else
  796. {
  797. bool res = await _sysDepRep.SoftDeleteAsync<Sys_Department>(dto.Id.ToString());
  798. if (!res)
  799. {
  800. return Ok(JsonView(false, "删除失败!"));
  801. }
  802. return Ok(JsonView(true, "删除成功!"));
  803. }
  804. }
  805. catch (Exception)
  806. {
  807. return Ok(JsonView(false, "程序错误!"));
  808. throw;
  809. }
  810. }
  811. #endregion
  812. #region 岗位板块
  813. /// <summary>
  814. /// 岗位查询
  815. /// </summary>
  816. /// <param name="dto"></param>
  817. /// <returns></returns>
  818. [HttpPost]
  819. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  820. public async Task<IActionResult> QueryJobPost(QueryJobPostDto dto)
  821. {
  822. try
  823. {
  824. if (dto.PortType == 1)
  825. {
  826. string sqlWhere = string.Empty;
  827. if (dto.CompanyId != 0)
  828. {
  829. sqlWhere += string.Format(@" And jp.CompanyId={0}", dto.CompanyId);
  830. }
  831. if (dto.DepId != 0)
  832. {
  833. sqlWhere += string.Format(@" And jp.DepId={0}", dto.DepId);
  834. }
  835. sqlWhere += string.Format(@" And jp.IsDel={0}", 0);
  836. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  837. {
  838. Regex r = new Regex("And");
  839. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  840. }
  841. List<Sys_JobPostI> jobList = await _jobRep.QueryJobPost(sqlWhere);
  842. List<JobPostView> List = _mapper.Map<List<JobPostView>>(jobList);
  843. if (jobList.Count == 0)
  844. {
  845. return Ok(JsonView(false, "暂无数据!"));
  846. }
  847. return Ok(JsonView(true, "查询成功!", jobList));
  848. }
  849. else if (dto.PortType == 2)
  850. {
  851. var result = _jobRep.QueryDto<Sys_JobPost, JobPostView>(s => s.CompanyId == dto.CompanyId && s.DepId == dto.DepId).ToList();
  852. if (result.Count == 0)
  853. {
  854. return Ok(JsonView(false, "暂无数据!"));
  855. }
  856. return Ok(JsonView(true, "查询成功!", result));
  857. }
  858. else if (dto.PortType == 3)
  859. {
  860. return Ok(JsonView(false, "暂无数据!"));
  861. }
  862. else
  863. {
  864. return Ok(JsonView(false, "暂无数据!"));
  865. }
  866. }
  867. catch (Exception ex)
  868. {
  869. return Ok(JsonView(false, "程序错误!"));
  870. throw;
  871. }
  872. }
  873. /// <summary>
  874. /// 添加岗位
  875. /// </summary>
  876. /// <param name="dto"></param>
  877. /// <returns></returns>
  878. [HttpPost]
  879. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  880. public async Task<IActionResult> AddJobPost(AddJobPostDto dto)
  881. {
  882. try
  883. {
  884. Sys_JobPost sys_Job = _mapper.Map<Sys_JobPost>(dto);
  885. int id = await _jobRep.AddAsyncReturnId(sys_Job);
  886. if (id == 0)
  887. {
  888. return Ok(JsonView(false, "添加失败"));
  889. }
  890. return Ok(JsonView(true, "添加成功", new { Id = id }));
  891. }
  892. catch (Exception ex)
  893. {
  894. return Ok(JsonView(false, "程序错误!"));
  895. throw;
  896. }
  897. }
  898. /// <summary>
  899. /// 修改岗位
  900. /// </summary>
  901. /// <param name="dto"></param>
  902. /// <returns></returns>
  903. [HttpPost]
  904. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  905. public async Task<IActionResult> EditJobPost(EditJobPostDto dto)
  906. {
  907. try
  908. {
  909. bool res = await _jobRep.UpdateAsync<Sys_JobPost>(a => a.Id == dto.Id, a => new Sys_JobPost
  910. {
  911. CompanyId = dto.CompanyId,
  912. DepId = dto.DepId,
  913. JobName = dto.JobName,
  914. Remark = dto.Remark,
  915. });
  916. if (!res)
  917. {
  918. return Ok(JsonView(false, "修改失败"));
  919. }
  920. return Ok(JsonView(true, "修改成功"));
  921. }
  922. catch (Exception ex)
  923. {
  924. return Ok(JsonView(false, "程序错误!"));
  925. throw;
  926. }
  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> DelJobPost(DelJobPostDto dto)
  936. {
  937. try
  938. {
  939. bool res = await _jobRep.SoftDeleteAsync<Sys_JobPost>(dto.Id.ToString());
  940. if (!res)
  941. {
  942. return Ok(JsonView(false, "删除失败!"));
  943. }
  944. return Ok(JsonView(true, "删除成功"));
  945. }
  946. catch (Exception)
  947. {
  948. return Ok(JsonView(false, "程序错误!"));
  949. throw;
  950. }
  951. }
  952. #endregion
  953. #region 用户操作
  954. ///// <summary>
  955. ///// 用户表指定字段加密
  956. ///// </summary>
  957. ///// <param name="dto"></param>
  958. ///// <returns></returns>
  959. //[HttpPost]
  960. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  961. //public async Task<IActionResult> UserBatchEncryption()
  962. //{
  963. // 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();
  964. // foreach (var item in items) EncryptionProcessor.EncryptProperties(item);
  965. // var updItems = await _sqlSugar.Updateable(items).UpdateColumns(x => new { x.Phone, x.UrgentPhone, x.IDCard }).ExecuteCommandAsync();
  966. // return Ok(JsonView(updItems));
  967. //}
  968. /// <summary>
  969. /// 查询所有员工名称
  970. /// </summary>
  971. /// <param name="dto"></param>
  972. /// <returns></returns>
  973. [HttpPost]
  974. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  975. public async Task<IActionResult> GetUserNameList(DtoBase dto)
  976. {
  977. var result = _userRep.GetUserNameList(dto.PortType);
  978. if (result.Result.Code != 0)
  979. {
  980. return Ok(JsonView(false, "暂无数据!"));
  981. }
  982. return Ok(JsonView(true, "查询成功!", result.Result.Data));
  983. }
  984. /// <summary>
  985. /// 查询所有员工(web)
  986. /// </summary>
  987. /// <param name="dto"></param>
  988. /// <returns></returns>
  989. [HttpPost]
  990. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  991. public async Task<IActionResult> GetUserList(DtoBase dto)
  992. {
  993. var result = _userRep.GetUserList(dto.PortType, string.Empty);
  994. if (result.Result.Code != 0)
  995. {
  996. return Ok(JsonView(false, "暂无数据!"));
  997. }
  998. return Ok(JsonView(true, "查询成功!", result.Result.Data));
  999. }
  1000. /// <summary>
  1001. /// 查询用户数据
  1002. /// </summary>
  1003. /// <param name="dto"></param>
  1004. /// <returns></returns>
  1005. [HttpPost]
  1006. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1007. public async Task<IActionResult> QueryUserList(UserDto dto)
  1008. {
  1009. string sqlWhere = string.Format(" Where su.IsDel = 0 ");
  1010. if (dto.CompanyId != 0)
  1011. {
  1012. sqlWhere += string.Format(@" And su.CompanyId={0}", dto.CompanyId);
  1013. }
  1014. if (dto.DepId != 0)
  1015. {
  1016. sqlWhere += string.Format(@" And su.DepId={0}", dto.DepId);
  1017. }
  1018. if (dto.JobPostId != 0)
  1019. {
  1020. sqlWhere += string.Format(@" And su.JobPostId={0}", dto.JobPostId);
  1021. }
  1022. List<UserInfo> _userList = await _userRep.QueryUser(sqlWhere);
  1023. if (_userList.Count == 0)
  1024. {
  1025. return Ok(JsonView(400, "暂无数据!", new List<String>()));
  1026. }
  1027. foreach (var item in _userList) EncryptionProcessor.DecryptProperties(item);
  1028. List<UserInfoWebView> userList = _mapper.Map<List<UserInfoWebView>>(_userList);
  1029. return Ok(JsonView(true, "查询成功!", userList));
  1030. }
  1031. /// <summary>
  1032. /// 员工信息 个人详细信息
  1033. /// </summary>
  1034. /// <returns></returns>
  1035. [HttpPost]
  1036. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1037. public async Task<IActionResult> UserInfo(UserInfoDto dto)
  1038. {
  1039. if (dto.Id < 1) return Ok(JsonView(false, "请选择有效的userId!"));
  1040. if (dto.PortType < 1 || dto.PortType > 3) return Ok(JsonView(false, MsgTips.Port));
  1041. var _view = await _sqlSugar.Queryable<Sys_Users>()
  1042. .Where(x => x.IsDel == 0 && x.Id == dto.Id)
  1043. .FirstAsync();
  1044. //解密
  1045. EncryptionProcessor.DecryptProperties(_view);
  1046. var data = new {
  1047. _view.Id,
  1048. _view.CnName,
  1049. _view.EnName,
  1050. _view.Number,
  1051. _view.CompanyId,
  1052. _view.DepId,
  1053. _view.JobPostId,
  1054. _view.Password,
  1055. _view.Sex,
  1056. _view.Ext,
  1057. _view.Phone,
  1058. _view.UrgentPhone,
  1059. _view.Email,
  1060. _view.Address,
  1061. _view.Edate,
  1062. //_view.Seniority,
  1063. _view.Birthday,
  1064. _view.IDCard,
  1065. _view.StartWorkDate,
  1066. _view.GraduateInstitutions,
  1067. _view.Professional,
  1068. _view.Education,
  1069. _view.TheOrAdultEducation,
  1070. _view.MaritalStatus,
  1071. _view.HomeAddress,
  1072. _view.UsePeriod,
  1073. _view.WorkExperience,
  1074. _view.Certificate,
  1075. //_view.QiyeChatUserId,
  1076. _view.Remark
  1077. };
  1078. return Ok(JsonView(true, "操作成功!", data));
  1079. }
  1080. /// <summary>
  1081. /// 员工信息 All信息修改
  1082. /// </summary>
  1083. /// <returns></returns>
  1084. [HttpPost]
  1085. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1086. public async Task<IActionResult> EditUserInfo(EditUserInfoDto _dto)
  1087. {
  1088. EditUserInfoDtoValidator validator = new EditUserInfoDtoValidator();
  1089. var validatorRes = await validator.ValidateAsync(_dto);
  1090. if (!validatorRes.IsValid)
  1091. {
  1092. var errors = new StringBuilder();
  1093. foreach (var error in validatorRes.Errors) errors.AppendLine(error.ErrorMessage);
  1094. return Ok(JsonView(false, errors.ToString()));
  1095. }
  1096. var userInfo = _mapper.Map<Sys_Users>(_dto);
  1097. if (_dto.CurrUserId < 1) return Ok(JsonView(false, "暂无修改权限!"));
  1098. //修改权限验证 指定人员 信息部门(4)和人事部刘一茹( 230)、赖红燕(309)
  1099. List<int> userIds = new List<int>() {
  1100. 4 ,//管理员
  1101. 5 ,//杨俊霄
  1102. 117 ,//人事审核号
  1103. 208 ,//雷怡
  1104. 230 ,//刘一茹
  1105. 233 ,//刘华举
  1106. 234 ,//蒋金辰
  1107. 235 ,//袁榕烽
  1108. 309 ,//赖红燕
  1109. };
  1110. if (!userIds.Contains(_dto.CurrUserId)) return Ok(JsonView(false, "暂无修改权限!"));
  1111. //加密
  1112. EncryptionProcessor.EncryptProperties(userInfo);
  1113. var res = await _sqlSugar.Updateable(userInfo)
  1114. .IgnoreColumns(x => new
  1115. {
  1116. x.QiyeChatUserId,
  1117. x.Rdate,
  1118. x.Seniority,
  1119. x.HrAudit,
  1120. x.CreateUserId,
  1121. x.CreateTime,
  1122. x.DeleteUserId,
  1123. x.DeleteTime,
  1124. x.IsDel
  1125. })
  1126. .Where(x => x.Id == _dto.Id)
  1127. .ExecuteCommandAsync();
  1128. if (res > 0) return Ok(JsonView(true, "操作成功!"));
  1129. return Ok(JsonView(false, "操作失败!"));
  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> EditUser(EditUserDto dto)
  1139. {
  1140. if(dto.CurrUserId < 1) return Ok(JsonView(false, "暂无修改权限!"));
  1141. //修改权限验证 指定人员 信息部门(4)和人事部刘一茹( 230)、赖红燕(309)
  1142. var userIds = new List<int>() {
  1143. 4 ,//管理员
  1144. 5 ,//杨俊霄
  1145. 117 ,//人事审核号
  1146. 208 ,//雷怡
  1147. 230 ,//刘一茹
  1148. 233 ,//刘华举
  1149. 234 ,//蒋金辰
  1150. 235 ,//袁榕烽
  1151. 309 ,//赖红燕
  1152. };
  1153. if (!userIds.Contains(dto.CurrUserId)) return Ok(JsonView(false, "暂无修改权限!"));
  1154. bool res = await _userRep.UpdateAsync<Sys_Users>(a => a.Id == dto.Id, a => new Sys_Users
  1155. {
  1156. Number = dto.Number,
  1157. CompanyId = dto.CompanyId,
  1158. DepId = dto.DepId,
  1159. JobPostId = dto.JobPostId,
  1160. Ext = dto.Ext,
  1161. UsePeriod = dto.UsePeriod,
  1162. //HrAudit = dto.HrAudit
  1163. });
  1164. if (!res)
  1165. {
  1166. return Ok(JsonView(false, "修改失败!"));
  1167. }
  1168. return Ok(JsonView(true, "修改成功!"));
  1169. }
  1170. /// <summary>
  1171. /// 修改用户信息(登录用户修改个人信息)
  1172. /// </summary>
  1173. /// <param name="dto"></param>
  1174. /// <returns></returns>
  1175. [HttpPost]
  1176. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1177. public async Task<IActionResult> EditMyUser(EditMyUserDto dto)
  1178. {
  1179. if (string.IsNullOrWhiteSpace(dto.CnName) ||
  1180. string.IsNullOrWhiteSpace(dto.Address) ||
  1181. string.IsNullOrWhiteSpace(dto.IDCard) ||
  1182. dto.Sex != 0 && dto.Sex != 1 ||
  1183. string.IsNullOrWhiteSpace(dto.MaritalStatus) ||
  1184. string.IsNullOrWhiteSpace(dto.HomeAddress) ||
  1185. dto.Birthday >= DateTime.Now.AddYears(-1))
  1186. {
  1187. return Ok(JsonView(false, "请完善你的个人信息!"));
  1188. }
  1189. else if (string.IsNullOrWhiteSpace(dto.GraduateInstitutions) ||
  1190. string.IsNullOrWhiteSpace(dto.Professional) ||
  1191. dto.Education == 0 ||
  1192. string.IsNullOrWhiteSpace(dto.GraduateInstitutions))
  1193. {
  1194. return Ok(JsonView(false, "请完善你的学历信息!"));
  1195. }
  1196. else if (string.IsNullOrWhiteSpace(dto.Phone) ||
  1197. string.IsNullOrWhiteSpace(dto.UrgentPhone) ||
  1198. string.IsNullOrWhiteSpace(dto.Email))
  1199. {
  1200. return Ok(JsonView(false, "请检查联系方式、紧急联系人及邮箱输写是否正确!"));
  1201. }
  1202. else
  1203. {
  1204. //指定字段加密
  1205. var phone = AesEncryptionHelper.Encrypt(dto.Phone);
  1206. var urgentPhone = AesEncryptionHelper.Encrypt(dto.UrgentPhone);
  1207. var IDCard = AesEncryptionHelper.Encrypt(dto.IDCard);
  1208. bool res = await _userRep.UpdateAsync<Sys_Users>(a => a.Id == dto.Id, a => new Sys_Users
  1209. {
  1210. CnName = dto.CnName,
  1211. EnName = dto.EnName,
  1212. Sex = dto.Sex,
  1213. Phone = phone,
  1214. UrgentPhone = urgentPhone,
  1215. Email = dto.Email,
  1216. Address = dto.Address,
  1217. Edate = dto.Edate,
  1218. Birthday = dto.Birthday,
  1219. IDCard = IDCard,
  1220. GraduateInstitutions = dto.GraduateInstitutions,
  1221. Professional = dto.Professional,
  1222. Education = dto.Education,
  1223. TheOrAdultEducation = dto.TheOrAdultEducation,
  1224. MaritalStatus = dto.MaritalStatus,
  1225. HomeAddress = dto.HomeAddress,
  1226. WorkExperience = dto.WorkExperience,
  1227. Certificate = dto.Certificate
  1228. });
  1229. if (!res)
  1230. {
  1231. return Ok(JsonView(false, "修改失败!"));
  1232. }
  1233. return Ok(JsonView(true, "修改成功!"));
  1234. }
  1235. }
  1236. /// <summary>
  1237. /// 删除用户信息
  1238. /// 即为离职
  1239. /// </summary>
  1240. /// <param name="dto"></param>
  1241. /// <returns></returns>
  1242. [HttpPost]
  1243. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1244. public async Task<IActionResult> PostUserDelById(UserDelDto dto)
  1245. {
  1246. if (dto == null)
  1247. {
  1248. return Ok(JsonView(false, "参数不能为空!"));
  1249. }
  1250. var _Users = _sqlSugar.Queryable<Sys_Users>().First(a => a.IsDel == 0 && a.Id == dto.Id);
  1251. if (_Users != null)
  1252. {
  1253. var sys_UsersList = _sqlSugar.Queryable<Sys_Users>().Where(a => a.IsDel == 0 && a.CompanyId == _Users.CompanyId).ToList();
  1254. if (sys_UsersList.Count == 1)
  1255. {
  1256. return Ok(JsonView(false, "该人员为公司最后一位,不可删除!"));
  1257. }
  1258. }
  1259. bool res = await _userRep.UpdateAsync<Sys_Users>(a => a.Id == dto.Id, a => new Sys_Users
  1260. {
  1261. IsDel = 1,
  1262. DeleteUserId = dto.OperateUserId,
  1263. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  1264. Rdate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  1265. });
  1266. if (!res)
  1267. {
  1268. return Ok(JsonView(false, "操作失败!"));
  1269. }
  1270. return Ok(JsonView(true, "操作成功!"));
  1271. }
  1272. /// <summary>
  1273. /// 员工信息
  1274. /// 人事审核
  1275. /// </summary>
  1276. /// <param name="dto"></param>
  1277. /// <returns></returns>
  1278. [HttpPost]
  1279. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1280. public async Task<IActionResult> PersonnelAudit(PersonnelAuditDto dto)
  1281. {
  1282. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数!"));
  1283. if (dto.Id < 1) return Ok(JsonView(false, "请传入有效的Id参数!"));
  1284. if (dto.IsAudit < 1 || dto.IsAudit > 2) return Ok(JsonView(false, "请传入有效的IsAudit参数!1:通过 2拒绝"));
  1285. bool res = await _userRep.UpdateAsync<Sys_Users>(a => a.Id == dto.Id, a => new Sys_Users { HrAudit = dto.IsAudit });
  1286. if (res)
  1287. {
  1288. //审核成功添加员工基础页面权限
  1289. var userData = _sqlSugar.Queryable<Sys_Users>().Where(it => it.Id == dto.Id).First();
  1290. int depId = 0, postId = 0;
  1291. if (userData != null) { depId = userData.DepId; postId = userData.JobPostId; }
  1292. bool s = DefaultPostAuth(depId, postId, dto.Id, dto.UserId);
  1293. string str = $"基础页面权限添加失败!";
  1294. if (s) str = $"基础页面权限添加成功!";
  1295. return Ok(JsonView(true, $"操作成功!{str}"));
  1296. }
  1297. return Ok(JsonView(false, "操作失败!"));
  1298. }
  1299. /// <summary>
  1300. /// 部门查询员工
  1301. /// </summary>
  1302. /// <param name="dto"></param>
  1303. /// <returns></returns>
  1304. [HttpPost]
  1305. public IActionResult QueryUserByDepart(QueryUserByDepartDto dto)
  1306. {
  1307. var jw = JsonView(false);
  1308. if (dto.DepartId < 1)
  1309. {
  1310. jw.Msg = "请传入正确的部门id";
  1311. return Ok(jw);
  1312. }
  1313. 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} )
  1314. AND su.IsDel = 0 ";
  1315. var result = _sqlSugar.SqlQueryable<Sys_Users>(sql).Select(x => new
  1316. {
  1317. x.Id,
  1318. x.CnName,
  1319. x.EnName
  1320. }).ToList();
  1321. jw.Data = result;
  1322. jw.Code = 200;
  1323. jw.Msg = "获取成功!";
  1324. return Ok(jw);
  1325. }
  1326. #endregion
  1327. #region 权限模块
  1328. /// <summary>
  1329. /// 权限数据页面初始化
  1330. /// </summary>
  1331. /// <param name="dto"></param>
  1332. /// <returns></returns>
  1333. //[Authorize]
  1334. [HttpPost]
  1335. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1336. public async Task<IActionResult> GetAuth(AuthDto dto)
  1337. {
  1338. Result result = new Result();
  1339. //模块数据
  1340. var setDataResult = await _setDataRepository.GetSySDefultModule();
  1341. if (setDataResult.Code != 0)
  1342. {
  1343. return Ok(JsonView(setDataResult.Msg));
  1344. }
  1345. //操作方式
  1346. var PageOperation = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, Sys_PageFunctionPermission>(x => x.IsEnable == 1).ToList();
  1347. //获取所有关联页面
  1348. var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  1349. //页面数据
  1350. var SystemMenuPermissionData = _SystemMenuPermissionRepository.QueryDto<Sys_SystemMenuPermission, SystemMenuPermissionView>(x => x.Mid == dto.moduleId && x.IsEnable == 1).ToList();
  1351. if (SystemMenuPermissionData == null || SystemMenuPermissionData.Count() == 0)
  1352. {
  1353. return Ok(JsonView("暂无数据"));
  1354. }
  1355. ArrayList viewData = new ArrayList();
  1356. //组合页面数据
  1357. foreach (var item in SystemMenuPermissionData)
  1358. {
  1359. ArrayList ids = new ArrayList();
  1360. foreach (var viewop in PageOperation)
  1361. {
  1362. var op = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.SmId == item.Id && x.FId == viewop.Id);
  1363. if (op != null)
  1364. {
  1365. ids.Add(viewop.Id);
  1366. }
  1367. }
  1368. viewData.Add(new
  1369. {
  1370. Id = item.Id,
  1371. Mid = item.Mid,
  1372. Name = item.Name,
  1373. SystemMenuCode = item.SystemMenuCode,
  1374. opList = ids,
  1375. selList = new string[0]
  1376. });
  1377. }
  1378. //公司数据
  1379. var CompanyDataResult = _CompanyRepository.GetCompanyData();
  1380. if (CompanyDataResult.Code != 0)
  1381. {
  1382. return Ok(JsonView(CompanyDataResult.Msg));
  1383. }
  1384. result.Code = 0;
  1385. result.Msg = "成功!";
  1386. var Dyresult = new
  1387. {
  1388. setDataResult = setDataResult.Data,
  1389. CompanyDataResult = CompanyDataResult.Data,
  1390. SystemMenuPermissionData = viewData,
  1391. PageOperation = PageOperation,
  1392. };
  1393. return Ok(JsonView(200, "成功!", Dyresult));
  1394. }
  1395. /// <summary>
  1396. /// 获取职务权限
  1397. /// </summary>
  1398. /// <param name="dto"></param>
  1399. /// <returns></returns>
  1400. [HttpPost]
  1401. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1402. public IActionResult QueryJobAuth(QueryJobAuthDto dto)
  1403. {
  1404. //选中的操作权限
  1405. var DBdata = _JobPostAuthorityRepository.QueryDto<Sys_JobPostAuthority, JobPostAuthorityView>(x => x.JpId == dto.jobid).ToList();
  1406. var SystemMenuPermissionData = _SystemMenuPermissionRepository.QueryDto<Sys_SystemMenuPermission, SystemMenuPermissionView>(x => x.Mid == dto.moduleId).ToList();
  1407. if (SystemMenuPermissionData == null || SystemMenuPermissionData.Count() == 0)
  1408. {
  1409. return Ok(JsonView("暂无数据"));
  1410. }
  1411. //所有操作
  1412. var PageOperation = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, Sys_PageFunctionPermission>().ToList();
  1413. //获取所有关联页面
  1414. var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  1415. ArrayList viewData = new ArrayList();
  1416. //组合页面数据
  1417. foreach (var item in SystemMenuPermissionData)
  1418. {
  1419. ArrayList ids = new ArrayList();
  1420. foreach (var viewop in PageOperation)
  1421. {
  1422. var op = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.SmId == item.Id && x.FId == viewop.Id);
  1423. if (op != null)
  1424. {
  1425. ids.Add(viewop.Id);
  1426. }
  1427. }
  1428. //获取本职务的页面拥有的权限
  1429. var DBwhere = DBdata.Where(x => x.SmId == item.Id && x.JpId == dto.jobid).ToList();
  1430. viewData.Add(new
  1431. {
  1432. Id = item.Id,
  1433. Mid = item.Mid,
  1434. Name = item.Name,
  1435. SystemMenuCode = item.SystemMenuCode,
  1436. opList = ids,
  1437. selList = DBwhere.Select(x => x.FId)
  1438. });
  1439. }
  1440. return Ok(JsonView(200, "成功!", viewData));
  1441. }
  1442. /// <summary>
  1443. /// 保存岗位权限
  1444. /// </summary>
  1445. /// <param name="dto"></param>
  1446. /// <returns></returns>
  1447. [HttpPost]
  1448. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1449. public async Task<IActionResult> SaveJobAuth(SaveJobDto dto)
  1450. {
  1451. //获取所有关联页面
  1452. var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  1453. var RemoveJobPostAuthList = _SystemMenuAndFunctionRepository._sqlSugar.SqlQueryable<Sys_JobPostAuthority>($@"
  1454. select a.* from Sys_JobPostAuthority a, Sys_SetData b ,Sys_SystemMenuPermission c
  1455. where a.SmId = c.Id and c.Mid = b.Id and JpId = {dto.Jpid} and c.Mid ={dto.modulId}
  1456. ").ToList();
  1457. List<Sys_JobPostAuthority> adds = new List<Sys_JobPostAuthority>();
  1458. foreach (var item in dto.Savejobs)
  1459. {
  1460. foreach (var fid in item.FIds)
  1461. {
  1462. var whereobj = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.FId == fid && x.SmId == item.SmId);
  1463. if (whereobj != null)
  1464. {
  1465. adds.Add(new Sys_JobPostAuthority
  1466. {
  1467. CreateTime = DateTime.Now,
  1468. CreateUserId = dto.UserId,
  1469. FId = fid,
  1470. JpId = dto.Jpid,
  1471. SmId = item.SmId
  1472. });
  1473. }
  1474. }
  1475. }
  1476. _JobPostAuthorityRepository.BeginTran();
  1477. try
  1478. { //删除岗位
  1479. bool isdel = await _JobPostAuthorityRepository.DeletesAsync<Sys_JobPostAuthority>(RemoveJobPostAuthList);
  1480. int UpRows = _JobPostAuthorityRepository.Adds<Sys_JobPostAuthority>(adds);
  1481. //获取所有职位员工
  1482. var jobUserAll = await QueryUserList(new UserDto { PortType = 2, JobPostId = dto.Jpid });
  1483. List<UserInfoWebView> users = null;
  1484. var QueryUserListApiResult = (((jobUserAll as OkObjectResult).Value) as OASystem.Domain.ViewModels.JsonView);
  1485. if (QueryUserListApiResult != null)
  1486. {
  1487. if (QueryUserListApiResult.Code == 200)
  1488. {
  1489. users = QueryUserListApiResult.Data as List<UserInfoWebView>;
  1490. }
  1491. }
  1492. if (users != null && users.Count > 0)
  1493. {
  1494. List<Sys_UserAuthority> userAuth = null;
  1495. var uids = string.Join(',', users.Select(x => x.Id)).TrimEnd(',');
  1496. var RemoveUserAuthorityListAndTemp = _UserAuthorityRepository._sqlSugar.SqlQueryable<Sys_UserAuthority>($@"
  1497. select a.* from Sys_UserAuthority a, Sys_SetData b ,Sys_SystemMenuPermission c
  1498. where a.SmId = c.Id and c.Mid = b.Id and uid in ({uids}) and c.Mid = {dto.modulId} and IsTemp = 1
  1499. ").ToList();
  1500. foreach (var user in users)
  1501. {
  1502. //删除个人级岗位权限
  1503. isdel = await _UserAuthorityRepository.DeletesAsync<Sys_UserAuthority>
  1504. (RemoveUserAuthorityListAndTemp.FindAll(x => x.UId == user.Id));
  1505. userAuth = adds.Select(x => new Sys_UserAuthority
  1506. {
  1507. CreateTime = DateTime.Now,
  1508. CreateUserId = dto.UserId,
  1509. FId = x.FId,
  1510. SmId = x.SmId,
  1511. UId = user.Id,
  1512. IsTemp = 1,
  1513. }).ToList();
  1514. //添加个人级别岗位
  1515. int AddRows = _UserAuthorityRepository.Adds<Sys_UserAuthority>(userAuth);
  1516. }
  1517. }
  1518. }
  1519. catch (Exception ex)
  1520. {
  1521. _JobPostAuthorityRepository.RollbackTran();
  1522. return Ok(JsonView("系统错误!"));
  1523. }
  1524. _JobPostAuthorityRepository.CommitTran();
  1525. return Ok(JsonView(200, "成功", new { }));
  1526. }
  1527. /// <summary>
  1528. /// 获取员工权限
  1529. /// </summary>
  1530. /// <param name="dto"></param>
  1531. /// <returns></returns>
  1532. [HttpPost]
  1533. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1534. public IActionResult QueryUserAuth(QueryUserAuthDto dto)
  1535. {
  1536. //选中的员工操作权限
  1537. var DBdata = _UserAuthorityRepository.QueryDto<Sys_UserAuthority, UserAuthorityView>(x => x.UId == dto.Userid).ToList();
  1538. var SystemMenuPermissionData = _SystemMenuPermissionRepository.QueryDto<Sys_SystemMenuPermission, SystemMenuPermissionView>(x => x.Mid == dto.moduleId).ToList();
  1539. if (SystemMenuPermissionData == null || SystemMenuPermissionData.Count() == 0)
  1540. {
  1541. return Ok(JsonView("暂无数据"));
  1542. }
  1543. //所有操作
  1544. var PageOperation = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, Sys_PageFunctionPermission>(x => x.IsEnable == 1).ToList();
  1545. //获取所有关联页面
  1546. var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  1547. ArrayList viewData = new ArrayList();
  1548. //组合页面数据
  1549. foreach (var item in SystemMenuPermissionData)
  1550. {
  1551. ArrayList ids = new ArrayList();
  1552. foreach (var viewop in PageOperation)
  1553. {
  1554. var op = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.SmId == item.Id && x.FId == viewop.Id);
  1555. if (op != null)
  1556. {
  1557. ids.Add(viewop.Id);
  1558. }
  1559. }
  1560. //获取本员工拥有的权限
  1561. var DBwhere = DBdata.Where(x => x.SmId == item.Id && x.UId == dto.Userid).ToList();
  1562. viewData.Add(new
  1563. {
  1564. Id = item.Id,
  1565. Mid = item.Mid,
  1566. Name = item.Name,
  1567. SystemMenuCode = item.SystemMenuCode,
  1568. opList = ids,
  1569. selList = DBwhere.Select(x => x.FId)
  1570. });
  1571. }
  1572. return Ok(JsonView(200, "成功!", viewData));
  1573. }
  1574. /// <summary>
  1575. /// 根据Id获取员工所有移动端查看权限
  1576. /// </summary>
  1577. /// <param name="dto"></param>
  1578. /// <returns></returns>
  1579. [HttpPost]
  1580. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1581. public IActionResult QueryUserAuthByUserId(QueryUserAuthByUserIdDto dto)
  1582. {
  1583. 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)
  1584. Inner Join Sys_SystemMenuPermission as sm With(Nolock) On u.SmId = sm.Id
  1585. Inner Join Sys_SetData as sd1 With(Nolock) On sm.Mid = sd1.Id
  1586. Where u.IsDel = 0 And sm.IsDel = 0
  1587. And u.UId = {0} And u.FId = 1 ", dto.UserId);
  1588. List<SystemModule_UserAuthSqlView> _dataSource = _sqlSugar.SqlQueryable<SystemModule_UserAuthSqlView>(sql).ToList();
  1589. List<SystemModule_UserAuthView> result = new List<SystemModule_UserAuthView>();
  1590. foreach (SystemModule_UserAuthSqlView item in _dataSource)
  1591. {
  1592. if (result.FirstOrDefault(s => s.ModuleId == item.ModuleId) == null)
  1593. {
  1594. List<SystemModule_UserAuthSqlView> tempList = _dataSource.Where(s => s.ModuleId == item.ModuleId).ToList();
  1595. List<SystemMenu_UserAuthView> menuList = new List<SystemMenu_UserAuthView>();
  1596. foreach (SystemModule_UserAuthSqlView item2 in tempList)
  1597. {
  1598. SystemMenu_UserAuthView menu = new SystemMenu_UserAuthView() { MenuId = item2.MenuId, MenuName = item2.MenuName };
  1599. menuList.Add(menu);
  1600. }
  1601. SystemModule_UserAuthView module = new SystemModule_UserAuthView() { MenuList = menuList, ModuleId = item.ModuleId, ModuleName = item.ModuleName };
  1602. result.Add(module);
  1603. }
  1604. }
  1605. return Ok(JsonView(200, "成功!", result));
  1606. }
  1607. /// <summary>
  1608. /// 保存员工权限
  1609. /// </summary>
  1610. /// <param name="dto"></param>
  1611. /// <returns></returns>
  1612. [HttpPost]
  1613. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1614. public async Task<IActionResult> SaveUserAuth(SaveUserDto dto)
  1615. {
  1616. //获取所有关联页面
  1617. var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  1618. //获取用户当前模块所有启用页面
  1619. var userpageList = _SystemMenuPermissionRepository._sqlSugar.SqlQueryable<Sys_UserAuthority>($@"
  1620. select a.* from Sys_UserAuthority a, Sys_SetData b ,Sys_SystemMenuPermission c
  1621. where a.SmId = c.Id and c.Mid = b.Id and uid = {dto.uid} and c.Mid ={dto.Modulid}
  1622. ").ToList();
  1623. List<Sys_UserAuthority> adds = new List<Sys_UserAuthority>();
  1624. foreach (var item in dto.Savejobs)
  1625. {
  1626. foreach (var fid in item.FIds)
  1627. {
  1628. var whereobj = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.FId == fid && x.SmId == item.SmId);
  1629. if (whereobj != null)
  1630. {
  1631. adds.Add(new Sys_UserAuthority
  1632. {
  1633. CreateTime = DateTime.Now,
  1634. CreateUserId = dto.UserId,
  1635. FId = fid,
  1636. UId = dto.uid,
  1637. SmId = item.SmId,
  1638. IsTemp = 0
  1639. });
  1640. }
  1641. }
  1642. }
  1643. _JobPostAuthorityRepository.BeginTran();
  1644. try
  1645. {
  1646. List<Sys_UserAuthority> userAuth = null;
  1647. //删除个人级岗位权限
  1648. bool isdel = await _UserAuthorityRepository.DeletesAsync<Sys_UserAuthority>(userpageList);
  1649. userAuth = adds.Select(x => new Sys_UserAuthority
  1650. {
  1651. CreateTime = DateTime.Now,
  1652. CreateUserId = dto.UserId,
  1653. FId = x.FId,
  1654. SmId = x.SmId,
  1655. UId = dto.uid,
  1656. IsTemp = 0,
  1657. }).ToList();
  1658. //添加个人级别岗位
  1659. int AddRows = _UserAuthorityRepository.Adds<Sys_UserAuthority>(userAuth);
  1660. }
  1661. catch (Exception ex)
  1662. {
  1663. _JobPostAuthorityRepository.RollbackTran();
  1664. return Ok(JsonView("系统错误!"));
  1665. }
  1666. _JobPostAuthorityRepository.CommitTran();
  1667. return Ok(JsonView(200, "成功", new { }));
  1668. }
  1669. #endregion
  1670. #region 页面配置
  1671. /// <summary>
  1672. /// 页面配置界面数据初始化
  1673. /// </summary>
  1674. /// <returns></returns>
  1675. //[Authorize]
  1676. [HttpPost]
  1677. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1678. public async Task<IActionResult> PageConfigInit()
  1679. {
  1680. ArrayList arr = new ArrayList();
  1681. var viewList = await _setDataRepository.GetSetDataAndPageInfoBySTId();
  1682. if (viewList.Code != 0)
  1683. {
  1684. return Ok(JsonView(viewList.Msg));
  1685. }
  1686. var ModList = await _setDataRepository.GetSySDefultModule();
  1687. return Ok(JsonView(new
  1688. {
  1689. viewList,
  1690. ModList,
  1691. }));
  1692. }
  1693. [HttpPost]
  1694. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1695. public async Task<IActionResult> EditPageInfo(SetDataAndPageInfoDto dto)
  1696. {
  1697. JsonView view = null;
  1698. _SystemMenuPermissionRepository.BeginTran();
  1699. var istrue = await _SystemMenuPermissionRepository.UpdateAsync(x => x.Id == dto.Pageid, x => new Sys_SystemMenuPermission
  1700. {
  1701. AndroidUrl = dto.AndroidUrl,
  1702. CreateTime = DateTime.Now,
  1703. Icon = dto.Icon,
  1704. IosUrl = dto.IosUrl,
  1705. Name = dto.PageName,
  1706. PhoneIsEnable = dto.PagePhoneIsEnable,
  1707. CreateUserId = dto.UserId,
  1708. IsDel = 0,
  1709. IsEnable = dto.PageIsEnable,
  1710. Mid = dto.Modulid,
  1711. Remark = dto.PageRemark,
  1712. SystemMenuCode = dto.SystemMenuCode,
  1713. WebUrl = dto.WebUrl,
  1714. });
  1715. if (istrue)
  1716. {
  1717. //删除页面绑定的操作后重新绑定
  1718. await _SystemMenuAndFunctionRepository.DeleteAsync(x => x.SmId == dto.Pageid);
  1719. List<Sys_SystemMenuAndFunction> binFun = new List<Sys_SystemMenuAndFunction>();
  1720. foreach (var item in dto.FunArr)
  1721. {
  1722. binFun.Add(new Sys_SystemMenuAndFunction
  1723. {
  1724. CreateTime = DateTime.Now,
  1725. CreateUserId = dto.UserId,
  1726. FId = item,
  1727. SmId = dto.Pageid,
  1728. IsDel = 0,
  1729. });
  1730. }
  1731. int number = _SystemMenuAndFunctionRepository.Adds<Sys_SystemMenuAndFunction>(binFun);
  1732. view = JsonView(istrue);
  1733. _SystemMenuPermissionRepository.CommitTran();
  1734. }
  1735. else
  1736. {
  1737. _SystemMenuPermissionRepository.RollbackTran();
  1738. view = JsonView("添加失败");
  1739. }
  1740. return Ok(view);
  1741. }
  1742. /// <summary>
  1743. /// 添加一个页面
  1744. /// </summary>
  1745. /// <param name="dto"></param>
  1746. /// <returns></returns>
  1747. [HttpPost]
  1748. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1749. public async Task<IActionResult> AddPageInfo(SetDataAndPageInfoDto dto)
  1750. {
  1751. JsonView view = null;
  1752. _SystemMenuPermissionRepository.BeginTran();
  1753. int number = await _SystemMenuPermissionRepository.AddAsyncReturnId(new Sys_SystemMenuPermission
  1754. {
  1755. AndroidUrl = dto.AndroidUrl,
  1756. CreateTime = DateTime.Now,
  1757. Icon = dto.Icon,
  1758. IosUrl = dto.IosUrl,
  1759. Name = dto.PageName,
  1760. PhoneIsEnable = dto.PagePhoneIsEnable,
  1761. CreateUserId = dto.UserId,
  1762. IsDel = 0,
  1763. IsEnable = dto.PageIsEnable,
  1764. Mid = dto.Modulid,
  1765. Remark = dto.PageRemark,
  1766. SystemMenuCode = dto.SystemMenuCode,
  1767. WebUrl = dto.WebUrl,
  1768. });
  1769. List<Sys_SystemMenuAndFunction> binFun = new List<Sys_SystemMenuAndFunction>();
  1770. foreach (var item in dto.FunArr)
  1771. {
  1772. binFun.Add(new Sys_SystemMenuAndFunction
  1773. {
  1774. CreateTime = DateTime.Now,
  1775. CreateUserId = dto.UserId,
  1776. FId = item,
  1777. SmId = number,
  1778. IsDel = 0,
  1779. });
  1780. }
  1781. number = _SystemMenuAndFunctionRepository.Adds<Sys_SystemMenuAndFunction>(binFun);
  1782. if (number > 0)
  1783. {
  1784. view = JsonView(number);
  1785. _SystemMenuPermissionRepository.CommitTran();
  1786. }
  1787. else
  1788. {
  1789. _SystemMenuPermissionRepository.RollbackTran();
  1790. view = JsonView("添加失败");
  1791. }
  1792. return Ok(view);
  1793. }
  1794. /// <summary>
  1795. /// 删除页面
  1796. /// </summary>
  1797. /// <param></param>
  1798. /// <returns></returns>
  1799. [HttpPost]
  1800. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1801. public async Task<IActionResult> DelPageInfo(List<SystemMenuDelDto> Dto)
  1802. {
  1803. JsonView view = new JsonView();
  1804. if (Dto.Count > 0)
  1805. {
  1806. try
  1807. {
  1808. _SystemMenuPermissionRepository.BeginTran();
  1809. bool istrue = false;
  1810. foreach (var item in Dto)
  1811. {
  1812. istrue = await _SystemMenuPermissionRepository.SoftDeleteAsync(item.Pageid.ToString());
  1813. if (!istrue)
  1814. {
  1815. throw new Exception("修改失败");
  1816. }
  1817. }
  1818. view.Code = 200;
  1819. view.Msg = "删除成功!";
  1820. view.Data = istrue;
  1821. _SystemMenuPermissionRepository.CommitTran();
  1822. }
  1823. catch (Exception)
  1824. {
  1825. _SystemMenuPermissionRepository.RollbackTran();
  1826. }
  1827. }
  1828. return Ok(JsonView(view));
  1829. }
  1830. /// <summary>
  1831. /// 获取页面绑定的操作
  1832. /// </summary>
  1833. /// <param name="Dto"></param>
  1834. /// <returns></returns>
  1835. [HttpPost]
  1836. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1837. public async Task<IActionResult> QueryPageFunById(PageFunDto Dto)
  1838. {
  1839. //页面与操作关联表
  1840. var pageAndFunList = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  1841. //页面功能表
  1842. var pageFunList = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, Sys_PageFunctionPermission>(x => x.IsEnable == 1).ToList();
  1843. ArrayList arr = new ArrayList();
  1844. foreach (var item in pageFunList)
  1845. {
  1846. var FindVal = pageAndFunList.Find(x => x.SmId == Dto.Pageid && x.FId == item.Id);
  1847. if (FindVal == null)
  1848. {
  1849. arr.Add(new
  1850. {
  1851. id = item.Id,
  1852. name = item.FunctionName,
  1853. value = false
  1854. });
  1855. }
  1856. else
  1857. {
  1858. arr.Add(new
  1859. {
  1860. id = item.Id,
  1861. name = item.FunctionName,
  1862. value = true
  1863. });
  1864. }
  1865. }
  1866. return Ok(JsonView(arr));
  1867. }
  1868. #endregion
  1869. #region 页面操作
  1870. /// <summary>
  1871. /// 操作权限功能表
  1872. /// </summary>
  1873. /// <returns></returns>
  1874. [HttpPost]
  1875. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1876. public async Task<IActionResult> PageFunInit()
  1877. {
  1878. var PageFunInit = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, PageFunctionPermissionView>().ToList();
  1879. if (PageFunInit == null)
  1880. {
  1881. return Ok(JsonView(false, "暂无数据!"));
  1882. }
  1883. return Ok(JsonView(true, "查询成功!", PageFunInit));
  1884. }
  1885. /// <summary>
  1886. /// 操作权限功能表操作(Status 1:添加,2:编辑)
  1887. /// </summary>
  1888. /// <returns></returns>
  1889. [HttpPost]
  1890. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1891. public async Task<IActionResult> OperationFun(OperationFunInitDta dto)
  1892. {
  1893. Result result = await _PageFunctionPermissionRepository.OperationFunInit(dto);
  1894. if (result.Code != 0)
  1895. {
  1896. return Ok(JsonView(false, result.Msg));
  1897. }
  1898. return Ok(JsonView(true, result.Msg));
  1899. }
  1900. /// <summary>
  1901. /// 删除功能
  1902. /// </summary>
  1903. /// <param name="dto"></param>
  1904. /// <returns></returns>
  1905. [HttpPost]
  1906. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1907. public async Task<IActionResult> DelFun(DelFunInitDta dto)
  1908. {
  1909. var res = await _PageFunctionPermissionRepository.SoftDeleteByIdAsync<Sys_PageFunctionPermission>(dto.Id.ToString(), dto.DeleteUserId);
  1910. if (!res)
  1911. {
  1912. return Ok(JsonView(false, "删除失败"));
  1913. }
  1914. return Ok(JsonView(true, "删除成功!"));
  1915. }
  1916. #endregion
  1917. #region 各部门首页消息提示
  1918. /// <summary>
  1919. /// 部门首页消息提示
  1920. /// </summary>
  1921. /// <returns></returns>
  1922. [HttpGet("{portType}")]
  1923. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1924. public async Task<IActionResult> DepartmentHomePageMessagePrompts(int portType)
  1925. {
  1926. var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
  1927. if (currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
  1928. var department = currUserInfo.Department;
  1929. if (portType < 1 || portType > 3) return Ok(JsonView(false, MsgTips.Port));
  1930. if (portType == 1 || portType == 2 || portType == 3) // web
  1931. {
  1932. //固定查询时间(当前月的上月)
  1933. var lastMoth = DateTime.Now.AddMonths(-1);
  1934. var (startDate, endDate) = CommonFun.GetMonthStartAndEndDates(lastMoth.Year, lastMoth.Month);
  1935. var startDateTime = Convert.ToDateTime(startDate.ToString("yyyy-MM-dd 00:00:00"));
  1936. var endDateTime = Convert.ToDateTime(endDate.ToString("yyyy-MM-dd 23:59:59"));
  1937. //固定查询时间(本年)
  1938. var currStartDate = Convert.ToDateTime($"{DateTime.Now.Year}-01-01 00:00:00");
  1939. var currEntDate = Convert.ToDateTime($"{DateTime.Now.Year}-12-31 23:59:59");
  1940. if (department.Equals("总经办")) //总经办
  1941. {
  1942. //1、资料数据(市场部客户资源、op地接导游、op地接车数据、商邀数据、团组收款数据)数据提示Range(固定上个月) -- Add
  1943. #region 市场部客户资源
  1944. //1.1 市场部客户资源
  1945. var users = await _sqlSugar.Queryable<Sys_Users>()
  1946. .LeftJoin<Sys_Department>((u, d) => u.DepId == d.Id)
  1947. .Where((u, d) => u.IsDel == 0 && (d.DepName.Contains("市场部") || u.Id == 21))
  1948. .Select((u, d) => new { u.Id, u.CnName })
  1949. .ToListAsync();
  1950. var marketData = await _sqlSugar.Queryable<Crm_NewClientData>()
  1951. .LeftJoin<Sys_Users>((ncd, u) => ncd.CreateUserId == u.Id)
  1952. .Where((ncd, u) => ncd.IsDel == 0 && ncd.CreateTime >= startDateTime && ncd.CreateTime <= endDateTime)
  1953. .Select((ncd, u) => new
  1954. {
  1955. Area = ncd.Location,
  1956. ncd.Client,
  1957. ncd.Contact,
  1958. ncd.Job,
  1959. Tel = ncd.Telephone,
  1960. ncd.CreateUserId,
  1961. CreatleUserName = u.CnName,
  1962. ncd.CreateTime,
  1963. })
  1964. .ToListAsync();
  1965. foreach (var item in marketData) EncryptionProcessor.DecryptProperties(item);
  1966. var marketDataGroup = marketData.GroupBy(x => x.CreateUserId).Select(g => new { CreateUserId = g.Key, Items = g.ToList(), Count = g.Count() });
  1967. var marketData2 = new List<dynamic>();
  1968. foreach (var user in users)
  1969. {
  1970. var userMarketData = marketDataGroup.FirstOrDefault(x => user.Id == x.CreateUserId);
  1971. if (userMarketData != null)
  1972. {
  1973. marketData2.Add(new
  1974. {
  1975. uId = user.Id,
  1976. name = user.CnName,
  1977. count = userMarketData.Count,
  1978. msgTips = $"上月新增市场客户资源共{userMarketData.Count}条",
  1979. userMarketData = userMarketData.Items
  1980. });
  1981. }
  1982. else
  1983. {
  1984. marketData2.Add(new
  1985. {
  1986. uId = user.Id,
  1987. name = user.CnName,
  1988. count = 0,
  1989. msgTips = $"上月新增市场客户资源共{0}条",
  1990. userMarketData = new List<dynamic>() { },
  1991. });
  1992. }
  1993. }
  1994. var marketData1 = new
  1995. {
  1996. msgTips = $"上月新增市场客户资源共{marketData.Count}条",
  1997. Data = marketData2,
  1998. };
  1999. #endregion
  2000. #region op地接导游
  2001. //1.2 op地接导游
  2002. var opTourGuideData = await _sqlSugar.Queryable<Res_LocalGuideData>()
  2003. .LeftJoin<Sys_Users>((lgd, u) => lgd.CreateUserId == u.Id)
  2004. .Where((lgd, u) => lgd.IsDel == 0 && lgd.CreateTime >= startDateTime && lgd.CreateTime <= endDateTime)
  2005. .Select((lgd, u) => new
  2006. {
  2007. Area = lgd.UnitArea,
  2008. Client = lgd.UnitName,
  2009. lgd.Contact,
  2010. Job = "",
  2011. Tel = lgd.ContactTel,
  2012. lgd.CreateUserId,
  2013. CreatleUserName = u.CnName,
  2014. lgd.CreateTime,
  2015. })
  2016. .ToListAsync();
  2017. foreach (var item in opTourGuideData) EncryptionProcessor.DecryptProperties(item);
  2018. var opTourGuideDataGroups = opTourGuideData.GroupBy(x => x.CreateUserId)
  2019. .Select(g => new {
  2020. uId = g.Key,
  2021. name = g.ToList().FirstOrDefault()?.CreatleUserName ?? "-",
  2022. msgTips = $"上月新增OP地接导游资源共{g.Count()}条",
  2023. userTourGuideData = g.ToList(),
  2024. Count = g.Count()
  2025. });
  2026. var opTourGuideData1 = new
  2027. {
  2028. msgTips = $"上月新增OP地接导游资源共{opTourGuideData.Count}条",
  2029. Data = opTourGuideDataGroups,
  2030. };
  2031. #endregion
  2032. #region op车数据
  2033. //1.3 op车数据
  2034. var opCarData = await _sqlSugar.Queryable<Res_CarData>()
  2035. .LeftJoin<Sys_Users>((cd, u) => cd.CreateUserId == u.Id)
  2036. .Where((cd, u) => cd.IsDel == 0 && cd.CreateTime >= startDateTime && cd.CreateTime <= endDateTime)
  2037. .Select((cd, u) => new CarDataMsgTipsView()
  2038. {
  2039. Area = cd.UnitArea,
  2040. Client = cd.UnitName,
  2041. Contact = cd.Contact,
  2042. Job = "",
  2043. Tel = cd.ContactTel,
  2044. CreateUserId = cd.CreateUserId,
  2045. CreatleUserName = u.CnName,
  2046. CreateTime = cd.CreateTime,
  2047. })
  2048. .ToListAsync();
  2049. foreach (var item in opCarData) EncryptionProcessor.DecryptProperties(item);
  2050. var opCarDataGroups = opCarData.GroupBy(x => x.CreateUserId)
  2051. .Select(g => new {
  2052. uId = g.Key,
  2053. name = g.ToList().FirstOrDefault()?.CreatleUserName ?? "-",
  2054. msgTips = $"上月新增OP地接车资源共{g.Count()}条",
  2055. userTourGuideData = g.ToList(),
  2056. Count = g.Count()
  2057. });
  2058. var opCarData1 = new
  2059. {
  2060. msgTips = $"上月新增OP地接车资源共{opCarData.Count}条",
  2061. Data = opCarDataGroups,
  2062. };
  2063. #endregion
  2064. #region 商邀数据
  2065. //1.4 商邀数据
  2066. var invitationData = await _sqlSugar.Queryable<Res_InvitationOfficialActivityData>()
  2067. .LeftJoin<Sys_Users>((ioa, u) => ioa.CreateUserId == u.Id)
  2068. .Where((ioa, u) => ioa.IsDel == 0 && ioa.CreateTime >= startDateTime && ioa.CreateTime <= endDateTime)
  2069. .Select((ioa, u) => new
  2070. {
  2071. //Area = string.Format("{0}{1}", ioa.Country, !string.IsNullOrEmpty(ioa.City) ? "" : "-" + ioa.City),
  2072. Area = string.Format("{0}{1}", ioa.Country, ioa.City),
  2073. Client = ioa.UnitName,
  2074. ioa.Contact,
  2075. ioa.Job,
  2076. ioa.Tel,
  2077. ioa.CreateUserId,
  2078. CreatleUserName = u.CnName,
  2079. ioa.CreateTime,
  2080. })
  2081. .ToListAsync();
  2082. var invitationGroups = invitationData.GroupBy(x => x.CreateUserId)
  2083. .Select(g => new {
  2084. uId = g.Key,
  2085. name = g.ToList().FirstOrDefault()?.CreatleUserName ?? "-",
  2086. msgTips = $"上月新增商邀资源共{g.Count()}条",
  2087. userTourGuideData = g.ToList(),
  2088. Count = g.Count()
  2089. });
  2090. var invitationData1 = new
  2091. {
  2092. msgTips = $"上月新增商邀资源共{invitationData.Count}条",
  2093. Data = invitationGroups,
  2094. };
  2095. #endregion
  2096. #region 团组收款数据
  2097. //1.5 团组收款数据
  2098. var groupCollectionData = await _sqlSugar.Queryable<Fin_ForeignReceivables>()
  2099. .LeftJoin<Sys_Users>((fr, u) => fr.CreateUserId == u.Id)
  2100. .LeftJoin<Grp_DelegationInfo>((fr, u, di) => fr.Diid == di.Id)
  2101. .LeftJoin<Sys_SetData>((fr, u, di, sd) => fr.Currency == sd.Id)
  2102. .Where((fr, u, di, sd) => fr.IsDel == 0 && fr.CreateTime >= startDateTime && fr.CreateTime <= endDateTime)
  2103. .Select((fr, u, di, sd) => new
  2104. {
  2105. fr.PriceName,
  2106. fr.Price,
  2107. fr.Count,
  2108. fr.Unit,
  2109. fr.ItemSumPrice,
  2110. Currency = sd.Name,
  2111. GroupName = di.TeamName,
  2112. fr.CreateUserId,
  2113. CreateUserName = u.CnName,
  2114. fr.CreateTime,
  2115. })
  2116. .ToListAsync();
  2117. var groupCollectionGroups = groupCollectionData.GroupBy(x => x.CreateUserId)
  2118. .Select(g => new
  2119. {
  2120. uId = g.Key,
  2121. name = g.ToList().FirstOrDefault()?.CreateUserName ?? "-",
  2122. msgTips = $"上月累计团组收款共{g.Count()}条",
  2123. userTourGuideData = g.ToList(),
  2124. Count = g.Count()
  2125. });
  2126. var groupCollectionData2 = new
  2127. {
  2128. msgTips = $"上月累计团组收款共{groupCollectionData.Count}条",
  2129. Data = groupCollectionGroups,
  2130. };
  2131. #endregion
  2132. var materialData = new
  2133. {
  2134. marketData = marketData1,
  2135. opTourGuideData = opTourGuideData1,
  2136. opCarData = opCarData1,
  2137. invitationData = invitationData1,
  2138. groupCollectionData = groupCollectionData2
  2139. };
  2140. //2、费用未审核(日付申请未审核数据、团组费用未审核数据)费用提示Range(固定本年)
  2141. #region 日付申请未审核数据
  2142. var dailyPaymentData = await _sqlSugar.Queryable<Fin_DailyFeePayment>()
  2143. .LeftJoin<Sys_Users>((dfp, u) => dfp.CreateUserId == u.Id)
  2144. .Where(dfp => dfp.IsDel == 0 &&
  2145. dfp.MAudit == 0 &&
  2146. dfp.CreateTime >= currStartDate &&
  2147. dfp.CreateTime <= currEntDate
  2148. )
  2149. .OrderBy(dfp => dfp.CreateTime, OrderByType.Desc)
  2150. //.OrderBy(dfp => dfp.FAudit, OrderByType.Desc)
  2151. .Select((dfp, u) => new
  2152. {
  2153. id = dfp.Id,
  2154. amountName = dfp.Instructions,
  2155. amount = dfp.SumPrice,
  2156. fAuditStatus = dfp.FAudit == 1 ? "审核通过" :
  2157. dfp.FAudit == 2 ? "审核未通过" : "未审核",
  2158. fAuditDate = dfp.FAuditDate,
  2159. dfp.CreateUserId,
  2160. CreateUserName = u.CnName,
  2161. dfp.CreateTime
  2162. })
  2163. .ToListAsync();
  2164. var dailyPaymentGroups = dailyPaymentData.GroupBy(x => x.CreateUserId)
  2165. .Select(g => new
  2166. {
  2167. uId = g.Key,
  2168. name = g.ToList().FirstOrDefault()?.CreateUserName ?? "-",
  2169. msgTips = $"本年有{g.Count()}条未审核日常付款申请条",
  2170. userTourGuideData = g.ToList(),
  2171. Count = g.Count()
  2172. });
  2173. var dailyPaymentData1 = new
  2174. {
  2175. msgTips = $"本年有{dailyPaymentData.Count()}条未审核日常付款申请条",
  2176. Data = dailyPaymentGroups,
  2177. };
  2178. #endregion
  2179. #region 团组费用未审核数据
  2180. var groupPaymentData = await _sqlSugar.Queryable<Grp_CreditCardPayment>()
  2181. .LeftJoin<Grp_DelegationInfo>((ccp, di) => ccp.DIId == di.Id)
  2182. .Where((ccp, di) => ccp.IsDel == 0 &&
  2183. ccp.IsAuditGM == 0 &&
  2184. ccp.CreateTime >= currStartDate &&
  2185. ccp.CreateTime <= currEntDate
  2186. )
  2187. .Select((ccp, di) => new
  2188. {
  2189. ccp.Id,
  2190. ccp.DIId,
  2191. GroupName = di.TeamName,
  2192. ccp.CreateTime,
  2193. })
  2194. .ToListAsync();
  2195. var groupPaymentGroups = groupPaymentData.GroupBy(x => x.DIId)
  2196. .Select(g => new
  2197. {
  2198. uId = g.Key,
  2199. name = g.ToList().FirstOrDefault()?.GroupName ?? "-",
  2200. msgTips = $"本年有{g.Count()}条未审核团组费用申请条",
  2201. userTourGuideData = g.ToList(),
  2202. Count = g.Count()
  2203. });
  2204. var groupPaymentData1 = new
  2205. {
  2206. msgTips = $"本年有{groupPaymentData.Count()}条未审核团组费用申请条",
  2207. Data = groupPaymentGroups,
  2208. };
  2209. #endregion
  2210. var feeUnAuditData = new
  2211. {
  2212. dailyPaymentData = dailyPaymentData1,
  2213. groupPaymentData = groupPaymentData1
  2214. };
  2215. return Ok(JsonView(new { materialData = materialData, feeUnAuditData = feeUnAuditData }));
  2216. }
  2217. else if (department.Equals("国交部"))//国交部
  2218. {
  2219. #region 团组费用录入提示
  2220. /*
  2221. * 名称:团组费用录入提示
  2222. * 描述:团组费用录入提醒(根据团组结束时间 - 3天 如果对应的数据表里没有这个团组的费用信息)
  2223. * 条件:时间范围不限制、 根据团组结束时间 - 3天 == 当前天数
  2224. */
  2225. var groupModlue = new List<int>() {
  2226. 76, //酒店预订
  2227. 79, //车/导游地接
  2228. 80, //签证
  2229. 81, //邀请/公务活动
  2230. //82, //团组客户保险
  2231. 85, //机票预订
  2232. 98, //其他款项
  2233. //285 ,//收款退还
  2234. //1015,//超支费用
  2235. };
  2236. var crrDate = DateTime.Now.ToString("yyyy-MM-dd");
  2237. var groupModlueData = await _sqlSugar.Queryable<Sys_SetData>().Where(x => groupModlue.Contains(x.Id)).ToListAsync();
  2238. var groupFeeData = await _sqlSugar.Queryable<Sys_SetData>()
  2239. .LeftJoin<Grp_CreditCardPayment>((sd, ccp) => sd.Id == ccp.CTable)
  2240. .LeftJoin<Grp_DelegationInfo>((sd, ccp, di) => ccp.DIId == di.Id)
  2241. .Where((sd, ccp, di) => ccp.IsDel == 0 &&
  2242. di.IsDel == 0 &&
  2243. groupModlue.Contains(ccp.CTable) &&
  2244. di.VisitEndDate.AddDays(-3).ToString("yyyy-MM-dd").Equals(crrDate)
  2245. )
  2246. .GroupBy((sd, ccp, di) => new { di.Id, di.TeamName, ccp.CTable, sd.Name }) //可以多字段
  2247. .Select((sd, ccp, di) => new {
  2248. diId = di.Id,
  2249. groupName = di.TeamName,
  2250. groupType = ccp.CTable,
  2251. groupTypeName = sd.Name,
  2252. //userId = ccp.CreateUserId,
  2253. count = SqlFunc.AggregateCount(ccp.CTable),
  2254. })
  2255. .ToListAsync();
  2256. var groupFeeData1 = groupFeeData.GroupBy(x => x.diId);
  2257. var groupNotFilledFeeData = new List<dynamic>();
  2258. foreach (var groupFee in groupFeeData1)
  2259. {
  2260. var diId = groupFee.Key;
  2261. var addData = groupFeeData.Where(x => x.diId == diId).Select(x => x.groupType).ToList();
  2262. if (addData.Count < 1) continue;
  2263. var unAddData = groupModlue.Except(addData).ToList();
  2264. if (unAddData.Count < 1) continue;
  2265. foreach (var typeId in unAddData)
  2266. {
  2267. groupNotFilledFeeData.Add(new
  2268. {
  2269. diId = diId,
  2270. groupName = groupFee.FirstOrDefault()?.groupName ?? "-",
  2271. groupType = typeId,
  2272. groupTypeName = groupModlueData.Find(x => x.Id == typeId)?.Name ?? "-",
  2273. count = 0
  2274. });
  2275. }
  2276. }
  2277. #endregion
  2278. #region 日付申请 -- 未审核数据
  2279. var depUserData = await _sqlSugar.Queryable<Sys_Users>()
  2280. .LeftJoin<Sys_Department>((u, d) => u.DepId == d.Id)
  2281. .LeftJoin<Sys_JobPost>((u, d, jp) => u.JobPostId == jp.Id)
  2282. .Where((u, d, jp) => u.IsDel == 0 && d.DepName.Contains("国交部"))
  2283. .Select((u, d, jp) => new
  2284. {
  2285. u.Id,
  2286. u.CnName,
  2287. u.DepId,
  2288. d.DepName,
  2289. u.JobPostId,
  2290. jp.JobName
  2291. })
  2292. .ToListAsync();
  2293. var depUserData1 = depUserData.Select(x => x.Id).ToList();
  2294. var unAuditDailyFeeData = await _sqlSugar.Queryable<Fin_DailyFeePayment>()
  2295. .LeftJoin<Sys_Users>((dfp, u) => dfp.CreateUserId == u.Id)
  2296. .Where((dfp, u) => dfp.IsDel == 0 &&
  2297. depUserData1.Contains(dfp.CreateUserId) &&
  2298. dfp.MAudit == 0 &&
  2299. dfp.CreateTime >= currStartDate &&
  2300. dfp.CreateTime <= currEntDate
  2301. )
  2302. .Select((dfp, u) => new
  2303. {
  2304. id = dfp.Id,
  2305. amountName = dfp.Instructions,
  2306. amount = dfp.SumPrice,
  2307. fAuditStatus = dfp.FAudit == 1 ? "审核通过" :
  2308. dfp.FAudit == 2 ? "审核未通过" : "未审核",
  2309. fAuditDate = dfp.FAuditDate,
  2310. dfp.CreateUserId,
  2311. CreateUserName = u.CnName,
  2312. dfp.CreateTime
  2313. })
  2314. .ToArrayAsync();
  2315. #endregion
  2316. var jobs = new List<string>() { "经理", "主管" };
  2317. if (jobs.Contains( currUserInfo.Role)) //经理、主管
  2318. {
  2319. #region 经理、主管
  2320. //经理、主管(部门下所有人员) --> 日付(-:未审核提示)、团组费用录入提醒(根据团组结束时间-3天 如果对应的数据表里没有这个团组的费用信息)
  2321. var dailyPaymentData = new
  2322. {
  2323. msgTips = $"本年有{unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2324. Data = new
  2325. {
  2326. uId = currUserInfo.UserId,
  2327. name = currUserInfo.UserName,
  2328. msgTips = $"本年有{unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2329. userTourGuideData = unAuditDailyFeeData,
  2330. Count = unAuditDailyFeeData.Count()
  2331. }
  2332. };
  2333. var groupNotFilledFeeDataAll = groupNotFilledFeeData
  2334. .GroupBy(x => x.diId)
  2335. .Select(g => new
  2336. {
  2337. uId = g.Key,
  2338. name = g.ToList().FirstOrDefault()?.groupName ?? "-",
  2339. msgTips = $"-",
  2340. hotelFeeData = g.Select(x1 => new
  2341. {
  2342. x1.groupType,
  2343. x1.groupTypeName
  2344. }).ToList(),
  2345. Count = g.Count()
  2346. })
  2347. .ToList();
  2348. var groupNotFillEdFeeData1 = new
  2349. {
  2350. msgTips = $"今天有{groupNotFilledFeeDataAll.Count()}个团组费用未填写",
  2351. Data = groupNotFilledFeeDataAll,
  2352. };
  2353. #endregion
  2354. return Ok(JsonView(new { groupNotFillEdFeeData = groupNotFillEdFeeData1, dailyPaymentData = dailyPaymentData }));
  2355. }
  2356. else if (currUserInfo.Role.Equals("计调"))//计调
  2357. {
  2358. #region 计调
  2359. //计调(myself) --> 暂定
  2360. return Ok(JsonView(false, "国交部-->计调岗位消息提示正在开发中......"));
  2361. #endregion
  2362. }
  2363. else if (currUserInfo.Role.Equals("机票"))//机票
  2364. {
  2365. #region 机票
  2366. //机票(myself) --> 日付(-:未审核提示)、机票费用(-:未录入提示)
  2367. var airTicket_unAuditDailyFeeData = unAuditDailyFeeData.Where(x => x.CreateUserId == currUserInfo.UserId).ToList();
  2368. var dailyPaymentData = new
  2369. {
  2370. msgTips = $"本年有{airTicket_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2371. Data = new
  2372. {
  2373. uId = currUserInfo.UserId,
  2374. name = currUserInfo.UserName,
  2375. msgTips = $"本年有{airTicket_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2376. userTourGuideData = airTicket_unAuditDailyFeeData,
  2377. Count = airTicket_unAuditDailyFeeData.Count()
  2378. }
  2379. };
  2380. var airTicket_groupNotFilledData = groupNotFilledFeeData
  2381. .Where(x => x.groupType == 85)
  2382. .GroupBy(x => x.diId)
  2383. .Select(g => new
  2384. {
  2385. uId = g.Key,
  2386. name = g.ToList().FirstOrDefault()?.groupName ?? "-",
  2387. msgTips = $"-",
  2388. airTicketFeeData = g.Select(x1 => new
  2389. {
  2390. x1.groupType,
  2391. x1.groupTypeName
  2392. }).ToList(),
  2393. Count = g.Count()
  2394. })
  2395. .ToList();
  2396. var groupNotFillEdFeeData1 = new
  2397. {
  2398. msgTips = $"今天有{airTicket_groupNotFilledData.Count()}个团组费用未填写",
  2399. Data = airTicket_groupNotFilledData,
  2400. };
  2401. #endregion
  2402. return Ok(JsonView(new { groupNotFillEdFeeData = groupNotFillEdFeeData1, dailyPaymentData = dailyPaymentData }));
  2403. }
  2404. else if (currUserInfo.Role.Equals("酒店"))//酒店
  2405. {
  2406. #region 酒店
  2407. //酒店(myself) --> 日付(-:未审核提示)、酒店费用(-:未录入提示)
  2408. var hotle_unAuditDailyFeeData = unAuditDailyFeeData.Where(x => x.CreateUserId == currUserInfo.UserId).ToList();
  2409. var dailyPaymentData = new
  2410. {
  2411. msgTips = $"本年有{hotle_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2412. Data = new
  2413. {
  2414. uId = currUserInfo.UserId,
  2415. name = currUserInfo.UserName,
  2416. msgTips = $"本年有{hotle_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2417. hotelFeeData = hotle_unAuditDailyFeeData,
  2418. Count = hotle_unAuditDailyFeeData.Count()
  2419. }
  2420. };
  2421. var hotel_groupNotFilledData = groupNotFilledFeeData
  2422. .Where(x => x.groupType == 76)
  2423. .GroupBy(x => x.diId)
  2424. .Select(g => new
  2425. {
  2426. uId = g.Key,
  2427. name = g.ToList().FirstOrDefault()?.groupName ?? "-",
  2428. msgTips = $"-",
  2429. hotelFeeData = g.Select(x1 => new
  2430. {
  2431. x1.groupType,
  2432. x1.groupTypeName
  2433. }).ToList(),
  2434. Count = g.Count()
  2435. })
  2436. .ToList();
  2437. var groupNotFillEdFeeData1 = new
  2438. {
  2439. msgTips = $"今天有{hotel_groupNotFilledData.Count()}个团组费用未填写",
  2440. Data = hotel_groupNotFilledData,
  2441. };
  2442. #endregion
  2443. return Ok(JsonView(new { groupNotFillEdFeeData = groupNotFillEdFeeData1, dailyPaymentData = dailyPaymentData }));
  2444. }
  2445. else if (currUserInfo.Role.Equals("签证"))//签证
  2446. {
  2447. #region 签证
  2448. //签证(myself) --> 日付(-:未审核提示)、签证费用(-:未录入提示)
  2449. var visa_unAuditDailyFeeData = unAuditDailyFeeData.Where(x => x.CreateUserId == currUserInfo.UserId).ToList();
  2450. var dailyPaymentData = new
  2451. {
  2452. msgTips = $"本年有{visa_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2453. Data = new
  2454. {
  2455. uId = currUserInfo.UserId,
  2456. name = currUserInfo.UserName,
  2457. msgTips = $"本年有{visa_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2458. visaFeeData = visa_unAuditDailyFeeData,
  2459. Count = visa_unAuditDailyFeeData.Count()
  2460. }
  2461. };
  2462. var visa_groupNotFilledData = groupNotFilledFeeData
  2463. .Where(x => x.groupType == 80)
  2464. .GroupBy(x => x.diId)
  2465. .Select(g => new
  2466. {
  2467. uId = g.Key,
  2468. name = g.ToList().FirstOrDefault()?.groupName ?? "-",
  2469. msgTips = $"-",
  2470. airTicketFeeData = g.Select(x1 => new
  2471. {
  2472. x1.groupType,
  2473. x1.groupTypeName
  2474. }).ToList(),
  2475. Count = g.Count()
  2476. })
  2477. .ToList();
  2478. var groupNotFillEdFeeData1 = new
  2479. {
  2480. msgTips = $"今天有{visa_groupNotFilledData.Count()}个团组费用未填写",
  2481. Data = visa_groupNotFilledData,
  2482. };
  2483. #endregion
  2484. return Ok(JsonView(new { groupNotFillEdFeeData = groupNotFillEdFeeData1, dailyPaymentData = dailyPaymentData }));
  2485. }
  2486. else if (currUserInfo.Role.Equals("商邀"))//商邀
  2487. {
  2488. #region 商邀
  2489. //商邀(myself) --> 日付(-:未审核提示)、商邀费用(-:未录入提示)、(公务、翻译人)(-:新增提示)
  2490. //日付
  2491. var in_unAuditDailyFeeData = unAuditDailyFeeData.Where(x => x.CreateUserId == currUserInfo.UserId).ToList();
  2492. var dailyPaymentData = new
  2493. {
  2494. msgTips = $"本年有{in_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2495. Data = new
  2496. {
  2497. uId = currUserInfo.UserId,
  2498. name = currUserInfo.UserName,
  2499. msgTips = $"本年有{in_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2500. visaFeeData = in_unAuditDailyFeeData,
  2501. Count = in_unAuditDailyFeeData.Count()
  2502. }
  2503. };
  2504. //团组未录入费用
  2505. var in_groupNotFilledData = groupNotFilledFeeData
  2506. .Where(x => x.groupType == 81)
  2507. .GroupBy(x => x.diId)
  2508. .Select(g => new
  2509. {
  2510. uId = g.Key,
  2511. name = g.ToList().FirstOrDefault()?.groupName ?? "-",
  2512. msgTips = $"-",
  2513. airTicketFeeData = g.Select(x1 => new
  2514. {
  2515. x1.groupType,
  2516. x1.groupTypeName
  2517. }).ToList(),
  2518. Count = g.Count()
  2519. })
  2520. .ToList();
  2521. var groupNotFillEdFeeData1 = new
  2522. {
  2523. msgTips = $"今天有{in_groupNotFilledData.Count()}个团组费用未填写",
  2524. Data = in_groupNotFilledData,
  2525. };
  2526. //商邀 - 基础数据
  2527. var invitationData = await _sqlSugar.Queryable<Res_InvitationOfficialActivityData>()
  2528. .LeftJoin<Sys_Users>((ioa, u) => ioa.CreateUserId == u.Id)
  2529. .Where((ioa, u) => ioa.IsDel == 0 && ioa.CreateTime >= startDateTime && ioa.CreateTime <= endDateTime)
  2530. .Select((ioa, u) => new
  2531. {
  2532. //Area = string.Format("{0}{1}", ioa.Country, !string.IsNullOrEmpty(ioa.City) ? "" : "-" + ioa.City),
  2533. Area = string.Format("{0}{1}", ioa.Country, ioa.City),
  2534. Client = ioa.UnitName,
  2535. ioa.Contact,
  2536. ioa.Job,
  2537. ioa.Tel,
  2538. ioa.CreateUserId,
  2539. CreatleUserName = u.CnName,
  2540. ioa.CreateTime,
  2541. })
  2542. .ToListAsync();
  2543. var invitationGroups = invitationData.GroupBy(x => x.CreateUserId)
  2544. .Select(g => new {
  2545. uId = g.Key,
  2546. name = g.ToList().FirstOrDefault()?.CreatleUserName ?? "-",
  2547. msgTips = $"上月新增商邀资源共{g.Count()}条",
  2548. userTourGuideData = g.ToList(),
  2549. Count = g.Count()
  2550. });
  2551. var invitationData1 = new
  2552. {
  2553. msgTips = $"上月新增商邀资源共{invitationData.Count}条",
  2554. Data = invitationGroups,
  2555. };
  2556. #endregion
  2557. return Ok(JsonView(new { groupNotFillEdFeeData = groupNotFillEdFeeData1, dailyPaymentData = dailyPaymentData, invitationData = invitationData }));
  2558. }
  2559. else if (currUserInfo.Role.Equals("OP"))//OP
  2560. {
  2561. #region OP
  2562. //OP(myself) --> 日付(-:未审核提示)、OP费用(-:未录入提示)、(导游、车)资源信息(-:新增提示)
  2563. //日付
  2564. var in_unAuditDailyFeeData = unAuditDailyFeeData.Where(x => x.CreateUserId == currUserInfo.UserId).ToList();
  2565. var dailyPaymentData = new
  2566. {
  2567. msgTips = $"本年有{in_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2568. Data = new
  2569. {
  2570. uId = currUserInfo.UserId,
  2571. name = currUserInfo.UserName,
  2572. msgTips = $"本年有{in_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2573. visaFeeData = in_unAuditDailyFeeData,
  2574. Count = in_unAuditDailyFeeData.Count()
  2575. }
  2576. };
  2577. //OP - 团组未录入费用
  2578. var in_groupNotFilledData = groupNotFilledFeeData
  2579. .Where(x => x.groupType == 79)
  2580. .GroupBy(x => x.diId)
  2581. .Select(g => new
  2582. {
  2583. uId = g.Key,
  2584. name = g.ToList().FirstOrDefault()?.groupName ?? "-",
  2585. msgTips = $"-",
  2586. airTicketFeeData = g.Select(x1 => new
  2587. {
  2588. x1.groupType,
  2589. x1.groupTypeName
  2590. }).ToList(),
  2591. Count = g.Count()
  2592. })
  2593. .ToList();
  2594. var groupNotFillEdFeeData1 = new
  2595. {
  2596. msgTips = $"今天有{in_groupNotFilledData.Count()}个团组费用未填写",
  2597. Data = in_groupNotFilledData,
  2598. };
  2599. #region op地接导游
  2600. //1.2 op地接导游
  2601. var opTourGuideData = await _sqlSugar.Queryable<Res_LocalGuideData>()
  2602. .LeftJoin<Sys_Users>((lgd, u) => lgd.CreateUserId == u.Id)
  2603. .Where((lgd, u) => lgd.IsDel == 0 && lgd.CreateTime >= startDateTime && lgd.CreateTime <= endDateTime)
  2604. .Select((lgd, u) => new
  2605. {
  2606. Area = lgd.UnitArea,
  2607. Client = lgd.UnitName,
  2608. lgd.Contact,
  2609. Job = "",
  2610. Tel = lgd.ContactTel,
  2611. lgd.CreateUserId,
  2612. CreatleUserName = u.CnName,
  2613. lgd.CreateTime,
  2614. })
  2615. .ToListAsync();
  2616. foreach (var item in opTourGuideData) EncryptionProcessor.DecryptProperties(item);
  2617. var opTourGuideDataGroups = opTourGuideData.GroupBy(x => x.CreateUserId)
  2618. .Select(g => new {
  2619. uId = g.Key,
  2620. name = g.ToList().FirstOrDefault()?.CreatleUserName ?? "-",
  2621. msgTips = $"上月新增OP地接导游资源共{g.Count()}条",
  2622. userTourGuideData = g.ToList(),
  2623. Count = g.Count()
  2624. });
  2625. var opTourGuideData1 = new
  2626. {
  2627. msgTips = $"上月新增OP地接导游资源共{opTourGuideData.Count}条",
  2628. Data = opTourGuideDataGroups,
  2629. };
  2630. #endregion
  2631. #region op车数据
  2632. //1.3 op车数据
  2633. var opCarData = await _sqlSugar.Queryable<Res_CarData>()
  2634. .LeftJoin<Sys_Users>((cd, u) => cd.CreateUserId == u.Id)
  2635. .Where((cd, u) => cd.IsDel == 0 && cd.CreateTime >= startDateTime && cd.CreateTime <= endDateTime)
  2636. .Select((cd, u) => new
  2637. {
  2638. Area = cd.UnitArea,
  2639. Client = cd.UnitName,
  2640. cd.Contact,
  2641. Job = "",
  2642. Tel = cd.ContactTel,
  2643. cd.CreateUserId,
  2644. CreatleUserName = u.CnName,
  2645. cd.CreateTime,
  2646. })
  2647. .ToListAsync();
  2648. var opCarDataGroups = opCarData.GroupBy(x => x.CreateUserId)
  2649. .Select(g => new {
  2650. uId = g.Key,
  2651. name = g.ToList().FirstOrDefault()?.CreatleUserName ?? "-",
  2652. msgTips = $"上月新增OP地接车资源共{g.Count()}条",
  2653. userTourGuideData = g.ToList(),
  2654. Count = g.Count()
  2655. });
  2656. var opCarData1 = new
  2657. {
  2658. msgTips = $"上月新增OP地接车资源共{opCarData.Count}条",
  2659. Data = opCarDataGroups,
  2660. };
  2661. #endregion
  2662. #endregion
  2663. return Ok(JsonView(new
  2664. {
  2665. groupNotFillEdFeeData = groupNotFillEdFeeData1,
  2666. dailyPaymentData = dailyPaymentData,
  2667. CarData = opCarData1,
  2668. TourGuideData = opTourGuideData
  2669. }));
  2670. }
  2671. return Ok(JsonView(false, "国交部消息提示正在开发中......"));
  2672. }
  2673. else if (department.Equals("财务部"))//总经办
  2674. {
  2675. #region 团组收款数据
  2676. var groupCollectionData = await _sqlSugar.Queryable<Fin_ForeignReceivables>()
  2677. .LeftJoin<Sys_Users>((fr, u) => fr.CreateUserId == u.Id)
  2678. .LeftJoin<Grp_DelegationInfo>((fr, u, di) => fr.Diid == di.Id)
  2679. .LeftJoin<Sys_SetData>((fr, u, di, sd) => fr.Currency == sd.Id)
  2680. .Where((fr, u, di, sd) => fr.IsDel == 0 && fr.CreateTime >= startDateTime && fr.CreateTime <= endDateTime)
  2681. .Select((fr, u, di, sd) => new
  2682. {
  2683. fr.PriceName,
  2684. fr.Price,
  2685. fr.Count,
  2686. fr.Unit,
  2687. fr.ItemSumPrice,
  2688. Currency = sd.Name,
  2689. GroupName = di.TeamName,
  2690. fr.CreateUserId,
  2691. CreateUserName = u.CnName,
  2692. fr.CreateTime,
  2693. })
  2694. .ToListAsync();
  2695. var groupCollectionGroups = groupCollectionData.GroupBy(x => x.CreateUserId)
  2696. .Select(g => new
  2697. {
  2698. uId = g.Key,
  2699. name = g.ToList().FirstOrDefault()?.CreateUserName ?? "-",
  2700. msgTips = $"上月累计团组收款共{g.Count()}条",
  2701. userTourGuideData = g.ToList(),
  2702. Count = g.Count()
  2703. });
  2704. var groupCollectionData1 = new
  2705. {
  2706. msgTips = $"上月累计团组收款共{groupCollectionData.Count}条",
  2707. Data = groupCollectionGroups,
  2708. };
  2709. #endregion
  2710. #region 日付申请未审核数据
  2711. var dailyPaymentData = await _sqlSugar.Queryable<Fin_DailyFeePayment>()
  2712. .LeftJoin<Sys_Users>((dfp, u) => dfp.CreateUserId == u.Id)
  2713. .Where(dfp => dfp.IsDel == 0 &&
  2714. dfp.MAudit == 0 &&
  2715. dfp.CreateTime >= currStartDate &&
  2716. dfp.CreateTime <= currEntDate
  2717. )
  2718. .OrderBy(dfp => dfp.CreateTime, OrderByType.Desc)
  2719. //.OrderBy(dfp => dfp.FAudit, OrderByType.Desc)
  2720. .Select((dfp, u) => new
  2721. {
  2722. id = dfp.Id,
  2723. amountName = dfp.Instructions,
  2724. amount = dfp.SumPrice,
  2725. fAuditStatus = dfp.FAudit == 1 ? "审核通过" :
  2726. dfp.FAudit == 2 ? "审核未通过" : "未审核",
  2727. fAuditDate = dfp.FAuditDate,
  2728. dfp.CreateUserId,
  2729. CreateUserName = u.CnName,
  2730. dfp.CreateTime
  2731. })
  2732. .ToListAsync();
  2733. var dailyPaymentGroups = dailyPaymentData.GroupBy(x => x.CreateUserId)
  2734. .Select(g => new
  2735. {
  2736. uId = g.Key,
  2737. name = g.ToList().FirstOrDefault()?.CreateUserName ?? "-",
  2738. msgTips = $"本年有{g.Count()}条未审核日常付款申请条",
  2739. userTourGuideData = g.ToList(),
  2740. Count = g.Count()
  2741. });
  2742. var dailyPaymentData1 = new
  2743. {
  2744. msgTips = $"本年有{dailyPaymentData.Count()}条未审核日常付款申请条",
  2745. Data = dailyPaymentGroups,
  2746. };
  2747. #endregion
  2748. return Ok(JsonView(new { groupCollectionData = groupCollectionData1, dailyPaymentData = dailyPaymentData1 }));
  2749. }
  2750. return Ok(JsonView(false,"其余部门消息提示正在开发者中......"));
  2751. }
  2752. return Ok(JsonView(false));
  2753. }
  2754. #endregion
  2755. }
  2756. }