소스 검색

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

LEIYI 2 주 전
부모
커밋
09ff753ad5
2개의 변경된 파일360개의 추가작업 그리고 7개의 파일을 삭제
  1. 352 7
      OASystem/OASystem.Api/Controllers/GroupsController.cs
  2. 8 0
      OASystem/OASystem.Domain/Dtos/Groups/GroupListDto.cs

+ 352 - 7
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -1883,6 +1883,12 @@ FROM
             return Ok(JsonView(true, "操作成功!", rst));
         }
 
+        /// <summary>
+        /// 团组合同下载(1.付款80% 2.付全款)
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        /// <exception cref="Exception"></exception>
         [HttpPost]
         public async Task<IActionResult> DownGroupContractFile(DownGroupContractFileDto dto)
         {
@@ -1999,6 +2005,9 @@ FROM
                 return Ok(jw);
             }
 
+            var rateList = (List<CurrencyInfo>?)CommonFun.GetCurrencyChinaToList(groupEnterExitCost.CurrencyRemark);
+            rateList ??= new List<CurrencyInfo>();
+
             var _DayAndCosts = _sqlSugar.Queryable<Grp_DayAndCost>().Where(it => it.IsDel == 0 && it.DiId == di.Id).ToList();
             var dac5 = _sqlSugar.Queryable<Grp_DayOtherPrice>()
                                 .LeftJoin<Sys_SetData>((x, a) => a.IsDel == 0 && a.Id == x.SetDataId)
@@ -2087,7 +2096,25 @@ FROM
             bookMarkDic.Add("EndCity", endCity);
             bookMarkDic.Add("StayDays", $"{di.VisitDays}天{di.VisitDays -1}晚");
 
-            Document doc = new Document($"{AppSettingsHelper.Get("WordBasePath")}GroupContractFile/Template/团组合同bookmarkFormat.doc");
+            Document doc = null;
+            var percentage = 0.8M;
+            var fileNameadd = "预付";
+
+            if (dto.FileType == 1)
+            {
+                doc = new Document($"{AppSettingsHelper.Get("WordBasePath")}GroupContractFile/Template/团组合同bookmarkFormat.doc");
+            }
+            else if (dto.FileType == 2)
+            {
+                doc = new Document($"{AppSettingsHelper.Get("WordBasePath")}GroupContractFile/Template/团组合同全款无表格.doc");
+                percentage = 1;
+                fileNameadd = "全款";
+            }
+            else
+            {
+                throw new Exception("FileType有误!");
+            }
+
             DocumentBuilder builder = new DocumentBuilder(doc);
 
             decimal totalPrice = 0.00M;
@@ -2165,20 +2192,328 @@ FROM
             }
 
             bookMarkDic.Add("TotalPrice", (totalPrice).ToString("#0.00"));
-            bookMarkDic.Add("TotalPrice1", (totalPrice * 0.8M).ToString("#0.00"));
-            bookMarkDic.Add("TotalPriceChinese", decimal.Parse((totalPrice * 0.8M).ToString("#0.00")).ConvertCNYUpper());
+            bookMarkDic.Add("TotalPrice1", (totalPrice * percentage).ToString("#0.00"));
+            bookMarkDic.Add("TotalPriceChinese", decimal.Parse((totalPrice * percentage).ToString("#0.00")).ConvertCNYUpper());
+
+            //--合同表格部分
+            bookMarkDic.Add("TimeNowDate", DateTime.Now.ToString("yyyy年MM月dd日"));
+            bookMarkDic.Add("ClientUnit1", di.ClientUnit);
+            bookMarkDic.Add("VisitCountry1", di.VisitCountry);
+            bookMarkDic.Add("DayCount", di.VisitDays.ToString());
+            bookMarkDic.Add("VisitingArea", di.VisitDate.ToString("yyyy年MM月dd日")+"-"+di.VisitEndDate.ToString("yyyy年MM月dd日"));
+            bookMarkDic.Add("CityPath1", cityPath);
+            bookMarkDic.Add("CityPath2", cityPath);
+
+            Table contractTable  = (Table)doc.GetChild(NodeType.Table, 1, true);
+
+            if (contractTable != null)
+            {
+
+                //数据源
+                var _DayAndCostsAndCity = _sqlSugar.Queryable<Grp_DayAndCost>()
+                    .LeftJoin<Grp_NationalTravelFee>((it, y) => it.NationalTravelFeeId == y.Id && y.IsDel == 0)
+                    .LeftJoin<Sys_SetData>((it, y, s) => s.IsDel == 0 && s.Id == it.Currency)
+                    .Where((it, y, s) => it.IsDel == 0 && it.DiId == di.Id)
+                    .Select((it, y, s) => new
+                    {
+                        it.Cost,
+                        it.SubTotal,
+                        it.Type,
+                        y.Id,
+                        y.City,
+                        s.Name,
+                        CurrencyCodeCn = s.Remark
+                    })
+                    .ToList()
+                    .Select(x => new
+                    {
+                        CurrencyCode = x.Name,
+                        CityId = x.Id,
+                        x.City,
+                        VisitPNumber = di.VisitPNumber,
+                        x.Type,
+                        x.Cost,
+                        x.SubTotal,
+                        Rate = rateList.Find(y => y.CurrencyCode == x.Name)?.Rate,
+                        x.CurrencyCodeCn,
+                    });
+
+                var dac1 = _DayAndCostsAndCity.Where(it => it.Type == 1).GroupBy(x => x.CityId).ToList(); //住宿费
+                var dac2 = _DayAndCostsAndCity.Where(it => it.Type == 2).GroupBy(x => x.CityId).ToList(); //伙食费
+                var dac3 = _DayAndCostsAndCity.Where(it => it.Type == 3).GroupBy(x => x.CityId).ToList(); //公杂费
+                var dac4 = _DayAndCostsAndCity.Where(it => it.Type == 4).GroupBy(x => x.CityId).ToList(); //培训费
+
+                List<tableSetting> tableSettings = new List<tableSetting>()
+                {
+                    new tableSetting{ Index = 1 , Property = "City"},
+                    new tableSetting{ Index = 2 , Property = "CurrencyCodeCn"},
+                    new tableSetting{ Index = 3 , Property = "Cost"},
+                    new tableSetting{ Index = 4 , Property = "VisitPNumber"},
+                    //new tableSetting{ Index = 5 , Property = ""},
+                    //new tableSetting{ Index = 6 , Property = ""},
+                    new tableSetting{ Index = 7 , Property = "Rate"},
+                    //new tableSetting{ Index = 8 , Property = ""},
+                };
+
+                //1.住宿费
+                int cloneRow = 8;
+                int startDayPrice = 8; //写入index
+                decimal ZSPriceSum = 0.00M, HSPriceSum = 0.00M, GZPriceSum = 0.00M;
+                foreach (var dac in dac1)
+                {
+                    var first = dac.First();
+                    var dayCount = dac.Count();
+                    Aspose.Words.Tables.Row row = contractTable.Rows[startDayPrice];
+                    for (int i = 1; i < row.Cells.Count; i++)
+                    {
+                        var cell = row.Cells[i];
+                        var findProperty = tableSettings.Find(x => x.Index == i);
+                        if (findProperty != null)
+                        {
+                            string value = first.GetType().GetProperty(findProperty.Property).GetValue(first).ToString();
+                            // 设置单元格内容
+                            cell.FirstParagraph.Runs.Clear(); // 清除原有内容
+                            cell.FirstParagraph.AppendChild(new Run(doc, value)); // 添加
+                        }
+                        else
+                        {
+                            switch (i)
+                            {
+                                case 5:
+                                    cell.FirstParagraph.Runs.Clear();
+                                    cell.FirstParagraph.AppendChild(new Run(doc, dayCount.ToString()));
+                                    break;
+
+                                case 6:
+                                    var xiaoji = dayCount * first.VisitPNumber * first.Cost;
+                                    cell.FirstParagraph.Runs.Clear();
+                                    cell.FirstParagraph.AppendChild(new Run(doc, xiaoji.ToString("F2")));
+                                    break;
+
+                                case 8:
+                                    var xiaojiRMB = dayCount * first.VisitPNumber * first.SubTotal;
+                                    cell.FirstParagraph.Runs.Clear();
+                                    cell.FirstParagraph.AppendChild(new Run(doc, xiaojiRMB.ToString("F2")));
+                                    ZSPriceSum += xiaojiRMB;
+                                    break;
+                                default:
+                                    break;
+                            }
+
+                        }
+                    }
+
+                    startDayPrice++;
+                    if (!dac1.Last().Equals(dac))
+                    {
+                        Aspose.Words.Tables.Row newRow = (Aspose.Words.Tables.Row)contractTable.Rows[cloneRow].Clone(true);
+                        // 将克隆的行追加到原行后面
+                        contractTable.Rows.Insert(startDayPrice, newRow);
+                    }
+                    else
+                    {
+                        cloneRow += dac1.Count() + 1;
+                        startDayPrice = cloneRow;
+                    }
+                }
+
+                //2.伙食费
+                foreach (var dac in dac2)
+                {
+                    var first = dac.First();
+                    var dayCount = dac.Count();
+                    Aspose.Words.Tables.Row row = contractTable.Rows[startDayPrice];
+                    for (int i = 1; i < row.Cells.Count; i++)
+                    {
+                        var cell = row.Cells[i];
+                        var findProperty = tableSettings.Find(x => x.Index == i);
+                        if (findProperty != null)
+                        {
+                            string value = first.GetType().GetProperty(findProperty.Property).GetValue(first).ToString();
+                            // 设置单元格内容
+                            cell.FirstParagraph.Runs.Clear(); // 清除原有内容
+                            cell.FirstParagraph.AppendChild(new Run(doc, value)); // 添加
+                        }
+                        else
+                        {
+                            switch (i)
+                            {
+                                case 5:
+                                    cell.FirstParagraph.Runs.Clear();
+                                    cell.FirstParagraph.AppendChild(new Run(doc, dayCount.ToString()));
+                                    break;
+
+                                case 6:
+                                    var xiaoji = dayCount * first.VisitPNumber * first.Cost;
+                                    cell.FirstParagraph.Runs.Clear();
+                                    cell.FirstParagraph.AppendChild(new Run(doc, xiaoji.ToString("F2")));
+                                    break;
+
+                                case 8:
+                                    var xiaojiRMB = dayCount * first.VisitPNumber * first.SubTotal;
+                                    cell.FirstParagraph.Runs.Clear();
+                                    cell.FirstParagraph.AppendChild(new Run(doc, xiaojiRMB.ToString("F2")));
+                                    HSPriceSum += xiaojiRMB;
+                                    break;
+                                default:
+                                    break;
+                            }
+
+                        }
+                    }
+
+                    startDayPrice++;
+                    if (!dac2.Last().Equals(dac))
+                    {
+                        Aspose.Words.Tables.Row newRow = (Aspose.Words.Tables.Row)contractTable.Rows[cloneRow].Clone(true);
+                        // 将克隆的行追加到原行后面
+                        contractTable.Rows.Insert(startDayPrice, newRow);
+                    }
+                    else
+                    {
+                        cloneRow += dac2.Count() + 1;
+                        startDayPrice = cloneRow;
+                    }
+                }
+
+                //3.公杂费
+                foreach (var dac in dac3)
+                {
+                    var first = dac.First();
+                    var dayCount = dac.Count();
+                    Aspose.Words.Tables.Row row = contractTable.Rows[startDayPrice];
+                    for (int i = 1; i < row.Cells.Count; i++)
+                    {
+                        var cell = row.Cells[i];
+                        var findProperty = tableSettings.Find(x => x.Index == i);
+                        if (findProperty != null)
+                        {
+                            string value = first.GetType().GetProperty(findProperty.Property).GetValue(first).ToString();
+                            // 设置单元格内容
+                            cell.FirstParagraph.Runs.Clear(); // 清除原有内容
+                            cell.FirstParagraph.AppendChild(new Run(doc, value)); // 添加
+                        }
+                        else
+                        {
+                            switch (i)
+                            {
+                                case 5:
+                                    cell.FirstParagraph.Runs.Clear();
+                                    cell.FirstParagraph.AppendChild(new Run(doc, dayCount.ToString()));
+                                    break;
+
+                                case 6:
+                                    var xiaoji = dayCount * first.VisitPNumber * first.Cost;
+                                    cell.FirstParagraph.Runs.Clear();
+                                    cell.FirstParagraph.AppendChild(new Run(doc, xiaoji.ToString("F2")));
+                                    break;
+
+                                case 8:
+                                    var xiaojiRMB = dayCount * first.VisitPNumber * first.SubTotal;
+                                    cell.FirstParagraph.Runs.Clear();
+                                    cell.FirstParagraph.AppendChild(new Run(doc, xiaojiRMB.ToString("F2")));
+                                    GZPriceSum += xiaojiRMB;
+                                    break;
+                                default:
+                                    break;
+                            }
+
+                        }
+                    }
+
+                    startDayPrice++;
+                    if (!dac3.Last().Equals(dac))
+                    {
+                        Aspose.Words.Tables.Row newRow = (Aspose.Words.Tables.Row)contractTable.Rows[cloneRow].Clone(true);
+                        // 将克隆的行追加到原行后面
+                        contractTable.Rows.Insert(startDayPrice, newRow);
+                    }
+                    else
+                    {
+                        cloneRow += dac3.Count() + 1;
+                        startDayPrice = cloneRow;
+                    }
+                }
+
+                //合并单元格
+                for (int i = 8; i < contractTable.Rows.Count - 1; i++)
+                {
+                    var currentRow = contractTable.Rows[i];
+                    var nextRow = contractTable.Rows[i + 1];
+
+                    // 获取当前行和下一行的第一个单元格
+                    Cell currentCell = currentRow.Cells[0];
+                    Cell nextCell = nextRow.Cells[0];
+
+                    // 检查单元格内容是否一致(去除尾部的换行符)
+                    string currentText = currentCell.GetText().Trim();
+                    string nextText = nextCell.GetText().Trim();
+
+                    if (currentText == nextText)
+                    {
+                        // 如果当前单元格已经被合并,找到合并的起始单元格
+                        if (currentCell.CellFormat.VerticalMerge == CellMerge.Previous)
+                        {
+                            // 找到合并的起始单元格
+                            int mergeStartIndex = FindMergeStartRowIndex(contractTable, i);
+                            // 将下一行的单元格设置为合并的后续单元格
+                            nextCell.CellFormat.VerticalMerge = CellMerge.Previous;
+                        }
+                        else
+                        {
+                            // 如果当前单元格是合并的起始单元格
+                            currentCell.CellFormat.VerticalMerge = CellMerge.First;
+                            // 将下一行的单元格设置为合并的后续单元格
+                            nextCell.CellFormat.VerticalMerge = CellMerge.Previous;
+                        }
+                    }
+                    else
+                    {
+                        // 如果内容不一致,重置当前单元格的合并属性
+                        if (currentCell.CellFormat.VerticalMerge == CellMerge.Previous)
+                        {
+                            // 如果当前单元格是合并的后续单元格,找到合并的起始单元格并重置
+                            int mergeStartIndex = FindMergeStartRowIndex(contractTable, i);
+                            contractTable.Rows[mergeStartIndex].Cells[0].CellFormat.VerticalMerge = CellMerge.First;
+                        }
+                        else
+                        {
+                            currentCell.CellFormat.VerticalMerge = CellMerge.None;
+                        }
+                    }
+                }
+
+                bookMarkDic.Add("ZSPriceSum", ZSPriceSum.ToString("F2"));
+                bookMarkDic.Add("HSPriceSum", HSPriceSum.ToString("F2"));
+                bookMarkDic.Add("GZPriceSum", GZPriceSum.ToString("F2"));
+            }
 
             foreach (var bookmarkName in bookMarkDic.Keys)
             {
                 Bookmark bookmark = doc.Range.Bookmarks[bookmarkName];
                 if (bookmark != null)
                 {
-                    builder.MoveToBookmark(bookmarkName);
-                    builder.Write(bookMarkDic[bookmarkName]);
+
+                    if (bookmarkName == "ClientUnit")
+                    {
+                        // 移动到书签位置
+                        builder.MoveTo(bookmark.BookmarkStart);
+                        // 设置字体样式为下划线
+                        builder.Font.Underline = Aspose.Words.Underline.Single;
+                        // 插入书签值
+                        builder.Write(bookMarkDic[bookmarkName]);
+                        // 清除字体格式,避免影响后续文本
+                        builder.Font.ClearFormatting();
+                    }
+                    else
+                    {
+                        builder.MoveToBookmark(bookmarkName);
+                        builder.Write(bookMarkDic[bookmarkName]);
+                    }
                 }
             }
 
-            string savePaht = $"{AppSettingsHelper.Get("WordBasePath")}GroupContractFile/Export/{di.TeamName}_预付版本合同文件.doc";
+            string savePaht = $"{AppSettingsHelper.Get("WordBasePath")}GroupContractFile/Export/{di.TeamName}_{fileNameadd}版本合同文件.doc";
             doc.Save(savePaht);
 
             jw.Msg = "生成成功!";
@@ -2187,9 +2522,19 @@ FROM
             return Ok(jw);
         }
 
+        static int FindMergeStartRowIndex(Table table, int rowIndex)
+        {
+            int index = rowIndex;
+            while (index > 0 && table.Rows[index].Cells[0].CellFormat.VerticalMerge == CellMerge.Previous)
+            {
+                index--;
+            }
+            return index;
+        }
+
         #endregion
 
-            #region 团组&签证
+        #region 团组&签证
 
         /// <summary>
         ///  根据团组Id获取签证客户信息List

+ 8 - 0
OASystem/OASystem.Domain/Dtos/Groups/GroupListDto.cs

@@ -291,6 +291,14 @@ namespace OASystem.Domain.Dtos.Groups
         public int UserId { get; set; }
     }
 
+
+    public class tableSetting
+    {
+        public int Index { get;set; }
+
+        public string Property { get; set; }
+    }
+
     public class GroupNameScreenDto : DtoBase
     {
         public string groupName { get; set; } = "";