| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Web.Script.Serialization;
- namespace DRG.DRGInterfaceClient
- {
- /// <summary>医疗机构信息项(来自 01010064)。</summary>
- public class HospitalInfoItem
- {
- public string id { get; set; }
- public string hospCode { get; set; }
- /// <summary>医保机构编码(OrganizationCode),用于 session.hospYBCode 与 --sync 匹配。</summary>
- public string code { get; set; }
- public string descripts { get; set; }
- public string MedinsLv { get; set; }
- internal static object Parse(Dictionary<string, object> d)
- {
- throw new NotImplementedException();
- }
- }
- /// <summary>同步配置(来自 02010079)。</summary>
- public class SyncConfig
- {
- public string syncType { get; set; }
- public string frequency { get; set; }
- public string scheduledTime { get; set; }
- public int lookbackDays { get; set; }
- public bool enabled { get; set; }
- public string synFlag { get; set; }
- public string warningFlag { get; set; }
- public string status { get; set; }
- public string errorMessage { get; set; }
- internal static SyncConfig Parse(object p)
- {
- throw new NotImplementedException();
- }
- }
- /// <summary>session 中非机构字段的默认值(来自 appsettings.json)。</summary>
- public class SessionDefaults
- {
- public string userID { get; set; }
- public string userCode { get; set; }
- public string userName { get; set; }
- public string locID { get; set; }
- public string locDesc { get; set; }
- public string groupID { get; set; }
- public string groupDesc { get; set; }
- public string sessionID { get; set; }
- public string userYBCode { get; set; }
- public string provID { get; set; }
- public string cityID { get; set; }
- public string areaCode { get; set; }
- public string path { get; set; }
- public int langID { get; set; }
- public string langDesc { get; set; }
- public string changeFlag { get; set; }
- public string changeDesc { get; set; }
- public string lastLoginDate { get; set; }
- public string lastLoginTime { get; set; }
- public string directorAuth { get; set; }
- public string defaultMenuType { get; set; }
- public string titleDesc { get; set; }
- public string errorMessageTime { get; set; }
- public string language { get; set; }
- public int messageTime { get; set; }
- }
- public class AppConfig
- {
- public string Endpoint { get; set; }
- public string AuthToken { get; set; }
- /// <summary>已勾选/定时要同步的医疗机构 code(医保编码)列表,支持多机构。</summary>
- public List<string> ScheduledHospCodes { get; set; }
- /// <summary>已废弃:旧版单机构定时字段,仅用于加载旧配置时迁移到 ScheduledHospCodes。</summary>
- public string ScheduledHospCode { get; set; }
- public string TaskName { get; set; }
- public int MaxLogSizeMB { get; set; }
- public int FullSyncStartDays { get; set; }
- public SessionDefaults SessionDefaults { get; set; }
- }
- /// <summary>appsettings.json 加载与运行时单例。</summary>
- public static class Config
- {
- private static AppConfig _current;
- private static readonly string ConfigPath =
- Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "appsettings.json");
- public static AppConfig Current
- {
- get { if (_current == null) _current = Load(); return _current; }
- }
- public static AppConfig Load()
- {
- // 先置默认,避免加载异常时 Logger -> Config.Current 产生重入递归
- if (_current == null) _current = Default();
- try
- {
- if (File.Exists(ConfigPath))
- {
- string json = File.ReadAllText(ConfigPath);
- var cfg = new JavaScriptSerializer().Deserialize<AppConfig>(json);
- if (cfg != null)
- {
- if (cfg.SessionDefaults == null) cfg.SessionDefaults = new SessionDefaults();
- if (cfg.ScheduledHospCodes == null) cfg.ScheduledHospCodes = new List<string>();
- // 旧版单机构配置迁移:把 ScheduledHospCode 并入 ScheduledHospCodes
- if (!string.IsNullOrWhiteSpace(cfg.ScheduledHospCode)
- && !cfg.ScheduledHospCodes.Contains(cfg.ScheduledHospCode, StringComparer.OrdinalIgnoreCase))
- cfg.ScheduledHospCodes.Add(cfg.ScheduledHospCode);
- _current = cfg;
- }
- }
- }
- catch (Exception ex)
- {
- Logger.Error("加载 appsettings.json 失败,使用默认值", ex);
- }
- return _current;
- }
- public static AppConfig Default()
- {
- return new AppConfig
- {
- Endpoint = "http://127.0.0.1:52773/csp/drg/sysInternalMutiple",
- AuthToken = "X1NZU1RFTTpwcnlrQDIwMjA=",
- ScheduledHospCodes = new List<string>(),
- TaskName = "DRGInterfaceClientSync",
- MaxLogSizeMB = 5,
- FullSyncStartDays = 365,
- SessionDefaults = new SessionDefaults
- {
- userID = "158",
- userCode = "admin",
- userName = "admin",
- locID = "1",
- locDesc = "DRG平台",
- groupID = "1",
- groupDesc = "管理员",
- sessionID = "",
- userYBCode = "",
- provID = "12",
- cityID = "98",
- areaCode = "340100",
- path = "",
- langID = 1,
- langDesc = "简体中文",
- changeFlag = "N",
- changeDesc = "",
- lastLoginDate = "",
- lastLoginTime = "",
- directorAuth = "N",
- defaultMenuType = "",
- titleDesc = "",
- errorMessageTime = "",
- language = "CN",
- messageTime = 1
- }
- };
- }
- public static void Save()
- {
- try
- {
- var json = new JavaScriptSerializer().Serialize(_current);
- File.WriteAllText(ConfigPath, json);
- }
- catch (Exception ex)
- {
- Logger.Error("保存 appsettings.json 失败", ex);
- }
- }
- }
- }
|