package com.ruoyi.errand.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.errand.constant.DelFlagConstant; import com.ruoyi.errand.domain.Banner; import com.ruoyi.errand.mapper.BannerMapper; import com.ruoyi.errand.object.dto.sys.AddBannerDTO; import com.ruoyi.errand.object.vo.app.BannerVO; import com.ruoyi.errand.object.vo.sys.BannerDetailVo; import com.ruoyi.errand.object.vo.sys.BannerPageListVO; import com.ruoyi.errand.object.vo.sys.EditBannerDTO; import com.ruoyi.errand.service.BannerService; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import java.util.Collections; import java.util.List; @Service public class BannerServiceImpl extends ServiceImpl implements BannerService { @Override public List getBannerList() { return this.getBaseMapper().getBannerList(); } @Override public void add(AddBannerDTO addBannerDTO) { Long count = this.baseMapper.selectCount(new LambdaQueryWrapper() .eq(Banner::getName, addBannerDTO.getName())); if (count > 0) { throw new ServiceException("名称重复"); } Banner banner = new Banner(); banner.setName(addBannerDTO.getName()); banner.setImageUrl(addBannerDTO.getImageUrl()); this.save(banner); } @Override public IPage pageList(IPage page, String name) { return this.baseMapper.pageList(page,name); } @Override public void edit(EditBannerDTO editBannerDTO) { Banner banner = this.getById(editBannerDTO.getId()); if (banner == null || banner.getDelFlag().equals(DelFlagConstant.DELETE)) { throw new ServiceException("banner不存在"); } banner.setName(editBannerDTO.getName()); banner.setImageUrl(editBannerDTO.getImageUrl()); this.baseMapper.updateById(banner); } @Override public void delete(Integer id) { Banner banner = this.getById(id); if (banner == null || banner.getDelFlag().equals(DelFlagConstant.DELETE)) { throw new ServiceException("banner不存在"); } banner.setDelFlag(DelFlagConstant.DELETE); this.baseMapper.updateById(banner); } @Override public BannerDetailVo detail(Integer id) { Banner banner = this.getById(id); if (banner == null || banner.getDelFlag().equals(DelFlagConstant.DELETE)) { throw new ServiceException("banner不存在"); } BannerDetailVo bannerDetailVo = new BannerDetailVo(); BeanUtils.copyProperties(banner, bannerDetailVo); return bannerDetailVo; } }