tangjiang 7 сар өмнө
parent
commit
53749f6e78

+ 7 - 1
src/DataSharing.Share/Enums/EWaitSendTaskState.cs

@@ -20,6 +20,12 @@ namespace DataSharing.Share.Enums
         /// 推送失败
         /// </summary>
         [Description("推送失败")]
-        PushFail = 2
+        PushFail = 2,
+
+        /// <summary>
+        /// 下一轮推送
+        /// </summary>
+        [Description("下一轮推送")]
+        StopPush = 9,
     }
 }

+ 83 - 147
src/DataSharing/Province/SendTask/TaskSubmitCaseInfoJob.cs

@@ -439,15 +439,8 @@ namespace DataSharing.Province.SendTask
                 //处理推送数据
                 foreach (var sendTask in tasks)
                 {
-                    bool isAdd = false;
-                    var existsTaskOrder = listOrder.FirstOrDefault(p => p.CaseSerial == sendTask.ProvinceNo);
-                    if (existsTaskOrder is null)
-                    {
-                        isAdd = true;
-                        //状态更改为推送中
-                        sendTask.State = EWaitSendTaskState.Pushing;
-                    }
-
+                    //状态更改为推送中
+                    sendTask.State = EWaitSendTaskState.Pushing;
                     //使用乐观锁,控制数据
                     if (await _waitSendTaskSubmitCaseInfoRepository.Updateable(sendTask).ExecuteCommandWithOptLockAsync() > 0)
                     {
@@ -473,84 +466,18 @@ namespace DataSharing.Province.SendTask
                         }
                         else
                         {
-                            ////组装这一条数据
-                            //listOrder.Add(sendTask.RequestData);
-                            //taskData.Add(sendTask);
-
-
-                            //没有这条数据直接添加
-                            if (isAdd)
-                            {
+                            var existsOrder = taskData.FirstOrDefault(p => p.ProvinceNo == sendTask.ProvinceNo);
+                            if (existsOrder is null)
                                 //组装这一条数据
                                 listOrder.Add(sendTask.RequestData);
-                                taskData.Add(sendTask);
-                            }
-
-                            #region 暂时没用到
-                            //var existsTaskOrder = taskData.FirstOrDefault(p => p.ProvinceNo == sendTask.ProvinceNo);
-                            ////没有这条数据直接添加
-                            //if (existsTaskOrder is null)
-                            //{
-                            //    //组装这一条数据
-                            //    listOrder.Add(sendTask.RequestData);
-                            //    taskData.Add(sendTask);
-                            //}
-                            //else
-                            //{
-                            //    //有这条数据,有这个工单数据,
-                            //    //比较写入时间,取最后写入的数据,将前面的数据写成已推送
-                            //    if (existsTaskOrder.CreationTime < sendTask.CreationTime)
-                            //    {
-                            //        //移除之前数据,写入最新数据
-                            //        taskData.Remove(existsTaskOrder);
-                            //        taskData.Add(sendTask);
-                            //        listOrder.Remove(existsTaskOrder.RequestData);
-                            //        listOrder.Add(sendTask.RequestData);
-
-                            //        //删除待推送表
-                            //        await _waitSendTaskSubmitCaseInfoRepository.RemoveAsync(existsTaskOrder, cancellationToken: context.CancellationToken);
-                            //        #region 处理数据推送主表数据
-                            //        //查询主表
-                            //        var sendData = await _sendTaskSubmitCaseInfoRepository.GetAsync(p => p.Id == existsTaskOrder.Id, context.CancellationToken);
-                            //        if (sendData != null)
-                            //        {
-                            //            sendData.LastTime = DateTime.Now;
-                            //            sendData.SendTimes = sendData.SendTimes + 1;
-
-                            //            if (sendData.FirstTime is null)
-                            //                sendData.FirstTime = DateTime.Now;
-
-                            //            sendData.IsSuccess = ESendTaskState.PushSuccess;
-                            //            await _sendTaskSubmitCaseInfoRepository.UpdateAsync(sendData, cancellationToken: context.CancellationToken);
-                            //        }
-                            //        #endregion
-                            //    }
-                            //    else
-                            //    {
-                            //        //已经是最新数据,则直接将数据修改为已推送
-                            //        //删除待推送表
-                            //        await _waitSendTaskSubmitCaseInfoRepository.RemoveAsync(sendTask, cancellationToken: context.CancellationToken);
-                            //        #region 处理数据推送主表数据
-                            //        //查询主表
-                            //        var sendData = await _sendTaskSubmitCaseInfoRepository.GetAsync(p => p.Id == sendTask.Id, context.CancellationToken);
-                            //        if (sendData != null)
-                            //        {
-                            //            sendData.LastTime = DateTime.Now;
-                            //            sendData.SendTimes = sendData.SendTimes + 1;
-
-                            //            if (sendData.FirstTime is null)
-                            //                sendData.FirstTime = DateTime.Now;
+                            else
+                                sendTask.State = EWaitSendTaskState.StopPush;
 
-                            //            sendData.IsSuccess = ESendTaskState.PushSuccess;
-                            //            await _sendTaskSubmitCaseInfoRepository.UpdateAsync(sendData, cancellationToken: context.CancellationToken);
-                            //        }
-                            //        #endregion
-                            //    }
-                            //} 
-                            #endregion
+                            taskData.Add(sendTask);
                         }
                     }
                 }
+
                 _logger.LogWarning("业务汇聚-服务工单受理锁定条数--------------------------------------" + taskData.Count);
 
                 if (listOrder != null && listOrder.Count > 0)
@@ -576,90 +503,99 @@ namespace DataSharing.Province.SendTask
                         //处理数据
                         foreach (var item in taskData)
                         {
-                            //查询是否有错误
-                            //有错误处理
-                            //没有错误删除待推送表,更新主表
-                            bool isError = false;
-                            if (result == null || result.Custom == null || result.ReturnInfo == null)
+                            if (item.State == EWaitSendTaskState.StopPush)
                             {
-                                //请求报错,那么则所有的推送失败
-                                isError = true;
+                                item.State = EWaitSendTaskState.WaitPush;
+                                //修改待推送表
+                                await _waitSendTaskSubmitCaseInfoRepository.UpdateAsync(item, context.CancellationToken);
                             }
                             else
                             {
-                                if (result.Custom.ErrorObjs.Exists(p => p.CaseSerial == item.ProvinceNo && p.ErrorMsg != "本次推送内容中该条数据重复,跳过"))
+                                //查询是否有错误
+                                //有错误处理
+                                //没有错误删除待推送表,更新主表
+                                bool isError = false;
+                                if (result == null || result.Custom == null || result.ReturnInfo == null)
+                                {
+                                    //请求报错,那么则所有的推送失败
                                     isError = true;
-                            }
+                                }
+                                else
+                                {
+                                    if (result.Custom.ErrorObjs.Exists(p => p.CaseSerial == item.ProvinceNo && p.ErrorMsg != "本次推送内容中该条数据重复,跳过"))
+                                        isError = true;
+                                }
 
-                            #region 处理待推送表数据
-                            //处理待推送数据
-                            if (isError)
-                            {
-                                //修改
-                                item.LastTime = DateTime.Now;
-                                item.SendTimes = item.SendTimes + 1;
+                                #region 处理待推送表数据
+                                //处理待推送数据
+                                if (isError)
+                                {
+                                    //修改
+                                    item.LastTime = DateTime.Now;
+                                    item.SendTimes = item.SendTimes + 1;
 
-                                if (item.FirstTime is null)
-                                    item.FirstTime = DateTime.Now;
+                                    if (item.FirstTime is null)
+                                        item.FirstTime = DateTime.Now;
 
-                                if (item.SendTimes >= 7)
-                                    item.State = EWaitSendTaskState.PushFail;
-                                else
-                                    item.State = EWaitSendTaskState.WaitPush;
+                                    if (item.SendTimes >= 7)
+                                        item.State = EWaitSendTaskState.PushFail;
+                                    else
+                                        item.State = EWaitSendTaskState.WaitPush;
 
-                                //修改待推送表
-                                await _waitSendTaskSubmitCaseInfoRepository.UpdateAsync(item, context.CancellationToken);
-                            }
-                            else
-                            {
-                                //删除
-                                await _waitSendTaskSubmitCaseInfoRepository.RemoveAsync(item, cancellationToken: context.CancellationToken);
-                            }
-                            #endregion
+                                    //修改待推送表
+                                    await _waitSendTaskSubmitCaseInfoRepository.UpdateAsync(item, context.CancellationToken);
+                                }
+                                else
+                                {
+                                    //删除
+                                    await _waitSendTaskSubmitCaseInfoRepository.RemoveAsync(item, cancellationToken: context.CancellationToken);
+                                }
+                                #endregion
 
-                            #region 处理数据推送主表数据
-                            //查询主表
-                            var sendData = await _sendTaskSubmitCaseInfoRepository.GetAsync(p => p.Id == item.Id, context.CancellationToken);
-                            if (sendData != null)
-                            {
-                                sendData.LastTime = DateTime.Now;
-                                sendData.SendTimes = sendData.SendTimes + 1;
+                                #region 处理数据推送主表数据
+                                //查询主表
+                                var sendData = await _sendTaskSubmitCaseInfoRepository.GetAsync(p => p.Id == item.Id, context.CancellationToken);
+                                if (sendData != null)
+                                {
+                                    sendData.LastTime = DateTime.Now;
+                                    sendData.SendTimes = sendData.SendTimes + 1;
 
-                                if (sendData.FirstTime is null)
-                                    sendData.FirstTime = DateTime.Now;
+                                    if (sendData.FirstTime is null)
+                                        sendData.FirstTime = DateTime.Now;
 
-                                sendData.IsSuccess = isError == false ? ESendTaskState.PushSuccess : ESendTaskState.PushFail;
-                                await _sendTaskSubmitCaseInfoRepository.UpdateAsync(sendData, cancellationToken: context.CancellationToken);
-                            }
-                            #endregion
+                                    sendData.IsSuccess = isError == false ? ESendTaskState.PushSuccess : ESendTaskState.PushFail;
+                                    await _sendTaskSubmitCaseInfoRepository.UpdateAsync(sendData, cancellationToken: context.CancellationToken);
+                                }
+                                #endregion
 
-                            #region 新增推送明细
-                            //新增明细
-                            DsSendTaskDetailInfo dsSendTaskDetailInfo = new()
-                            {
-                                TaskId = item.Id,
-                                IsSuccess = !isError,
-                                Result = System.Text.RegularExpressions.Regex.Unescape(JsonSerializer.Serialize(result)),
-                                ResultErrorData = error,
-                                ProcessingServices = _channelConfigurationManager.GetConfigurationProcessingServices()
-                            };
-                            await _sendTaskDetailInfoRepository.AddAsync(dsSendTaskDetailInfo, context.CancellationToken);
-                            #endregion
+                                #region 新增推送明细
+                                //新增明细
+                                DsSendTaskDetailInfo dsSendTaskDetailInfo = new()
+                                {
+                                    TaskId = item.Id,
+                                    IsSuccess = !isError,
+                                    Result = System.Text.RegularExpressions.Regex.Unescape(JsonSerializer.Serialize(result)),
+                                    ResultErrorData = error,
+                                    ProcessingServices = _channelConfigurationManager.GetConfigurationProcessingServices()
+                                };
+                                await _sendTaskDetailInfoRepository.AddAsync(dsSendTaskDetailInfo, context.CancellationToken);
+                                #endregion
 
-                            #region 上传成功后,处理工单的上传时间,用于统计
-                            if (!isError)
-                            {
-                                var order = await _orderSendRepository.GetAsync(p => p.ProvinceNo == item.ProvinceNo, context.CancellationToken);
-                                if (order != null)
+                                #region 上传成功后,处理工单的上传时间,用于统计
+                                if (!isError)
                                 {
-                                    if (order.FirstSendProvinceTime is null)
-                                        order.FirstSendProvinceTime = DateTime.Now;
+                                    var order = await _orderSendRepository.GetAsync(p => p.ProvinceNo == item.ProvinceNo, context.CancellationToken);
+                                    if (order != null)
+                                    {
+                                        if (order.FirstSendProvinceTime is null)
+                                            order.FirstSendProvinceTime = DateTime.Now;
 
-                                    order.LastSendProvinceTime = DateTime.Now;
-                                    await _orderSendRepository.UpdateAsync(order, context.CancellationToken);
+                                        order.LastSendProvinceTime = DateTime.Now;
+                                        await _orderSendRepository.UpdateAsync(order, context.CancellationToken);
+                                    }
                                 }
+                                #endregion
                             }
-                            #endregion
                         }
                     }
                 }