SystemController.cs 127 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052
  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, "请检查信息是否输入完整!", string.Empty));
  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. }
  811. }
  812. #endregion
  813. #region 岗位板块
  814. /// <summary>
  815. /// 岗位查询
  816. /// </summary>
  817. /// <param name="dto"></param>
  818. /// <returns></returns>
  819. [HttpPost]
  820. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  821. public async Task<IActionResult> QueryJobPost(QueryJobPostDto dto)
  822. {
  823. try
  824. {
  825. if (dto.PortType == 1)
  826. {
  827. string sqlWhere = string.Empty;
  828. if (dto.CompanyId != 0)
  829. {
  830. sqlWhere += string.Format(@" And jp.CompanyId={0}", dto.CompanyId);
  831. }
  832. if (dto.DepId != 0)
  833. {
  834. sqlWhere += string.Format(@" And jp.DepId={0}", dto.DepId);
  835. }
  836. sqlWhere += string.Format(@" And jp.IsDel={0}", 0);
  837. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  838. {
  839. Regex r = new Regex("And");
  840. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  841. }
  842. List<Sys_JobPostI> jobList = await _jobRep.QueryJobPost(sqlWhere);
  843. List<JobPostView> List = _mapper.Map<List<JobPostView>>(jobList);
  844. if (jobList.Count == 0)
  845. {
  846. return Ok(JsonView(false, "暂无数据!"));
  847. }
  848. return Ok(JsonView(true, "查询成功!", jobList));
  849. }
  850. else if (dto.PortType == 2)
  851. {
  852. var result = _jobRep.QueryDto<Sys_JobPost, JobPostView>(s => s.CompanyId == dto.CompanyId && s.DepId == dto.DepId).ToList();
  853. if (result.Count == 0)
  854. {
  855. return Ok(JsonView(false, "暂无数据!"));
  856. }
  857. return Ok(JsonView(true, "查询成功!", result));
  858. }
  859. else if (dto.PortType == 3)
  860. {
  861. return Ok(JsonView(false, "暂无数据!"));
  862. }
  863. else
  864. {
  865. return Ok(JsonView(false, "暂无数据!"));
  866. }
  867. }
  868. catch (Exception ex)
  869. {
  870. return Ok(JsonView(false, "程序错误!"));
  871. throw;
  872. }
  873. }
  874. /// <summary>
  875. /// 添加岗位
  876. /// </summary>
  877. /// <param name="dto"></param>
  878. /// <returns></returns>
  879. [HttpPost]
  880. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  881. public async Task<IActionResult> AddJobPost(AddJobPostDto dto)
  882. {
  883. try
  884. {
  885. Sys_JobPost sys_Job = _mapper.Map<Sys_JobPost>(dto);
  886. int id = await _jobRep.AddAsyncReturnId(sys_Job);
  887. if (id == 0)
  888. {
  889. return Ok(JsonView(false, "添加失败"));
  890. }
  891. return Ok(JsonView(true, "添加成功", new { Id = id }));
  892. }
  893. catch (Exception ex)
  894. {
  895. return Ok(JsonView(false, "程序错误!"));
  896. throw;
  897. }
  898. }
  899. /// <summary>
  900. /// 修改岗位
  901. /// </summary>
  902. /// <param name="dto"></param>
  903. /// <returns></returns>
  904. [HttpPost]
  905. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  906. public async Task<IActionResult> EditJobPost(EditJobPostDto dto)
  907. {
  908. try
  909. {
  910. bool res = await _jobRep.UpdateAsync<Sys_JobPost>(a => a.Id == dto.Id, a => new Sys_JobPost
  911. {
  912. CompanyId = dto.CompanyId,
  913. DepId = dto.DepId,
  914. JobName = dto.JobName,
  915. Remark = dto.Remark,
  916. });
  917. if (!res)
  918. {
  919. return Ok(JsonView(false, "修改失败"));
  920. }
  921. return Ok(JsonView(true, "修改成功"));
  922. }
  923. catch (Exception ex)
  924. {
  925. return Ok(JsonView(false, "程序错误!"));
  926. throw;
  927. }
  928. }
  929. /// <summary>
  930. /// 删除岗位
  931. /// </summary>
  932. /// <param name="dto"></param>
  933. /// <returns></returns>
  934. [HttpPost]
  935. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  936. public async Task<IActionResult> DelJobPost(DelJobPostDto dto)
  937. {
  938. try
  939. {
  940. bool res = await _jobRep.SoftDeleteAsync<Sys_JobPost>(dto.Id.ToString());
  941. if (!res)
  942. {
  943. return Ok(JsonView(false, "删除失败!"));
  944. }
  945. return Ok(JsonView(true, "删除成功"));
  946. }
  947. catch (Exception)
  948. {
  949. return Ok(JsonView(false, "程序错误!"));
  950. throw;
  951. }
  952. }
  953. #endregion
  954. #region 用户操作
  955. ///// <summary>
  956. ///// 用户表指定字段加密
  957. ///// </summary>
  958. ///// <param name="dto"></param>
  959. ///// <returns></returns>
  960. //[HttpPost]
  961. //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  962. //public async Task<IActionResult> UserBatchEncryption()
  963. //{
  964. // 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();
  965. // foreach (var item in items) EncryptionProcessor.EncryptProperties(item);
  966. // var updItems = await _sqlSugar.Updateable(items).UpdateColumns(x => new { x.Phone, x.UrgentPhone, x.IDCard }).ExecuteCommandAsync();
  967. // return Ok(JsonView(updItems));
  968. //}
  969. /// <summary>
  970. /// 查询所有员工名称
  971. /// </summary>
  972. /// <param name="dto"></param>
  973. /// <returns></returns>
  974. [HttpPost]
  975. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  976. public async Task<IActionResult> GetUserNameList(DtoBase dto)
  977. {
  978. var result = _userRep.GetUserNameList(dto.PortType);
  979. if (result.Result.Code != 0)
  980. {
  981. return Ok(JsonView(false, "暂无数据!"));
  982. }
  983. return Ok(JsonView(true, "查询成功!", result.Result.Data));
  984. }
  985. /// <summary>
  986. /// 查询所有员工(web)
  987. /// </summary>
  988. /// <param name="dto"></param>
  989. /// <returns></returns>
  990. [HttpPost]
  991. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  992. public async Task<IActionResult> GetUserList(DtoBase dto)
  993. {
  994. var result = _userRep.GetUserList(dto.PortType, string.Empty);
  995. if (result.Result.Code != 0)
  996. {
  997. return Ok(JsonView(false, "暂无数据!"));
  998. }
  999. return Ok(JsonView(true, "查询成功!", result.Result.Data));
  1000. }
  1001. /// <summary>
  1002. /// 查询用户数据
  1003. /// </summary>
  1004. /// <param name="dto"></param>
  1005. /// <returns></returns>
  1006. [HttpPost]
  1007. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1008. public async Task<IActionResult> QueryUserList(UserDto dto)
  1009. {
  1010. string sqlWhere = string.Format(" Where su.IsDel = 0 ");
  1011. if (dto.CompanyId != 0)
  1012. {
  1013. sqlWhere += string.Format(@" And su.CompanyId={0}", dto.CompanyId);
  1014. }
  1015. if (dto.DepId != 0)
  1016. {
  1017. sqlWhere += string.Format(@" And su.DepId={0}", dto.DepId);
  1018. }
  1019. if (dto.JobPostId != 0)
  1020. {
  1021. sqlWhere += string.Format(@" And su.JobPostId={0}", dto.JobPostId);
  1022. }
  1023. List<UserInfo> _userList = await _userRep.QueryUser(sqlWhere);
  1024. if (_userList.Count == 0)
  1025. {
  1026. return Ok(JsonView(400, "暂无数据!", new List<String>()));
  1027. }
  1028. foreach (var item in _userList) EncryptionProcessor.DecryptProperties(item);
  1029. List<UserInfoWebView> userList = _mapper.Map<List<UserInfoWebView>>(_userList);
  1030. return Ok(JsonView(true, "查询成功!", userList));
  1031. }
  1032. /// <summary>
  1033. /// 员工信息 个人详细信息
  1034. /// </summary>
  1035. /// <returns></returns>
  1036. [HttpPost]
  1037. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1038. public async Task<IActionResult> UserInfo(UserInfoDto dto)
  1039. {
  1040. if (dto.Id < 1) return Ok(JsonView(false, "请选择有效的userId!"));
  1041. if (dto.PortType < 1 || dto.PortType > 3) return Ok(JsonView(false, MsgTips.Port));
  1042. var _view = await _sqlSugar.Queryable<Sys_Users>()
  1043. .Where(x => x.IsDel == 0 && x.Id == dto.Id)
  1044. .FirstAsync();
  1045. //解密
  1046. EncryptionProcessor.DecryptProperties(_view);
  1047. var data = new
  1048. {
  1049. _view.Id,
  1050. _view.CnName,
  1051. _view.EnName,
  1052. _view.Number,
  1053. _view.CompanyId,
  1054. _view.DepId,
  1055. _view.JobPostId,
  1056. _view.Password,
  1057. _view.Sex,
  1058. _view.Ext,
  1059. _view.Phone,
  1060. _view.UrgentPhone,
  1061. _view.Email,
  1062. _view.Address,
  1063. _view.Edate,
  1064. //_view.Seniority,
  1065. _view.Birthday,
  1066. _view.IDCard,
  1067. _view.StartWorkDate,
  1068. _view.GraduateInstitutions,
  1069. _view.Professional,
  1070. _view.Education,
  1071. _view.TheOrAdultEducation,
  1072. _view.MaritalStatus,
  1073. _view.HomeAddress,
  1074. _view.UsePeriod,
  1075. _view.WorkExperience,
  1076. _view.Certificate,
  1077. //_view.QiyeChatUserId,
  1078. _view.Remark
  1079. };
  1080. return Ok(JsonView(true, "操作成功!", data));
  1081. }
  1082. /// <summary>
  1083. /// 员工信息 All信息修改
  1084. /// </summary>
  1085. /// <returns></returns>
  1086. [HttpPost]
  1087. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1088. public async Task<IActionResult> EditUserInfo(EditUserInfoDto _dto)
  1089. {
  1090. EditUserInfoDtoValidator validator = new EditUserInfoDtoValidator();
  1091. var validatorRes = await validator.ValidateAsync(_dto);
  1092. if (!validatorRes.IsValid)
  1093. {
  1094. var errors = new StringBuilder();
  1095. foreach (var error in validatorRes.Errors) errors.AppendLine(error.ErrorMessage);
  1096. return Ok(JsonView(false, errors.ToString()));
  1097. }
  1098. var userInfo = _mapper.Map<Sys_Users>(_dto);
  1099. if (_dto.CurrUserId < 1) return Ok(JsonView(false, "暂无修改权限!"));
  1100. //修改权限验证 指定人员 信息部门(4)和人事部刘一茹( 230)、赖红燕(309)
  1101. List<int> userIds = new List<int>() {
  1102. 4 ,//管理员
  1103. 5 ,//杨俊霄
  1104. 117 ,//人事审核号
  1105. 208 ,//雷怡
  1106. 230 ,//刘一茹
  1107. 233 ,//刘华举
  1108. 234 ,//蒋金辰
  1109. 235 ,//袁榕烽
  1110. 309 ,//赖红燕
  1111. };
  1112. if (!userIds.Contains(_dto.CurrUserId)) return Ok(JsonView(false, "暂无修改权限!"));
  1113. //加密
  1114. EncryptionProcessor.EncryptProperties(userInfo);
  1115. var res = await _sqlSugar.Updateable(userInfo)
  1116. .IgnoreColumns(x => new
  1117. {
  1118. x.QiyeChatUserId,
  1119. x.Rdate,
  1120. x.Seniority,
  1121. x.HrAudit,
  1122. x.CreateUserId,
  1123. x.CreateTime,
  1124. x.DeleteUserId,
  1125. x.DeleteTime,
  1126. x.IsDel
  1127. })
  1128. .Where(x => x.Id == _dto.Id)
  1129. .ExecuteCommandAsync();
  1130. if (res > 0) return Ok(JsonView(true, "操作成功!"));
  1131. return Ok(JsonView(false, "操作失败!"));
  1132. }
  1133. /// <summary>
  1134. /// 修改用户信息(上级修改/分配 公司、部门、岗位、工号等信息)
  1135. /// </summary>
  1136. /// <param name="dto"></param>
  1137. /// <returns></returns>
  1138. [HttpPost]
  1139. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1140. public async Task<IActionResult> EditUser(EditUserDto dto)
  1141. {
  1142. if (dto.CurrUserId < 1) return Ok(JsonView(false, "暂无修改权限!"));
  1143. //修改权限验证 指定人员 信息部门(4)和人事部刘一茹( 230)、赖红燕(309)
  1144. var userIds = new List<int>() {
  1145. 4 ,//管理员
  1146. 5 ,//杨俊霄
  1147. 117 ,//人事审核号
  1148. 208 ,//雷怡
  1149. 230 ,//刘一茹
  1150. 233 ,//刘华举
  1151. 234 ,//蒋金辰
  1152. 235 ,//袁榕烽
  1153. 309 ,//赖红燕
  1154. };
  1155. if (!userIds.Contains(dto.CurrUserId)) return Ok(JsonView(false, "暂无修改权限!"));
  1156. bool res = await _userRep.UpdateAsync<Sys_Users>(a => a.Id == dto.Id, a => new Sys_Users
  1157. {
  1158. Number = dto.Number,
  1159. CompanyId = dto.CompanyId,
  1160. DepId = dto.DepId,
  1161. JobPostId = dto.JobPostId,
  1162. Ext = dto.Ext,
  1163. UsePeriod = dto.UsePeriod,
  1164. //HrAudit = dto.HrAudit
  1165. });
  1166. if (!res)
  1167. {
  1168. return Ok(JsonView(false, "修改失败!"));
  1169. }
  1170. return Ok(JsonView(true, "修改成功!"));
  1171. }
  1172. /// <summary>
  1173. /// 修改用户信息(登录用户修改个人信息)
  1174. /// </summary>
  1175. /// <param name="dto"></param>
  1176. /// <returns></returns>
  1177. [HttpPost]
  1178. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1179. public async Task<IActionResult> EditMyUser(EditMyUserDto dto)
  1180. {
  1181. if (string.IsNullOrWhiteSpace(dto.CnName) ||
  1182. string.IsNullOrWhiteSpace(dto.Address) ||
  1183. string.IsNullOrWhiteSpace(dto.IDCard) ||
  1184. dto.Sex != 0 && dto.Sex != 1 ||
  1185. string.IsNullOrWhiteSpace(dto.MaritalStatus) ||
  1186. string.IsNullOrWhiteSpace(dto.HomeAddress) ||
  1187. dto.Birthday >= DateTime.Now.AddYears(-1))
  1188. {
  1189. return Ok(JsonView(false, "请完善你的个人信息!"));
  1190. }
  1191. else if (string.IsNullOrWhiteSpace(dto.GraduateInstitutions) ||
  1192. string.IsNullOrWhiteSpace(dto.Professional) ||
  1193. dto.Education == 0 ||
  1194. string.IsNullOrWhiteSpace(dto.GraduateInstitutions))
  1195. {
  1196. return Ok(JsonView(false, "请完善你的学历信息!"));
  1197. }
  1198. else if (string.IsNullOrWhiteSpace(dto.Phone) ||
  1199. string.IsNullOrWhiteSpace(dto.UrgentPhone) ||
  1200. string.IsNullOrWhiteSpace(dto.Email))
  1201. {
  1202. return Ok(JsonView(false, "请检查联系方式、紧急联系人及邮箱输写是否正确!"));
  1203. }
  1204. else
  1205. {
  1206. //指定字段加密
  1207. var phone = AesEncryptionHelper.Encrypt(dto.Phone);
  1208. var urgentPhone = AesEncryptionHelper.Encrypt(dto.UrgentPhone);
  1209. var IDCard = AesEncryptionHelper.Encrypt(dto.IDCard);
  1210. bool res = await _userRep.UpdateAsync<Sys_Users>(a => a.Id == dto.Id, a => new Sys_Users
  1211. {
  1212. CnName = dto.CnName,
  1213. EnName = dto.EnName,
  1214. Sex = dto.Sex,
  1215. Phone = phone,
  1216. UrgentPhone = urgentPhone,
  1217. Email = dto.Email,
  1218. Address = dto.Address,
  1219. Edate = dto.Edate,
  1220. Birthday = dto.Birthday,
  1221. IDCard = IDCard,
  1222. GraduateInstitutions = dto.GraduateInstitutions,
  1223. Professional = dto.Professional,
  1224. Education = dto.Education,
  1225. TheOrAdultEducation = dto.TheOrAdultEducation,
  1226. MaritalStatus = dto.MaritalStatus,
  1227. HomeAddress = dto.HomeAddress,
  1228. WorkExperience = dto.WorkExperience,
  1229. Certificate = dto.Certificate
  1230. });
  1231. if (!res)
  1232. {
  1233. return Ok(JsonView(false, "修改失败!"));
  1234. }
  1235. return Ok(JsonView(true, "修改成功!"));
  1236. }
  1237. }
  1238. /// <summary>
  1239. /// 删除用户信息
  1240. /// 即为离职
  1241. /// </summary>
  1242. /// <param name="dto"></param>
  1243. /// <returns></returns>
  1244. [HttpPost]
  1245. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1246. public async Task<IActionResult> PostUserDelById(UserDelDto dto)
  1247. {
  1248. if (dto == null)
  1249. {
  1250. return Ok(JsonView(false, "参数不能为空!"));
  1251. }
  1252. var _Users = _sqlSugar.Queryable<Sys_Users>().First(a => a.IsDel == 0 && a.Id == dto.Id);
  1253. if (_Users != null)
  1254. {
  1255. var sys_UsersList = _sqlSugar.Queryable<Sys_Users>().Where(a => a.IsDel == 0 && a.CompanyId == _Users.CompanyId).ToList();
  1256. if (sys_UsersList.Count == 1)
  1257. {
  1258. return Ok(JsonView(false, "该人员为公司最后一位,不可删除!"));
  1259. }
  1260. }
  1261. bool res = await _userRep.UpdateAsync<Sys_Users>(a => a.Id == dto.Id, a => new Sys_Users
  1262. {
  1263. IsDel = 1,
  1264. DeleteUserId = dto.OperateUserId,
  1265. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  1266. Rdate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  1267. });
  1268. if (!res)
  1269. {
  1270. return Ok(JsonView(false, "操作失败!"));
  1271. }
  1272. return Ok(JsonView(true, "操作成功!"));
  1273. }
  1274. /// <summary>
  1275. /// 员工信息
  1276. /// 人事审核
  1277. /// </summary>
  1278. /// <param name="dto"></param>
  1279. /// <returns></returns>
  1280. [HttpPost]
  1281. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1282. public async Task<IActionResult> PersonnelAudit(PersonnelAuditDto dto)
  1283. {
  1284. if (dto.UserId < 1) return Ok(JsonView(false, "请传入有效的UserId参数!"));
  1285. if (dto.Id < 1) return Ok(JsonView(false, "请传入有效的Id参数!"));
  1286. if (dto.IsAudit < 1 || dto.IsAudit > 2) return Ok(JsonView(false, "请传入有效的IsAudit参数!1:通过 2拒绝"));
  1287. bool res = await _userRep.UpdateAsync<Sys_Users>(a => a.Id == dto.Id, a => new Sys_Users { HrAudit = dto.IsAudit });
  1288. if (res)
  1289. {
  1290. //审核成功添加员工基础页面权限
  1291. var userData = _sqlSugar.Queryable<Sys_Users>().Where(it => it.Id == dto.Id).First();
  1292. int depId = 0, postId = 0;
  1293. if (userData != null) { depId = userData.DepId; postId = userData.JobPostId; }
  1294. bool s = DefaultPostAuth(depId, postId, dto.Id, dto.UserId);
  1295. string str = $"基础页面权限添加失败!";
  1296. if (s) str = $"基础页面权限添加成功!";
  1297. return Ok(JsonView(true, $"操作成功!{str}"));
  1298. }
  1299. return Ok(JsonView(false, "操作失败!"));
  1300. }
  1301. /// <summary>
  1302. /// 部门查询员工
  1303. /// </summary>
  1304. /// <param name="dto"></param>
  1305. /// <returns></returns>
  1306. [HttpPost]
  1307. public IActionResult QueryUserByDepart(QueryUserByDepartDto dto)
  1308. {
  1309. var jw = JsonView(false);
  1310. if (dto.DepartId < 1)
  1311. {
  1312. jw.Msg = "请传入正确的部门id";
  1313. return Ok(jw);
  1314. }
  1315. 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} )
  1316. AND su.IsDel = 0 ";
  1317. var result = _sqlSugar.SqlQueryable<Sys_Users>(sql).Select(x => new
  1318. {
  1319. x.Id,
  1320. x.CnName,
  1321. x.EnName
  1322. }).ToList();
  1323. jw.Data = result;
  1324. jw.Code = 200;
  1325. jw.Msg = "获取成功!";
  1326. return Ok(jw);
  1327. }
  1328. #endregion
  1329. #region 权限模块
  1330. /// <summary>
  1331. /// 权限数据页面初始化
  1332. /// </summary>
  1333. /// <param name="dto"></param>
  1334. /// <returns></returns>
  1335. //[Authorize]
  1336. [HttpPost]
  1337. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1338. public async Task<IActionResult> GetAuth(AuthDto dto)
  1339. {
  1340. Result result = new Result();
  1341. //模块数据
  1342. var setDataResult = await _setDataRepository.GetSySDefultModule();
  1343. if (setDataResult.Code != 0)
  1344. {
  1345. return Ok(JsonView(setDataResult.Msg));
  1346. }
  1347. //操作方式
  1348. var PageOperation = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, Sys_PageFunctionPermission>(x => x.IsEnable == 1).ToList();
  1349. //获取所有关联页面
  1350. var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  1351. //页面数据
  1352. var SystemMenuPermissionData = _SystemMenuPermissionRepository.QueryDto<Sys_SystemMenuPermission, SystemMenuPermissionView>(x => x.Mid == dto.moduleId && x.IsEnable == 1).ToList();
  1353. if (SystemMenuPermissionData == null || SystemMenuPermissionData.Count() == 0)
  1354. {
  1355. return Ok(JsonView("暂无数据"));
  1356. }
  1357. ArrayList viewData = new ArrayList();
  1358. //组合页面数据
  1359. foreach (var item in SystemMenuPermissionData)
  1360. {
  1361. ArrayList ids = new ArrayList();
  1362. foreach (var viewop in PageOperation)
  1363. {
  1364. var op = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.SmId == item.Id && x.FId == viewop.Id);
  1365. if (op != null)
  1366. {
  1367. ids.Add(viewop.Id);
  1368. }
  1369. }
  1370. viewData.Add(new
  1371. {
  1372. Id = item.Id,
  1373. Mid = item.Mid,
  1374. Name = item.Name,
  1375. SystemMenuCode = item.SystemMenuCode,
  1376. opList = ids,
  1377. selList = new string[0]
  1378. });
  1379. }
  1380. //公司数据
  1381. var CompanyDataResult = _CompanyRepository.GetCompanyData();
  1382. if (CompanyDataResult.Code != 0)
  1383. {
  1384. return Ok(JsonView(CompanyDataResult.Msg));
  1385. }
  1386. result.Code = 0;
  1387. result.Msg = "成功!";
  1388. var Dyresult = new
  1389. {
  1390. setDataResult = setDataResult.Data,
  1391. CompanyDataResult = CompanyDataResult.Data,
  1392. SystemMenuPermissionData = viewData,
  1393. PageOperation = PageOperation,
  1394. };
  1395. return Ok(JsonView(200, "成功!", Dyresult));
  1396. }
  1397. /// <summary>
  1398. /// 获取职务权限
  1399. /// </summary>
  1400. /// <param name="dto"></param>
  1401. /// <returns></returns>
  1402. [HttpPost]
  1403. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1404. public IActionResult QueryJobAuth(QueryJobAuthDto dto)
  1405. {
  1406. //选中的操作权限
  1407. var DBdata = _JobPostAuthorityRepository.QueryDto<Sys_JobPostAuthority, JobPostAuthorityView>(x => x.JpId == dto.jobid).ToList();
  1408. var SystemMenuPermissionData = _SystemMenuPermissionRepository.QueryDto<Sys_SystemMenuPermission, SystemMenuPermissionView>(x => x.Mid == dto.moduleId).ToList();
  1409. if (SystemMenuPermissionData == null || SystemMenuPermissionData.Count() == 0)
  1410. {
  1411. return Ok(JsonView("暂无数据"));
  1412. }
  1413. //所有操作
  1414. var PageOperation = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, Sys_PageFunctionPermission>().ToList();
  1415. //获取所有关联页面
  1416. var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  1417. ArrayList viewData = new ArrayList();
  1418. //组合页面数据
  1419. foreach (var item in SystemMenuPermissionData)
  1420. {
  1421. ArrayList ids = new ArrayList();
  1422. foreach (var viewop in PageOperation)
  1423. {
  1424. var op = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.SmId == item.Id && x.FId == viewop.Id);
  1425. if (op != null)
  1426. {
  1427. ids.Add(viewop.Id);
  1428. }
  1429. }
  1430. //获取本职务的页面拥有的权限
  1431. var DBwhere = DBdata.Where(x => x.SmId == item.Id && x.JpId == dto.jobid).ToList();
  1432. viewData.Add(new
  1433. {
  1434. Id = item.Id,
  1435. Mid = item.Mid,
  1436. Name = item.Name,
  1437. SystemMenuCode = item.SystemMenuCode,
  1438. opList = ids,
  1439. selList = DBwhere.Select(x => x.FId)
  1440. });
  1441. }
  1442. return Ok(JsonView(200, "成功!", viewData));
  1443. }
  1444. /// <summary>
  1445. /// 保存岗位权限
  1446. /// </summary>
  1447. /// <param name="dto"></param>
  1448. /// <returns></returns>
  1449. [HttpPost]
  1450. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1451. public async Task<IActionResult> SaveJobAuth(SaveJobDto dto)
  1452. {
  1453. //获取所有关联页面
  1454. var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  1455. var RemoveJobPostAuthList = _SystemMenuAndFunctionRepository._sqlSugar.SqlQueryable<Sys_JobPostAuthority>($@"
  1456. select a.* from Sys_JobPostAuthority a, Sys_SetData b ,Sys_SystemMenuPermission c
  1457. where a.SmId = c.Id and c.Mid = b.Id and JpId = {dto.Jpid} and c.Mid ={dto.modulId}
  1458. ").ToList();
  1459. List<Sys_JobPostAuthority> adds = new List<Sys_JobPostAuthority>();
  1460. foreach (var item in dto.Savejobs)
  1461. {
  1462. foreach (var fid in item.FIds)
  1463. {
  1464. var whereobj = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.FId == fid && x.SmId == item.SmId);
  1465. if (whereobj != null)
  1466. {
  1467. adds.Add(new Sys_JobPostAuthority
  1468. {
  1469. CreateTime = DateTime.Now,
  1470. CreateUserId = dto.UserId,
  1471. FId = fid,
  1472. JpId = dto.Jpid,
  1473. SmId = item.SmId
  1474. });
  1475. }
  1476. }
  1477. }
  1478. _JobPostAuthorityRepository.BeginTran();
  1479. try
  1480. { //删除岗位
  1481. bool isdel = await _JobPostAuthorityRepository.DeletesAsync<Sys_JobPostAuthority>(RemoveJobPostAuthList);
  1482. int UpRows = _JobPostAuthorityRepository.Adds<Sys_JobPostAuthority>(adds);
  1483. //获取所有职位员工
  1484. var jobUserAll = await QueryUserList(new UserDto { PortType = 2, JobPostId = dto.Jpid });
  1485. List<UserInfoWebView> users = null;
  1486. var QueryUserListApiResult = (((jobUserAll as OkObjectResult).Value) as OASystem.Domain.ViewModels.JsonView);
  1487. if (QueryUserListApiResult != null)
  1488. {
  1489. if (QueryUserListApiResult.Code == 200)
  1490. {
  1491. users = QueryUserListApiResult.Data as List<UserInfoWebView>;
  1492. }
  1493. }
  1494. if (users != null && users.Count > 0)
  1495. {
  1496. List<Sys_UserAuthority> userAuth = null;
  1497. var uids = string.Join(',', users.Select(x => x.Id)).TrimEnd(',');
  1498. var RemoveUserAuthorityListAndTemp = _UserAuthorityRepository._sqlSugar.SqlQueryable<Sys_UserAuthority>($@"
  1499. select a.* from Sys_UserAuthority a, Sys_SetData b ,Sys_SystemMenuPermission c
  1500. where a.SmId = c.Id and c.Mid = b.Id and uid in ({uids}) and c.Mid = {dto.modulId} and IsTemp = 1
  1501. ").ToList();
  1502. foreach (var user in users)
  1503. {
  1504. //删除个人级岗位权限
  1505. isdel = await _UserAuthorityRepository.DeletesAsync<Sys_UserAuthority>
  1506. (RemoveUserAuthorityListAndTemp.FindAll(x => x.UId == user.Id));
  1507. userAuth = adds.Select(x => new Sys_UserAuthority
  1508. {
  1509. CreateTime = DateTime.Now,
  1510. CreateUserId = dto.UserId,
  1511. FId = x.FId,
  1512. SmId = x.SmId,
  1513. UId = user.Id,
  1514. IsTemp = 1,
  1515. }).ToList();
  1516. //添加个人级别岗位
  1517. int AddRows = _UserAuthorityRepository.Adds<Sys_UserAuthority>(userAuth);
  1518. }
  1519. }
  1520. }
  1521. catch (Exception ex)
  1522. {
  1523. _JobPostAuthorityRepository.RollbackTran();
  1524. return Ok(JsonView("系统错误!"));
  1525. }
  1526. _JobPostAuthorityRepository.CommitTran();
  1527. return Ok(JsonView(200, "成功", new { }));
  1528. }
  1529. /// <summary>
  1530. /// 获取员工权限
  1531. /// </summary>
  1532. /// <param name="dto"></param>
  1533. /// <returns></returns>
  1534. [HttpPost]
  1535. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1536. public IActionResult QueryUserAuth(QueryUserAuthDto dto)
  1537. {
  1538. //选中的员工操作权限
  1539. var DBdata = _UserAuthorityRepository.QueryDto<Sys_UserAuthority, UserAuthorityView>(x => x.UId == dto.Userid).ToList();
  1540. var SystemMenuPermissionData = _SystemMenuPermissionRepository.QueryDto<Sys_SystemMenuPermission, SystemMenuPermissionView>(x => x.Mid == dto.moduleId).ToList();
  1541. if (SystemMenuPermissionData == null || SystemMenuPermissionData.Count() == 0)
  1542. {
  1543. return Ok(JsonView("暂无数据"));
  1544. }
  1545. //所有操作
  1546. var PageOperation = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, Sys_PageFunctionPermission>(x => x.IsEnable == 1).ToList();
  1547. //获取所有关联页面
  1548. var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  1549. ArrayList viewData = new ArrayList();
  1550. //组合页面数据
  1551. foreach (var item in SystemMenuPermissionData)
  1552. {
  1553. ArrayList ids = new ArrayList();
  1554. foreach (var viewop in PageOperation)
  1555. {
  1556. var op = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.SmId == item.Id && x.FId == viewop.Id);
  1557. if (op != null)
  1558. {
  1559. ids.Add(viewop.Id);
  1560. }
  1561. }
  1562. //获取本员工拥有的权限
  1563. var DBwhere = DBdata.Where(x => x.SmId == item.Id && x.UId == dto.Userid).ToList();
  1564. viewData.Add(new
  1565. {
  1566. Id = item.Id,
  1567. Mid = item.Mid,
  1568. Name = item.Name,
  1569. SystemMenuCode = item.SystemMenuCode,
  1570. opList = ids,
  1571. selList = DBwhere.Select(x => x.FId)
  1572. });
  1573. }
  1574. return Ok(JsonView(200, "成功!", viewData));
  1575. }
  1576. /// <summary>
  1577. /// 根据Id获取员工所有移动端查看权限
  1578. /// </summary>
  1579. /// <param name="dto"></param>
  1580. /// <returns></returns>
  1581. [HttpPost]
  1582. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1583. public IActionResult QueryUserAuthByUserId(QueryUserAuthByUserIdDto dto)
  1584. {
  1585. 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)
  1586. Inner Join Sys_SystemMenuPermission as sm With(Nolock) On u.SmId = sm.Id
  1587. Inner Join Sys_SetData as sd1 With(Nolock) On sm.Mid = sd1.Id
  1588. Where u.IsDel = 0 And sm.IsDel = 0
  1589. And u.UId = {0} And u.FId = 1 ", dto.UserId);
  1590. List<SystemModule_UserAuthSqlView> _dataSource = _sqlSugar.SqlQueryable<SystemModule_UserAuthSqlView>(sql).ToList();
  1591. List<SystemModule_UserAuthView> result = new List<SystemModule_UserAuthView>();
  1592. foreach (SystemModule_UserAuthSqlView item in _dataSource)
  1593. {
  1594. if (result.FirstOrDefault(s => s.ModuleId == item.ModuleId) == null)
  1595. {
  1596. List<SystemModule_UserAuthSqlView> tempList = _dataSource.Where(s => s.ModuleId == item.ModuleId).ToList();
  1597. List<SystemMenu_UserAuthView> menuList = new List<SystemMenu_UserAuthView>();
  1598. foreach (SystemModule_UserAuthSqlView item2 in tempList)
  1599. {
  1600. SystemMenu_UserAuthView menu = new SystemMenu_UserAuthView() { MenuId = item2.MenuId, MenuName = item2.MenuName };
  1601. menuList.Add(menu);
  1602. }
  1603. SystemModule_UserAuthView module = new SystemModule_UserAuthView() { MenuList = menuList, ModuleId = item.ModuleId, ModuleName = item.ModuleName };
  1604. result.Add(module);
  1605. }
  1606. }
  1607. return Ok(JsonView(200, "成功!", result));
  1608. }
  1609. /// <summary>
  1610. /// 保存员工权限
  1611. /// </summary>
  1612. /// <param name="dto"></param>
  1613. /// <returns></returns>
  1614. [HttpPost]
  1615. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1616. public async Task<IActionResult> SaveUserAuth(SaveUserDto dto)
  1617. {
  1618. //获取所有关联页面
  1619. var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  1620. //获取用户当前模块所有启用页面
  1621. var userpageList = _SystemMenuPermissionRepository._sqlSugar.SqlQueryable<Sys_UserAuthority>($@"
  1622. select a.* from Sys_UserAuthority a, Sys_SetData b ,Sys_SystemMenuPermission c
  1623. where a.SmId = c.Id and c.Mid = b.Id and uid = {dto.uid} and c.Mid ={dto.Modulid}
  1624. ").ToList();
  1625. List<Sys_UserAuthority> adds = new List<Sys_UserAuthority>();
  1626. foreach (var item in dto.Savejobs)
  1627. {
  1628. foreach (var fid in item.FIds)
  1629. {
  1630. var whereobj = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.FId == fid && x.SmId == item.SmId);
  1631. if (whereobj != null)
  1632. {
  1633. adds.Add(new Sys_UserAuthority
  1634. {
  1635. CreateTime = DateTime.Now,
  1636. CreateUserId = dto.UserId,
  1637. FId = fid,
  1638. UId = dto.uid,
  1639. SmId = item.SmId,
  1640. IsTemp = 0
  1641. });
  1642. }
  1643. }
  1644. }
  1645. _JobPostAuthorityRepository.BeginTran();
  1646. try
  1647. {
  1648. List<Sys_UserAuthority> userAuth = null;
  1649. //删除个人级岗位权限
  1650. bool isdel = await _UserAuthorityRepository.DeletesAsync<Sys_UserAuthority>(userpageList);
  1651. userAuth = adds.Select(x => new Sys_UserAuthority
  1652. {
  1653. CreateTime = DateTime.Now,
  1654. CreateUserId = dto.UserId,
  1655. FId = x.FId,
  1656. SmId = x.SmId,
  1657. UId = dto.uid,
  1658. IsTemp = 0,
  1659. }).ToList();
  1660. //添加个人级别岗位
  1661. int AddRows = _UserAuthorityRepository.Adds<Sys_UserAuthority>(userAuth);
  1662. }
  1663. catch (Exception ex)
  1664. {
  1665. _JobPostAuthorityRepository.RollbackTran();
  1666. return Ok(JsonView("系统错误!"));
  1667. }
  1668. _JobPostAuthorityRepository.CommitTran();
  1669. return Ok(JsonView(200, "成功", new { }));
  1670. }
  1671. #endregion
  1672. #region 页面配置
  1673. /// <summary>
  1674. /// 页面配置界面数据初始化
  1675. /// </summary>
  1676. /// <returns></returns>
  1677. //[Authorize]
  1678. [HttpPost]
  1679. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1680. public async Task<IActionResult> PageConfigInit()
  1681. {
  1682. ArrayList arr = new ArrayList();
  1683. var viewList = await _setDataRepository.GetSetDataAndPageInfoBySTId();
  1684. if (viewList.Code != 0)
  1685. {
  1686. return Ok(JsonView(viewList.Msg));
  1687. }
  1688. var ModList = await _setDataRepository.GetSySDefultModule();
  1689. return Ok(JsonView(new
  1690. {
  1691. viewList,
  1692. ModList,
  1693. }));
  1694. }
  1695. [HttpPost]
  1696. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1697. public async Task<IActionResult> EditPageInfo(SetDataAndPageInfoDto dto)
  1698. {
  1699. JsonView view = null;
  1700. _SystemMenuPermissionRepository.BeginTran();
  1701. var istrue = await _SystemMenuPermissionRepository.UpdateAsync(x => x.Id == dto.Pageid, x => new Sys_SystemMenuPermission
  1702. {
  1703. AndroidUrl = dto.AndroidUrl,
  1704. CreateTime = DateTime.Now,
  1705. Icon = dto.Icon,
  1706. IosUrl = dto.IosUrl,
  1707. Name = dto.PageName,
  1708. PhoneIsEnable = dto.PagePhoneIsEnable,
  1709. CreateUserId = dto.UserId,
  1710. IsDel = 0,
  1711. IsEnable = dto.PageIsEnable,
  1712. Mid = dto.Modulid,
  1713. Remark = dto.PageRemark,
  1714. SystemMenuCode = dto.SystemMenuCode,
  1715. WebUrl = dto.WebUrl,
  1716. });
  1717. if (istrue)
  1718. {
  1719. //删除页面绑定的操作后重新绑定
  1720. await _SystemMenuAndFunctionRepository.DeleteAsync(x => x.SmId == dto.Pageid);
  1721. List<Sys_SystemMenuAndFunction> binFun = new List<Sys_SystemMenuAndFunction>();
  1722. foreach (var item in dto.FunArr)
  1723. {
  1724. binFun.Add(new Sys_SystemMenuAndFunction
  1725. {
  1726. CreateTime = DateTime.Now,
  1727. CreateUserId = dto.UserId,
  1728. FId = item,
  1729. SmId = dto.Pageid,
  1730. IsDel = 0,
  1731. });
  1732. }
  1733. int number = _SystemMenuAndFunctionRepository.Adds<Sys_SystemMenuAndFunction>(binFun);
  1734. view = JsonView(istrue);
  1735. _SystemMenuPermissionRepository.CommitTran();
  1736. }
  1737. else
  1738. {
  1739. _SystemMenuPermissionRepository.RollbackTran();
  1740. view = JsonView("添加失败");
  1741. }
  1742. return Ok(view);
  1743. }
  1744. /// <summary>
  1745. /// 添加一个页面
  1746. /// </summary>
  1747. /// <param name="dto"></param>
  1748. /// <returns></returns>
  1749. [HttpPost]
  1750. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1751. public async Task<IActionResult> AddPageInfo(SetDataAndPageInfoDto dto)
  1752. {
  1753. JsonView view = null;
  1754. _SystemMenuPermissionRepository.BeginTran();
  1755. int number = await _SystemMenuPermissionRepository.AddAsyncReturnId(new Sys_SystemMenuPermission
  1756. {
  1757. AndroidUrl = dto.AndroidUrl,
  1758. CreateTime = DateTime.Now,
  1759. Icon = dto.Icon,
  1760. IosUrl = dto.IosUrl,
  1761. Name = dto.PageName,
  1762. PhoneIsEnable = dto.PagePhoneIsEnable,
  1763. CreateUserId = dto.UserId,
  1764. IsDel = 0,
  1765. IsEnable = dto.PageIsEnable,
  1766. Mid = dto.Modulid,
  1767. Remark = dto.PageRemark,
  1768. SystemMenuCode = dto.SystemMenuCode,
  1769. WebUrl = dto.WebUrl,
  1770. });
  1771. List<Sys_SystemMenuAndFunction> binFun = new List<Sys_SystemMenuAndFunction>();
  1772. foreach (var item in dto.FunArr)
  1773. {
  1774. binFun.Add(new Sys_SystemMenuAndFunction
  1775. {
  1776. CreateTime = DateTime.Now,
  1777. CreateUserId = dto.UserId,
  1778. FId = item,
  1779. SmId = number,
  1780. IsDel = 0,
  1781. });
  1782. }
  1783. number = _SystemMenuAndFunctionRepository.Adds<Sys_SystemMenuAndFunction>(binFun);
  1784. if (number > 0)
  1785. {
  1786. view = JsonView(number);
  1787. _SystemMenuPermissionRepository.CommitTran();
  1788. }
  1789. else
  1790. {
  1791. _SystemMenuPermissionRepository.RollbackTran();
  1792. view = JsonView("添加失败");
  1793. }
  1794. return Ok(view);
  1795. }
  1796. /// <summary>
  1797. /// 删除页面
  1798. /// </summary>
  1799. /// <param></param>
  1800. /// <returns></returns>
  1801. [HttpPost]
  1802. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1803. public async Task<IActionResult> DelPageInfo(List<SystemMenuDelDto> Dto)
  1804. {
  1805. JsonView view = new JsonView();
  1806. if (Dto.Count > 0)
  1807. {
  1808. try
  1809. {
  1810. _SystemMenuPermissionRepository.BeginTran();
  1811. bool istrue = false;
  1812. foreach (var item in Dto)
  1813. {
  1814. istrue = await _SystemMenuPermissionRepository.SoftDeleteAsync(item.Pageid.ToString());
  1815. if (!istrue)
  1816. {
  1817. throw new Exception("修改失败");
  1818. }
  1819. }
  1820. view.Code = 200;
  1821. view.Msg = "删除成功!";
  1822. view.Data = istrue;
  1823. _SystemMenuPermissionRepository.CommitTran();
  1824. }
  1825. catch (Exception)
  1826. {
  1827. _SystemMenuPermissionRepository.RollbackTran();
  1828. }
  1829. }
  1830. return Ok(JsonView(view));
  1831. }
  1832. /// <summary>
  1833. /// 获取页面绑定的操作
  1834. /// </summary>
  1835. /// <param name="Dto"></param>
  1836. /// <returns></returns>
  1837. [HttpPost]
  1838. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1839. public async Task<IActionResult> QueryPageFunById(PageFunDto Dto)
  1840. {
  1841. //页面与操作关联表
  1842. var pageAndFunList = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  1843. //页面功能表
  1844. var pageFunList = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, Sys_PageFunctionPermission>(x => x.IsEnable == 1).ToList();
  1845. ArrayList arr = new ArrayList();
  1846. foreach (var item in pageFunList)
  1847. {
  1848. var FindVal = pageAndFunList.Find(x => x.SmId == Dto.Pageid && x.FId == item.Id);
  1849. if (FindVal == null)
  1850. {
  1851. arr.Add(new
  1852. {
  1853. id = item.Id,
  1854. name = item.FunctionName,
  1855. value = false
  1856. });
  1857. }
  1858. else
  1859. {
  1860. arr.Add(new
  1861. {
  1862. id = item.Id,
  1863. name = item.FunctionName,
  1864. value = true
  1865. });
  1866. }
  1867. }
  1868. return Ok(JsonView(arr));
  1869. }
  1870. #endregion
  1871. #region 页面操作
  1872. /// <summary>
  1873. /// 操作权限功能表
  1874. /// </summary>
  1875. /// <returns></returns>
  1876. [HttpPost]
  1877. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1878. public async Task<IActionResult> PageFunInit()
  1879. {
  1880. var PageFunInit = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, PageFunctionPermissionView>().ToList();
  1881. if (PageFunInit == null)
  1882. {
  1883. return Ok(JsonView(false, "暂无数据!"));
  1884. }
  1885. return Ok(JsonView(true, "查询成功!", PageFunInit));
  1886. }
  1887. /// <summary>
  1888. /// 操作权限功能表操作(Status 1:添加,2:编辑)
  1889. /// </summary>
  1890. /// <returns></returns>
  1891. [HttpPost]
  1892. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1893. public async Task<IActionResult> OperationFun(OperationFunInitDta dto)
  1894. {
  1895. Result result = await _PageFunctionPermissionRepository.OperationFunInit(dto);
  1896. if (result.Code != 0)
  1897. {
  1898. return Ok(JsonView(false, result.Msg));
  1899. }
  1900. return Ok(JsonView(true, result.Msg));
  1901. }
  1902. /// <summary>
  1903. /// 删除功能
  1904. /// </summary>
  1905. /// <param name="dto"></param>
  1906. /// <returns></returns>
  1907. [HttpPost]
  1908. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1909. public async Task<IActionResult> DelFun(DelFunInitDta dto)
  1910. {
  1911. var res = await _PageFunctionPermissionRepository.SoftDeleteByIdAsync<Sys_PageFunctionPermission>(dto.Id.ToString(), dto.DeleteUserId);
  1912. if (!res)
  1913. {
  1914. return Ok(JsonView(false, "删除失败"));
  1915. }
  1916. return Ok(JsonView(true, "删除成功!"));
  1917. }
  1918. #endregion
  1919. #region 各部门首页消息提示
  1920. /// <summary>
  1921. /// 部门首页消息提示
  1922. /// </summary>
  1923. /// <returns></returns>
  1924. [HttpGet("{portType}")]
  1925. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1926. public async Task<IActionResult> DepartmentHomePageMessagePrompts(int portType)
  1927. {
  1928. var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
  1929. if (currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
  1930. var department = currUserInfo.Department;
  1931. if (portType < 1 || portType > 3) return Ok(JsonView(false, MsgTips.Port));
  1932. if (portType == 1 || portType == 2 || portType == 3) // web
  1933. {
  1934. //固定查询时间(当前月的上月)
  1935. var lastMoth = DateTime.Now.AddMonths(-1);
  1936. var (startDate, endDate) = CommonFun.GetMonthStartAndEndDates(lastMoth.Year, lastMoth.Month);
  1937. var startDateTime = Convert.ToDateTime(startDate.ToString("yyyy-MM-dd 00:00:00"));
  1938. var endDateTime = Convert.ToDateTime(endDate.ToString("yyyy-MM-dd 23:59:59"));
  1939. //固定查询时间(本年)
  1940. var currStartDate = Convert.ToDateTime($"{DateTime.Now.Year}-01-01 00:00:00");
  1941. var currEntDate = Convert.ToDateTime($"{DateTime.Now.Year}-12-31 23:59:59");
  1942. if (department.Equals("总经办")) //总经办
  1943. {
  1944. //1、资料数据(市场部客户资源、op地接导游、op地接车数据、商邀数据、团组收款数据)数据提示Range(固定上个月) -- Add
  1945. #region 市场部客户资源
  1946. //1.1 市场部客户资源
  1947. var users = await _sqlSugar.Queryable<Sys_Users>()
  1948. .LeftJoin<Sys_Department>((u, d) => u.DepId == d.Id)
  1949. .Where((u, d) => u.IsDel == 0 && (d.DepName.Contains("市场部") || u.Id == 21))
  1950. .Select((u, d) => new { u.Id, u.CnName })
  1951. .ToListAsync();
  1952. var marketData = await _sqlSugar.Queryable<Crm_NewClientData>()
  1953. .LeftJoin<Sys_Users>((ncd, u) => ncd.CreateUserId == u.Id)
  1954. .Where((ncd, u) => ncd.IsDel == 0 && ncd.CreateTime >= startDateTime && ncd.CreateTime <= endDateTime)
  1955. .Select((ncd, u) => new
  1956. {
  1957. Area = ncd.Location,
  1958. ncd.Client,
  1959. ncd.Contact,
  1960. ncd.Job,
  1961. Tel = ncd.Telephone,
  1962. ncd.CreateUserId,
  1963. CreatleUserName = u.CnName,
  1964. ncd.CreateTime,
  1965. })
  1966. .ToListAsync();
  1967. foreach (var item in marketData) EncryptionProcessor.DecryptProperties(item);
  1968. var marketDataGroup = marketData.GroupBy(x => x.CreateUserId).Select(g => new { CreateUserId = g.Key, Items = g.ToList(), Count = g.Count() });
  1969. var marketData2 = new List<dynamic>();
  1970. foreach (var user in users)
  1971. {
  1972. var userMarketData = marketDataGroup.FirstOrDefault(x => user.Id == x.CreateUserId);
  1973. if (userMarketData != null)
  1974. {
  1975. marketData2.Add(new
  1976. {
  1977. uId = user.Id,
  1978. name = user.CnName,
  1979. count = userMarketData.Count,
  1980. msgTips = $"上月新增市场客户资源共{userMarketData.Count}条",
  1981. userMarketData = userMarketData.Items
  1982. });
  1983. }
  1984. else
  1985. {
  1986. marketData2.Add(new
  1987. {
  1988. uId = user.Id,
  1989. name = user.CnName,
  1990. count = 0,
  1991. msgTips = $"上月新增市场客户资源共{0}条",
  1992. userMarketData = new List<dynamic>() { },
  1993. });
  1994. }
  1995. }
  1996. var marketData1 = new
  1997. {
  1998. msgTips = $"上月新增市场客户资源共{marketData.Count}条",
  1999. Data = marketData2,
  2000. };
  2001. #endregion
  2002. #region op地接导游
  2003. //1.2 op地接导游
  2004. var opTourGuideData = await _sqlSugar.Queryable<Res_LocalGuideData>()
  2005. .LeftJoin<Sys_Users>((lgd, u) => lgd.CreateUserId == u.Id)
  2006. .Where((lgd, u) => lgd.IsDel == 0 && lgd.CreateTime >= startDateTime && lgd.CreateTime <= endDateTime)
  2007. .Select((lgd, u) => new
  2008. {
  2009. Area = lgd.UnitArea,
  2010. Client = lgd.UnitName,
  2011. lgd.Contact,
  2012. Job = "",
  2013. Tel = lgd.ContactTel,
  2014. lgd.CreateUserId,
  2015. CreatleUserName = u.CnName,
  2016. lgd.CreateTime,
  2017. })
  2018. .ToListAsync();
  2019. foreach (var item in opTourGuideData) EncryptionProcessor.DecryptProperties(item);
  2020. var opTourGuideDataGroups = opTourGuideData.GroupBy(x => x.CreateUserId)
  2021. .Select(g => new
  2022. {
  2023. uId = g.Key,
  2024. name = g.ToList().FirstOrDefault()?.CreatleUserName ?? "-",
  2025. msgTips = $"上月新增OP地接导游资源共{g.Count()}条",
  2026. userTourGuideData = g.ToList(),
  2027. Count = g.Count()
  2028. });
  2029. var opTourGuideData1 = new
  2030. {
  2031. msgTips = $"上月新增OP地接导游资源共{opTourGuideData.Count}条",
  2032. Data = opTourGuideDataGroups,
  2033. };
  2034. #endregion
  2035. #region op车数据
  2036. //1.3 op车数据
  2037. var opCarData = await _sqlSugar.Queryable<Res_CarData>()
  2038. .LeftJoin<Sys_Users>((cd, u) => cd.CreateUserId == u.Id)
  2039. .Where((cd, u) => cd.IsDel == 0 && cd.CreateTime >= startDateTime && cd.CreateTime <= endDateTime)
  2040. .Select((cd, u) => new CarDataMsgTipsView()
  2041. {
  2042. Area = cd.UnitArea,
  2043. Client = cd.UnitName,
  2044. Contact = cd.Contact,
  2045. Job = "",
  2046. Tel = cd.ContactTel,
  2047. CreateUserId = cd.CreateUserId,
  2048. CreatleUserName = u.CnName,
  2049. CreateTime = cd.CreateTime,
  2050. })
  2051. .ToListAsync();
  2052. foreach (var item in opCarData) EncryptionProcessor.DecryptProperties(item);
  2053. var opCarDataGroups = opCarData.GroupBy(x => x.CreateUserId)
  2054. .Select(g => new
  2055. {
  2056. uId = g.Key,
  2057. name = g.ToList().FirstOrDefault()?.CreatleUserName ?? "-",
  2058. msgTips = $"上月新增OP地接车资源共{g.Count()}条",
  2059. userTourGuideData = g.ToList(),
  2060. Count = g.Count()
  2061. });
  2062. var opCarData1 = new
  2063. {
  2064. msgTips = $"上月新增OP地接车资源共{opCarData.Count}条",
  2065. Data = opCarDataGroups,
  2066. };
  2067. #endregion
  2068. #region 商邀数据
  2069. //1.4 商邀数据
  2070. var invitationData = await _sqlSugar.Queryable<Res_InvitationOfficialActivityData>()
  2071. .LeftJoin<Sys_Users>((ioa, u) => ioa.CreateUserId == u.Id)
  2072. .Where((ioa, u) => ioa.IsDel == 0 && ioa.CreateTime >= startDateTime && ioa.CreateTime <= endDateTime)
  2073. .Select((ioa, u) => new
  2074. {
  2075. //Area = string.Format("{0}{1}", ioa.Country, !string.IsNullOrEmpty(ioa.City) ? "" : "-" + ioa.City),
  2076. Area = string.Format("{0}{1}", ioa.Country, ioa.City),
  2077. Client = ioa.UnitName,
  2078. ioa.Contact,
  2079. ioa.Job,
  2080. ioa.Tel,
  2081. ioa.CreateUserId,
  2082. CreatleUserName = u.CnName,
  2083. ioa.CreateTime,
  2084. })
  2085. .ToListAsync();
  2086. var invitationGroups = invitationData.GroupBy(x => x.CreateUserId)
  2087. .Select(g => new
  2088. {
  2089. uId = g.Key,
  2090. name = g.ToList().FirstOrDefault()?.CreatleUserName ?? "-",
  2091. msgTips = $"上月新增商邀资源共{g.Count()}条",
  2092. userTourGuideData = g.ToList(),
  2093. Count = g.Count()
  2094. });
  2095. var invitationData1 = new
  2096. {
  2097. msgTips = $"上月新增商邀资源共{invitationData.Count}条",
  2098. Data = invitationGroups,
  2099. };
  2100. #endregion
  2101. #region 团组收款数据
  2102. //1.5 团组收款数据
  2103. var groupCollectionData = await _sqlSugar.Queryable<Fin_ForeignReceivables>()
  2104. .LeftJoin<Sys_Users>((fr, u) => fr.CreateUserId == u.Id)
  2105. .LeftJoin<Grp_DelegationInfo>((fr, u, di) => fr.Diid == di.Id)
  2106. .LeftJoin<Sys_SetData>((fr, u, di, sd) => fr.Currency == sd.Id)
  2107. .Where((fr, u, di, sd) => fr.IsDel == 0 && fr.CreateTime >= startDateTime && fr.CreateTime <= endDateTime)
  2108. .Select((fr, u, di, sd) => new
  2109. {
  2110. fr.PriceName,
  2111. fr.Price,
  2112. fr.Count,
  2113. fr.Unit,
  2114. fr.ItemSumPrice,
  2115. Currency = sd.Name,
  2116. GroupName = di.TeamName,
  2117. fr.CreateUserId,
  2118. CreateUserName = u.CnName,
  2119. fr.CreateTime,
  2120. })
  2121. .ToListAsync();
  2122. var groupCollectionGroups = groupCollectionData.GroupBy(x => x.CreateUserId)
  2123. .Select(g => new
  2124. {
  2125. uId = g.Key,
  2126. name = g.ToList().FirstOrDefault()?.CreateUserName ?? "-",
  2127. msgTips = $"上月累计团组收款共{g.Count()}条",
  2128. userTourGuideData = g.ToList(),
  2129. Count = g.Count()
  2130. });
  2131. var groupCollectionData2 = new
  2132. {
  2133. msgTips = $"上月累计团组收款共{groupCollectionData.Count}条",
  2134. Data = groupCollectionGroups,
  2135. };
  2136. #endregion
  2137. var materialData = new
  2138. {
  2139. marketData = marketData1,
  2140. opTourGuideData = opTourGuideData1,
  2141. opCarData = opCarData1,
  2142. invitationData = invitationData1,
  2143. groupCollectionData = groupCollectionData2
  2144. };
  2145. //2、费用未审核(日付申请未审核数据、团组费用未审核数据)费用提示Range(固定本年)
  2146. #region 日付申请未审核数据
  2147. var dailyPaymentData = await _sqlSugar.Queryable<Fin_DailyFeePayment>()
  2148. .LeftJoin<Sys_Users>((dfp, u) => dfp.CreateUserId == u.Id)
  2149. .Where(dfp => dfp.IsDel == 0 &&
  2150. dfp.MAudit == 0 &&
  2151. dfp.CreateTime >= currStartDate &&
  2152. dfp.CreateTime <= currEntDate
  2153. )
  2154. .OrderBy(dfp => dfp.CreateTime, OrderByType.Desc)
  2155. //.OrderBy(dfp => dfp.FAudit, OrderByType.Desc)
  2156. .Select((dfp, u) => new
  2157. {
  2158. id = dfp.Id,
  2159. amountName = dfp.Instructions,
  2160. amount = dfp.SumPrice,
  2161. fAuditStatus = dfp.FAudit == 1 ? "审核通过" :
  2162. dfp.FAudit == 2 ? "审核未通过" : "未审核",
  2163. fAuditDate = dfp.FAuditDate,
  2164. dfp.CreateUserId,
  2165. CreateUserName = u.CnName,
  2166. dfp.CreateTime
  2167. })
  2168. .ToListAsync();
  2169. var dailyPaymentGroups = dailyPaymentData.GroupBy(x => x.CreateUserId)
  2170. .Select(g => new
  2171. {
  2172. uId = g.Key,
  2173. name = g.ToList().FirstOrDefault()?.CreateUserName ?? "-",
  2174. msgTips = $"本年有{g.Count()}条未审核日常付款申请条",
  2175. userTourGuideData = g.ToList(),
  2176. Count = g.Count()
  2177. });
  2178. var dailyPaymentData1 = new
  2179. {
  2180. msgTips = $"本年有{dailyPaymentData.Count()}条未审核日常付款申请条",
  2181. Data = dailyPaymentGroups,
  2182. };
  2183. #endregion
  2184. #region 团组费用未审核数据
  2185. var groupPaymentData = await _sqlSugar.Queryable<Grp_CreditCardPayment>()
  2186. .LeftJoin<Grp_DelegationInfo>((ccp, di) => ccp.DIId == di.Id)
  2187. .Where((ccp, di) => ccp.IsDel == 0 &&
  2188. ccp.IsAuditGM == 0 &&
  2189. ccp.CreateTime >= currStartDate &&
  2190. ccp.CreateTime <= currEntDate
  2191. )
  2192. .Select((ccp, di) => new
  2193. {
  2194. ccp.Id,
  2195. ccp.DIId,
  2196. GroupName = di.TeamName,
  2197. ccp.CreateTime,
  2198. })
  2199. .ToListAsync();
  2200. var groupPaymentGroups = groupPaymentData.GroupBy(x => x.DIId)
  2201. .Select(g => new
  2202. {
  2203. uId = g.Key,
  2204. name = g.ToList().FirstOrDefault()?.GroupName ?? "-",
  2205. msgTips = $"本年有{g.Count()}条未审核团组费用申请条",
  2206. userTourGuideData = g.ToList(),
  2207. Count = g.Count()
  2208. });
  2209. var groupPaymentData1 = new
  2210. {
  2211. msgTips = $"本年有{groupPaymentData.Count()}条未审核团组费用申请条",
  2212. Data = groupPaymentGroups,
  2213. };
  2214. #endregion
  2215. var feeUnAuditData = new
  2216. {
  2217. dailyPaymentData = dailyPaymentData1,
  2218. groupPaymentData = groupPaymentData1
  2219. };
  2220. return Ok(JsonView(new { materialData = materialData, feeUnAuditData = feeUnAuditData }));
  2221. }
  2222. else if (department.Equals("国交部"))//国交部
  2223. {
  2224. #region 团组费用录入提示
  2225. /*
  2226. * 名称:团组费用录入提示
  2227. * 描述:团组费用录入提醒(根据团组结束时间 - 3天 如果对应的数据表里没有这个团组的费用信息)
  2228. * 条件:时间范围不限制、 根据团组结束时间 - 3天 == 当前天数
  2229. */
  2230. var groupModlue = new List<int>() {
  2231. 76, //酒店预订
  2232. 79, //车/导游地接
  2233. 80, //签证
  2234. 81, //邀请/公务活动
  2235. //82, //团组客户保险
  2236. 85, //机票预订
  2237. 98, //其他款项
  2238. //285 ,//收款退还
  2239. //1015,//超支费用
  2240. };
  2241. var crrDate = DateTime.Now.ToString("yyyy-MM-dd");
  2242. var groupModlueData = await _sqlSugar.Queryable<Sys_SetData>().Where(x => groupModlue.Contains(x.Id)).ToListAsync();
  2243. var groupFeeData = await _sqlSugar.Queryable<Sys_SetData>()
  2244. .LeftJoin<Grp_CreditCardPayment>((sd, ccp) => sd.Id == ccp.CTable)
  2245. .LeftJoin<Grp_DelegationInfo>((sd, ccp, di) => ccp.DIId == di.Id)
  2246. .Where((sd, ccp, di) => ccp.IsDel == 0 &&
  2247. di.IsDel == 0 &&
  2248. groupModlue.Contains(ccp.CTable) &&
  2249. di.VisitEndDate.AddDays(-3).ToString("yyyy-MM-dd").Equals(crrDate)
  2250. )
  2251. .GroupBy((sd, ccp, di) => new { di.Id, di.TeamName, ccp.CTable, sd.Name }) //可以多字段
  2252. .Select((sd, ccp, di) => new
  2253. {
  2254. diId = di.Id,
  2255. groupName = di.TeamName,
  2256. groupType = ccp.CTable,
  2257. groupTypeName = sd.Name,
  2258. //userId = ccp.CreateUserId,
  2259. count = SqlFunc.AggregateCount(ccp.CTable),
  2260. })
  2261. .ToListAsync();
  2262. var groupFeeData1 = groupFeeData.GroupBy(x => x.diId);
  2263. var groupNotFilledFeeData = new List<dynamic>();
  2264. foreach (var groupFee in groupFeeData1)
  2265. {
  2266. var diId = groupFee.Key;
  2267. var addData = groupFeeData.Where(x => x.diId == diId).Select(x => x.groupType).ToList();
  2268. if (addData.Count < 1) continue;
  2269. var unAddData = groupModlue.Except(addData).ToList();
  2270. if (unAddData.Count < 1) continue;
  2271. foreach (var typeId in unAddData)
  2272. {
  2273. groupNotFilledFeeData.Add(new
  2274. {
  2275. diId = diId,
  2276. groupName = groupFee.FirstOrDefault()?.groupName ?? "-",
  2277. groupType = typeId,
  2278. groupTypeName = groupModlueData.Find(x => x.Id == typeId)?.Name ?? "-",
  2279. count = 0
  2280. });
  2281. }
  2282. }
  2283. #endregion
  2284. #region 日付申请 -- 未审核数据
  2285. var depUserData = await _sqlSugar.Queryable<Sys_Users>()
  2286. .LeftJoin<Sys_Department>((u, d) => u.DepId == d.Id)
  2287. .LeftJoin<Sys_JobPost>((u, d, jp) => u.JobPostId == jp.Id)
  2288. .Where((u, d, jp) => u.IsDel == 0 && d.DepName.Contains("国交部"))
  2289. .Select((u, d, jp) => new
  2290. {
  2291. u.Id,
  2292. u.CnName,
  2293. u.DepId,
  2294. d.DepName,
  2295. u.JobPostId,
  2296. jp.JobName
  2297. })
  2298. .ToListAsync();
  2299. var depUserData1 = depUserData.Select(x => x.Id).ToList();
  2300. var unAuditDailyFeeData = await _sqlSugar.Queryable<Fin_DailyFeePayment>()
  2301. .LeftJoin<Sys_Users>((dfp, u) => dfp.CreateUserId == u.Id)
  2302. .Where((dfp, u) => dfp.IsDel == 0 &&
  2303. depUserData1.Contains(dfp.CreateUserId) &&
  2304. dfp.MAudit == 0 &&
  2305. dfp.CreateTime >= currStartDate &&
  2306. dfp.CreateTime <= currEntDate
  2307. )
  2308. .Select((dfp, u) => new
  2309. {
  2310. id = dfp.Id,
  2311. amountName = dfp.Instructions,
  2312. amount = dfp.SumPrice,
  2313. fAuditStatus = dfp.FAudit == 1 ? "审核通过" :
  2314. dfp.FAudit == 2 ? "审核未通过" : "未审核",
  2315. fAuditDate = dfp.FAuditDate,
  2316. dfp.CreateUserId,
  2317. CreateUserName = u.CnName,
  2318. dfp.CreateTime
  2319. })
  2320. .ToArrayAsync();
  2321. #endregion
  2322. var jobs = new List<string>() { "经理", "主管" };
  2323. if (jobs.Contains(currUserInfo.Role)) //经理、主管
  2324. {
  2325. #region 经理、主管
  2326. //经理、主管(部门下所有人员) --> 日付(-:未审核提示)、团组费用录入提醒(根据团组结束时间-3天 如果对应的数据表里没有这个团组的费用信息)
  2327. var dailyPaymentData = new
  2328. {
  2329. msgTips = $"本年有{unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2330. Data = new
  2331. {
  2332. uId = currUserInfo.UserId,
  2333. name = currUserInfo.UserName,
  2334. msgTips = $"本年有{unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2335. userTourGuideData = unAuditDailyFeeData,
  2336. Count = unAuditDailyFeeData.Count()
  2337. }
  2338. };
  2339. var groupNotFilledFeeDataAll = groupNotFilledFeeData
  2340. .GroupBy(x => x.diId)
  2341. .Select(g => new
  2342. {
  2343. uId = g.Key,
  2344. name = g.ToList().FirstOrDefault()?.groupName ?? "-",
  2345. msgTips = $"-",
  2346. hotelFeeData = g.Select(x1 => new
  2347. {
  2348. x1.groupType,
  2349. x1.groupTypeName
  2350. }).ToList(),
  2351. Count = g.Count()
  2352. })
  2353. .ToList();
  2354. var groupNotFillEdFeeData1 = new
  2355. {
  2356. msgTips = $"今天有{groupNotFilledFeeDataAll.Count()}个团组费用未填写",
  2357. Data = groupNotFilledFeeDataAll,
  2358. };
  2359. #endregion
  2360. return Ok(JsonView(new { groupNotFillEdFeeData = groupNotFillEdFeeData1, dailyPaymentData = dailyPaymentData }));
  2361. }
  2362. else if (currUserInfo.Role.Equals("计调"))//计调
  2363. {
  2364. #region 计调
  2365. //计调(myself) --> 暂定
  2366. return Ok(JsonView(false, "国交部-->计调岗位消息提示正在开发中......"));
  2367. #endregion
  2368. }
  2369. else if (currUserInfo.Role.Equals("机票"))//机票
  2370. {
  2371. #region 机票
  2372. //机票(myself) --> 日付(-:未审核提示)、机票费用(-:未录入提示)
  2373. var airTicket_unAuditDailyFeeData = unAuditDailyFeeData.Where(x => x.CreateUserId == currUserInfo.UserId).ToList();
  2374. var dailyPaymentData = new
  2375. {
  2376. msgTips = $"本年有{airTicket_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2377. Data = new
  2378. {
  2379. uId = currUserInfo.UserId,
  2380. name = currUserInfo.UserName,
  2381. msgTips = $"本年有{airTicket_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2382. userTourGuideData = airTicket_unAuditDailyFeeData,
  2383. Count = airTicket_unAuditDailyFeeData.Count()
  2384. }
  2385. };
  2386. var airTicket_groupNotFilledData = groupNotFilledFeeData
  2387. .Where(x => x.groupType == 85)
  2388. .GroupBy(x => x.diId)
  2389. .Select(g => new
  2390. {
  2391. uId = g.Key,
  2392. name = g.ToList().FirstOrDefault()?.groupName ?? "-",
  2393. msgTips = $"-",
  2394. airTicketFeeData = g.Select(x1 => new
  2395. {
  2396. x1.groupType,
  2397. x1.groupTypeName
  2398. }).ToList(),
  2399. Count = g.Count()
  2400. })
  2401. .ToList();
  2402. var groupNotFillEdFeeData1 = new
  2403. {
  2404. msgTips = $"今天有{airTicket_groupNotFilledData.Count()}个团组费用未填写",
  2405. Data = airTicket_groupNotFilledData,
  2406. };
  2407. #endregion
  2408. return Ok(JsonView(new { groupNotFillEdFeeData = groupNotFillEdFeeData1, dailyPaymentData = dailyPaymentData }));
  2409. }
  2410. else if (currUserInfo.Role.Equals("酒店"))//酒店
  2411. {
  2412. #region 酒店
  2413. //酒店(myself) --> 日付(-:未审核提示)、酒店费用(-:未录入提示)
  2414. var hotle_unAuditDailyFeeData = unAuditDailyFeeData.Where(x => x.CreateUserId == currUserInfo.UserId).ToList();
  2415. var dailyPaymentData = new
  2416. {
  2417. msgTips = $"本年有{hotle_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2418. Data = new
  2419. {
  2420. uId = currUserInfo.UserId,
  2421. name = currUserInfo.UserName,
  2422. msgTips = $"本年有{hotle_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2423. hotelFeeData = hotle_unAuditDailyFeeData,
  2424. Count = hotle_unAuditDailyFeeData.Count()
  2425. }
  2426. };
  2427. var hotel_groupNotFilledData = groupNotFilledFeeData
  2428. .Where(x => x.groupType == 76)
  2429. .GroupBy(x => x.diId)
  2430. .Select(g => new
  2431. {
  2432. uId = g.Key,
  2433. name = g.ToList().FirstOrDefault()?.groupName ?? "-",
  2434. msgTips = $"-",
  2435. hotelFeeData = g.Select(x1 => new
  2436. {
  2437. x1.groupType,
  2438. x1.groupTypeName
  2439. }).ToList(),
  2440. Count = g.Count()
  2441. })
  2442. .ToList();
  2443. var groupNotFillEdFeeData1 = new
  2444. {
  2445. msgTips = $"今天有{hotel_groupNotFilledData.Count()}个团组费用未填写",
  2446. Data = hotel_groupNotFilledData,
  2447. };
  2448. #endregion
  2449. return Ok(JsonView(new { groupNotFillEdFeeData = groupNotFillEdFeeData1, dailyPaymentData = dailyPaymentData }));
  2450. }
  2451. else if (currUserInfo.Role.Equals("签证"))//签证
  2452. {
  2453. #region 签证
  2454. //签证(myself) --> 日付(-:未审核提示)、签证费用(-:未录入提示)
  2455. var visa_unAuditDailyFeeData = unAuditDailyFeeData.Where(x => x.CreateUserId == currUserInfo.UserId).ToList();
  2456. var dailyPaymentData = new
  2457. {
  2458. msgTips = $"本年有{visa_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2459. Data = new
  2460. {
  2461. uId = currUserInfo.UserId,
  2462. name = currUserInfo.UserName,
  2463. msgTips = $"本年有{visa_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2464. visaFeeData = visa_unAuditDailyFeeData,
  2465. Count = visa_unAuditDailyFeeData.Count()
  2466. }
  2467. };
  2468. var visa_groupNotFilledData = groupNotFilledFeeData
  2469. .Where(x => x.groupType == 80)
  2470. .GroupBy(x => x.diId)
  2471. .Select(g => new
  2472. {
  2473. uId = g.Key,
  2474. name = g.ToList().FirstOrDefault()?.groupName ?? "-",
  2475. msgTips = $"-",
  2476. airTicketFeeData = g.Select(x1 => new
  2477. {
  2478. x1.groupType,
  2479. x1.groupTypeName
  2480. }).ToList(),
  2481. Count = g.Count()
  2482. })
  2483. .ToList();
  2484. var groupNotFillEdFeeData1 = new
  2485. {
  2486. msgTips = $"今天有{visa_groupNotFilledData.Count()}个团组费用未填写",
  2487. Data = visa_groupNotFilledData,
  2488. };
  2489. #endregion
  2490. return Ok(JsonView(new { groupNotFillEdFeeData = groupNotFillEdFeeData1, dailyPaymentData = dailyPaymentData }));
  2491. }
  2492. else if (currUserInfo.Role.Equals("商邀"))//商邀
  2493. {
  2494. #region 商邀
  2495. //商邀(myself) --> 日付(-:未审核提示)、商邀费用(-:未录入提示)、(公务、翻译人)(-:新增提示)
  2496. //日付
  2497. var in_unAuditDailyFeeData = unAuditDailyFeeData.Where(x => x.CreateUserId == currUserInfo.UserId).ToList();
  2498. var dailyPaymentData = new
  2499. {
  2500. msgTips = $"本年有{in_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2501. Data = new
  2502. {
  2503. uId = currUserInfo.UserId,
  2504. name = currUserInfo.UserName,
  2505. msgTips = $"本年有{in_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2506. visaFeeData = in_unAuditDailyFeeData,
  2507. Count = in_unAuditDailyFeeData.Count()
  2508. }
  2509. };
  2510. //团组未录入费用
  2511. var in_groupNotFilledData = groupNotFilledFeeData
  2512. .Where(x => x.groupType == 81)
  2513. .GroupBy(x => x.diId)
  2514. .Select(g => new
  2515. {
  2516. uId = g.Key,
  2517. name = g.ToList().FirstOrDefault()?.groupName ?? "-",
  2518. msgTips = $"-",
  2519. airTicketFeeData = g.Select(x1 => new
  2520. {
  2521. x1.groupType,
  2522. x1.groupTypeName
  2523. }).ToList(),
  2524. Count = g.Count()
  2525. })
  2526. .ToList();
  2527. var groupNotFillEdFeeData1 = new
  2528. {
  2529. msgTips = $"今天有{in_groupNotFilledData.Count()}个团组费用未填写",
  2530. Data = in_groupNotFilledData,
  2531. };
  2532. //商邀 - 基础数据
  2533. var invitationData = await _sqlSugar.Queryable<Res_InvitationOfficialActivityData>()
  2534. .LeftJoin<Sys_Users>((ioa, u) => ioa.CreateUserId == u.Id)
  2535. .Where((ioa, u) => ioa.IsDel == 0 && ioa.CreateTime >= startDateTime && ioa.CreateTime <= endDateTime)
  2536. .Select((ioa, u) => new
  2537. {
  2538. //Area = string.Format("{0}{1}", ioa.Country, !string.IsNullOrEmpty(ioa.City) ? "" : "-" + ioa.City),
  2539. Area = string.Format("{0}{1}", ioa.Country, ioa.City),
  2540. Client = ioa.UnitName,
  2541. ioa.Contact,
  2542. ioa.Job,
  2543. ioa.Tel,
  2544. ioa.CreateUserId,
  2545. CreatleUserName = u.CnName,
  2546. ioa.CreateTime,
  2547. })
  2548. .ToListAsync();
  2549. var invitationGroups = invitationData.GroupBy(x => x.CreateUserId)
  2550. .Select(g => new
  2551. {
  2552. uId = g.Key,
  2553. name = g.ToList().FirstOrDefault()?.CreatleUserName ?? "-",
  2554. msgTips = $"上月新增商邀资源共{g.Count()}条",
  2555. userTourGuideData = g.ToList(),
  2556. Count = g.Count()
  2557. });
  2558. var invitationData1 = new
  2559. {
  2560. msgTips = $"上月新增商邀资源共{invitationData.Count}条",
  2561. Data = invitationGroups,
  2562. };
  2563. #endregion
  2564. return Ok(JsonView(new { groupNotFillEdFeeData = groupNotFillEdFeeData1, dailyPaymentData = dailyPaymentData, invitationData = invitationData }));
  2565. }
  2566. else if (currUserInfo.Role.Equals("OP"))//OP
  2567. {
  2568. #region OP
  2569. //OP(myself) --> 日付(-:未审核提示)、OP费用(-:未录入提示)、(导游、车)资源信息(-:新增提示)
  2570. //日付
  2571. var in_unAuditDailyFeeData = unAuditDailyFeeData.Where(x => x.CreateUserId == currUserInfo.UserId).ToList();
  2572. var dailyPaymentData = new
  2573. {
  2574. msgTips = $"本年有{in_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2575. Data = new
  2576. {
  2577. uId = currUserInfo.UserId,
  2578. name = currUserInfo.UserName,
  2579. msgTips = $"本年有{in_unAuditDailyFeeData.Count()}条未审核日常付款申请条",
  2580. visaFeeData = in_unAuditDailyFeeData,
  2581. Count = in_unAuditDailyFeeData.Count()
  2582. }
  2583. };
  2584. //OP - 团组未录入费用
  2585. var in_groupNotFilledData = groupNotFilledFeeData
  2586. .Where(x => x.groupType == 79)
  2587. .GroupBy(x => x.diId)
  2588. .Select(g => new
  2589. {
  2590. uId = g.Key,
  2591. name = g.ToList().FirstOrDefault()?.groupName ?? "-",
  2592. msgTips = $"-",
  2593. airTicketFeeData = g.Select(x1 => new
  2594. {
  2595. x1.groupType,
  2596. x1.groupTypeName
  2597. }).ToList(),
  2598. Count = g.Count()
  2599. })
  2600. .ToList();
  2601. var groupNotFillEdFeeData1 = new
  2602. {
  2603. msgTips = $"今天有{in_groupNotFilledData.Count()}个团组费用未填写",
  2604. Data = in_groupNotFilledData,
  2605. };
  2606. #region op地接导游
  2607. //1.2 op地接导游
  2608. var opTourGuideData = await _sqlSugar.Queryable<Res_LocalGuideData>()
  2609. .LeftJoin<Sys_Users>((lgd, u) => lgd.CreateUserId == u.Id)
  2610. .Where((lgd, u) => lgd.IsDel == 0 && lgd.CreateTime >= startDateTime && lgd.CreateTime <= endDateTime)
  2611. .Select((lgd, u) => new
  2612. {
  2613. Area = lgd.UnitArea,
  2614. Client = lgd.UnitName,
  2615. lgd.Contact,
  2616. Job = "",
  2617. Tel = lgd.ContactTel,
  2618. lgd.CreateUserId,
  2619. CreatleUserName = u.CnName,
  2620. lgd.CreateTime,
  2621. })
  2622. .ToListAsync();
  2623. foreach (var item in opTourGuideData) EncryptionProcessor.DecryptProperties(item);
  2624. var opTourGuideDataGroups = opTourGuideData.GroupBy(x => x.CreateUserId)
  2625. .Select(g => new
  2626. {
  2627. uId = g.Key,
  2628. name = g.ToList().FirstOrDefault()?.CreatleUserName ?? "-",
  2629. msgTips = $"上月新增OP地接导游资源共{g.Count()}条",
  2630. userTourGuideData = g.ToList(),
  2631. Count = g.Count()
  2632. });
  2633. var opTourGuideData1 = new
  2634. {
  2635. msgTips = $"上月新增OP地接导游资源共{opTourGuideData.Count}条",
  2636. Data = opTourGuideDataGroups,
  2637. };
  2638. #endregion
  2639. #region op车数据
  2640. //1.3 op车数据
  2641. var opCarData = await _sqlSugar.Queryable<Res_CarData>()
  2642. .LeftJoin<Sys_Users>((cd, u) => cd.CreateUserId == u.Id)
  2643. .Where((cd, u) => cd.IsDel == 0 && cd.CreateTime >= startDateTime && cd.CreateTime <= endDateTime)
  2644. .Select((cd, u) => new
  2645. {
  2646. Area = cd.UnitArea,
  2647. Client = cd.UnitName,
  2648. cd.Contact,
  2649. Job = "",
  2650. Tel = cd.ContactTel,
  2651. cd.CreateUserId,
  2652. CreatleUserName = u.CnName,
  2653. cd.CreateTime,
  2654. })
  2655. .ToListAsync();
  2656. var opCarDataGroups = opCarData.GroupBy(x => x.CreateUserId)
  2657. .Select(g => new
  2658. {
  2659. uId = g.Key,
  2660. name = g.ToList().FirstOrDefault()?.CreatleUserName ?? "-",
  2661. msgTips = $"上月新增OP地接车资源共{g.Count()}条",
  2662. userTourGuideData = g.ToList(),
  2663. Count = g.Count()
  2664. });
  2665. var opCarData1 = new
  2666. {
  2667. msgTips = $"上月新增OP地接车资源共{opCarData.Count}条",
  2668. Data = opCarDataGroups,
  2669. };
  2670. #endregion
  2671. #endregion
  2672. return Ok(JsonView(new
  2673. {
  2674. groupNotFillEdFeeData = groupNotFillEdFeeData1,
  2675. dailyPaymentData = dailyPaymentData,
  2676. CarData = opCarData1,
  2677. TourGuideData = opTourGuideData
  2678. }));
  2679. }
  2680. return Ok(JsonView(false, "国交部消息提示正在开发中......"));
  2681. }
  2682. else if (department.Equals("财务部"))//总经办
  2683. {
  2684. #region 团组收款数据
  2685. var groupCollectionData = await _sqlSugar.Queryable<Fin_ForeignReceivables>()
  2686. .LeftJoin<Sys_Users>((fr, u) => fr.CreateUserId == u.Id)
  2687. .LeftJoin<Grp_DelegationInfo>((fr, u, di) => fr.Diid == di.Id)
  2688. .LeftJoin<Sys_SetData>((fr, u, di, sd) => fr.Currency == sd.Id)
  2689. .Where((fr, u, di, sd) => fr.IsDel == 0 && fr.CreateTime >= startDateTime && fr.CreateTime <= endDateTime)
  2690. .Select((fr, u, di, sd) => new
  2691. {
  2692. fr.PriceName,
  2693. fr.Price,
  2694. fr.Count,
  2695. fr.Unit,
  2696. fr.ItemSumPrice,
  2697. Currency = sd.Name,
  2698. GroupName = di.TeamName,
  2699. fr.CreateUserId,
  2700. CreateUserName = u.CnName,
  2701. fr.CreateTime,
  2702. })
  2703. .ToListAsync();
  2704. var groupCollectionGroups = groupCollectionData.GroupBy(x => x.CreateUserId)
  2705. .Select(g => new
  2706. {
  2707. uId = g.Key,
  2708. name = g.ToList().FirstOrDefault()?.CreateUserName ?? "-",
  2709. msgTips = $"上月累计团组收款共{g.Count()}条",
  2710. userTourGuideData = g.ToList(),
  2711. Count = g.Count()
  2712. });
  2713. var groupCollectionData1 = new
  2714. {
  2715. msgTips = $"上月累计团组收款共{groupCollectionData.Count}条",
  2716. Data = groupCollectionGroups,
  2717. };
  2718. #endregion
  2719. #region 日付申请未审核数据
  2720. var dailyPaymentData = await _sqlSugar.Queryable<Fin_DailyFeePayment>()
  2721. .LeftJoin<Sys_Users>((dfp, u) => dfp.CreateUserId == u.Id)
  2722. .Where(dfp => dfp.IsDel == 0 &&
  2723. dfp.MAudit == 0 &&
  2724. dfp.CreateTime >= currStartDate &&
  2725. dfp.CreateTime <= currEntDate
  2726. )
  2727. .OrderBy(dfp => dfp.CreateTime, OrderByType.Desc)
  2728. //.OrderBy(dfp => dfp.FAudit, OrderByType.Desc)
  2729. .Select((dfp, u) => new
  2730. {
  2731. id = dfp.Id,
  2732. amountName = dfp.Instructions,
  2733. amount = dfp.SumPrice,
  2734. fAuditStatus = dfp.FAudit == 1 ? "审核通过" :
  2735. dfp.FAudit == 2 ? "审核未通过" : "未审核",
  2736. fAuditDate = dfp.FAuditDate,
  2737. dfp.CreateUserId,
  2738. CreateUserName = u.CnName,
  2739. dfp.CreateTime
  2740. })
  2741. .ToListAsync();
  2742. var dailyPaymentGroups = dailyPaymentData.GroupBy(x => x.CreateUserId)
  2743. .Select(g => new
  2744. {
  2745. uId = g.Key,
  2746. name = g.ToList().FirstOrDefault()?.CreateUserName ?? "-",
  2747. msgTips = $"本年有{g.Count()}条未审核日常付款申请条",
  2748. userTourGuideData = g.ToList(),
  2749. Count = g.Count()
  2750. });
  2751. var dailyPaymentData1 = new
  2752. {
  2753. msgTips = $"本年有{dailyPaymentData.Count()}条未审核日常付款申请条",
  2754. Data = dailyPaymentGroups,
  2755. };
  2756. #endregion
  2757. return Ok(JsonView(new { groupCollectionData = groupCollectionData1, dailyPaymentData = dailyPaymentData1 }));
  2758. }
  2759. return Ok(JsonView(false, "其余部门消息提示正在开发者中......"));
  2760. }
  2761. return Ok(JsonView(false));
  2762. }
  2763. #endregion
  2764. }
  2765. }