Authored by wangshusheng

砍价

... ... @@ -16,4 +16,10 @@ public interface CutDownPriceUserRecordMapper {
CutDownPriceUserRecord selectCutDownPriceUserRecord(@Param("userId") Integer userId, @Param("activityId") Integer activityId, @Param("productSkn") Integer productSkn);
int updateCutDownHelpCount(@Param("userId") Integer userId, @Param("activityId") Integer activityId, @Param("productSkn") Integer productSkn);
int updateDecreaseUseCount(@Param("userId") Integer userId, @Param("activityId") Integer activityId, @Param("productSkn") Integer productSkn);
int updateIncreaseUseCount(@Param("userId") Integer userId, @Param("activityId") Integer activityId, @Param("productSkn") Integer productSkn);
}
... ...
package com.yoho.activity.dal;
import com.yoho.activity.dal.model.CutdownPriceOrderRecord;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface CutdownPriceOrderRecordMapper {
int addCutdownPriceOrderRecord(CutdownPriceOrderRecord record);
int selectCutdownPriceOrderRecordCount(CutdownPriceOrderRecord req);
List<CutdownPriceOrderRecord> selectCutdownPriceOrderRecord(@Param("uid") Integer uid);
int cancelCutdownPriceOrderRecord(CutdownPriceOrderRecord req);
}
... ... @@ -6,8 +6,11 @@ public class CutDownPriceUserRecord {
private Integer id;
private Integer userId;
private Integer createTime;
private Integer updateTime;
private Integer activityId;
private Integer productSkn;
private Integer helpCount;
private Integer useCount;
public Integer getId() {
return id;
... ... @@ -49,4 +52,27 @@ public class CutDownPriceUserRecord {
this.productSkn = productSkn;
}
public Integer getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Integer updateTime) {
this.updateTime = updateTime;
}
public Integer getHelpCount() {
return helpCount;
}
public void setHelpCount(Integer helpCount) {
this.helpCount = helpCount;
}
public Integer getUseCount() {
return useCount;
}
public void setUseCount(Integer useCount) {
this.useCount = useCount;
}
}
... ...
... ... @@ -6,10 +6,13 @@
<result column="user_id" property="userId" jdbcType="INTEGER" />
<result column="activity_id" property="activityId" jdbcType="INTEGER" />
<result column="product_skn" property="productSkn" jdbcType="INTEGER" />
<result column="help_count" property="helpCount" jdbcType="INTEGER" />
<result column="use_count" property="useCount" jdbcType="INTEGER" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
<result column="update_time" property="updateTime" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, user_id, activity_id, product_skn, create_time
id, user_id, activity_id, product_skn, help_count, use_count, create_time, update_time
</sql>
<insert id="addCutDownUserRecord" parameterType="com.yoho.activity.dal.model.CutDownPriceUserRecord">
... ... @@ -44,4 +47,27 @@
and product_skn = #{productSkn,jdbcType=INTEGER}
</select>
<update id="updateCutDownHelpCount" >
update cutdown_price_user_record
set help_count = help_count+1, update_time= UNIX_TIMESTAMP()
where user_id = #{userId,jdbcType=INTEGER}
and activity_id = #{activityId,jdbcType=INTEGER}
and productSkn = #{productSkn,jdbcType=INTEGER}
</update>
<update id="updateDecreaseUseCount" >
update cutdown_price_user_record
set use_count = use_count-1, update_time= UNIX_TIMESTAMP()
where user_id = #{userId,jdbcType=INTEGER}
and activity_id = #{activityId,jdbcType=INTEGER}
and productSkn = #{productSkn,jdbcType=INTEGER}
</update>
<update id="updateIncreaseUseCount" >
update cutdown_price_user_record
set use_count = use_count+1, update_time= UNIX_TIMESTAMP()
where user_id = #{userId,jdbcType=INTEGER}
and activity_id = #{activityId,jdbcType=INTEGER}
and productSkn = #{productSkn,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yoho.activity.dal.CutdownPriceOrderRecordMapper" >
<resultMap id="BaseResultMap" type="com.yoho.activity.dal.model.CutdownPriceOrderRecord" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="user_id" property="userId" jdbcType="INTEGER" />
<result column="activity_id" property="activityId" jdbcType="INTEGER" />
<result column="productSkn" property="productSkn" jdbcType="INTEGER" />
<result column="order_code" property="orderCode" jdbcType="VARCHAR" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
<result column="update_time" property="updateTime" jdbcType="INTEGER" />
<result column="status" property="status" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, user_id, activity_id, productSkn, order_code, create_time, update_time, status
</sql>
<insert id="addCutdownPriceOrderRecord" parameterType="com.yoho.activity.dal.model.CutdownPriceOrderRecord" >
insert into cutdown_price_order_record (user_id, activity_id, productSkn, order_code, create_time, update_time) values
(#{userId,jdbcType=INTEGER}, #{activityId,jdbcType=INTEGER}, #{productSkn,jdbcType=INTEGER}, #{orderCode,jdbcType=VARCHAR}, #{createTime,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER})
</insert>
<select id="selectCutdownPriceOrderRecordCount" resultType="java.lang.Integer" parameterType="com.yoho.activity.dal.model.CutdownPriceOrderRecord" >
select
count(1)
from cutdown_price_order_record p
where 1=1 and status = 0
and p.user_id = #{userId,jdbcType=INTEGER}
and p.activity_id=#{activityId,jdbcType=INTEGER}
and p.productSkn=#{productSkn,jdbcType=INTEGER}
</select>
<select id="selectCutdownPriceOrderRecord" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from cutdown_price_order_record p
where 1=1 and p.status = 0
and p.user_id = #{userId,jdbcType=INTEGER}
</select>
<update id="cancelCutdownPriceOrderRecord" parameterType="com.yoho.activity.dal.model.CutdownPriceOrderRecord">
update cutdown_price_order_record
set status = 1, update_time= #{updateTime,jdbcType=INTEGER}
where user_id = #{userId,jdbcType=INTEGER}
and order_code = #{orderCode,jdbcType=VARCHAR}
and activity_id = #{activityId,jdbcType=INTEGER}
and productSkn = #{productSkn,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
... ... @@ -8,6 +8,7 @@ import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yoho.product.model.CollageProductBo;
import com.yoho.product.response.PageResponseBo;
import com.yoho.product.response.VoidResponse;
import com.yoho.service.model.activity.CutDownPriceActivityProductBo;
import com.yoho.service.model.activity.CutDownPriceProductHelpUserBo;
import com.yoho.service.model.activity.CutDownProductQueryRequest;
... ... @@ -109,14 +110,14 @@ public class CutDownProductPriceRest {
throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_PARAM_ERROR);
}
logger.info("CutDownProductPriceRest queryCutPriceProductForOrder params is{}", cutPriceHelpUserRequestBO);
CutDownPriceActivityProductBo productInfo = cutDownPriceService.queryCutProductInfo(cutPriceHelpUserRequestBO);
CutDownPriceActivityProductBo productInfo = cutDownPriceService.queryCutProductInfoForOrder(cutPriceHelpUserRequestBO);
// 校验是否已经砍价成功
if(productInfo.getHasJoinNum()<productInfo.getJoinNum()){
logger.warn(" you have not cutdown success, params is {}", cutPriceHelpUserRequestBO);
throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_YOU_HASNOT_CUTDOWN_SUCCESS_ERROR);
}
// 校验是否已经使用过
if(productInfo.getUseCount()>0){
if(productInfo.getUseCount()==0){
logger.warn(" you have used this cutdown, params is {}", cutPriceHelpUserRequestBO);
throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_YOU_HAS_USED_CUTDOWNORDER_ERROR);
}
... ... @@ -130,7 +131,7 @@ public class CutDownProductPriceRest {
*/
@RequestMapping("/addCutPriceUseRecord")
@ResponseBody
public int addCutPriceUseRecord(@RequestBody CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO) {
public VoidResponse addCutPriceUseRecord(@RequestBody CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO) {
logger.info("CutDownProductPriceRest addCutPriceUseRecord params is{}", cutPriceHelpUserRequestBO);
if (null==cutPriceHelpUserRequestBO || null==cutPriceHelpUserRequestBO.getUserId()
|| null==cutPriceHelpUserRequestBO.getProductSkn() || null==cutPriceHelpUserRequestBO.getActivityId()) {
... ... @@ -138,9 +139,9 @@ public class CutDownProductPriceRest {
throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_PARAM_ERROR);
}
int result = cutDownPriceService.addCutPriceUseRecord(cutPriceHelpUserRequestBO);
cutDownPriceService.addCutPriceUseRecord(cutPriceHelpUserRequestBO);
logger.info("CutDownProductPriceRest addCutPriceUseRecord success");
return result;
return new VoidResponse(VoidResponse.CODE);
}
/**
* 给订单提供接口:取消砍价下单,修改状态,可以重新下单
... ... @@ -148,15 +149,15 @@ public class CutDownProductPriceRest {
*/
@RequestMapping("/cancelCutPriceUseRecord")
@ResponseBody
public int cancelCutPriceUseRecord(@RequestBody CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO) {
public VoidResponse cancelCutPriceUseRecord(@RequestBody CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO) {
logger.info("CutDownProductPriceRest cancelCutPriceUseRecord params is{}", cutPriceHelpUserRequestBO);
if (null==cutPriceHelpUserRequestBO || null==cutPriceHelpUserRequestBO.getUserId()
|| null==cutPriceHelpUserRequestBO.getProductSkn() || null==cutPriceHelpUserRequestBO.getActivityId()) {
logger.warn("warning param userId or productSkn or activityId is null,req is {}", cutPriceHelpUserRequestBO);
throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_PARAM_ERROR);
}
int result = cutDownPriceService.cancelCutPriceUseRecord(cutPriceHelpUserRequestBO);
cutDownPriceService.cancelCutPriceUseRecord(cutPriceHelpUserRequestBO);
logger.info("CutDownProductPriceRest cancelCutPriceUseRecord success");
return result;
return new VoidResponse(VoidResponse.CODE);
}
}
... ...
... ... @@ -17,13 +17,15 @@ public interface ICutDownPriceService {
CutDownPriceActivityProductBo queryCutProductInfo(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO);
CutDownPriceActivityProductBo queryCutProductInfoForOrder(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO);
BigDecimal addHelpUserInfo(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO);
int addCutPriceRecord(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO);
PageResponseBo<CutDownPriceActivityProductBo> queryMyCutPriceListByPage(CutDownProductQueryRequest request);
int addCutPriceUseRecord(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO);
void addCutPriceUseRecord(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO);
int cancelCutPriceUseRecord(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO);
}
... ...
... ... @@ -8,10 +8,8 @@ import com.yoho.activity.common.redis.RedisValueCache;
import com.yoho.activity.common.utils.DateUtils;
import com.yoho.activity.dal.CutDownPriceUserHelpMapper;
import com.yoho.activity.dal.CutDownPriceUserRecordMapper;
import com.yoho.activity.dal.CutdownPriceOrderRecordMapper;
import com.yoho.activity.dal.model.CutDownPriceProductHelpUser;
import com.yoho.activity.dal.model.CutDownPriceUserRecord;
import com.yoho.activity.dal.model.CutdownPriceOrderRecord;
import com.yoho.activity.queue.service.ICutDownPriceActivityService;
import com.yoho.activity.queue.service.ICutDownPriceProductService;
import com.yoho.activity.queue.service.ICutDownPriceService;
... ... @@ -26,12 +24,13 @@ import com.yoho.product.request.BatchBaseRequest;
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.request.LimitProductHelpUserRequestBO;
import com.yoho.service.model.activity.drawline.response.UserBaseRspBO;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
... ... @@ -52,8 +51,6 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
@Autowired
private CutDownPriceUserRecordMapper cutDownPriceUserRecordMapper;
@Autowired
private CutdownPriceOrderRecordMapper cutdownPriceOrderRecordMapper;
@Autowired
private ICutDownPriceActivityService cutDownActivityService;
@Autowired
private ICutDownPriceProductService cutDownPriceProductService;
... ... @@ -131,16 +128,41 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
return bo;
}
@Override
public CutDownPriceActivityProductBo queryCutProductInfoForOrder(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO) {
Integer activityId = cutPriceHelpUserRequestBO.getActivityId();
Integer productSkn = cutPriceHelpUserRequestBO.getProductSkn();
Integer userId = cutPriceHelpUserRequestBO.getUserId();
// 查询活动信息
CutDownPriceActivityBo activityBo = cutDownActivityService.queryActivityInfo(activityId);
checkValidActivity(activityBo, activityId);
// 查询商品配置信息
CutDownPriceProductBo cutDownPriceProductBo = cutDownPriceProductService.queryCutDownPriceProductBo(activityId, productSkn);
if(cutDownPriceProductBo==null){
logger.warn(" the cutdown product not exist, activityId is {}, productSkn is {}", activityId, productSkn);
throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_PRODUCT_NOTEXIST_ERROR);
}
CutDownPriceUserRecord record = cutDownPriceUserRecordMapper.selectCutDownPriceUserRecord(userId, activityId, productSkn);
// 组装信息
CutDownPriceActivityProductBo bo = buildCutDownPriceActivityProductBo(activityBo, cutDownPriceProductBo, null, null);
if(record!=null){
// 设置是否已使用
bo.setUseCount(record.getUseCount());
// 设置已砍价记录
bo.setHasJoinNum(record.getHelpCount());
}
return bo;
}
private int selectCutdownPriceOrderRecordCount(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO) {
Integer userId = cutPriceHelpUserRequestBO.getUserId();
int useCount = 0;
// 登陆情况下查询使用记录
if(userId!=null){
CutdownPriceOrderRecord record = new CutdownPriceOrderRecord();
record.setActivityId(cutPriceHelpUserRequestBO.getActivityId());
record.setProductSkn(cutPriceHelpUserRequestBO.getProductSkn());
record.setUserId(userId);
useCount = cutdownPriceOrderRecordMapper.selectCutdownPriceOrderRecordCount(record);
CutDownPriceUserRecord record = cutDownPriceUserRecordMapper.selectCutDownPriceUserRecord(userId, cutPriceHelpUserRequestBO.getActivityId(), cutPriceHelpUserRequestBO.getProductSkn());
if(record!=null){
useCount = record.getUseCount();
}
}
return useCount;
}
... ... @@ -191,30 +213,25 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
}
@Override
public int addCutPriceUseRecord(CutPriceHelpUserRequestBO requestBO) {
CutdownPriceOrderRecord record = new CutdownPriceOrderRecord();
record.setActivityId(requestBO.getActivityId());
record.setOrderCode(requestBO.getOrderCode());
record.setProductSkn(requestBO.getProductSkn());
record.setUserId(requestBO.getUserId());
record.setCreateTime(DateUtils.getCurrentTimeSecond());
record.setUpdateTime(DateUtils.getCurrentTimeSecond());
int result = cutdownPriceOrderRecordMapper.addCutdownPriceOrderRecord(record);
public void addCutPriceUseRecord(CutPriceHelpUserRequestBO requestBO) {
try{
// 扣减可使用次数
int affectRow = cutDownPriceUserRecordMapper.updateDecreaseUseCount(requestBO.getUserId(), requestBO.getActivityId(), requestBO.getProductSkn());
if(affectRow<=0){
logger.warn("updateDecreaseUseCount success!!!,affectRow is:{} ", affectRow);
throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_YOU_HAS_USED_CUTDOWNORDER_ERROR);
}
}catch(DataIntegrityViolationException e){
throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_YOU_HAS_USED_CUTDOWNORDER_ERROR);
}
// 清理缓存
return result;
}
@Override
public int cancelCutPriceUseRecord(CutPriceHelpUserRequestBO requestBO) {
CutdownPriceOrderRecord record = new CutdownPriceOrderRecord();
record.setActivityId(requestBO.getActivityId());
record.setOrderCode(requestBO.getOrderCode());
record.setProductSkn(requestBO.getProductSkn());
record.setUserId(requestBO.getUserId());
record.setCreateTime(DateUtils.getCurrentTimeSecond());
record.setUpdateTime(DateUtils.getCurrentTimeSecond());
int result = cutdownPriceOrderRecordMapper.cancelCutdownPriceOrderRecord(record);
//让缓存过期 1.列表缓存 2.总数的缓存 3.用户限购码缓存
// 回补可使用次数
int result = cutDownPriceUserRecordMapper.updateIncreaseUseCount(requestBO.getUserId(), requestBO.getActivityId(), requestBO.getProductSkn());
// 清理缓存
return result;
}
... ... @@ -248,8 +265,10 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
CutDownPriceProductHelpUser helpUser = convertCutDownPriceProductHelpUser(cutPriceHelpUserRequestBO);
helpUser.setCutPrice(cutPrice);
helpUser.setCreateTime(DateUtils.getCurrentTimeSecond());
// 插入表
// 插入好友帮砍记录
cutPriceUserHelpMapper.addHelpUserInfo(helpUser);
// 修改用户发起砍价记录表中的帮砍次数
cutDownPriceUserRecordMapper.updateCutDownHelpCount(userId, activityId, productSkn);
// 清理缓存,用户帮砍记录列表、商品详情页
clearCache(activityId, productSkn, userId);
return cutPrice;
... ... @@ -364,21 +383,24 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
activityProductBo.setHighPrice(cutDownPriceProductBo.getHighPrice());
activityProductBo.setLowPrice(cutDownPriceProductBo.getLowPrice());
activityProductBo.setJoinNum(cutDownPriceProductBo.getJoinNum());
Map<Integer, ProductBo> productBoMap = Arrays.asList(productBoArray).stream().parallel().collect(Collectors.toMap(ProductBo::getErpProductId, (p) -> p));
ProductBo productBo = productBoMap.get(cutDownPriceProductBo.getProductSkn());
if(productBo!=null){
activityProductBo.setProductName(productBo.getProductName());
activityProductBo.setDefaultImages(productBo.getDefaultImageUrl());
if(ArrayUtils.isNotEmpty(productBoArray)){
Map<Integer, ProductBo> productBoMap = Arrays.asList(productBoArray).stream().parallel().collect(Collectors.toMap(ProductBo::getErpProductId, (p) -> p));
ProductBo productBo = productBoMap.get(cutDownPriceProductBo.getProductSkn());
if(productBo!=null){
activityProductBo.setProductName(productBo.getProductName());
activityProductBo.setDefaultImages(productBo.getDefaultImageUrl());
}
}
BigDecimal hasCutPrice = new BigDecimal(0);
for(CutDownPriceProductHelpUserBo helpUserBo : helpUserBos){
hasCutPrice = hasCutPrice.add(helpUserBo.getCutPrice());
activityProductBo.setUserImgUrl(helpUserBo.getUserImgUrl());// 赋值一次就可以了
if(CollectionUtils.isNotEmpty(helpUserBos)){
BigDecimal hasCutPrice = new BigDecimal(0);
for(CutDownPriceProductHelpUserBo helpUserBo : helpUserBos){
hasCutPrice = hasCutPrice.add(helpUserBo.getCutPrice());
activityProductBo.setUserImgUrl(helpUserBo.getUserImgUrl());// 赋值一次就可以了
}
activityProductBo.setHasCutPrice(hasCutPrice);
activityProductBo.setHasJoinNum(helpUserBos.size());
}
activityProductBo.setHasCutPrice(hasCutPrice);
activityProductBo.setHasJoinNum(helpUserBos.size());
return activityProductBo;
}
... ...