SystemController.cs 32 KB

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