SystemController.cs 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729
  1. using AutoMapper.Execution;
  2. using Google.Protobuf.WellKnownTypes;
  3. using Microsoft.AspNetCore.Mvc.Formatters;
  4. using Microsoft.AspNetCore.Mvc.ModelBinding;
  5. using Newtonsoft.Json.Linq;
  6. using OASystem.Domain.Dtos.System;
  7. using Org.BouncyCastle.Asn1.Cms;
  8. using System.Collections;
  9. using System.Xml.Linq;
  10. using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
  11. namespace OASystem.API.Controllers
  12. {
  13. /// <summary>
  14. /// 系统设置
  15. /// </summary>
  16. //[Authorize]
  17. [Route("api/[controller]/[action]")]
  18. public class SystemController : ControllerBase
  19. {
  20. private readonly CompanyRepository _syscomRep;
  21. private readonly DepartmentRepository _sysDepRep;
  22. private readonly UsersRepository _userRep;
  23. private readonly IMapper _mapper;
  24. private readonly MessageRepository _messageRep;
  25. private readonly SetDataRepository _setDataRepository;
  26. private readonly SystemMenuPermissionRepository _SystemMenuPermissionRepository;
  27. private readonly CompanyRepository _CompanyRepository;
  28. private readonly PageFunctionPermissionRepository _PageFunctionPermissionRepository;
  29. private readonly SystemMenuAndFunctionRepository _SystemMenuAndFunctionRepository;
  30. private readonly JobPostAuthorityRepository _JobPostAuthorityRepository;
  31. private readonly JobPostRepository _jobRep;
  32. private readonly SetDataTypeRepository _setDataTypeRep;
  33. private readonly UserAuthorityRepository _UserAuthorityRepository;
  34. public SystemController( CompanyRepository syscom, DepartmentRepository sysDepRep, UsersRepository userRep,
  35. IMapper mapper, SetDataRepository setDataRepository, CompanyRepository companyRepository,
  36. SystemMenuPermissionRepository systemMenuPermissionRepository, PageFunctionPermissionRepository pageFunctionPermissionRepository,
  37. SystemMenuAndFunctionRepository systemMenuAndFunctionRepository, JobPostAuthorityRepository jobPostAuthorityRepository,
  38. JobPostRepository jobRep,UserAuthorityRepository userAuthorityRepository, MessageRepository messageRep,SetDataTypeRepository setDataTypeRep)
  39. {
  40. _syscomRep = syscom;
  41. _sysDepRep = sysDepRep;
  42. _messageRep = messageRep;
  43. _userRep = userRep;
  44. _mapper = mapper;
  45. _setDataRepository = setDataRepository;
  46. _CompanyRepository = companyRepository;
  47. _SystemMenuPermissionRepository = systemMenuPermissionRepository;
  48. _PageFunctionPermissionRepository = pageFunctionPermissionRepository;
  49. _SystemMenuAndFunctionRepository = systemMenuAndFunctionRepository;
  50. _JobPostAuthorityRepository = jobPostAuthorityRepository;
  51. _UserAuthorityRepository = userAuthorityRepository;
  52. _jobRep = jobRep;
  53. _setDataTypeRep = setDataTypeRep;
  54. }
  55. #region 消息
  56. /// <summary>
  57. /// 获取消息列表
  58. /// </summary>
  59. /// <param name="dto"></param>
  60. /// <returns></returns>
  61. [HttpPost]
  62. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  63. public async Task<IActionResult> GetMsgList(MsgDto dto)
  64. {
  65. var msgData = await _messageRep.GetMsgList(dto);
  66. if (msgData.Code != 0)
  67. {
  68. return Ok(JsonView(false, msgData.Msg));
  69. }
  70. return Ok(JsonView(true,"成功", msgData.Data));
  71. }
  72. /// <summary>
  73. /// 获取消息详细信息
  74. /// </summary>
  75. /// <param name="dto"></param>
  76. /// <returns></returns>
  77. [HttpPost]
  78. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  79. public async Task<IActionResult> GetMsgInfo(MsgInfoDto dto)
  80. {
  81. var msgData = await _messageRep.GetMsgInfo(dto);
  82. if (msgData.Code != 0)
  83. {
  84. return Ok(JsonView(false, msgData.Msg));
  85. }
  86. return Ok(JsonView(true, msgData.Data));
  87. }
  88. /// <summary>
  89. /// 消息设置已读
  90. /// </summary>
  91. /// <param name="dto"></param>
  92. /// <returns></returns>
  93. [HttpPost]
  94. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  95. public async Task<IActionResult> SetMessageRead(MsgSetReadDto dto)
  96. {
  97. var msgData = await _messageRep.SetMsgRead(dto);
  98. if (msgData.Code != 0)
  99. {
  100. return Ok(JsonView(false, msgData.Msg));
  101. }
  102. return Ok(JsonView(true, msgData.Data));
  103. }
  104. /// <summary>
  105. /// 消息设置已读
  106. /// </summary>
  107. /// <param name="dto"></param>
  108. /// <returns></returns>
  109. [HttpPost]
  110. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  111. public async Task<IActionResult> DeleMsg(MsgDeleteDto dto)
  112. {
  113. var msgData = await _messageRep.DelMsg(dto);
  114. if (msgData.Code != 0)
  115. {
  116. return Ok(JsonView(false, msgData.Msg));
  117. }
  118. return Ok(JsonView(true, msgData.Data));
  119. }
  120. #endregion
  121. #region 数据类型资料
  122. /// <summary>
  123. /// 根据类型查询数据
  124. /// </summary>
  125. /// <param name="dto"></param>
  126. /// <returns></returns>
  127. [HttpPost]
  128. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  129. public async Task<IActionResult> QuerySetData(SetDataDto dto)
  130. {
  131. try
  132. {
  133. if (dto.DataType == 0)
  134. {
  135. return Ok(JsonView(false, "请传类型Id!"));
  136. }
  137. var setData = _setDataRepository.QueryDto<Sys_SetData, SetDataView>(s => s.STid == dto.DataType && s.IsDel==0).ToList();
  138. if (setData.Count == 0)
  139. {
  140. return Ok(JsonView(false, "暂无数据!"));
  141. }
  142. return Ok(JsonView(true, "查询成功!", setData));
  143. }
  144. catch (Exception ex)
  145. {
  146. return Ok(JsonView(false, "程序错误!"));
  147. throw;
  148. }
  149. }
  150. /// <summary>
  151. /// 数据类型表查询
  152. /// </summary>
  153. /// <param name="dto"></param>
  154. /// <returns></returns>
  155. [HttpPost]
  156. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  157. public async Task<IActionResult> QuerySetDataType(SetDataTypeDto dto)
  158. {
  159. try
  160. {
  161. Result setDataType = await _setDataTypeRep.QuerySetDataType(dto);
  162. if (setDataType.Code == 0)
  163. {
  164. return Ok(JsonView(true, "查询成功", setDataType.Data));
  165. }
  166. else
  167. {
  168. return Ok(JsonView(false, setDataType.Msg));
  169. }
  170. }
  171. catch (Exception)
  172. {
  173. return Ok(JsonView(false, "程序错误!"));
  174. throw;
  175. }
  176. }
  177. /// <summary>
  178. /// 数据类型表操作(Status:1.新增,2.修改)
  179. /// </summary>
  180. /// <param name="dto"></param>
  181. /// <returns></returns>
  182. [HttpPost]
  183. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  184. public async Task<IActionResult> OperationSetDataType(OperationSetDataTypeDto dto)
  185. {
  186. try
  187. {
  188. if (dto.Name == "")
  189. {
  190. return Ok(JsonView(false, "请检查类型名称是否填写!"));
  191. }
  192. Result result = await _setDataTypeRep.OperationSetDataType(dto);
  193. if (result.Code != 0)
  194. {
  195. return Ok(JsonView(false, result.Msg));
  196. }
  197. return Ok(JsonView(true, result.Msg));
  198. }
  199. catch (Exception ex)
  200. {
  201. return Ok(JsonView(false, "程序错误!"));
  202. throw;
  203. }
  204. }
  205. /// <summary>
  206. /// 数据类型表操作删除
  207. /// </summary>
  208. /// <param name="dto"></param>
  209. /// <returns></returns>
  210. [HttpPost]
  211. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  212. public async Task<IActionResult> DelSetDataType(DelSetDataTypeDto dto)
  213. {
  214. try
  215. {
  216. var res = await _setDataTypeRep.SoftDeleteByIdAsync<Sys_SetDataType>(dto.Id.ToString(), dto.DeleteUserId);
  217. if (!res)
  218. {
  219. return Ok(JsonView(false, "删除失败"));
  220. }
  221. return Ok(JsonView(true, "删除成功!"));
  222. }
  223. catch (Exception ex)
  224. {
  225. return Ok(JsonView(false, "程序错误!"));
  226. throw;
  227. }
  228. }
  229. #endregion
  230. #region 数据类型板块
  231. /// <summary>
  232. /// 数据类型板块表查询
  233. /// </summary>
  234. /// <param name="dto"></param>
  235. /// <returns></returns>
  236. [HttpPost]
  237. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  238. public async Task<IActionResult> QuerySetDataInfo(SetDataIDto dto)
  239. {
  240. try
  241. {
  242. Result setData = await _setDataRepository.QuerySetData(dto);
  243. if (setData.Code == 0)
  244. {
  245. return Ok(JsonView(true, "查询成功", setData.Data));
  246. }
  247. else
  248. {
  249. return Ok(JsonView(false, setData.Msg));
  250. }
  251. }
  252. catch (Exception)
  253. {
  254. return Ok(JsonView(false, "程序错误!"));
  255. throw;
  256. }
  257. }
  258. /// <summary>
  259. /// 数据类型板块表操作(Status:1.新增,2.修改)
  260. /// </summary>
  261. /// <param name="dto"></param>
  262. /// <returns></returns>
  263. [HttpPost]
  264. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  265. public async Task<IActionResult> OperationSetData(OperationSetDataDto dto)
  266. {
  267. try
  268. {
  269. if (dto.Name == "")
  270. {
  271. return Ok(JsonView(false, "请检查板块名称是否填写!"));
  272. }
  273. Result result = await _setDataRepository.OperationSetData(dto);
  274. if (result.Code != 0)
  275. {
  276. return Ok(JsonView(false, result.Msg));
  277. }
  278. return Ok(JsonView(true, result.Msg));
  279. }
  280. catch (Exception ex)
  281. {
  282. return Ok(JsonView(false, "程序错误!"));
  283. throw;
  284. }
  285. }
  286. /// <summary>
  287. /// 数据类型表操作删除
  288. /// </summary>
  289. /// <param name="dto"></param>
  290. /// <returns></returns>
  291. [HttpPost]
  292. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  293. public async Task<IActionResult> DelSetData(DelSetDataDto dto)
  294. {
  295. try
  296. {
  297. var res = await _setDataRepository.SoftDeleteByIdAsync<Sys_SetData>(dto.Id.ToString(), dto.DeleteUserId);
  298. if (!res)
  299. {
  300. return Ok(JsonView(false, "删除失败"));
  301. }
  302. return Ok(JsonView(true, "删除成功!"));
  303. }
  304. catch (Exception ex)
  305. {
  306. return Ok(JsonView(false, "程序错误!"));
  307. throw;
  308. }
  309. }
  310. #endregion
  311. #region 企业操作
  312. /// <summary>
  313. /// 查询企业数据
  314. /// </summary>
  315. /// <param name="dto"></param>
  316. /// <returns></returns>
  317. [HttpPost]
  318. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  319. public async Task<IActionResult> getCompanyList(DtoBase dto)
  320. {
  321. try
  322. {
  323. if (dto.PortType == 1)
  324. {
  325. var CompanyDataResult = _CompanyRepository.GetCompanyData();
  326. if (CompanyDataResult.Code != 0)
  327. {
  328. return Ok(JsonView(CompanyDataResult.Msg));
  329. }
  330. List<CompanyView> companyListView = _mapper.Map<List<CompanyView>>(CompanyDataResult.Data);
  331. for (int i = 0; i < companyListView.Count; i++)
  332. {
  333. if (companyListView[i].ParentCompanyId != 0)
  334. {
  335. companyListView[i].ParentCompanyName = companyListView.Find(x => x.Id == companyListView[i].ParentCompanyId).CompanyName;
  336. }
  337. if (companyListView[i].ContactUserId!=0)
  338. {
  339. var user = _userRep.QueryDto<Sys_Users,UserInfoWebView>(x => x.Id == companyListView[i].ContactUserId).ToList();
  340. if (user.Count!=0)
  341. {
  342. companyListView[i].ContactUserName = user[0].CnName;
  343. }
  344. }
  345. }
  346. return Ok(JsonView(true, "查询成功!", companyListView));
  347. }
  348. else if (dto.PortType == 2)
  349. {
  350. var CompanyDataResult = _CompanyRepository.GetCompanyData();
  351. if (CompanyDataResult.Code != 0)
  352. {
  353. return Ok(JsonView(CompanyDataResult.Msg));
  354. }
  355. return Ok(JsonView(true,"查询成功!", CompanyDataResult.Data));
  356. }
  357. else if (dto.PortType == 3)
  358. {
  359. return Ok(JsonView(false, "暂无数据!"));
  360. }
  361. else
  362. {
  363. return Ok(JsonView(false, "暂无数据!"));
  364. }
  365. }
  366. catch (Exception ex)
  367. {
  368. return Ok(JsonView(false, "程序错误!"));
  369. throw;
  370. }
  371. }
  372. /// <summary>
  373. /// 添加企业数据
  374. /// </summary>
  375. /// <param name="dto"></param>
  376. /// <returns></returns>
  377. [HttpPost]
  378. [ProducesResponseType(typeof(JsonView),StatusCodes.Status200OK)]
  379. public async Task<IActionResult> AddCompany(AddCompanyDto dto)
  380. {
  381. try
  382. {
  383. if (string.IsNullOrWhiteSpace(dto.CompanyName) || dto.CreateUserId == 0 || string.IsNullOrWhiteSpace(dto.CompanyCode))
  384. {
  385. return Ok(JsonView(false, "请检查信息是否输入完整!"));
  386. }
  387. else if (string.IsNullOrWhiteSpace(dto.Tel))
  388. {
  389. return Ok(JsonView(false, "请检查联系方式是否输入正确!"));
  390. }
  391. else
  392. {
  393. Sys_Company _Company = _mapper.Map<Sys_Company>(dto);
  394. int id = await _syscomRep.AddAsyncReturnId(_Company);
  395. if (id == 0)
  396. {
  397. return Ok(JsonView(false, "添加失败!"));
  398. }
  399. return Ok(JsonView(true,"添加成功", new { Id = id }));
  400. }
  401. }
  402. catch (Exception)
  403. {
  404. return Ok(JsonView(false, "程序错误!"));
  405. throw;
  406. }
  407. }
  408. /// <summary>
  409. /// 企业修改
  410. /// </summary>
  411. /// <param name="dto"></param>
  412. /// <returns></returns>
  413. [HttpPost]
  414. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  415. public async Task<IActionResult>EditCompany(EditCompanyDto dto)
  416. {
  417. try
  418. {
  419. if (string.IsNullOrWhiteSpace(dto.CompanyName) || string.IsNullOrWhiteSpace(dto.CompanyCode) || string.IsNullOrWhiteSpace(dto.Address) || dto.ContactUserId == 0)
  420. {
  421. return Ok(JsonView(false, "请检查信息是否输入完整!"));
  422. }
  423. else if (string.IsNullOrWhiteSpace(dto.Tel))
  424. {
  425. return Ok(JsonView(false, "请检查联系方式是否输入正确!"));
  426. }
  427. else
  428. {
  429. bool res = await _syscomRep.UpdateAsync(a => a.Id == dto.Id, a => new Sys_Company
  430. {
  431. CompanyName = dto.CompanyName,
  432. CompanyCode = dto.CompanyCode,
  433. Address = dto.Address,
  434. ParentCompanyId = dto.ParentCompanyId,
  435. Tel = dto.Tel,
  436. ContactUserId = dto.ContactUserId,
  437. Remark=dto.Remark,
  438. });
  439. if (!res) { return Ok(JsonView(false, "修改失败")); }
  440. return Ok(JsonView(true,"修改成功!"));
  441. }
  442. }
  443. catch (Exception)
  444. {
  445. return Ok(JsonView(false, "程序错误!"));
  446. throw;
  447. }
  448. }
  449. /// <summary>
  450. /// 企业删除
  451. /// </summary>
  452. /// <param name="dto"></param>
  453. /// <returns></returns>
  454. [HttpPost]
  455. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  456. public async Task<IActionResult> DelCompany(DelCompanyDto dto)
  457. {
  458. try
  459. {
  460. bool res = await _syscomRep.SoftDeleteAsync<Sys_Company>(dto.Id.ToString());
  461. if (!res) { return Ok(JsonView(false, "删除失败")); }
  462. return Ok(JsonView(true, "删除成功"));
  463. }
  464. catch (Exception)
  465. {
  466. return Ok(JsonView(false, "程序错误!"));
  467. throw;
  468. }
  469. }
  470. #endregion
  471. #region 部门操作
  472. /// <summary>
  473. /// 查询部门数据
  474. /// </summary>
  475. /// <param name="dto"></param>
  476. /// <returns></returns>
  477. [HttpPost]
  478. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  479. public async Task<IActionResult> QueryDepartmentList(DepartmentDto dto)
  480. {
  481. try
  482. {
  483. if (dto.PortType==1)
  484. {
  485. if (dto.CompanyId!=0)
  486. {
  487. var result = _sysDepRep.QueryDto<Sys_Department, DepartmentIView>(s => s.CompanyId == dto.CompanyId).ToList();
  488. if (result.Count == 0)
  489. {
  490. return Ok(JsonView(false, "暂无数据!"));
  491. }
  492. for (int i = 0; i < result.Count; i++)
  493. {
  494. if (result[i].ParentDepId != 0)
  495. {
  496. result[i].ParentDepName = result.Find(x => x.Id == result[i].ParentDepId).ParentDepName;
  497. }
  498. var company = _sysDepRep.QueryDto<Sys_Company, CompanyView>(s => s.Id == result[i].CompanyId).ToList();
  499. if (company.Count != 0)
  500. {
  501. result[i].CompanyName = company[0].CompanyName;
  502. }
  503. return Ok(JsonView(true, "查询成功!", result));
  504. }
  505. }
  506. else
  507. {
  508. var result = _sysDepRep.QueryDto<Sys_Department, DepartmentIView>(s => s.IsDel <=1).ToList();
  509. if (result.Count == 0)
  510. {
  511. return Ok(JsonView(false, "暂无数据!"));
  512. }
  513. for (int i = 0; i < result.Count; i++)
  514. {
  515. if (result[i].ParentDepId != 0)
  516. {
  517. result[i].ParentDepName = result.Find(x => x.Id == result[i].ParentDepId).ParentDepName;
  518. }
  519. var company = _sysDepRep.QueryDto<Sys_Company, CompanyView>(s => s.Id == result[i].CompanyId).ToList();
  520. if (company.Count != 0)
  521. {
  522. result[i].CompanyName = company[0].CompanyName;
  523. }
  524. }
  525. return Ok(JsonView(true, "查询成功!", result));
  526. }
  527. return Ok(JsonView(false, "暂无数据!"));
  528. }
  529. else if (dto.PortType==2)
  530. {
  531. var result = _sysDepRep.QueryDto<Sys_Department, DepartmentIView>(s => s.CompanyId == dto.CompanyId).ToList();
  532. if (result.Count == 0)
  533. {
  534. return Ok(JsonView(false, "暂无数据!"));
  535. }
  536. return Ok(JsonView(true,"查询成功!",result));
  537. }
  538. else if (dto.PortType == 3)
  539. {
  540. return Ok(JsonView(false, "暂无数据!"));
  541. }
  542. else
  543. {
  544. return Ok(JsonView(false, "暂无数据!"));
  545. }
  546. }
  547. catch (Exception ex)
  548. {
  549. return Ok(JsonView(false, "程序错误!"));
  550. throw;
  551. }
  552. }
  553. /// <summary>
  554. /// 部门添加
  555. /// </summary>
  556. /// <param name="dto"></param>
  557. /// <returns></returns>
  558. [HttpPost]
  559. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  560. public async Task<IActionResult> AddDepartment(AddDepartmentDto dto)
  561. {
  562. try
  563. {
  564. if (dto.CreateUserId == 0 || string.IsNullOrWhiteSpace(dto.DepName) || dto.CompanyId == 0 || string.IsNullOrWhiteSpace(dto.DepCode))
  565. {
  566. return Ok(JsonView(false, "请检查信息是否输入完整!"));
  567. }
  568. else
  569. {
  570. Sys_Department _Department = _mapper.Map<Sys_Department>(dto);
  571. int id = await _sysDepRep.AddAsyncReturnId(_Department);
  572. if (id == 0)
  573. {
  574. return Ok(JsonView(false, "添加失败!"));
  575. }
  576. return Ok(JsonView(true, "添加成功!", new { Id = id }));
  577. }
  578. }
  579. catch (Exception)
  580. {
  581. return Ok(JsonView(false, "程序错误!"));
  582. throw;
  583. }
  584. }
  585. /// <summary>
  586. /// 部门修改
  587. /// </summary>
  588. /// <param name="dto"></param>
  589. /// <returns></returns>
  590. [HttpPost]
  591. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  592. public async Task<IActionResult> EditDepartment(EditDepartmentDto dto)
  593. {
  594. try
  595. {
  596. if (dto.Id==0 || string.IsNullOrWhiteSpace(dto.DepName) || dto.CompanyId == 0 || string.IsNullOrWhiteSpace(dto.DepCode))
  597. {
  598. return Ok(JsonView(false, "请检查信息是否输入完整!"));
  599. }
  600. else
  601. {
  602. bool res = await _sysDepRep.UpdateAsync<Sys_Department>(a => a.Id == dto.Id, a => new Sys_Department
  603. {
  604. CompanyId=dto.CompanyId,
  605. DepCode=dto.DepCode,
  606. DepName=dto.DepName,
  607. ParentDepId=dto.ParentDepId,
  608. Remark=dto.Remark,
  609. });
  610. if (!res)
  611. {
  612. return Ok(JsonView(false, "修改失败!"));
  613. }
  614. return Ok(JsonView(true, "修改成功!"));
  615. }
  616. }
  617. catch (Exception)
  618. {
  619. return Ok(JsonView(false, "程序错误!"));
  620. throw;
  621. }
  622. }
  623. /// <summary>
  624. /// 部门删除
  625. /// </summary>
  626. /// <param name="dto"></param>
  627. /// <returns></returns>
  628. [HttpPost]
  629. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  630. public async Task<IActionResult> DelDepartment(DelDepartmentDto dto)
  631. {
  632. try
  633. {
  634. if (dto.Id == 0)
  635. {
  636. return Ok(JsonView(-1, "请检查信息是否输入完整!", null));
  637. }
  638. else
  639. {
  640. bool res =await _sysDepRep.SoftDeleteAsync<Sys_Department>(dto.Id.ToString());
  641. if (!res)
  642. {
  643. return Ok(JsonView(false, "删除失败!"));
  644. }
  645. return Ok(JsonView(true, "删除成功!"));
  646. }
  647. }
  648. catch (Exception)
  649. {
  650. return Ok(JsonView(false, "程序错误!"));
  651. throw;
  652. }
  653. }
  654. #endregion
  655. #region 岗位板块
  656. /// <summary>
  657. /// 岗位查询
  658. /// </summary>
  659. /// <param name="dto"></param>
  660. /// <returns></returns>
  661. [HttpPost]
  662. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  663. public async Task<IActionResult> QueryJobPost(QueryJobPostDto dto)
  664. {
  665. try
  666. {
  667. if (dto.PortType == 1)
  668. {
  669. string sqlWhere = string.Empty;
  670. if (dto.CompanyId != 0)
  671. {
  672. sqlWhere += string.Format(@" And jp.CompanyId={0}", dto.CompanyId);
  673. }
  674. if (dto.DepId != 0)
  675. {
  676. sqlWhere += string.Format(@" And jp.DepId={0}", dto.DepId);
  677. }
  678. sqlWhere += string.Format(@" And jp.IsDel={0}", 0);
  679. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  680. {
  681. Regex r = new Regex("And");
  682. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  683. }
  684. List<Sys_JobPostI> jobList = await _jobRep.QueryJobPost(sqlWhere);
  685. List<JobPostView> List = _mapper.Map<List<JobPostView>>(jobList);
  686. if (jobList.Count == 0)
  687. {
  688. return Ok(JsonView(false, "暂无数据!"));
  689. }
  690. return Ok(JsonView(true, "查询成功!", jobList));
  691. }
  692. else if (dto.PortType == 2)
  693. {
  694. var result = _jobRep.QueryDto<Sys_JobPost, JobPostView>(s => s.CompanyId == dto.CompanyId && s.DepId==dto.DepId).ToList();
  695. if (result.Count == 0)
  696. {
  697. return Ok(JsonView(false, "暂无数据!"));
  698. }
  699. return Ok(JsonView(true, "查询成功!", result));
  700. }
  701. else if (dto.PortType == 3)
  702. {
  703. return Ok(JsonView(false, "暂无数据!"));
  704. }
  705. else
  706. {
  707. return Ok(JsonView(false, "暂无数据!"));
  708. }
  709. }
  710. catch (Exception ex)
  711. {
  712. return Ok(JsonView(false, "程序错误!"));
  713. throw;
  714. }
  715. }
  716. /// <summary>
  717. /// 添加岗位
  718. /// </summary>
  719. /// <param name="dto"></param>
  720. /// <returns></returns>
  721. [HttpPost]
  722. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  723. public async Task<IActionResult> AddJobPost(AddJobPostDto dto)
  724. {
  725. try
  726. {
  727. Sys_JobPost sys_Job = _mapper.Map<Sys_JobPost>(dto);
  728. int id = await _jobRep.AddAsyncReturnId(sys_Job);
  729. if (id == 0)
  730. {
  731. return Ok(JsonView(false, "添加失败"));
  732. }
  733. return Ok(JsonView(true, "添加成功", new { Id = id }));
  734. }
  735. catch (Exception ex)
  736. {
  737. return Ok(JsonView(false, "程序错误!"));
  738. throw;
  739. }
  740. }
  741. /// <summary>
  742. /// 修改岗位
  743. /// </summary>
  744. /// <param name="dto"></param>
  745. /// <returns></returns>
  746. [HttpPost]
  747. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  748. public async Task<IActionResult> EditJobPost(EditJobPostDto dto)
  749. {
  750. try
  751. {
  752. bool res = await _jobRep.UpdateAsync<Sys_JobPost>(a=>a.Id==dto.Id,a =>new Sys_JobPost
  753. {
  754. CompanyId=dto.CompanyId,
  755. DepId=dto.DepId,
  756. JobName=dto.JobName,
  757. Remark=dto.Remark,
  758. });
  759. if (!res)
  760. {
  761. return Ok(JsonView(false, "修改失败"));
  762. }
  763. return Ok(JsonView(true, "修改成功"));
  764. }
  765. catch (Exception ex)
  766. {
  767. return Ok(JsonView(false, "程序错误!"));
  768. throw;
  769. }
  770. }
  771. /// <summary>
  772. /// 删除岗位
  773. /// </summary>
  774. /// <param name="dto"></param>
  775. /// <returns></returns>
  776. [HttpPost]
  777. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  778. public async Task<IActionResult> DelJobPost(DelJobPostDto dto)
  779. {
  780. try
  781. {
  782. bool res = await _jobRep.SoftDeleteAsync<Sys_JobPost>(dto.Id.ToString());
  783. if (!res)
  784. {
  785. return Ok(JsonView(false, "删除失败!"));
  786. }
  787. return Ok(JsonView(true, "删除成功"));
  788. }
  789. catch (Exception)
  790. {
  791. return Ok(JsonView(false, "程序错误!"));
  792. throw;
  793. }
  794. }
  795. #endregion
  796. #region 用户操作
  797. /// <summary>
  798. /// 查询所有员工名称
  799. /// </summary>
  800. /// <param name="dto"></param>
  801. /// <returns></returns>
  802. [HttpPost]
  803. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  804. public async Task<IActionResult> GetUserNameList(DtoBase dto)
  805. {
  806. try
  807. {
  808. var result = _userRep.GetUserNameList(dto.PortType);
  809. if (result.Result.Code != 0)
  810. {
  811. return Ok(JsonView(false, "暂无数据!"));
  812. }
  813. return Ok(JsonView(true, "查询成功!", result.Result.Data));
  814. }
  815. catch (Exception)
  816. {
  817. return Ok(JsonView(false, "程序错误!"));
  818. throw;
  819. }
  820. }
  821. /// <summary>
  822. /// 查询所有员工(web)
  823. /// </summary>
  824. /// <param name="dto"></param>
  825. /// <returns></returns>
  826. [HttpPost]
  827. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  828. public async Task<IActionResult> GetUserList(DtoBase dto)
  829. {
  830. try
  831. {
  832. var result = _userRep.GetUserList(dto.PortType, string.Empty);
  833. if (result.Result.Code != 0)
  834. {
  835. return Ok(JsonView(false, "暂无数据!"));
  836. }
  837. return Ok(JsonView(true, "查询成功!", result.Result.Data));
  838. }
  839. catch (Exception)
  840. {
  841. return Ok(JsonView(false, "程序错误!"));
  842. throw;
  843. }
  844. }
  845. /// <summary>
  846. /// 查询用户数据
  847. /// </summary>
  848. /// <param name="dto"></param>
  849. /// <returns></returns>
  850. [HttpPost]
  851. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  852. public async Task<IActionResult> QueryUserList(UserDto dto)
  853. {
  854. try
  855. {
  856. string sqlWhere = string.Format(" Where su.IsDel = 0 ");
  857. if (dto.CompanyId!=0)
  858. {
  859. sqlWhere += string.Format(@" And su.CompanyId={0}", dto.CompanyId);
  860. }
  861. if (dto.DepId != 0)
  862. {
  863. sqlWhere += string.Format(@" And su.DepId={0}", dto.DepId);
  864. }
  865. if (dto.JobPostId != 0)
  866. {
  867. sqlWhere += string.Format(@" And su.JobPostId={0}", dto.JobPostId);
  868. }
  869. List<UserInfo> _userList =await _userRep.QueryUser(sqlWhere);
  870. if (_userList.Count == 0)
  871. {
  872. return Ok(JsonView(false, "暂无数据!"));
  873. }
  874. List<UserInfoWebView> userList = _mapper.Map<List<UserInfoWebView>>(_userList);
  875. return Ok(JsonView(true,"查询成功!", userList));
  876. }
  877. catch (Exception)
  878. {
  879. return Ok(JsonView(false, "程序错误!"));
  880. throw;
  881. }
  882. }
  883. /// <summary>
  884. /// 修改用户信息(上级修改/分配 公司、部门、岗位、工号等信息)
  885. /// </summary>
  886. /// <param name="dto"></param>
  887. /// <returns></returns>
  888. [HttpPost]
  889. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  890. public async Task<IActionResult> EditUser(EditUserDto dto)
  891. {
  892. try
  893. {
  894. bool res = await _userRep.UpdateAsync<Sys_Users>(a => a.Id == dto.Id, a => new Sys_Users
  895. {
  896. Number = dto.Number,
  897. CompanyId = dto.CompanyId,
  898. DepId = dto.DepId,
  899. JobPostId = dto.JobPostId,
  900. Ext = dto.Ext,
  901. UsePeriod = dto.UsePeriod,
  902. HrAudit = dto.HrAudit
  903. });
  904. if (!res)
  905. {
  906. return Ok(JsonView(false, "修改失败!"));
  907. }
  908. return Ok(JsonView(true, "修改成功!"));
  909. }
  910. catch (Exception)
  911. {
  912. return Ok(JsonView(false, "程序错误!"));
  913. throw;
  914. }
  915. }
  916. /// <summary>
  917. /// 修改用户信息(登录用户修改个人信息)
  918. /// </summary>
  919. /// <param name="dto"></param>
  920. /// <returns></returns>
  921. [HttpPost]
  922. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  923. public async Task<IActionResult> EditMyUser(EditMyUserDto dto)
  924. {
  925. try
  926. {
  927. if (string.IsNullOrWhiteSpace(dto.CnName) || string.IsNullOrWhiteSpace(dto.Address) || string.IsNullOrWhiteSpace(dto.IDCard) || dto.Sex != 0 && dto.Sex != 1 ||
  928. string.IsNullOrWhiteSpace(dto.MaritalStatus) || string.IsNullOrWhiteSpace(dto.HomeAddress)|| dto.Birthday>=DateTime.Now.AddYears(-1))
  929. {
  930. return Ok(JsonView(false, "请完善你的个人信息!"));
  931. }
  932. else if (string.IsNullOrWhiteSpace(dto.GraduateInstitutions) || string.IsNullOrWhiteSpace(dto.Professional) || dto.Education == 0 || string.IsNullOrWhiteSpace(dto.GraduateInstitutions))
  933. {
  934. return Ok(JsonView(false, "请完善你的学历信息!"));
  935. }
  936. else if (string.IsNullOrWhiteSpace(dto.Phone) || string.IsNullOrWhiteSpace(dto.UrgentPhone) || string.IsNullOrWhiteSpace(dto.Email))
  937. {
  938. return Ok(JsonView(false, "请检查联系方式、紧急联系人及邮箱输写是否正确!"));
  939. }
  940. else
  941. {
  942. bool res = await _userRep.UpdateAsync<Sys_Users>(a => a.Id == dto.Id, a => new Sys_Users
  943. {
  944. CnName = dto.CnName,
  945. EnName = dto.EnName,
  946. Sex = dto.Sex,
  947. Phone = dto.Phone,
  948. UrgentPhone = dto.UrgentPhone,
  949. Email = dto.Email,
  950. Address = dto.Address,
  951. Edate = dto.Edate,
  952. Birthday = dto.Birthday,
  953. IDCard = dto.IDCard,
  954. GraduateInstitutions = dto.GraduateInstitutions,
  955. Professional = dto.Professional,
  956. Education = dto.Education,
  957. TheOrAdultEducation = dto.TheOrAdultEducation,
  958. MaritalStatus = dto.MaritalStatus,
  959. HomeAddress = dto.HomeAddress,
  960. WorkExperience = dto.WorkExperience,
  961. Certificate = dto.Certificate
  962. });
  963. if (!res)
  964. {
  965. return Ok(JsonView(false, "修改失败!"));
  966. }
  967. return Ok(JsonView(true, "修改成功!"));
  968. }
  969. }
  970. catch (Exception)
  971. {
  972. return Ok(JsonView(false, "程序错误!"));
  973. throw;
  974. }
  975. }
  976. /// <summary>
  977. /// 删除用户信息
  978. /// 即为离职
  979. /// </summary>
  980. /// <param name="dto"></param>
  981. /// <returns></returns>
  982. [HttpPost]
  983. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  984. public async Task<IActionResult> PostUserDelById(UserDelDto dto)
  985. {
  986. try
  987. {
  988. if (dto == null)
  989. {
  990. return Ok(JsonView(false, "参数不能为空!"));
  991. }
  992. bool res = await _userRep.UpdateAsync<Sys_Users>(a => a.Id == dto.Id, a => new Sys_Users
  993. {
  994. IsDel = 1,
  995. DeleteUserId = dto.OperateUserId,
  996. DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  997. Rdate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  998. });
  999. if (!res)
  1000. {
  1001. return Ok(JsonView(false, "操作失败!"));
  1002. }
  1003. return Ok(JsonView(true, "操作成功!"));
  1004. }
  1005. catch (Exception)
  1006. {
  1007. return Ok(JsonView(false, "程序错误!"));
  1008. }
  1009. }
  1010. #endregion
  1011. #region 权限模块
  1012. /// <summary>
  1013. /// 权限数据页面初始化
  1014. /// </summary>
  1015. /// <param name="dto"></param>
  1016. /// <returns></returns>
  1017. //[Authorize]
  1018. [HttpPost]
  1019. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1020. public async Task<IActionResult> GetAuth(AuthDto dto)
  1021. {
  1022. Result result = new Result();
  1023. //模块数据
  1024. var setDataResult = await _setDataRepository.GetSySDefultModule();
  1025. if (setDataResult.Code != 0)
  1026. {
  1027. return Ok(JsonView(setDataResult.Msg));
  1028. }
  1029. //操作方式
  1030. var PageOperation = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, Sys_PageFunctionPermission>(x=>x.IsEnable == 1).ToList();
  1031. //获取所有关联页面
  1032. var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  1033. //页面数据
  1034. var SystemMenuPermissionData = _SystemMenuPermissionRepository.QueryDto<Sys_SystemMenuPermission, SystemMenuPermissionView>(x=>x.Mid == dto.moduleId && x.IsEnable == 1).ToList();
  1035. if (SystemMenuPermissionData == null || SystemMenuPermissionData.Count() == 0)
  1036. {
  1037. return Ok(JsonView("暂无数据"));
  1038. }
  1039. ArrayList viewData = new ArrayList();
  1040. //组合页面数据
  1041. foreach (var item in SystemMenuPermissionData)
  1042. {
  1043. ArrayList ids = new ArrayList();
  1044. foreach (var viewop in PageOperation)
  1045. {
  1046. var op = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.SmId == item.Id && x.FId == viewop.Id);
  1047. if (op != null)
  1048. {
  1049. ids.Add(viewop.Id);
  1050. }
  1051. }
  1052. viewData.Add(new
  1053. {
  1054. Id = item.Id,
  1055. Mid = item.Mid,
  1056. Name = item.Name,
  1057. SystemMenuCode = item.SystemMenuCode,
  1058. opList = ids,
  1059. selList = new string[0]
  1060. }) ;
  1061. }
  1062. //公司数据
  1063. var CompanyDataResult = _CompanyRepository.GetCompanyData();
  1064. if (CompanyDataResult.Code != 0)
  1065. {
  1066. return Ok(JsonView(CompanyDataResult.Msg));
  1067. }
  1068. result.Code = 0;
  1069. result.Msg = "成功!";
  1070. var Dyresult = new
  1071. {
  1072. setDataResult = setDataResult.Data,
  1073. CompanyDataResult = CompanyDataResult.Data,
  1074. SystemMenuPermissionData = viewData,
  1075. PageOperation = PageOperation,
  1076. };
  1077. return Ok(JsonView(200, "成功!", Dyresult));
  1078. }
  1079. /// <summary>
  1080. /// 获取职务权限
  1081. /// </summary>
  1082. /// <param name="dto"></param>
  1083. /// <returns></returns>
  1084. [HttpPost]
  1085. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1086. public IActionResult QueryJobAuth(QueryJobAuthDto dto)
  1087. {
  1088. //选中的操作权限
  1089. var DBdata = _JobPostAuthorityRepository.QueryDto<Sys_JobPostAuthority, JobPostAuthorityView>(x=>x.JpId == dto.jobid).ToList();
  1090. var SystemMenuPermissionData = _SystemMenuPermissionRepository.QueryDto<Sys_SystemMenuPermission, SystemMenuPermissionView>(x => x.Mid == dto.moduleId).ToList();
  1091. if (SystemMenuPermissionData == null || SystemMenuPermissionData.Count() == 0)
  1092. {
  1093. return Ok(JsonView("暂无数据"));
  1094. }
  1095. //所有操作
  1096. var PageOperation = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, Sys_PageFunctionPermission>().ToList();
  1097. //获取所有关联页面
  1098. var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  1099. ArrayList viewData = new ArrayList();
  1100. //组合页面数据
  1101. foreach (var item in SystemMenuPermissionData)
  1102. {
  1103. ArrayList ids = new ArrayList();
  1104. foreach (var viewop in PageOperation)
  1105. {
  1106. var op = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.SmId == item.Id && x.FId == viewop.Id);
  1107. if (op != null)
  1108. {
  1109. ids.Add(viewop.Id);
  1110. }
  1111. }
  1112. //获取本职务的页面拥有的权限
  1113. var DBwhere = DBdata.Where(x => x.SmId == item.Id && x.JpId == dto.jobid).ToList();
  1114. viewData.Add(new
  1115. {
  1116. Id = item.Id,
  1117. Mid = item.Mid,
  1118. Name = item.Name,
  1119. SystemMenuCode = item.SystemMenuCode,
  1120. opList = ids,
  1121. selList = DBwhere.Select(x => x.FId)
  1122. }) ;
  1123. }
  1124. return Ok(JsonView(200, "成功!", viewData));
  1125. }
  1126. /// <summary>
  1127. /// 保存岗位权限
  1128. /// </summary>
  1129. /// <param name="dto"></param>
  1130. /// <returns></returns>
  1131. [HttpPost]
  1132. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1133. public async Task<IActionResult> SaveJobAuth(SaveJobDto dto)
  1134. {
  1135. //获取所有关联页面
  1136. var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  1137. var RemoveJobPostAuthList = _SystemMenuAndFunctionRepository._sqlSugar.SqlQueryable<Sys_JobPostAuthority>($@"
  1138. select a.* from Sys_JobPostAuthority a, Sys_SetData b ,Sys_SystemMenuPermission c
  1139. where a.SmId = c.Id and c.Mid = b.Id and JpId = {dto.Jpid} and c.Mid ={dto.modulId}
  1140. ").ToList();
  1141. List<Sys_JobPostAuthority> adds = new List<Sys_JobPostAuthority>();
  1142. foreach (var item in dto.Savejobs)
  1143. {
  1144. foreach (var fid in item.FIds)
  1145. {
  1146. var whereobj = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.FId == fid && x.SmId == item.SmId);
  1147. if (whereobj != null)
  1148. {
  1149. adds.Add(new Sys_JobPostAuthority
  1150. {
  1151. CreateTime = DateTime.Now,
  1152. CreateUserId = 245,
  1153. FId = fid,
  1154. JpId = dto.Jpid,
  1155. SmId = item.SmId
  1156. });
  1157. }
  1158. }
  1159. }
  1160. _JobPostAuthorityRepository.BeginTran();
  1161. try
  1162. { //删除岗位
  1163. bool isdel = await _JobPostAuthorityRepository.DeletesAsync<Sys_JobPostAuthority>(RemoveJobPostAuthList);
  1164. int UpRows = _JobPostAuthorityRepository.Adds<Sys_JobPostAuthority>(adds);
  1165. //获取所有职位员工
  1166. var jobUserAll = await QueryUserList(new UserDto { PortType = 2, JobPostId = dto.Jpid });
  1167. List<UserInfoWebView> users = null;
  1168. var QueryUserListApiResult = (((jobUserAll as OkObjectResult).Value) as OASystem.Domain.ViewModels.JsonView);
  1169. if (QueryUserListApiResult != null)
  1170. {
  1171. if (QueryUserListApiResult.Code == 200)
  1172. {
  1173. users = QueryUserListApiResult.Data as List<UserInfoWebView>;
  1174. }
  1175. }
  1176. if (users != null && users.Count > 0)
  1177. {
  1178. List<Sys_UserAuthority> userAuth = null;
  1179. var uids = string.Join(',', users.Select(x => x.Id)).TrimEnd(',');
  1180. var RemoveUserAuthorityListAndTemp = _UserAuthorityRepository._sqlSugar.SqlQueryable<Sys_UserAuthority>($@"
  1181. select a.* from Sys_UserAuthority a, Sys_SetData b ,Sys_SystemMenuPermission c
  1182. where a.SmId = c.Id and c.Mid = b.Id and uid in ({uids}) and c.Mid = {dto.modulId} and IsTemp = 1
  1183. ").ToList();
  1184. foreach (var user in users)
  1185. {
  1186. //删除个人级岗位权限
  1187. isdel = await _UserAuthorityRepository.DeletesAsync<Sys_UserAuthority>
  1188. (RemoveUserAuthorityListAndTemp.FindAll(x=>x.UId == user.Id));
  1189. userAuth = adds.Select(x=> new Sys_UserAuthority
  1190. {
  1191. CreateTime = DateTime.Now,
  1192. CreateUserId = 235,
  1193. FId = x.FId,
  1194. SmId = x.SmId,
  1195. UId = user.Id,
  1196. IsTemp = 1,
  1197. }).ToList();
  1198. //添加个人级别岗位
  1199. int AddRows = _UserAuthorityRepository.Adds<Sys_UserAuthority>(userAuth);
  1200. }
  1201. }
  1202. }
  1203. catch (Exception ex)
  1204. {
  1205. _JobPostAuthorityRepository.RollbackTran();
  1206. return Ok(JsonView("系统错误!"));
  1207. }
  1208. _JobPostAuthorityRepository.CommitTran();
  1209. return Ok(JsonView(200, "成功", new { }));
  1210. }
  1211. /// <summary>
  1212. /// 获取员工权限
  1213. /// </summary>
  1214. /// <param name="dto"></param>
  1215. /// <returns></returns>
  1216. [HttpPost]
  1217. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1218. public IActionResult QueryUserAuth(QueryUserAuthDto dto)
  1219. {
  1220. //选中的员工操作权限
  1221. var DBdata = _UserAuthorityRepository.QueryDto<Sys_UserAuthority, UserAuthorityView>(x => x.UId == dto.Userid).ToList();
  1222. var SystemMenuPermissionData = _SystemMenuPermissionRepository.QueryDto<Sys_SystemMenuPermission, SystemMenuPermissionView>(x => x.Mid == dto.moduleId).ToList();
  1223. if (SystemMenuPermissionData == null || SystemMenuPermissionData.Count() == 0)
  1224. {
  1225. return Ok(JsonView("暂无数据"));
  1226. }
  1227. //所有操作
  1228. var PageOperation = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, Sys_PageFunctionPermission>(x=>x.IsEnable == 1).ToList();
  1229. //获取所有关联页面
  1230. var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  1231. ArrayList viewData = new ArrayList();
  1232. //组合页面数据
  1233. foreach (var item in SystemMenuPermissionData)
  1234. {
  1235. ArrayList ids = new ArrayList();
  1236. foreach (var viewop in PageOperation)
  1237. {
  1238. var op = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.SmId == item.Id && x.FId == viewop.Id);
  1239. if (op != null)
  1240. {
  1241. ids.Add(viewop.Id);
  1242. }
  1243. }
  1244. //获取本员工拥有的权限
  1245. var DBwhere = DBdata.Where(x => x.SmId == item.Id && x.UId == dto.Userid).ToList();
  1246. viewData.Add(new
  1247. {
  1248. Id = item.Id,
  1249. Mid = item.Mid,
  1250. Name = item.Name,
  1251. SystemMenuCode = item.SystemMenuCode,
  1252. opList = ids,
  1253. selList = DBwhere.Select(x => x.FId)
  1254. });
  1255. }
  1256. return Ok(JsonView(200, "成功!", viewData));
  1257. }
  1258. /// <summary>
  1259. /// 保存员工权限
  1260. /// </summary>
  1261. /// <param name="dto"></param>
  1262. /// <returns></returns>
  1263. [HttpPost]
  1264. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1265. public async Task<IActionResult> SaveUserAuth(SaveUserDto dto)
  1266. {
  1267. //获取所有关联页面
  1268. var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  1269. //获取用户当前模块所有启用页面
  1270. var userpageList = _SystemMenuPermissionRepository._sqlSugar.SqlQueryable<Sys_UserAuthority>($@"
  1271. select a.* from Sys_UserAuthority a, Sys_SetData b ,Sys_SystemMenuPermission c
  1272. where a.SmId = c.Id and c.Mid = b.Id and uid = {dto.uid} and c.Mid ={dto.Modulid}
  1273. ").ToList();
  1274. List<Sys_UserAuthority> adds = new List<Sys_UserAuthority>();
  1275. foreach (var item in dto.Savejobs)
  1276. {
  1277. foreach (var fid in item.FIds)
  1278. {
  1279. var whereobj = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.FId == fid && x.SmId == item.SmId);
  1280. if (whereobj != null)
  1281. {
  1282. adds.Add(new Sys_UserAuthority
  1283. {
  1284. CreateTime = DateTime.Now,
  1285. CreateUserId = 235,
  1286. FId = fid,
  1287. UId = dto.uid,
  1288. SmId = item.SmId,
  1289. IsTemp = 0
  1290. });
  1291. }
  1292. }
  1293. }
  1294. _JobPostAuthorityRepository.BeginTran();
  1295. try
  1296. {
  1297. List<Sys_UserAuthority> userAuth = null;
  1298. //删除个人级岗位权限
  1299. bool isdel = await _UserAuthorityRepository.DeletesAsync<Sys_UserAuthority>(userpageList);
  1300. userAuth = adds.Select(x => new Sys_UserAuthority
  1301. {
  1302. CreateTime = DateTime.Now,
  1303. CreateUserId = 235,
  1304. FId = x.FId,
  1305. SmId = x.SmId,
  1306. UId = dto.uid,
  1307. IsTemp = 0,
  1308. }).ToList();
  1309. //添加个人级别岗位
  1310. int AddRows = _UserAuthorityRepository.Adds<Sys_UserAuthority>(userAuth);
  1311. }
  1312. catch (Exception ex)
  1313. {
  1314. _JobPostAuthorityRepository.RollbackTran();
  1315. return Ok(JsonView("系统错误!"));
  1316. }
  1317. _JobPostAuthorityRepository.CommitTran();
  1318. return Ok(JsonView(200, "成功", new { }));
  1319. }
  1320. #endregion
  1321. #region 页面配置
  1322. /// <summary>
  1323. /// 页面配置界面数据初始化
  1324. /// </summary>
  1325. /// <returns></returns>
  1326. //[Authorize]
  1327. [HttpPost]
  1328. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1329. public async Task<IActionResult> PageConfigInit()
  1330. {
  1331. ArrayList arr = new ArrayList();
  1332. var viewList = await _setDataRepository.GetSetDataAndPageInfoBySTId();
  1333. if (viewList.Code != 0)
  1334. {
  1335. return Ok(JsonView(viewList.Msg));
  1336. }
  1337. var ModList = await _setDataRepository.GetSySDefultModule();
  1338. return Ok(JsonView(new
  1339. {
  1340. viewList,
  1341. ModList,
  1342. }));
  1343. }
  1344. [HttpPost]
  1345. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1346. public async Task<IActionResult> EditPageInfo(SetDataAndPageInfoView dto)
  1347. {
  1348. JsonView view = null;
  1349. _SystemMenuPermissionRepository.BeginTran();
  1350. var istrue = await _SystemMenuPermissionRepository.UpdateAsync(x=>x.Id == dto.Pageid ,x=> new Sys_SystemMenuPermission
  1351. {
  1352. AndroidUrl = dto.AndroidUrl,
  1353. CreateTime = DateTime.Now,
  1354. Icon = dto.Icon,
  1355. IosUrl = dto.IosUrl,
  1356. Name = dto.PageName,
  1357. PhoneIsEnable = dto.PagePhoneIsEnable,
  1358. CreateUserId = 235,
  1359. IsDel = 0,
  1360. IsEnable = dto.PageIsEnable,
  1361. Mid = dto.Modulid,
  1362. Remark = dto.PageRemark,
  1363. SystemMenuCode = dto.SystemMenuCode,
  1364. WebUrl = dto.WebUrl,
  1365. });
  1366. if (istrue)
  1367. {
  1368. //删除页面绑定的操作后重新绑定
  1369. await _SystemMenuAndFunctionRepository.DeleteAsync(x => x.SmId == dto.Pageid);
  1370. List<Sys_SystemMenuAndFunction> binFun = new List<Sys_SystemMenuAndFunction>();
  1371. foreach (var item in dto.FunArr)
  1372. {
  1373. binFun.Add(new Sys_SystemMenuAndFunction
  1374. {
  1375. CreateTime = DateTime.Now,
  1376. CreateUserId = 235,
  1377. FId = item,
  1378. SmId = dto.Pageid,
  1379. IsDel = 0,
  1380. });
  1381. }
  1382. int number = _SystemMenuAndFunctionRepository.Adds<Sys_SystemMenuAndFunction>(binFun);
  1383. view = JsonView(istrue);
  1384. _SystemMenuPermissionRepository.CommitTran();
  1385. }
  1386. else
  1387. {
  1388. _SystemMenuPermissionRepository.RollbackTran();
  1389. view = JsonView("添加失败");
  1390. }
  1391. return Ok(view);
  1392. }
  1393. /// <summary>
  1394. /// 添加一个页面
  1395. /// </summary>
  1396. /// <param name="dto"></param>
  1397. /// <returns></returns>
  1398. [HttpPost]
  1399. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1400. public async Task<IActionResult> AddPageInfo(SetDataAndPageInfoView dto)
  1401. {
  1402. JsonView view = null;
  1403. _SystemMenuPermissionRepository.BeginTran();
  1404. int number = await _SystemMenuPermissionRepository.AddAsyncReturnId(new Sys_SystemMenuPermission
  1405. {
  1406. AndroidUrl = dto.AndroidUrl,
  1407. CreateTime = DateTime.Now,
  1408. Icon = dto.Icon,
  1409. IosUrl = dto.IosUrl,
  1410. Name = dto.PageName,
  1411. PhoneIsEnable = dto.PagePhoneIsEnable,
  1412. CreateUserId = 235,
  1413. IsDel = 0,
  1414. IsEnable = dto.PageIsEnable,
  1415. Mid = dto.Modulid,
  1416. Remark = dto.PageRemark,
  1417. SystemMenuCode = dto.SystemMenuCode,
  1418. WebUrl = dto.WebUrl,
  1419. });
  1420. List<Sys_SystemMenuAndFunction> binFun = new List<Sys_SystemMenuAndFunction>();
  1421. foreach (var item in dto.FunArr)
  1422. {
  1423. binFun.Add(new Sys_SystemMenuAndFunction
  1424. {
  1425. CreateTime = DateTime.Now,
  1426. CreateUserId = 235,
  1427. FId = item,
  1428. SmId = number,
  1429. IsDel = 0,
  1430. });
  1431. }
  1432. number = _SystemMenuAndFunctionRepository.Adds<Sys_SystemMenuAndFunction>(binFun);
  1433. if (number > 0)
  1434. {
  1435. view = JsonView(number);
  1436. _SystemMenuPermissionRepository.CommitTran();
  1437. }
  1438. else
  1439. {
  1440. _SystemMenuPermissionRepository.RollbackTran();
  1441. view = JsonView("添加失败");
  1442. }
  1443. return Ok(view);
  1444. }
  1445. /// <summary>
  1446. /// 删除页面
  1447. /// </summary>
  1448. /// <param></param>
  1449. /// <returns></returns>
  1450. [HttpPost]
  1451. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1452. public async Task<IActionResult> DelPageInfo(List<SystemMenuDelDto> Dto)
  1453. {
  1454. JsonView view = new JsonView();
  1455. if (Dto.Count > 0)
  1456. {
  1457. try
  1458. {
  1459. _SystemMenuPermissionRepository.BeginTran();
  1460. bool istrue = false;
  1461. foreach (var item in Dto)
  1462. {
  1463. istrue = await _SystemMenuPermissionRepository.SoftDeleteAsync(item.Pageid.ToString());
  1464. if (!istrue)
  1465. {
  1466. throw new Exception("修改失败");
  1467. }
  1468. }
  1469. view.Code = 200;
  1470. view.Msg = "删除成功!";
  1471. view.Data = istrue;
  1472. _SystemMenuPermissionRepository.CommitTran();
  1473. }
  1474. catch (Exception)
  1475. {
  1476. _SystemMenuPermissionRepository.RollbackTran();
  1477. }
  1478. }
  1479. return Ok(JsonView(view));
  1480. }
  1481. /// <summary>
  1482. /// 获取页面绑定的操作
  1483. /// </summary>
  1484. /// <param name="Dto"></param>
  1485. /// <returns></returns>
  1486. [HttpPost]
  1487. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1488. public async Task<IActionResult> QueryPageFunById(PageFunDto Dto)
  1489. {
  1490. //页面与操作关联表
  1491. var pageAndFunList = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  1492. //页面功能表
  1493. var pageFunList = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, Sys_PageFunctionPermission>(x => x.IsEnable == 1).ToList();
  1494. ArrayList arr = new ArrayList();
  1495. foreach (var item in pageFunList)
  1496. {
  1497. var FindVal = pageAndFunList.Find(x => x.SmId == Dto.Pageid && x.FId == item.Id);
  1498. if (FindVal == null)
  1499. {
  1500. arr.Add(new
  1501. {
  1502. id = item.Id,
  1503. name = item.FunctionName,
  1504. value =false
  1505. });
  1506. }
  1507. else
  1508. {
  1509. arr.Add( new {
  1510. id = item.Id,
  1511. name = item.FunctionName,
  1512. value = true
  1513. });
  1514. }
  1515. }
  1516. return Ok(JsonView(arr));
  1517. }
  1518. #endregion
  1519. #region 页面操作
  1520. /// <summary>
  1521. /// 操作权限功能表
  1522. /// </summary>
  1523. /// <returns></returns>
  1524. [HttpPost]
  1525. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1526. public async Task<IActionResult> PageFunInit()
  1527. {
  1528. try
  1529. {
  1530. var PageFunInit = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, PageFunctionPermissionView>().ToList();
  1531. if (PageFunInit == null)
  1532. {
  1533. return Ok(JsonView(false, "暂无数据!"));
  1534. }
  1535. return Ok(JsonView(true, "查询成功!", PageFunInit));
  1536. }
  1537. catch (Exception ex)
  1538. {
  1539. return Ok(JsonView(false, "程序错误!"));
  1540. throw;
  1541. }
  1542. }
  1543. /// <summary>
  1544. /// 操作权限功能表操作(Status 1:添加,2:编辑)
  1545. /// </summary>
  1546. /// <returns></returns>
  1547. [HttpPost]
  1548. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1549. public async Task<IActionResult> OperationFun(OperationFunInitDta dto)
  1550. {
  1551. try
  1552. {
  1553. Result result = await _PageFunctionPermissionRepository.OperationFunInit(dto);
  1554. if (result.Code != 0)
  1555. {
  1556. return Ok(JsonView(false, result.Msg));
  1557. }
  1558. return Ok(JsonView(true, result.Msg));
  1559. }
  1560. catch (Exception ex)
  1561. {
  1562. return Ok(JsonView(false, "程序错误!"));
  1563. throw;
  1564. }
  1565. }
  1566. /// <summary>
  1567. /// 删除功能
  1568. /// </summary>
  1569. /// <param name="dto"></param>
  1570. /// <returns></returns>
  1571. [HttpPost]
  1572. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  1573. public async Task<IActionResult> DelFun(DelFunInitDta dto)
  1574. {
  1575. try
  1576. {
  1577. var res = await _PageFunctionPermissionRepository.SoftDeleteByIdAsync<Sys_PageFunctionPermission>(dto.Id.ToString(), dto.DeleteUserId);
  1578. if (!res)
  1579. {
  1580. return Ok(JsonView(false, "删除失败"));
  1581. }
  1582. return Ok(JsonView(true, "删除成功!"));
  1583. }
  1584. catch (Exception ex)
  1585. {
  1586. return Ok(JsonView(false, "程序错误!"));
  1587. }
  1588. }
  1589. #endregion
  1590. }
  1591. }