Browse Source

新增城市基础信息相关功能和数据结构

在 `GroupsController.cs` 中添加了 `GroupProvCityBasicSource` API 方法,用于获取城市基础信息数据源,并添加了相关的 XML 注释。
在 `GroupListDto.cs` 中新增 `GroupProvCityBasicSourceDto` 类及 `CityId` 和 `CityName` 属性,以存储城市信息。
在 `Grp_DelegationInfo.cs` 中添加 `CityId` 属性以存储城市类型 ID。
更新 `Sys_Cities.cs` 中城市等级的注释,增加对直辖市的描述。
在 `DelegationInfoView.cs` 中新增 `GroupCityBasicSourceView` 和 `CityTree` 类,表示城市基础信息和树结构。
在 `DelegationInfoRepository.cs` 中添加 `CityBasicSource` 和 `CityInfoById` 方法,更新 SQL 查询以包含 `CityId` 字段,并在创建和更新团组信息时处理城市相关数据。
LEIYI 2 weeks ago
parent
commit
afb4cb81f6

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

@@ -964,6 +964,29 @@ namespace OASystem.API.Controllers
 
         }
 
+        /// <summary>
+        /// 接团信息 编辑添加
+        /// 省份-城市 基础信息数据源
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> GroupProvCityBasicSource(GroupProvCityBasicSourceDto dto)
+        {
+            int pageIndex = dto.PageIndex, pageSize = dto.PageSize;
+            string search = dto.Search;
+
+            var data = await _groupRepository.CityBasicSource();
+            int total = data.Length;
+            data = data.WhereIF(!string.IsNullOrEmpty(search), x => x.Name.Contains(search))
+                .Skip((pageIndex - 1) * pageSize)
+                .Take(pageSize)
+                .ToArray();
+
+            return Ok(JsonView(data, total));
+        }
+
         /// <summary>
         /// 接团信息 操作(增改)
         /// </summary>

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

@@ -1,5 +1,6 @@
 using FluentValidation;
 using Newtonsoft.Json;
+using OASystem.Domain.ViewModels;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
@@ -16,6 +17,12 @@ namespace OASystem.Domain.Dtos.Groups
     {
     }
 
+    public class GroupProvCityBasicSourceDto : DtoBase
+    {
+        public string Search { get; set; }
+    }
+
+
     /// <summary>
     /// 获取团组列表 Page 请求实体类
     /// </summary>
@@ -82,6 +89,11 @@ namespace OASystem.Domain.Dtos.Groups
         /// </summary>
         public int Id { get; set; }
 
+        /// <summary>
+        /// 城市类型Id
+        /// Sys_Cities 
+        /// </summary>
+        public int CityId { get; set; }
         /// <summary>
         /// 用户Id
         /// </summary>
@@ -396,6 +408,9 @@ namespace OASystem.Domain.Dtos.Groups
         /// </summary>
         public int Id { get; set; }
 
+        public int CityId { get; set; }
+        public string CityName { get; set; }
+
         /// <summary>
         /// 用户Id
         /// </summary>

+ 7 - 0
OASystem/OASystem.Domain/Entities/Groups/Grp_DelegationInfo.cs

@@ -12,6 +12,13 @@ namespace OASystem.Domain.Entities.Groups
     [SugarTable("Grp_DelegationInfo")]
     public class Grp_DelegationInfo:EntityBase
     {
+        /// <summary>
+        /// 城市类型Id
+        /// Sys_Cities 
+        /// </summary>
+        [SugarColumn(IsNullable = true, ColumnDataType = "int")]
+        public int CityId { get; set; }
+
         /// <summary>
         /// 销售报价号
         /// </summary>

+ 1 - 1
OASystem/OASystem.Domain/Entities/System/Sys_Cities.cs

@@ -37,7 +37,7 @@ namespace OASystem.Domain.Entities.System
 
         /// <summary>
         /// 城市等级
-        /// 1 省份 2 城市 3 区县
+        /// 1 省份 2 城市 3 区县 4 直辖市
         /// </summary>
         [SugarColumn(IsNullable = true, ColumnDataType = "int")]
         public  int  Level { get; set; }

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

@@ -231,6 +231,30 @@ namespace OASystem.Domain.ViewModels.Groups
 
     }
 
+
+    public class GroupCityBasicSourceView
+    {
+
+        public int Id { get; set; }
+
+        public string Name { get; set; }
+    }
+
+
+    public class CityTree
+    {
+        [SqlSugar.SugarColumn(IsPrimaryKey = true)]
+        public int Id { get; set; } //关联字段 默认是主键
+        public string Name_CN { get; set; }
+        public int ParentId { get; set; }//父级字段
+        public int Level { get; set; }
+        public int CountriesId { get; set; }
+        public int IsDel { get; set; }
+
+        [SqlSugar.SugarColumn(IsIgnore = true)]
+        public List<CityTree> Child { get; set; }
+    }
+
     /// <summary>
     /// 接团信息详情
     /// 返回视图
@@ -242,6 +266,9 @@ namespace OASystem.Domain.ViewModels.Groups
         /// </summary>
         public int Id { get; set; }
 
+        public int CityId { get; set; }
+        public string CityName { get; set; }
+
         /// <summary>
         /// 销售报价号
         /// </summary>

+ 93 - 6
OASystem/OASystem.Infrastructure/Repositories/Groups/DelegationInfoRepository.cs

@@ -23,6 +23,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using System.Xml.Linq;
 
 namespace OASystem.Infrastructure.Repositories.Groups
 {
@@ -440,7 +441,7 @@ namespace OASystem.Infrastructure.Repositories.Groups
 
             if (dto.PortType == 1 || dto.PortType == 2 || dto.PortType == 3) //Web Or Android
             {
-                string sql = string.Format(@"Select Id,SalesQuoteNo,TourCode,JietuanOperator,TeamLevSId,TeamDid,TeamName,ClientName,
+                string sql = string.Format(@"Select Id,CityId,SalesQuoteNo,TourCode,JietuanOperator,TeamLevSId,TeamDid,TeamName,ClientName,
 	                                                ClientUnit,VisitCountry,VisitDate,VisitDays,VisitPNumber,TontractTime,IsBid,
 	                                                PayDay,PaymentMoney,VisitPurpose,SpecialNeeds,OtherNeeds,CGRWSPBMMC,CGRWSPWH,
 	                                                ZZSCBMMC,ZZSCSPWH,Remark,TellPhone,WeChatNo,OpRoyaltyLv,OpRoyaltyRemark,Officialneeds
@@ -452,12 +453,24 @@ namespace OASystem.Infrastructure.Repositories.Groups
                     _DelegationInfo.TeamName = FormartTeamName(_DelegationInfo.TeamName);
                     _DelegationInfo.VisitCountry = FormartTeamName(_DelegationInfo.VisitCountry);
 
-                    //if (_DelegationInfo.TontractTime)
-                    //{
+                    //验证城市值 不存在则设置默认值
+                    var cityInfo = await CityInfoById(_DelegationInfo.CityId);
+                    if (cityInfo != null)
+                    {
+                        _DelegationInfo.CityName = cityInfo.Name;
+                    }
+                    else
+                    {
+                        _DelegationInfo.CityId = 3505;
+                        _DelegationInfo.CityName = "四川-成都";
+                    }
 
-                    //}
+                        //if (_DelegationInfo.TontractTime)
+                        //{
 
-                    result.Code = 0;
+                        //}
+
+                      result.Code = 0;
                     result.Msg = "成功!";
                     result.Data = _DelegationInfo;
 
@@ -562,6 +575,77 @@ namespace OASystem.Infrastructure.Repositories.Groups
             return result;
         }
 
+
+        /// <summary>
+        /// 获取接团信息 编辑 
+        /// 城市基础 数据源
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        public async Task<GroupCityBasicSourceView[]> CityBasicSource()
+        {
+            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, "四川");
+
+                foreach (var province in data)
+                {
+                    foreach (var city in province.Child)
+                    {
+                        list.Add(new GroupCityBasicSourceView() { 
+                            Id = city.Id,
+                            Name = $"{province.Name_CN}-{city.Name_CN}"
+                        });
+                    }
+                }
+
+                //四川成都放在最前面
+                var cdInfo = list.FirstOrDefault(x => x.Name.Equals("四川-成都"));
+                if (cdInfo != null)
+                {
+                    list.Remove(cdInfo);
+                    list.Insert(0, cdInfo);
+                }
+            }
+            return list.ToArray();
+        }
+
+        /// <summary>
+        /// 获取接团信息 编辑 
+        /// 基础 数据源
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        public async Task<GroupCityBasicSourceView> CityInfoById(int id)
+        {
+            var list = await CityBasicSource();
+            var info = list.FirstOrDefault(x => x.Id == id);
+
+            return info;
+        }
+
+        private List<CityTree> MoveElementToFront(List<CityTree> list, string elementName)
+        {
+            var element = list.FirstOrDefault(x => x.Name_CN == elementName);
+            if (element != null)
+            {
+                list.Remove(element);
+                list.Insert(0, element);
+            }
+            return list;
+        }
+
+
         /// <summary>
         /// 获取接团信息 编辑 
         /// 基础 数据源
@@ -641,7 +725,8 @@ namespace OASystem.Infrastructure.Repositories.Groups
                     userData = userData1,
                     clientData = clientData1,
                     depData = userDepDatas,
-                    rankData = rankDatas
+                    rankData = rankDatas,
+                    cityData = await CityBasicSource()
                 };
             }
 
@@ -724,6 +809,7 @@ namespace OASystem.Infrastructure.Repositories.Groups
 
                     Grp_DelegationInfo delegationInfo = new Grp_DelegationInfo()
                     {
+                        CityId = dto.CityId,
                         SalesQuoteNo = dto.SalesQuoteNo,
                         TeamLevSId = dto.TeamLevSId,
                         ClientName = dto.ClientName,
@@ -791,6 +877,7 @@ namespace OASystem.Infrastructure.Repositories.Groups
                 {
                     var updateStatus = await UpdateAsync(a => a.Id == dto.Id, a => new Grp_DelegationInfo
                     {
+                        CityId = dto.CityId,
                         SalesQuoteNo = dto.SalesQuoteNo,
                         TeamLevSId = dto.TeamLevSId,
                         ClientName = dto.ClientName,