Commit 9a8cc93b by zry

api dev

parent e2d44293
This diff was suppressed by a .gitattributes entry.
using Microsoft.AspNetCore.Mvc; using FluentValidation.AspNetCore;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
...@@ -13,7 +14,7 @@ ...@@ -13,7 +14,7 @@
namespace Performance.Api.Controllers namespace Performance.Api.Controllers
{ {
[Route("api/[controller]/[action]")] [Route("api/[controller]")]
public class AccountController : Controller public class AccountController : Controller
{ {
UserService _userService; UserService _userService;
...@@ -28,23 +29,74 @@ public class AccountController : Controller ...@@ -28,23 +29,74 @@ public class AccountController : Controller
_options = options.Value; _options = options.Value;
} }
/// <summary>
/// 登录
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[NoVerify] [NoVerify]
[HttpPost] [HttpPost]
public ApiResponse<LoginInfo> Login([FromBody]LoginRequest request) [Route("login")]
public ApiResponse<UserIdentity> Login([FromBody]LoginRequest request)
{ {
var response = _userService.Login(request); var user = _userService.Login(request);
if (response.State == ResponseType.OK)
if (string.IsNullOrEmpty(user.Token))
user.Token = Guid.NewGuid().ToString("N");
var option = new MemoryCacheEntryOptions()
{ {
if (string.IsNullOrEmpty(response.Data.Token)) SlidingExpiration = TimeSpan.FromMinutes(_options.ExpirationMinutes)
response.Data.Token = Guid.NewGuid().ToString("N"); };
_memoryCache.Set(user.Token, user, option);
var option = new MemoryCacheEntryOptions()
{ return new ApiResponse<UserIdentity>(ResponseType.OK, user);
SlidingExpiration = TimeSpan.FromMinutes(_options.ExpirationMinutes) }
};
_memoryCache.Set(response.Data.Token, response.Data, option); /// <summary>
} /// 新增用户
return response; /// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("insert")]
[HttpPost]
public ApiResponse Insert(
[CustomizeValidator(RuleSet = "Insert")]
[FromBody]UserRequest request)
{
if (!_userService.Insert(request))
return new ApiResponse(ResponseType.Fail);
return new ApiResponse(ResponseType.OK);
}
/// <summary>
/// 修改用户
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("update")]
[HttpPost]
public ApiResponse Update(
[CustomizeValidator(RuleSet = "Update")]
[FromBody]UserRequest request)
{
if (!_userService.Update(request))
return new ApiResponse(ResponseType.Fail);
return new ApiResponse(ResponseType.OK);
}
/// <summary>
/// 设置用户管辖医院
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("sethospital")]
[HttpPost]
public ApiResponse SetHospital([FromBody]SetHospitalRequest request)
{
if (!_userService.SetHospital(request))
return new ApiResponse(ResponseType.Fail);
return new ApiResponse(ResponseType.OK);
} }
} }
} }
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Performance.DtoModels;
using Performance.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Performance.Api.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class DefaultController : ControllerBase
{
ILogger<DefaultController> _logger;
PerExcelService _excelService;
UserService _userService;
public DefaultController(PerExcelService excelService,
UserService userService,
ILogger<DefaultController> logger)
{
_excelService = excelService;
_userService = userService;
_logger = logger;
}
[HttpGet]
public ActionResult<PerExcel> Get()
{
var sd = _userService.GetUser();
_logger.LogDebug("debug", "aaaaaa");
var excel = _excelService.Analyze(@"C:\Users\ry\Desktop\文件\测试.xlsx");
return excel;
}
}
}
\ No newline at end of file
using FluentValidation.AspNetCore;
using Microsoft.AspNetCore.Mvc;
using Performance.DtoModels;
using Performance.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace Performance.Api.Controllers
{
[Route("api/[controller]")]
public class HospitalController : Controller
{
HospitalService _hospitalService;
public HospitalController(HospitalService hospitalService)
{
_hospitalService = hospitalService;
}
[Route("hospitallist")]
[HttpPost]
public ApiResponse<List<HospitalResponse>> GetHospitalList([FromBody]ApiRequest request)
{
var hospitalList = _hospitalService.GetUserHopital(request.ActiveUId);
return new ApiResponse<List<HospitalResponse>>(ResponseType.OK, "ok", hospitalList);
}
[Route("insert")]
[HttpPost]
public ApiResponse Insert([CustomizeValidator(RuleSet = "Insert"), FromBody]HospitalRequest request)
{
if (!_hospitalService.Insert(request))
return new ApiResponse(ResponseType.Fail);
return new ApiResponse(ResponseType.OK);
}
[Route("update")]
[HttpPost]
public ApiResponse Update([CustomizeValidator(RuleSet = "Update"), FromBody]HospitalRequest request)
{
if (!_hospitalService.Update(request))
return new ApiResponse(ResponseType.Fail);
return new ApiResponse(ResponseType.OK);
}
[Route("delete")]
[HttpPost]
public ApiResponse Delete([CustomizeValidator(RuleSet = "Delete"), FromBody]HospitalRequest request)
{
if (!_hospitalService.Delete(request))
return new ApiResponse(ResponseType.Fail);
return new ApiResponse(ResponseType.OK);
}
}
}
using FluentValidation.AspNetCore;
using Microsoft.AspNetCore.Mvc;
using Performance.DtoModels;
using Performance.DtoModels.Request;
using Performance.Infrastructure;
using Performance.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
namespace Performance.Api.Controllers
{
[Route("api/[controller]")]
public class SmsController : Controller
{
private SmsService _smsService;
public SmsController(SmsService smsService)
{
this._smsService = smsService;
}
/// <summary>
/// 发送验证码
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("code")]
[HttpPost]
[NoVerify]
public ApiResponse Code([FromBody]SmsCodeRequest request)
{
if (_smsService.SendCode(request.Type, request.Mobile))
return new ApiResponse(ResponseType.Fail);
return new ApiResponse(ResponseType.OK);
}
/// <summary>
/// 验证码验证
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("check")]
[HttpPost]
[NoVerify]
public ApiResponse Check([CustomizeValidator(RuleSet = "SmsCheck")][FromBody]SmsCodeRequest request)
{
if (_smsService.Check(request.Mobile, request.Code))
return new ApiResponse(ResponseType.Fail);
return new ApiResponse(ResponseType.OK);
}
}
}
...@@ -14,6 +14,7 @@ public class ValuesController : ControllerBase ...@@ -14,6 +14,7 @@ public class ValuesController : ControllerBase
[HttpGet] [HttpGet]
public ActionResult<IEnumerable<string>> Get() public ActionResult<IEnumerable<string>> Get()
{ {
//var excel = _excelService.Analyze(@"C:\Users\ry\Desktop\文件\测试.xlsx");
return new string[] { "value1", "value2" }; return new string[] { "value1", "value2" };
} }
......
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Internal; using Microsoft.AspNetCore.Http.Internal;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Controllers;
...@@ -18,35 +19,39 @@ namespace Performance.Api ...@@ -18,35 +19,39 @@ namespace Performance.Api
{ {
public class ActionsFilter : IAsyncActionFilter public class ActionsFilter : IAsyncActionFilter
{ {
private readonly ILogger<ActionsFilter> logger; private readonly ILogger<ActionsFilter> _logger;
private readonly IMemoryCache cache; private readonly IMemoryCache _cache;
private readonly IHostingEnvironment _env;
public ActionsFilter(ILoggerFactory factory, IMemoryCache cache) public ActionsFilter(ILoggerFactory factory, IMemoryCache cache, IHostingEnvironment env)
{ {
this.logger = factory.CreateLogger<ActionsFilter>(); this._logger = factory.CreateLogger<ActionsFilter>();
this.cache = cache; this._cache = cache;
this._env = env;
} }
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{ {
logger.BeginScope("s+++++++++++++++++++++++++++++++++");
var request = context.HttpContext.Request; var request = context.HttpContext.Request;
//启用body倒带功能 //启用body倒带功能
request.EnableRewind(); request.EnableRewind();
//记录Request请求 //记录Request请求
var kv = GetRequestContent(request); var kv = GetRequestContent(request);
logger.LogInformation($"请求内容 {request.Method}:{JsonHelper.Serialize(kv)}"); _logger.LogInformation($"请求内容 {request.Method}:{JsonHelper.Serialize(kv)}");
//token验证 //token验证
var arry = ((ControllerActionDescriptor)context.ActionDescriptor).MethodInfo.GetCustomAttributes(typeof(NoVerifyAttribute), true); if (!_env.IsDevelopment())
if (arry.Length == 0)
{ {
var token = kv.GetValue("token", ""); var arry = ((ControllerActionDescriptor)context.ActionDescriptor).MethodInfo.GetCustomAttributes(typeof(NoVerifyAttribute), true);
var user = cache.Get<LoginInfo>(token); if (arry.Length == 0)
if (string.IsNullOrEmpty(token) || user == null || user.Token.Equals(token))
{ {
var response = new ApiResponse(ResponseType.TokenError, "Token无效"); var token = kv.GetValue("token", "");
context.Result = new ObjectResult(response); var user = _cache.Get<UserIdentity>(token);
return; if (string.IsNullOrEmpty(token) || user == null || !user.Token.Equals(token))
{
var response = new ApiResponse(ResponseType.TokenError, "Token无效");
context.Result = new ObjectResult(response);
return;
}
} }
} }
...@@ -56,19 +61,21 @@ public ActionsFilter(ILoggerFactory factory, IMemoryCache cache) ...@@ -56,19 +61,21 @@ public ActionsFilter(ILoggerFactory factory, IMemoryCache cache)
var messageList = context.ModelState.Values var messageList = context.ModelState.Values
.Where(t => !string.IsNullOrEmpty(t?.Errors?.FirstOrDefault()?.ErrorMessage)) .Where(t => !string.IsNullOrEmpty(t?.Errors?.FirstOrDefault()?.ErrorMessage))
.Select(t => t?.Errors?.FirstOrDefault()?.ErrorMessage); .Select(t => t?.Errors?.FirstOrDefault()?.ErrorMessage);
string errorMessage = string.Join(",", messageList); var response = new ApiResponse(ResponseType.ParameterError, "参数错误", messageList);
var response = new ApiResponse(ResponseType.ParameterError, "参数错误", errorMessage);
context.Result = new ObjectResult(response); context.Result = new ObjectResult(response);
var jsonData = JsonHelper.Serialize(context.Result); var jsonData = JsonHelper.Serialize(context.Result);
logger.LogInformation($"响应结果:{jsonData}"); _logger.LogInformation($"响应结果:{jsonData}");
} }
//记录response结果 //记录response结果
else else
{ {
var executedContext = await next(); var executedContext = await next();
if (executedContext.Exception != null)
throw executedContext.Exception;
var objectResult = (ObjectResult)executedContext.Result; var objectResult = (ObjectResult)executedContext.Result;
var jsonData = JsonHelper.Serialize(objectResult.Value); var jsonData = JsonHelper.Serialize(objectResult.Value);
logger.LogInformation($"响应结果:{jsonData}"); _logger.LogInformation($"响应结果:{jsonData}");
} }
} }
......
...@@ -21,8 +21,15 @@ public Task OnExceptionAsync(ExceptionContext context) ...@@ -21,8 +21,15 @@ public Task OnExceptionAsync(ExceptionContext context)
{ {
var logger = loggerFactory.CreateLogger<ExceptionsFilter>(); var logger = loggerFactory.CreateLogger<ExceptionsFilter>();
logger.LogError($"接口异常:{context.Exception.ToString()}"); logger.LogError($"接口异常:{context.Exception.ToString()}");
var response = new ApiResponse(ResponseType.Error, "接口异常", context.Exception.Message); if (context.Exception is PerformanceException)
context.Result = new ObjectResult(response); {
context.Result = new ObjectResult(new ApiResponse(ResponseType.Fail, context.Exception.Message));
}
else
{
var response = new ApiResponse(ResponseType.Error, "接口内部异常", context.Exception.Message);
context.Result = new ObjectResult(response);
}
return Task.CompletedTask; return Task.CompletedTask;
} }
} }
......
...@@ -46,12 +46,14 @@ public void ConfigureServices(IServiceCollection services) ...@@ -46,12 +46,14 @@ public void ConfigureServices(IServiceCollection services)
{ {
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
services services
//筛选器配置
.AddMvc(option => .AddMvc(option =>
{ {
option.Filters.Add<ActionsFilter>(); option.Filters.Add<ActionsFilter>();
option.Filters.Add<ExceptionsFilter>(); option.Filters.Add<ExceptionsFilter>();
}) })
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1) .SetCompatibilityVersion(CompatibilityVersion.Version_2_1)
//json格式配置
.AddJsonOptions(json => .AddJsonOptions(json =>
{ {
json.SerializerSettings.Converters.Add(new IsoDateTimeConverterContent() { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" }); json.SerializerSettings.Converters.Add(new IsoDateTimeConverterContent() { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" });
...@@ -63,6 +65,7 @@ public void ConfigureServices(IServiceCollection services) ...@@ -63,6 +65,7 @@ public void ConfigureServices(IServiceCollection services)
json.SerializerSettings.Culture = new CultureInfo("it-IT"); json.SerializerSettings.Culture = new CultureInfo("it-IT");
json.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; json.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
}) })
//model验证
.AddFluentValidation(fv => .AddFluentValidation(fv =>
{ {
//禁用其他以使FluentValidation是唯一执行的验证库 //禁用其他以使FluentValidation是唯一执行的验证库
...@@ -76,16 +79,25 @@ public void ConfigureServices(IServiceCollection services) ...@@ -76,16 +79,25 @@ public void ConfigureServices(IServiceCollection services)
} }
}); });
//automapper 配置
Mapper.Initialize(cfg => cfg.AddProfile<AutoMapperConfigs>()); Mapper.Initialize(cfg => cfg.AddProfile<AutoMapperConfigs>());
services.AddAutoMapper(); services.AddAutoMapper();
//service注入 repoitory注入
services services
.AddPerformanceService() .AddPerformanceService()
.AddPerformanceRepoitory() .AddPerformanceRepoitory();
//appsetting注入
services
.Configure<AppConnection>(Configuration.GetSection("AppConnection")) .Configure<AppConnection>(Configuration.GetSection("AppConnection"))
.Configure<Application>(Configuration.GetSection("Application")); .Configure<Application>(Configuration.GetSection("Application"))
.Configure<HuyiSmsConfig>(Configuration.GetSection("HuyiSmsConfig"));
//huyi短信发送注入
services.AddScoped<HuyiSmsNotify>();
//ef配置
var connection = services.BuildServiceProvider().GetService<IOptions<AppConnection>>(); var connection = services.BuildServiceProvider().GetService<IOptions<AppConnection>>();
services.AddDbContext<PerformanceDbContext>(options => services.AddDbContext<PerformanceDbContext>(options =>
{ {
......
using Microsoft.Extensions.Caching.Memory;
using Performance.DtoModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Performance.Api.Util
{
public class UserUtil
{
IMemoryCache _memoryCache;
public UserUtil(IMemoryCache memoryCache)
{
_memoryCache = memoryCache;
}
public UserIdentity At(ApiRequest request)
{
return At(request.Token);
}
public UserIdentity At(string token)
{
if (string.IsNullOrEmpty(token))
throw new PerformanceException("token is not null");
return _memoryCache.Get<UserIdentity>(token);
}
}
}
{ {
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Debug", "Default": "Debug",
"System": "Information", "System": "Information",
"Microsoft": "Information" "Microsoft": "Information"
} }
},
"AppConnection": {
"PerformanceConnectionString": "server=192.168.18.166;database=db_performance;uid=root;pwd=1234qwer;pooling=true;charset=utf8;convert zero datetime=true;port=3306;connection timeout=120;max pool size=512;allow user variables=true;"
},
"Application": {
//登录过期时间
"ExpirationMinutes": "5",
//验证码过期
"SmsCodeMinutes": "5"
} }
} }
{ {
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Warning" "Default": "Warning"
} }
}, },
//连接字符串
"AppConnection": { "AppConnection": {
"PerformanceConnectionString": "server=192.168.18.166;database=db_performance;uid=root;pwd=1234qwer;pooling=true;charset=utf8;convert zero datetime=true;port=3306;connection timeout=120;max pool size=512;allow user variables=true;" "PerformanceConnectionString": "server=116.62.245.55;database=db_performance;uid=suvalue;pwd=suvalue2017;pooling=true;charset=utf8;convert zero datetime=true;port=3306;connection timeout=120;max pool size=512;allow user variables=true;"
},
//互亿
"HuyiSmsConfig": {
"Url": "http://106.ihuyi.cn/webservice/sms.php?method=Submit",
"Account": "cf_szjk",
"Password": "123456"
}, },
"Application": { "Application": {
//¼ʱ //登录过期时间
"ExpirationMinutes": "1" "ExpirationMinutes": "120",
//验证码过期
"SmsCodeMinutes": "30",
//短信模板
"SmsTemplate": "溯直健康提醒您,您的验证码为:[code],当天有效!"
} }
} }
...@@ -14,4 +14,8 @@ ...@@ -14,4 +14,8 @@
<ProjectReference Include="..\Performance.Services\Performance.Services.csproj" /> <ProjectReference Include="..\Performance.Services\Performance.Services.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
</Project> </Project>
...@@ -9,5 +9,9 @@ namespace Performance.DtoModels ...@@ -9,5 +9,9 @@ namespace Performance.DtoModels
public class ApiRequest public class ApiRequest
{ {
public string Token { get; set; } public string Token { get; set; }
public string Version { get; set; }
public string Device { get; set; }
public string AppName { get; set; }
public int ActiveUId { get; set; }
} }
} }
...@@ -22,7 +22,7 @@ public ApiResponse() ...@@ -22,7 +22,7 @@ public ApiResponse()
{ {
} }
public ApiResponse(ResponseType type) public ApiResponse(ResponseType type)
: this(type, "", null) : this(type, type.ToString(), null)
{ {
} }
...@@ -31,6 +31,11 @@ public ApiResponse(ResponseType type, string message) ...@@ -31,6 +31,11 @@ public ApiResponse(ResponseType type, string message)
{ {
} }
public ApiResponse(ResponseType type, TEntity entity)
: this(type, type.ToString(), entity)
{
}
public ApiResponse(ResponseType type, string message, TEntity entity) public ApiResponse(ResponseType type, string message, TEntity entity)
{ {
State = type; State = type;
...@@ -39,7 +44,7 @@ public ApiResponse(ResponseType type, string message, TEntity entity) ...@@ -39,7 +44,7 @@ public ApiResponse(ResponseType type, string message, TEntity entity)
} }
} }
public class ApiResponse : ApiResponse<Object> public sealed class ApiResponse : ApiResponse<Object>
{ {
public ApiResponse() public ApiResponse()
{ {
...@@ -53,6 +58,10 @@ public ApiResponse(ResponseType type, string message) : base(type, message) ...@@ -53,6 +58,10 @@ public ApiResponse(ResponseType type, string message) : base(type, message)
{ {
} }
public ApiResponse(ResponseType type, object entity) : base(type, entity)
{
}
public ApiResponse(ResponseType type, string message, object entity) : base(type, message, entity) public ApiResponse(ResponseType type, string message, object entity) : base(type, message, entity)
{ {
} }
......
...@@ -6,6 +6,17 @@ namespace Performance.DtoModels.AppSettings ...@@ -6,6 +6,17 @@ namespace Performance.DtoModels.AppSettings
{ {
public class Application public class Application
{ {
/// <summary>
/// 登录过期时间
/// </summary>
public int ExpirationMinutes { get; set; } public int ExpirationMinutes { get; set; }
/// <summary>
/// 验证码过期
/// </summary>
public int SmsCodeMinutes { get; set; }
/// <summary>
/// 短信模板
/// </summary>
public string SmsTemplate { get; set; }
} }
} }
...@@ -10,10 +10,25 @@ public class AutoMapperConfigs : Profile ...@@ -10,10 +10,25 @@ public class AutoMapperConfigs : Profile
{ {
public AutoMapperConfigs() public AutoMapperConfigs()
{ {
CreateMap<LoginInfo, Sys_User>() //用户登录信息
CreateMap<UserIdentity, sys_user>()
.ForMember(dest => dest.ID, opt => opt.MapFrom(src => src.UserID)); .ForMember(dest => dest.ID, opt => opt.MapFrom(src => src.UserID));
CreateMap<Sys_User, LoginInfo>() CreateMap<sys_user, UserIdentity>()
.ForMember(dest => dest.UserID, opt => opt.MapFrom(src => src.ID)); .ForMember(dest => dest.UserID, opt => opt.MapFrom(src => src.ID));
//用户新增/修改 请求
CreateMap<UserRequest, sys_user>();
CreateMap<sys_user, UserRequest>();
// 用户医院列表 响应
CreateMap<HospitalResponse, sys_hospital>()
.ForMember(dest => dest.ID, opt => opt.MapFrom(src => src.HosID));
CreateMap<sys_hospital, HospitalResponse>()
.ForMember(dest => dest.HosID, opt => opt.MapFrom(src => src.ID));
// 医院新增/修改 请求
CreateMap<HospitalRequest, sys_hospital>();
CreateMap<sys_hospital, HospitalRequest>();
} }
} }
} }
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace Performance.DtoModels
{
public class CustomValidator
{
/// <summary>
/// 判断输入的字符串是否是一个合法的手机号
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public static bool IsMobile(string input)
{
if (string.IsNullOrEmpty(input))
{
return false;
}
Regex regex = new Regex("^1[34578]\\d{9}$");
return regex.IsMatch(input);
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
namespace Performance.DtoModels
{
/// <summary> 验证码类型 </summary>
public enum SmsCodeType
{
[Description("登录")]
Login = 1,
[Description("其他")]
Other = 2,
}
/// <summary> 用户状态 </summary>
public enum States
{
[Description("登录")]
Enabled = 1,
[Description("其他")]
Disabled = 2,
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Threading.Tasks;
namespace Performance.DtoModels
{
public class PerformanceException : Exception
{
public PerformanceException()
{
}
public PerformanceException(string message) : base(message)
{
}
public PerformanceException(string message, Exception innerException) : base(message, innerException)
{
}
protected PerformanceException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
}
using FluentValidation;
using System;
using System.Collections.Generic;
using System.Text;
namespace Performance.DtoModels
{
/// <summary>
/// 登录请求
/// </summary>
public class HospitalRequest : ApiRequest
{
public int ID { get; set; }
/// <summary>
/// 医院名称
/// </summary>
public string HosName { get; set; }
/// <summary>
/// 简称
/// </summary>
public string ShortName { get; set; }
/// <summary>
///
/// </summary>
public string AreaCode { get; set; }
/// <summary>
///
/// </summary>
public string HosLevel { get; set; }
/// <summary>
///
/// </summary>
public string HosType { get; set; }
/// <summary>
///
/// </summary>
public Nullable<int> States { get; set; }
}
public class HospitalRequestValidator : AbstractValidator<HospitalRequest>
{
public HospitalRequestValidator()
{
Action action = () =>
{
RuleFor(x => x.HosName).NotNull().NotEmpty().Length(1, 50);
RuleFor(x => x.AreaCode).NotNull().NotEmpty().Length(1, 50);
RuleFor(x => x.HosLevel).NotNull().NotEmpty().Length(1, 50);
RuleFor(x => x.HosType).NotNull().NotEmpty().Length(1, 50);
};
RuleSet("Insert", () =>
{
action();
});
RuleSet("Update", () =>
{
action();
RuleFor(x => x.ID).NotNull().GreaterThan(0);
RuleFor(x => x.States).NotNull().InclusiveBetween(1, 2);
});
RuleSet("Delete", () =>
{
RuleFor(x => x.ID).NotNull().GreaterThan(0);
});
}
}
}
...@@ -22,19 +22,11 @@ public class LoginRequestValidator : AbstractValidator<LoginRequest> ...@@ -22,19 +22,11 @@ public class LoginRequestValidator : AbstractValidator<LoginRequest>
{ {
public LoginRequestValidator() public LoginRequestValidator()
{ {
RuleFor(x => x.LoginType) RuleFor(x => x.LoginType).InclusiveBetween(1, 2);
.InclusiveBetween(1, 2)
.WithMessage("LoginType超出范围");
RuleFor(x => x.Account) RuleFor(x => x.Account).NotEmpty().NotNull().Length(1, 200);
.NotNull()
.Length(1, 200)
.WithMessage("Account参数错误");
RuleFor(x => x.Password) RuleFor(x => x.Password).NotEmpty().NotNull().Length(1, 200);
.NotNull()
.Length(1, 200)
.WithMessage("Password参数错误");
} }
} }
} }
using FluentValidation;
using System;
using System.Collections.Generic;
using System.Text;
namespace Performance.DtoModels
{
/// <summary>
/// 登录请求
/// </summary>
public class SetHospitalRequest : ApiRequest
{
public int UserID { get; set; }
public int[] HosIDArray { get; set; }
}
public class SetHospitalRequestValidator : AbstractValidator<SetHospitalRequest>
{
public SetHospitalRequestValidator()
{
RuleFor(x => x.UserID).GreaterThan(0);
}
}
}
using FluentValidation;
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace Performance.DtoModels.Request
{
public class SmsCodeRequest : ApiRequest
{
/// <summary>
/// 短信验证类型 1 手机号登录 2 其他
/// </summary>
public int Type { get; set; }
public string Mobile { get; set; }
public string Code { get; set; }
}
public class SmsCodeRequestValidator : AbstractValidator<SmsCodeRequest>
{
public SmsCodeRequestValidator()
{
RuleFor(x => x.Type).InclusiveBetween(1, 2);
RuleFor(x => x.Mobile).Length(11).Must((pre) => { return CustomValidator.IsMobile(pre); });
RuleSet("SmsCheck", () =>
{
RuleFor(x => x.Code).Length(4, 6);
});
}
}
}
using FluentValidation;
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace Performance.DtoModels
{
public class UserRequest : ApiRequest
{
public int ID { get; set; }
/// <summary>
/// 真实名称
/// </summary>
public string RealName { get; set; }
/// <summary>
/// 手机号
/// </summary>
public string Mobile { get; set; }
/// <summary>
/// 登录名称
/// </summary>
public string Login { get; set; }
/// <summary>
/// 密码
/// </summary>
public string Password { get; set; }
/// <summary>
/// 邮箱
/// </summary>
public string Mail { get; set; }
/// <summary>
/// 用户状态 1启用 2禁用
/// </summary>
public Nullable<int> States { get; set; }
}
public class UserRequestValidator : AbstractValidator<UserRequest>
{
public UserRequestValidator()
{
Action action = () =>
{
RuleFor(x => x.RealName).NotNull().NotEmpty();
RuleFor(x => x.Login).NotNull().NotEmpty();
RuleFor(x => x.Mobile).NotNull().NotEmpty().Must((pre) => { return CustomValidator.IsMobile(pre); });
RuleFor(x => x.Mail).EmailAddress().When(pre => { return !string.IsNullOrEmpty(pre.Mail); });
};
RuleSet("Insert", () =>
{
action();
RuleFor(x => x.Password).NotNull().NotEmpty().Length(4, 20);
});
RuleSet("Update", () =>
{
action();
RuleFor(x => x.ID).NotNull().NotEmpty().GreaterThan(0);
RuleFor(x => x.States).NotNull().NotEmpty().InclusiveBetween(1, 2);
});
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace Performance.DtoModels
{
public class HospitalResponse
{
public int HosID { get; set; }
public string HosName { get; set; }
public string ShortName { get; set; }
public string AreaCode { get; set; }
public string HosLevel { get; set; }
public string HosType { get; set; }
public string States { get; set; }
}
}
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
namespace Performance.DtoModels namespace Performance.DtoModels
{ {
public class LoginInfo public class UserIdentity
{ {
public string Token { get; set; } public string Token { get; set; }
public int UserID { get; set; } public int UserID { get; set; }
......
...@@ -11,7 +11,9 @@ public PerformanceDbContext(DbContextOptions<PerformanceDbContext> options) ...@@ -11,7 +11,9 @@ public PerformanceDbContext(DbContextOptions<PerformanceDbContext> options)
{ {
} }
public virtual DbSet<Sys_User> Sys_User { get; set; } public virtual DbSet<sys_user> Sys_User { get; set; }
public virtual DbSet<sys_hospital> Sys_Hospital { get; set; }
public virtual DbSet<sys_sms> Sys_Sms { get; set; }
public virtual DbSet<sys_user_hospital> Sys_User_Hospital { get; set; }
} }
} }
using System; //-----------------------------------------------------------------------
using System.Collections.Generic; // <copyright file=" sys_user.cs">
// * FileName: sys_user.cs
// * history : 2019-03-05 14:05:41
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.ComponentModel.DataAnnotations;
namespace Performance.EntityModels namespace Performance.EntityModels
{ {
public partial class Sys_User /// <summary>
/// sys_user Entity Model
/// </summary>
public class sys_user
{ {
public int ID { get; set; } /// <summary>
public DateTime? CreatDate { get; set; } ///
public int? CreateUser { get; set; } /// </summary>
[Key]
public int ID { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public Nullable<DateTime> CreateDate { get; set; }
/// <summary>
/// 创建人
/// </summary>
public Nullable<int> CreateUser { get; set; }
/// <summary>
/// 真实名称
/// </summary>
public string RealName { get; set; } public string RealName { get; set; }
/// <summary>
/// 手机号
/// </summary>
public string Mobile { get; set; } public string Mobile { get; set; }
/// <summary>
/// 登录名称
/// </summary>
public string Login { get; set; } public string Login { get; set; }
/// <summary>
/// 密码
/// </summary>
public string Password { get; set; } public string Password { get; set; }
/// <summary>
/// 邮箱
/// </summary>
public string Mail { get; set; } public string Mail { get; set; }
public int? States { get; set; }
/// <summary>
/// 用户状态 1启用 2禁用
/// </summary>
public Nullable<int> States { get; set; }
} }
} }
//-----------------------------------------------------------------------
// <copyright file=" dis_drug_tree.cs">
// * FileName: dis_drug_tree.cs
// * history : Created by T4 2019-03-04 14:25:12
// </copyright>
//-----------------------------------------------------------------------
using System;
namespace Performance.EntityModels
{
/// <summary>
/// dis_drug_tree Entity Model
/// </summary>
public partial class dis_drug_tree
{
/// <summary>
/// 主键
/// E:\code_git\performance\performance\Performance.EntityModels\Entity
/// </summary>
public int ID { get; set; }
/// <summary>
/// 省份
/// </summary>
public string province { get; set; }
/// <summary>
/// 医院ID
/// </summary>
public Nullable<int> hospitalid { get; set; }
/// <summary>
/// 年
/// </summary>
public int year { get; set; }
/// <summary>
/// 月
/// </summary>
public int month { get; set; }
/// <summary>
/// 数据源(门诊/住院)
/// </summary>
public string source { get; set; }
/// <summary>
/// 医院等级
/// </summary>
public string hosLevel { get; set; }
/// <summary>
/// 医院性质
/// </summary>
public string hosType { get; set; }
/// <summary>
/// 疾病
/// </summary>
public Nullable<int> disease { get; set; }
/// <summary>
/// 当前名称
/// </summary>
public string currentName { get; set; }
/// <summary>
/// 人次
/// </summary>
public Nullable<int> personTimes { get; set; }
/// <summary>
/// 父级名称
/// </summary>
public string parentName { get; set; }
}
}
//-----------------------------------------------------------------------
// <copyright file=" dis_drug_type.cs">
// * FileName: dis_drug_type.cs
// * history : Created by T4 2019-03-04 14:25:12
// </copyright>
//-----------------------------------------------------------------------
using System;
namespace Performance.EntityModels
{
/// <summary>
/// dis_drug_type Entity Model
/// </summary>
public partial class dis_drug_type
{
/// <summary>
/// 主键
/// E:\code_git\performance\performance\Performance.EntityModels\Entity
/// </summary>
public int ID { get; set; }
/// <summary>
/// 省份
/// </summary>
public string province { get; set; }
/// <summary>
/// 医院ID
/// </summary>
public Nullable<int> hospitalid { get; set; }
/// <summary>
/// 年
/// </summary>
public int year { get; set; }
/// <summary>
/// 月
/// </summary>
public int month { get; set; }
/// <summary>
/// 数据源(门诊/住院)
/// </summary>
public string source { get; set; }
/// <summary>
/// 医院等级
/// </summary>
public string hosLevel { get; set; }
/// <summary>
/// 医院性质
/// </summary>
public string hosType { get; set; }
/// <summary>
/// 疾病
/// </summary>
public Nullable<int> disease { get; set; }
/// <summary>
/// 药物分类(中、西、草)
/// </summary>
public string drugType { get; set; }
/// <summary>
/// 人次
/// </summary>
public Nullable<int> personTimes { get; set; }
/// <summary>
/// 金额
/// </summary>
public Nullable<int> fee { get; set; }
}
}
//-----------------------------------------------------------------------
// <copyright file=" dis_drug_useinfo_fee.cs">
// * FileName: dis_drug_useinfo_fee.cs
// * history : Created by T4 2019-03-04 14:25:12
// </copyright>
//-----------------------------------------------------------------------
using System;
namespace Performance.EntityModels
{
/// <summary>
/// dis_drug_useinfo_fee Entity Model
/// </summary>
public partial class dis_drug_useinfo_fee
{
/// <summary>
/// 主键
/// E:\code_git\performance\performance\Performance.EntityModels\Entity
/// </summary>
public int ID { get; set; }
/// <summary>
/// 省份
/// </summary>
public string province { get; set; }
/// <summary>
/// 医院ID
/// </summary>
public Nullable<int> hospitalid { get; set; }
/// <summary>
/// 年
/// </summary>
public int year { get; set; }
/// <summary>
/// 月
/// </summary>
public int month { get; set; }
/// <summary>
/// 数据源(门诊/住院)
/// </summary>
public string source { get; set; }
/// <summary>
/// 医院等级
/// </summary>
public string hosLevel { get; set; }
/// <summary>
/// 医院性质
/// </summary>
public string hosType { get; set; }
/// <summary>
/// 通用名
/// </summary>
public string commonName { get; set; }
/// <summary>
/// 药品名
/// </summary>
public string drugName { get; set; }
/// <summary>
/// 人次
/// </summary>
public Nullable<int> personTimes { get; set; }
/// <summary>
/// 费用
/// </summary>
public Nullable<int> fee { get; set; }
/// <summary>
/// 病种
/// </summary>
public Nullable<int> disease { get; set; }
}
}
//-----------------------------------------------------------------------
// <copyright file=" dis_drugatc.cs">
// * FileName: dis_drugatc.cs
// * history : Created by T4 2019-03-04 14:25:12
// </copyright>
//-----------------------------------------------------------------------
using System;
namespace Performance.EntityModels
{
/// <summary>
/// dis_drugatc Entity Model
/// </summary>
public partial class dis_drugatc
{
/// <summary>
///
/// E:\code_git\performance\performance\Performance.EntityModels\Entity
/// </summary>
public int ID { get; set; }
/// <summary>
/// 省份
/// </summary>
public string province { get; set; }
/// <summary>
/// 医院ID
/// </summary>
public Nullable<int> hospitalId { get; set; }
/// <summary>
/// 年
/// </summary>
public int year { get; set; }
/// <summary>
/// 月
/// </summary>
public int month { get; set; }
/// <summary>
/// 数据源(门诊/住院)
/// </summary>
public string source { get; set; }
/// <summary>
/// 医院等级
/// </summary>
public string hosLevel { get; set; }
/// <summary>
/// 医院性质
/// </summary>
public string hosType { get; set; }
/// <summary>
/// 商品名
/// </summary>
public string drugName { get; set; }
/// <summary>
/// 药物化学物质
/// </summary>
public string mechanism { get; set; }
/// <summary>
/// 病种
/// </summary>
public Nullable<int> disease { get; set; }
/// <summary>
/// 人次
/// </summary>
public Nullable<int> personTimes { get; set; }
}
}
//-----------------------------------------------------------------------
// <copyright file=" dis_ip_fee.cs">
// * FileName: dis_ip_fee.cs
// * history : Created by T4 2019-03-04 14:25:12
// </copyright>
//-----------------------------------------------------------------------
using System;
namespace Performance.EntityModels
{
/// <summary>
/// dis_ip_fee Entity Model
/// </summary>
public partial class dis_ip_fee
{
/// <summary>
/// 主键
/// E:\code_git\performance\performance\Performance.EntityModels\Entity
/// </summary>
public int ID { get; set; }
/// <summary>
/// 省份
/// </summary>
public string province { get; set; }
/// <summary>
/// 医院ID
/// </summary>
public Nullable<int> hospitalid { get; set; }
/// <summary>
/// 年
/// </summary>
public int year { get; set; }
/// <summary>
/// 月
/// </summary>
public int month { get; set; }
/// <summary>
/// 数据源(门诊/住院)
/// </summary>
public string source { get; set; }
/// <summary>
/// 医院等级
/// </summary>
public string hosLevel { get; set; }
/// <summary>
/// 医院性质
/// </summary>
public string hosType { get; set; }
/// <summary>
/// 手术量
/// </summary>
public Nullable<int> operationNum { get; set; }
/// <summary>
/// 总费用
/// </summary>
public Nullable<int> allFee { get; set; }
/// <summary>
/// 病床使用天数
/// </summary>
public Nullable<int> hosBad { get; set; }
/// <summary>
/// 病种
/// </summary>
public Nullable<int> disease { get; set; }
/// <summary>
/// 药费
/// </summary>
public Nullable<int> fee { get; set; }
/// <summary>
/// 人次
/// </summary>
public Nullable<int> personTimes { get; set; }
/// <summary>
/// 人数
/// </summary>
public Nullable<int> personNum { get; set; }
}
}
//-----------------------------------------------------------------------
// <copyright file=" dis_use_drugs.cs">
// * FileName: dis_use_drugs.cs
// * history : Created by T4 2019-03-04 14:25:12
// </copyright>
//-----------------------------------------------------------------------
using System;
namespace Performance.EntityModels
{
/// <summary>
/// dis_use_drugs Entity Model
/// </summary>
public partial class dis_use_drugs
{
/// <summary>
/// 主键
/// E:\code_git\performance\performance\Performance.EntityModels\Entity
/// </summary>
public int ID { get; set; }
/// <summary>
/// 省份
/// </summary>
public string province { get; set; }
/// <summary>
/// 医院ID
/// </summary>
public Nullable<int> hospitalid { get; set; }
/// <summary>
/// 年
/// </summary>
public int year { get; set; }
/// <summary>
/// 月
/// </summary>
public int month { get; set; }
/// <summary>
/// 数据源(门诊/住院)
/// </summary>
public string source { get; set; }
/// <summary>
/// 医院等级
/// </summary>
public string hosLevel { get; set; }
/// <summary>
/// 医院性质
/// </summary>
public string hosType { get; set; }
/// <summary>
/// 疾病
/// </summary>
public Nullable<int> disease { get; set; }
/// <summary>
/// 通名用
/// </summary>
public string commonName { get; set; }
/// <summary>
/// 人次
/// </summary>
public Nullable<int> personTimes { get; set; }
}
}
//-----------------------------------------------------------------------
// <copyright file=" drug_department_useinfo.cs">
// * FileName: drug_department_useinfo.cs
// * history : Created by T4 2019-03-04 14:25:12
// </copyright>
//-----------------------------------------------------------------------
using System;
namespace Performance.EntityModels
{
/// <summary>
/// drug_department_useinfo Entity Model
/// </summary>
public partial class drug_department_useinfo
{
/// <summary>
///
/// E:\code_git\performance\performance\Performance.EntityModels\Entity
/// </summary>
public int ID { get; set; }
/// <summary>
/// 省份
/// </summary>
public string province { get; set; }
/// <summary>
/// 医院ID
/// </summary>
public Nullable<int> hospitalid { get; set; }
/// <summary>
/// 年
/// </summary>
public int year { get; set; }
/// <summary>
/// 月
/// </summary>
public int month { get; set; }
/// <summary>
/// 数据源(门诊/住院)
/// </summary>
public string source { get; set; }
/// <summary>
/// 医院等级
/// </summary>
public string hosLevel { get; set; }
/// <summary>
/// 医院性质
/// </summary>
public string hosType { get; set; }
/// <summary>
/// 商品名
/// </summary>
public string drugName { get; set; }
/// <summary>
/// 通用名
/// </summary>
public string commonName { get; set; }
/// <summary>
/// 科室
/// </summary>
public string department { get; set; }
/// <summary>
/// 人次
/// </summary>
public Nullable<int> personTimes { get; set; }
}
}
//-----------------------------------------------------------------------
// <copyright file=" drug_dosage.cs">
// * FileName: drug_dosage.cs
// * history : Created by T4 2019-03-04 14:25:12
// </copyright>
//-----------------------------------------------------------------------
using System;
namespace Performance.EntityModels
{
/// <summary>
/// drug_dosage Entity Model
/// </summary>
public partial class drug_dosage
{
/// <summary>
///
/// E:\code_git\performance\performance\Performance.EntityModels\Entity
/// </summary>
public int ID { get; set; }
/// <summary>
/// 省份
/// </summary>
public string province { get; set; }
/// <summary>
/// 医院ID
/// </summary>
public Nullable<int> hospitalid { get; set; }
/// <summary>
/// 年
/// </summary>
public int year { get; set; }
/// <summary>
/// 月
/// </summary>
public int month { get; set; }
/// <summary>
/// 数据源(门诊/住院)
/// </summary>
public string source { get; set; }
/// <summary>
/// 医院等级
/// </summary>
public string hosLevel { get; set; }
/// <summary>
/// 医院性质
/// </summary>
public string hosType { get; set; }
/// <summary>
/// 商品名
/// </summary>
public string drugName { get; set; }
/// <summary>
/// 通用名
/// </summary>
public string commonName { get; set; }
/// <summary>
/// 剂型
/// </summary>
public string dosage { get; set; }
/// <summary>
/// 人次
/// </summary>
public Nullable<int> personTimes { get; set; }
}
}
//-----------------------------------------------------------------------
// <copyright file=" drug_first_use.cs">
// * FileName: drug_first_use.cs
// * history : Created by T4 2019-03-04 14:25:12
// </copyright>
//-----------------------------------------------------------------------
using System;
namespace Performance.EntityModels
{
/// <summary>
/// drug_first_use Entity Model
/// </summary>
public partial class drug_first_use
{
/// <summary>
/// 主键
/// E:\code_git\performance\performance\Performance.EntityModels\Entity
/// </summary>
public int ID { get; set; }
/// <summary>
/// 省份
/// </summary>
public string province { get; set; }
/// <summary>
/// 医院ID
/// </summary>
public Nullable<int> hospitalid { get; set; }
/// <summary>
/// 年
/// </summary>
public int year { get; set; }
/// <summary>
/// 月
/// </summary>
public int month { get; set; }
/// <summary>
/// 数据源(门诊/住院)
/// </summary>
public string source { get; set; }
/// <summary>
/// 医院等级
/// </summary>
public string hosLevel { get; set; }
/// <summary>
/// 医院性质
/// </summary>
public string hosType { get; set; }
/// <summary>
/// 通用名
/// </summary>
public string commonName { get; set; }
/// <summary>
/// 商品名
/// </summary>
public string drugname { get; set; }
/// <summary>
/// 人次
/// </summary>
public Nullable<int> personTimes { get; set; }
}
}
//-----------------------------------------------------------------------
// <copyright file=" drug_hosinfo.cs">
// * FileName: drug_hosinfo.cs
// * history : Created by T4 2019-03-04 14:25:12
// </copyright>
//-----------------------------------------------------------------------
using System;
namespace Performance.EntityModels
{
/// <summary>
/// drug_hosinfo Entity Model
/// </summary>
public partial class drug_hosinfo
{
/// <summary>
///
/// E:\code_git\performance\performance\Performance.EntityModels\Entity
/// </summary>
public int ID { get; set; }
/// <summary>
/// 省份
/// </summary>
public string province { get; set; }
/// <summary>
/// 医院ID
/// </summary>
public Nullable<int> hospitalid { get; set; }
/// <summary>
/// 年
/// </summary>
public int year { get; set; }
/// <summary>
/// 月
/// </summary>
public int month { get; set; }
/// <summary>
/// 数据源(门诊/住院)
/// </summary>
public string source { get; set; }
/// <summary>
/// 医院等级
/// </summary>
public string hosLevel { get; set; }
/// <summary>
/// 医院性质
/// </summary>
public string hosType { get; set; }
/// <summary>
/// 商品名
/// </summary>
public string drugName { get; set; }
/// <summary>
/// 通用名
/// </summary>
public string commonName { get; set; }
/// <summary>
/// 人次
/// </summary>
public Nullable<int> personTimes { get; set; }
}
}
//-----------------------------------------------------------------------
// <copyright file=" drug_p_info.cs">
// * FileName: drug_p_info.cs
// * history : Created by T4 2019-03-04 14:25:12
// </copyright>
//-----------------------------------------------------------------------
using System;
namespace Performance.EntityModels
{
/// <summary>
/// drug_p_info Entity Model
/// </summary>
public partial class drug_p_info
{
/// <summary>
///
/// E:\code_git\performance\performance\Performance.EntityModels\Entity
/// </summary>
public int ID { get; set; }
/// <summary>
/// 省份
/// </summary>
public string province { get; set; }
/// <summary>
/// 医院ID
/// </summary>
public Nullable<int> hospitalid { get; set; }
/// <summary>
/// 年
/// </summary>
public int year { get; set; }
/// <summary>
/// 月
/// </summary>
public int month { get; set; }
/// <summary>
/// 数据源(门诊/住院)
/// </summary>
public string source { get; set; }
/// <summary>
/// 医院等级
/// </summary>
public string hosLevel { get; set; }
/// <summary>
/// 医院性质
/// </summary>
public string hosType { get; set; }
/// <summary>
/// 商品名
/// </summary>
public string drugName { get; set; }
/// <summary>
/// 通用名
/// </summary>
public string commonName { get; set; }
/// <summary>
/// 人次
/// </summary>
public Nullable<int> personTimes { get; set; }
/// <summary>
/// 费用
/// </summary>
public Nullable<int> fee { get; set; }
/// <summary>
/// 病种
/// </summary>
public string disease { get; set; }
/// <summary>
///
/// </summary>
public Nullable<int> dis_person_times { get; set; }
/// <summary>
///
/// </summary>
public Nullable<int> dis_fee { get; set; }
}
}
//-----------------------------------------------------------------------
// <copyright file=" drug_p_mi.cs">
// * FileName: drug_p_mi.cs
// * history : Created by T4 2019-03-04 14:25:12
// </copyright>
//-----------------------------------------------------------------------
using System;
namespace Performance.EntityModels
{
/// <summary>
/// drug_p_mi Entity Model
/// </summary>
public partial class drug_p_mi
{
/// <summary>
///
/// E:\code_git\performance\performance\Performance.EntityModels\Entity
/// </summary>
public int ID { get; set; }
/// <summary>
/// 省份
/// </summary>
public string province { get; set; }
/// <summary>
/// 医院ID
/// </summary>
public Nullable<int> hospitalid { get; set; }
/// <summary>
/// 年
/// </summary>
public int year { get; set; }
/// <summary>
/// 月
/// </summary>
public int month { get; set; }
/// <summary>
/// 数据源(门诊/住院)
/// </summary>
public string source { get; set; }
/// <summary>
/// 医院等级
/// </summary>
public string hosLevel { get; set; }
/// <summary>
/// 医院性质
/// </summary>
public string hosType { get; set; }
/// <summary>
/// 人次
/// </summary>
public Nullable<int> personTimes { get; set; }
/// <summary>
/// 医保类型
/// </summary>
public string medicalInsurance { get; set; }
/// <summary>
/// 商品名
/// </summary>
public string drugName { get; set; }
/// <summary>
/// 通用名
/// </summary>
public string commonName { get; set; }
}
}
//-----------------------------------------------------------------------
// <copyright file=" drug_p_userinfo.cs">
// * FileName: drug_p_userinfo.cs
// * history : Created by T4 2019-03-04 14:25:12
// </copyright>
//-----------------------------------------------------------------------
using System;
namespace Performance.EntityModels
{
/// <summary>
/// drug_p_userinfo Entity Model
/// </summary>
public partial class drug_p_userinfo
{
/// <summary>
///
/// E:\code_git\performance\performance\Performance.EntityModels\Entity
/// </summary>
public int ID { get; set; }
/// <summary>
/// 省份
/// </summary>
public string province { get; set; }
/// <summary>
/// 医院ID
/// </summary>
public Nullable<int> hospitalid { get; set; }
/// <summary>
/// 年
/// </summary>
public int year { get; set; }
/// <summary>
/// 月
/// </summary>
public int month { get; set; }
/// <summary>
/// 数据源(门诊/住院)
/// </summary>
public string source { get; set; }
/// <summary>
/// 医院等级
/// </summary>
public string hosLevel { get; set; }
/// <summary>
/// 医院性质
/// </summary>
public string hosType { get; set; }
/// <summary>
/// 商品名
/// </summary>
public string drugName { get; set; }
/// <summary>
/// 通用名
/// </summary>
public string commonName { get; set; }
/// <summary>
/// 性别
/// </summary>
public string sex { get; set; }
/// <summary>
/// 年龄
/// </summary>
public Nullable<int> age { get; set; }
/// <summary>
/// 人次
/// </summary>
public Nullable<int> personTimes { get; set; }
}
}
//-----------------------------------------------------------------------
// <copyright file=" drug_som.cs">
// * FileName: drug_som.cs
// * history : Created by T4 2019-03-04 14:25:12
// </copyright>
//-----------------------------------------------------------------------
using System;
namespace Performance.EntityModels
{
/// <summary>
/// drug_som Entity Model
/// </summary>
public partial class drug_som
{
/// <summary>
///
/// E:\code_git\performance\performance\Performance.EntityModels\Entity
/// </summary>
public int ID { get; set; }
/// <summary>
/// 省份
/// </summary>
public string province { get; set; }
/// <summary>
/// 医院ID
/// </summary>
public Nullable<int> hospitalid { get; set; }
/// <summary>
/// 年
/// </summary>
public int year { get; set; }
/// <summary>
/// 月
/// </summary>
public int month { get; set; }
/// <summary>
/// 数据源(门诊/住院)
/// </summary>
public string source { get; set; }
/// <summary>
/// 医院等级
/// </summary>
public string hosLevel { get; set; }
/// <summary>
/// 医院性质
/// </summary>
public string hosType { get; set; }
/// <summary>
/// 商品名
/// </summary>
public string drugName { get; set; }
/// <summary>
/// 通用名
/// </summary>
public string commonName { get; set; }
/// <summary>
/// 人次
/// </summary>
public Nullable<int> personTimes { get; set; }
/// <summary>
/// 费用
/// </summary>
public Nullable<int> fee { get; set; }
}
}
//-----------------------------------------------------------------------
// <copyright file=" hos_department_coc.cs">
// * FileName: hos_department_coc.cs
// * history : Created by T4 2019-03-04 14:25:12
// </copyright>
//-----------------------------------------------------------------------
using System;
namespace Performance.EntityModels
{
/// <summary>
/// hos_department_coc Entity Model
/// </summary>
public partial class hos_department_coc
{
/// <summary>
/// 主键
/// E:\code_git\performance\performance\Performance.EntityModels\Entity
/// </summary>
public int ID { get; set; }
/// <summary>
/// 省份
/// </summary>
public string province { get; set; }
/// <summary>
/// 医院ID
/// </summary>
public Nullable<int> hospitalid { get; set; }
/// <summary>
/// 年
/// </summary>
public int year { get; set; }
/// <summary>
/// 月
/// </summary>
public int month { get; set; }
/// <summary>
/// 数据源(门诊/住院)
/// </summary>
public string source { get; set; }
/// <summary>
/// 医院等级
/// </summary>
public string hosLevel { get; set; }
/// <summary>
/// 医院性质
/// </summary>
public string hosType { get; set; }
/// <summary>
/// 科室
/// </summary>
public string department { get; set; }
/// <summary>
/// 耗材金额
/// </summary>
public Nullable<int> fee { get; set; }
}
}
//-----------------------------------------------------------------------
// <copyright file=" hos_department_fee.cs">
// * FileName: hos_department_fee.cs
// * history : Created by T4 2019-03-04 14:25:12
// </copyright>
//-----------------------------------------------------------------------
using System;
namespace Performance.EntityModels
{
/// <summary>
/// hos_department_fee Entity Model
/// </summary>
public partial class hos_department_fee
{
/// <summary>
/// 主键
/// E:\code_git\performance\performance\Performance.EntityModels\Entity
/// </summary>
public int ID { get; set; }
/// <summary>
/// 省份
/// </summary>
public string province { get; set; }
/// <summary>
/// 医院ID
/// </summary>
public Nullable<int> hospitalid { get; set; }
/// <summary>
/// 年
/// </summary>
public int year { get; set; }
/// <summary>
/// 月
/// </summary>
public int month { get; set; }
/// <summary>
/// 数据源(门诊/住院)
/// </summary>
public string source { get; set; }
/// <summary>
/// 医院等级
/// </summary>
public string hosLevel { get; set; }
/// <summary>
/// 医院性质
/// </summary>
public string hosType { get; set; }
/// <summary>
/// 科室
/// </summary>
public string department { get; set; }
/// <summary>
/// 药品金额
/// </summary>
public Nullable<int> fee { get; set; }
}
}
//-----------------------------------------------------------------------
// <copyright file=" hos_disease_person.cs">
// * FileName: hos_disease_person.cs
// * history : Created by T4 2019-03-04 14:25:12
// </copyright>
//-----------------------------------------------------------------------
using System;
namespace Performance.EntityModels
{
/// <summary>
/// hos_disease_person Entity Model
/// </summary>
public partial class hos_disease_person
{
/// <summary>
/// 主键
/// E:\code_git\performance\performance\Performance.EntityModels\Entity
/// </summary>
public int ID { get; set; }
/// <summary>
/// 省份
/// </summary>
public string province { get; set; }
/// <summary>
/// 医院ID
/// </summary>
public Nullable<int> hospitalid { get; set; }
/// <summary>
/// 年
/// </summary>
public int year { get; set; }
/// <summary>
/// 月
/// </summary>
public int month { get; set; }
/// <summary>
/// 数据源(门诊/住院)
/// </summary>
public string source { get; set; }
/// <summary>
/// 医院等级
/// </summary>
public string hosLevel { get; set; }
/// <summary>
/// 医院性质
/// </summary>
public string hosType { get; set; }
/// <summary>
/// 病种
/// </summary>
public string disease { get; set; }
/// <summary>
/// 人次
/// </summary>
public Nullable<int> persontimes { get; set; }
}
}
//-----------------------------------------------------------------------
// <copyright file=" hos_drug_fee.cs">
// * FileName: hos_drug_fee.cs
// * history : Created by T4 2019-03-04 14:25:12
// </copyright>
//-----------------------------------------------------------------------
using System;
namespace Performance.EntityModels
{
/// <summary>
/// hos_drug_fee Entity Model
/// </summary>
public partial class hos_drug_fee
{
/// <summary>
/// 主键
/// E:\code_git\performance\performance\Performance.EntityModels\Entity
/// </summary>
public int ID { get; set; }
/// <summary>
/// 省份
/// </summary>
public string province { get; set; }
/// <summary>
/// 医院ID
/// </summary>
public Nullable<int> hospitalid { get; set; }
/// <summary>
/// 年
/// </summary>
public int year { get; set; }
/// <summary>
/// 月
/// </summary>
public int month { get; set; }
/// <summary>
/// 数据源(门诊/住院)
/// </summary>
public string source { get; set; }
/// <summary>
/// 医院等级
/// </summary>
public string hosLevel { get; set; }
/// <summary>
/// 医院性质
/// </summary>
public string hosType { get; set; }
/// <summary>
/// 药品名
/// </summary>
public string drugName { get; set; }
/// <summary>
/// 药品费用
/// </summary>
public Nullable<int> fee { get; set; }
/// <summary>
///
/// </summary>
public string commonName { get; set; }
/// <summary>
///
/// </summary>
public Nullable<int> personTimes { get; set; }
/// <summary>
///
/// </summary>
public string drugtype { get; set; }
}
}
//-----------------------------------------------------------------------
// <copyright file=" hos_drug_type.cs">
// * FileName: hos_drug_type.cs
// * history : Created by T4 2019-03-04 14:25:12
// </copyright>
//-----------------------------------------------------------------------
using System;
namespace Performance.EntityModels
{
/// <summary>
/// hos_drug_type Entity Model
/// </summary>
public partial class hos_drug_type
{
/// <summary>
/// 主键
/// E:\code_git\performance\performance\Performance.EntityModels\Entity
/// </summary>
public int ID { get; set; }
/// <summary>
/// 省份
/// </summary>
public string province { get; set; }
/// <summary>
/// 医院ID
/// </summary>
public Nullable<int> hospitalid { get; set; }
/// <summary>
/// 年
/// </summary>
public int year { get; set; }
/// <summary>
/// 月
/// </summary>
public int month { get; set; }
/// <summary>
/// 数据源(门诊/住院)
/// </summary>
public string source { get; set; }
/// <summary>
/// 医院等级
/// </summary>
public string hosLevel { get; set; }
/// <summary>
/// 医院性质
/// </summary>
public string hosType { get; set; }
/// <summary>
/// 药品名
/// </summary>
public string drugType { get; set; }
/// <summary>
/// 人次
/// </summary>
public Nullable<int> personTimes { get; set; }
/// <summary>
/// 金额
/// </summary>
public Nullable<int> fee { get; set; }
}
}
//-----------------------------------------------------------------------
// <copyright file=" hos_drugatc.cs">
// * FileName: hos_drugatc.cs
// * history : Created by T4 2019-03-04 14:25:12
// </copyright>
//-----------------------------------------------------------------------
using System;
namespace Performance.EntityModels
{
/// <summary>
/// hos_drugatc Entity Model
/// </summary>
public partial class hos_drugatc
{
/// <summary>
/// ID
/// E:\code_git\performance\performance\Performance.EntityModels\Entity
/// </summary>
public int ID { get; set; }
/// <summary>
/// 省份
/// </summary>
public string province { get; set; }
/// <summary>
/// 医院ID
/// </summary>
public Nullable<int> hospitalid { get; set; }
/// <summary>
/// 年
/// </summary>
public int year { get; set; }
/// <summary>
/// 月
/// </summary>
public int month { get; set; }
/// <summary>
/// 数据源(门诊/住院)
/// </summary>
public string source { get; set; }
/// <summary>
/// 医院等级
/// </summary>
public string hosLevel { get; set; }
/// <summary>
/// 医院性质
/// </summary>
public string hosType { get; set; }
/// <summary>
/// 药物化学物质
/// </summary>
public string mechanism { get; set; }
/// <summary>
/// 金额
/// </summary>
public decimal fee { get; set; }
}
}
//-----------------------------------------------------------------------
// <copyright file=" sys_hospital.cs">
// * FileName: sys_hospital.cs
// * history : 2019-03-05 14:05:41
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.ComponentModel.DataAnnotations;
namespace Performance.EntityModels
{
/// <summary>
/// sys_hospital Entity Model
/// </summary>
public class sys_hospital
{
/// <summary>
/// ID
/// </summary>
[Key]
public int ID { get; set; }
/// <summary>
///
/// </summary>
public Nullable<DateTime> CreateDate { get; set; }
/// <summary>
///
/// </summary>
public Nullable<int> CreateUser { get; set; }
/// <summary>
/// 医院名称
/// </summary>
public string HosName { get; set; }
/// <summary>
/// 简称
/// </summary>
public string ShortName { get; set; }
/// <summary>
/// 医院区域编码
/// </summary>
public string AreaCode { get; set; }
/// <summary>
/// 医院等级
/// </summary>
public string HosLevel { get; set; }
/// <summary>
/// 医院类型
/// </summary>
public string HosType { get; set; }
/// <summary>
/// 医院状态 1 启用 2 禁用
/// </summary>
public Nullable<int> States { get; set; }
}
}
//-----------------------------------------------------------------------
// <copyright file=" sys_sms.cs">
// * FileName: sys_sms.cs
// * history : 2019-03-05 11:49:50
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.ComponentModel.DataAnnotations;
namespace Performance.EntityModels
{
/// <summary>
/// sys_sms Entity Model
/// </summary>
public class sys_sms
{
/// <summary>
///
/// </summary>
[Key]
public int ID { get; set; }
/// <summary>
///
/// </summary>
public Nullable<int> CreateUser { get; set; }
/// <summary>
///
/// </summary>
public Nullable<DateTime> CreateDate { get; set; }
/// <summary>
/// 手机号
/// </summary>
public string Mobile { get; set; }
/// <summary>
/// 验证码
/// </summary>
public string SmsCode { get; set; }
/// <summary>
/// 过期时间
/// </summary>
public DateTime Expiration { get; set; }
/// <summary>
/// 验证码类型 1 登录 2 其他
/// </summary>
public int CodeType { get; set; }
}
}
//-----------------------------------------------------------------------
// <copyright file=" sys_user_hospital.cs">
// * FileName: sys_user_hospital.cs
// * history : 2019-03-05 11:49:50
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.ComponentModel.DataAnnotations;
namespace Performance.EntityModels
{
/// <summary>
/// sys_user_hospital Entity Model
/// </summary>
public class sys_user_hospital
{
/// <summary>
///
/// </summary>
[Key]
public int ID { get; set; }
/// <summary>
///
/// </summary>
public Nullable<int> UserID { get; set; }
/// <summary>
///
/// </summary>
public Nullable<int> HosID { get; set; }
}
}
...@@ -11,6 +11,29 @@ ...@@ -11,6 +11,29 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Remove="Entity\dis_drugatc.Generated.cs" />
<Compile Remove="Entity\dis_drug_tree.Generated.cs" />
<Compile Remove="Entity\dis_drug_type.Generated.cs" />
<Compile Remove="Entity\dis_drug_useinfo_fee.Generated.cs" />
<Compile Remove="Entity\dis_ip_fee.Generated.cs" />
<Compile Remove="Entity\dis_use_drugs.Generated.cs" />
<Compile Remove="Entity\drug_department_useinfo.Generated.cs" />
<Compile Remove="Entity\drug_dosage.Generated.cs" />
<Compile Remove="Entity\drug_first_use.Generated.cs" />
<Compile Remove="Entity\drug_hosinfo.Generated.cs" />
<Compile Remove="Entity\drug_p_info.Generated.cs" />
<Compile Remove="Entity\drug_p_mi.Generated.cs" />
<Compile Remove="Entity\drug_p_userinfo.Generated.cs" />
<Compile Remove="Entity\drug_som.Generated.cs" />
<Compile Remove="Entity\hos_department_coc.Generated.cs" />
<Compile Remove="Entity\hos_department_fee.Generated.cs" />
<Compile Remove="Entity\hos_disease_person.Generated.cs" />
<Compile Remove="Entity\hos_drugatc.Generated.cs" />
<Compile Remove="Entity\hos_drug_fee.Generated.cs" />
<Compile Remove="Entity\hos_drug_type.Generated.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.0" />
</ItemGroup> </ItemGroup>
......
using System;
using System.IO;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Text;
namespace Performance.Infrastructure
{
public class HttpHelper
{
#region 发送post请求
/// <summary>
/// 发送post请求
/// </summary>
/// <param name="Url"></param>
/// <param name="postDataStr"></param>
/// <returns></returns>
public static string HttpPost(string Url, string postDataStr, string encoding = "utf-8", bool IsJson = false)
{
HttpWebResponse response = null;
HttpWebRequest request = null;
string retString = "";
if (Url.ToLower().StartsWith("https"))
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);//验证服务器证书回调自动验证
try
{
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
System.GC.Collect();
request = (HttpWebRequest)WebRequest.Create(Url);
request.Method = "POST";
request.KeepAlive = false;
request.ProtocolVersion = HttpVersion.Version10;
if (IsJson)
request.ContentType = "application/json";
else
request.ContentType = "application/x-www-form-urlencoded";
byte[] bData = (Encoding.UTF8.GetBytes(postDataStr));
request.ContentLength = bData.Length;
Stream writeStream = request.GetRequestStream();
writeStream.Write(bData, 0, bData.Length);
writeStream.Close();
using (response = (HttpWebResponse)request.GetResponse())
{
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding(encoding));
retString = myStreamReader.ReadToEnd();
myStreamReader.Close();
myResponseStream.Close();
return retString;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (request != null)
request.Abort();
if (response != null)
response.Close();
}
}
#endregion 发送post请求
public static string HttpPost(string Url, string postDataStr, bool IsJson)
{
return HttpPost(Url, postDataStr, "utf-8", IsJson);
}
#region 发送get请求
/// <summary>
/// 发送get请求
/// </summary>
/// <param name="Url"></param>
/// <param name="postDataStr"></param>
/// <returns></returns>
public static string HttpGet(string Url, string postDataStr, string encoding = "utf-8")
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url + (postDataStr == "" ? "" : "?") + postDataStr);
request.Method = "GET";
request.ContentType = "text/html;charset=UTF-8";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream myResponseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding(encoding));
string retString = myStreamReader.ReadToEnd();
myStreamReader.Close();
myResponseStream.Close();
return retString;
}
#endregion 发送get请求
public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{ // 总是接受
return true;
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Text;
namespace Performance.Infrastructure
{
public class RandomHelper
{
/// <summary>
/// 四位验证码
/// </summary>
/// <returns></returns>
public static string GetSmsCode()
{
Random rad = new Random(Guid.NewGuid().GetHashCode());
var code = rad.Next(1000, 10000);
return code.ToString().PadLeft(4, '0');
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace Performance.Infrastructure
{
public class VerificationHelper
{
/// <summary>
/// 判断输入的字符串是否是一个合法的手机号
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public static bool IsMobilePhone(string input)
{
if (string.IsNullOrEmpty(input))
{
return false;
}
Regex regex = new Regex("^1[34578]\\d{9}$");
return regex.IsMatch(input);
}
}
}
using System;
using System.Collections;
using System.IO;
using System.Text;
using System.Xml.Serialization;
namespace Performance.Infrastructure
{
/// <summary>
/// XML序列化、反序列化工具类
/// </summary>
public class XMLSerializer
{
public XMLSerializer() : this("utf-8") { }
public XMLSerializer(string encodName)
{
EncodName = encodName;
}
public string EncodName { get; set; }
/// <summary>
/// 序列化器缓存
/// </summary>
private static Hashtable serializers = Hashtable.Synchronized(new Hashtable());
/// <summary>
/// 一个空的命名空间
/// </summary>
private static XmlSerializerNamespaces xmlNs = GetXmlNameSpace();
/// <summary>
/// 从字符串中反序列化一个T类型对象
/// </summary>
/// <typeparam name="T">序列化、反序列化对象的类型</typeparam>
/// <param name="source">T类型的格式化字符串</param>
/// <returns>T类型对象</returns>
public T Deserialize<T>(string source)
where T : class
{
MemoryStream stream = new MemoryStream(Encoding.GetEncoding(EncodName).GetBytes(source));
return Deserialize<T>(stream);
}
/// <summary>
/// 从当前流中反序列化一个T类型对象
/// </summary>
/// <typeparam name="T">序列化、反序列化对象的类型</typeparam>
/// <param name="source">T类型的流</param>
/// <returns>T类型对象</returns>
public T Deserialize<T>(System.IO.Stream source)
where T : class
{
XmlSerializer serializer = GetXmlSerializer(typeof(T));
T objRet = (T)serializer.Deserialize(source);
return objRet;
}
/// <summary>
/// 从当前字节串中反序列化一个T类型对象
/// </summary>
/// <typeparam name="T">序列化、反序列化对象的类型</typeparam>
/// <param name="source">T类型的字节串</param>
/// <returns>T类型对象</returns>
public T Deserialize<T>(byte[] source)
where T : class
{
if (source == null || source.Length == 0)
return default(T);
using (MemoryStream ms = new MemoryStream())
{
ms.Write(source, 0, source.Length);
ms.Position = 0;
return Deserialize<T>(ms);
}
}
/// <summary>
/// 从文件中反序列化一个T类型对象
/// </summary>
/// <typeparam name="T">序列化、反序列化对象的类型</typeparam>
/// <param name="fileName">T类型的格式化文件</param>
/// <returns>T类型对象</returns>
public T DeserializeFromFile<T>(string fileName)
where T : class
{
using (TextReader tr = new StreamReader(fileName, Encoding.UTF8))
{
XmlSerializer serializer = GetXmlSerializer(typeof(T));
T objRet = (T)serializer.Deserialize(tr);
return objRet;
}
}
/// <summary>
/// 将T类序列化为一个字符串
/// </summary>
/// <typeparam name="T">序列化、反序列化对象的类型</typeparam>
/// <param name="t">T类型对象</param>
/// <returns>T类型的格式化字符串</returns>
public string Serialize<T>(T t)
where T : class
{
string retSerialXml = "";
MemoryStream stream = new MemoryStream();
XmlSerializer serializer = GetXmlSerializer(typeof(T));
serializer.Serialize(stream, t, xmlNs);
retSerialXml = Encoding.GetEncoding(EncodName).GetString(stream.GetBuffer());
return retSerialXml.Trim('\0');
}
/// <summary>
/// 将T类序列化到一个流中
/// </summary>
/// <typeparam name="T">序列化、反序列化对象的类型</typeparam>
/// <param name="t">T类型对象</param>
/// <param name="destination">流</param>
public void Serialize<T>(T t, System.IO.Stream destination)
where T : class
{
XmlSerializer serializer = GetXmlSerializer(typeof(T));
serializer.Serialize(destination, t, xmlNs);
}
/// <summary>
/// 将T类序列化到一个字节序列中
/// </summary>
/// <typeparam name="T">序列化、反序列化对象的类型</typeparam>
/// <param name="t">T类型对象</param>
/// <param name="buf">字节序列</param>
public void Serialize<T>(T t, ref byte[] buf)
where T : class
{
MemoryStream stream = new MemoryStream();
XmlSerializer serializer = GetXmlSerializer(typeof(T));
serializer.Serialize(stream, t, xmlNs);
buf = stream.GetBuffer();
}
/// <summary>
/// 将T类序列化到一个文件中
/// </summary>
/// <typeparam name="T">序列化、反序列化对象的类型</typeparam>
/// <param name="t">T类型对象</param>
/// <param name="fileName">输出的文件名</param>
public void Serialize<T>(T t, string fileName)
where T : class
{
using (TextWriter writer = new StreamWriter(fileName))
{
XmlSerializer serializer = GetXmlSerializer(typeof(T));
serializer.Serialize(writer, t, xmlNs);
}
}
/// <summary>
/// 从缓存中获取一个XML序列化对象,如果没有,则创建,并添加到缓存中
/// </summary>
/// <returns>XML序列化对象</returns>
private XmlSerializer GetXmlSerializer(Type objType)
{
if (objType == null)
return null;
if (serializers.ContainsKey(objType.FullName))
return (XmlSerializer)serializers[objType.FullName];
else
{
if (serializers.Count >= 100)
serializers.Clear();
XmlSerializer serializer = new XmlSerializer(objType);
serializers.Add(objType.FullName, serializer);
return serializer;
}
}
/// <summary>
/// 获取一个空的命名空间
/// </summary>
/// <returns>空命名空间</returns>
private static XmlSerializerNamespaces GetXmlNameSpace()
{
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("", "");
return ns;
}
}
}
\ No newline at end of file
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
</ItemGroup> </ItemGroup>
......
 using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Performance.Infrastructure;
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
namespace Performance.Infrastructure
{
public class HuyiSmsConfig
{
public string Url { get; set; }
public string Account { get; set; }
public string Password { get; set; }
}
public class HuyiSmsNotify
{
private HuyiSmsConfig _config;
private readonly ILogger<HuyiSmsNotify> _logger;
public HuyiSmsNotify(IOptions<HuyiSmsConfig> config, ILoggerFactory factory)
{
this._logger = factory.CreateLogger<HuyiSmsNotify>();
_config = config.Value;
}
public HuyiResponse SendSms(string mobile, string content)
{
var cfg = _config;
string postBody = $"account={cfg.Account}&password={cfg.Password}&mobile={mobile}&content={content}";
UTF8Encoding encoding = new UTF8Encoding();
byte[] postData = encoding.GetBytes(postBody);
var response = HttpHelper.HttpPost(cfg.Url, postBody, false);
_logger.LogInformation(response);
var serializer = new XMLSerializer();
return serializer.Deserialize<HuyiResponse>(response);
}
}
[XmlRoot(ElementName = "SubmitResult", Namespace = "http://106.ihuyi.cn/")]
public class HuyiResponse
{
[XmlElement("code")]
public string code { get; set; }
[XmlElement("msg")]
public string msg { get; set; }
[XmlElement("smsid")]
public string smsid { get; set; }
}
}
using Microsoft.EntityFrameworkCore; using Dapper;
using Microsoft.EntityFrameworkCore;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
...@@ -18,6 +19,15 @@ public BaseRepository(DbContext context) ...@@ -18,6 +19,15 @@ public BaseRepository(DbContext context)
this.context = context; this.context = context;
} }
public TEntity DapperQueryFirst(string sql, object param)
{
return context.Database.GetDbConnection().QueryFirst<TEntity>(sql, param);
}
public IEnumerable<TEntity> DapperQuery(string sql, object param)
{
return context.Database.GetDbConnection().Query<TEntity>(sql, param);
}
public bool Add(TEntity entity) public bool Add(TEntity entity)
{ {
context.Set<TEntity>().Add(entity); context.Set<TEntity>().Add(entity);
...@@ -41,18 +51,22 @@ public bool AddRange(params TEntity[] entities) ...@@ -41,18 +51,22 @@ public bool AddRange(params TEntity[] entities)
await context.Set<TEntity>().AddRangeAsync(entities); await context.Set<TEntity>().AddRangeAsync(entities);
return await context.SaveChangesAsync() > 0; return await context.SaveChangesAsync() > 0;
} }
public bool Remove(TEntity entity)
public async Task<bool> Delete(TEntity entity)
{ {
context.Set<TEntity>().Remove(entity); context.Set<TEntity>().Remove(entity);
return await context.SaveChangesAsync() > 0; return context.SaveChanges() > 0;
}
public bool RemoveRange(params TEntity[] entities)
{
context.Set<TEntity>().RemoveRange(entities);
return context.SaveChanges() > 0;
} }
public async Task<bool> Update(TEntity entity) public bool Update(TEntity entity)
{ {
context.Set<TEntity>().Update(entity); context.Set<TEntity>().Update(entity);
return await context.SaveChangesAsync() > 0; return context.SaveChanges() > 0;
} }
public IEnumerable<TEntity> GetEntities() public IEnumerable<TEntity> GetEntities()
......
//-----------------------------------------------------------------------
// <copyright file=" sys_hospital.cs">
// * FileName: sys_hospital.cs
// * history : Created by T4 2019-03-04 14:41:21
// </copyright>
//-----------------------------------------------------------------------
using Performance.EntityModels;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Performance.Repository
{
/// <summary>
/// sys_hospital Repository
/// </summary>
public class PerforHospitalRepository : PerforRepository<sys_hospital>
{
public PerforHospitalRepository(PerformanceDbContext context) : base(context)
{
}
}
}
//-----------------------------------------------------------------------
// <copyright file=" sys_sms.cs">
// * FileName: sys_sms.cs
// * history : Created by T4 2019-03-04 14:41:21
// </copyright>
//-----------------------------------------------------------------------
using Performance.EntityModels;
using System;
namespace Performance.Repository
{
/// <summary>
/// sys_sms Repository
/// </summary>
public class PerforSmsRepository : PerforRepository<sys_sms>
{
public PerforSmsRepository(PerformanceDbContext context) : base(context)
{
}
}
}
//-----------------------------------------------------------------------
// <copyright file=" sys_user_hospital.cs">
// * FileName: sys_user_hospital.cs
// * history : Created by T4 2019-03-04 14:41:21
// </copyright>
//-----------------------------------------------------------------------
using Performance.EntityModels;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Performance.Repository
{
/// <summary>
/// sys_user_hospital Repository
/// </summary>
public class PerforUserhospitalRepository : PerforRepository<sys_user_hospital>
{
public PerforUserhospitalRepository(PerformanceDbContext context) : base(context)
{
}
public List<sys_user_hospital> GetUserHospital(int userid)
{
string sql = "select * from sys_user_hospital where userid=@userid";
return DapperQuery(sql, new { userid }).ToList();
}
}
}
using Performance.EntityModels; //-----------------------------------------------------------------------
// <copyright file=" sys_user.cs">
// * FileName: sys_user.cs
// * history : Created by T4 2019-03-04 14:41:21
// </copyright>
//-----------------------------------------------------------------------
using Performance.EntityModels;
using System; using System;
using System.Collections.Generic;
using System.Text;
namespace Performance.Repository namespace Performance.Repository
{ {
public class PerforUserRepository : PerforRepository<Sys_User> /// <summary>
/// sys_user Repository
/// </summary>
public class PerforUserRepository : PerforRepository<sys_user>
{ {
public PerforUserRepository(PerformanceDbContext context) : base(context) public PerforUserRepository(PerformanceDbContext context) : base(context)
{ {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Dapper" Version="1.60.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.0" />
<PackageReference Include="MySql.Data" Version="8.0.15" /> <PackageReference Include="MySql.Data" Version="8.0.15" />
<PackageReference Include="MySql.Data.EntityFrameworkCore" Version="8.0.15" /> <PackageReference Include="MySql.Data.EntityFrameworkCore" Version="8.0.15" />
......
using AutoMapper;
using Performance.DtoModels;
using Performance.EntityModels;
using Performance.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Performance.Services
{
public class HospitalService : IAutoInjection
{
private PerforHospitalRepository _hospitalRepository;
private PerforUserhospitalRepository _joinRepository;
public HospitalService(PerforHospitalRepository hospitalRepository,
PerforUserhospitalRepository joinRepository)
{
this._hospitalRepository = hospitalRepository;
this._joinRepository = joinRepository;
}
/// <summary>
/// 查询用户下属医院
/// </summary>
/// <param name="userid"></param>
/// <returns></returns>
public List<HospitalResponse> GetUserHopital(int userid)
{
if (userid <= 0)
throw new PerformanceException($"userid:{userid} 错误");
var joinList = _joinRepository.GetEntities(t => t.UserID == userid).ToList();
if (joinList == null && joinList.Count == 0)
throw new PerformanceException($"userid:{userid} 没有下属医院");
var hosList = _hospitalRepository.GetEntities(t => joinList.Select(j => j.HosID).Contains(t.ID)).ToList();
return Mapper.Map<List<sys_hospital>, List<HospitalResponse>>(hosList);
}
/// <summary>
/// 新增医院
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public bool Insert(HospitalRequest request)
{
if (null != _hospitalRepository.GetEntity(t => t.HosName == request.HosName))
throw new PerformanceException("医院名称重复");
var hospital = Mapper.Map<sys_hospital>(request);
hospital.CreateDate = DateTime.Now;
hospital.CreateUser = request.ActiveUId;
hospital.States = (int)States.Enabled;
return _hospitalRepository.Add(hospital);
}
/// <summary>
/// 修改医院
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public bool Update(HospitalRequest request)
{
var hospital = _hospitalRepository.GetEntity(t => t.ID == request.ID);
if (null == hospital)
throw new PerformanceException($"医院不存在 ID:{request.ID}");
hospital.HosName = request.HosName;
hospital.ShortName = request.ShortName;
hospital.HosLevel = request.HosLevel;
hospital.HosType = request.HosType;
hospital.AreaCode = request.AreaCode;
hospital.States = request.States;
return _hospitalRepository.Update(hospital);
}
/// <summary>
/// 删除医院
/// </summary>
/// <param name="request"></param>
/// <param name="hosid"></param>
/// <returns></returns>
public bool Delete(HospitalRequest request)
{
var hospital = _hospitalRepository.GetEntity(t => t.ID == request.ID);
if (null == hospital)
throw new PerformanceException($"医院不存在 ID:{request.ID}");
return _hospitalRepository.Remove(hospital);
}
}
}
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
namespace Performance.Services namespace Performance.Services
{ {
/// <summary>
/// 继承接口 自动注入DI
/// </summary>
public interface IAutoInjection public interface IAutoInjection
{ {
} }
......
using Microsoft.Extensions.Options;
using Performance.DtoModels;
using Performance.DtoModels.AppSettings;
using Performance.EntityModels;
using Performance.Infrastructure;
using Performance.Repository;
using System;
using System.Collections.Generic;
using System.Text;
namespace Performance.Services
{
public class SmsService : IAutoInjection
{
private PerforSmsRepository _smsRepository;
private PerforUserRepository _userRepository;
private Application _options;
private HuyiSmsNotify _sms;
public SmsService(PerforSmsRepository smsRepository,
PerforUserRepository userRepository,
IOptions<Application> options,
HuyiSmsNotify sms)
{
this._smsRepository = smsRepository;
this._userRepository = userRepository;
this._options = options.Value;
this._sms = sms;
}
/// <summary>
/// 发送验证码
/// </summary>
/// <param name="mobile"></param>
/// <returns></returns>
public bool SendCode(int type, string mobile)
{
int? uid = null;
if (type == (int)SmsCodeType.Login)
{
var user = _userRepository.GetEntity(t => t.Mobile == mobile || t.Login == mobile);
if (user == null)
throw new PerformanceException("当前手机号不是系统账号");
uid = user.ID;
}
var code = RandomHelper.GetSmsCode();
if (code.Length == 0)
throw new PerformanceException("随机验证码失败");
sys_sms sms = new sys_sms
{
CreateDate = DateTime.Now,
CreateUser = uid,
Mobile = mobile.Trim(),
SmsCode = code,
Expiration = DateTime.Now.AddMinutes(_options.SmsCodeMinutes),
CodeType = (int)SmsCodeType.Login
};
var message = _options.SmsTemplate.Replace("[code]", code);
var response = _sms.SendSms(mobile, message);
//2 是互亿返回成功状态
if (response.code != "2")
throw new PerformanceException(response.msg);
return _smsRepository.Add(sms);
}
/// <summary>
/// 检查验证码
/// </summary>
/// <param name="mobile"></param>
/// <param name="code"></param>
/// <returns></returns>
public bool Check(string mobile, string code)
{
if (string.IsNullOrEmpty(mobile) || string.IsNullOrEmpty(code))
throw new PerformanceException("参数无效");
var sms = _smsRepository.GetEntity(t => t.Mobile == mobile.Trim() && t.SmsCode == code.Trim());
return sms == null;
}
}
}
...@@ -13,37 +13,125 @@ namespace Performance.Services ...@@ -13,37 +13,125 @@ namespace Performance.Services
{ {
public class UserService : IAutoInjection public class UserService : IAutoInjection
{ {
PerforRepository<Sys_User> _userRepository; private PerforUserRepository _userRepository;
public UserService(PerforRepository<Sys_User> userRepository) private PerforSmsRepository _smsRepository;
private PerforHospitalRepository _hospitalRepository;
private PerforUserhospitalRepository _userhospitalRepository;
public UserService(PerforSmsRepository smsRepository,
PerforUserRepository userRepository,
PerforHospitalRepository hospitalRepository,
PerforUserhospitalRepository userhospitalRepository)
{ {
this._userRepository = userRepository; this._userRepository = userRepository;
this._smsRepository = smsRepository;
this._hospitalRepository = hospitalRepository;
this._userhospitalRepository = userhospitalRepository;
} }
public List<Sys_User> GetUser() /// <summary>
{ /// 登录
return _userRepository.GetEntities().ToList(); /// </summary>
} /// <param name="request"></param>
/// <returns></returns>
public ApiResponse<LoginInfo> Login(LoginRequest request) public UserIdentity Login(LoginRequest request)
{ {
//手机号登录 //手机号登录
if (request.LoginType == 1) if (request.LoginType == 1)
{ {
var sms = _smsRepository.GetEntity(t => t.Mobile == request.Account.Trim() && t.SmsCode == request.Password.Trim());
if (sms == null)
throw new PerformanceException("验证码验证失败");
var user = _userRepository.GetEntity(t => t.Mobile == request.Account); var user = _userRepository.GetEntity(t => t.Mobile == request.Account);
if (user == null)
throw new PerformanceException("用户信息查询失败");
var data = Mapper.Map<UserIdentity>(user);
data.Token = Guid.NewGuid().ToString("N");
return data;
} }
//账号密码登录 //账号密码登录
else if (request.LoginType == 2) else if (request.LoginType == 2)
{ {
var user = _userRepository.GetEntity(t => t.Login == request.Account); var user = _userRepository.GetEntity(t => t.Login == request.Account);
if (user != null && user.Password == request.Password) if (user == null)
{ throw new PerformanceException($"用户不存在 UserId:{request.Account}");
var data = Mapper.Map<LoginInfo>(user); if (!user.Password.Equals(request.Password, StringComparison.OrdinalIgnoreCase))
data.Token = Guid.NewGuid().ToString("N"); throw new PerformanceException($"密码错误");
return new ApiResponse<LoginInfo>(ResponseType.OK, "登录成功", data);
} var data = Mapper.Map<UserIdentity>(user);
data.Token = Guid.NewGuid().ToString("N");
return data;
} }
return new ApiResponse<LoginInfo>(); throw new PerformanceException($"登录类型LoginType:{request.LoginType}暂不支持");
}
/// <summary>
/// 新增用户
/// </summary>
/// <param name="request"></param>
public bool Insert(UserRequest request)
{
if (null != _userRepository.GetEntity(t => t.Login == request.Login))
throw new PerformanceException("登录名重复");
if (null != _userRepository.GetEntity(t => t.Mobile == request.Mobile))
throw new PerformanceException("手机号重复");
var user = Mapper.Map<sys_user>(request);
user.CreateDate = DateTime.Now;
user.CreateUser = request.ActiveUId;
user.States = (int)States.Enabled;
return _userRepository.Add(user);
}
/// <summary>
/// 设置用户医院
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public bool SetHospital(SetHospitalRequest request)
{
var user = _userRepository.GetEntity(t => t.ID == request.UserID);
if (null == user)
throw new PerformanceException($"用户不存在 UserId:{request.UserID}");
var userHospital = _userhospitalRepository.GetUserHospital(request.UserID);
bool rmResult = true, addResult = true;
//获取需要删除的医院
var rmHospital = userHospital.Where(t => !request.HosIDArray.Contains(t.HosID.Value));
if (rmHospital != null && rmHospital.Count() > 0)
rmResult = _userhospitalRepository.RemoveRange(rmHospital.ToArray());
//获取需要新增的医院
var addHospital = request.HosIDArray.Where(t => !userHospital.Select(u => u.HosID).Contains(t));
if (addHospital != null && addHospital.Count() > 0)
{
var allHospital = _hospitalRepository.GetEntities();
//获取有效医院ID
var array = addHospital.Where(t => allHospital.Select(h => h.ID).Contains(t))
.Select(t => new sys_user_hospital { UserID = request.UserID, HosID = t }).ToArray();
addResult = _userhospitalRepository.AddRange(array);
}
return rmResult && addResult;
}
/// <summary>
/// 修改用户
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public bool Update(UserRequest request)
{
var user = _userRepository.GetEntity(t => t.ID == request.ID);
if (null == user)
throw new PerformanceException($"用户不存在 UserId:{request.ID}");
user.Login = request.Login;
user.Mobile = request.Mobile;
user.RealName = request.RealName;
user.Mail = request.Mail;
user.States = request.States;
return _userRepository.Update(user);
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment