using Microsoft.AspNetCore.Mvc;
using System;
using Znyc.Recruitment.Admin.Commons.Entitys;
using Znyc.Recruitment.Admin.Commons.IServices;
namespace Znyc.Recruitment.Admin.AspNetCore.Controllers
{
///
/// 基本控制器,增删改查
///
/// 实体类型
/// 数据输出实体类型
/// 数据输入实体类型
/// Service类型
/// 主键数据类型
[ApiController]
public abstract class AreaApiController : ApiController
where T : Entity
where TService : IService
where TODto : class
where TIDto : class
where TKey : IEquatable
{
#region 属性变量
///
/// 服务接口
///
public TService _service;
#endregion 属性变量
#region 构造函数及常用
///
/// 构造方法
///
///
public AreaApiController(TService service)
{
_service = service;
}
#endregion 构造函数及常用
#region 查询单个实体
// ///
// /// 根据主键Id获取一个对象信息
// ///
// /// 主键Id
// ///
// [HttpGet("GetById")]
//// [FunctionAuthorize("")]
// //[NoPermissionRequired]
// [AllowAnonymous]
// public virtual async Task> GetById(TKey id)
// {
// var result = new CommonResult();
// var info = await _service.GetOutDtoAsync(id);
// if (info != null)
// {
// result.ErrCode = ErrCode.successCode;
// result.ResData = info;
// }
// else
// {
// result.ErrMsg = ErrCode.err50001;
// result.ErrCode = "50001";
// }
// return result;
// }
#endregion 查询单个实体
//#region 返回集合的接口
/////
///// 根据条件查询数据库,并返回对象集合(用于分页数据显示)
/////
///// 查询条件
///// 指定对象的集合
//[HttpPost("FindWithPager")]
//[FunctionAuthorize("List")]
//public virtual CommonResult> FindWithPager(SearchInputDto search)
//{
// var result = new CommonResult>();
// result.ResData = _service.FindWithPager(search);
// result.ErrCode = ErrCode.successCode;
// return result;
//}
/////
///// 根据条件查询数据库,并返回对象集合(用于分页数据显示)
/////
/////
/////
//[HttpPost("FindWithPagerAsync")]
//[FunctionAuthorize("List")]
//public virtual async Task>> FindWithPagerAsync(SearchInputDto search)
//{
// var result = new CommonResult>();
// result.ResData = await _service.FindWithPagerAsync(search);
// result.ErrCode = ErrCode.successCode;
// return result;
//}
///
/// 获取所有可用的
///
///
//[HttpGet("GetAllEnable")]
//[FunctionAuthorize("List")]
//public virtual async Task>> GetAllEnable()
//{
// var result = new CommonResult>();
// var list = await _service.GetAllByIsNotDeleteAndEnabledMarkAsync();
// var resultList = list.MapTo();
// result.ResData = resultList;
// result.ErrCode = ErrCode.successCode;
// result.ErrMsg = ErrCode.err0;
// return result;
//}
#region 公共添加、修改、删除、软删除接口
///
/// 在插入数据前对数据的修改操作
///
///
///
protected virtual void OnBeforeInsert(T info)
{
//留给子类对参数对象进行修改
}
///
/// 在更新数据前对数据的修改操作
///
///
///
protected virtual void OnBeforeUpdate(T info)
{
//留给子类对参数对象进行修改
}
///
/// 在软删除数据前对数据的修改操作
///
///
///
protected virtual void OnBeforeSoftDelete(T info)
{
//留给子类对参数对象进行修改
}
/////
///// 异步新增数据,无效
/////
/////
/////
//[HttpPost("Insert")]
//[FunctionAuthorize("Add")]
//public virtual async Task InsertAsync(TIDto tinfo)
//{
// var result = new CommonResult();
// var info = tinfo.MapTo();
// OnBeforeInsert(info);
// long ln = await _service.InsertAsync(info).ConfigureAwait(false);
// if (ln > 0)
// {
// result.ErrCode = ErrCode.successCode;
// result.ErrMsg = ErrCode.err0;
// }
// else
// {
// result.ErrMsg = ErrCode.err43001;
// result.ErrCode = "43001";
// }
// return ToJsonContent(result);
//}
/////
///// 异步更新数据,需要在业务模块控制器重写该方法,否则更新无效
/////
/////
/////
//[HttpPost("Update")]
//[FunctionAuthorize("Edit")]
//public virtual async Task UpdateAsync(TIDto inInfo)
//{
// var result = new CommonResult();
// return ToJsonContent(result);
//}
/////
///// 物理删除
/////
///// 主键Id
//[HttpDelete("Delete")]
//[FunctionAuthorize("Delete")]
//public virtual IActionResult Delete(TKey id)
//{
// var result = new CommonResult();
// var bl = _service.Delete(id);
// if (bl)
// {
// result.ErrCode = ErrCode.successCode;
// result.ErrMsg = ErrCode.err0;
// }
// else
// {
// result.ErrMsg = ErrCode.err43003;
// result.ErrCode = "43003";
// }
// return ToJsonContent(result);
//}
/////
///// 异步物理删除
/////
///// 主键Id
//[HttpDelete("DeleteAsync")]
//[FunctionAuthorize("Delete")]
//public virtual async Task DeleteAsync(TKey id)
//{
// var result = new CommonResult();
// var bl = await _service.DeleteAsync(id).ConfigureAwait(false);
// if (bl)
// {
// result.ErrCode = ErrCode.successCode;
// result.ErrMsg = ErrCode.err0;
// }
// else
// {
// result.ErrMsg = ErrCode.err43003;
// result.ErrCode = "43003";
// }
// return ToJsonContent(result);
//}
/////
///// 异步批量物理删除
/////
/////
//[HttpDelete("DeleteBatchAsync")]
//[FunctionAuthorize("Delete")]
//public virtual async Task DeleteBatchAsync(DeletesInputDto info)
//{
// var result = new CommonResult();
// var where = string.Empty;
// if (typeof(TKey) == typeof(string))
// @where = "id in ('" + info.Ids.Join(",").Trim(',').Replace(",", "','") + "')";
// else if (typeof(TKey) == typeof(int)) @where = "id in (" + info.Ids.Join(",") + ")";
// if (!string.IsNullOrEmpty(where))
// {
// var bl = await _service.DeleteBatchWhereAsync(where).ConfigureAwait(false);
// if (bl)
// {
// result.ErrCode = ErrCode.successCode;
// result.ErrMsg = ErrCode.err0;
// }
// else
// {
// result.ErrMsg = ErrCode.err43003;
// result.ErrCode = "43003";
// }
// }
// return ToJsonContent(result);
//}
/////
///// 软删除信息
/////
///// 主键Id
///// 删除标识,默认为1:即设为删除,0:未删除
//[HttpPost("DeleteSoft")]
//[FunctionAuthorize("DeleteSoft")]
//public virtual IActionResult DeleteSoft(TKey id, string bltag = "1")
//{
// var result = new CommonResult();
// var bl = false;
// if (bltag == "0") bl = true;
// var blResult = _service.DeleteSoft(bl, id, CurrentUser.UserId);
// if (blResult)
// {
// result.ErrCode = ErrCode.successCode;
// result.ErrMsg = ErrCode.err0;
// }
// else
// {
// result.ErrMsg = ErrCode.err43002;
// result.ErrCode = "43002";
// }
// return ToJsonContent(result);
//}
///
/// 异步软删除信息
///
/// 主键Id
/// 删除标识,默认为1:即设为删除,0:未删除
//[HttpDelete("DeleteSoftAsync")]
//[FunctionAuthorize("DeleteSoft")]
//public virtual async Task DeleteSoftAsync(TKey id, string bltag = "1")
//{
// var result = new CommonResult();
// var bl = false;
// if (bltag == "0") bl = true;
// var blResult = await _service.DeleteSoftAsync(bl, id, CurrentUser.UserId);
// if (blResult)
// {
// result.ErrCode = ErrCode.successCode;
// result.ErrMsg = ErrCode.err0;
// }
// else
// {
// result.ErrMsg = ErrCode.err43002;
// result.ErrCode = "43002";
// }
// return ToJsonContent(result);
//}
/////
///// 异步批量软删除信息
/////
/////
/////
//[HttpDelete("DeleteSoftBatchAsync")]
//[FunctionAuthorize("DeleteSoft")]
//public virtual async Task DeleteSoftBatchAsync(UpdateEnableViewModel info)
//{
// var result = new CommonResult();
// var where = string.Empty;
// if (typeof(int) == typeof(string))
// @where = "id in ('" + info.Ids.Join(",").Trim(',').Replace(",", "','") + "')";
// else if (typeof(int) == typeof(int)) @where = "id in (" + info.Ids.Join(",") + ")";
// if (!string.IsNullOrEmpty(where))
// {
// var bl = false;
// if (info.Flag == "1") bl = true;
// var blResult = await _service.DeleteSoftBatchAsync(bl, where, CurrentUser.UserId);
// if (blResult)
// {
// result.ErrCode = ErrCode.successCode;
// result.ErrMsg = ErrCode.err0;
// }
// else
// {
// result.ErrMsg = ErrCode.err43002;
// result.ErrCode = "43002";
// }
// }
// return ToJsonContent(result);
//}
#endregion 公共添加、修改、删除、软删除接口
// #endregion
}
}