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.
86 lines
3.0 KiB
86 lines
3.0 KiB
2 months ago
|
// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
|
||
|
//
|
||
|
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
|
||
|
|
||
|
using System.ComponentModel;
|
||
|
using Admin.NET.Core;
|
||
|
using Bodk.NET.Customer.Entities;
|
||
|
using Bodk.NET.Customer.Models;
|
||
|
using Furion.DependencyInjection;
|
||
|
using Furion.DynamicApiController;
|
||
|
using Furion.FriendlyException;
|
||
|
using Mapster;
|
||
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||
|
using Microsoft.AspNetCore.Authorization;
|
||
|
using Microsoft.AspNetCore.Mvc;
|
||
|
|
||
|
namespace Bodk.NET.Customer.Services;
|
||
|
|
||
|
/// <summary>
|
||
|
/// 客户接口控制器
|
||
|
/// </summary>
|
||
|
[ApiDescriptionSettings(Groups = new[] { "Bodk Groups" }, Name = "Customer", Description = "客户接口")]
|
||
|
public class CustomerService(SqlSugarRepository<BodkCustomer> repository) : IDynamicApiController, ITransient
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 新增客户
|
||
|
/// </summary>
|
||
|
/// <returns></returns>
|
||
|
[ApiDescriptionSettings(Name = "Add"), HttpPost]
|
||
|
[DisplayName("Add")]
|
||
|
[Authorize(AuthenticationSchemes =
|
||
|
JwtBearerDefaults.AuthenticationScheme + "," + SignatureAuthenticationDefaults.AuthenticationScheme)]
|
||
|
public async Task<long> AddCustomer(AddCustomerInput input)
|
||
|
{
|
||
|
var entity = input.Adapt<BodkCustomer>();
|
||
|
bool exist = await CheckCustomerExist(entity);
|
||
|
if (exist)
|
||
|
throw Oops.Oh("该用户已存在");
|
||
|
return await repository.InsertReturnSnowflakeIdAsync(entity);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 更新客户
|
||
|
/// </summary>
|
||
|
/// <returns></returns>
|
||
|
[ApiDescriptionSettings(Name = "Update"), HttpPost]
|
||
|
[DisplayName("Update")]
|
||
|
[Authorize(AuthenticationSchemes =
|
||
|
JwtBearerDefaults.AuthenticationScheme + "," + SignatureAuthenticationDefaults.AuthenticationScheme)]
|
||
|
public async Task UpdateCustomer(UpdateCustomerInput input)
|
||
|
{
|
||
|
var entity = input.Adapt<BodkCustomer>();
|
||
|
bool exist = await CheckCustomerExist(input.Id);
|
||
|
if (!exist)
|
||
|
throw Oops.Oh("该用户不存在");
|
||
|
await repository.UpdateAsync(entity);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 获取客户列表
|
||
|
/// </summary>
|
||
|
/// <returns></returns>
|
||
|
[ApiDescriptionSettings(Name = "Update"), HttpPost]
|
||
|
[DisplayName("Update")]
|
||
|
[Authorize(AuthenticationSchemes =
|
||
|
JwtBearerDefaults.AuthenticationScheme + "," + SignatureAuthenticationDefaults.AuthenticationScheme)]
|
||
|
public async Task PageCustomer(UpdateCustomerInput input)
|
||
|
{
|
||
|
var entity = input.Adapt<BodkCustomer>();
|
||
|
bool exist = await CheckCustomerExist(input.Id);
|
||
|
if (!exist)
|
||
|
throw Oops.Oh("该用户不存在");
|
||
|
await repository.UpdateAsync(entity);
|
||
|
}
|
||
|
|
||
|
private async Task<bool> CheckCustomerExist(BodkCustomer entity)
|
||
|
{
|
||
|
return await repository.AsQueryable().AnyAsync(u => u.IdCard == entity.IdCard)
|
||
|
|| await repository.AsQueryable().AnyAsync(u => u.Phone == entity.Phone);
|
||
|
}
|
||
|
|
||
|
private Task<bool> CheckCustomerExist(long id)
|
||
|
{
|
||
|
return repository.AsQueryable().AnyAsync(u => u.Id == id);
|
||
|
}
|
||
|
}
|