using Infrastructure.Attribute; using SqlSugar; using System.Linq; using System.Threading.Tasks; using ARW.Model; using ARW.Repository; using ARW.Repository.Business.Custom.GoodsBrowsingHistorys; using ARW.Service.Api.IBusinessService.Custom.GoodsBrowsingHistorys; using ARW.Model.Dto.Api.Custom.GoodsBrowsingHistorys; using ARW.Model.Models.Business.Custom.GoodsBrowsingHistorys; using ARW.Model.Vo.Api.Custom.GoodsBrowsingHistorys; namespace ARW.Service.Api.BusinessService.Custom.GoodsBrowsingHistorys { /// /// 商品浏览记录接口实现类Api /// /// @author lwh /// @date 2023-10-22 /// [AppService(ServiceType = typeof(IGoodsBrowsingHistoryServiceApi), ServiceLifetime = LifeTime.Transient)] public class GoodsBrowsingHistoryServiceImplApi : BaseService, IGoodsBrowsingHistoryServiceApi { private readonly GoodsBrowsingHistoryRepository _GoodsBrowsingHistoryRepository; public GoodsBrowsingHistoryServiceImplApi(GoodsBrowsingHistoryRepository GoodsBrowsingHistoryRepository) { this._GoodsBrowsingHistoryRepository = GoodsBrowsingHistoryRepository; } #region Api接口代码 /// /// 查询商品浏览记录列表(Api) /// /// /// public async Task> GetGoodsBrowsingHistoryListApi(GoodsBrowsingHistoryQueryDtoApi parm) { //开始拼装查询条件d var predicate = Expressionable.Create(); predicate = predicate.AndIF(parm.CustomerGuid != 0, s => s.CustomerGuid == parm.CustomerGuid); var query = _GoodsBrowsingHistoryRepository .Queryable() .Where(predicate.ToExpression()) .OrderBy(s => s.Create_time, OrderByType.Desc) .Select(s => new GoodsBrowsingHistoryVoApi { SpuId = s.GoodsGuid, CraeteTime = s.Create_time.ToString("yyyy-MM-dd"), }); var list = await query.ToPageAsync(parm); foreach (var item in list.Result) { item.Thumb = item.Thumb.Split(",").First(); } return list; } /// /// 添加或修改商品浏览记录 /// public async Task AddOrUpdateGoodsBrowsingHistory(GoodsBrowsingHistory model) { if (model.GoodsBrowsingHistoryId != 0) { var response = await _GoodsBrowsingHistoryRepository.UpdateAsync(model); return "修改成功!"; } else { var response = await _GoodsBrowsingHistoryRepository.InsertReturnSnowflakeIdAsync(model); return "添加成功!"; } } #endregion } }