admin
2021-06-24 df4441322e9801c102299451da41d7c40b4502e9
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
package com.ks.daylucky.service.impl;
 
import com.ks.daylucky.dao.ActivityDrawnRecieveNotifyInfoDao;
import com.ks.daylucky.exception.ActivityDrawnRecieveNotifyInfoException;
import com.ks.daylucky.pojo.DO.ActivityDrawnRecieveNotifyInfo;
import com.ks.daylucky.service.ActivityDrawnRecieveNotifyInfoService;
import com.ks.lib.common.exception.ParamsException;
import com.ks.lucky.pojo.DO.LuckyActivityAwardResult;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
 
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Date;
 
@Service
public class ActivityDrawnRecieveNotifyInfoServiceImpl implements ActivityDrawnRecieveNotifyInfoService {
 
    @Resource
    private ActivityDrawnRecieveNotifyInfoDao activityDrawnRecieveNotifyInfoDao;
 
    @Validated
    @Override
    public void addNotify(@Valid ActivityDrawnRecieveNotifyInfo notifyInfo) throws ParamsException, ActivityDrawnRecieveNotifyInfoException {
        if (notifyInfo.getCreateTime() == null) {
            notifyInfo.setCreateTime(new Date());
        }
 
        String id = null;
        switch (notifyInfo.getAwardResult().getState()) {
 
            case LuckyActivityAwardResult
                    .STATE_NOT_RECIEVE:
                id = ActivityDrawnRecieveNotifyInfo.createId(notifyInfo.getAwardResult().getId(), ActivityDrawnRecieveNotifyInfo.TYPE_UNRECIEVE);
                break;
 
            case LuckyActivityAwardResult
                    .STATE_OUT_OF_DATE:
                id = ActivityDrawnRecieveNotifyInfo.createId(notifyInfo.getAwardResult().getId(), ActivityDrawnRecieveNotifyInfo.TYPE_OUTDATE);
                break;
 
            default:
                return;
        }
        //生成主键
        ActivityDrawnRecieveNotifyInfo oldInfo = activityDrawnRecieveNotifyInfoDao.get(id);
        if (oldInfo != null) {
            throw new ActivityDrawnRecieveNotifyInfoException(ActivityDrawnRecieveNotifyInfoException.CODE_EXIST, "通知已经存在");
        }
        notifyInfo.setId(id);
        activityDrawnRecieveNotifyInfoDao.save(notifyInfo);
    }
 
    @Override
    public ActivityDrawnRecieveNotifyInfo getShowNotifyInfo(Long appId, Long uid, Long activityId) {
 
        return activityDrawnRecieveNotifyInfoDao.getShowNotifyInfo(appId, uid, activityId);
    }
 
    @Override
    public void setNotifyShown(String id) {
        ActivityDrawnRecieveNotifyInfo update = new ActivityDrawnRecieveNotifyInfo();
        update.setId(id);
        update.setShown(true);
        update.setShowTime(new Date());
        activityDrawnRecieveNotifyInfoDao.updateSelective(update);
    }
 
    @Override
    public ActivityDrawnRecieveNotifyInfo selectByPrimaryKey(String id) {
        return activityDrawnRecieveNotifyInfoDao.get(id);
    }
 
 
}