Browse Source

Merge branch 'dev' of http://git.12345lm.cn/Fengwo/hotline into dev

Dun.Jason 9 months ago
parent
commit
b6b40ec7e0

+ 2 - 1
src/Hotline.Api/Controllers/OrderController.cs

@@ -2960,6 +2960,7 @@ public class OrderController : BaseController
         }
         catch (Exception e)
         {
+            _logger.LogError($"工单开启流程失败!, {e.Message}, {e.StackTrace}");
             if (isAdd)
                 await Remove(id);
             throw new UserFriendlyException($"工单开启流程失败!, {e.Message}, {e.StackTrace}", "工单开启流程失败");
@@ -5520,7 +5521,7 @@ public class OrderController : BaseController
                     try
                     {
                         if (item.Source != "麻辣社区" || item.Source != "人民网" || item.Source != "省长信箱" || item.Source != "问政四川")
-                            //if (item.Source < ESource.MLSQ || item.Source > ESource.WZSC)
+                        //if (item.Source < ESource.MLSQ || item.Source > ESource.WZSC)
                         {
                             errorCount++;
                             continue;

+ 5 - 1
src/Hotline.Application/FlowEngine/WorkflowApplication.cs

@@ -353,6 +353,9 @@ public class WorkflowApplication : IWorkflowApplication, IScopeDependency
         var endStepDefine = workflow.WorkflowDefinition.FindEndStepDefine();
         if (endStepDefine is null)
             throw new UserFriendlyException("未正确配置结束节点");
+        var unHandleStep = workflow.Steps.FirstOrDefault(d => d.Status is not EWorkflowStepStatus.Handled);
+        if (unHandleStep is null)
+            throw new UserFriendlyException($"无待办节点, workflowId: {workflowId}", "无待办节点");
         var dto = new NextWorkflowDto
         {
             WorkflowId = workflowId,
@@ -362,7 +365,8 @@ public class WorkflowApplication : IWorkflowApplication, IScopeDependency
             BusinessType = endStepDefine.BusinessType,
             ReviewResult = reviewResult,
             Opinion = opinion,
-            Files = files
+            Files = files,
+            StepId = unHandleStep.Id
         };
         await NextAsync(dto, current, cancellationToken: cancellationToken);
     }

+ 16 - 13
src/Hotline.Application/Handlers/FlowEngine/WorkflowEndHandler.cs

@@ -212,23 +212,26 @@ public class WorkflowEndHandler : INotificationHandler<EndWorkflowNotify>
                 // {
                 //     orderFlowDto.TrCallRecordDto = _mapper.Map<TrCallDto>(callRecord);
                 // }
-                
-                if (_callcenterOptions.Value.CallCenterType == AppDefaults.CallCenterType.TianRun)
+                if (order.SourceChannelCode == AppDefaults.SourceChannel.DianHua &&
+                    !string.IsNullOrEmpty(order.CallId))
                 {
-                    // var callRecord = await _trCallRecordRepository.GetAsync(p => p.OtherAccept == order.CallId, cancellationToken);
-                    var callRecord = await _callApplication.GetTianrunCallAsync(order.CallId, cancellationToken);
-                    if (callRecord != null)
+                    if (_callcenterOptions.Value.CallCenterType == AppDefaults.CallCenterType.TianRun)
                     {
-                        orderFlowDto.TrCallRecordDto = _mapper.Map<TrCallDto>(callRecord);
+                        // var callRecord = await _trCallRecordRepository.GetAsync(p => p.OtherAccept == order.CallId, cancellationToken);
+                        var callRecord = await _callApplication.GetTianrunCallAsync(order.CallId, cancellationToken);
+                        if (callRecord != null)
+                        {
+                            orderFlowDto.TrCallRecordDto = _mapper.Map<TrCallDto>(callRecord);
+                        }
+                    }
+                    else if (_callcenterOptions.Value.CallCenterType == AppDefaults.CallCenterType.XingTang)
+                    {
+                        var call = await _callApplication.GetCallAsync(order.CallId, cancellationToken);
+                        if (call is not null)
+                            orderFlowDto.TrCallRecordDto = _mapper.Map<TrCallDto>(call);
                     }
                 }
-                else if (_callcenterOptions.Value.CallCenterType == AppDefaults.CallCenterType.XingTang)
-                {
-                    var call = await _callApplication.GetCallAsync(order.CallId, cancellationToken);
-                    if(call is not null)
-                        orderFlowDto.TrCallRecordDto = _mapper.Map<TrCallDto>(call);
-                }
-                
+
                 //这里需要判断是否是警情退回
                 orderFlowDto.IsNonPoliceReturn = notification.Dto.External == null ? false : notification.Dto.External.IsPoliceReturn;
                 await _capPublisher.PublishAsync(Hotline.Share.Mq.EventNames.HotlineOrderFiled, orderFlowDto, cancellationToken: cancellationToken);

+ 15 - 12
src/Hotline.Application/Handlers/FlowEngine/WorkflowStartHandler.cs

@@ -110,21 +110,24 @@ namespace Hotline.Application.Handlers.FlowEngine
                     //     publishCallRecordDto.TrCallRecordDto = _mapper.Map<TrCallDto>(callRecord);
                     // }
 
-
-                    if (_callcenterOptions.Value.CallCenterType == AppDefaults.CallCenterType.TianRun)
+                    if (order.SourceChannelCode == AppDefaults.SourceChannel.DianHua &&
+                        !string.IsNullOrEmpty(order.CallId))
                     {
-                        // var callRecord = await _trCallRecordRepository.GetAsync(p => p.OtherAccept == order.CallId, cancellationToken);
-                        var callRecord = await _callApplication.GetTianrunCallAsync(order.CallId, cancellationToken);
-                        if (callRecord != null)
+                        if (_callcenterOptions.Value.CallCenterType == AppDefaults.CallCenterType.TianRun)
                         {
-                            publishCallRecordDto.TrCallRecordDto = _mapper.Map<TrCallDto>(callRecord);
+                            // var callRecord = await _trCallRecordRepository.GetAsync(p => p.OtherAccept == order.CallId, cancellationToken);
+                            var callRecord = await _callApplication.GetTianrunCallAsync(order?.CallId, cancellationToken);
+                            if (callRecord != null)
+                            {
+                                publishCallRecordDto.TrCallRecordDto = _mapper.Map<TrCallDto>(callRecord);
+                            }
+                        }
+                        else if (_callcenterOptions.Value.CallCenterType == AppDefaults.CallCenterType.XingTang)
+                        {
+                            var call = await _callApplication.GetCallAsync(order?.CallId, cancellationToken);
+                            if (call is not null)
+                                publishCallRecordDto.TrCallRecordDto = _mapper.Map<TrCallDto>(call);
                         }
-                    }
-                    else if (_callcenterOptions.Value.CallCenterType == AppDefaults.CallCenterType.XingTang)
-                    {
-                        var call = await _callApplication.GetCallAsync(order.CallId, cancellationToken);
-                        if(call is not null)
-                            publishCallRecordDto.TrCallRecordDto = _mapper.Map<TrCallDto>(call);
                     }
 
 

+ 46 - 84
src/Hotline.Application/Orders/OrderApplication.cs

@@ -597,18 +597,6 @@ public class OrderApplication : IOrderApplication, IScopeDependency
 				NoHandlerExtendedNum = SqlFunc.AggregateSum(SqlFunc.IIF(o.Status < EOrderStatus.Filed && o.ExpiredTime < SqlFunc.GetDate(), 1, 0)),
 			}).MergeTable();
 
-		//var queryCountersign = _workflowCountersignRepository.Queryable()
-		//	.LeftJoin<WorkflowCountersignMember>((x, o) => x.Id == o.WorkflowCountersignId)
-		//	.WhereIF(dto.StartTime.HasValue, x => x.CreationTime >= dto.StartTime)
-		//	.WhereIF(dto.EndTime.HasValue, x => x.CreationTime <= dto.EndTime)
-		//	.GroupBy((x, o) => o.Key)
-		//	.Select((x, o) => new OrderBiOrgDataListVo
-		//	{
-		//		OrgId = o.Key,
-		//		CounterHandlerExtendedNum = SqlFunc.AggregateSum(SqlFunc.IIF(o.IsHandled && x.IsExpired.HasValue && x.IsExpired.Value == true, 1, 0)),
-		//		CounterNoHandlerExtendedNum = SqlFunc.AggregateSum(SqlFunc.IIF(o.IsHandled == false && x.IsExpired.HasValue && x.IsExpired.Value == true, 1, 0)),
-		//	}).MergeTable();
-
 		var queryCountersign = _workflowStepRepository.Queryable()
             .Where(x=>x.CountersignPosition != ECountersignPosition.None)
 			.WhereIF(dto.StartTime.HasValue, x => x.CreationTime >= dto.StartTime)
@@ -622,9 +610,8 @@ public class OrderApplication : IOrderApplication, IScopeDependency
 			}).MergeTable();
 
 		var query = queryOrder.LeftJoin(queryCountersign, (or, co) => or.OrgId == co.OrgId)
-			.LeftJoin<SystemOrganize>((or, co, so) => or.OrgId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")) == so.Id)
-			//宜宾只统计一级部门
-			.Where((or, co, so) => so.Level == 1)
+			//.LeftJoin<SystemOrganize>((or, co, so) => or.OrgId.Substring(SqlFunc.MappingColumn<int>("0"), SqlFunc.MappingColumn<int>("6")) == so.Id)
+			.LeftJoin<SystemOrganize>((or, co, so) => or.OrgId == so.Id && so.Level == 1)
 			.GroupBy((or, co, so) => new { so.Id, so.Name })
 			.Select((or, co, so) => new OrderBiOrgDataListVo
 			{
@@ -664,42 +651,32 @@ public class OrderApplication : IOrderApplication, IScopeDependency
 	{
 		dto.EndTime = dto.EndTime.AddDays(1).AddSeconds(-1);
 
-		var quer = _orderRepository.Queryable()
-			.InnerJoin<SystemOrganize>((x, so) => x.ActualHandleOrgCode == so.Id)
-			.Where(x => x.CreationTime >= dto.StartTime && x.CreationTime <= dto.EndTime)
-			//.WhereIF(dto.Statuses.Any(), x => dto.Statuses.Contains(x.Status))  //工单状态
-			.WhereIF(dto.QueryType == 1, x => x.Status >= EOrderStatus.Filed && x.ExpiredTime < x.FiledTime) //业务已办超期
-			.WhereIF(dto.QueryType == 3, x => x.Status < EOrderStatus.Filed && x.ExpiredTime < SqlFunc.GetDate()) //业务待办超期
-			.WhereIF(dto.QueryType == 5, x =>
-				(x.Status >= EOrderStatus.Filed && x.ExpiredTime < x.FiledTime) || (x.Status < EOrderStatus.Filed && x.ExpiredTime < SqlFunc.GetDate()))
-			.WhereIF(!string.IsNullOrEmpty(dto.OrgCode) && dto.QueryType is 1 or 3 , x => x.ActualHandleOrgCode == dto.OrgCode)
-			//.WhereIF(!string.IsNullOrEmpty(dto.OrgCode) && dto.QueryType is 1 or 3 && dto.OrgCode != "001", x => x.ActualHandleOrgCode.StartsWith(dto.OrgCode))
-			.MergeTable();
-
-		if (dto.QueryType is 2 or 4 or 5)
+        var quer = _orderRepository.Queryable()
+	        .InnerJoin<SystemOrganize>((x, so) => x.ActualHandleOrgCode == so.Id &&  so.Level == 1)
+			.Where((x, so) => x.CreationTime >= dto.StartTime && x.CreationTime <= dto.EndTime)
+            //.WhereIF(dto.Statuses.Any(), x => dto.Statuses.Contains(x.Status))  //工单状态
+            .WhereIF(dto.QueryType == 1, (x, so) => x.Status >= EOrderStatus.Filed && x.ExpiredTime < x.FiledTime) //业务已办超期
+            .WhereIF(dto.QueryType == 3, (x, so) => x.Status < EOrderStatus.Filed && x.ExpiredTime < SqlFunc.GetDate()) //业务待办超期
+            .WhereIF(dto.QueryType == 5, (x, so) =>
+                (x.Status >= EOrderStatus.Filed && x.ExpiredTime < x.FiledTime) || (x.Status < EOrderStatus.Filed && x.ExpiredTime < SqlFunc.GetDate()))
+            .WhereIF(!string.IsNullOrEmpty(dto.OrgCode) , (x, so) => x.ActualHandleOrgCode == dto.OrgCode)
+			.Select(x => new Order { DaysOverdueOrgName = x.ActualHandleOrgName, Id = x.Id.SelectAll() });
+		if (dto.QueryType is 2 or 4 )
 		{
-            //var queryCountersign = _workflowCountersignRepository.Queryable()
-            //	.LeftJoin<WorkflowCountersignMember>((x, o) => x.Id == o.WorkflowCountersignId)
-            //	.Where((x, o) => x.CreationTime >= dto.StartTime && x.CreationTime <= dto.EndTime && x.IsExpired.HasValue && x.IsExpired.Value == true)
-            //	.WhereIF(dto.QueryType == 2, (x, o) => o.IsHandled == true) //会签已办超期
-            //	.WhereIF(dto.QueryType == 4, (x, o) => o.IsHandled == false) //会签待办超期
-            //	.WhereIF(!string.IsNullOrEmpty(dto.OrgCode) && dto.QueryType is 2 or 4 or 5, (x, o) => o.Key.StartsWith(dto.OrgCode))
-            //	//.GroupBy((x,o)=>x.WorkflowId)
-            //	.Select((x, o) => new { Id = x.WorkflowId })
-            //	.MergeTable();
             var queryCountersign = _workflowStepRepository.Queryable()
-                .Includes(x=>x.Workflow)
-                .LeftJoin<Order>((x,o)=>x.ExternalId  == o.Id)
-                .Where((x, o) => x.CountersignPosition != ECountersignPosition.None && x.Workflow.ModuleCode == "OrderHandle")
-                .Where((x, o) => x.CreationTime >= dto.StartTime && x.CreationTime <= dto.EndTime)
-                .WhereIF(dto.QueryType == 2, (x, o) => x.Status == Share.Enums.FlowEngine.EWorkflowStepStatus.Handled && x.StepExpiredTime < x.HandleTime) //会签已办超期
-                .WhereIF(dto.QueryType == 4, (x, o) => x.Status != Share.Enums.FlowEngine.EWorkflowStepStatus.Handled && x.StepExpiredTime < SqlFunc.GetDate())//会签待办超期
-			    .WhereIF(!string.IsNullOrEmpty(dto.OrgCode) && dto.QueryType is 2 or 4 or 5, (x, o) => x.HandlerOrgId == dto.OrgCode)
-				.GroupBy((x, o) => o)
-                .Select((x, o)=>o)
-                .MergeTable();
-            //quer = quer.InnerJoin(queryCountersign, (x, c) => x.WorkflowId == c.Id);
-            quer = _orderRepository.UnionAll(quer, queryCountersign).Distinct();
+                .Includes(x => x.Workflow)
+                .InnerJoin<SystemOrganize>((x, so) => x.HandlerOrgId == so.Id && so.Level == 1)
+				.Where((x, so) => x.CountersignPosition != ECountersignPosition.None && x.Workflow.ModuleCode == "OrderHandle")
+                .Where((x, so) => x.CreationTime >= dto.StartTime && x.CreationTime <= dto.EndTime)
+                .WhereIF(dto.QueryType == 2, (x, so) => x.Status == Share.Enums.FlowEngine.EWorkflowStepStatus.Handled && x.StepExpiredTime < x.HandleTime) //会签已办超期
+                .WhereIF(dto.QueryType == 4, (x, so) => x.Status != Share.Enums.FlowEngine.EWorkflowStepStatus.Handled && x.StepExpiredTime < SqlFunc.GetDate())//会签待办超期
+                .WhereIF(!string.IsNullOrEmpty(dto.OrgCode) , (x, so) => x.HandlerOrgId == dto.OrgCode)
+				.GroupBy(x => new { x.ExternalId, x.HandlerOrgName })
+                .Select(x => new { Id = x.ExternalId, WorkflowId = x.ExternalId, HandlerOrgName = x.HandlerOrgName });
+
+             quer = _orderRepository.Queryable().InnerJoin(queryCountersign, (o, w) => o.Id == w.Id)
+				 .Select((o, w) => new Order { DaysOverdueOrgName = w.HandlerOrgName, Id = o.Id.SelectAll() });
+			//quer = _orderRepository.UnionAll(quer, queryCountersignOrder);
 		}
         return quer;
 	}
@@ -715,44 +692,29 @@ public class OrderApplication : IOrderApplication, IScopeDependency
 		bool IsCenter = _sessionContext.OrgIsCenter;
 
 		var quer = _orderRepository.Queryable()
-			.InnerJoin<SystemOrganize>((x, so) => x.ActualHandleOrgCode == so.Id)
-			.Where(x => x.CreationTime >= dto.StartTime && x.CreationTime <= dto.EndTime)
-            .WhereIF(dto.Statuses.Any(), x => dto.Statuses.Contains(x.Status))  //工单状态
-            .WhereIF( dto.ExpiredType is  2, x=>x.OrderDelays.Any(x=>  x.DelayState == EDelayState.Pass))
-            .Where(x =>
+			.InnerJoin<SystemOrganize>((x, so) => x.ActualHandleOrgCode == so.Id && so.Level == 1)
+			.Where((x, so) => x.CreationTime >= dto.StartTime && x.CreationTime <= dto.EndTime)
+            .WhereIF(dto.Statuses.Any(), (x, so) => dto.Statuses.Contains(x.Status))  //工单状态
+            .WhereIF( dto.ExpiredType is  2, (x, so) => x.OrderDelays.Any(x=>  x.DelayState == EDelayState.Pass))
+            .Where((x, so) =>
 				(x.Status >= EOrderStatus.Filed && x.ExpiredTime < x.FiledTime) || (x.Status < EOrderStatus.Filed && x.ExpiredTime < SqlFunc.GetDate()))
-            .WhereIF(IsCenter == false, x => x.ActualHandleOrgCode == _sessionContext.RequiredOrgId)
-			.WhereIF(!string.IsNullOrEmpty(dto.OrgName)  , x => x.AcceptorOrgName == dto.OrgName)
-			.MergeTable();
-
-   //     var queryCountersign = _workflowCountersignRepository.Queryable()
-   //         .LeftJoin<WorkflowCountersignMember>((x, o) => x.Id == o.WorkflowCountersignId)
-   //         .Where((x, o) => x.CreationTime >= dto.StartTime && x.CreationTime <= dto.EndTime && x.IsExpired.HasValue && x.IsExpired.Value == true)
-   //         .WhereIF(IsCenter == false, (x, o) => o.Key.StartsWith(_sessionContext.RequiredOrgId))
-			//.WhereIF(!string.IsNullOrEmpty(dto.OrgName), (x, o) => o.Value == dto.OrgName)
-   //         .Select((x, o) => new { Id = x.WorkflowId, ActualHandleOrgCode = o.Key, ActualHandleOrgName = o.Value })
-   //         .MergeTable();
+            .WhereIF(IsCenter == false, (x, so) => x.ActualHandleOrgCode == _sessionContext.RequiredOrgId)
+			.WhereIF(!string.IsNullOrEmpty(dto.OrgName)  , (x, so) => x.AcceptorOrgName == dto.OrgName)
+			.Select( x => new Order { DaysOverdueOrgName = x.ActualHandleOrgName, Id = x.Id.SelectAll() });
+
         var queryCountersign = _workflowStepRepository.Queryable()
 	        .Includes(x => x.Workflow)
-	        .LeftJoin<Order>((x, o) => x.ExternalId == o.Id)
-			.Where((x, o) => x.CountersignPosition != ECountersignPosition.None && x.Workflow.ModuleCode == "OrderHandle")
-	        .Where((x, o) => x.CreationTime >= dto.StartTime && x.CreationTime <= dto.EndTime)
-            .Where((x, o) => (x.Status == Share.Enums.FlowEngine.EWorkflowStepStatus.Handled && x.StepExpiredTime < x.HandleTime)||(x.Status != Share.Enums.FlowEngine.EWorkflowStepStatus.Handled && x.StepExpiredTime < SqlFunc.GetDate()))
-		    .WhereIF(IsCenter == false, (x,o) => x.HandlerOrgId == _sessionContext.RequiredOrgId)
-			.GroupBy((x, o) => o)
-	        .Select((x, o) => new Order
-            {
-                DaysOverdueOrgName = x.HandlerOrgName,
-                Id = x.Id.SelectAll()
-            })
-            .MergeTable();
-
-		//quer = quer.LeftJoin(queryCountersign, (x, c) => x.WorkflowId == c.Id).Select((x, c) => new Order
-  //      {
-	 //       DaysOverdueOrgName = SqlFunc.IIF(!string.IsNullOrEmpty(c.Id), c.ActualHandleOrgName, x.ActualHandleOrgName),
-		//	Id = x.Id.SelectAll()
-		//}) ;
-        quer = _orderRepository.UnionAll(quer, queryCountersign).Distinct();
+            .InnerJoin<SystemOrganize>((x, so) => x.HandlerOrgId == so.Id && so.Level == 1)
+			.Where((x, so) => x.CountersignPosition != ECountersignPosition.None && x.Workflow.ModuleCode == "OrderHandle")
+	        .Where((x, so) => x.CreationTime >= dto.StartTime && x.CreationTime <= dto.EndTime)
+            .Where((x, so) => (x.Status == Share.Enums.FlowEngine.EWorkflowStepStatus.Handled && x.StepExpiredTime < x.HandleTime)||(x.Status != Share.Enums.FlowEngine.EWorkflowStepStatus.Handled && x.StepExpiredTime < SqlFunc.GetDate()))
+		    .WhereIF(IsCenter == false, (x, so) => x.HandlerOrgId == _sessionContext.RequiredOrgId)
+	        .GroupBy(x => new { x.ExternalId, x.HandlerOrgName })
+	        .Select(x => new { Id = x.ExternalId, WorkflowId = x.ExternalId, HandlerOrgName = x.HandlerOrgName });
+
+        var queryCountersignOrder = _orderRepository.Queryable().InnerJoin(queryCountersign, (o, w) => o.Id == w.Id)
+            .Select((o,w)=> new Order { DaysOverdueOrgName = w.HandlerOrgName, Id = o.Id.SelectAll() });
+		quer = _orderRepository.UnionAll(quer, queryCountersignOrder).MergeTable().InnerJoin<SystemOrganize>((x, so) => x.ActualHandleOrgCode == so.Id);
 		return quer;
 	}
 

+ 2 - 2
src/Hotline.Repository.SqlSugar/Extensions/SqlSugarStartupExtensions.cs

@@ -207,8 +207,8 @@ namespace Hotline.Repository.SqlSugar.Extensions
             /***写AOP等方法***/
             db.Aop.OnLogExecuting = (sql, pars) =>
             {
-                //Log.Information("Sql: {0}", sql);
-                //Log.Information("SqlParameters: {0}", string.Join(',', pars.Select(d => d.Value)));
+                Log.Information("Sql: {0}", sql);
+                Log.Information("SqlParameters: {0}", string.Join(',', pars.Select(d => d.Value)));
             };
             db.Aop.OnError = (exp) =>//SQL报错
             {