Browse Source

调整省份ID及相关数据源逻辑

在 `GroupsController.cs` 中修改了多个方法的返回逻辑,增加了对 `groupData.Code` 的检查,并替换了数据库查询逻辑为调用 `_groupRepository` 的方法。默认省份 ID 从 1408 改为 122,并在相关 DTO 中进行了相应的调整。新增了 `ProvinceCityBasicSource` 和 `CityBasicSource` 方法以获取基础数据源,并确保特定城市在列表前面。`EnterExitCostGroupNameAsync` 方法的返回类型也进行了更新,以适应新的数据结构。
LEIYI 2 weeks ago
parent
commit
36f9e5b850

+ 45 - 64
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -956,12 +956,12 @@ namespace OASystem.API.Controllers
         public async Task<IActionResult> GroupEditBasicSource(GroupListDto dto)
         {
             var groupData = await _groupRepository.GroupEditBasicSource(dto);
+
             if (groupData.Code != 0)
             {
                 return Ok(JsonView(false, groupData.Msg));
             }
             return Ok(JsonView(groupData.Data));
-
         }
 
         /// <summary>
@@ -5611,25 +5611,9 @@ FROM
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
         public async Task<IActionResult> GetEnterExitProvBelongCostDataSource()
         {
-            var provData = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 110).ToListAsync();
-
-            var view = provData.Select(x =>
-            {
+            var provData = await _groupRepository.ProvinceBasicSource();
 
-                int.TryParse(x.Remark, out int val);
-
-                var data = new SetDataSortView
-                {
-                    Id = x.Id,
-                    Name = x.Name,
-                    Index = val
-                };
-
-                return data;
-            }).OrderBy(x => x.Index).ToArray();
-
-
-            return Ok(JsonView(true, "查询成功!", view));
+            return Ok(JsonView(true, "查询成功!", provData));
         }
 
 
@@ -5642,6 +5626,7 @@ FROM
         public async Task<IActionResult> GetEnterExitCostDataSource(EnterExitCostDataSourceDto dto)
         {
             var groupNameData = await _groupRepository.EnterExitCostGroupNameAsync();
+            var groupNamFirst = groupNameData.FirstOrDefault();
 
             string sql = string.Format("Select * From Sys_SetData Where IsDel = 0");
             //SetDataInfoView
@@ -5651,13 +5636,18 @@ FROM
             List<SetDataInfoView> _CurrencyData = _mapper.Map<List<SetDataInfoView>>(currencyData);
 
             //验证城市归属并给默认值
-            int provinceId = dto.ProvinceId;
-            if (provinceId < 1) provinceId = 1408;
+            int provinceId = 122;
+            if (groupNamFirst != null) provinceId = groupNamFirst.ProvinceId;
 
             var wordTypeData = Array.Empty<SetDataInfoView>();
             var excelTypeData = Array.Empty<SetDataInfoView>();
-
-            if (provinceId == 1408) //四川
+            /*
+             * 122 四川
+             * 108 贵州
+             * 103 重庆
+             * 132 云南
+             */
+            if (provinceId == 122) //四川
             {
                 //三公费用-Word明细类型
                 wordTypeData = dataSource
@@ -5680,11 +5670,11 @@ FROM
                     })
                     .ToArray();
             }
-            else if (provinceId == 1409) //贵州
+            else if (provinceId == 108) //贵州
             { }
-            else if (provinceId == 1410) //重庆
+            else if (provinceId == 103) //重庆
             { }
-            else if (provinceId == 1411) //昆明
+            else if (provinceId == 132) //云南
             { }
 
             var _currencyInfos = await GeneralMethod.EnterExitCostInitRate();
@@ -5692,7 +5682,7 @@ FROM
             var viewPermissionData = await _enterExitCostRep.PermissionViewUsersAsync();
             return Ok(JsonView(true, "查询成功!", new
             {
-                GroupNameData = groupNameData.Data,
+                GroupNameData = groupNameData,
                 CurrencyData = _CurrencyData,
                 WordTypeData = wordTypeData,
                 ExcelTypeData = excelTypeData,
@@ -7463,22 +7453,22 @@ FROM
             return _city;
         }
 
-        /// <summary>
-        /// 团组模块 - 出入境费用 - 明细表导出
-        /// </summary>
-        /// <returns></returns>
-        [HttpPost]
-        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
-        public async Task<IActionResult> PostEnterExitCostExportDetailsList(EnterExitCostOperateDto dto)
-        {
-            var data = await _enterExitCostRep.PostEnterExitCostOperate(dto);
+        ///// <summary>
+        ///// 团组模块 - 出入境费用 - 明细表导出
+        ///// </summary>
+        ///// <returns></returns>
+        //[HttpPost]
+        //[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        //public async Task<IActionResult> PostEnterExitCostExportDetailsList(EnterExitCostOperateDto dto)
+        //{
+        //    var data = await _enterExitCostRep.PostEnterExitCostOperate(dto);
 
-            if (data.Code != 0)
-            {
-                return Ok(JsonView(false, data.Msg));
-            }
-            return Ok(JsonView(true, data.Msg, data.Data));
-        }
+        //    if (data.Code != 0)
+        //    {
+        //        return Ok(JsonView(false, data.Msg));
+        //    }
+        //    return Ok(JsonView(true, data.Msg, data.Data));
+        //}
 
         /// <summary>
         /// 团组模块 - 出入境费用 - 一键清空
@@ -7577,20 +7567,20 @@ FROM
         public async Task<IActionResult> GetNationalTravelFeeData(NationalTravelFeeDataDto dto)
         {
             int provinceId = dto.ProvinceId;
-            if (provinceId < 1) provinceId = 1408; //默认四川省数据
+            if (provinceId < 1) provinceId = 122; //默认四川省数据
 
             var nftData = await _sqlSugar
-                .Queryable<Grp_NationalTravelFee, Sys_SetData, Sys_Users, Sys_SetData>((ntf, sd1, u, sd2) => new JoinQueryInfos(
+                .Queryable<Grp_NationalTravelFee, Sys_SetData, Sys_Users, Sys_Cities>((ntf, sd1, u, c) => new JoinQueryInfos(
                     JoinType.Left, ntf.Currency == sd1.Id,
                     JoinType.Left, ntf.LastUpdateUserId == u.Id,
-                    JoinType.Left, ntf.ProvinceId == sd2.Id
+                    JoinType.Left, ntf.ProvinceId == c.Id
                 ))
-                .Where((ntf, sd1, u, sd2) => ntf.IsDel == 0 && ntf.ProvinceId == provinceId)
-                .Select((ntf, sd1, u, sd2) => new NationalTravelFeeInfoView
+                .Where((ntf, sd1, u, c) => ntf.IsDel == 0 && ntf.ProvinceId == provinceId)
+                .Select((ntf, sd1, u, c) => new NationalTravelFeeInfoView
                 {
                     Id = ntf.Id,
                     ProvinceId = ntf.ProvinceId,
-                    ProvinceName = sd2.Name,
+                    ProvinceName = c.Name_CN,
                     Continent = ntf.Continent,
                     Country = ntf.Country,
                     City = ntf.City,
@@ -7639,7 +7629,10 @@ FROM
                     CityData = cityData1
                 };
 
-                dataSource.Add(countryData2);
+                if (!dataSource.Contains(countryData2))
+                {
+                    dataSource.Add(countryData2);
+                }
             }
 
             return Ok(JsonView(true, "查询成功!", dataSource));
@@ -7661,21 +7654,9 @@ FROM
             if (pageIndex == 0) pageIndex = 1;
             if (pageSize == 0) pageSize = 10;
 
-            string whereSql = string.Empty;
-            if (!string.IsNullOrEmpty(dto.Country)) whereSql += string.Format(@" And gntf.Country ='{0}'", dto.Country);
-
-            if (!string.IsNullOrEmpty(dto.City)) whereSql += string.Format(@" And gntf.City='{0}'", dto.City);
-
-            string pageSql = string.Format(@"Select * From (
-                                             Select row_number() over(order by gntf.LastUpdateTime Desc) as RowNumber,
-                                             ssd.Name as CurrencyCode, ssd.Remark as CurrencyName,su.CnName as LastUpdateUserName,gntf.* 
-                                             From Grp_NationalTravelFee gntf
-                                             Left Join Sys_SetData ssd On ssd.STid = 66 And gntf.Currency = ssd.Id
-                                             Left Join Sys_Users su On gntf.LastUpdateUserId = su.Id 
-                                             Where gntf.Isdel = 0 {0} ) temp ", whereSql);
             RefAsync<int> total = 0;
             var nationalTravelFeeData = await _sqlSugar
-                .Queryable<Grp_NationalTravelFee, Sys_SetData, Sys_Users, Sys_SetData>((ntf, sd1, u, sd2) => new JoinQueryInfos(
+                .Queryable<Grp_NationalTravelFee, Sys_SetData, Sys_Users, Sys_Cities>((ntf, sd1, u, sd2) => new JoinQueryInfos(
                     JoinType.Left, ntf.Currency == sd1.Id,
                     JoinType.Left, ntf.LastUpdateUserId == u.Id,
                     JoinType.Left, ntf.ProvinceId == sd2.Id
@@ -7690,7 +7671,7 @@ FROM
                     RowNumber = SqlFunc.RowNumber($"{ntf.LastUpdateTime} Desc"),
                     Id = ntf.Id,
                     ProvinceId = ntf.ProvinceId,
-                    ProvinceName = sd2.Name,
+                    ProvinceName = sd2.Name_CN,
                     Continent = ntf.Continent,
                     Country = ntf.Country,
                     City = ntf.City,
@@ -9177,7 +9158,7 @@ FROM
             var draftDatas = await _sqlSugar.Queryable<Grp_EnterExitCostDraft>().Where(x => x.IsDel == 0).OrderByDescending(x => x.CreateTime).Select(x => new { x.Id, x.DraftName }).ToListAsync();
             jw.Code = StatusCodes.Status200OK;
             jw.Msg = "操作成功!";
-            jw.Data = new { groupNameDatas = groupNameDatas.Data, draftNames = draftDatas };
+            jw.Data = new { groupNameDatas = groupNameDatas, draftNames = draftDatas };
             return Ok(jw);
         }
 

+ 6 - 6
OASystem/OASystem.Domain/Dtos/Groups/EnterExitCostDto.cs

@@ -13,7 +13,7 @@ namespace OASystem.Domain.Dtos.Groups
 
     public class EnterExitCostDataSourceDto : PortDtoBase
     {
-        public int ProvinceId { get; set; } = 1408;
+        //public int ProvinceId { get; set; } = 1408;
     }
 
     /// <summary>
@@ -64,10 +64,10 @@ namespace OASystem.Domain.Dtos.Groups
         /// </summary>
         public int Id { get; set; }
 
-        /// <summary>
-        /// 省份Id
-        /// </summary>
-        public int ProvinceId { get; set; }
+        ///// <summary>
+        ///// 省份Id
+        ///// </summary>
+        //public int ProvinceId { get; set; }
 
         /// <summary>
         /// 团组Id
@@ -389,7 +389,7 @@ namespace OASystem.Domain.Dtos.Groups
 
     public class NationalTravelFeeDataDto : PortDtoBase
     {
-        public int ProvinceId { get; set; } = 1408;
+        public int ProvinceId { get; set; } = 122; //默认四川
     }
 
     /// <summary>

+ 6 - 4
OASystem/OASystem.Domain/ViewModels/Groups/EnterExitCostView.cs

@@ -22,6 +22,8 @@ namespace OASystem.Domain.ViewModels.Groups
         public string GroupName { get; set; }
 
         public string IsNull { get; set; }
+
+        public int ProvinceId { get; set; }
     }
 
     /// <summary>
@@ -244,10 +246,10 @@ namespace OASystem.Domain.ViewModels.Groups
         /// </summary>
         public int Id { get; set; }
 
-        /// <summary>
-        /// 归属省份Id
-        /// </summary>
-        public int ProvinceId { get; set; }
+        ///// <summary>
+        ///// 归属省份Id
+        ///// </summary>
+        //public int ProvinceId { get; set; }
 
         /// <summary>
         /// 团组Id

+ 106 - 9
OASystem/OASystem.Infrastructure/Repositories/Groups/DelegationInfoRepository.cs

@@ -1,6 +1,7 @@
 using AutoMapper;
 using Newtonsoft.Json;
 using NPOI.OpenXmlFormats.Wordprocessing;
+using NPOI.POIFS.Properties;
 using NPOI.SS.Formula.Functions;
 using OASystem.Domain;
 using OASystem.Domain.AesEncryption;
@@ -576,20 +577,69 @@ namespace OASystem.Infrastructure.Repositories.Groups
         }
 
 
+
         /// <summary>
         /// 获取接团信息 编辑 
         /// 城市基础 数据源
         /// </summary>
         /// <param name="dto"></param>
         /// <returns></returns>
-        public async Task<GroupCityBasicSourceView[]> CityBasicSource()
+        public async Task<List<CityTree>> ProvinceCityBasicSource()
         {
-            var list = new List<GroupCityBasicSourceView>();
-
             var data = await _sqlSugar.Queryable<CityTree>().AS("Sys_Cities")
                 .Where(x => x.IsDel == 0 && x.CountriesId == 44)
                 .ToTreeAsync(it => it.Child, it => it.ParentId, 0);
 
+            if (data.Any())
+            {
+                //移动指定数据在最前面
+                data = MoveElementToFront(data, "云南");
+                data = MoveElementToFront(data, "贵州");
+                data = MoveElementToFront(data, "重庆");
+                data = MoveElementToFront(data, "四川");
+            }
+            return data;
+        }
+
+
+        /// <summary>
+        /// 获取接团信息 编辑 
+        /// 省份基础 数据源
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        public async Task<GroupCityBasicSourceView[]> ProvinceBasicSource()
+        {
+            var list = Array.Empty<GroupCityBasicSourceView>();
+
+            var data = await ProvinceCityBasicSource();
+
+            if (data.Any())
+            {
+                //移动指定数据在最前面
+                data = MoveElementToFront(data, "北京");
+                data = MoveElementToFront(data, "云南");
+                data = MoveElementToFront(data, "贵州");
+                data = MoveElementToFront(data, "重庆");
+                data = MoveElementToFront(data, "四川");
+
+                list = data.Select(x => new GroupCityBasicSourceView() { Id = x.Id, Name = x.Name_CN }).ToArray();
+            }
+            return list;
+        }
+
+        /// <summary>
+        /// 获取接团信息 编辑 
+        /// 城市基础 数据源
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        public async Task<GroupCityBasicSourceView[]> CityBasicSource()
+        {
+            var list = new List<GroupCityBasicSourceView>();
+
+            var data = await ProvinceCityBasicSource();
+
             if (data.Any())
             {
                 //移动指定数据在最前面
@@ -1277,13 +1327,12 @@ namespace OASystem.Infrastructure.Repositories.Groups
         /// </summary>
         /// <param name="dto"></param>
         /// <returns></returns>
-        public async Task<Result> EnterExitCostGroupNameAsync()
+        public async Task<EnterExitCostGroupNameView[]> EnterExitCostGroupNameAsync()
         {
-            var result = new Result() { Code = -2, Msg = "未知错误" };
-
             var groupSql = string.Format(@$"SELECT
   Id,
   TeamName GroupName,
+  CityId ProvinceId,
   CASE
     WHEN (
       SELECT
@@ -1303,9 +1352,57 @@ WHERE
 ORDER BY
   VisitStartDate Desc");
 
-            result.Data = await _sqlSugar.SqlQueryable<EnterExitCostGroupNameView>(groupSql).ToListAsync();
-            result.Code = 0;
-            return result;
+            var groupDatas = await _sqlSugar.SqlQueryable<EnterExitCostGroupNameView>(groupSql).ToArrayAsync();
+            var provCityDatas = await ProvinceCityBasicSource();
+            if (provCityDatas.Any())
+            {
+                foreach (var item in groupDatas)
+                {
+                    var provinceId = item.ProvinceId;
+                    var isDefualtVal = true;
+                    if (provinceId > 0)
+                    {
+                        var parentId = FindParentIdByChildId(provCityDatas, item.ProvinceId);
+                        if (parentId != null)
+                        {
+                            isDefualtVal = false;
+                            item.ProvinceId = (int)parentId;
+                        }
+                    }
+
+                    if (isDefualtVal)
+                    {
+                        item.ProvinceId = 122; //默认四川
+                    }
+                }
+            }
+            
+            return groupDatas;
+        }
+
+        /// <summary>
+        /// 递归地遍历树状结构,查找子项的父类 Id。
+        /// </summary>
+        /// <param name="tree"></param>
+        /// <param name="childId"></param>
+        /// <returns></returns>
+        private int? FindParentIdByChildId(List<CityTree> tree, int childId)
+        {
+            foreach (var node in tree)
+            {
+                if (node.Child.Any(c => c.Id == childId))
+                {
+                    return node.Id;
+                }
+
+                var parentId = FindParentIdByChildId(node.Child, childId);
+                if (parentId.HasValue)
+                {
+                    return parentId;
+                }
+            }
+
+            return null;
         }
 
         #endregion