浏览代码

Merge branch 'develop' of http://132.232.92.186:3000/XinXiBu/OA2023 into develop

yuanrf 7 月之前
父节点
当前提交
49e2eea7fa

+ 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
 

+ 32 - 3
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>
@@ -194,16 +199,40 @@ namespace OASystem.Domain.Dtos.PersonnelModule
     /// </summary>
     public class GoodsReceiveListDTO : DtoBase
     {
-
         /// <summary>
         /// 物品Id
         /// </summary>
         public int GoodsId { get; set; }
 
         /// <summary>
-        /// 当前登录UserId
+        /// 物品Name
+        /// </summary>
+        public string GoodsName { get; set; }
+
+        /// <summary>
+        /// 开始时间
+        /// </summary>
+        public string BeginDt { get; set; }
+
+        /// <summary>
+        /// 结束时间
+        /// </summary>
+        public string EndDt { get; set; }
+
+        /// <summary>
+        /// 类型Ids
+        /// </summary>
+        public string? TypeLabel { get; set; }
+
+        /// <summary>
+        /// UserIds
+        /// </summary>
+        public string? UserLabel { get; set; }
+
+        /// <summary>
+        /// AuditIds
         /// </summary>
-        public int CurrUserId { get; set; }
+        public string AuditLabel { 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
     }
 }

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

@@ -80,6 +80,7 @@ namespace OASystem.Domain.ViewModels.PersonnelModule
     /// </summary>
     public class GoodsReceiveListView: GoodsReceiveView
     {
+        public string GoodsType { get; set; }
     }
     /// <summary>
     /// 
@@ -88,6 +89,9 @@ namespace OASystem.Domain.ViewModels.PersonnelModule
     {
         public string GoodsStorageInfo { get; set; }
         public object? QuantityInfos { get; set; }
+        public object? GoodsStorageInfoStr { get; set; }
+
+        public string GoodsType { get; set; }
     }
 
     /// <summary>

+ 150 - 51
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,
@@ -515,20 +516,80 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
         /// <returns></returns>
         public async Task<JsonView> GoodsReceiveList(GoodsReceiveListDTO dto)
         {
+            //参数处理
+            int[] typeLabel = new int[] { },
+                  userLabel = new int[] { },
+                  auditLabel = new int[] { };
+            if (!string.IsNullOrEmpty(dto.TypeLabel))
+            {
+                typeLabel = dto.TypeLabel
+                    .Split(',')
+                    .Select(x =>
+                    {
+                        if (int.TryParse(x, out var id)) return id;
+                        return id;
+                    })
+                    .ToArray();
+            }
+            if (!string.IsNullOrEmpty(dto.UserLabel))
+            {
+                userLabel = dto.UserLabel
+                    .Split(',')
+                    .Select(x =>
+                    {
+                        if (int.TryParse(x, out var id)) return id;
+                        return id;
+                    })
+                    .ToArray();
+            }
+            if (!string.IsNullOrEmpty(dto.AuditLabel))
+            {
+                auditLabel = dto.AuditLabel
+                    .Split(',')
+                    .Select(x =>
+                    {
+                        if (int.TryParse(x, out var id)) return id;
+                        return id;
+                    })
+                    .ToArray();
+            }
+
+            //物品ID和物品名称只能传一个
+            if (dto.GoodsId > 0) dto.GoodsName = string.Empty;
+            if (!string.IsNullOrEmpty(dto.GoodsName)) dto.GoodsId = 0;
+
+            bool beginBool = false,
+                 endBool = false;
+            DateTime begin = DateTime.Now, 
+                     end = DateTime.Now;
+            if (!string.IsNullOrEmpty(dto.BeginDt) && !string.IsNullOrEmpty(dto.EndDt))
+            {
+                beginBool = DateTime.TryParse($"{dto.BeginDt} 00:00:00", out begin);
+                endBool = DateTime.TryParse($"{dto.EndDt} 23:59:59", out end);
+            }
+
+
+
             RefAsync<int> total = 0;
             var data = await _sqlSugar.Queryable<Pm_GoodsReceive>()
                                       .LeftJoin<Pm_GoodsInfo>((gr, gi) => gr.GoodsId == gi.Id)
-                                      .LeftJoin<Sys_Users>((gr, gi, u1) => gr.AuditUserId == u1.Id)
-                                      .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)
-                                      .Select((gr, gi, u1, u2) => new GoodsReceiveListView
+                                      .LeftJoin<Sys_SetData>((gr, gi,sd) => gi.Type == sd.Id)
+                                      .LeftJoin<Sys_Users>((gr, gi,sd,u1) => gr.AuditUserId == u1.Id)
+                                      .LeftJoin<Sys_Users>((gr, gi,sd, u1, u2) => gr.CreateUserId == u2.Id)
+                                      .Where((gr, gi, sd, u1, u2) => gr.IsDel == 0)
+                                      .WhereIF(dto.GoodsId > 0, (gr, gi, sd, u1, u2) => gr.GoodsId == dto.GoodsId)
+                                      .WhereIF(!string.IsNullOrEmpty(dto.GoodsName), (gr, gi, sd, u1, u2) => gi.Name.Contains(dto.GoodsName))
+                                      .WhereIF(auditLabel.Length > 0, (gr, gi, sd, u1, u2) => auditLabel.Contains((int)gr.AuditStatus))
+                                      .WhereIF(typeLabel.Length > 0, (gr, gi, sd, u1, u2) => typeLabel.Contains(gi.Type))
+                                      .WhereIF(userLabel.Length > 0, (gr, gi, sd, u1, u2) => userLabel.Contains(gr.CreateUserId))
+                                      .WhereIF(beginBool && endBool, (gr, gi, sd, u1, u2) => gr.CreateTime >= begin && gr.CreateTime <= end)
+                                      .Select((gr, gi, sd, u1, u2) => new GoodsReceiveListView
                                       {
                                           Id = gr.Id,
                                           GroupId = gr.GroupId,
                                           GoodsId = gr.GoodsId,
                                           GoodsName = gi.Name,
+                                          GoodsType = sd.Name,
                                           Quantity = gr.Quantity,
                                           Reason = gr.Reason,
                                           Remark = gr.Remark,
@@ -591,6 +652,7 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
                     var subData1 = JsonConvert.DeserializeObject<List<GoodsReceiveLinkStorageView>>(data.GoodsStorageInfo);
                     if (subData1.Count > 0)
                     {
+                        string goodsStorageInfoStr = string.Empty;
                         var storageIds = subData1.Select(x => x.StorageId).ToList();
                         var storages = await _sqlSugar.Queryable<Pm_GoodsStorage>().Where(x => x.IsDel == 0 && storageIds.Contains(x.Id)).ToListAsync();
                         foreach (var item in subData1)
@@ -604,9 +666,11 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
                                     BatchNo = storageInfo.BatchNo,
                                     RecsiveQuantity = item.Quantity
                                 });
+                                goodsStorageInfoStr += $"物品名称:{data.GoodsName} 批次号:{storageInfo.BatchNo} 领用数量:{item.Quantity} \r\n";
                             }
                         }
-                        data.QuantityInfos = data;
+                        data.QuantityInfos = subData;
+                        data.GoodsStorageInfoStr = goodsStorageInfoStr;
                     }
                 }
                 catch (Exception e)
@@ -731,6 +795,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 +807,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 +831,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 +847,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;
+                                }
+                            }
+                        }
+                    }
                 }
             }