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 ARW.Model; using ARW.Repository; using ARW.Repository.Business.Custom.CustomerAddresses; using ARW.Service.Api.IBusinessService.Custom.CustomerAddresses; using ARW.Model.Dto.Api.Custom.CustomerAddresses; using ARW.Model.Models.Business.Custom.CustomerAddresses; using ARW.Model.Vo.Api.Custom.CustomerAddresses; using ARW.Model.Models.Business.Custom.Regions; using ARW.Model.Models.Business.Custom.Customers; using Microsoft.AspNetCore.Server.IISIntegration; namespace ARW.Service.Api.BusinessService.Custom.CustomerAddresses { /// /// 客户收货地址接口实现类Api /// /// @author admin /// @date 2023-06-09 /// [AppService(ServiceType = typeof(ICustomerAddressServiceApi), ServiceLifetime = LifeTime.Transient)] public class CustomerAddressServiceImplApi : BaseService, ICustomerAddressServiceApi { private readonly CustomerAddressRepository _CustomerAddressRepository; public CustomerAddressServiceImplApi(CustomerAddressRepository CustomerAddressRepository) { this._CustomerAddressRepository = CustomerAddressRepository; } #region Api接口代码 /// /// 查询客户收货地址列表(Api) /// /// /// public async Task> GetCustomerAddressListApi(CustomerAddressQueryDtoApi parm) { //开始拼装查询条件d var predicate = Expressionable.Create(); var query = _CustomerAddressRepository .Queryable() .LeftJoin((s, c) => s.CustomerAddressProvinceId == c.RegionId) .LeftJoin((s, c, d) => s.CustomerAddressCityId == d.RegionId) .LeftJoin((s, c, d, f) => s.CustomerAddressAreaId == f.RegionId) .LeftJoin((s, c, d, f, g) => s.CustomerAddressCustomerGuid == g.CustomerGuid) .Where((s) => s.CustomerAddressCustomerGuid == parm.CustomerAddressCustomerGuid) .Where(predicate.ToExpression()) .OrderBy(s => s.Create_time, OrderByType.Asc) .Select((s, c, d, f, g) => new CustomerAddressVoApi { CustomerAddressId = s.CustomerAddressId, CustomerAddressGuid = s.CustomerAddressGuid, Name = s.CustomerAddressName, PhoneNumber = s.CustomerAddressPhone, Address = c.RegionName + d.RegionName + f.RegionName + s.CustomerAddressDetailed, IsDefault = s.CustomerAddressGuid == g.CustomerDefaultAddressGuid }); return await query.ToListAsync(); } /// /// 查询客户收货地址详情(Api) /// /// /// public Task GetCustomerAddressDetails(CustomerAddressDtoApi parm) { var query = _CustomerAddressRepository .Queryable() .LeftJoin((s, c) => s.CustomerAddressProvinceId == c.RegionPid) .LeftJoin((s, c, d) => s.CustomerAddressCityId == d.RegionPid) .LeftJoin((s, c, d, f) => s.CustomerAddressAreaId == f.RegionPid) .LeftJoin((s, c, d, f, g) => s.CustomerAddressCustomerGuid == g.CustomerGuid) .Where(s => s.CustomerAddressGuid == parm.CustomerAddressGuid) .Select(s => new CustomerAddressApiDetailsVo { 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, }).Take(1); return query.ToJsonAsync(); } #endregion } }