tangjiang hai 9 meses
pai
achega
6f57113465

+ 25 - 61
src/Hotline.Application/StatisticalReport/OrderReportApplication.cs

@@ -23,69 +23,33 @@ namespace Hotline.Application.StatisticalReport
     public class OrderReportApplication : IOrderReportApplication, IScopeDependency
     {
         private readonly IOrderRepository _orderRepository;
-        private readonly IRepository<Hotspot> _hotspotTypeRepository;
-        private readonly ISystemDicDataCacheManager _sysDicDataCacheManager;
         private readonly IRepository<OrderVisitDetail> _orderVisitDetailRepository;
         private readonly IRepository<OrderDelay> _orderDelayRepository;
         private readonly IMapper _mapper;
-        private readonly IRepository<WorkflowCountersign> _workflowCountersignRepository;
-        private readonly IRepository<OrderSpecial> _orderSpecialRepository;
-        private readonly IRepository<OrderVisit> _orderVisitRepository;
-        private readonly IRepository<TrCallRecord> _trCallRecordRepository;
         private readonly IRepository<OrderPublish> _orderPublishRepository;
-        private readonly IRepository<SystemOrganize> _systemOrganizeRepository;
-        private readonly IRepository<AiOrderVisitDetail> _aiOrderVisitDetailRepository;
         private readonly ISessionContext _sessionContext;
-        private readonly ISystemSettingCacheManager _systemSettingCacheManager;
-        private readonly IRepository<OrderSpecialDetail> _orderSpecialDetailRepository;
         private readonly IRepository<WorkflowTrace> _workflowTraceRepository;
         private readonly IRepository<OrderScreen> _orderScreenRepository;
-        private readonly IOrderSecondaryHandlingApplication _orderSecondaryHandlingApplication;
-        private readonly ITimeLimitDomainService _timeLimitDomainService;
 
         public OrderReportApplication(
             IOrderRepository orderRepository,
-            IRepository<Hotspot> hotspotTypeRepository,
-            ISystemDicDataCacheManager sysDicDataCacheManager,
             IRepository<OrderVisitDetail> orderVisitDetailRepository,
             IRepository<OrderDelay> orderDelayRepository,
-            IRepository<WorkflowCountersign> workflowCountersignRepository,
-            IRepository<OrderSpecial> orderSpecialRepository,
             IMapper mapper,
-            IRepository<OrderVisit> orderVisitRepository,
-            IRepository<TrCallRecord> trCallRecordRepository,
             IRepository<OrderPublish> orderPublishRepository,
-            IRepository<SystemOrganize> systemOrganizeRepository,
-            IRepository<AiOrderVisitDetail> aiOrderVisitDetailRepository,
             ISessionContext sessionContext,
-            ISystemSettingCacheManager systemSettingCacheManager,
-            IRepository<OrderSpecialDetail> orderSpecialDetailRepository,
             IRepository<WorkflowTrace> workflowTraceRepository,
-            IRepository<OrderScreen> orderScreenRepository,
-            IOrderSecondaryHandlingApplication orderSecondaryHandlingApplication,
-            ITimeLimitDomainService timeLimitDomainService
+            IRepository<OrderScreen> orderScreenRepository
             )
         {
             _orderRepository = orderRepository;
-            _hotspotTypeRepository = hotspotTypeRepository;
-            _sysDicDataCacheManager = sysDicDataCacheManager;
             _orderVisitDetailRepository = orderVisitDetailRepository;
             _orderDelayRepository = orderDelayRepository;
-            _workflowCountersignRepository = workflowCountersignRepository;
-            _orderSpecialRepository = orderSpecialRepository;
             _mapper = mapper;
-            _orderVisitRepository = orderVisitRepository;
-            _trCallRecordRepository = trCallRecordRepository;
             _orderPublishRepository = orderPublishRepository;
-            _systemOrganizeRepository = systemOrganizeRepository;
-            _aiOrderVisitDetailRepository = aiOrderVisitDetailRepository;
             _sessionContext = sessionContext;
-            _systemSettingCacheManager = systemSettingCacheManager;
-            _orderSpecialDetailRepository = orderSpecialDetailRepository;
             _workflowTraceRepository = workflowTraceRepository;
             _orderScreenRepository = orderScreenRepository;
-            _orderSecondaryHandlingApplication = orderSecondaryHandlingApplication;
-            _timeLimitDomainService = timeLimitDomainService;
         }
         /// <summary>
         /// 部门办件统计表---新
@@ -156,8 +120,8 @@ FROM (
 		select  ""HandlerOrgId"",SUM(( CASE  WHEN ( ""HandlerOrgId"" IS NOT NULL ) THEN 1  ELSE 0 END )) AS ""YbOrderCountNum"",0 ""ZbOrderCountNum"",0 ""YbOverdue"",0 ""ZbOverdue"",0 ""HqybOverdue"",0 ""HqzbOverdue"",0 ""DelayEnd"",0 ""DelayWait"",0""Archived"" ,0 ""ToBeArchived"",0 ""WaitPublished"",0 ""PublishedOpen"",0 ""PublishedNoOpen"" ,0 ""OrderDelayCount"",0 ""ScreenCount"",0 ""ScreenApproval"", 0 ""ScreenPass"" , 0 ""ScreenNotPass"",0 ""SatisfactionCount"", 0 ""NotSatisfactionCount"" from(
 		 select ""o"".""Id"",SUBSTRING(""t"".""HandlerOrgId"",1,{3}) ""HandlerOrgId"" from ""workflow_trace"" ""t""
 			left join ""order"" ""o"" on ""o"".""Id""=""t"".""ExternalId""
-			where ""o"".""CreationTime"">='{0}' and ""o"".""CreationTime""<='{1}'  and ""t"".""ModuleCode""='OrderHandle' and ""t"".""Status"">=2   {2} --and ""t"".""CountersignPosition""<=1 
-			GROUP BY ""HandlerOrgId"",""o"".""Id""
+			where ""o"".""CreationTime"">='{0}' and ""o"".""CreationTime""<='{1}'  and ""t"".""ModuleCode""='OrderHandle' and ""t"".""TraceState"" !=10  and ""t"".""Status"">=2   {2} --and ""t"".""CountersignPosition""<=1 
+			GROUP BY SUBSTRING(""t"".""HandlerOrgId"",1,{3}),""o"".""Id""
 		)""s"" where ""HandlerOrgId"" IS not NULL {4}
 		GROUP BY ""HandlerOrgId""
 		union ALL
@@ -166,7 +130,7 @@ FROM (
 		 select ""o"".""Id"",SUBSTRING(""t"".""HandlerOrgId"",1,{3}) ""HandlerOrgId"" from ""workflow_trace"" ""t""
 			left join ""order"" ""o"" on ""o"".""Id""=""t"".""ExternalId""
 			where ""o"".""CreationTime"">='{0}' and ""o"".""CreationTime""<='{1}'  and ""t"".""ModuleCode""='OrderHandle' and ""t"".""Status""<2  {2} --and ""t"".""CountersignPosition""<=1 
-			GROUP BY ""HandlerOrgId"",""o"".""Id""
+			GROUP BY SUBSTRING(""t"".""HandlerOrgId"",1,{3}),""o"".""Id""
 		)""s"" where ""HandlerOrgId"" IS not NULL {4}
 		GROUP BY ""HandlerOrgId""
 		union ALL
@@ -174,8 +138,8 @@ FROM (
 		select  ""HandlerOrgId"",0 ""YbOrderCountNum"",0 ""ZbOrderCountNum"",SUM(( CASE  WHEN ( ""HandlerOrgId"" IS NOT NULL ) THEN 1  ELSE 0 END )) AS ""YbOverdue"" ,0 ""ZbOverdue"",0 ""HqybOverdue"",0 ""HqzbOverdue"",0 ""DelayEnd"",0 ""DelayWait"",0""Archived"",0 ""ToBeArchived"",0 ""WaitPublished"",0 ""PublishedOpen"",0 ""PublishedNoOpen"",0 ""OrderDelayCount"",0 ""ScreenCount"",0 ""ScreenApproval"", 0 ""ScreenPass"" , 0 ""ScreenNotPass"" ,0 ""SatisfactionCount"", 0 ""NotSatisfactionCount"" from(
 		 select ""o"".""Id"",SUBSTRING(""t"".""HandlerOrgId"",1,{3}) ""HandlerOrgId"" from ""workflow_trace"" ""t""
 			left join ""order"" ""o"" on ""o"".""Id""=""t"".""ExternalId""
-			where ""o"".""CreationTime"">='{0}' and ""o"".""CreationTime""<='{1}'  and ""t"".""ModuleCode""='OrderHandle' and ""t"".""Status"">=2 and ""HandleTime"">""StepExpiredTime"" and ""t"".""CountersignPosition""=0   {2}
-			GROUP BY ""HandlerOrgId"",""o"".""Id""
+			where ""o"".""CreationTime"">='{0}' and ""o"".""CreationTime""<='{1}'  and ""t"".""ModuleCode""='OrderHandle' and ""t"".""TraceState"" !=10 and ""t"".""Status"">=2 and ""HandleTime"">""StepExpiredTime"" and ""t"".""CountersignPosition""=0   {2}
+			GROUP BY SUBSTRING(""t"".""HandlerOrgId"",1,{3}),""o"".""Id""
 		)""s"" where ""HandlerOrgId"" IS not NULL {4}
 		GROUP BY ""HandlerOrgId""
 		union ALL
@@ -184,7 +148,7 @@ FROM (
 		 select ""o"".""Id"",SUBSTRING(""t"".""HandlerOrgId"",1,{3}) ""HandlerOrgId"" from ""workflow_trace"" ""t""
 			left join ""order"" ""o"" on ""o"".""Id""=""t"".""ExternalId""
 			where ""o"".""CreationTime"">='{0}' and ""o"".""CreationTime""<='{1}'  and ""t"".""ModuleCode""='OrderHandle' and ""t"".""Status""<2 and (SELECT NOW())>""StepExpiredTime"" and ""t"".""CountersignPosition""=0   {2}
-			GROUP BY ""HandlerOrgId"",""o"".""Id""
+			GROUP BY SUBSTRING(""t"".""HandlerOrgId"",1,{3}),""o"".""Id""
 		)""s"" where ""HandlerOrgId"" IS not NULL {4}
 		GROUP BY ""HandlerOrgId""
 		union ALL
@@ -192,8 +156,8 @@ FROM (
 		select  ""HandlerOrgId"",0 ""YbOrderCountNum"",0 ""ZbOrderCountNum"",0 ""YbOverdue"" ,0 ""ZbOverdue"",SUM(( CASE  WHEN ( ""HandlerOrgId"" IS NOT NULL ) THEN 1  ELSE 0 END )) AS ""HqybOverdue"",0 ""HqzbOverdue"",0 ""DelayEnd"",0 ""DelayWait"",0""Archived"",0 ""ToBeArchived"",0 ""WaitPublished"",0 ""PublishedOpen"",0 ""PublishedNoOpen"",0 ""OrderDelayCount"",0 ""ScreenCount"",0 ""ScreenApproval"", 0 ""ScreenPass"" , 0 ""ScreenNotPass"" ,0 ""SatisfactionCount"", 0 ""NotSatisfactionCount"" from(
 		 select ""o"".""Id"",SUBSTRING(""t"".""HandlerOrgId"",1,{3}) ""HandlerOrgId"" from ""workflow_trace"" ""t""
 			left join ""order"" ""o"" on ""o"".""Id""=""t"".""ExternalId""
-			where ""o"".""CreationTime"">='{0}' and ""o"".""CreationTime""<='{1}'  and ""t"".""ModuleCode""='OrderHandle' and ""t"".""Status"">=2 and ""HandleTime"">""StepExpiredTime"" and ""CountersignPosition"">0  {2}
-			GROUP BY ""HandlerOrgId"",""o"".""Id""
+			where ""o"".""CreationTime"">='{0}' and ""o"".""CreationTime""<='{1}'  and ""t"".""ModuleCode""='OrderHandle' and ""t"".""TraceState"" !=10 and ""t"".""Status"">=2 and ""HandleTime"">""StepExpiredTime"" and ""CountersignPosition"">0  {2}
+			GROUP BY SUBSTRING(""t"".""HandlerOrgId"",1,{3}),""o"".""Id""
 		)""s"" where ""HandlerOrgId"" IS not NULL {4}
 		GROUP BY ""HandlerOrgId""
 		union ALL
@@ -203,7 +167,7 @@ FROM (
 			left join ""order"" ""o"" on ""o"".""Id""=""t"".""ExternalId""
 			where ""o"".""CreationTime"">='{0}' and ""o"".""CreationTime""<='{1}'  and ""t"".""ModuleCode""='OrderHandle' and ""t"".""Status""<2 and (SELECT NOW())>""StepExpiredTime"" 
 			and   ""CountersignPosition"">0  {2}
-			GROUP BY ""HandlerOrgId"",""o"".""Id""
+			GROUP BY SUBSTRING(""t"".""HandlerOrgId"",1,{3}),""o"".""Id""
 		)""s"" where ""HandlerOrgId"" IS not NULL {4}
 		GROUP BY ""HandlerOrgId""
 		union ALL
@@ -211,8 +175,8 @@ FROM (
 		select  ""HandlerOrgId"",0 ""YbOrderCountNum"",0 ""ZbOrderCountNum"",0 ""YbOverdue"" ,0 ""ZbOverdue"",0 ""HqybOverdue"",0 ""HqzbOverdue"",SUM(( CASE  WHEN ( ""HandlerOrgId"" IS NOT NULL ) THEN 1  ELSE 0 END )) AS ""DelayEnd"",0 ""DelayWait"" ,0""Archived"",0 ""ToBeArchived"",0 ""WaitPublished"",0 ""PublishedOpen"",0 ""PublishedNoOpen"",0 ""OrderDelayCount"",0 ""ScreenCount"",0 ""ScreenApproval"", 0 ""ScreenPass"" , 0 ""ScreenNotPass"" ,0 ""SatisfactionCount"", 0 ""NotSatisfactionCount"" from(
 		 select ""o"".""Id"",SUBSTRING(""t"".""HandlerOrgId"",1,{3}) ""HandlerOrgId"" from ""workflow_trace"" ""t""
 			left join ""order"" ""o"" on ""o"".""Id""=""t"".""ExternalId""
-			where ""o"".""CreationTime"">='{0}' and ""o"".""CreationTime""<='{1}'  and ""t"".""ModuleCode""='OrderHandle' and ""t"".""Status"">=2 and ""CountersignPosition"">0 {2}
-			GROUP BY ""HandlerOrgId"",""o"".""Id""
+			where ""o"".""CreationTime"">='{0}' and ""o"".""CreationTime""<='{1}'  and ""t"".""ModuleCode""='OrderHandle' and ""t"".""TraceState"" !=10 and ""t"".""Status"">=2 and ""CountersignPosition"">0 {2}
+			GROUP BY SUBSTRING(""t"".""HandlerOrgId"",1,{3}),""o"".""Id""
 		)""s"" where ""HandlerOrgId"" IS not NULL {4}
 		GROUP BY ""HandlerOrgId""
 		union ALL
@@ -221,7 +185,7 @@ FROM (
 		 select ""o"".""Id"",SUBSTRING(""t"".""HandlerOrgId"",1,{3}) ""HandlerOrgId"" from ""workflow_trace"" ""t""
 			left join ""order"" ""o"" on ""o"".""Id""=""t"".""ExternalId""
 			where ""o"".""CreationTime"">='{0}' and ""o"".""CreationTime""<='{1}'  and ""t"".""ModuleCode""='OrderHandle' and ""t"".""Status""<2 and ""CountersignPosition"">0 {2}
-			GROUP BY ""HandlerOrgId"",""o"".""Id""
+			GROUP BY SUBSTRING(""t"".""HandlerOrgId"",1,{3}),""o"".""Id""
 		)""s"" where ""HandlerOrgId"" IS not NULL  {4}
 		GROUP BY ""HandlerOrgId""
 		UNION ALL
@@ -354,8 +318,8 @@ FROM (
 		select  ""HandlerOrgId"",SUM(( CASE  WHEN ( ""HandlerOrgId"" IS NOT NULL ) THEN 1  ELSE 0 END )) AS ""YbOrderCountNum"",0 ""ZbOrderCountNum"",0 ""YbOverdue"",0 ""ZbOverdue"",0 ""HqybOverdue"",0 ""HqzbOverdue"",0 ""DelayEnd"",0 ""DelayWait"",0""Archived"" ,0 ""ToBeArchived"",0 ""WaitPublished"",0 ""PublishedOpen"",0 ""PublishedNoOpen"" ,0 ""OrderDelayCount"",0 ""ScreenCount"",0 ""ScreenApproval"", 0 ""ScreenPass"" , 0 ""ScreenNotPass"",0 ""SatisfactionCount"", 0 ""NotSatisfactionCount"" from(
 		 select ""o"".""Id"",SUBSTRING(""t"".""HandlerOrgId"",1,{3}) ""HandlerOrgId"" from ""workflow_trace"" ""t""
 			left join ""order"" ""o"" on ""o"".""Id""=""t"".""ExternalId""
-			where ""o"".""CreationTime"">='{0}' and ""o"".""CreationTime""<='{1}'  and ""t"".""ModuleCode""='OrderHandle' and ""t"".""Status"">=2   {2} --and ""t"".""CountersignPosition""<=1 
-			GROUP BY ""HandlerOrgId"",""o"".""Id""
+			where ""o"".""CreationTime"">='{0}' and ""o"".""CreationTime""<='{1}'  and ""t"".""ModuleCode""='OrderHandle' and ""t"".""TraceState"" !=10 and ""t"".""Status"">=2   {2} --and ""t"".""CountersignPosition""<=1 
+			GROUP BY SUBSTRING(""t"".""HandlerOrgId"",1,{3}),""o"".""Id""
 		)""s"" where ""HandlerOrgId"" IS not NULL {4}
 		GROUP BY ""HandlerOrgId""
 		union ALL
@@ -364,7 +328,7 @@ FROM (
 		 select ""o"".""Id"",SUBSTRING(""t"".""HandlerOrgId"",1,{3}) ""HandlerOrgId"" from ""workflow_trace"" ""t""
 			left join ""order"" ""o"" on ""o"".""Id""=""t"".""ExternalId""
 			where ""o"".""CreationTime"">='{0}' and ""o"".""CreationTime""<='{1}'  and ""t"".""ModuleCode""='OrderHandle' and ""t"".""Status""<2  {2} --and ""t"".""CountersignPosition""<=1 
-			GROUP BY ""HandlerOrgId"",""o"".""Id""
+			GROUP BY SUBSTRING(""t"".""HandlerOrgId"",1,{3}),""o"".""Id""
 		)""s"" where ""HandlerOrgId"" IS not NULL {4}
 		GROUP BY ""HandlerOrgId""
 		union ALL
@@ -372,8 +336,8 @@ FROM (
 		select  ""HandlerOrgId"",0 ""YbOrderCountNum"",0 ""ZbOrderCountNum"",SUM(( CASE  WHEN ( ""HandlerOrgId"" IS NOT NULL ) THEN 1  ELSE 0 END )) AS ""YbOverdue"" ,0 ""ZbOverdue"",0 ""HqybOverdue"",0 ""HqzbOverdue"",0 ""DelayEnd"",0 ""DelayWait"",0""Archived"",0 ""ToBeArchived"",0 ""WaitPublished"",0 ""PublishedOpen"",0 ""PublishedNoOpen"",0 ""OrderDelayCount"",0 ""ScreenCount"",0 ""ScreenApproval"", 0 ""ScreenPass"" , 0 ""ScreenNotPass"" ,0 ""SatisfactionCount"", 0 ""NotSatisfactionCount"" from(
 		 select ""o"".""Id"",SUBSTRING(""t"".""HandlerOrgId"",1,{3}) ""HandlerOrgId"" from ""workflow_trace"" ""t""
 			left join ""order"" ""o"" on ""o"".""Id""=""t"".""ExternalId""
-			where ""o"".""CreationTime"">='{0}' and ""o"".""CreationTime""<='{1}'  and ""t"".""ModuleCode""='OrderHandle' and ""t"".""Status"">=2 and ""HandleTime"">""StepExpiredTime"" and ""t"".""CountersignPosition""=0   {2}
-			GROUP BY ""HandlerOrgId"",""o"".""Id""
+			where ""o"".""CreationTime"">='{0}' and ""o"".""CreationTime""<='{1}'  and ""t"".""ModuleCode""='OrderHandle' and ""t"".""TraceState"" !=10 and ""t"".""Status"">=2 and ""HandleTime"">""StepExpiredTime"" and ""t"".""CountersignPosition""=0   {2}
+			GROUP BY SUBSTRING(""t"".""HandlerOrgId"",1,{3}),""o"".""Id""
 		)""s"" where ""HandlerOrgId"" IS not NULL {4}
 		GROUP BY ""HandlerOrgId""
 		union ALL
@@ -382,7 +346,7 @@ FROM (
 		 select ""o"".""Id"",SUBSTRING(""t"".""HandlerOrgId"",1,{3}) ""HandlerOrgId"" from ""workflow_trace"" ""t""
 			left join ""order"" ""o"" on ""o"".""Id""=""t"".""ExternalId""
 			where ""o"".""CreationTime"">='{0}' and ""o"".""CreationTime""<='{1}'  and ""t"".""ModuleCode""='OrderHandle' and ""t"".""Status""<2 and (SELECT NOW())>""StepExpiredTime"" and ""t"".""CountersignPosition""=0   {2}
-			GROUP BY ""HandlerOrgId"",""o"".""Id""
+			GROUP BY SUBSTRING(""t"".""HandlerOrgId"",1,{3}),""o"".""Id""
 		)""s"" where ""HandlerOrgId"" IS not NULL {4}
 		GROUP BY ""HandlerOrgId""
 		union ALL
@@ -390,8 +354,8 @@ FROM (
 		select  ""HandlerOrgId"",0 ""YbOrderCountNum"",0 ""ZbOrderCountNum"",0 ""YbOverdue"" ,0 ""ZbOverdue"",SUM(( CASE  WHEN ( ""HandlerOrgId"" IS NOT NULL ) THEN 1  ELSE 0 END )) AS ""HqybOverdue"",0 ""HqzbOverdue"",0 ""DelayEnd"",0 ""DelayWait"",0""Archived"",0 ""ToBeArchived"",0 ""WaitPublished"",0 ""PublishedOpen"",0 ""PublishedNoOpen"",0 ""OrderDelayCount"",0 ""ScreenCount"",0 ""ScreenApproval"", 0 ""ScreenPass"" , 0 ""ScreenNotPass"" ,0 ""SatisfactionCount"", 0 ""NotSatisfactionCount"" from(
 		 select ""o"".""Id"",SUBSTRING(""t"".""HandlerOrgId"",1,{3}) ""HandlerOrgId"" from ""workflow_trace"" ""t""
 			left join ""order"" ""o"" on ""o"".""Id""=""t"".""ExternalId""
-			where ""o"".""CreationTime"">='{0}' and ""o"".""CreationTime""<='{1}'  and ""t"".""ModuleCode""='OrderHandle' and ""t"".""Status"">=2 and ""HandleTime"">""StepExpiredTime"" and ""CountersignPosition"">0  {2}
-			GROUP BY ""HandlerOrgId"",""o"".""Id""
+			where ""o"".""CreationTime"">='{0}' and ""o"".""CreationTime""<='{1}'  and ""t"".""ModuleCode""='OrderHandle' and ""t"".""TraceState"" !=10 and ""t"".""Status"">=2 and ""HandleTime"">""StepExpiredTime"" and ""CountersignPosition"">0  {2}
+			GROUP BY SUBSTRING(""t"".""HandlerOrgId"",1,{3}),""o"".""Id""
 		)""s"" where ""HandlerOrgId"" IS not NULL {4}
 		GROUP BY ""HandlerOrgId""
 		union ALL
@@ -401,7 +365,7 @@ FROM (
 			left join ""order"" ""o"" on ""o"".""Id""=""t"".""ExternalId""
 			where ""o"".""CreationTime"">='{0}' and ""o"".""CreationTime""<='{1}'  and ""t"".""ModuleCode""='OrderHandle' and ""t"".""Status""<2 and (SELECT NOW())>""StepExpiredTime"" 
 			and   ""CountersignPosition"">0  {2}
-			GROUP BY ""HandlerOrgId"",""o"".""Id""
+			GROUP BY SUBSTRING(""t"".""HandlerOrgId"",1,{3}),""o"".""Id""
 		)""s"" where ""HandlerOrgId"" IS not NULL {4}
 		GROUP BY ""HandlerOrgId""
 		union ALL
@@ -409,8 +373,8 @@ FROM (
 		select  ""HandlerOrgId"",0 ""YbOrderCountNum"",0 ""ZbOrderCountNum"",0 ""YbOverdue"" ,0 ""ZbOverdue"",0 ""HqybOverdue"",0 ""HqzbOverdue"",SUM(( CASE  WHEN ( ""HandlerOrgId"" IS NOT NULL ) THEN 1  ELSE 0 END )) AS ""DelayEnd"",0 ""DelayWait"" ,0""Archived"",0 ""ToBeArchived"",0 ""WaitPublished"",0 ""PublishedOpen"",0 ""PublishedNoOpen"",0 ""OrderDelayCount"",0 ""ScreenCount"",0 ""ScreenApproval"", 0 ""ScreenPass"" , 0 ""ScreenNotPass"" ,0 ""SatisfactionCount"", 0 ""NotSatisfactionCount"" from(
 		 select ""o"".""Id"",SUBSTRING(""t"".""HandlerOrgId"",1,{3}) ""HandlerOrgId"" from ""workflow_trace"" ""t""
 			left join ""order"" ""o"" on ""o"".""Id""=""t"".""ExternalId""
-			where ""o"".""CreationTime"">='{0}' and ""o"".""CreationTime""<='{1}'  and ""t"".""ModuleCode""='OrderHandle' and ""t"".""Status"">=2 and ""CountersignPosition"">0 {2}
-			GROUP BY ""HandlerOrgId"",""o"".""Id""
+			where ""o"".""CreationTime"">='{0}' and ""o"".""CreationTime""<='{1}'  and ""t"".""ModuleCode""='OrderHandle' and ""t"".""TraceState"" !=10 and ""t"".""Status"">=2 and ""CountersignPosition"">0 {2}
+			GROUP BY SUBSTRING(""t"".""HandlerOrgId"",1,{3}),""o"".""Id""
 		)""s"" where ""HandlerOrgId"" IS not NULL {4}
 		GROUP BY ""HandlerOrgId""
 		union ALL
@@ -419,7 +383,7 @@ FROM (
 		 select ""o"".""Id"",SUBSTRING(""t"".""HandlerOrgId"",1,{3}) ""HandlerOrgId"" from ""workflow_trace"" ""t""
 			left join ""order"" ""o"" on ""o"".""Id""=""t"".""ExternalId""
 			where ""o"".""CreationTime"">='{0}' and ""o"".""CreationTime""<='{1}'  and ""t"".""ModuleCode""='OrderHandle' and ""t"".""Status""<2 and ""CountersignPosition"">0 {2}
-			GROUP BY ""HandlerOrgId"",""o"".""Id""
+			GROUP BY SUBSTRING(""t"".""HandlerOrgId"",1,{3}),""o"".""Id""
 		)""s"" where ""HandlerOrgId"" IS not NULL  {4}
 		GROUP BY ""HandlerOrgId""
 		UNION ALL