第一版,与万事诚联调完成版本。

This commit is contained in:
falcon 2019-03-27 14:46:35 +08:00
parent 18980f1187
commit 5502681f99
18 changed files with 211 additions and 76 deletions

Binary file not shown.

View File

@ -2,9 +2,54 @@
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Web.Mvc;
using Cmdjy.Dal;
using System.Linq;
namespace Cmdjy.Bll
{
/// <summary>
/// 标记Action需要对输出进行加密
/// </summary>
[AttributeUsage(AttributeTargets.Method,AllowMultiple = false,Inherited = false)]
[Obsolete("未完成",true)]
public class DesAttribute:ActionFilterAttribute, IResultFilter
{
public Lazy<DjyDbContext> Db { get; set; }
// var acceptEncoding = filterContext.HttpContext.Request.Headers["Accept-Encoding"];
// if(string.IsNullOrEmpty(acceptEncoding)) return;
// var response = filterContext.HttpContext.Response;
// if(response.Filter == null) return;
// acceptEncoding = acceptEncoding.ToLower();
// if(acceptEncoding.Contains("gzip")) {
// response.AppendHeader("Content-encoding", "gzip");
// response.Filter = new GZipStream(response.Filter,CompressionMode.Compress);
// }
// else if(acceptEncoding.Contains("deflate")) {
// response.AppendHeader("Content-encoding", "deflate");
// response.Filter = new DeflateStream(response.Filter,CompressionMode.Compress);
//}
public override void OnResultExecuting(ResultExecutingContext filterContext) {
//var disableDes = filterContext.HttpContext.Request.Form.HasKey ?? false;
var request = filterContext.HttpContext.Request;
var db = this.Db.Value;
var companyCode = request["CompanyCode"];
var icompanycode = 0;
if(!int.TryParse(companyCode,out var iicc)) {
}
var conpanyQu = db.CompanyInfos.Where(m => m.Id == iicc);
var response = filterContext.HttpContext.Response;
base.OnResultExecuting(filterContext);
}
public override void OnResultExecuted(ResultExecutedContext filterContext) {
base.OnResultExecuted(filterContext);
}
}
/// <summary>
/// 加密帮助类
/// </summary>

View File

@ -48,6 +48,9 @@
<Reference Include="Autofac, Version=4.9.2.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<HintPath>..\packages\Autofac.4.9.2\lib\net45\Autofac.dll</HintPath>
</Reference>
<Reference Include="Autofac.Integration.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
<HintPath>..\packages\Autofac.Mvc5.4.0.2\lib\net45\Autofac.Integration.Mvc.dll</HintPath>
</Reference>
<Reference Include="CommonClass.Factory, Version=1.2.0.8, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\CommonClass.Factory.1.2.0.8\lib\net45\CommonClass.Factory.dll</HintPath>
</Reference>
@ -194,6 +197,7 @@
<Compile Include="Bll\DesHelper.cs" />
<Compile Include="Bll\Cache.cs" />
<Compile Include="Controllers\CompanyController.cs" />
<Compile Include="Controllers\ControllerBase.cs" />
<Compile Include="Controllers\HisInfoController.cs" />
<Compile Include="Controllers\HisUpdataController.cs" />
<Compile Include="Controllers\WsdInterfaceController.cs" />
@ -213,6 +217,7 @@
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
<Compile Include="IOCFactory.cs" />
<Compile Include="Models\HisInfoModels.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="WebContext.cs" />

View File

@ -3,26 +3,6 @@
padding-bottom: 20px;
}
/* Set padding to keep content from hitting the edges */
.body-content {
padding-left: 15px;
padding-right: 15px;
}
/* Override the default bootstrap behavior where horizontal description lists
will truncate terms that are too long to fit in the left column
*/
.dl-horizontal dt {
white-space: normal;
}
/* Set width on the form input elements since they're 100% wide by default */
input,
select,
textarea {
max-width: 280px;
}
table {
border: 1px solid #000;
}
@ -43,10 +23,10 @@ table {
/*工具条*/
.toolBar {
list-style: none;
padding:0px;
padding: 0px;
}
.toolBar li {
display: inline-block;
padding:3px 5px;
padding: 3px 5px;
}

View File

@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Newtonsoft.Json;
namespace Cmdjy.Controllers
{
public class ControllerBase:Controller
{
protected override JsonResult Json(object data,string contentType,Encoding contentEncoding) {
return Json(data,contentType,contentEncoding,JsonRequestBehavior.DenyGet);
}
protected override JsonResult Json(object data,string contentType,Encoding contentEncoding,JsonRequestBehavior behavior) {
return new MyJsonResult {
Data = data,
ContentType = contentType,
ContentEncoding = contentEncoding,
JsonRequestBehavior = behavior
};
}
}
public class MyJsonResult:JsonResult
{
public override void ExecuteResult(ControllerContext context) {
if(context == null) {
throw new ArgumentNullException("context");
}
if(JsonRequestBehavior == JsonRequestBehavior.DenyGet &&
String.Equals(context.HttpContext.Request.HttpMethod,"GET",StringComparison.OrdinalIgnoreCase)) {
throw new InvalidOperationException("GetNotAllowed");
}
HttpResponseBase response = context.HttpContext.Response;
if(!String.IsNullOrEmpty(ContentType)) {
response.ContentType = ContentType;
}
else {
response.ContentType = "application/json";
}
if(ContentEncoding != null) {
response.ContentEncoding = ContentEncoding;
}
if(Data != null) {
response.Write(JsonConvert.SerializeObject(Data));
}
}
}
}

View File

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc;
namespace Cmdjy.Controllers
{

View File

@ -1,30 +1,28 @@
using System;
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 Cmdjy.Dal;
using CommonHelper;
using Newtonsoft.Json;
using WsdInterfaceModels;
namespace Cmdjy.Controllers
{
public class WsdInterfaceController:Controller
public class WsdInterfaceController:ControllerBase
{
public Lazy<DjyDbContext> Db { get; set; }
public ActionResult Index() {
var model = new WsdRequest {
StartNo = "0",MaxCount = "10",
CompanyCode="1", CompanyName= "万仕达",
CompanyCode = "1",CompanyName = "万仕达",
};
return PartialView(model);
}
public ActionResult GetData(WsdRequest info) {
public ActionResult GetData(WsdRequest info,string noDes,string needNull) {
var result = new WsdResult {
Code = EnumCode.Success,
};
@ -70,13 +68,14 @@ namespace Cmdjy.Controllers
//存缓存
if(one != null) cache.SetData(pkey,one);
}
//对应代煎药厂商
if(one == null) {
if(needNull != null && one == null) {
one = new WsdPrescriptionInfo {
Type = WsdPrescriptionType.NullOrder,Id = i,
};
}
result.Prescriptions.Add(one);
if(one != null) {
result.Prescriptions.Add(one);
}
}
result.Code = EnumCode.Success;
result.Count = result.Prescriptions.Where(m => m.Type != WsdPrescriptionType.NullOrder).Count();
@ -84,11 +83,11 @@ namespace Cmdjy.Controllers
result.More = db.PrescriptionInfos.Max(m => m.Id) > (start + count);
}
//编码json串 + 加密信息
//return Json(result);
var resStr = JsonConvert.SerializeObject(result);
return Content(resStr);
//var mw = DesHelper.GetHelper().Encrypty(cKey,resStr);
//logWsdRequest(info,result,resStr,mw);
//return mw;
var mw = noDes == null ? DesHelper.GetHelper().Encrypty(cKey,resStr) : resStr;
logWsdRequest(info,result,resStr,mw);
return Content(mw);
}
/// <summary>
/// 记录日志
@ -130,6 +129,7 @@ namespace Cmdjy.Controllers
foreach(var item in qu) {
var od = new WsdDrugInfo();
od.CopyFrom(item);
od.PrescriptionId = item.PrescriptionId.ToString();
result.Add(od);
}
}

View File

@ -1,16 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.Data.Entity;
using Cmdjy.Dal.Tables;
using CommonClass.Factory;
namespace Cmdjy.Dal
{
/// <summary>
/// 崇明代煎药数据库
/// </summary>
public partial class DjyDbContext:DbContext
public partial class DjyDbContext:DbContext, IRegisterSelf
{
public DjyDbContext() : base("DjyDbContext") {
}

View File

@ -2,6 +2,7 @@
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using Autofac.Integration.Mvc;
using Cmdjy.Dal;
namespace Cmdjy
@ -9,6 +10,9 @@ namespace Cmdjy
public class MvcApplication:System.Web.HttpApplication
{
protected void Application_Start() {
DependencyResolver.SetResolver(new AutofacDependencyResolver(IOC.Factory));
if(WebSettings.AutoMigrations) {
Database.SetInitializer(new MigrateDatabaseToLatestVersion<DjyDbContext,Configuration>());
}

View File

@ -0,0 +1,37 @@
using Autofac;
using Autofac.Integration.Mvc;
using CommonClass.Factory;
namespace Cmdjy
{
/// <summary>
/// IOC框架
/// </summary>
public class IOC
{
private static IOCFactory _iocFactory = null;
private static object _objLock = new object();
/// <summary>
/// 控制反转容器工厂
/// </summary>
public static ILifetimeScope Factory {
get {
if(_iocFactory == null) {
lock(_objLock) {
if(_iocFactory == null) {
_iocFactory = new IOCFactory();
_iocFactory.BeforeBuild += _iocFactory_BeforeBuild;
_iocFactory.Init();
}
}
}
return _iocFactory.Container.BeginLifetimeScope();
}
}
private static void _iocFactory_BeforeBuild(IOCFactory arg1,ContainerBuilder arg2) {
arg2.RegisterControllers(typeof(IOC).Assembly).PropertiesAutowired();
}
}
}

View File

@ -1,6 +1,7 @@
<h1>代煎药平台</h1>
<hr />
<ol class="toolBar">
<li>版本1.0</li>
<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>

View File

@ -1,21 +1,35 @@
@model WsdInterfaceModels.WsdRequest
<style type="text/css">
</style>
<fieldset>
<legend>要查询的数据</legend>
@using(Ajax.BeginForm("GetData",new AjaxOptions {
OnSuccess = "wsdSucc",
OnSuccess = "wsdSucc",OnBegin = "wsdBeg",
})) {
<label>第三方机构代码:@Html.EditorFor(m => m.CompanyCode) </label>
<label>第三方机构名称:@Html.EditorFor(m => m.CompanyName)</label>
<label>开始流水号:@Html.EditorFor(m => m.StartNo)</label>
<br />
<label>返回不加密数据:<input type="checkbox" name="noDes" checked="checked" /></label>
<label>最大下载数量:@Html.EditorFor(m => m.MaxCount)</label>
<label>地址:@Url.Action("GetData")</label>
<input type="submit" value="查询" />
}
</fieldset>
<div id="wsdMsg"></div>
<pre id="wsdMsg"></pre>
<script type="text/javascript">
$("#wsdMsg").hide();
function wsdSucc(data) {
$("#wsdMsg").text(data);
if (!data.match("^\{(.+:.+,*){1,}\}$")) {
$("#wsdMsg").show().text(data);
} else {
$("#wsdMsg").show().text(JSON.stringify(JSON.parse(data), null, 2));
}
}
function wsdBeg() {
$("#wsdMsg").text("");
}
</script>

View File

@ -20,7 +20,7 @@
<add key="RedisConnectionString" value="" />
<!--万仕达接口一次最大传送处方数-->
<add key="wsd:maxCount" value="100" />
<add key="wsd:maxCount" value="50" />
</appSettings>
<connectionStrings>
@ -66,7 +66,7 @@
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.2.4.0" newVersion="5.2.4.0" />
<bindingRedirect oldVersion="0.0.0.0-5.2.4.0" newVersion="5.2.4.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral" />

View File

@ -2,6 +2,7 @@
<packages>
<package id="Antlr" version="3.5.0.2" targetFramework="net461" />
<package id="Autofac" version="4.9.2" targetFramework="net461" />
<package id="Autofac.Mvc5" version="4.0.2" targetFramework="net461" />
<package id="bootstrap" version="3.3.7" targetFramework="net461" />
<package id="CommonClass.Factory" version="1.2.0.8" targetFramework="net461" />
<package id="EntityFramework" version="6.2.0" targetFramework="net461" />

View File

@ -10,9 +10,9 @@ namespace Cmdjy.Bll.Tests
{
[TestMethod()]
public void EncryptyTest() {
byte[] IV = { 0x01,0x02,0x03,0x14,0x05,0x06,0x17,0x08 };
string key = "12365478";
var des = DesHelper.GetHelper(PaddingMode.PKCS7,CipherMode.CBC,IV);
//byte[] IV = { 0x01,0x02,0x03,0x14,0x05,0x06,0x17,0x08 };
string key = "wscdy19;";
var des = DesHelper.GetHelper();
Console.WriteLine($"Key:{key}");
string mingwen = getMingWen();
Console.WriteLine($"明文:{mingwen}");
@ -20,13 +20,13 @@ namespace Cmdjy.Bll.Tests
Console.WriteLine($"密文:{miwen}");
var miwen2 = des.Encrypty(key,mingwen);
Console.WriteLine($"密文2{miwen2}");
Assert.AreEqual(miwen,miwen2);
Assert.AreEqual(miwen,miwen2,"多次加密密文应该相同");
var mingwen2 = des.DesCrypty(key,miwen);
Assert.AreEqual(mingwen,mingwen2);
Assert.AreEqual(mingwen,mingwen2,"明文和密文相同");
}
public string getMingWen() {
string str = "abcdefghijklmnopqrstuvwxyz1234567890,./*-+";
string str = "abcdefghijklmnopqrstuvwxyz1234567890,./*-+{}[],.;\"";
var result = new StringBuilder();
int len = 100;
var rean = new Random();
@ -36,5 +36,9 @@ namespace Cmdjy.Bll.Tests
}
return result.ToString();
}
public string Realstr() {
return @"";
}
}
}

View File

@ -36,6 +36,7 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="CommonClass.Factory, Version=1.2.0.8, Culture=neutral, PublicKeyToken=null" />
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.2.0\lib\net45\EntityFramework.dll</HintPath>
</Reference>

View File

@ -29,6 +29,10 @@
<assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.9.2.0" newVersion="4.9.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.4.0" newVersion="5.2.4.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.serviceModel>

View File

@ -4,22 +4,6 @@
public static class ObjExtend
{
/// <summary>
/// 从目标对象中复制属性的值,执行浅表复制
/// </summary>
/// <param name="t">复制目标</param>
/// <param name="s">复制原</param>
public static void CopyFrom(this object t,object s) {
foreach(var p in s.GetType().GetProperties()) {
if(p.CanRead) {
var tp = t.GetType().GetProperty(p.Name);
if(tp != null && tp.CanWrite && canConvert(p.PropertyType,tp.PropertyType)) {
tp.SetValue(t,p.GetValue(s));
//tp.SetValue(t,Convert.ChangeType(p.GetValue(s),tp.PropertyType));
}
}
}
}
/// <summary>
/// 从目标对象中复制属性的值,执行浅表复制
/// </summary>
@ -28,7 +12,14 @@
/// <param name="s">复制原</param>
/// <returns></returns>
public static T CopyFrom<T>(this T t,object s) where T : class {
CopyFrom(t,s);
foreach(var p in s.GetType().GetProperties()) {
if(p.CanRead) {
var tp = t.GetType().GetProperty(p.Name);
if(tp != null && tp.CanWrite && canConvert(p.PropertyType,tp.PropertyType)) {
tp.SetValue(t,p.GetValue(s));
}
}
}
return t as T;
}
/// <summary>