From e1a088bbb6f78ee9566597588a4659f0a3395d55 Mon Sep 17 00:00:00 2001 From: falcon <9504402@qq.com> Date: Mon, 1 Apr 2019 14:45:19 +0800 Subject: [PATCH] =?UTF-8?q?(#16)=E6=B7=BB=E5=8A=A0=E5=8C=BB=E7=96=97?= =?UTF-8?q?=E6=9C=BA=E6=9E=84=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WebSiteCode/Cmdjy/Cmdjy/Bll/Cache.cs | 20 +++++ .../Bll/DataQuery/HospitalInfoDataQuery.cs | 78 +++++++++++++++++++ .../Cmdjy/Cmdjy/Bll/DataQuery/IDataQuery.cs | 74 ++++++++++++++++++ WebSiteCode/Cmdjy/Cmdjy/Cmdjy.csproj | 4 + WebSiteCode/Cmdjy/Cmdjy/Content/Site.css | 8 ++ .../Cmdjy/Controllers/HisInfoController.cs | 3 + .../Controllers/HospitalInfoController.cs | 27 +++++++ .../Cmdjy/Cmdjy/Dal/Tables/HospitalInfo.cs | 28 ++++++- WebSiteCode/Cmdjy/Cmdjy/IOCFactory.cs | 6 ++ WebSiteCode/Cmdjy/Cmdjy/Web.config | 4 +- 10 files changed, 246 insertions(+), 6 deletions(-) create mode 100644 WebSiteCode/Cmdjy/Cmdjy/Bll/DataQuery/HospitalInfoDataQuery.cs create mode 100644 WebSiteCode/Cmdjy/Cmdjy/Bll/DataQuery/IDataQuery.cs create mode 100644 WebSiteCode/Cmdjy/Cmdjy/Controllers/HospitalInfoController.cs diff --git a/WebSiteCode/Cmdjy/Cmdjy/Bll/Cache.cs b/WebSiteCode/Cmdjy/Cmdjy/Bll/Cache.cs index aaca96b..e1494df 100644 --- a/WebSiteCode/Cmdjy/Cmdjy/Bll/Cache.cs +++ b/WebSiteCode/Cmdjy/Cmdjy/Bll/Cache.cs @@ -1,6 +1,8 @@ using System; using Newtonsoft.Json; using StackExchange.Redis; +using CommonClass.Factory; +using Autofac; namespace Cmdjy.Bll { @@ -17,6 +19,14 @@ namespace Cmdjy.Bll } } + public class CacheRegister:IRegister + { + public void Register(ContainerBuilder builder) { + builder.Register(c => new RedisHelper()); + } + + } + public interface ICache { /// @@ -45,6 +55,11 @@ namespace Cmdjy.Bll /// 缓存的数据 /// 缓存时间 void SetData(string key,T obj,TimeSpan timeSpan); + /// + /// 删除数据缓存 + /// + /// 数据的键 + void RemoveData(string key); } /// /// 数据缓存实现类 @@ -98,5 +113,10 @@ namespace Cmdjy.Bll if(value == null) return null; return JsonConvert.DeserializeObject(value); } + + public void RemoveData(string key) { + if(!Usable) return; + this.Database.KeyDelete(key); + } } } \ No newline at end of file diff --git a/WebSiteCode/Cmdjy/Cmdjy/Bll/DataQuery/HospitalInfoDataQuery.cs b/WebSiteCode/Cmdjy/Cmdjy/Bll/DataQuery/HospitalInfoDataQuery.cs new file mode 100644 index 0000000..8a17956 --- /dev/null +++ b/WebSiteCode/Cmdjy/Cmdjy/Bll/DataQuery/HospitalInfoDataQuery.cs @@ -0,0 +1,78 @@ +using System.Collections.Generic; +using System.Data.Entity; +using System.Linq; +using Cmdjy.Dal; +using Cmdjy.Dal.Tables; +using CommonClass.Factory; + +namespace Cmdjy.Bll.DataQuery +{ + /// + /// 医疗机构信息数据查询 + /// + public interface IHospitalInfoDataQuery:IDataQuery { } + + public class HospitalInfoDataQuery:IHospitalInfoDataQuery, IRegisterBaseInterface + { + public DataQueryConfig Config { get; set; } + public ICache Cache { get; set; } + public DjyDbContext Db { get; set; } + + public HospitalInfoDataQuery(DataQueryConfig con,ICache ca,DjyDbContext db) { + this.Config = con; this.Cache = ca; this.Db = db; + } + + public HospitalInfo AddNew(HospitalInfo one) { + this.Db.Entry(one).State = EntityState.Added; + this.Db.SaveChanges(); + this.Cache.SetData(_getKey(one.Id.ToString()),one,Config.CacheTimeSpan); + return one; + } + + public IEnumerable GetAll() { + IEnumerable result = null; + if(this.Config.EnableCache) { + result = this.Cache.GetData>(_getKey()); + } + if(result == null) { + result = GetQuery(this.Db,null).ToList(); + this.Cache.SetData(_getKey(),result); + } + return result; + } + + public HospitalInfo GetOneById(params object[] id) { + HospitalInfo result = null; + if(this.Config.EnableCache) { + result = this.Cache.GetData(_getKey(id[0].ToString())); + } + if(result == null) { + result = this.Db.HospitalInfos.Find(id); + this.Cache.SetData(_getKey(id[0].ToString()),result); + } + return result; + } + + public IQueryable GetQuery(DjyDbContext db,DataFilterBase filter) { + return db.HospitalInfos.AsQueryable(); + } + + public HospitalInfo Remove(HospitalInfo one) { + this.Db.Entry(one).State = EntityState.Deleted; + this.Db.SaveChanges(); + this.Cache.RemoveData(_getKey(one.Id.ToString())); + return one; + } + + public HospitalInfo Updata(HospitalInfo one) { + this.Db.Entry(one).State = EntityState.Modified; + this.Db.SaveChanges(); + this.Cache.RemoveData(_getKey(one.Id.ToString())); + this.Cache.SetData(_getKey(one.Id.ToString()),one); + return one; + } + + private string _getKey(string id) => $"HospitalInfo:Id:{id}"; + private string _getKey() => "HospitalInfo:All"; + } +} \ No newline at end of file diff --git a/WebSiteCode/Cmdjy/Cmdjy/Bll/DataQuery/IDataQuery.cs b/WebSiteCode/Cmdjy/Cmdjy/Bll/DataQuery/IDataQuery.cs new file mode 100644 index 0000000..4b25a62 --- /dev/null +++ b/WebSiteCode/Cmdjy/Cmdjy/Bll/DataQuery/IDataQuery.cs @@ -0,0 +1,74 @@ +using System.Collections.Generic; +using System.Linq; +using CommonClass.Factory; +using System; +using Cmdjy.Dal; + +namespace Cmdjy.Bll.DataQuery +{ + /// + /// 业务逻辑层数据查询接口 + /// + public interface IDataQuery + { + /// + /// 查询配置 + /// + DataQueryConfig Config { get; set; } + /// + /// 获取所有数据,可以从缓冲区获取 + /// + /// 数据枚举 + IEnumerable GetAll(); + /// + /// 通过Id获取数据。 + /// + /// 数据的Id + /// 获取到的数据或Null + T GetOneById(params object[] id); + /// + /// 获取数据查询。 + /// + /// 查询筛选器 + /// 数据查询 + IQueryable GetQuery(DjyDbContext db,DataFilterBase filter); + /// + /// 添加新数据 + /// + /// 要添加的数据 + /// 添加后的数据 + T AddNew(T one); + /// + /// 删除数据 + /// + /// 要删除的数据 + /// 删除后的数据 + T Remove(T one); + /// + /// 要更新的数据 + /// + /// 要更新的数据。 + /// 更新后的数据 + T Updata(T one); + } + /// + /// 数据筛选器基类 + /// + public class DataFilterBase + { + } + /// + /// 数据查询配置 + /// + public class DataQueryConfig:IRegisterSelf + { + /// + /// 是否允许使用缓冲 + /// + public bool EnableCache { get; set; } = true; + /// + /// 缓冲过期时间 + /// + public TimeSpan CacheTimeSpan { get; set; } = WebSettings.DefaultCacheTimeSpan; + } +} diff --git a/WebSiteCode/Cmdjy/Cmdjy/Cmdjy.csproj b/WebSiteCode/Cmdjy/Cmdjy/Cmdjy.csproj index c60b958..7be2b57 100644 --- a/WebSiteCode/Cmdjy/Cmdjy/Cmdjy.csproj +++ b/WebSiteCode/Cmdjy/Cmdjy/Cmdjy.csproj @@ -194,12 +194,15 @@ + + + @@ -286,6 +289,7 @@ + diff --git a/WebSiteCode/Cmdjy/Cmdjy/Content/Site.css b/WebSiteCode/Cmdjy/Cmdjy/Content/Site.css index 6429134..ca3314d 100644 --- a/WebSiteCode/Cmdjy/Cmdjy/Content/Site.css +++ b/WebSiteCode/Cmdjy/Cmdjy/Content/Site.css @@ -30,3 +30,11 @@ table { display: inline-block; padding: 3px 5px; } + +pre { + white-space: pre-wrap; + white-space: -moz-pre-wrap; + white-space: -pre-wrap; + white-space: -o-pre-wrap; + word-wrap: break-word; +} diff --git a/WebSiteCode/Cmdjy/Cmdjy/Controllers/HisInfoController.cs b/WebSiteCode/Cmdjy/Cmdjy/Controllers/HisInfoController.cs index 4c6a734..9c88066 100644 --- a/WebSiteCode/Cmdjy/Cmdjy/Controllers/HisInfoController.cs +++ b/WebSiteCode/Cmdjy/Cmdjy/Controllers/HisInfoController.cs @@ -7,6 +7,9 @@ using Cmdjy.Models; namespace Cmdjy.Controllers { + /// + /// 医疗机构处方、药品信息控制器 + /// public class HisInfoController:Controller { /// diff --git a/WebSiteCode/Cmdjy/Cmdjy/Controllers/HospitalInfoController.cs b/WebSiteCode/Cmdjy/Cmdjy/Controllers/HospitalInfoController.cs new file mode 100644 index 0000000..26cc2ca --- /dev/null +++ b/WebSiteCode/Cmdjy/Cmdjy/Controllers/HospitalInfoController.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Mvc; +using Cmdjy.Bll.DataQuery; +using Cmdjy.Dal; + +namespace Cmdjy.Controllers +{ + /// + /// 医疗机构信息控制器 + /// + public class HospitalInfoController:ControllerBase + { + public Lazy HosInfo { get; set; } + + public ActionResult Index() { + return View(); + } + + public ActionResult HospitalList() { + var model = this.HosInfo.Value.GetAll(); + return Json(model,JsonRequestBehavior.AllowGet); + } + } +} \ No newline at end of file diff --git a/WebSiteCode/Cmdjy/Cmdjy/Dal/Tables/HospitalInfo.cs b/WebSiteCode/Cmdjy/Cmdjy/Dal/Tables/HospitalInfo.cs index c14db97..648e428 100644 --- a/WebSiteCode/Cmdjy/Cmdjy/Dal/Tables/HospitalInfo.cs +++ b/WebSiteCode/Cmdjy/Cmdjy/Dal/Tables/HospitalInfo.cs @@ -1,9 +1,6 @@ using System; -using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Web; namespace Cmdjy.Dal.Tables { @@ -24,12 +21,35 @@ namespace Cmdjy.Dal.Tables /// public string HosName { get; set; } /// + /// 医疗机构代煎药联系电话 + /// + public string HosPhone { get; set; } + /// + /// 医疗机构地址 + /// + public string HosAddress { get; set; } + /// /// 前置机地址 /// public string FrontAddress { get; set; } /// /// 记录状态 /// - public int Status { get; set; } + public HospitalInfoStatus Status { get; set; } + } + /// + /// 记录状态 + /// + [Flags] + public enum HospitalInfoStatus + { + /// + /// 无效 + /// + Disable = 0, + /// + /// 有效 + /// + Enable = 1, } } \ No newline at end of file diff --git a/WebSiteCode/Cmdjy/Cmdjy/IOCFactory.cs b/WebSiteCode/Cmdjy/Cmdjy/IOCFactory.cs index fb1d314..54b3e9a 100644 --- a/WebSiteCode/Cmdjy/Cmdjy/IOCFactory.cs +++ b/WebSiteCode/Cmdjy/Cmdjy/IOCFactory.cs @@ -1,6 +1,7 @@ using Autofac; using Autofac.Integration.Mvc; using CommonClass.Factory; +using Autofac.Integration; namespace Cmdjy { @@ -30,7 +31,12 @@ namespace Cmdjy } private static void _iocFactory_BeforeBuild(IOCFactory arg1,ContainerBuilder arg2) { + //注册控制器 arg2.RegisterControllers(typeof(IOC).Assembly).PropertiesAutowired(); + //注入特性 + arg2.RegisterFilterProvider(); + //注册模型绑定 + arg2.RegisterModelBinderProvider(); } } diff --git a/WebSiteCode/Cmdjy/Cmdjy/Web.config b/WebSiteCode/Cmdjy/Cmdjy/Web.config index b071647..3714fd6 100644 --- a/WebSiteCode/Cmdjy/Cmdjy/Web.config +++ b/WebSiteCode/Cmdjy/Cmdjy/Web.config @@ -24,8 +24,8 @@ - - + +