using Microsoft.AspNetCore.Mvc;
using OASystem.Domain.Dtos.CRM;
using OASystem.Domain.Entities.Customer;
using OASystem.Infrastructure.Repositories.CRM;
using static OASystem.Domain.Dtos.CRM.NewClientDataQueryDto;
namespace OASystem.API.Controllers
{
[Route("api/[controller]/[action]")]
public class MarketCustomerResourcesController : ControllerBase
{
private readonly NewClientDataRepository _clientDataRepository;
///
/// 初始化
///
public MarketCustomerResourcesController(NewClientDataRepository clientDataRepository)
{
this._clientDataRepository = clientDataRepository;
}
///
/// 查询客户资料数据
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task QueryNewClientData(NewClientDataQueryDto dto)
{
try
{
Result resTable = await _clientDataRepository.QueryNewClientData(dto);
//Result resSelect = await _clientDataRepository.NewClientSelectData();
return Ok(JsonView(true, resTable.Msg, resTable.Data));
}
catch (Exception)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
///
/// 客户资料操作(Status:1.新增,2.修改)
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task NewClientOp(NewClientOpDto dto)
{
try
{
Domain.Result result = await _clientDataRepository.NewClientOp(dto);
if (result.Code != 0)
{
return Ok(JsonView(false, result.Msg));
}
return Ok(JsonView(true, result.Msg));
}
catch (Exception)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
///
/// 新客户资料操作(删除)
///
///
///
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task NewClientDel(DelBaseDto dto)
{
try
{
var res = await _clientDataRepository.SoftDeleteByIdAsync(dto.Id.ToString(), dto.DeleteUserId);
if (!res)
{
return Ok(JsonView(false, "删除失败"));
}
return Ok(JsonView(true, "删除成功!"));
}
catch (Exception ex)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
[HttpPost]
[ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
public async Task QueryUserSelect()
{
try
{
Result resTable = await _clientDataRepository.QueryUserSelect();
return Ok(JsonView(true, resTable.Msg, resTable));
}
catch (Exception)
{
return Ok(JsonView(false, "程序错误!"));
throw;
}
}
}
}