SystemController.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  1. using System.Collections;
  2. namespace OASystem.API.Controllers
  3. {
  4. /// <summary>
  5. /// 系统设置
  6. /// </summary>
  7. //[Authorize]
  8. [Route("api/[controller]/[action]")]
  9. public class SystemController : ControllerBase
  10. {
  11. private readonly CompanyRepository _syscomRep;
  12. private readonly DepartmentRepository _sysDepRep;
  13. private readonly UsersRepository _userRep;
  14. private readonly IMapper _mapper;
  15. private readonly SetDataRepository _setDataRepository;
  16. private readonly SystemMenuPermissionRepository _SystemMenuPermissionRepository;
  17. private readonly CompanyRepository _CompanyRepository;
  18. private readonly PageFunctionPermissionRepository _PageFunctionPermissionRepository;
  19. private readonly SystemMenuAndFunctionRepository _SystemMenuAndFunctionRepository;
  20. private readonly JobPostAuthorityRepository _JobPostAuthorityRepository;
  21. private readonly JobPostRepository _jobRep;
  22. public SystemController( CompanyRepository syscom, DepartmentRepository sysDepRep, UsersRepository userRep,
  23. IMapper mapper, SetDataRepository setDataRepository, CompanyRepository companyRepository,
  24. SystemMenuPermissionRepository systemMenuPermissionRepository, PageFunctionPermissionRepository pageFunctionPermissionRepository,
  25. SystemMenuAndFunctionRepository systemMenuAndFunctionRepository, JobPostAuthorityRepository jobPostAuthorityRepository, JobPostRepository jobRep)
  26. {
  27. _syscomRep = syscom;
  28. _sysDepRep = sysDepRep;
  29. _userRep = userRep;
  30. _mapper = mapper;
  31. _setDataRepository = setDataRepository;
  32. _CompanyRepository = companyRepository;
  33. _SystemMenuPermissionRepository = systemMenuPermissionRepository;
  34. _PageFunctionPermissionRepository = pageFunctionPermissionRepository;
  35. _SystemMenuAndFunctionRepository = systemMenuAndFunctionRepository;
  36. _JobPostAuthorityRepository = jobPostAuthorityRepository;
  37. }
  38. #region 企业操作
  39. /// <summary>
  40. /// 查询企业数据
  41. /// </summary>
  42. /// <param name="dto"></param>
  43. /// <returns></returns>
  44. [HttpPost]
  45. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  46. public async Task<IActionResult> getCompanyList(DtoBase dto)
  47. {
  48. try
  49. {
  50. if (dto.PortType == 1)
  51. {
  52. var CompanyDataResult = _CompanyRepository.GetCompanyData();
  53. if (CompanyDataResult.Code != 0)
  54. {
  55. return Ok(JsonView(CompanyDataResult.Msg));
  56. }
  57. List<CompanyView> companyListView = _mapper.Map<List<CompanyView>>(CompanyDataResult.Data);
  58. for (int i = 0; i < companyListView.Count; i++)
  59. {
  60. if (companyListView[i].ParentCompanyId != 0)
  61. {
  62. companyListView[i].ParentCompanyName = companyListView.Find(x => x.Id == companyListView[i].ParentCompanyId).CompanyName;
  63. }
  64. }
  65. return Ok(JsonView(true, "查询成功!", companyListView));
  66. }
  67. else if (dto.PortType == 2)
  68. {
  69. var CompanyDataResult = _CompanyRepository.GetCompanyData();
  70. if (CompanyDataResult.Code != 0)
  71. {
  72. return Ok(JsonView(CompanyDataResult.Msg));
  73. }
  74. return Ok(JsonView(true,"查询成功!", CompanyDataResult.Data));
  75. }
  76. else if (dto.PortType == 3)
  77. {
  78. return Ok(JsonView(false, "暂无数据!"));
  79. }
  80. else
  81. {
  82. return Ok(JsonView(false, "暂无数据!"));
  83. }
  84. }
  85. catch (Exception ex)
  86. {
  87. return Ok(JsonView(false, "程序错误!"));
  88. throw;
  89. }
  90. }
  91. /// <summary>
  92. /// 添加企业数据
  93. /// </summary>
  94. /// <param name="dto"></param>
  95. /// <returns></returns>
  96. [HttpPost]
  97. [ProducesResponseType(typeof(JsonView),StatusCodes.Status200OK)]
  98. public async Task<IActionResult> AddCompany(AddCompanyDto dto)
  99. {
  100. try
  101. {
  102. if (string.IsNullOrWhiteSpace(dto.CompanyName) || dto.CreateUserId == 0 || string.IsNullOrWhiteSpace(dto.CompanyCode))
  103. {
  104. return Ok(JsonView(false, "请检查信息是否输入完整!"));
  105. }
  106. else if (string.IsNullOrWhiteSpace(dto.Tel))
  107. {
  108. return Ok(JsonView(false, "请检查联系方式是否输入正确!"));
  109. }
  110. else
  111. {
  112. Sys_Company _Company = _mapper.Map<Sys_Company>(dto);
  113. int id = await _syscomRep.AddAsyncReturnId(_Company);
  114. if (id == 0)
  115. {
  116. return Ok(JsonView(false, "添加失败!"));
  117. }
  118. return Ok(JsonView(true,"添加成功", new { Id = id }));
  119. }
  120. }
  121. catch (Exception)
  122. {
  123. return Ok(JsonView(false, "程序错误!"));
  124. throw;
  125. }
  126. }
  127. /// <summary>
  128. /// 企业修改
  129. /// </summary>
  130. /// <param name="dto"></param>
  131. /// <returns></returns>
  132. [HttpPost]
  133. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  134. public async Task<IActionResult>EditCompany(EditCompanyDto dto)
  135. {
  136. try
  137. {
  138. if (string.IsNullOrWhiteSpace(dto.CompanyName) || string.IsNullOrWhiteSpace(dto.CompanyCode) || string.IsNullOrWhiteSpace(dto.Address) || dto.ParentCompanyId == 0 || dto.ContactUserId == 0)
  139. {
  140. return Ok(JsonView(false, "请检查信息是否输入完整!"));
  141. }
  142. else if (string.IsNullOrWhiteSpace(dto.Tel))
  143. {
  144. return Ok(JsonView(false, "请检查联系方式是否输入正确!"));
  145. }
  146. else
  147. {
  148. bool res = await _syscomRep.UpdateAsync(a => a.Id == dto.Id, a => new Sys_Company
  149. {
  150. CompanyName = dto.CompanyName,
  151. CompanyCode = dto.CompanyCode,
  152. Address = dto.Address,
  153. ParentCompanyId = dto.ParentCompanyId,
  154. Tel = dto.Tel,
  155. ContactUserId = dto.ContactUserId,
  156. });
  157. if (!res) { return Ok(JsonView(false, "修改失败")); }
  158. return Ok(JsonView(true,"修改成功!"));
  159. }
  160. }
  161. catch (Exception)
  162. {
  163. return Ok(JsonView(false, "程序错误!"));
  164. throw;
  165. }
  166. }
  167. /// <summary>
  168. /// 企业删除
  169. /// </summary>
  170. /// <param name="dto"></param>
  171. /// <returns></returns>
  172. [HttpPost]
  173. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  174. public async Task<IActionResult> DelCompany(DelCompanyDto dto)
  175. {
  176. try
  177. {
  178. bool res = await _syscomRep.SoftDeleteAsync<Sys_Company>(dto.Id.ToString());
  179. if (!res) { return Ok(JsonView(false, "删除失败")); }
  180. return Ok(JsonView(true, "删除成功"));
  181. }
  182. catch (Exception)
  183. {
  184. return Ok(JsonView(false, "程序错误!"));
  185. throw;
  186. }
  187. }
  188. #endregion
  189. #region 部门操作
  190. /// <summary>
  191. /// 查询部门数据
  192. /// </summary>
  193. /// <param name="dto"></param>
  194. /// <returns></returns>
  195. [HttpPost]
  196. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  197. public async Task<IActionResult> QueryDepartmentList(DepartmentDto dto)
  198. {
  199. try
  200. {
  201. if (dto.PortType==1)
  202. {
  203. var result = _sysDepRep.QueryDto<Sys_Department, DepartmentIView>(s => s.CompanyId == dto.CompanyId).ToList();
  204. if (result.Count == 0)
  205. {
  206. return Ok(JsonView(false, "暂无数据!"));
  207. }
  208. return Ok(JsonView(true, "查询成功!", result));
  209. }
  210. else if (dto.PortType==2)
  211. {
  212. var result = _sysDepRep.QueryDto<Sys_Department, DepartmentIView>(s => s.CompanyId == dto.CompanyId).ToList();
  213. if (result.Count == 0)
  214. {
  215. return Ok(JsonView(false, "暂无数据!"));
  216. }
  217. return Ok(JsonView(true,"查询成功!",result));
  218. }
  219. else if (dto.PortType == 3)
  220. {
  221. return Ok(JsonView(false, "暂无数据!"));
  222. }
  223. else
  224. {
  225. return Ok(JsonView(false, "暂无数据!"));
  226. }
  227. }
  228. catch (Exception ex)
  229. {
  230. return Ok(JsonView(false, "程序错误!"));
  231. throw;
  232. }
  233. }
  234. /// <summary>
  235. /// 部门添加
  236. /// </summary>
  237. /// <param name="dto"></param>
  238. /// <returns></returns>
  239. [HttpPost]
  240. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  241. public async Task<IActionResult> AddDepartment(AddDepartmentDto dto)
  242. {
  243. try
  244. {
  245. if (dto.CreateUserId == 0 || string.IsNullOrWhiteSpace(dto.DepName) || dto.CompanyId == 0 || string.IsNullOrWhiteSpace(dto.DepCode))
  246. {
  247. return Ok(JsonView(false, "请检查信息是否输入完整!"));
  248. }
  249. else
  250. {
  251. Sys_Department _Department = _mapper.Map<Sys_Department>(dto);
  252. int id = await _sysDepRep.AddAsyncReturnId(_Department);
  253. if (id == 0)
  254. {
  255. return Ok(JsonView(false, "添加失败!"));
  256. }
  257. return Ok(JsonView(true, "添加成功!", new { Id = id }));
  258. }
  259. }
  260. catch (Exception)
  261. {
  262. return Ok(JsonView(false, "程序错误!"));
  263. throw;
  264. }
  265. }
  266. /// <summary>
  267. /// 部门修改
  268. /// </summary>
  269. /// <param name="dto"></param>
  270. /// <returns></returns>
  271. [HttpPost]
  272. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  273. public async Task<IActionResult> EditDepartment(EditDepartmentDto dto)
  274. {
  275. try
  276. {
  277. if (dto.Id==0 || string.IsNullOrWhiteSpace(dto.DepName) || dto.CompanyId == 0 || string.IsNullOrWhiteSpace(dto.DepCode))
  278. {
  279. return Ok(JsonView(false, "请检查信息是否输入完整!"));
  280. }
  281. else
  282. {
  283. bool res = await _sysDepRep.UpdateAsync<Sys_Department>(a => a.Id == dto.Id, a => new Sys_Department
  284. {
  285. CompanyId=dto.CompanyId,
  286. DepCode=dto.DepCode,
  287. DepName=dto.DepName,
  288. ParentDepId=dto.ParentDepId,
  289. Remark=dto.Remark,
  290. });
  291. if (!res)
  292. {
  293. return Ok(JsonView(false, "修改失败!"));
  294. }
  295. return Ok(JsonView(true, "修改成功!"));
  296. }
  297. }
  298. catch (Exception)
  299. {
  300. return Ok(JsonView(false, "程序错误!"));
  301. throw;
  302. }
  303. }
  304. /// <summary>
  305. /// 部门删除
  306. /// </summary>
  307. /// <param name="dto"></param>
  308. /// <returns></returns>
  309. [HttpPost]
  310. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  311. public async Task<IActionResult> DelDepartment(DelDepartmentDto dto)
  312. {
  313. try
  314. {
  315. if (dto.Id == 0)
  316. {
  317. return Ok(JsonView(-1, "请检查信息是否输入完整!", null));
  318. }
  319. else
  320. {
  321. bool res =await _sysDepRep.SoftDeleteAsync<Sys_Department>(dto.Id.ToString());
  322. if (!res)
  323. {
  324. return Ok(JsonView(false, "删除失败!"));
  325. }
  326. return Ok(JsonView(true, "删除成功!"));
  327. }
  328. }
  329. catch (Exception)
  330. {
  331. return Ok(JsonView(false, "程序错误!"));
  332. throw;
  333. }
  334. }
  335. #endregion
  336. #region 岗位板块
  337. /// <summary>
  338. /// 岗位查询
  339. /// </summary>
  340. /// <param name="dto"></param>
  341. /// <returns></returns>
  342. [HttpPost]
  343. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  344. public async Task<IActionResult> QueryJobPost(QueryJobPostDto dto)
  345. {
  346. try
  347. {
  348. if (dto.PortType == 1)
  349. {
  350. var result = _sysDepRep.QueryDto<Sys_JobPost, JobPostView>(s => s.CompanyId == dto.CompanyId && s.DepId == dto.DepId).ToList();
  351. if (result.Count == 0)
  352. {
  353. return Ok(JsonView(false, "暂无数据!"));
  354. }
  355. return Ok(JsonView(true, "查询成功!", result));
  356. }
  357. else if (dto.PortType == 2)
  358. {
  359. var result = _jobRep.QueryDto<Sys_JobPost, JobPostView>(s => s.CompanyId == dto.CompanyId && s.DepId==dto.DepId).ToList();
  360. if (result.Count == 0)
  361. {
  362. return Ok(JsonView(false, "暂无数据!"));
  363. }
  364. return Ok(JsonView(true, "查询成功!", result));
  365. }
  366. else if (dto.PortType == 3)
  367. {
  368. return Ok(JsonView(false, "暂无数据!"));
  369. }
  370. else
  371. {
  372. return Ok(JsonView(false, "暂无数据!"));
  373. }
  374. }
  375. catch (Exception ex)
  376. {
  377. return Ok(JsonView(false, "程序错误!"));
  378. throw;
  379. }
  380. }
  381. /// <summary>
  382. /// 添加岗位
  383. /// </summary>
  384. /// <param name="dto"></param>
  385. /// <returns></returns>
  386. [HttpPost]
  387. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  388. public async Task<IActionResult> AddJobPost(AddJobPostDto dto)
  389. {
  390. try
  391. {
  392. Sys_JobPost sys_Job = _mapper.Map<Sys_JobPost>(dto);
  393. int id = await _jobRep.AddAsyncReturnId(sys_Job);
  394. if (id == 0)
  395. {
  396. return Ok(JsonView(false, "添加失败"));
  397. }
  398. return Ok(JsonView(true, "添加成功", new { Id = id }));
  399. }
  400. catch (Exception ex)
  401. {
  402. return Ok(JsonView(false, "程序错误!"));
  403. throw;
  404. }
  405. }
  406. /// <summary>
  407. /// 修改岗位
  408. /// </summary>
  409. /// <param name="dto"></param>
  410. /// <returns></returns>
  411. [HttpPost]
  412. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  413. public async Task<IActionResult> EditJobPost(EditJobPostDto dto)
  414. {
  415. try
  416. {
  417. bool res = await _jobRep.UpdateAsync<Sys_JobPost>(a=>a.Id==dto.Id,a =>new Sys_JobPost
  418. {
  419. CompanyId=dto.CompanyId,
  420. DepId=dto.DepId,
  421. JobName=dto.JobName,
  422. Remark=dto.Remark,
  423. });
  424. if (!res)
  425. {
  426. return Ok(JsonView(false, "修改失败"));
  427. }
  428. return Ok(JsonView(true, "修改成功"));
  429. }
  430. catch (Exception ex)
  431. {
  432. return Ok(JsonView(false, "程序错误!"));
  433. throw;
  434. }
  435. }
  436. /// <summary>
  437. /// 删除岗位
  438. /// </summary>
  439. /// <param name="dto"></param>
  440. /// <returns></returns>
  441. [HttpPost]
  442. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  443. public async Task<IActionResult> DelJobPost(DelJobPostDto dto)
  444. {
  445. try
  446. {
  447. bool res = await _jobRep.SoftDeleteAsync<Sys_JobPost>(dto.Id.ToString());
  448. if (!res)
  449. {
  450. return Ok(JsonView(false, "删除失败!"));
  451. }
  452. return Ok(JsonView(true, "删除成功"));
  453. }
  454. catch (Exception)
  455. {
  456. return Ok(JsonView(false, "程序错误!"));
  457. throw;
  458. }
  459. }
  460. #endregion
  461. #region 用户操作
  462. /// <summary>
  463. /// 查询所有员工(web)
  464. /// </summary>
  465. /// <param name="dto"></param>
  466. /// <returns></returns>
  467. //[OASystemAuthentication]
  468. [HttpPost]
  469. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  470. public async Task<IActionResult> GetUserList(DtoBase dto)
  471. {
  472. try
  473. {
  474. var result = _userRep.GetUserList(dto.PortType, string.Empty);
  475. if (result.Result.Code != 0)
  476. {
  477. return Ok(JsonView(false, "暂无数据!"));
  478. }
  479. return Ok(JsonView(true, "查询成功!", result.Result.Data));
  480. }
  481. catch (Exception)
  482. {
  483. return Ok(JsonView(false, "程序错误!"));
  484. throw;
  485. }
  486. }
  487. /// <summary>
  488. /// 查询用户数据
  489. /// </summary>
  490. /// <param name="dto"></param>
  491. /// <returns></returns>
  492. [HttpPost]
  493. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  494. public async Task<IActionResult> QueryUserList(UserDto dto)
  495. {
  496. try
  497. {
  498. string sqlWhere = string.Empty;
  499. if (dto.CompanyId!=0)
  500. {
  501. sqlWhere += string.Format(@" And su.CompanyId={0}", dto.CompanyId);
  502. }
  503. if (dto.DepId != 0)
  504. {
  505. sqlWhere += string.Format(@" And su.DepId={0}", dto.DepId);
  506. }
  507. if (dto.JobPostId != 0)
  508. {
  509. sqlWhere += string.Format(@" And su.JobPostId={0}", dto.JobPostId);
  510. }
  511. if (!string.IsNullOrEmpty(sqlWhere.Trim()))
  512. {
  513. Regex r = new Regex("And");
  514. sqlWhere = r.Replace(sqlWhere, "Where", 1);
  515. }
  516. var result=_userRep.GetUserList(dto.PortType,sqlWhere);
  517. if (result.Result.Code!=0)
  518. {
  519. return Ok(JsonView(false, "暂无数据!"));
  520. }
  521. return Ok(JsonView(true,"查询成功!",result.Result.Data));
  522. }
  523. catch (Exception)
  524. {
  525. return Ok(JsonView(false, "程序错误!"));
  526. throw;
  527. }
  528. }
  529. /// <summary>
  530. /// 修改用户信息(上级修改/分配 公司、部门、岗位、工号等信息)
  531. /// </summary>
  532. /// <param name="dto"></param>
  533. /// <returns></returns>
  534. [HttpPost]
  535. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  536. public async Task<IActionResult> EditUser(EditUserDto dto)
  537. {
  538. try
  539. {
  540. bool res = await _userRep.UpdateAsync<Sys_Users>(a => a.Id == dto.Id, a => new Sys_Users
  541. {
  542. Number = dto.Number,
  543. CompanyId = dto.CompanyId,
  544. DepId = dto.DepId,
  545. JobPostId = dto.JobPostId,
  546. Ext = dto.Ext,
  547. UsePeriod = dto.UsePeriod,
  548. HrAudit = dto.HrAudit
  549. });
  550. if (!res)
  551. {
  552. return Ok(JsonView(false, "修改失败!"));
  553. }
  554. return Ok(JsonView(true, "修改成功!"));
  555. }
  556. catch (Exception)
  557. {
  558. return Ok(JsonView(false, "程序错误!"));
  559. throw;
  560. }
  561. }
  562. /// <summary>
  563. /// 修改用户信息(登录用户修改个人信息)
  564. /// </summary>
  565. /// <param name="dto"></param>
  566. /// <returns></returns>
  567. [HttpPost]
  568. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  569. public async Task<IActionResult> EditMyUser(EditMyUserDto dto)
  570. {
  571. try
  572. {
  573. if (string.IsNullOrWhiteSpace(dto.CnName) || string.IsNullOrWhiteSpace(dto.Address) || string.IsNullOrWhiteSpace(dto.IDCard) || dto.Sex != 0 && dto.Sex != 1 ||
  574. string.IsNullOrWhiteSpace(dto.MaritalStatus) || string.IsNullOrWhiteSpace(dto.HomeAddress)|| dto.Birthday>=DateTime.Now.AddYears(-1))
  575. {
  576. return Ok(JsonView(false, "请完善你的个人信息!"));
  577. }
  578. else if (string.IsNullOrWhiteSpace(dto.GraduateInstitutions) || string.IsNullOrWhiteSpace(dto.Professional) || dto.Education == 0 || string.IsNullOrWhiteSpace(dto.GraduateInstitutions))
  579. {
  580. return Ok(JsonView(false, "请完善你的学历信息!"));
  581. }
  582. else if (string.IsNullOrWhiteSpace(dto.Phone) || string.IsNullOrWhiteSpace(dto.UrgentPhone) || string.IsNullOrWhiteSpace(dto.Email))
  583. {
  584. return Ok(JsonView(false, "请检查联系方式、紧急联系人及邮箱输写是否正确!"));
  585. }
  586. else
  587. {
  588. bool res = await _userRep.UpdateAsync<Sys_Users>(a => a.Id == dto.Id, a => new Sys_Users
  589. {
  590. CnName = dto.CnName,
  591. EnName = dto.EnName,
  592. Sex = dto.Sex,
  593. Phone = dto.Phone,
  594. UrgentPhone = dto.UrgentPhone,
  595. Email = dto.Email,
  596. Address = dto.Address,
  597. Edate = dto.Edate,
  598. Birthday = dto.Birthday,
  599. IDCard = dto.IDCard,
  600. GraduateInstitutions = dto.GraduateInstitutions,
  601. Professional = dto.Professional,
  602. Education = dto.Education,
  603. TheOrAdultEducation = dto.TheOrAdultEducation,
  604. MaritalStatus = dto.MaritalStatus,
  605. HomeAddress = dto.HomeAddress,
  606. WorkExperience = dto.WorkExperience,
  607. Certificate = dto.Certificate
  608. });
  609. if (!res)
  610. {
  611. return Ok(JsonView(false, "修改失败!"));
  612. }
  613. return Ok(JsonView(true, "修改成功!"));
  614. }
  615. }
  616. catch (Exception)
  617. {
  618. return Ok(JsonView(false, "程序错误!"));
  619. throw;
  620. }
  621. }
  622. #endregion
  623. #region 权限模块
  624. /// <summary>
  625. /// 权限数据页面初始化
  626. /// </summary>
  627. /// <param name="dto"></param>
  628. /// <returns></returns>
  629. //[Authorize]
  630. [HttpPost]
  631. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  632. public async Task<IActionResult> GetAuth(AuthDto dto)
  633. {
  634. Result result = new Result();
  635. //模块数据
  636. var setDataResult = await _setDataRepository.GetSySDefultModule(_setDataRepository);
  637. if (setDataResult.Code != 0)
  638. {
  639. return Ok(JsonView(setDataResult.Msg));
  640. }
  641. //操作方式
  642. var PageOperation = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, Sys_PageFunctionPermission>().ToList();
  643. //获取所有关联页面
  644. var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  645. //页面数据
  646. var SystemMenuPermissionData = _SystemMenuPermissionRepository.QueryDto<Sys_SystemMenuPermission, SystemMenuPermissionView>(x=>x.Mid == dto.moduleId).ToList();
  647. if (SystemMenuPermissionData == null || SystemMenuPermissionData.Count() == 0)
  648. {
  649. return Ok(JsonView("暂无数据"));
  650. }
  651. ArrayList viewData = new ArrayList();
  652. //组合页面数据
  653. foreach (var item in SystemMenuPermissionData)
  654. {
  655. ArrayList ids = new ArrayList();
  656. foreach (var viewop in PageOperation)
  657. {
  658. var op = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.SmId == item.Id && x.FId == viewop.Id);
  659. if (op != null)
  660. {
  661. ids.Add(viewop.Id);
  662. }
  663. }
  664. viewData.Add(new
  665. {
  666. Id = item.Id,
  667. Mid = item.Mid,
  668. Name = item.Name,
  669. SystemMenuCode = item.SystemMenuCode,
  670. opList = ids,
  671. selList = new string[0]
  672. }) ;
  673. }
  674. //公司数据
  675. var CompanyDataResult = _CompanyRepository.GetCompanyData();
  676. if (CompanyDataResult.Code != 0)
  677. {
  678. return Ok(JsonView(CompanyDataResult.Msg));
  679. }
  680. result.Code = 0;
  681. result.Msg = "成功!";
  682. var Dyresult = new
  683. {
  684. setDataResult = setDataResult.Data,
  685. CompanyDataResult = CompanyDataResult.Data,
  686. SystemMenuPermissionData = viewData,
  687. PageOperation = PageOperation,
  688. };
  689. return Ok(JsonView(200, "成功!", Dyresult));
  690. }
  691. /// <summary>
  692. /// 获取职务权限
  693. /// </summary>
  694. /// <param name="dto"></param>
  695. /// <returns></returns>
  696. [HttpPost]
  697. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  698. public IActionResult QueryJobAuth(QueryJobAuthDto dto)
  699. {
  700. //选中的操作权限
  701. var DBdata = _JobPostAuthorityRepository.QueryDto<Sys_JobPostAuthority, JobPostAuthorityView>(x=>x.JpId == dto.jobid).ToList();
  702. var SystemMenuPermissionData = _SystemMenuPermissionRepository.QueryDto<Sys_SystemMenuPermission, SystemMenuPermissionView>(x => x.Mid == dto.moduleId).ToList();
  703. if (SystemMenuPermissionData == null || SystemMenuPermissionData.Count() == 0)
  704. {
  705. return Ok(JsonView("暂无数据"));
  706. }
  707. //所有操作
  708. var PageOperation = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, Sys_PageFunctionPermission>().ToList();
  709. //获取所有关联页面
  710. var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  711. ArrayList viewData = new ArrayList();
  712. //组合页面数据
  713. foreach (var item in SystemMenuPermissionData)
  714. {
  715. ArrayList ids = new ArrayList();
  716. foreach (var viewop in PageOperation)
  717. {
  718. var op = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.SmId == item.Id && x.FId == viewop.Id);
  719. if (op != null)
  720. {
  721. ids.Add(viewop.Id);
  722. }
  723. }
  724. //获取本职务的页面拥有的权限
  725. var DBwhere = DBdata.Where(x => x.SmId == item.Id && x.JpId == dto.jobid).ToList();
  726. viewData.Add(new
  727. {
  728. Id = item.Id,
  729. Mid = item.Mid,
  730. Name = item.Name,
  731. SystemMenuCode = item.SystemMenuCode,
  732. opList = ids,
  733. selList = DBwhere.Select(x => x.FId)
  734. }) ;
  735. }
  736. return Ok(JsonView(200, "成功!", viewData));
  737. }
  738. /// <summary>
  739. /// 保存岗位权限
  740. /// </summary>
  741. /// <param name="dto"></param>
  742. /// <returns></returns>
  743. [HttpPost]
  744. [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
  745. public async Task<IActionResult> SaveJobAuth(SaveJobDto dto)
  746. {
  747. //获取所有关联页面
  748. var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
  749. List<Sys_JobPostAuthority> adds = new List<Sys_JobPostAuthority>();
  750. foreach (var item in dto.Savejobs)
  751. {
  752. foreach (var fid in item.FIds)
  753. {
  754. var whereobj = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.FId == fid && x.SmId == item.SmId);
  755. if (whereobj != null)
  756. {
  757. adds.Add(new Sys_JobPostAuthority
  758. {
  759. CreateTime = DateTime.Now,
  760. CreateUserId = 245,
  761. FId = fid,
  762. JpId = dto.Jpid,
  763. SmId = item.SmId
  764. });
  765. }
  766. }
  767. }
  768. _JobPostAuthorityRepository.BeginTran();
  769. try
  770. {
  771. bool isdel = await _JobPostAuthorityRepository.DeleteAsync<Sys_JobPostAuthority>(x => x.JpId == dto.Jpid);
  772. int UpRows = _JobPostAuthorityRepository.Adds<Sys_JobPostAuthority>(adds);
  773. }
  774. catch (Exception ex)
  775. {
  776. _JobPostAuthorityRepository.RollbackTran();
  777. return Ok(JsonView("系统错误!"));
  778. }
  779. _JobPostAuthorityRepository.CommitTran();
  780. return Ok(JsonView(200, "成功", new { }));
  781. }
  782. #endregion
  783. }
  784. }