yuanrf 3 тижнів тому
батько
коміт
3d2d3ad2e5

+ 305 - 1
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -1883,9 +1883,313 @@ FROM
             return Ok(JsonView(true, "操作成功!", rst));
         }
 
+        [HttpPost]
+        public async Task<IActionResult> DownGroupContractFile(DownGroupContractFileDto dto)
+        {
+            var jw = JsonView(false);
+            var di = await _sqlSugar.Queryable<Grp_DelegationInfo>()
+                                     .FirstAsync(x => x.Id == dto.GroupId && x.IsDel == 0);
+
+            if (di == null)
+            {
+                jw.Msg = "团组Id有误!";
+                return Ok(jw);
+            }
+
+
+            #region 权限校验
+
+            var allDownFile = new List<int>() { 21 };
+            try
+            {
+                var setting = _sqlSugar.Queryable<Sys_SetData>()
+                                 .First(x => x.Id == 1418 && x.IsDel == 0);
+                allDownFile.AddRange(JsonConvert.DeserializeObject<List<int>>(setting.Remark));
+            }
+            catch (Exception)
+            { }
+
+            var guojiaoDownFile = new List<int>() { 330 };
+            var shichangDownFile = new List<int>() { 95 };
+            if (allDownFile.Contains(dto.UserId))
+            {
+
+            }
+            else if (guojiaoDownFile.Contains(dto.UserId))
+            {
+                var guojiaobuDi = new List<int>() { 4, 21 };
+                var departmentStr = _sqlSugar.Queryable<Sys_Department>()
+                                                .LeftJoin<Sys_Users>((d, u) => d.Id == u.DepId && u.IsDel == 0)
+                                                .Where((d, u) => u.Id == di.JietuanOperator)
+                                                .Select((d, u) => d.DepName)
+                                                .First();
+                if (!guojiaobuDi.Contains(di.JietuanOperator) && departmentStr != "策划部")
+                {
+                    jw.Msg = "暂无下载权限!";
+                    return Ok(jw);
+                }
+            }
+            else if (shichangDownFile.Contains(dto.UserId))
+            {
+                var dic = new Dictionary<int, int[]>()
+                 {
+                     { 95, new int []{ 95 , 337 , 302, 350, 355, 357, 353 , 359 , 361, 368, 364, 366, 369} }
+                 };
+
+                try
+                {
+                    var sqSetting = _sqlSugar.Queryable<Sys_SetData>().First(x => x.Id == 1417);
+                    if (sqSetting != null)
+                    {
+                        Dictionary<int, int[]> result = JsonConvert.DeserializeObject<Dictionary<int, int[]>>(sqSetting.Remark);
+                        foreach (var item in result.Keys)
+                        {
+                            if (dic.Keys.Contains(item))
+                            {
+                                int[] dilatation = new int[dic[item].Length + result[item].Length];
+                                Array.Copy(dic[item], dilatation, dic[item].Length);
+                                Array.Copy(result[item], 0, dilatation, dic[item].Length, result[item].Length);
+                                dic[item] = dilatation;
+                            }
+                            else
+                            {
+                                dic.Add(item, result[item]);
+                            }
+                        }
+                    }
+
+                    if (!dic[95].Contains(di.CreateUserId))
+                    {
+                        jw.Msg = "暂无下载权限!";
+                        return Ok(jw);
+                    }
+                }
+                catch (Exception)
+                { }
+            }
+            else if (dto.UserId == di.CreateUserId)
+            {
+
+            }
+            else
+            {
+                jw.Msg = "暂无下载权限!";
+                return Ok(jw);
+            }
+
+            #endregion
+
+
+            var blackCodeList = await _sqlSugar.Queryable<Air_TicketBlackCode>()
+                                                .Where(x=>x.DiId == dto.GroupId && x.IsDel == 0)
+                                                .ToListAsync();
+
+            if (!blackCodeList.Any())
+            {
+                jw.Msg = "该团无机票行程代码!";
+                return Ok(jw);
+            }
+
+            var groupEnterExitCost = await _sqlSugar.Queryable<Grp_EnterExitCost>()
+                                                    .FirstAsync(x => x.DiId == dto.GroupId && x.IsDel == 0);
+
+            if (groupEnterExitCost == null)
+            {
+                jw.Msg = "暂无三公费用信息!";
+                return Ok(jw);
+            }
+
+            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)
+                                .LeftJoin<Sys_SetData>((x, a, b) => b.IsDel == 0 && b.Id == x.Currency)
+                                .Where((x, a, b) => x.IsDel == 0 && x.Diid == di.Id)
+                                .Select((x, a, b) => new
+                                {
+                                    x.Index,
+                                    itemName = a.Name,
+                                    CurrencyStr = b.Name,
+                                    x.Cost,
+                                    x.SubTotal,
+                                    x.Remark
+                                })
+                                .OrderBy((x) => x.Index)
+                                .ToList();
+
+            decimal stayFeeTotal = groupEnterExitCost.ChoiceThree == 1 ? _DayAndCosts.Where(it => it.Type == 1).Sum(it => it.SubTotal) : 0.00M;  // 住宿费
+            decimal mealsFeeTotal = groupEnterExitCost.ChoiceFour == 1 ? _DayAndCosts.Where(it => it.Type == 2).Sum(it => it.SubTotal) : 0.00M;  // 伙食费费
+            decimal miscellaneousFeeTotal = groupEnterExitCost.ChoiceFive == 1 ? _DayAndCosts.Where(it => it.Type == 3).Sum(it => it.SubTotal) : 0.00M; // 公杂费
+            decimal tainFeeTotal = groupEnterExitCost.ChoiceSix == 1 ? _DayAndCosts.Where(it => it.Type == 4).Sum(it => it.SubTotal) : 0.00M;  // 培训费
+            decimal otherPriceTotal = groupEnterExitCost.OtherExpenses_Checked == 1 ? dac5.Sum(x => x.SubTotal) : 0.00M; //其他费用
+            decimal insidePayTotal = groupEnterExitCost.ChoiceOne == 1 ? groupEnterExitCost.InsidePay : 0.00M;
+
+            decimal otherFeeTotal = insidePayTotal + stayFeeTotal + mealsFeeTotal + miscellaneousFeeTotal + tainFeeTotal + otherPriceTotal;
+
+            decimal subJJC = 0.00M,
+                    subGWC = 0.00M,
+                    subTDC = 0.00M;
+
+            //经济舱
+            if (groupEnterExitCost.SumJJC == 1)
+            {
+                subJJC = otherFeeTotal + groupEnterExitCost.OutsideJJPay;
+            }
+            //公务舱
+            if (groupEnterExitCost.SumGWC == 1)
+            {
+                subGWC = otherFeeTotal + groupEnterExitCost.OutsideGWPay;
+            }
+            //头等舱
+            if (groupEnterExitCost.SumTDC == 1)
+            {
+                subTDC = otherFeeTotal + groupEnterExitCost.OutsideTDPay;
+            }
+
+
+            var groupClints = await _sqlSugar.Queryable<Grp_TourClientList>()
+                                             .LeftJoin<Sys_SetData>((x,s) => s.Id == x.ShippingSpaceTypeId && s.IsDel == 0 )
+                                             .Where((x, s) => x.DiId == dto.GroupId && x.IsDel == 0)
+                                             .Select((x, s) => new
+                                             {
+                                                 x.Id,
+                                                 s.Name,
+                                             })
+                                             .ToListAsync();
+
+            //获取舱位人数
+            var cabinCount = groupClints.GroupBy(x => x.Name)
+                                        .Select(x => new { Cabin = x.Key, Count = x.Count() })
+                                        .ToList();
+
+            string cityPath = string.Empty;
+            string startCity = string.Empty;
+            string endCity = string.Empty;
+
+            foreach (var item in blackCodeList)
+            {
+                string city = GeneralMethod.GetGroupCityLine(item, "-");
+                cityPath += city + "\r\n";
+                if (item.Equals(blackCodeList.First()))
+                {
+                    var sp = city.Split('-');
+                    startCity = sp[0];
+                    endCity = sp[sp.Length - 1];
+                }
+            }
+
+            Dictionary<string, string> bookMarkDic = new Dictionary<string, string>();
+            bookMarkDic.Add("ClientUnit",di.ClientUnit);
+            bookMarkDic.Add("VisitCountry", di.VisitCountry);
+            bookMarkDic.Add("VisitDate", di.VisitDate.ToString("yyyy年MM月dd日"));
+            bookMarkDic.Add("VisitPNumber", di.VisitPNumber.ToString());
+            bookMarkDic.Add("CityPath", cityPath);
+            bookMarkDic.Add("StartCity", startCity);
+            bookMarkDic.Add("EndCity", endCity);
+            bookMarkDic.Add("StayDays", $"{di.VisitDays}天{di.VisitDays -1}晚");
+
+            Document doc = new Document($"{AppSettingsHelper.Get("WordBasePath")}GroupContractFile/Template/团组合同bookmarkFormat.doc");
+            DocumentBuilder builder = new DocumentBuilder(doc);
+
+            decimal totalPrice = 0.00M;
+            Table firstTable = (Table)doc.GetChild(NodeType.Table, 0, true);
+            if (firstTable != null)
+            {
+                // 遍历表格的行和单元格
+                foreach (Aspose.Words.Tables.Row row in firstTable.Rows)
+                {
+                    for (int i = 0; i < row.Cells.Count; i++)
+                    {
+                        var cell = row.Cells[i];
+
+                        // 读取单元格内容
+                        string cellTextFirst = row.Cells[0].FirstParagraph.ToString(Aspose.Words.SaveFormat.Text).Trim(); 
+
+                        if (cellTextFirst.Contains("舱位"))
+                        {
+                            break;
+                        }
+
+                        if (cellTextFirst == "经济舱" || cellTextFirst == "公务舱")
+                        {
+                            if (i == 2)
+                            {
+                                if (cellTextFirst == "经济舱")
+                                {
+                                    // 设置单元格内容
+                                    cell.FirstParagraph.Runs.Clear(); // 清除原有内容
+                                    cell.FirstParagraph.AppendChild(new Run(doc, subJJC.ToString())); // 添加
+                                }
+                                else
+                                {
+                                    // 设置单元格内容
+                                    cell.FirstParagraph.Runs.Clear(); // 清除原有内容
+                                    cell.FirstParagraph.AppendChild(new Run(doc, subGWC.ToString())); // 添加
+                                }
+                            }
+
+                            if (i == 3)
+                            {
+                                var count = cabinCount.Find(x => x.Cabin == cellTextFirst)?.Count;
+
+                                if (count != null)
+                                {
+                                    // 设置单元格内容
+                                    cell.FirstParagraph.Runs.Clear(); // 清除原有内容
+                                    cell.FirstParagraph.AppendChild(new Run(doc, count.ToString())); // 添加
+                                }
+                            }
+
+                            if (i == 4)
+                            {
+                                var rowPrice = 0.00M;
+                                var count = cabinCount.Find(x => x.Cabin == cellTextFirst)?.Count;
+                                count ??= 0;
+                                if (cellTextFirst == "经济舱")
+                                {
+                                    rowPrice = subJJC * (int)count;
+                                }
+                                else
+                                {
+                                    rowPrice = subGWC * (int)count;
+                                }
+
+                                totalPrice += rowPrice;
+
+                                // 设置单元格内容
+                                cell.FirstParagraph.Runs.Clear(); // 清除原有内容
+                                cell.FirstParagraph.AppendChild(new Run(doc, rowPrice.ToString())); // 添加
+                            }
+                        }
+                    }
+                }
+            }
+
+            bookMarkDic.Add("TotalPrice", (totalPrice * 0.8M).ToString("#0.00"));
+            bookMarkDic.Add("TotalPrice1", (totalPrice * 0.8M).ToString("#0.00"));
+            bookMarkDic.Add("TotalPriceChinese", decimal.Parse((totalPrice * 0.8M).ToString("#0.00")).ConvertCNYUpper());
+
+            foreach (var bookmarkName in bookMarkDic.Keys)
+            {
+                Bookmark bookmark = doc.Range.Bookmarks[bookmarkName];
+                if (bookmark != null)
+                {
+                    builder.MoveToBookmark(bookmarkName);
+                    builder.Write(bookMarkDic[bookmarkName]);
+                }
+            }
+
+            string savePaht = $"{AppSettingsHelper.Get("WordBasePath")}GroupContractFile/Export/{di.TeamName}_预付版本合同文件.doc";
+            doc.Save(savePaht);
+
+            jw.Msg = "生成成功!";
+            jw.Code = 200;
+            jw.Data = new { Url = AppSettingsHelper.Get("WordBaseUrl") + savePaht.Replace(AppSettingsHelper.Get("WordBasePath"), AppSettingsHelper.Get("WordFtpPath"))};
+            return Ok(jw);
+        }
+
         #endregion
 
-        #region 团组&签证
+            #region 团组&签证
 
         /// <summary>
         ///  根据团组Id获取签证客户信息List

+ 76 - 0
OASystem/OASystem.Api/OAMethodLib/GeneralMethod.cs

@@ -2705,6 +2705,82 @@ namespace OASystem.API.OAMethodLib
         }
 
 
+        /// <summary>
+        /// op行程单 团组 城市路径
+        /// </summary>
+        /// <param name="black">黑屏代码实例</param>
+        /// <param name="separator">分隔符</param>
+        /// <returns></returns>
+        public static string GetGroupCityLine(Air_TicketBlackCode black, string separator)
+        {
+            string city = string.Empty;
+            if (black != null)
+            {
+                black.BlackCode = black.BlackCode == null ? "" : black.BlackCode;
+                var blackSp = Regex.Split(black.BlackCode, "\\d+\\.", RegexOptions.IgnoreCase).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
+                if (blackSp.Length > 0)
+                {
+                    try
+                    {
+                        var cityArrCode = new List<string>(20);
+                        foreach (var item in blackSp)
+                        {
+                            var itemSp = item.Split(' ').Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
+                            var IndexSelect = itemSp[2];
+                            var cityArrCodeLength = cityArrCode.Count - 1;
+                            var startCity = IndexSelect.Substring(0, 3);
+                            if (cityArrCodeLength > 0)
+                            {
+                                var arrEndCity = cityArrCode[cityArrCodeLength];
+                                if (arrEndCity != startCity)
+                                {
+                                    cityArrCode.Add(startCity.ToUpper());
+                                }
+                            }
+                            else
+                            {
+                                cityArrCode.Add(startCity.ToUpper());
+                            }
+
+                            var endCity = IndexSelect.Substring(3, 3);
+                            cityArrCode.Add(endCity.ToUpper());
+                        }
+
+                        var cityThree = string.Empty;
+                        cityArrCode.ForEach(x => cityThree += "'" + x + "',");
+                        cityThree = cityThree.TrimEnd(',');
+                        if (string.IsNullOrWhiteSpace(cityThree))
+                        {
+                            throw new Exception("error");
+                        }
+
+                        string sql = $"SELECT * FROM Res_ThreeCode rtc WHERE UPPER(rtc.Three) in ({cityThree}) ";
+                        var cityArr = _dirRep._sqlSugar.SqlQueryable<Res_ThreeCode>(sql).ToList();
+                        foreach (var item in cityArrCode)
+                        {
+                            var find = cityArr.Find(x => x.Three.ToUpper() == item.ToUpper());
+                            if (find != null)
+                            {
+                                city += find.City + separator;
+                            }
+                            else
+                            {
+                                city += item + "[三字码未收录]" + separator;
+                            }
+                        }
+                        city = city.TrimEnd(char.Parse(separator));
+                    }
+                    catch (Exception e)
+                    {
+                        city = "[黑屏代码格式不正确!]";
+                    }
+                }
+            }
+            else city = "[黑屏代码有误!]";
+            return city;
+        }
+
+
         /// <summary>
         /// op行程单 团组 城市路径
         /// </summary>

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

@@ -272,6 +272,25 @@ namespace OASystem.Domain.Dtos.Groups
 
     }
 
+    public class DownGroupContractFileDto
+    {
+        /// <summary>
+        /// 团组Id
+        /// </summary>
+        public int GroupId { get; set; }
+
+        /// <summary>
+        /// 文件类型
+        /// </summary>
+        public int FileType { get; set; }
+
+
+        /// <summary>
+        /// 用户Id
+        /// </summary>
+        public int UserId { get; set; }
+    }
+
     public class GroupNameScreenDto : DtoBase
     {
         public string groupName { get; set; } = "";