using Microsoft.AspNetCore.Mvc; using System; using System.Threading.Tasks; using Znyc.Admin.AspNetCore.Controllers; using Znyc.Admin.AspNetCore.Entitys; using Znyc.Admin.AspNetCore.Mvc; using Znyc.Admin.Commons.Entitys; using Znyc.Admin.Commons.Pages; using Znyc.Admin.Security.Dtos; using Znyc.Admin.Security.Entitys; using Znyc.Admin.Security.IServices; namespace Znyc.Admin.WebApi.Controllers { /// /// 公司服务 /// [ApiController] [Route("api/Dispatching/[controller]")] public class CompanyController : AreaApiController { private readonly ICompanyService _companyServices; /// /// 构造函数 /// public CompanyController( ICompanyService service ) : base(service) { _companyServices = service; } /// /// 新增前处理数据 /// /// protected override void OnBeforeInsert(Company info) { info.Id = 0; info.CreatedTime = DateTime.Now; info.CreatedUserId = CurrentUser.UserId; info.IsDeleted = false; } /// /// 在更新数据前对数据的修改操作 /// /// /// protected override void OnBeforeUpdate(Company info) { info.CreatedUserId = CurrentUser.UserId; info.ModifiedUserId = CurrentUser.UserId; info.ModifiedTime = DateTime.Now; } /// /// 在软删除数据前对数据的修改操作 /// /// /// protected override void OnBeforeSoftDelete(Company info) { info.IsDeleted = true; } /// /// 异步分页查询 /// /// /// [HttpPost("FindWithPagerSearchAsync")] [FunctionAuthorize("List")] public async Task FindWithPagerSearchAsync(SearchUserModel search) { CommonResult> result = new CommonResult> { ResData = await _companyServices.FindWithPagerSearchAsync(search), ErrCode = ErrCode.successCode }; return ToJsonContent(result); } /// /// 审核公司状态 /// /// /// /// [HttpPut("AuditAsync")] public async Task AuditAsync(long id, int status) { CommonResult result = new CommonResult(); result = await _companyServices.AuditAsync(id, status); if (result.Success) { result.ErrCode = ErrCode.successCode; result.ErrMsg = ErrCode.err0; } else { result.ErrMsg = result.ErrMsg; result.ErrCode = "43002"; } return ToJsonContent(result); } /// /// 修改公司状态 /// /// /// /// [HttpPut("UpdateAsync")] public async Task UpdateAsync(long id, int status) { CommonResult result = new CommonResult(); result = await _companyServices.UpdateAsync(id, status); if (result.Success) { result.ErrCode = ErrCode.successCode; result.ErrMsg = ErrCode.err0; } else { result.ErrMsg = ErrCode.err43002; result.ErrCode = "43002"; } return ToJsonContent(result); } } }