xiaoyong931011
2021-07-15 2f2006691270d2788e32ca3eeae5a3b2faed0fc1
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
package com.xzx.gc.user.service;
 
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import com.xzx.gc.common.constant.Constants;
import com.xzx.gc.common.utils.DateUtils;
import com.xzx.gc.common.utils.RedisUtil;
import com.xzx.gc.entity.RedPaperRule;
import com.xzx.gc.user.mapper.AccountMapper;
import com.xzx.gc.user.mapper.RedPaperMapper;
import com.xzx.gc.user.mapper.RedPaperRuleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.Date;
 
@Service
@Transactional
public class RedPaperRuleService {
 
 
    @Autowired
    private RedPaperMapper redPaperMapper;
 
    @Autowired
    private RedisUtil redisUtil;
 
    @Autowired
    private AccountMapper accountMapper;
 
    @Autowired
    private RedPaperRuleMapper redPaperRuleMapper;
 
 
    /**
     * 红包在规则时间范围内是否有效
     * @param ruleId
     * @return
     */
    public boolean isvalid( Integer ruleId ){
        //是否在规则的时间内
        RedPaperRule redPaperRule = redPaperRuleMapper.selectByPrimaryKey(ruleId);
        if(redPaperRule==null||Constants.DEL_FLAG==Convert.toInt(redPaperRule.getDelFlag(),1)||Constants.FAIL.equals(Convert.toStr(redPaperRule.getStatus(),"0"))){
           return false;
        }
 
        Date startTime = DateUtil.parse(redPaperRule.getStartTime(),DateUtils.DATE_FORMAT_YMD);
        Date endTime =  DateUtil.parse(redPaperRule.getEndTime(),DateUtils.DATE_FORMAT_YMD);
 
        boolean in = DateUtil.isIn(DateUtil.parse(DateUtil.today(),DateUtils.DATE_FORMAT_YMD), startTime, endTime);
 
        if(!in){
            return false;
        }
        return true;
    }
 
 
    /**
     * 获取当前时间内符合条件的一条规则
     * @return
     */
    public RedPaperRule getOne(String ruleType,String partnerId){
        return redPaperRuleMapper.getOne(DateUtil.format(new Date(),DateUtils.DATE_FORMAT_YMD),ruleType,partnerId);
    }
 
}