Просмотр исходного кода

商邀资料查询 QueryInvitationOfficialActivityData
更改为后台分页

leiy 1 год назад
Родитель
Сommit
1ddfc7ddae

+ 52 - 8
OASystem/OASystem.Api/Controllers/ResourceController.cs

@@ -1378,19 +1378,63 @@ Inner Join Sys_Department as d With(Nolock) On u.DepId=d.Id Where m.Id={0} ", _m
         {
             try
             {
-                Stopwatch stopwatch = Stopwatch.StartNew();
-                Result groupData = await _InvitationOfficialActivityDataRep.QueryInvitationOfficialActivityData(dto);
-                if (groupData.Code != 0)
+                #region 参数验证
+
+                if (dto.PageIndex < 1) return Ok(JsonView(false, "请传入有效的PageIndex参数!"));
+
+                if (dto.PageSize < 1) return Ok(JsonView(false, "请传入有效的PageSize参数!"));
+
+                #endregion
+
+                string sqlWhere = string.Empty;
+                if (!string.IsNullOrWhiteSpace(dto.Country)) { sqlWhere += string.Format(@" And i.Country like '%{0}%'", dto.Country); }
+                if (!string.IsNullOrWhiteSpace(dto.UnitName)) { sqlWhere += string.Format(@" And i.UnitName like '%{0}%'", dto.UnitName); }
+                if (!string.IsNullOrWhiteSpace(dto.Contact)) { sqlWhere += string.Format(@" And i.Contact like '%{0}%'", dto.Contact); }
+                if (!string.IsNullOrWhiteSpace(dto.Delegation)) { sqlWhere += string.Format(@" And ','+i.Delegation+',' like '%,{0},%'", dto.Delegation); }
+                if (!string.IsNullOrWhiteSpace(dto.Field)) { sqlWhere += string.Format(@" And i.Field like '%{0}%'", dto.Field); }
+
+                if (dto.CreateUserId != 0 && !string.IsNullOrWhiteSpace(dto.CreateUserId.ToString())) { sqlWhere += string.Format(@" And i.CreateUserId={0}", dto.CreateUserId); }
+                if (!string.IsNullOrWhiteSpace(dto.StartCreateTime) && !string.IsNullOrWhiteSpace(dto.EndCreateTime))
                 {
-                    return Ok(JsonView(false, groupData.Msg));
+                    sqlWhere += string.Format(@" And i.CreateTime between '{0}' and '{1}'", dto.StartCreateTime, dto.EndCreateTime);
+                }
+                sqlWhere += string.Format(@"And Isdel={0}", 0);
+
+                if (!string.IsNullOrEmpty(sqlWhere.Trim()))
+                {
+                    Regex r = new Regex("And");
+                    sqlWhere = r.Replace(sqlWhere, "Where", 1);
                 }
-                stopwatch.Stop();
-                return Ok(JsonView(true, $"{groupData.Msg} 耗时:{stopwatch.ElapsedMilliseconds / 1000}s", groupData.Data));
+                string sql = string.Format(@"Select ROW_NUMBER() Over(Order By i.CreateTime Desc) As Row_Number,
+                                             i.*,u.CnName As CreateUserName 
+                                             From Res_InvitationOfficialActivityData i 
+                                             Left Join Sys_Users u On i.CreateUserId = u.Id {0}", sqlWhere);
+
+                int totalCount = 0;
+
+                List<InvitationOfficialActivityDataView> _ivitiesViews = _sqlSugar.SqlQueryable<InvitationOfficialActivityDataView>(sql).ToPageList(dto.PageIndex, dto.PageSize, ref totalCount);
+
+                List<Grp_DelegationInfo> _DelegationInfos = _sqlSugar.Queryable<Grp_DelegationInfo>().ToList();
+
+                foreach (var item in _ivitiesViews)
+                {
+                    string delegationNameList = "";
+                    string[] DelegationName = item.Delegation.Split(',');
+                    for (int i = 0; i < DelegationName.Length; i++)
+                    {
+                        delegationNameList += _DelegationInfos.Find(it => it.Id == int.Parse(DelegationName[i]))?.TeamName ?? "Unknown" + ",";
+                    }
+                    if (!string.IsNullOrWhiteSpace(delegationNameList))
+                    {
+                        item.DelegationStr = delegationNameList.Substring(0, delegationNameList.Length - 1);
+                    }
+                }
+
+                return Ok(JsonView(true, $"查询成功!", _ivitiesViews, totalCount));
             }
             catch (Exception ex)
             {
-                return Ok(JsonView(false, "程序错误!"));
-                throw;
+                return Ok(JsonView(false, ex.Message));
             }
         }
         /// <summary>

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

@@ -10,6 +10,7 @@ namespace OASystem.Domain.ViewModels.Resource
 {
     public class InvitationOfficialActivityDataView: Res_InvitationOfficialActivityData
     {
+        public int Row_Number { get; set; }
         public string CreateUserName { get; set; }
         public string DelegationStr { get;set; }
     }