You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
266 lines
8.2 KiB
C#
266 lines
8.2 KiB
C#
using Common;
|
|
using Common.DJYModel;
|
|
using Common.Extensions;
|
|
using Common.Tools;
|
|
using Common.Utilities;
|
|
using djy.IService.Djy;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace djy_AfrApi.Controllers
|
|
{
|
|
|
|
/// <summary>
|
|
/// api接口基类
|
|
/// </summary>
|
|
public class ApiBase : Controller
|
|
{
|
|
#region 构建响应对象
|
|
[NonAction]
|
|
protected ResponsePage<T> SuccessPage<T>(PageModel<T> pageModel)
|
|
{
|
|
if (pageModel is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(pageModel));
|
|
}
|
|
|
|
return new ResponsePage<T>()
|
|
{
|
|
Code = 200,
|
|
Message = "查询成功",
|
|
Result = pageModel.Result,
|
|
Count = pageModel.Count,
|
|
PageNumber = pageModel.PageNumber,
|
|
PageSize = pageModel.PageSize
|
|
};
|
|
}
|
|
[NonAction]
|
|
protected Response SuccessResp(string message = "操作成功")
|
|
{
|
|
return new Response()
|
|
{
|
|
Code = 200,
|
|
Message = message
|
|
};
|
|
}
|
|
[NonAction]
|
|
protected Response<T> SuccessResp<T>(T result)
|
|
{
|
|
return new Response<T>()
|
|
{
|
|
Code = 200,
|
|
Message = "操作成功",
|
|
Result = result
|
|
};
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region http数据获取
|
|
/// <summary>
|
|
/// 创建日志
|
|
/// </summary>
|
|
/// <param name="Message">内容</param>
|
|
/// <param name="GroupName"></param>
|
|
/// <param name="DataJson"></param>
|
|
/// <param name="ObjGid"></param>
|
|
/// <param name="ResultJson"></param>
|
|
protected void _LogsAdd(string Message, string GroupName = null, object DataJson = null, string ObjGid = null, object ResultJson = null)
|
|
{
|
|
var toolsserver = IOC.AddServer<IToolsService>();
|
|
toolsserver.LogsAdd(Message, GroupName, DataJson, ObjGid, ResultJson);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取大简云设置权限
|
|
/// </summary>
|
|
/// <param name="KeyName">keyname标识</param>
|
|
/// <returns></returns>
|
|
protected DJyUserAuthorityDto GetDJyUserAuthority(string KeyName)
|
|
{
|
|
var _djyserver = IOC.AddServer<IDjyUserService>();
|
|
var rs = _djyserver.GetUserAuthority(GetLoginId, KeyName);
|
|
if (rs.Status)
|
|
{
|
|
return rs.Data;
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 获取登录详情信息
|
|
/// </summary>
|
|
/// <param name="UserGid"></param>
|
|
protected User GetUserInfo(Guid? UserGid = null)
|
|
{
|
|
var _suser = IOC.AddServer<IDjyUserService>();
|
|
if (UserGid == null)
|
|
{ UserGid = GetLoginId; }
|
|
var rs = _suser.GetUserInfo(UserGid.ToString());
|
|
if (rs.Status)
|
|
{
|
|
return rs.Data;
|
|
}
|
|
else
|
|
{ return null; }
|
|
}
|
|
|
|
/// <summary>
|
|
/// 统一获取大简云权限查询权限的userid companyid 没有权限则指定userid和companyid 为不存的guid值
|
|
/// </summary>
|
|
/// <typeparam name="T"></typeparam>
|
|
/// <param name="BindData"></param>
|
|
/// <param name="KeyName">模块keyname标识</param>
|
|
/// <param name="type">0 查询查看权限 1 操作更新权限 默认 0</param>
|
|
/// <returns></returns>
|
|
protected UserAuthorityDto GetUserAuthorityToFormDto(string KeyName, int type = 0)
|
|
{
|
|
//本人的绑定UserId 全部 userid 和 compayid不做绑定 注册公司的 绑定 companyid 没有权限则指定userid和companyid 为不存的guid值
|
|
var RetrunData = new UserAuthorityDto();
|
|
var _djyserver = IOC.AddServer<IDjyUserService>();
|
|
User User;
|
|
User = null;
|
|
var uuid = GetLoginId.ToString();
|
|
var userrs = _djyserver.GetUserInfo(GetLoginId.ToString());
|
|
|
|
var notguid = Guid.Parse("00000000-0000-0000-0000-000000000001");
|
|
|
|
RetrunData.CompayId = null;
|
|
|
|
if (userrs.Status)
|
|
{
|
|
User = userrs.Data;
|
|
RetrunData.CompayId = Guid.Parse(User.CompId);
|
|
}
|
|
if (User == null)
|
|
{
|
|
RetrunData.UserId = notguid;
|
|
RetrunData.CompayId = notguid;
|
|
}
|
|
|
|
var aut = GetDJyUserAuthority(KeyName);
|
|
if (aut != null)
|
|
{//根据权限处理 _userid 和 _companyid 值
|
|
RetrunData.IsPower = true;
|
|
var _useraut = aut.Visiblerange;
|
|
if (type == 1)
|
|
{
|
|
_useraut = aut.Operaterange;
|
|
}
|
|
switch (_useraut)
|
|
{
|
|
|
|
case 0://全部
|
|
RetrunData.UserId = null;
|
|
RetrunData.CompayId = null;
|
|
break;
|
|
case 1://本公司
|
|
RetrunData.UserId = null;
|
|
RetrunData.CompayId = Guid.Parse(User.CompId);
|
|
break;
|
|
case 3://本人
|
|
RetrunData.UserId = GetLoginId;
|
|
RetrunData.CompayId = null;
|
|
break;
|
|
case 4://无权限或或默认权限
|
|
//_uerid = notguid;
|
|
//_companyid = notguid;
|
|
RetrunData.UserId = null;
|
|
RetrunData.CompayId = null;
|
|
break;
|
|
|
|
case 7://注册公司
|
|
RetrunData.UserId = null;
|
|
RetrunData.CompayId = Guid.Parse(User.CompId);
|
|
break;
|
|
default:
|
|
RetrunData.UserId = notguid;
|
|
RetrunData.CompayId = notguid;
|
|
break;
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
RetrunData.UserId = GetLoginId;
|
|
RetrunData.CompayId = null;
|
|
RetrunData.IsPower = true;
|
|
}
|
|
|
|
//if (sysOptionConfig.Webconfig.IsDev)
|
|
//{
|
|
// RetrunData.UserId = null;
|
|
// RetrunData.CompayId =null;
|
|
// RetrunData.IsPower = true;
|
|
//}
|
|
|
|
return RetrunData;
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// 获取登录Id
|
|
/// </summary>
|
|
protected Guid? GetLoginId { get { return Guid.Parse(GetClaimsValue("loginid")); } }
|
|
|
|
/// <summary>
|
|
/// 获取登录类型
|
|
/// </summary>
|
|
protected EnumUser.UserType GetLoginType
|
|
{
|
|
get
|
|
{
|
|
var type = GetClaimsValue("logintype");
|
|
if (type.Isint())
|
|
{
|
|
return (EnumUser.UserType)int.Parse(type);
|
|
}
|
|
else { return EnumUser.UserType.All; }
|
|
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据key获取claims值 没有则返回null
|
|
/// </summary>
|
|
/// <param name="Key"></param>
|
|
/// <param name="IsDecrtypt">是否是加密</param>
|
|
/// <returns></returns>
|
|
protected string GetClaimsValue(string Key, bool IsDecrtypt = true)
|
|
{
|
|
try
|
|
{
|
|
var claims = HttpContext.User.Claims;
|
|
|
|
var id = claims.SingleOrDefault(s => s.Type == Key);
|
|
if (id == null)
|
|
{
|
|
return "0";
|
|
}
|
|
|
|
return IsDecrtypt ? _DecryptDES(id.Value) : id.Value;
|
|
}
|
|
catch
|
|
{
|
|
return null;
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// DES解密
|
|
/// </summary>
|
|
/// <param name="value"></param>
|
|
/// <returns></returns>
|
|
protected static string _DecryptDES(string value)
|
|
{
|
|
return SafeTools.DecryptDES(value, sysOptionConfig.Webconfig.DesKey);
|
|
}
|
|
#endregion
|
|
}
|
|
}
|