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.
 
 

123 lines
3.8 KiB

using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
using Znyc.Cloudcar.Admin.AspNetCore.Controllers;
using Znyc.Cloudcar.Admin.AspNetCore.Entitys;
using Znyc.Cloudcar.Admin.AspNetCore.Mvc;
using Znyc.Cloudcar.Admin.Commons.Encrypt;
using Znyc.Cloudcar.Admin.Commons.Entitys;
using Znyc.Cloudcar.Admin.Commons.Helpers;
using Znyc.Cloudcar.Admin.Security.Dtos;
using Znyc.Cloudcar.Admin.Security.Entitys;
using Znyc.Cloudcar.Admin.Security.IServices;
namespace Znyc.Cloudcar.Admin.WebApi.Controllers
{
/// <summary>
/// 应用管理接口
/// </summary>
[ApiController]
[Route("api/Security/[controller]")]
public class APPController : AreaApiController<APPEntity, AppOutputDto, APPInputDto, IAPPService,
long>
{
/// <summary>
/// 构造函数
/// </summary>
/// <param name="service"></param>
public APPController(IAPPService service) : base(service)
{
_service = service;
}
/// <summary>
/// 新增前处理数据
/// </summary>
/// <param name="info"></param>
protected override void OnBeforeInsert(APPEntity info)
{
info.Id = 0;
info.AppSecret = MD5Util.GetMD5_32(GuidUtils.NewGuidFormatN()).ToUpper();
info.CreatedTime = DateTime.Now;
info.CreatedUserId = CurrentUser.UserId;
info.IsDeleted = false;
}
/// <summary>
/// 在更新数据前对数据的修改操作
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
protected override void OnBeforeUpdate(APPEntity info)
{
info.ModifiedUserId = CurrentUser.UserId;
info.ModifiedTime = DateTime.Now;
}
/// <summary>
/// 在软删除数据前对数据的修改操作
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
protected override void OnBeforeSoftDelete(APPEntity info)
{
info.IsDeleted = true;
}
/// <summary>
/// 异步更新数据
/// </summary>
/// <param name="tinfo"></param>
/// <returns></returns>
[HttpPost("Update")]
[FunctionAuthorize("Edit")]
public async Task<IActionResult> UpdateAsync(APPInputDto tinfo)
{
CommonResult result = new CommonResult();
APPEntity info = _service.Get(tinfo.Id);
info.AppId = tinfo.AppId;
OnBeforeUpdate(info);
bool bl = await _service.UpdateAsync(info, tinfo.Id).ConfigureAwait(true);
if (bl)
{
result.ErrCode = ErrCode.successCode;
result.ErrMsg = ErrCode.err0;
}
else
{
result.ErrMsg = ErrCode.err43002;
result.ErrCode = "43002";
}
return ToJsonContent(result);
}
/// <summary>
/// 重置AppSecret
/// </summary>
/// <returns></returns>
[HttpGet("ResetAppSecret")]
[FunctionAuthorize("ResetAppSecret")]
public async Task<IActionResult> ResetAppSecret(int id)
{
CommonResult result = new CommonResult();
APPEntity aPP = _service.Get(id);
aPP.AppSecret = MD5Util.GetMD5_32(GuidUtils.NewGuidFormatN()).ToUpper();
bool bl = await _service.UpdateAsync(aPP, id);
if (bl)
{
result.ErrCode = ErrCode.successCode;
result.ErrMsg = aPP.AppSecret;
result.Success = true;
}
else
{
result.ErrMsg = ErrCode.err43002;
result.ErrCode = "43002";
}
return ToJsonContent(result);
}
}
}