(#16)添加医疗机构查询

This commit is contained in:
falcon 2019-04-01 14:45:19 +08:00
parent aaf152055d
commit e1a088bbb6
10 changed files with 246 additions and 6 deletions

View File

@ -1,6 +1,8 @@
using System; using System;
using Newtonsoft.Json; using Newtonsoft.Json;
using StackExchange.Redis; using StackExchange.Redis;
using CommonClass.Factory;
using Autofac;
namespace Cmdjy.Bll namespace Cmdjy.Bll
{ {
@ -17,6 +19,14 @@ namespace Cmdjy.Bll
} }
} }
public class CacheRegister:IRegister
{
public void Register(ContainerBuilder builder) {
builder.Register<ICache>(c => new RedisHelper());
}
}
public interface ICache public interface ICache
{ {
/// <summary> /// <summary>
@ -45,6 +55,11 @@ namespace Cmdjy.Bll
/// <param name="obj">缓存的数据</param> /// <param name="obj">缓存的数据</param>
/// <param name="timeSpan">缓存时间</param> /// <param name="timeSpan">缓存时间</param>
void SetData<T>(string key,T obj,TimeSpan timeSpan); void SetData<T>(string key,T obj,TimeSpan timeSpan);
/// <summary>
/// 删除数据缓存
/// </summary>
/// <param name="key">数据的键</param>
void RemoveData(string key);
} }
/// <summary> /// <summary>
/// 数据缓存实现类 /// 数据缓存实现类
@ -98,5 +113,10 @@ namespace Cmdjy.Bll
if(value == null) return null; if(value == null) return null;
return JsonConvert.DeserializeObject<T>(value); return JsonConvert.DeserializeObject<T>(value);
} }
public void RemoveData(string key) {
if(!Usable) return;
this.Database.KeyDelete(key);
}
} }
} }

View File

@ -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
{
/// <summary>
/// 医疗机构信息数据查询
/// </summary>
public interface IHospitalInfoDataQuery:IDataQuery<HospitalInfo> { }
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<HospitalInfo> GetAll() {
IEnumerable<HospitalInfo> result = null;
if(this.Config.EnableCache) {
result = this.Cache.GetData<IEnumerable<HospitalInfo>>(_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<HospitalInfo>(_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<HospitalInfo> 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";
}
}

View File

@ -0,0 +1,74 @@
using System.Collections.Generic;
using System.Linq;
using CommonClass.Factory;
using System;
using Cmdjy.Dal;
namespace Cmdjy.Bll.DataQuery
{
/// <summary>
/// 业务逻辑层数据查询接口
/// </summary>
public interface IDataQuery<T>
{
/// <summary>
/// 查询配置
/// </summary>
DataQueryConfig Config { get; set; }
/// <summary>
/// 获取所有数据,可以从缓冲区获取
/// </summary>
/// <returns>数据枚举</returns>
IEnumerable<T> GetAll();
/// <summary>
/// 通过Id获取数据。
/// </summary>
/// <param name="id">数据的Id</param>
/// <returns>获取到的数据或Null</returns>
T GetOneById(params object[] id);
/// <summary>
/// 获取数据查询。
/// </summary>
/// <param name="filter">查询筛选器</param>
/// <returns>数据查询</returns>
IQueryable<T> GetQuery(DjyDbContext db,DataFilterBase filter);
/// <summary>
/// 添加新数据
/// </summary>
/// <param name="one">要添加的数据</param>
/// <returns>添加后的数据</returns>
T AddNew(T one);
/// <summary>
/// 删除数据
/// </summary>
/// <param name="one">要删除的数据</param>
/// <returns>删除后的数据</returns>
T Remove(T one);
/// <summary>
/// 要更新的数据
/// </summary>
/// <param name="one">要更新的数据。</param>
/// <returns>更新后的数据</returns>
T Updata(T one);
}
/// <summary>
/// 数据筛选器基类
/// </summary>
public class DataFilterBase
{
}
/// <summary>
/// 数据查询配置
/// </summary>
public class DataQueryConfig:IRegisterSelf
{
/// <summary>
/// 是否允许使用缓冲
/// </summary>
public bool EnableCache { get; set; } = true;
/// <summary>
/// 缓冲过期时间
/// </summary>
public TimeSpan CacheTimeSpan { get; set; } = WebSettings.DefaultCacheTimeSpan;
}
}

View File

@ -194,12 +194,15 @@
<Compile Include="App_Start\FilterConfig.cs" /> <Compile Include="App_Start\FilterConfig.cs" />
<Compile Include="App_Start\RouteConfig.cs" /> <Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="Bll\BackgroundTask.cs" /> <Compile Include="Bll\BackgroundTask.cs" />
<Compile Include="Bll\DataQuery\HospitalInfoDataQuery.cs" />
<Compile Include="Bll\DataQuery\IDataQuery.cs" />
<Compile Include="Bll\DesHelper.cs" /> <Compile Include="Bll\DesHelper.cs" />
<Compile Include="Bll\Cache.cs" /> <Compile Include="Bll\Cache.cs" />
<Compile Include="Controllers\CompanyController.cs" /> <Compile Include="Controllers\CompanyController.cs" />
<Compile Include="Controllers\ControllerBase.cs" /> <Compile Include="Controllers\ControllerBase.cs" />
<Compile Include="Controllers\HisInfoController.cs" /> <Compile Include="Controllers\HisInfoController.cs" />
<Compile Include="Controllers\HisUpdataController.cs" /> <Compile Include="Controllers\HisUpdataController.cs" />
<Compile Include="Controllers\HospitalInfoController.cs" />
<Compile Include="Controllers\WsdInterfaceController.cs" /> <Compile Include="Controllers\WsdInterfaceController.cs" />
<Compile Include="Dal\Configuration.cs" /> <Compile Include="Dal\Configuration.cs" />
<Compile Include="Dal\DbContextFactory.cs" /> <Compile Include="Dal\DbContextFactory.cs" />
@ -286,6 +289,7 @@
<ItemGroup> <ItemGroup>
<Folder Include="App_Data\" /> <Folder Include="App_Data\" />
<Folder Include="Views\HisUpdata\" /> <Folder Include="Views\HisUpdata\" />
<Folder Include="Views\HospitalInfo\" />
<Folder Include="Views\Test\" /> <Folder Include="Views\Test\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -30,3 +30,11 @@ table {
display: inline-block; display: inline-block;
padding: 3px 5px; 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;
}

View File

@ -7,6 +7,9 @@ using Cmdjy.Models;
namespace Cmdjy.Controllers namespace Cmdjy.Controllers
{ {
/// <summary>
/// 医疗机构处方、药品信息控制器
/// </summary>
public class HisInfoController:Controller public class HisInfoController:Controller
{ {
/// <summary> /// <summary>

View File

@ -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
{
/// <summary>
/// 医疗机构信息控制器
/// </summary>
public class HospitalInfoController:ControllerBase
{
public Lazy<IHospitalInfoDataQuery> HosInfo { get; set; }
public ActionResult Index() {
return View();
}
public ActionResult HospitalList() {
var model = this.HosInfo.Value.GetAll();
return Json(model,JsonRequestBehavior.AllowGet);
}
}
}

View File

@ -1,9 +1,6 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
namespace Cmdjy.Dal.Tables namespace Cmdjy.Dal.Tables
{ {
@ -24,12 +21,35 @@ namespace Cmdjy.Dal.Tables
/// </summary> /// </summary>
public string HosName { get; set; } public string HosName { get; set; }
/// <summary> /// <summary>
/// 医疗机构代煎药联系电话
/// </summary>
public string HosPhone { get; set; }
/// <summary>
/// 医疗机构地址
/// </summary>
public string HosAddress { get; set; }
/// <summary>
/// 前置机地址 /// 前置机地址
/// </summary> /// </summary>
public string FrontAddress { get; set; } public string FrontAddress { get; set; }
/// <summary> /// <summary>
/// 记录状态 /// 记录状态
/// </summary> /// </summary>
public int Status { get; set; } public HospitalInfoStatus Status { get; set; }
}
/// <summary>
/// 记录状态
/// </summary>
[Flags]
public enum HospitalInfoStatus
{
/// <summary>
/// 无效
/// </summary>
Disable = 0,
/// <summary>
/// 有效
/// </summary>
Enable = 1,
} }
} }

View File

@ -1,6 +1,7 @@
using Autofac; using Autofac;
using Autofac.Integration.Mvc; using Autofac.Integration.Mvc;
using CommonClass.Factory; using CommonClass.Factory;
using Autofac.Integration;
namespace Cmdjy namespace Cmdjy
{ {
@ -30,7 +31,12 @@ namespace Cmdjy
} }
private static void _iocFactory_BeforeBuild(IOCFactory arg1,ContainerBuilder arg2) { private static void _iocFactory_BeforeBuild(IOCFactory arg1,ContainerBuilder arg2) {
//注册控制器
arg2.RegisterControllers(typeof(IOC).Assembly).PropertiesAutowired(); arg2.RegisterControllers(typeof(IOC).Assembly).PropertiesAutowired();
//注入特性
arg2.RegisterFilterProvider();
//注册模型绑定
arg2.RegisterModelBinderProvider();
} }
} }

View File

@ -24,8 +24,8 @@
</appSettings> </appSettings>
<connectionStrings> <connectionStrings>
<!--<add name="DjyDbContext" connectionString="Data Source=FALCON-PC\SQLSERVER2008R2;Persist Security info=True;Initial Catalog=cmdjy;Integrated Security=True" providerName="System.Data.SqlClient" />--> <add name="DjyDbContext" connectionString="Data Source=FALCON-PC\SQLSERVER2008R2;Persist Security info=True;Initial Catalog=cmdjy;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="DjyDbContext" connectionString="Data Source=10.244.216.112;Initial Catalog=cmdjy;User ID=cmdjy;Password=win@00*" providerName="System.Data.SqlClient" /> <!--<add name="DjyDbContext" connectionString="Data Source=10.244.216.112;Initial Catalog=cmdjy;User ID=cmdjy;Password=win@00*" providerName="System.Data.SqlClient" />-->
</connectionStrings> </connectionStrings>
<system.web> <system.web>
<compilation debug="true" targetFramework="4.6.1" /> <compilation debug="true" targetFramework="4.6.1" />