Commit 00012cc9 by 钟博

修改 用户、人员、科室批量添加bug

parent 731d876e
......@@ -391,22 +391,14 @@ public ApiResponse GetBatchUserStructrue()
/// <returns></returns>
[Route("BatchSaveUser")]
[HttpPost]
public ApiResponse BatchSaveUser([FromBody] UserCollectData data)
public ApiResponse BatchSaveUser([CustomizeValidator(RuleSet = "Insert"), FromBody] UserCollectData data)
{
var result = _userService.SaveUserHandsFlat(data);
switch (result)
{
case 0:
//hack:后续根据accounting更改提示信息
return new ApiResponse(ResponseType.Error, "科室字典为空");
case 1:
return new ApiResponse(ResponseType.OK);
case 2:
return new ApiResponse(ResponseType.Error, "登录名重复");
default:
return new ApiResponse(ResponseType.Error, "核算单元填写错误");
}
if (result == "")
return new ApiResponse(ResponseType.OK);
else
return new ApiResponse(ResponseType.Error, result);
}
}
}
\ No newline at end of file
......@@ -91,7 +91,7 @@ public ApiResponse Success([FromBody] AllotRequest request)
/// <returns></returns>
[Route("insert")]
[HttpPost]
public ApiResponse Insert([CustomizeValidator(RuleSet = "Insert"), FromBody] AllotRequest request)
public ApiResponse Insert([FromBody] AllotRequest request)
{
var userId = _claim.GetUserId();
var result = _allotService.InsertAllot(request, userId);
......
......@@ -622,7 +622,7 @@ public ApiResponse BatchSaveAccounting(int allotId, [FromBody] SaveCollectData r
if (result)
return new ApiResponse(ResponseType.OK);
else
return new ApiResponse(ResponseType.Error, "请选正确的核算组别");
return new ApiResponse(ResponseType.Error, "请选正确的核算组别");
}
......
using System;
using FluentValidation;
using System;
using System.Collections.Generic;
using System.Text;
......@@ -19,4 +20,6 @@ public class UserCollectData
public string[] ColHeaders { get; set; }
public string[][] Data { get; set; }
}
}
......@@ -648,9 +648,9 @@ public List<cof_accounting> GetAccountingList(AccoungingRequest request)
case 1: //返回accounting列表
case 2: //返回核算单元类型
default:
return cofaccountingRepository.GetEntities(t => t.AllotId == request.AllotId);
return cofaccountingRepository.GetEntities(t => t.AllotId == request.AllotId)?.OrderBy(t=>t.AccountingUnit).ThenBy(t=>t.UnitType).ToList();
case 3: //返回核算单元
return cofaccountingRepository.GetEntities(t => t.AllotId == request.AllotId && t.UnitType == request.UnitType);
return cofaccountingRepository.GetEntities(t => t.AllotId == request.AllotId && t.UnitType == request.UnitType)?.OrderBy(t=>t.AccountingUnit).ThenBy(t=>t.UnitType).ToList();
}
}
......@@ -741,12 +741,12 @@ public bool BatchSaveAccounting(int allotId, SaveCollectData request)
var json = JsonHelper.Serialize(item);
var data = JsonHelper.Deserialize<cof_accounting>(json);
if (!unitType.Contains(data.UnitType)) return false;
if (!unitType.Contains(data?.UnitType) && !string.IsNullOrEmpty(data?.UnitType)) return false;
if (getAccounts != null)
if (getAccounts.Any(t => t.AccountingUnit == data?.AccountingUnit && t.UnitType == data.UnitType))continue;
var any = accounts.Any(t => t.AccountingUnit == data?.AccountingUnit && t.UnitType == data.UnitType);
if (getAccounts.Any(t => t.AccountingUnit == data?.AccountingUnit && t.UnitType == data?.UnitType))continue;
var any = accounts.Any(t => t.AccountingUnit == data?.AccountingUnit && t.UnitType == data?.UnitType);
if (!string.IsNullOrEmpty(data?.AccountingUnit) && !string.IsNullOrEmpty(data?.UnitType) && !any)
if (!string.IsNullOrEmpty(data.AccountingUnit) && !string.IsNullOrEmpty(data.UnitType) && !any)
{
accounts.Add(data);
}
......
......@@ -204,6 +204,7 @@ public per_employee CreatePerson(PerEmployeeResponse request)
int day = DateTime.DaysInMonth(allot.Year, allot.Month);
entity.Attendance = request.AttendanceDay / day;
entity.CreateTime = DateTime.Now;
entity.IsVerify = 0;
//CheckAccountingDept(request.HospitalId.Value, request.AccountingUnit, request.Department);
peremployeeRepository.Add(entity);
......@@ -680,16 +681,16 @@ public bool BathSavePerson(int AllotId, int HospitalId, SaveCollectData request)
var persons = peremployeeRepository.GetEntities(t => t.HospitalId == HospitalId && t.AllotId == AllotId);
foreach (var item in dicData)
{
if (!string.IsNullOrEmpty(item["AttendanceDay"]) && !string.IsNullOrEmpty(item["ReservedRatio"]) )
if (!string.IsNullOrEmpty(item["AttendanceDay"]) && !string.IsNullOrEmpty(item["ReservedRatio"]))
{
if ((!Regex.IsMatch(item["AttendanceDay"], "^([12][0-9]|31|[1-9])$")) || (!Regex.IsMatch(item["ReservedRatio"], @"0.\d+")))
if ((!Regex.IsMatch(item["AttendanceDay"], "^([12][0-9]|31|[1-9])$")) || (!Regex.IsMatch(item["ReservedRatio"], @"\b(0(\.\d{1,2})?)|1\b")))
return false;
}
var json = JsonHelper.Serialize(item);
var data = JsonHelper.Deserialize<per_employee>(json);
if(persons!=null)
if (persons.Any(t => t.PersonnelNumber?.Trim() == data.PersonnelNumber?.Trim() && t.DoctorName?.Trim() == data.DoctorName?.Trim())) continue;
if (persons != null)
if (persons.Any(t => t.PersonnelNumber?.Trim() == data.PersonnelNumber?.Trim() && t.DoctorName?.Trim() == data.DoctorName?.Trim())) continue;
var any = employees.Any(w => w.Department?.Trim() == data.Department?.Trim() && w.DoctorName?.Trim() == data.DoctorName?.Trim());
if (!string.IsNullOrEmpty(data.Department?.Trim()) && !string.IsNullOrEmpty(data.AccountingUnit?.Trim()) && !string.IsNullOrEmpty(data.DoctorName?.Trim()) && !any)
......@@ -699,11 +700,12 @@ public bool BathSavePerson(int AllotId, int HospitalId, SaveCollectData request)
data.DoctorName = data.DoctorName?.Trim();
data.PersonnelNumber = data.PersonnelNumber?.Trim();
data.CreateTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd hh:mm:dd"));
data.IsVerify = 0;
employees.Add(data);
}
}
if(employees.Any())
peremployeeRepository.AddRange(employees.ToArray());
if (employees.Any())
peremployeeRepository.AddRange(employees.ToArray());
return true;
}
......@@ -718,18 +720,18 @@ public void SaveDeptDicHands(int HospitalId, SaveCollectData request)
var json = JsonHelper.Serialize(dic);
var data = JsonHelper.Deserialize<DeptdicHands>(json);
if(depts!=null)
if (depts.Any(t => t.Department?.Trim() == data.Department?.Trim() && t.HISDeptName?.Trim() == data.HISDeptName?.Trim())) continue;
var any = deptDics.Any(w => w.Department?.Trim() == data.Department?.Trim() && w.HISDeptName?.Trim() == data.HISDeptName?.Trim());
if (depts != null)
if (depts.Any(t => t.Department?.Trim() == data.Department?.Trim())) continue;
var any = deptDics.Any(w => w.Department?.Trim() == data.Department?.Trim());
if (!string.IsNullOrEmpty(data.Department?.Trim()) && !string.IsNullOrEmpty(data.HISDeptName?.Trim()) && !any)
if (!string.IsNullOrEmpty(data.Department?.Trim()) && !any)
{
DeptDicList(HospitalId, deptDics, data);
}
}
if(deptDics.Any())
perdeptdicRepository.AddRange(deptDics.ToArray());
if (deptDics.Any())
perdeptdicRepository.AddRange(deptDics.ToArray());
}
private void DeptDicList(int HospitalId, List<per_dept_dic> deptDics, DeptdicHands data)
......@@ -737,24 +739,24 @@ private void DeptDicList(int HospitalId, List<per_dept_dic> deptDics, DeptdicHan
var nowTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"));
#region 住院
if (data.InpatDoctorAccounting != "" || data.InpatNurseAccounting != "" || data.InpatTechnicAccounting != "")
if (!string.IsNullOrEmpty(data.InpatDoctorAccounting) || !string.IsNullOrEmpty(data.InpatNurseAccounting) || !string.IsNullOrEmpty(data.InpatTechnicAccounting))
{
if (data.InpatDoctorAccounting != "")
if (!string.IsNullOrEmpty(data.InpatDoctorAccounting))
{
per_dept_dic deptDic = new per_dept_dic() { Source = "住院", HospitalId = HospitalId, Department = data.Department?.Trim(), HISDeptName = data.HISDeptName?.Trim(), CreateTime = nowTime };
deptDic.AccountingUnit = data.InpatDoctorAccounting?.Trim();
deptDic.UnitType = "医生组";
deptDics.Add(deptDic);
}
if (data.InpatNurseAccounting != "")
if (!string.IsNullOrEmpty(data.InpatNurseAccounting))
{
per_dept_dic deptDic = new per_dept_dic() { Source = "住院", HospitalId = HospitalId, Department = data.Department?.Trim(), HISDeptName = data.HISDeptName?.Trim(), CreateTime = nowTime };
deptDic.AccountingUnit = data.InpatNurseAccounting?.Trim();
deptDic.UnitType = "护理组";
deptDics.Add(deptDic);
}
if (data.InpatTechnicAccounting != "")
if (!string.IsNullOrEmpty(data.InpatTechnicAccounting))
{
per_dept_dic deptDic = new per_dept_dic() { Source = "住院", HospitalId = HospitalId, Department = data.Department?.Trim(), HISDeptName = data.HISDeptName?.Trim(), CreateTime = nowTime };
deptDic.AccountingUnit = data.InpatTechnicAccounting?.Trim();
......@@ -767,24 +769,24 @@ private void DeptDicList(int HospitalId, List<per_dept_dic> deptDics, DeptdicHan
#region 门诊
if (data.OutDoctorAccounting != "" || data.OutNurseAccounting != "" || data.OutTechnicAccounting != "")
if (!string.IsNullOrEmpty(data.OutDoctorAccounting) || !string.IsNullOrEmpty(data.OutNurseAccounting) || !string.IsNullOrEmpty(data.OutTechnicAccounting))
{
if (data.OutDoctorAccounting != "")
if (!string.IsNullOrEmpty(data.OutDoctorAccounting))
{
per_dept_dic deptDic = new per_dept_dic() { Source = "门诊", HospitalId = HospitalId, Department = data.Department?.Trim(), HISDeptName = data.HISDeptName?.Trim(), CreateTime = nowTime };
deptDic.AccountingUnit = data.OutDoctorAccounting?.Trim();
deptDic.UnitType = "医生组";
deptDics.Add(deptDic);
}
if (data.OutNurseAccounting != "")
if (!string.IsNullOrEmpty(data.OutNurseAccounting))
{
per_dept_dic deptDic = new per_dept_dic() { Source = "门诊", HospitalId = HospitalId, Department = data.Department?.Trim(), HISDeptName = data.HISDeptName?.Trim(), CreateTime = nowTime };
deptDic.AccountingUnit = data.OutNurseAccounting?.Trim();
deptDic.UnitType = "护理组";
deptDics.Add(deptDic);
}
if (data.OutTechnicAccounting != "")
if (!string.IsNullOrEmpty(data.OutTechnicAccounting))
{
per_dept_dic deptDic = new per_dept_dic() { Source = "门诊", HospitalId = HospitalId, Department = data.Department?.Trim(), HISDeptName = data.HISDeptName?.Trim(), CreateTime = nowTime };
deptDic.AccountingUnit = data.OutTechnicAccounting?.Trim();
......@@ -796,7 +798,7 @@ private void DeptDicList(int HospitalId, List<per_dept_dic> deptDics, DeptdicHan
#endregion
if (data.LogisticsAccounting != "")
if (!string.IsNullOrEmpty(data.LogisticsAccounting))
{
per_dept_dic deptDic = new per_dept_dic()
{
......@@ -810,7 +812,7 @@ private void DeptDicList(int HospitalId, List<per_dept_dic> deptDics, DeptdicHan
deptDics.Add(deptDic);
}
if (data.SpecialAccounting != "")
if (!string.IsNullOrEmpty(data.SpecialAccounting))
{
per_dept_dic deptDic = new per_dept_dic()
{
......
......@@ -727,7 +727,7 @@ public HandsonTable GetUserHandsFlat()
return result;
}
public int SaveUserHandsFlat(UserCollectData request)
public string SaveUserHandsFlat(UserCollectData request)
{
try
{
......@@ -737,58 +737,87 @@ public int SaveUserHandsFlat(UserCollectData request)
var hospitals = _hospitalRepository.GetEntities();
//hack:后续修改为accounting中的数据
var accounts = perforCofaccountingRepository.GetEntities();
var allot = _perallotRepository.GetEntities(t => t.HospitalId == request.HospitalId);
var res=accounts?.Join(allot, t =>t.AllotId, w =>w.ID, (t, w) => new cof_accounting{ AccountingUnit=t.AccountingUnit }).Distinct();
//var allot = _perallotRepository.GetEntities(t => t.HospitalId == request.HospitalId);
//var res = accounts?.Join(allot, t => t.AllotId, w => w.ID, (t, w) => new cof_accounting { AccountingUnit = t.AccountingUnit }).Distinct();
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[] { "护士长", "科主任", "特殊科室", "行政科室" };
foreach (var item in dicData)
var allDataList = dicData.Select(item => JsonHelper.Deserialize<UserHandsResponse>(JsonHelper.Serialize(item)));
var names = allDataList?.Select(w => w?.HosName).Distinct();
Dictionary<string, List<string>> res = new Dictionary<string, List<string>>();
foreach (var item in names)
{
if (item == null) return "必填项为空";
var HospitalId = hospitals.FirstOrDefault(w => w.HosName == item)?.ID;
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);
}
foreach (var data in allDataList)
{
var json = JsonHelper.Serialize(item);
var data = JsonHelper.Deserialize<UserHandsResponse>(json);
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) return "科室字典为空";
if (users.Any(c => c.Login == data?.Login) && !string.IsNullOrEmpty(data.Login)
|| getUsers.Any(c => c.Login == data?.Login)) return "登录名重复";
if (roleArr.Contains(data.RoleName) && res == null) return 0;
if (users.Any(c => c.Login == data?.Login) || getUsers.Any(c => c.Login == data?.Login)) return 2;
if (roleArr.Contains(data.RoleName) && !res.Any(t => t.AccountingUnit == data.Department)) return 3;
if (roleArr.Contains(data.RoleName) && res[data.HosName] != null && !res[data.HosName].Any(t => t == data.Department))
return "核算单元填写错误";
if (!string.IsNullOrEmpty(data.Login) && !string.IsNullOrEmpty(data.RealName) && !string.IsNullOrEmpty(data.HosName))
var user = new sys_user
{
var user = new sys_user
{
RealName = data.RealName,
CreateDate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd hh:mm:dd")),
CreateUser = request.CreateUser,
Department = data?.Department ?? "",
IsDelete = 1,
Login = data.Login,
Password = data?.Password ?? "123456",
States = 1,
Mobile = data?.Mobile ?? "",
Mail = data?.Mail ?? ""
};
users.Add(user);
var userRole = new sys_user_role
{
RoleID = (int)roles.FirstOrDefault(t => t.RoleName == data.RoleName)?.Type,
};
userRoles.Add(userRole);
RealName = data.RealName,
CreateDate = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd hh:mm:dd")),
CreateUser = request.CreateUser,
Department = data?.Department ?? "",
IsDelete = 1,
Login = data.Login,
Password = data?.Password ?? "123456",
States = 1,
Mobile = data?.Mobile ?? "",
Mail = data?.Mail ?? ""
};
users.Add(user);
//var userRole = new sys_user_role
//{
// RoleID = (int)roles.FirstOrDefault(t => t.RoleName == data.RoleName)?.Type,
//};
//userRoles.Add(userRole);
//var userHos = new sys_user_hospital
//{
// HospitalID = hospitals.FirstOrDefault(t => t.HosName == data.HosName)?.ID
//};
//userHoss.Add(userHos);
var userHos = new sys_user_hospital
{
HospitalID = hospitals.FirstOrDefault(t => t.HosName == data.HosName)?.ID
};
userHoss.Add(userHos);
}
}
_userRepository.AddRange(users.ToArray());
var roleJoin = userRoles.Join(users, t => new { }, w => new { }, (t, w) => new sys_user_role { RoleID = t.RoleID, UserID = w.ID });
var hosJoin = userHoss.Join(users, t => new { }, w => new { }, (t, w) => new sys_user_hospital { HospitalID = t.HospitalID, UserID = w.ID });
//var roleJoin = userRoles.Join(users, t => new { }, w => new { }, (t, w) => new sys_user_role { RoleID = t.RoleID, UserID = w.ID });
//var hosJoin = userHoss.Join(users, t => new { }, w => new { }, (t, w) => new sys_user_hospital { HospitalID = t.HospitalID, UserID = w.ID });
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 });
var roleJoin = joinData.Select(t => new sys_user_role
{
UserID = t.outer.ID,
RoleID = (int)roles.FirstOrDefault(r => r.RoleName == t.inner.RoleName)?.Type
});
_userroleRepository.AddRange(roleJoin.ToArray());
var hosJoin = joinData.Select(t => new sys_user_hospital
{
UserID = t.outer.ID,
HospitalID = hospitals.FirstOrDefault(h => h.HosName == t.inner.HosName)?.ID
});
_userhospitalRepository.AddRange(hosJoin.ToArray());
return 1;
return "";
}
catch (Exception e)
{
......
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