admin
2020-11-25 06d1a63564b1fc4b85ae86f7e2f80bc56de5c8ca
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
package com.ks.lucky.service.remote;
 
import com.ks.app.entity.AppInfo;
import com.ks.app.exception.AppException;
import com.ks.app.service.AppService;
import com.ks.lucky.exception.LuckyActivityException;
import com.ks.lucky.mapper.LuckyActivityMapper;
import com.ks.lucky.pojo.DO.LuckyActivity;
import com.ks.lucky.query.ActivityDaoQuery;
import com.ks.lucky.remote.service.activity.LuckyActivityService;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
 
import javax.annotation.Resource;
import java.util.List;
 
@Service
public class LuckyActivityServiceImpl implements LuckyActivityService {
 
    @Resource
    private LuckyActivityMapper luckyActivityMapper;
 
    @Reference(version = "1.0")
    private AppService appService;
 
    private Long getAppId(String appKey) throws AppException {
        AppInfo app = appService.getApp(appKey);
        if (app == null) {
            throw new AppException(AppException.CODE_NOT_EXIST, "应用不存在");
        }
        return app.getId();
    }
 
    @Override
    public List<LuckyActivity> getActivityList(String appKey, Long sponsorId, List<Integer> stateList, String key, int page, int pageSize) {
        ActivityDaoQuery query = new ActivityDaoQuery();
        query.stateList = stateList;
        query.key = key;
        query.sponsorId = sponsorId;
 
        try {
            query.appId = getAppId(appKey);
        } catch (AppException e) {
            return null;
        }
        query.start = (page - 1) * pageSize;
        query.count = pageSize;
        query.sort = "start_time desc";
        return luckyActivityMapper.list(query);
    }
 
    @Override
    public long countActivity(String appKey, Long sponsorId, List<Integer> stateList, String key) {
        ActivityDaoQuery query = new ActivityDaoQuery();
        query.stateList = stateList;
        query.key = key;
        query.sponsorId = sponsorId;
        try {
            query.appId = getAppId(appKey);
        } catch (AppException e) {
            return 0L;
        }
        return luckyActivityMapper.count(query);
    }
 
 
    @Validated
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createActivity(LuckyActivity activity) throws LuckyActivityException {
 
        if (activity.getAwardsList() == null || activity.getAwardsList().size() == 0) {
            throw new LuckyActivityException(LuckyActivityException.CODE_PARAMS_NOT_ENOUGH, "请设置奖项信息");
        }
 
        if (activity.getOpenInfo() == null) {
            throw new LuckyActivityException(LuckyActivityException.CODE_PARAMS_NOT_ENOUGH, "请设置开奖信息");
        }
        if (activity.getSponsorInfo() == null) {
            throw new LuckyActivityException(LuckyActivityException.CODE_PARAMS_NOT_ENOUGH, "请设置赞助信息");
        }
    }
 
    @Override
    public void verifyActivity(Long activityId, boolean pass, String remarks) throws LuckyActivityException {
 
    }
 
    @Override
    public LuckyActivity getActivityDetail(Long id) {
        return null;
    }
 
    @Override
    public void updateActivity(LuckyActivity activity) throws LuckyActivityException {
 
    }
}