key1_beacon_api/ARW.Service/Business/BusinessService/Custom/CustomerAddresses/CustomerAddressService.cs
2023-06-09 15:10:09 +08:00

117 lines
4.5 KiB
C#

using Infrastructure.Attribute;
using Microsoft.AspNetCore.Http;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Infrastructure;
using ARW.Model;
using ARW.Repository;
using ARW.Repository.Business.Custom.CustomerAddresses;
using ARW.Service.Business.IBusinessService.Custom.CustomerAddresses;
using ARW.Model.Dto.Business.Custom.CustomerAddresses;
using ARW.Model.Vo.Business.Custom.CustomerAddresses;
using ARW.Model.Models.Business.Custom.CustomerAddresses;
using ARW.Model.Models.Business.Custom.Regions;
using ARW.Model.Models.Business.Custom.Customers;
using ARW.Repository.Business.Custom.Customers;
namespace ARW.Service.Business.BusinessService.Custom.CustomerAddresses
{
/// <summary>
/// 客户收货地址接口实现类
///
/// @author admin
/// @date 2023-06-05
/// </summary>
[AppService(ServiceType = typeof(ICustomerAddressService), ServiceLifetime = LifeTime.Transient)]
public class CustomerAddressServiceImpl : BaseService<CustomerAddress>, ICustomerAddressService
{
private readonly CustomerAddressRepository _CustomerAddressRepository;
private readonly CustomerRepository _CustomerRepository;
public CustomerAddressServiceImpl(CustomerAddressRepository CustomerAddressRepository, CustomerRepository customerRepository)
{
this._CustomerAddressRepository = CustomerAddressRepository;
_CustomerRepository = customerRepository;
}
#region
/// <summary>
/// 查询客户收货地址分页列表
/// </summary>
public Task<PagedInfo<CustomerAddressVo>> GetCustomerAddressList(CustomerAddressQueryDto parm)
{
//开始拼装查询条件d
var predicate = Expressionable.Create<CustomerAddress>();
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.CustomerAddressName), it => it.CustomerAddressName.Contains(parm.CustomerAddressName));
predicate = predicate.AndIF(!string.IsNullOrEmpty(parm.CustomerAddressPhone), it => it.CustomerAddressPhone.Contains(parm.CustomerAddressPhone));
var query = _CustomerAddressRepository
.Queryable()
.LeftJoin<Customer>((s, c) => s.CustomerAddressCustomerGuid == c.CustomerGuid)
.LeftJoin<Region>((s, c, d) => s.CustomerAddressProvinceId == d.RegionId)
.LeftJoin<Region>((s, c, d, f) => s.CustomerAddressCityId == f.RegionId)
.LeftJoin<Region>((s, c, d, f, g) => s.CustomerAddressAreaId == g.RegionId)
.Where(predicate.ToExpression())
.OrderBy(s => s.Create_time, OrderByType.Desc)
.Select((s, c, d, f, g) => new CustomerAddressVo
{
CustomerName = c.CustomerNickname,
CustomerAddress = d.RegionName + "/" + f.RegionName + "/" + g.RegionName,
CustomerAddressId = s.CustomerAddressId,
CustomerAddressGuid = s.CustomerAddressGuid,
CustomerAddressCustomerGuid = s.CustomerAddressCustomerGuid,
CustomerAddressProvinceId = s.CustomerAddressProvinceId,
CustomerAddressCityId = s.CustomerAddressCityId,
CustomerAddressAreaId = s.CustomerAddressAreaId,
CustomerAddressName = s.CustomerAddressName,
CustomerAddressPhone = s.CustomerAddressPhone,
CustomerAddressDetailed = s.CustomerAddressDetailed,
});
return query.ToPageAsync(parm);
}
/// <summary>
/// 添加或修改客户收货地址
/// </summary>
public async Task<string> AddOrUpdateCustomerAddress(CustomerAddress model)
{
if (model.CustomerAddressId != 0)
{
var response = await _CustomerAddressRepository.UpdateAsync(model);
return "修改成功!";
}
else
{
var response = await _CustomerAddressRepository.InsertReturnSnowflakeIdAsync(model);
return "添加成功!";
}
}
#region Excel处理
/// <summary>
/// Excel数据导出处理
/// </summary>
public async Task<List<CustomerAddressVo>> HandleExportData(List<CustomerAddressVo> data)
{
return data;
}
#endregion
#endregion
}
}