| 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);  | 
|     }  | 
|   | 
| }  |