Sfoglia il codice sorgente

PostMateOpGroupPageList、PostMateOpGroupInit
优化响应速度

leiy 8 mesi fa
parent
commit
d560efcf0f

+ 188 - 62
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -12128,14 +12128,12 @@ ORDER by  gctggrc.id DESC
 
             bool isDepStatus = await GeneralMethod.IsMarketingStaff(dto.CurrUserId);
             List<Grp_DelegationInfo> groupInfos = new List<Grp_DelegationInfo>();
-            if (isDepStatus)
-            {
-                groupInfos = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0 && it.JietuanOperator == dto.CurrUserId).OrderByDescending(it => it.CreateUserId).ToListAsync();
-            }
-            else
-            {
-                groupInfos = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0).OrderByDescending(it => it.CreateUserId).ToListAsync();
-            }
+            groupInfos =  _sqlSugar.Queryable<Grp_DelegationInfo>()
+                                        .Where(it => it.IsDel == 0)
+                                        .WhereIF(isDepStatus, it => it.JietuanOperator == dto.CurrUserId)
+                                        .OrderByDescending(it => it.CreateUserId)
+                                        .ToList();
+            if (groupInfos.Count < 1) return Ok(JsonView(false,"暂无和你相关的团组信息!"));
 
             var country = groupInfos.Select(it => it.VisitCountry).ToList();
             var diids = groupInfos.Select(it => it.Id).ToList();
@@ -12146,23 +12144,13 @@ ORDER by  gctggrc.id DESC
                 var dataArray = _groupRepository.GroupSplitCountry(data);
                 if (dataArray.Count > 0) countrys.AddRange(dataArray);
             }
-            countrys = countrys.Distinct().ToList();
-
-            for (int i = 0; i < countrys.Count; i++)
-            {
-                string item = countrys[i];
-                if (string.IsNullOrEmpty(item) || item.Contains("-"))
-                {
-                    countrys.Remove(item);
-                    i--;
-                }
-            }
+            countrys = countrys.Where(it => !string.IsNullOrEmpty(it)).Distinct().ToList();
 
             List<string> areaArray = new List<string>(); //GetGroupCityLine
-
-            foreach (var item in diids)
+            var areaItem = GeneralMethod.GetGroupCityLineItem(diids, "-");
+            foreach (var item in areaItem)
             {
-                string areaStr = GeneralMethod.GetGroupCityLine(item, "-");
+                string areaStr = item.Value;
                 if (!string.IsNullOrEmpty(areaStr))
                 {
                     string[] str1 = areaStr.Split("-");
@@ -12175,50 +12163,24 @@ ORDER by  gctggrc.id DESC
 
             if (areaArray.Count > 0) areaArray = areaArray.Distinct().ToList();
 
-            List<Sys_Cities> cityDatas = new List<Sys_Cities>();
-            string countriesDataStr = await RedisRepository.RedisFactory.CreateRedisRepository().StringGetAsync<string>("CityDatas");//string 取
-            if (string.IsNullOrEmpty(countriesDataStr))
-            {
-                cityDatas = await _sqlSugar.Queryable<Sys_Cities>().Where(it => it.IsDel == 0).ToListAsync();
-                TimeSpan ts = DateTime.Now.AddHours(2).TimeOfDay; //设置redis 过期时间 2
-                await RedisRepository.RedisFactory.CreateRedisRepository().StringSetAsync<string>("CountriesDatas", JsonConvert.SerializeObject(cityDatas), ts);//string 存
-            }
-            else
-            {
-                cityDatas = JsonConvert.DeserializeObject<List<Sys_Cities>>(countriesDataStr);
-            }
+            var cityDatas = _sqlSugar.Queryable<Sys_Cities>()
+                                     .Where(it => it.IsDel == 0 && areaArray.Contains(it.Name_CN))
+                                     .Select(it => new { id = it.Id, parentId = it.CountriesId, name = it.Name_CN })
+                                     .ToList();
 
-            List<Sys_Cities> existCitys = new List<Sys_Cities>();
-            var existCitys1 = cityDatas.Where(it => areaArray.Contains(it.Name_CN)).Select(it => new { id = it.Id, parentId = it.CountriesId, name = it.Name_CN }).ToList();
+            List<int> countriesIds = cityDatas.Select(it => it.parentId).ToList();
 
-            List<int> countriesIds = existCitys1.Select(it => it.parentId).ToList();
+            var countriesDatas = _sqlSugar.Queryable<Sys_Countries>()
+                                          .Where(it => countriesIds.Contains(it.Id))
+                                          .Select(it => new { it.Id, Name = it.Name_CN })
+                                          .ToList();
 
-            var countriesDatas = await _sqlSugar.Queryable<Sys_Countries>()
-                                                .Where(it => countriesIds.Contains(it.Id))
-                                                .Select(it => new { it.Id, Name = it.Name_CN })
-                                                .ToListAsync();
 
-            //var countryDatas = countriesDatas.Select(it => new
-            //{
-            //    id = it.Id,
-            //    name = it.Name,
-            //    childList = existCitys.Where(it1 => it1.CountriesId == it.Id).Select(it1 => new { parentId = it1.CountriesId, id = it1.Id, name = it1.Name_CN }).ToList()
-            //}).ToList();
-
-            var teamNames = groupInfos.Select(it => it.TeamName).ToList();
-
-            for (int i = 0; i < teamNames.Count; i++)
-            {
-                string item = teamNames[i];
-                if (string.IsNullOrEmpty(item) || item.Contains("-"))
-                {
-                    teamNames.Remove(item);
-                    i--;
-                }
-            }
+            var teamNames = groupInfos.Where(it => !string.IsNullOrEmpty(it.TeamName) )
+                                      .Select(it => it.TeamName).ToList();
 
             stopwatch.Stop();
-            return Ok(JsonView(true, $"操作成功,耗时{stopwatch.ElapsedMilliseconds} ms", new { teamNames,countriesDatas, citiesDatas = existCitys1 }));
+            return Ok(JsonView(true, $"操作成功,耗时{stopwatch.ElapsedMilliseconds} ms", new { teamNames,countriesDatas, citiesDatas = cityDatas }));
 
         }
 
@@ -12371,6 +12333,10 @@ ORDER by  gctggrc.id DESC
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
         public async Task<IActionResult> PostMateOpGroupPageList(MateOpGroupPageListDto dto)
         {
+
+            var swatch = new Stopwatch();
+            swatch.Start();
+
             #region  参数验证
             if (dto.UserId < 1) return Ok(JsonView(false, "员工Id为空"));
             if (dto.PageId < 1) return Ok(JsonView(false, "页面Id为空"));
@@ -12403,8 +12369,8 @@ ORDER by  gctggrc.id DESC
                 {
                     _view = _view.Where(x => x.TeamName != null && x.TeamName.Contains(dto.TeamName)).ToList();
                 }
-
-                return Ok(JsonView(true, "查询成功!", _view.Skip(dto.PageIndex).Take(dto.PageSize).ToList(), _view.Count));
+                swatch.Stop();
+                return Ok(JsonView(true, $"查询成功!耗时 {swatch.ElapsedMilliseconds} ms", _view.Skip(dto.PageIndex).Take(dto.PageSize).ToList(), _view.Count));
             }
             else
             {
@@ -12789,6 +12755,166 @@ ORDER by  gctggrc.id DESC
         #endregion
 
 
+        #region 查看邀请方
+        /// <summary>
+        /// 查看邀请方
+        /// 邀请方信息 Init
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> PostGroupLinkInvitingUnitNameInit(GroupLinkInvitingUnitNameInitDto dto)
+        {
+            string sqlWhere = string.Empty;
+            if (!string.IsNullOrEmpty(dto.Search))
+            {
+                sqlWhere = string.Format($@" And UnitName Like '%{dto.Search}%'");
+            }
+            string sql = string.Format($@"Select 
+ ROW_NUMBER() Over(Order By Id desc) As Row_Number,
+ Id,
+ UnitName
+From Res_InvitationOfficialActivityData 
+Where IsDel = 0
+And (UnitName != '' Or UnitName != null) {sqlWhere}");
+
+            RefAsync<int> total = 0;
+            var _views = await _sqlSugar.SqlQueryable<GroupLinkInvitingUnitNameInitView>(sql).ToPageListAsync(dto.PageIndex, dto.PageSize, total);
+
+
+            return Ok(JsonView(true, MsgTips.Succeed, _views, total));
+        }
+
+        /// <summary>
+        /// 查看邀请方
+        /// 国家信息 Init
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> PostGroupLinkInvitingCountryInit(GroupLinkInvitingUnitNameInitDto dto)
+        {
+            var groupInfos = await _sqlSugar.Queryable<Grp_DelegationInfo>().Where(it => it.IsDel == 0).OrderByDescending(it => it.CreateUserId).ToListAsync();
+
+            var country = groupInfos.Select(it => it.VisitCountry).ToList();
+            var diids = groupInfos.Select(it => it.Id).ToList();
+            List<string> countrys = new List<string>();
+            foreach (var item in country)
+            {
+                var data = _groupRepository.FormartTeamName(item);
+                var dataArray = _groupRepository.GroupSplitCountry(data);
+                if (dataArray.Count > 0) countrys.AddRange(dataArray);
+            }
+            countrys = countrys.Distinct().ToList();
+
+            for (int i = 0; i < countrys.Count; i++)
+            {
+                string item = countrys[i];
+                if (string.IsNullOrEmpty(item) || item.Contains("-"))
+                {
+                    countrys.Remove(item);
+                    i--;
+                }
+            }
+
+            RefAsync<int> total = 0;
+            var countyDatas = await _sqlSugar.Queryable<Sys_Countries>()
+                                             .Where(it => countrys.Contains(it.Name_CN))
+                                             .WhereIF(!string.IsNullOrEmpty(dto.Search), it => it.Name_CN.Contains(dto.Search))
+                                             .Select(it => new { id = it.Id, name = it.Name_CN })
+                                             .ToPageListAsync(dto.PageIndex,dto.PageSize, total);
+
+            return Ok(JsonView(true, MsgTips.Succeed, countyDatas, total));
+        }
+
+        /// <summary>
+        /// 查看邀请方
+        /// 城市信息 Init
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> PostGroupLinkInvitingCityInit(GroupLinkInvitingCityInitDto dto)
+        {
+            if (dto.CountiesId < 1) return Ok(JsonView(false, "请传入有效的国家Id"));
+            RefAsync<int> total = 0;
+            var countyDatas = await _sqlSugar.Queryable<Sys_Cities>()
+                                             .Where(it => it.CountriesId == dto.CountiesId)
+                                             .WhereIF(!string.IsNullOrEmpty(dto.Search), it => it.Name_CN.Contains(dto.Search))
+                                             .OrderBy(it => new { IsCapital = SqlFunc.Asc(it.IsCapital), Id = SqlFunc.Asc(it.Id) })
+                                             .Select(it => new { id = it.Id, name = it.Name_CN })
+                                             .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
+
+            return Ok(JsonView(true, MsgTips.Succeed, countyDatas, total));
+        }
+
+        /// <summary>
+        /// 查看邀请方
+        /// 团组名称 Init
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> PostGroupLinkInvitingGroupInit(GroupLinkInvitingDto dto)
+        {
+            var watch = new Stopwatch();
+            watch.Start();
+            RefAsync<int> total = 0;
+            var countyDatas = await _sqlSugar.Queryable<Grp_DelegationInfo>()
+                                             .Where(it => it.IsDel == 0)
+                                             .WhereIF(!string.IsNullOrEmpty(dto.Search), it => it.TeamName.Contains(dto.Search))
+                                             .OrderBy(it => new { JietuanTime = SqlFunc.Desc(it.JietuanTime) })
+                                             .Select(it => new { id = it.Id, name = it.TeamName })
+                                             .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
+            watch.Stop();
+
+            return Ok(JsonView(true, $"{MsgTips.Succeed},耗时 {watch.ElapsedMilliseconds} ms", countyDatas, total));
+        }
+
+        /// <summary>
+        /// 查看邀请方
+        /// 团组 & 邀请方信息
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
+        public async Task<IActionResult> PostGroupLinkInvitingPageList(GroupLinkInvitingPageListDto dto)
+        {
+            var watch = new Stopwatch();
+            watch.Start();
+            RefAsync<int> total = 0;
+            var infos = await _sqlSugar.Queryable<GroupLinkInvitingPageListView>()
+                                             .AS("Grp_DelegationInfo")
+                                             .Includes(x => x.InvitingInfos)
+                                             .Where(x => x.IsDel == 0)
+                                             .Where(x => x.InvitingInfos.Any(z => z.IsDel == 0))
+                                             .WhereIF(!string.IsNullOrEmpty(dto.Counrty), x => x.VisitCountry.Contains(dto.Counrty))
+                                             .WhereIF(!string.IsNullOrEmpty(dto.Area), x => x.InvitingInfos.Any(z => z.Area.Contains(dto.Area))) //TeamName
+                                             .WhereIF(!string.IsNullOrEmpty(dto.TeamName), x => x.TeamName.Contains(dto.TeamName)) //
+                                             .WhereIF(!string.IsNullOrEmpty(dto.UnitName), x => x.InvitingInfos.Any(z => z.Client.Contains(dto.UnitName)))
+                                             .OrderBy(x => new { JietuanTime = SqlFunc.Desc(x.VisitStartDate) })
+                                             .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
+            var userDatas = _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0).ToList();
+            var setDatas = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0).ToList();
+            infos.ForEach(x => {
+                x.TeamDid = setDatas.Find(y => int.Parse(x.TeamDid) == y.Id)?.Name ?? "-";
+                x.JietuanOperator = userDatas.Find(y => int.Parse(x.JietuanOperator) == y.Id)?.CnName ?? "-";
+                x.TeamLevSId = setDatas.Find(y => int.Parse(x.TeamLevSId) == y.Id)?.Name ?? "-";
+            });
+
+            watch.Stop();
+
+            return Ok(JsonView(true, $"{MsgTips.Succeed},耗时 {watch.ElapsedMilliseconds} ms", infos, total));
+        }
+
+        #endregion
+
+
 
         #region 报批行程
         /// <summary>

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

@@ -2289,6 +2289,96 @@ namespace OASystem.API.OAMethodLib
             return city;
         }
 
+
+        /// <summary>
+        /// op行程单 团组 城市路径
+        /// </summary>
+        /// <param name="diid">团组Id</param>
+        /// <param name="separator">分隔符</param>
+        /// <returns></returns>
+        public static Dictionary<int,string> GetGroupCityLineItem(List<int> diids, string separator)
+        {
+            Dictionary<int, string> dicCitys = new Dictionary<int, string>();
+            var cityCodes = _dirRep._sqlSugar.Queryable<Res_ThreeCode>().Where(it => it.IsDel == 0).ToList();
+            var blackCodes = _dirRep._sqlSugar.Queryable<Air_TicketBlackCode>().Where(x => x.IsDel == 0 && diids.Contains(x.DiId)).ToList();
+
+            foreach (var diid in diids)
+            {
+                string city = string.Empty;
+                var blackCode = blackCodes.Where(it => it.DiId == diid).ToList();
+                if (blackCode.Count > 0)
+                {
+                    var black = blackCode.First();
+                    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");
+                            }
+
+                            var cityArr = cityCodes.Where(it => cityThree.Contains(it.Three.ToUpper())).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 = "[未录入黑屏代码]";
+
+                dicCitys.Add(diid,city);
+            }
+
+            
+
+            return dicCitys;
+        }
+
+
         /// <summary>
         /// op行程单相关团组信息 含途径城市
         /// </summary>

+ 34 - 0
OASystem/OASystem.Domain/Dtos/Groups/GroupLinkInvitingDto.cs

@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.Dtos.Groups
+{
+    public class GroupLinkInvitingDto : DtoBase
+    {
+        public string Search { get; set; }
+    }
+
+    public class GroupLinkInvitingUnitNameInitDto : DtoBase
+    {
+        public string Search { get; set; }
+    }
+
+    public class GroupLinkInvitingCityInitDto : GroupLinkInvitingDto
+    {
+        public int CountiesId { get; set; }
+    }
+
+    public class GroupLinkInvitingPageListDto : DtoBase
+    {
+        public string Counrty { get; set; }
+
+        public string Area { get; set; }
+
+        public string TeamName { get; set; }
+
+        public string UnitName { get; set; }
+    }
+}

+ 7 - 0
OASystem/OASystem.Domain/Dtos/Groups/MateOpTravelDto.cs

@@ -16,6 +16,13 @@ namespace OASystem.Domain.Dtos.Groups
         public int CurrUserId { get; set; }
     }
 
+    public class MateOpGroupInit : DtoBase
+    {
+        public int CurrUserId { get; set; }
+        public string Search { get; set; }
+    }
+
+
     public class MateOpGroupCountryChangeDataDto
     {
         public int CountriesId { get; set; }

+ 91 - 0
OASystem/OASystem.Domain/ViewModels/Groups/GroupLinkInvitingView.cs

@@ -0,0 +1,91 @@
+using OASystem.Domain.Entities.Groups;
+using OASystem.Domain.Entities.Resource;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.ViewModels.Groups
+{
+    public class GroupLinkInvitingView
+    {
+    }
+
+    public class GroupLinkInvitingUnitNameInitView
+    {
+        public int Row_Number { get; set; }
+        public int Id { get; set; }
+
+        public string UnitName { get; set; }
+    }
+
+    public class GroupLinkInvitingPageListView
+    {
+        [SqlSugar.SugarColumn(IsPrimaryKey = true)]
+        public int Id { get; set; }
+
+        public string TeamName { get; set; }
+
+        public DateTime VisitStartDate { get; set; }
+        public DateTime VisitEndDate { get; set; }
+        /// <summary>
+        /// 团组类型 
+        /// </summary>
+        public string TeamDid { get; set; }
+
+        public string TeamLevSId { get; set; }
+
+        /// <summary>
+        /// 出访国家
+        /// </summary>
+        public string VisitCountry { get; set; }
+        /// <summary>
+        /// 出访天数
+        /// </summary>
+        public int VisitDays { get; set; }
+        /// <summary>
+        /// 出访人数
+        /// </summary>
+        public int VisitPNumber { get; set; }
+        /// <summary>
+        /// 接团操作人
+        /// </summary>
+        public string JietuanOperator { get; set; }
+        /// <summary>
+        /// 客户名称
+        /// </summary>
+        public string ClientName { get; set; }
+        /// <summary>
+        /// 客户单位
+        /// </summary>
+        public string ClientUnit { get; set; }
+
+        public int IsDel { get; set; }
+
+        [Navigate(NavigateType.OneToMany, nameof(Res_OfficialActivities.DiId), nameof(Id))]
+        public List<InvitingInfo> InvitingInfos { get; set; }
+
+    }
+
+    [SugarTable("Res_OfficialActivities")]
+    public class InvitingInfo
+    {
+        public int Id { get; set; }
+        public int DiId { get; set; }
+        public string Country { get; set; }
+        public string Area { get; set; }
+        public string Client { get; set; }
+        public string Contact { get; set; }
+        public string Job { get; set; }
+        public int IsDel { get; set; }
+    }
+
+
+    public class GroupLinkInvitingPageListView1 : Grp_DelegationInfo
+    {
+        [Navigate(NavigateType.OneToMany, nameof(Res_OfficialActivities.DiId), nameof(Id))]
+        public List<Res_OfficialActivities> InvitingInfos { get; set; }
+    }
+
+}