瀏覽代碼

优化SQL查询格式,添加更新时间和用户属性

在多个控制器和存储库中调整了SQL查询的格式,使其更加整齐和易读。
在多个类中添加了与最后更新时间和更新用户相关的属性。
在 `ViewBase.cs` 中添加了 `TextView` 类。
在 `DelegationInfoRepository.cs` 中,添加了 `userDepDatas` 和 `rankDatas` 数据,并将其包含在返回结果中。
LEIYI 2 月之前
父節點
當前提交
7be6e8ef75

+ 6 - 6
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -413,12 +413,12 @@ namespace OASystem.API.Controllers
             watch.Start();
             watch.Start();
             RefAsync<int> total = 0;
             RefAsync<int> total = 0;
             var countyDatas = await _sqlSugar.Queryable<Grp_DelegationInfo>()
             var countyDatas = await _sqlSugar.Queryable<Grp_DelegationInfo>()
-                                             .Where((di) => di.IsDel == 0 && !string.IsNullOrWhiteSpace(di.TeamName))
-                                             .WhereIF(!string.IsNullOrEmpty(dto.Search), (di) => di.TeamName.Contains(dto.Search))
-                                             .OrderBy((di) => new { id = SqlFunc.Desc(di.Id) })
-                                             .Select((di) => new { id = di.Id, name = di.TeamName, di.ClientName, di.VisitPNumber, di.VisitCountry, di.VisitDays, di.VisitStartDate, di.VisitEndDate, di.TourCode })
-                                             .Distinct()
-                                             .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
+                .Where((di) => di.IsDel == 0 && !string.IsNullOrWhiteSpace(di.TeamName))
+                .WhereIF(!string.IsNullOrEmpty(dto.Search), (di) => di.TeamName.Contains(dto.Search))
+                .OrderBy((di) => new { id = SqlFunc.Desc(di.Id) })
+                .Select((di) => new { id = di.Id, name = di.TeamName, di.ClientName, di.VisitPNumber, di.VisitCountry, di.VisitDays, di.VisitStartDate, di.VisitEndDate,di.TourCode })
+                .Distinct()
+                .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
             watch.Stop();
             watch.Stop();
 
 
             return Ok(JsonView(true, $"{MsgTips.Succeed},耗时 {watch.ElapsedMilliseconds} ms", countyDatas, total));
             return Ok(JsonView(true, $"{MsgTips.Succeed},耗时 {watch.ElapsedMilliseconds} ms", countyDatas, total));

+ 46 - 45
OASystem/OASystem.Api/Controllers/ResourceController.cs

@@ -1468,22 +1468,23 @@ Inner Join Sys_Department as d With(Nolock) On u.DepId=d.Id Where m.Id={0} ", _m
 
 
                 DateTime endTime = new DateTime();
                 DateTime endTime = new DateTime();
                 var InvitationOfficialActivityDataList = _sqlSugar.Queryable<Res_InvitationOfficialActivityData>()
                 var InvitationOfficialActivityDataList = _sqlSugar.Queryable<Res_InvitationOfficialActivityData>()
-                                                                  .Where(x => x.IsDel == 0)
-                                                                  .WhereIF(dto.CreateUserId != 0 && !string.IsNullOrWhiteSpace(dto.CreateUserId.ToString()), x => x.CreateUserId == dto.CreateUserId)
-                                                                  .WhereIF(DateTime.TryParse(dto.StartCreateTime , out DateTime startTime) && DateTime.TryParse(dto.EndCreateTime, out  endTime), x => x.CreateTime >= startTime && x.CreateTime <= endTime )
-                                                                  .Select(columns)
-                                                                  .ToList();
+                    .Where(x => x.IsDel == 0)
+                    .WhereIF(dto.CreateUserId != 0 && !string.IsNullOrWhiteSpace(dto.CreateUserId.ToString()), x => x.CreateUserId == dto.CreateUserId)
+                    .WhereIF(DateTime.TryParse(dto.StartCreateTime , out DateTime startTime) && DateTime.TryParse(dto.EndCreateTime, out  endTime), x => x.CreateTime >= startTime && x.CreateTime <= endTime )
+                    .Select(columns)
+                    .ToList();
 
 
                 foreach (var item in InvitationOfficialActivityDataList)
                 foreach (var item in InvitationOfficialActivityDataList)
                 {
                 {
                     EncryptionProcessor.DecryptProperties(item);
                     EncryptionProcessor.DecryptProperties(item);
                 }
                 }
-                InvitationOfficialActivityDataList = InvitationOfficialActivityDataList.WhereIF(!string.IsNullOrWhiteSpace(dto.Country), x => !string.IsNullOrWhiteSpace(x.Country) && x.Country.Contains(dto.Country))
-                                                                                       .WhereIF(!string.IsNullOrWhiteSpace(dto.UnitName), x => !string.IsNullOrWhiteSpace(x.UnitName) && x.UnitName.Contains(dto.UnitName))
-                                                                                       .WhereIF(!string.IsNullOrWhiteSpace(dto.Contact), x => !string.IsNullOrWhiteSpace(x.Contact) && x.Contact.Contains(dto.Contact))
-                                                                                       .WhereIF(!string.IsNullOrWhiteSpace(dto.Delegation), x => !string.IsNullOrWhiteSpace(x.Delegation) && x.Delegation.Contains(dto.Delegation))
-                                                                                       .WhereIF(!string.IsNullOrWhiteSpace(dto.Field), x => !string.IsNullOrWhiteSpace(x.Field) && x.Field.Contains(dto.Field))
-                                                                                       .ToList();
+                InvitationOfficialActivityDataList = InvitationOfficialActivityDataList
+                    .WhereIF(!string.IsNullOrWhiteSpace(dto.Country), x => !string.IsNullOrWhiteSpace(x.Country) && x.Country.Contains(dto.Country))
+                    .WhereIF(!string.IsNullOrWhiteSpace(dto.UnitName), x => !string.IsNullOrWhiteSpace(x.UnitName) && x.UnitName.Contains(dto.UnitName))
+                    .WhereIF(!string.IsNullOrWhiteSpace(dto.Contact), x => !string.IsNullOrWhiteSpace(x.Contact) && x.Contact.Contains(dto.Contact))
+                    .WhereIF(!string.IsNullOrWhiteSpace(dto.Delegation), x => !string.IsNullOrWhiteSpace(x.Delegation) && x.Delegation.Contains(dto.Delegation))
+                    .WhereIF(!string.IsNullOrWhiteSpace(dto.Field), x => !string.IsNullOrWhiteSpace(x.Field) && x.Field.Contains(dto.Field))
+                    .ToList();
 
 
                 foreach (var item in ExcludedKeyStr)
                 foreach (var item in ExcludedKeyStr)
                 {
                 {
@@ -1503,40 +1504,40 @@ Inner Join Sys_Department as d With(Nolock) On u.DepId=d.Id Where m.Id={0} ", _m
                 RefAsync<int> totalCount = 0;
                 RefAsync<int> totalCount = 0;
 
 
                 var _ivitiesViews = await _sqlSugar.Queryable<Res_InvitationOfficialActivityData>()
                 var _ivitiesViews = await _sqlSugar.Queryable<Res_InvitationOfficialActivityData>()
-                                             .LeftJoin<Sys_Users>((a, b) => b.IsDel == 0 && a.CreateUserId == b.Id)
-                                             .Where((a, b) => ids.Contains(a.Id))
-                                             .OrderByDescending((a, b) => a.CreateTime)
-                                             .Select((a, b) => new InvitationOfficialActivityDataView
-                                             {
-                                                 FaceBook = a.FaceBook,
-                                                 Id = a.Id,
-                                                 CreateUserId = a.CreateUserId,
-                                                 IsDel = 0,
-                                                 Address = a.Address,
-                                                 Background = a.Background,
-                                                 City = a.City,
-                                                 Contact = a.Contact,
-                                                 Country = a.Country,
-                                                 CreateTime = a.CreateTime,
-                                                 CreateUserName = b.CnName,
-                                                 Delegation = a.Delegation,
-                                                 Email = a.Email,
-                                                 Fax = a.Fax,
-                                                 Field = a.Field,
-                                                 FilePath = a.FilePath,
-                                                 Ins = a.Ins,
-                                                 WeChat = a.WeChat,
-                                                 UnitWeb = a.UnitWeb,
-                                                 UnitName = a.UnitName,
-                                                 UnitInfo = a.UnitInfo,
-                                                 Tel = a.Tel,
-                                                 SndFilePath = a.SndFilePath,
-                                                 SndFileName = a.SndFileName,
-                                                 Remark = a.Remark,
-                                                 OtherInfo = a.OtherInfo,
-                                                 Job = a.Job
-                                             })
-                                             .ToPageListAsync(dto.PageIndex, dto.PageSize, totalCount);
+                    .LeftJoin<Sys_Users>((a, b) => b.IsDel == 0 && a.CreateUserId == b.Id)
+                    .Where((a, b) => ids.Contains(a.Id))
+                    .OrderByDescending((a, b) => a.CreateTime)
+                    .Select((a, b) => new InvitationOfficialActivityDataView
+                    {
+                        FaceBook = a.FaceBook,
+                        Id = a.Id,
+                        CreateUserId = a.CreateUserId,
+                        IsDel = 0,
+                        Address = a.Address,
+                        Background = a.Background,
+                        City = a.City,
+                        Contact = a.Contact,
+                        Country = a.Country,
+                        CreateTime = a.CreateTime,
+                        CreateUserName = b.CnName,
+                        Delegation = a.Delegation,
+                        Email = a.Email,
+                        Fax = a.Fax,
+                        Field = a.Field,
+                        FilePath = a.FilePath,
+                        Ins = a.Ins,
+                        WeChat = a.WeChat,
+                        UnitWeb = a.UnitWeb,
+                        UnitName = a.UnitName,
+                        UnitInfo = a.UnitInfo,
+                        Tel = a.Tel,
+                        SndFilePath = a.SndFilePath,
+                        SndFileName = a.SndFileName,
+                        Remark = a.Remark,
+                        OtherInfo = a.OtherInfo,
+                        Job = a.Job
+                    })
+                    .ToPageListAsync(dto.PageIndex, dto.PageSize, totalCount);
 
 
                 var allGroupIds = new HashSet<int>();
                 var allGroupIds = new HashSet<int>();
                 foreach (var item in _ivitiesViews)
                 foreach (var item in _ivitiesViews)

+ 4 - 0
OASystem/OASystem.Domain/Entities/Groups/Grp_NationalTravelFee.cs

@@ -70,3 +70,7 @@ namespace OASystem.Domain.Entities.Groups
 
 
     }
     }
 }
 }
+
+
+
+

+ 11 - 0
OASystem/OASystem.Domain/Entities/Resource/Res_InvitationOfficialActivityData.cs

@@ -145,5 +145,16 @@ namespace OASystem.Domain.Entities.Resource
         [SugarColumn(IsNullable = true, ColumnDataType = "varchar(500)")]
         [SugarColumn(IsNullable = true, ColumnDataType = "varchar(500)")]
         [Encrypted]
         [Encrypted]
         public string Background { get; set; }
         public string Background { get; set; }
+
+        /// <summary>
+        /// 最后更新者Id
+        /// </summary>
+        [SugarColumn(ColumnDescription = "最后更新者Id", IsNullable = true, ColumnDataType = "int")]
+        public int LastUpdateUserId { get; set; }
+        /// <summary>
+        ///  最后更新时间
+        /// </summary>
+        [SugarColumn(ColumnDescription = "最后更新时间", IsNullable = true, ColumnDataType = "DateTime")]
+        public DateTime LastUpdateTime { get; set; }
     }
     }
 }
 }

+ 15 - 0
OASystem/OASystem.Domain/ViewModels/Resource/InvitationOfficialActivityDataView.cs

@@ -18,6 +18,20 @@ namespace OASystem.Domain.ViewModels.Resource
         public int Row_Number { get; set; }
         public int Row_Number { get; set; }
         public string CreateUserName { get; set; }
         public string CreateUserName { get; set; }
         public string DelegationStr { get; set; }
         public string DelegationStr { get; set; }
+
+        /// <summary>
+        /// 最后更新时间距今天的天数
+        /// </summary>
+        public int LastUpdateDays
+        {
+            get
+            {
+                int days = 0;
+                if (LastUpdateTime == DateTime.MinValue) days = DateTime.Now.Subtract(CreateTime).Days;
+                else days = DateTime.Now.Subtract(LastUpdateTime).Days;
+                return days;
+            }
+        }
     }
     }
 
 
     public class IOAInfoView
     public class IOAInfoView
@@ -178,5 +192,6 @@ namespace OASystem.Domain.ViewModels.Resource
         public string Remark { get; set; }
         public string Remark { get; set; }
 
 
         public string DelegationStr { get; set; }
         public string DelegationStr { get; set; }
+
     }
     }
 }
 }

+ 11 - 0
OASystem/OASystem.Domain/ViewModels/Resource/TranslatorLibraryView.cs

@@ -159,6 +159,17 @@ namespace OASystem.Domain.ViewModels.Resource
         public DateTime CreateTime { get; set; }
         public DateTime CreateTime { get; set; }
         [Encrypted]
         [Encrypted]
         public string Remark { get; set; }
         public string Remark { get; set; }
+        public DateTime LastUpddateTime { get; set; }
+        public int LastUpdateDays
+        {
+            get
+            {
+                int days = 0;
+                if (LastUpddateTime == DateTime.MinValue) days = DateTime.Now.Subtract(CreateTime).Days;
+                else days = DateTime.Now.Subtract(LastUpddateTime).Days;
+                return days;
+            }
+        }
     }
     }
 
 
 
 

+ 7 - 0
OASystem/OASystem.Domain/ViewModels/ViewBase.cs

@@ -101,4 +101,11 @@
 
 
         public int Total { get; set; }
         public int Total { get; set; }
     }
     }
+
+    public class TextView
+    {
+        public string Value { get; set; }
+        public string Text { get; set; }
+    }
+
 }
 }

+ 12 - 1
OASystem/OASystem.Infrastructure/Repositories/Groups/DelegationInfoRepository.cs

@@ -535,6 +535,15 @@ namespace OASystem.Infrastructure.Repositories.Groups
                     }).ToList();
                     }).ToList();
                 }
                 }
 
 
+                var userDepDatas = new List<TextView>();
+                userDepDatas.Insert(0, new TextView() { Text = "全部", Value = "全部" });
+                userDepDatas.Insert(1, new TextView() { Text = "国交部", Value = "国交部" });
+                userDepDatas.Insert(2, new TextView() { Text = "市场部", Value = "市场部" });
+                userDepDatas.Insert(3, new TextView() { Text = "策划部", Value = "策划部" });
+
+                var rankDatas = await _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && x.STid == 56).Select(x => new TextView { Value = x.Id.ToString(), Text = x.Name }).ToListAsync();
+                rankDatas.Insert(0, new TextView { Value = "0", Text = "全部" });
+
                 result.Code = 0;
                 result.Code = 0;
                 result.Msg = "成功!";
                 result.Msg = "成功!";
                 result.Data = new
                 result.Data = new
@@ -542,7 +551,9 @@ namespace OASystem.Infrastructure.Repositories.Groups
                     teamTypeData = teamTypeData1,
                     teamTypeData = teamTypeData1,
                     teamLevData = teamLevData1,
                     teamLevData = teamLevData1,
                     userData = userData1,
                     userData = userData1,
-                    clientData = clientData1
+                    clientData = clientData1,
+                    depData = userDepDatas,
+                    rankData = rankDatas
                 };
                 };
             }
             }
 
 

+ 30 - 27
OASystem/OASystem.Infrastructure/Repositories/Resource/InvitationOfficialActivityDataRepository.cs

@@ -45,31 +45,31 @@ namespace OASystem.Infrastructure.Repositories.Resource
             RefAsync<int> total = 0;
             RefAsync<int> total = 0;
             
             
             var _view = await _sqlSugar.Queryable<Res_InvitationOfficialActivityData>()
             var _view = await _sqlSugar.Queryable<Res_InvitationOfficialActivityData>()
-                                        .LeftJoin<Sys_Users>((ioa, u) => ioa.CreateUserId == u.Id)
-                                        .Where((ioa,u) => ioa.IsDel == 0)
-                                        .WhereIF(!string.IsNullOrEmpty(dto.Country), (ioa, u) => ioa.Country.Contains(dto.Country))
-                                        .WhereIF(!string.IsNullOrEmpty(dto.UnitName), (ioa, u) => ioa.UnitName.Contains(dto.UnitName))
-                                        .WhereIF(!string.IsNullOrEmpty(dto.Contact), (ioa, u) => ioa.Contact.Contains(dto.Contact))
-                                        .WhereIF(!string.IsNullOrEmpty(dto.Delegation), (ioa, u) => ioa.Delegation.Contains(dto.Delegation))
-                                        .WhereIF(!string.IsNullOrEmpty(dto.Field), (ioa, u) => ioa.Field.Contains(dto.Field))
-                                        .WhereIF(_beginDtBool && _endDtBool, (ioa, u) => ioa.CreateTime >= _beginDt && ioa.CreateTime <= _endDt)
-                                        .WhereIF(dto.CreateUserId > 0, (ioa, u) => ioa.CreateUserId == dto.CreateUserId)
-                                        .Select((ioa, u) => new { 
-                                            Row_Number = ioa.RowIndex,
-                                            ioa.Id,
-                                            ioa.Country,
-                                            ioa.City,
-                                            ioa.UnitName,
-                                            ioa.Field,
-                                            ioa.Contact,
-                                            ioa.Job,
-                                            ioa.Tel,
-                                            ioa.CreateTime,
-                                            CreateUserName = u.CnName,
-                                            DelegationStr = ioa.Delegation
-                                        })
-                                        .OrderByDescending((ioa) => ioa.CreateTime)
-                                        .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
+                .LeftJoin<Sys_Users>((ioa, u) => ioa.CreateUserId == u.Id)
+                .Where((ioa,u) => ioa.IsDel == 0)
+                .WhereIF(!string.IsNullOrEmpty(dto.Country), (ioa, u) => ioa.Country.Contains(dto.Country))
+                .WhereIF(!string.IsNullOrEmpty(dto.UnitName), (ioa, u) => ioa.UnitName.Contains(dto.UnitName))
+                .WhereIF(!string.IsNullOrEmpty(dto.Contact), (ioa, u) => ioa.Contact.Contains(dto.Contact))
+                .WhereIF(!string.IsNullOrEmpty(dto.Delegation), (ioa, u) => ioa.Delegation.Contains(dto.Delegation))
+                .WhereIF(!string.IsNullOrEmpty(dto.Field), (ioa, u) => ioa.Field.Contains(dto.Field))
+                .WhereIF(_beginDtBool && _endDtBool, (ioa, u) => ioa.CreateTime >= _beginDt && ioa.CreateTime <= _endDt)
+                .WhereIF(dto.CreateUserId > 0, (ioa, u) => ioa.CreateUserId == dto.CreateUserId)
+                .Select((ioa, u) => new { 
+                    Row_Number = ioa.RowIndex,
+                    ioa.Id,
+                    ioa.Country,
+                    ioa.City,
+                    ioa.UnitName,
+                    ioa.Field,
+                    ioa.Contact,
+                    ioa.Job,
+                    ioa.Tel,
+                    ioa.CreateTime,
+                    CreateUserName = u.CnName,
+                    DelegationStr = ioa.Delegation
+                })
+                .OrderByDescending((ioa) => ioa.CreateTime)
+                .ToPageListAsync(dto.PageIndex, dto.PageSize, total);
 
 
 
 
             foreach (var item in _view)
             foreach (var item in _view)
@@ -214,6 +214,8 @@ namespace OASystem.Infrastructure.Repositories.Resource
             JsonView result = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "操作失败!" };
             JsonView result = new JsonView() { Code = StatusCodes.Status400BadRequest, Msg = "操作失败!" };
 
 
             var _info = _mapper.Map<Res_InvitationOfficialActivityData>(dto);
             var _info = _mapper.Map<Res_InvitationOfficialActivityData>(dto);
+            _info.LastUpdateTime = _info.CreateTime;
+            _info.LastUpdateUserId = _info.CreateUserId;
 
 
             if (dto.Status == 1)//添加
             if (dto.Status == 1)//添加
             {
             {
@@ -286,7 +288,9 @@ namespace OASystem.Infrastructure.Repositories.Resource
                     SndFileName = _info.SndFileName,
                     SndFileName = _info.SndFileName,
                     Fax = _info.Fax,
                     Fax = _info.Fax,
                     //CreateUserId = _info.CreateUserId,
                     //CreateUserId = _info.CreateUserId,
-                    Remark = _info.Remark
+                    Remark = _info.Remark,
+                    LastUpdateUserId = _info.LastUpdateUserId,
+                    LastUpdateTime = _info.LastUpdateTime
                 });
                 });
 
 
                 if (!res) return result;
                 if (!res) return result;
@@ -316,7 +320,6 @@ namespace OASystem.Infrastructure.Repositories.Resource
             return result;
             return result;
         }
         }
 
 
-
         public async Task< List<string>> Upload(IFormFile[] formFiles)
         public async Task< List<string>> Upload(IFormFile[] formFiles)
         {
         {
             var fileNames = new List<string>();
             var fileNames = new List<string>();