多科室涉及代码科室优化

parent cf2a7cb6
......@@ -122,7 +122,7 @@ public ApiResponse SelfInfo()
user.Role = _roleService.GetUserRole(user.UserID);
user.Hospital = _hospitalService.GetUserHopital(user.UserID);
int[] roleArray = new int[] { _options.NurseRole, _options.DirectorRole, _options.SpecialRole, _options.OfficeRole };
int[] roleArray = UnitTypeUtil.Maps.Keys.ToArray();
user.IsAgainAdmin = user.Role != null ? roleArray.Contains(user.Role.First().Type ?? 0) : false;
return new ApiResponse(ResponseType.OK, user);
}
......@@ -149,56 +149,56 @@ public ApiResponse<UserResponse> UpdateSelf([CustomizeValidator(RuleSet = "Self"
[HttpPost]
public ApiResponse<List<UserResponse>> List([FromBody] UserRequest request)
{
var userList = _userService.GetUserList(_claim.GetUserId(),request.Role);
var userList = _userService.GetUserList(_claim.GetUserId(), request.Role);
return new ApiResponse<List<UserResponse>>(ResponseType.OK, "ok", userList);
}
/// <summary>
/// 新增用户
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("insert")]
[HttpPost]
public ApiResponse<UserResponse> Insert([CustomizeValidator(RuleSet = "Insert"), FromBody] UserRequest request)
{
var userId = _claim.GetUserId();
var user = _userService.Insert(request, userId);
user.Role = request.Role;
return new ApiResponse<UserResponse>(ResponseType.OK, user);
}
/// <summary>
/// 新增用户
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("delete")]
[HttpPost]
public ApiResponse Delete([CustomizeValidator(RuleSet = "Delete"), FromBody] UserRequest request)
{
return _userService.Delete(request.ID);
}
/// <summary>
/// 删除用户
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("update")]
[HttpPost]
public ApiResponse<UserResponse> Update([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.GetUserRole(userId);
var isAgainAdmin = roles != null ? roleArray.Contains(roles.First().Type ?? 0) : false;
var user = _userService.Update(request, isAgainAdmin);
user.Role = request.Role;
return new ApiResponse<UserResponse>(ResponseType.OK, user);
}
///// <summary>
///// 新增用户
///// </summary>
///// <param name="request"></param>
///// <returns></returns>
//[Route("insert")]
//[HttpPost]
//public ApiResponse<UserResponse> Insert([CustomizeValidator(RuleSet = "Insert"), FromBody] UserRequest request)
//{
// var userId = _claim.GetUserId();
// var user = _userService.Insert(request, userId);
// user.Role = request.Role;
// return new ApiResponse<UserResponse>(ResponseType.OK, user);
//}
///// <summary>
///// 新增用户
///// </summary>
///// <param name="request"></param>
///// <returns></returns>
//[Route("delete")]
//[HttpPost]
//public ApiResponse Delete([CustomizeValidator(RuleSet = "Delete"), FromBody] UserRequest request)
//{
// return _userService.Delete(request.ID);
//}
///// <summary>
///// 删除用户
///// </summary>
///// <param name="request"></param>
///// <returns></returns>
//[Route("update")]
//[HttpPost]
//public ApiResponse<UserResponse> Update([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.GetUserRole(userId);
// var isAgainAdmin = roles != null ? roleArray.Contains(roles.First().Type ?? 0) : false;
// var user = _userService.Update(request, isAgainAdmin);
// user.Role = request.Role;
// return new ApiResponse<UserResponse>(ResponseType.OK, user);
//}
/// <summary>
/// 修改用户密码
......@@ -311,7 +311,7 @@ public ApiResponse SelfInfos([FromBody] UserRequest request)
user.Role = _roleService.GetUsersRole(user.UserID);
user.Hospital = _hospitalService.GetUserHopital(user.UserID);
int[] roleArray = new int[] { _options.NurseRole, _options.DirectorRole, _options.SpecialRole, _options.OfficeRole };
int[] roleArray = UnitTypeUtil.Maps.Keys.ToArray();
if (request.Role <= 0)
user.IsAgainAdmin = user.Role != null ? roleArray.Contains(user.Role.First().Type ?? 0) : false;
else
......@@ -345,13 +345,7 @@ public ApiResponse<UserResponse> UpdateUser([CustomizeValidator(RuleSet = "Updat
{
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);
var user = _userService.UpdateUser(request, userId);
user.RoleArr = request.RoleArr;
return new ApiResponse<UserResponse>(ResponseType.OK, user);
}
......@@ -391,12 +385,7 @@ public ApiResponse GetBatchUserStructrue()
[HttpPost]
public ApiResponse BatchSaveUser([CustomizeValidator(RuleSet = "Insert"), FromBody] UserCollectData data)
{
var result = _userService.SaveUserHandsFlat(data);
if (result == "")
return new ApiResponse(ResponseType.OK);
else
return new ApiResponse(ResponseType.Error, result);
return _userService.SaveUserHandsFlat(data);
}
}
}
\ No newline at end of file
using FluentValidation.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Performance.DtoModels;
using Performance.DtoModels.AppSettings;
using Performance.Infrastructure;
using Performance.Services;
using Performance.Services.ExtractExcelService;
using System;
using System.IO;
using System.Linq;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace Performance.Api.Controllers
{
/// <summary>
/// 科室二次分配
/// </summary>
[Route("api/[controller]")]
public class AgainAllotController : Controller
{
private AgainAllotService againAllotService;
private RoleService roleService;
private ComputeService computeService;
private ClaimService claimService;
private AllotService allotService;
private IWebHostEnvironment env;
private ConfigService configService;
private Application application;
public AgainAllotController(AgainAllotService againAllotService,
RoleService roleService,
ClaimService claimService,
AllotService allotService,
IWebHostEnvironment env,
ConfigService configService,
ComputeService computeService,
IOptions<Application> options)
{
this.againAllotService = againAllotService;
this.roleService = roleService;
this.claimService = claimService;
this.allotService = allotService;
this.env = env;
this.configService = configService;
this.computeService = computeService;
this.application = options.Value;
}
/// <summary>
/// 返回当前用户医院下绩效列表
/// </summary>
/// <returns></returns>
[Route("allotlist")]
[HttpPost]
public ApiResponse AllotList()
{
var userId = claimService.GetUserId();
var list = againAllotService.GetAllotList(userId);
return new ApiResponse(ResponseType.OK, list);
}
/// <summary>
/// 上传文件
/// </summary>
/// <param name="form"></param>
/// <returns></returns>
[Route("import")]
[HttpPost]
public ApiResponse Import([FromForm] IFormCollection form)
{
var againid = form.ToDictionary().GetValue("againid", 0);
if (againid <= 0)
return new ApiResponse(ResponseType.Fail, "参数错误", "againid无效");
var file = ((FormFileCollection)form.Files).FirstOrDefault();
if (file == null)
return new ApiResponse(ResponseType.Fail, "参数错误", "文件无效");
if (!ExtractHelper.IsXlsxFile(file.FileName))
return new ApiResponse(ResponseType.Fail, "文件格式错误", "文件暂只支持xlsx文件");
var again = againAllotService.GetAgainallot(againid);
if (again == null)
return new ApiResponse(ResponseType.Fail, "二次绩效记录不存在");
var allot = allotService.GetAllot(again.AllotID.Value);
if (allot == null)
return new ApiResponse(ResponseType.Fail, "一次绩效记录不存在");
var name = FileHelper.GetFileNameNoExtension(file.FileName) + DateTime.Now.ToString("yyyyMMddHHmmssfff");
var ext = FileHelper.GetExtension(file.FileName);
var dpath = Path.Combine(env.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 = file.OpenReadStream())
{
byte[] bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
if (!FileHelper.CreateFile(path, bytes))
return new ApiResponse(ResponseType.Fail, $"{file.FileName}上传失败");
allot.Path = path;
allot.Remark = EnumHelper.GetDescription(AllotStates.数据已上传);
if (!againAllotService.Update(allot, againid))
return new ApiResponse(ResponseType.Fail, $"{file.FileName}上传成功,修改状态失败");
configService.ClearAgain(againid);
}
return new ApiResponse(ResponseType.OK);
}
///// <summary>
///// 查看科室绩效
///// </summary>
///// <param name="request"></param>
///// <returns></returns>
//[Route("departmentdetail")]
//[HttpPost]
//public ApiResponse DepartmentDetail([CustomizeValidator(RuleSet = "Generate"), FromBody]AgainAllotRequest request)
//{
// var userId = claimService.GetUserId();
// var roles = roleService.GetUserRole(userId);
// var department = claimService.GetUserClaim(JwtClaimTypes.Department);
// var again = againAllotService.GetAgainallot(request.AgainAllotID);
// if (again == null)
// return new ApiResponse(ResponseType.Fail, "当前二次绩效ID无效");
// if (roles.First().Type == application.DirectorRole)
// {
// var detail = computeService.GetDepartmentDetail(again.AllotID.Value, department, 1);
// return new ApiResponse(ResponseType.OK, detail);
// }
// else if (roles.First().Type == application.NurseRole)
// {
// var detail = computeService.GetDepartmentDetail(again.AllotID.Value, department, 2);
// return new ApiResponse(ResponseType.OK, detail);
// }
// return new ApiResponse(ResponseType.Fail, "当前用户角色无法识别");
//}
///// <summary>
///// 生成绩效
///// </summary>
///// <param name="request"></param>
///// <returns></returns>
//[Route("generate")]
//[HttpPost]
//public ApiResponse Generate([CustomizeValidator(RuleSet = "Generate"), FromBody]AgainAllotRequest request)
//{
// var userId = claimService.GetUserId();
// var department = claimService.GetUserClaim(JwtClaimTypes.Department);
// var result = againAllotService.Generate(request, userId, department);
// return new ApiResponse(ResponseType.OK);
//}
/// <summary>
/// 查看绩效详情
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("detail")]
[HttpPost]
public ApiResponse Detail([CustomizeValidator(RuleSet = "Generate"), FromBody] AgainAllotRequest request)
{
var result = againAllotService.Detail(request);
return new ApiResponse(ResponseType.OK, new { result.AgainSituation, result.SheetExport });
}
}
}
//using FluentValidation.AspNetCore;
//using Microsoft.AspNetCore.Hosting;
//using Microsoft.AspNetCore.Http;
//using Microsoft.AspNetCore.Mvc;
//using Microsoft.Extensions.Options;
//using Performance.DtoModels;
//using Performance.DtoModels.AppSettings;
//using Performance.Infrastructure;
//using Performance.Services;
//using Performance.Services.ExtractExcelService;
//using System;
//using System.IO;
//using System.Linq;
//// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
//namespace Performance.Api.Controllers
//{
// /// <summary>
// /// 科室二次分配
// /// </summary>
// [Route("api/[controller]")]
// public class AgainAllotController : Controller
// {
// private AgainAllotService againAllotService;
// private RoleService roleService;
// private ComputeService computeService;
// private ClaimService claimService;
// private AllotService allotService;
// private IWebHostEnvironment env;
// private ConfigService configService;
// private Application application;
// public AgainAllotController(AgainAllotService againAllotService,
// RoleService roleService,
// ClaimService claimService,
// AllotService allotService,
// IWebHostEnvironment env,
// ConfigService configService,
// ComputeService computeService,
// IOptions<Application> options)
// {
// this.againAllotService = againAllotService;
// this.roleService = roleService;
// this.claimService = claimService;
// this.allotService = allotService;
// this.env = env;
// this.configService = configService;
// this.computeService = computeService;
// this.application = options.Value;
// }
// /// <summary>
// /// 返回当前用户医院下绩效列表
// /// </summary>
// /// <returns></returns>
// [Route("allotlist")]
// [HttpPost]
// public ApiResponse AllotList()
// {
// var userId = claimService.GetUserId();
// var list = againAllotService.GetAllotList(userId);
// return new ApiResponse(ResponseType.OK, list);
// }
// /// <summary>
// /// 上传文件
// /// </summary>
// /// <param name="form"></param>
// /// <returns></returns>
// [Route("import")]
// [HttpPost]
// public ApiResponse Import([FromForm] IFormCollection form)
// {
// var againid = form.ToDictionary().GetValue("againid", 0);
// if (againid <= 0)
// return new ApiResponse(ResponseType.Fail, "参数错误", "againid无效");
// var file = ((FormFileCollection)form.Files).FirstOrDefault();
// if (file == null)
// return new ApiResponse(ResponseType.Fail, "参数错误", "文件无效");
// if (!ExtractHelper.IsXlsxFile(file.FileName))
// return new ApiResponse(ResponseType.Fail, "文件格式错误", "文件暂只支持xlsx文件");
// var again = againAllotService.GetAgainallot(againid);
// if (again == null)
// return new ApiResponse(ResponseType.Fail, "二次绩效记录不存在");
// var allot = allotService.GetAllot(again.AllotID.Value);
// if (allot == null)
// return new ApiResponse(ResponseType.Fail, "一次绩效记录不存在");
// var name = FileHelper.GetFileNameNoExtension(file.FileName) + DateTime.Now.ToString("yyyyMMddHHmmssfff");
// var ext = FileHelper.GetExtension(file.FileName);
// var dpath = Path.Combine(env.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 = file.OpenReadStream())
// {
// byte[] bytes = new byte[stream.Length];
// stream.Read(bytes, 0, bytes.Length);
// if (!FileHelper.CreateFile(path, bytes))
// return new ApiResponse(ResponseType.Fail, $"{file.FileName}上传失败");
// allot.Path = path;
// allot.Remark = EnumHelper.GetDescription(AllotStates.数据已上传);
// if (!againAllotService.Update(allot, againid))
// return new ApiResponse(ResponseType.Fail, $"{file.FileName}上传成功,修改状态失败");
// configService.ClearAgain(againid);
// }
// return new ApiResponse(ResponseType.OK);
// }
// ///// <summary>
// ///// 查看科室绩效
// ///// </summary>
// ///// <param name="request"></param>
// ///// <returns></returns>
// //[Route("departmentdetail")]
// //[HttpPost]
// //public ApiResponse DepartmentDetail([CustomizeValidator(RuleSet = "Generate"), FromBody]AgainAllotRequest request)
// //{
// // var userId = claimService.GetUserId();
// // var roles = roleService.GetUserRole(userId);
// // var department = claimService.GetUserClaim(JwtClaimTypes.Department);
// // var again = againAllotService.GetAgainallot(request.AgainAllotID);
// // if (again == null)
// // return new ApiResponse(ResponseType.Fail, "当前二次绩效ID无效");
// // if (roles.First().Type == application.DirectorRole)
// // {
// // var detail = computeService.GetDepartmentDetail(again.AllotID.Value, department, 1);
// // return new ApiResponse(ResponseType.OK, detail);
// // }
// // else if (roles.First().Type == application.NurseRole)
// // {
// // var detail = computeService.GetDepartmentDetail(again.AllotID.Value, department, 2);
// // return new ApiResponse(ResponseType.OK, detail);
// // }
// // return new ApiResponse(ResponseType.Fail, "当前用户角色无法识别");
// //}
// ///// <summary>
// ///// 生成绩效
// ///// </summary>
// ///// <param name="request"></param>
// ///// <returns></returns>
// //[Route("generate")]
// //[HttpPost]
// //public ApiResponse Generate([CustomizeValidator(RuleSet = "Generate"), FromBody]AgainAllotRequest request)
// //{
// // var userId = claimService.GetUserId();
// // var department = claimService.GetUserClaim(JwtClaimTypes.Department);
// // var result = againAllotService.Generate(request, userId, department);
// // return new ApiResponse(ResponseType.OK);
// //}
// /// <summary>
// /// 查看绩效详情
// /// </summary>
// /// <param name="request"></param>
// /// <returns></returns>
// [Route("detail")]
// [HttpPost]
// public ApiResponse Detail([CustomizeValidator(RuleSet = "Generate"), FromBody] AgainAllotRequest request)
// {
// var result = againAllotService.Detail(request);
// return new ApiResponse(ResponseType.OK, new { result.AgainSituation, result.SheetExport });
// }
// }
//}
......@@ -14,14 +14,14 @@
"ExpirationMinutes": "1200",
//验证码过期
"SmsCodeMinutes": "5",
//护士长二次绩效管理员
"NurseRole": "3",
//科主任二次绩效管理员
"DirectorRole": "4",
//特殊科室二次绩效管理员
"SpecialRole": "9",
//数据收集角色(可查看所有)
"CollectRoles": [ 1, 2, 5, 6, 7, 8 ],
////护士长二次绩效管理员
//"NurseRole": "3",
////科主任二次绩效管理员
//"DirectorRole": "4",
////特殊科室二次绩效管理员
//"SpecialRole": "9",
////数据收集角色(可查看所有)
//"CollectRoles": [ 1, 2, 5, 6, 7, 8 ],
// 抽取结果Excel文件保存地址
"AbsolutePath": "E:\\wwwroot\\testjx.suvalue.com",
// 抽取结果Excel文件保存地址 更替的 网络地址
......
......@@ -49,27 +49,6 @@
</summary>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.AccountController.Insert(Performance.DtoModels.UserRequest)">
<summary>
新增用户
</summary>
<param name="request"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.AccountController.Delete(Performance.DtoModels.UserRequest)">
<summary>
新增用户
</summary>
<param name="request"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.AccountController.Update(Performance.DtoModels.UserRequest)">
<summary>
删除用户
</summary>
<param name="request"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.AccountController.Password(Performance.DtoModels.PasswordRequest)">
<summary>
修改用户密码
......@@ -149,29 +128,18 @@
</summary>
<returns></returns>
</member>
<member name="T:Performance.Api.Controllers.AgainAllotController">
<summary>
科室二次分配
</summary>
</member>
<member name="M:Performance.Api.Controllers.AgainAllotController.AllotList">
<summary>
返回当前用户医院下绩效列表
</summary>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.AgainAllotController.Import(Microsoft.AspNetCore.Http.IFormCollection)">
<member name="M:Performance.Api.Controllers.AccountController.HistoryDepartment(System.Int32)">
<summary>
上传文件
用户过往科室
</summary>
<param name="form"></param>
<param name="userId"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.AgainAllotController.Detail(Performance.DtoModels.AgainAllotRequest)">
<member name="M:Performance.Api.Controllers.AccountController.DeleteHistoryDepartment(System.Int32)">
<summary>
查看绩效详情
删除用户过往科室
</summary>
<param name="request"></param>
<param name="historyId"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.AllotController.List(Performance.DtoModels.AllotRequest)">
......
......@@ -34,31 +34,6 @@
短信模板
</summary>
</member>
<member name="P:Performance.DtoModels.AppSettings.Application.NurseRole">
<summary>
护士长二次绩效管理员
</summary>
</member>
<member name="P:Performance.DtoModels.AppSettings.Application.DirectorRole">
<summary>
科主任二次绩效管理员
</summary>
</member>
<member name="P:Performance.DtoModels.AppSettings.Application.SpecialRole">
<summary>
特殊科室二次绩效管理员
</summary>
</member>
<member name="P:Performance.DtoModels.AppSettings.Application.CollectRoles">
<summary>
数据收集角色(可查看所有)
</summary>
</member>
<member name="P:Performance.DtoModels.AppSettings.Application.OfficeRole">
<summary>
行政科室二次绩效管理员
</summary>
</member>
<member name="P:Performance.DtoModels.AppSettings.Application.Receiver">
<summary>
邮件指定接收人
......@@ -130,39 +105,6 @@
<member name="F:Performance.DtoModels.DbSrouceType.Performance">
<summary> 绩效库 </summary>
</member>
<member name="F:Performance.DtoModels.AllotStates.数据未上传">
<summary> 数据未上传 </summary>
</member>
<member name="F:Performance.DtoModels.AllotStates.数据已上传">
<summary> 数据已上传 </summary>
</member>
<member name="F:Performance.DtoModels.AllotStates.正在校验数据">
<summary> 正在校验数据 </summary>
</member>
<member name="F:Performance.DtoModels.AllotStates.数据验证通过">
<summary> 数据验证通过 </summary>
</member>
<member name="F:Performance.DtoModels.AllotStates.数据错误">
<summary> 数据错误 </summary>
</member>
<member name="F:Performance.DtoModels.AllotStates.正在生成绩效">
<summary> 正在生成绩效 </summary>
</member>
<member name="F:Performance.DtoModels.AllotStates.绩效下发">
<summary> 绩效下发 </summary>
</member>
<member name="F:Performance.DtoModels.AllotStates.绩效解析失败">
<summary> 绩效解析失败 </summary>
</member>
<member name="F:Performance.DtoModels.AllotStates.归档">
<summary> 归档 </summary>
</member>
<member name="F:Performance.DtoModels.AllotStates.等待">
<summary> 等待 </summary>
</member>
<member name="F:Performance.DtoModels.AllotStates.绩效结果解析成功">
<summary> 绩效结果解析成功 </summary>
</member>
<member name="F:Performance.DtoModels.AgWorkloadType.PreAccountingReward">
<summary>
核算前奖励
......@@ -735,9 +677,6 @@
是否需要二次分配
</summary>
</member>
<member name="T:Performance.DtoModels.UnitType">
<summary> 核算单元类型 </summary>
</member>
<member name="F:Performance.DtoModels.SheetType.Unidentifiable">
<summary> 无法识别 </summary>
</member>
......
......@@ -8650,6 +8650,41 @@
父级ID
</summary>
</member>
<member name="T:Performance.EntityModels.sys_user_history">
<summary>
用户角色关联表
</summary>
</member>
<member name="P:Performance.EntityModels.sys_user_history.UserID">
<summary>
用户ID
</summary>
</member>
<member name="P:Performance.EntityModels.sys_user_history.RoleID">
<summary>
角色ID
</summary>
</member>
<member name="P:Performance.EntityModels.sys_user_history.RoleType">
<summary>
角色类型
</summary>
</member>
<member name="P:Performance.EntityModels.sys_user_history.RoleName">
<summary>
角色名称
</summary>
</member>
<member name="P:Performance.EntityModels.sys_user_history.Department">
<summary>
科室名称
</summary>
</member>
<member name="P:Performance.EntityModels.sys_user_history.CreateDate">
<summary>
核算单元变更时间
</summary>
</member>
<member name="T:Performance.EntityModels.sys_user_hospital">
<summary>
......@@ -9045,5 +9080,41 @@
预留金额
</summary>
</member>
<member name="F:AllotStates.数据未上传">
<summary> 数据未上传 </summary>
</member>
<member name="F:AllotStates.数据已上传">
<summary> 数据已上传 </summary>
</member>
<member name="F:AllotStates.正在校验数据">
<summary> 正在校验数据 </summary>
</member>
<member name="F:AllotStates.数据验证通过">
<summary> 数据验证通过 </summary>
</member>
<member name="F:AllotStates.数据错误">
<summary> 数据错误 </summary>
</member>
<member name="F:AllotStates.正在生成绩效">
<summary> 正在生成绩效 </summary>
</member>
<member name="F:AllotStates.绩效下发">
<summary> 绩效下发 </summary>
</member>
<member name="F:AllotStates.绩效解析失败">
<summary> 绩效解析失败 </summary>
</member>
<member name="F:AllotStates.归档">
<summary> 归档 </summary>
</member>
<member name="F:AllotStates.等待">
<summary> 等待 </summary>
</member>
<member name="F:AllotStates.绩效结果解析成功">
<summary> 绩效结果解析成功 </summary>
</member>
<member name="T:UnitType">
<summary> 核算单元类型 </summary>
</member>
</members>
</doc>
......@@ -18,26 +18,26 @@ public class Application
/// 短信模板
/// </summary>
public string SmsTemplate { get; set; }
/// <summary>
/// 护士长二次绩效管理员
/// </summary>
public int NurseRole { get; set; }
/// <summary>
/// 科主任二次绩效管理员
/// </summary>
public int DirectorRole { get; set; }
/// <summary>
/// 特殊科室二次绩效管理员
/// </summary>
public int SpecialRole { get; set; }
/// <summary>
/// 数据收集角色(可查看所有)
/// </summary>
public int[] CollectRoles { get; set; }
/// <summary>
/// 行政科室二次绩效管理员
/// </summary>
public int OfficeRole { get; set; }
///// <summary>
///// 护士长二次绩效管理员
///// </summary>
//public int NurseRole { get; set; }
///// <summary>
///// 科主任二次绩效管理员
///// </summary>
//public int DirectorRole { get; set; }
///// <summary>
///// 特殊科室二次绩效管理员
///// </summary>
//public int SpecialRole { get; set; }
///// <summary>
///// 数据收集角色(可查看所有)
///// </summary>
//public int[] CollectRoles { get; set; }
///// <summary>
///// 行政科室二次绩效管理员
///// </summary>
//public int OfficeRole { get; set; }
/// <summary>
/// 邮件指定接收人
/// </summary>
......
......@@ -45,42 +45,6 @@ public enum DbSrouceType
Performance = 2,
}
public enum AllotStates
{
/// <summary> 数据未上传 </summary>
[Description("数据未上传")]
数据未上传 = 0,
/// <summary> 数据已上传 </summary>
[Description("数据已上传")]
数据已上传 = 1,
/// <summary> 正在校验数据 </summary>
[Description("正在校验数据")]
正在校验数据 = 2,
/// <summary> 数据验证通过 </summary>
[Description("数据验证通过")]
数据验证通过 = 3,
/// <summary> 数据错误 </summary>
[Description("数据错误")]
数据错误 = 4,
/// <summary> 正在生成绩效 </summary>
[Description("正在生成绩效")]
正在生成绩效 = 5,
/// <summary> 绩效下发 </summary>
[Description("绩效下发")]
绩效下发 = 6,
/// <summary> 绩效解析失败 </summary>
[Description("绩效解析失败")]
绩效解析失败 = 7,
/// <summary> 归档 </summary>
[Description("归档")]
归档 = 8,
/// <summary> 等待 </summary>
[Description("等待")]
等待 = 9,
/// <summary> 绩效结果解析成功 </summary>
[Description("数据验证通过")]
绩效结果解析成功 = 10,
}
public enum AgWorkloadType
{
......@@ -119,24 +83,6 @@ public enum DataFormat
日期YYYYMMDD
}
public enum Role
{
绩效管理员 = 1,
医院管理员 = 2,
护士长 = 3,
科主任 = 4,
绩效核算办 = 5,
院领导 = 6,
财务科 = 7,
人事科 = 8,
特殊科室 = 9,
行政科室 = 10,
数据收集 = 11,
护理部审核 = 12,
绩效查询 = 13,
审计 = 14,
}
public class Background
{
public enum JobType
......
......@@ -11,44 +11,6 @@ public enum ExcelVersion
xls
}
/// <summary> 核算单元类型 </summary>
public enum UnitType
{
[Description("医生组")]
医生组 = 1,
[Description("护理组")]
护理组 = 2,
[Description("医技组")]
医技组 = 3,
[Description("专家组")]
专家组 = 4,
//[Description("其他")]
//其他 = 5,
[Description("特殊核算组")]
特殊核算组 = 6,
[Description("其他医生组")]
其他医生组 = 7,
[Description("其他护理组")]
其他护理组 = 8,
[Description("其他医技组")]
其他医技组 = 9,
[Description("行政高层")]
行政高层 = 10,
[Description("行政中层")]
行政中层 = 11,
[Description("行政后勤")]
行政后勤 = 12,
}
public enum SheetType
{
......
using System.ComponentModel;
public enum AllotStates
{
/// <summary> 数据未上传 </summary>
[Description("数据未上传")]
数据未上传 = 0,
/// <summary> 数据已上传 </summary>
[Description("数据已上传")]
数据已上传 = 1,
/// <summary> 正在校验数据 </summary>
[Description("正在校验数据")]
正在校验数据 = 2,
/// <summary> 数据验证通过 </summary>
[Description("数据验证通过")]
数据验证通过 = 3,
/// <summary> 数据错误 </summary>
[Description("数据错误")]
数据错误 = 4,
/// <summary> 正在生成绩效 </summary>
[Description("正在生成绩效")]
正在生成绩效 = 5,
/// <summary> 绩效下发 </summary>
[Description("绩效下发")]
绩效下发 = 6,
/// <summary> 绩效解析失败 </summary>
[Description("绩效解析失败")]
绩效解析失败 = 7,
/// <summary> 归档 </summary>
[Description("归档")]
归档 = 8,
/// <summary> 等待 </summary>
[Description("等待")]
等待 = 9,
/// <summary> 绩效结果解析成功 </summary>
[Description("数据验证通过")]
绩效结果解析成功 = 10,
}
public enum Role
{
绩效管理员 = 1,
医院管理员 = 2,
护士长 = 3,
科主任 = 4,
绩效核算办 = 5,
院领导 = 6,
财务科 = 7,
人事科 = 8,
特殊科室 = 9,
行政科室 = 10,
数据收集 = 11,
护理部审核 = 12,
绩效查询 = 13,
审计 = 14,
}
/// <summary> 核算单元类型 </summary>
public enum UnitType
{
[Description("医生组")]
医生组 = 1,
[Description("护理组")]
护理组 = 2,
[Description("医技组")]
医技组 = 3,
[Description("专家组")]
专家组 = 4,
//[Description("其他")]
//其他 = 5,
[Description("特殊核算组")]
特殊核算组 = 6,
[Description("其他医生组")]
其他医生组 = 7,
[Description("其他护理组")]
其他护理组 = 8,
[Description("其他医技组")]
其他医技组 = 9,
[Description("行政高层")]
行政高层 = 10,
[Description("行政中层")]
行政中层 = 11,
[Description("行政后勤")]
行政后勤 = 12,
}
using Performance.EntityModels;
using System.Collections.Generic;
using System.Linq;
public class UserInfoCenter
{
public sys_user User { get; set; }
public sys_role URole { get; set; }
public List<sys_hospital> Hospitals { get; set; }
public List<int> HospitalIds => Hospitals?.Select(w => w.ID).ToList() ?? new List<int>();
}
using Microsoft.EntityFrameworkCore;
using Performance.EntityModels;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Performance.Repository
{
public partial class PerforUserRepository : PerforRepository<sys_user>
{
/// <summary>
/// 获取用户 医院 角色 过往科室
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public UserInfoCenter GetUser(int userId)
{
var user = context.Set<sys_user>().FirstOrDefault(w => w.IsDelete == 1 && w.ID == userId);
if (user == null)
return null;
var roles = from ur in context.Set<sys_user_role>()
join r in context.Set<sys_role>() on ur.RoleID equals r.ID
where ur.UserID == user.ID
select r;
var hospitals = from uh in context.Set<sys_user_hospital>()
join h in context.Set<sys_hospital>() on uh.HospitalID equals h.ID
where uh.UserID == user.ID
select h;
return new UserInfoCenter
{
User = user,
URole = roles.FirstOrDefault() ?? new sys_role(),
Hospitals = hospitals.ToList() ?? new List<sys_hospital>(),
};
}
/// <summary>
/// 获取指定RoleType的用户
/// </summary>
/// <param name="roleType"></param>
/// <returns></returns>
public List<sys_user> GetUsersByRoleType(params int[] roleType)
{
var users = from u in context.Set<sys_user>()
join ur in context.Set<sys_user_role>() on u.ID equals ur.UserID
join r in context.Set<sys_role>() on ur.RoleID equals r.ID
select new { u, r };
return users.Where(w => roleType.Contains(w.r.Type ?? w.r.ID)).Select(w => w.u).ToList();
}
}
}
using AutoMapper;
using Microsoft.Extensions.Options;
using Performance.DtoModels;
using Performance.DtoModels.AppSettings;
using Performance.EntityModels;
using Performance.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Performance.Services
{
public class AgainAllotService : IAutoInjection
{
private Application application;
private readonly IMapper _mapper;
private AgainService againService;
private RoleService roleService;
private ConfigService configService;
private PerforCofagainRepository perforCofagainRepository;
private PerforPeragainallotRepository perforPeragainallotRepository;
private PerforResaccountRepository perforResaccountRepository;
//private PerforResaccountnurseRepository perforResaccountnurseRepository;
private PerforUserRepository perforUserRepository;
private PerforUserhospitalRepository perforUserhospitalRepository;
private PerforPerallotRepository perforPerallotRepository;
private PerforAgagainsituationRepository perforAgagainsituationRepository;
private PerforAgdataRepository perforAgdataRepository;
private PerforAgemployeeRepository perforAgemployeeRepository;
private PerforAgheaderRepository perforAgheaderRepository;
public AgainAllotService(
IOptions<Application> options,
IMapper mapper,
AgainService againService,
RoleService roleService,
PerforCofagainRepository perforCofagainRepository,
PerforPeragainallotRepository perforPeragainallotRepository,
PerforResaccountRepository perforResaccountRepository,
//PerforResaccountnurseRepository perforResaccountnurseRepository,
PerforUserRepository perforUserRepository,
PerforUserhospitalRepository perforUserhospitalRepository,
PerforPerallotRepository perforPerallotRepository,
PerforAgagainsituationRepository perforAgagainsituationRepository,
PerforAgdataRepository perforAgdataRepository,
PerforAgemployeeRepository perforAgemployeeRepository,
PerforAgheaderRepository perforAgheaderRepository,
ConfigService configService)
{
this.application = options.Value;
_mapper = mapper;
this.againService = againService;
this.roleService = roleService;
this.perforCofagainRepository = perforCofagainRepository;
this.perforPeragainallotRepository = perforPeragainallotRepository;
this.perforResaccountRepository = perforResaccountRepository;
//this.perforResaccountnurseRepository = perforResaccountnurseRepository;
this.perforUserRepository = perforUserRepository;
this.perforUserhospitalRepository = perforUserhospitalRepository;
this.perforPerallotRepository = perforPerallotRepository;
this.perforAgagainsituationRepository = perforAgagainsituationRepository;
this.perforAgdataRepository = perforAgdataRepository;
this.perforAgemployeeRepository = perforAgemployeeRepository;
this.perforAgheaderRepository = perforAgheaderRepository;
this.configService = configService;
}
///// <summary>
///// 生成二次绩效
///// </summary>
///// <param name="request"></param>
//public bool Generate(AgainAllotRequest request, int userId, string department)
//{
// var againAllot = perforPeragainallotRepository.GetEntity(t => t.ID == request.AgainAllotID);
// if (againAllot == null || againAllot.ID == 0)
// throw new PerformanceException("绩效二次分配不存在");
// var roles = roleService.GetRole(userId);
// perforPeragainallotRepository.Update(againAllot, p => { p.States = 2; });
// //清理二次绩效无用数据
// configService.ClearAgain(againAllot.ID);
// try
// {
// #region 基础信息
// //获取基础配置信息
// var config = perforCofagainRepository.GetEntities(t => t.AllotID == againAllot.AllotID);
// var jobfactor = config.FirstOrDefault(t => t.Type == 1)?.Value;
// var workfactor = config.FirstOrDefault(t => t.Type == 2)?.Value;
// var days = config.FirstOrDefault(t => t.Type == 3)?.Value;
// decimal? basicnumber = 0m;
// //获取科室实发绩效
// if (roles != null)
// {
// var role = roles.FirstOrDefault();
// if (role != null)
// {
// if (application.NurseRole == role.Type)
// basicnumber = perforResaccountRepository.GetEntity(t => t.UnitType == (int)UnitType.护理组 && t.AllotID == againAllot.AllotID && t.AccountingUnit == department)?.RealGiveFee;
// else if (application.DirectorRole == role.Type)
// basicnumber = perforResaccountRepository.GetEntity(t => t.UnitType != (int)UnitType.护理组 && t.AllotID == againAllot.AllotID && t.AccountingUnit == department)?.RealGiveFee;
// }
// }
// #endregion
// #region 计算
// //读取二次计算excel数据
// var perAgainExcel = againService.ReadData(againAllot);
// //护士长或科主任出勤
// var bossAttendance = perAgainExcel.AgainEmployee.FirstOrDefault(t => t.JobTitle == "护士长")?.Attendance;
// //计算职称出勤系数、年资出勤系数
// foreach (var item in perAgainExcel.AgainEmployee)
// {
// item.JobAttendanceFactor = item.JobFactor * item.Attendance / days;
// item.YearAttendanceFactor = item.Attendance * item.YearFactor / days;
// }
// //计算 科室系数人均
// var departmentFactorAvg = basicnumber / perAgainExcel.AgainEmployee.Sum(t => t.YearAttendanceFactor);
// //二次分配科室概览
// PerAgainSituation situation = new PerAgainSituation
// {
// NightShift = perAgainExcel.AgainEmployee.Sum(t => t.NightShift),
// DepartmentTotal = basicnumber,
// BossPerfor = departmentFactorAvg * bossAttendance / days,
// Award = perAgainExcel.AgainEmployee.Sum(t => t.Award),
// Allowance = perAgainExcel.AgainEmployee.Sum(t => t.Allowance),
// AlonePerfor = perAgainExcel.AgainEmployee.Sum(t => t.AlonePerfor),
// Attendance = days,
// DepartmentFactorAvg = departmentFactorAvg
// };
// //业绩二次分配科室概览:业绩分配绩效、职称绩效、工作量绩效
// situation.AllotPerfor = situation.DepartmentTotal - situation.BossPerfor - situation.Award - situation.Allowance - situation.AlonePerfor;
// situation.JobPerfor = situation.AllotPerfor * jobfactor;
// situation.WorkloadPerfor = situation.AllotPerfor * workfactor;
// var rowList = perAgainExcel.AgainData.Select(t => t.RowNumber).Distinct().ToList();
// //业绩二次分配科室动态数据:工作量得分
// foreach (var rowNumber in rowList)
// {
// var againEmployee = perAgainExcel.AgainEmployee.FirstOrDefault(t => t.RowNumber == rowNumber);
// var atRowList = perAgainExcel.AgainData.Where(t => t.RowNumber == rowNumber);
// decimal? sumValue = 0m;
// foreach (var atRow in atRowList)
// sumValue += atRow.IsFactor == 1 ? atRow.IsFactor * atRow.CellValue : atRow.CellValue;
// sumValue = sumValue * againEmployee?.YearFactor;
// var head = perAgainExcel.Header.Children.FirstOrDefault(t => t.CellValue == "工作量得分");
// if (head == null)
// {
// perAgainExcel.Header.MergeCell++;
// var pointrow = perAgainExcel.Header.Children.Max(t => t.PointRow);
// var pointcell = perAgainExcel.Header.Children.Max(t => t.PointCell);
// head = new PerHeader(pointrow, pointcell, "工作量得分", 1, 1, 1, null, 1);
// perAgainExcel.Header.Children.Add(head);
// }
// perAgainExcel.AgainData.Add(new PerAgainData(rowNumber.Value, "工作量得分", sumValue, 1, 2, null, "", "", head.SignID));
// }
// //业绩二次分配科室动态数据:绩效工资
// foreach (var rowNumber in rowList)
// {
// var workvalue = perAgainExcel.AgainData.FirstOrDefault(t => t.RowNumber == rowNumber && t.TypeName == "工作量得分")?.CellValue;
// var sumvalue = perAgainExcel.AgainData.Where(t => t.TypeName == "工作量得分").Sum(t => t.CellValue);
// var perforValue = workvalue / sumvalue * situation.WorkloadPerfor;
// var head = perAgainExcel.Header.Children.FirstOrDefault(t => t.CellValue == "绩效工资");
// if (head == null)
// {
// perAgainExcel.Header.MergeCell++;
// var pointrow = perAgainExcel.Header.Children.Max(t => t.PointRow);
// var pointcell = perAgainExcel.Header.Children.Max(t => t.PointCell);
// head = new PerHeader(pointrow, pointcell, "绩效工资", 1, 1, 1, null, 1);
// perAgainExcel.Header.Children.Add(head);
// }
// perAgainExcel.AgainData.Add(new PerAgainData(rowNumber.Value, "绩效工资", perforValue, 1, 2, null, "", "", head.SignID));
// }
// //业绩二次分配科室:应发绩效、实发绩效
// string[] jobArray = new string[] { "护士长", "科主任" };
// foreach (var employee in perAgainExcel.AgainEmployee)
// {
// if (jobArray.Contains(employee.JobTitle))
// {
// employee.GiveFee = situation.BossPerfor;
// employee.RealGiveFee = situation.BossPerfor;
// }
// else
// {
// employee.JobAttendancePerfor = situation.JobPerfor * employee.JobAttendanceFactor / perAgainExcel.AgainEmployee.Sum(t => t.JobAttendanceFactor);
// var value = perAgainExcel.AgainData.FirstOrDefault(t => t.RowNumber == employee.RowNumber && t.TypeName == "绩效工资")?.CellValue;
// employee.GiveFee = (employee.JobAttendancePerfor ?? 0) + (value ?? 0) + (employee.Award ?? 0) + (employee.Allowance ?? 0) + (employee.AlonePerfor ?? 0);
// employee.RealGiveFee = (employee.GiveFee ?? 0) + (employee.NightShift ?? 0);
// }
// }
// #endregion
// #region 保存
// var againsituation = _mapper.Map<ag_againsituation>(situation);
// againsituation.AllotID = againAllot.AllotID;
// againsituation.AgainAllotID = againAllot.ID;
// perforAgagainsituationRepository.Add(againsituation);
// var employeeList = _mapper.Map<List<ag_employee>>(perAgainExcel.AgainEmployee);
// employeeList.ForEach(item => { item.AllotID = againAllot.AllotID; item.AgainAllotID = againAllot.ID; });
// perforAgemployeeRepository.AddRange(employeeList.ToArray());
// var pHeader = _mapper.Map<ag_header>(perAgainExcel.Header);
// pHeader.AllotID = againAllot.AllotID;
// pHeader.AgainAllotID = againAllot.ID;
// var cHeaderList = _mapper.Map<List<ag_header>>(perAgainExcel.Header.Children);
// cHeaderList.ForEach(item => { item.AllotID = againAllot.AllotID; item.AgainAllotID = againAllot.ID; });
// perforAgheaderRepository.Add(pHeader);
// perforAgheaderRepository.AddRange(cHeaderList.ToArray());
// var dataList = _mapper.Map<List<ag_data>>(perAgainExcel.AgainData);
// dataList.ForEach(item => { item.AllotID = againAllot.AllotID; item.AgainAllotID = againAllot.ID; });
// perforAgdataRepository.AddRange(dataList.ToArray());
// #endregion
// }
// catch (Exception ex)
// {
// perforPeragainallotRepository.Update(againAllot, p => { p.States = 4; p.Remark = ex.ToString(); });
// }
// perforPeragainallotRepository.Update(againAllot, p => { p.States = 3; });
// return true;
// //return SheetFormat(perAgainExcel, situation);
//}
/// <summary>
/// 绩效详情表格转换
/// </summary>
/// <param name="perAgainExcel"></param>
/// <param name="situation"></param>
/// <returns></returns>
private (SheetExportResponse SheetExport, PerAgainSituation AgainSituation) SheetFormat(PerAgainExcel perAgainExcel, PerAgainSituation situation)
{
#region 表格显示
SheetExportResponse response = new SheetExportResponse("二次绩效分配表");
//返回表格展示数据结构
var row = new Row(0);
row.Data.Add(new Cell(1, "姓名", 2, 1, false, false));
row.Data.Add(new Cell(2, "职务", 2, 1, false, false));
row.Data.Add(new Cell(3, "职称系数", 2, 1, false, false));
row.Data.Add(new Cell(4, "出勤", 2, 1, false, false));
row.Data.Add(new Cell(5, "职称出勤系数", 2, 1, false, false));
row.Data.Add(new Cell(6, "年资", 2, 1, false, false));
row.Data.Add(new Cell(7, "年资出勤系数", 2, 1, false, false));
row.Data.Add(new Cell(8, "职称出勤绩效", 2, 1, false, false));
row.Data.Add(new Cell(9, perAgainExcel.Header.CellValue, 1, perAgainExcel.Header.Children.Count, false, false));
row.Data.Add(new Cell(9 + perAgainExcel.Header.Children.Count, "重点奖励", 2, 1, false, false));
row.Data.Add(new Cell(10 + perAgainExcel.Header.Children.Count, "管理津贴", 2, 1, false, false));
row.Data.Add(new Cell(11 + perAgainExcel.Header.Children.Count, "单独核算人员绩效", 2, 1, false, false));
row.Data.Add(new Cell(12 + perAgainExcel.Header.Children.Count, "应发绩效工资金额", 2, 1, false, false));
row.Data.Add(new Cell(13 + perAgainExcel.Header.Children.Count, "夜班费", 2, 1, false, false));
row.Data.Add(new Cell(14 + perAgainExcel.Header.Children.Count, "实发工资合计", 2, 1, false, false));
var rowTwo = new Row(1);
int startpoint = 9;
perAgainExcel.Header.Children.ForEach(t =>
{
rowTwo.Data.Add(new Cell(startpoint, t.CellValue, 1, 1, false, false));
startpoint++;
});
response.Header.Add(row);
response.Header.Add(rowTwo);
for (int i = 0; i < perAgainExcel.AgainEmployee.Count(); i++)
{
var item = perAgainExcel.AgainEmployee.ElementAt(i);
var rowbody = new Row(i);
rowbody.Data.Add(new Cell(1, item.Name, 1, 1, false, false));
rowbody.Data.Add(new Cell(2, item.JobTitle, 1, 1, false, false));
rowbody.Data.Add(new Cell(3, item.JobFactor, 1, 1, false, false));
rowbody.Data.Add(new Cell(4, item.Attendance, 1, 1, false, false));
rowbody.Data.Add(new Cell(5, item.JobAttendanceFactor, 1, 1, false, false));
rowbody.Data.Add(new Cell(6, item.YearFactor, 1, 1, false, false));
rowbody.Data.Add(new Cell(7, item.YearAttendanceFactor, 1, 1, false, false));
rowbody.Data.Add(new Cell(8, item.JobAttendancePerfor, 1, 1, false, false));
var againList = perAgainExcel.AgainData.Where(t => t.RowNumber == item.RowNumber);
startpoint = 9;
perAgainExcel.Header.Children.ForEach(t =>
{
var cellValue = againList.FirstOrDefault(s => t.SignID == s.SignID)?.CellValue;
rowbody.Data.Add(new Cell(startpoint, cellValue, 1, 1, false, false));
startpoint++;
});
rowbody.Data.Add(new Cell(9 + perAgainExcel.Header.Children.Count, item.Award, 1, 1, false, false));
rowbody.Data.Add(new Cell(10 + perAgainExcel.Header.Children.Count, item.Allowance, 1, 1, false, false));
rowbody.Data.Add(new Cell(11 + perAgainExcel.Header.Children.Count, item.AlonePerfor, 1, 1, false, false));
rowbody.Data.Add(new Cell(12 + perAgainExcel.Header.Children.Count, item.GiveFee, 1, 1, false, false));
rowbody.Data.Add(new Cell(13 + perAgainExcel.Header.Children.Count, item.NightShift, 1, 1, false, false));
rowbody.Data.Add(new Cell(14 + perAgainExcel.Header.Children.Count, item.RealGiveFee, 1, 1, false, false));
response.Row.Add(rowbody);
}
#endregion
return (response, situation);
}
/// <summary>
/// 查看二次分配详情及概览
/// </summary>
/// <param name="request"></param>
/// <param name="user"></param>
/// <returns></returns>
public (SheetExportResponse SheetExport, PerAgainSituation AgainSituation) Detail(AgainAllotRequest request)
{
var againAllot = perforPeragainallotRepository.GetEntity(t => t.ID == request.AgainAllotID);
if (againAllot == null || againAllot.ID == 0)
throw new PerformanceException("绩效二次分配不存在");
var situation = perforAgagainsituationRepository.GetEntity(t => t.AgainAllotID == againAllot.ID);
var againsituation = _mapper.Map<PerAgainSituation>(situation);
var againEmployee = perforAgemployeeRepository.GetEntities(t => t.AgainAllotID == againAllot.ID);
//var employeeList = _mapper.Map<List<PerAgainEmployee>>(againEmployee);
var header = perforAgheaderRepository.GetEntities(t => t.AgainAllotID == againAllot.ID);
//var headerList = _mapper.Map<List<PerHeader>>(header);
var data = perforAgdataRepository.GetEntities(t => t.AgainAllotID == againAllot.ID);
//var dataList = _mapper.Map<List<PerAgainData>>(data);
var pHead = header.FirstOrDefault(t => t.CellValue == "工作量绩效工资");
var head = _mapper.Map<PerHeader>(pHead);
var cHead = _mapper.Map<List<PerHeader>>(header.Where(t => t.CellValue != "工作量绩效工资"));
head.Children = cHead;
var perAgainExcel = new PerAgainExcel
{
Header = head,
AgainData = _mapper.Map<List<PerAgainData>>(data),
AgainEmployee = _mapper.Map<List<PerAgainEmployee>>(againEmployee)
};
return SheetFormat(perAgainExcel, againsituation);
}
/// <summary>
/// 二次绩效新增记录
/// </summary>
/// <param name="allot"></param>
/// <param name="userid"></param>
/// <returns></returns>
public bool Update(per_allot allot, int againid)
{
var again = perforPeragainallotRepository.GetEntity(t => t.ID == againid);
again.ID = againid;
again.UploadDateTime = DateTime.Now;
again.Path = allot.Path;
again.Remark = allot.Remark;
again.States = 1;
return perforPeragainallotRepository.Update(again);
}
/// <summary>
/// 根据人物角色获取绩效列表
/// </summary>
/// <returns></returns>
public List<AgainAllotResponse> GetAllotList(int userid)
{
var user = perforUserRepository.GetEntity(t => t.ID == userid);
if (user == null)
throw new NotImplementedException("人员ID无效");
var hospital = perforUserhospitalRepository.GetEntity(t => t.UserID == userid);
if (hospital == null)
throw new NotImplementedException("人员未选择医院");
var allot = perforPerallotRepository.GetEntities(t => t.HospitalId == hospital.HospitalID && t.States == 6);
if (allot == null)
throw new NotImplementedException("该医院未生成绩效");
var allotId = allot.Select(t => t.ID).ToList();
var again = perforPeragainallotRepository.GetEntities(t => allotId.Contains(t.AllotID.Value) && t.Department == user.Department);
var arrId = again == null ? new List<int>() : again.Select(t => t.AllotID.Value).ToList();
//取得未生成二次绩效的绩效id
var exceptId = allotId.Except(arrId).ToList();
if (exceptId.Count > 0)
{
allot = allot.Where(t => exceptId.Contains(t.ID)).ToList();
var model = allot.Select(t => new per_againallot
{
AllotID = t.ID,
CreateUser = userid,
CreateDateTime = DateTime.Now,
Department = user.Department,
States = 0
});
//生成二次绩效
perforPeragainallotRepository.AddRange(model.ToArray());
}
again = perforPeragainallotRepository.GetEntities(t => allotId.Contains(t.AllotID.Value) && t.CreateUser == userid);
List<AgainAllotResponse> list = _mapper.Map<List<AgainAllotResponse>>(again);
list.ForEach(t =>
{
var data = allot.Where(p => p.ID == t.AllotID).FirstOrDefault();
t.Year = data.Year;
t.Month = data.Month;
});
return list.OrderByDescending(t => t.Year).ThenByDescending(t => t.Month).ToList();
}
/// <summary>
/// 获取状态不是归档的二次绩效的记录
/// </summary>
/// <param name="againid"></param>
/// <returns></returns>
public per_againallot GetAgainallot(int againid)
{
var list = perforPeragainallotRepository.GetEntity(t => t.ID == againid && t.States != 5);
return list;
}
}
}
//using AutoMapper;
//using Microsoft.Extensions.Options;
//using Performance.DtoModels;
//using Performance.DtoModels.AppSettings;
//using Performance.EntityModels;
//using Performance.Repository;
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//namespace Performance.Services
//{
// public class AgainAllotService : IAutoInjection
// {
// private Application application;
// private readonly IMapper _mapper;
// private AgainService againService;
// private RoleService roleService;
// private ConfigService configService;
// private PerforCofagainRepository perforCofagainRepository;
// private PerforPeragainallotRepository perforPeragainallotRepository;
// private PerforResaccountRepository perforResaccountRepository;
// //private PerforResaccountnurseRepository perforResaccountnurseRepository;
// private PerforUserRepository perforUserRepository;
// private PerforUserhospitalRepository perforUserhospitalRepository;
// private PerforPerallotRepository perforPerallotRepository;
// private PerforAgagainsituationRepository perforAgagainsituationRepository;
// private PerforAgdataRepository perforAgdataRepository;
// private PerforAgemployeeRepository perforAgemployeeRepository;
// private PerforAgheaderRepository perforAgheaderRepository;
// public AgainAllotService(
// IOptions<Application> options,
// IMapper mapper,
// AgainService againService,
// RoleService roleService,
// PerforCofagainRepository perforCofagainRepository,
// PerforPeragainallotRepository perforPeragainallotRepository,
// PerforResaccountRepository perforResaccountRepository,
// //PerforResaccountnurseRepository perforResaccountnurseRepository,
// PerforUserRepository perforUserRepository,
// PerforUserhospitalRepository perforUserhospitalRepository,
// PerforPerallotRepository perforPerallotRepository,
// PerforAgagainsituationRepository perforAgagainsituationRepository,
// PerforAgdataRepository perforAgdataRepository,
// PerforAgemployeeRepository perforAgemployeeRepository,
// PerforAgheaderRepository perforAgheaderRepository,
// ConfigService configService)
// {
// this.application = options.Value;
// _mapper = mapper;
// this.againService = againService;
// this.roleService = roleService;
// this.perforCofagainRepository = perforCofagainRepository;
// this.perforPeragainallotRepository = perforPeragainallotRepository;
// this.perforResaccountRepository = perforResaccountRepository;
// //this.perforResaccountnurseRepository = perforResaccountnurseRepository;
// this.perforUserRepository = perforUserRepository;
// this.perforUserhospitalRepository = perforUserhospitalRepository;
// this.perforPerallotRepository = perforPerallotRepository;
// this.perforAgagainsituationRepository = perforAgagainsituationRepository;
// this.perforAgdataRepository = perforAgdataRepository;
// this.perforAgemployeeRepository = perforAgemployeeRepository;
// this.perforAgheaderRepository = perforAgheaderRepository;
// this.configService = configService;
// }
// ///// <summary>
// ///// 生成二次绩效
// ///// </summary>
// ///// <param name="request"></param>
// //public bool Generate(AgainAllotRequest request, int userId, string department)
// //{
// // var againAllot = perforPeragainallotRepository.GetEntity(t => t.ID == request.AgainAllotID);
// // if (againAllot == null || againAllot.ID == 0)
// // throw new PerformanceException("绩效二次分配不存在");
// // var roles = roleService.GetRole(userId);
// // perforPeragainallotRepository.Update(againAllot, p => { p.States = 2; });
// // //清理二次绩效无用数据
// // configService.ClearAgain(againAllot.ID);
// // try
// // {
// // #region 基础信息
// // //获取基础配置信息
// // var config = perforCofagainRepository.GetEntities(t => t.AllotID == againAllot.AllotID);
// // var jobfactor = config.FirstOrDefault(t => t.Type == 1)?.Value;
// // var workfactor = config.FirstOrDefault(t => t.Type == 2)?.Value;
// // var days = config.FirstOrDefault(t => t.Type == 3)?.Value;
// // decimal? basicnumber = 0m;
// // //获取科室实发绩效
// // if (roles != null)
// // {
// // var role = roles.FirstOrDefault();
// // if (role != null)
// // {
// // if (application.NurseRole == role.Type)
// // basicnumber = perforResaccountRepository.GetEntity(t => t.UnitType == (int)UnitType.护理组 && t.AllotID == againAllot.AllotID && t.AccountingUnit == department)?.RealGiveFee;
// // else if (application.DirectorRole == role.Type)
// // basicnumber = perforResaccountRepository.GetEntity(t => t.UnitType != (int)UnitType.护理组 && t.AllotID == againAllot.AllotID && t.AccountingUnit == department)?.RealGiveFee;
// // }
// // }
// // #endregion
// // #region 计算
// // //读取二次计算excel数据
// // var perAgainExcel = againService.ReadData(againAllot);
// // //护士长或科主任出勤
// // var bossAttendance = perAgainExcel.AgainEmployee.FirstOrDefault(t => t.JobTitle == "护士长")?.Attendance;
// // //计算职称出勤系数、年资出勤系数
// // foreach (var item in perAgainExcel.AgainEmployee)
// // {
// // item.JobAttendanceFactor = item.JobFactor * item.Attendance / days;
// // item.YearAttendanceFactor = item.Attendance * item.YearFactor / days;
// // }
// // //计算 科室系数人均
// // var departmentFactorAvg = basicnumber / perAgainExcel.AgainEmployee.Sum(t => t.YearAttendanceFactor);
// // //二次分配科室概览
// // PerAgainSituation situation = new PerAgainSituation
// // {
// // NightShift = perAgainExcel.AgainEmployee.Sum(t => t.NightShift),
// // DepartmentTotal = basicnumber,
// // BossPerfor = departmentFactorAvg * bossAttendance / days,
// // Award = perAgainExcel.AgainEmployee.Sum(t => t.Award),
// // Allowance = perAgainExcel.AgainEmployee.Sum(t => t.Allowance),
// // AlonePerfor = perAgainExcel.AgainEmployee.Sum(t => t.AlonePerfor),
// // Attendance = days,
// // DepartmentFactorAvg = departmentFactorAvg
// // };
// // //业绩二次分配科室概览:业绩分配绩效、职称绩效、工作量绩效
// // situation.AllotPerfor = situation.DepartmentTotal - situation.BossPerfor - situation.Award - situation.Allowance - situation.AlonePerfor;
// // situation.JobPerfor = situation.AllotPerfor * jobfactor;
// // situation.WorkloadPerfor = situation.AllotPerfor * workfactor;
// // var rowList = perAgainExcel.AgainData.Select(t => t.RowNumber).Distinct().ToList();
// // //业绩二次分配科室动态数据:工作量得分
// // foreach (var rowNumber in rowList)
// // {
// // var againEmployee = perAgainExcel.AgainEmployee.FirstOrDefault(t => t.RowNumber == rowNumber);
// // var atRowList = perAgainExcel.AgainData.Where(t => t.RowNumber == rowNumber);
// // decimal? sumValue = 0m;
// // foreach (var atRow in atRowList)
// // sumValue += atRow.IsFactor == 1 ? atRow.IsFactor * atRow.CellValue : atRow.CellValue;
// // sumValue = sumValue * againEmployee?.YearFactor;
// // var head = perAgainExcel.Header.Children.FirstOrDefault(t => t.CellValue == "工作量得分");
// // if (head == null)
// // {
// // perAgainExcel.Header.MergeCell++;
// // var pointrow = perAgainExcel.Header.Children.Max(t => t.PointRow);
// // var pointcell = perAgainExcel.Header.Children.Max(t => t.PointCell);
// // head = new PerHeader(pointrow, pointcell, "工作量得分", 1, 1, 1, null, 1);
// // perAgainExcel.Header.Children.Add(head);
// // }
// // perAgainExcel.AgainData.Add(new PerAgainData(rowNumber.Value, "工作量得分", sumValue, 1, 2, null, "", "", head.SignID));
// // }
// // //业绩二次分配科室动态数据:绩效工资
// // foreach (var rowNumber in rowList)
// // {
// // var workvalue = perAgainExcel.AgainData.FirstOrDefault(t => t.RowNumber == rowNumber && t.TypeName == "工作量得分")?.CellValue;
// // var sumvalue = perAgainExcel.AgainData.Where(t => t.TypeName == "工作量得分").Sum(t => t.CellValue);
// // var perforValue = workvalue / sumvalue * situation.WorkloadPerfor;
// // var head = perAgainExcel.Header.Children.FirstOrDefault(t => t.CellValue == "绩效工资");
// // if (head == null)
// // {
// // perAgainExcel.Header.MergeCell++;
// // var pointrow = perAgainExcel.Header.Children.Max(t => t.PointRow);
// // var pointcell = perAgainExcel.Header.Children.Max(t => t.PointCell);
// // head = new PerHeader(pointrow, pointcell, "绩效工资", 1, 1, 1, null, 1);
// // perAgainExcel.Header.Children.Add(head);
// // }
// // perAgainExcel.AgainData.Add(new PerAgainData(rowNumber.Value, "绩效工资", perforValue, 1, 2, null, "", "", head.SignID));
// // }
// // //业绩二次分配科室:应发绩效、实发绩效
// // string[] jobArray = new string[] { "护士长", "科主任" };
// // foreach (var employee in perAgainExcel.AgainEmployee)
// // {
// // if (jobArray.Contains(employee.JobTitle))
// // {
// // employee.GiveFee = situation.BossPerfor;
// // employee.RealGiveFee = situation.BossPerfor;
// // }
// // else
// // {
// // employee.JobAttendancePerfor = situation.JobPerfor * employee.JobAttendanceFactor / perAgainExcel.AgainEmployee.Sum(t => t.JobAttendanceFactor);
// // var value = perAgainExcel.AgainData.FirstOrDefault(t => t.RowNumber == employee.RowNumber && t.TypeName == "绩效工资")?.CellValue;
// // employee.GiveFee = (employee.JobAttendancePerfor ?? 0) + (value ?? 0) + (employee.Award ?? 0) + (employee.Allowance ?? 0) + (employee.AlonePerfor ?? 0);
// // employee.RealGiveFee = (employee.GiveFee ?? 0) + (employee.NightShift ?? 0);
// // }
// // }
// // #endregion
// // #region 保存
// // var againsituation = _mapper.Map<ag_againsituation>(situation);
// // againsituation.AllotID = againAllot.AllotID;
// // againsituation.AgainAllotID = againAllot.ID;
// // perforAgagainsituationRepository.Add(againsituation);
// // var employeeList = _mapper.Map<List<ag_employee>>(perAgainExcel.AgainEmployee);
// // employeeList.ForEach(item => { item.AllotID = againAllot.AllotID; item.AgainAllotID = againAllot.ID; });
// // perforAgemployeeRepository.AddRange(employeeList.ToArray());
// // var pHeader = _mapper.Map<ag_header>(perAgainExcel.Header);
// // pHeader.AllotID = againAllot.AllotID;
// // pHeader.AgainAllotID = againAllot.ID;
// // var cHeaderList = _mapper.Map<List<ag_header>>(perAgainExcel.Header.Children);
// // cHeaderList.ForEach(item => { item.AllotID = againAllot.AllotID; item.AgainAllotID = againAllot.ID; });
// // perforAgheaderRepository.Add(pHeader);
// // perforAgheaderRepository.AddRange(cHeaderList.ToArray());
// // var dataList = _mapper.Map<List<ag_data>>(perAgainExcel.AgainData);
// // dataList.ForEach(item => { item.AllotID = againAllot.AllotID; item.AgainAllotID = againAllot.ID; });
// // perforAgdataRepository.AddRange(dataList.ToArray());
// // #endregion
// // }
// // catch (Exception ex)
// // {
// // perforPeragainallotRepository.Update(againAllot, p => { p.States = 4; p.Remark = ex.ToString(); });
// // }
// // perforPeragainallotRepository.Update(againAllot, p => { p.States = 3; });
// // return true;
// // //return SheetFormat(perAgainExcel, situation);
// //}
// /// <summary>
// /// 绩效详情表格转换
// /// </summary>
// /// <param name="perAgainExcel"></param>
// /// <param name="situation"></param>
// /// <returns></returns>
// private (SheetExportResponse SheetExport, PerAgainSituation AgainSituation) SheetFormat(PerAgainExcel perAgainExcel, PerAgainSituation situation)
// {
// #region 表格显示
// SheetExportResponse response = new SheetExportResponse("二次绩效分配表");
// //返回表格展示数据结构
// var row = new Row(0);
// row.Data.Add(new Cell(1, "姓名", 2, 1, false, false));
// row.Data.Add(new Cell(2, "职务", 2, 1, false, false));
// row.Data.Add(new Cell(3, "职称系数", 2, 1, false, false));
// row.Data.Add(new Cell(4, "出勤", 2, 1, false, false));
// row.Data.Add(new Cell(5, "职称出勤系数", 2, 1, false, false));
// row.Data.Add(new Cell(6, "年资", 2, 1, false, false));
// row.Data.Add(new Cell(7, "年资出勤系数", 2, 1, false, false));
// row.Data.Add(new Cell(8, "职称出勤绩效", 2, 1, false, false));
// row.Data.Add(new Cell(9, perAgainExcel.Header.CellValue, 1, perAgainExcel.Header.Children.Count, false, false));
// row.Data.Add(new Cell(9 + perAgainExcel.Header.Children.Count, "重点奖励", 2, 1, false, false));
// row.Data.Add(new Cell(10 + perAgainExcel.Header.Children.Count, "管理津贴", 2, 1, false, false));
// row.Data.Add(new Cell(11 + perAgainExcel.Header.Children.Count, "单独核算人员绩效", 2, 1, false, false));
// row.Data.Add(new Cell(12 + perAgainExcel.Header.Children.Count, "应发绩效工资金额", 2, 1, false, false));
// row.Data.Add(new Cell(13 + perAgainExcel.Header.Children.Count, "夜班费", 2, 1, false, false));
// row.Data.Add(new Cell(14 + perAgainExcel.Header.Children.Count, "实发工资合计", 2, 1, false, false));
// var rowTwo = new Row(1);
// int startpoint = 9;
// perAgainExcel.Header.Children.ForEach(t =>
// {
// rowTwo.Data.Add(new Cell(startpoint, t.CellValue, 1, 1, false, false));
// startpoint++;
// });
// response.Header.Add(row);
// response.Header.Add(rowTwo);
// for (int i = 0; i < perAgainExcel.AgainEmployee.Count(); i++)
// {
// var item = perAgainExcel.AgainEmployee.ElementAt(i);
// var rowbody = new Row(i);
// rowbody.Data.Add(new Cell(1, item.Name, 1, 1, false, false));
// rowbody.Data.Add(new Cell(2, item.JobTitle, 1, 1, false, false));
// rowbody.Data.Add(new Cell(3, item.JobFactor, 1, 1, false, false));
// rowbody.Data.Add(new Cell(4, item.Attendance, 1, 1, false, false));
// rowbody.Data.Add(new Cell(5, item.JobAttendanceFactor, 1, 1, false, false));
// rowbody.Data.Add(new Cell(6, item.YearFactor, 1, 1, false, false));
// rowbody.Data.Add(new Cell(7, item.YearAttendanceFactor, 1, 1, false, false));
// rowbody.Data.Add(new Cell(8, item.JobAttendancePerfor, 1, 1, false, false));
// var againList = perAgainExcel.AgainData.Where(t => t.RowNumber == item.RowNumber);
// startpoint = 9;
// perAgainExcel.Header.Children.ForEach(t =>
// {
// var cellValue = againList.FirstOrDefault(s => t.SignID == s.SignID)?.CellValue;
// rowbody.Data.Add(new Cell(startpoint, cellValue, 1, 1, false, false));
// startpoint++;
// });
// rowbody.Data.Add(new Cell(9 + perAgainExcel.Header.Children.Count, item.Award, 1, 1, false, false));
// rowbody.Data.Add(new Cell(10 + perAgainExcel.Header.Children.Count, item.Allowance, 1, 1, false, false));
// rowbody.Data.Add(new Cell(11 + perAgainExcel.Header.Children.Count, item.AlonePerfor, 1, 1, false, false));
// rowbody.Data.Add(new Cell(12 + perAgainExcel.Header.Children.Count, item.GiveFee, 1, 1, false, false));
// rowbody.Data.Add(new Cell(13 + perAgainExcel.Header.Children.Count, item.NightShift, 1, 1, false, false));
// rowbody.Data.Add(new Cell(14 + perAgainExcel.Header.Children.Count, item.RealGiveFee, 1, 1, false, false));
// response.Row.Add(rowbody);
// }
// #endregion
// return (response, situation);
// }
// /// <summary>
// /// 查看二次分配详情及概览
// /// </summary>
// /// <param name="request"></param>
// /// <param name="user"></param>
// /// <returns></returns>
// public (SheetExportResponse SheetExport, PerAgainSituation AgainSituation) Detail(AgainAllotRequest request)
// {
// var againAllot = perforPeragainallotRepository.GetEntity(t => t.ID == request.AgainAllotID);
// if (againAllot == null || againAllot.ID == 0)
// throw new PerformanceException("绩效二次分配不存在");
// var situation = perforAgagainsituationRepository.GetEntity(t => t.AgainAllotID == againAllot.ID);
// var againsituation = _mapper.Map<PerAgainSituation>(situation);
// var againEmployee = perforAgemployeeRepository.GetEntities(t => t.AgainAllotID == againAllot.ID);
// //var employeeList = _mapper.Map<List<PerAgainEmployee>>(againEmployee);
// var header = perforAgheaderRepository.GetEntities(t => t.AgainAllotID == againAllot.ID);
// //var headerList = _mapper.Map<List<PerHeader>>(header);
// var data = perforAgdataRepository.GetEntities(t => t.AgainAllotID == againAllot.ID);
// //var dataList = _mapper.Map<List<PerAgainData>>(data);
// var pHead = header.FirstOrDefault(t => t.CellValue == "工作量绩效工资");
// var head = _mapper.Map<PerHeader>(pHead);
// var cHead = _mapper.Map<List<PerHeader>>(header.Where(t => t.CellValue != "工作量绩效工资"));
// head.Children = cHead;
// var perAgainExcel = new PerAgainExcel
// {
// Header = head,
// AgainData = _mapper.Map<List<PerAgainData>>(data),
// AgainEmployee = _mapper.Map<List<PerAgainEmployee>>(againEmployee)
// };
// return SheetFormat(perAgainExcel, againsituation);
// }
// /// <summary>
// /// 二次绩效新增记录
// /// </summary>
// /// <param name="allot"></param>
// /// <param name="userid"></param>
// /// <returns></returns>
// public bool Update(per_allot allot, int againid)
// {
// var again = perforPeragainallotRepository.GetEntity(t => t.ID == againid);
// again.ID = againid;
// again.UploadDateTime = DateTime.Now;
// again.Path = allot.Path;
// again.Remark = allot.Remark;
// again.States = 1;
// return perforPeragainallotRepository.Update(again);
// }
// /// <summary>
// /// 根据人物角色获取绩效列表
// /// </summary>
// /// <returns></returns>
// public List<AgainAllotResponse> GetAllotList(int userid)
// {
// var user = perforUserRepository.GetEntity(t => t.ID == userid);
// if (user == null)
// throw new NotImplementedException("人员ID无效");
// var hospital = perforUserhospitalRepository.GetEntity(t => t.UserID == userid);
// if (hospital == null)
// throw new NotImplementedException("人员未选择医院");
// var allot = perforPerallotRepository.GetEntities(t => t.HospitalId == hospital.HospitalID && t.States == 6);
// if (allot == null)
// throw new NotImplementedException("该医院未生成绩效");
// var allotId = allot.Select(t => t.ID).ToList();
// var again = perforPeragainallotRepository.GetEntities(t => allotId.Contains(t.AllotID.Value) && t.Department == user.Department);
// var arrId = again == null ? new List<int>() : again.Select(t => t.AllotID.Value).ToList();
// //取得未生成二次绩效的绩效id
// var exceptId = allotId.Except(arrId).ToList();
// if (exceptId.Count > 0)
// {
// allot = allot.Where(t => exceptId.Contains(t.ID)).ToList();
// var model = allot.Select(t => new per_againallot
// {
// AllotID = t.ID,
// CreateUser = userid,
// CreateDateTime = DateTime.Now,
// Department = user.Department,
// States = 0
// });
// //生成二次绩效
// perforPeragainallotRepository.AddRange(model.ToArray());
// }
// again = perforPeragainallotRepository.GetEntities(t => allotId.Contains(t.AllotID.Value) && t.CreateUser == userid);
// List<AgainAllotResponse> list = _mapper.Map<List<AgainAllotResponse>>(again);
// list.ForEach(t =>
// {
// var data = allot.Where(p => p.ID == t.AllotID).FirstOrDefault();
// t.Year = data.Year;
// t.Month = data.Month;
// });
// return list.OrderByDescending(t => t.Year).ThenByDescending(t => t.Month).ToList();
// }
// /// <summary>
// /// 获取状态不是归档的二次绩效的记录
// /// </summary>
// /// <param name="againid"></param>
// /// <returns></returns>
// public per_againallot GetAgainallot(int againid)
// {
// var list = perforPeragainallotRepository.GetEntity(t => t.ID == againid && t.States != 5);
// return list;
// }
// }
//}
......@@ -16,6 +16,7 @@
using System.Data;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
namespace Performance.Services
{
......@@ -30,6 +31,7 @@ public class AllotService : IAutoInjection
private IWebHostEnvironment _evn;
private ILogger<AllotService> _logger;
private readonly IMapper _mapper;
private readonly PerforUserRepository _userRepository;
private PerforPerallotRepository _allotRepository;
private IEmailService emailService;
private readonly IOptions<Application> options;
......@@ -55,6 +57,7 @@ public class AllotService : IAutoInjection
public AllotService(
IMapper mapper,
PerforUserRepository userRepository,
PerforPerallotRepository allotRepository,
BaiscNormService baiscNormService,
ImportDataService importDataService,
......@@ -85,6 +88,7 @@ public class AllotService : IAutoInjection
QueryDataService queryDataService)
{
_mapper = mapper;
_userRepository = userRepository;
_allotRepository = allotRepository;
_againallotRepository = againallotRepository;
_logger = logger;
......@@ -650,26 +654,19 @@ public List<log_dbug> AllotLog(per_allot allot, int type)
/// <returns></returns>
public List<EmployeeReservedDto> GetReserved(int hospitalId, int year, int userid)
{
var user = userService.GetUser(userid);
if (user == null)
throw new PerformanceException("用户信息错误");
var role = roleService.GetUserRole(userid)?.FirstOrDefault()?.Type;
if (!role.HasValue)
throw new PerformanceException("用户信息错误");
var userInfo = _userRepository.GetUser(userid);
if (userInfo?.User == null) throw new NotImplementedException("当前用户不存在");
if (userInfo?.URole == null) throw new NotImplementedException("当前用户暂未分配角色");
var reserveds = _reportRepository.GetEmployeeReserved(hospitalId, year);
if (reserveds != null && reserveds.Any())
{
if (role.Value == options.Value.NurseRole)
reserveds = reserveds.Where(w => UnitTypeUtil.Is(w.UnitType, UnitType.护理组, UnitType.其他护理组) && w.AccountingUnit == user.Department)?.ToList();
else if (role.Value == options.Value.DirectorRole)
reserveds = reserveds.Where(w => UnitTypeUtil.Is(w.UnitType, UnitType.医生组, UnitType.其他医生组, UnitType.医技组, UnitType.其他医技组) && w.AccountingUnit == user.Department)?.ToList();
else if (role.Value == options.Value.SpecialRole)
reserveds = reserveds.Where(w => UnitTypeUtil.Is(w.UnitType, UnitType.特殊核算组) && w.AccountingUnit == user.Department)?.ToList();
else if (role.Value == options.Value.OfficeRole)
reserveds = reserveds.Where(w => UnitTypeUtil.Is(w.UnitType, UnitType.行政中层, UnitType.行政后勤) && w.AccountingUnit == user.Department)?.ToList();
Expression<Func<EmployeeReservedDto, bool>> exp = w => w.AccountingUnit == userInfo.User.Department;
if (userInfo.URole.Type.HasValue && UnitTypeUtil.Maps.ContainsKey(userInfo.URole.Type.Value))
exp = exp.And(t => UnitTypeUtil.Maps[userInfo.URole.Type.Value].Contains(t.UnitType));
reserveds = reserveds.Where(exp.Compile())?.ToList();
}
return reserveds;
......
......@@ -250,7 +250,7 @@ public IEnumerable<collect_permission> GetCollectSheet(int hospitalId, int userI
var userrole = userroleRepository.GetEntity(t => t.UserID == userId);
if (userrole == null) return new List<collect_permission>();
if (!options.CollectRoles.Contains(userrole.RoleID))
if (!UnitTypeUtil.CollectRoles.Contains(userrole.RoleID))
{
var types = new[] { (int)SheetType.OtherIncome, (int)SheetType.Expend, (int)SheetType.Workload, (int)SheetType.SpecialUnit };
var sheetNames = exmoduleRepository.GetEntities(w => w.HospitalId == hospitalId && types.Contains(w.SheetType ?? 0))?.Select(t => t.ModuleName).ToList() ?? new List<string>();
......
......@@ -77,12 +77,12 @@ public List<CostTransferResponse> GetAuditList(int allotId, int menuType, int ro
var account = GetAccounting(allotId, roleType, Department);
Expression<Func<cost_transfer, bool>> exp = t => t.AllotId == allotId;
if (roleType == application.DirectorRole)
if (roleType == (int)Role.科主任)
if (menuType == 1)
exp = exp.And(t => new List<string> { UnitType.医生组.ToString(), UnitType.医技组.ToString() }.Contains(t.ApplicantUnitType));
else
exp = exp.And(t => new List<string> { UnitType.医生组.ToString(), UnitType.医技组.ToString() }.Contains(t.AdoptedUnitType));
else if (roleType == application.NurseRole)
else if (roleType == (int)Role.护士长)
if (menuType == 1)
exp = exp.And(t => t.ApplicantUnitType == UnitType.护理组.ToString());
else
......@@ -149,14 +149,9 @@ public List<CostTransferResponse> GetAuditList(int allotId, int menuType, int ro
public cof_accounting GetAccounting(int allotId, int roleType, string Department = null)
{
Expression<Func<cof_accounting, bool>> exp = t => t.AllotId == allotId && t.AccountingUnit == Department;
if (roleType == application.DirectorRole)
exp = exp.And(t => new List<string> { UnitType.医生组.ToString(), UnitType.医技组.ToString() }.Contains(t.UnitType));
else if (roleType == application.NurseRole)
exp = exp.And(t => t.UnitType == UnitType.护理组.ToString());
else if (roleType == application.SpecialRole)
exp = exp.And(t => t.UnitType == UnitType.特殊核算组.ToString());
else if (roleType == application.OfficeRole)
exp = exp.And(t => t.UnitType == UnitType.行政后勤.ToString());
if (UnitTypeUtil.Maps.ContainsKey(roleType))
exp = exp.And(t => UnitTypeUtil.Maps[roleType].Contains(t.UnitType));
var account = cofaccountingRepository.GetEntity(exp);
......
......@@ -23,6 +23,7 @@ public class CustomExtractService : IAutoInjection
private readonly IOptions<Application> _options;
private readonly UserService _userService;
private readonly RoleService _roleService;
private readonly PerforUserRepository _userRepository;
private readonly PerforPerallotRepository _perallotRepository;
private readonly PerforPerdeptdicRepository _perforPerdeptdicRepository;
private readonly PerforHospitalconfigRepository _perforHospitalconfigRepository;
......@@ -34,6 +35,7 @@ public class CustomExtractService : IAutoInjection
IOptions<Application> options,
UserService userService,
RoleService roleService,
PerforUserRepository userRepository,
PerforPerallotRepository perallotRepository,
PerforPerdeptdicRepository perforPerdeptdicRepository,
PerforHospitalconfigRepository perforHospitalconfigRepository,
......@@ -44,6 +46,7 @@ public class CustomExtractService : IAutoInjection
_options = options;
_userService = userService;
_roleService = roleService;
_userRepository = userRepository;
_perallotRepository = perallotRepository;
_perforPerdeptdicRepository = perforPerdeptdicRepository;
_perforHospitalconfigRepository = perforHospitalconfigRepository;
......@@ -57,8 +60,8 @@ public bool CheckConfigScript(int userId, int allotId)
?? throw new PerformanceException("绩效ID无效");
var scripts = _perforcustscriptRepository.GetEntities(w => w.HospitalId == allot.HospitalId && w.IsEnable == 1);
scripts = (IsSecondAdmin(userId, out string[] unitType))
var center = _userRepository.GetUser(userId);
scripts = UnitTypeUtil.Maps.ContainsKey(center?.URole.Type ?? 0)
? scripts?.Where(w => w.IsSecondAllot == 1).ToList()
: scripts?.Where(w => w.IsOnceAllot == 1).ToList();
......@@ -74,9 +77,11 @@ public bool ExtractData(int userId, int allotId, out string resultFilePath)
var filePath = ExtractHelper.GetExtractFile(allot.HospitalId);
resultFilePath = filePath;
var center = _userRepository.GetUser(userId);
var scripts = _perforcustscriptRepository.GetEntities(w => w.HospitalId == allot.HospitalId && w.IsEnable == 1);
scripts = (IsSecondAdmin(userId, out string[] unitType))
scripts = UnitTypeUtil.Maps.ContainsKey(center?.URole.Type ?? 0)
? scripts?.Where(w => w.IsSecondAllot == 1).ToList()
: scripts?.Where(w => w.IsOnceAllot == 1).ToList();
......@@ -132,7 +137,12 @@ private void WriteDataToFile(int userId, per_allot allot, List<cust_script> scri
?? throw new PerformanceException("当前医院没有数据库地址配置");
var parameters = GetParameters(allot);
var (isSecondAdmin, department, unitType) = GetUserDepartment(userId);
var center = _userRepository.GetUser(userId);
var isSecondAdmin = UnitTypeUtil.Maps.ContainsKey(center?.URole.Type ?? 0);
var department = isSecondAdmin ? (center?.User.Department ?? "") : string.Empty;
var unitType = UnitTypeUtil.Maps[center?.URole.Type ?? 0];
parameters.Add("@department", $"'{department}'");
if (unitType != null && unitType.Any())
parameters.Add("@unittype", $"{string.Join(", ", unitType.Select(t => $"'{t}'"))}");
......@@ -292,44 +302,5 @@ public IEnumerable<dynamic> QueryData(sys_hospitalconfig config, string execsql,
};
return pairs;
}
/// <summary>
/// 是否是二次分配管理员 是 true 否 false
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
private bool IsSecondAdmin(int userId, out string[] unitType)
{
Dictionary<int, string[]> pairs = new Dictionary<int, string[]>
{
{ _options.Value.NurseRole, new string[] { UnitType.护理组.ToString() } },
{ _options.Value.DirectorRole, new string[] { UnitType.医生组.ToString(), UnitType.医技组.ToString() } },
{ _options.Value.SpecialRole, new string[] { UnitType.特殊核算组.ToString() } },
{ _options.Value.OfficeRole, new string[] { UnitType.行政后勤.ToString() } },
};
var roleId = _roleService.GetRole(userId)?.FirstOrDefault().ID ?? 0;
if (pairs.ContainsKey(roleId))
{
unitType = pairs[roleId];
return true;
}
unitType = new string[] { };
return false;
}
/// <summary>
/// 返回二次分配管理科室 默认 返回 空值
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
private (bool isSecondAdmin, string department, string[] unitType) GetUserDepartment(int userId)
{
var user = _userService.GetUser(userId)
?? throw new PerformanceException("当前用户信息无效");
var isSecondAdmin = IsSecondAdmin(userId, out string[] unitType);
var department = isSecondAdmin ? (user.Department ?? "") : string.Empty;
return (isSecondAdmin, department, unitType);
}
}
}
......@@ -188,12 +188,15 @@ public List<per_employee> GetPerEmployee(int allotId)
/// <returns></returns>
public List<per_employee> GetPersons(int allotId, int userId)
{
var (dept, unittype) = GetDeptByUser(userId);
var userInfo = perforUserRepository.GetUser(userId);
var dept = userInfo?.User.Department ?? "";
var unittype = (userInfo != null && userInfo.URole.Type.HasValue && UnitTypeUtil.Maps.ContainsKey(userInfo.URole.Type.Value))
? UnitTypeUtil.Maps[userInfo.URole.Type.Value]
: new string[0];
Expression<Func<per_employee, bool>> exp = t => t.AllotId == allotId;
if (!string.IsNullOrEmpty(dept) && unittype.Any())
{
exp = exp.And(t => t.AccountingUnit == dept && unittype.Contains(t.UnitType));
}
var list = peremployeeRepository.GetEntities(exp);
if (list != null && list.Any())
......@@ -209,17 +212,18 @@ public List<per_employee> GetPersons(int allotId, int userId)
/// <returns></returns>
public PageList<per_employee> GetPersons(int allotId, int userId, PersonParamsRequest request)
{
var (dept, unittype) = GetDeptByUser(userId);
var userInfo = perforUserRepository.GetUser(userId);
var dept = userInfo?.User.Department ?? "";
var unittype = (userInfo != null && userInfo.URole.Type.HasValue && UnitTypeUtil.Maps.ContainsKey(userInfo.URole.Type.Value))
? UnitTypeUtil.Maps[userInfo.URole.Type.Value]
: new string[0];
Expression<Func<per_employee, bool>> exp = t => t.AllotId == allotId;
if (!string.IsNullOrEmpty(dept) && unittype.Any())
{
exp = exp.And(t => t.AccountingUnit == dept && unittype.Contains(t.UnitType));
}
if (request != null && !string.IsNullOrEmpty(request.SearchQuery))
{
exp = exp.And(t => true && (t.AccountingUnit.Contains(request.SearchQuery) || t.PersonnelNumber.Contains(request.SearchQuery) || t.DoctorName.Contains(request.SearchQuery) || t.Department.Contains(request.SearchQuery)));
}
var result = new List<per_employee>();
......@@ -446,31 +450,23 @@ public IEnumerable<DeptdicResponse> GetDepartments(int hospitalId)
return result.OrderBy(w => w.IsVerify).ThenByDescending(t => t.CreateTime).ThenBy(t => t.Department);
}
private (string dept, string[] unittype) GetDeptByUser(int userId)
{
var user = perforUserRepository.GetEntity(t => t.ID == userId && t.IsDelete == 1);
if (user == null) throw new PerformanceException("用户信息错误");
//private (string dept, string[] unittype) GetDeptByUser(int userId)
//{
// var user = perforUserRepository.GetEntity(t => t.ID == userId && t.IsDelete == 1);
// if (user == null) throw new PerformanceException("用户信息错误");
var userrole = perforUserroleRepository.GetEntity(t => t.UserID == user.ID);
var role = perforRoleRepository.GetEntity(t => t.ID == userrole.RoleID);
// var userrole = perforUserroleRepository.GetEntity(t => t.UserID == user.ID);
// var role = perforRoleRepository.GetEntity(t => t.ID == userrole.RoleID);
if (role == null) return ("", new string[] { });
Dictionary<int, string[]> dict = new Dictionary<int, string[]>
{
{ application.DirectorRole, new string[]{ UnitType.医生组.ToString(), UnitType.其他医生组.ToString(), UnitType.医技组.ToString(), UnitType.其他医技组.ToString() } },
{ application.NurseRole, new string[]{ UnitType.护理组.ToString() } },
{ application.SpecialRole, new string[]{ UnitType.特殊核算组.ToString() } },
{ application.OfficeRole, new string[]{ UnitType.行政后勤.ToString(), "行政工勤" } },
};
// if (role == null) return ("", new string[] { });
if (dict.Keys.Contains(role.Type.Value))
{
return (user.Department, dict[role.Type.Value]);
}
// if (UnitTypeUtil.Maps.ContainsKey(role.Type.Value))
// {
// return (user.Department, UnitTypeUtil.Maps[role.Type.Value]);
// }
return ("", new string[] { });
}
// return ("", new string[] { });
//}
private Deptdic GetDeptdic(per_dept_dic dic)
{
......@@ -636,7 +632,8 @@ public List<TitleValue> DeptDics(int hospitalId, int type)
/// <returns></returns>
public object DeptWorkloadDetail(WorkDetailRequest request, int userId)
{
string[] unitTypes = GetUnitType(userId);
var center = perforUserRepository.GetUser(userId);
string[] unitTypes = UnitTypeUtil.Maps[center?.URole.Type ?? 0];
if (unitTypes == null || !unitTypes.Any()) return new string[] { };
var allot = perallotRepository.GetEntity(w => w.ID == request.AllotId);
......@@ -667,7 +664,8 @@ public object DeptWorkloadDetail(WorkDetailRequest request, int userId)
/// <returns></returns>
public object DeptIncomeDetail(WorkDetailRequest request, int userId)
{
string[] unitTypes = GetUnitType(userId);
var center = perforUserRepository.GetUser(userId);
string[] unitTypes = UnitTypeUtil.Maps[center?.URole.Type ?? 0];
if (unitTypes == null || !unitTypes.Any()) return new string[] { };
var allot = perallotRepository.GetEntity(w => w.ID == request.AllotId);
......@@ -694,27 +692,6 @@ public object DeptIncomeDetail(WorkDetailRequest request, int userId)
return new string[] { };
}
private string[] GetUnitType(int userId)
{
Dictionary<int, string[]> dict = new Dictionary<int, string[]>
{
{ application.DirectorRole, new string []{ UnitType.医生组.ToString(), UnitType.其他医生组.ToString(), UnitType.其他医技组.ToString(), UnitType.医技组.ToString() } },
{ application.NurseRole, new string []{ UnitType.护理组.ToString(), UnitType.其他护理组.ToString() } },
{ application.SpecialRole, new string []{ UnitType.特殊核算组.ToString() } },
{ application.OfficeRole, new string []{ UnitType.行政后勤.ToString() } },
};
var user = perforUserRepository.GetEntity(t => t.ID == userId);
if (user == null)
throw new NotImplementedException("人员ID无效");
var userrole = perforUserroleRepository.GetEntity(t => t.UserID == userId);
var role = perforRoleRepository.GetEntity(t => t.ID == userrole.RoleID);
if (!role.Type.HasValue || !dict.ContainsKey(role.Type.Value))
return new string[] { };
return dict[role.Type.Value];
}
public HandsonTable GetBatchPersonStructrue(int hospitalId)
{
......
......@@ -65,7 +65,8 @@ public List<SelectionOptions> GetReportSelection(int groupId, int userId, int ho
if (selections == null)
return options;
var isMedical = IsMedical(userId);
var userInfo = userRepository.GetUser(userId);
var isMedical = (userInfo != null && userInfo.URole.Type.HasValue && UnitTypeUtil.Maps.ContainsKey(userInfo.URole.Type.Value));
var dispaly = new int[] { (int)SelectionState.UsableAndNotDispaly, (int)SelectionState.NotUsableAndNotDispaly };
foreach (var item in selections.Where(t => t.State.HasValue && !dispaly.Contains(t.State.Value)))
......@@ -136,8 +137,9 @@ public List<ReportData> GetReportData(int hospitalId, int groupId, int reportId,
var selections = selectionRepository.GetEntities(w => arr2.Contains(w.ID) && w.State.HasValue && dispaly.Contains(w.State.Value))
?? new List<rep_selection>();
var isMedical = IsMedical(userId);
var department = GetUserDepartment(userId);
var userInfo = userRepository.GetUser(userId);
var isMedical = (userInfo != null && userInfo.URole.Type.HasValue && UnitTypeUtil.Maps.ContainsKey(userInfo.URole.Type.Value));
var department = userInfo?.User.Department ?? "";
List<ReportData> result = new List<ReportData>();
foreach (var report in reports)
......@@ -358,16 +360,6 @@ private string ReplacePlaceholder(List<rep_selection> selections, List<Selection
return content;
}
private bool IsMedical(int userId)
{
var userrole = userroleRepository.GetEntity(t => t.UserID == userId);
var role = roleRepository.GetEntity(t => t.ID == userrole.RoleID);
var roleTypes = new[] { application.NurseRole, application.DirectorRole, application.SpecialRole, application.OfficeRole };
if (role.Type.HasValue && roleTypes.Contains(role.Type.Value))
return true;
else
return false;
}
private string GetUserDepartment(int userId)
{
......
......@@ -739,7 +739,7 @@ public List<ag_othersource> GetOtherTempDetails(int userId, int secondId, int is
var role = _userService.GetUserFirstRole(userId);
//行政科室 只有两种逻辑,或从保存中加载,或加载EXCEL表
if (role?.Type == _application.OfficeRole)
if (role?.Type == (int)Role.行政科室)
{
// 如果已经保存>>走保存加载逻辑
if (employeeSource == (int)EmployeeSource.Initial)
......
......@@ -128,32 +128,35 @@ ComputeService computeService
/// <returns></returns>
public List<SecondListResponse> GetSecondList(int userId)
{
var user = userRepository.GetEntity(t => t.ID == userId);
if (user == null)
throw new NotImplementedException("人员ID无效");
var userrole = userroleRepository.GetEntity(t => t.UserID == userId);
var role = roleRepository.GetEntity(t => t.ID == userrole.RoleID);
var userhospital = userhospitalRepository.GetEntity(t => t.UserID == userId);
if (userhospital == null)
throw new NotImplementedException("人员未选择医院");
var allotList = perallotRepository.GetEntities(t => t.HospitalId == userhospital.HospitalID && new List<int> { 6, 8, 10 }.Contains(t.States));
if (allotList == null || allotList.Count == 0)
return new List<SecondListResponse>();
var userInfo = userRepository.GetUser(userId);
if (userInfo?.User == null) throw new NotImplementedException("当前用户不存在");
if (userInfo?.URole == null) throw new NotImplementedException("当前用户暂未分配角色");
if (userInfo?.Hospitals == null) throw new NotImplementedException("当前用户暂未分配医院");
var status = new List<int> { (int)AllotStates.绩效下发, (int)AllotStates.归档, (int)AllotStates.绩效结果解析成功 };
var allotList = perallotRepository.GetEntities(t => userInfo.HospitalIds.Contains(t.HospitalId) && status.Contains(t.States));
if (allotList == null || allotList.Count == 0) return new List<SecondListResponse>();
var allotListId = allotList.Select(t => t.ID).ToList();
Expression<Func<ag_secondallot, bool>> exp = t => allotListId.Contains(t.AllotId.Value) && t.Department == user.Department;
if (role.Type == application.DirectorRole)
exp = exp.And(t => new List<string> { UnitType.医生组.ToString(), UnitType.其他医生组.ToString(), UnitType.其他医技组.ToString(), UnitType.医技组.ToString() }.Contains(t.UnitType));
else if (role.Type == application.NurseRole)
exp = exp.And(t => t.UnitType == UnitType.护理组.ToString() || t.UnitType == UnitType.其他护理组.ToString());
else if (role.Type == application.SpecialRole)
exp = exp.And(t => t.UnitType == UnitType.特殊核算组.ToString());
else if (role.Type == application.OfficeRole)
exp = exp.And(t => t.UnitType == UnitType.行政后勤.ToString());
var secondList = agsecondallotRepository.GetEntities(exp);
// 查询当前角色下科室的绩效
UnitTypeUtil.Maps.TryGetValue(userInfo?.URole.Type ?? 0, out string[] unitType);
var secondList = agsecondallotRepository.GetEntities(t => allotListId.Contains(t.AllotId.Value) && unitType.Contains(t.UnitType) && t.Department == userInfo.User.Department);
// 查询过往科室的绩效
foreach (var item in userInfo.Historys)
{
UnitTypeUtil.Maps.TryGetValue(item.RoleType ?? 0, out string[] histroyUnitType);
var histroys = agsecondallotRepository.GetEntities(t => allotListId.Contains(t.AllotId.Value) && histroyUnitType.Contains(t.UnitType) && t.Department == item.Department);
if (histroys != null && histroys.Any())
secondList.AddRange(histroys.ToArray());
}
var list = _mapper.Map<List<SecondListResponse>>(secondList);
var hospital = hospitalRepository.GetEntity(t => t.ID == userhospital.HospitalID);
// 二次分配只支持单医院
var hospital = userInfo.Hospitals.First();
list?.ForEach(t =>
{
var allot = allotList.FirstOrDefault(a => a.ID == t.AllotId);
......@@ -169,17 +172,17 @@ public List<SecondListResponse> GetSecondList(int userId)
if (secondList != null && secondList.Any())
{
// 暂时在加载列表时补充信息
var worktypes = agworkloadtypeRepository.GetEntities(t => t.HospitalId == userhospital.HospitalID && t.Department == secondList.First().Department && t.UnitType == secondList.First().UnitType);
var worktypes = agworkloadtypeRepository.GetEntities(t => t.HospitalId == hospital.ID && t.Department == secondList.First().Department && t.UnitType == secondList.First().UnitType);
if (worktypes != null && worktypes.Any())
{
worktypes.ForEach(t => AddWorkTypeDefaultValues(t));
}
// 补充默认工作量项
CheckDefaultWorkload(userhospital.HospitalID ?? 0, secondList.First().Department, secondList.First().UnitType);
CheckDefaultWorkload(hospital.ID, secondList.First().Department, secondList.First().UnitType);
}
return list;
return list.OrderByDescending(w => w.Year).ThenByDescending(w => w.Month).ToList();
}
#region 二次绩效详情
......@@ -862,20 +865,11 @@ public List<SecondTempResponse> GetTemp(int hospitalid, string department, int u
var temps = agtempRepository.GetEntities(t => t.IsEnable == 1);
if (temps != null && temps.Any())
{
var userrole = userroleRepository.GetEntity(t => t.UserID == userId);
var role = roleRepository.GetEntity(t => t.ID == userrole.RoleID);
Dictionary<int, string[]> dic = new Dictionary<int, string[]>
{
{ application.DirectorRole, new[]{ UnitType.医生组.ToString(), UnitType.其他医生组.ToString(), UnitType.医技组.ToString(), UnitType.其他医技组.ToString() } },
{ application.NurseRole, new[]{ UnitType.护理组.ToString(), UnitType.其他护理组.ToString()} },
{ application.SpecialRole, new[]{ UnitType.特殊核算组.ToString() }},
{ application.OfficeRole, new[]{ UnitType.行政后勤.ToString() } },
};
var userCenter = userRepository.GetUser(userId);
Expression<Func<ag_usetemp, bool>> exp = t => t.HospitalId == hospitalid && t.Department == department;
if (role.Type.HasValue && dic.ContainsKey(role.Type.Value))
exp = exp.And(t => dic[role.Type.Value].Contains(t.UnitType));
if (userCenter?.URole != null && userCenter.URole.Type.HasValue)
exp = exp.And(t => UnitTypeUtil.Maps[userCenter.URole.Type.Value].Contains(t.UnitType));
var useTemp = agusetempRepository.GetEntity(exp);
var secondTemps = _mapper.Map<List<SecondTempResponse>>(temps);
......@@ -1586,20 +1580,11 @@ public bool AuditSubmit(ag_secondallot second, int userId)
if (allot == null)
throw new PerformanceException("二次绩效无效!");
var userrole = userroleRepository.GetEntity(t => t.UserID == userId);
var role = roleRepository.GetEntity(t => t.ID == userrole.RoleID);
Dictionary<int, string[]> dic = new Dictionary<int, string[]>
{
{ application.DirectorRole, new[]{ UnitType.医生组.ToString(), UnitType.其他医生组.ToString(), UnitType.医技组.ToString(), UnitType.其他医技组.ToString() } },
{ application.NurseRole, new[]{ UnitType.护理组.ToString(), UnitType.其他护理组.ToString()} },
{ application.SpecialRole, new[]{ UnitType.特殊核算组.ToString() }},
{ application.OfficeRole, new[]{ UnitType.行政后勤.ToString() } },
};
var userCenter = userRepository.GetUser(userId);
Expression<Func<ag_usetemp, bool>> exp = t => t.HospitalId == allot.HospitalId && t.Department == second.Department;
if (role.Type.HasValue && dic.ContainsKey(role.Type.Value))
exp = exp.And(t => dic[role.Type.Value].Contains(t.UnitType));
if (userCenter?.URole != null && userCenter.URole.Type.HasValue)
exp = exp.And(t => UnitTypeUtil.Maps[userCenter.URole.Type.Value].Contains(t.UnitType));
var temp = agusetempRepository.GetEntity(exp);
if (temp == null)
......@@ -2433,9 +2418,9 @@ public dynamic Print(int secondId)
public List<DeptDataDetails> DeptComputeDetailList(int userId, int allotId, out int isShowManage)
{
var user = userRepository.GetEntity(t => t.ID == userId);
if (user == null)
throw new NotImplementedException("人员ID无效");
var userCenter = userRepository.GetUser(userId);
if (userCenter?.User == null) throw new NotImplementedException("当前用户不存在");
var deptDatas = new List<DeptDataDetails>();
var allot = perallotRepository.GetEntity(t => t.ID == allotId);
......@@ -2446,19 +2431,18 @@ public List<DeptDataDetails> DeptComputeDetailList(int userId, int allotId, out
if (!status.Contains(allot.States)) return deptDatas;
var userrole = userroleRepository.GetEntity(t => t.UserID == userId);
var role = roleRepository.GetEntity(t => t.ID == userrole.RoleID);
Dictionary<int, List<string>> dict = new Dictionary<int, List<string>>
{
{ application.DirectorRole, new List<string>{ AccountUnitType.科主任.ToString()} },
{ application.NurseRole, new List<string>{ AccountUnitType.护士长.ToString() } },
{ application.OfficeRole, new List<string> { AccountUnitType.行政中层.ToString() } },
{ application.SpecialRole, new List<string> { AccountUnitType.科主任.ToString() , AccountUnitType.护士长.ToString() } },
{ (int)Role.科主任, new List<string>{ AccountUnitType.科主任.ToString()} },
{ (int)Role.护士长, new List<string>{ AccountUnitType.护士长.ToString() } },
{ (int)Role.行政科室, new List<string> { AccountUnitType.行政中层.ToString() } },
{ (int)Role.特殊科室, new List<string> { AccountUnitType.科主任.ToString() , AccountUnitType.护士长.ToString() } },
};
if (!dict.Keys.Contains(role.Type.Value)) return new List<DeptDataDetails>();
if (!dict.Keys.Contains(userCenter?.URole.Type ?? 0)) return new List<DeptDataDetails>();
var computes = rescomputeRepository.GetEntities(t => t.AllotID == allotId && t.AccountingUnit == user.Department && dict[role.Type.Value].Contains(t.AccountType));
var computes = rescomputeRepository.GetEntities(t => t.AllotID == allotId && t.AccountingUnit == userCenter.User.Department && dict[userCenter.URole.Type.Value].Contains(t.AccountType));
if (computes == null || !computes.Any()) return new List<DeptDataDetails>();
foreach (var item in computes)
{
......
......@@ -9,6 +9,25 @@ namespace Performance.Services
public class UnitTypeUtil
{
public static string[] Office = new string[] { "行政后勤", "行政工勤" };
/// <summary>
/// 数据收集角色(可查看所有)
/// </summary>
public static int[] CollectRoles { get; } = new int[] { (int)Role.绩效管理员, (int)Role.医院管理员, (int)Role.绩效核算办, (int)Role.院领导, (int)Role.财务科, (int)Role.人事科 };
/// <summary>
/// 二次分配角色映射表
/// </summary>
public static Dictionary<int, string[]> Maps { get; } = new Dictionary<int, string[]>
{
{ (int)Role.科主任, new string[]{ UnitType.医生组.ToString(), UnitType.其他医生组.ToString(), UnitType.医技组.ToString(), UnitType.其他医技组.ToString() } },
{ (int)Role.护士长, new string[]{ UnitType.护理组.ToString(), } },
{ (int)Role.特殊科室, new string[]{ UnitType.特殊核算组.ToString(), } },
{ (int)Role.行政科室, new string[]{ UnitType.行政后勤.ToString(), "行政工勤" } },
};
public class RoleUnitMap
{
public Role Role { get; set; }
public string[] UnitType { get; set; }
}
/// <summary>
/// 是否是行政后勤/工勤
......@@ -74,5 +93,6 @@ public static string Recognition(string name, AccountUnitType defaultValue)
return defaultValue.ToString();
}
}
}
......@@ -21,6 +21,7 @@ public class UserService : IAutoInjection
private readonly IMapper _mapper;
private PerforSmsRepository _smsRepository;
private PerforHospitalRepository _hospitalRepository;
private readonly PerforUserhistoryRepository _userhistoryRepository;
private PerforUserhospitalRepository _userhospitalRepository;
private PerforRoleRepository _roleRepository;
private PerforUserroleRepository _userroleRepository;
......@@ -39,6 +40,7 @@ public class UserService : IAutoInjection
PerforSmsRepository smsRepository,
PerforUserRepository userRepository,
PerforHospitalRepository hospitalRepository,
PerforUserhistoryRepository userhistoryRepository,
PerforUserhospitalRepository userhospitalRepository,
PerforRoleRepository roleRepository,
PerforUserroleRepository userroleRepository,
......@@ -52,20 +54,21 @@ public class UserService : IAutoInjection
PerforCofaccountingRepository perforCofaccountingRepository)
{
this.application = application.Value;
this._userRepository = userRepository;
_userRepository = userRepository;
_mapper = mapper;
this._smsRepository = smsRepository;
this._hospitalRepository = hospitalRepository;
this._userhospitalRepository = userhospitalRepository;
this._roleRepository = roleRepository;
this._userroleRepository = userroleRepository;
this._employeeRepository = employeeRepository;
this._perforPerallotRepository = perforPerallotRepository;
this._imaccountbasicRepository = imaccountbasicRepository;
this._imspecialunitRepository = imspecialunitRepository;
this._resaccountRepository = resaccountRepository;
this._perallotRepository = perallotRepository;
this._perdeptdicRepository = perdeptdicRepository;
_smsRepository = smsRepository;
_hospitalRepository = hospitalRepository;
_userhistoryRepository = userhistoryRepository;
_userhospitalRepository = userhospitalRepository;
_roleRepository = roleRepository;
_userroleRepository = userroleRepository;
_employeeRepository = employeeRepository;
_perforPerallotRepository = perforPerallotRepository;
_imaccountbasicRepository = imaccountbasicRepository;
_imspecialunitRepository = imspecialunitRepository;
_resaccountRepository = resaccountRepository;
_perallotRepository = perallotRepository;
_perdeptdicRepository = perdeptdicRepository;
this.perforCofaccountingRepository = perforCofaccountingRepository;
}
......@@ -148,34 +151,24 @@ public List<int> GetUserHospital(int userId)
/// <returns></returns>
public List<UserResponse> GetUserList(int userID, int roleType = 1)
{
var userConter = _userRepository.GetUser(userID);
if (userConter?.User == null) throw new PerformanceException("当前用户信息无效");
if (userConter?.URole == null) throw new PerformanceException("当前用户角色无效");
var roleTypes = (roleType == (int)Role.绩效查询)
? EnumHelper.GetItems<Role>().Where(w => w.Value == (int)Role.绩效查询).Select(w => w.Value).ToArray()
: EnumHelper.GetItems<Role>().Where(w => w.Value != (int)Role.绩效查询).Select(w => w.Value).ToArray();
var users = _userRepository.GetUsersByRoleType(roleTypes);
var userRoles = _userroleRepository.GetEntities();
var userHospitals = _userhospitalRepository.GetEntities();
var users = _userRepository.GetEntities();
var hospitals = _hospitalRepository.GetEntities();
var roles = _roleRepository.GetEntities();
var userrole = userRoles?.FirstOrDefault(t => t.UserID == userID);
if (roleType == 12)
{
var jxQuery = userRoles.Where(t => t.RoleID == roles?.FirstOrDefault(c => c.RoleName == "绩效查询")?.ID).Select(t => t.UserID);
users = users.Where(t => jxQuery.Contains(t.ID)).ToList();
}
else
{
var jxQuery = userRoles.Where(t => roles.Where(c => c.RoleName != "绩效查询").Select(c => c.ID).Contains(t.RoleID)).Select(t => t.UserID);
users = users.Where(t => jxQuery.Contains(t.ID)).ToList();
}
if (userrole == null)
throw new PerformanceException("用户未配置角色");
var role = roles?.FirstOrDefault(t => t.ID == userrole.RoleID);
if (role == null)
throw new PerformanceException("用户角色不存在");
var result = new List<UserResponse>();
if (role.IsViewAllUsers == 2)
if (userConter?.URole.IsViewAllUsers == 2)
{
var userlist = users?.Where(t => t.CreateUser == userID && t.IsDelete == 1 && (t.ParentID == 0 || t.ParentID == null));
var sonUser = users?.Where(t => t.ParentID != 0 && t.ParentID != null);
......@@ -247,56 +240,56 @@ public List<UserResponse> GetUserList(int userID, int roleType = 1)
return result;
}
/// <summary>
/// 删除
/// </summary>
/// <param name="iD"></param>
/// <returns></returns>
public ApiResponse Delete(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);
return result ? new ApiResponse(ResponseType.OK) : new ApiResponse(ResponseType.Fail);
}
/// <summary>
/// 新增用户
/// </summary>
/// <param name="request"></param>
public UserResponse Insert(UserRequest request, int userid)
{
if (null != _userRepository.GetEntity(t => t.Login == request.Login && t.IsDelete == 1))
throw new PerformanceException("登录名重复");
//if (null != _userRepository.GetEntity(t => t.Mobile == request.Mobile && t.IsDelete == 1))
// throw new PerformanceException("手机号重复");
//if (request.Role == 3 && string.IsNullOrEmpty(request.Department))
// 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.Contains(request.Role) && 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 = request.Department;
user.IsDelete = 1;
if (!_userRepository.Add(user))
throw new PerformanceException("保存失败");
//添加用户角色关联关系
_userroleRepository.Add(new sys_user_role { UserID = user.ID, RoleID = request.Role });
//添加用户医院
SetHospital(user.ID, request.HosIDArray);
return _mapper.Map<UserResponse>(user);
}
///// <summary>
///// 删除
///// </summary>
///// <param name="iD"></param>
///// <returns></returns>
//public ApiResponse Delete(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);
// return result ? new ApiResponse(ResponseType.OK) : new ApiResponse(ResponseType.Fail);
//}
///// <summary>
///// 新增用户
///// </summary>
///// <param name="request"></param>
//public UserResponse Insert(UserRequest request, int userid)
//{
// if (null != _userRepository.GetEntity(t => t.Login == request.Login && t.IsDelete == 1))
// throw new PerformanceException("登录名重复");
// //if (null != _userRepository.GetEntity(t => t.Mobile == request.Mobile && t.IsDelete == 1))
// // throw new PerformanceException("手机号重复");
// //if (request.Role == 3 && string.IsNullOrEmpty(request.Department))
// // 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.Contains(request.Role) && 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 = request.Department;
// user.IsDelete = 1;
// if (!_userRepository.Add(user))
// throw new PerformanceException("保存失败");
// //添加用户角色关联关系
// _userroleRepository.Add(new sys_user_role { UserID = user.ID, RoleID = request.Role });
// //添加用户医院
// SetHospital(user.ID, request.HosIDArray);
// return _mapper.Map<UserResponse>(user);
//}
/// <summary>
/// 设置用户医院
......@@ -330,53 +323,59 @@ public bool SetHospital(int userId, int[] hosIDArray)
return rmResult && addResult;
}
/// <summary>
/// 修改用户
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public UserResponse Update(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}");
///// <summary>
///// 修改用户
///// </summary>
///// <param name="request"></param>
///// <returns></returns>
//public UserResponse Update(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("登录名重复");
// 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("登录名重复");
//vlist = _userRepository.GetEntities(t => t.ID != user.ID && t.Mobile == request.Mobile && t.IsDelete == 1);
//if (null != vlist && vlist.Count() > 0)
// throw new PerformanceException("手机号重复");
// var userRole = _userroleRepository.GetEntity(t => t.UserID == request.ID);
if (isAgainAdmin && string.IsNullOrEmpty(request.Department))
throw new PerformanceException("二次绩效管理员科室不能为空");
// //vlist = _userRepository.GetEntities(t => t.ID != user.ID && t.Mobile == request.Mobile && t.IsDelete == 1);
// //if (null != vlist && vlist.Count() > 0)
// // throw new PerformanceException("手机号重复");
if (isAgainAdmin && request.HosIDArray.Length > 1)
throw new PerformanceException("二次绩效管理员只支持单家医院");
// if (isAgainAdmin && string.IsNullOrEmpty(request.Department))
// throw new PerformanceException("二次绩效管理员科室不能为空");
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 = request.Department;
// if (isAgainAdmin && request.HosIDArray.Length > 1)
// throw new PerformanceException("二次绩效管理员只支持单家医院");
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(user.ID, request.HosIDArray);
// SaveHistoryDepartment(user.ID, newRoleId: request.Role, newDepartment: request.Department);
// 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 = request.Department;
// if (!_userRepository.Update(user))
// throw new PerformanceException("保存失败");
// //删除用户角色关联关系
// if (null != userRole)
// _userroleRepository.Remove(userRole);
// //添加用户角色关联关系
// _userroleRepository.Add(new sys_user_role { UserID = request.ID, RoleID = request.Role });
// //添加用户医院
// SetHospital(user.ID, request.HosIDArray);
// return _mapper.Map<UserResponse>(user);
//}
return _mapper.Map<UserResponse>(user);
}
/// <summary>
/// 修改个人信息
......@@ -584,7 +583,7 @@ public UserResponse InsertUser(UserRequest request, int userid)
if (null != _userRepository.GetEntity(t => t.Login == request.Login && t.IsDelete == 1))
throw new PerformanceException("登录名重复");
int[] roleArray = new int[] { application.NurseRole, application.DirectorRole, application.SpecialRole, application.OfficeRole };
int[] roleArray = UnitTypeUtil.Maps.Keys.ToArray();
if (roleArray.Intersect(request.RoleArr).Any() && string.IsNullOrEmpty(request.Department))
throw new PerformanceException("二次绩效管理员科室不能为空");
......@@ -625,27 +624,37 @@ public UserResponse InsertUser(UserRequest request, int userid)
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public UserResponse UpdateUser(UserRequest request, bool isAgainAdmin)
public UserResponse UpdateUser(UserRequest request, int userId)
{
var roleIds = request.RoleArr != null && request.RoleArr.Length > 0 ? request.RoleArr.Distinct().ToArray() : new int[0];
if (roleIds.Length == 0)
throw new PerformanceException("请选择用户角色");
var isAgainAdmin = request.RoleArr.Any(w => UnitTypeUtil.Maps.ContainsKey(w));
if (isAgainAdmin && string.IsNullOrEmpty(request?.Department))
throw new PerformanceException("二次绩效管理员科室不能为空");
var user = _userRepository.GetEntity(t => t.ID == request.ID && t.IsDelete == 1);
if (null == user)
throw new PerformanceException($"用户不存在 UserId:{request.ID}");
if (null == user) throw new PerformanceException($"当前用户不存在");
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 (null != vlist && vlist.Count() > 0) throw new PerformanceException("登录名重复");
if (isAgainAdmin && string.IsNullOrEmpty(request.Department))
throw new PerformanceException("二次绩效管理员科室不能为空");
// 只有单角色账号并且是二次分配的科室 才会记录历史科室
if (roleIds.Length == 1 && UnitTypeUtil.Maps.ContainsKey(roleIds[0]))
{
_userRepository.SaveHistoryDepartment(user.ID, request.RoleArr[0], request.Department);
}
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 : "";
user.Department = UnitTypeUtil.Maps.ContainsKey(request.RoleArr[0]) ? request.Department : "";
if (!_userRepository.Update(user))
throw new PerformanceException("保存失败");
......@@ -653,6 +662,7 @@ public UserResponse UpdateUser(UserRequest request, bool isAgainAdmin)
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] });
//添加用户医院
......@@ -687,7 +697,7 @@ public UserResponse UpdateUser(UserRequest request, bool isAgainAdmin)
diffUser.Mail = request.Mail;
diffUser.States = request.States;
diffUser.Password = string.IsNullOrEmpty(request.Password) ? user.Password : request.Password;
diffUser.Department = roleArray.Contains(request.RoleArr[i]) ? request.Department : "";
diffUser.Department = UnitTypeUtil.Maps.ContainsKey(request.RoleArr[i]) ? request.Department : "";
if (!_userRepository.Add(diffUser))
throw new PerformanceException("保存失败");
//添加子用户角色关联关系
......@@ -723,24 +733,24 @@ public ApiResponse DeleteUser(int iD)
#endregion
public HandsonTable GetUserHandsFlat()
public HandsonTableBase GetUserHandsFlat()
{
var result = new HandsonTable((int)SheetType.Unidentifiable, Users.Select(t => t.Value).ToArray(), Users.Select(t => new collect_permission
HandsonTableBase table = new HandsonTableBase()
{
HeadName = t.Value,
Visible = 1
}).ToList());
if (result.Columns != null && result.Columns.Any())
Columns = Users.Select(t => new HandsonColumn(t.Value)).ToList(),
ColHeaders = Users.Select(t => t.Value).ToList(),
};
if (table.Columns != null && table.Columns.Any())
{
foreach (var column in result.Columns)
foreach (var column in table.Columns)
{
if (column.Data == "角色")
if (Users.Any(w => w.Key == nameof(sys_role.RoleName)) && Users.First(w => w.Key == nameof(sys_role.RoleName)).Value == column.Data)
{
column.Type = "autocomplete";
column.Source = _roleRepository.GetEntities().Select(t => t.RoleName).ToArray();
column.Strict = true;
}
else if (column.Data == "分配医院")
if (Users.Any(w => w.Key == nameof(sys_hospital.HosName)) && Users.First(w => w.Key == nameof(sys_hospital.HosName)).Value == column.Data)
{
column.Type = "autocomplete";
column.Source = _hospitalRepository.GetEntities().Select(t => t.HosName).ToArray();
......@@ -748,7 +758,7 @@ public HandsonTable GetUserHandsFlat()
}
}
}
return result;
return table;
}
/// <summary>
......@@ -756,7 +766,7 @@ public HandsonTable GetUserHandsFlat()
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public string SaveUserHandsFlat(UserCollectData request)
public ApiResponse SaveUserHandsFlat(UserCollectData request)
{
try
{
......@@ -769,35 +779,81 @@ public string SaveUserHandsFlat(UserCollectData request)
List<sys_user> users = new List<sys_user>();
List<sys_user_role> userRoles = new List<sys_user_role>();
List<sys_user_hospital> userHoss = new List<sys_user_hospital>();
var roleArr = new[] { "护士长", "科主任", "特殊科室", "行政科室" };
var allDataList = dicData.Select(item => JsonHelper.Deserialize<UserHandsResponse>(JsonHelper.Serialize(item)));
var names = allDataList?.Select(w => w?.HosName).Distinct();
var roleArr = new string[] { Role.护士长.ToString(), Role.科主任.ToString(), Role.特殊科室.ToString(), Role.行政科室.ToString() };
var allDataList = dicData.Select(item => JsonHelper.Deserialize<UserHandsResponse>(JsonHelper.Serialize(item))).ToList();
Dictionary<string, List<string>> res = new Dictionary<string, List<string>>();
foreach (var item in names)
List<Dictionary<string, string>> error = new List<Dictionary<string, string>>();
for (int i = 0; i < allDataList.Count(); i++)
{
if (string.IsNullOrEmpty(item)) return "必填项为空";
var HospitalId = hospitals.FirstOrDefault(w => w.HosName == item)?.ID;
// 姓名、登录名、角色、分配医院
if (string.IsNullOrEmpty(allDataList[i].Login?.Trim())
|| string.IsNullOrEmpty(allDataList[i].RealName?.Trim())
|| string.IsNullOrEmpty(allDataList[i].RoleName?.Trim())
|| string.IsNullOrEmpty(allDataList[i].HosName?.Trim())
|| string.IsNullOrEmpty(allDataList[i].Department?.Trim()))
{
if (HospitalId == null) return "未找到分配医院";
error.Add(new Dictionary<string, string>
{
{ "行号", $"第{i+1}行" },
{ "姓名", allDataList[i].Login ?? "" },
{ "登录名", allDataList[i].RealName ?? "" },
{ "角色", allDataList[i].RoleName ?? "" },
{ "分配医院", allDataList[i].HosName ?? "" },
{ "核算单元", allDataList[i].Department.ToString() ?? "" },
{ "错误原因", "“关键信息缺失”请补全或删除" },
});
}
else if (!hospitals.Any(w => w.HosName == (allDataList[i].HosName?.Trim())))
{
error.Add(new Dictionary<string, string>
{
{ "行号", $"第{i+1}行" },
{ "姓名", allDataList[i].Login ?? "" },
{ "登录名", allDataList[i].RealName ?? "" },
{ "角色", allDataList[i].RoleName ?? "" },
{ "分配医院", allDataList[i].HosName ?? "" },
{ "核算单元", allDataList[i].Department.ToString() ?? "" },
{ "错误原因", "“分配医院”错误,请修改或删除" },
});
}
else if (roleArr.Contains(allDataList[i].RoleName?.Trim()) && !accounts.Any(w => w.AccountingUnit == allDataList[i].Department?.Trim()))
{
error.Add(new Dictionary<string, string>
{
{ "行号", $"第{i+1}行" },
{ "姓名", allDataList[i].Login ?? "" },
{ "登录名", allDataList[i].RealName ?? "" },
{ "角色", allDataList[i].RoleName ?? "" },
{ "分配医院", allDataList[i].HosName ?? "" },
{ "核算单元", allDataList[i].Department ?? "" },
{ "错误原因", "“核算单元”错误,请修改或删除" },
});
}
var allot = _perallotRepository.GetEntities(t => t.HospitalId == HospitalId);
var accountingUnits = accounts?.Join(allot, t => t.AllotId, w => w.ID, (t, w) => t.AccountingUnit).Distinct().ToList();
res.Add(item, accountingUnits);
else if (getUsers.Any(c => c.Login == allDataList[i].Login?.Trim()))
{
error.Add(new Dictionary<string, string>
{
{ "行号", $"第{i+1}行" },
{ "姓名", allDataList[i].Login ?? "" },
{ "登录名", allDataList[i].RealName ?? "" },
{ "角色", allDataList[i].RoleName ?? "" },
{ "分配医院", allDataList[i].HosName ?? "" },
{ "核算单元", allDataList[i].Department ?? "" },
{ "错误原因", "“登录名”已存在,请修改或删除" },
});
}
}
if (error.Count > 0)
return new ApiResponse(ResponseType.WarningTable, "验证不通过,当前操作已拒绝", error);
foreach (var data in allDataList)
{
if (string.IsNullOrEmpty(data.Login) || string.IsNullOrEmpty(data.RealName)
|| string.IsNullOrEmpty(data.RoleName) || string.IsNullOrEmpty(data.HosName))
return "必填项为空";
if (roleArr.Contains(data.RoleName) && res != null && res[data.HosName] != null && !res[data.HosName].Any(t => t == data.Department))
return "核算单元填写错误";
if (users.Any(c => c.Login == data?.Login) && !string.IsNullOrEmpty(data.Login)
|| getUsers.Any(c => c.Login == data?.Login)) continue;
if (users.Any(c => c.Login == data?.Login)) continue;
var user = new sys_user
{
......@@ -816,9 +872,9 @@ public string SaveUserHandsFlat(UserCollectData request)
}
_userRepository.AddRange(users.ToArray());
var joinData = users.Join(allDataList,
outer => new { outer.Login, outer.RealName, Department = outer.Department ?? "" },
inner => new { inner.Login, inner.RealName, Department = inner.Department ?? "" },
var joinData = users.Join(allDataList,
outer => new { outer.Login, outer.RealName, Department = outer.Department ?? "" },
inner => new { inner.Login, inner.RealName, Department = inner.Department ?? "" },
(outer, inner) => new { outer, inner });
......@@ -836,7 +892,7 @@ public string SaveUserHandsFlat(UserCollectData request)
});
_userhospitalRepository.AddRange(hosJoin.ToArray());
return "";
return new ApiResponse(ResponseType.OK, "保存成功");
}
catch (Exception)
{
......
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