Commit 8392e9fd by lcx

原始数据单数据修改

parent 78ba2d91
......@@ -10,6 +10,6 @@ public class OriginalRequest
public int RowNumber { get; set; }
public List<Cell> Cells { get; set; }
public Cell Cell { get; set; }
}
}
......@@ -39,13 +39,14 @@ public class OriginalService : IAutoInjection
public bool EditFactorData(int userId, OriginalRequest request)
{
// 含有系数的数据
var allData = imdataRepository.GetEntities(t => t.SheetID == request.SheetId);
var basic = allData.FirstOrDefault(t => t.ID == request.Cells.FirstOrDefault(w => w.Id > 0).Id);
var basic = allData.FirstOrDefault(t => t.ID == request.Cell.Id);
// 获取相同核算类型的数据
var updateData = allData.Where(t => t.UnitType == basic.UnitType);
foreach (var cell in request.Cells.Where(t => t.Id > 0))
{
var data = updateData.Where(t => t.TypeName == cell.FieldName).ToList();
var factor = ConvertHelper.To<decimal>(cell.CellValue);
var data = updateData.Where(t => t.TypeName == request.Cell.FieldName).ToList();
// 修改同一类型下的系数
var factor = ConvertHelper.To<decimal>(request.Cell.CellValue);
if (data != null && data.Any())
{
data.ForEach(t =>
......@@ -55,22 +56,20 @@ public bool EditFactorData(int userId, OriginalRequest request)
t.UpdateUser = userId;
});
}
}
return imdataRepository.UpdateRange(updateData.ToArray());
}
public bool EditHeaderData(int userId, OriginalRequest request)
{
var filters = new List<string> { "核算单元(医技组)", "核算单元(医生组)", "核算单元(护理组)", "科室名称", "核算单元", "核算单元类型", "" };
var headers = request.Cells.Where(t => !filters.Contains(t.FieldName));
var allData = imheaderRepository.GetEntities(t => headers.Select(w => w.Id).Contains(t.ID));
foreach (var data in allData)
{
data.CellValue = request.Cells.FirstOrDefault(w => w.Id == data.ID).CellValue.ToString();
if (!filters.Contains(request.Cell.FieldName))
throw new PerformanceException("该单元格暂不支持修改");
var data = imheaderRepository.GetEntity(t => t.ID == request.Cell.Id);
data.CellValue = request.Cell.CellValue.ToString();
data.UpdateDate = DateTime.Now;
data.UpdateUser = userId;
}
return imheaderRepository.UpdateRange(allData.ToArray());
return imheaderRepository.Update(data);
}
public bool EditSheetData(int userId, OriginalRequest request)
......@@ -101,11 +100,11 @@ public bool EditSheetData(int userId, OriginalRequest request)
private bool EditEmployee(int userId, OriginalRequest request)
{
var employee = imemployeeRepository.GetEntity(t => request.Cells.FirstOrDefault().Id == t.ID);
var employee = imemployeeRepository.GetEntity(t => request.Cell.Id == t.ID);
if (employee == null)
throw new PerformanceException("提交数据无效");
SetValue(employee, request.Cells);
SetValue(employee, request.Cell);
employee.UpdateDate = DateTime.Now;
employee.UpdateUser = userId;
return imemployeeRepository.Update(employee);
......@@ -113,11 +112,11 @@ private bool EditEmployee(int userId, OriginalRequest request)
private bool EditEmployeeClinic(int userId, OriginalRequest request)
{
var employeeClinic = imemployeeclinicRepository.GetEntity(t => request.Cells.FirstOrDefault().Id == t.ID);
var employeeClinic = imemployeeclinicRepository.GetEntity(t => request.Cell.Id == t.ID);
if (employeeClinic == null)
throw new PerformanceException("提交数据无效");
SetValue(employeeClinic, request.Cells);
SetValue(employeeClinic, request.Cell);
employeeClinic.UpdateDate = DateTime.Now;
employeeClinic.UpdateUser = userId;
return imemployeeclinicRepository.Update(employeeClinic);
......@@ -125,33 +124,19 @@ private bool EditEmployeeClinic(int userId, OriginalRequest request)
private bool EditSpecialUnit(int userId, OriginalRequest request)
{
var specialUnit = imspecialunitRepository.GetEntity(t => request.Cells.FirstOrDefault().Id == t.ID);
var specialUnit = imspecialunitRepository.GetEntity(t => request.Cell.Id == t.ID);
if (specialUnit == null)
throw new PerformanceException("提交数据无效");
SetValue(specialUnit, request.Cells);
SetValue(specialUnit, request.Cell);
specialUnit.UpdateDate = DateTime.Now;
specialUnit.UpdateUser = userId;
return imspecialunitRepository.Update(specialUnit);
}
private void SetValue<TEntity>(TEntity entity, List<Cell> cells)
private void SetValue<TEntity>(TEntity entity, Cell cell)
{
PropertyInfo[] info = (typeof(TEntity)).GetProperties();
foreach (var item in info)
{
//// 修改前的值
//var result = typeof(TEntity).GetProperty(item.Name).GetValue(entity);
var element = PerSheetHeader.employeeHeaders.FirstOrDefault(t => t.Item8 == item.Name);
var index = PerSheetHeader.employeeHeaders.IndexOf(element);
if (index < 0) continue;
var cell = cells.FirstOrDefault(t => t.PointCell == index);
if (cell == null) continue;
typeof(TEntity).GetProperty(item.Name).SetValue(entity, cell.CellValue);
}
typeof(TEntity).GetProperty(cell.FieldName).SetValue(entity, cell.CellValue);
}
#endregion
......@@ -165,23 +150,23 @@ private bool EditFeeData(int userId, OriginalRequest request)
if (allData == null || !allData.Any(t => t.RowNumber == request.RowNumber))
throw new PerformanceException("提交数据无效");
var updateData = request.Cells.Where(t => t.Id > 0);
if (updateData != null && updateData.Any())
var updateData = request.Cell;
if (updateData != null)
{
var data = allData.Where(t => t.RowNumber == request.RowNumber).ToList();
ImDataPublic(request.Cells, data);
ImDataPublic(request.Cell, data);
var publicTypes = new string[] { "核算单元(医技组)", "核算单元(医生组)", "核算单元(护理组)", "科室名称", "核算单元", "核算单元类型" };
request.Cells.Where(t => publicTypes.Contains(t.FieldName)).ToList().ForEach(t =>
if (!publicTypes.Contains(updateData.FieldName))
{
var type = t.CellValue.GetType();
var type = updateData.CellValue.GetType();
if (type.Name != "String")
{
var entity = data.FirstOrDefault(w => w.ID == t.Id);
entity.CellValue = ConvertHelper.To<decimal?>(t.CellValue);
var entity = data.FirstOrDefault(w => w.ID == updateData.Id);
entity.CellValue = ConvertHelper.To<decimal?>(updateData.CellValue);
entity.UpdateDate = DateTime.Now;
entity.UpdateUser = userId;
}
});
}
result = imdataRepository.UpdateRange(data.ToArray());
}
......@@ -189,7 +174,7 @@ private bool EditFeeData(int userId, OriginalRequest request)
return result;
}
private void ImDataPublic(IEnumerable<Cell> cells, List<im_data> allData)
private void ImDataPublic(Cell cell, List<im_data> allData)
{
Dictionary<int, string> publicTypes = new Dictionary<int, string>
{
......@@ -199,7 +184,10 @@ private void ImDataPublic(IEnumerable<Cell> cells, List<im_data> allData)
};
foreach (var item in publicTypes)
{
var cellvalue = cells.FirstOrDefault(t => t.FieldName == item.Value).CellValue.ToString();
if (cell.FieldName != item.Value)
continue;
var cellvalue = cell.CellValue.ToString();
var unitType = allData.FirstOrDefault(t => t.UnitType == item.Key).AccountingUnit;
if (cellvalue != unitType)
{
......@@ -209,25 +197,26 @@ private void ImDataPublic(IEnumerable<Cell> cells, List<im_data> allData)
});
}
}
var celldept = cells.FirstOrDefault(t => t.FieldName == "科室名称").CellValue.ToString();
if (cell.FieldName == "科室名称")
{
var department = allData.FirstOrDefault().Department;
if (celldept != department)
if (cell.CellValue.ToString() != department)
{
allData.ForEach(t =>
{
t.Department = celldept;
t.Department = cell.CellValue.ToString();
});
}
}
}
private bool ImDataInsert(int userId, OriginalRequest request, List<im_data> allData)
{
var addData = request.Cells.Where(t => t.Id == 0).ToList();
if (addData == null || !addData.Any())
if (request.Cell.Id == 0)
return true;
// 列
var headers = imheaderRepository.GetEntities(t => t.SheetID == request.SheetId);
var header = imheaderRepository.GetEntity(t => t.SheetID == request.SheetId && t.CellValue == request.Cell.FieldName);
// 核算单元、科室
var publicData = allData.First();
// rownumber含有的核算类型
......@@ -239,24 +228,19 @@ private bool ImDataInsert(int userId, OriginalRequest request, List<im_data> all
FactorValue = t.Max(group => group.FactorValue)
});
var newData = addData.Join(factor, inner => inner.FieldName, outer => outer.TypeName, (inner, outer) => new { inner, outer })
.Select(t =>
{
var singId = headers.FirstOrDefault(w => w.CellValue == t.inner.FieldName)?.SignID;
return new im_data
var newData = factor.Select(t => new im_data
{
RowNumber = request.RowNumber,
AccountingUnit = publicData.AccountingUnit,
Department = publicData.Department,
UnitType = t.outer.UnitType,
TypeName = t.inner.FieldName,
CellValue = ConvertHelper.To<decimal>(t.inner.CellValue),
UnitType = t.UnitType,
TypeName = request.Cell.FieldName,
CellValue = ConvertHelper.To<decimal>(request.Cell.CellValue),
IsFactor = 1,
FactorValue = t.outer.FactorValue,
SignID = singId,
FactorValue = t.FactorValue,
SignID = header.SignID,
UpdateDate = DateTime.Now,
UpdateUser = userId,
};
});
return imdataRepository.AddRange(newData.ToArray());
......
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