SystemController.cs 98 KB

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