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.ShopManager.ShopAddresss; using ARW.Service.Business.IBusinessService.ShopManager.ShopAddresss; using ARW.Model.Dto.Business.ShopManager.ShopAddresss; using ARW.Model.Models.Business.ShopManager.ShopAddresss; using ARW.Model.Vo.Business.ShopManager.ShopAddresss; using ARW.Model.Models.Business.Custom.Regions; using ARW.Repository.System; using ARW.Model.Models.Business.ShopManager.Shops; namespace ARW.Service.Business.BusinessService.ShopManager.ShopAddresss { /// /// 店铺地址接口实现类 /// /// @author 黎文豪 /// @date 2023-06-15 /// [AppService(ServiceType = typeof(IShopAddressService), ServiceLifetime = LifeTime.Transient)] public class ShopAddressServiceImpl : BaseService, IShopAddressService { private readonly ShopAddressRepository _ShopAddressRepository; private readonly SysDictDataRepository _SysDictDataRepository; public ShopAddressServiceImpl(ShopAddressRepository ShopAddressRepository, SysDictDataRepository sysDictDataRepository) { this._ShopAddressRepository = ShopAddressRepository; _SysDictDataRepository = sysDictDataRepository; } #region 业务逻辑代码 /// /// 查询店铺地址分页列表 /// public async Task> GetShopAddressList(ShopAddressQueryDto parm) { //开始拼装查询条件d var predicate = Expressionable.Create(); predicate = predicate.AndIF(parm.ShopGuid != 0, s => s.ShopGuid == parm.ShopGuid); predicate = predicate.AndIF(parm.ShopAddressType != null, s => s.ShopAddressType == parm.ShopAddressType); var query = _ShopAddressRepository .Queryable() .LeftJoin((s, d) => s.ProvinceId == d.RegionId) .LeftJoin((s, d, f) => s.CityId == f.RegionId) .LeftJoin((s, d, f, g) => s.DistrictId == g.RegionId) .LeftJoin((s, d, f, g, c) => s.ShopGuid == c.ShopGuid) .Where(predicate.ToExpression()) .OrderBy(s => s.ShopAddressSort, OrderByType.Asc) .Select((s, d, f, g, c) => new ShopAddressVo { ShopGuid = s.ShopGuid, ShopName = c.ShopName, ShopAddressId = s.ShopAddressId, ShopAddressGuid = s.ShopAddressGuid, ShopAddressType = s.ShopAddressType, AddressName = d.RegionName + "/" + f.RegionName + "/" + g.RegionName, ProvinceId = s.ProvinceId, CityId = s.CityId, DistrictId = s.DistrictId, ShopAddressContactName = s.ShopAddressContactName, ShopAddressContactNumber = s.ShopAddressContactNumber, ShopAddressDetailedAddress = s.ShopAddressDetailedAddress, ShopAddressSort = s.ShopAddressSort, CreateTime = s.Create_time.ToString("yyyy-MM-dd HH:mm") }); return await query.ToPageAsync(parm); } /// /// 添加或修改店铺地址 /// public async Task AddOrUpdateShopAddress(ShopAddress model) { if (model.ShopAddressId != 0) { var response = await _ShopAddressRepository.UpdateAsync(model); return "修改成功!"; } else { var response = await _ShopAddressRepository.InsertReturnSnowflakeIdAsync(model); return "添加成功!"; } } #region Excel处理 /// /// Excel数据导出处理 /// public async Task> HandleExportData(List data) { foreach (var item in data) { item.ShopAddressTypeName = _SysDictDataRepository.GetDictNameByName("shop_address_type", item.ShopAddressType.ToString()); } return data; } #endregion #endregion } }