SystemController.cs 136 KB

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