Browse Source

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

fly 8 months ago
parent
commit
5fe1d20d83

+ 138 - 2
src/HealthExamBookingService/HealthExamBookingService.cs

@@ -23,6 +23,9 @@ using WingInterfaceLibrary.DTO.Patient;
 using WingServerCommon.Utilities;
 using WingInterfaceLibrary.Enum.VitalEnum;
 using System.Text.RegularExpressions;
+using WingInterfaceLibrary.Request.DBVitalRequest;
+using System.Reflection;
+using WingInterfaceLibrary.Interface.VitalInterface;
 
 namespace VitalRegisterService;
 
@@ -33,6 +36,7 @@ public partial class HealthExamBookingService : JsonRpcService, IVitalHealthExam
     private string _cloudServerUrl;
     private string _syncToken;
     private int _syncSeconds;
+    private string _jingQiServerUrl;
     private List<HealthExamLabelDTO> _examLabels = new List<HealthExamLabelDTO>();
     private IAuthenticationService _authenticationService;
     private IVitalUserDBService _vitalUserDBService;
@@ -46,6 +50,8 @@ public partial class HealthExamBookingService : JsonRpcService, IVitalHealthExam
     private IReportService _wingReportService;
     private IVitalPatientDBService _vitalPatientDBService;
     private RpcClient _cloudRpcClient;
+    private IVitalFacturyUserDBService _vitalFacturyUserDBService;
+    private IVitalFacturyUserService _vitalFacturyUserService;
     private List<HealthExamItemDTO> _jiayiExamItems = new List<HealthExamItemDTO>
     {
         new HealthExamItemDTO { Code = "HEIBasic", Name = "基础检查", Content = "" },
@@ -90,6 +96,16 @@ public partial class HealthExamBookingService : JsonRpcService, IVitalHealthExam
         _wingReportService = GetProxy<IReportService>();
         _vitalPatientDBService = GetProxy<IVitalPatientDBService>();
         _cloudRpcClient = new RpcClient();
+        _vitalFacturyUserDBService = GetProxy<IVitalFacturyUserDBService>();
+        _vitalFacturyUserService = GetProxy<IVitalFacturyUserService>();
+        try
+        {
+            _jingQiServerUrl = EnvironmentConfigManager.GetParammeter<StringParameter>("Vital", "JingQiServerUrl").Value;
+        }
+        catch
+        {
+            Logger.WriteLineWarn($"HealthExamBookingService Vital JingQiServerUrl not config");
+        }
     }
 
     /// <summary>
@@ -455,7 +471,7 @@ public partial class HealthExamBookingService : JsonRpcService, IVitalHealthExam
             {
                 if (existedRegisterInfos?.Any(x => x.ProjectType == request.ProjectType) ?? false)
                 {
-                    ThrowCustomerException(WingInterfaceLibrary.Enum.CustomerRpcCode.RegisteredSameDay, "Registered Same Day");
+                    ThrowCustomerException(CustomerRpcCode.RegisteredSameDay, "Registered Same Day");
                 }
             }
             var patientInfo = await _vitalPatientDBService.GetPatientDetailAsync(new WingInterfaceLibrary.Request.DBVitalRequest.GetPatientDBRequest
@@ -465,6 +481,9 @@ public partial class HealthExamBookingService : JsonRpcService, IVitalHealthExam
             });
             var isNewPatient = patientInfo == null || string.IsNullOrWhiteSpace(patientInfo.Code);
             var crowdLabels = patientInfo?.CrowdLabels?.ToList() ?? new List<string>();
+            //晶奇
+            var jingQiRes = await JingQiExamRegisterAsync(request);
+            dto.JingQiExamInfos = jingQiRes;
             //体检号
             var num = await _registerInfoDBService.GetRegisterNumberAsync(organizationCode);
             var physicalExamNumber = $"{orgInfo.OrganizationUniqueCode ?? string.Empty}{DateTime.Now.ToString("yyyyMMdd")}{(num + 1).ToString("000")}";
@@ -484,7 +503,6 @@ public partial class HealthExamBookingService : JsonRpcService, IVitalHealthExam
                     {
                         await CreateRecordAsync(dto);
                     }
-                    
                     if (orgInfo.ExamItemCodes?.Contains("HEIECG") ?? false)//心电
                     {
                         await AddElectrocardiogramRecord(dto, userInfo.Code, organizationCode);
@@ -501,6 +519,93 @@ public partial class HealthExamBookingService : JsonRpcService, IVitalHealthExam
         return new AddRegiterInfoResult();
     }
 
+    /// <summary>
+    /// 删除登记信息
+    /// </summary>
+    /// <returns></returns>
+    public async Task<bool> DeleteRegiterInfoAsync(DeleteRegiterInfoRequest request)
+    {
+        var registerCode = request.RegisterCode;
+        var registerInfo = await _registerInfoDBService.FindRegisterInfoByCodeAsync(registerCode);
+        if (registerInfo != null && registerInfo.JingQiExamInfos != null && registerInfo.JingQiExamInfos.Any()
+            && registerInfo.JingQiExamInfos.ContainsKey("PhyId") && !string.IsNullOrWhiteSpace(registerInfo.JingQiExamInfos["PhyId"]))
+        {
+            try
+            {
+                var jingQiRes = await _vitalFacturyUserService.FacturyExamDeleteAsync(new FacturyExamDeleteRequest
+                {
+                    Token = request.Token,
+                    PhyId = registerInfo.JingQiExamInfos["PhyId"],
+                    Identity = registerInfo.IDCardNo,
+                    PatientName = registerInfo.Name,
+                });
+                if (jingQiRes.Status != "0")
+                {
+                    Logger.WriteLineError($"HealthExamBookingService DeleteRegiterInfoAsync failed, cardNo:{registerInfo.IDCardNo}, Status:{jingQiRes.Status}, ErroMsg:{jingQiRes.ErroMsg}");
+                }
+                else
+                {
+                    Logger.WriteLineInfo($"HealthExamBookingService DeleteRegiterInfoAsync success, cardNo:{registerInfo.IDCardNo}, Status:{jingQiRes.Status}, ErroMsg:{jingQiRes.ErroMsg}");
+                }
+            }
+            catch (Exception ex)
+            {
+            }
+        }
+        return await _registerInfoDBService.DeleteRegisterInfoAsync(registerCode);
+    }
+
+    private async Task<Dictionary<string, string>> JingQiExamRegisterAsync(AddRegiterInfoRequest request)
+    {
+        var jingQiExamInfos = new Dictionary<string, string>();
+        if (await IsJingQiRequiredAsync(request))
+        {
+            FacturyExamRegisterResult jingQiRes = null;
+            try
+            {
+                jingQiRes = await _vitalFacturyUserService.FacturyExamRegisterAsync(new FacturyExamRegisterRequest
+                {
+                    Token = request.Token,
+                    Identity = request.IDCardNo,
+                    PatientName = request.Name,
+                });
+            }
+            catch (Exception ex)
+            {
+                return jingQiExamInfos;
+            }
+            if (jingQiRes.Status != "0")
+            {
+                Logger.WriteLineError($"HealthExamBookingService JingQiExamRegisterAsync failed, cardNo:{request.IDCardNo}, Status:{jingQiRes.Status}, ErroMsg:{jingQiRes.ErroMsg}");
+                if (jingQiRes.Status == "2")
+                {
+                    ThrowCustomerException(CustomerRpcCode.JingQiNonArea, "JingQiNonArea");
+                }
+                else if (jingQiRes.Status == "3")
+                {
+                    ThrowCustomerException(CustomerRpcCode.JingQiExamedInYear, "JingQiExamedInYear");
+                }
+                else
+                {
+                    ThrowCustomerException(CustomerRpcCode.JingQiApiFailed, jingQiRes.ErroMsg);
+                }
+            }
+            else
+            {
+                Logger.WriteLineInfo($"HealthExamBookingService JingQiExamRegisterAsync success, cardNo:{request.IDCardNo}, Status:{jingQiRes.Status}, ErroMsg:{jingQiRes.ErroMsg}");
+            }
+            PropertyInfo[] properties = typeof(FacturyExamRegisterResult).GetProperties();
+            foreach (PropertyInfo property in properties)
+            {
+                if (property.Name != "Status" && property.Name != "ErroMsg")
+                {
+                    jingQiExamInfos.Add(property.Name, property.GetValue(jingQiRes)?.ToString());
+                }
+            }
+        }
+        return jingQiExamInfos;
+    }
+
     private async Task<string> CreateRecordAsync(RegisterInfoDTO registerInfo)
     {
         try
@@ -835,4 +940,35 @@ public partial class HealthExamBookingService : JsonRpcService, IVitalHealthExam
         }
         return null;
     }
+
+    private async Task<bool> IsJingQiRequiredAsync(TokenRequest request)
+    {
+        if (string.IsNullOrWhiteSpace(_jingQiServerUrl))
+        {
+            return false;
+        }
+        var userCode = await GetClientIdByTokenAsync(request.Token);
+        var userInfo = await _vitalUserDBService.GetUserDetailAsync(new GetUserDBRequest
+        {
+            Code = userCode,
+        });
+        if (userInfo == null || string.IsNullOrWhiteSpace(userInfo.FacturyUserCode))
+        {
+            return false;
+        }
+        var facturyUser = await _vitalFacturyUserDBService.GetFacturyUserDBAsync(new GetFacturyUserDBRequest
+        {
+            Code = userInfo.FacturyUserCode,
+        });
+        var facturyOrg = await _vitalFacturyUserDBService.GetFacturyUserDBAsync(new GetFacturyUserDBRequest
+        {
+            Code = facturyUser.FatherCode,
+        });
+        if (facturyUser == null || string.IsNullOrWhiteSpace(facturyUser.FacturyCode)
+            || facturyOrg == null || string.IsNullOrWhiteSpace(facturyOrg.FacturyCode))
+        {
+            return false;
+        }
+        return true;
+    }
 }

+ 14 - 0
src/Resource/Measure/MeasureSpecialImpl.json

@@ -29,6 +29,11 @@
 			"FLOW VOL",
 			"Levator Hiatus Stress"
 		],
+		"GeneralMeasureTypeNameList": [
+			"SemiManualTrace",
+			"LvSingleSimpson",
+			"LvSimpson"
+		],
 		"ChildItemList": [
 			"SV Diam",
 			"TR Vmax",
@@ -105,6 +110,15 @@
 				"RemoveAvailableOutputs": [
 					"SV"
 				]
+			},
+			{
+				"BaseTypeName": "GastricCapacity",
+				"BaseMeasureTypeName": "",
+				"Name": "",
+				"RemoveAvailableOutputs": [
+					"Perimeter",
+					"GastricCapacity"
+				]
 			}
 		]
 	}

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

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

+ 67 - 0
src/VitalMixtureService/DBService/Entities/FacturyPostHistoryEntity.cs

@@ -0,0 +1,67 @@
+namespace VitalService.Entities
+{
+    public class FacturyPostHistoryEntity : BaseEntity
+    {
+        /// <summary>
+        /// 厂商标识
+        /// </summary>
+        /// <value></value>
+        public string FacturyUniqueCode { get; set; }
+
+        /// <summary>
+        /// 厂商接口地址
+        /// </summary>
+        /// <value></value>
+        public string FacturyUrl { get; set; }
+
+        /// <summary>
+        /// 病人身份证
+        /// </summary>
+        /// <value></value>
+        public string IDCardNo { get; set; }
+
+        /// <summary>
+        /// 病人姓名
+        /// </summary>
+        /// <value></value>
+        public string PatientName { get; set; }
+
+        /// <summary>
+        /// 接口类型
+        /// </summary>
+        /// <value></value>
+        public string ApiType { get; set; }
+
+        /// <summary>
+        /// 状态 1:待发送;2:发送成功;3:发送失败
+        /// </summary>
+        /// <value></value>
+        public int Status { get; set; }
+
+        /// <summary>
+        /// 发送时间
+        /// </summary>
+        /// <value></value>
+        public DateTime PostTime { get; set; }
+
+        /// <summary>
+        /// 请求头部信息
+        /// </summary>
+        /// <value></value>
+        public Dictionary<string, string> Headers { get; set; }
+
+        /// <summary>
+        /// 请求内容
+        /// </summary>
+        /// <value></value>
+        public string Content { get; set; }
+
+        /// <summary>
+        /// 响应内容
+        /// </summary>
+        /// <value></value>
+        public string Result { get; set; }
+
+
+    }
+}

+ 21 - 0
src/VitalMixtureService/DBService/QueryAction/FacturyPostHistoryQueryAction.cs

@@ -0,0 +1,21 @@
+using MongoDB.Driver;
+using VitalService.Entities;
+
+namespace VitalService.QueryAction
+{
+    public class FacturyPostHistoryQueryAction : IQueryAction<FacturyPostHistoryEntity>
+    {
+        public async Task<FilterDefinition<FacturyPostHistoryEntity>> GetQuery(string keyword)
+        {
+            if (string.IsNullOrWhiteSpace(keyword))
+            {
+                return Builders<FacturyPostHistoryEntity>.Filter.Empty;
+            }
+            var bsonRegular = new MongoDB.Bson.BsonRegularExpression($".*{keyword}.*", "ig");
+            var keywordFilters = new List<FilterDefinition<FacturyPostHistoryEntity>>();
+            keywordFilters.Add(Builders<FacturyPostHistoryEntity>.Filter.Regex(f => f.IDCardNo, bsonRegular));
+            keywordFilters.Add(Builders<FacturyPostHistoryEntity>.Filter.Regex(f => f.PatientName, bsonRegular));
+            return Builders<FacturyPostHistoryEntity>.Filter.Or(keywordFilters);
+        }
+    }
+}

+ 12 - 0
src/VitalMixtureService/DBService/Repositories/FacturyPostHistoryDBRepository.cs

@@ -0,0 +1,12 @@
+using VitalService.Entities;
+
+namespace VitalService.Repositories
+{
+    public class FacturyPostHistoryDBRepository : SimpleDBRepository<FacturyPostHistoryEntity>
+    {
+        public FacturyPostHistoryDBRepository() : base("FacturyPostHistory")
+        {
+           
+        }
+    }
+}

+ 118 - 0
src/VitalMixtureService/DBService/Service/FacturyPostHistoryDBService.cs

@@ -0,0 +1,118 @@
+using MongoDB.Driver;
+using VitalService.Entities;
+using WingServerCommon.Mapper;
+using VitalService.Request;
+using WingInterfaceLibrary.Request.DBVitalRequest;
+using WingInterfaceLibrary.DTO.Vital;
+using WingInterfaceLibrary.Request;
+using WingInterfaceLibrary.Interface.DBVitalInterface;
+
+namespace VitalService.Service
+{
+    /// <summary>
+    /// 第三方厂商数据推送记录
+    /// </summary>
+    public partial class VitalDatabaseService : IVitalFacturyPostHistoryDBService
+    {
+        /// <summary>
+        /// 创建数据
+        /// </summary>
+        /// <param name="request">创建请求</param>
+        /// <returns></returns>
+        public async Task<string> CreateFacturyPostHistoryDBAsync(CreateFacturyPostHistoryDBRequest request)
+        {
+            var entity = new FacturyPostHistoryEntity
+            {
+                FacturyUniqueCode = request.FacturyUniqueCode ?? string.Empty,
+                FacturyUrl = request.FacturyUrl,
+                IDCardNo = request.IDCardNo,
+                PatientName = request.PatientName,
+                ApiType = request.ApiType,
+                Status = request.Status,
+                PostTime = request.PostTime,
+                Headers = request.Headers,
+                Content = request.Content,
+                Result = request.Result,
+            };
+            return await _facturyPostHistoryDBRepository.InsertOneAsync(entity);
+        }
+
+        /// <summary>
+        /// 更新数据
+        /// </summary>
+        /// <param name="request">更新请求</param>
+        /// <returns></returns>
+        public async Task<bool> UpdateFacturyPostHistoryDBAsync(UpdateFacturyPostHistoryDBRequest request)
+        {
+            var code = request.Code;
+            if (!string.IsNullOrWhiteSpace(code))
+            {
+                var entity = await _facturyPostHistoryDBRepository.FindOneAsync(Builders<FacturyPostHistoryEntity>.Filter.Eq(f => f.Code, code));
+                if (entity != null && !entity.IsDelete)
+                {
+                    var filter = Builders<FacturyPostHistoryEntity>.Filter.Eq(f => f.Code, code);
+                    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.UpdateTime, DateTime.UtcNow);
+                    return await _facturyPostHistoryDBRepository.UpdateOneAsync(filter, update) > 0;
+                }
+            }
+            return false;
+        }
+
+        /// <summary>
+        /// 根据编码获取第三方厂商数据推送记录
+        /// </summary>
+        /// <param name="request">数据编码</param>
+        /// <returns></returns>
+        public async Task<FacturyPostHistoryDTO> GetFacturyPostHistoryDBAsync(GetFacturyPostHistoryDBRequest request)
+        {
+            var filter = Builders<FacturyPostHistoryEntity>.Filter.Eq(f => f.Code, request.Code);
+            var result = await _facturyPostHistoryDBRepository.FindOneAsync(filter);
+            return result.MappingTo<FacturyPostHistoryDTO>();
+        }
+
+        /// <summary>
+        /// 分页获取第三方厂商数据推送记录
+        /// </summary>
+        /// <param name="request">分页请求</param>
+        /// <returns></returns>
+        public async Task<PageCollection<FacturyPostHistoryDTO>> GetFacturyPostHistoryByPageDBAsync(GetFacturyPostHistoryByPageDBRequest request)
+        {
+            var filter = await _facturyPostHistoryDBRepository.GetPageFilter(request);
+            var pageFilter = new DBPageRequest<FacturyPostHistoryEntity>
+            {
+                PageIndex = request.PageIndex,
+                PageSize = request.PageSize,
+                Filter = filter,
+                Sort = Builders<FacturyPostHistoryEntity>.Sort.Descending(x => x.CreateTime)
+            };
+            var result = await _facturyPostHistoryDBRepository.GetPages(pageFilter);
+            return result.MappingTo<PageCollection<FacturyPostHistoryDTO>>();
+        }
+
+        /// <summary>
+        /// 获取所有未推送数据记录
+        /// </summary>
+        /// <param name="request">分页请求</param>
+        /// <returns></returns>
+        public async Task<List<FacturyPostHistoryDTO>> GetNonPostHistoryDBAsync(GetNonPostHistoryDBRequest request)
+        {
+            var filter = Builders<FacturyPostHistoryEntity>.Filter.Eq(f => f.Status, 1);
+            var result = await _facturyPostHistoryDBRepository.FindAllAsync(filter);
+            return result.MappingTo<List<FacturyPostHistoryDTO>>();
+        }
+
+        /// <summary>
+        /// 删除数据
+        /// </summary>
+        /// <param name="request">数据编码</param>
+        /// <returns></returns>
+        public async Task<bool> RemoveFacturyPostHistoryDBAsync(RemoveFacturyPostHistoryDBRequest request)
+        {
+            return await _facturyPostHistoryDBRepository.DeleteOneAsync("Code", request.Code);
+        }
+    }
+}

+ 1 - 1
src/VitalMixtureService/DBService/Service/FacturyUserDBService.cs

@@ -23,7 +23,7 @@ namespace VitalService.Service
         {
             var entity = new FacturyUserEntity
             {
-                FacturyUniqueCode = request.FacturyUniqueCode,
+                FacturyUniqueCode = request.FacturyUniqueCode ?? string.Empty,
                 FacturyType = request.FacturyType,
                 FacturyCode = request.FacturyCode,
                 FacturyName = request.FacturyName,

+ 2 - 0
src/VitalMixtureService/DBService/Service/VNoteDatabaseService.cs

@@ -80,6 +80,7 @@ namespace VitalService.Service
         private TownHealthPlatformStatisticsDBRepository _townHealthPlatformStatisticsDBRepository { get; set; }
         private VillageHealthPlatformStatisticsDBRepository _villageHealthPlatformStatisticsDBRepository { get; set; }
         private FacturyUserDBRepository _facturyUserDBRepository { get; set; }
+        private FacturyPostHistoryDBRepository _facturyPostHistoryDBRepository { get; set; }
         private JobQueue _jobQueueStatistic;
         private JobQueue _jobQueueReportSend;
         private JobQueue _jobQueueDataPulling;
@@ -134,6 +135,7 @@ namespace VitalService.Service
             _townHealthPlatformStatisticsDBRepository = new TownHealthPlatformStatisticsDBRepository();
             _villageHealthPlatformStatisticsDBRepository = new VillageHealthPlatformStatisticsDBRepository();
             _facturyUserDBRepository = new FacturyUserDBRepository();
+            _facturyPostHistoryDBRepository = new FacturyPostHistoryDBRepository();
             var initDBFlagFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "initDB.flag");
             var isInit = File.Exists(initDBFlagFile);
             if (!isInit)

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

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

+ 2 - 0
src/VitalMixtureService/FrontService/Service/BaseService.cs

@@ -75,6 +75,7 @@ namespace VitalService.Service
         private IVitalPrescriptionDBService _prescriptionDBService;
         private IVitalOrganizationDBService _vitalOrganizationDBService;
         private IVitalFacturyUserDBService _vitalFacturyUserDBService;
+        private IVitalFacturyPostHistoryDBService _vitalFacturyPostHistoryDBService;
         private PigeonUpload _pigeonUpload;
         private List<string> _appsettingCrowdLabels = new List<string>();
         private JingQiApiHelper _jingQiApiHelper;
@@ -130,6 +131,7 @@ namespace VitalService.Service
             _vitalHealthExamBookingService = GetProxy<IVitalHealthExamBookingService>();
             _vitalOrganizationDBService = GetProxy<IVitalOrganizationDBService>();
             _vitalFacturyUserDBService = GetProxy<IVitalFacturyUserDBService>();
+            _vitalFacturyPostHistoryDBService = GetProxy<IVitalFacturyPostHistoryDBService>();
             _prescriptionDBService = GetProxy<IVitalPrescriptionDBService>();
             AnalyzeStrategy.StorageHandler = UploadData;
             StartApi();

+ 114 - 0
src/VitalMixtureService/FrontService/Service/FacturyPostHistoryService.cs

@@ -0,0 +1,114 @@
+using WingServerCommon.Service;
+using WingInterfaceLibrary.Interface.VitalInterface;
+using WingInterfaceLibrary.Request.Vital;
+using WingInterfaceLibrary.Request.DBVitalRequest;
+using WingInterfaceLibrary.DTO.Vital;
+using WingInterfaceLibrary.Request;
+
+namespace VitalService.Service
+{
+    /// <summary>
+    /// 第三方厂商推送数据服务
+    /// </summary>
+    public partial class VitalService : JsonRpcService, IVitalFacturyPostHistoryService
+    {
+        /// <summary>
+        /// 创建数据
+        /// </summary>
+        /// <param name="request">创建请求</param>
+        /// <returns></returns>
+        public async Task<string> CreateFacturyPostHistoryAsync(CreateFacturyPostHistoryRequest request)
+        {
+            return await _vitalFacturyPostHistoryDBService.CreateFacturyPostHistoryDBAsync(new CreateFacturyPostHistoryDBRequest
+            {
+                FacturyUniqueCode = request.FacturyUniqueCode,
+                ApiType = request.ApiType,
+                FacturyUrl = request.FacturyUrl,
+                IDCardNo = request.IDCardNo,
+                PatientName = request.PatientName,
+                Status = request.Status,
+                PostTime = request.PostTime,
+                Headers = request.Headers,
+                Content = request.Content,
+                Result = request.Result,
+            });
+        }
+
+        /// <summary>
+        /// 根据编码获取第三方厂商推送记录
+        /// </summary>
+        /// <param name="request">数据编码</param>
+        /// <returns></returns>
+        public async Task<FacturyPostHistoryDTO> GetFacturyPostHistoryAsync(GetFacturyPostHistoryRequest request)
+        {
+            var dbRequest = new GetFacturyPostHistoryDBRequest
+            {
+                Code = request.Code,
+            };
+            return await _vitalFacturyPostHistoryDBService.GetFacturyPostHistoryDBAsync(dbRequest);
+        }
+
+        /// <summary>
+        /// 分页获取厂商推送记录
+        /// </summary>
+        /// <param name="request">分页请求</param>
+        /// <returns></returns>
+        public async Task<PageCollection<FacturyPostHistoryDTO>> GetFacturyPostHistoryByPageAsync(GetFacturyPostHistoryByPageRequest request)
+        {
+            var dbRequest = new GetFacturyPostHistoryByPageDBRequest
+            {
+                PageIndex = request.PageIndex,
+                PageSize = request.PageSize,
+                Keyword = request.Keyword,
+                StartTime = request.StartTime,
+                EndTime = request.EndTime,
+            };
+            return await _vitalFacturyPostHistoryDBService.GetFacturyPostHistoryByPageDBAsync(dbRequest);
+        }
+
+        /// <summary>
+        /// 删除厂商推送记录
+        /// </summary>
+        /// <param name="request">数据编码</param>
+        /// <returns></returns>
+        public async Task<bool> RemoveFacturyPostHistoryAsync(RemoveFacturyPostHistoryRequest request)
+        {
+            var dbRequest = new RemoveFacturyPostHistoryDBRequest
+            {
+                Code = request.Code,
+            };
+            return await _vitalFacturyPostHistoryDBService.RemoveFacturyPostHistoryDBAsync(dbRequest);
+        }
+
+        /// <summary>
+        /// 重发厂商推送记录
+        /// </summary>
+        /// <param name="request">数据编码</param>
+        /// <returns></returns>
+        public async Task<bool> ResendFacturyPostHistoryAsync(ResendFacturyPostHistoryRequest request)
+        {
+            var history = await _vitalFacturyPostHistoryDBService.GetFacturyPostHistoryDBAsync(new GetFacturyPostHistoryDBRequest
+            {
+                Code = request.Code,
+            });
+            if (history != null)
+            {
+                await _vitalFacturyPostHistoryDBService.CreateFacturyPostHistoryDBAsync(new CreateFacturyPostHistoryDBRequest
+                {
+                    FacturyUniqueCode = history.FacturyUniqueCode,
+                    ApiType = history.ApiType,
+                    FacturyUrl = history.FacturyUrl,
+                    IDCardNo = history.IDCardNo,
+                    PatientName = history.PatientName,
+                    Status = 1,
+                    PostTime = DateTime.MinValue,
+                    Headers = history.Headers,
+                    Content = history.Content,
+                    Result = history.Result,
+                });
+                return true;
+            }
+            return false;
+        }
+    }
+}

+ 80 - 3
src/VitalMixtureService/FrontService/Service/FacturyUserService.cs

@@ -5,6 +5,7 @@ using WingInterfaceLibrary.Request.DBVitalRequest;
 using WingInterfaceLibrary.DTO.Vital;
 using WingInterfaceLibrary.Request;
 using WingInterfaceLibrary.Enum;
+using Newtonsoft.Json;
 
 namespace VitalService.Service
 {
@@ -136,7 +137,7 @@ namespace VitalService.Service
         /// <returns></returns>
         public async Task<FacturyExamRegisterResult> FacturyExamRegisterAsync(FacturyExamRegisterRequest request)
         {
-            var userCode = string.Empty;
+            var userCode = await GetClientIdByTokenAsync(request.Token);
             var userInfo = await _userDBService.GetUserDetailAsync(new GetUserDBRequest
             {
                 Code = userCode,
@@ -164,13 +165,26 @@ namespace VitalService.Service
                 }
                 else
                 {
-                    var jingQiRes = await _jingQiApiHelper.ExamRegisterAsync(new Factury.JingQiExamRegisterRequest
+                    var jingQiReq = new Factury.JingQiExamRegisterRequest
                     {
                         identity = request.Identity,
                         orgcode = facturyOrg.FacturyCode,
                         usrcode = facturyUser.FacturyCode,
                         phydatetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
-                    }, facturyOrg.FacturyData);
+                    };
+                    var jingQiRes = await _jingQiApiHelper.ExamRegisterAsync(jingQiReq, facturyOrg.FacturyData);
+                    await _vitalFacturyPostHistoryDBService.CreateFacturyPostHistoryDBAsync(new CreateFacturyPostHistoryDBRequest
+                    {
+                        ApiType = "ExamRegisterAsync",
+                        FacturyUrl = _jingQiApiHelper.RegisterUrl,
+                        IDCardNo = request.Identity,
+                        PatientName = request.PatientName,
+                        Status = jingQiRes.status == "0" ? 2 : 3,
+                        PostTime = DateTime.UtcNow,
+                        Headers = facturyOrg.FacturyData,
+                        Content = JsonConvert.SerializeObject(jingQiReq),
+                        Result = JsonConvert.SerializeObject(jingQiRes),
+                    });
                     return new FacturyExamRegisterResult
                     {
                         Status = jingQiRes.status,
@@ -192,5 +206,68 @@ namespace VitalService.Service
             }
             return null;
         }
+
+        /// <summary>
+        /// 晶奇系统删除注册
+        /// </summary>
+        /// <param name="request">请求实体</param>
+        /// <returns></returns>
+        public async Task<FacturyExamDeleteResult> FacturyExamDeleteAsync(FacturyExamDeleteRequest request)
+        {
+            var userCode = await GetClientIdByTokenAsync(request.Token);
+            var userInfo = await _userDBService.GetUserDetailAsync(new GetUserDBRequest
+            {
+                Code = userCode,
+            });
+            if (userInfo == null || string.IsNullOrWhiteSpace(userInfo.FacturyUserCode) || _jingQiApiHelper == null)
+            {
+                // 不推送晶奇系统
+                ThrowRpcException((int)CustomerRpcCode.JingQiNotRequired, "JingQiNotRequired", "");
+            }
+            else
+            {
+                var facturyUser = await _vitalFacturyUserDBService.GetFacturyUserDBAsync(new GetFacturyUserDBRequest
+                {
+                    Code = userInfo.FacturyUserCode,
+                });
+                var facturyOrg = await _vitalFacturyUserDBService.GetFacturyUserDBAsync(new GetFacturyUserDBRequest
+                {
+                    Code = facturyUser.FatherCode,
+                });
+                if (facturyUser == null || string.IsNullOrWhiteSpace(facturyUser.FacturyCode)
+                    || facturyOrg == null || string.IsNullOrWhiteSpace(facturyOrg.FacturyCode))
+                {
+                    // 不推送晶奇系统
+                    ThrowRpcException((int)CustomerRpcCode.JingQiNotRequired, "JingQiNotRequired", "");
+                }
+                else
+                {
+                    var jingQiReq = new Factury.JingQiExamDeleteRequest
+                    {
+                        phyid = request.PhyId,
+                    };
+                    var jingQiRes = await _jingQiApiHelper.ExamDeleteAsync(jingQiReq, facturyOrg.FacturyData);
+                    await _vitalFacturyPostHistoryDBService.CreateFacturyPostHistoryDBAsync(new CreateFacturyPostHistoryDBRequest
+                    {
+                        ApiType = "ExamDeleteAsync",
+                        FacturyUrl = _jingQiApiHelper.DeleteRegisterUrl,
+                        IDCardNo = request.Identity,
+                        PatientName = request.PatientName,
+                        Status = jingQiRes.status == "0" ? 2 : 3,
+                        PostTime = DateTime.UtcNow,
+                        Headers = facturyOrg.FacturyData,
+                        Content = JsonConvert.SerializeObject(jingQiReq),
+                        Result = JsonConvert.SerializeObject(jingQiRes),
+                    });
+                    return new FacturyExamDeleteResult
+                    {
+                        Status = jingQiRes.status,
+                        ErroMsg = jingQiRes.ErroMsg,
+                    };
+                }
+
+            }
+            return null;
+        }
     }
 }