切换模板删除数据

parent e5d1d461
...@@ -80,7 +80,7 @@ public ApiResponse SaveValue(int secondid, [FromBody] List<ag_fixatitem> request ...@@ -80,7 +80,7 @@ public ApiResponse SaveValue(int secondid, [FromBody] List<ag_fixatitem> request
if (repetition.Any()) if (repetition.Any())
throw new PerformanceException(string.Join(";", repetition.Select(t => $"行{t.Key.RowNumber}项‘{t.Key.ItemName}’重复录入"))); throw new PerformanceException(string.Join(";", repetition.Select(t => $"行{t.Key.RowNumber}项‘{t.Key.ItemName}’重复录入")));
var result = secondAllotService.SaveValue(request); var result = secondAllotService.SaveValue(request, secondid);
return new ApiResponse(ResponseType.OK); return new ApiResponse(ResponseType.OK);
} }
......
using AutoMapper; using AutoMapper;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Performance.DtoModels; using Performance.DtoModels;
using Performance.DtoModels.AppSettings; using Performance.DtoModels.AppSettings;
...@@ -17,6 +18,7 @@ namespace Performance.Services ...@@ -17,6 +18,7 @@ namespace Performance.Services
public class SecondAllotService : IAutoInjection public class SecondAllotService : IAutoInjection
{ {
private readonly Application application; private readonly Application application;
private readonly ILogger<SecondAllotService> _logger;
private readonly PerforHospitalRepository hospitalRepository; private readonly PerforHospitalRepository hospitalRepository;
private readonly PerforUserRepository perforUserRepository; private readonly PerforUserRepository perforUserRepository;
private readonly PerforUserhospitalRepository perforUserhospitalRepository; private readonly PerforUserhospitalRepository perforUserhospitalRepository;
...@@ -44,6 +46,7 @@ public class SecondAllotService : IAutoInjection ...@@ -44,6 +46,7 @@ public class SecondAllotService : IAutoInjection
private readonly List<ag_tempitem> tempitems = new List<ag_tempitem>(); private readonly List<ag_tempitem> tempitems = new List<ag_tempitem>();
public SecondAllotService(IOptions<Application> application, public SecondAllotService(IOptions<Application> application,
ILogger<SecondAllotService> logger,
PerforHospitalRepository hospitalRepository, PerforHospitalRepository hospitalRepository,
PerforUserRepository perforUserRepository, PerforUserRepository perforUserRepository,
PerforUserhospitalRepository perforUserhospitalRepository, PerforUserhospitalRepository perforUserhospitalRepository,
...@@ -70,6 +73,7 @@ public class SecondAllotService : IAutoInjection ...@@ -70,6 +73,7 @@ public class SecondAllotService : IAutoInjection
PerforImemployeeclinicRepository imemployeeclinicRepository) PerforImemployeeclinicRepository imemployeeclinicRepository)
{ {
this.application = application.Value; this.application = application.Value;
_logger = logger;
this.hospitalRepository = hospitalRepository; this.hospitalRepository = hospitalRepository;
this.perforUserRepository = perforUserRepository; this.perforUserRepository = perforUserRepository;
this.perforUserhospitalRepository = perforUserhospitalRepository; this.perforUserhospitalRepository = perforUserhospitalRepository;
...@@ -678,15 +682,14 @@ private void SupplyHeaderByWorkItem(UseTempRequest request, SecondResponse resul ...@@ -678,15 +682,14 @@ private void SupplyHeaderByWorkItem(UseTempRequest request, SecondResponse resul
/// </summary> /// </summary>
/// <param name="request"></param> /// <param name="request"></param>
/// <returns></returns> /// <returns></returns>
public bool SaveValue(List<ag_fixatitem> request) public bool SaveValue(List<ag_fixatitem> request, int secondId)
{ {
var secondId = request.First().SecondId;
var second = perforAgsecondallotRepository.GetEntity(t => t.Id == secondId); var second = perforAgsecondallotRepository.GetEntity(t => t.Id == secondId);
if (second == null) if (second == null)
throw new PerformanceException("二次绩效ID不存在"); throw new PerformanceException("二次绩效ID不存在");
var fixatitems = perforAgfixatitemRepository.GetEntities(t => t.SecondId == secondId); var fixatitems = perforAgfixatitemRepository.GetEntities(t => t.SecondId == secondId);
var result = DelValue(fixatitems, request); var result = DelValue(secondId, fixatitems, request);
List<ag_fixatitem> update = new List<ag_fixatitem>(), insert = new List<ag_fixatitem>(); List<ag_fixatitem> update = new List<ag_fixatitem>(), insert = new List<ag_fixatitem>();
if (fixatitems != null && fixatitems.Any()) if (fixatitems != null && fixatitems.Any())
{ {
...@@ -719,23 +722,27 @@ public bool SaveValue(List<ag_fixatitem> request) ...@@ -719,23 +722,27 @@ public bool SaveValue(List<ag_fixatitem> request)
/// <summary> /// <summary>
/// 删除未保存的历史数据 /// 删除未保存的历史数据
/// </summary> /// </summary>
/// <param name="fixatlist">数据库中查询到的值</param> /// <param name="oldFixatItems">数据库中查询到的值</param>
/// <param name="fixatitems">需要保存的数据</param> /// <param name="newFixatItems">需要保存的数据</param>
/// <returns></returns> /// <returns></returns>
public bool DelValue(List<ag_fixatitem> fixatlist, List<ag_fixatitem> fixatitems) public bool DelValue(int secondId, List<ag_fixatitem> oldFixatItems, List<ag_fixatitem> newFixatItems)
{ {
var result = true; var result = true;
// 提交数据为空时,删除所有数据 // 提交数据为空时,删除所有数据
if (fixatitems == null || fixatitems.Count == 0) if (newFixatItems == null || newFixatItems.Count == 0)
{ {
if (fixatlist != null && fixatlist.Any()) if (oldFixatItems != null && oldFixatItems.Any())
result = perforAgfixatitemRepository.RemoveRange(fixatlist.ToArray()); {
result = perforAgfixatitemRepository.RemoveRange(oldFixatItems.ToArray());
_logger.LogError($"删除二次分配录入数据:{oldFixatItems.Count()}");
_logger.LogError($"删除二次分配录入数据:{JsonHelper.Serialize(oldFixatItems.Select(w => w.ID))}");
}
return result; return result;
} }
if (fixatlist != null && fixatlist.Any()) if (oldFixatItems != null && oldFixatItems.Any())
{ {
var groupData = fixatlist.GroupBy(t => new { t.RowNumber, t.ItemName }).Select(t => new var groupData = oldFixatItems.GroupBy(t => new { t.RowNumber, t.ItemName }).Select(t => new
{ {
t.Key.RowNumber, t.Key.RowNumber,
t.Key.ItemName, t.Key.ItemName,
...@@ -745,16 +752,20 @@ public bool DelValue(List<ag_fixatitem> fixatlist, List<ag_fixatitem> fixatitems ...@@ -745,16 +752,20 @@ public bool DelValue(List<ag_fixatitem> fixatlist, List<ag_fixatitem> fixatitems
// 删除重复数据 // 删除重复数据
if (groupData.Any(t => t.Count > 1)) if (groupData.Any(t => t.Count > 1))
{ {
var delData = fixatlist.Where(t => !groupData.Select(w => w.Id).Contains(t.ID)); var delData = oldFixatItems.Where(t => t.SecondId == secondId && !groupData.Select(w => w.Id).Contains(t.ID));
int flag = fixatlist.RemoveAll(t => !groupData.Select(w => w.Id).Contains(t.ID)); int flag = oldFixatItems.RemoveAll(t => t.SecondId == secondId && !groupData.Select(w => w.Id).Contains(t.ID));
_logger.LogError($"删除二次分配录入数据:{delData.Count()}");
result = perforAgfixatitemRepository.RemoveRange(delData.ToArray()); result = perforAgfixatitemRepository.RemoveRange(delData.ToArray());
} }
// 删除行号不存在的数据 // 删除行号不存在的数据
var saveRows = fixatitems.Select(t => t.RowNumber).Distinct(); var saveRows = newFixatItems.Where(t => t.SecondId == secondId).Select(t => t.RowNumber).Distinct();
var delRows = fixatlist.Select(t => t.RowNumber).Distinct().Except(saveRows); var delRows = oldFixatItems.Where(t => t.SecondId == secondId).Select(t => t.RowNumber).Distinct().Except(saveRows);
if (delRows != null && delRows.Count() > 0) if (delRows != null && delRows.Count() > 0)
result = perforAgfixatitemRepository.RemoveRange(fixatlist.Where(t => delRows.Contains(t.RowNumber)).ToArray()); {
result = perforAgfixatitemRepository.RemoveRange(oldFixatItems.Where(t => delRows.Contains(t.RowNumber)).ToArray());
_logger.LogError($"删除二次分配录入数据 删除行号不存在的数据:{oldFixatItems.Count()}");
}
} }
return result; return result;
...@@ -909,15 +920,15 @@ public bool UseTemp(UseTempRequest request) ...@@ -909,15 +920,15 @@ public bool UseTemp(UseTempRequest request)
#endregion 获取需要添加的数据 无需操作的数据 #endregion 获取需要添加的数据 无需操作的数据
//perforAgsecondallotRepository.UpdateRange(update_second_usetemps.ToArray()); ////perforAgsecondallotRepository.UpdateRange(update_second_usetemps.ToArray());
if (list != null && list.Count > 0) //if (list != null && list.Count > 0)
{ //{
var delList = fixatList.Except(list); // var delList = fixatList.Except(list);
perforAgfixatitemRepository.RemoveRange(delList.ToArray()); // perforAgfixatitemRepository.RemoveRange(delList.Where(w => w.SecondId == request.SecondId).ToArray());
if (addList != null && addList.Count > 0) // if (addList != null && addList.Count > 0)
perforAgfixatitemRepository.AddRange(addList.ToArray()); // perforAgfixatitemRepository.AddRange(addList.ToArray());
} //}
} }
} }
return result; return result;
...@@ -1718,7 +1729,7 @@ public List<SecPrintResponse> Print(int secondId) ...@@ -1718,7 +1729,7 @@ public List<SecPrintResponse> Print(int secondId)
JobNumber = fixaitems.FirstOrDefault(t => t.RowNumber == rownumber && t.ItemName == "人员工号")?.ItemValue, JobNumber = fixaitems.FirstOrDefault(t => t.RowNumber == rownumber && t.ItemName == "人员工号")?.ItemValue,
PersonName = fixaitems.FirstOrDefault(t => t.RowNumber == rownumber && t.ItemName == "姓名")?.ItemValue, PersonName = fixaitems.FirstOrDefault(t => t.RowNumber == rownumber && t.ItemName == "姓名")?.ItemValue,
Department = second.Department, Department = second.Department,
RealAmount = distperfor + nightworkperfor, RealAmount = (distperfor ?? 0) + (nightworkperfor ?? 0),
}; };
sec.WorkPost = fixaitems.FirstOrDefault(t => t.RowNumber == rownumber && t.ItemName == "职称")?.ItemValue; sec.WorkPost = fixaitems.FirstOrDefault(t => t.RowNumber == rownumber && t.ItemName == "职称")?.ItemValue;
sec.TitlePerfor = ConvertHelper.To<decimal?>(fixaitems.FirstOrDefault(t => t.RowNumber == rownumber && t.ItemName == "职称绩效")?.ItemValue); sec.TitlePerfor = ConvertHelper.To<decimal?>(fixaitems.FirstOrDefault(t => t.RowNumber == rownumber && t.ItemName == "职称绩效")?.ItemValue);
......
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