Commit 79c0f877 by zry

Merge branch 'master' into feature/hangfire

parents c4f1eb96 bd02894d
......@@ -69,6 +69,33 @@ public ApiResponse<UserIdentity> Login([FromBody]LoginRequest request)
}
/// <summary>
/// 修改个人信息
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("updateself")]
[HttpPost]
public ApiResponse<UserResponse> UpdateSelf([CustomizeValidator(RuleSet = "Self"), FromBody]UserRequest request)
{
request.ID = _claim.At(request.Token).UserID;
var user = _userService.UpdateSelf(request);
return new ApiResponse<UserResponse>(ResponseType.OK, user);
}
/// <summary>
///
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("list")]
[HttpPost]
public ApiResponse<List<UserResponse>> List([FromBody]ApiRequest request)
{
var userList = _userService.GetUserList(_claim.At(request.Token).UserID);
return new ApiResponse<List<UserResponse>>(ResponseType.OK, "ok", userList);
}
/// <summary>
/// 新增用户
/// </summary>
/// <param name="request"></param>
......
......@@ -36,6 +36,7 @@ public ApiResponse<HospitalResponse> Insert([CustomizeValidator(RuleSet = "Inser
{
var userid = _claim.At(request.Token).UserID;
var hospital = _hospitalService.Insert(request, userid);
_hospitalService.InsertUserHospital(userid, hospital.HosID);
return new ApiResponse<HospitalResponse>(ResponseType.OK, hospital);
}
......
......@@ -96,10 +96,10 @@ public void ConfigureServices(IServiceCollection services)
.Configure<Application>(Configuration.GetSection("Application"))
.Configure<HuyiSmsConfig>(Configuration.GetSection("HuyiSmsConfig"));
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });
});
//services.AddSwaggerGen(c =>
//{
// c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });
//});
//huyi短信发送注入
services.AddScoped<HuyiSmsNotify>();
......@@ -132,16 +132,16 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
{
app.UseStatusCodePagesWithReExecute("/error/{0}");
}
// Enable middleware to serve generated Swagger as a JSON endpoint.
app.UseSwagger();
//// Enable middleware to serve generated Swagger as a JSON endpoint.
//app.UseSwagger();
// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
// specifying the Swagger JSON endpoint.
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
c.RoutePrefix = string.Empty;
});
//// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
//// specifying the Swagger JSON endpoint.
//app.UseSwaggerUI(c =>
//{
// c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
// c.RoutePrefix = string.Empty;
//});
app.UseHangfireServer();
app.UseHangfireDashboard();
......
......@@ -61,7 +61,20 @@ public UserRequestValidator()
{
action();
RuleFor(x => x.ID).NotNull().NotEmpty().GreaterThan(0);
RuleFor(x => x.States).NotNull().NotEmpty().InclusiveBetween(1, 2);
RuleFor(x => x.States).InclusiveBetween(1, 2);
RuleFor(x => x.Password).Length(4, 20);
});
RuleSet("Self", () =>
{
RuleFor(x => x.Password).Length(4, 20);
RuleFor(x => x.Mobile).Must((pre) =>
{
if (!string.IsNullOrEmpty(pre))
return CustomValidator.IsMobile(pre);
return true;
});
RuleFor(x => x.Mail).EmailAddress().When(pre => { return !string.IsNullOrEmpty(pre.Mail); });
});
}
}
......
......@@ -12,6 +12,6 @@ public class HospitalResponse
public string AreaCode { get; set; }
public string HosLevel { get; set; }
public string HosType { get; set; }
public string States { get; set; }
public int States { get; set; }
}
}
......@@ -14,5 +14,6 @@ public class UserResponse
public string Mail { get; set; }
public string Mobile { get; set; }
public int States { get; set; }
public List<int> Hospital { get; set; }
}
}
......@@ -53,6 +53,17 @@ public sys_hospital GetHopital(int hosid)
}
/// <summary>
/// 新增
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public bool InsertUserHospital(int userid, int hospitalid)
{
var uh = new sys_user_hospital { UserID = userid, HospitalID = hospitalid };
return _joinRepository.Add(uh);
}
/// <summary>
/// 新增医院
/// </summary>
/// <param name="request"></param>
......
......@@ -66,6 +66,29 @@ public UserIdentity Login(LoginRequest request)
}
/// <summary>
/// 查询用户列表
/// </summary>
/// <param name="userID"></param>
/// <returns></returns>
public List<UserResponse> GetUserList(int userID)
{
var userlist = _userRepository.GetEntities(t => t.CreateUser == userID);
var result = Mapper.Map<List<UserResponse>>(userlist);
if (result != null && result.Count > 0)
{
foreach (var item in result)
{
var hoslist = _userhospitalRepository.GetEntities(p => p.UserID == item.UserID);
if (hoslist != null && hoslist.Count() > 0)
{
item.Hospital = hoslist.Select(p => p.HospitalID.Value).ToList();
}
}
}
return result;
}
/// <summary>
/// 新增用户
/// </summary>
/// <param name="request"></param>
......@@ -141,6 +164,37 @@ public UserResponse Update(UserRequest request)
user.RealName = request.RealName;
user.Mail = request.Mail;
user.States = request.States;
user.Password = string.IsNullOrEmpty(request.Password) ? user.Password : request.Password;
if (!_userRepository.Update(user))
throw new PerformanceException("保存失败");
return Mapper.Map<UserResponse>(user);
}
/// <summary>
/// 修改个人信息
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public UserResponse UpdateSelf(UserRequest request)
{
var user = _userRepository.GetEntity(t => t.ID == request.ID);
if (null == user)
throw new PerformanceException($"用户不存在 UserId:{request.ID}");
var vlist = _userRepository.GetEntities(t => t.ID != user.ID && t.Login == request.Login);
if (null != vlist && vlist.Count() > 0)
throw new PerformanceException("登录名重复");
vlist = _userRepository.GetEntities(t => t.ID != user.ID && t.Mobile == request.Mobile);
if (null != vlist && vlist.Count() > 0)
throw new PerformanceException("手机号重复");
user.Mobile = string.IsNullOrEmpty(request.RealName) ? user.Mobile : request.Mobile;
user.RealName = string.IsNullOrEmpty(request.RealName) ? user.RealName : request.RealName;
user.Mail = string.IsNullOrEmpty(request.Mail) ? user.Mail : request.Mail;
user.Password = string.IsNullOrEmpty(request.Password) ? user.Password : request.Password;
if (!_userRepository.Update(user))
throw new PerformanceException("保存失败");
......
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