Browse Source

增强日志记录与物品管理功能

在多个文件中进行了重要更新:
- 在 `Program.cs` 中添加了对 `OASystem.Domain.Entities.Financial` 的引用,增加了 SQL 执行日志功能。
- 在 `FinancialController.cs` 和 `DailyFeePaymentRepository.cs` 中添加了日志记录的依赖注入。
- 在 `PersonnelModuleController.cs` 和 `GoodsDTO.cs` 中添加了 `IsReplace` 属性,以处理物品是否需要归还的逻辑。
- 更新了 `OASystem.API.csproj` 中的 `Serilog` 版本,增强了日志记录能力。
- 在 `GoodsRepository.cs` 中调整了物品入库和审核逻辑,确保状态处理的准确性。
- 定义了新的实体类 `Fin_ApplicationLinkGoods`,用于表示日付申请单与物品的关联。
Lyyyi 4 days ago
parent
commit
d930259d22

+ 18 - 8
OASystem/EntitySync/Program.cs

@@ -1,4 +1,5 @@
-using OASystem.Domain.Entities.Groups;
+using OASystem.Domain.Entities.Financial;
+using OASystem.Domain.Entities.Groups;
 using OASystem.Domain.Entities.PersonnelModule;
 using OASystem.Domain.Entities.Resource;
 using OASystem.Domain.Entities.System;
@@ -10,7 +11,14 @@ var db = new SqlSugarClient(new ConnectionConfig()
     DbType = DbType.SqlServer,
     IsAutoCloseConnection = true,
     InitKeyType = InitKeyType.Attribute
-});
+},
+    provider =>
+    {
+        provider.Aop.OnLogExecuting = (sql, pars) =>
+        {
+            Console.WriteLine(sql); // 输出生成的 SQL
+        };
+    });
 
 #region Aop
 //db.Aop.OnLogExecuting = (sql, pars) =>
@@ -37,6 +45,7 @@ else
 
 //同步数据表结构
 db.DbMaintenance.CreateDatabase();
+
 db.CodeFirst.SetStringDefaultLength(50).BackupTable().InitTables(new Type[]
 {
     //typeof(Sys_PageFunctionPermission)
@@ -156,12 +165,13 @@ db.CodeFirst.SetStringDefaultLength(50).BackupTable().InitTables(new Type[]
     //typeof(Grp_GroupShareFile),//团组共享文件 
     //typeof(Pm_GoodsAudit),//物品确认审核表 
     
-    typeof(Pm_GoodsReceiveDetails),//物品领用明细表 
+    //typeof(Pm_GoodsReceiveDetails),//物品领用明细表 
     /*审核流程相关表*/
-    typeof(Sys_AuditFlow),//审核流程表 
-    typeof(Sys_AuditRecord),//审核记录表 
-    typeof(Sys_AuditTemplate),//审核模板表 
-    typeof(Sys_AuditTemplateNode),//审核模板节点表 
-    typeof(Sys_AuditTemplateNodeUser),//审核模板节点人员表 
+    //typeof(Sys_AuditFlow),//审核流程表 
+    //typeof(Sys_AuditRecord),//审核记录表 
+    //typeof(Sys_AuditTemplate),//审核模板表 
+    //typeof(Sys_AuditTemplateNode),//审核模板节点表 
+    //typeof(Sys_AuditTemplateNodeUser),//审核模板节点人员表 
+    typeof(Fin_ApplicationLinkGoods),//日服申请单物品关联表 
 }); 
 Console.WriteLine("数据库结构同步完成!");

+ 16 - 3
OASystem/OASystem.Api/Controllers/FinancialController.cs

@@ -40,6 +40,7 @@ namespace OASystem.API.Controllers
     {
         private readonly IMapper _mapper;
         private readonly IConfiguration _config;
+        private readonly ILogger<FinancialController> _logger;
         private readonly SqlSugarClient _sqlSugar;
         private readonly HttpClient _httpClient;
         private readonly SetDataTypeRepository _setDataTypeRep;
@@ -55,13 +56,25 @@ namespace OASystem.API.Controllers
         /// <summary>
         /// 初始化
         /// </summary>
-        public FinancialController(IMapper mapper, IConfiguration configuration, DailyFeePaymentRepository daiRep, SqlSugarClient sqlSugar, SetDataTypeRepository setDataTypeRep,
-            TeamRateRepository teamRateRep, ForeignReceivablesRepository ForForeignReceivablesRep, ProceedsReceivedRepository proceedsReceivedRep,
-            PaymentRefundAndOtherMoneyRepository paymentRefundAndOtherMoneyRep, HttpClient httpClient, DelegationInfoRepository delegationInfoRep, SetDataRepository setDataRep,
+        public FinancialController(
+            IMapper mapper, 
+            IConfiguration configuration,
+            ILogger<FinancialController> logger,
+            DailyFeePaymentRepository daiRep, 
+            SqlSugarClient sqlSugar, 
+            SetDataTypeRepository setDataTypeRep,
+            TeamRateRepository teamRateRep, 
+            ForeignReceivablesRepository ForForeignReceivablesRep, 
+            ProceedsReceivedRepository proceedsReceivedRep,
+            PaymentRefundAndOtherMoneyRepository paymentRefundAndOtherMoneyRep, 
+            HttpClient httpClient, 
+            DelegationInfoRepository delegationInfoRep, 
+            SetDataRepository setDataRep,
             ForeignReceivablesRepository foreignReceivablesRepository)
         {
             _mapper = mapper;
             _config = configuration;
+            _logger = logger;
             _daiRep = daiRep;
             _sqlSugar = sqlSugar;
             _setDataTypeRep = setDataTypeRep;

+ 10 - 7
OASystem/OASystem.Api/Controllers/PersonnelModuleController.cs

@@ -1,9 +1,7 @@
 using Aspose.Cells;
 using FluentValidation;
 using Microsoft.AspNetCore.SignalR;
-using NPOI.XSSF.Model;
 using OASystem.API.OAMethodLib;
-using OASystem.API.OAMethodLib.APNs;
 using OASystem.API.OAMethodLib.Hub.HubClients;
 using OASystem.API.OAMethodLib.Hub.Hubs;
 using OASystem.API.OAMethodLib.QiYeWeChatAPI;
@@ -14,14 +12,12 @@ using OASystem.Domain.Entities.Groups;
 using OASystem.Domain.Entities.PersonnelModule;
 using OASystem.Domain.ViewModels.PersonnelModule;
 using OASystem.Domain.ViewModels.QiYeWeChat;
-using OASystem.Domain.ViewModels.Statistics;
 using OASystem.Infrastructure.Repositories.Groups;
 using OASystem.Infrastructure.Repositories.PersonnelModule;
 using System.Data;
 using System.Diagnostics;
 using System.Globalization;
 using static OASystem.API.OAMethodLib.JWTHelper;
-using static OpenAI.GPT3.ObjectModels.SharedModels.IOpenAiModels;
 
 namespace OASystem.API.Controllers
 {
@@ -2050,7 +2046,7 @@ WHERE
             if (dto.IsExcelDownload)
             {
                 if (userId < 1) return Ok(JsonView(false, "excel导出时,需传入正确的当前操作人UserId!"));
-;
+                ;
                 #region 页面操作权限验证
                 PageFunAuthViewBase pageFunAuthView = await GeneralMethod.PostUserPageFuncDatas(userId, pageId);
                 if (pageFunAuthView.FilesDownloadAuth == 0) return Ok(JsonView(false, "您未分配文件下载权限!"));
@@ -2135,6 +2131,7 @@ WHERE
                 ReceiveDetails = receiveDetails,
                 Reason = dto.Reason,
                 Remark = dto.Remark,
+                IsReplace = dto.IsReplace,
                 CurrUserId = currUserInfo.UserId,
             };
 
@@ -2186,7 +2183,7 @@ WHERE
             var view = await _goodsRep.GoodsReceiveAudit(idArray, currUserInfo.UserId, dto.AuditEnum);
             //var view = new JsonView() { Code = StatusCodes.Status200OK};
             //TODO:出库成功 并且是团组相关物资 向团组其他款项添加信息
-            #region 出库成功并且是团组相关物资 向团组其他款项添加信息
+            #region 出库成功 && 不需要归还的物资(IsReplace == false) && 团组相关物资 向团组其他款项添加信息
 
             if (view.Code != StatusCodes.Status200OK) return Ok(view);
 
@@ -2197,6 +2194,12 @@ WHERE
             var receiveInfo = await _sqlSugar.Queryable<Pm_GoodsReceive>().FirstAsync(x => x.IsDel == 0 && x.Id == receiveId);
             if (receiveInfo == null) return Ok(view);
 
+            if (receiveInfo.IsReplace)
+            {
+                view.Msg += $"\r\n 需要归还的物资不向团组其他款项添加信息!";
+                return Ok(view);
+            }
+
             var auditEnums = new List<GoodsAuditEnum>() { GoodsAuditEnum.OutConfirmed, GoodsAuditEnum.OutRejected };
             if (!auditEnums.Contains(receiveInfo.AuditStatus)) return Ok(view);
 
@@ -2352,7 +2355,7 @@ WHERE
                 //物资领用通知
                 await AppNoticeLibrary.SendUserMsg_CompanyShare_ToHR(sign, dto.GroupId, dto.CurrUserId);
             }
-            
+
             return Ok(res);
         }
 

+ 4 - 1
OASystem/OASystem.Api/OASystem.API.csproj

@@ -49,7 +49,10 @@
     <PackageReference Include="Quartz" Version="3.6.2" />
     <PackageReference Include="QuartzUI.Extension.AspNetCore" Version="1.1.8" />
     <PackageReference Include="RestSharp" Version="106.15.0" />
-    <PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
+    <PackageReference Include="Serilog" Version="4.0.0" />
+    <PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
+    <PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
+    <PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
     <PackageReference Include="SqlSugarCore" Version="5.1.3.35" />
     <PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
     <PackageReference Include="System.Data.OleDb" Version="8.0.0" />

+ 12 - 0
OASystem/OASystem.Api/Program.cs

@@ -15,6 +15,7 @@ using Quartz;
 using Quartz.Impl;
 using Quartz.Spi;
 using QuzrtzJob.Factory;
+using Serilog.Formatting.Compact;
 
 Console.Title = $"FMGJ OASystem Server";
 var builder = WebApplication.CreateBuilder(args);
@@ -291,8 +292,13 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
 #region 初始化日志
 Log.Logger = new LoggerConfiguration()
        .MinimumLevel.Debug()
+       .Enrich.FromLogContext()
+       .WriteTo.Console()
        .WriteTo.File(Path.Combine("Logs", @"Log.txt"), rollingInterval: RollingInterval.Day)
        .CreateLogger();
+
+// 配置Serilog为Log;
+builder.Host.UseSerilog();
 #endregion
 
 #region 引入注册Autofac Module
@@ -390,6 +396,12 @@ builder.Services.TryAddSingleton(typeof(CommonService));
 
 var app = builder.Build();
 
+//serilog日志 请求中间管道
+app.UseSerilogRequestLogging(options =>
+{
+    options.MessageTemplate = "HTTP {RequestMethod} {RequestPath} responded {StatusCode} in {Elapsed:0.0000}ms";
+});
+
 AutofacIocManager.Instance.Container = app.UseHostFiltering().ApplicationServices.GetAutofacRoot();//AutofacIocManager
 
 // Configure the HTTP request pipeline.

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

@@ -340,6 +340,11 @@ namespace OASystem.Domain.Dtos.PersonnelModule
         /// </summary>
         public string? Reason { get; set; }
 
+        /// <summary>
+        /// 是否归还
+        /// </summary>
+        public bool IsReplace { get; set; } = false;
+
         /// <summary>
         /// 备注
         /// </summary>
@@ -398,6 +403,11 @@ namespace OASystem.Domain.Dtos.PersonnelModule
         /// </summary>
         public string? Reason { get; set; }
 
+        /// <summary>
+        /// 是否归还
+        /// </summary>
+        public bool IsReplace { get; set; }
+
         /// <summary>
         /// 备注
         /// </summary>

+ 66 - 0
OASystem/OASystem.Domain/Entities/Financial/Fin_ApplicationLinkGoods.cs

@@ -0,0 +1,66 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.Entities.Financial
+{
+    /// <summary>
+    /// 日服申请单物品关联表
+    /// </summary>
+    [SugarTable(tableName: "Fin_ApplicationLinkGoods", tableDescription: "日服申请单物品关联表")]
+    public class Fin_ApplicationLinkGoods : EntityBase
+    {
+        /// <summary>
+        /// 日付申请Id(Fin_DailyFeePayment)
+        /// </summary>
+        [SugarColumn(ColumnName = "DailyId", ColumnDescription = "日付申请Id(Fin_DailyFeePayment)", IsNullable = true, ColumnDataType = "int")]
+        public int DailyId { get; private set; }
+
+        /// <summary>
+        /// 物品Id(Pm_GoodsInfo)
+        /// </summary>
+        [SugarColumn(ColumnName = "GoodsId", ColumnDescription = "物品Id(Pm_GoodsInfo)", IsNullable = true, ColumnDataType = "int")]
+        public int GoodsId { get; private set; }
+
+        /// <summary>
+        /// 物品入库Id(Pm_GoodsStorage)
+        /// </summary>
+        [SugarColumn(ColumnName = "GoodsStorageId", ColumnDescription = "物品入库Id(Pm_GoodsStorage)", IsNullable = true, ColumnDataType = "int")]
+        public int GoodsStorageId { get; private set; }
+
+        public Fin_ApplicationLinkGoods() { }
+
+        /// <summary>
+        /// info
+        /// 构造函数
+        /// </summary>
+        /// <param name="id"></param>
+        /// <param name="dailyId"></param>
+        /// <param name="goodsId"></param>
+        /// <param name="goodsStorageId"></param>
+        /// <param name="remark"></param>
+        /// <param name="userId"></param>
+        public Fin_ApplicationLinkGoods(int id, int dailyId, int goodsId, int goodsStorageId, string remark, int userId)
+        {
+            Id = id;
+            DailyId = dailyId;
+            GoodsId = goodsId;
+            GoodsStorageId = goodsStorageId;
+            Remark = remark;
+            CreateUserId = userId;
+            CreateTime = DateTime.Now;
+        }
+
+        /// <summary>
+        /// 删除赋值构造函数
+        /// </summary>
+        /// <param name="userId"></param>
+        public Fin_ApplicationLinkGoods(int userId)
+        {
+            DeleteUserId = userId;
+            DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
+        }
+    }
+}

+ 5 - 0
OASystem/OASystem.Domain/Entities/PersonnelModule/Pm_GoodsReceive.cs

@@ -78,5 +78,10 @@ namespace OASystem.Domain.Entities.PersonnelModule
         public string StatusDesc { get; set; }
         // = string.Format("领用确认:状态:待确认  审核人:-  审核时间:-;<br/>人事部:状态:待确认  审核人:-  审核时间:-;<br/>财务部:状态:待确认  审核人:-  审核时间:-;");
 
+        /// <summary>
+        /// 是否归还
+        /// </summary>
+        [SugarColumn(ColumnDescription = "是否归还", IsNullable = true, ColumnDataType = "bit")]
+        public bool IsReplace { get; set; } = false;
     }
 }

+ 2 - 0
OASystem/OASystem.Domain/ViewModels/Financial/Fin_DailyFeePaymentView.cs

@@ -226,6 +226,7 @@ namespace OASystem.Domain.ViewModels.Financial
                 if (FAudit == 0) str = "未审核";
                 else if (FAudit == 1) str = "已通过";
                 else if (FAudit == 2) str = "未通过";
+                else if (FAudit == 3) str = "自动审核";
                 return str;
             }
         }
@@ -243,6 +244,7 @@ namespace OASystem.Domain.ViewModels.Financial
                 if (MAudit == 0) str = "未审核";
                 else if (MAudit == 1) str = "已通过";
                 else if (MAudit == 2) str = "未通过";
+                else if (MAudit == 3) str = "自动审核";
                 return str;
             }
         }

+ 1 - 0
OASystem/OASystem.Infrastructure/OASystem.Infrastructure.csproj

@@ -25,6 +25,7 @@
     <PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
     <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
     <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.0" />
+    <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" />
     <PackageReference Include="NPOI" Version="2.6.0" />
     <PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
     <PackageReference Include="SqlSugarCore" Version="5.1.3.32" />

+ 207 - 60
OASystem/OASystem.Infrastructure/Repositories/Financial/DailyFeePaymentRepository.cs

@@ -1,19 +1,16 @@
 using AutoMapper;
-using NPOI.SS.Formula.Functions;
+using Microsoft.Extensions.Logging;
+using Serilog;
+using Newtonsoft.Json;
 using OASystem.Domain;
 using OASystem.Domain.Dtos;
 using OASystem.Domain.Dtos.Financial;
+using OASystem.Domain.Dtos.PersonnelModule;
 using OASystem.Domain.Entities.Financial;
-using OASystem.Domain.Entities.Groups;
+using OASystem.Domain.Entities.PersonnelModule;
 using OASystem.Domain.ViewModels.Financial;
+using OASystem.Infrastructure.Repositories.PersonnelModule;
 using OASystem.Infrastructure.Repositories.System;
-using System;
-using System.Collections.Generic;
-using System.ComponentModel.Design;
-using System.Linq;
-using System.Runtime.Intrinsics.Arm;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace OASystem.Infrastructure.Repositories.Financial
 {
@@ -23,9 +20,11 @@ namespace OASystem.Infrastructure.Repositories.Financial
     public class DailyFeePaymentRepository : BaseRepository<Fin_DailyFeePayment, Fin_DailyFeePaymentView>
     {
         private readonly IMapper _mapper;
-        private readonly System.SetDataTypeRepository _setDataTypeRep;
-        private readonly System.UsersRepository _UsersRep;
-        private readonly System.CompanyRepository _CompanyRep;
+        private readonly SetDataTypeRepository _setDataTypeRep;
+        private readonly UsersRepository _UsersRep;
+        private readonly CompanyRepository _CompanyRep;
+        private readonly GoodsRepository _goodsRep;
+        private readonly ILogger<DailyFeePaymentRepository> _logger;
 
         /// <summary>
         /// 
@@ -35,17 +34,23 @@ namespace OASystem.Infrastructure.Repositories.Financial
         /// <param name="setDataTypeRep"></param>
         /// <param name="usersRep"></param>
         /// <param name="companyRep"></param>
-        public DailyFeePaymentRepository(SqlSugarClient sqlSugar, 
-            IMapper mapper, 
-            System.SetDataTypeRepository setDataTypeRep,
-            UsersRepository usersRep, 
-            CompanyRepository companyRep)
+        /// <param name="goodsRep"></param>
+        /// <param name="logger"></param>
+        public DailyFeePaymentRepository(SqlSugarClient sqlSugar,
+            IMapper mapper,
+            SetDataTypeRepository setDataTypeRep,
+            UsersRepository usersRep,
+            CompanyRepository companyRep,
+            GoodsRepository goodsRep,
+            ILogger<DailyFeePaymentRepository> logger)
             : base(sqlSugar)
         {
-            this._mapper = mapper;
-            this._setDataTypeRep = setDataTypeRep;
-            this._UsersRep = usersRep;
-            this._CompanyRep = companyRep;
+            _mapper = mapper;
+            _setDataTypeRep = setDataTypeRep;
+            _UsersRep = usersRep;
+            _CompanyRep = companyRep;
+            _goodsRep = goodsRep;
+            _logger = logger;
         }
 
         /// <summary>
@@ -114,9 +119,9 @@ namespace OASystem.Infrastructure.Repositories.Financial
                 else
                 {
                     userData.Insert(0, new { Id = -1, CnName = "全部", DepId = 0, DepName = "", JobPostId = 0, JobName = "" });
-                }                     
-                                      
-            }                         
+                }
+
+            }
             var userData1 = userData.Select(x => new { x.Id, x.CnName }).ToList();
 
             //62 公转 63 私转        
@@ -136,7 +141,7 @@ namespace OASystem.Infrastructure.Repositories.Financial
 
             if (dto.PortType == 1) //web
             {
-                DailyFeePaymentList = new 
+                DailyFeePaymentList = new
                 {
                     FeeTypeData = priceTypeData,
                     FeeSubTypeData = priceSubTypeData,
@@ -169,6 +174,7 @@ namespace OASystem.Infrastructure.Repositories.Financial
         /// 90 Parent 各部门基础固定费用明细  
         /// 104 Parent 团组费用
         /// 672 Sub 办公费用-信息部申请费用
+        /// 1433 Sub 团组/会务储备物资采购
         /// </summary>
         /// <param name="typeId"></param>
         /// <returns></returns>
@@ -176,14 +182,15 @@ namespace OASystem.Infrastructure.Repositories.Financial
         {
             if (typeId < 1) return false;
 
-            var parentIds = new List<int>() 
-                {   
+            var parentIds = new List<int>()
+                {
                     90,  // 各部门基础固定费用明细
                     104, // 团组费用
                 };
             var subIds = new List<int>()
                 {
-                    672, //办公费用-信息部申请费用
+                    672,  //办公费用-信息部申请费用
+                    1433, //团组/会务储备物资采购
                 };
 
             var parentTypeDatas = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && parentIds.Contains(x.STid)).ToListAsync();
@@ -206,7 +213,7 @@ namespace OASystem.Infrastructure.Repositories.Financial
         /// <returns></returns>
         public async Task<Result> GetPriceTypeAddData(PortDtoBase dto)
         {
-            Result result = new Result() { Code = -2 };
+            Result result = new() { Code = -2 };
 
             dynamic? DailyFeePaymentList = null;
 
@@ -420,7 +427,7 @@ namespace OASystem.Infrastructure.Repositories.Financial
             _fee.GroupId = dto.GroupId;
 
             //自动审核验证
-            var auditPer  = await GMAutoApprovalType(dto.PriceTypeId);
+            var auditPer = await GMAutoApprovalType(dto.PriceTypeId);
             var priceTypeInfo = await _sqlSugar.Queryable<Sys_SetData>().FirstAsync(x => x.IsDel == 0 && x.Id == dto.PriceTypeId);
             if (auditPer)
             {
@@ -558,13 +565,13 @@ namespace OASystem.Infrastructure.Repositories.Financial
             Result result = new Result() { Code = -2 };
 
             int? delFeeStatus = await _sqlSugar.Updateable<Fin_DailyFeePayment>()
-                                  .Where(a => a.Id == dto.Id)
-                                  .SetColumns(a => new Fin_DailyFeePayment
-                                  {
-                                      IsDel = 1,
-                                      DeleteUserId = dto.Id,
-                                      DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
-                                  }).ExecuteCommandAsync();
+                .Where(a => a.Id == dto.Id)
+                .SetColumns(a => new Fin_DailyFeePayment
+                {
+                    IsDel = 1,
+                    DeleteUserId = dto.UserId,
+                    DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
+                }).ExecuteCommandAsync();
 
             result.Code = 0;
             return result;
@@ -581,36 +588,176 @@ namespace OASystem.Infrastructure.Repositories.Financial
 
             if (dto.AuditType == 1) //财务审核
             {
-                int? auditStatus = await _sqlSugar.Updateable<Fin_DailyFeePayment>()
-                                  .Where(a => a.Id == dto.Id)
-                                  .SetColumns(a => new Fin_DailyFeePayment
-                                  {
-                                      FAudit = dto.AuditStatus,
-                                      FAuditDate = DateTime.Now,
-                                  }).ExecuteCommandAsync();
-                if (auditStatus != null && auditStatus > 0)
-                    result.Code = 0;
-                else
-                    result.Msg = "财务审核操作失败";
+                int auditStatus = await _sqlSugar.Updateable<Fin_DailyFeePayment>()
+                    .Where(a => a.Id == dto.Id)
+                    .SetColumns(a => new Fin_DailyFeePayment
+                    {
+                        FAudit = dto.AuditStatus,
+                        FAuditDate = DateTime.Now,
+                    }).ExecuteCommandAsync();
+                if (auditStatus > 0) result.Code = 0;
+                else result.Msg = "财务审核操作失败";
             }
             else if (dto.AuditType == 2) //总经理
             {
-                int? auditStatus = await _sqlSugar.Updateable<Fin_DailyFeePayment>()
-                                  .Where(a => a.Id == dto.Id)
-                                  .SetColumns(a => new Fin_DailyFeePayment
-                                  {
-                                      MAudit = dto.AuditStatus,
-                                      MAuditDate = DateTime.Now,
-                                  }).ExecuteCommandAsync();
-
-                if (auditStatus != null && auditStatus > 0)
-                    result.Code = 0;
-                else
-                    result.Msg = "总经理审核操作失败";
+                int auditStatus = await _sqlSugar.Updateable<Fin_DailyFeePayment>()
+                    .Where(a => a.Id == dto.Id)
+                    .SetColumns(a => new Fin_DailyFeePayment
+                    {
+                        MAudit = dto.AuditStatus,
+                        MAuditDate = DateTime.Now,
+                    }).ExecuteCommandAsync();
+                if (auditStatus > 0) result.Code = 0;
+                else result.Msg = "总经理审核操作失败";
             }
+
+            #region 审核完全通过 指定类型 向物资添加信息
+            //费用类型
+            var feeTypeIds = new List<int>() {
+                1433,    //团组/会务储备物资采购
+                1435,    //公司固定物资采购
+            };
+
+            //审核状态集合
+            var auditStatuses = new List<int>() {
+                1,  //审核通过
+                3,  //自动审核 
+            };
+
+            var dailyInfo = await _sqlSugar.Queryable<Fin_DailyFeePayment>()
+                .FirstAsync(x => x.Id == dto.Id && x.IsDel == 0 &&
+                                 auditStatuses.Contains(x.MAudit) &&
+                                 auditStatuses.Contains(x.FAudit) &&
+                                 feeTypeIds.Contains(x.PriceTypeId));
+            if (dailyInfo != null)
+            {
+                //执行物资添加、入库、关联信息操作
+                var linkOpRes = await ApplicationLinkGoodsAddAsync(dailyInfo.Id);
+
+                // Updated the logging statement to ensure consistent message templates
+                _logger.LogInformation("【日付申请单关联物品】请求参数:{DailyInfoId}\r\n返回参数:{LinkOpResData}\r\n返回消息:{LinkOpResMsg}",
+                    dailyInfo.Id,
+                    JsonConvert.SerializeObject(linkOpRes.Data),
+                    linkOpRes.Msg);
+            }
+
+            #endregion
+
             return result;
         }
 
 
+        /// <summary>
+        /// 购买申请单关联物品
+        /// </summary>
+        /// <param name="applicatId">日付申请Id</param>
+        /// <returns></returns>
+        public async Task<JsonView> ApplicationLinkGoodsAddAsync(int applicatId)
+        {
+            if (applicatId < 1) return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = $"日付申请单ID不正确!" };
+            //if (currUserId < 1) return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = $"当前登陆人ID不正确!" };
+
+            var dailyInfoRes = await GetSearchById(new Domain.Dtos.Financial.SearchDailyFeePaymentDto() { PortType = 1, Id = applicatId });
+            if (dailyInfoRes.Code != 0) return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = dailyInfoRes?.Msg ?? "日付申请单信息不存在!" };
+
+            string dynamicJson = JsonConvert.SerializeObject(dailyInfoRes.Data);
+            Fin_DailyFeePaymentInfolView dailyInfo = JsonConvert.DeserializeObject<Fin_DailyFeePaymentInfolView>(dynamicJson);
+
+            if (dailyInfo == null || !dailyInfo.FeeContents.Any())
+            {
+                return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = $"付申请单信息不存在!!" };
+            }
+
+            //审核验证 总经理 && 财务 审核通过 才可进行 物品添加、入库、关联信息 操作
+            if (dailyInfo.MAudit == 0 || dailyInfo.MAudit == 2 || dailyInfo.FAudit == 0 || dailyInfo.FAudit == 2)
+            {
+                return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = $"审核未通过,不可进行物资关联信息!" };
+            }
+
+            _sqlSugar.BeginTran();
+
+            //1.验证物品信息
+            var currGoodsTypeId = dailyInfo.PriceTypeId switch
+            {
+                1433 => 1424, //团组物资
+                1435 => 1426, //固定资产
+                _ => 0
+            };
+
+            var paras = new List<dynamic>();
+
+            foreach (var item in dailyInfo.FeeContents)
+            {
+                var goodsInfo = await _sqlSugar.Queryable<Pm_GoodsInfo>().FirstAsync(x => x.Name.Equals(item.PriceName) && x.IsDel == 0)
+                    ?? new Pm_GoodsInfo()
+                    {
+                        Id = 0,
+                        Name = item.PriceName,
+                        Type = currGoodsTypeId,
+                        Unit = "-",
+                        CreateUserId = dailyInfo.CreateUserId,
+                        Remark = $"日付申请模块新增物品信息(需自行更改单位):\n{item.Remark}",
+                    };
+                //物品不存在执行添加
+                if (goodsInfo.Id == 0)
+                {
+                    goodsInfo.Id = await _sqlSugar.Insertable(goodsInfo).ExecuteReturnIdentityAsync();
+                    if (goodsInfo.Id < 1)
+                    {
+                        _sqlSugar.RollbackTran();
+                        return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = $"物品添加失败!" };
+                    }
+                }
+
+                //执行入库信息添加
+                var storageRes = await _goodsRep.GoodsStorageOp(new GoodsStorageOpDto()
+                {
+                    GoodsId = goodsInfo.Id,
+                    Quantity = item.Quantity,
+                    UnitPrice = item.Price,
+                    TotalPrice = item.ItemTotal,
+                    SupplierName = "-",
+                    SupplierTel = "-",
+                    SupplierAddress = "-",
+                    SupplierSource = "-",
+                    StorageUserId = 374, //固定前台ID为入库人
+                    StorageTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
+                    Remark = $"日付申请模块新增物品入库信息:{item.Remark}",
+                }, 374);
+
+                if (storageRes.Code != StatusCodes.Status200OK)
+                {
+                    _sqlSugar.RollbackTran();
+                    return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = $"物品入库信息添加失败!" };
+                }
+                var storageId = Convert.ToInt32(storageRes.Data.GetType().GetProperty("sign").GetValue(storageRes.Data, null) ?? 0);
+
+                //执行关联表添加
+                var addStatus = await _sqlSugar.Insertable(new Fin_ApplicationLinkGoods(
+                    id: 0,
+                    dailyId: dailyInfo.Id,
+                    goodsId: goodsInfo.Id,
+                    goodsStorageId: storageId,
+                    remark: "",
+                    userId: dailyInfo.CreateUserId
+                    )).ExecuteCommandAsync();
+                if (addStatus < 1)
+                {
+                    _sqlSugar.RollbackTran();
+                    return new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = $"日付、物品入库信息关联信息添加失败!" };
+                }
+
+                paras.Add(new
+                {
+                    dailyId = dailyInfo.Id,
+                    goodsId = goodsInfo.Id,
+                    GoodsStorageId = storageId,
+                    LinkTableId = addStatus
+                });
+            }
+            _sqlSugar.CommitTran();
+
+            return new JsonView() { Code = StatusCodes.Status200OK, Data = paras, Msg = $"操作成功!" };
+        }
     }
 }

+ 16 - 7
OASystem/OASystem.Infrastructure/Repositories/PersonnelModule/GoodsRepository.cs

@@ -1,12 +1,16 @@
 using Aspose.Cells;
 using AutoMapper;
 using EyeSoft.Collections.Generic;
+using EyeSoft.Reflection;
 using Newtonsoft.Json;
 using OASystem.Domain;
 using OASystem.Domain.Dtos.PersonnelModule;
+using OASystem.Domain.Entities.Financial;
 using OASystem.Domain.Entities.Groups;
 using OASystem.Domain.Entities.PersonnelModule;
+using OASystem.Domain.ViewModels.Financial;
 using OASystem.Domain.ViewModels.PersonnelModule;
+using OASystem.Infrastructure.Repositories.Financial;
 using OASystem.Infrastructure.Repositories.System;
 using OASystem.Infrastructure.Tools;
 
@@ -24,7 +28,10 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
         private string _excelPath;
         private List<int> _goodsTypeIds; //多部门审核物品类型Id     
         private readonly ApprovalProcessRepository _approvalProcessRep;
-        public GoodsRepository(SqlSugarClient sqlSugar, IMapper mapper, ApprovalProcessRepository approvalProcessRep) : base(sqlSugar)
+        public GoodsRepository(SqlSugarClient sqlSugar, 
+            IMapper mapper,
+            ApprovalProcessRepository approvalProcessRep) 
+            : base(sqlSugar)
         {
             _mapper = mapper;
             _jv = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "操作失败!" };
@@ -501,6 +508,7 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
             info.CreateUserId = currUserId;
             info.BatchNo = DateTime.Now.ToString("yyyyMMddHHmmssfff");
 
+            var sign = dto.Id;
             _sqlSugar.BeginTran();
             if (info.Id > 0) //修改
             {
@@ -558,8 +566,8 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
             {
                 info.ConfirmStatus = GoodsConfirmEnum.WaitConfirm;
 
-                var storageAddId = await _sqlSugar.Insertable(info).ExecuteReturnIdentityAsync();
-                if (storageAddId < 1)
+                sign = await _sqlSugar.Insertable(info).ExecuteReturnIdentityAsync();
+                if (sign < 1)
                 {
                     _sqlSugar.RollbackTran();
                     _jv.Msg = $"添加失败!";
@@ -567,7 +575,7 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
                 }
 
                 //入库确认默认状态
-                List<Pm_GoodsAudit> auditInfos = GoodsStorageConfirm(1, storageAddId, info.CreateUserId);
+                List<Pm_GoodsAudit> auditInfos = GoodsStorageConfirm(1, sign, info.CreateUserId);
                 if (auditInfos.Any())
                 {
                     //验证添加多条或者单条审核状态
@@ -583,6 +591,7 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
             }
 
             _sqlSugar.CommitTran();
+            _jv.Data = new { sign };
             _jv.Msg = $"操作成功!";
             _jv.Code = StatusCodes.Status200OK;
             return _jv;
@@ -2986,7 +2995,6 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
             return _jv;
         }
 
-
         #region New 物品领用、审核
 
         /// <summary>
@@ -3244,6 +3252,7 @@ FROM
                 Reason = dto.Reason,
                 Remark = dto.Remark,
                 AuditStatus = GoodsAuditEnum.Pending,
+                IsReplace = dto.IsReplace,
                 CreateUserId = currUserId,
             };
             var receiveDetails = _mapper.Map<Pm_GoodsReceiveDetails[]>(dto.ReceiveDetails);
@@ -3251,7 +3260,6 @@ FROM
 
             _sqlSugar.BeginTran();
 
-
             //审核状态验证 false:其他物品 true:贵重物品
             var isBatchVail = false;
 
@@ -3514,7 +3522,7 @@ FROM
                 374, // 罗颖
                 233, // 刘华举
                 208, // 雷怡
-                343, //  陈湘
+                343, // 陈湘
             };
             var isShowAllPeople = showAllPeopleIds.Any(x => x == currUserId);
 
@@ -4200,5 +4208,6 @@ FROM
         }
 
         #endregion
+
     }
 }