Browse Source

重构插入和删除项处理逻辑

将 `addItems` 重命名为 `insertItems`,并改为逐个插入操作,确保插入失败时返回错误信息。添加了对前台删除项的验证和处理逻辑,确保在更新项之前处理删除项,并在删除失败时返回相应的错误信息。成功编辑后设置成功消息并提交事务。

优化人民币处理及报价项逻辑

在 `GroupsController.cs` 中,将人民币(CNY)插入费率列表的开头,并增加对 `result.GroupId` 的赋值操作,确保报价信息的正确性。同时,重构了费用项的处理逻辑,提升了代码可读性。

在 `EnterExitCostQuoteRepository.cs` 中,修改报价名称查询逻辑为根据 `quoteId` 查找,并重构了插入和更新报价项的逻辑,确保新增、更新和删除项的处理更加清晰,维护数据一致性。
LEIYI 1 day ago
parent
commit
91af64a983

+ 24 - 23
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -13257,7 +13257,7 @@ FROM
                 if (!info1.Rates.Any())
                 {
                     var rates = await GeneralMethod.EnterExitCostInitRate();
-                    rates.Add(new CurrencyInfo() { CurrencyCode = "CNY", CurrencyName = "人民币", Rate = 1.00000M });
+                    rates.Insert(0, new CurrencyInfo() { CurrencyCode = "CNY", CurrencyName = "人民币", Rate = 1.00000M });
                     info1.Rates = rates.ToArray();
                 }
                 return Ok(JsonView(info1));
@@ -13265,6 +13265,7 @@ FROM
 
             var result = await _enterExitCostQuoteRep.InfoByGroupIdAsync(dto.DiId);
 
+            result.GroupId = groupId;
             //处理报价名称
             var groupInfo = await _sqlSugar.Queryable<Grp_DelegationInfo>().FirstAsync(x => x.Id == dto.DiId && x.IsDel == 0);
             if (groupInfo != null)
@@ -13288,7 +13289,6 @@ FROM
             var info = await _enterExitCostRep.GetEnterExitCostInfoByDiId(dto);
             if (info.Code != StatusCodes.Status200OK)
             {
-                result.GroupId = groupId;
                 if (!result.Rates.Any())
                 {
                     var rates = await GeneralMethod.EnterExitCostInitRate();
@@ -13304,7 +13304,13 @@ FROM
             var cityFilter = new List<string>() { "全部城市", "其他城市" };
             var currencys = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 66).ToListAsync();
             var eecRates = infoView.Currencys;
-             
+            //默认添加人名币
+            if (!eecRates.Any(x => x.CurrencyCode.Equals("CNY")))
+            {
+                eecRates.Insert(0, new CurrencyInfo() { CurrencyCode = "CNY", CurrencyName = "人民币", Rate = 1.00000M });
+            }
+
+
             //处理团组人数
             int pplNum = 1;
             if (groupInfo != null) pplNum = groupInfo.VisitPNumber;
@@ -13511,7 +13517,7 @@ FROM
                     var thisRate = eecRates.FirstOrDefault(x => x.CurrencyCode.Equals(thisCurrency))?.Rate ?? 1.0000M;
                     int quantity = item.ToList().Count;
 
-                    mealCosts.Add(new QuoteSubItemInfo
+                    miscCosts.Add(new QuoteSubItemInfo
                     {
                         ItemId = miscItemTypeId,
                         Index = miscIndex,
@@ -13526,7 +13532,7 @@ FROM
                     miscIndex++;
                 }
 
-                views.AddRange(mealCosts);
+                views.AddRange(miscCosts);
             }
 
             #endregion
@@ -13609,12 +13615,12 @@ FROM
                     else
                     {
                         var rates = await GeneralMethod.EnterExitCostInitRate();
+                        rates.Insert(0,new CurrencyInfo() { CurrencyCode = "CNY", CurrencyName = "人民币", Rate = 1.00000M });
                         result.Rates = rates.ToArray();
                     }
                 }
             }
 
-            result.Rates = eecRates.ToArray();
 
             return Ok(JsonView(result));
         }
@@ -13685,12 +13691,12 @@ FROM
             var vehArranges = info.FeeItems.FirstOrDefault(x => x.ItemId == 1357);   //车辆安排
             var inviteTo = info.FeeItems.FirstOrDefault(x => x.ItemId == 1358);      //邀请函发放对象
             var inviteCosts = info.FeeItems.FirstOrDefault(x => x.ItemId == 1359);   //邀请函费用
-            var inviteTime = info.FeeItems.FirstOrDefault(x => x.ItemId == 1560);    //邀请函发放时间
-            var officialActs = info.FeeItems.FirstOrDefault(x => x.ItemId == 1561);  //公务活动
-            var visaIns = info.FeeItems.FirstOrDefault(x => x.ItemId == 1562);       //签证+保险
-            var serviceCosts = info.FeeItems.FirstOrDefault(x => x.ItemId == 1563);  //服务费
-            var pubMiscs = info.FeeItems.FirstOrDefault(x => x.ItemId == 1564);      //公杂费
-            var taxCosts = info.FeeItems.FirstOrDefault(x => x.ItemId == 1565);      //税费
+            var inviteTime = info.FeeItems.FirstOrDefault(x => x.ItemId == 1360);    //邀请函发放时间
+            var officialActs = info.FeeItems.FirstOrDefault(x => x.ItemId == 1361);  //公务活动
+            var visaIns = info.FeeItems.FirstOrDefault(x => x.ItemId == 1362);       //签证+保险
+            var serviceCosts = info.FeeItems.FirstOrDefault(x => x.ItemId == 1363);  //服务费
+            var pubMiscs = info.FeeItems.FirstOrDefault(x => x.ItemId == 1364);      //公杂费
+            var taxCosts = info.FeeItems.FirstOrDefault(x => x.ItemId == 1365);      //税费
 
             //获取模板
             string tempPath = AppSettingsHelper.Get("ExcelBasePath") + "Template/出入境费用明细报价表模板.xlsx";
@@ -13840,13 +13846,10 @@ FROM
                 StringBuilder label = new StringBuilder();
                 foreach (var item in vehArranges.Infos)
                 {
-                    label.Append(item.Remark);
                     label.AppendLine();
                     label.AppendLine();
                     label.Append(item.FeeName);
-                    label.Append("\r\n\r\n费用:");
-                    label.Append(item.FeeName);
-                    label.Append(item.TotalAmt.TruncDecimals(2));
+                    label.Append($"\r\n\r\n费用:{item.TotalAmt.TruncDecimals(2)}元");
                 }
 
                 designer.SetDataSource("VehArrangeLabel", label.ToString());
@@ -13937,7 +13940,6 @@ FROM
                     vi_label.AppendLine(label);
                 }
 
-                designer.SetDataSource("AccomLabel", vi_label.ToString());
             }
 
             designer.SetDataSource("VisaInsContent", vi_label.ToString());
@@ -13978,17 +13980,16 @@ FROM
                     rate = rateInfo?.Rate ?? 1.0000M;
 
                     string label = string.Format("{0}:{1}{2}/天*{3}*{4}人", thisFeeName, item.UnitPrice.TruncDecimals(2), currencyName, item.Quantity, item.PplNum);
-                    vi_label.AppendLine(label);
+                    pm_label.AppendLine(label);
                 }
-                if (vi_label.HasValue())
+                if (pm_label.HasValue())
                 {
                     //以上小计:13497.6元\r\n(美金汇率:7.5 )\r\n部分发放成员
-                    vi_label.AppendLine(string.Format("以上小计:{0}元", pubMiscs.TotalAmt.TruncDecimals(2)));
-                    vi_label.AppendLine(string.Format("({0}汇率:{1})", currencyName, rate.TruncDecimals(4)));
-                    vi_label.AppendLine(string.Format("部分发放成员"));
+                    pm_label.AppendLine(string.Format("以上小计:{0}元", pubMiscs.TotalAmt.TruncDecimals(2)));
+                    pm_label.AppendLine(string.Format("({0}汇率:{1})", currencyName, rate.TruncDecimals(4)));
+                    pm_label.AppendLine(string.Format("部分发放成员"));
                 }
 
-                designer.SetDataSource("AccomLabel", vi_label.ToString());
             }
             designer.SetDataSource("PubMiscsContent", pm_label.ToString());
             #endregion

+ 44 - 39
OASystem/OASystem.Infrastructure/Repositories/Groups/EnterExitCostQuoteRepository.cs

@@ -240,7 +240,8 @@ namespace OASystem.Infrastructure.Repositories.Groups
                         PplNum = x.PplNum,
                         Currency = x.Currency,
                         TotalAmt = x.TotalAmt,
-                        Index = x.Index
+                        Index = x.Index,
+                        Remark = x.Remark
                     }).ToListAsync();
 
                 if (quoteItems.Any())
@@ -406,7 +407,7 @@ namespace OASystem.Infrastructure.Repositories.Groups
                 }
             }
 
-            var isNull = await _sqlSugar.Queryable<Grp_EnterExitCostQuote>().FirstAsync(x => x.IsDel == 0 && x.Name.Equals(quoteName)) == null ? true : false;
+            var isNull = await _sqlSugar.Queryable<Grp_EnterExitCostQuote>().FirstAsync(x => x.IsDel == 0 && x.Id == quoteId) == null ? true : false;
 
             _sqlSugar.BeginTran();
 
@@ -442,50 +443,24 @@ namespace OASystem.Infrastructure.Repositories.Groups
                     return jw;
                 }
 
-                var addItems = quoteItemInfos.Where(x => x.Id < 1).ToList();
+                var insertItems = quoteItemInfos.Where(x => x.Id < 1).ToList();
                 var updItems = quoteItemInfos.Where(x => x.Id > 0).ToList();
-                if (addItems.Any())
+                if (insertItems.Any())
                 {
-                    var addItem = await _sqlSugar.Insertable(addItems).ExecuteCommandAsync();
-                    if (addItem < 1)
-                    {
-                        jw.Msg = "编辑失败!";
-                        _sqlSugar.RollbackTran();
-                        return jw;
+                    foreach (var item in insertItems) {
+                        var insertInfo = await _sqlSugar.Insertable(item).ExecuteReturnEntityAsync();
+                        if (insertInfo == null)
+                        {
+                            jw.Msg = "编辑失败!";
+                            _sqlSugar.RollbackTran();
+                            return jw;
+                        }
+                        quoteItemInfos.Add(insertInfo);
                     }
                 }
 
                 if (updItems.Any())
                 {
-                    //验证及处理前台删除项数据
-                    var perDelItems = await _sqlSugar.Queryable<Grp_EnterExitCostQuoteItem>()
-                        .Where(x => x.IsDel == 0 && x.QuoteId == quoteId)
-                        .ToListAsync();
-                    if (perDelItems.Any())
-                    {
-                        var delItems = perDelItems.Where(x => !updItems.Select(y => y.Id).Contains(x.Id)).ToList();
-                        if (delItems.Any())
-                        {
-                            var newDelItems = delItems.Select(x =>
-                                new Grp_EnterExitCostQuoteItem
-                                {
-                                    Id = x.Id,
-                                    DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
-                                    DeleteUserId = dto.CurrUserId,
-                                    IsDel = 1
-                                }).ToList();
-                            var delItemStatus = await _sqlSugar.Updateable(newDelItems)
-                                .UpdateColumns(x => new { x.DeleteTime, x.DeleteUserId, x.IsDel })
-                                .ExecuteCommandAsync();
-                            if (delItemStatus < 1)
-                            {
-                                jw.Msg = "移除项费用失败!";
-                                _sqlSugar.RollbackTran();
-                                return jw;
-                            }
-                        }
-                    }
-
                     var updItem = await _sqlSugar.Updateable(updItems).IgnoreColumns(x => new { x.CreateUserId, x.CreateTime, x.IsDel }).ExecuteCommandAsync();
                     if (updItem < 1)
                     {
@@ -494,6 +469,36 @@ namespace OASystem.Infrastructure.Repositories.Groups
                         return jw;
                     }
                 }
+
+                //验证及处理前台删除项数据
+                var perDelItems = await _sqlSugar.Queryable<Grp_EnterExitCostQuoteItem>()
+                    .Where(x => x.IsDel == 0 && x.QuoteId == quoteId)
+                    .ToListAsync();
+                if (perDelItems.Any())
+                {
+                    var delItems = perDelItems.Where(x => !quoteItemInfos.Select(y => y.Id).Contains(x.Id)).ToList();
+                    if (delItems.Any())
+                    {
+                        var newDelItems = delItems.Select(x =>
+                            new Grp_EnterExitCostQuoteItem
+                            {
+                                Id = x.Id,
+                                DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
+                                DeleteUserId = dto.CurrUserId,
+                                IsDel = 1
+                            }).ToList();
+                        var delItemStatus = await _sqlSugar.Updateable(newDelItems)
+                            .UpdateColumns(x => new { x.DeleteTime, x.DeleteUserId, x.IsDel })
+                            .ExecuteCommandAsync();
+                        if (delItemStatus < 1)
+                        {
+                            jw.Msg = "移除项费用失败!";
+                            _sqlSugar.RollbackTran();
+                            return jw;
+                        }
+                    }
+                }
+
                 jw.Msg = "编辑成功!";
             }