using CZFW.Core; using CZFW.Core.Security; using CZFW.Framework.Model; using CZKJ.GBRS2.Interface; using CZKJ.GBRS2.Model; using CZKJ.GBRS2.ViewModel; using Microsoft.EntityFrameworkCore; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Globalization; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Linq; namespace CZKJ.GBRS2.Logic { public class CustomerQueryLogic : ICustomerQuery { CZDbContext dbContext = CZHttpContext.ServiceProvider.GetService(typeof(CZDbContext)) as CZDbContext; public async Task GetHuaWeiToken(string contNo) { string getToeknUrl = $"{ConfigHelper.GetValue("HuaWei:Url")}/apply/token?appId={ConfigHelper.GetValue("HuaWei:AppId")}&appKey={ConfigHelper.GetValue("HuaWei:AppKey")}"; var responseString = await HttpHelper.HttpPostAsync(getToeknUrl); SentParams para = new SentParams(); TransData model = new TransData(); model.ContentData = new ContentData { BusinessNo = contNo, BusinessType = "1", PrintType = "1" }; model.HeadData = new HeadData { REQ_APP_ID = "2", RESP_APP_ID = "1", ID = Utility.GetUnixTimeTick().ToString() /*configuration.GetValue("TransId")*/, TRANS_ID = "QRY033", TRANS_DATE = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff", new CultureInfo("en-US")) }; para.TransData = model; string sign = DesEncrypt.JavaMD5(JsonConvert.SerializeObject(para) + ConfigHelper.GetValue("CoreQuery:Key")); string url = $"http://{ConfigHelper.GetValue("CoreQuery:IP")}/officialWebsiteHttpServer?sign=" + sign; var res = await HttpHelper.HttpPost2(url, JsonConvert.SerializeObject(para)); var jobJect = JObject.Parse(res)["TransData"]["ContentData"]; if (jobJect == null) { return ""; } DownLoadPolicy downLoadPolicy = JsonConvert.DeserializeObject(jobJect.ToString()); CoreHuaWeiFile coreFileInfo = new CoreHuaWeiFile(); HuaWeiTokenModel toekenModel = JsonConvert.DeserializeObject(responseString); string getDownLoadUrl = $"{ConfigHelper.GetValue("HuaWei:Url")}/apply/download?objectId={downLoadPolicy.EleDownloadObjectId}&token={toekenModel.Data.Token}"; var downLoadReponse = await HttpHelper.HttpPostAsync(getDownLoadUrl); return downLoadReponse; } /// /// 客户号获取名下保单列表 /// /// /// /// public async Task GetListByUserId(string userId, string cutomerType = "0") { SentParams para = new SentParams(); TransData model = new TransData(); //CutomerNo用户号,CustomerType:用户类型 model.ContentData = new ContentData { CustomerNo = userId, CustomerType = cutomerType }; model.HeadData = new HeadData { REQ_APP_ID = "2", RESP_APP_ID = "1", ID = Utility.GetUnixTimeTick().ToString() /*configuration.GetValue("TransId")*/, TRANS_ID = "QRY003", TRANS_DATE = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff", new CultureInfo("en-US")) }; para.TransData = model; string sign = DesEncrypt.JavaMD5(JsonConvert.SerializeObject(para) + ConfigHelper.GetValue("CoreQuery:Key")); string url = $"http://{ConfigHelper.GetValue("CoreQuery:IP")}/officialWebsiteHttpServer?sign=" + sign; var res = await HttpHelper.HttpPost2(url, JsonConvert.SerializeObject(para)); SentParams resultPara = JsonConvert.DeserializeObject(res); if (resultPara.TransData.HeadData.ERR_MEASSGE != "交易成功") { return null; } return res; } /// /// 保单号查询保单信息 /// /// /// public async Task GetPolicyModel(string ContNo) { InsurancePolicyModel viewModel = new InsurancePolicyModel(); SentParams para = new SentParams(); TransData model = new TransData(); model.ContentData = new ContentData { ContNo = ContNo }; model.HeadData = new HeadData { REQ_APP_ID = "2", RESP_APP_ID = "1", ID = Utility.GetUnixTimeTick().ToString() /*configuration.GetValue("TransId")*/, TRANS_ID = "QRY004", TRANS_DATE = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff", new CultureInfo("en-US")) }; para.TransData = model; string sign = DesEncrypt.JavaMD5(JsonConvert.SerializeObject(para) + ConfigHelper.GetValue("CoreQuery:Key")); string url = $"http://{ConfigHelper.GetValue("CoreQuery:IP")}/officialWebsiteHttpServer?sign=" + sign; var res = await HttpHelper.HttpPost2(url, JsonConvert.SerializeObject(para)); var jobJect = JObject.Parse(res)["TransData"]["ContentData"]; if (jobJect != null) { viewModel = JsonConvert.DeserializeObject(jobJect.ToString()); } return viewModel; } /// /// 保单号查询险种 /// 已停用 /// /// /// /// public async Task GetPolNo(string ContNo) { SentParams para = new SentParams(); TransData model = new TransData(); model.ContentData = new ContentData { CustomerNo = ConfigHelper.GetValue("CoreQuery:CustomerNo"), CustomerType = ConfigHelper.GetValue("CoreQuery:CustomerType") }; model.HeadData = new HeadData { REQ_APP_ID = "2", RESP_APP_ID = "1", ID = Utility.GetUnixTimeTick().ToString() /*configuration.GetValue("TransId")*/, TRANS_ID = "QRY003", TRANS_DATE = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff", new CultureInfo("en-US")) }; para.TransData = model; string sign = DesEncrypt.JavaMD5(JsonConvert.SerializeObject(para) + ConfigHelper.GetValue("CoreQuery:Key")); string url = $"http://10.237.55.185:9002/officialWebsiteHttpServer?sign=" + sign; var res = await HttpHelper.HttpPost2(url, JsonConvert.SerializeObject(para)); return res; } /// /// 获取保单概要列表用于用户登录进来时展示 /// /// /// public async Task> GetReportNoList(List list) { List result = new List(); List model = new List(); foreach (var element in list) { ReportNoListModel entity = new ReportNoListModel(); var queryResult = await GetPolicyModel(element); entity.ContNo = element; entity.StartTime =Convert.ToDateTime( queryResult.CValiDate); //DateTime.ParseExact(queryResult.CValiDate, "ddd MMM dd HH:mm:ss CST yyyy", new CultureInfo("en-us")).ToString("yyyy-MM-dd"); switch (queryResult.AppFlag) { case "0": entity.State = "投保中"; break; case "1": entity.State = "有效"; break; case "4": entity.State = "终止"; break; case "5": entity.State = "中止"; break; case "9": entity.State = "续期中"; break; } model.Add(entity); } foreach (var item in model.OrderByDescending(x=>x.StartTime)) { ReportNoList entity = new ReportNoList(); entity.StartTime = item.StartTime.ToString("yyyy-MM-dd"); entity.State = item.State; entity.ContNo = item.ContNo; result.Add(entity); } return result; } /// /// 泛型查询 /// /// /// /// /// public async Task HttpMenth(string contNo, string transId) { SentParams para = new SentParams(); TransData model = new TransData(); if (transId == "QRY006") { model.ContentData = new ContentData { PolNo = contNo }; } else { model.ContentData = new ContentData { ContNo = contNo }; } model.HeadData = new HeadData { REQ_APP_ID = "2", RESP_APP_ID = "1", ID = Utility.GetUnixTimeTick().ToString() /*configuration.GetValue("TransId")*/, TRANS_ID = transId, TRANS_DATE = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff", new CultureInfo("en-US")) }; para.TransData = model; string sign = DesEncrypt.JavaMD5(JsonConvert.SerializeObject(para) + ConfigHelper.GetValue("CoreQuery:Key")); string url = $"http://{ConfigHelper.GetValue("CoreQuery:IP")}/officialWebsiteHttpServer?sign=" + sign; var res = await HttpHelper.HttpPost2(url, JsonConvert.SerializeObject(para)); JToken jobJect = null; //Object thisLock = new Object(); if (transId == "QRY004" || transId == "QRY007" || transId == "QRY006") { jobJect = JObject.Parse(res)["TransData"]["ContentData"]; //if (transId == "QRY004") //{ // lock (thisLock) // dbContext.Database.ExecuteSqlCommandAsync($"INSERT INTO insurancepolicy(`InsurancePolicyJson`)VALUES({res})"); //} //else if (transId == "QRY007") //{ // lock (thisLock) // dbContext.Database.ExecuteSqlCommandAsync($"INSERT INTO policyholder(`PolicyHolderJson`)VALUES({res})"); //} //else if (transId == "QRY006") //{ // lock (thisLock) // dbContext.Database.ExecuteSqlCommandAsync($"INSERT INTO inquiryinsurancepolicy(`InquiryInsurancePolicyJson`)VALUES({res})"); //} } else if (transId == "QRY008") { jobJect = JObject.Parse(res)["TransData"]["ContentData"]["InsuredInfos"]; //lock (thisLock) // dbContext.Database.ExecuteSqlCommandAsync($"INSERT INTO policyinsured(`PolicyInsuredJson`)VALUES({res})"); } else if (transId == "QRY005") { try { jobJect = JObject.Parse(res)["TransData"]["ContentData"]["PolNos"]; } catch (Exception ex) { jobJect = null; } } else { jobJect = JObject.Parse(res)["TransData"]["ContentData"]["BnfInfos"]; //lock (thisLock) // dbContext.Database.ExecuteSqlCommandAsync($"INSERT INTO policybeneficiary(`PolicyBeneficiaryJson`)VALUES({res})"); } if (jobJect != null) { string str = jobJect.ToString(); T viewModel = JsonConvert.DeserializeObject(jobJect.ToString()); return viewModel; } return default(T); } /// /// 保单号查询保单详情 /// /// /// public async Task QueryReprot(string contNo) { if (string.IsNullOrWhiteSpace(contNo)) { return null; } ReportQueryViewModel resultViewModel = new ReportQueryViewModel(); var res004 = HttpMenth(contNo, "QRY004"); var res009 = HttpMenth>(contNo, "QRY009"); var res007 = HttpMenth(contNo, "QRY007"); var res008 = HttpMenth>(contNo, "QRY008"); var res005 = HttpMenth>(contNo, "QRY005"); resultViewModel.InsurancePolicyModel = await res004; if (resultViewModel.InsurancePolicyModel == null) { return resultViewModel; } resultViewModel.PolicyBeneficiaryModel = await res009; resultViewModel.PolicyHolderModel = await res007; resultViewModel.PolicyInsuredModel = await res008; var PolNos = await res005; if (PolNos != null) { resultViewModel.PolNo = PolNos; foreach (var element in resultViewModel.PolNo) { var entity = await HttpMenth(element.PolNo, "QRY006"); entity.AddFeeRate = ChangeDataToD(entity.AddFeeRate); if (entity.RiskCode == "0012" || entity.RiskCode == "0017") { entity.IsEY = true; } resultViewModel.inquiryInsurancePolicyModels.Add(entity); } } return resultViewModel; } public async Task Transformation(string contNo) { var data = await QueryReprot(contNo); if (data.InsurancePolicyModel == null) { return data; } foreach (var item in data.inquiryInsurancePolicyModels) { if (!string.IsNullOrEmpty(item.CValiDate)) { item.CValiDate = item.CValiDate; //DateTime.ParseExact(item.CValiDate, "ddd MMM dd HH:mm:ss CST yyyy", new CultureInfo("en-us")).ToString("yyyy-MM-dd"); } else { item.CValiDate = ""; } if (item.MainPolNo == item.PolNo) { data.MianPolicyName = item.RiskName; if (item.RiskCode == "0012" || item.RiskCode == "0017") { data.IsEY = true; } } } //保单信息生效日期转换 if (!string.IsNullOrEmpty(data.InsurancePolicyModel.CValiDate)) { data.InsurancePolicyModel.CValiDate = data.InsurancePolicyModel.CValiDate;//DateTime.ParseExact(data.InsurancePolicyModel.CValiDate, "ddd MMM dd HH:mm:ss CST yyyy", new CultureInfo("en-us")).ToString("yyyy-MM-dd"); } else { data.InsurancePolicyModel.CValiDate = ""; } //保单回执 if (string.IsNullOrEmpty(data.InsurancePolicyModel.CustomGetPolDate)) { data.InsurancePolicyModel.CustomGetPolDate = ""; } ///投保人生日转换 /// if (!string.IsNullOrEmpty(data.PolicyHolderModel.AppntBirthday)) { data.PolicyHolderModel.AppntBirthday = data.PolicyHolderModel.AppntBirthday;//DateTime.ParseExact(data.PolicyHolderModel.AppntBirthday, "ddd MMM dd HH:mm:ss CST yyyy", new CultureInfo("en-us")).ToString("yyyy-MM-dd"); } else { data.PolicyHolderModel.AppntBirthday = ""; } switch (data.PolicyHolderModel.AppntSex) { case "0": data.PolicyHolderModel.AppntSex = "男"; break; case "1": data.PolicyHolderModel.AppntSex = "女"; break; case "2": data.PolicyHolderModel.AppntSex = "不祥"; break; } switch (data.InsurancePolicyModel.InHesitationFlag) { case "0": data.InsurancePolicyModel.InHesitationFlag = "犹豫期内"; break; case "1": data.InsurancePolicyModel.InHesitationFlag = "犹豫期外"; break; } switch (data.PolicyHolderModel.IDType) { case "0": data.PolicyHolderModel.IDType = "身份证"; break; case "1": data.PolicyHolderModel.IDType = "护照"; break; case "2": data.PolicyHolderModel.IDType = "军人身份证"; break; case "3": data.PolicyHolderModel.IDType = "户口本"; break; case "4": data.PolicyHolderModel.IDType = "通行证"; break; case "5": data.PolicyHolderModel.IDType = "出生证明"; break; case "6": data.PolicyHolderModel.IDType = "外国人永久居留身份证"; break; } if (!string.IsNullOrEmpty(data.PolicyHolderModel.IDNo) && data.PolicyHolderModel.IDNo.Length == 18) { data.PolicyHolderModel.IDNo = data.PolicyHolderModel.IDNo.Substring(0, 6) + "********" + data.PolicyHolderModel.IDNo.Substring(14, 4); } else { data.PolicyHolderModel.IDNo = ""; } if (!string.IsNullOrEmpty(data.PolicyHolderModel.Mobile)) { data.PolicyHolderModel.Mobile = data.PolicyHolderModel.Mobile.Substring(0, 3) + "****" + data.PolicyHolderModel.Mobile.Substring(7, 4); } else { data.PolicyHolderModel.Mobile = ""; } foreach (var item in data.PolicyInsuredModel) { if (!string.IsNullOrEmpty(item.IDNo) && item.IDNo.Length == 18) { item.IDNo = item.IDNo.Substring(0, 6) + "********" + item.IDNo.Substring(14, 4); } else { item.IDNo = ""; } if (!string.IsNullOrEmpty(item.Mobile)) { item.Mobile = item.Mobile.Substring(0, 3) + "****" + item.Mobile.Substring(7, 4); } else { item.Mobile = ""; } //被保人生日转换 if (!string.IsNullOrEmpty(item.Birthday)) { item.Birthday = item.Birthday;//DateTime.ParseExact(item.Birthday, "ddd MMM dd HH:mm:ss CST yyyy", new CultureInfo("en-us")).ToString("yyyy-MM-dd"); } else { item.Birthday = ""; } switch (item.Sex) { case "0": item.Sex = "男"; break; case "1": item.Sex = "女"; break; case "2": item.Sex = "不祥"; break; } switch (item.IDType) { case "0": item.IDType = "身份证"; break; case "1": item.IDType = "护照"; break; case "2": item.IDType = "军人身份证"; break; case "3": item.IDType = "户口本"; break; case "4": item.IDType = "通行证"; break; case "5": item.IDType = "出生证明"; break; case "6": item.IDType = "外国人永久居留身份证"; break; } switch (item.RelationToAppnt) { case "00": item.RelationToAppnt = "本人"; break; case "01": item.RelationToAppnt = "配偶"; break; case "02": item.RelationToAppnt = "子女"; break; case "03": item.RelationToAppnt = "父母"; break; case "04": item.RelationToAppnt = "亲属"; break; case "05": item.RelationToAppnt = "雇佣关系"; break; } } foreach (var item in data.PolicyBeneficiaryModel) { if (!string.IsNullOrEmpty(item.IDNo) && item.IDNo.Length == 18) { item.IDNo = item.IDNo.Substring(0, 6) + "********" + item.IDNo.Substring(14, 4); } else { item.IDNo = ""; } if (!string.IsNullOrEmpty(item.Mobile)) { item.Mobile = item.Mobile.Substring(0, 3) + "****" + item.Mobile.Substring(7, 4); } else { item.Mobile = ""; } //受益人生日转换 if (!string.IsNullOrEmpty(item.Birthday)) { item.Birthday = item.Birthday;// DateTime.ParseExact(item.Birthday, "ddd MMM dd HH:mm:ss CST yyyy", new CultureInfo("en-us")).ToString("yyyy-MM-dd"); } else { item.Birthday = ""; } switch (item.Sex) { case "0": item.Sex = "男"; break; case "1": item.Sex = "女"; break; case "2": item.Sex = "不祥"; break; } switch (item.IDType) { case "0": item.IDType = "身份证"; break; case "1": item.IDType = "护照"; break; case "2": item.IDType = "军人身份证"; break; case "3": item.IDType = "户口本"; break; case "4": item.IDType = "通行证"; break; case "5": item.IDType = "出生证明"; break; case "6": item.IDType = "外国人永久居留身份证"; break; } switch (item.RelationToInsured) { case "00": item.RelationToInsured = "本人"; break; case "01": item.RelationToInsured = "配偶"; break; case "02": item.RelationToInsured = "子女"; break; case "03": item.RelationToInsured = "父母"; break; case "04": item.RelationToInsured = "亲属"; break; case "05": item.RelationToInsured = "雇佣关系"; break; } } return data; } private string ChangeDataToD(string strData) { Decimal dData = 0.0M; if (strData.Contains("E")) { dData = Convert.ToDecimal(Decimal.Parse(strData.ToString(), System.Globalization.NumberStyles.Float)); } return dData.ToString(); } #region 旧版本 /// /// 根据保单号查询保单详情 /// /// /// /// //public ReportQueryViewModel QueryReprot(string ContNo) //{ // if (string.IsNullOrWhiteSpace(ContNo)) // { // return null; // } // ReportQueryViewModel resultViewModel = new ReportQueryViewModel(); // HttpMenth(ContNo, "QRY004"); // #region 查询保单信息 // SentParams para = new SentParams(); // TransData model = new TransData(); // model.ContentData = new ContentData { ContNo = ContNo}; // model.HeadData = new HeadData { REQ_APP_ID = "2", RESP_APP_ID = "1", ID = Utility.GetUnixTimeTick().ToString() /*configuration.GetValue("TransId")*/, TRANS_ID = "QRY004", TRANS_DATE = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff", new CultureInfo("en-US")) }; // para.TransData = model; // string sign = DesEncrypt.JavaMD5(JsonConvert.SerializeObject(para) + ConfigHelper.GetValue("CoreQuery:Key")); // string url = $"http://{ConfigHelper.GetValue("CoreQuery:IP")}/officialWebsiteHttpServer?sign=" + sign; // var res = HttpHelper.HttpPost2(url, JsonConvert.SerializeObject(para)); // resultViewModel.InsurancePolicyModel = JsonConvert.DeserializeObject(res); // #endregion // #region 查询受益人信息 // SentParams para1 = new SentParams(); // TransData model1 = new TransData(); // model.ContentData = new ContentData { ContNo = ContNo }; // model.HeadData = new HeadData { REQ_APP_ID = "2", RESP_APP_ID = "1", ID = Utility.GetUnixTimeTick().ToString() /*configuration.GetValue("TransId")*/, TRANS_ID = "QRY009", TRANS_DATE = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff", new CultureInfo("en-US")) }; // para.TransData = model; // string sign1 = DesEncrypt.JavaMD5(JsonConvert.SerializeObject(para) + ConfigHelper.GetValue("CoreQuery:Key")); // string url1 = $"http://{ConfigHelper.GetValue("CoreQuery:IP")}/officialWebsiteHttpServer?sign=" + sign; // var res1 = HttpHelper.HttpPost2(url, JsonConvert.SerializeObject(para)); // resultViewModel.PolicyBeneficiaryModel = JsonConvert.DeserializeObject>(res1); // #endregion // #region 查询投保人信息 // SentParams para2 = new SentParams(); // TransData model2 = new TransData(); // model.ContentData = new ContentData { ContNo = ContNo }; // model.HeadData = new HeadData { REQ_APP_ID = "2", RESP_APP_ID = "1", ID = Utility.GetUnixTimeTick().ToString() /*configuration.GetValue("TransId")*/, TRANS_ID = "QRY007", TRANS_DATE = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff", new CultureInfo("en-US")) }; // para.TransData = model; // string sign2 = DesEncrypt.JavaMD5(JsonConvert.SerializeObject(para) + ConfigHelper.GetValue("CoreQuery:Key")); // string url2 = $"http://{ConfigHelper.GetValue("CoreQuery:IP")}/officialWebsiteHttpServer?sign=" + sign; // var res2 = HttpHelper.HttpPost2(url, JsonConvert.SerializeObject(para)); // resultViewModel.PolicyHolderModel = JsonConvert.DeserializeObject< List>(res2); // #endregion // #region 查询被保人 // SentParams para3 = new SentParams(); // TransData model3 = new TransData(); // model.ContentData = new ContentData { ContNo = ContNo }; // model.HeadData = new HeadData { REQ_APP_ID = "2", RESP_APP_ID = "1", ID = Utility.GetUnixTimeTick().ToString() /*configuration.GetValue("TransId")*/, TRANS_ID = "QRY008", TRANS_DATE = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff", new CultureInfo("en-US")) }; // para.TransData = model; // string sign3 = DesEncrypt.JavaMD5(JsonConvert.SerializeObject(para) + ConfigHelper.GetValue("CoreQuery:Key")); // string url3 = $"http://{ConfigHelper.GetValue("CoreQuery:IP")}/officialWebsiteHttpServer?sign=" + sign; // var res3 = HttpHelper.HttpPost2(url, JsonConvert.SerializeObject(para)); // resultViewModel.PolicyInsuredModel = JsonConvert.DeserializeObject< List>(res3); // #endregion // #region 根据保单号查询险种 // SentParams para4 = new SentParams(); // TransData model4 = new TransData(); // model.ContentData = new ContentData { ContNo = ContNo }; // model.HeadData = new HeadData { REQ_APP_ID = "2", RESP_APP_ID = "1", ID = Utility.GetUnixTimeTick().ToString() /*configuration.GetValue("TransId")*/, TRANS_ID = "QRY009", TRANS_DATE = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff", new CultureInfo("en-US")) }; // para.TransData = model; // string sign4 = DesEncrypt.JavaMD5(JsonConvert.SerializeObject(para) + ConfigHelper.GetValue("CoreQuery:Key")); // string url4 = $"http://{ConfigHelper.GetValue("CoreQuery:IP")}/officialWebsiteHttpServer?sign=" + sign; // var res4 = HttpHelper.HttpPost2(url, JsonConvert.SerializeObject(para)); // resultViewModel.PolNo = JsonConvert.DeserializeObject>(res4); // #endregion // return resultViewModel; //} #endregion } }