SystemController.cs 129 KB

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