SystemController.cs 54 KB

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