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 { /// /// 系统设置 /// //[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 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, 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; _setDataRepository = setDataRepository; _CompanyRepository = companyRepository; _SystemMenuPermissionRepository = systemMenuPermissionRepository; _PageFunctionPermissionRepository = pageFunctionPermissionRepository; _SystemMenuAndFunctionRepository = systemMenuAndFunctionRepository; _JobPostAuthorityRepository = jobPostAuthorityRepository; _UserAuthorityRepository = userAuthorityRepository; _jobRep = jobRep; _setDataTypeRep = setDataTypeRep; } #region 消息 /// /// 获取消息列表 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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)); } /// /// 获取消息详细信息 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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)); } /// /// 消息设置已读 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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)); } /// /// 消息设置已读 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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 数据类型资料 /// /// 根据类型查询数据 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task QuerySetData(SetDataDto dto) { try { if (dto.DataType == 0) { return Ok(JsonView(false, "请传类型Id!")); } var setData = _setDataRepository.QueryDto(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; } } /// /// 数据类型表查询 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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; } } /// /// 数据类型表操作(Status:1.新增,2.修改) /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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; } } /// /// 数据类型表操作删除 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task DelSetDataType(DelSetDataTypeDto dto) { try { var res = await _setDataTypeRep.SoftDeleteByIdAsync(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 数据类型板块 /// /// 数据类型板块表查询 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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; } } /// /// 数据类型板块表操作(Status:1.新增,2.修改) /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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; } } /// /// 数据类型表操作删除 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task DelSetData(DelSetDataDto dto) { try { var res = await _setDataRepository.SoftDeleteByIdAsync(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 企业操作 /// /// 查询企业数据 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task getCompanyList(DtoBase dto) { try { if (dto.PortType == 1) { var CompanyDataResult = _CompanyRepository.GetCompanyData(); if (CompanyDataResult.Code != 0) { return Ok(JsonView(CompanyDataResult.Msg)); } List companyListView = _mapper.Map>(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(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; } } /// /// 添加企业数据 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView),StatusCodes.Status200OK)] public async Task 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(dto); int id = await _syscomRep.AddAsyncReturnId(_Company); if (id == 0) { return Ok(JsonView(false, "添加失败!")); } return Ok(JsonView(true,"添加成功", new { Id = id })); } } catch (Exception) { return Ok(JsonView(false, "程序错误!")); throw; } } /// /// 企业修改 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async TaskEditCompany(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; } } /// /// 企业删除 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task DelCompany(DelCompanyDto dto) { try { bool res = await _syscomRep.SoftDeleteAsync(dto.Id.ToString()); if (!res) { return Ok(JsonView(false, "删除失败")); } return Ok(JsonView(true, "删除成功")); } catch (Exception) { return Ok(JsonView(false, "程序错误!")); throw; } } #endregion #region 部门操作 /// /// 查询部门数据 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task QueryDepartmentList(DepartmentDto dto) { try { if (dto.PortType==1) { if (dto.CompanyId!=0) { var result = _sysDepRep.QueryDto(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(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(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(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(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; } } /// /// 部门添加 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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(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; } } /// /// 部门修改 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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(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; } } /// /// 部门删除 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task DelDepartment(DelDepartmentDto dto) { try { if (dto.Id == 0) { return Ok(JsonView(-1, "请检查信息是否输入完整!", null)); } else { bool res =await _sysDepRep.SoftDeleteAsync(dto.Id.ToString()); if (!res) { return Ok(JsonView(false, "删除失败!")); } return Ok(JsonView(true, "删除成功!")); } } catch (Exception) { return Ok(JsonView(false, "程序错误!")); throw; } } #endregion #region 岗位板块 /// /// 岗位查询 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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 jobList = await _jobRep.QueryJobPost(sqlWhere); List List = _mapper.Map>(jobList); if (jobList.Count == 0) { return Ok(JsonView(false, "暂无数据!")); } return Ok(JsonView(true, "查询成功!", jobList)); } else if (dto.PortType == 2) { var result = _jobRep.QueryDto(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; } } /// /// 添加岗位 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task AddJobPost(AddJobPostDto dto) { try { Sys_JobPost sys_Job = _mapper.Map(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; } } /// /// 修改岗位 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task EditJobPost(EditJobPostDto dto) { try { bool res = await _jobRep.UpdateAsync(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; } } /// /// 删除岗位 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task DelJobPost(DelJobPostDto dto) { try { bool res = await _jobRep.SoftDeleteAsync(dto.Id.ToString()); if (!res) { return Ok(JsonView(false, "删除失败!")); } return Ok(JsonView(true, "删除成功")); } catch (Exception) { return Ok(JsonView(false, "程序错误!")); throw; } } #endregion #region 用户操作 /// /// 查询所有员工名称 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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; } } /// /// 查询所有员工(web) /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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; } } /// /// 查询用户数据 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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 _userList =await _userRep.QueryUser(sqlWhere); if (_userList.Count == 0) { return Ok(JsonView(false, "暂无数据!")); } List userList = _mapper.Map>(_userList); return Ok(JsonView(true,"查询成功!", userList)); } catch (Exception) { return Ok(JsonView(false, "程序错误!")); throw; } } /// /// 修改用户信息(上级修改/分配 公司、部门、岗位、工号等信息) /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task EditUser(EditUserDto dto) { try { bool res = await _userRep.UpdateAsync(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; } } /// /// 修改用户信息(登录用户修改个人信息) /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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(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; } } /// /// 删除用户信息 /// 即为离职 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task PostUserDelById(UserDelDto dto) { try { if (dto == null) { return Ok(JsonView(false, "参数不能为空!")); } bool res = await _userRep.UpdateAsync(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, "程序错误!")); } } #endregion #region 权限模块 /// /// 权限数据页面初始化 /// /// /// //[Authorize] [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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(x=>x.IsEnable == 1).ToList(); //获取所有关联页面 var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto().ToList(); //页面数据 var SystemMenuPermissionData = _SystemMenuPermissionRepository.QueryDto(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)); } /// /// 获取职务权限 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public IActionResult QueryJobAuth(QueryJobAuthDto dto) { //选中的操作权限 var DBdata = _JobPostAuthorityRepository.QueryDto(x=>x.JpId == dto.jobid).ToList(); var SystemMenuPermissionData = _SystemMenuPermissionRepository.QueryDto(x => x.Mid == dto.moduleId).ToList(); if (SystemMenuPermissionData == null || SystemMenuPermissionData.Count() == 0) { return Ok(JsonView("暂无数据")); } //所有操作 var PageOperation = _PageFunctionPermissionRepository.QueryDto().ToList(); //获取所有关联页面 var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto().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)); } /// /// 保存岗位权限 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task SaveJobAuth(SaveJobDto dto) { //获取所有关联页面 var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto().ToList(); var RemoveJobPostAuthList = _SystemMenuAndFunctionRepository._sqlSugar.SqlQueryable($@" 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 adds = new List(); 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(RemoveJobPostAuthList); int UpRows = _JobPostAuthorityRepository.Adds(adds); //获取所有职位员工 var jobUserAll = await QueryUserList(new UserDto { PortType = 2, JobPostId = dto.Jpid }); List 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; } } if (users != null && users.Count > 0) { List userAuth = null; var uids = string.Join(',', users.Select(x => x.Id)).TrimEnd(','); var RemoveUserAuthorityListAndTemp = _UserAuthorityRepository._sqlSugar.SqlQueryable($@" 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 (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(userAuth); } } } catch (Exception ex) { _JobPostAuthorityRepository.RollbackTran(); return Ok(JsonView("系统错误!")); } _JobPostAuthorityRepository.CommitTran(); return Ok(JsonView(200, "成功", new { })); } /// /// 获取员工权限 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public IActionResult QueryUserAuth(QueryUserAuthDto dto) { //选中的员工操作权限 var DBdata = _UserAuthorityRepository.QueryDto(x => x.UId == dto.Userid).ToList(); var SystemMenuPermissionData = _SystemMenuPermissionRepository.QueryDto(x => x.Mid == dto.moduleId).ToList(); if (SystemMenuPermissionData == null || SystemMenuPermissionData.Count() == 0) { return Ok(JsonView("暂无数据")); } //所有操作 var PageOperation = _PageFunctionPermissionRepository.QueryDto(x=>x.IsEnable == 1).ToList(); //获取所有关联页面 var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto().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)); } /// /// 保存员工权限 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task SaveUserAuth(SaveUserDto dto) { //获取所有关联页面 var Sys_SystemMenuAndFunction = _SystemMenuAndFunctionRepository.QueryDto().ToList(); //获取用户当前模块所有启用页面 var userpageList = _SystemMenuPermissionRepository._sqlSugar.SqlQueryable($@" 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 adds = new List(); 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 userAuth = null; //删除个人级岗位权限 bool isdel = await _UserAuthorityRepository.DeletesAsync(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(userAuth); } catch (Exception ex) { _JobPostAuthorityRepository.RollbackTran(); return Ok(JsonView("系统错误!")); } _JobPostAuthorityRepository.CommitTran(); return Ok(JsonView(200, "成功", new { })); } #endregion #region 页面配置 /// /// 页面配置界面数据初始化 /// /// //[Authorize] [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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 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 binFun = new List(); 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(binFun); view = JsonView(istrue); _SystemMenuPermissionRepository.CommitTran(); } else { _SystemMenuPermissionRepository.RollbackTran(); view = JsonView("添加失败"); } return Ok(view); } /// /// 添加一个页面 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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 binFun = new List(); 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(binFun); if (number > 0) { view = JsonView(number); _SystemMenuPermissionRepository.CommitTran(); } else { _SystemMenuPermissionRepository.RollbackTran(); view = JsonView("添加失败"); } return Ok(view); } /// /// 删除页面 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task DelPageInfo(List 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)); } /// /// 获取页面绑定的操作 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task QueryPageFunById(PageFunDto Dto) { //页面与操作关联表 var pageAndFunList = _SystemMenuAndFunctionRepository.QueryDto().ToList(); //页面功能表 var pageFunList = _PageFunctionPermissionRepository.QueryDto(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 页面操作 /// /// 操作权限功能表 /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task PageFunInit() { try { var PageFunInit = _PageFunctionPermissionRepository.QueryDto().ToList(); if (PageFunInit == null) { return Ok(JsonView(false, "暂无数据!")); } return Ok(JsonView(true, "查询成功!", PageFunInit)); } catch (Exception ex) { return Ok(JsonView(false, "程序错误!")); throw; } } /// /// 操作权限功能表操作(Status 1:添加,2:编辑) /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task 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; } } /// /// 删除功能 /// /// /// [HttpPost] [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)] public async Task DelFun(DelFunInitDta dto) { try { var res = await _PageFunctionPermissionRepository.SoftDeleteByIdAsync(dto.Id.ToString(), dto.DeleteUserId); if (!res) { return Ok(JsonView(false, "删除失败")); } return Ok(JsonView(true, "删除成功!")); } catch (Exception ex) { return Ok(JsonView(false, "程序错误!")); } } #endregion } }