SystemController.cs 65 KB

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