LEIYI hai 5 meses
pai
achega
9540607a66

+ 3 - 0
OASystem/OASystem.Api/Controllers/PersonnelModuleController.cs

@@ -1941,6 +1941,9 @@ namespace OASystem.API.Controllers
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
         public async Task<IActionResult> GoodsReceiveList(GoodsReceiveListDTO dto)
         {
+            //var currUserInfo = JwtHelper.SerializeJwt(HttpContext.Request.Headers.Authorization);
+            //if (currUserInfo == null) return Ok(JsonView(false, "请传入token!"));
+
             if (dto.PortType < 1 || dto.PortType > 3) return Ok(JsonView(false, MsgTips.Port));
             if (dto.PageIndex < 1 || dto.PageSize < 1) return Ok(JsonView(false, MsgTips.PageIndex));
 

+ 51 - 1
OASystem/OASystem.Api/Program.cs

@@ -116,7 +116,57 @@ builder.Services.AddScoped(options =>
             ConnectionString = _config.GetConnectionString("OA2014DB"),
             DbType = DbType.SqlServer,
             IsAutoCloseConnection = true },
-    });
+    }
+    //    , db =>
+    //{
+    //    //SQL执行完
+    //    db.Aop.OnLogExecuted = (sql, pars) =>
+    //    {
+    //        //if (db.Ado.SqlExecutionTime.TotalSeconds > 1)
+    //        //{
+    //            //代码CS文件名
+    //            var fileName = db.Ado.SqlStackTrace.FirstFileName;
+    //            //代码行数
+    //            var fileLine = db.Ado.SqlStackTrace.FirstLine;
+    //            //方法名
+    //            var FirstMethodName = db.Ado.SqlStackTrace.FirstMethodName;
+
+    //            //执行完了可以输出SQL执行时间 (OnLogExecutedDelegate) 
+    //            Console.WriteLine("NowTime:" + DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"));
+    //            Console.WriteLine("MethodName:" + FirstMethodName);
+    //            Console.WriteLine("ElapsedTime:" + db.Ado.SqlExecutionTime.ToString());
+    //            Console.WriteLine("ExecuteSQL:" + sql);
+
+    //        //}
+    //    };
+    //    //SQL执行前
+    //    db.Aop.OnLogExecuting = (sql, pars) => 
+    //    {
+    //        //获取原生SQL推荐 5.1.4.63  性能OK
+    //        //UtilMethods.GetNativeSql(sql, pars);
+
+    //        //获取无参数化SQL 影响性能只适合调试
+    //        //UtilMethods.GetSqlString(DbType.SqlServer,sql,pars)
+    //    };
+    //    //SQL报错
+    //    db.Aop.OnError = (exp) =>
+    //    {
+    //        //获取原生SQL推荐 5.1.4.63  性能OK
+    //        //UtilMethods.GetNativeSql(exp.sql, exp.parameters);
+
+    //        //获取无参数SQL对性能有影响,特别大的SQL参数多的,调试使用
+    //        //UtilMethods.GetSqlString(DbType.SqlServer, exp.sql, exp.parameters);
+    //    };
+    //    //修改SQL和参数的值
+    //    db.Aop.OnExecutingChangeSql = (sql, pars) => 
+    //    {
+    //        //sql=newsql
+    //        //foreach(var p in pars) //修改
+    //        return new KeyValuePair<string, SugarParameter[]>(sql, pars);
+    //    };
+
+    //}
+    );
 });
 #endregion
 

+ 5 - 0
OASystem/OASystem.Domain/Dtos/PersonnelModule/GoodsDTO.cs

@@ -91,6 +91,11 @@ namespace OASystem.Domain.Dtos.PersonnelModule
         /// 物品Id
         /// </summary>
         public int GoodsId { get; set; }
+
+        /// <summary>
+        /// 入库批次号
+        /// </summary>
+        public string? BatchNo { get; set; }
     }
 
     /// <summary>

+ 2 - 2
OASystem/OASystem.Domain/Enums/GoodsAuditEnum.cs

@@ -20,12 +20,12 @@ namespace OASystem.Domain.Enums
         /// <summary>
         /// 已通过审核
         /// </summary>
-        [Description("已通过审核")]
+        [Description("已通过")]
         Approved,
         /// <summary>
         /// 已拒绝审核
         /// </summary>
-        [Description("未通过审核")]
+        [Description("未通过")]
         UnApproved
     }
 }

+ 2 - 0
OASystem/OASystem.Domain/ViewModels/PersonnelModule/GoodsInfoView.cs

@@ -88,6 +88,8 @@ namespace OASystem.Domain.ViewModels.PersonnelModule
     {
         public string GoodsStorageInfo { get; set; }
         public object? QuantityInfos { get; set; }
+
+        public string GoodsStorageInfoStr { get; set; }
     }
 
     /// <summary>

+ 84 - 46
OASystem/OASystem.Infrastructure/Repositories/PersonnelModule/GoodsRepository.cs

@@ -284,6 +284,7 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
                                       .LeftJoin<Sys_Users>((gs, gi, u, u1) => gs.StorageUserId == u1.Id)
                                       .Where((gs, gi, u, u1) => gs.IsDel == 0)
                                       .WhereIF(dto.GoodsId > 0, (gs, gi, u, u1) => gs.GoodsId == dto.GoodsId)
+                                      .WhereIF(!string.IsNullOrEmpty(dto.BatchNo), (gs, gi, u, u1) => gs.BatchNo.Contains(dto.BatchNo))
                                       .Select((gs, gi, u, u1) => new
                                       {
                                           gs.Id,
@@ -291,6 +292,8 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
                                           gs.BatchNo,
                                           GoodsName = gi.Name,
                                           gs.Quantity,
+                                          gs.ReceiveQuantity,
+                                          QuantityStatusText = gs.Quantity - gs.ReceiveQuantity == 0 ? "已领用完" : "-",
                                           gs.UnitPrice,
                                           gs.TotalPrice,
                                           gs.SupplierName,
@@ -522,7 +525,7 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
                                       .LeftJoin<Sys_Users>((gr, gi, u1, u2) => gr.CreateUserId == u2.Id)
                                       .Where((gr, gi, u1, u2) => gr.IsDel == 0)
                                       .WhereIF(dto.GoodsId > 0, (gr, gi, u1, u2) => gr.GoodsId == dto.GoodsId)
-                                      .WhereIF(dto.GoodsId > 0, (gr, gi, u1, u2) => gr.CreateUserId == dto.CurrUserId)
+                                      .WhereIF(dto.CurrUserId > 0, (gr, gi, u1, u2) => gr.CreateUserId == dto.CurrUserId)
                                       .Select((gr, gi, u1, u2) => new GoodsReceiveListView
                                       {
                                           Id = gr.Id,
@@ -606,7 +609,7 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
                                 });
                             }
                         }
-                        data.QuantityInfos = data;
+                        data.QuantityInfos = subData;
                     }
                 }
                 catch (Exception e)
@@ -731,6 +734,7 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
             {
                 //1.更改审核状态
                 var currInfo = receiveInfos.Find(x => x.Id == id);
+                if (currInfo == null) continue;
                 var edit = await _sqlSugar.Updateable<Pm_GoodsReceive>()
                                              .SetColumns(x => new Pm_GoodsReceive()
                                              {
@@ -742,12 +746,19 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
                                              .ExecuteCommandAsync();
                 if (edit < 1) status = false;
 
-                if (auditEnum != GoodsAuditEnum.Approved) continue;
-
+                //if (auditEnum != GoodsAuditEnum.Approved) continue;
                 //2.更改库存
                 var goodsInfo = await _sqlSugar.Queryable<Pm_GoodsInfo>().Where(x => x.Id == currInfo.GoodsId).FirstAsync();
-                goodsInfo.StockQuantity = goodsInfo.StockQuantity - currInfo.Quantity;
-                goodsInfo.OQ_Total += currInfo.Quantity;
+                if (auditEnum == GoodsAuditEnum.Pending) 
+                {
+                    goodsInfo.StockQuantity += currInfo.Quantity;
+                    goodsInfo.OQ_Total -= currInfo.Quantity;
+                }
+                else if (auditEnum == GoodsAuditEnum.Approved)
+                {
+                    goodsInfo.StockQuantity -= currInfo.Quantity;
+                    goodsInfo.OQ_Total += currInfo.Quantity;
+                }else if(auditEnum == GoodsAuditEnum.UnApproved) continue;
                 goodsInfo.LastUpdateTime = DateTime.Now;
                 goodsInfo.LastUpdateUserId = userId;
 
@@ -759,7 +770,7 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
                                                        x.LastUpdateUserId,
                                                        x.LastUpdateTime,
                                                    })
-                                                   .Where(x => x.Id == id)
+                                                   .Where(x => x.Id == currInfo.GoodsId)
                                                    .ExecuteCommandAsync();
 
                 if (editGoods < 1) status = false;
@@ -775,53 +786,80 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
                 var goodsReceiveInfos = new List<GoodsReceiveLinkStorageView>();
                 var batchStorageInfos = new List<Pm_GoodsStorage>();
                 var receiveQuantity = 0.00M; //领用总数量
-                foreach (var storage in goodsStorages)
+                if (auditEnum == GoodsAuditEnum.Approved)
                 {
-                    if (currInfo.Quantity == receiveQuantity) break;
+                    foreach (var storage in goodsStorages)
+                    {
+                        if (currInfo.Quantity == receiveQuantity) break;
 
-                    var thisBatchSurplusQuantity = storage.Quantity - storage.ReceiveQuantity;
-                    if (thisBatchSurplusQuantity <= 0.00M) continue;
+                        var thisBatchSurplusQuantity = storage.Quantity - storage.ReceiveQuantity;
+                        if (thisBatchSurplusQuantity <= 0.00M) continue;
 
-                    var thisBatchReceiveQuantity = 0.00M; //此批次领用数量
-                    const decimal unit = 0.50M;
-                    while (receiveQuantity < currInfo.Quantity)
-                    {
-                        if (thisBatchSurplusQuantity == thisBatchReceiveQuantity) break;
+                        var thisBatchReceiveQuantity = 0.00M; //此批次领用数量
+                        const decimal unit = 0.50M;
+                        while (receiveQuantity < currInfo.Quantity)
+                        {
+                            if (thisBatchSurplusQuantity == thisBatchReceiveQuantity) break;
 
-                        thisBatchReceiveQuantity += unit;
-                        receiveQuantity += unit;
+                            thisBatchReceiveQuantity += unit;
+                            receiveQuantity += unit;
+                        }
+                        goodsReceiveInfos.Add(new GoodsReceiveLinkStorageView
+                        {
+                            StorageId = storage.Id,
+                            Quantity = thisBatchReceiveQuantity
+                        });
+                        storage.ReceiveQuantity += thisBatchReceiveQuantity;
+                        var storageUpd = storage;
+                        //storageUpd.ReceiveQuantity += thisBatchReceiveQuantity;
+                        batchStorageInfos.Add(storageUpd);
                     }
-                    goodsReceiveInfos.Add(new GoodsReceiveLinkStorageView
+                    //3.1 更改批次库存
+                    if (goodsReceiveInfos.Count > 0)
                     {
-                        StorageId = storage.Id,
-                        Quantity = thisBatchReceiveQuantity
-                    });
-                    storage.ReceiveQuantity += thisBatchReceiveQuantity;
-                    var storageUpd = storage;
-                    //storageUpd.ReceiveQuantity += thisBatchReceiveQuantity;
-                    batchStorageInfos.Add(storageUpd);
-                }
-                //3.1 更改批次库存
-                if (goodsReceiveInfos.Count > 0)
-                {
-                    var edit1 = await _sqlSugar.Updateable(batchStorageInfos)
-                                                   .UpdateColumns(x => x.ReceiveQuantity)
-                                                   .WhereColumns(x => x.Id)
-                                                   .ExecuteCommandAsync();
-                    if (edit1 < 1) status = false;
-                }
+                        var edit1 = await _sqlSugar.Updateable(batchStorageInfos)
+                            .UpdateColumns(x => x.ReceiveQuantity)
+                            .WhereColumns(x => x.Id)
+                            .ExecuteCommandAsync();
+                        if (edit1 < 1) status = false;
+                    }
 
-                //3.2 添加入库批次关联领用人
-                if (goodsReceiveInfos.Count > 0)
+                    //3.2 添加入库批次关联领用人
+                    if (goodsReceiveInfos.Count > 0)
+                    {
+                        var edit1 = await _sqlSugar.Updateable<Pm_GoodsReceive>()
+                            .SetColumns(x => new Pm_GoodsReceive()
+                            {
+                                GoodsStorageInfo = JsonConvert.SerializeObject(goodsReceiveInfos)
+                            })
+                            .Where(x => x.Id == id)
+                            .ExecuteCommandAsync();
+                        if (edit1 < 1) status = false;
+                    }
+                }
+                else if (auditEnum == GoodsAuditEnum.Pending)
                 {
-                    var edit1 = await _sqlSugar.Updateable<Pm_GoodsReceive>()
-                                                   .SetColumns(x => new Pm_GoodsReceive()
-                                                   {
-                                                       GoodsStorageInfo = JsonConvert.SerializeObject(goodsReceiveInfos)
-                                                   })
-                                                   .Where(x => x.Id == id)
-                                                   .ExecuteCommandAsync();
-                    if (edit1 < 1) status = false;
+                    var goodsStorageInfo = currInfo.GoodsStorageInfo;
+                    if (!string.IsNullOrEmpty(goodsStorageInfo))
+                    {
+                        var goodsStorageInfos = JsonConvert.DeserializeObject<List<GoodsReceiveLinkStorageView>>(goodsStorageInfo);
+                        if (goodsStorageInfos.Count > 0)
+                        {
+                            foreach (var item in goodsStorageInfos)
+                            {
+                                var newStorageInfo = await _sqlSugar.Queryable<Pm_GoodsStorage>()
+                                    .Where(x => x.IsDel == 0 && x.Id == item.StorageId)
+                                    .FirstAsync();
+                                if (newStorageInfo != null)
+                                {
+                                    var newEdit = await _sqlSugar.Updateable(newStorageInfo)
+                                        .ReSetValue(x => x.ReceiveQuantity = x.ReceiveQuantity - item.Quantity)
+                                        .ExecuteCommandAsync();
+                                    if (newEdit < 1) status = false;
+                                }
+                            }
+                        }
+                    }
                 }
             }