123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770 |
- using AutoMapper.Execution;
- using Google.Protobuf.WellKnownTypes;
- using Microsoft.AspNetCore.Mvc.Formatters;
- using Microsoft.AspNetCore.Mvc.ModelBinding;
- using Newtonsoft.Json.Linq;
- using OASystem.Domain.Dtos.System;
- using Org.BouncyCastle.Asn1.Cms;
- using System.Collections;
- using System.Xml.Linq;
- using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
- namespace OASystem.API.Controllers
- {
- /// <summary>
- /// 系统设置
- /// </summary>
- //[Authorize]
- [Route("api/[controller]/[action]")]
- public class SystemController : ControllerBase
- {
- private readonly CompanyRepository _syscomRep;
- private readonly DepartmentRepository _sysDepRep;
- private readonly UsersRepository _userRep;
- private readonly IMapper _mapper;
- private readonly SqlSugarClient _sqlSugar;
- private readonly MessageRepository _messageRep;
- private readonly SetDataRepository _setDataRepository;
- private readonly SystemMenuPermissionRepository _SystemMenuPermissionRepository;
- private readonly CompanyRepository _CompanyRepository;
- private readonly PageFunctionPermissionRepository _PageFunctionPermissionRepository;
- private readonly SystemMenuAndFunctionRepository _SystemMenuAndFunctionRepository;
- private readonly JobPostAuthorityRepository _JobPostAuthorityRepository;
- private readonly JobPostRepository _jobRep;
- private readonly SetDataTypeRepository _setDataTypeRep;
- private readonly UserAuthorityRepository _UserAuthorityRepository;
- public SystemController( CompanyRepository syscom, DepartmentRepository sysDepRep, UsersRepository userRep,
- IMapper mapper,SqlSugarClient sqlSugar, SetDataRepository setDataRepository, CompanyRepository companyRepository,
- SystemMenuPermissionRepository systemMenuPermissionRepository, PageFunctionPermissionRepository pageFunctionPermissionRepository,
- SystemMenuAndFunctionRepository systemMenuAndFunctionRepository, JobPostAuthorityRepository jobPostAuthorityRepository,
- JobPostRepository jobRep,UserAuthorityRepository userAuthorityRepository, MessageRepository messageRep,SetDataTypeRepository setDataTypeRep)
-
- {
- _syscomRep = syscom;
- _sysDepRep = sysDepRep;
- _messageRep = messageRep;
- _userRep = userRep;
- _mapper = mapper;
- _sqlSugar = sqlSugar;
- _setDataRepository = setDataRepository;
- _CompanyRepository = companyRepository;
- _SystemMenuPermissionRepository = systemMenuPermissionRepository;
- _PageFunctionPermissionRepository = pageFunctionPermissionRepository;
- _SystemMenuAndFunctionRepository = systemMenuAndFunctionRepository;
- _JobPostAuthorityRepository = jobPostAuthorityRepository;
- _UserAuthorityRepository = userAuthorityRepository;
- _jobRep = jobRep;
- _setDataTypeRep = setDataTypeRep;
- }
- #region 消息
- /// <summary>
- /// 获取消息列表
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GetMsgList(MsgDto dto)
- {
- var msgData = await _messageRep.GetMsgList(dto);
- if (msgData.Code != 0)
- {
- return Ok(JsonView(false, msgData.Msg));
- }
- return Ok(JsonView(true,"成功", msgData.Data));
- }
- /// <summary>
- /// 获取消息详细信息
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GetMsgInfo(MsgInfoDto dto)
- {
- var msgData = await _messageRep.GetMsgInfo(dto);
- if (msgData.Code != 0)
- {
- return Ok(JsonView(false, msgData.Msg));
- }
- return Ok(JsonView(true, msgData.Data));
- }
- /// <summary>
- /// 消息设置已读
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> SetMessageRead(MsgSetReadDto dto)
- {
- var msgData = await _messageRep.SetMsgRead(dto);
- if (msgData.Code != 0)
- {
- return Ok(JsonView(false, msgData.Msg));
- }
- return Ok(JsonView(true, msgData.Data));
- }
- /// <summary>
- /// 消息设置已读
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> DeleMsg(MsgDeleteDto dto)
- {
- var msgData = await _messageRep.DelMsg(dto);
- if (msgData.Code != 0)
- {
- return Ok(JsonView(false, msgData.Msg));
- }
- return Ok(JsonView(true, msgData.Data));
- }
- #endregion
- #region 数据类型资料
- /// <summary>
- /// 根据类型查询数据
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> QuerySetData(SetDataDto dto)
- {
- try
- {
- if (dto.DataType == 0)
- {
- return Ok(JsonView(false, "请传类型Id!"));
- }
- var setData = _setDataRepository.QueryDto<Sys_SetData, SetDataView>(s => s.STid == dto.DataType && s.IsDel==0).ToList();
- if (setData.Count == 0)
- {
- return Ok(JsonView(false, "暂无数据!"));
- }
- return Ok(JsonView(true, "查询成功!", setData));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, "程序错误!"));
- throw;
- }
- }
- /// <summary>
- /// 数据类型表查询
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> QuerySetDataType(SetDataTypeDto dto)
- {
- try
- {
- Result setDataType = await _setDataTypeRep.QuerySetDataType(dto);
- if (setDataType.Code == 0)
- {
- return Ok(JsonView(true, "查询成功", setDataType.Data));
- }
- else
- {
- return Ok(JsonView(false, setDataType.Msg));
- }
- }
- catch (Exception)
- {
- return Ok(JsonView(false, "程序错误!"));
- throw;
- }
- }
- /// <summary>
- /// 数据类型表操作(Status:1.新增,2.修改)
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> OperationSetDataType(OperationSetDataTypeDto dto)
- {
- try
- {
- if (dto.Name == "")
- {
- return Ok(JsonView(false, "请检查类型名称是否填写!"));
- }
- Result result = await _setDataTypeRep.OperationSetDataType(dto);
- if (result.Code != 0)
- {
- return Ok(JsonView(false, result.Msg));
- }
- return Ok(JsonView(true, result.Msg));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, "程序错误!"));
- throw;
- }
- }
- /// <summary>
- /// 数据类型表操作删除
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> DelSetDataType(DelSetDataTypeDto dto)
- {
- try
- {
- var res = await _setDataTypeRep.SoftDeleteByIdAsync<Sys_SetDataType>(dto.Id.ToString(), dto.DeleteUserId);
- if (!res)
- {
- return Ok(JsonView(false, "删除失败"));
- }
- return Ok(JsonView(true, "删除成功!"));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, "程序错误!"));
- throw;
- }
- }
- #endregion
- #region 数据类型板块
- /// <summary>
- /// 数据类型板块表查询
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> QuerySetDataInfo(SetDataIDto dto)
- {
- try
- {
- Result setData = await _setDataRepository.QuerySetData(dto);
- if (setData.Code == 0)
- {
- return Ok(JsonView(true, "查询成功", setData.Data));
- }
- else
- {
- return Ok(JsonView(false, setData.Msg));
- }
- }
- catch (Exception)
- {
- return Ok(JsonView(false, "程序错误!"));
- throw;
- }
- }
- /// <summary>
- /// 数据类型板块表操作(Status:1.新增,2.修改)
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> OperationSetData(OperationSetDataDto dto)
- {
- try
- {
- if (dto.Name == "")
- {
- return Ok(JsonView(false, "请检查板块名称是否填写!"));
- }
- Result result = await _setDataRepository.OperationSetData(dto);
- if (result.Code != 0)
- {
- return Ok(JsonView(false, result.Msg));
- }
- return Ok(JsonView(true, result.Msg));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, "程序错误!"));
- throw;
- }
- }
- /// <summary>
- /// 数据类型表操作删除
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> DelSetData(DelSetDataDto dto)
- {
- try
- {
- var res = await _setDataRepository.SoftDeleteByIdAsync<Sys_SetData>(dto.Id.ToString(), dto.DeleteUserId);
- if (!res)
- {
- return Ok(JsonView(false, "删除失败"));
- }
- return Ok(JsonView(true, "删除成功!"));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, "程序错误!"));
- throw;
- }
- }
- #endregion
- #region 企业操作
- /// <summary>
- /// 查询企业数据
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> getCompanyList(DtoBase dto)
- {
- try
- {
- if (dto.PortType == 1)
- {
- var CompanyDataResult = _CompanyRepository.GetCompanyData();
- if (CompanyDataResult.Code != 0)
- {
- return Ok(JsonView(CompanyDataResult.Msg));
- }
- List<CompanyView> companyListView = _mapper.Map<List<CompanyView>>(CompanyDataResult.Data);
- for (int i = 0; i < companyListView.Count; i++)
- {
- if (companyListView[i].ParentCompanyId != 0)
- {
- companyListView[i].ParentCompanyName = companyListView.Find(x => x.Id == companyListView[i].ParentCompanyId).CompanyName;
- }
- if (companyListView[i].ContactUserId!=0)
- {
- var user = _userRep.QueryDto<Sys_Users,UserInfoWebView>(x => x.Id == companyListView[i].ContactUserId).ToList();
- if (user.Count!=0)
- {
- companyListView[i].ContactUserName = user[0].CnName;
- }
-
- }
- }
- return Ok(JsonView(true, "查询成功!", companyListView));
- }
- else if (dto.PortType == 2)
- {
- var CompanyDataResult = _CompanyRepository.GetCompanyData();
- if (CompanyDataResult.Code != 0)
- {
- return Ok(JsonView(CompanyDataResult.Msg));
- }
-
- return Ok(JsonView(true,"查询成功!", CompanyDataResult.Data));
- }
- else if (dto.PortType == 3)
- {
- return Ok(JsonView(false, "暂无数据!"));
- }
- else
- {
- return Ok(JsonView(false, "暂无数据!"));
- }
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, "程序错误!"));
- throw;
- }
- }
- /// <summary>
- /// 添加企业数据
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView),StatusCodes.Status200OK)]
- public async Task<IActionResult> AddCompany(AddCompanyDto dto)
- {
- try
- {
- if (string.IsNullOrWhiteSpace(dto.CompanyName) || dto.CreateUserId == 0 || string.IsNullOrWhiteSpace(dto.CompanyCode))
- {
- return Ok(JsonView(false, "请检查信息是否输入完整!"));
- }
- else if (string.IsNullOrWhiteSpace(dto.Tel))
- {
- return Ok(JsonView(false, "请检查联系方式是否输入正确!"));
- }
- else
- {
- Sys_Company _Company = _mapper.Map<Sys_Company>(dto);
- Result data = await _syscomRep.AddCompany(_Company);
- if (data.Code != 0)
- {
- return Ok(JsonView(false, "添加失败!"));
- }
- return Ok(JsonView(true,"添加成功"));
- }
- }
- catch (Exception)
- {
- return Ok(JsonView(false, "程序错误!"));
- throw;
- }
-
-
- }
- /// <summary>
- /// 企业修改
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult>EditCompany(EditCompanyDto dto)
- {
- try
- {
- if (string.IsNullOrWhiteSpace(dto.CompanyName) || string.IsNullOrWhiteSpace(dto.CompanyCode) || string.IsNullOrWhiteSpace(dto.Address) || dto.ContactUserId == 0)
- {
- return Ok(JsonView(false, "请检查信息是否输入完整!"));
- }
- else if (string.IsNullOrWhiteSpace(dto.Tel))
- {
- return Ok(JsonView(false, "请检查联系方式是否输入正确!"));
- }
- else
- {
- bool res = await _syscomRep.UpdateAsync(a => a.Id == dto.Id, a => new Sys_Company
- {
- CompanyName = dto.CompanyName,
- CompanyCode = dto.CompanyCode,
- Address = dto.Address,
- ParentCompanyId = dto.ParentCompanyId,
- Tel = dto.Tel,
- ContactUserId = dto.ContactUserId,
- Remark=dto.Remark,
- });
- if (!res) { return Ok(JsonView(false, "修改失败")); }
- return Ok(JsonView(true,"修改成功!"));
- }
- }
- catch (Exception)
- {
- return Ok(JsonView(false, "程序错误!"));
- throw;
- }
-
-
- }
- /// <summary>
- /// 企业删除
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> DelCompany(DelCompanyDto dto)
- {
- try
- {
- bool res = await _syscomRep.SoftDeleteAsync<Sys_Company>(dto.Id.ToString());
- if (!res) { return Ok(JsonView(false, "删除失败")); }
- return Ok(JsonView(true, "删除成功"));
- }
- catch (Exception)
- {
- return Ok(JsonView(false, "程序错误!"));
- throw;
- }
-
-
- }
- #endregion
- #region 部门操作
- /// <summary>
- /// 查询部门数据
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
-
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> QueryDepartmentList(DepartmentDto dto)
- {
- try
- {
- if (dto.PortType==1)
- {
- if (dto.CompanyId!=0)
- {
- var result = _sysDepRep.QueryDto<Sys_Department, DepartmentIView>(s => s.CompanyId == dto.CompanyId).ToList();
- if (result.Count == 0)
- {
- return Ok(JsonView(false, "暂无数据!"));
- }
- for (int i = 0; i < result.Count; i++)
- {
- if (result[i].ParentDepId != 0)
- {
- result[i].ParentDepName = result.Find(x => x.Id == result[i].ParentDepId).ParentDepName;
- }
- var company = _sysDepRep.QueryDto<Sys_Company, CompanyView>(s => s.Id == result[i].CompanyId).ToList();
- if (company.Count != 0)
- {
- result[i].CompanyName = company[0].CompanyName;
- }
- return Ok(JsonView(true, "查询成功!", result));
- }
- }
- else
- {
- var result = _sysDepRep.QueryDto<Sys_Department, DepartmentIView>(s => s.IsDel <=1).ToList();
- if (result.Count == 0)
- {
- return Ok(JsonView(false, "暂无数据!"));
- }
- for (int i = 0; i < result.Count; i++)
- {
- if (result[i].ParentDepId != 0)
- {
- result[i].ParentDepName = result.Find(x => x.Id == result[i].ParentDepId).ParentDepName;
- }
- var company = _sysDepRep.QueryDto<Sys_Company, CompanyView>(s => s.Id == result[i].CompanyId).ToList();
- if (company.Count != 0)
- {
- result[i].CompanyName = company[0].CompanyName;
- }
- }
- return Ok(JsonView(true, "查询成功!", result));
- }
- return Ok(JsonView(false, "暂无数据!"));
- }
- else if (dto.PortType==2)
- {
- var result = _sysDepRep.QueryDto<Sys_Department, DepartmentIView>(s => s.CompanyId == dto.CompanyId).ToList();
- if (result.Count == 0)
- {
- return Ok(JsonView(false, "暂无数据!"));
- }
- return Ok(JsonView(true,"查询成功!",result));
- }
- else if (dto.PortType == 3)
- {
- return Ok(JsonView(false, "暂无数据!"));
- }
- else
- {
- return Ok(JsonView(false, "暂无数据!"));
- }
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, "程序错误!"));
- throw;
- }
-
- }
- /// <summary>
- /// 部门添加
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> AddDepartment(AddDepartmentDto dto)
- {
- try
- {
- if (dto.CreateUserId == 0 || string.IsNullOrWhiteSpace(dto.DepName) || dto.CompanyId == 0 || string.IsNullOrWhiteSpace(dto.DepCode))
- {
- return Ok(JsonView(false, "请检查信息是否输入完整!"));
- }
- else
- {
- Sys_Department _Department = _mapper.Map<Sys_Department>(dto);
- int id = await _sysDepRep.AddAsyncReturnId(_Department);
- if (id == 0)
- {
- return Ok(JsonView(false, "添加失败!"));
- }
- return Ok(JsonView(true, "添加成功!", new { Id = id }));
- }
- }
- catch (Exception)
- {
- return Ok(JsonView(false, "程序错误!"));
- throw;
- }
-
-
- }
- /// <summary>
- /// 部门修改
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> EditDepartment(EditDepartmentDto dto)
- {
- try
- {
- if (dto.Id==0 || string.IsNullOrWhiteSpace(dto.DepName) || dto.CompanyId == 0 || string.IsNullOrWhiteSpace(dto.DepCode))
- {
- return Ok(JsonView(false, "请检查信息是否输入完整!"));
- }
- else
- {
- bool res = await _sysDepRep.UpdateAsync<Sys_Department>(a => a.Id == dto.Id, a => new Sys_Department
- {
- CompanyId=dto.CompanyId,
- DepCode=dto.DepCode,
- DepName=dto.DepName,
- ParentDepId=dto.ParentDepId,
- Remark=dto.Remark,
- });
- if (!res)
- {
- return Ok(JsonView(false, "修改失败!"));
- }
- return Ok(JsonView(true, "修改成功!"));
- }
- }
- catch (Exception)
- {
- return Ok(JsonView(false, "程序错误!"));
- throw;
- }
- }
- /// <summary>
- /// 部门删除
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> DelDepartment(DelDepartmentDto dto)
- {
- try
- {
- if (dto.Id == 0)
- {
- return Ok(JsonView(-1, "请检查信息是否输入完整!", null));
- }
- else
- {
- bool res =await _sysDepRep.SoftDeleteAsync<Sys_Department>(dto.Id.ToString());
- if (!res)
- {
- return Ok(JsonView(false, "删除失败!"));
- }
- return Ok(JsonView(true, "删除成功!"));
- }
- }
- catch (Exception)
- {
- return Ok(JsonView(false, "程序错误!"));
- throw;
- }
- }
- #endregion
- #region 岗位板块
- /// <summary>
- /// 岗位查询
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> QueryJobPost(QueryJobPostDto dto)
- {
- try
- {
- if (dto.PortType == 1)
- {
- string sqlWhere = string.Empty;
- if (dto.CompanyId != 0)
- {
- sqlWhere += string.Format(@" And jp.CompanyId={0}", dto.CompanyId);
- }
- if (dto.DepId != 0)
- {
- sqlWhere += string.Format(@" And jp.DepId={0}", dto.DepId);
- }
- sqlWhere += string.Format(@" And jp.IsDel={0}", 0);
- if (!string.IsNullOrEmpty(sqlWhere.Trim()))
- {
- Regex r = new Regex("And");
- sqlWhere = r.Replace(sqlWhere, "Where", 1);
- }
- List<Sys_JobPostI> jobList = await _jobRep.QueryJobPost(sqlWhere);
- List<JobPostView> List = _mapper.Map<List<JobPostView>>(jobList);
- if (jobList.Count == 0)
- {
- return Ok(JsonView(false, "暂无数据!"));
- }
- return Ok(JsonView(true, "查询成功!", jobList));
- }
- else if (dto.PortType == 2)
- {
- var result = _jobRep.QueryDto<Sys_JobPost, JobPostView>(s => s.CompanyId == dto.CompanyId && s.DepId==dto.DepId).ToList();
- if (result.Count == 0)
- {
- return Ok(JsonView(false, "暂无数据!"));
- }
- return Ok(JsonView(true, "查询成功!", result));
- }
- else if (dto.PortType == 3)
- {
- return Ok(JsonView(false, "暂无数据!"));
- }
- else
- {
- return Ok(JsonView(false, "暂无数据!"));
- }
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, "程序错误!"));
- throw;
- }
- }
- /// <summary>
- /// 添加岗位
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> AddJobPost(AddJobPostDto dto)
- {
- try
- {
- Sys_JobPost sys_Job = _mapper.Map<Sys_JobPost>(dto);
- int id = await _jobRep.AddAsyncReturnId(sys_Job);
- if (id == 0)
- {
- return Ok(JsonView(false, "添加失败"));
- }
- return Ok(JsonView(true, "添加成功", new { Id = id }));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, "程序错误!"));
- throw;
- }
- }
- /// <summary>
- /// 修改岗位
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> EditJobPost(EditJobPostDto dto)
- {
- try
- {
- bool res = await _jobRep.UpdateAsync<Sys_JobPost>(a=>a.Id==dto.Id,a =>new Sys_JobPost
- {
- CompanyId=dto.CompanyId,
- DepId=dto.DepId,
- JobName=dto.JobName,
- Remark=dto.Remark,
- });
- if (!res)
- {
- return Ok(JsonView(false, "修改失败"));
- }
- return Ok(JsonView(true, "修改成功"));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, "程序错误!"));
- throw;
- }
- }
- /// <summary>
- /// 删除岗位
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> DelJobPost(DelJobPostDto dto)
- {
- try
- {
- bool res = await _jobRep.SoftDeleteAsync<Sys_JobPost>(dto.Id.ToString());
- if (!res)
- {
- return Ok(JsonView(false, "删除失败!"));
- }
- return Ok(JsonView(true, "删除成功"));
- }
- catch (Exception)
- {
- return Ok(JsonView(false, "程序错误!"));
- throw;
- }
- }
- #endregion
- #region 用户操作
- /// <summary>
- /// 查询所有员工名称
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GetUserNameList(DtoBase dto)
- {
- try
- {
- var result = _userRep.GetUserNameList(dto.PortType);
- if (result.Result.Code != 0)
- {
- return Ok(JsonView(false, "暂无数据!"));
- }
- return Ok(JsonView(true, "查询成功!", result.Result.Data));
- }
- catch (Exception)
- {
- return Ok(JsonView(false, "程序错误!"));
- throw;
- }
- }
- /// <summary>
- /// 查询所有员工(web)
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GetUserList(DtoBase dto)
- {
- try
- {
- var result = _userRep.GetUserList(dto.PortType, string.Empty);
- if (result.Result.Code != 0)
- {
- return Ok(JsonView(false, "暂无数据!"));
- }
- return Ok(JsonView(true, "查询成功!", result.Result.Data));
- }
- catch (Exception)
- {
- return Ok(JsonView(false, "程序错误!"));
- throw;
- }
- }
- /// <summary>
- /// 查询用户数据
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> QueryUserList(UserDto dto)
- {
- try
- {
- string sqlWhere = string.Format(" Where su.IsDel = 0 ");
- if (dto.CompanyId!=0)
- {
- sqlWhere += string.Format(@" And su.CompanyId={0}", dto.CompanyId);
- }
- if (dto.DepId != 0)
- {
- sqlWhere += string.Format(@" And su.DepId={0}", dto.DepId);
- }
- if (dto.JobPostId != 0)
- {
- sqlWhere += string.Format(@" And su.JobPostId={0}", dto.JobPostId);
- }
-
- List<UserInfo> _userList =await _userRep.QueryUser(sqlWhere);
- if (_userList.Count == 0)
- {
- return Ok(JsonView(false, "暂无数据!"));
- }
- List<UserInfoWebView> userList = _mapper.Map<List<UserInfoWebView>>(_userList);
- return Ok(JsonView(true,"查询成功!", userList));
- }
- catch (Exception)
- {
- return Ok(JsonView(false, "程序错误!"));
- throw;
- }
-
- }
- /// <summary>
- /// 修改用户信息(上级修改/分配 公司、部门、岗位、工号等信息)
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> EditUser(EditUserDto dto)
- {
- try
- {
- bool res = await _userRep.UpdateAsync<Sys_Users>(a => a.Id == dto.Id, a => new Sys_Users
- {
- Number = dto.Number,
- CompanyId = dto.CompanyId,
- DepId = dto.DepId,
- JobPostId = dto.JobPostId,
- Ext = dto.Ext,
- UsePeriod = dto.UsePeriod,
- HrAudit = dto.HrAudit
- });
- if (!res)
- {
- return Ok(JsonView(false, "修改失败!"));
- }
- return Ok(JsonView(true, "修改成功!"));
- }
- catch (Exception)
- {
- return Ok(JsonView(false, "程序错误!"));
- throw;
- }
- }
- /// <summary>
- /// 修改用户信息(登录用户修改个人信息)
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> EditMyUser(EditMyUserDto dto)
- {
- try
- {
- if (string.IsNullOrWhiteSpace(dto.CnName) || string.IsNullOrWhiteSpace(dto.Address) || string.IsNullOrWhiteSpace(dto.IDCard) || dto.Sex != 0 && dto.Sex != 1 ||
- string.IsNullOrWhiteSpace(dto.MaritalStatus) || string.IsNullOrWhiteSpace(dto.HomeAddress)|| dto.Birthday>=DateTime.Now.AddYears(-1))
- {
- return Ok(JsonView(false, "请完善你的个人信息!"));
- }
- else if (string.IsNullOrWhiteSpace(dto.GraduateInstitutions) || string.IsNullOrWhiteSpace(dto.Professional) || dto.Education == 0 || string.IsNullOrWhiteSpace(dto.GraduateInstitutions))
- {
- return Ok(JsonView(false, "请完善你的学历信息!"));
- }
- else if (string.IsNullOrWhiteSpace(dto.Phone) || string.IsNullOrWhiteSpace(dto.UrgentPhone) || string.IsNullOrWhiteSpace(dto.Email))
- {
- return Ok(JsonView(false, "请检查联系方式、紧急联系人及邮箱输写是否正确!"));
- }
- else
- {
- bool res = await _userRep.UpdateAsync<Sys_Users>(a => a.Id == dto.Id, a => new Sys_Users
- {
- CnName = dto.CnName,
- EnName = dto.EnName,
- Sex = dto.Sex,
- Phone = dto.Phone,
- UrgentPhone = dto.UrgentPhone,
- Email = dto.Email,
- Address = dto.Address,
- Edate = dto.Edate,
- Birthday = dto.Birthday,
- IDCard = dto.IDCard,
- GraduateInstitutions = dto.GraduateInstitutions,
- Professional = dto.Professional,
- Education = dto.Education,
- TheOrAdultEducation = dto.TheOrAdultEducation,
- MaritalStatus = dto.MaritalStatus,
- HomeAddress = dto.HomeAddress,
- WorkExperience = dto.WorkExperience,
- Certificate = dto.Certificate
- });
- if (!res)
- {
- return Ok(JsonView(false, "修改失败!"));
- }
- return Ok(JsonView(true, "修改成功!"));
- }
-
- }
- catch (Exception)
- {
- return Ok(JsonView(false, "程序错误!"));
- throw;
- }
- }
- /// <summary>
- /// 删除用户信息
- /// 即为离职
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PostUserDelById(UserDelDto dto)
- {
- try
- {
- if (dto == null)
- {
- return Ok(JsonView(false, "参数不能为空!"));
- }
- Sys_Users _Users=_sqlSugar.Queryable<Sys_Users>().First(a=>a.IsDel==0 && a.Id==dto.Id);
- if (_Users != null)
- {
- List<Sys_Users> sys_UsersList=_sqlSugar.Queryable<Sys_Users>().Where(a=>a.IsDel==0 && a.CompanyId==_Users.CompanyId).ToList();
- if (sys_UsersList.Count==1)
- {
- return Ok(JsonView(false, "该人员为公司最后一位,不可删除!"));
- }
- }
-
- bool res = await _userRep.UpdateAsync<Sys_Users>(a => a.Id == dto.Id, a => new Sys_Users
- {
- IsDel = 1,
- DeleteUserId = dto.OperateUserId,
- DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
- Rdate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
- });
- if (!res)
- {
- return Ok(JsonView(false, "操作失败!"));
- }
- return Ok(JsonView(true, "操作成功!"));
- }
- catch (Exception)
- {
- return Ok(JsonView(false, "程序错误!"));
- }
- }
- /// <summary>
- /// 人事审核
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PersonnelAudit(PersonnelAuditDto dto)
- {
- try
- {
- if (dto == null)
- {
- return Ok(JsonView(false, "参数不能为空!"));
- }
- bool res = await _userRep.UpdateAsync<Sys_Users>(a => a.Id == dto.Id, a => new Sys_Users
- {
- HrAudit=dto.isAudit
- });
- if (!res)
- {
- return Ok(JsonView(false, "操作失败!"));
- }
- return Ok(JsonView(true, "操作成功!"));
- }
- catch (Exception)
- {
- return Ok(JsonView(false, "程序错误!"));
- }
- }
- #endregion
- #region 权限模块
- /// <summary>
- /// 权限数据页面初始化
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- //[Authorize]
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GetAuth(AuthDto dto)
- {
- Result result = new Result();
- //模块数据
- var setDataResult = await _setDataRepository.GetSySDefultModule();
- if (setDataResult.Code != 0)
- {
- return Ok(JsonView(setDataResult.Msg));
- }
- //操作方式
- var PageOperation = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, Sys_PageFunctionPermission>(x=>x.IsEnable == 1).ToList();
- //获取所有关联页面
- var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
- //页面数据
- var SystemMenuPermissionData = _SystemMenuPermissionRepository.QueryDto<Sys_SystemMenuPermission, SystemMenuPermissionView>(x=>x.Mid == dto.moduleId && x.IsEnable == 1).ToList();
- if (SystemMenuPermissionData == null || SystemMenuPermissionData.Count() == 0)
- {
- return Ok(JsonView("暂无数据"));
- }
- ArrayList viewData = new ArrayList();
- //组合页面数据
- foreach (var item in SystemMenuPermissionData)
- {
- ArrayList ids = new ArrayList();
- foreach (var viewop in PageOperation)
- {
- var op = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.SmId == item.Id && x.FId == viewop.Id);
- if (op != null)
- {
- ids.Add(viewop.Id);
- }
- }
- viewData.Add(new
- {
- Id = item.Id,
- Mid = item.Mid,
- Name = item.Name,
- SystemMenuCode = item.SystemMenuCode,
- opList = ids,
- selList = new string[0]
- }) ;
- }
- //公司数据
- var CompanyDataResult = _CompanyRepository.GetCompanyData();
- if (CompanyDataResult.Code != 0)
- {
- return Ok(JsonView(CompanyDataResult.Msg));
- }
- result.Code = 0;
- result.Msg = "成功!";
- var Dyresult = new
- {
- setDataResult = setDataResult.Data,
- CompanyDataResult = CompanyDataResult.Data,
- SystemMenuPermissionData = viewData,
- PageOperation = PageOperation,
- };
- return Ok(JsonView(200, "成功!", Dyresult));
- }
- /// <summary>
- /// 获取职务权限
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public IActionResult QueryJobAuth(QueryJobAuthDto dto)
- {
- //选中的操作权限
- var DBdata = _JobPostAuthorityRepository.QueryDto<Sys_JobPostAuthority, JobPostAuthorityView>(x=>x.JpId == dto.jobid).ToList();
- var SystemMenuPermissionData = _SystemMenuPermissionRepository.QueryDto<Sys_SystemMenuPermission, SystemMenuPermissionView>(x => x.Mid == dto.moduleId).ToList();
- if (SystemMenuPermissionData == null || SystemMenuPermissionData.Count() == 0)
- {
- return Ok(JsonView("暂无数据"));
- }
- //所有操作
- var PageOperation = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, Sys_PageFunctionPermission>().ToList();
- //获取所有关联页面
- var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
- ArrayList viewData = new ArrayList();
- //组合页面数据
- foreach (var item in SystemMenuPermissionData)
- {
- ArrayList ids = new ArrayList();
- foreach (var viewop in PageOperation)
- {
- var op = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.SmId == item.Id && x.FId == viewop.Id);
- if (op != null)
- {
- ids.Add(viewop.Id);
- }
- }
- //获取本职务的页面拥有的权限
- var DBwhere = DBdata.Where(x => x.SmId == item.Id && x.JpId == dto.jobid).ToList();
- viewData.Add(new
- {
- Id = item.Id,
- Mid = item.Mid,
- Name = item.Name,
- SystemMenuCode = item.SystemMenuCode,
- opList = ids,
- selList = DBwhere.Select(x => x.FId)
- }) ;
- }
- return Ok(JsonView(200, "成功!", viewData));
- }
- /// <summary>
- /// 保存岗位权限
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> SaveJobAuth(SaveJobDto dto)
- {
- //获取所有关联页面
- var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
- var RemoveJobPostAuthList = _SystemMenuAndFunctionRepository._sqlSugar.SqlQueryable<Sys_JobPostAuthority>($@"
- select a.* from Sys_JobPostAuthority a, Sys_SetData b ,Sys_SystemMenuPermission c
- where a.SmId = c.Id and c.Mid = b.Id and JpId = {dto.Jpid} and c.Mid ={dto.modulId}
- ").ToList();
- List<Sys_JobPostAuthority> adds = new List<Sys_JobPostAuthority>();
- foreach (var item in dto.Savejobs)
- {
- foreach (var fid in item.FIds)
- {
- var whereobj = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.FId == fid && x.SmId == item.SmId);
- if (whereobj != null)
- {
- adds.Add(new Sys_JobPostAuthority
- {
- CreateTime = DateTime.Now,
- CreateUserId = 245,
- FId = fid,
- JpId = dto.Jpid,
- SmId = item.SmId
- });
- }
- }
- }
- _JobPostAuthorityRepository.BeginTran();
- try
- { //删除岗位
- bool isdel = await _JobPostAuthorityRepository.DeletesAsync<Sys_JobPostAuthority>(RemoveJobPostAuthList);
- int UpRows = _JobPostAuthorityRepository.Adds<Sys_JobPostAuthority>(adds);
- //获取所有职位员工
- var jobUserAll = await QueryUserList(new UserDto { PortType = 2, JobPostId = dto.Jpid });
- List<UserInfoWebView> users = null;
- var QueryUserListApiResult = (((jobUserAll as OkObjectResult).Value) as OASystem.Domain.ViewModels.JsonView);
- if (QueryUserListApiResult != null)
- {
- if (QueryUserListApiResult.Code == 200)
- {
- users = QueryUserListApiResult.Data as List<UserInfoWebView>;
- }
- }
- if (users != null && users.Count > 0)
- {
- List<Sys_UserAuthority> userAuth = null;
- var uids = string.Join(',', users.Select(x => x.Id)).TrimEnd(',');
- var RemoveUserAuthorityListAndTemp = _UserAuthorityRepository._sqlSugar.SqlQueryable<Sys_UserAuthority>($@"
- select a.* from Sys_UserAuthority a, Sys_SetData b ,Sys_SystemMenuPermission c
- where a.SmId = c.Id and c.Mid = b.Id and uid in ({uids}) and c.Mid = {dto.modulId} and IsTemp = 1
- ").ToList();
- foreach (var user in users)
- {
- //删除个人级岗位权限
- isdel = await _UserAuthorityRepository.DeletesAsync<Sys_UserAuthority>
- (RemoveUserAuthorityListAndTemp.FindAll(x=>x.UId == user.Id));
- userAuth = adds.Select(x=> new Sys_UserAuthority
- {
- CreateTime = DateTime.Now,
- CreateUserId = 235,
- FId = x.FId,
- SmId = x.SmId,
- UId = user.Id,
- IsTemp = 1,
- }).ToList();
- //添加个人级别岗位
- int AddRows = _UserAuthorityRepository.Adds<Sys_UserAuthority>(userAuth);
- }
- }
- }
- catch (Exception ex)
- {
- _JobPostAuthorityRepository.RollbackTran();
- return Ok(JsonView("系统错误!"));
- }
- _JobPostAuthorityRepository.CommitTran();
- return Ok(JsonView(200, "成功", new { }));
- }
- /// <summary>
- /// 获取员工权限
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public IActionResult QueryUserAuth(QueryUserAuthDto dto)
- {
- //选中的员工操作权限
- var DBdata = _UserAuthorityRepository.QueryDto<Sys_UserAuthority, UserAuthorityView>(x => x.UId == dto.Userid).ToList();
- var SystemMenuPermissionData = _SystemMenuPermissionRepository.QueryDto<Sys_SystemMenuPermission, SystemMenuPermissionView>(x => x.Mid == dto.moduleId).ToList();
- if (SystemMenuPermissionData == null || SystemMenuPermissionData.Count() == 0)
- {
- return Ok(JsonView("暂无数据"));
- }
- //所有操作
- var PageOperation = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, Sys_PageFunctionPermission>(x=>x.IsEnable == 1).ToList();
- //获取所有关联页面
- var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
- ArrayList viewData = new ArrayList();
- //组合页面数据
- foreach (var item in SystemMenuPermissionData)
- {
- ArrayList ids = new ArrayList();
- foreach (var viewop in PageOperation)
- {
- var op = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.SmId == item.Id && x.FId == viewop.Id);
- if (op != null)
- {
- ids.Add(viewop.Id);
- }
- }
- //获取本员工拥有的权限
- var DBwhere = DBdata.Where(x => x.SmId == item.Id && x.UId == dto.Userid).ToList();
- viewData.Add(new
- {
- Id = item.Id,
- Mid = item.Mid,
- Name = item.Name,
- SystemMenuCode = item.SystemMenuCode,
- opList = ids,
- selList = DBwhere.Select(x => x.FId)
- });
- }
- return Ok(JsonView(200, "成功!", viewData));
- }
- /// <summary>
- /// 保存员工权限
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> SaveUserAuth(SaveUserDto dto)
- {
- //获取所有关联页面
- var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
- //获取用户当前模块所有启用页面
- var userpageList = _SystemMenuPermissionRepository._sqlSugar.SqlQueryable<Sys_UserAuthority>($@"
- select a.* from Sys_UserAuthority a, Sys_SetData b ,Sys_SystemMenuPermission c
- where a.SmId = c.Id and c.Mid = b.Id and uid = {dto.uid} and c.Mid ={dto.Modulid}
- ").ToList();
- List<Sys_UserAuthority> adds = new List<Sys_UserAuthority>();
- foreach (var item in dto.Savejobs)
- {
- foreach (var fid in item.FIds)
- {
- var whereobj = Sys_SystemMenuAndFunction.FirstOrDefault(x => x.FId == fid && x.SmId == item.SmId);
- if (whereobj != null)
- {
- adds.Add(new Sys_UserAuthority
- {
- CreateTime = DateTime.Now,
- CreateUserId = 235,
- FId = fid,
- UId = dto.uid,
- SmId = item.SmId,
- IsTemp = 0
- });
- }
- }
- }
- _JobPostAuthorityRepository.BeginTran();
- try
- {
- List<Sys_UserAuthority> userAuth = null;
- //删除个人级岗位权限
- bool isdel = await _UserAuthorityRepository.DeletesAsync<Sys_UserAuthority>(userpageList);
- userAuth = adds.Select(x => new Sys_UserAuthority
- {
- CreateTime = DateTime.Now,
- CreateUserId = 235,
- FId = x.FId,
- SmId = x.SmId,
- UId = dto.uid,
- IsTemp = 0,
- }).ToList();
- //添加个人级别岗位
- int AddRows = _UserAuthorityRepository.Adds<Sys_UserAuthority>(userAuth);
- }
- catch (Exception ex)
- {
- _JobPostAuthorityRepository.RollbackTran();
- return Ok(JsonView("系统错误!"));
- }
- _JobPostAuthorityRepository.CommitTran();
- return Ok(JsonView(200, "成功", new { }));
- }
- #endregion
- #region 页面配置
- /// <summary>
- /// 页面配置界面数据初始化
- /// </summary>
- /// <returns></returns>
- //[Authorize]
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PageConfigInit()
- {
- ArrayList arr = new ArrayList();
- var viewList = await _setDataRepository.GetSetDataAndPageInfoBySTId();
- if (viewList.Code != 0)
- {
- return Ok(JsonView(viewList.Msg));
- }
- var ModList = await _setDataRepository.GetSySDefultModule();
- return Ok(JsonView(new
- {
- viewList,
- ModList,
- }));
- }
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> EditPageInfo(SetDataAndPageInfoView dto)
- {
- JsonView view = null;
- _SystemMenuPermissionRepository.BeginTran();
- var istrue = await _SystemMenuPermissionRepository.UpdateAsync(x=>x.Id == dto.Pageid ,x=> new Sys_SystemMenuPermission
- {
- AndroidUrl = dto.AndroidUrl,
- CreateTime = DateTime.Now,
- Icon = dto.Icon,
- IosUrl = dto.IosUrl,
- Name = dto.PageName,
- PhoneIsEnable = dto.PagePhoneIsEnable,
- CreateUserId = 235,
- IsDel = 0,
- IsEnable = dto.PageIsEnable,
- Mid = dto.Modulid,
- Remark = dto.PageRemark,
- SystemMenuCode = dto.SystemMenuCode,
- WebUrl = dto.WebUrl,
- });
- if (istrue)
- {
- //删除页面绑定的操作后重新绑定
- await _SystemMenuAndFunctionRepository.DeleteAsync(x => x.SmId == dto.Pageid);
- List<Sys_SystemMenuAndFunction> binFun = new List<Sys_SystemMenuAndFunction>();
- foreach (var item in dto.FunArr)
- {
- binFun.Add(new Sys_SystemMenuAndFunction
- {
- CreateTime = DateTime.Now,
- CreateUserId = 235,
- FId = item,
- SmId = dto.Pageid,
- IsDel = 0,
- });
- }
- int number = _SystemMenuAndFunctionRepository.Adds<Sys_SystemMenuAndFunction>(binFun);
- view = JsonView(istrue);
- _SystemMenuPermissionRepository.CommitTran();
- }
- else
- {
- _SystemMenuPermissionRepository.RollbackTran();
- view = JsonView("添加失败");
- }
- return Ok(view);
- }
-
- /// <summary>
- /// 添加一个页面
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> AddPageInfo(SetDataAndPageInfoView dto)
- {
- JsonView view = null;
- _SystemMenuPermissionRepository.BeginTran();
- int number = await _SystemMenuPermissionRepository.AddAsyncReturnId(new Sys_SystemMenuPermission
- {
- AndroidUrl = dto.AndroidUrl,
- CreateTime = DateTime.Now,
- Icon = dto.Icon,
- IosUrl = dto.IosUrl,
- Name = dto.PageName,
- PhoneIsEnable = dto.PagePhoneIsEnable,
- CreateUserId = 235,
- IsDel = 0,
- IsEnable = dto.PageIsEnable,
- Mid = dto.Modulid,
- Remark = dto.PageRemark,
- SystemMenuCode = dto.SystemMenuCode,
- WebUrl = dto.WebUrl,
- });
- List<Sys_SystemMenuAndFunction> binFun = new List<Sys_SystemMenuAndFunction>();
- foreach (var item in dto.FunArr)
- {
- binFun.Add(new Sys_SystemMenuAndFunction
- {
- CreateTime = DateTime.Now,
- CreateUserId = 235,
- FId = item,
- SmId = number,
- IsDel = 0,
- });
- }
- number = _SystemMenuAndFunctionRepository.Adds<Sys_SystemMenuAndFunction>(binFun);
- if (number > 0)
- {
- view = JsonView(number);
- _SystemMenuPermissionRepository.CommitTran();
- }
- else
- {
- _SystemMenuPermissionRepository.RollbackTran();
- view = JsonView("添加失败");
- }
- return Ok(view);
- }
- /// <summary>
- /// 删除页面
- /// </summary>
- /// <param></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> DelPageInfo(List<SystemMenuDelDto> Dto)
- {
- JsonView view = new JsonView();
- if (Dto.Count > 0)
- {
- try
- {
- _SystemMenuPermissionRepository.BeginTran();
- bool istrue = false;
- foreach (var item in Dto)
- {
- istrue = await _SystemMenuPermissionRepository.SoftDeleteAsync(item.Pageid.ToString());
- if (!istrue)
- {
- throw new Exception("修改失败");
- }
- }
-
- view.Code = 200;
- view.Msg = "删除成功!";
- view.Data = istrue;
- _SystemMenuPermissionRepository.CommitTran();
- }
- catch (Exception)
- {
- _SystemMenuPermissionRepository.RollbackTran();
- }
- }
- return Ok(JsonView(view));
- }
-
- /// <summary>
- /// 获取页面绑定的操作
- /// </summary>
- /// <param name="Dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> QueryPageFunById(PageFunDto Dto)
- {
- //页面与操作关联表
- var pageAndFunList = _SystemMenuAndFunctionRepository.QueryDto<Sys_SystemMenuAndFunction, SystemMenuAndFunctionView>().ToList();
- //页面功能表
- var pageFunList = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, Sys_PageFunctionPermission>(x => x.IsEnable == 1).ToList();
- ArrayList arr = new ArrayList();
- foreach (var item in pageFunList)
- {
- var FindVal = pageAndFunList.Find(x => x.SmId == Dto.Pageid && x.FId == item.Id);
- if (FindVal == null)
- {
- arr.Add(new
- {
- id = item.Id,
- name = item.FunctionName,
- value =false
- });
- }
- else
- {
- arr.Add( new {
- id = item.Id,
- name = item.FunctionName,
- value = true
- });
- }
- }
- return Ok(JsonView(arr));
- }
- #endregion
- #region 页面操作
- /// <summary>
- /// 操作权限功能表
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> PageFunInit()
- {
- try
- {
- var PageFunInit = _PageFunctionPermissionRepository.QueryDto<Sys_PageFunctionPermission, PageFunctionPermissionView>().ToList();
- if (PageFunInit == null)
- {
- return Ok(JsonView(false, "暂无数据!"));
- }
- return Ok(JsonView(true, "查询成功!", PageFunInit));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, "程序错误!"));
- throw;
- }
- }
- /// <summary>
- /// 操作权限功能表操作(Status 1:添加,2:编辑)
- /// </summary>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> OperationFun(OperationFunInitDta dto)
- {
- try
- {
- Result result = await _PageFunctionPermissionRepository.OperationFunInit(dto);
- if (result.Code != 0)
- {
- return Ok(JsonView(false, result.Msg));
- }
- return Ok(JsonView(true, result.Msg));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, "程序错误!"));
- throw;
- }
- }
- /// <summary>
- /// 删除功能
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> DelFun(DelFunInitDta dto)
- {
- try
- {
- var res = await _PageFunctionPermissionRepository.SoftDeleteByIdAsync<Sys_PageFunctionPermission>(dto.Id.ToString(), dto.DeleteUserId);
- if (!res)
- {
- return Ok(JsonView(false, "删除失败"));
- }
- return Ok(JsonView(true, "删除成功!"));
- }
- catch (Exception ex)
- {
- return Ok(JsonView(false, "程序错误!"));
- }
- }
-
- #endregion
- }
- }
|