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.
126 lines
4.6 KiB
126 lines
4.6 KiB
// 大名科技(天津)有限公司版权所有 电话:18020030720 QQ:515096995
|
|
//
|
|
// 此源代码遵循位于源代码树根目录中的 LICENSE 文件的许可证
|
|
|
|
using System.ComponentModel;
|
|
using Admin.NET.Bodk.Core;
|
|
using Admin.NET.Bodk.Customer.Entities;
|
|
using Admin.NET.Bodk.Customer.Models;
|
|
using Admin.NET.Core;
|
|
using Admin.NET.Core.Service;
|
|
using Furion.DatabaseAccessor;
|
|
using Furion.DependencyInjection;
|
|
using Mapster;
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Admin.NET.Bodk.Customer;
|
|
|
|
[ApiDescriptionSettings(Groups = new[] { "Bodk Groups" }, Name = "Customer", Description = "客户接口服务")]
|
|
public class CustomerService(
|
|
UserManager userManager,
|
|
SysOrgService sysOrgService,
|
|
SysUserService sysUserService,
|
|
SqlSugarRepository<CustomerEntity> repository) : ServiceBase(userManager, sysOrgService, sysUserService)
|
|
{
|
|
/// <summary>
|
|
/// 获取客户信息
|
|
/// </summary>
|
|
/// <param name="input"></param>
|
|
/// <returns></returns>
|
|
[UnitOfWork]
|
|
[ApiDescriptionSettings(Name = "GetList"), HttpPost]
|
|
[DisplayName("GetList")]
|
|
[Authorize(AuthenticationSchemes =
|
|
JwtBearerDefaults.AuthenticationScheme + "," + SignatureAuthenticationDefaults.AuthenticationScheme)]
|
|
public async Task<SqlSugarPagedList<Models.Customer>> GetList(QueryCustomerInput input)
|
|
{
|
|
var queryable = repository.AsQueryable();
|
|
var userOrgIdList = await SysOrgService.GetUserOrgIdList();
|
|
List<long>? orgList;
|
|
|
|
orgList = UserManager.SuperAdmin ? null : userOrgIdList;
|
|
// queryable = queryable
|
|
// .Includes(u => u.OrgIds)
|
|
// .WhereIF(orgList != null,
|
|
// u => orgList != null && u.OrgIds != null && u.OrgIds.Intersect(orgList).Any());
|
|
return await queryable
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.Name),
|
|
m => input.Name != null && m.Name.Contains(input.Name))
|
|
.WhereIF(input.Id is not null, u => u.Id == input.Id)
|
|
.WhereIF(input.Phone is not null, m => m.Phone == input.Phone)
|
|
.WhereIF(!string.IsNullOrWhiteSpace(input.IdCard),
|
|
m => input.IdCard != null && m.IdCard.Contains(input.IdCard))
|
|
.Mapper(u =>
|
|
{
|
|
Console.WriteLine(u.IsMale);
|
|
})
|
|
.Select<Models.Customer>(u => new Models.Customer()
|
|
{
|
|
Id = u.Id,
|
|
Name = u.Name,
|
|
Phone = u.Phone,
|
|
IdCard = u.IdCard,
|
|
CreateTime = u.CreateTime,
|
|
UpdateTime = u.UpdateTime,
|
|
CreateUserName = u.CreateUserName,
|
|
OrgIds = u.OrgIds,
|
|
IsMale = u.IsMale,
|
|
IsDelete = u.IsDelete,
|
|
CreateUserId = u.CreateUserId,
|
|
UpdateUserId = u.UpdateUserId,
|
|
UpdateUserName = u.UpdateUserName
|
|
})
|
|
.ToPagedListAsync(input.Page, input.PageSize);
|
|
}
|
|
|
|
[UnitOfWork]
|
|
[ApiDescriptionSettings(Name = "Add"), HttpPost]
|
|
[DisplayName("Add")]
|
|
[Authorize(AuthenticationSchemes =
|
|
JwtBearerDefaults.AuthenticationScheme + "," + SignatureAuthenticationDefaults.AuthenticationScheme)]
|
|
public async Task<long?> AddCustomer(AddCustomerInput input)
|
|
{
|
|
var entity = new CustomerEntity()
|
|
{
|
|
IdCard = input.IdCard,
|
|
Name = input.Name,
|
|
Phone = input.Phone,
|
|
IsMale = input.IsMale,
|
|
ImageUrl = input.ImageUrl,
|
|
VoiceUrl = input.VoiceUrl,
|
|
};
|
|
entity = await AddBefore(entity);
|
|
return await repository.InsertReturnSnowflakeIdAsync(entity);
|
|
}
|
|
|
|
[UnitOfWork]
|
|
[ApiDescriptionSettings(Name = "Update"), HttpPost]
|
|
[DisplayName("Update")]
|
|
[Authorize(AuthenticationSchemes =
|
|
JwtBearerDefaults.AuthenticationScheme + "," + SignatureAuthenticationDefaults.AuthenticationScheme)]
|
|
public async Task UpdateCustomer(UpdateCustomerInput input)
|
|
{
|
|
var entity = new CustomerEntity()
|
|
{
|
|
Id = input.Id,
|
|
IdCard = input.IdCard,
|
|
Name = input.Name,
|
|
Phone = input.Phone,
|
|
IsMale = input.IsMale,
|
|
ImageUrl = input.ImageUrl,
|
|
VoiceUrl = input.VoiceUrl
|
|
};
|
|
entity = await UpdateBefore(entity);
|
|
var result= await repository.UpdateAsync(entity);
|
|
}
|
|
|
|
[UnitOfWork]
|
|
[ApiDescriptionSettings(Name = "Delete"), HttpPost]
|
|
[DisplayName("Delete")]
|
|
public async Task DeleteCustomer(long? id)
|
|
{
|
|
await repository.DeleteByIdAsync(id);
|
|
}
|
|
}
|