using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
using Znyc.Recruitment.Admin.AspNetCore.Controllers;
using Znyc.Recruitment.Admin.AspNetCore.Entitys;
using Znyc.Recruitment.Admin.AspNetCore.Mvc;
using Znyc.Recruitment.Admin.Commons.Entitys;
using Znyc.Recruitment.Admin.Commons.Mapping;
using Znyc.Recruitment.Admin.Security.Dtos;
using Znyc.Recruitment.Admin.Security.Entitys;
using Znyc.Recruitment.Admin.Security.IServices;
namespace Znyc.Recruitment.Admin.WebApi.Controllers
{
///
/// 审核
///
[ApiController]
[Route("api/Security/[controller]")]
public class AuditController : AreaApiController
{
private readonly IAuditService _productAuditService;
///
/// 构造函数
///
public AuditController(
IAuditService productAuditService,
IUserService userService
) : base(productAuditService)
{
_productAuditService = productAuditService;
}
///
/// 新增前处理数据
///
///
protected override void OnBeforeInsert(AuditEntity info)
{
info.Id = 0;
info.CreatedTime = DateTime.Now;
info.CreatedUserId = CurrentUser.UserId;
info.IsDeleted = false;
}
///
/// 在更新数据前对数据的修改操作
///
///
///
protected override void OnBeforeUpdate(AuditEntity info)
{
info.AuditUserId = CurrentUser.UserId;
info.ModifiedUserId = CurrentUser.UserId;
info.ModifiedTime = DateTime.Now;
}
///
/// 在软删除数据前对数据的修改操作
///
///
///
protected override void OnBeforeSoftDelete(AuditEntity info)
{
info.IsDeleted = true;
}
///
/// 审核通过
///
///
///
///
[HttpPut("AuditSuccessAsync")]
[FunctionAuthorize("")]
public async Task AuditSuccessAsync(long pid, int productType)
{
CommonResult result = new CommonResult();
AuditEntity info = new AuditEntity
{
ProductId = pid,
ProductType = productType
};
OnBeforeInsert(info);
result = await _productAuditService.AuditSuccessAsync(info);
if (result.Success)
{
result.ErrCode = ErrCode.successCode;
result.ErrMsg = ErrCode.err0;
}
else
{
result.ErrMsg = ErrCode.err43002;
result.ErrCode = "43002";
}
return ToJsonContent(result);
}
///
/// 审核失败
///
///
///
[HttpPut("AuditFailAsync")]
[FunctionAuthorize("")]
public async Task AuditFailAsync(AuditInputDto productAuditInput)
{
CommonResult result = new CommonResult();
AuditEntity info = productAuditInput.MapTo();
OnBeforeInsert(info);
result = await _productAuditService.AuditFailAsync(info);
if (result.Success)
{
result.ErrCode = ErrCode.successCode;
result.ErrMsg = ErrCode.err0;
}
else
{
result.ErrMsg = ErrCode.err43002;
result.ErrCode = "43002";
}
return ToJsonContent(result);
}
}
}