Commit 03339a8d by 1391696987

梧州企业微信登录绩效

parent 17cb0ca0
...@@ -17,6 +17,8 @@ public static void AddAppSettingConfiguration(this IServiceCollection services, ...@@ -17,6 +17,8 @@ public static void AddAppSettingConfiguration(this IServiceCollection services,
services services
.Configure<AppConnection>(configuration.GetSection("AppConnection")) .Configure<AppConnection>(configuration.GetSection("AppConnection"))
.Configure<Wechat>(configuration.GetSection("Wechat"))
.Configure<WzOAuth>(configuration.GetSection("WzOAuth"))
.Configure<Application>(configuration.GetSection("Application")) .Configure<Application>(configuration.GetSection("Application"))
.Configure<HuyiSmsConfig>(configuration.GetSection("HuyiSmsConfig")) .Configure<HuyiSmsConfig>(configuration.GetSection("HuyiSmsConfig"))
.Configure<EmailOptions>(configuration.GetSection("EmailOptions")) .Configure<EmailOptions>(configuration.GetSection("EmailOptions"))
......
...@@ -2,11 +2,14 @@ ...@@ -2,11 +2,14 @@
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Performance.DtoModels; using Performance.DtoModels;
using Performance.DtoModels.AppSettings; using Performance.DtoModels.AppSettings;
using Performance.EntityModels; using Performance.EntityModels;
using Performance.Infrastructure;
using Performance.Services; using Performance.Services;
using RestSharp;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
...@@ -17,26 +20,36 @@ namespace Performance.Api.Controllers ...@@ -17,26 +20,36 @@ namespace Performance.Api.Controllers
[Route("api/[controller]")] [Route("api/[controller]")]
public class AccountController : Controller public class AccountController : Controller
{ {
private readonly ILogger<AccountController> logger;
private UserService _userService; private UserService _userService;
private RoleService _roleService; private RoleService _roleService;
private IMemoryCache _memoryCache; private IMemoryCache _memoryCache;
private Application _options; private Application _options;
private ClaimService _claim; private ClaimService _claim;
private HospitalService _hospitalService; private HospitalService _hospitalService;
private readonly IOptions<Wechat> _wechat;
private readonly IOptions<WzOAuth> _wzOAuth;
public AccountController(UserService userService, public AccountController(
ILogger<AccountController> logger,
UserService userService,
HospitalService hospitalService, HospitalService hospitalService,
RoleService roleService, RoleService roleService,
IMemoryCache memoryCache, IMemoryCache memoryCache,
IOptions<Application> options, IOptions<Application> options,
ClaimService claim) ClaimService claim,
IOptions<Wechat> wechat,
IOptions<WzOAuth> wzOAuth)
{ {
this.logger = logger;
_userService = userService; _userService = userService;
_roleService = roleService; _roleService = roleService;
_memoryCache = memoryCache; _memoryCache = memoryCache;
_hospitalService = hospitalService; _hospitalService = hospitalService;
_options = options.Value; _options = options.Value;
_claim = claim; _claim = claim;
_wechat = wechat;
_wzOAuth = wzOAuth;
} }
/// <summary> /// <summary>
...@@ -82,192 +95,303 @@ public ApiResponse<JwtToken> Login([FromBody] LoginRequest request) ...@@ -82,192 +95,303 @@ public ApiResponse<JwtToken> Login([FromBody] LoginRequest request)
} }
/// <summary> /// <summary>
/// 刷新登录JWT TOKEN /// 微信登录
/// </summary> /// </summary>
/// <param name="code"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost] [HttpPost]
[Route("refresh")] [Route("WechatLogin")]
public ApiResponse<JwtToken> Refresh() [AllowAnonymous]
public ApiResponse WechatLogin(string code)
{ {
var userClaim = _claim.GetUserClaim();
var claims = new Claim[] InterfaceRequest interfaceRequest = new InterfaceRequest()
{ {
new Claim(JwtClaimTypes.Id, userClaim.FirstOrDefault(t => t.Type == JwtClaimTypes.Id)?.Value??""), Url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken",
new Claim(JwtClaimTypes.Login, userClaim.FirstOrDefault(t => t.Type == JwtClaimTypes.Login)?.Value??""), Function = "GatAccess_token"
new Claim(JwtClaimTypes.RealName, userClaim.FirstOrDefault(t => t.Type == JwtClaimTypes.RealName)?.Value??""),
new Claim(JwtClaimTypes.Mail, userClaim.FirstOrDefault(t => t.Type == JwtClaimTypes.Mail)?.Value??""),
new Claim(JwtClaimTypes.AppName, userClaim.FirstOrDefault(t => t.Type == JwtClaimTypes.AppName)?.Value??""),
new Claim(JwtClaimTypes.Device, userClaim.FirstOrDefault(t => t.Type == JwtClaimTypes.Device)?.Value??""),
new Claim(JwtClaimTypes.Department, userClaim.FirstOrDefault(t => t.Type == JwtClaimTypes.Department)?.Value??""),
}; };
var jwtToken = JwtTokenHelper.GenerateToken(claims, _options.ExpirationMinutes); var getAccess_tokenDic = _userService.AccessInterface(interfaceRequest, out string content);
// 设置当前请求Jwt失效 string access_token = "";
var jwt = _claim.GetJwtToken(); if (getAccess_tokenDic.ContainsKey("access_token"))
//claimService.SetJwtBlacklist(jwt); access_token = getAccess_tokenDic["access_token"].ToString();
return new ApiResponse<JwtToken>(ResponseType.OK, jwtToken);
}
/// <summary>
/// 查询个人信息
/// </summary>
/// <returns></returns>
[Route("selfinfo")]
[HttpPost]
public ApiResponse SelfInfo()
{
var userid = _claim.GetUserId();
var user = _userService.GetUser(userid);
user.Role = _roleService.GetUserRole(user.UserID);
user.Hospital = _hospitalService.GetUserHopital(user.UserID);
int[] roleArray = new int[] { _options.NurseRole, _options.DirectorRole, _options.SpecialRole, _options.OfficeRole };
user.IsAgainAdmin = user.Role != null ? roleArray.Contains(user.Role.First().Type ?? 0) : false;
return new ApiResponse(ResponseType.OK, user);
}
/// <summary> interfaceRequest.Url = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo";
/// 修改个人信息 interfaceRequest.Function = "GetUserId";
/// </summary> interfaceRequest.Access_token = access_token;
/// <param name="request"></param> interfaceRequest.Code = code;
/// <returns></returns>
[Route("updateself")]
[HttpPost]
public ApiResponse<UserResponse> UpdateSelf([CustomizeValidator(RuleSet = "Self"), FromBody] UserRequest request)
{
request.ID = _claim.GetUserId();
var user = _userService.UpdateSelf(request);
return new ApiResponse<UserResponse>(ResponseType.OK, user);
}
/// <summary> var getUserIdDic = _userService.AccessInterface(interfaceRequest, out string conten);
/// 用户列表 string userId = "";
/// </summary> if (getUserIdDic.ContainsKey("UserId"))
/// <returns></returns> userId = getUserIdDic["UserId"].ToString();
[Route("list")]
[HttpPost] var empCode = _userService.GetWxUserEmpCode(userId);
public ApiResponse<List<UserResponse>> List([FromBody] UserRequest request)
{
var userList = _userService.GetUserList(_claim.GetUserId(),request.Role);
return new ApiResponse<List<UserResponse>>(ResponseType.OK, "ok", userList);
}
return new ApiResponse(ResponseType.OK, new { userId, empCode });
}
/// <summary> /// <summary>
/// 新增用户 /// 梧州Token假接口
/// </summary> /// </summary>
/// <param name="request"></param>
/// <returns></returns> /// <returns></returns>
[Route("insert")]
[HttpPost] [HttpPost]
public ApiResponse<UserResponse> Insert([CustomizeValidator(RuleSet = "Insert"), FromBody] UserRequest request) [Route("WuzhouToken")]
[AllowAnonymous]
public dynamic WuzhouToken()
{ {
var userId = _claim.GetUserId(); string json1 = "{\"success\":true,\"status\":{\"code\":0,\"msg\":\"处理成功。\"},\"extraMsg\":\"\",\"item\":{\"id\":\"9f1e83f1-6a9d-4bc4-8e93-611cb41991ba\",\"timeout\":7200000,\"startTimestamp\":\"2022-06-01 16:47:42.049\"}}";
var user = _userService.Insert(request, userId); var dic = JsonHelper.Deserialize<Dictionary<string, object>>(json1);
user.Role = request.Role; return dic;
return new ApiResponse<UserResponse>(ResponseType.OK, user);
} }
/// <summary> /// <summary>
/// 新增用户 /// 梧州验证登录假接口
/// </summary> /// </summary>
/// <param name="request"></param>
/// <returns></returns> /// <returns></returns>
[Route("delete")]
[HttpPost] [HttpPost]
public ApiResponse Delete([CustomizeValidator(RuleSet = "Delete"), FromBody] UserRequest request) [Route("WuzhouValidPass")]
[AllowAnonymous]
public dynamic WuzhouValidPass()
{ {
return _userService.Delete(request.ID); string json1 = "{\"success\":true,\"status\":{\"code\":0,\"msg\":\"处理成功。\"},\"extraMsg\":\"\",\"item\":true}";
var dic = JsonHelper.Deserialize<Dictionary<string, object>>(json1);
return dic;
} }
/// <summary> /// <summary>
/// 删除用户 /// 梧州登录
/// </summary> /// </summary>
/// <param name="request"></param> /// <param name="request"></param>
/// <returns></returns> /// <returns></returns>
[Route("update")]
[HttpPost] [HttpPost]
public ApiResponse<UserResponse> Update([CustomizeValidator(RuleSet = "Update"), FromBody] UserRequest request) [Route("WuzhouLogin")]
[AllowAnonymous]
public dynamic WuzhouLogin([FromBody] WuzhouLoginRequest request)
{ {
var userId = _claim.GetUserId(); if (string.IsNullOrEmpty(request.EmpCode) ||
string.IsNullOrEmpty(request.Password) ||
int[] roleArray = new int[] { _options.NurseRole, _options.DirectorRole, _options.SpecialRole, _options.OfficeRole }; string.IsNullOrEmpty(request.SocialCode) ||
var roles = _roleService.GetUserRole(userId); string.IsNullOrEmpty(request.Mobile) ||
var isAgainAdmin = roles != null ? roleArray.Contains(roles.First().Type ?? 0) : false; string.IsNullOrEmpty(request.UserId))
return new ApiResponse(ResponseType.Fail, "请补全数据!");
InterfaceRequest interfaceRequest = new InterfaceRequest()
{
Url = _wzOAuth.Value.GetTokenUrl,
Function = "GetX_Token"
};
var user = _userService.Update(request, isAgainAdmin); var getTokenDic = _userService.AccessInterface(interfaceRequest, out string tokenContent);
user.Role = request.Role;
return new ApiResponse<UserResponse>(ResponseType.OK, user);
}
/// <summary> string token = "";
/// 修改用户密码 if (getTokenDic.GetValue("success", false) == true)
/// </summary> {
/// <param name="request"></param> var item = getTokenDic["item"];
/// <returns></returns> var itemdic = JsonHelper.Deserialize<Dictionary<string, object>>(item.ToString());
[Route("password")] token = itemdic["id"].ToString();
[HttpPost] }
public ApiResponse<UserResponse> Password([FromBody] PasswordRequest request) else
{ {
var userid = _claim.GetUserId(); return tokenContent;
var user = _userService.UpdatePwd(request, userid); }
return new ApiResponse<UserResponse>(ResponseType.OK, user);
}
/// <summary> interfaceRequest.Url = _wzOAuth.Value.ValidPassUrl;
/// 角色列表 interfaceRequest.Function = "ValidPass";
/// </summary> interfaceRequest.wuzhouLoginRequest = request;
/// <returns></returns>
[Route("rolelist")]
[HttpPost]
public ApiResponse<List<sys_role>> RoleList()
{
var userid = _claim.GetUserId();
var roleList = _userService.RoleList(userid);
return new ApiResponse<List<sys_role>>(ResponseType.OK, "ok", roleList);
}
/// <summary> var validPassDic = _userService.AccessInterface(interfaceRequest, out string validPassContent);
/// 科室列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("department")]
[HttpPost]
public ApiResponse<List<TitleValue>> Department([FromBody] SetDepartmentRequest request)
{
var department = _userService.Department(request.HospitalID);
return new ApiResponse<List<TitleValue>>(ResponseType.OK, "ok", department);
}
/// <summary> if (validPassDic.GetValue("success", false) == true && validPassDic.GetValue("item", false) == true)
/// 演示用户 _userService.SaveWxUser(request.UserId, request.EmpCode);
/// </summary> return validPassContent;
/// <returns></returns>
[Route("demo/users")]
[HttpPost]
public ApiResponse<List<TitleValue<int>>> DemoUsers()
{
var users = _userService.GetDemoUsers();
return new ApiResponse<List<TitleValue<int>>>(ResponseType.OK, users);
} }
/// <summary>
/// 刷新登录JWT TOKEN
/// </summary>
/// <returns></returns>
[HttpPost]
[Route("refresh")]
public ApiResponse<JwtToken> Refresh()
{
var userClaim = _claim.GetUserClaim();
var claims = new Claim[]
{
new Claim(JwtClaimTypes.Id, userClaim.FirstOrDefault(t => t.Type == JwtClaimTypes.Id)?.Value??""),
new Claim(JwtClaimTypes.Login, userClaim.FirstOrDefault(t => t.Type == JwtClaimTypes.Login)?.Value??""),
new Claim(JwtClaimTypes.RealName, userClaim.FirstOrDefault(t => t.Type == JwtClaimTypes.RealName)?.Value??""),
new Claim(JwtClaimTypes.Mail, userClaim.FirstOrDefault(t => t.Type == JwtClaimTypes.Mail)?.Value??""),
new Claim(JwtClaimTypes.AppName, userClaim.FirstOrDefault(t => t.Type == JwtClaimTypes.AppName)?.Value??""),
new Claim(JwtClaimTypes.Device, userClaim.FirstOrDefault(t => t.Type == JwtClaimTypes.Device)?.Value??""),
new Claim(JwtClaimTypes.Department, userClaim.FirstOrDefault(t => t.Type == JwtClaimTypes.Department)?.Value??""),
};
var jwtToken = JwtTokenHelper.GenerateToken(claims, _options.ExpirationMinutes);
// 设置当前请求Jwt失效
var jwt = _claim.GetJwtToken();
//claimService.SetJwtBlacklist(jwt);
return new ApiResponse<JwtToken>(ResponseType.OK, jwtToken);
}
/// <summary>
/// 查询个人信息
/// </summary>
/// <returns></returns>
[Route("selfinfo")]
[HttpPost]
public ApiResponse SelfInfo()
{
var userid = _claim.GetUserId();
var user = _userService.GetUser(userid);
user.Role = _roleService.GetUserRole(user.UserID);
user.Hospital = _hospitalService.GetUserHopital(user.UserID);
/// <summary> int[] roleArray = new int[] { _options.NurseRole, _options.DirectorRole, _options.SpecialRole, _options.OfficeRole };
/// 更换角色获取Token user.IsAgainAdmin = user.Role != null ? roleArray.Contains(user.Role.First().Type ?? 0) : false;
/// </summary> return new ApiResponse(ResponseType.OK, user);
/// <param name="userId"></param> }
/// <returns></returns>
[Route("demo/token/{userId}")] /// <summary>
[HttpPost] /// 修改个人信息
public ApiResponse<JwtToken> DemoUsers(int userId) /// </summary>
{ /// <param name="request"></param>
if (userId < 1) /// <returns></returns>
return new ApiResponse<JwtToken>(ResponseType.ParameterError, "用户不存在,请先创建!"); [Route("updateself")]
[HttpPost]
var user = _userService.GetDemoUserIdentity(userId); public ApiResponse<UserResponse> UpdateSelf([CustomizeValidator(RuleSet = "Self"), FromBody] UserRequest request)
var userClaim = _claim.GetUserClaim(); {
var claims = new Claim[] request.ID = _claim.GetUserId();
var user = _userService.UpdateSelf(request);
return new ApiResponse<UserResponse>(ResponseType.OK, user);
}
/// <summary>
/// 用户列表
/// </summary>
/// <returns></returns>
[Route("list")]
[HttpPost]
public ApiResponse<List<UserResponse>> List([FromBody] UserRequest request)
{
var userList = _userService.GetUserList(_claim.GetUserId(), request.Role);
return new ApiResponse<List<UserResponse>>(ResponseType.OK, "ok", userList);
}
/// <summary>
/// 新增用户
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("insert")]
[HttpPost]
public ApiResponse<UserResponse> Insert([CustomizeValidator(RuleSet = "Insert"), FromBody] UserRequest request)
{
var userId = _claim.GetUserId();
var user = _userService.Insert(request, userId);
user.Role = request.Role;
return new ApiResponse<UserResponse>(ResponseType.OK, user);
}
/// <summary>
/// 新增用户
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("delete")]
[HttpPost]
public ApiResponse Delete([CustomizeValidator(RuleSet = "Delete"), FromBody] UserRequest request)
{
return _userService.Delete(request.ID);
}
/// <summary>
/// 删除用户
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("update")]
[HttpPost]
public ApiResponse<UserResponse> Update([CustomizeValidator(RuleSet = "Update"), FromBody] UserRequest request)
{
var userId = _claim.GetUserId();
int[] roleArray = new int[] { _options.NurseRole, _options.DirectorRole, _options.SpecialRole, _options.OfficeRole };
var roles = _roleService.GetUserRole(userId);
var isAgainAdmin = roles != null ? roleArray.Contains(roles.First().Type ?? 0) : false;
var user = _userService.Update(request, isAgainAdmin);
user.Role = request.Role;
return new ApiResponse<UserResponse>(ResponseType.OK, user);
}
/// <summary>
/// 修改用户密码
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("password")]
[HttpPost]
public ApiResponse<UserResponse> Password([FromBody] PasswordRequest request)
{
var userid = _claim.GetUserId();
var user = _userService.UpdatePwd(request, userid);
return new ApiResponse<UserResponse>(ResponseType.OK, user);
}
/// <summary>
/// 角色列表
/// </summary>
/// <returns></returns>
[Route("rolelist")]
[HttpPost]
public ApiResponse<List<sys_role>> RoleList()
{ {
var userid = _claim.GetUserId();
var roleList = _userService.RoleList(userid);
return new ApiResponse<List<sys_role>>(ResponseType.OK, "ok", roleList);
}
/// <summary>
/// 科室列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("department")]
[HttpPost]
public ApiResponse<List<TitleValue>> Department([FromBody] SetDepartmentRequest request)
{
var department = _userService.Department(request.HospitalID);
return new ApiResponse<List<TitleValue>>(ResponseType.OK, "ok", department);
}
/// <summary>
/// 演示用户
/// </summary>
/// <returns></returns>
[Route("demo/users")]
[HttpPost]
public ApiResponse<List<TitleValue<int>>> DemoUsers()
{
var users = _userService.GetDemoUsers();
return new ApiResponse<List<TitleValue<int>>>(ResponseType.OK, users);
}
/// <summary>
/// 更换角色获取Token
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
[Route("demo/token/{userId}")]
[HttpPost]
public ApiResponse<JwtToken> DemoUsers(int userId)
{
if (userId < 1)
return new ApiResponse<JwtToken>(ResponseType.ParameterError, "用户不存在,请先创建!");
var user = _userService.GetDemoUserIdentity(userId);
var userClaim = _claim.GetUserClaim();
var claims = new Claim[]
{
new Claim(JwtClaimTypes.Id, user.UserID.ToString()), new Claim(JwtClaimTypes.Id, user.UserID.ToString()),
new Claim(JwtClaimTypes.Login, user.Login), new Claim(JwtClaimTypes.Login, user.Login),
new Claim(JwtClaimTypes.RealName, user.RealName), new Claim(JwtClaimTypes.RealName, user.RealName),
...@@ -275,128 +399,128 @@ public ApiResponse<JwtToken> DemoUsers(int userId) ...@@ -275,128 +399,128 @@ public ApiResponse<JwtToken> DemoUsers(int userId)
new Claim(JwtClaimTypes.AppName, userClaim.FirstOrDefault(t => t.Type == JwtClaimTypes.AppName)?.Value??""), new Claim(JwtClaimTypes.AppName, userClaim.FirstOrDefault(t => t.Type == JwtClaimTypes.AppName)?.Value??""),
new Claim(JwtClaimTypes.Device,userClaim.FirstOrDefault(t => t.Type == JwtClaimTypes.Device)?.Value??""), new Claim(JwtClaimTypes.Device,userClaim.FirstOrDefault(t => t.Type == JwtClaimTypes.Device)?.Value??""),
new Claim(JwtClaimTypes.Department, user.Department ?? ""), new Claim(JwtClaimTypes.Department, user.Department ?? ""),
}; };
var jwtToken = JwtTokenHelper.GenerateToken(claims, _options.ExpirationMinutes); var jwtToken = JwtTokenHelper.GenerateToken(claims, _options.ExpirationMinutes);
return new ApiResponse<JwtToken>(ResponseType.OK, jwtToken); return new ApiResponse<JwtToken>(ResponseType.OK, jwtToken);
} }
/// <summary> /// <summary>
/// 修改用户密码 /// 修改用户密码
/// </summary> /// </summary>
/// <param name="userId">用户id</param> /// <param name="userId">用户id</param>
/// <returns></returns> /// <returns></returns>
[Route("reset/{userId}")] [Route("reset/{userId}")]
[HttpPost] [HttpPost]
public ApiResponse<UserResponse> Password(int userId) public ApiResponse<UserResponse> Password(int userId)
{ {
var loginUserId = _claim.GetUserId(); var loginUserId = _claim.GetUserId();
var user = _userService.ResetPwd(userId, loginUserId); var user = _userService.ResetPwd(userId, loginUserId);
return new ApiResponse<UserResponse>(ResponseType.OK, user); return new ApiResponse<UserResponse>(ResponseType.OK, user);
} }
#region 多角色
/// <summary>
/// 查询用户信息
/// </summary>
/// <returns></returns>
[Route("selfInfos")]
[HttpPost]
public ApiResponse SelfInfos([FromBody] UserRequest request)
{
var userid = _claim.GetUserId();
var user = _userService.GetUser(userid);
user.Role = _roleService.GetUsersRole(user.UserID);
user.Hospital = _hospitalService.GetUserHopital(user.UserID);
int[] roleArray = new int[] { _options.NurseRole, _options.DirectorRole, _options.SpecialRole, _options.OfficeRole };
if (request.Role <= 0)
user.IsAgainAdmin = user.Role != null ? roleArray.Contains(user.Role.First().Type ?? 0) : false;
else
user.IsAgainAdmin = user.Role != null ? roleArray.Contains(user.Role.First(t => t.RoleID == request.Role).Type ?? 0) : false;
return new ApiResponse(ResponseType.OK, user);
}
/// <summary>
/// 新增用户
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("InsertUser")]
[HttpPost]
public ApiResponse<UserResponse> InsertUser([CustomizeValidator(RuleSet = "Insert"), FromBody] UserRequest request)
{
var userId = _claim.GetUserId();
var user = _userService.InsertUser(request, userId);
user.RoleArr = request.RoleArr;
return new ApiResponse<UserResponse>(ResponseType.OK, user);
}
/// <summary>
/// 编辑用户
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("UpdateUser")]
[HttpPost]
public ApiResponse<UserResponse> UpdateUser([CustomizeValidator(RuleSet = "Update"), FromBody] UserRequest request)
{
var userId = _claim.GetUserId();
int[] roleArray = new int[] { _options.NurseRole, _options.DirectorRole, _options.SpecialRole, _options.OfficeRole };
var roles = _roleService.GetUsersRole(userId);
//var roleType = roles.Select(c => c.Type).ToArray();
var intersect = roleArray.Intersect(roles.Select(c => (int)c.Type).ToArray());
var isAgainAdmin = roles != null ? intersect.Any() : false;
var user = _userService.UpdateUser(request, isAgainAdmin);
user.RoleArr = request.RoleArr;
return new ApiResponse<UserResponse>(ResponseType.OK, user);
}
/// <summary>
/// 新增用户
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("DeleteUser")]
[HttpPost]
public ApiResponse DeleteUser([CustomizeValidator(RuleSet = "Delete"), FromBody] UserRequest request)
{
return _userService.DeleteUser(request.ID);
}
#endregion
/// <summary> #region 多角色
/// 批量新增用户表头
/// </summary>
/// <returns></returns>
[Route("GetBatchUserStructrue")]
[HttpPost]
public ApiResponse GetBatchUserStructrue()
{
var result = _userService.GetUserHandsFlat();
return new ApiResponse(ResponseType.OK, result);
}
/// <summary>
/// 查询用户信息
/// </summary>
/// <returns></returns>
[Route("selfInfos")]
[HttpPost]
public ApiResponse SelfInfos([FromBody] UserRequest request)
{
var userid = _claim.GetUserId();
var user = _userService.GetUser(userid);
user.Role = _roleService.GetUsersRole(user.UserID);
user.Hospital = _hospitalService.GetUserHopital(user.UserID);
int[] roleArray = new int[] { _options.NurseRole, _options.DirectorRole, _options.SpecialRole, _options.OfficeRole };
if (request.Role <= 0)
user.IsAgainAdmin = user.Role != null ? roleArray.Contains(user.Role.First().Type ?? 0) : false;
else
user.IsAgainAdmin = user.Role != null ? roleArray.Contains(user.Role.First(t => t.RoleID == request.Role).Type ?? 0) : false;
return new ApiResponse(ResponseType.OK, user);
}
/// <summary>
/// 新增用户
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("InsertUser")]
[HttpPost]
public ApiResponse<UserResponse> InsertUser([CustomizeValidator(RuleSet = "Insert"), FromBody] UserRequest request)
{
var userId = _claim.GetUserId();
var user = _userService.InsertUser(request, userId);
user.RoleArr = request.RoleArr;
return new ApiResponse<UserResponse>(ResponseType.OK, user);
}
/// <summary>
/// 编辑用户
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("UpdateUser")]
[HttpPost]
public ApiResponse<UserResponse> UpdateUser([CustomizeValidator(RuleSet = "Update"), FromBody] UserRequest request)
{
var userId = _claim.GetUserId();
int[] roleArray = new int[] { _options.NurseRole, _options.DirectorRole, _options.SpecialRole, _options.OfficeRole };
var roles = _roleService.GetUsersRole(userId);
//var roleType = roles.Select(c => c.Type).ToArray();
var intersect = roleArray.Intersect(roles.Select(c => (int)c.Type).ToArray());
var isAgainAdmin = roles != null ? intersect.Any() : false;
var user = _userService.UpdateUser(request, isAgainAdmin);
user.RoleArr = request.RoleArr;
return new ApiResponse<UserResponse>(ResponseType.OK, user);
}
/// <summary>
/// 新增用户
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("DeleteUser")]
[HttpPost]
public ApiResponse DeleteUser([CustomizeValidator(RuleSet = "Delete"), FromBody] UserRequest request)
{
return _userService.DeleteUser(request.ID);
}
#endregion
/// <summary>
/// 批量新增用户表头
/// </summary>
/// <returns></returns>
[Route("GetBatchUserStructrue")]
[HttpPost]
public ApiResponse GetBatchUserStructrue()
{
var result = _userService.GetUserHandsFlat();
return new ApiResponse(ResponseType.OK, result);
}
/// <summary>
/// 批量新增用户
/// </summary>
/// <returns></returns>
[Route("BatchSaveUser")]
[HttpPost]
public ApiResponse BatchSaveUser([CustomizeValidator(RuleSet = "Insert"), FromBody] UserCollectData data)
{
var result = _userService.SaveUserHandsFlat(data);
if (result == "")
return new ApiResponse(ResponseType.OK);
else
return new ApiResponse(ResponseType.Error, result);
/// <summary> }
/// 批量新增用户
/// </summary>
/// <returns></returns>
[Route("BatchSaveUser")]
[HttpPost]
public ApiResponse BatchSaveUser([CustomizeValidator(RuleSet = "Insert"), FromBody] UserCollectData data)
{
var result = _userService.SaveUserHandsFlat(data);
if (result == "")
return new ApiResponse(ResponseType.OK);
else
return new ApiResponse(ResponseType.Error, result);
} }
} }
} \ No newline at end of file
\ No newline at end of file
...@@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121. ...@@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
--> -->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <PropertyGroup>
<DeleteExistingFiles>True</DeleteExistingFiles> <DeleteExistingFiles>False</DeleteExistingFiles>
<ExcludeApp_Data>False</ExcludeApp_Data> <ExcludeApp_Data>False</ExcludeApp_Data>
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish> <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration> <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
......
...@@ -6,6 +6,16 @@ ...@@ -6,6 +6,16 @@
"Microsoft": "Warning" "Microsoft": "Warning"
} }
}, },
"Wechat": {
"CorpId": "ww58ec167201a95da7",
"CorpSecret": "1rgWzgJBIZ3r0Q2sW1trVw5QdXOHmgUhepk90ecI2rk"
},
"WzOAuth": {
"Code": "CNYICE",
"Token": "9e76f970728c4013a1333a76aa26631e",
"GetTokenUrl": "http://192.168.100.137/oauth/doAuth",
"ValidPassUrl": "http://192.168.100.225:12999/herp/employee/validPass"
},
"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=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;"
}, },
......
...@@ -5,6 +5,18 @@ ...@@ -5,6 +5,18 @@
"System": "Information" "System": "Information"
} }
}, },
"Wechat": {
"CorpId": "ww58ec167201a95da7",
"CorpSecret": "1rgWzgJBIZ3r0Q2sW1trVw5QdXOHmgUhepk90ecI2rk"
},
"WzOAuth": {
"Code": "CNYICE",
"Token": "9e76f970728c4013a1333a76aa26631e",
//"GetTokenUrl": "http://192.168.100.137/oauth/doAuth",
//"ValidPassUrl": "http://192.168.100.225:12999/herp/employee/validPass"
"GetTokenUrl": "http://localhost:5001/api/Account/WuzhouToken",
"ValidPassUrl": "http://localhost:5001/api/Account/WuzhouValidPass"
},
"AppConnection": { "AppConnection": {
//"PerformanceConnectionString": "server=112.124.13.17;database=db_performance;uid=suvalue;pwd=suvalue2016;pooling=true;charset=utf8;convert zero datetime=true;port=3306;connection timeout=120;max pool size=512;allow user variables=true;", //"PerformanceConnectionString": "server=112.124.13.17;database=db_performance;uid=suvalue;pwd=suvalue2016;pooling=true;charset=utf8;convert zero datetime=true;port=3306;connection timeout=120;max pool size=512;allow user variables=true;",
"PerformanceConnectionString": "server=192.168.18.166;database=db_performance_screen;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=192.168.18.166;database=db_performance_screen;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;"
......
...@@ -4,6 +4,16 @@ ...@@ -4,6 +4,16 @@
"Default": "Warning" "Default": "Warning"
} }
}, },
"Wechat": {
"CorpId": "ww58ec167201a95da7",
"CorpSecret": "1rgWzgJBIZ3r0Q2sW1trVw5QdXOHmgUhepk90ecI2rk"
},
"WzOAuth": {
"Code": "CNYICE",
"Token": "9e76f970728c4013a1333a76aa26631e",
"GetTokenUrl": "http://192.168.100.137/oauth/doAuth",
"ValidPassUrl": "http://192.168.100.225:12999/herp/employee/validPass"
},
//连接字符串 //连接字符串
"AppConnection": { "AppConnection": {
"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;" "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;"
......
...@@ -24,6 +24,32 @@ ...@@ -24,6 +24,32 @@
<param name="request"></param> <param name="request"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:Performance.Api.Controllers.AccountController.WechatLogin(System.String)">
<summary>
微信登录
</summary>
<param name="code"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.AccountController.WuzhouToken">
<summary>
梧州Token假接口
</summary>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.AccountController.WuzhouValidPass">
<summary>
梧州验证登录假接口
</summary>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.AccountController.WuzhouLogin(Performance.DtoModels.WuzhouLoginRequest)">
<summary>
梧州登录
</summary>
<param name="request"></param>
<returns></returns>
</member>
<member name="M:Performance.Api.Controllers.AccountController.Refresh"> <member name="M:Performance.Api.Controllers.AccountController.Refresh">
<summary> <summary>
刷新登录JWT TOKEN 刷新登录JWT TOKEN
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Performance.DtoModels.AppSettings
{
public class Wechat
{
public string CorpId { get; set; }
public string CorpSecret { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Performance.DtoModels.AppSettings
{
public class WzOAuth
{
public string Code { get; set; }
public string Token { get; set; }
public string GetTokenUrl { get; set; }
public string ValidPassUrl { get; set; }
}
}
...@@ -19,7 +19,24 @@ public class LoginRequest ...@@ -19,7 +19,24 @@ public class LoginRequest
public string AppName { get; set; } public string AppName { get; set; }
public string Device { get; set; } public string Device { get; set; }
} }
public class InterfaceRequest
{
public string Url { get; set; }
public string Function { get; set; }
public string Access_token { get; set; }
public string Code { get; set; }
public string X_Token { get; set; }
public WuzhouLoginRequest wuzhouLoginRequest { get; set; }
}
public class WuzhouLoginRequest
{
public string UserId { get; set; }
public string EmpCode { get; set; }
public string Password { get; set; }
public string SocialCode { get; set; }
public string Mobile { get; set; }
}
public class LoginRequestValidator : AbstractValidator<LoginRequest> public class LoginRequestValidator : AbstractValidator<LoginRequest>
{ {
public LoginRequestValidator() public LoginRequestValidator()
......
namespace Performance.DtoModels
{
internal class key
{
}
}
\ No newline at end of file
...@@ -249,5 +249,6 @@ public PerformanceDbContext(DbContextOptions<PerformanceDbContext> options) ...@@ -249,5 +249,6 @@ public PerformanceDbContext(DbContextOptions<PerformanceDbContext> options)
public virtual DbSet<per_attendance> per_attendance { get; set; } public virtual DbSet<per_attendance> per_attendance { get; set; }
public virtual DbSet<per_attendance_type> per_attendance_type { get; set; } public virtual DbSet<per_attendance_type> per_attendance_type { get; set; }
public virtual DbSet<per_attendance_vacation> per_attendance_vacation { get; set; } public virtual DbSet<per_attendance_vacation> per_attendance_vacation { get; set; }
public virtual DbSet<wx_user> wx_user { get; set; }
} }
} }

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Performance.EntityModels.Entity
{
public class wx_user
{
public int Id { get; set; }
public string UserId { get; set; }
public string PersonnelNumber { get; set; }
public DateTime? CreateTime { get; set; }
}
}
using Performance.EntityModels;
using Performance.EntityModels.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Performance.Repository.Repository
{
public class PerforWxUserRepository : PerforRepository<wx_user>
{
public PerforWxUserRepository(PerformanceDbContext context) : base(context)
{
}
}
}
using AutoMapper; using AutoMapper;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using Performance.DtoModels; using Performance.DtoModels;
using Performance.DtoModels.AppSettings; using Performance.DtoModels.AppSettings;
using Performance.EntityModels; using Performance.EntityModels;
using Performance.EntityModels.Entity;
using Performance.Infrastructure; using Performance.Infrastructure;
using Performance.Repository; using Performance.Repository;
using Performance.Repository.Repository;
using RestSharp;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
...@@ -16,6 +20,7 @@ namespace Performance.Services ...@@ -16,6 +20,7 @@ namespace Performance.Services
{ {
public class UserService : IAutoInjection public class UserService : IAutoInjection
{ {
private ILogger<UserService> logger;
private Application application; private Application application;
private PerforUserRepository _userRepository; private PerforUserRepository _userRepository;
private readonly IMapper _mapper; private readonly IMapper _mapper;
...@@ -32,8 +37,12 @@ public class UserService : IAutoInjection ...@@ -32,8 +37,12 @@ public class UserService : IAutoInjection
private PerforPerallotRepository _perallotRepository; private PerforPerallotRepository _perallotRepository;
private PerforPerdeptdicRepository _perdeptdicRepository; private PerforPerdeptdicRepository _perdeptdicRepository;
private readonly PerforCofaccountingRepository perforCofaccountingRepository; private readonly PerforCofaccountingRepository perforCofaccountingRepository;
private readonly PerforWxUserRepository perforWxUserRepository;
private readonly IOptions<Wechat> _wechat;
private readonly IOptions<WzOAuth> _wzOAuth;
public UserService( public UserService(
ILogger<UserService> logger,
IMapper mapper, IMapper mapper,
IOptions<Application> application, IOptions<Application> application,
PerforSmsRepository smsRepository, PerforSmsRepository smsRepository,
...@@ -49,8 +58,12 @@ public class UserService : IAutoInjection ...@@ -49,8 +58,12 @@ public class UserService : IAutoInjection
PerforResaccountRepository resaccountRepository, PerforResaccountRepository resaccountRepository,
PerforPerallotRepository perallotRepository, PerforPerallotRepository perallotRepository,
PerforPerdeptdicRepository perdeptdicRepository, PerforPerdeptdicRepository perdeptdicRepository,
PerforCofaccountingRepository perforCofaccountingRepository) PerforCofaccountingRepository perforCofaccountingRepository,
PerforWxUserRepository perforWxUserRepository,
IOptions<Wechat> wechat,
IOptions<WzOAuth> wzOAuth)
{ {
this.logger = logger;
this.application = application.Value; this.application = application.Value;
this._userRepository = userRepository; this._userRepository = userRepository;
_mapper = mapper; _mapper = mapper;
...@@ -67,8 +80,89 @@ public class UserService : IAutoInjection ...@@ -67,8 +80,89 @@ public class UserService : IAutoInjection
this._perallotRepository = perallotRepository; this._perallotRepository = perallotRepository;
this._perdeptdicRepository = perdeptdicRepository; this._perdeptdicRepository = perdeptdicRepository;
this.perforCofaccountingRepository = perforCofaccountingRepository; this.perforCofaccountingRepository = perforCofaccountingRepository;
this.perforWxUserRepository = perforWxUserRepository;
_wechat = wechat;
_wzOAuth = wzOAuth;
} }
/// <summary>
/// 访问接口
/// </summary>
/// <param name="interfaceRequest"></param>
/// <param name="content"></param>
/// <returns></returns>
public Dictionary<string, object> AccessInterface(InterfaceRequest interfaceRequest, out string content)
{
var restClient = new RestClient(interfaceRequest.Url);
restClient.Timeout = -1;
var request = new RestRequest(Method.POST);
switch (interfaceRequest.Function)
{
case "GatAccess_token":
request.AddQueryParameter("CorpId", _wechat.Value.CorpId);
request.AddQueryParameter("CorpSecret", _wechat.Value.CorpSecret);
break;
case "GetUserId":
request.AddQueryParameter("access_token", interfaceRequest.Access_token);
request.AddQueryParameter("code", interfaceRequest.Code);
break;
case "GetX_Token":
request.AddQueryParameter("Code", _wzOAuth.Value.Code);
request.AddQueryParameter("Token", _wzOAuth.Value.Token);
break;
case "ValidPass":
request.AddHeader("x-token", interfaceRequest.X_Token);
request.AddQueryParameter("empCode", interfaceRequest.wuzhouLoginRequest.EmpCode);
request.AddQueryParameter("password", interfaceRequest.wuzhouLoginRequest.Password);
request.AddQueryParameter("socialCode", interfaceRequest.wuzhouLoginRequest.SocialCode);
request.AddQueryParameter("mobile", interfaceRequest.wuzhouLoginRequest.Mobile);
break;
}
IRestResponse response = restClient.Execute(request);
content = response.Content;
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
return JsonHelper.Deserialize<Dictionary<string, object>>(response.Content);
}
else
{
logger.LogError($"接口请求错误:{response.StatusCode},{response.Content}");
return null;
}
}
/// <summary>
/// 获取微信绑定用户的工号
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public string GetWxUserEmpCode(string userId)
{
var wxUser = perforWxUserRepository.GetEntity(t => t.UserId == userId);
if (wxUser == null)
return "";
return wxUser.PersonnelNumber;
}
/// <summary>
/// 如果数据库里不存在该用户则添加
/// </summary>
/// <param name="userId"></param>
/// <param name="empCode"></param>
/// <returns></returns>
public bool SaveWxUser(string userId, string empCode)
{
if (string.IsNullOrEmpty(GetWxUserEmpCode(userId)))
{
var wx_user = new wx_user()
{
UserId = userId,
PersonnelNumber = empCode,
CreateTime = DateTime.Now
};
return perforWxUserRepository.Add(wx_user);
}
return false;
}
/// <summary> /// <summary>
/// 登录 /// 登录
/// </summary> /// </summary>
...@@ -816,9 +910,9 @@ public string SaveUserHandsFlat(UserCollectData request) ...@@ -816,9 +910,9 @@ public string SaveUserHandsFlat(UserCollectData request)
} }
_userRepository.AddRange(users.ToArray()); _userRepository.AddRange(users.ToArray());
var joinData = users.Join(allDataList, var joinData = users.Join(allDataList,
outer => new { outer.Login, outer.RealName, Department = outer.Department ?? "" }, outer => new { outer.Login, outer.RealName, Department = outer.Department ?? "" },
inner => new { inner.Login, inner.RealName, Department = inner.Department ?? "" }, inner => new { inner.Login, inner.RealName, Department = inner.Department ?? "" },
(outer, inner) => new { outer, inner }); (outer, inner) => new { outer, inner });
......
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