@ -2,8 +2,8 @@
using Common.DJYModel ;
using Common.DJYModel ;
using Common.Extensions ;
using Common.Extensions ;
using Common.Tools ;
using Common.Tools ;
using Common.Utilities ;
using djy.IService.Djy ;
using djy.IService.Djy ;
using Microsoft.AspNetCore.Authorization ;
using Microsoft.AspNetCore.Http ;
using Microsoft.AspNetCore.Http ;
using Microsoft.AspNetCore.Mvc ;
using Microsoft.AspNetCore.Mvc ;
using System ;
using System ;
@ -15,14 +15,35 @@ namespace djy_AfrApi.Controllers
/// <summary>
/// <summary>
/// api接口基类
/// api接口基类
/// </summary>
/// </summary>
[Route("api/[controller] ")]
[ApiController]
[Authorize]
public class ApiBase : Controller
public class ApiBase : Controller
{
{
#region http数据获取
#region 构建响应对象
[NonAction]
protected ResponsePage < T > SuccessPage < T > ( PageModel < T > 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
} ;
}
# endregion
#region http数据获取
/// <summary>
/// <summary>
/// 创建日志
/// 创建日志
/// </summary>
/// </summary>
@ -42,14 +63,16 @@ namespace djy_AfrApi.Controllers
/// </summary>
/// </summary>
/// <param name="KeyName">keyname标识</param>
/// <param name="KeyName">keyname标识</param>
/// <returns></returns>
/// <returns></returns>
protected DJyUserAuthorityDto GetDJyUserAuthority ( string KeyName ) {
protected DJyUserAuthorityDto GetDJyUserAuthority ( string KeyName )
{
var _djyserver = IOC . AddServer < IDjyUserService > ( ) ;
var _djyserver = IOC . AddServer < IDjyUserService > ( ) ;
var rs = _djyserver . GetUserAuthority ( GetLoginId , KeyName ) ;
var rs = _djyserver . GetUserAuthority ( GetLoginId , KeyName ) ;
if ( rs . Status )
if ( rs . Status )
{
{
return rs . Data ;
return rs . Data ;
}
}
else {
else
{
return null ;
return null ;
}
}
}
}
@ -57,7 +80,7 @@ namespace djy_AfrApi.Controllers
/// 获取登录详情信息
/// 获取登录详情信息
/// </summary>
/// </summary>
/// <param name="UserGid"></param>
/// <param name="UserGid"></param>
protected User GetUserInfo ( Guid ? UserGid = null )
protected User GetUserInfo ( Guid ? UserGid = null )
{
{
var _suser = IOC . AddServer < IDjyUserService > ( ) ;
var _suser = IOC . AddServer < IDjyUserService > ( ) ;
if ( UserGid = = null )
if ( UserGid = = null )
@ -79,7 +102,8 @@ namespace djy_AfrApi.Controllers
/// <param name="KeyName">模块keyname标识</param>
/// <param name="KeyName">模块keyname标识</param>
/// <param name="type">0 查询查看权限 1 操作更新权限 默认 0</param>
/// <param name="type">0 查询查看权限 1 操作更新权限 默认 0</param>
/// <returns></returns>
/// <returns></returns>
protected UserAuthorityDto GetUserAuthorityToFormDto ( string KeyName , int type = 0 ) {
protected UserAuthorityDto GetUserAuthorityToFormDto ( string KeyName , int type = 0 )
{
//本人的绑定UserId 全部 userid 和 compayid不做绑定 注册公司的 绑定 companyid 没有权限则指定userid和companyid 为不存的guid值
//本人的绑定UserId 全部 userid 和 compayid不做绑定 注册公司的 绑定 companyid 没有权限则指定userid和companyid 为不存的guid值
var RetrunData = new UserAuthorityDto ( ) ;
var RetrunData = new UserAuthorityDto ( ) ;
var _djyserver = IOC . AddServer < IDjyUserService > ( ) ;
var _djyserver = IOC . AddServer < IDjyUserService > ( ) ;
@ -87,9 +111,9 @@ namespace djy_AfrApi.Controllers
User = null ;
User = null ;
var uuid = GetLoginId . ToString ( ) ;
var uuid = GetLoginId . ToString ( ) ;
var userrs = _djyserver . GetUserInfo ( GetLoginId . ToString ( ) ) ;
var userrs = _djyserver . GetUserInfo ( GetLoginId . ToString ( ) ) ;
var notguid = Guid . Parse ( "00000000-0000-0000-0000-000000000001" ) ;
var notguid = Guid . Parse ( "00000000-0000-0000-0000-000000000001" ) ;
RetrunData . CompayId = null ;
RetrunData . CompayId = null ;
if ( userrs . Status )
if ( userrs . Status )
@ -107,11 +131,13 @@ namespace djy_AfrApi.Controllers
if ( aut ! = null )
if ( aut ! = null )
{ //根据权限处理 _userid 和 _companyid 值
{ //根据权限处理 _userid 和 _companyid 值
RetrunData . IsPower = true ;
RetrunData . IsPower = true ;
var _useraut = aut . Visiblerange ;
var _useraut = aut . Visiblerange ;
if ( type = = 1 ) {
if ( type = = 1 )
{
_useraut = aut . Operaterange ;
_useraut = aut . Operaterange ;
}
}
switch ( _useraut ) {
switch ( _useraut )
{
case 0 : //全部
case 0 : //全部
RetrunData . UserId = null ;
RetrunData . UserId = null ;
@ -134,12 +160,12 @@ namespace djy_AfrApi.Controllers
case 7 : //注册公司
case 7 : //注册公司
RetrunData . UserId = null ;
RetrunData . UserId = null ;
RetrunData . CompayId = Guid . Parse ( User . CompId ) ;
RetrunData . CompayId = Guid . Parse ( User . CompId ) ;
break ;
break ;
default :
default :
RetrunData . UserId = notguid ;
RetrunData . UserId = notguid ;
RetrunData . CompayId = notguid ;
RetrunData . CompayId = notguid ;
break ;
break ;
}
}
}
}
@ -152,9 +178,9 @@ namespace djy_AfrApi.Controllers
//if (sysOptionConfig.Webconfig.IsDev)
//if (sysOptionConfig.Webconfig.IsDev)
//{
//{
// RetrunData.UserId = null;
// RetrunData.UserId = null;
// RetrunData.CompayId =null;
// RetrunData.CompayId =null;
// RetrunData.IsPower = true;
// RetrunData.IsPower = true;
//}
//}
return RetrunData ;
return RetrunData ;
@ -165,7 +191,7 @@ namespace djy_AfrApi.Controllers
/// <summary>
/// <summary>
/// 获取登录Id
/// 获取登录Id
/// </summary>
/// </summary>
protected Guid ? GetLoginId { get { return Guid . Parse ( GetClaimsValue ( "loginid" ) ) ; } }
protected Guid ? GetLoginId { get { return Guid . Parse ( GetClaimsValue ( "loginid" ) ) ; } }
/// <summary>
/// <summary>
/// 获取登录类型
/// 获取登录类型
@ -204,8 +230,9 @@ namespace djy_AfrApi.Controllers
return IsDecrtypt ? _DecryptDES ( id . Value ) : id . Value ;
return IsDecrtypt ? _DecryptDES ( id . Value ) : id . Value ;
}
}
catch {
catch
return null ;
{
return null ;
}
}
}
}
@ -220,82 +247,4 @@ namespace djy_AfrApi.Controllers
}
}
# endregion
# endregion
}
}
/// <summary>
///api接口基类
/// </summary>
/// <typeparam name="IS">接口类型比如 Iservice</typeparam>
public class ApiBase < IS > : ApiBase
{
/// <summary>
///
/// </summary>
protected IS _server = IOC . AddServer < IS > ( ) ;
/// <summary>
/// 执行指定的方法
/// </summary>
/// <param name="methodName">方法名称</param>
/// <param name="parameters">参数对象队列</param>
/// <returns></returns>
protected object _InvokeServer ( string methodName , object [ ] parameters )
{
return _server . GetType ( ) . GetMethod ( methodName ) . Invoke ( _server , parameters ) ;
}
}
/// <summary>
/// api接口基类
/// </summary>
/// <typeparam name="IS">接口类型比如 Iservice</typeparam>
/// <typeparam name="D">Dto Model</typeparam>
/// <typeparam name="T">Tables数据表model</typeparam>
public class ApiBase < IS , D , T > : ApiBase < IS >
{
/// <summary>
/// 根据Id获取实体
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
protected virtual object _GetId ( long Id )
{
return _InvokeServer ( "GetId" , new object [ ] { Id } ) ;
}
/// <summary>
///基础的创建接口 提交创建对象
/// </summary>
/// <param name="Dto"></param>
/// <returns></returns>
protected virtual object _Add ( T Dto )
{
return _InvokeServer ( "Add" , new object [ ] { Dto } ) ;
}
/// <summary>
/// 最基础的更新接口 传递要更新的数据对象 必须有Id
/// </summary>
/// <param name="Dto"></param>
/// <returns></returns>
protected virtual object _Up ( T Dto )
{
return _InvokeServer ( "Up" , new object [ ] { Dto , null , null } ) ;
}
/// <summary>
/// 最基础的删除接口 [1,2,3]
/// </summary>
/// <param name="Idlist"></param>
/// <returns></returns>
protected virtual object _Del ( long [ ] Idlist )
{
return _InvokeServer ( "Del" , new object [ ] { Idlist } ) ;
}
}
}
}