admin
2021-01-18 d6df4ca797ee1c6ce8fa78768f5425f187734bd9
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package com.ks.lucky.service.impl;
 
import com.ks.lib.common.exception.ParamsException;
import com.ks.lucky.dao.LuckySponsorAdDao;
import com.ks.lucky.exception.LuckyActivitySponsorInfoException;
import com.ks.lucky.exception.LuckySponsorAdException;
import com.ks.lucky.mapper.LuckyActivitySponsorInfoMapper;
import com.ks.lucky.mapper.LuckySponsorsMapper;
import com.ks.lucky.pojo.DO.LuckyActivitySponsorInfo;
import com.ks.lucky.pojo.DO.LuckySponsorAd;
import com.ks.lucky.pojo.DO.LuckySponsors;
import com.ks.lucky.query.ActivitySponsorInfoQuery;
import com.ks.lucky.remote.service.LuckySponsorAdService;
import com.ks.lucky.util.annotation.RedisCache;
import com.ks.lucky.util.annotation.RedisCacheEvict;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;
 
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
 
/**
 * 活动赞助信息管理
 */
@Component
public class LuckyActivitySponsorInfoManager {
 
    @Resource
    private LuckyActivitySponsorInfoMapper luckyActivitySponsorInfoMapper;
 
    @Resource
    private LuckySponsorAdDao luckySponsorAdDao;
 
    @Resource
    private LuckySponsorAdService luckySponsorAdService;
 
    @Resource
    private LuckySponsorsMapper luckySponsorsMapper;
 
 
    /**
     * 添加赞助信息
     *
     * @param sponsorInfo
     * @throws LuckyActivitySponsorInfoException
     */
    @Validated
    public void addSponsorInfo(LuckyActivitySponsorInfo sponsorInfo) throws LuckyActivitySponsorInfoException, LuckySponsorAdException, ParamsException {
        ActivitySponsorInfoQuery query = new ActivitySponsorInfoQuery();
        query.activityId = sponsorInfo.getActivityId();
        query.start = 0;
        query.count = 1;
 
        List<LuckyActivitySponsorInfo> list = luckyActivitySponsorInfoMapper.list(query);
        if (list != null && list.size() > 0) {
            throw new LuckyActivitySponsorInfoException(LuckyActivitySponsorInfoException.CODE_EXIST, "活动赞助信息已经存在");
        }
 
        if (sponsorInfo.getCreateTime() == null) {
            sponsorInfo.setCreateTime(new Date());
        }
 
        if (sponsorInfo.getAd() != null) {
            if (sponsorInfo.getAd().getId() == null) {
                //添加广告
                String id = luckySponsorAdService.addSponsorAd(sponsorInfo.getAd());
                sponsorInfo.getAd().setId(id);
                sponsorInfo.setSponsorAdId(id);
            }
        }
 
 
        luckyActivitySponsorInfoMapper.insertSelective(sponsorInfo);
    }
 
    /**
     * 修改赞助信息
     *
     * @param sponsorInfo
     * @throws LuckyActivitySponsorInfoException
     */
    @RedisCacheEvict(cate = "activity", key = "'activity-detail-'+#activityId")
    @RedisCacheEvict(cate = "activity-sponsorinfo", key = "'getSponsorInfo-'+#activityId")
    @RedisCacheEvict(cate = "activity-sponsorinfo", key = "'getSponsorInfoDetail-'+#sponsorInfo.id")
    public void updateSponsorInfo(LuckyActivitySponsorInfo sponsorInfo, Long activityId) throws LuckyActivitySponsorInfoException {
        luckyActivitySponsorInfoMapper.updateByPrimaryKeySelective(sponsorInfo);
    }
 
    /**
     * 获取赞助信息列表
     *
     * @param activityId
     * @return
     */
    @RedisCache(cate = "activity-sponsorinfo", key = "'getSponsorInfo-'+#activityId")
    public LuckyActivitySponsorInfo getSponsorInfo(Long activityId) {
        ActivitySponsorInfoQuery query = new ActivitySponsorInfoQuery();
        query.activityId = activityId;
        query.start = 0;
        query.count = 1;
        List<LuckyActivitySponsorInfo> list = luckyActivitySponsorInfoMapper.list(query);
        if (list != null && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
 
    /**
     * 获取赞助信息详情
     *
     * @param id
     * @return
     */
    @RedisCache(cate = "activity-sponsorinfo", key = "'getSponsorInfoDetail-'+#id")
    public LuckyActivitySponsorInfo getSponsorInfoDetail(Long id) {
        LuckyActivitySponsorInfo info = luckyActivitySponsorInfoMapper.selectByPrimaryKey(id);
        if (info == null) {
            return null;
        }
 
        if (info.getSponsorAdId() != null) {
            LuckySponsorAd ad = luckySponsorAdDao.get(info.getSponsorAdId());
            info.setAd(ad);
        }
 
        if (info.getSponsorId() != null) {
            LuckySponsors sponsor = luckySponsorsMapper.selectByPrimaryKey(info.getSponsorId());
            info.setSponsors(sponsor);
        }
        return info;
    }
 
    /**
     * 删除赞助信息
     *
     * @param id
     */
    @RedisCacheEvict(cate = "activity", key = "'activity-detail-'+#activityId")
    @RedisCacheEvict(cate = "activity-sponsorinfo", key = "'getSponsorInfo-'+#activityId")
    @RedisCacheEvict(cate = "activity-sponsorinfo", key = "'getSponsorInfoDetail-'+#id")
    public void deleteSponsorInfo(Long id, Long activityId) {
        luckySponsorsMapper.deleteByPrimaryKey(id);
    }
 
}