package com.xiaopeng.operation.service.impl; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.xiaopeng.api.model.operation.XpWhitelist; import com.xiaopeng.common.core.web.page.PageInfo; import com.xiaopeng.evi.oss.service.AliOssService; import com.xiaopeng.operation.mapper.XpBannerMapper; import com.xiaopeng.api.model.operation.XpBanner; import com.xiaopeng.operation.query.BannerPageListQuery; import com.xiaopeng.operation.query.WhitelistPageListQuery; import com.xiaopeng.operation.service.XpBannerService; import com.xiaopeng.operation.vo.XpBannerListVo; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.io.UnsupportedEncodingException; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; /** *

* banner管理 服务实现类 *

* * @author liu * @since 2026-02-03 */ @Service public class XpBannerServiceImpl extends ServiceImpl implements XpBannerService { @Resource private AliOssService aliOssService; @Override public List getXpBannerList() { LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(XpBanner::getBannerStatus, 1); // 当前时间在开始和结束时间范围内 List list = list(wrapper.last(" and now() between start_time and end_time order by sort desc")); // 组装数据 if (list != null && !list.isEmpty()) { return list.stream().map(item -> { XpBannerListVo vo = new XpBannerListVo(); vo.setId(item.getId()); vo.setJumpType(item.getJumpType()); vo.setJumpUrl(item.getJumpUrl()); JSONObject jsonObject = JSON.parseArray(item.getBannerPictures()).getJSONObject(0); String downloadUrl = null; try { // 1 downloadUrl = aliOssService.getDownloadUrl(jsonObject.getString("id"), jsonObject.getString("name"), true); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } jsonObject.put("url", downloadUrl); vo.setImageUrl(jsonObject.toJSONString()); return vo; }).collect(Collectors.toList()); } return Collections.emptyList(); } @Override public PageInfo pageList(BannerPageListQuery query) { PageInfo pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); List list = this.baseMapper.pageList(pageInfo, query); for (XpBanner xpBanner : list) { JSONObject jsonObject = JSON.parseArray(xpBanner.getBannerPictures()).getJSONObject(0); String downloadUrl = null; try { // 1 downloadUrl = aliOssService.getDownloadUrl(jsonObject.getString("id"), jsonObject.getString("name"), true); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } jsonObject.put("url", downloadUrl); xpBanner.setBannerPictures(jsonObject.toJSONString()); } pageInfo.setRecords(list); return pageInfo; } }