huliguo
2 天以前 5d7b65670282a4fad015e37d567cfa171b162052
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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<BannerMapper, Banner> implements BannerService {
 
    @Override
    public List<BannerVO> getBannerList() {
        return this.getBaseMapper().getBannerList();
 
    }
 
    @Override
    public void add(AddBannerDTO addBannerDTO) {
        Long count = this.baseMapper.selectCount(new LambdaQueryWrapper<Banner>()
                .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<BannerPageListVO> pageList(IPage<BannerPageListVO> 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;
    }
}