|
@ -20,19 +20,26 @@ using Wood.Util; |
|
|
|
|
|
|
|
|
namespace Wood.Service.Datas |
|
|
namespace Wood.Service.Datas |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class SupplierProProcessEquipmentDtService : NormalBaseController<SUPPLIER_PRO_PROCESS_EQUIPMENT_DT> |
|
|
public class SupplierProProcessEquipmentDtService : NormalBaseController<SUPPLIER_PRO_PROCESS_EQUIPMENT_DT> |
|
|
{ |
|
|
{ |
|
|
|
|
|
const string _taskName = "工艺装备"; |
|
|
|
|
|
|
|
|
private readonly IRepository<TaskSub> _taskSubRepository; |
|
|
private readonly IRepository<TaskSub> _taskSubRepository; |
|
|
private readonly IRepository<SUPPLIER_PRO_PROCESS_EQUIPMENT> _supplierProProcessEquipmentRepository; |
|
|
private readonly IRepository<SUPPLIER_PRO_PROCESS_EQUIPMENT> _supplierProProcessEquipmentRepository; |
|
|
private readonly IRepository<TaskConifgure> _taskConfigureRepository; |
|
|
private readonly IRepository<TaskConifgure> _taskConfigureRepository; |
|
|
|
|
|
private readonly CommonService _commonService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public SupplierProProcessEquipmentDtService(JobDbContext context, IServiceProvider builder, IConfiguration configuration, IRepository<SUPPLIER_PRO_PROCESS_EQUIPMENT_DT> repository, IRepository<TaskSub> taskSubRepository, IRepository<SUPPLIER_PRO_PROCESS_EQUIPMENT> supplierProProcessEquipmentRepository, IRepository<TaskConifgure> taskConfigureRepository) : base(context, builder, configuration, repository) |
|
|
public SupplierProProcessEquipmentDtService(JobDbContext context, IServiceProvider builder, IConfiguration configuration, IRepository<SUPPLIER_PRO_PROCESS_EQUIPMENT_DT> repository, IRepository<TaskSub> taskSubRepository, IRepository<SUPPLIER_PRO_PROCESS_EQUIPMENT> supplierProProcessEquipmentRepository, IRepository<TaskConifgure> taskConfigureRepository, CommonService commonService) : base(context, builder, configuration, repository) |
|
|
{ |
|
|
{ |
|
|
_taskSubRepository = taskSubRepository; |
|
|
_taskSubRepository = taskSubRepository; |
|
|
_supplierProProcessEquipmentRepository = supplierProProcessEquipmentRepository; |
|
|
_supplierProProcessEquipmentRepository = supplierProProcessEquipmentRepository; |
|
|
_taskConfigureRepository = taskConfigureRepository; |
|
|
_taskConfigureRepository = taskConfigureRepository; |
|
|
|
|
|
|
|
|
|
|
|
_taskSubRepository.SetDbContext(_context); |
|
|
|
|
|
_supplierProProcessEquipmentRepository.SetDbContext(_context); |
|
|
|
|
|
_taskConfigureRepository.SetDbContext(_context); |
|
|
|
|
|
_commonService = commonService; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
[HttpPost] |
|
|
[HttpPost] |
|
@ -63,24 +70,24 @@ namespace Wood.Service.Datas |
|
|
} |
|
|
} |
|
|
throw new Exception(sb.ToString()); |
|
|
throw new Exception(sb.ToString()); |
|
|
} |
|
|
} |
|
|
var empDtLst = impResult.Data; |
|
|
var entityLst = impResult.Data; |
|
|
|
|
|
|
|
|
using TransactionScope scope = new TransactionScope(); |
|
|
using var transaction = _context.Database.BeginTransaction(); |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
#region 数据库操作
|
|
|
#region 数据库操作
|
|
|
//添加任务
|
|
|
//添加任务
|
|
|
TaskSub taskSubObj = await BuildTaskSub(empDtLst.Count); |
|
|
TaskSub taskSubObj = _commonService.BuildTaskSub(entityLst.Count, _taskName); |
|
|
await _taskSubRepository.AddAsync(taskSubObj); |
|
|
await _taskSubRepository.AddAsync(taskSubObj); |
|
|
//添加任务明细
|
|
|
//添加任务明细
|
|
|
foreach (var empDtObj in empDtLst) |
|
|
foreach (var empDtObj in entityLst) |
|
|
{ |
|
|
{ |
|
|
SUPPLIER_PRO_PROCESS_EQUIPMENT empObj = ExpressionGenericMapper<SUPPLIER_PRO_PROCESS_EQUIPMENT_DT, SUPPLIER_PRO_PROCESS_EQUIPMENT>.Trans(empDtObj); |
|
|
SUPPLIER_PRO_PROCESS_EQUIPMENT empObj = ExpressionGenericMapper<SUPPLIER_PRO_PROCESS_EQUIPMENT_DT, SUPPLIER_PRO_PROCESS_EQUIPMENT>.Trans(empDtObj); |
|
|
empObj.TaskId = taskSubObj.TaskId; |
|
|
empObj.TaskId = taskSubObj.TaskId; |
|
|
await _supplierProProcessEquipmentRepository.AddAsync(empObj); |
|
|
await _supplierProProcessEquipmentRepository.AddAsync(empObj); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
foreach (var empDtObj in empDtLst) |
|
|
foreach (var empDtObj in entityLst) |
|
|
{ |
|
|
{ |
|
|
//以供应商代码+奇瑞零件号+工艺编码+工艺版本为唯一数据,做新增或者更新存储
|
|
|
//以供应商代码+奇瑞零件号+工艺编码+工艺版本为唯一数据,做新增或者更新存储
|
|
|
var firstObj = _context.Set<SUPPLIER_PRO_PROCESS_EQUIPMENT_DT>().FirstOrDefault( |
|
|
var firstObj = _context.Set<SUPPLIER_PRO_PROCESS_EQUIPMENT_DT>().FirstOrDefault( |
|
@ -100,23 +107,24 @@ namespace Wood.Service.Datas |
|
|
} |
|
|
} |
|
|
#endregion
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
scope.Complete(); |
|
|
transaction.Commit(); |
|
|
return Ok(true); |
|
|
return Ok(true); |
|
|
} |
|
|
} |
|
|
catch (Exception ex) |
|
|
catch (Exception ex) |
|
|
{ |
|
|
{ |
|
|
|
|
|
transaction.Rollback(); |
|
|
throw new Exception("方法体执行报错,事务回滚:" + ex.Message); |
|
|
throw new Exception("方法体执行报错,事务回滚:" + ex.Message); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public override async Task<ActionResult<SUPPLIER_PRO_PROCESS_EQUIPMENT_DT>> Create(SUPPLIER_PRO_PROCESS_EQUIPMENT_DT entity) |
|
|
public override async Task<ActionResult<SUPPLIER_PRO_PROCESS_EQUIPMENT_DT>> Create(SUPPLIER_PRO_PROCESS_EQUIPMENT_DT entity) |
|
|
{ |
|
|
{ |
|
|
using TransactionScope scope = new TransactionScope(); |
|
|
using var transaction = _context.Database.BeginTransaction(); |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
#region 数据库操作
|
|
|
#region 数据库操作
|
|
|
//添加任务
|
|
|
//添加任务
|
|
|
TaskSub taskSubObj = await BuildTaskSub(1); |
|
|
TaskSub taskSubObj = _commonService.BuildTaskSub(1, _taskName); |
|
|
await _taskSubRepository.AddAsync(taskSubObj); |
|
|
await _taskSubRepository.AddAsync(taskSubObj); |
|
|
//添加任务明细
|
|
|
//添加任务明细
|
|
|
SUPPLIER_PRO_PROCESS_EQUIPMENT empObj = ExpressionGenericMapper<SUPPLIER_PRO_PROCESS_EQUIPMENT_DT, SUPPLIER_PRO_PROCESS_EQUIPMENT>.Trans(entity); |
|
|
SUPPLIER_PRO_PROCESS_EQUIPMENT empObj = ExpressionGenericMapper<SUPPLIER_PRO_PROCESS_EQUIPMENT_DT, SUPPLIER_PRO_PROCESS_EQUIPMENT>.Trans(entity); |
|
@ -139,23 +147,24 @@ namespace Wood.Service.Datas |
|
|
} |
|
|
} |
|
|
#endregion
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
scope.Complete(); |
|
|
transaction.Commit(); |
|
|
return Ok(true); |
|
|
return Ok(true); |
|
|
} |
|
|
} |
|
|
catch (Exception ex) |
|
|
catch (Exception ex) |
|
|
{ |
|
|
{ |
|
|
|
|
|
transaction.Rollback(); |
|
|
throw new Exception("方法体执行报错,事务回滚:" + ex.Message); |
|
|
throw new Exception("方法体执行报错,事务回滚:" + ex.Message); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public override async Task<IActionResult> Update(SUPPLIER_PRO_PROCESS_EQUIPMENT_DT entity) |
|
|
public override async Task<IActionResult> Update(SUPPLIER_PRO_PROCESS_EQUIPMENT_DT entity) |
|
|
{ |
|
|
{ |
|
|
using TransactionScope scope = new TransactionScope(); |
|
|
using var transaction = _context.Database.BeginTransaction(); |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
#region 数据库操作
|
|
|
#region 数据库操作
|
|
|
//添加任务
|
|
|
//添加任务
|
|
|
TaskSub taskSubObj = await BuildTaskSub(1); |
|
|
TaskSub taskSubObj = _commonService.BuildTaskSub(1, _taskName); |
|
|
await _taskSubRepository.AddAsync(taskSubObj); |
|
|
await _taskSubRepository.AddAsync(taskSubObj); |
|
|
//添加任务明细
|
|
|
//添加任务明细
|
|
|
SUPPLIER_PRO_PROCESS_EQUIPMENT empObj = ExpressionGenericMapper<SUPPLIER_PRO_PROCESS_EQUIPMENT_DT, SUPPLIER_PRO_PROCESS_EQUIPMENT>.Trans(entity); |
|
|
SUPPLIER_PRO_PROCESS_EQUIPMENT empObj = ExpressionGenericMapper<SUPPLIER_PRO_PROCESS_EQUIPMENT_DT, SUPPLIER_PRO_PROCESS_EQUIPMENT>.Trans(entity); |
|
@ -178,51 +187,14 @@ namespace Wood.Service.Datas |
|
|
} |
|
|
} |
|
|
#endregion
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
scope.Complete(); |
|
|
transaction.Commit(); |
|
|
return Ok(true); |
|
|
return Ok(true); |
|
|
} |
|
|
} |
|
|
catch (Exception ex) |
|
|
catch (Exception ex) |
|
|
{ |
|
|
{ |
|
|
|
|
|
transaction.Rollback(); |
|
|
throw new Exception("方法体执行报错,事务回滚:" + ex.Message); |
|
|
throw new Exception("方法体执行报错,事务回滚:" + ex.Message); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 生成TaskSub
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="dataCount">任务明细数量</param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
/// <exception cref="Exception"></exception>
|
|
|
|
|
|
private async Task<TaskSub> BuildTaskSub(int dataCount) |
|
|
|
|
|
{ |
|
|
|
|
|
List<TaskConifgure> taskConfigureLst = (await _taskConfigureRepository.GetAllAsync()).ToList(); |
|
|
|
|
|
|
|
|
|
|
|
TaskConifgure? taskConfigureObj = taskConfigureLst.FirstOrDefault(itm => itm.TaskName == "工艺装备"); |
|
|
|
|
|
if (taskConfigureObj == null) |
|
|
|
|
|
{ |
|
|
|
|
|
throw new Exception("任务配置表没有'工艺装备'任务"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TaskSub taskSub = new TaskSub(); |
|
|
|
|
|
taskSub.TableName = taskConfigureObj.TableName; //关联的数据表名称(如:订单表、用户表等,可为空)
|
|
|
|
|
|
taskSub.TaskName = taskConfigureObj.TaskName; //任务名称(用于业务层面标识任务,如:数据同步任务、报表生成任务)
|
|
|
|
|
|
taskSub.DataCount = dataCount; //数据总量(任务处理的数据条目数)
|
|
|
|
|
|
taskSub.Subscriber = taskConfigureObj.Client; //发布给那个客户
|
|
|
|
|
|
taskSub.FailedCount = 0; //失败次数(任务执行失败的累计次数)
|
|
|
|
|
|
taskSub.FailedInfo = ""; //失败详情(记录失败原因、异常堆栈等信息,支持长文本)
|
|
|
|
|
|
taskSub.Domain = ""; //所属域(多租户场景下标识租户,如:租户A、租户B)
|
|
|
|
|
|
taskSub.Site = ""; //站点标识(多站点部署时标识所属站点,如:Site1、Site2)
|
|
|
|
|
|
taskSub.CreateUser = CommonHelper.UserName; //从那个内部系统创建系统
|
|
|
|
|
|
taskSub.CreateTime = CommonHelper.CurrentTime; //创建时间(任务创建的时间戳)
|
|
|
|
|
|
taskSub.Remark = ""; //备注信息(任务相关的补充说明,支持长文本)
|
|
|
|
|
|
taskSub.UpdateUser = ""; //最后更新人(记录任务最后修改者)
|
|
|
|
|
|
taskSub.UpdateTime = null; //最后更新时间(任务最后修改的时间戳,可为空)
|
|
|
|
|
|
taskSub.SyncedPageCount = 0; //已同步页数
|
|
|
|
|
|
taskSub.ReadState = true; |
|
|
|
|
|
taskSub.CreationTime = CommonHelper.CurrentTime; |
|
|
|
|
|
taskSub.TaskId = CommonHelper.NewGuid; |
|
|
|
|
|
return taskSub; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|