123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518 |
-
- namespace OASystem.API.Controllers
- {
-
-
-
-
- [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 SetDataRepository _setDataRepository;
- private readonly SystemMenuPermissionRepository _SystemMenuPermissionRepository;
- private readonly CompanyRepository _CompanyRepository;
- public SystemController( CompanyRepository syscom,DepartmentRepository sysDepRep, UsersRepository userRep,
- IMapper mapper, SetDataRepository setDataRepository, CompanyRepository companyRepository,
- SystemMenuPermissionRepository systemMenuPermissionRepository)
- {
- _syscomRep = syscom;
- _sysDepRep = sysDepRep;
- _userRep = userRep;
- _mapper = mapper;
- _setDataRepository = setDataRepository;
- _CompanyRepository = companyRepository;
- _SystemMenuPermissionRepository = systemMenuPermissionRepository;
- }
- #region user 操作
-
-
-
-
-
- [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;
- }
- }
- #endregion
- #region 企业操作
-
-
-
-
-
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> getCompanyList(DtoBase dto)
- {
- try
- {
- if (dto.PortType == 1)
- {
- return Ok(JsonView(false, "暂无数据!"));
- }
- 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<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);
- 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 Task<IActionResult>EditCompany(EditCompanyDto dto)
- {
- try
- {
- if (string.IsNullOrWhiteSpace(dto.CompanyName) || string.IsNullOrWhiteSpace(dto.CompanyCode) || string.IsNullOrWhiteSpace(dto.Address) || dto.ParentCompanyId == 0 || 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,
- });
- 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<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 部门操作
-
-
-
-
-
-
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> QueryDepartmentList(DepartmentDto dto)
- {
- try
- {
- if (dto.PortType==1)
- {
- 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;
- }
-
- }
-
-
-
-
-
- [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;
- }
-
-
- }
-
-
-
-
-
- [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;
- }
- }
-
-
-
-
-
- [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 岗位板块
-
-
-
-
-
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> QueryJobPost(QueryJobPostDto dto)
- {
- try
- {
- if (dto.PortType == 1)
- {
- return Ok(JsonView(false, "暂无数据!"));
- }
- else if (dto.PortType == 2)
- {
- var result = _sysDepRep.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;
- }
- }
- #endregion
- #region 用户操作
-
-
-
-
-
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> QueryUserList(UserDto dto)
- {
- try
- {
- string sqlWhere = string.Empty;
- 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 (!string.IsNullOrEmpty(sqlWhere.Trim()))
- {
- Regex r = new Regex("And");
- sqlWhere = r.Replace(sqlWhere, "Where", 1);
- }
- var result=_userRep.GetUserList(dto.PortType,sqlWhere);
- 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<IActionResult> AddUser(AddUserDto dto)
- {
- int id = 0;
- return Ok(JsonView(true, "添加成功!", new { Id = id }));
- }
- #endregion
- #region 权限模块
-
-
-
-
-
- [Authorize]
- [HttpPost]
- [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
- public async Task<IActionResult> GetAuth(AuthDto dto)
- {
- Result result = new Result();
-
- var setDataResult = await _setDataRepository.GetSySDefultModule(_setDataRepository);
- if (setDataResult.Code != 0)
- {
- return Ok(JsonView(setDataResult.Msg));
- }
- List<SetDataView> setDataList = _mapper.Map<List<SetDataView>>(setDataResult.Data);
- var mod = setDataList.Find(x => x.Name == "权限模块");
- if (mod == null)
- {
- return Ok(JsonView("未找到权限模块!"));
- }
-
- var SystemMenuPermissionData = _SystemMenuPermissionRepository.GetSystemMenuViweData(_SystemMenuPermissionRepository, mod.Id, dto.pageSize, dto.currentPage);
- if (SystemMenuPermissionData.Code != 0)
- {
- return Ok(JsonView(SystemMenuPermissionData.Msg));
- }
-
- 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 = SystemMenuPermissionData.Data
- };
- return Ok(JsonView(200, "成功!", Dyresult));
- }
- #endregion
- }
- }
|