From 10ada97c04a399429285003bfcf97bbf8b24e940 Mon Sep 17 00:00:00 2001
From: username@email.com <yzy2002yzy@163.com>
Date: 星期一, 21 十一月 2022 14:41:52 +0800
Subject: [PATCH] 项目查询

---
 zhengcaioa/Services/ProjectService.cs |   47 ++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/zhengcaioa/Services/ProjectService.cs b/zhengcaioa/Services/ProjectService.cs
index 02ce881..6b8ba4d 100644
--- a/zhengcaioa/Services/ProjectService.cs
+++ b/zhengcaioa/Services/ProjectService.cs
@@ -612,21 +612,58 @@
 
 
             //}
+            if (!string.IsNullOrEmpty(searchEntity.Wanshan))
+            {
+                if (searchEntity.Wanshan == "A")
+                {
+                    sql.Append(" and ( a.[drhx] is null or exists  ( select b.[Id] from    [CooperatecustomCustomer] b where b.rec_status='A' and a.[drhx] = b.[name] union  select c.[Id] from    [IntentionCustomer] c where c.rec_status='A' and a.[drhx] = c.[name] ) ) ");
+
+                    sql.Append(" and ( a.[drhx] is null or  exists  ( select b.[Id] from    [CooperatecustomCustomer] b where b.rec_status='A' and a.[dshx] = b.[name] union  select c.[Id] from    [IntentionCustomer] c where c.rec_status='A' and a.[dshx] = c.[name] )  ) ");
+
+                    sql.Append(" and  ( a.[drhx] is null or  exists  ( select b.[Id] from    [CooperatecustomCustomer] b where b.rec_status='A' and a.[caigourenname] = b.[name] union  select c.[Id] from    [IntentionCustomer] c where c.rec_status='A' and a.[caigourenname] = c.[name] ) )  ");
+
+                    sql.Append(" and ( a.[drhx] is null or  exists  ( select b.[Id] from    [CooperatecustomCustomer] b where b.rec_status='A' and a.[dailiname] = b.[name] union  select c.[Id] from    [IntentionCustomer] c where c.rec_status='A' and a.[dailiname] = c.[name] ) )  ");
+
+                    sql.Append(" and (  a.[drhx] is null or  exists  ( select b.[Id] from    [CooperatecustomCustomer] b where b.rec_status='A' and a.[drhx] = b.[name] union  select c.[Id] from    [IntentionCustomer] c where c.rec_status='A' and a.[drhx] = c.[name] ) )  ");
+
+                    sql.Append(" and  (  (select count(b.zhongbiaoId)  from [Projectzhongbiao] b  where  a.[Id]=b.[ProjectId] )  = 0  or    ( (select count(b.zhongbiaoId)  from [Projectzhongbiao] b  where  a.[Id]=b.[ProjectId] ) = ( select count(b.zhongbiaoId) from [Projectzhongbiao] b  where  a.[Id]=b.[ProjectId]    and exists  ( select d.[Id] from    [CooperatecustomCustomer] d where d.rec_status='A' and b.[names] = d.[name] union  select c.[Id] from     [IntentionCustomer] c where c.rec_status='A' and b.[names] = c.[name] )   )))     ");
+                    sql.Append(" and  (  (select count(b.youxiaoId)  from [Projectyouxiao] b  where  a.[Id]=b.[ProjectId] )  = 0  or    ( (select count(b.youxiaoId)  from [Projectyouxiao] b  where  a.[Id]=b.[ProjectId] ) = ( select count(b.youxiaoId) from [Projectyouxiao] b  where  a.[Id]=b.[ProjectId]    and exists  ( select d.[Id] from    [CooperatecustomCustomer] d where d.rec_status='A' and b.[namesyouxiao] = d.[name] union  select c.[Id] from     [IntentionCustomer] c where c.rec_status='A' and b.[namesyouxiao] = c.[name] )   )))     ");
+                    sql.Append(" and  (  (select count(b.reasonId)  from [Projectreason] b  where  a.[Id]=b.[ProjectId] )  = 0   or    ( (select count(b.reasonId)  from [Projectreason] b  where  a.[Id]=b.[ProjectId] ) = ( select count(b.reasonId) from [Projectreason] b  where  a.[Id]=b.[ProjectId]    and exists  ( select d.[Id] from    [CooperatecustomCustomer] d where d.rec_status='A' and b.[reasonname] = d.[name] union  select c.[Id] from     [IntentionCustomer] c where c.rec_status='A' and b.[reasonname] = c.[name] )   )))     ");
+                }
+                else
+                {
+                    sql.Append(" and not  ( ( a.[drhx] is null or exists  ( select b.[Id] from    [CooperatecustomCustomer] b where b.rec_status='A' and a.[drhx] = b.[name] union  select c.[Id] from    [IntentionCustomer] c where c.rec_status='A' and a.[drhx] = c.[name] ) ) ");
+
+                    sql.Append(" and ( a.[drhx] is null or  exists  ( select b.[Id] from    [CooperatecustomCustomer] b where b.rec_status='A' and a.[dshx] = b.[name] union  select c.[Id] from    [IntentionCustomer] c where c.rec_status='A' and a.[dshx] = c.[name] )  ) ");
+
+                    sql.Append(" and  ( a.[drhx] is null or  exists  ( select b.[Id] from    [CooperatecustomCustomer] b where b.rec_status='A' and a.[caigourenname] = b.[name] union  select c.[Id] from    [IntentionCustomer] c where c.rec_status='A' and a.[caigourenname] = c.[name] ) )  ");
+
+                    sql.Append(" and ( a.[drhx] is null or  exists  ( select b.[Id] from    [CooperatecustomCustomer] b where b.rec_status='A' and a.[dailiname] = b.[name] union  select c.[Id] from    [IntentionCustomer] c where c.rec_status='A' and a.[dailiname] = c.[name] ) )  ");
+
+                    sql.Append(" and (  a.[drhx] is null or  exists  ( select b.[Id] from    [CooperatecustomCustomer] b where b.rec_status='A' and a.[drhx] = b.[name] union  select c.[Id] from    [IntentionCustomer] c where c.rec_status='A' and a.[drhx] = c.[name] ) )  ");
+
+                    sql.Append(" and  (  (select count(b.zhongbiaoId)  from [Projectzhongbiao] b  where  a.[Id]=b.[ProjectId] )  = 0  or    ( (select count(b.zhongbiaoId)  from [Projectzhongbiao] b  where  a.[Id]=b.[ProjectId] ) = ( select count(b.zhongbiaoId) from [Projectzhongbiao] b  where  a.[Id]=b.[ProjectId]    and exists  ( select d.[Id] from    [CooperatecustomCustomer] d where d.rec_status='A' and b.[names] = d.[name] union  select c.[Id] from     [IntentionCustomer] c where c.rec_status='A' and b.[names] = c.[name] )   )))     ");
+                    sql.Append(" and  (  (select count(b.youxiaoId)  from [Projectyouxiao] b  where  a.[Id]=b.[ProjectId] )  = 0  or    ( (select count(b.youxiaoId)  from [Projectyouxiao] b  where  a.[Id]=b.[ProjectId] ) = ( select count(b.youxiaoId) from [Projectyouxiao] b  where  a.[Id]=b.[ProjectId]    and exists  ( select d.[Id] from    [CooperatecustomCustomer] d where d.rec_status='A' and b.[namesyouxiao] = d.[name] union  select c.[Id] from     [IntentionCustomer] c where c.rec_status='A' and b.[namesyouxiao] = c.[name] )   )))     ");
+                    sql.Append(" and  (  (select count(b.reasonId)  from [Projectreason] b  where  a.[Id]=b.[ProjectId] )  = 0   or    ( (select count(b.reasonId)  from [Projectreason] b  where  a.[Id]=b.[ProjectId] ) = ( select count(b.reasonId) from [Projectreason] b  where  a.[Id]=b.[ProjectId]    and exists  ( select d.[Id] from    [CooperatecustomCustomer] d where d.rec_status='A' and b.[reasonname] = d.[name] union  select c.[Id] from     [IntentionCustomer] c where c.rec_status='A' and b.[reasonname] = c.[name] )   ))) )    ");
+                }
+            }
 
 
 
 
 
-
-            var query = _context.Projects
+                var query = _context.Projects
            .FromSqlRaw(sql.ToString()).OrderByDescending(x=>x.StartTime)
            .ToList();
 
-            
 
-            
+
+           
+
+
+
             //if (searchEntity.totalrows == 0)
-                searchEntity.totalrows = query.Count();
+            searchEntity.totalrows = query.Count();
             var lianlist = query.Skip((searchEntity.page - 1) * searchEntity.rows).Take(searchEntity.rows).ToList();
             list = _mapper.Map<List<ProjectDTO>>(lianlist);
 

--
Gitblit v1.9.1