SystemController.cs 32 KB

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