接口调整

parent ac20c91e
......@@ -126,20 +126,6 @@ public ApiResponse<UserResponse> Update([CustomizeValidator(RuleSet = "Update"),
}
/// <summary>
/// 设置用户管辖医院
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("sethospital")]
[HttpPost]
public ApiResponse SetHospital([FromBody]SetHospitalRequest request)
{
if (!_userService.SetHospital(request))
return new ApiResponse(ResponseType.Fail);
return new ApiResponse(ResponseType.OK);
}
/// <summary>
/// 修改用户密码
/// </summary>
/// <param name="request"></param>
......@@ -173,9 +159,9 @@ public ApiResponse<List<sys_role>> RoleList([FromBody]ApiRequest request)
/// <returns></returns>
[Route("department")]
[HttpPost]
public ApiResponse<List<TitleValue>> Department([FromBody]ApiRequest request)
public ApiResponse<List<TitleValue>> Department([FromBody]SetDepartmentRequest request)
{
var department = _userService.Department();
var department = _userService.Department(request.HospitalID);
return new ApiResponse<List<TitleValue>>(ResponseType.OK, "ok", department);
}
}
......
......@@ -8,17 +8,16 @@ namespace Performance.DtoModels
/// <summary>
/// 登录请求
/// </summary>
public class SetHospitalRequest : ApiRequest
public class SetDepartmentRequest : ApiRequest
{
public int UserID { get; set; }
public int[] HosIDArray { get; set; }
public int HospitalID { get; set; }
}
public class SetHospitalRequestValidator : AbstractValidator<SetHospitalRequest>
public class SetDepartmentRequestValidator : AbstractValidator<SetDepartmentRequest>
{
public SetHospitalRequestValidator()
public SetDepartmentRequestValidator()
{
RuleFor(x => x.UserID).GreaterThan(0);
RuleFor(x => x.HospitalID).GreaterThan(0);
}
}
}
......@@ -44,6 +44,11 @@ public class UserRequest : ApiRequest
public int Role { get; set; }
/// <summary>
/// 用户医院ID
/// </summary>
public int[] HosIDArray { get; set; }
/// <summary>
/// 用户科室
/// </summary>
public string Department { get; set; }
......@@ -66,6 +71,7 @@ public UserRequestValidator()
action();
RuleFor(x => x.Role).NotNull().NotEmpty().GreaterThan(0);
RuleFor(x => x.Password).NotNull().NotEmpty().Length(4, 20);
RuleFor(x => x.HosIDArray).NotNull().NotEmpty().Must(f => f.Length > 0);
});
RuleSet("Update", () =>
......@@ -75,6 +81,7 @@ public UserRequestValidator()
RuleFor(x => x.States).InclusiveBetween(1, 2);
RuleFor(x => x.Password).Length(4, 20);
RuleFor(x => x.Role).NotNull().NotEmpty().GreaterThan(0);
RuleFor(x => x.HosIDArray).NotNull().NotEmpty().Must(f => f.Length > 0);
});
RuleSet("Self", () =>
......
using AutoMapper;
using Microsoft.Extensions.Options;
using Newtonsoft.Json.Linq;
using Performance.DtoModels;
using Performance.DtoModels.AppSettings;
using Performance.EntityModels;
using Performance.Repository;
using System;
......@@ -13,6 +15,7 @@ namespace Performance.Services
{
public class UserService : IAutoInjection
{
private Application application;
private PerforUserRepository _userRepository;
private PerforSmsRepository _smsRepository;
private PerforHospitalRepository _hospitalRepository;
......@@ -20,14 +23,18 @@ public class UserService : IAutoInjection
private PerforRoleRepository _roleRepository;
private PerforUserroleRepository _userroleRepository;
private PerforImemployeeRepository _employeeRepository;
public UserService(PerforSmsRepository smsRepository,
private PerforPerallotRepository _perforPerallotRepository;
public UserService(IOptions<Application> application,
PerforSmsRepository smsRepository,
PerforUserRepository userRepository,
PerforHospitalRepository hospitalRepository,
PerforUserhospitalRepository userhospitalRepository,
PerforRoleRepository roleRepository,
PerforUserroleRepository userroleRepository,
PerforImemployeeRepository employeeRepository)
PerforImemployeeRepository employeeRepository,
PerforPerallotRepository perforPerallotRepository)
{
this.application = application.Value;
this._userRepository = userRepository;
this._smsRepository = smsRepository;
this._hospitalRepository = hospitalRepository;
......@@ -35,6 +42,7 @@ public class UserService : IAutoInjection
this._roleRepository = roleRepository;
this._userroleRepository = userroleRepository;
this._employeeRepository = employeeRepository;
this._perforPerallotRepository = perforPerallotRepository;
}
/// <summary>
......@@ -106,12 +114,18 @@ public List<UserResponse> GetUserList(int userID)
/// <param name="request"></param>
public UserResponse Insert(UserRequest request, int userid)
{
int[] roleArray = new int[] { application.NurseRole, application.DirectorRole };
if (null != _userRepository.GetEntity(t => t.Login == request.Login))
throw new PerformanceException("登录名重复");
if (null != _userRepository.GetEntity(t => t.Mobile == request.Mobile))
throw new PerformanceException("手机号重复");
if (request.Role == 3 && string.IsNullOrEmpty(request.Department))
throw new PerformanceException("请选择科室");
if (roleArray.Contains(request.Role) && request.HosIDArray.Length > 1)
throw new PerformanceException("二次绩效管理员只支持单家医院");
if (roleArray.Contains(request.Role) && string.IsNullOrEmpty(request.Department))
throw new PerformanceException("二次绩效管理员科室不能为空");
var user = Mapper.Map<sys_user>(request);
user.CreateDate = DateTime.Now;
user.CreateUser = userid;
......@@ -122,6 +136,9 @@ public UserResponse Insert(UserRequest request, int userid)
throw new PerformanceException("保存失败");
//添加用户角色关联关系
_userroleRepository.Add(new sys_user_role { UserID = user.ID, RoleID = request.Role });
//添加用户医院
SetHospital(request.ID, request.HosIDArray);
return Mapper.Map<UserResponse>(user);
}
......@@ -130,27 +147,27 @@ public UserResponse Insert(UserRequest request, int userid)
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public bool SetHospital(SetHospitalRequest request)
public bool SetHospital(int userId, int[] hosIDArray)
{
var user = _userRepository.GetEntity(t => t.ID == request.UserID);
var user = _userRepository.GetEntity(t => t.ID == userId);
if (null == user)
throw new PerformanceException($"用户不存在 UserId:{request.UserID}");
var userHospital = _userhospitalRepository.GetUserHospital(request.UserID);
throw new PerformanceException($"用户不存在 UserId:{userId}");
var userHospital = _userhospitalRepository.GetUserHospital(userId);
bool rmResult = true, addResult = true;
//获取需要删除的医院
var rmHospital = userHospital.Where(t => !request.HosIDArray.Contains(t.HospitalID.Value));
var rmHospital = userHospital.Where(t => !hosIDArray.Contains(t.HospitalID.Value));
if (rmHospital != null && rmHospital.Count() > 0)
rmResult = _userhospitalRepository.RemoveRange(rmHospital.ToArray());
//获取需要新增的医院
var addHospital = request.HosIDArray.Where(t => !userHospital.Select(u => u.HospitalID).Contains(t));
var addHospital = hosIDArray.Where(t => !userHospital.Select(u => u.HospitalID).Contains(t));
if (addHospital != null && addHospital.Count() > 0)
{
var allHospital = _hospitalRepository.GetEntities();
//获取有效医院ID
var array = addHospital.Where(t => allHospital.Select(h => h.ID).Contains(t))
.Select(t => new sys_user_hospital { UserID = request.UserID, HospitalID = t }).ToArray();
.Select(t => new sys_user_hospital { UserID = userId, HospitalID = t }).ToArray();
addResult = _userhospitalRepository.AddRange(array);
}
......@@ -164,7 +181,7 @@ public bool SetHospital(SetHospitalRequest request)
/// <returns></returns>
public UserResponse Update(UserRequest request)
{
int[] roleArray = new int[] { application.NurseRole, application.DirectorRole };
var user = _userRepository.GetEntity(t => t.ID == request.ID);
if (null == user)
throw new PerformanceException($"用户不存在 UserId:{request.ID}");
......@@ -177,15 +194,11 @@ public UserResponse Update(UserRequest request)
if (null != vlist && vlist.Count() > 0)
throw new PerformanceException("手机号重复");
if (request.Role == 3 && string.IsNullOrEmpty(request.Department))
throw new PerformanceException("请选择科室");
if (roleArray.Contains(request.Role) && string.IsNullOrEmpty(request.Department))
throw new PerformanceException("二次绩效管理员科室不能为空");
//删除用户角色关联关系
var userRole = _userroleRepository.GetEntity(t => t.UserID == request.ID);
if (null != userRole)
_userroleRepository.Remove(userRole);
//添加用户角色关联关系
_userroleRepository.Add(new sys_user_role { UserID = request.ID, RoleID = request.Role });
if (roleArray.Contains(request.Role) && request.HosIDArray.Length > 1)
throw new PerformanceException("二次绩效管理员只支持单家医院");
user.Login = request.Login;
user.Mobile = request.Mobile;
......@@ -197,6 +210,16 @@ public UserResponse Update(UserRequest request)
if (!_userRepository.Update(user))
throw new PerformanceException("保存失败");
//删除用户角色关联关系
var userRole = _userroleRepository.GetEntity(t => t.UserID == request.ID);
if (null != userRole)
_userroleRepository.Remove(userRole);
//添加用户角色关联关系
_userroleRepository.Add(new sys_user_role { UserID = request.ID, RoleID = request.Role });
//添加用户医院
SetHospital(request.ID, request.HosIDArray);
return Mapper.Map<UserResponse>(user);
}
......@@ -266,10 +289,15 @@ public List<sys_role> RoleList()
/// 科室列表
/// </summary>
/// <returns></returns>
public List<TitleValue> Department()
public List<TitleValue> Department(int hospitalID)
{
var department = _employeeRepository.GetEntities(t => t.Department != "").Select(t => t.Department).Distinct();
return department.Select(t => new TitleValue { Title = t, Value = t }).OrderBy(t => t.Title).ToList();
var allotList = _perforPerallotRepository.GetEntities(t => t.HospitalId == hospitalID);
if (allotList != null)
{
var department = _employeeRepository.GetEntities(t => t.Department != "" && allotList.Select(s => s.ID).ToList().Contains(t.AllotID.Value));
return department.Select(t => new TitleValue { Title = t.Department, Value = t.Department }).OrderBy(t => t.Title).Distinct().ToList();
}
return new List<TitleValue>();
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment