添加万仕达代煎药webapi接口

This commit is contained in:
falcon 2019-03-26 14:35:45 +08:00
parent 1208647496
commit 18980f1187
4 changed files with 168 additions and 6 deletions

View File

@ -277,12 +277,12 @@
<Content Include="Views\HisInfo\DrugList.cshtml" />
<Content Include="Views\Company\Index.cshtml" />
<Content Include="Views\Company\CompanyList.cshtml" />
<Content Include="Views\WsdInterface\Index.cshtml" />
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\" />
<Folder Include="Views\HisUpdata\" />
<Folder Include="Views\Test\" />
<Folder Include="Views\WsdInterface\" />
</ItemGroup>
<ItemGroup>
<Content Include="fonts\glyphicons-halflings-regular.woff2" />

View File

@ -3,15 +3,155 @@ using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WsdInterfaceModels;
using Cmdjy.Dal;
using Cmdjy.Dal.Tables;
using Cmdjy.Bll;
using Newtonsoft.Json;
using CommonHelper;
namespace Cmdjy.Controllers
{
public class WsdInterfaceController : Controller
public class WsdInterfaceController:Controller
{
// GET: WsdInterface
public ActionResult Index()
{
return View();
public Lazy<DjyDbContext> Db { get; set; }
public ActionResult Index() {
var model = new WsdRequest {
StartNo = "0",MaxCount = "10",
CompanyCode="1", CompanyName= "万仕达",
};
return PartialView(model);
}
public ActionResult GetData(WsdRequest info) {
var result = new WsdResult {
Code = EnumCode.Success,
};
string cKey = null;
var db = this.Db.Value;
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)) {
result.Code = EnumCode.Exception;
result.Msg = "Start值错误";
}
int count = 0;
if(!int.TryParse(info.MaxCount,out count)) {
result.Code = EnumCode.Exception;
result.Msg = "MaxCount值错误";
}
if(count <= 0) {
result.Code = EnumCode.Exception;
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 = $"Company:Id:{info.CompanyCode}:Pre:Id:{i}";
var one = cache.GetData<WsdPrescriptionInfo>(pkey);
if(one == null) {
//从数据库获取处方信息
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,
};
}
result.Prescriptions.Add(one);
}
result.Code = EnumCode.Success;
result.Count = result.Prescriptions.Where(m => m.Type != WsdPrescriptionType.NullOrder).Count();
result.Msg = "";
result.More = db.PrescriptionInfos.Max(m => m.Id) > (start + count);
}
//编码json串 + 加密信息
var resStr = JsonConvert.SerializeObject(result);
return Content(resStr);
//var mw = DesHelper.GetHelper().Encrypty(cKey,resStr);
//logWsdRequest(info,result,resStr,mw);
//return mw;
}
/// <summary>
/// 记录日志
/// </summary>
/// <param name="info">请求信息</param>
/// <param name="result">响应对象</param>
/// <param name="resStr">响应字符串</param>
/// <param name="mw">响应密文</param>
private void logWsdRequest(WsdRequest info,WsdResult result,string resStr,string mw) {
var db = this.Db.Value;
if(result != null && result.Prescriptions != null) {
foreach(var p in result.Prescriptions) {
if(p.Drugs != null) {
foreach(var d in p.Drugs) {
db.WsdRequestLogs.Add(new Dal.Tables.WsdRequestLog {
StartNo = info.StartNo,MaxCount = info.MaxCount,
ClientAddress = Request.UserHostAddress,
LogDatatime = DateTime.Now,DrugId = d.Id.ToString(),
PrescriptionId = p.Id.ToString(),
Code = result.Code.ToString(),Msg = result.Msg,
});
}
}
}
}
db.SaveChanges();
}
/// <summary>
/// 从数据库获取药品列表
/// </summary>
/// <param name="id">处方号</param>
private List<WsdDrugInfo> getDrugInfoFromDb(int id) {
List<WsdDrugInfo> result = null;
var db = this.Db.Value;
var qu = db.DrugInfos.Where(m => m.PrescriptionId == id);
if(qu.Any()) {
result = new List<WsdDrugInfo>();
foreach(var item in qu) {
var od = new WsdDrugInfo();
od.CopyFrom(item);
result.Add(od);
}
}
return result;
}
/// <summary>
/// 从数据库获取处方
/// </summary>
/// <param name="i">处方号</param>
private WsdPrescriptionInfo getPrescriptionInfoFromDb(string cId,int i) {
WsdPrescriptionInfo result = null;
var db = this.Db.Value;
var qu = db.PrescriptionInfos
.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();
result = new WsdPrescriptionInfo();
result.CopyFrom(fir);
}
return result;
}
}
}

View File

@ -3,6 +3,7 @@
<ol class="toolBar">
<li>@Ajax.ActionLink("厂商列表","Index","Company",new AjaxOptions { UpdateTargetId = "main" })</li>
<li>@Ajax.ActionLink("医疗机构处方列表","Index","HisInfo",new AjaxOptions { UpdateTargetId = "main" })</li>
<li>@Ajax.ActionLink("万仕达下载测试","Index","WsdInterface",new AjaxOptions { UpdateTargetId = "main" })</li>
</ol>
<hr />
<div id="main"></div>

View File

@ -0,0 +1,21 @@
@model WsdInterfaceModels.WsdRequest
<fieldset>
<legend>要查询的数据</legend>
@using(Ajax.BeginForm("GetData",new AjaxOptions {
OnSuccess = "wsdSucc",
})) {
<label>第三方机构代码:@Html.EditorFor(m => m.CompanyCode) </label>
<label>第三方机构名称:@Html.EditorFor(m => m.CompanyName)</label>
<label>开始流水号:@Html.EditorFor(m => m.StartNo)</label>
<label>最大下载数量:@Html.EditorFor(m => m.MaxCount)</label>
<input type="submit" value="查询" />
}
</fieldset>
<div id="wsdMsg"></div>
<script type="text/javascript">
function wsdSucc(data) {
$("#wsdMsg").text(data);
}
</script>