| 
					
				 | 
			
			
				@@ -35,195 +35,276 @@ namespace OASystem.Infrastructure.Repositories.CRM 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         public async Task<Result> QueryNewClientData(NewClientDataQueryDto dto) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             Result result = new Result() { Code = -2, Msg = "未知错误" }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             try 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if (dto.PortType == 1) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                #region 交集 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                List<int> NewClientDataId1 = new List<int>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                List<int> NewClientDataId2 = new List<int>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                string NewClientDataId = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                int state = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    List<int> NewClientDataId1 = new List<int>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    List<int> NewClientDataId2 = new List<int>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    string NewClientDataId = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    int state = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if ( !string.IsNullOrEmpty(dto.Userid) ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                #region 负责人 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (!string.IsNullOrWhiteSpace(dto.Userid)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    string sql = string.Format(@"select u1.UsersId,u2.CnName,u1.NewClientDataId from Crm_ClientDataAndUser u1,Sys_Users u2 where u1.UsersId=u2.Id and u1.UsersId in ({0})", dto.Userid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    List<AscribedUser> ascribedUsers = await _sqlSugar.SqlQueryable<AscribedUser>(sql).ToListAsync(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (ascribedUsers.Count != 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        string sql = string.Format(@"select u1.UsersId,u2.CnName,u1.NewClientDataId from Crm_ClientDataAndUser u1,Sys_Users u2 where u1.UsersId=u2.Id and u1.UsersId in ({0})", dto.Userid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        List<AscribedUser> ascribedUsers = await _sqlSugar.SqlQueryable<AscribedUser>(sql).ToListAsync(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        if (ascribedUsers.Count != 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        foreach (var ascribedUser in ascribedUsers) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            foreach (var ascribedUser in ascribedUsers) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            if (ascribedUser.NewClientDataId != 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                if (ascribedUser.NewClientDataId != 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                    NewClientDataId1.Add(ascribedUser.NewClientDataId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                NewClientDataId1.Add(ascribedUser.NewClientDataId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        else 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            result = new Result() { Code = -1, Msg = "暂无数据" }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        state = -1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (!string.IsNullOrWhiteSpace(dto.Business)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    else 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        result = new Result() { Code = -1, Msg = "暂无数据" }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    state = -1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                #endregion 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                #region 业务归属 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (!string.IsNullOrWhiteSpace(dto.Business)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    string sql = string.Format(@"select d1.*,d2.Name from Crm_ClientDataAndBusiness d1,Sys_SetData d2 where d1.SetDataId=d2.Id and d1.SetDataId in ({0})", dto.Business); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    List<AscribedDepartment> AscribedDepartment = await _sqlSugar.SqlQueryable<AscribedDepartment>(sql).ToListAsync(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (AscribedDepartment.Count != 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        string sql = string.Format(@"select d1.*,d2.Name from Crm_ClientDataAndBusiness d1,Sys_SetData d2 where d1.SetDataId=d2.Id and d1.SetDataId in ({0})", dto.Business); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        List<AscribedDepartment> AscribedDepartment = await _sqlSugar.SqlQueryable<AscribedDepartment>(sql).ToListAsync(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        if (AscribedDepartment.Count != 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        foreach (var item in AscribedDepartment) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            foreach (var item in AscribedDepartment) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            if (item.NewClientDataId != 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                if (item.NewClientDataId != 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                    NewClientDataId2.Add(item.NewClientDataId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                NewClientDataId2.Add(item.NewClientDataId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        else 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            result = new Result() { Code = -1, Msg = "暂无数据" }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        state = -1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    List<int> intStr = new List<int>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    else 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        result = new Result() { Code = -1, Msg = "暂无数据" }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    state = -1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                #endregion 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                List<int> intList = new List<int>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (NewClientDataId1.Count != 0 && NewClientDataId2.Count != 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        intStr = NewClientDataId1.Intersect(NewClientDataId2).ToList(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (NewClientDataId1.Count != 0 && NewClientDataId2.Count != 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    intList = NewClientDataId1.Intersect(NewClientDataId2).ToList(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    else if (NewClientDataId1.Count != 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        intStr = NewClientDataId1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    else if (NewClientDataId2.Count != 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        intStr = NewClientDataId2; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    foreach (var item in intStr) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        NewClientDataId += item + ","; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (!string.IsNullOrWhiteSpace(NewClientDataId)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        NewClientDataId = NewClientDataId.Substring(0, NewClientDataId.Length - 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    string sqlWhere = string.Empty; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (!string.IsNullOrWhiteSpace(dto.Contact)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        sqlWhere += string.Format(@" And s.Contact like '%{0}%'", dto.Contact); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (!string.IsNullOrWhiteSpace(dto.Location)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        sqlWhere += string.Format(@" And s.Location like '%{0}%'", dto.Location); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (!string.IsNullOrWhiteSpace(dto.Client)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        sqlWhere += string.Format(@" And s.Client like '%{0}%'", dto.Client); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (state == -1) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                else if (NewClientDataId1.Count != 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    intList = NewClientDataId1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                else if (NewClientDataId2.Count != 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    intList = NewClientDataId2; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                #endregion 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                foreach (var item in intList) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    NewClientDataId += item + ","; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (!string.IsNullOrWhiteSpace(NewClientDataId)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    NewClientDataId = NewClientDataId.Substring(0, NewClientDataId.Length - 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                string sqlWhere = string.Empty; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                #region 联系人条件 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (!string.IsNullOrWhiteSpace(dto.Contact)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    sqlWhere += string.Format(@" And s.Contact like '%{0}%'", dto.Contact); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                #endregion 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                #region 地区条件 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (!string.IsNullOrWhiteSpace(dto.Location)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    sqlWhere += string.Format(@" And s.Location like '%{0}%'", dto.Location); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                #endregion 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                #region 单位条件 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (!string.IsNullOrWhiteSpace(dto.Client)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    sqlWhere += string.Format(@" And s.Client like '%{0}%'", dto.Client); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                #endregion 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (state == -1) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (string.IsNullOrWhiteSpace(NewClientDataId)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        if (string.IsNullOrWhiteSpace(NewClientDataId)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            NewClientDataId = "0"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        sqlWhere += string.Format(@" And s.Id in({0})", NewClientDataId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        NewClientDataId = "0"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (dto.Lvlid != 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        sqlWhere += string.Format(@" And s.Lvlid={0}", dto.Lvlid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    sqlWhere += string.Format(@" And s.Id in({0})", NewClientDataId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                #region 地市州条件 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (dto.Lvlid != 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    sqlWhere += string.Format(@" And s.Lvlid={0}", dto.Lvlid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                #endregion 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                #region 省域条件 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (dto.Range != 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    string setDataSql = "select * from Sys_SetData where STid = 33 and isdel = 0  "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    switch (dto.Range) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        case 419: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            setDataSql += " and (Name like '%四%川%' or Name like '%成%都%')"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        case 421: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            setDataSql += " and (Name like '%贵%州%' or Name like '%贵%阳%')"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        case 420: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            setDataSql += " and (Name like '%云%南%' or Name like '%昆%明%')"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        case 423: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            setDataSql += " and (Name like '%重庆%')"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        case 422: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            setDataSql += " and (Name like '%西%藏%' or Name like '%拉%萨%')"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        case 578: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            setDataSql += " and (Name like '%青%海%' or Name like '%西%宁%')"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        case 605: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            setDataSql += " and (Name like '%陕%西%' or Name like '%西%安%')"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        case 606: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            setDataSql += " and (Name like '%宁%夏%' or Name like '%银%川%')"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        case 625: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            setDataSql += " and (Name like '%甘%肃%' or Name like '%兰%州%')"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        case 634: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            setDataSql += " and (Name like '%新%疆%' or Name like '%乌%鲁%木%齐%')"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    sqlWhere += string.Format(@" And s.Lvlid=s1.Id And s.IsDel={0} ", 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (!string.IsNullOrEmpty(sqlWhere.Trim())) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    var RangeSetDataList = _sqlSugar.SqlQueryable<Sys_SetData>(setDataSql).Select(x=>x.Id).ToList(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    string lvlds = string.Join(',', RangeSetDataList).TrimEnd(','); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (!string.IsNullOrEmpty(lvlds)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        Regex r = new Regex("And"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        sqlWhere = r.Replace(sqlWhere, "Where", 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        sqlWhere += string.Format(@" And s.Lvlid in ({0}) ", lvlds); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    int pIndex = dto.PageIndex * dto.PageSize - dto.PageSize + 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    int pSize = dto.PageIndex * dto.PageSize; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    string sqlNew = string.Format(@"select (SELECT  COUNT(1) FROM Crm_NewClientData s left Join Sys_SetData s1  On s.Lvlid=s1.Id {0}) AS countPage,* from (select ROW_NUMBER()  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                #endregion 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                #region 客户类别 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (dto.Category != 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    sqlWhere += string.Format(@" And s.Category = {0}", dto.Category); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                #endregion 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                sqlWhere += string.Format(@" And s.Lvlid=s1.Id And s.IsDel={0} ", 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (!string.IsNullOrEmpty(sqlWhere.Trim())) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    Regex r = new Regex("And"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    sqlWhere = r.Replace(sqlWhere, "Where", 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                int pIndex = dto.PageIndex * dto.PageSize - dto.PageSize + 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                int pSize = dto.PageIndex * dto.PageSize; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                string sqlNew = string.Format(@"select (SELECT  COUNT(1) FROM Crm_NewClientData s left Join Sys_SetData s1  On s.Lvlid=s1.Id {0}) AS countPage,* from (select ROW_NUMBER()  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                                     over(order by s.CreateTime desc) RowNumber,s.*,s1.Name as 'LvlName' from Crm_NewClientData s left Join Sys_SetData s1  On s.Lvlid=s1.Id {0}) as co where     
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                                     RowNumber between {1} and {2} ", sqlWhere, pIndex, pSize); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    List<NewClientDataView> NewClientDataView = await _sqlSugar.SqlQueryable<NewClientDataView>(sqlNew).ToListAsync(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    foreach (var item in NewClientDataView) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        Sys_SetData CategoryStr = _sqlSugar.Queryable<Sys_SetData>().Single(it => it.Id == item.Category); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        item.CategoryStr = CategoryStr != null ? CategoryStr.Name : null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        Sys_SetData lvlStr = _sqlSugar.Queryable<Sys_SetData>().Single(it => it.Id == item.Lvlid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        item.LvlidStr = lvlStr != null ? lvlStr.Name : null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    #region 下拉框初始化数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    //负责人下拉框 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    List<dynamic> _Users = new List<dynamic>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    List<Sys_Users> users = _sqlSugar.Queryable<Sys_Users>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    .Where(u => u.CnName == "张海麟" || u.CnName == "安宁" || u.CnName == "李彩娟" || u.CnName == "舒庆" || u.CnName == "李媛媛" && u.IsDel == 0).ToList(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    foreach (Sys_Users user in users) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        var data = new 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                List<NewClientDataView> NewClientDataView = await _sqlSugar.SqlQueryable<NewClientDataView>(sqlNew).ToListAsync(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                foreach (var item in NewClientDataView) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    Sys_SetData CategoryStr = _sqlSugar.Queryable<Sys_SetData>().Single(it => it.Id == item.Category); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    item.CategoryStr = CategoryStr != null ? CategoryStr.Name : null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    Sys_SetData lvlStr = _sqlSugar.Queryable<Sys_SetData>().Single(it => it.Id == item.Lvlid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    item.LvlidStr = lvlStr != null ? lvlStr.Name : null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (NewClientDataView.Count > 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    int count = NewClientDataView[0].countPage; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    float totalPage = (float)count / dto.PageSize;//总页数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (totalPage == 0) totalPage = 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    else totalPage = (int)Math.Ceiling((double)totalPage); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (dto.PortType == 1) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        #region 下拉框初始化数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        //负责人下拉框 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        List<dynamic> _Users = new List<dynamic>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        List<Sys_Users> users = _sqlSugar.Queryable<Sys_Users>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .Where(u => (u.CnName == "张海麟" || u.CnName == "安宁" || u.CnName == "李彩娟" || u.CnName == "舒庆" || u.CnName == "李媛媛") && u.IsDel == 0).ToList(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        foreach (Sys_Users user in users) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            Id = user.Id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            Name = user.CnName 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            var data = new 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                Id = user.Id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                Name = user.CnName 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            _Users.Add(data); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        _Users.Add(data); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    //省域数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    List<dynamic> _Province = new List<dynamic>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    List<Sys_SetData> province = _sqlSugar.Queryable<Sys_SetData>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    .Where(u => u.STid == 42 && u.IsDel == 0).ToList(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    foreach (Sys_SetData item in province) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        var data = new 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        //省域数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        List<dynamic> _Province = new List<dynamic>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        List<Sys_SetData> province = _sqlSugar.Queryable<Sys_SetData>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .Where(u => u.STid == 42 && u.IsDel == 0).ToList(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        foreach (Sys_SetData item in province) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            Id = item.Id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            Name = item.Name 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            var data = new 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                Id = item.Id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                Name = item.Name 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            _Province.Add(data); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        _Province.Add(data); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    //客户级别数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    List<dynamic> _level = new List<dynamic>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    List<Sys_SetData> level = _sqlSugar.Queryable<Sys_SetData>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    .Where(u => u.STid == 33 && u.IsDel == 0).ToList(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    foreach (Sys_SetData item in level) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        var data = new 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        //客户级别数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        List<dynamic> _level = new List<dynamic>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        List<Sys_SetData> level = _sqlSugar.Queryable<Sys_SetData>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .Where(u => u.STid == 33 && u.IsDel == 0).ToList(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        foreach (Sys_SetData item in level) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            Id = item.Id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            Name = item.Name 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            var data = new 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                Id = item.Id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                Name = item.Name 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            _level.Add(data); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        _level.Add(data); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    //客户类别 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    List<dynamic> _CustomerClass = new List<dynamic>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    List<Sys_SetData> CustomerClass = _sqlSugar.Queryable<Sys_SetData>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    .Where(u => u.STid == 37 && u.IsDel == 0).ToList(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    foreach (Sys_SetData item in CustomerClass) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        var data = new 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        //客户类别 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        List<dynamic> _CustomerClass = new List<dynamic>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        List<Sys_SetData> CustomerClass = _sqlSugar.Queryable<Sys_SetData>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .Where(u => u.STid == 37 && u.IsDel == 0).ToList(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        foreach (Sys_SetData item in CustomerClass) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            Id = item.Id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            Name = item.Name 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            var data = new 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                Id = item.Id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                Name = item.Name 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            _CustomerClass.Add(data); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        _CustomerClass.Add(data); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    //业务分类  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    List<dynamic> _ServiceClass = new List<dynamic>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    List<Sys_SetData> ServiceClass = _sqlSugar.Queryable<Sys_SetData>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    .Where(u => u.STid == 36 && u.IsDel == 0).ToList(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    foreach (Sys_SetData item in province) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        var data = new 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        //业务分类  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        List<dynamic> _ServiceClass = new List<dynamic>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        List<Sys_SetData> ServiceClass = _sqlSugar.Queryable<Sys_SetData>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        .Where(u => u.STid == 36 && u.IsDel == 0).ToList(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        foreach (Sys_SetData item in province) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            Id = item.Id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            Name = item.Name 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            var data = new 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                Id = item.Id, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                                Name = item.Name 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            _ServiceClass.Add(data); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        _ServiceClass.Add(data); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        #endregion 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    #endregion 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (NewClientDataView.Count != 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         foreach (var item in NewClientDataView) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             List<AscribedUser> AscribedUser = await _sqlSugar.SqlQueryable<AscribedUser> 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -235,12 +316,6 @@ namespace OASystem.Infrastructure.Repositories.CRM 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                             item.AscribedDepartment = AscribedDepartment; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        int count = NewClientDataView[0].countPage; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        float totalPage = (float)count / dto.PageSize;//总页数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        if (totalPage == 0) totalPage = 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        else totalPage = (int)Math.Ceiling((double)totalPage); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         var groupNumber = await QueryNumberGroups(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         var Data = new 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -261,133 +336,21 @@ namespace OASystem.Infrastructure.Repositories.CRM 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    else 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    else if (dto.PortType == 2) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        result = new Result() { Code = -1, Msg = "暂无数据!" }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        result = new Result() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            Code = 0, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            Msg = "查询成功", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                            Data = new { pageCount = count, totalPage = (int)totalPage, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = NewClientDataView }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                else if (dto.PortType == 2) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                else 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    List<int> NewClientDataId1 = new List<int>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    List<int> NewClientDataId2 = new List<int>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    string NewClientDataId = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (!string.IsNullOrWhiteSpace(dto.Userid)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        string sql = string.Format(@"select u1.UsersId,u2.CnName,u1.NewClientDataId from Crm_ClientDataAndUser u1,Sys_Users u2 where u1.UsersId=u2.Id and u1.UsersId in ({0}) and u1.isdel = 0 and u2.isdel = 0", dto.Userid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        List<AscribedUser> ascribedUsers = await _sqlSugar.SqlQueryable<AscribedUser>(sql).ToListAsync(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        if (ascribedUsers.Count != 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            foreach (var ascribedUser in ascribedUsers) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                if (ascribedUser.NewClientDataId != 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                    NewClientDataId1.Add(ascribedUser.NewClientDataId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        else 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            result = new Result() { Code = -1, Msg = "暂无数据" }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (!string.IsNullOrWhiteSpace(dto.Business)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        string sql = string.Format(@"select d1.*,d2.Name from Crm_ClientDataAndBusiness d1,Sys_SetData d2 where d1.SetDataId=d2.Id and d1.SetDataId in({0}) and d1.isdel = 0 and d2.isdel = 0", dto.Business); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        List<AscribedDepartment> AscribedDepartment = await _sqlSugar.SqlQueryable<AscribedDepartment>(sql).ToListAsync(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        if (AscribedDepartment.Count != 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            foreach (var item in AscribedDepartment) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                if (item.NewClientDataId != 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                    NewClientDataId2.Add(item.NewClientDataId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        else 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                            result = new Result() { Code = -1, Msg = "暂无数据" }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    List<int> intStr = new List<int>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (NewClientDataId1.Count != 0 && NewClientDataId2.Count != 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        intStr = NewClientDataId1.Intersect(NewClientDataId2).ToList(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    else if (NewClientDataId1.Count != 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        intStr = NewClientDataId1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    else if (NewClientDataId2.Count != 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        intStr = NewClientDataId2; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    foreach (var item in intStr) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        NewClientDataId += item + ","; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (!string.IsNullOrWhiteSpace(NewClientDataId)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        NewClientDataId = NewClientDataId.Substring(0, NewClientDataId.Length - 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    string sqlWhere = string.Empty; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (!string.IsNullOrWhiteSpace(dto.Contact)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        sqlWhere += string.Format(@" And s.Contact like '%{0}%'", dto.Contact); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (!string.IsNullOrWhiteSpace(dto.Location)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        sqlWhere += string.Format(@" And s.Location like '%{0}%'", dto.Location); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (!string.IsNullOrWhiteSpace(dto.Client)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        sqlWhere += string.Format(@" And s.Client like '%{0}%'", dto.Client); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (!string.IsNullOrWhiteSpace(NewClientDataId)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        sqlWhere += string.Format(@" And s.Id in({0})", NewClientDataId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (dto.Lvlid != 0) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        sqlWhere += string.Format(@" And s.Lvlid={0}", dto.Lvlid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    sqlWhere += string.Format(@" And s.Lvlid=s1.Id And s.IsDel={0} ", 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (!string.IsNullOrEmpty(sqlWhere.Trim())) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        Regex r = new Regex("And"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        sqlWhere = r.Replace(sqlWhere, "Where", 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    #region 分页查询 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    int pIndex = dto.PageIndex * dto.PageSize - dto.PageSize + 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    int pSize = dto.PageIndex * dto.PageSize; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    string sqlNew = string.Format(@"select (SELECT  COUNT(1) FROM Crm_NewClientData s left Join Sys_SetData s1  On s.Lvlid=s1.Id {0}) AS countPage,* from (select ROW_NUMBER()  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                                    over(order by s.CreateTime desc) RowNumber,s.*,s1.Name as 'LvlName' from Crm_NewClientData s left Join Sys_SetData s1  On s.Lvlid=s1.Id {0}) as co where     
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                                                    RowNumber between {1} and {2} ", sqlWhere, pIndex, pSize); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    List<NewClientDataView> NewClientDataView = await _sqlSugar.SqlQueryable<NewClientDataView>(sqlNew).ToListAsync(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    #endregion 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    foreach (var item in NewClientDataView) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        Sys_SetData CategoryStr = _sqlSugar.Queryable<Sys_SetData>().Single(it => it.Id == item.Category); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        item.CategoryStr = CategoryStr.Name; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        Sys_SetData lvlStr = _sqlSugar.Queryable<Sys_SetData>().Single(it => it.Id == item.Lvlid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        item.LvlidStr = lvlStr.Name; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    int count = NewClientDataView[0].countPage; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    float totalPage = (float)count / dto.PageSize;//总页数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    if (totalPage == 0) totalPage = 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    else totalPage = (int)Math.Ceiling((double)totalPage); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    result = new Result() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        Code = 0, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        Msg = "查询成功", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                        Data = new { pageCount = count, totalPage = (int)totalPage, pageIndex = dto.PageIndex, pageSize = dto.PageSize, pageSource = NewClientDataView }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    result = new Result() { Code = -1, Msg = "暂无数据!" }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             catch (Exception ex) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -404,7 +367,7 @@ namespace OASystem.Infrastructure.Repositories.CRM 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 //负责人下拉框 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 List<dynamic> _Users = new List<dynamic>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 List<Sys_Users> users = _sqlSugar.Queryable<Sys_Users>() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                .Where(u => u.CnName == "张海麟" || u.CnName == "安宁" || u.CnName == "李彩娟" || u.CnName == "舒庆" || u.CnName == "李媛媛" && u.IsDel == 0).ToList(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                .Where(u => (u.CnName == "张海麟" || u.CnName == "安宁" || u.CnName == "李彩娟" || u.CnName == "舒庆" || u.CnName == "李媛媛") && u.IsDel == 0).ToList(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 foreach (Sys_Users user in users) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     var data = new 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -423,7 +386,6 @@ namespace OASystem.Infrastructure.Repositories.CRM 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             catch (Exception) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 result = new Result() { Code = -2, Msg = "未知错误" }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                throw; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -496,7 +458,6 @@ namespace OASystem.Infrastructure.Repositories.CRM 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             catch (Exception) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 result = new Result() { Code = -2, Msg = "未知错误" }; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                throw; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 |