SystemController.cs 127 KB

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