parent
34003dd3da
commit
d8aa65ff8e
|
@ -23,15 +23,14 @@ namespace Cmdjy.Bll
|
|||
/// </summary>
|
||||
public byte[] IV { get; set; }
|
||||
/// <summary>
|
||||
/// 加密key
|
||||
/// </summary>
|
||||
public string Key { get; set; }
|
||||
/// <summary>
|
||||
/// 加密字符串获取Base64密文
|
||||
/// </summary>
|
||||
/// <param name="str">要加密的字符串</param>
|
||||
public string Encrypty(string str) {
|
||||
byte[] bKey = Encoding.UTF8.GetBytes(Key.Substring(0,8));
|
||||
public string Encrypty(string key,string str) {
|
||||
if(key.Length < 8) {
|
||||
throw new Exception("加密用的key长度为8位");
|
||||
}
|
||||
byte[] bKey = Encoding.UTF8.GetBytes(key.Substring(0,8));
|
||||
byte[] bStr = Encoding.UTF8.GetBytes(str);
|
||||
var desc = createProvider();
|
||||
using(var mStream = new MemoryStream()) {
|
||||
|
@ -46,9 +45,12 @@ namespace Cmdjy.Bll
|
|||
/// 从Base64密文解密,获取字符串
|
||||
/// </summary>
|
||||
/// <param name="str">密文</param>
|
||||
public string DesCrypty(string str) {
|
||||
public string DesCrypty(string key,string str) {
|
||||
if(key.Length < 8) {
|
||||
throw new Exception("加密用的key长度为8位");
|
||||
}
|
||||
var bStr = Convert.FromBase64String(str);
|
||||
byte[] bKey = Encoding.UTF8.GetBytes(Key.Substring(0,8));
|
||||
byte[] bKey = Encoding.UTF8.GetBytes(key.Substring(0,8));
|
||||
var desc = createProvider();
|
||||
using(var mStream = new MemoryStream()) {
|
||||
using(var cStream = new CryptoStream(mStream,desc.CreateDecryptor(bKey,IV),CryptoStreamMode.Write)) {
|
||||
|
@ -75,9 +77,8 @@ namespace Cmdjy.Bll
|
|||
/// </summary>
|
||||
public static DesHelper GetHelper() {
|
||||
if(_deshelper == null) {
|
||||
var key = WebSettings.DesKey;
|
||||
byte[] IV = { 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08 };
|
||||
_deshelper = GetHelper(PaddingMode.PKCS7,CipherMode.CBC,IV,key);
|
||||
_deshelper = GetHelper(PaddingMode.PKCS7,CipherMode.CBC,IV);
|
||||
|
||||
}
|
||||
return _deshelper;
|
||||
|
@ -89,12 +90,9 @@ namespace Cmdjy.Bll
|
|||
/// <param name="cipher">加密算法模式</param>
|
||||
/// <param name="IV">初始化向量</param>
|
||||
/// <param name="key">加密关键字</param>
|
||||
public static DesHelper GetHelper(PaddingMode padding,CipherMode cipher,byte[] IV,string key) {
|
||||
if(key.Length < 8) {
|
||||
throw new Exception("加密用的key长度为8位");
|
||||
}
|
||||
public static DesHelper GetHelper(PaddingMode padding,CipherMode cipher,byte[] IV) {
|
||||
return new DesHelper {
|
||||
Cipher = cipher,IV = IV,Key = key,Padding = padding,
|
||||
Cipher = cipher,IV = IV,Padding = padding,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -189,9 +189,11 @@
|
|||
<Compile Include="Bll\ObjExtend.cs" />
|
||||
<Compile Include="Controllers\HisInfoController.cs" />
|
||||
<Compile Include="Dal\Configuration.cs" />
|
||||
<Compile Include="Dal\DbContextFactory.cs" />
|
||||
<Compile Include="Dal\Queryes\HisDrugQuery.cs" />
|
||||
<Compile Include="Dal\Queryes\HisPrescriptionQuery.cs" />
|
||||
<Compile Include="Dal\Queryes\IDbQuery.cs" />
|
||||
<Compile Include="Dal\Tables\CompanyInfo.cs" />
|
||||
<Compile Include="Dal\Tables\WsdRequestLog.cs" />
|
||||
<Compile Include="Dal\Wappers\HisDrugInfoWapper.cs" />
|
||||
<Compile Include="Dal\Wappers\HisPrescriptyInfoWapper.cs" />
|
||||
|
|
15
WebSiteCode/Cmdjy/Cmdjy/Dal/DbContextFactory.cs
Normal file
15
WebSiteCode/Cmdjy/Cmdjy/Dal/DbContextFactory.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
namespace Cmdjy.Dal
|
||||
{
|
||||
/// <summary>
|
||||
/// 数据上下文工厂
|
||||
/// </summary>
|
||||
public class DbContextFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取代煎药数据库
|
||||
/// </summary>
|
||||
public static DjyDbContext CreateDbContext() {
|
||||
return DjyDbContext.GetContext();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,7 +12,11 @@ namespace Cmdjy.Dal
|
|||
/// </summary>
|
||||
public partial class DjyDbContext:DbContext
|
||||
{
|
||||
public DjyDbContext() : base("DjyDbContext") {
|
||||
public static DjyDbContext GetContext() {
|
||||
return new DjyDbContext();
|
||||
}
|
||||
|
||||
private DjyDbContext() : base("DjyDbContext") {
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
|
@ -32,5 +36,9 @@ namespace Cmdjy.Dal
|
|||
/// 万仕达下载日志
|
||||
/// </summary>
|
||||
public DbSet<WsdRequestLog> WsdRequestLogs { get; set; }
|
||||
/// <summary>
|
||||
/// 代煎药厂商信息
|
||||
/// </summary>
|
||||
public DbSet<CompanyInfo> CompanyInfos { get; set; }
|
||||
}
|
||||
}
|
|
@ -26,7 +26,7 @@ namespace Cmdjy.Dal.Queryes
|
|||
|
||||
|
||||
public IEnumerable<HisDrugInfo> GetAll() {
|
||||
using(var db = new DjyDbContext()) {
|
||||
using(var db = DbContextFactory.CreateDbContext()) {
|
||||
return GetQuery(db).ToList();
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ namespace Cmdjy.Dal.Queryes
|
|||
var key = getPKey(pId.ToString());
|
||||
var val = this.Cache.Value.GetData<IEnumerable<HisDrugInfo>>(key);
|
||||
if(val == null) {
|
||||
using(var db = new DjyDbContext()) {
|
||||
using(var db = DbContextFactory.CreateDbContext()) {
|
||||
val = GetQuery(db).Where(m => m.PrescriptionId == pId).ToList();
|
||||
if(val != null) this.Cache.Value.SetData(key,val);
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ namespace Cmdjy.Dal.Queryes
|
|||
var key = getKey(id.ToString());
|
||||
var val = this.Cache.Value.GetData<HisDrugInfo>(key);
|
||||
if(val == null) {
|
||||
using(var db = new DjyDbContext()) {
|
||||
using(var db = DbContextFactory.CreateDbContext()) {
|
||||
val = db.DrugInfos.Find(id);
|
||||
if(val != null) this.Cache.Value.SetData(key,val);
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ namespace Cmdjy.Dal.Queryes
|
|||
}
|
||||
|
||||
public void Insert(HisDrugInfo obj) {
|
||||
using(var db = new DjyDbContext()) {
|
||||
using(var db = DbContextFactory.CreateDbContext()) {
|
||||
db.Entry(obj).State = EntityState.Added;
|
||||
db.SaveChanges();
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace Cmdjy.Dal.Queryes
|
|||
}
|
||||
|
||||
public IEnumerable<HisPrescriptionInfo> GetAll() {
|
||||
using(var db = new DjyDbContext()) {
|
||||
using(var db = DbContextFactory.CreateDbContext()) {
|
||||
return db.PrescriptionInfos.ToList();
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ namespace Cmdjy.Dal.Queryes
|
|||
var key = getKey(id.ToString());
|
||||
var val = this.Cache.Value.GetData<HisPrescriptionInfo>(key);
|
||||
if(val == null) {
|
||||
using(var db = new DjyDbContext()) {
|
||||
using(var db = DbContextFactory.CreateDbContext()) {
|
||||
val = db.PrescriptionInfos.Find(id);
|
||||
if(val != null) this.Cache.Value.SetData(key,val);
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ namespace Cmdjy.Dal.Queryes
|
|||
}
|
||||
|
||||
public void Insert(HisPrescriptionInfo obj) {
|
||||
using(var db = new DjyDbContext()) {
|
||||
using(var db = DbContextFactory.CreateDbContext()) {
|
||||
db.Entry(obj).State = EntityState.Added;
|
||||
db.SaveChanges();
|
||||
}
|
||||
|
|
49
WebSiteCode/Cmdjy/Cmdjy/Dal/Tables/CompanyInfo.cs
Normal file
49
WebSiteCode/Cmdjy/Cmdjy/Dal/Tables/CompanyInfo.cs
Normal file
|
@ -0,0 +1,49 @@
|
|||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Cmdjy.Dal.Tables
|
||||
{
|
||||
/// <summary>
|
||||
/// 代煎药厂商信息
|
||||
/// </summary>
|
||||
[Table("CompanyInfo")]
|
||||
public class CompanyInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 厂商编号
|
||||
/// </summary>
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
/// <summary>
|
||||
/// 厂商名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
/// <summary>
|
||||
/// 厂商地址
|
||||
/// </summary>
|
||||
public string Address { get; set; }
|
||||
/// <summary>
|
||||
/// 厂商电话
|
||||
/// </summary>
|
||||
public string Phone { get; set; }
|
||||
/// <summary>
|
||||
/// 安全关键字
|
||||
/// </summary>
|
||||
public string SecurityKey { get; set; }
|
||||
/// <summary>
|
||||
/// 厂商状态
|
||||
/// </summary>
|
||||
public EnumComanyInfo Status { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 厂家状态
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum EnumComanyInfo
|
||||
{
|
||||
Enable = 0,
|
||||
Disable = 1,
|
||||
}
|
||||
}
|
|
@ -147,6 +147,14 @@ namespace Cmdjy.Dal.Tables
|
|||
/// 用法
|
||||
/// </summary>
|
||||
public string Usage { get; set; }
|
||||
/// <summary>
|
||||
/// 代煎药厂商代码
|
||||
/// </summary>
|
||||
public string CompanyCode { get; set; }
|
||||
/// <summary>
|
||||
/// 代煎药厂商名称
|
||||
/// </summary>
|
||||
public string CompanyName { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace Cmdjy.Models
|
|||
public static class HisInfo
|
||||
{
|
||||
public static IEnumerable<HisPrescriptionInfo> GetPreInfos(PreFilter filter) {
|
||||
using(var db = new DjyDbContext()) {
|
||||
using(var db = DbContextFactory.CreateDbContext()) {
|
||||
var qu = db.PrescriptionInfos.AsQueryable();
|
||||
if(filter == null) return qu.ToList();
|
||||
if(!string.IsNullOrEmpty(filter.Start) && int.TryParse(filter.Start,out var s)) {
|
||||
|
@ -25,7 +25,7 @@ namespace Cmdjy.Models
|
|||
}
|
||||
|
||||
public static IEnumerable<HisDrugInfo> GetDrugInfos(int preId) {
|
||||
using(var db = new DjyDbContext()) {
|
||||
using(var db = DbContextFactory.CreateDbContext()) {
|
||||
var qu = db.DrugInfos.Where(m => m.PrescriptionId == preId);
|
||||
return qu.ToList();
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace Cmdjy.ws
|
|||
[WebMethod(Description = "医疗机构上传处方信息")]
|
||||
public string PostPrescriptionInfo(HisPrescriptionInfo info) {
|
||||
HisPrescriptionResult result = null;
|
||||
using(var db = new DjyDbContext()) {
|
||||
using(var db = DbContextFactory.CreateDbContext()) {
|
||||
var en = new HisPrescriptyInfoWapper(info) as Dal.Tables.HisPrescriptionInfo;
|
||||
en.RawAddress = this.Context.Request.UserHostAddress;
|
||||
en.CreateDatetime = DateTime.Now;
|
||||
|
@ -49,7 +49,7 @@ namespace Cmdjy.ws
|
|||
[WebMethod(Description = "医疗机构上传药品信息")]
|
||||
public string PostDrugInfo(HisDrugInfo info) {
|
||||
HisDrugResult result = null;
|
||||
using(var db = new DjyDbContext()) {
|
||||
using(var db = DbContextFactory.CreateDbContext()) {
|
||||
var en = new HisDrugInfoWapper(info) as Dal.Tables.HisDrugInfo;
|
||||
en.RawAddress = this.Context.Request.UserHostAddress;
|
||||
en.CreateDatetime = DateTime.Now;
|
||||
|
@ -213,6 +213,14 @@ namespace Cmdjy.ws
|
|||
/// 收费费用序号
|
||||
/// </summary>
|
||||
public string Sffyxh { get; set; }
|
||||
/// <summary>
|
||||
/// 代煎药厂商代码
|
||||
/// </summary>
|
||||
public string CompanyCode { get; set; }
|
||||
/// <summary>
|
||||
/// 代煎药厂商名称
|
||||
/// </summary>
|
||||
public string CompanyName { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// HIS发送处方信息应答
|
||||
|
|
|
@ -5,6 +5,7 @@ using System.Web.Services;
|
|||
using Cmdjy.Bll;
|
||||
using Newtonsoft.Json;
|
||||
using System.Threading.Tasks;
|
||||
using Cmdjy.Dal;
|
||||
|
||||
namespace Cmdjy.ws
|
||||
{
|
||||
|
@ -22,8 +23,19 @@ namespace Cmdjy.ws
|
|||
[WebMethod(Description = "获取代煎药处方信息")]
|
||||
public string GetData(WsdRequest info) {
|
||||
var result = new WsdResult {
|
||||
Code = EnumCode.Success,
|
||||
};
|
||||
result.Prescriptions = new List<WsdPrescriptionInfo>();
|
||||
string cKey = null;
|
||||
using(var db = DbContextFactory.CreateDbContext()) {
|
||||
var companyInfo = db.CompanyInfos.Where(m => m.Id.ToString() == info.CompanyCode);
|
||||
if(companyInfo.Any()) {
|
||||
cKey = companyInfo.First().SecurityKey;
|
||||
}
|
||||
}
|
||||
if(string.IsNullOrEmpty(cKey)) {
|
||||
result.Code = EnumCode.Exception;
|
||||
result.Msg = "CompanyCode值错误";
|
||||
}
|
||||
//获取数据
|
||||
int start = 0;
|
||||
if(!int.TryParse(info.StartNo,out start)) {
|
||||
|
@ -37,23 +49,26 @@ namespace Cmdjy.ws
|
|||
}
|
||||
if(count <= 0) {
|
||||
result.Code = EnumCode.Exception;
|
||||
result.Msg = "Count值小于0。";
|
||||
result.Msg = "Count值错误。";
|
||||
}
|
||||
if(result.Code != EnumCode.Exception) {
|
||||
result.Prescriptions = new List<WsdPrescriptionInfo>();
|
||||
count = count > WebSettings.WsdMaxCount ? WebSettings.WsdMaxCount : count;
|
||||
var cache = CacheFactory.Cache;
|
||||
for(int i = start;i < start + count;i++) {
|
||||
//从缓存获取
|
||||
var pkey = $"Wsd:Pre:Id:{i}";
|
||||
var pkey = $"Company:Id:{info.CompanyCode}:Pre:Id:{i}";
|
||||
var one = cache.GetData<WsdPrescriptionInfo>(pkey);
|
||||
if(one == null) {
|
||||
//从数据库获取处方信息
|
||||
one = getPrescriptionInfoFromDb(i);
|
||||
one = getPrescriptionInfoFromDb(info.CompanyCode,i);
|
||||
//判断是否为
|
||||
//获取药品信息
|
||||
if(one != null) one.Drugs = getDrugInfoFromDb(one.Id);
|
||||
//存缓存
|
||||
if(one != null) cache.SetData(pkey,one);
|
||||
}
|
||||
//对应代煎药厂商
|
||||
if(one == null) {
|
||||
one = new WsdPrescriptionInfo {
|
||||
Type = WsdPrescriptionType.NullOrder,Id = i,
|
||||
|
@ -64,14 +79,14 @@ namespace Cmdjy.ws
|
|||
result.Code = EnumCode.Success;
|
||||
result.Count = result.Prescriptions.Where(m => m.Type != WsdPrescriptionType.NullOrder).Count();
|
||||
result.Msg = "";
|
||||
using(var db = new Dal.DjyDbContext()) {
|
||||
using(var db = DbContextFactory.CreateDbContext()) {
|
||||
result.More = db.PrescriptionInfos.Max(m => m.Id) > (start + count);
|
||||
}
|
||||
}
|
||||
//编码:json串 + 加密信息
|
||||
try {
|
||||
var resStr = JsonConvert.SerializeObject(result);
|
||||
var mw = DesHelper.GetHelper().Encrypty(resStr);
|
||||
var mw = DesHelper.GetHelper().Encrypty(cKey,resStr);
|
||||
logWsdRequest(info,result,resStr,mw);
|
||||
return mw;
|
||||
}
|
||||
|
@ -87,7 +102,7 @@ namespace Cmdjy.ws
|
|||
/// <param name="resStr">响应字符串</param>
|
||||
/// <param name="mw">响应密文</param>
|
||||
private void logWsdRequest(WsdRequest info,WsdResult result,string resStr,string mw) {
|
||||
using(var db = new Dal.DjyDbContext()) {
|
||||
using(var db = DbContextFactory.CreateDbContext()) {
|
||||
if(result != null && result.Prescriptions != null) {
|
||||
foreach(var p in result.Prescriptions) {
|
||||
if(p.Drugs != null) {
|
||||
|
@ -113,7 +128,7 @@ namespace Cmdjy.ws
|
|||
/// <param name="id">处方号</param>
|
||||
private static List<WsdDrugInfo> getDrugInfoFromDb(int id) {
|
||||
List<WsdDrugInfo> result = null;
|
||||
using(var db = new Dal.DjyDbContext()) {
|
||||
using(var db = DbContextFactory.CreateDbContext()) {
|
||||
var qu = db.DrugInfos.Where(m => m.PrescriptionId == id);
|
||||
if(qu.Any()) {
|
||||
result = new List<WsdDrugInfo>();
|
||||
|
@ -130,11 +145,11 @@ namespace Cmdjy.ws
|
|||
/// 从数据库获取处方
|
||||
/// </summary>
|
||||
/// <param name="i">处方号</param>
|
||||
private static WsdPrescriptionInfo getPrescriptionInfoFromDb(int i) {
|
||||
private static WsdPrescriptionInfo getPrescriptionInfoFromDb(string cId,int i) {
|
||||
WsdPrescriptionInfo result = null;
|
||||
using(var db = new Dal.DjyDbContext()) {
|
||||
using(var db = DbContextFactory.CreateDbContext()) {
|
||||
var qu = db.PrescriptionInfos
|
||||
.Where(m => m.Id == i)
|
||||
.Where(m => m.Id == i && m.CompanyCode == cId)
|
||||
.Where(m => m.Type == Dal.Tables.PrescriptionType.Order || m.Type == Dal.Tables.PrescriptionType.CancelOrder);
|
||||
if(qu.Any()) {
|
||||
var fir = qu.First();
|
||||
|
@ -151,6 +166,14 @@ namespace Cmdjy.ws
|
|||
/// </summary>
|
||||
public class WsdRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 代煎药厂商编码。
|
||||
/// </summary>
|
||||
public string CompanyCode { get; set; }
|
||||
/// <summary>
|
||||
/// 代煎药厂商名称
|
||||
/// </summary>
|
||||
public string CompanyName { get; set; }
|
||||
/// <summary>
|
||||
/// 处方起始流水号。按照数字从1开始累加。返回结果包含此编号的处方。
|
||||
/// </summary>
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Cmdjy.Bll;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace Cmdjy.Bll.Tests
|
||||
{
|
||||
|
@ -14,21 +10,25 @@ namespace Cmdjy.Bll.Tests
|
|||
{
|
||||
[TestMethod()]
|
||||
public void EncryptyTest() {
|
||||
byte[] IV = { 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08 };
|
||||
var des = DesHelper.GetHelper(PaddingMode.PKCS7,CipherMode.CBC,IV,"12365478");
|
||||
Console.WriteLine($"Key:{des.Key}");
|
||||
byte[] IV = { 0x01,0x02,0x03,0x14,0x05,0x06,0x17,0x08 };
|
||||
string key = "12365478";
|
||||
var des = DesHelper.GetHelper(PaddingMode.PKCS7,CipherMode.CBC,IV);
|
||||
Console.WriteLine($"Key:{key}");
|
||||
string mingwen = getMingWen();
|
||||
Console.WriteLine($"明文:{mingwen}");
|
||||
var miwen = des.Encrypty(mingwen);
|
||||
var miwen = des.Encrypty(key,mingwen);
|
||||
Console.WriteLine($"密文:{miwen}");
|
||||
var mingwen2 = des.DesCrypty(miwen);
|
||||
var miwen2 = des.Encrypty(key,mingwen);
|
||||
Console.WriteLine($"密文2:{miwen2}");
|
||||
Assert.AreEqual(miwen,miwen2);
|
||||
var mingwen2 = des.DesCrypty(key,miwen);
|
||||
Assert.AreEqual(mingwen,mingwen2);
|
||||
}
|
||||
|
||||
public string getMingWen() {
|
||||
string str = "abcdefghijklmnopqrstuvwxyz123456789,./*-+";
|
||||
string str = "abcdefghijklmnopqrstuvwxyz1234567890,./*-+";
|
||||
var result = new StringBuilder();
|
||||
int len = 1000;
|
||||
int len = 100;
|
||||
var rean = new Random();
|
||||
for(int i = 0;i < len;i++) {
|
||||
var p = rean.Next(str.Length);
|
||||
|
|
Loading…
Reference in New Issue
Block a user