|
@@ -1,10 +1,6 @@
|
|
|
|
|
|
-using MySqlX.XDevAPI.Common;
|
|
|
-using OASystem.Domain.Dtos.System;
|
|
|
-using OASystem.Domain.Entities.System;
|
|
|
-using OASystem.Domain.ViewModels.System;
|
|
|
-using OASystem.Infrastructure.Repositories.Login;
|
|
|
-using OASystem.Infrastructure.Repositories.System;
|
|
|
+
|
|
|
+
|
|
|
|
|
|
namespace OASystem.API.Controllers
|
|
|
{
|
|
@@ -15,6 +11,7 @@ namespace OASystem.API.Controllers
|
|
|
[Route("api/[controller]/[action]")]
|
|
|
public class SystemController : ControllerBase
|
|
|
{
|
|
|
+
|
|
|
private readonly CompanyRepository _syscomRep;
|
|
|
private readonly DepartmentRepository _sysDepRep;
|
|
|
private readonly UsersRepository _userRep;
|
|
@@ -30,65 +27,219 @@ namespace OASystem.API.Controllers
|
|
|
}
|
|
|
|
|
|
#region user 操作
|
|
|
-
|
|
|
-
|
|
|
- [HttpGet]
|
|
|
- [ProducesResponseType(typeof(LoginView), StatusCodes.Status200OK)]
|
|
|
- public async Task<IActionResult> GetUserList()
|
|
|
+ /// <summary>
|
|
|
+ /// 查询所有员工(web)
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost]
|
|
|
+ [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
|
|
|
+ public async Task<IActionResult> GetUserList(DtoBase dto)
|
|
|
{
|
|
|
- var userList = _userRep.GetUserList(_userRep);
|
|
|
-
|
|
|
- if (userList.Result.Code != 0)
|
|
|
+ try
|
|
|
{
|
|
|
- return Ok(JsonView(false, userList.Result.Msg));
|
|
|
+ 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;
|
|
|
}
|
|
|
-
|
|
|
- return Ok(JsonView(userList.Result.Data));
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 企业操作
|
|
|
- [HttpGet]
|
|
|
- [ProducesResponseType(typeof(LoginView), StatusCodes.Status200OK)]
|
|
|
- public async Task<IActionResult> getCompanyList()
|
|
|
+ /// <summary>
|
|
|
+ /// 查询企业数据
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="dto"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost]
|
|
|
+ [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
|
|
|
+ public async Task<IActionResult> getCompanyList(DtoBase dto)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- //var companyList = _sysDepRep.QueryDto<Sys_Company, CompanyView>(c=>c.IsDel!=null).ToList();
|
|
|
- string sqlWhere = "select * from Sys_Company";
|
|
|
- var companyList = _syscomRep.GetListBySqlWithNolock(sqlWhere);
|
|
|
- List<CompanyView> DataList = _mapper.Map<List<CompanyView>>(companyList);
|
|
|
- if (DataList.Count == 0)
|
|
|
+ if (dto.PortType == 1)
|
|
|
+ {
|
|
|
+ return Ok(JsonView(false, "暂无数据!"));
|
|
|
+ }
|
|
|
+ else if (dto.PortType == 2)
|
|
|
+ {
|
|
|
+ var companyList = _sysDepRep.QueryDto<Sys_Company, CompanyView>(a=>a.IsDel!=null).ToList();
|
|
|
+ if (companyList.Count == 0)
|
|
|
+ {
|
|
|
+ return Ok(JsonView(false, "暂无数据!"));
|
|
|
+ }
|
|
|
+ return Ok(JsonView(true,"查询成功!",companyList));
|
|
|
+ }
|
|
|
+ else if (dto.PortType == 3)
|
|
|
+ {
|
|
|
+ return Ok(JsonView(false, "暂无数据!"));
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
return Ok(JsonView(false, "暂无数据!"));
|
|
|
}
|
|
|
- return Ok(JsonView(DataList));
|
|
|
}
|
|
|
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);
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <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.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;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <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>
|
|
|
//[Authorize]
|
|
|
[HttpPost]
|
|
|
- [ProducesResponseType(typeof(LoginView), StatusCodes.Status200OK)]
|
|
|
+ [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
|
|
|
public async Task<IActionResult> QueryDepartmentList(DepartmentDto dto)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- var result = _sysDepRep.QueryDto<Sys_Department, DepartmentView>(s => s.CompanyId == dto.CompanyId).ToList();
|
|
|
- if (result.Count==0)
|
|
|
+ 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, "暂无数据!"));
|
|
|
}
|
|
|
- return Ok(JsonView(result));
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
@@ -96,13 +247,126 @@ namespace OASystem.API.Controllers
|
|
|
throw;
|
|
|
}
|
|
|
|
|
|
- //return Ok(JsonView(0, "调用完成:", result));
|
|
|
+ }
|
|
|
+ /// <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(LoginView), StatusCodes.Status200OK)]
|
|
|
+ [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
|
|
|
public async Task<IActionResult> QueryUserList(UserDto dto)
|
|
|
{
|
|
|
try
|
|
@@ -116,24 +380,18 @@ namespace OASystem.API.Controllers
|
|
|
{
|
|
|
sqlWhere += string.Format(@" And su.DepId={0}", dto.DepId);
|
|
|
}
|
|
|
- string userSqlWhere = string.Format(@"Select sjp.JobName,sd.DepName,sc.CompanyName,su.* From Sys_Users su
|
|
|
- Inner Join Sys_Company sc On su.CompanyId = sc.Id
|
|
|
- Inner Join Sys_Department sd On su.DepId = sd.Id
|
|
|
- Inner Join Sys_JobPost sjp On su.JobPostId = sjp.Id where 1=1 {0}",sqlWhere);
|
|
|
- var _userList = _userRep.GetListBySqlWithNolock(userSqlWhere);
|
|
|
- List<UserInfoListView> _userDataList = _mapper.Map<List<UserInfoListView>>(_userList);//这一步,映射不上JobName,DepName,CompanyName,
|
|
|
-
|
|
|
- if (_userDataList.Count==0)
|
|
|
+ if (!string.IsNullOrEmpty(sqlWhere.Trim()))
|
|
|
{
|
|
|
- return Ok(JsonView(false, "暂无数据!"));
|
|
|
+ Regex r = new Regex("And");
|
|
|
+ sqlWhere = r.Replace(sqlWhere, "Where", 1);
|
|
|
}
|
|
|
- for (int i = 0; i < _userDataList.Count; i++)
|
|
|
+ var result=_userRep.GetUserList(dto.PortType,sqlWhere);
|
|
|
+ if (result.Result.Code!=0)
|
|
|
{
|
|
|
- _userDataList[i].CompanyName = _userList[i].CompanyName;
|
|
|
- _userDataList[i].DepName = _userList[i].DepName;
|
|
|
- _userDataList[i].JobName = _userList[i].JobName;
|
|
|
+ return Ok(JsonView(false, "暂无数据!"));
|
|
|
+
|
|
|
}
|
|
|
- return Ok(JsonView(_userDataList));
|
|
|
+ return Ok(JsonView(true,"查询成功!",result.Result.Data));
|
|
|
}
|
|
|
catch (Exception)
|
|
|
{
|