Authored by tanling

红包规则

... ... @@ -44,6 +44,11 @@
<groupId>com.yoho.core</groupId>
<artifactId>yoho-core-rest-server</artifactId>
</dependency>
<dependency>
<groupId>com.yohobuy.platform</groupId>
<artifactId>platform-dal</artifactId>
<version>1.0.3-6.8.5-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
... ...
... ... @@ -2,7 +2,9 @@ package com.yohobuy.platform.operations.restapi;
import com.yohobuy.platform.common.restapi.ApiResponse;
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.slf4j.Logger;
... ... @@ -48,6 +50,36 @@ public class RedPacketConfigController {
return new ApiResponse.ApiResponseBuilder().build();
}
/**
* 查询红包规则
* @return
*/
@RequestMapping("/getRedPacketRule")
@ResponseBody
public ApiResponse getRedPacketRule(){
RedPacketRuleBo redPacketRuleBo= redpacketConfigService.getRedpacketRule();
return new ApiResponse.ApiResponseBuilder().data(redPacketRuleBo).build();
}
/**
* 保存红包规则
* @return
*/
@RequestMapping("/addRedPacketRule")
@ResponseBody
public ApiResponse addRedPacketRule(@RequestBody RedPacketRuleBo redPacketRuleBo){
try{
redpacketConfigService.addRedPacketRule(redPacketRuleBo);
return new ApiResponse.ApiResponseBuilder().build();
}catch (ServiceException e){
return new ApiResponse.ApiResponseBuilder().code(e.getCode()).message(e.getMessage()).build();
}
}
/* @RequestMapping("/deletePacket")
@ResponseBody
public ApiResponse deletePacket(RedpacketConfigReq req){
... ...
... ... @@ -2,7 +2,9 @@ package com.yohobuy.platform.operations.service;
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;
public interface IRedpacketConfigService {
... ... @@ -14,4 +16,17 @@ public interface IRedpacketConfigService {
void removeRedpacket(RedpacketConfigReq req);
void updatePacketStatus(RedpacketConfigReq req);
/**
* 获取红包使用规则配置
* @return
*/
RedPacketRuleBo getRedpacketRule();
/**
* 更新红包规则
* @param redPacketRuleBo
* @throws ServiceException
*/
void addRedPacketRule(RedPacketRuleBo redPacketRuleBo) throws ServiceException;
}
... ...
... ... @@ -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
... ...
... ... @@ -24,7 +24,7 @@
<dependency>
<groupId>com.yoho.service.platform.model</groupId>
<artifactId>platform-service-model</artifactId>
<version>1.2.3-6.8.5-SNAPSHOT</version>
<version>1.2.3-6.8.6-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.yoho.dsf.yhplatform</groupId>
... ...
... ... @@ -60,7 +60,7 @@ rabbit_user=yoho
rabbit_password=yoho
#zookeeper address
zkAddress=127.0.0.1:2181
zkAddress=192.168.102.45:2181
#dev
web.context=pfcms
... ...
... ... @@ -138,6 +138,8 @@ datasources:
- com.yohobuy.platform.dal.operations.IRedpacketConfigDao
- com.yohobuy.platform.dal.operations.LikedActivityMapper
- com.yohobuy.platform.dal.operations.LikedDetailMapper
- com.yohobuy.platform.dal.operations.RedpacketRuleConfigMapper
yh_shops:
servers:
- 192.168.102.219:3306
... ...
... ... @@ -136,6 +136,8 @@ datasources:
- com.yohobuy.platform.dal.operations.IRedpacketConfigDao
- com.yohobuy.platform.dal.operations.LikedActivityMapper
- com.yohobuy.platform.dal.operations.LikedDetailMapper
- com.yohobuy.platform.dal.operations.RedpacketRuleConfigMapper
yh_shops:
servers:
- ${jdbc.mysql.yhshops.master}
... ...