using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Storage; using TaskManager.Contracts.Dtos; using TaskManager.Entity; using TaskManager.Entity.Entitys; using TaskManager.EntityFramework; namespace TaskManager.Controllers { /// /// 采购订单风险确认 /// public class CherySupplierConPoService : CheryRecurringJobInputPageController { public CherySupplierConPoService(HttpClient httpClient, JobDbContext jobDbContext, LogController log, IRepository repository) : base(httpClient, jobDbContext, log, repository) { } [HttpGet] public async Task GetDetialByID(String id) { SUPPLIER_CON_DATE first = new SUPPLIER_CON_DATE(); var m = await _jobDbContext.SUPPLIER_CON_DATE.FirstOrDefaultAsync(p => p.Id == id); if (m != null) { return m; } return first; } /// /// 确认提交 /// /// /// [HttpPost] public async Task Confirm([FromBody] List entites) { var taskId = Guid.NewGuid(); var task = new TaskSub(); task.TaskId = taskId; task.TaskName = "采购订单风险确认"; task.Subscriber = "Chery"; task.TableName = "SUPPLIER_CON_PO"; task.DataCount = entites.Count; task.Domain = "1"; task.Site = "1"; task.FailedCount = 0; task.CreateTime = DateTime.Now; task.CreateUser = "admin"; task.CreationTime = DateTime.Now; task.SyncedPageCount = 0; entites.ForEach(p => { p.ReadState = true; p.TaskId = taskId; }); using (var transaction = await _jobDbContext.Database.BeginTransactionAsync()) { var tran = transaction.GetDbTransaction(); try { await _jobDbContext.BulkUpdateAsync(entites, options => { options.Transaction = tran; }); await _jobDbContext.AddAsync(task); _jobDbContext.SaveChanges(); // 提交事务 await transaction.CommitAsync(); } catch (Exception ex) { await transaction.RollbackAsync(); return new JsonResult(new { Code = 400, Message = ex.Message }); } } return new JsonResult(new { Code = 200, Message = "确认成功!" }); } /// /// 批量修改 /// /// /// [HttpPost] public async Task BatchUpdate([FromBody] List entites) { await _jobDbContext.BulkUpdateAsync(entites, options => { options.ColumnPrimaryKeyExpression = p => p.UId; options.UseTableLock = false; }); return new JsonResult(new { Code = 200, Message = "批量修改成功!" }); } } }