浏览代码

Merge branch 'master' of http://git.ius.plus:88/Project-Wing/WingCloudServer

denny 8 月之前
父节点
当前提交
94649b397d

+ 5 - 1
src/HealthExamBookingService/HealthExamBookingService.cs

@@ -577,7 +577,11 @@ public partial class HealthExamBookingService : JsonRpcService, IVitalHealthExam
             if (jingQiRes.Status != "0")
             {
                 Logger.WriteLineError($"HealthExamBookingService JingQiExamRegisterAsync failed, cardNo:{request.IDCardNo}, Status:{jingQiRes.Status}, ErroMsg:{jingQiRes.ErroMsg}");
-                if (jingQiRes.Status == "2")
+                if (jingQiRes.Status == "")
+                {
+                    ThrowCustomerException(CustomerRpcCode.JingQiException, "JingQiException");
+                }
+                else if (jingQiRes.Status == "2")
                 {
                     ThrowCustomerException(CustomerRpcCode.JingQiNonArea, "JingQiNonArea");
                 }

+ 2 - 0
src/VitalMixtureService/DBService/DBAutoMapperProfile.cs

@@ -347,7 +347,9 @@ namespace VitalServer
             CreateMap<PopulationFinishStatisticsEntity, PopulationFinishStatisticsDTO>().ReverseMap();
 			
             CreateMap<FacturyUserDTO, FacturyUserEntity>().ReverseMap();
+            CreateMap<PageCollection<FacturyUserDTO>, PageCollection<FacturyUserEntity>>().ReverseMap();
             CreateMap<FacturyPostHistoryDTO, FacturyPostHistoryEntity>().ReverseMap();
+            CreateMap<PageCollection<FacturyPostHistoryDTO>, PageCollection<FacturyPostHistoryEntity>>().ReverseMap();
 		}
 	}
 }

+ 5 - 1
src/VitalMixtureService/DBService/Service/FacturyPostHistoryDBService.cs

@@ -54,7 +54,7 @@ namespace VitalService.Service
                     var update = Builders<FacturyPostHistoryEntity>.Update
                         .Set(f => f.Status, request.Status)
                         .Set(f => f.Result, request.Result)
-                        .Set(f => f.PostTime, DateTime.UtcNow)
+                        .Set(f => f.PostTime, request.PostTime)
                         .Set(f => f.UpdateTime, DateTime.UtcNow);
                     return await _facturyPostHistoryDBRepository.UpdateOneAsync(filter, update) > 0;
                 }
@@ -82,6 +82,10 @@ namespace VitalService.Service
         public async Task<PageCollection<FacturyPostHistoryDTO>> GetFacturyPostHistoryByPageDBAsync(GetFacturyPostHistoryByPageDBRequest request)
         {
             var filter = await _facturyPostHistoryDBRepository.GetPageFilter(request);
+            if (request.Status > 0)
+            {
+                filter &= Builders<FacturyPostHistoryEntity>.Filter.Eq(x => x.Status, request.Status);
+            }
             var pageFilter = new DBPageRequest<FacturyPostHistoryEntity>
             {
                 PageIndex = request.PageIndex,

+ 102 - 0
src/VitalMixtureService/Factury/FacturyManage.cs

@@ -0,0 +1,102 @@
+using Newtonsoft.Json;
+using WingInterfaceLibrary.DTO.Vital;
+using WingServerCommon.Log;
+using WingServerCommon.Utilities.Executors;
+
+namespace VitalService.Factury
+{
+    public class FacturyManage
+    {
+        private BaseApiHelper _baseApiHelper;
+        private Action<string, bool, DateTime, string> OnUpdateHistoryStatus;
+        private Func<List<FacturyPostHistoryDTO>> OnGetNonPostHistory;
+        private readonly SequenceExecutor<FacturyPostHistoryDTO> _sequenceExecutor = new SequenceExecutor<FacturyPostHistoryDTO>("FacturySequenceExecutor");
+
+        public FacturyManage(Action<string, bool, DateTime, string> funUpdateHistoryStatus
+            , Func<List<FacturyPostHistoryDTO>> funGetNonPostHistory)
+        {
+            _baseApiHelper = new BaseApiHelper(60);
+            OnUpdateHistoryStatus = funUpdateHistoryStatus;
+            OnGetNonPostHistory = funGetNonPostHistory;
+            SendNonPostHistory();
+        }
+
+        public void Add(FacturyPostHistoryDTO history)
+        {
+            if (history.Status == 1 && !_sequenceExecutor.GetRestWorkers().Any(x => x.Parameter.Code == history.Code))
+            {
+                _sequenceExecutor.Add(DoPost, history);
+            }
+        }
+
+        private void SendNonPostHistory()
+        {
+            var nonPostRecords = OnGetNonPostHistory?.Invoke();
+            Logger.WriteLineInfo($"VitalMixtureService FacturyManage SendNonPostHistory nonPostRecords totalCount:{nonPostRecords?.Count ?? 0}");
+            if (nonPostRecords?.Any() ?? false)
+            {
+                foreach (var record in nonPostRecords)
+                {
+                    Add(record);
+                }
+            }
+        }
+
+        private bool DoPost(FacturyPostHistoryDTO history)
+        {
+            var idCardNo = history.IDCardNo;
+            var postTime = DateTime.UtcNow;
+            try
+            {
+                Logger.WriteLineInfo($"VitalMixtureService FacturyManage DoPost start, idCardNo:{idCardNo}");
+                var res = GetResult(history.FacturyUrl, history.Content, history.Headers, idCardNo).Result;
+
+                var success = res.Item1;
+                var rpcRes = res.Item2;
+                if (success)
+                {
+                    Logger.WriteLineInfo($"VitalMixtureService FacturyManage DoPost success, idCardNo:{idCardNo}, res:{rpcRes}");
+                }
+                else
+                {
+                    Logger.WriteLineError($"VitalMixtureService FacturyManage DoPost failed, idCardNo:{idCardNo}, res:{rpcRes}");
+                }
+                OnUpdateHistoryStatus?.Invoke(history.Code, success, postTime, rpcRes);
+            }
+            catch (Exception ex)
+            {
+                Logger.WriteLineInfo($"VitalMixtureService FacturyManage DoPost error, ex:{ex}");
+            }
+            finally
+            {
+                Logger.WriteLineInfo($"VitalMixtureService FacturyManage DoPost finally, idCardNo:{idCardNo}");
+            }
+            return true;
+        }
+
+        private async Task<Tuple<bool, string>> GetResult(string url, string request, Dictionary<string, string> headers, string idCardNo)
+        {
+            try
+            {
+                var res = await _baseApiHelper.GetResult(url, request, headers);
+                if (!string.IsNullOrWhiteSpace(res))
+                {
+                    var facturyRes = JsonConvert.DeserializeObject<FacturyResult>(res);
+                    return new Tuple<bool, string>(facturyRes.status == "0", res);
+                }
+                return new Tuple<bool, string>(false, res);
+            }
+            catch (Exception ex)
+            {
+                Logger.WriteLineWarn($"VitalMixtureService FacturyManage error, idCardNo:{idCardNo}, ex:{ex}");
+                return new Tuple<bool, string>(false, ex.ToString());
+            }
+        }
+
+    }
+
+    public class FacturyResult
+    {
+        public string status { get; set; }
+    }
+}

+ 13 - 13
src/VitalMixtureService/Factury/JingQiApiHelper.cs

@@ -23,7 +23,7 @@ namespace VitalService.Factury
             }
         }
 
-        public JingQiApiHelper(string serverUrl, double seconds = 30) : base(seconds)
+        public JingQiApiHelper(string serverUrl, double seconds = 60) : base(seconds)
         {
             _serverUrl = serverUrl?.Trim('/') ?? string.Empty;
             Logger.WriteLineInfo($"VitalMixtureService JingQiApiHelper init, serverUrl:{_serverUrl}, seconds:{seconds}");
@@ -35,10 +35,10 @@ namespace VitalService.Factury
         /// <param name="request"></param>
         /// <param name="headers"></param>
         /// <returns></returns>
-        public async Task<JingQiResult<JingQiExamRegisterResult>> ExamRegisterAsync(JingQiExamRegisterRequest request, Dictionary<string, string> headers)
+        public async Task<JingQiResult<JingQiExamRegisterResult>> ExamRegisterAsync(JingQiExamRegisterRequest request, Dictionary<string, string> headers, string idCardNo)
         {
-            Logger.WriteLineInfo($"VitalMixtureService JingQiApiHelper ExamRegisterAsync start, request:{request}");
-            return await GetJingQiResult<JingQiExamRegisterResult>(RegisterUrl, JsonConvert.SerializeObject(request), headers);
+            Logger.WriteLineInfo($"VitalMixtureService JingQiApiHelper ExamRegisterAsync start, idCardNo:{idCardNo}, request:{request}");
+            return await GetJingQiResult<JingQiExamRegisterResult>(RegisterUrl, JsonConvert.SerializeObject(request), headers, idCardNo);
         }
 
         /// <summary>
@@ -47,40 +47,40 @@ namespace VitalService.Factury
         /// <param name="request"></param>
         /// <param name="headers"></param>
         /// <returns></returns>
-        public async Task<JingQiResult<JingQiExamDeleteResult>> ExamDeleteAsync(JingQiExamDeleteRequest request, Dictionary<string, string> headers)
+        public async Task<JingQiResult<JingQiExamDeleteResult>> ExamDeleteAsync(JingQiExamDeleteRequest request, Dictionary<string, string> headers, string idCardNo)
         {
-            Logger.WriteLineInfo($"VitalMixtureService JingQiApiHelper ExamDeleteAsync start, request:{request}");
-            return await GetJingQiResult<JingQiExamDeleteResult>(DeleteRegisterUrl, JsonConvert.SerializeObject(request), headers);
+            Logger.WriteLineInfo($"VitalMixtureService JingQiApiHelper ExamDeleteAsync start, idCardNo:{idCardNo}, request:{request}");
+            return await GetJingQiResult<JingQiExamDeleteResult>(DeleteRegisterUrl, JsonConvert.SerializeObject(request), headers, idCardNo);
         }
 
-        private async Task<JingQiResult<TResult>> GetJingQiResult<TResult>(string url, string request, Dictionary<string, string> headers)
+        private async Task<JingQiResult<TResult>> GetJingQiResult<TResult>(string url, string request, Dictionary<string, string> headers, string idCardNo)
         {
             try
             {
                 var res = await GetResult(url, request, headers);
-                Logger.WriteLineInfo($"VitalMixtureService JingQiApiHelper GetJingQiResult success, res:{res}");
+                Logger.WriteLineInfo($"VitalMixtureService JingQiApiHelper GetJingQiResult success, idCardNo:{idCardNo}, res:{res}");
                 if (!string.IsNullOrWhiteSpace(res))
                 {
                     var jingQiResult = JsonConvert.DeserializeObject<JingQiResult<TResult>>(res);
                     if (jingQiResult.status == "0")
                     {
-                        Logger.WriteLineInfo($"VitalMixtureService JingQiApiHelper GetJingQiResult success, ErroMsg:{jingQiResult.ErroMsg}");
+                        Logger.WriteLineInfo($"VitalMixtureService JingQiApiHelper GetJingQiResult success, idCardNo:{idCardNo}, ErroMsg:{jingQiResult.ErroMsg}");
                     }
                     else
                     {
-                        Logger.WriteLineError($"VitalMixtureService JingQiApiHelper GetJingQiResult failed, status:{jingQiResult.status}, ErroMsg:{jingQiResult.ErroMsg}");
+                        Logger.WriteLineError($"VitalMixtureService JingQiApiHelper GetJingQiResult failed, idCardNo:{idCardNo}, status:{jingQiResult.status}, ErroMsg:{jingQiResult.ErroMsg}");
                     }
                     return jingQiResult;
                 }
                 return new JingQiResult<TResult>
                 {
-                    status = "error",
+                    status = "",
                     ErroMsg = "",
                 };
             }
             catch (Exception ex)
             {
-                Logger.WriteLineWarn($"VitalMixtureService JingQiApiHelper GetJingQiResult error, ex:{ex}");
+                Logger.WriteLineWarn($"VitalMixtureService JingQiApiHelper GetJingQiResult error, idCardNo:{idCardNo}, ex:{ex}");
                 return new JingQiResult<TResult>
                 {
                     status = "error",

+ 7 - 5
src/VitalMixtureService/FrontService/Service/BaseService.cs

@@ -79,6 +79,7 @@ namespace VitalService.Service
         private PigeonUpload _pigeonUpload;
         private List<string> _appsettingCrowdLabels = new List<string>();
         private JingQiApiHelper _jingQiApiHelper;
+        private FacturyManage _facturyManage;
         /// <summary>
         /// Init service
         /// </summary>
@@ -136,11 +137,6 @@ namespace VitalService.Service
             AnalyzeStrategy.StorageHandler = UploadData;
             StartApi();
             LoadResourceInfos();
-            var jingQiServerUrl = EnvironmentConfigManager.GetParammeter<StringParameter>("Vital", "JingQiServerUrl").Value;
-            if (!string.IsNullOrWhiteSpace(jingQiServerUrl))
-            {
-                _jingQiApiHelper = new JingQiApiHelper(jingQiServerUrl);
-            }
         }
 
         /// <summary>
@@ -155,6 +151,12 @@ namespace VitalService.Service
                     StartCheckInitOrganizationAsync().Wait();
                     _pigeonUpload = new PigeonUpload(_cloudServerUrl, _syncToken);
                 }
+                var jingQiServerUrl = EnvironmentConfigManager.GetParammeter<StringParameter>("Vital", "JingQiServerUrl").Value;
+                if (!string.IsNullOrWhiteSpace(jingQiServerUrl))
+                {
+                    _jingQiApiHelper = new JingQiApiHelper(jingQiServerUrl);
+                }
+                _facturyManage = new FacturyManage(OnUpdateHistoryStatus, OnGetNonPostHistory);
             }
             catch (Exception ex)
             {

+ 45 - 10
src/VitalMixtureService/FrontService/Service/FacturyPostHistoryService.cs

@@ -4,6 +4,7 @@ using WingInterfaceLibrary.Request.Vital;
 using WingInterfaceLibrary.Request.DBVitalRequest;
 using WingInterfaceLibrary.DTO.Vital;
 using WingInterfaceLibrary.Request;
+using WingServerCommon.Log;
 
 namespace VitalService.Service
 {
@@ -62,6 +63,7 @@ namespace VitalService.Service
                 Keyword = request.Keyword,
                 StartTime = request.StartTime,
                 EndTime = request.EndTime,
+                Status = request.Status,
             };
             return await _vitalFacturyPostHistoryDBService.GetFacturyPostHistoryByPageDBAsync(dbRequest);
         }
@@ -93,22 +95,55 @@ namespace VitalService.Service
             });
             if (history != null)
             {
-                await _vitalFacturyPostHistoryDBService.CreateFacturyPostHistoryDBAsync(new CreateFacturyPostHistoryDBRequest
+                await _vitalFacturyPostHistoryDBService.UpdateFacturyPostHistoryDBAsync(new UpdateFacturyPostHistoryDBRequest
                 {
-                    FacturyUniqueCode = history.FacturyUniqueCode,
-                    ApiType = history.ApiType,
-                    FacturyUrl = history.FacturyUrl,
-                    IDCardNo = history.IDCardNo,
-                    PatientName = history.PatientName,
-                    Status = 1,
+                    Code = history.Code,
                     PostTime = DateTime.MinValue,
-                    Headers = history.Headers,
-                    Content = history.Content,
-                    Result = history.Result,
+                    Result = "",
+                    Status = 1,
                 });
+                history = await _vitalFacturyPostHistoryDBService.GetFacturyPostHistoryDBAsync(new GetFacturyPostHistoryDBRequest { Code = history.Code });
+                _facturyManage.Add(history);
                 return true;
             }
             return false;
         }
+
+        private void OnUpdateHistoryStatus(string code, bool success, DateTime postTime, string rpcResult)
+        {
+            try
+            {
+                var dbRequest = new UpdateFacturyPostHistoryDBRequest
+                {
+                    Code = code,
+                    PostTime = postTime,
+                    Result = rpcResult,
+                    Status = success ? 2 : 3,
+                };
+                var res = _vitalFacturyPostHistoryDBService.UpdateFacturyPostHistoryDBAsync(dbRequest).Result;
+            }
+            catch (Exception ex)
+            {
+                Logger.WriteLineWarn($"FacturyPostHistoryService OnUpdateHistoryStatus error, ex:{ex}");
+            }
+        }
+
+        private List<FacturyPostHistoryDTO> OnGetNonPostHistory()
+        {
+            var nonPostHistory = new List<FacturyPostHistoryDTO>();
+            try
+            {
+                nonPostHistory = _vitalFacturyPostHistoryDBService.GetNonPostHistoryDBAsync(new GetNonPostHistoryDBRequest
+                {
+
+                }).Result;
+            }
+            catch (Exception ex)
+            {
+                Logger.WriteLineWarn($"FacturyPostHistoryService OnGetNonPostHistory error, ex:{ex}");
+            }
+            return nonPostHistory;
+        }
+
     }
 }

+ 2 - 2
src/VitalMixtureService/FrontService/Service/FacturyUserService.cs

@@ -172,7 +172,7 @@ namespace VitalService.Service
                         usrcode = facturyUser.FacturyCode,
                         phydatetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                     };
-                    var jingQiRes = await _jingQiApiHelper.ExamRegisterAsync(jingQiReq, facturyOrg.FacturyData);
+                    var jingQiRes = await _jingQiApiHelper.ExamRegisterAsync(jingQiReq, facturyOrg.FacturyData, request.Identity);
                     await _vitalFacturyPostHistoryDBService.CreateFacturyPostHistoryDBAsync(new CreateFacturyPostHistoryDBRequest
                     {
                         ApiType = "ExamRegisterAsync",
@@ -246,7 +246,7 @@ namespace VitalService.Service
                     {
                         phyid = request.PhyId,
                     };
-                    var jingQiRes = await _jingQiApiHelper.ExamDeleteAsync(jingQiReq, facturyOrg.FacturyData);
+                    var jingQiRes = await _jingQiApiHelper.ExamDeleteAsync(jingQiReq, facturyOrg.FacturyData, request.Identity);
                     await _vitalFacturyPostHistoryDBService.CreateFacturyPostHistoryDBAsync(new CreateFacturyPostHistoryDBRequest
                     {
                         ApiType = "ExamDeleteAsync",