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.
 
 

131 lines
3.9 KiB

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
using Yitter.IdGenerator;
using Znyc.Cloudcar.Admin.AspNetCore.Controllers;
using Znyc.Cloudcar.Admin.AspNetCore.Entitys;
using Znyc.Cloudcar.Admin.AspNetCore.Mvc;
using Znyc.Cloudcar.Admin.Commons.Entitys;
using Znyc.Cloudcar.Admin.Commons.Pages;
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 EquipmentController : AreaApiController<EquipmentEntity, EquipmentOutputDto, EquipmentAddInput, IEquipmentService, long>
{
/// <summary>
/// 设备管理
/// </summary>
/// <param name="service"></param>
public EquipmentController(IEquipmentService service) : base(service)
{
}
/// <summary>
/// 新增前处理数据
/// </summary>
/// <param name="info"></param>
protected override void OnBeforeInsert(EquipmentEntity info)
{
info.Id = YitIdHelper.NextId();
info.CreatedTime = DateTime.Now;
info.CreatedUserId = CurrentUser.UserId;
info.IsDeleted = false;
}
/// <summary>
/// 在更新数据前对数据的修改操作
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
protected override void OnBeforeUpdate(EquipmentEntity info)
{
info.ModifiedUserId = CurrentUser.UserId;
info.ModifiedTime = DateTime.Now;
}
/// <summary>
/// 在软删除数据前对数据的修改操作
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
protected override void OnBeforeSoftDelete(EquipmentEntity info)
{
info.IsDeleted = true;
}
/// <summary>
/// 分页查询
/// </summary>
/// <param name="search"></param>
/// <returns></returns>
[HttpPost("FindWithPagerSearchAsync")]
[FunctionAuthorize("List")]
[AllowAnonymous]
public async Task<IActionResult> FindWithPagerSearchAsync(SearchEquipmentModel search)
{
var result = new CommonResult<PageResult<EquipmentOutputDto>>
{
ResData = await _service.FindWithPagerSearchAsync(search),
ErrCode = ErrCode.successCode
};
return ToJsonContent(result);
}
/// <summary>
/// 下架
/// </summary>
/// <returns></returns>
[HttpPut]
public async Task<IActionResult> CancelAsync(long id)
{
CommonResult result = new CommonResult();
result= await _service.CancelAsync(id);
if (result.Success)
{
result.ErrCode = ErrCode.successCode;
result.ErrMsg = ErrCode.err0;
}
else
{
result.ErrMsg = ErrCode.err43002;
result.ErrCode = "43002";
}
return ToJsonContent(result);
}
/// <summary>
/// 成交
/// </summary>
/// <returns></returns>
[HttpPut("CompleteAsync")]
public async Task<IActionResult> CompleteAsync(long id)
{
CommonResult result = new CommonResult();
result = await _service.CompleteAsync(id);
if (result.Success)
{
result.ErrCode = ErrCode.successCode;
result.ErrMsg = ErrCode.err0;
}
else
{
result.ErrMsg = ErrCode.err43002;
result.ErrCode = "43002";
}
return ToJsonContent(result);
}
}
}