...
|
...
|
@@ -2,17 +2,26 @@ package com.yohobuy.platform.operations.service.impl; |
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.yoho.core.rest.client.ServiceCaller;
|
|
|
import com.yoho.message.sdk.utils.DateUtils;
|
|
|
import com.yohobuy.platform.common.util.DateUtil;
|
|
|
import com.yohobuy.platform.common.util.StringUtil;
|
|
|
import com.yohobuy.platform.dal.operations.IHtmlContentDao;
|
|
|
import com.yohobuy.platform.dal.operations.IRedpacketConfigDao;
|
|
|
import com.yohobuy.platform.dal.operations.RedpacketRuleConfigMapper;
|
|
|
import com.yohobuy.platform.dal.operations.model.HtmlContent;
|
|
|
import com.yohobuy.platform.dal.operations.model.RedpacketConfig;
|
|
|
import com.yohobuy.platform.dal.operations.model.RedpacketRuleConfig;
|
|
|
import com.yohobuy.platform.model.common.PageResponseVO;
|
|
|
import com.yohobuy.platform.model.common.ServiceException;
|
|
|
import com.yohobuy.platform.model.operations.RedPacketConfigBo;
|
|
|
import com.yohobuy.platform.model.operations.RedPacketRuleBo;
|
|
|
import com.yohobuy.platform.model.operations.request.RedpacketConfigReq;
|
|
|
import com.yohobuy.platform.operations.service.IRedpacketConfigService;
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
...
|
...
|
@@ -20,8 +29,7 @@ import org.springframework.stereotype.Service; |
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
@Service
|
|
|
public class RedpacketConfigServiceImpl implements IRedpacketConfigService {
|
...
|
...
|
@@ -31,6 +39,15 @@ public class RedpacketConfigServiceImpl implements IRedpacketConfigService { |
|
|
|
|
|
@Autowired
|
|
|
IRedpacketConfigDao redpacketConfigDao;
|
|
|
|
|
|
@Autowired
|
|
|
RedpacketRuleConfigMapper redpacketRuleConfigMapper;
|
|
|
|
|
|
@Autowired
|
|
|
IHtmlContentDao iHtmlContentDao;
|
|
|
|
|
|
public static final String RED_PACKAET_NODE_CODE = "20181002-161516";
|
|
|
|
|
|
@Autowired
|
|
|
ServiceCaller serviceCaller;
|
|
|
|
...
|
...
|
@@ -38,6 +55,93 @@ public class RedpacketConfigServiceImpl implements IRedpacketConfigService { |
|
|
private String apiUrl;
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取红包使用规则配置
|
|
|
* @return
|
|
|
*/
|
|
|
public RedPacketRuleBo getRedpacketRule(){
|
|
|
|
|
|
// 获取(我的红包问号中的介绍)以外的红包配置信息
|
|
|
RedpacketRuleConfig redpacketRuleConfig = redpacketRuleConfigMapper.selectRedpacketRule();
|
|
|
if (redpacketRuleConfig == null){
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
RedPacketRuleBo redPacketRuleBo = new RedPacketRuleBo();
|
|
|
BeanUtils.copyProperties(redpacketRuleConfig, redPacketRuleBo);
|
|
|
|
|
|
HtmlContent htmlContent = iHtmlContentDao.selectOneByNodeCode(RED_PACKAET_NODE_CODE);
|
|
|
if (htmlContent != null && StringUtils.isNotBlank(htmlContent.getInuseContent())){
|
|
|
redPacketRuleBo.setMyRedpacketQuestion(htmlContent.getInuseContent());
|
|
|
}
|
|
|
|
|
|
return redPacketRuleBo;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 更新红包规则
|
|
|
* @param redPacketRuleBo
|
|
|
* @throws ServiceException
|
|
|
*/
|
|
|
public void addRedPacketRule(RedPacketRuleBo redPacketRuleBo) throws ServiceException{
|
|
|
|
|
|
// 校验
|
|
|
if (StringUtil.isBlank(redPacketRuleBo.getToken())){
|
|
|
logger.warn("addRedPacketRule token is empty");
|
|
|
throw new ServiceException(411, "token不能为空!");
|
|
|
}
|
|
|
|
|
|
// token是否存在
|
|
|
RedpacketConfig redpacketConfig = redpacketConfigDao.selectByToken(redPacketRuleBo.getToken());
|
|
|
if (redpacketConfig == null){
|
|
|
logger.warn("addRedPacketRule token[{}] not exist", redPacketRuleBo.getToken());
|
|
|
throw new ServiceException(501, "token不存在,请确认!");
|
|
|
}
|
|
|
|
|
|
// token红包的有效期间>商品详情页红包显示的有效期间
|
|
|
if (redPacketRuleBo.getShowStartTime() != null && redPacketRuleBo.getShowEndTime() != null
|
|
|
&& !Objects.isNull(redpacketConfig.getStartTime()) && !Objects.isNull(redpacketConfig.getEndTime())){
|
|
|
|
|
|
if (Integer.compare(redPacketRuleBo.getShowStartTime(), redpacketConfig.getStartTime())>0
|
|
|
|| Integer.compare(redPacketRuleBo.getShowEndTime(), redpacketConfig.getEndTime())<0){
|
|
|
logger.warn("addRedPacketRule token time [start {}] [end {}] < show time [start {}] [end {}] error.",
|
|
|
redpacketConfig.getStartTime(), redpacketConfig.getEndTime(), redPacketRuleBo.getShowStartTime(), redPacketRuleBo.getShowEndTime());
|
|
|
throw new ServiceException(502, "Token的有效期必须>领取时间");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 是否存在红包规则配置
|
|
|
RedpacketRuleConfig redpacketRuleConfig = redpacketRuleConfigMapper.selectRedpacketRule();
|
|
|
if (redpacketRuleConfig == null){
|
|
|
|
|
|
redpacketRuleConfig = new RedpacketRuleConfig();
|
|
|
BeanUtils.copyProperties(redPacketRuleBo, redpacketRuleConfig);
|
|
|
int now = DateUtils.getCurrentTimeSeconds();
|
|
|
redpacketRuleConfig.setCreateTime(now);
|
|
|
redpacketRuleConfig.setUpdateTime(now);
|
|
|
|
|
|
redpacketRuleConfigMapper.insertSelective(redpacketRuleConfig);
|
|
|
|
|
|
}else{
|
|
|
|
|
|
BeanUtils.copyProperties(redPacketRuleBo, redpacketRuleConfig);
|
|
|
int now = DateUtils.getCurrentTimeSeconds();
|
|
|
redpacketRuleConfig.setUpdateTime(now);
|
|
|
redpacketRuleConfigMapper.updateByPrimaryKeySelective(redpacketRuleConfig);
|
|
|
}
|
|
|
|
|
|
|
|
|
// 更新红包规则中的-我的红包中的问号介绍
|
|
|
HtmlContent htmlContent = iHtmlContentDao.selectOneByNodeCode(RED_PACKAET_NODE_CODE);
|
|
|
// 不考虑不存在的情况
|
|
|
if (htmlContent != null){
|
|
|
htmlContent.setInuseContent(redPacketRuleBo.getMyRedpacketQuestion());
|
|
|
iHtmlContentDao.updateInuseContent(htmlContent);
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
...
|
...
|
|