Browse Source

团组操作 --> 团组列表Excel下载

LEIYI 6 months ago
parent
commit
e9731f8e68

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

@@ -26,6 +26,7 @@ using OASystem.Domain.ViewModels.Groups;
 using OASystem.Infrastructure.Repositories.Financial;
 using OASystem.Infrastructure.Repositories.Groups;
 using Quartz.Util;
+using SqlSugar;
 using SqlSugar.Extensions;
 using System.Collections;
 using System.Data;
@@ -1002,6 +1003,100 @@ namespace OASystem.API.Controllers
                 throw;
             }
         }
+
+        /// <summary>
+        /// 团组清单 Excel
+        /// </summary>
+        /// <param name="beginDt">开始时间 EG:“2024-01-01”</param>
+        /// <param name="endDt">结束时间 EG;“2024-12-31”</param>
+        /// <returns></returns>
+        [HttpGet]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> GroupListFile([FromQuery]string beginDt, [FromQuery] string endDt)
+        {
+            DateTime _beginDt, _endDt;
+            bool beginBool = DateTime.TryParse($"{beginDt} 00:00:00", out _beginDt),
+                 endBool = DateTime.TryParse($"{endDt} 23:59:59", out _endDt);
+            if (!beginBool && !endBool)
+            {
+                return Ok(JsonView(false, "开始或结束时间不正确!"));
+            }
+
+            string sql = string.Format(@"Select Row_Number,Id,SalesQuoteNo,TourCode,TeamTypeId, TeamType,
+                                             	TeamLevId,TeamLev,TeamName,ClientName,ClientUnit,
+                                             	VisitDate,VisitDays,VisitPNumber,JietuanOperatorId,
+                                             	JietuanOperator,IsSure,CreateTime,IsBid
+                                             	From (
+                                             	Select row_number() over(order by gdi.CreateTime Desc) as Row_Number,
+                                             	gdi.Id,SalesQuoteNo,TourCode,ssd.Id TeamTypeId, ssd.Name TeamType,
+                                             	ssd1.Id TeamLevId,ssd1.Name TeamLev,TeamName,ClientName,ClientUnit,
+                                             	VisitDate,VisitDays,VisitPNumber,JietuanOperator JietuanOperatorId,
+                                             	su.CnName JietuanOperator,IsSure,gdi.CreateTime,gdi.IsBid
+                                             	From  Grp_DelegationInfo gdi
+                                             	Left Join Sys_SetData ssd On gdi.TeamDid = ssd.Id 
+                                             	Left Join Sys_SetData ssd1 On gdi.TeamLevSId = ssd1.Id
+                                             	Left Join Sys_Users su On gdi.JietuanOperator = su.Id
+                                             	Where gdi.IsDel = 0 And gdi.CreateTime Between '{0}' And '{1}'
+                                             ) temp", _beginDt.ToString("yyyy-MM-dd HH:mm:ss"), _endDt.ToString("yyyy-MM-dd HH:mm:ss"));
+
+
+            var groupList = await _sqlSugar.SqlQueryable<DelegationListView>(sql).ToListAsync();
+
+            #region 处理所属部门
+            /*
+             * 1.sq 和 gyy 等显示 市场部
+             * 2.王鸽和主管及张总还有管理员号统一国交部
+             * 2-1.  4	管理员 ,21	张海麟
+             */
+            List<int> userIds = groupList.Select(it => it.JietuanOperatorId).ToList();
+            List<int> userIds1 = new List<int>() { 4, 21 };
+            var userDepDatas = await _sqlSugar.Queryable<Sys_Users>()
+                                              .LeftJoin<Sys_Department>((u, d) => u.DepId == d.Id)
+                                              .Where(u => u.IsDel == 0 && userIds.Contains(u.Id))
+                                              .Select((u, d) => new { UserId = u.Id, DepName = userIds1.Contains(u.Id) ? "国交部" : d.DepName })
+                                              .ToListAsync();
+
+            foreach (var item in groupList)
+            {
+                item.Department = userDepDatas.Find(it => item.JietuanOperatorId == it.UserId)?.DepName ?? "Unknown";
+            }
+            #endregion
+
+            #region Excel
+            var tempPath = AppSettingsHelper.Get("ExcelTempPath");
+            var servicePath = AppSettingsHelper.Get("GrpFileBaseUrl");
+            var savePath = AppSettingsHelper.Get("GrpListFileBasePath");
+            var ftpPath = AppSettingsHelper.Get("GrpListFileFtpPath");
+            var fileName = $"团组清单({beginDt}~{endDt}){DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx";
+
+
+            //载入模板
+            WorkbookDesigner designer = new WorkbookDesigner();
+            designer.Workbook = new Workbook($"{tempPath}团组清单模板.xlsx");
+
+            
+            designer.SetDataSource("Titel", $"团组清单({beginDt}~{endDt})");
+
+            DataTable dt = CommonFun.GetDataTableFromIList<DelegationListView>(groupList); ;
+            dt.TableName = "GroupList";
+            designer.SetDataSource(dt);
+            designer.Process();
+
+            if (!Directory.Exists(savePath))
+            {
+                Directory.CreateDirectory(savePath);
+            }
+
+            string serverPath = $"{savePath}{fileName}";
+            designer.Workbook.Save(serverPath);
+            string rst =$"{servicePath}{ftpPath}{fileName}";
+
+            #endregion
+
+            return Ok(JsonView(true, "操作成功!", rst));
+        }
+
+
         #endregion
 
         #region 团组&签证

+ 5 - 1
OASystem/OASystem.Api/appsettings.json

@@ -122,6 +122,10 @@
   "GrpFileBasePath": "D:/FTP/File/OA2023/Office/GrpFile/",
   "GrpFileFtpPath": "Office/GrpFile/",
 
+  "ExcelTempPath": "D:/FTP/File/OA2023/Office/Excel/Template/",
+  "GrpListFileBasePath": "D:/FTP/File/OA2023/Office/GrpFile/GroupList/",
+  "GrpListFileFtpPath": "Office/GrpFile/GroupList/",
+
   "VisaProgressImageBaseUrl": "http://132.232.92.186:24/",
   "VisaProgressImageBasePath": "D:/FTP/File/OA2023/Image/Visa/",
   "VisaProgressImageFtpPath": "Image/Visa/",
@@ -354,7 +358,7 @@
       ]
     }
   ],
-  
+
   //日付类型Data
   "Dailypayment": "666,667"
 }

+ 9 - 0
OASystem/OASystem.Domain/ViewModels/Groups/DelegationInfoView.cs

@@ -456,6 +456,13 @@ namespace OASystem.Domain.ViewModels.Groups
         /// </summary>
         public DateTime VisitDate { get; set; }
 
+        public string VisitDateStr
+        {
+            get
+            {
+                return VisitDate.ToString("yyyy-MM-dd");
+            }
+        }
         /// <summary>
         /// 出行天数
         /// </summary>
@@ -482,6 +489,8 @@ namespace OASystem.Domain.ViewModels.Groups
         /// 流程管控Id
         /// </summary>
         public int GrpScheduleId { get; set; } = 0;
+
+        public DateTime CreateTime { get; set; }
     }