瀏覽代碼

添加团组审核和Excel上传功能

在 `GroupsController.cs` 中新增 `DecreaseFeeAutomaticAudit` 方法以处理团组增减款项的自动审核。
在 `MarketCustomerResourcesController.cs` 中新增 `InsertDataExcel1` 方法以处理Excel文件上传和数据存储。
在 `PersonnelModuleController.cs` 中实现对 `GroupsController` 的依赖注入。
在 `SystemController.cs` 中新增 `TransactionExTest` 方法以测试事务异常处理。
更新 `ExceptionHandlingMiddleware.cs` 以支持事务回滚。
调整 `FeeAuditRepository.cs` 和 `GoodsRepository.cs` 中的审核逻辑,确保费用验证和出库处理。
更新 `appsettings.json` 配置文件并删除无用的二进制文件。
LEIYI 1 周之前
父節點
當前提交
c9da0c9603

+ 19 - 0
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -4971,6 +4971,25 @@ FROM
             return Ok(JsonView(true, groupData.Msg, groupData.Data));
 
         }
+
+        /// <summary>
+        /// 团组增减款项操作 自动审核test
+        /// </summary>
+        /// <param name="groupId"></param>
+        /// <param name="dataId"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> DecreaseFeeAutomaticAudit(int groupId,int dataId)
+        {
+            //自动审核
+            var autoAdit = await _feeAuditRep.FeeAutomaticAudit(3, groupId, dataId);
+
+
+            return Ok(autoAdit);
+
+        }
+
         /// <summary>
         /// 团组增减款项操作 删除
         /// </summary>

+ 122 - 0
OASystem/OASystem.Api/Controllers/MarketCustomerResourcesController.cs

@@ -1270,6 +1270,128 @@ namespace OASystem.API.Controllers
             });
         }
 
+        [HttpPost]
+        public IActionResult InsertDataExcel1(IFormFile file )
+        {
+
+            // 检查文件是否为空
+            if (file == null || file.Length == 0)
+            {
+                return BadRequest("No file uploaded.");
+            }
+
+            // 保存文件到服务器
+            var uploadsFolder = Path.Combine(Directory.GetCurrentDirectory(), "File");
+            if (!Directory.Exists(uploadsFolder))
+            {
+                Directory.CreateDirectory(uploadsFolder);
+            }
+
+            var filePath = Path.Combine(uploadsFolder, file.FileName);
+            using (var stream = new FileStream(filePath, FileMode.Create))
+            {
+                 file.CopyToAsync(stream);
+            }
+
+            Workbook workbook = new Workbook(filePath);
+
+            // 获取第一个工作表
+            Worksheet worksheet = workbook.Worksheets[0];
+
+            // 获取表头(第一行作为列名)
+            int headerRowIndex = 0; // 假设第一行是表头
+            Row headerRow = worksheet.Cells.Rows[headerRowIndex];
+            int colCount = worksheet.Cells.MaxDataColumn + 1;
+
+            // 动态存储列名
+            var clients = new List<Crm_ClientDataAndUser>();
+
+            // 遍历数据行(从第二行开始)
+            int rowCount = worksheet.Cells.MaxDataRow + 1;
+            for (int row = headerRowIndex + 1; row < rowCount; row++)
+            {
+                var cellVal1 = worksheet.Cells[row, 0].Value;  //序号
+                var cellVal2 = worksheet.Cells[row, 1].Value;  //数据Id
+                var cellVal3 = worksheet.Cells[row, 2].Value;  //userId
+
+                int parentId = !string.IsNullOrEmpty(cellVal2?.ToString()) ? int.Parse(cellVal2?.ToString()) : 0;
+                int userId = !string.IsNullOrEmpty(cellVal3?.ToString()) ? int.Parse(cellVal3?.ToString()) : 0;
+                var rowData = new Crm_ClientDataAndUser()
+                {
+                    usersId = userId,
+                    NewClientDataId = parentId
+                };
+
+                clients.Add(rowData); // 将当前行数据添加到集合中
+            }
+
+            var count = 0;
+
+            //var notClentUser = new List<int>() { 21, 95  , 327 };
+            var notClentUser = new List<int>() { 21, 95, 327,213 };
+
+            var insertList = new List<Crm_ClientDataAndUser>();
+
+            if (clients.Count > 0)
+            {
+                _sqlSugar.BeginTran();
+
+
+                //检索相关客户数据
+                var newClientArr = _sqlSugar.Queryable<Crm_NewClientData>()
+                    .Where(x => x.IsDel == 0)
+                    .Select(x => new Crm_NewClientData
+                    {
+                        Client = x.Client,
+                        Id = x.Id
+                    })
+                    .ToList();
+
+                foreach (var item in clients)
+                {
+                    var searchClient = newClientArr.Where(x => x.Id == item.NewClientDataId).ToList();
+
+                    foreach (var clientData in searchClient)
+                    {
+                        var clientDataAndUser = _sqlSugar.Queryable<Crm_ClientDataAndUser>()
+                                                .Where(x => x.NewClientDataId == clientData.Id && x.IsDel == 0)
+                                                .ToList();
+
+                        if (clientDataAndUser.Count > 0)
+                        {
+                            //清除关联表数据
+                            _sqlSugar.Updateable<Crm_ClientDataAndUser>()
+                                .Where(x => !notClentUser.Contains(x.usersId)
+                                && x.NewClientDataId == clientData.Id && x.IsDel == 0)
+                                .SetColumns(x => new Crm_ClientDataAndUser
+                                {
+                                    IsDel = 1,
+                                    DeleteTime = DateTime.Now.ToString(),
+                                    DeleteUserId = 235
+                                })
+                                .ExecuteCommand();
+                        }
+
+                        insertList.Add(new Crm_ClientDataAndUser
+                        {
+                            usersId = item.usersId,
+                            NewClientDataId = clientData.Id,
+                            CreateTime = DateTime.Now,
+                            CreateUserId = 235,
+                        });
+                    }
+                }
+
+                count = _sqlSugar.Insertable(insertList).ExecuteCommand();
+
+                _sqlSugar.CommitTran();
+            }
+
+            return Ok(new
+            {
+                count,
+            });
+        }
 
         #region 回滚数据记录
 

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

@@ -42,6 +42,7 @@ namespace OASystem.API.Controllers
 
         private readonly IHubContext<ChatHub, IChatClient> _hubContext;
         private readonly GoodsRepository _goodsRep;
+        private readonly GroupsController _groupsController;
 
         private string url;
         private string path;
@@ -57,6 +58,7 @@ namespace OASystem.API.Controllers
         /// <param name="hubContext"></param>
         /// <param name="goodsRep"></param>
         /// <param name="sqlSugar"></param>
+        /// <param name="groupsController"></param>
         public PersonnelModuleController(
             IHubContext<ChatHub, IChatClient> hubContext,
             IMapper mapper,
@@ -65,7 +67,8 @@ namespace OASystem.API.Controllers
             UsersRepository usersRep,
             TaskAllocationRepository taskAllocationRep,
             GoodsRepository goodsRep,
-            SqlSugarClient sqlSugar
+            SqlSugarClient sqlSugar,
+            GroupsController groupsController
             )
         {
             _mapper = mapper;
@@ -86,7 +89,7 @@ namespace OASystem.API.Controllers
             this._taskAllocationRep = taskAllocationRep;
             _hubContext = hubContext;
             _goodsRep = goodsRep;
-
+            _groupsController = groupsController;
         }
 
         #region 工资表单
@@ -2154,7 +2157,45 @@ WHERE
                     return id;
                 })
                 .ToArray();
-            return Ok(await _goodsRep.GoodsReceiveAudit(idArray, currUserInfo.UserId, dto.AuditEnum));
+
+
+            var view = await _goodsRep.GoodsReceiveAudit(idArray, currUserInfo.UserId, dto.AuditEnum);
+
+            //TODO:出库成功 并且是团组相关物资 向团组其他款项添加信息
+            #region 出库成功并且是团组相关物资 向团组其他款项添加信息
+
+            if (idArray.Length < 1) return Ok(view);
+
+            int receiveId = idArray[0];
+
+            var receiveInfo = await _sqlSugar.Queryable<Pm_GoodsReceive>().FirstAsync(x => x.IsDel == 0 && x.Id == receiveId);
+            if (receiveInfo == null) return Ok(view);
+
+            if (receiveInfo.AuditStatus != GoodsAuditEnum.OutConfirmed) return Ok(view);
+
+            var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(x => x.IsDel == 0 && x.Id == receiveInfo.GroupId);
+            if (groupInfo == null) return Ok(view);
+
+            var basicData = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 91).ToListAsync();
+            var goodsInfo = await _sqlSugar.Queryable<Pm_GoodsInfo>().FirstAsync(x => x.IsDel == 0 && x.Id == receiveInfo.GoodsId);
+            if (goodsInfo == null) return Ok(view);
+
+            var basicInfo = basicData.FirstOrDefault(x => x.Name.Equals(goodsInfo.Name));
+            if (basicInfo == null) return Ok(view);
+
+            var requestData = new DecreasePaymentsOpDto() {
+                Status = 1,
+                DiId = groupInfo.Id,
+
+
+            };
+            //var otherFeeView = await _groupsController.OpDecreasePayments(requestData);
+
+            
+
+            #endregion
+
+            return Ok(view);
         }
 
         /// <summary>

+ 64 - 50
OASystem/OASystem.Api/Controllers/SystemController.cs

@@ -3106,26 +3106,13 @@ And u.UId = {0} And u.FId = 1 ", dto.UserId);
             for (int row = headerRowIndex + 1; row < rowCount; row++)
             {
                 var cellVal1 = worksheet.Cells[row, 0].Value;  //序号
-                var cellVal2 = worksheet.Cells[row, 1].Value;  //区域分类
-                var cellVal3 = worksheet.Cells[row, 2].Value;  //省级分类
-                var cellVal4 = worksheet.Cells[row, 3].Value;  //单位名称
-                var cellVal5 = worksheet.Cells[row, 4].Value;  //单位详细地址
-                var cellVal6 = worksheet.Cells[row, 5].Value;  //座机号
-                var cellVal7 = worksheet.Cells[row, 6].Value;  //所在城市
-                var cellVal8 = worksheet.Cells[row, 7].Value;  //分配人Id
-
-                int userId = !string.IsNullOrEmpty(cellVal8?.ToString()) ? int.Parse(cellVal8?.ToString()) : 0;
+                var cellVal2 = worksheet.Cells[row, 1].Value;  //单位名称
+                var cellVal3 = worksheet.Cells[row, 2].Value;  //出访次数
+
+                int count = !string.IsNullOrEmpty(cellVal3?.ToString()) ? int.Parse(cellVal3?.ToString()) : 0;
                 var rowData = new Crm_NewClientData() {
-                    Number = userId,
-                    Lvlid = lvData.FirstOrDefault(x => x.Name.Equals(cellVal2?.ToString()))?.Id ?? 0,//区域分类
-                    Client = cellVal4?.ToString().Trim(),//单位名称
-                    Weight = "C",//客户权重
-                    Phone = cellVal6?.ToString(), //座机号
-                    Location = cellVal7?.ToString(),//所在城市
-                    Address = cellVal5?.ToString(),//单位详细地址
-                    LastUpdateUserId = 4, //最后更新人
-                    LastUpdateTime = DateTime.Now, //最后更新时间
-                    CreateUserId = 4, //创建人
+                    Number = count,
+                    Client = cellVal2?.ToString().Trim(),//单位名称
                 };
 
                 clients.Add(rowData); // 将当前行数据添加到集合中
@@ -3134,47 +3121,52 @@ And u.UId = {0} And u.FId = 1 ", dto.UserId);
 
             if (clients.Any())
             {
-                _sqlSugar.BeginTran();
-                try
-                {
-                    int total = 0;
-                    foreach (var item in clients)
-                    {
+                var clientArr = clients.Select(x => x.Client).ToList();
+                var clientDatas = _sqlSugar.Queryable<Crm_NewClientData>().Where(x => x.IsDel == 0)
+                    .ToList()
+                    .Select(x => new { id = x.Id, client = AesEncryptionHelper.Decrypt(x.Client), remark = AesEncryptionHelper.Decrypt(x.Remark) });
 
-                        var userId = item.Number;
-                        item.Number = 0;
+                var clientDatas1 = clientDatas.Where(x => clientArr.Contains(x.client)).ToList();
 
-                        var insertId = _sqlSugar.Insertable(item).ExecuteReturnIdentity();
-                        if (insertId < 1)
-                        {
-                            _sqlSugar.RollbackTran();
-                            return Ok(JsonView(false));
-                        }
+                var updates = new List<Crm_NewClientData>();
 
-                        var linkUser = new Crm_ClientDataAndUser() {
-                            usersId = userId,
-                            NewClientDataId = insertId,
-                            CreateUserId = 4
-                        };
+                foreach (var item in clientDatas1)
+                {
 
-                        var insertSub = _sqlSugar.Insertable(linkUser).ExecuteReturnIdentity();
-                        if (insertSub < 1)
-                        {
-                            _sqlSugar.RollbackTran();
-                            return Ok(JsonView(false));
-                        }
-                        total++;
+                    string newRemark = item.remark;
+                    var str = clients.FirstOrDefault(x => x.Client.Equals(item.client))?.Number ?? 0;
+                    if (str > 0)
+                    {
+                        newRemark += $"\r\n2025年拟出访次数{str}次";
                     }
 
-                    _sqlSugar.CommitTran();
-                    return Ok(JsonView(true,$"操作成功!成功条数:{total}"));
+                    updates.Add(new Crm_NewClientData() { 
+                        Id = item.id,
+
+                        Remark = AesEncryptionHelper.Encrypt(newRemark)
+                    });
 
                 }
-                catch (Exception)
+
+                if (updates.Any())
                 {
-                    _sqlSugar.RollbackTran();
-                    return Ok(JsonView(false));
+                    //加密后更改
+                    var update = _sqlSugar.Updateable(updates).UpdateColumns(it => new {
+                        //it.Client, 
+                        it.Remark,
+                        //it.Phone,
+                        //it.Address,
+                        // it.Location,
+                    }).ExecuteCommand();
+
+
+                    if (update > 0)
+                    {
+                        return Ok(JsonView(true, $"数据加密成功!加密条数:{update}"));
+                    }
                 }
+
+
             }
             return Ok(JsonView(false));
         }
@@ -3222,6 +3214,28 @@ And u.UId = {0} And u.FId = 1 ", dto.UserId);
             return Ok(JsonView(false));
         }
 
+
+        /// <summary>
+        /// 数库事务异常测试
+        /// </summary>
+        /// <returns></returns>
+        [HttpGet]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> TransactionExTest()
+        {
+            _sqlSugar.BeginTran();
+
+
+            var a1 = new List<dynamic>();
+
+            var a2 = a1[0].ToString();
+
+
+            _sqlSugar.RollbackTran();
+
+            return Ok(JsonView(false));
+        }
+
         #endregion
 
     }

二進制
OASystem/OASystem.Api/File/xxxxxx.xls


+ 7 - 3
OASystem/OASystem.Api/Middlewares/ExceptionHandlingMiddleware.cs

@@ -25,7 +25,7 @@ namespace OASystem.API.Middlewares
         /// </summary>
         /// <param name="httpContext"></param>
         /// <returns></returns>
-        public async Task InvokeAsync(HttpContext httpContext)
+        public async Task InvokeAsync(HttpContext httpContext, SqlSugarClient db)
         {
             try
             {
@@ -33,7 +33,7 @@ namespace OASystem.API.Middlewares
             }
             catch (Exception ex)
             {
-                await HandleExceptionAsync(httpContext, ex); // 捕获异常了 在HandleExceptionAsync中处理
+                await HandleExceptionAsync(httpContext, ex, db); // 捕获异常了 在HandleExceptionAsync中处理
             }
         }
 
@@ -43,8 +43,12 @@ namespace OASystem.API.Middlewares
         /// <param name="context"></param>
         /// <param name="exception"></param>
         /// <returns></returns>
-        private async Task HandleExceptionAsync(HttpContext context, Exception exception)
+        private async Task HandleExceptionAsync(HttpContext context, Exception exception, SqlSugarClient db)
         {
+            if (db.Ado != null && db.Ado.Transaction != null)
+            {
+                db.Ado.RollbackTran();
+            }
 
             context.Response.ContentType = "application/json";  // 返回json 类型
             var response = context.Response;

+ 8 - 0
OASystem/OASystem.Api/appsettings.json

@@ -411,6 +411,14 @@
         {
           "Id": 334,
           "Name": "朱琳"
+        },
+        {
+          "Id": 325,
+          "Name": "陈策"
+        },
+        {
+          "Id": 187,
+          "Name": "曾艳"
         }
       ]
     },

+ 1 - 4
OASystem/OASystem.Domain/Dtos/Groups/DecreasePaymentsDto.cs

@@ -56,10 +56,7 @@ namespace OASystem.Domain.Dtos.Groups
         /// <summary>
         /// 对方姓名
         /// </summary>
-        public string OtherSideName
-        {
-            get; set;
-        }
+        public string OtherSideName { get; set; }
 
         /// <summary>
         /// 编号

+ 10 - 0
OASystem/OASystem.Infrastructure/Repositories/Groups/FeeAuditRepository.cs

@@ -383,6 +383,7 @@ namespace OASystem.Infrastructure.Repositories.Groups
                 var groupDetails = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.IsDel == 0 && x.Id == diId).FirstAsync();
                 if (groupDetails != null) groupSize = groupDetails.VisitPNumber;
 
+                decimal otherSubTotal = costContents.Sum(x => x.TeFee);
                 decimal groupCostCNYTotal = costContents.Sum(x => x.TeFee) * _teamRate * groupSize; //团组成本出行物资总金额
                 if (groupCostCNYTotal <= 0.00M)
                 {
@@ -418,6 +419,15 @@ namespace OASystem.Infrastructure.Repositories.Groups
                     }
                 }
                 ids = ids.Distinct().ToList();
+
+                //验证该费用是不是出行物资费用 是:审核 不是:不审核
+                if (!ids.Contains(dataId))
+                {
+                    _view.Msg = $"该费用不属于出行物资,不执行自动审核!";
+                    QuashAudit(currModule, diId, dataId);
+                    return _view;
+                }
+
                 decimal otherFeeCNYTotal = otherFeeDatas.Where(x => ids.Contains(x.Id)).Sum(x => x.FeeTotal);  //其他费用出行物资总金额
                 if (otherFeeCNYTotal <= 0.00M)
                 {

+ 1 - 1
OASystem/OASystem.Infrastructure/Repositories/PersonnelModule/GoodsRepository.cs

@@ -1511,7 +1511,6 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
                     break;
                 case GoodsAuditEnum.OutConfirmed: //出库确认
                     _jv = await GoodsReceiveOutConfirming(receiveInfo, userId, auditDep, auditEnum);
-                    //TODO:出库成功 并且是团组相关物资 向团组其他款项添加信息
 
                     break;
                 case GoodsAuditEnum.OutRejected:  //出库拒绝
@@ -1523,6 +1522,7 @@ namespace OASystem.Infrastructure.Repositories.PersonnelModule
             {
                 _sqlSugar.CommitTran();
                 _jv.Msg = $"操作成功!";
+                _jv.Data = auditEnum;
                 return _jv;
             }