Authored by wangshusheng

砍价修改

... ... @@ -66,6 +66,24 @@ public class RedisValueCache {
return null;
}
public <T> List<T> getList(CacheKeyEnum cacheEnum, Object obj, Class<T> clazz) {
List<T> t = null;
RedisKeyBuilder key = null;
try {
key = RedisKeyBuilder.newInstance().appendFixed(cacheEnum.getCacheKey()).appendVar(obj);
String value = yhValueOperations.get(key);
if (StringUtils.isBlank(value)) {
logger.info("cache miss key is:{}", key);
return null;
}
t = JSON.parseArray(value, clazz);
logger.info("cache hit key is:{}", key);
return t;
} catch (Exception e) {
logger.warn("get from cache failed!!! key is:{}", key, e);
return null;
}
}
/**
* 设置值
... ... @@ -218,6 +236,7 @@ public class RedisValueCache {
}
return t;
}
public static void main(String[] args) {
String str = "12345";
String jsonStr = JSON.toJSONString(str);
... ...
... ... @@ -11,4 +11,5 @@ public interface CutDownPriceActivityMapper {
List<CutDownPriceActivity> selectCutDownPriceActivityList(@Param("list") List<Integer> activityId);
List<CutDownPriceActivity> selectEffectCutPriceActivity();
}
... ...
... ... @@ -13,7 +13,7 @@ public interface CutDownPriceUserHelpMapper {
List<CutDownPriceProductHelpUser> selectHelpInfoByUidAndCode(@Param("list") List<Integer> uidList, @Param("activityId") Integer activityId, @Param("productSkn") Integer productSkn);
Integer selectExistHelpInfo(@Param("userId") Integer userId, @Param("helpUserId") String helpUserId, @Param("activityId") Integer activityId, @Param("productSkn") Integer productSkn);
Integer selectExistHelpInfo(@Param("userId") Integer userId, @Param("helpUserId") Integer helpUserId, @Param("activityId") Integer activityId, @Param("productSkn") Integer productSkn);
List<CutDownPriceProductHelpUser> selectHelpInfoList(@Param("list") List<CutPriceHelpUserRequestBO> requestList);
}
... ...
... ... @@ -5,9 +5,7 @@ import java.math.BigDecimal;
public class CutDownPriceProductHelpUser {
private Integer id;
private Integer userId;
private String helpUserId;
private String helpUserName;
private String helpUserImgUrl;
private Integer helpUserId;
private Integer createTime;
private Integer activityId;
private Integer productSkn;
... ... @@ -29,30 +27,14 @@ public class CutDownPriceProductHelpUser {
this.userId = userId;
}
public String getHelpUserId() {
public Integer getHelpUserId() {
return helpUserId;
}
public void setHelpUserId(String helpUserId) {
public void setHelpUserId(Integer helpUserId) {
this.helpUserId = helpUserId;
}
public String getHelpUserName() {
return helpUserName;
}
public void setHelpUserName(String helpUserName) {
this.helpUserName = helpUserName;
}
public String getHelpUserImgUrl() {
return helpUserImgUrl;
}
public void setHelpUserImgUrl(String helpUserImgUrl) {
this.helpUserImgUrl = helpUserImgUrl;
}
public Integer getCreateTime() {
return createTime;
}
... ...
... ... @@ -17,6 +17,16 @@
activity_id, activity_name, status, begin_time, end_time, create_time, update_time, jump_url, banner_url
</sql>
<select id="selectEffectCutPriceActivity" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from cutdown_price_activity
where 1=1 and status=1
and begin_time &lt;= UNIX_TIMESTAMP()
and end_time &gt;= UNIX_TIMESTAMP()
order by begin_time
</select>
<select id="selectCutDownPriceActivity" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
... ...
... ... @@ -4,16 +4,14 @@
<resultMap id="BaseResultMap" type="com.yoho.activity.dal.model.CutDownPriceProductHelpUser">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="user_id" property="userId" jdbcType="INTEGER" />
<result column="help_user_id" property="helpUserId" jdbcType="VARCHAR" />
<result column="help_user_name" property="helpUserName" jdbcType="VARCHAR" />
<result column="help_user_img_url" property="helpUserImgUrl" jdbcType="VARCHAR" />
<result column="help_user_id" property="helpUserId" jdbcType="INTEGER" />
<result column="activity_id" property="activityId" jdbcType="INTEGER" />
<result column="product_skn" property="productSkn" jdbcType="INTEGER" />
<result column="cut_price" property="cutPrice" jdbcType="DECIMAL" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, user_id, help_user_id,help_user_name,help_user_img_url,activity_id,product_skn,cut_price,create_time
id, user_id, help_user_id,activity_id,product_skn,cut_price,create_time
</sql>
<select id="selectHelpInfo" resultMap="BaseResultMap">
... ... @@ -26,9 +24,8 @@
</select>
<insert id="addHelpUserInfo" parameterType="com.yoho.activity.dal.model.CutDownPriceProductHelpUser">
insert into cutdown_price_help_user (user_id, help_user_id,help_user_name,help_user_img_url,activity_id,product_skn,cut_price,create_time)
values (#{userId,jdbcType=INTEGER}, #{helpUserId,jdbcType=VARCHAR}, #{helpUserName,jdbcType=VARCHAR},
#{helpUserImgUrl,jdbcType=VARCHAR}, #{activityId,jdbcType=INTEGER}, #{productSkn,jdbcType=INTEGER},
insert into cutdown_price_help_user (user_id, help_user_id,activity_id,product_skn,cut_price,create_time)
values (#{userId,jdbcType=INTEGER}, #{helpUserId,jdbcType=INTEGER}, #{activityId,jdbcType=INTEGER}, #{productSkn,jdbcType=INTEGER},
#{cutPrice,jdbcType=DECIMAL}, #{createTime,jdbcType=INTEGER}
)
</insert>
... ... @@ -36,7 +33,7 @@
<select id="selectExistHelpInfo" resultType="java.lang.Integer">
select count(1) FROM cutdown_price_help_user
where user_id = #{userId,jdbcType=INTEGER}
AND help_user_id = #{helpUserId,jdbcType=VARCHAR}
AND help_user_id = #{helpUserId,jdbcType=INTEGER}
AND activity_id = #{activityId,jdbcType=INTEGER}
AND product_skn = #{productSkn,jdbcType=INTEGER}
</select>
... ...
... ... @@ -7,8 +7,10 @@ import com.yoho.core.rest.annotation.ServiceDesc;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yoho.product.model.CollageProductBo;
import com.yoho.product.request.BaseRequest;
import com.yoho.product.response.PageResponseBo;
import com.yoho.product.response.VoidResponse;
import com.yoho.service.model.activity.CutDownPriceActivityBo;
import com.yoho.service.model.activity.CutDownPriceActivityProductBo;
import com.yoho.service.model.activity.CutDownPriceProductHelpUserBo;
import com.yoho.service.model.activity.CutDownProductQueryRequest;
... ... @@ -37,7 +39,19 @@ public class CutDownProductPriceRest {
private ICutDownPriceService cutDownPriceService;
/**
* 用户发起砍价
* 查询正在生效的砍价活动
*/
@RequestMapping("/queryEffectCutPriceActivity")
@ResponseBody
public CutDownPriceActivityBo queryEffectCutPriceActivity(@RequestBody BaseRequest<Integer> request) {
logger.info("CutDownProductPriceRest queryEffectCutPriceActivity");
CutDownPriceActivityBo bo = cutDownPriceService.queryEffectCutPriceActivity();
logger.info("CutDownProductPriceRest queryEffectCutPriceActivity success");
return bo;
}
/**
* 用户发起砍价,系统自动砍价
*/
@RequestMapping("/addCutPriceRecord")
@ResponseBody
... ... @@ -73,7 +87,7 @@ public class CutDownProductPriceRest {
}
/**
* 好友帮忙砍价
* 好友帮忙砍价,并自动发起一个砍价
*/
@RequestMapping("/addCutPriceHelpUserInfo")
@ResponseBody
... ...
... ... @@ -12,4 +12,6 @@ public interface ICutDownPriceActivityService {
CutDownPriceActivityBo queryActivityInfo(Integer activityId);
List<CutDownPriceActivityBo> queryActivityInfos(List<Integer> activityIds);
List<CutDownPriceActivityBo> queryEffectCutPriceActivitys();
}
... ...
... ... @@ -2,6 +2,7 @@ package com.yoho.activity.queue.service;
import com.yoho.activity.dal.model.CutDownPriceProductHelpUser;
import com.yoho.product.response.PageResponseBo;
import com.yoho.service.model.activity.CutDownPriceActivityBo;
import com.yoho.service.model.activity.CutDownPriceActivityProductBo;
import com.yoho.service.model.activity.CutDownPriceProductHelpUserBo;
import com.yoho.service.model.activity.CutDownProductQueryRequest;
... ... @@ -28,4 +29,6 @@ public interface ICutDownPriceService {
void addCutPriceUseRecord(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO);
int cancelCutPriceUseRecord(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO);
CutDownPriceActivityBo queryEffectCutPriceActivity();
}
... ...
... ... @@ -39,6 +39,24 @@ public class CutDownPriceActivityServiceImpl implements ICutDownPriceActivitySer
private BeanConvert convert;
@Override
public List<CutDownPriceActivityBo> queryEffectCutPriceActivitys() {
String redisKeySuffix = "effective";
List<CutDownPriceActivityBo> cutDownPriceActivityBoList = redisValueCache.getList(CacheKeyEnum.CUTDOWN_PRICE_ACTIVITYBO_INFO, redisKeySuffix, CutDownPriceActivityBo.class);
if (null != cutDownPriceActivityBoList){
logger.info("CutDownPriceActivityServiceImpl :: queryActivityInfo getCache result is{}",cutDownPriceActivityBoList);
return cutDownPriceActivityBoList;
}
List<CutDownPriceActivity> cutDownPriceActivitys = cutDownPriceActivityMapper.selectEffectCutPriceActivity();
if (CollectionUtils.isEmpty(cutDownPriceActivitys)){
logger.info("CutDownPriceActivityServiceImpl :: queryActivityInfo result is null");
return null;
}
cutDownPriceActivityBoList = convert.convertFromList(cutDownPriceActivitys, CutDownPriceActivityBo.class);
redisValueCache.set(CacheKeyEnum.CUTDOWN_PRICE_ACTIVITYBO_INFO, redisKeySuffix, cutDownPriceActivityBoList, 3600, TimeUnit.SECONDS);
return cutDownPriceActivityBoList;
}
@Override
public CutDownPriceActivityBo queryActivityInfo(Integer activityId) {
String redisKeySuffix = activityId + "";
CutDownPriceActivityBo cutDownPriceActivityBo = redisValueCache.get(CacheKeyEnum.CUTDOWN_PRICE_ACTIVITYBO_INFO, redisKeySuffix, CutDownPriceActivityBo.class);
... ...
... ... @@ -25,8 +25,11 @@ import com.yoho.product.response.PageResponseBo;
import com.yoho.service.model.activity.*;
import com.yoho.service.model.activity.drawline.request.CutPriceHelpUserRequestBO;
import com.yoho.service.model.activity.drawline.response.UserBaseRspBO;
import com.yoho.service.model.social.request.UicUserReqBO;
import com.yoho.service.model.social.response.UserInfoRspBO;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -42,6 +45,9 @@ import java.util.stream.Collectors;
@Service
public class CutDownPriceServiceImpl implements ICutDownPriceService {
private static Logger logger = LoggerFactory.getLogger(CutDownPriceServiceImpl.class);
private static final Integer SYSTEM_HELP_ID = 0;
private static final String SYSTEM_HELP_NAME = "有货";
private static final String SYSTEM_HELP_IMAGE = "https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTKic2dZ7ib6p1PJJXFpYl95ibRyvSKCib3icUiaStlRN6PWmcRZjzPn4w4moEk2xhUxpYbibuPtBNPJBMeqQ/132";
@Autowired
private RedisValueCache redisValueCache;
@Autowired
... ... @@ -62,6 +68,23 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
private BeanConvert convert;
@Override
public CutDownPriceActivityBo queryEffectCutPriceActivity() {
CutDownPriceActivityBo activityBo = null;
List<CutDownPriceActivityBo> activityBoList = cutDownActivityService.queryEffectCutPriceActivitys();
if(CollectionUtils.isEmpty(activityBoList)){
return null;
}
int currentTime = DateUtils.getCurrentTimeSecond();
for(CutDownPriceActivityBo bo : activityBoList){
if(bo.getBeginTime()<currentTime && bo.getEndTime()>currentTime){
activityBo = bo;
break;
}
}
return activityBo;
}
@Override
public List<CutDownPriceProductHelpUserBo> queryHelpInfo(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO) {
Integer activityId = cutPriceHelpUserRequestBO.getActivityId();
Integer productSkn = cutPriceHelpUserRequestBO.getProductSkn();
... ... @@ -92,13 +115,15 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
/**
* 查询某一个用户的帮砍记录
*/
private List<CutDownPriceProductHelpUserBo> queryHelpInfoList(List<CutPriceHelpUserRequestBO> requestList) {
private List<CutDownPriceProductHelpUserBo> queryHelpInfoList(Integer userId, List<CutPriceHelpUserRequestBO> requestList) {
List<CutDownPriceProductHelpUser> helpUsers = cutPriceUserHelpMapper.selectHelpInfoList(requestList);
if (CollectionUtils.isEmpty(helpUsers)){
logger.info("CutDownPriceServiceImpl :: queryHelpInfoList result is null");
return Lists.newArrayList();
}
List<CutDownPriceProductHelpUserBo> helpUsersBoList = convert.convertFromList(helpUsers, CutDownPriceProductHelpUserBo.class);
//获取用户头像
getUserInfo(userId, helpUsersBoList);
return helpUsersBoList;
}
... ... @@ -200,7 +225,7 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
List<CutDownPriceProductBo> cutProductBoList = cutDownPriceProductService.queryCutDownPriceProductBoListByRecords(cutPriceUserRecordList);
// 查询已砍价记录
List<CutPriceHelpUserRequestBO> userRequestList = convert.convertFromList(cutPriceUserRecordList, CutPriceHelpUserRequestBO.class);
List<CutDownPriceProductHelpUserBo> helpUserBoList = this.queryHelpInfoList(userRequestList);
List<CutDownPriceProductHelpUserBo> helpUserBoList = this.queryHelpInfoList(uid, userRequestList);
// 根据skn列表查询商品信息
BatchBaseRequest<Integer> productRequest = new BatchBaseRequest<Integer>();
productRequest.setParams(Lists.newArrayList(productSkns));
... ... @@ -240,7 +265,7 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
Integer activityId = cutPriceHelpUserRequestBO.getActivityId();
Integer productSkn = cutPriceHelpUserRequestBO.getProductSkn();
Integer userId = cutPriceHelpUserRequestBO.getUserId();
String helpUserId = cutPriceHelpUserRequestBO.getHelpUserId();
Integer helpUserId = cutPriceHelpUserRequestBO.getHelpUserId();
//判断用户是否已经帮助砍价
Integer count = cutPriceUserHelpMapper.selectExistHelpInfo(userId, helpUserId, activityId, productSkn);
... ... @@ -269,6 +294,16 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
cutPriceUserHelpMapper.addHelpUserInfo(helpUser);
// 修改用户发起砍价记录表中的帮砍次数
cutDownPriceUserRecordMapper.updateCutDownHelpCount(userId, activityId, productSkn);
// 用户帮忙砍价后,自动发起砍价活动,系统帮助砍价除外
if(!SYSTEM_HELP_ID.equals(helpUserId)){
try{
cutPriceHelpUserRequestBO.setUserId(Integer.valueOf(helpUserId));
logger.info(" system start addCutPriceRecord, userId is {}, activityId is {}, productSkn is {}", userId, activityId, productSkn);
addCutPriceRecord(cutPriceHelpUserRequestBO);
}catch(Exception e){
logger.warn(" system addHelpUserInfo failed, userId is {}, activityId is {}, productSkn is {}, exception is {}", userId, activityId, productSkn, e);
}
}
// 清理缓存,用户帮砍记录列表、商品详情页
clearCache(activityId, productSkn, userId);
return cutPrice;
... ... @@ -299,7 +334,16 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
record.setProductSkn(productSkn);
record.setUserId(userId);
record.setCreateTime(DateUtils.getCurrentTimeSecond());
logger.info(" addCutDownUserRecord, userId is {}, activityId is {}, productSkn is {}", userId, activityId, productSkn);
int num = cutDownPriceUserRecordMapper.addCutDownUserRecord(record);
// 系统帮助砍第一次价
try{
logger.info(" system start addHelpUserInfo, userId is {}, activityId is {}, productSkn is {}", userId, activityId, productSkn);
addHelpUserInfo(convertCutDownPriceProductSystemHelpUser(cutPriceHelpUserRequestBO));
}catch(Exception e){
logger.warn(" system addHelpUserInfo failed, userId is {}, activityId is {}, productSkn is {}, exception is {}", userId, activityId, productSkn, e);
}
return num;
}
... ... @@ -327,12 +371,17 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
user.setUserId(request.getUserId());
user.setActivityId(request.getActivityId());
user.setProductSkn(request.getProductSkn());
user.setHelpUserName(request.getHelpUserName());
user.setHelpUserId(request.getHelpUserId());
user.setHelpUserImgUrl(request.getHelpUserImgUrl());
return user;
}
private CutPriceHelpUserRequestBO convertCutDownPriceProductSystemHelpUser(CutPriceHelpUserRequestBO request) {
request.setHelpUserName(SYSTEM_HELP_NAME);
request.setHelpUserId(SYSTEM_HELP_ID);
request.setHelpUserImgUrl(SYSTEM_HELP_IMAGE);
return request;
}
private BigDecimal calculateCutPrice(CutDownPriceProductBo cutDownPriceProductBo, List<CutDownPriceProductHelpUser> helpUsers) {
if(helpUsers==null){
helpUsers = new ArrayList<>();
... ... @@ -355,20 +404,47 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
}
private void getUserInfo(Integer userId, List<CutDownPriceProductHelpUserBo> helpUserBos) {
List<Integer> uidList = new ArrayList<>();
uidList.add(userId);
AsyncFuture<UserBaseRspBO[]> userBaseRspBOArrAsync = drawlineList2MapService.postForUserBaseInfo(uidList);
UserBaseRspBO[] userBaseRspBOs = userBaseRspBOArrAsync.get();
StringBuilder sb = new StringBuilder();
sb.append(userId);
for (CutDownPriceProductHelpUserBo helpUserBo : helpUserBos){
sb.append(",").append(helpUserBo.getHelpUserId());
}
UserInfoRspBO[] userInfoBoArray = invokeUicGetUserInfo(sb.toString());
for (CutDownPriceProductHelpUserBo helpUserBo : helpUserBos){
for (UserInfoRspBO userInfoRspBO : userInfoBoArray){
if(helpUserBo.getHelpUserId().equals(SYSTEM_HELP_ID)) {
helpUserBo.setHelpUserImgUrl(SYSTEM_HELP_IMAGE);
helpUserBo.setHelpUserName(SYSTEM_HELP_NAME);
break;
}else if (helpUserBo.getHelpUserId().equals(userInfoRspBO.getUid())){
helpUserBo.setHelpUserImgUrl(userInfoRspBO.getHeadIco());
helpUserBo.setHelpUserName(userInfoRspBO.getNickName());
break;
}
}
}
for (CutDownPriceProductHelpUserBo helpUserBo : helpUserBos){
for (UserBaseRspBO userBaseRspBO : userBaseRspBOs){
if (helpUserBo.getUserId().equals(userBaseRspBO.getUid())){
helpUserBo.setUserImgUrl(userBaseRspBO.getHeadIco());
for (UserInfoRspBO userInfoRspBO : userInfoBoArray){
if (userId.equals(userInfoRspBO.getUid())){
helpUserBo.setUserImgUrl(userInfoRspBO.getHeadIco());
break;
}
}
}
}
private UserInfoRspBO[] invokeUicGetUserInfo(String uids) {
if(StringUtils.isEmpty(uids)){
return new UserInfoRspBO[0];
}
UicUserReqBO request = new UicUserReqBO();
request.setUids(uids);
logger.info("start invoke uic.getUserInfoListByYohoUid, uids is {}", uids);
UserInfoRspBO[] userInfoBoArray = serviceCaller.call("uic.getUserInfoListByYohoUid", request, UserInfoRspBO[].class);
return userInfoBoArray;
}
private CutDownPriceActivityProductBo buildCutDownPriceActivityProductBo(CutDownPriceActivityBo activityBo,
CutDownPriceProductBo cutDownPriceProductBo,
List<CutDownPriceProductHelpUserBo> helpUserBos,
... ...
... ... @@ -46,6 +46,7 @@
<value>/queryCutPriceProductForOrder</value>
<value>/addCutPriceUseRecord</value>
<value>/cancelCutPriceUseRecord</value>
<value>/queryEffectCutPriceActivity</value>
</list>
</property>
<property name="excludeMethods">
... ...