2021与蓝度共同重构项目,服务端
zhanzhiqin
2022-03-01 da6ea6d775461e6d56eb50cbdd79e6ba3b8f41e4
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package com.sandu.ximon.admin.service;
 
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.lang.Snowflake;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.sandu.common.execption.BusinessException;
import com.sandu.common.service.impl.BaseServiceImpl;
import com.sandu.common.util.ResUtils;
import com.sandu.ximon.admin.dto.BannerDto;
import com.sandu.ximon.admin.dto.BannerPositionDto;
import com.sandu.ximon.admin.param.BannerParam;
import com.sandu.ximon.admin.security.SecurityUtils;
import com.sandu.ximon.dao.domain.Banner;
import com.sandu.ximon.dao.mapper.BannerMapper;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
@Service
@AllArgsConstructor
public class BannerService extends BaseServiceImpl<BannerMapper, Banner> {
 
    private final Snowflake snowflake;
 
//    /**
//     * 获取banner跳转列表
//     */
//    public List<BannerPositionDto> listPosition() {
//        return ListUtil.of(new BannerPositionDto("首页1", 0), new BannerPositionDto("首页2", 1),
//                new BannerPositionDto("首页3", 2), new BannerPositionDto("首页4", 3));
//    }
 
    /**
     * 添加banner
     */
    public boolean addBanner(BannerParam bannerParam) {
        Banner banner = new Banner();
        banner.setId(snowflake.nextId());
        banner.setBannerUrl(ResUtils.removePrefix(bannerParam.getUrl()));
        banner.setAuthor(SecurityUtils.getUsername());
        banner.setBindingAuthor(bannerParam.getBinding_author());
        return save(banner);
    }
 
    /**
     * 修改banner
     *
     * @param bannerId
     * @param bannerParam
     * @return
     */
    public boolean updateBanner(Long bannerId, BannerParam bannerParam) {
        Banner banner = getById(bannerId);
        if (banner == null) {
            throw new BusinessException("找不到banner");
        }
        Banner update = new Banner();
        // BeanUtils.copyProperties(bannerParam, update);
        update.setId(bannerId);
        update.setBannerUrl(bannerParam.getUrl());
        return updateById(update);
    }
 
    /**
     * 删除banner
     *
     * @param bannerId
     * @return
     */
    public boolean deleteBanner(Long bannerId) {
        Banner banner = getById(bannerId);
        if (banner == null) {
            throw new BusinessException("找不到banner");
        }
        return removeById(bannerId);
    }
 
    /**
     * 查询banner
     *
     * @return
     */
    public List<Banner> listBanner() {
        LambdaQueryWrapper<Banner> wrapper = Wrappers.lambdaQuery(Banner.class);
        List<Banner> list = list(wrapper);
        for (Banner banner : list) {
            banner.setBannerUrl(ResUtils.addPrefix(banner.getBannerUrl()));
        }
        return list;
    }
 
    /**
     * 获取详情
     *
     * @param bannerId
     * @return
     */
    public BannerDto detailBanner(Long bannerId) {
        Banner banner = getById(bannerId);
        if (banner == null) {
            throw new BusinessException("找不到banner");
        }
        BannerDto bannerDto = new BannerDto();
        BeanUtils.copyProperties(banner, bannerDto);
        bannerDto.setAUrl(ResUtils.addPrefix(banner.getBannerUrl()));
        return bannerDto;
    }
}