diff --git a/API/TaskManager.EntityFramework/Repository/Repository.cs b/API/TaskManager.EntityFramework/Repository/Repository.cs index 194f9b5..269ee01 100644 --- a/API/TaskManager.EntityFramework/Repository/Repository.cs +++ b/API/TaskManager.EntityFramework/Repository/Repository.cs @@ -55,10 +55,6 @@ namespace TaskManager.EntityFramework.Repository public async Task UpdateAsync(TEntity entity) { - //product 已前台更新后 - _context.Attach(entity); - _context.Entry(entity).State = EntityState.Modified; - _dbSet.Update(entity); await _context.SaveChangesAsync(); } diff --git a/API/Wood.Service/Controllers/CheryRecurringJobInputPageController.cs b/API/Wood.Service/Controllers/CheryRecurringJobInputPageController.cs index b352773..b163409 100644 --- a/API/Wood.Service/Controllers/CheryRecurringJobInputPageController.cs +++ b/API/Wood.Service/Controllers/CheryRecurringJobInputPageController.cs @@ -151,7 +151,7 @@ namespace TaskManager.Controllers return; } var sublist = _jobDbContext.TaskSub.Where(p => taskName.Contains(p.TaskName) && p.WriteState == false && p.Subscriber == client ).ToList(); - int pageSize = 50; + int pageSize = 10; if (!sublist.Any()) { foreach (var sub in sublist) diff --git a/API/Wood.Service/Controllers/NormalBaseController.cs b/API/Wood.Service/Controllers/NormalBaseController.cs index a85e18a..cf32cb6 100644 --- a/API/Wood.Service/Controllers/NormalBaseController.cs +++ b/API/Wood.Service/Controllers/NormalBaseController.cs @@ -74,17 +74,23 @@ namespace Wood.Service.Controllers /// /// /// - [HttpPut("{id}")] + [HttpPut] + [Route("Update/{UId}")] public async virtual Task Update(T entity) { + if (entity.UId == 0) + { + throw new Exception("更新时,实体主键UId不能为空或0"); + } var _first = await _repository.GetByIdAsync(entity.UId); if (_first == null) { + throw new Exception($"NormalBaseController.Update报错:根据UId{entity.UId}没有找到记录"); return new JsonResult(new { Code = 400, Message = "修改失败!" }); } + EntityMapper.Trans(_first, entity, "UId"); - - await _repository.UpdateAsync(entity); + await _repository.UpdateAsync(_first); return new JsonResult(new { Code = 200, Message = "修改成功!" }); } /// @@ -313,6 +319,7 @@ namespace Wood.Service.Controllers } catch (Exception ex) { + throw new Exception("NormalBaseController.Import报错:" + ex.Message); // await _logger.AddError(ex.Message, TaskName); return new JsonResult(new { Code = 400, Message = "导入失败!" }); } diff --git a/API/Wood.Service/Datas/SupplierEmployeeDtService.cs b/API/Wood.Service/Datas/SupplierEmployeeDtService.cs index b1e71ab..96e2daf 100644 --- a/API/Wood.Service/Datas/SupplierEmployeeDtService.cs +++ b/API/Wood.Service/Datas/SupplierEmployeeDtService.cs @@ -82,7 +82,7 @@ namespace Wood.Service.Datas //添加任务明细 foreach (var empDtObj in entityLst) { - SUPPLIER_EMPLOYEE empObj = ExpressionGenericMapper.Trans(empDtObj); + SUPPLIER_EMPLOYEE empObj = EntityMapper.Trans(empDtObj); empObj.TaskId = taskSubObj.TaskId; await _supplierEmployeeRepository.AddAsync(empObj); } @@ -131,7 +131,7 @@ namespace Wood.Service.Datas TaskSub taskSubObj = _commonService.BuildTaskSub(1, _taskName); await _taskSubRepository.AddAsync(taskSubObj); //添加任务明细 - SUPPLIER_EMPLOYEE empObj = ExpressionGenericMapper.Trans(entity); + SUPPLIER_EMPLOYEE empObj = EntityMapper.Trans(entity); empObj.TaskId = taskSubObj.TaskId; await _supplierEmployeeRepository.AddAsync(empObj); @@ -173,7 +173,7 @@ namespace Wood.Service.Datas TaskSub taskSubObj = _commonService.BuildTaskSub(1, _taskName); await _taskSubRepository.AddAsync(taskSubObj); //添加任务明细 - SUPPLIER_EMPLOYEE empObj = ExpressionGenericMapper.Trans(entity); + SUPPLIER_EMPLOYEE empObj = EntityMapper.Trans(entity); empObj.TaskId = taskSubObj.TaskId; await _supplierEmployeeRepository.AddAsync(empObj); diff --git a/API/Wood.Service/Datas/SupplierInfoDtService.cs b/API/Wood.Service/Datas/SupplierInfoDtService.cs index c93c52c..916b1e0 100644 --- a/API/Wood.Service/Datas/SupplierInfoDtService.cs +++ b/API/Wood.Service/Datas/SupplierInfoDtService.cs @@ -81,7 +81,7 @@ namespace Wood.Service.Datas //添加任务明细 foreach (var empDtObj in entityLst) { - SUPPLIER_INFO empObj = ExpressionGenericMapper.Trans(empDtObj); + SUPPLIER_INFO empObj = EntityMapper.Trans(empDtObj); empObj.TaskId = taskSubObj.TaskId; await _supplierInfoRepository.AddAsync(empObj); } @@ -131,7 +131,7 @@ namespace Wood.Service.Datas await _taskSubRepository.AddAsync(taskSubObj); //添加任务明细 - SUPPLIER_INFO empObj = ExpressionGenericMapper.Trans(entity); + SUPPLIER_INFO empObj = EntityMapper.Trans(entity); empObj.TaskId = taskSubObj.TaskId; await _supplierInfoRepository.AddAsync(empObj); @@ -172,7 +172,7 @@ namespace Wood.Service.Datas TaskSub taskSubObj = _commonService.BuildTaskSub(1, _taskName); await _taskSubRepository.AddAsync(taskSubObj); //添加任务明细 - SUPPLIER_INFO empObj = ExpressionGenericMapper.Trans(entity); + SUPPLIER_INFO empObj = EntityMapper.Trans(entity); empObj.TaskId = taskSubObj.TaskId; await _supplierInfoRepository.AddAsync(empObj); diff --git a/API/Wood.Service/Datas/SupplierProAttachmentDataDtService.cs b/API/Wood.Service/Datas/SupplierProAttachmentDataDtService.cs index 81e0c11..bfbe29f 100644 --- a/API/Wood.Service/Datas/SupplierProAttachmentDataDtService.cs +++ b/API/Wood.Service/Datas/SupplierProAttachmentDataDtService.cs @@ -82,7 +82,7 @@ namespace Wood.Service.Datas //添加任务明细 foreach (var empDtObj in entityLst) { - SUPPLIER_PRO_ATTACHMENT_DATA empObj = ExpressionGenericMapper.Trans(empDtObj); + SUPPLIER_PRO_ATTACHMENT_DATA empObj = EntityMapper.Trans(empDtObj); empObj.TaskId = taskSubObj.TaskId; await _supplierProAttachmentDataRepository.AddAsync(empObj); } @@ -114,7 +114,7 @@ namespace Wood.Service.Datas TaskSub taskSubObj = _commonService.BuildTaskSub(1, _taskName); await _taskSubRepository.AddAsync(taskSubObj); //添加任务明细 - SUPPLIER_PRO_ATTACHMENT_DATA empObj = ExpressionGenericMapper.Trans(entity); + SUPPLIER_PRO_ATTACHMENT_DATA empObj = EntityMapper.Trans(entity); empObj.TaskId = taskSubObj.TaskId; await _supplierProAttachmentDataRepository.AddAsync(empObj); diff --git a/API/Wood.Service/Datas/SupplierProProcessEquipmentDtService.cs b/API/Wood.Service/Datas/SupplierProProcessEquipmentDtService.cs index f237114..a7ffca2 100644 --- a/API/Wood.Service/Datas/SupplierProProcessEquipmentDtService.cs +++ b/API/Wood.Service/Datas/SupplierProProcessEquipmentDtService.cs @@ -82,7 +82,7 @@ namespace Wood.Service.Datas //添加任务明细 foreach (var empDtObj in entityLst) { - SUPPLIER_PRO_PROCESS_EQUIPMENT empObj = ExpressionGenericMapper.Trans(empDtObj); + SUPPLIER_PRO_PROCESS_EQUIPMENT empObj = EntityMapper.Trans(empDtObj); empObj.TaskId = taskSubObj.TaskId; await _supplierProProcessEquipmentRepository.AddAsync(empObj); } @@ -129,7 +129,7 @@ namespace Wood.Service.Datas TaskSub taskSubObj = _commonService.BuildTaskSub(1, _taskName); await _taskSubRepository.AddAsync(taskSubObj); //添加任务明细 - SUPPLIER_PRO_PROCESS_EQUIPMENT empObj = ExpressionGenericMapper.Trans(entity); + SUPPLIER_PRO_PROCESS_EQUIPMENT empObj = EntityMapper.Trans(entity); empObj.TaskId = taskSubObj.TaskId; await _supplierProProcessEquipmentRepository.AddAsync(empObj); @@ -169,7 +169,7 @@ namespace Wood.Service.Datas TaskSub taskSubObj = _commonService.BuildTaskSub(1, _taskName); await _taskSubRepository.AddAsync(taskSubObj); //添加任务明细 - SUPPLIER_PRO_PROCESS_EQUIPMENT empObj = ExpressionGenericMapper.Trans(entity); + SUPPLIER_PRO_PROCESS_EQUIPMENT empObj = EntityMapper.Trans(entity); empObj.TaskId = taskSubObj.TaskId; await _supplierProProcessEquipmentRepository.AddAsync(empObj); diff --git a/API/Wood.Util/CommonHelper.cs b/API/Wood.Util/CommonHelper.cs index 3736a81..c00104d 100644 --- a/API/Wood.Util/CommonHelper.cs +++ b/API/Wood.Util/CommonHelper.cs @@ -65,10 +65,10 @@ namespace Wood.Util /// /// /// - public class ExpressionGenericMapper//Mapper`2 + public class EntityMapper//Mapper`2 { private static Func _FUNC = null; - static ExpressionGenericMapper() + static EntityMapper() { ParameterExpression parameterExpression = Expression.Parameter(typeof(TIn), "p"); List memberBindingList = new List(); @@ -96,4 +96,43 @@ namespace Wood.Util return _FUNC(t); } } + + + /// + /// 反射实现Mapper + /// + public class EntityMapper + { + /// + /// 反射 + /// + /// + /// + /// + /// + public static void Trans(TIn tIn, TOut tOut, string excludeMembers = "") + { + string[] excludeMemberArr = excludeMembers.Split(",").Select(itm => itm.Trim()).ToArray(); + + foreach (var itemOut in tOut.GetType().GetProperties()) + { + if (excludeMemberArr.Contains(itemOut.Name)) + { + continue; + } + var propIn = tIn.GetType().GetProperty(itemOut.Name); + itemOut.SetValue(tOut, propIn.GetValue(tIn, null), null); + } + + foreach (var itemOut in tOut.GetType().GetFields()) + { + if (excludeMemberArr.Contains(itemOut.Name)) + { + continue; + } + var fieldIn = tIn.GetType().GetField(itemOut.Name); + itemOut.SetValue(tOut, fieldIn.GetValue(tIn)); + } + } + } }