using FastReport.Export.Hpgl.Commands; using Newtonsoft.Json.Linq; using PTMedicalInsurance.Business; using PTMedicalInsurance.Helper; using PTMedicalInsurance.Variables; using Sunny.UI; using System; using System.Collections.Generic; using System.Linq; using System.Runtime.ConstrainedExecution; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace PTMedicalInsurance.Forms.BasicDatas.services { public class DirectoryDownloadLocalExtService { CenterBusiness cBus = new CenterBusiness(); HisMainBusiness hBus = new HisMainBusiness(); HisIrisServices hIS = new HisIrisServices(); MIIrisServices mIS = new MIIrisServices(); InvokeHelper invoker = new InvokeHelper(); private ProgressWrapper _dataLoader; public delegate JObject GetImportInput(JObject joInput); public delegate JObject ApplyToIris(string code, JArray jaParam); private Dictionary downlaodTypeMap = new Dictionary { { DownloadType.None,""}, { DownloadType.Directory,"7043"}, { DownloadType.LimitPrice,"7044"}, { DownloadType.SelfRatio,"7045"} }; #region 目录下载 /// /// 单次下载具体实现 /// /// /// /// public int SignleDownload(DataLoaderContext context, out string err) { err = "下载完成"; object[] args = context.args; DataDownloadContext dataDownloadContext = (DataDownloadContext)args[0]; //设置最大值 if (context.setProgressMaximum != null) { context.setProgressMaximum(dataDownloadContext.pageSize); } JObject joData = new JObject(); joData.Add("id", dataDownloadContext.ver); joData.Add("fixmedinsCode",Global.inf.hospitalNO); string trade = downlaodTypeMap.GetValue(dataDownloadContext.downloadType); JObject joRtn = invoker.invokeCenterService((TradeEnum)Enum.Parse(typeof(TradeEnum),trade), new JObject { ["data"] = joData }); if (JsonHelper.parseCenterRtnValue(joRtn, out err) != 0) { return -1; } dataDownloadContext.totalCount = int.Parse(joRtn["output"]["data"]["recordCounts"].ToString()); dataDownloadContext.pageNum = int.Parse(joRtn["output"]["data"]["pageNum"].ToString()); dataDownloadContext.totalPages = int.Parse(joRtn["output"]["data"]["pages"].ToString()); string header = $"本次下载总条数【{dataDownloadContext.totalCount}】,总页数【{dataDownloadContext.totalPages}】,当前下载页数【{dataDownloadContext.pageNum}】"; if (context.setProgressHeaderText != null) { context.setProgressHeaderText(dataDownloadContext.progressBarStyle, header, dataDownloadContext.speed); } //数组传递,导入IRIS JArray ja = JArray.FromObject(joRtn["output"]["data"]["data"]); return ImportToIris(context, ja, out err); } /// /// 单次下载封装 /// /// /// public void SignleDownload(string ver, DownloadType downloadType,Form frm) { _dataLoader = new ProgressWrapper(SignleDownload, frm); _dataLoader.SetProgressBar(ProgressBarStyle.Continuous, "正在更新...", 50); DataDownloadContext dataDownloadContext = new DataDownloadContext(); dataDownloadContext.ver = ver; dataDownloadContext.downloadType = downloadType; _dataLoader.Start(new object[] { dataDownloadContext }, (result, errMsg) => { // 在这里处理结果和错误信息 if (result == 0) { MessageBox.Show(errMsg); } else { MessageBox.Show(errMsg); } }); } /// /// 循环下载 /// /// /// /// public int LoopDownload(DataLoaderContext context, out string err) { err = ""; bool bStop = true; object[] args = context.args; DataDownloadContext dataDownloadContext = (DataDownloadContext)args[0]; while (bStop) { if (SignleDownload(context, out err) != 0) { Global.writeLog("err:" + err); bStop = false; return -1; } } return 0; } public void LoopDownload(string ver,DownloadType downloadType, Form frm) { _dataLoader = new ProgressWrapper(LoopDownload, frm); _dataLoader.SetProgressBar(ProgressBarStyle.Continuous, "正在下载...", 50); DataDownloadContext dataDownloadContext = new DataDownloadContext(); dataDownloadContext.ver = ver; dataDownloadContext.downloadType = downloadType; dataDownloadContext.progressBarStyle = ProgressBarStyle.Continuous; dataDownloadContext.header = "正在下载"; dataDownloadContext.speed = 50; _dataLoader.Start(new object[] { dataDownloadContext }, (result, errMsg) => { // 在这里处理结果和错误信息 if (result == 0) { MessageBox.Show(errMsg); } else { MessageBox.Show(errMsg); } }); } #endregion #region 导入iris数据库 /// /// 导入IRIS /// /// /// /// /// private int ImportToIris(DataLoaderContext context, JArray ja, out string err) { JArray jaIrisInput = new JArray(); int num = 0; int errorCount = 0; DataDownloadContext dataDownloadContext = (DataDownloadContext)context.args[0]; GetImportInput getImportInput = null; ApplyToIris applyToIris = null; string code = ""; if (dataDownloadContext.downloadType == DownloadType.Directory) { getImportInput = GetImportInputFrom7043; applyToIris = applyDataToIris; code = "09010035"; } if (dataDownloadContext.downloadType == DownloadType.LimitPrice) { getImportInput = GetImportInputFrom7044; applyToIris = applyDataToIris; code = "09010035"; } if (dataDownloadContext.downloadType == DownloadType.SelfRatio) { getImportInput = GetImportInputFrom7045; applyToIris = applyDataToSelfProper; code = "090100xx"; } err = ""; foreach (JObject jo in ja) { jaIrisInput.Add(getImportInput(jo)); dataDownloadContext.ver = JsonHelper.getDestValue(jo, "id"); num++; if ((num % 50) == 0 || (num == ja.Count)) { JObject joRtn = applyToIris(code, jaIrisInput); if (joRtn["errorCode"].ToString() != "0") { errorCount = errorCount + 1; err = "\r\n" + err + joRtn["errorMessage"].ToString(); } jaIrisInput = new JArray(); } // 检查是否应取消操作 if (context.Worker.CancellationPending) { err = "操作取消!"; return -1; // 或者其他表示取消的返回值 } if (context.reportProgress != null) { context.reportProgress(num); } //下载完成就停止 if (dataDownloadContext.totalCount == 0) { err = "下载完成!"; return -1; // 或者其他表示取消的返回值 } } return 0; } private JObject applyDataToIris(string code, JArray jaParam) { JObject joIn = new JObject(); JObject joRtn = new JObject(); string outParam = ""; try { joIn.Add(new JProperty("params", jaParam)); joIn.Add("code", code); joIn.Add("updateUserID", Global.user.ID); InvokeHelper invoker = new InvokeHelper(); string sInput = joIn.ToString(); joRtn = invoker.invokeInsuService(sInput, "applyDataToIris"); outParam = joRtn.ToString(); return joRtn; } catch (Exception ex) { joRtn = JsonHelper.setExceptionJson(-1, "applyDataToIris", ex.Message); outParam = joRtn.ToString(); return joRtn; } } //插入自付自付比例奥 private JObject applyDataToSelfProper(string code, JArray jaParam) { JObject joIn = new JObject(); JObject joRtn = new JObject(); string outParam = ""; try { //joIn.Add(new JProperty("params", jaParam)); //joIn.Add("code", code); //joIn.Add("updateUserID", Global.user.ID); //InvokeHelper invoker = new InvokeHelper(); //string sInput = joIn.ToString(); //joRtn = invoker.invokeInsuService(sInput, "applyDataToIris"); //outParam = joRtn.ToString(); joRtn.Add("errorCode","-1"); joRtn.Add("errorMessage", "未找到插入自付比例表方法"); return joRtn; } catch (Exception ex) { joRtn = JsonHelper.setExceptionJson(-1, "applyDataToSelfProper", ex.Message); outParam = joRtn.ToString(); return joRtn; } } #endregion #region 获取入参 /// /// 从国家目录类别转换为医保平台自己规定的类型 /// /// /// /// private void GetHisTypeFromListType(string listType, out string hisType, out string hisName) { hisType = hisName = ""; string firstLetter = listType.Substring(0, 1); switch (firstLetter) { case "1": hisType = "1"; hisName = "药品"; break; case "2": hisType = "2"; hisName = "诊疗"; break; case "3": hisType = "3"; hisName = "材料"; break; default: hisType = "2"; hisName = "诊疗"; break; } } /// /// 获取入参 /// /// /// /// private JObject GetImportInputFrom7043(JObject joInput) { dynamic jsonTemp = new JObject(); jsonTemp.ID = ""; jsonTemp.updateUserID = Global.user.ID; jsonTemp.HospitalDr = Global.inf.hospitalDr; jsonTemp.InterfaceDr = Global.inf.interfaceDr; jsonTemp.Code = JsonHelper.getDestValue(joInput, "hilistCode"); jsonTemp.Name = JsonHelper.getDestValue(joInput, "hilistName"); string hisType, hisName; GetHisTypeFromListType(JsonHelper.getDestValue(joInput, "listType"), out hisType, out hisName); jsonTemp.HisType = hisType; jsonTemp.HisTypeName = hisName; jsonTemp.LocateCode = ""; jsonTemp.LocateName = ""; jsonTemp.DosageFormCode = JsonHelper.getDestValue(joInput, "drugDosform"); jsonTemp.DosageFormName = JsonHelper.getDestValue(joInput, "dosformName"); jsonTemp.CategoryCode = JsonHelper.getDestValue(joInput, "medChrgitmType"); jsonTemp.CategoryName = ""; jsonTemp.Specification = JsonHelper.getDestValue(joInput, "regSpec"); jsonTemp.SpecificationCode = ""; jsonTemp.UnitOfPackag = ""; jsonTemp.UnitOfValuation = ""; jsonTemp.StartDate = JsonHelper.getDestValue(joInput, "begnDate"); jsonTemp.EndDate = JsonHelper.getDestValue(joInput, "endDate"); jsonTemp.PinyinSearchCode = JsonHelper.getDestValue(joInput, "pinyin"); jsonTemp.Instructions = JsonHelper.getDestValue(joInput, "lmtUsescp"); jsonTemp.ExceptContent = JsonHelper.getDestValue(joInput, "trtExctCont"); jsonTemp.Connotation = JsonHelper.getDestValue(joInput, "trtItemCont"); jsonTemp.ValidFlag = 1; jsonTemp.Note = JsonHelper.getDestValue(joInput, "memo"); jsonTemp.VersionNO = JsonHelper.getDestValue(joInput, "id"); jsonTemp.VersionName = ""; jsonTemp.UseFlag = 1; jsonTemp.DrugSafetyStandardCode = ""; jsonTemp.ApprovalNO = JsonHelper.getDestValue(joInput, "aprvno"); jsonTemp.SpecialFlag = ""; jsonTemp.LimitFlag = ""; jsonTemp.LimitRange = ""; jsonTemp.UniqueRecordNO = ""; jsonTemp.Manufacturers = JsonHelper.getDestValue(joInput, "prodentpName"); jsonTemp.Company = ""; jsonTemp.MinPackagingQuantity = JsonHelper.getDestValue(joInput, "minPacCnt"); jsonTemp.MinPackagingUnit = JsonHelper.getDestValue(joInput, "minPacunt"); jsonTemp.ChargeItemLevel = JsonHelper.getDestValue(joInput, "chrgitmLv"); jsonTemp.ChargeItemType = JsonHelper.getDestValue(joInput, "medChrgitmType"); jsonTemp.ListType = JsonHelper.getDestValue(joInput, "listType"); return jsonTemp; } private JObject GetImportInputFrom7044(JObject joInput) { dynamic jsonTemp = new JObject(); jsonTemp.ID = ""; jsonTemp.updateUserID = Global.user.ID; jsonTemp.HospitalDr = Global.inf.hospitalDr; jsonTemp.InterfaceDr = Global.inf.interfaceDr; jsonTemp.Code = JsonHelper.getDestValue(joInput, "hilistCode"); jsonTemp.CeilingPrice = JsonHelper.getDestValue(joInput, "hilistPricUplmtAmt"); return jsonTemp; } private JObject GetImportInputFrom7045(JObject joInput) { dynamic jsonTemp = new JObject(); jsonTemp.ID = ""; jsonTemp.updateUserID = Global.user.ID; jsonTemp.HospitalDr = Global.inf.hospitalDr; jsonTemp.InterfaceDr = Global.inf.interfaceDr; jsonTemp.Code = JsonHelper.getDestValue(joInput, "hilistCode"); jsonTemp.SelfPercent = JsonHelper.getDestValue(joInput, "selfpayProp"); return jsonTemp; } #endregion } public class DataDownloadContext { public int totalCount = 0; public int pageNum = 1; public int pageSize = 1000; public int totalPages = 0; public string ver = ""; public ProgressBarStyle progressBarStyle = ProgressBarStyle.Continuous; public string header = ""; public int speed =50; public DownloadType downloadType = DownloadType.None; } public enum DownloadType { None = 0, Directory =1, LimitPrice =2, SelfRatio =3 } }