Browse Source

仓储异常修改

Murphy 2 years ago
parent
commit
0baa8c7cbb

+ 19 - 9
MicroServices/Business/Business.Application/ResourceExamineManagement/ResourceExamineAppService.cs

@@ -34,6 +34,7 @@ using System.ComponentModel.DataAnnotations.Schema;
 using System.ComponentModel.DataAnnotations;
 using System.Diagnostics.CodeAnalysis;
 using System.Diagnostics;
+using Volo.Abp.Uow;
 
 namespace Business.ResourceExamineManagement
 {
@@ -220,7 +221,9 @@ namespace Business.ResourceExamineManagement
         /// 标准BOM表
         /// </summary>
         private readonly ISqlRepository<ProductStructureMaster> _productStructureMaster;
-
+        private readonly ISqlRepository<WorkOrdRouting> _workOrdRouting;
+        private readonly ISqlRepository<WorkOrdMaster> _workOrdMaster;
+        private readonly ISqlRepository<WorkOrdDetail> _workOrdDetail;
         /// <summary>
         /// 资源检查入参
         /// </summary>
@@ -339,7 +342,10 @@ namespace Business.ResourceExamineManagement
             BusinessDbContext businessDbContext,
             ProductionScheduleAppService productionScheduleAppService,
             ISqlRepository<RoutingOpDetail> routingOpDetail,
-            ISqlRepository<ProductStructureMaster> productStructureMaster
+            ISqlRepository<ProductStructureMaster> productStructureMaster,
+            ISqlRepository<WorkOrdRouting> workOrdRouting,
+            ISqlRepository<WorkOrdMaster> workOrdMaster,
+            ISqlRepository<WorkOrdDetail> workOrdDetail
             )
         {
             _mes_technique = mes_technique;
@@ -406,7 +412,10 @@ namespace Business.ResourceExamineManagement
             _productionScheduleAppService = productionScheduleAppService;
             _routingOpDetail = routingOpDetail;
             _productStructureMaster = productStructureMaster;
-        }
+            _workOrdRouting = workOrdRouting;
+            _workOrdMaster=workOrdMaster;
+            _workOrdDetail=workOrdDetail;
+    }
         #endregion
 
         /// <summary>
@@ -2285,6 +2294,7 @@ namespace Business.ResourceExamineManagement
         /// 同步工单等相关数据
         /// </summary>
         /// <param name="morders"></param>
+        [UnitOfWork]
         public async void CreateWorkOrdDates(List<mo_mes_morder> morders)
         {
             //获取工艺路线数据:product_code=物料编码
@@ -2356,12 +2366,12 @@ namespace Business.ResourceExamineManagement
                 }
             }
 
-            await _businessDbContext.BulkInsertAsync(workOrds);
-            await _businessDbContext.BulkInsertAsync(workOrdRoutings);
-            await _businessDbContext.BulkInsertAsync(workOrdDetails);
-
-            //排产,工单肯定有值
-            await _productionScheduleAppService.DoProductShcedule(workOrds);
+            //await _businessDbContext.BulkInsertAsync(workOrds);
+            //await _businessDbContext.BulkInsertAsync(workOrdRoutings);
+            //await _businessDbContext.BulkInsertAsync(workOrdDetails);
+            _workOrdMaster.Insert(workOrds);
+            _workOrdRouting.Insert(workOrdRoutings);
+            _workOrdDetail.Insert(workOrdDetails);
         }
 
         /// <summary>

+ 22 - 22
MicroServices/Business/Business.EntityFrameworkCore/Repository/SqlRepositories/SqlRepository.cs

@@ -18,69 +18,69 @@ namespace Business.EntityFrameworkCore.SqlRepositories
 {
     public class SqlRepository<T>:ISqlRepository<T> where T : class, new()
     {
-        private IDbContextProvider<BusinessDbContext> _dbContextProvider;
+        readonly BusinessDbContext _dbContext;
 
-        public SqlRepository(IDbContextProvider<BusinessDbContext> dbContextProvider)
+        public SqlRepository(BusinessDbContext dbContext)
         {
-            _dbContextProvider = dbContextProvider;
+            _dbContext = dbContext;
         }
         public  async Task<int> Insert(T entity)
         {
-            _dbContextProvider.GetDbContext().Set<T>().Add(entity);
-            return await _dbContextProvider.GetDbContext().SaveChangesAsync();
+            _dbContext.Set<T>().Add(entity);
+            return await _dbContext.SaveChangesAsync();
         }
 
         public async Task<int> Insert(List<T> entitylist)
         {
-            _dbContextProvider.GetDbContext().Set<T>().AddRange(entitylist);
-            return await _dbContextProvider.GetDbContext().SaveChangesAsync();
+            _dbContext.Set<T>().AddRange(entitylist);
+            return await _dbContext.SaveChangesAsync();
         }
 
         public async Task<int> Update(T entity)
         {
-            _dbContextProvider.GetDbContext().Set<T>().Update(entity);
-           return await _dbContextProvider.GetDbContext().SaveChangesAsync();
+            _dbContext.Set<T>().Update(entity);
+           return await _dbContext.SaveChangesAsync();
         }
         public async Task<int> Update(List<T> entitylist)
         {
-            _dbContextProvider.GetDbContext().Set<T>().UpdateRange(entitylist);
-           return await _dbContextProvider.GetDbContext().SaveChangesAsync();
+            _dbContext.Set<T>().UpdateRange(entitylist);
+           return await _dbContext.SaveChangesAsync();
         }
 
         public  async Task<int> Update(Expression<Func<T, bool>> whereLambda, Expression<Func<T, T>> entity)
         {
-            _dbContextProvider.GetDbContext().Set<T>().Where(whereLambda).BatchUpdate(entity);
-            return await _dbContextProvider.GetDbContext().SaveChangesAsync();
+            _dbContext.Set<T>().Where(whereLambda).BatchUpdate(entity);
+            return await _dbContext.SaveChangesAsync();
         }
 
         public  async Task<int> Delete(Expression<Func<T, bool>> whereLambda)
         {
-            _dbContextProvider.GetDbContext().Set<T>().Where(whereLambda).BatchDelete();
-            return await _dbContextProvider.GetDbContext().SaveChangesAsync();
+            _dbContext.Set<T>().Where(whereLambda).BatchDelete();
+            return await _dbContext.SaveChangesAsync();
         }
 
         public  async Task<bool> IsExist(Expression<Func<T, bool>> whereLambda)
         {
-            return await _dbContextProvider.GetDbContext().Set<T>().AnyAsync(whereLambda);
+            return await _dbContext.Set<T>().AnyAsync(whereLambda);
         }
 
         public  async Task<List<T>> Select()
         {
-            return await _dbContextProvider.GetDbContext().Set<T>().ToListAsync();
+            return await _dbContext.Set<T>().ToListAsync();
         }
 
         public  async Task<List<T>> Select(Expression<Func<T, bool>> whereLambda)
         {
-            return await _dbContextProvider.GetDbContext().Set<T>().Where(whereLambda).ToListAsync();
+            return await _dbContext.Set<T>().Where(whereLambda).ToListAsync();
         }
 
         public  async Task<Tuple<List<T>, int>> Select<S>(int pageSize, int pageIndex, Expression<Func<T, bool>> whereLambda, Expression<Func<T, S>> orderByLambda, bool isAsc)
         {
-            var total = _dbContextProvider.GetDbContext().Set<T>().Where(whereLambda).Count();
+            var total = _dbContext.Set<T>().Where(whereLambda).Count();
 
             if (isAsc)
             {
-                var entities = await _dbContextProvider.GetDbContext().Set<T>().Where(whereLambda)
+                var entities = await _dbContext.Set<T>().Where(whereLambda)
                                       .OrderBy<T, S>(orderByLambda)
                                       .Skip(pageSize * (pageIndex - 1))
                                       .Take(pageSize).ToListAsync();
@@ -89,7 +89,7 @@ namespace Business.EntityFrameworkCore.SqlRepositories
             }
             else
             {
-                var entities =await _dbContextProvider.GetDbContext().Set<T>().Where(whereLambda)
+                var entities =await _dbContext.Set<T>().Where(whereLambda)
                                       .OrderByDescending<T, S>(orderByLambda)
                                       .Skip(pageSize * (pageIndex - 1))
                                       .Take(pageSize).ToListAsync();
@@ -103,7 +103,7 @@ namespace Business.EntityFrameworkCore.SqlRepositories
             DataSet ds = new DataSet();
             try
             {
-                string connectionString = _dbContextProvider.GetDbContextAsync().Result.Database.GetDbConnection().ConnectionString;
+                string connectionString = _dbContext.Database.GetConnectionString();
                 SqlDataAdapter da = new SqlDataAdapter(sql, connectionString);
                 da.Fill(ds, tableName);
             }