Browse Source

优化团组信息处理逻辑和代码结构

在 `GroupsController.cs` 中调整了 `UsersRepository` 和 `IJuHeApiService` 的参数顺序,并更新了相关方法的参数类型为 `GroupOrderPreInfoDto`。新增 `GroupOrderPreInfoDto` 类,包含 `Id` 和 `TempId` 属性。

在 `GroupOrderPreInfoRepository.cs` 中增加了团组名称列表的获取,优化了查询格式,更新了方法的 XML 注释,增强了代码可读性。处理 `items` 时增加了对原始数据缺失的处理,确保模板字段的完整性。更新和插入操作的代码格式也进行了优化。
LEIYI 2 weeks ago
parent
commit
b9e71972d2

+ 12 - 11
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -190,7 +190,8 @@ namespace OASystem.API.Controllers
             SetDataRepository setDataRep,
             TourClientListRepository tourClientListRep,
             TeamRateRepository teamRateRep,
-            UsersRepository usersRep, IJuHeApiService juHeApi,
+            UsersRepository usersRep, 
+            IJuHeApiService juHeApi,
             InvertedListRepository invertedListRep,
             VisaFeeInfoRepository visaFeeInfoRep,
             TicketBlackCodeRepository ticketBlackCodeRep,
@@ -271,7 +272,7 @@ namespace OASystem.API.Controllers
         /// <summary>
         /// 获取团组流程管控信息
         /// </summary>
-        /// <param name="_jsonDto"></param>
+        /// <param name="_jsonDto">查询参数</param>
         /// <returns></returns>
         [HttpPost]
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
@@ -523,14 +524,13 @@ namespace OASystem.API.Controllers
         /// <summary>
         ///  团组前期信息 Info
         /// </summary>
-        /// <param name="id">Id</param>
-        /// <param name="tempId">Id</param>
+        /// <param name="dto">Id</param>
         /// <returns></returns>
-        [HttpGet("{id}/{tempId}")]
+        [HttpGet("{Id}/{TempId}")]
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
-        public async Task<IActionResult> GroupOrderPreInfo(int id,int tempId = 1404)
+        public async Task<IActionResult> GroupOrderPreInfo([FromRoute] GroupOrderPreInfoDto dto)
         {
-            return Ok(await _grpOrderPreInfoRep.InfoAsync(id, tempId));
+            return Ok(await _grpOrderPreInfoRep.InfoAsync(dto.Id, dto.TempId));
         }
 
         /// <summary>
@@ -548,13 +548,14 @@ namespace OASystem.API.Controllers
         /// <summary>
         ///  团组前期信息 文件下载
         /// </summary>
-        /// <param name="id">Id</param>
-        /// <param name="tempId">Id</param>
+        /// <param name="dto">Id</param>
         /// <returns></returns>
-        [HttpGet("{id}/{tempId}")]
+        [HttpGet("{Id}/{TempId}")]
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
-        public async Task<IActionResult> GroupOrderPreInfoFileDownload(int id, int tempId = 1404)
+        public async Task<IActionResult> GroupOrderPreInfoFileDownload([FromRoute] GroupOrderPreInfoDto dto)
         {
+            int id = dto.Id,tempId = dto.TempId;
+
             var view = await _grpOrderPreInfoRep.InfoAsync(id, tempId);
 
             var data = view.Data as GrpOrderPreInfoView;

+ 5 - 0
OASystem/OASystem.Domain/Dtos/Groups/GroupOrderPreInfoDtos.cs

@@ -20,4 +20,9 @@ namespace OASystem.Domain.Dtos.Groups
     {
         public string Search { get; set; }
     }
+    public class GroupOrderPreInfoDto
+    {
+        public int Id { get; set; }
+        public int TempId { get; set; } = 1404;
+    }
 }

+ 37 - 19
OASystem/OASystem.Infrastructure/Repositories/Groups/GroupOrderPreInfoRepository.cs

@@ -37,9 +37,20 @@ namespace OASystem.Infrastructure.Repositories.Groups
         {
             var jw = new JsonView() { Code = StatusCodes.Status200OK, Msg = "操作成功!" };
 
+            // 获取团组名称列表(端口类型为1)
             var groupNames = await _groupInfoRep.GetGroupNameList(new Domain.Dtos.Groups.GroupNameDto() { PortType = 1 });
-            var tempDatas = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 109).Select(x => new { x.Id, x.Name }).ToListAsync();
-            var names = await _sqlSugar.Queryable<Grp_OrderPreInfo>().Where(x => x.IsDel == 0 && x.CreateUserId == userId).OrderByDescending(x => x.Id).Select(x => new { x.Id, x.Name }).ToListAsync();
+
+            var tempDatas = await _sqlSugar.Queryable<Sys_SetData>()
+                .Where(x => x.IsDel == 0 && x.STid == 109)
+                .Select(x => new { x.Id, x.Name })
+                .ToListAsync();
+
+            var names = await _sqlSugar.Queryable<Grp_OrderPreInfo>()
+                .Where(x => x.IsDel == 0 && x.CreateUserId == userId)
+                .OrderByDescending(x => x.Id)
+                .Select(x => new { x.Id, x.Name })
+                .ToListAsync();
+
             jw.Data = new
             {
                 groupNames = groupNames,
@@ -53,7 +64,7 @@ namespace OASystem.Infrastructure.Repositories.Groups
         /// <summary>
         /// 获取模板信息
         /// </summary>
-        /// <param name="tempId"></param>
+        /// <param name="tempId">模板编号,默认 1404</param>
         /// <returns></returns>
         public async Task<GrpOrderPreItemView[]> TempInfoById(int tempId = 1404)
         {
@@ -82,22 +93,24 @@ namespace OASystem.Infrastructure.Repositories.Groups
         /// <summary>
         /// 获取团组下单前信息
         /// </summary>
-        /// <param name="id"></param>
+        /// <param name="id">下单前信息Id</param>
+        /// <param name="tempId">模板编号,默认 1404</param>
         /// <returns></returns>
         public async Task<JsonView> InfoAsync(int id, int tempId = 1404)
         {
             var jw = new JsonView() { Code = StatusCodes.Status200OK, Msg = "操作成功!" };
             var view = new GrpOrderPreInfoView();
-            var info = await _sqlSugar.Queryable<Grp_OrderPreInfo>().FirstAsync(x => x.IsDel == 0 && x.Id == id);
+            var info = await _sqlSugar.Queryable<Grp_OrderPreInfo>()
+                .FirstAsync(x => x.IsDel == 0 && x.Id == id);
 
             var temps = await TempInfoById(tempId);
             if (info == null)
             {
-                //view.TempId = tempId;
                 view.Items = temps;
                 jw.Data = view;
                 return jw;
             }
+
             view.Id = id;
             view.Name = info.Name;
             view.GroupId = info.GroupId;
@@ -115,7 +128,6 @@ namespace OASystem.Infrastructure.Repositories.Groups
                     ParentId = opi.ParentId,
                     FieldTempId = ft.Id,
                     FieldName = sd1.Name,
-                    //FieldTypeName = !string.IsNullOrEmpty(ft.Remark) ? sd2.Name + "-" + ft.Remark : sd2.Name,
                     FieldTypeName = sd2.Name,
                     OriginVal = opi.Value,
                     Remark = opi.Remark,
@@ -125,23 +137,22 @@ namespace OASystem.Infrastructure.Repositories.Groups
                 })
                 .ToArrayAsync();
 
-            if (!items.Any()) view.Items = temps;
+            // 如果原始数据不存在或者数量不匹配,则补充模板中缺失的字段
+            if (!items.Any())
+            {
+                view.Items = temps;
+            }
             else
             {
-                if (items.Length != temps.Length)
+                var itemsList = items.ToList();
+                foreach (var temp in temps)
                 {
-                    foreach (var item in temps)
+                    if (!itemsList.Any(x => x.FieldName.Equals(temp.FieldName)))
                     {
-                        if (items.FirstOrDefault(x => x.FieldName.Equals(item.FieldName)) == null)
-                        {
-                            var arr = new GrpOrderPreItemView[] { item };
-                            view.Items.AddRange(arr);
-                        }
+                        itemsList.Add(temp);
                     }
                 }
-                else view.Items = items;
-
-                view.Items = view.Items.Length > 0 ? view.Items.OrderBy(x => x.Index).ToArray() : view.Items;
+                view.Items = itemsList.OrderBy(x => x.Index).ToArray();
             }
 
             jw.Data = view;
@@ -175,10 +186,13 @@ namespace OASystem.Infrastructure.Repositories.Groups
                 GroupId = dto.GroupId,
                 CreateUserId = currUserId
             };
+
             var items = new List<Grp_OrderPreItem>();
+            // 处理每一项信息
             foreach (var item in dto.Items)
             {
                 var val = "";
+                // 如果新值为 string[] 时,序列化为 JSON 字符串,否则直接转换
                 if (item.NewValue is Array obj)
                 {
                     val =  JsonConvert.SerializeObject( (string[])item.NewValue);
@@ -202,7 +216,10 @@ namespace OASystem.Infrastructure.Repositories.Groups
             _sqlSugar.BeginTran();
             if (dto.Id > 0) //修改
             {
-                var infoUpd = await _sqlSugar.Updateable(info).UpdateColumns(x => new { x.Name, x.GroupId }).ExecuteCommandAsync();
+                var infoUpd = await _sqlSugar.Updateable(info)
+                    .UpdateColumns(x => new { x.Name, x.GroupId })
+                    .ExecuteCommandAsync();
+
                 if (infoUpd < 1)
                 {
                     _sqlSugar.RollbackTran();
@@ -232,6 +249,7 @@ namespace OASystem.Infrastructure.Repositories.Groups
                     return jw;
                 }
 
+                // 设置所有项的 ParentId 为新增后的 Id
                 foreach (var item in items) item.ParentId = addId;
 
                 if (items.Any()) await _sqlSugar.Insertable(items).ExecuteCommandAsync();