You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
373 lines
13 KiB
373 lines
13 KiB
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using Znyc.Cloudcar.Admin.Commons.Entitys;
|
|
using Znyc.Cloudcar.Admin.Commons.IServices;
|
|
|
|
namespace Znyc.Cloudcar.Admin.AspNetCore.Controllers
|
|
{
|
|
/// <summary>
|
|
/// 基本控制器,增删改查
|
|
/// </summary>
|
|
/// <typeparam name="T">实体类型</typeparam>
|
|
/// <typeparam name="TODto">数据输出实体类型</typeparam>
|
|
/// <typeparam name="TIDto">数据输入实体类型</typeparam>
|
|
/// <typeparam name="TService">Service类型</typeparam>
|
|
/// <typeparam name="TKey">主键数据类型</typeparam>
|
|
[ApiController]
|
|
public abstract class AreaApiController<T, TODto, TIDto, TService, TKey> : ApiController
|
|
where T : Entity
|
|
where TService : IService<T, TODto, TKey>
|
|
where TODto : class
|
|
where TIDto : class
|
|
where TKey : IEquatable<TKey>
|
|
{
|
|
#region 属性变量
|
|
|
|
/// <summary>
|
|
/// 服务接口
|
|
/// </summary>
|
|
public TService _service;
|
|
|
|
#endregion 属性变量
|
|
|
|
#region 构造函数及常用
|
|
|
|
/// <summary>
|
|
/// 构造方法
|
|
/// </summary>
|
|
/// <param name="service"></param>
|
|
public AreaApiController(TService service)
|
|
{
|
|
_service = service;
|
|
}
|
|
|
|
#endregion 构造函数及常用
|
|
|
|
#region 查询单个实体
|
|
|
|
// /// <summary>
|
|
// /// 根据主键Id获取一个对象信息
|
|
// /// </summary>
|
|
// /// <param name="id">主键Id</param>
|
|
// /// <returns></returns>
|
|
// [HttpGet("GetById")]
|
|
//// [FunctionAuthorize("")]
|
|
// //[NoPermissionRequired]
|
|
// [AllowAnonymous]
|
|
// public virtual async Task<CommonResult<TODto>> GetById(TKey id)
|
|
// {
|
|
// var result = new CommonResult<TODto>();
|
|
// 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 返回集合的接口
|
|
|
|
///// <summary>
|
|
///// 根据条件查询数据库,并返回对象集合(用于分页数据显示)
|
|
///// </summary>
|
|
///// <param name="search">查询条件</param>
|
|
///// <returns>指定对象的集合</returns>
|
|
//[HttpPost("FindWithPager")]
|
|
//[FunctionAuthorize("List")]
|
|
//public virtual CommonResult<PageResult<TODto>> FindWithPager(SearchInputDto<T> search)
|
|
//{
|
|
// var result = new CommonResult<PageResult<TODto>>();
|
|
// result.ResData = _service.FindWithPager(search);
|
|
// result.ErrCode = ErrCode.successCode;
|
|
// return result;
|
|
//}
|
|
|
|
///// <summary>
|
|
///// 根据条件查询数据库,并返回对象集合(用于分页数据显示)
|
|
///// </summary>
|
|
///// <param name="search"></param>
|
|
///// <returns></returns>
|
|
//[HttpPost("FindWithPagerAsync")]
|
|
//[FunctionAuthorize("List")]
|
|
//public virtual async Task<CommonResult<PageResult<TODto>>> FindWithPagerAsync(SearchInputDto<T> search)
|
|
//{
|
|
// var result = new CommonResult<PageResult<TODto>>();
|
|
// result.ResData = await _service.FindWithPagerAsync(search);
|
|
// result.ErrCode = ErrCode.successCode;
|
|
// return result;
|
|
//}
|
|
|
|
/// <summary>
|
|
/// 获取所有可用的
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
//[HttpGet("GetAllEnable")]
|
|
//[FunctionAuthorize("List")]
|
|
//public virtual async Task<CommonResult<List<TODto>>> GetAllEnable()
|
|
//{
|
|
// var result = new CommonResult<List<TODto>>();
|
|
// var list = await _service.GetAllByIsNotDeleteAndEnabledMarkAsync();
|
|
// var resultList = list.MapTo<TODto>();
|
|
// result.ResData = resultList;
|
|
// result.ErrCode = ErrCode.successCode;
|
|
// result.ErrMsg = ErrCode.err0;
|
|
|
|
// return result;
|
|
//}
|
|
|
|
#region 公共添加、修改、删除、软删除接口
|
|
|
|
/// <summary>
|
|
/// 在插入数据前对数据的修改操作
|
|
/// </summary>
|
|
/// <param name="info"></param>
|
|
/// <returns></returns>
|
|
protected virtual void OnBeforeInsert(T info)
|
|
{
|
|
//留给子类对参数对象进行修改
|
|
}
|
|
|
|
/// <summary>
|
|
/// 在更新数据前对数据的修改操作
|
|
/// </summary>
|
|
/// <param name="info"></param>
|
|
/// <returns></returns>
|
|
protected virtual void OnBeforeUpdate(T info)
|
|
{
|
|
//留给子类对参数对象进行修改
|
|
}
|
|
|
|
/// <summary>
|
|
/// 在软删除数据前对数据的修改操作
|
|
/// </summary>
|
|
/// <param name="info"></param>
|
|
/// <returns></returns>
|
|
protected virtual void OnBeforeSoftDelete(T info)
|
|
{
|
|
//留给子类对参数对象进行修改
|
|
}
|
|
|
|
///// <summary>
|
|
///// 异步新增数据,无效
|
|
///// </summary>
|
|
///// <param name="tinfo"></param>
|
|
///// <returns></returns>
|
|
//[HttpPost("Insert")]
|
|
//[FunctionAuthorize("Add")]
|
|
//public virtual async Task<IActionResult> InsertAsync(TIDto tinfo)
|
|
//{
|
|
// var result = new CommonResult();
|
|
// var info = tinfo.MapTo<T>();
|
|
// 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);
|
|
//}
|
|
|
|
///// <summary>
|
|
///// 异步更新数据,需要在业务模块控制器重写该方法,否则更新无效
|
|
///// </summary>
|
|
///// <param name="inInfo"></param>
|
|
///// <returns></returns>
|
|
//[HttpPost("Update")]
|
|
//[FunctionAuthorize("Edit")]
|
|
//public virtual async Task<IActionResult> UpdateAsync(TIDto inInfo)
|
|
//{
|
|
// var result = new CommonResult();
|
|
// return ToJsonContent(result);
|
|
//}
|
|
|
|
///// <summary>
|
|
///// 物理删除
|
|
///// </summary>
|
|
///// <param name="id">主键Id</param>
|
|
//[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);
|
|
//}
|
|
|
|
///// <summary>
|
|
///// 异步物理删除
|
|
///// </summary>
|
|
///// <param name="id">主键Id</param>
|
|
//[HttpDelete("DeleteAsync")]
|
|
//[FunctionAuthorize("Delete")]
|
|
//public virtual async Task<IActionResult> 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);
|
|
//}
|
|
|
|
///// <summary>
|
|
///// 异步批量物理删除
|
|
///// </summary>
|
|
///// <param name="info"></param>
|
|
//[HttpDelete("DeleteBatchAsync")]
|
|
//[FunctionAuthorize("Delete")]
|
|
//public virtual async Task<IActionResult> 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);
|
|
//}
|
|
|
|
///// <summary>
|
|
///// 软删除信息
|
|
///// </summary>
|
|
///// <param name="id">主键Id</param>
|
|
///// <param name="bltag">删除标识,默认为1:即设为删除,0:未删除</param>
|
|
//[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);
|
|
//}
|
|
|
|
/// <summary>
|
|
/// 异步软删除信息
|
|
/// </summary>
|
|
/// <param name="id">主键Id</param>
|
|
/// <param name="bltag">删除标识,默认为1:即设为删除,0:未删除</param>
|
|
//[HttpDelete("DeleteSoftAsync")]
|
|
//[FunctionAuthorize("DeleteSoft")]
|
|
//public virtual async Task<IActionResult> 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);
|
|
//}
|
|
|
|
///// <summary>
|
|
///// 异步批量软删除信息
|
|
///// </summary>
|
|
///// <param name="info"></param>
|
|
///// <returns></returns>
|
|
//[HttpDelete("DeleteSoftBatchAsync")]
|
|
//[FunctionAuthorize("DeleteSoft")]
|
|
//public virtual async Task<IActionResult> 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
|
|
}
|
|
}
|