Commit 489d61a5 by 钟博

Merge branch 'v2020morge' into v2020morge-graphql

parents f13bd5ed 59ce6d53
......@@ -294,5 +294,77 @@ public ApiResponse<UserResponse> Password(int userId)
var user = _userService.ResetPwd(userId, loginUserId);
return new ApiResponse<UserResponse>(ResponseType.OK, user);
}
#region 多角色
/// <summary>
/// 查询用户信息
/// </summary>
/// <returns></returns>
[Route("selfInfos")]
[HttpPost]
public ApiResponse SelfInfos()
{
var userid = _claim.GetUserId();
var user = _userService.GetUser(userid);
user.Role = _roleService.GetUsersRole(user.UserID);
user.Hospital = _hospitalService.GetUserHopital(user.UserID);
int[] roleArray = new int[] { _options.NurseRole, _options.DirectorRole, _options.SpecialRole, _options.OfficeRole };
user.IsAgainAdmin = user.Role != null ? roleArray.Contains(user.Role.First().Type ?? 0) : false;
return new ApiResponse(ResponseType.OK, user);
}
/// <summary>
/// 新增用户
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("InsertUser")]
[HttpPost]
public ApiResponse<UserResponse> InsertUser([CustomizeValidator(RuleSet = "Insert"), FromBody] UserRequest request)
{
var userId = _claim.GetUserId();
var user = _userService.InsertUser(request, userId);
user.RoleArr = request.RoleArr;
return new ApiResponse<UserResponse>(ResponseType.OK, user);
}
/// <summary>
/// 编辑用户
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("UpdateUser")]
[HttpPost]
public ApiResponse<UserResponse> UpdateUser([CustomizeValidator(RuleSet = "Update"), FromBody] UserRequest request)
{
var userId = _claim.GetUserId();
int[] roleArray = new int[] { _options.NurseRole, _options.DirectorRole, _options.SpecialRole, _options.OfficeRole };
var roles = _roleService.GetUsersRole(userId);
//var roleType = roles.Select(c => c.Type).ToArray();
var intersect= roleArray.Intersect(roles.Select(c=>(int)c.Type).ToArray());
var isAgainAdmin = roles != null ? intersect.Any() : false;
var user = _userService.UpdateUser(request, isAgainAdmin);
user.RoleArr = request.RoleArr;
return new ApiResponse<UserResponse>(ResponseType.OK, user);
}
/// <summary>
/// 新增用户
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("DeleteUser")]
[HttpPost]
public ApiResponse DeleteUser([CustomizeValidator(RuleSet = "Delete"), FromBody] UserRequest request)
{
return _userService.DeleteUser(request.ID);
}
#endregion
}
}
\ No newline at end of file
......@@ -185,6 +185,53 @@ public ApiResponse Import([FromForm] IFormCollection form)
return new ApiResponse(ResponseType.OK, true);
}
/// <summary>
/// 上传文件
/// </summary>
/// <param name="form"></param>
/// <returns></returns>
[Route("ImportExtraction/{allotId}")]
[HttpPost]
public ApiResponse ImportExtraction(int allotId)
{
var allot = _allotService.GetAllot(allotId);
if (allot == null)
return new ApiResponse(ResponseType.Fail, "allotid不存在");
var extract = allot.ExtractPath.Split("\\").Last();
var fileName = System.Text.RegularExpressions.Regex.Replace(extract, @"\d", "");
//var file = ((FormFileCollection)allot.ExtractPath).FirstOrDefault();
//if (file == null)
// return new ApiResponse(ResponseType.Fail, "参数错误", "文件无效");
var name = FileHelper.GetFileNameNoExtension(fileName) + DateTime.Now.ToString("yyyyMMddHHmmssfff");
var ext = FileHelper.GetExtension(fileName);
var dpath = Path.Combine(_evn.ContentRootPath, "Files", $"{allot.HospitalId}", $"{allot.Year}{allot.Month.ToString().PadLeft(2, '0')}");
FileHelper.CreateDirectory(dpath);
var path = Path.Combine(dpath, $"{name}{ext}");
using (var stream = System.IO.File.OpenRead(allot.ExtractPath))
{
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
if (!FileHelper.CreateFile(path, bytes))
return new ApiResponse(ResponseType.Fail, $"上传失败");
allot.Path = path;
allot.States = (int)AllotStates.FileUploaded;
allot.Remark = EnumHelper.GetDescription(AllotStates.FileUploaded);
allot.UploadDate = DateTime.Now;
allot.Generate = (int)AllotGenerate.Init;
if (!_allotService.Update(allot))
return new ApiResponse(ResponseType.Fail, $"上传成功,修改状态失败");
_configService.Clear(allot.ID);
}
return new ApiResponse(ResponseType.OK);
}
/// <summary>
/// 绩效生成
/// </summary>
......
......@@ -42,7 +42,11 @@ public class UserRequest
/// 角色
/// </summary>
public int Role { get; set; }
/// <summary>
/// 角色Arr
/// </summary>
public int[] RoleArr { get; set; }
/// <summary>
/// 用户医院ID
/// </summary>
......@@ -69,7 +73,7 @@ public UserRequestValidator()
RuleSet("Insert", () =>
{
action();
RuleFor(x => x.Role).NotNull().NotEmpty().GreaterThan(0);
RuleFor(x => x.RoleArr).NotNull().NotEmpty();
RuleFor(x => x.Password).NotNull().NotEmpty().Length(4, 20);
RuleFor(x => x.HosIDArray).NotNull().NotEmpty().Must(f => f.Length > 0);
});
......@@ -80,7 +84,7 @@ public UserRequestValidator()
RuleFor(x => x.ID).NotNull().NotEmpty().GreaterThan(0);
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.RoleArr).NotNull().NotEmpty();
RuleFor(x => x.HosIDArray).NotNull().NotEmpty().Must(f => f.Length > 0);
});
......
......@@ -32,5 +32,7 @@ public class RoleResponse
/// 首页地址
/// </summary>
public string IndexUrl { get; set; }
public int Value { get; set; }
}
}
......@@ -17,5 +17,7 @@ public class UserResponse
public string Hospital { get; set; }
public int Role { get; set; }
public string Department { get; set; }
public int[] RoleArr { get; set; }
}
}
......@@ -70,5 +70,10 @@ public class sys_user
/// 删除状态 1可用 2删除
/// </summary>
public Nullable<int> IsDelete { get; set; }
/// <summary>
/// 父级ID
/// </summary>
public Nullable<int> ParentID { get; set; }
}
}
......@@ -30,6 +30,7 @@ public class CollectService : IAutoInjection
private readonly PerforCollectpermissionRepository perforcollectpermissionRepository;
private readonly PerforUserroleRepository userroleRepository;
private readonly PerforImaccountbasicRepository perforImaccountbasicRepository;
private readonly PerforPerdeptdicRepository perforPerdeptdicRepository;
private readonly SheetSevice sheetSevice;
private readonly Application options;
......@@ -46,6 +47,7 @@ public class CollectService : IAutoInjection
PerforCollectpermissionRepository perforcollectpermissionRepository,
PerforUserroleRepository userroleRepository,
PerforImaccountbasicRepository perforImaccountbasicRepository,
PerforPerdeptdicRepository perforPerdeptdicRepository,
SheetSevice sheetSevice,
IOptions<Application> options)
{
......@@ -61,6 +63,7 @@ public class CollectService : IAutoInjection
this.perforcollectpermissionRepository = perforcollectpermissionRepository;
this.userroleRepository = userroleRepository;
this.perforImaccountbasicRepository = perforImaccountbasicRepository;
this.perforPerdeptdicRepository = perforPerdeptdicRepository;
this.sheetSevice = sheetSevice;
this.options = options.Value;
}
......@@ -368,11 +371,27 @@ public HandsonTable GetCollectData(int userId, int allotId, string sheetName)
else if (sheet.SheetType == (int)SheetType.LogisticsEmployee)
rowDatas = GetLogisticsEmployee(sheet);
else if (sheet.SheetType == (int)SheetType.AccountBasic)
rowDatas = GetAccountBasic(sheet);
{
List<HandsonCellData> cells = new List<HandsonCellData>();
var dept = perforPerdeptdicRepository.GetAccountBasicAccountingUnit(allot.HospitalId);
rowDatas = GetAccountBasic(sheet, dept, cells);
}
else
rowDatas = GetCommonData(sheet);
}
//补全核算单元和类型
var sTypes = new[] { (int)SheetType.AccountExtra, (int)SheetType.PersonExtra, (int)SheetType.AccountDrugAssess, (int)SheetType.AccountMaterialsAssess };
var sTypeName = new[] { "6.1目标考核", "6.6 科室预算比例" };
if (sTypes.Contains((int)sheet.SheetType) || sTypeName.Contains(sheet.SheetName))
{
List<HandsonCellData> cells = new List<HandsonCellData>();
var perSheet = perforPersheetRepository.GetEntity(t=>t.AllotID==allotId && t.SheetName=="4.1 临床科室医护绩效测算表");
var dept = perforPerdeptdicRepository.GetAccountBasicAccountingUnit(allot.HospitalId);
GetAccountBasic(perSheet, dept, cells);
UnitFit(rowDatas, cells, sheet);
}
if (rowDatas == null || !rowDatas.Any())
rowDatas = GetAccountExtra(allot, sheet.SheetType.Value);
......@@ -514,10 +533,11 @@ private HandsonRowData CreateRowData(int row, ColumnInfo[] columns, SortedDictio
return xx;
}
private List<HandsonRowData> GetAccountBasic(per_sheet sheet)
private List<HandsonRowData> GetAccountBasic(per_sheet sheet, IEnumerable<per_dept_dic> dept, List<HandsonCellData> cells)
{
//var accounts = sheetSevice.SheetExport(sheet.ID);
var result = new List<HandsonRowData>();
var groupAccount = perforImdataRepository.GetEntities(t => t.SheetID == sheet.ID); //.OrderBy(c=>c.RowNumber).GroupBy(c => c.RowNumber);
if (groupAccount != null && groupAccount.Any())
{
......@@ -551,14 +571,28 @@ private List<HandsonRowData> GetAccountBasic(per_sheet sheet)
break;
}
var rowData = new HandsonRowData(rowNumber.Value, data);
result.Add(rowData);
string unit = ""; string type = "";
foreach (var cell in data)
{
if (cell.Name == "核算单元")
{
unit = cell.Value.ToString();
}
else if (cell.Name == "核算单元类型")
{
type = cell.Value.ToString();
}
}
cells.Add(new HandsonCellData(unit, type));
}
//var temps = accounts.Row.Select(item => new { row = item.Rownumber, dic = JsonHelper.Deserialize(item) });
//return new List<HandsonRowData>(temps.Select(temp => CreateRowData(temp.row, ExcelReadConfig.AccountBaisc, temp.dic)));
}
UnitFit(result, dept, cells);
return result;
}
......@@ -669,6 +703,110 @@ public void SaveCollectData(int allotId, SaveCollectData request)
return result;
}
private void UnitFit(List<HandsonRowData> rowDatas, IEnumerable<per_dept_dic> dept, List<HandsonCellData> cellDatas)
{
var rowCount = rowDatas.Count;
List<HandsonRowData> suppRowDatas = new List<HandsonRowData>();
foreach (var dic in dept)
{
bool exists = false;
bool exists2 = false;
foreach (var rowData in rowDatas)
{
foreach (var cellData in rowData.CellData)
{
//var cell = rowData.CellData.Where(c => c.Value == dic.AccountingUnit).ToList();
if (cellData.Value?.ToString() == dic.AccountingUnit)
{
exists = true;
}
if (exists && cellData.Value?.ToString() == dic.UnitType)
{
exists2 = true;
}
}
}
if ((exists == false && exists2 == false) || exists2 == false)
{
cellDatas.Add(new HandsonCellData(dic.AccountingUnit, dic.UnitType));
var cells = new List<HandsonCellData>();
cells.Add(new HandsonCellData("核算单元", dic.AccountingUnit));
cells.Add(new HandsonCellData("核算单元类型", dic.UnitType));
suppRowDatas.Add(new HandsonRowData(rowCount++, cells));
}
}
cellDatas.Distinct().ToList();
rowDatas.AddRange(suppRowDatas);
}
private void UnitFit(List<HandsonRowData> rowDatas, List<HandsonCellData> cellDatas, per_sheet sheet)
{
var rowCount = rowDatas.Count;
List<HandsonRowData> suppRowDatas = new List<HandsonRowData>();
foreach (var cell in cellDatas)
{
bool exists = false;
bool exists2 = false;
var cells = new List<HandsonCellData>();
if (cell.Name == "总务科")
{
var ss = 1;
}
foreach (var rowData in rowDatas)
{
foreach (var cellData in rowData.CellData)
{
//var cell = rowData.CellData.Where(c => c.Value == dic.AccountingUnit).ToList();
if (cellData.Value?.ToString() == cell.Name)
{
exists = true;
}
if (cellData.Name == "核算单元分类" && cellData.Value == cell.Value)
{
exists2 = true;
}
else if (cellData.Name == "核算组别" && cellData.Value == cell.Value)
{
exists2 = true;
}
else if (cellData.Name == "核算单元类型" && cellData.Value == cell.Value)
{
exists2 = true;
}
else
{
exists2 = true;
}
}
}
if (exists == false || (exists == false && exists2 == false) || exists2 == false)
{
cells.Add(new HandsonCellData("核算单元", cell.Name));
if (sheet.SheetName == "5.2业务中层行政中高层医院奖罚")
{
cells.Add(new HandsonCellData("核算单元分类", cell.Value));
}
else if (sheet.SheetName == "5.1 科室绩效医院奖罚")
{
cells.Add(new HandsonCellData("核算组别", cell.Value));
}
else
{
cells.Add(new HandsonCellData("核算单元类型", cell.Value));
}
suppRowDatas.Add(new HandsonRowData(++rowCount, cells));
}
}
rowDatas.AddRange(suppRowDatas);
}
}
public class CollectDataConfig
......
......@@ -13,12 +13,15 @@ public class RoleService : IAutoInjection
{
private PerforRoleRepository _roleRepository;
private PerforUserroleRepository _userroleRepository;
private PerforUserRepository _userRepository;
public RoleService(PerforRoleRepository roleRepository,
PerforUserroleRepository userroleRepository)
PerforUserroleRepository userroleRepository,
PerforUserRepository userRepository)
{
this._roleRepository = roleRepository;
this._userroleRepository = userroleRepository;
_userRepository = userRepository;
}
/// <summary>
......@@ -51,5 +54,54 @@ public List<sys_role> GetRole(int userid)
return roles;
}
public List<RoleResponse> GetUsersRole(int userid)
{
List<RoleResponse> roleResponses = new List<RoleResponse>();
var user=_userRepository.GetEntity(c => c.ID == userid);
var ParentUser = _userRepository.GetEntities(c => c.ParentID == userid);
if (user.ParentID!=null || user.ParentID==0)
{
ParentUser=_userRepository.GetEntities(c => c.ID == user.ParentID);
}
if (user != null)
{
foreach (var sysUser in ParentUser)
{
var useRoles = GetARole(sysUser.ID);
var role = Mapper.Map<RoleResponse>(useRoles);
role.Value = sysUser.ID;
roleResponses.Add(role);
}
}
var roles = GetARole(userid);
if (roles!=null)
{
var role = Mapper.Map<RoleResponse>(roles);
role.Value = userid;
roleResponses.Add(role);
}
return roleResponses;
}
/// <summary>
/// 获取用户角色
/// </summary>
/// <param name="userid"></param>
/// <returns></returns>
public sys_role GetARole(int userid)
{
if (userid <= 0)
throw new PerformanceException($"userid:{userid} 错误");
var joinList = _userroleRepository.GetEntities(t => t.UserID == userid);
if (joinList == null)
return null;
var roles = _roleRepository.GetEntity(t => joinList.Select(j => j.RoleID).Contains(t.ID));
return roles;
}
}
}
......@@ -142,7 +142,7 @@ public List<UserResponse> GetUserList(int userID)
if (role.IsViewAllUsers == 2)
{
var userlist = _userRepository.GetEntities(t => t.CreateUser == userID && t.IsDelete == 1);
var userlist = _userRepository.GetEntities(t => t.CreateUser == userID && t.IsDelete == 1 && (t.ParentID == 0 || t.ParentID == null));
result = Mapper.Map<List<UserResponse>>(userlist);
}
else
......@@ -151,7 +151,7 @@ public List<UserResponse> GetUserList(int userID)
if (hospitalIds == null || !hospitalIds.Any()) return result;
var userIds = _userhospitalRepository.GetEntities(t => hospitalIds.Contains(t.HospitalID)).Select(t => t.UserID).Distinct();
var userlist = _userRepository.GetEntities(t => t.ID != userID && userIds.Contains(t.ID) && t.IsDelete == 1);
var userlist = _userRepository.GetEntities(t => t.ID != userID && userIds.Contains(t.ID) && t.IsDelete == 1 && (t.ParentID == 0 || t.ParentID == null));
result = Mapper.Map<List<UserResponse>>(userlist);
}
if (result != null && result.Count > 0)
......@@ -163,9 +163,26 @@ public List<UserResponse> GetUserList(int userID)
{
item.Hospital = string.Join(",", hoslist.Select(p => p.HospitalID.Value));
}
List<int> roleId = new List<int>();
var userRole = _userroleRepository.GetEntity(t => t.UserID == item.UserID);
if (userRole != null)
{
item.Role = userRole.RoleID;
roleId.Add(userRole.RoleID);
}
var diffUserRole = _userRepository.GetEntities(c => c.ParentID == item.UserID);
if (diffUserRole != null)
{
foreach (var user in diffUserRole)
{
var diffRole = _userroleRepository.GetEntity(t => t.UserID == user.ID);
roleId.Add(diffRole.RoleID);
}
}
item.RoleArr = roleId?.ToArray();
}
}
return result;
......@@ -496,5 +513,160 @@ public UserResponse ResetPwd(int userId, int loginUserId)
throw new PerformanceException("重置失败");
return Mapper.Map<UserResponse>(user);
}
#region 多角色
/// <summary>
/// 新增用户
/// </summary>
/// <param name="request"></param>
public UserResponse InsertUser(UserRequest request, int userid)
{
if (null != _userRepository.GetEntity(t => t.Login == request.Login && t.IsDelete == 1))
throw new PerformanceException("登录名重复");
if (request.HosIDArray.Length > 1)
throw new PerformanceException("二次绩效管理员只支持单家医院");
int[] roleArray = new int[] { application.NurseRole, application.DirectorRole, application.SpecialRole, application.OfficeRole };
if (roleArray.Intersect(request.RoleArr).Any() && string.IsNullOrEmpty(request.Department))
throw new PerformanceException("二次绩效管理员科室不能为空");
var user = Mapper.Map<sys_user>(request);
user.CreateDate = DateTime.Now;
user.CreateUser = userid;
user.States = (int)States.Enabled;
user.Department = roleArray.Contains(request.RoleArr[0]) ? request.Department : "";
user.IsDelete = 1;
if (!_userRepository.Add(user))
throw new PerformanceException("保存失败");
//添加用户角色关联关系
_userroleRepository.Add(new sys_user_role { UserID = user.ID, RoleID = request.RoleArr[0] });
//添加用户医院
SetHospital(user.ID, request.HosIDArray);
var userID = user.ID;
for (int i = 1; i < request.RoleArr.Length; i++)
{
user.Login = request.Login + i;
user.ParentID = userID;
user.Department = roleArray.Contains(request.RoleArr[i]) ? request.Department : "";
user.ID++;
_userRepository.Add(user);
//添加用户角色关联关系
_userroleRepository.Add(new sys_user_role { UserID = user.ID, RoleID = request.RoleArr[i] });
//添加用户医院
SetHospital(user.ID, request.HosIDArray);
}
return Mapper.Map<UserResponse>(user);
}
/// <summary>
/// 修改用户
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public UserResponse UpdateUser(UserRequest request, bool isAgainAdmin)
{
var user = _userRepository.GetEntity(t => t.ID == request.ID && t.IsDelete == 1);
if (null == user)
throw new PerformanceException($"用户不存在 UserId:{request.ID}");
var vlist = _userRepository.GetEntities(t => t.ID != user.ID && t.Login == request.Login && t.IsDelete == 1);
if (null != vlist && vlist.Count() > 0)
throw new PerformanceException("登录名重复");
if (isAgainAdmin && string.IsNullOrEmpty(request.Department))
throw new PerformanceException("二次绩效管理员科室不能为空");
if (isAgainAdmin && request.HosIDArray.Length > 1)
throw new PerformanceException("二次绩效管理员只支持单家医院");
int[] roleArray = new int[] { application.NurseRole, application.DirectorRole, application.SpecialRole, application.OfficeRole };
user.Login = request.Login;
user.Mobile = request.Mobile;
user.RealName = request.RealName;
user.Mail = request.Mail;
user.States = request.States;
user.Password = string.IsNullOrEmpty(request.Password) ? user.Password : request.Password;
user.Department = roleArray.Contains(request.RoleArr[0]) ? request.Department : "";
if (!_userRepository.Update(user))
throw new PerformanceException("保存失败");
//删除用户角色关联关系
var userRole = _userroleRepository.GetEntity(t => t.UserID == user.ID);
if (null != userRole)
_userroleRepository.Remove(userRole);
//添加用户角色关联关系
_userroleRepository.Add(new sys_user_role { UserID = user.ID, RoleID = request.RoleArr[0] });
//添加用户医院
SetHospital(user.ID, request.HosIDArray);
//删除子用户角色关联关系
var userSubset = _userRepository.GetEntities(c => c.ParentID == user.ID);
if (userSubset!=null)
{
foreach (var item in userSubset)
{
var diffUserRole = _userroleRepository.GetEntity(t => t.UserID == item.ID);
if (null != diffUserRole)
_userroleRepository.Remove(diffUserRole);
}
_userRepository.RemoveRange(userSubset.ToArray());
}
var userID = user.ID;
var userLogin = user.Login;
for (int i = 1; i < request.RoleArr.Length; i++)
{
sys_user diffUser = new sys_user();
diffUser.CreateDate = DateTime.Now;
diffUser.CreateUser = user.CreateUser;
diffUser.IsDelete = 1;
diffUser.Login = userLogin + i;
diffUser.ParentID = userID;
diffUser.Mobile = request.Mobile;
diffUser.RealName = request.RealName;
diffUser.Mail = request.Mail;
diffUser.States = request.States;
diffUser.Password = string.IsNullOrEmpty(request.Password) ? user.Password : request.Password;
diffUser.Department = roleArray.Contains(request.RoleArr[0]) ? request.Department : "";
if (!_userRepository.Add(diffUser))
throw new PerformanceException("保存失败");
//添加子用户角色关联关系
_userroleRepository.Add(new sys_user_role { UserID = diffUser.ID, RoleID = request.RoleArr[i] });
//添加子用户医院
SetHospital(diffUser.ID, request.HosIDArray);
}
return Mapper.Map<UserResponse>(user);
}
public ApiResponse DeleteUser(int iD)
{
var user = _userRepository.GetEntity(t => t.ID == iD && t.IsDelete == 1);
if (null == user)
throw new PerformanceException($"用户不存在 UserId:{iD}");
user.IsDelete = 2;
var result = _userRepository.Remove(user);
var users = _userRepository.GetEntities(t => t.ParentID == user.ID && t.IsDelete == 1)?.ToArray();
if (users!=null)
{
_userRepository.RemoveRange(users);
foreach (var item in users)
{
var userRole = _userroleRepository.GetEntity(t => t.UserID == item.ID);
if (null != userRole)
_userroleRepository.Remove(userRole);
}
}
return result ? new ApiResponse(ResponseType.OK) : new ApiResponse(ResponseType.Fail);
}
#endregion
}
}
\ No newline at end of file
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