Authored by wangshusheng

砍价

@@ -16,4 +16,10 @@ public interface CutDownPriceUserRecordMapper { @@ -16,4 +16,10 @@ public interface CutDownPriceUserRecordMapper {
16 16
17 CutDownPriceUserRecord selectCutDownPriceUserRecord(@Param("userId") Integer userId, @Param("activityId") Integer activityId, @Param("productSkn") Integer productSkn); 17 CutDownPriceUserRecord selectCutDownPriceUserRecord(@Param("userId") Integer userId, @Param("activityId") Integer activityId, @Param("productSkn") Integer productSkn);
18 18
  19 + int updateCutDownHelpCount(@Param("userId") Integer userId, @Param("activityId") Integer activityId, @Param("productSkn") Integer productSkn);
  20 +
  21 + int updateDecreaseUseCount(@Param("userId") Integer userId, @Param("activityId") Integer activityId, @Param("productSkn") Integer productSkn);
  22 +
  23 + int updateIncreaseUseCount(@Param("userId") Integer userId, @Param("activityId") Integer activityId, @Param("productSkn") Integer productSkn);
  24 +
19 } 25 }
1 -package com.yoho.activity.dal;  
2 -  
3 -import com.yoho.activity.dal.model.CutdownPriceOrderRecord;  
4 -import org.apache.ibatis.annotations.Param;  
5 -  
6 -import java.util.List;  
7 -  
8 -public interface CutdownPriceOrderRecordMapper {  
9 -  
10 - int addCutdownPriceOrderRecord(CutdownPriceOrderRecord record);  
11 -  
12 - int selectCutdownPriceOrderRecordCount(CutdownPriceOrderRecord req);  
13 -  
14 - List<CutdownPriceOrderRecord> selectCutdownPriceOrderRecord(@Param("uid") Integer uid);  
15 -  
16 - int cancelCutdownPriceOrderRecord(CutdownPriceOrderRecord req);  
17 -  
18 -}  
@@ -6,8 +6,11 @@ public class CutDownPriceUserRecord { @@ -6,8 +6,11 @@ public class CutDownPriceUserRecord {
6 private Integer id; 6 private Integer id;
7 private Integer userId; 7 private Integer userId;
8 private Integer createTime; 8 private Integer createTime;
  9 + private Integer updateTime;
9 private Integer activityId; 10 private Integer activityId;
10 private Integer productSkn; 11 private Integer productSkn;
  12 + private Integer helpCount;
  13 + private Integer useCount;
11 14
12 public Integer getId() { 15 public Integer getId() {
13 return id; 16 return id;
@@ -49,4 +52,27 @@ public class CutDownPriceUserRecord { @@ -49,4 +52,27 @@ public class CutDownPriceUserRecord {
49 this.productSkn = productSkn; 52 this.productSkn = productSkn;
50 } 53 }
51 54
  55 + public Integer getUpdateTime() {
  56 + return updateTime;
  57 + }
  58 +
  59 + public void setUpdateTime(Integer updateTime) {
  60 + this.updateTime = updateTime;
  61 + }
  62 +
  63 + public Integer getHelpCount() {
  64 + return helpCount;
  65 + }
  66 +
  67 + public void setHelpCount(Integer helpCount) {
  68 + this.helpCount = helpCount;
  69 + }
  70 +
  71 + public Integer getUseCount() {
  72 + return useCount;
  73 + }
  74 +
  75 + public void setUseCount(Integer useCount) {
  76 + this.useCount = useCount;
  77 + }
52 } 78 }
@@ -6,10 +6,13 @@ @@ -6,10 +6,13 @@
6 <result column="user_id" property="userId" jdbcType="INTEGER" /> 6 <result column="user_id" property="userId" jdbcType="INTEGER" />
7 <result column="activity_id" property="activityId" jdbcType="INTEGER" /> 7 <result column="activity_id" property="activityId" jdbcType="INTEGER" />
8 <result column="product_skn" property="productSkn" jdbcType="INTEGER" /> 8 <result column="product_skn" property="productSkn" jdbcType="INTEGER" />
  9 + <result column="help_count" property="helpCount" jdbcType="INTEGER" />
  10 + <result column="use_count" property="useCount" jdbcType="INTEGER" />
9 <result column="create_time" property="createTime" jdbcType="INTEGER" /> 11 <result column="create_time" property="createTime" jdbcType="INTEGER" />
  12 + <result column="update_time" property="updateTime" jdbcType="INTEGER" />
10 </resultMap> 13 </resultMap>
11 <sql id="Base_Column_List" > 14 <sql id="Base_Column_List" >
12 - id, user_id, activity_id, product_skn, create_time 15 + id, user_id, activity_id, product_skn, help_count, use_count, create_time, update_time
13 </sql> 16 </sql>
14 17
15 <insert id="addCutDownUserRecord" parameterType="com.yoho.activity.dal.model.CutDownPriceUserRecord"> 18 <insert id="addCutDownUserRecord" parameterType="com.yoho.activity.dal.model.CutDownPriceUserRecord">
@@ -44,4 +47,27 @@ @@ -44,4 +47,27 @@
44 and product_skn = #{productSkn,jdbcType=INTEGER} 47 and product_skn = #{productSkn,jdbcType=INTEGER}
45 </select> 48 </select>
46 49
  50 + <update id="updateCutDownHelpCount" >
  51 + update cutdown_price_user_record
  52 + set help_count = help_count+1, update_time= UNIX_TIMESTAMP()
  53 + where user_id = #{userId,jdbcType=INTEGER}
  54 + and activity_id = #{activityId,jdbcType=INTEGER}
  55 + and productSkn = #{productSkn,jdbcType=INTEGER}
  56 + </update>
  57 +
  58 + <update id="updateDecreaseUseCount" >
  59 + update cutdown_price_user_record
  60 + set use_count = use_count-1, update_time= UNIX_TIMESTAMP()
  61 + where user_id = #{userId,jdbcType=INTEGER}
  62 + and activity_id = #{activityId,jdbcType=INTEGER}
  63 + and productSkn = #{productSkn,jdbcType=INTEGER}
  64 + </update>
  65 +
  66 + <update id="updateIncreaseUseCount" >
  67 + update cutdown_price_user_record
  68 + set use_count = use_count+1, update_time= UNIX_TIMESTAMP()
  69 + where user_id = #{userId,jdbcType=INTEGER}
  70 + and activity_id = #{activityId,jdbcType=INTEGER}
  71 + and productSkn = #{productSkn,jdbcType=INTEGER}
  72 + </update>
47 </mapper> 73 </mapper>
1 -<?xml version="1.0" encoding="UTF-8" ?>  
2 -<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >  
3 -<mapper namespace="com.yoho.activity.dal.CutdownPriceOrderRecordMapper" >  
4 - <resultMap id="BaseResultMap" type="com.yoho.activity.dal.model.CutdownPriceOrderRecord" >  
5 - <id column="id" property="id" jdbcType="INTEGER" />  
6 - <result column="user_id" property="userId" jdbcType="INTEGER" />  
7 - <result column="activity_id" property="activityId" jdbcType="INTEGER" />  
8 - <result column="productSkn" property="productSkn" jdbcType="INTEGER" />  
9 - <result column="order_code" property="orderCode" jdbcType="VARCHAR" />  
10 - <result column="create_time" property="createTime" jdbcType="INTEGER" />  
11 - <result column="update_time" property="updateTime" jdbcType="INTEGER" />  
12 - <result column="status" property="status" jdbcType="INTEGER" />  
13 - </resultMap>  
14 - <sql id="Base_Column_List" >  
15 - id, user_id, activity_id, productSkn, order_code, create_time, update_time, status  
16 - </sql>  
17 - <insert id="addCutdownPriceOrderRecord" parameterType="com.yoho.activity.dal.model.CutdownPriceOrderRecord" >  
18 - insert into cutdown_price_order_record (user_id, activity_id, productSkn, order_code, create_time, update_time) values  
19 - (#{userId,jdbcType=INTEGER}, #{activityId,jdbcType=INTEGER}, #{productSkn,jdbcType=INTEGER}, #{orderCode,jdbcType=VARCHAR}, #{createTime,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER})  
20 - </insert>  
21 -  
22 - <select id="selectCutdownPriceOrderRecordCount" resultType="java.lang.Integer" parameterType="com.yoho.activity.dal.model.CutdownPriceOrderRecord" >  
23 - select  
24 - count(1)  
25 - from cutdown_price_order_record p  
26 - where 1=1 and status = 0  
27 - and p.user_id = #{userId,jdbcType=INTEGER}  
28 - and p.activity_id=#{activityId,jdbcType=INTEGER}  
29 - and p.productSkn=#{productSkn,jdbcType=INTEGER}  
30 - </select>  
31 -  
32 - <select id="selectCutdownPriceOrderRecord" resultMap="BaseResultMap" parameterType="java.lang.Integer" >  
33 - select  
34 - <include refid="Base_Column_List" />  
35 - from cutdown_price_order_record p  
36 - where 1=1 and p.status = 0  
37 - and p.user_id = #{userId,jdbcType=INTEGER}  
38 - </select>  
39 -  
40 - <update id="cancelCutdownPriceOrderRecord" parameterType="com.yoho.activity.dal.model.CutdownPriceOrderRecord">  
41 - update cutdown_price_order_record  
42 - set status = 1, update_time= #{updateTime,jdbcType=INTEGER}  
43 - where user_id = #{userId,jdbcType=INTEGER}  
44 - and order_code = #{orderCode,jdbcType=VARCHAR}  
45 - and activity_id = #{activityId,jdbcType=INTEGER}  
46 - and productSkn = #{productSkn,jdbcType=INTEGER}  
47 - </update>  
48 -  
49 -</mapper>  
@@ -8,6 +8,7 @@ import com.yoho.error.ServiceError; @@ -8,6 +8,7 @@ import com.yoho.error.ServiceError;
8 import com.yoho.error.exception.ServiceException; 8 import com.yoho.error.exception.ServiceException;
9 import com.yoho.product.model.CollageProductBo; 9 import com.yoho.product.model.CollageProductBo;
10 import com.yoho.product.response.PageResponseBo; 10 import com.yoho.product.response.PageResponseBo;
  11 +import com.yoho.product.response.VoidResponse;
11 import com.yoho.service.model.activity.CutDownPriceActivityProductBo; 12 import com.yoho.service.model.activity.CutDownPriceActivityProductBo;
12 import com.yoho.service.model.activity.CutDownPriceProductHelpUserBo; 13 import com.yoho.service.model.activity.CutDownPriceProductHelpUserBo;
13 import com.yoho.service.model.activity.CutDownProductQueryRequest; 14 import com.yoho.service.model.activity.CutDownProductQueryRequest;
@@ -109,14 +110,14 @@ public class CutDownProductPriceRest { @@ -109,14 +110,14 @@ public class CutDownProductPriceRest {
109 throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_PARAM_ERROR); 110 throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_PARAM_ERROR);
110 } 111 }
111 logger.info("CutDownProductPriceRest queryCutPriceProductForOrder params is{}", cutPriceHelpUserRequestBO); 112 logger.info("CutDownProductPriceRest queryCutPriceProductForOrder params is{}", cutPriceHelpUserRequestBO);
112 - CutDownPriceActivityProductBo productInfo = cutDownPriceService.queryCutProductInfo(cutPriceHelpUserRequestBO); 113 + CutDownPriceActivityProductBo productInfo = cutDownPriceService.queryCutProductInfoForOrder(cutPriceHelpUserRequestBO);
113 // 校验是否已经砍价成功 114 // 校验是否已经砍价成功
114 if(productInfo.getHasJoinNum()<productInfo.getJoinNum()){ 115 if(productInfo.getHasJoinNum()<productInfo.getJoinNum()){
115 logger.warn(" you have not cutdown success, params is {}", cutPriceHelpUserRequestBO); 116 logger.warn(" you have not cutdown success, params is {}", cutPriceHelpUserRequestBO);
116 throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_YOU_HASNOT_CUTDOWN_SUCCESS_ERROR); 117 throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_YOU_HASNOT_CUTDOWN_SUCCESS_ERROR);
117 } 118 }
118 // 校验是否已经使用过 119 // 校验是否已经使用过
119 - if(productInfo.getUseCount()>0){ 120 + if(productInfo.getUseCount()==0){
120 logger.warn(" you have used this cutdown, params is {}", cutPriceHelpUserRequestBO); 121 logger.warn(" you have used this cutdown, params is {}", cutPriceHelpUserRequestBO);
121 throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_YOU_HAS_USED_CUTDOWNORDER_ERROR); 122 throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_YOU_HAS_USED_CUTDOWNORDER_ERROR);
122 } 123 }
@@ -130,7 +131,7 @@ public class CutDownProductPriceRest { @@ -130,7 +131,7 @@ public class CutDownProductPriceRest {
130 */ 131 */
131 @RequestMapping("/addCutPriceUseRecord") 132 @RequestMapping("/addCutPriceUseRecord")
132 @ResponseBody 133 @ResponseBody
133 - public int addCutPriceUseRecord(@RequestBody CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO) { 134 + public VoidResponse addCutPriceUseRecord(@RequestBody CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO) {
134 logger.info("CutDownProductPriceRest addCutPriceUseRecord params is{}", cutPriceHelpUserRequestBO); 135 logger.info("CutDownProductPriceRest addCutPriceUseRecord params is{}", cutPriceHelpUserRequestBO);
135 if (null==cutPriceHelpUserRequestBO || null==cutPriceHelpUserRequestBO.getUserId() 136 if (null==cutPriceHelpUserRequestBO || null==cutPriceHelpUserRequestBO.getUserId()
136 || null==cutPriceHelpUserRequestBO.getProductSkn() || null==cutPriceHelpUserRequestBO.getActivityId()) { 137 || null==cutPriceHelpUserRequestBO.getProductSkn() || null==cutPriceHelpUserRequestBO.getActivityId()) {
@@ -138,9 +139,9 @@ public class CutDownProductPriceRest { @@ -138,9 +139,9 @@ public class CutDownProductPriceRest {
138 throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_PARAM_ERROR); 139 throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_PARAM_ERROR);
139 } 140 }
140 141
141 - int result = cutDownPriceService.addCutPriceUseRecord(cutPriceHelpUserRequestBO); 142 + cutDownPriceService.addCutPriceUseRecord(cutPriceHelpUserRequestBO);
142 logger.info("CutDownProductPriceRest addCutPriceUseRecord success"); 143 logger.info("CutDownProductPriceRest addCutPriceUseRecord success");
143 - return result; 144 + return new VoidResponse(VoidResponse.CODE);
144 } 145 }
145 /** 146 /**
146 * 给订单提供接口:取消砍价下单,修改状态,可以重新下单 147 * 给订单提供接口:取消砍价下单,修改状态,可以重新下单
@@ -148,15 +149,15 @@ public class CutDownProductPriceRest { @@ -148,15 +149,15 @@ public class CutDownProductPriceRest {
148 */ 149 */
149 @RequestMapping("/cancelCutPriceUseRecord") 150 @RequestMapping("/cancelCutPriceUseRecord")
150 @ResponseBody 151 @ResponseBody
151 - public int cancelCutPriceUseRecord(@RequestBody CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO) { 152 + public VoidResponse cancelCutPriceUseRecord(@RequestBody CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO) {
152 logger.info("CutDownProductPriceRest cancelCutPriceUseRecord params is{}", cutPriceHelpUserRequestBO); 153 logger.info("CutDownProductPriceRest cancelCutPriceUseRecord params is{}", cutPriceHelpUserRequestBO);
153 if (null==cutPriceHelpUserRequestBO || null==cutPriceHelpUserRequestBO.getUserId() 154 if (null==cutPriceHelpUserRequestBO || null==cutPriceHelpUserRequestBO.getUserId()
154 || null==cutPriceHelpUserRequestBO.getProductSkn() || null==cutPriceHelpUserRequestBO.getActivityId()) { 155 || null==cutPriceHelpUserRequestBO.getProductSkn() || null==cutPriceHelpUserRequestBO.getActivityId()) {
155 logger.warn("warning param userId or productSkn or activityId is null,req is {}", cutPriceHelpUserRequestBO); 156 logger.warn("warning param userId or productSkn or activityId is null,req is {}", cutPriceHelpUserRequestBO);
156 throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_PARAM_ERROR); 157 throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_PARAM_ERROR);
157 } 158 }
158 - int result = cutDownPriceService.cancelCutPriceUseRecord(cutPriceHelpUserRequestBO); 159 + cutDownPriceService.cancelCutPriceUseRecord(cutPriceHelpUserRequestBO);
159 logger.info("CutDownProductPriceRest cancelCutPriceUseRecord success"); 160 logger.info("CutDownProductPriceRest cancelCutPriceUseRecord success");
160 - return result; 161 + return new VoidResponse(VoidResponse.CODE);
161 } 162 }
162 } 163 }
@@ -17,13 +17,15 @@ public interface ICutDownPriceService { @@ -17,13 +17,15 @@ public interface ICutDownPriceService {
17 17
18 CutDownPriceActivityProductBo queryCutProductInfo(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO); 18 CutDownPriceActivityProductBo queryCutProductInfo(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO);
19 19
  20 + CutDownPriceActivityProductBo queryCutProductInfoForOrder(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO);
  21 +
20 BigDecimal addHelpUserInfo(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO); 22 BigDecimal addHelpUserInfo(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO);
21 23
22 int addCutPriceRecord(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO); 24 int addCutPriceRecord(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO);
23 25
24 PageResponseBo<CutDownPriceActivityProductBo> queryMyCutPriceListByPage(CutDownProductQueryRequest request); 26 PageResponseBo<CutDownPriceActivityProductBo> queryMyCutPriceListByPage(CutDownProductQueryRequest request);
25 27
26 - int addCutPriceUseRecord(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO); 28 + void addCutPriceUseRecord(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO);
27 29
28 int cancelCutPriceUseRecord(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO); 30 int cancelCutPriceUseRecord(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO);
29 } 31 }
@@ -8,10 +8,8 @@ import com.yoho.activity.common.redis.RedisValueCache; @@ -8,10 +8,8 @@ import com.yoho.activity.common.redis.RedisValueCache;
8 import com.yoho.activity.common.utils.DateUtils; 8 import com.yoho.activity.common.utils.DateUtils;
9 import com.yoho.activity.dal.CutDownPriceUserHelpMapper; 9 import com.yoho.activity.dal.CutDownPriceUserHelpMapper;
10 import com.yoho.activity.dal.CutDownPriceUserRecordMapper; 10 import com.yoho.activity.dal.CutDownPriceUserRecordMapper;
11 -import com.yoho.activity.dal.CutdownPriceOrderRecordMapper;  
12 import com.yoho.activity.dal.model.CutDownPriceProductHelpUser; 11 import com.yoho.activity.dal.model.CutDownPriceProductHelpUser;
13 import com.yoho.activity.dal.model.CutDownPriceUserRecord; 12 import com.yoho.activity.dal.model.CutDownPriceUserRecord;
14 -import com.yoho.activity.dal.model.CutdownPriceOrderRecord;  
15 import com.yoho.activity.queue.service.ICutDownPriceActivityService; 13 import com.yoho.activity.queue.service.ICutDownPriceActivityService;
16 import com.yoho.activity.queue.service.ICutDownPriceProductService; 14 import com.yoho.activity.queue.service.ICutDownPriceProductService;
17 import com.yoho.activity.queue.service.ICutDownPriceService; 15 import com.yoho.activity.queue.service.ICutDownPriceService;
@@ -26,12 +24,13 @@ import com.yoho.product.request.BatchBaseRequest; @@ -26,12 +24,13 @@ import com.yoho.product.request.BatchBaseRequest;
26 import com.yoho.product.response.PageResponseBo; 24 import com.yoho.product.response.PageResponseBo;
27 import com.yoho.service.model.activity.*; 25 import com.yoho.service.model.activity.*;
28 import com.yoho.service.model.activity.drawline.request.CutPriceHelpUserRequestBO; 26 import com.yoho.service.model.activity.drawline.request.CutPriceHelpUserRequestBO;
29 -import com.yoho.service.model.activity.drawline.request.LimitProductHelpUserRequestBO;  
30 import com.yoho.service.model.activity.drawline.response.UserBaseRspBO; 27 import com.yoho.service.model.activity.drawline.response.UserBaseRspBO;
31 import org.apache.commons.collections.CollectionUtils; 28 import org.apache.commons.collections.CollectionUtils;
  29 +import org.apache.commons.lang3.ArrayUtils;
32 import org.slf4j.Logger; 30 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory; 31 import org.slf4j.LoggerFactory;
34 import org.springframework.beans.factory.annotation.Autowired; 32 import org.springframework.beans.factory.annotation.Autowired;
  33 +import org.springframework.dao.DataIntegrityViolationException;
35 import org.springframework.stereotype.Service; 34 import org.springframework.stereotype.Service;
36 35
37 import javax.annotation.Resource; 36 import javax.annotation.Resource;
@@ -52,8 +51,6 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { @@ -52,8 +51,6 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
52 @Autowired 51 @Autowired
53 private CutDownPriceUserRecordMapper cutDownPriceUserRecordMapper; 52 private CutDownPriceUserRecordMapper cutDownPriceUserRecordMapper;
54 @Autowired 53 @Autowired
55 - private CutdownPriceOrderRecordMapper cutdownPriceOrderRecordMapper;  
56 - @Autowired  
57 private ICutDownPriceActivityService cutDownActivityService; 54 private ICutDownPriceActivityService cutDownActivityService;
58 @Autowired 55 @Autowired
59 private ICutDownPriceProductService cutDownPriceProductService; 56 private ICutDownPriceProductService cutDownPriceProductService;
@@ -131,16 +128,41 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { @@ -131,16 +128,41 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
131 return bo; 128 return bo;
132 } 129 }
133 130
  131 + @Override
  132 + public CutDownPriceActivityProductBo queryCutProductInfoForOrder(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO) {
  133 + Integer activityId = cutPriceHelpUserRequestBO.getActivityId();
  134 + Integer productSkn = cutPriceHelpUserRequestBO.getProductSkn();
  135 + Integer userId = cutPriceHelpUserRequestBO.getUserId();
  136 + // 查询活动信息
  137 + CutDownPriceActivityBo activityBo = cutDownActivityService.queryActivityInfo(activityId);
  138 + checkValidActivity(activityBo, activityId);
  139 + // 查询商品配置信息
  140 + CutDownPriceProductBo cutDownPriceProductBo = cutDownPriceProductService.queryCutDownPriceProductBo(activityId, productSkn);
  141 + if(cutDownPriceProductBo==null){
  142 + logger.warn(" the cutdown product not exist, activityId is {}, productSkn is {}", activityId, productSkn);
  143 + throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_PRODUCT_NOTEXIST_ERROR);
  144 + }
  145 + CutDownPriceUserRecord record = cutDownPriceUserRecordMapper.selectCutDownPriceUserRecord(userId, activityId, productSkn);
  146 + // 组装信息
  147 + CutDownPriceActivityProductBo bo = buildCutDownPriceActivityProductBo(activityBo, cutDownPriceProductBo, null, null);
  148 + if(record!=null){
  149 + // 设置是否已使用
  150 + bo.setUseCount(record.getUseCount());
  151 + // 设置已砍价记录
  152 + bo.setHasJoinNum(record.getHelpCount());
  153 + }
  154 + return bo;
  155 + }
  156 +
134 private int selectCutdownPriceOrderRecordCount(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO) { 157 private int selectCutdownPriceOrderRecordCount(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO) {
135 Integer userId = cutPriceHelpUserRequestBO.getUserId(); 158 Integer userId = cutPriceHelpUserRequestBO.getUserId();
136 int useCount = 0; 159 int useCount = 0;
137 // 登陆情况下查询使用记录 160 // 登陆情况下查询使用记录
138 if(userId!=null){ 161 if(userId!=null){
139 - CutdownPriceOrderRecord record = new CutdownPriceOrderRecord();  
140 - record.setActivityId(cutPriceHelpUserRequestBO.getActivityId());  
141 - record.setProductSkn(cutPriceHelpUserRequestBO.getProductSkn());  
142 - record.setUserId(userId);  
143 - useCount = cutdownPriceOrderRecordMapper.selectCutdownPriceOrderRecordCount(record); 162 + CutDownPriceUserRecord record = cutDownPriceUserRecordMapper.selectCutDownPriceUserRecord(userId, cutPriceHelpUserRequestBO.getActivityId(), cutPriceHelpUserRequestBO.getProductSkn());
  163 + if(record!=null){
  164 + useCount = record.getUseCount();
  165 + }
144 } 166 }
145 return useCount; 167 return useCount;
146 } 168 }
@@ -191,30 +213,25 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { @@ -191,30 +213,25 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
191 } 213 }
192 214
193 @Override 215 @Override
194 - public int addCutPriceUseRecord(CutPriceHelpUserRequestBO requestBO) {  
195 - CutdownPriceOrderRecord record = new CutdownPriceOrderRecord();  
196 - record.setActivityId(requestBO.getActivityId());  
197 - record.setOrderCode(requestBO.getOrderCode());  
198 - record.setProductSkn(requestBO.getProductSkn());  
199 - record.setUserId(requestBO.getUserId());  
200 - record.setCreateTime(DateUtils.getCurrentTimeSecond());  
201 - record.setUpdateTime(DateUtils.getCurrentTimeSecond());  
202 - int result = cutdownPriceOrderRecordMapper.addCutdownPriceOrderRecord(record); 216 + public void addCutPriceUseRecord(CutPriceHelpUserRequestBO requestBO) {
  217 + try{
  218 + // 扣减可使用次数
  219 + int affectRow = cutDownPriceUserRecordMapper.updateDecreaseUseCount(requestBO.getUserId(), requestBO.getActivityId(), requestBO.getProductSkn());
  220 + if(affectRow<=0){
  221 + logger.warn("updateDecreaseUseCount success!!!,affectRow is:{} ", affectRow);
  222 + throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_YOU_HAS_USED_CUTDOWNORDER_ERROR);
  223 + }
  224 + }catch(DataIntegrityViolationException e){
  225 + throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_YOU_HAS_USED_CUTDOWNORDER_ERROR);
  226 + }
203 // 清理缓存 227 // 清理缓存
204 - return result;  
205 } 228 }
206 229
207 @Override 230 @Override
208 public int cancelCutPriceUseRecord(CutPriceHelpUserRequestBO requestBO) { 231 public int cancelCutPriceUseRecord(CutPriceHelpUserRequestBO requestBO) {
209 - CutdownPriceOrderRecord record = new CutdownPriceOrderRecord();  
210 - record.setActivityId(requestBO.getActivityId());  
211 - record.setOrderCode(requestBO.getOrderCode());  
212 - record.setProductSkn(requestBO.getProductSkn());  
213 - record.setUserId(requestBO.getUserId());  
214 - record.setCreateTime(DateUtils.getCurrentTimeSecond());  
215 - record.setUpdateTime(DateUtils.getCurrentTimeSecond());  
216 - int result = cutdownPriceOrderRecordMapper.cancelCutdownPriceOrderRecord(record);  
217 - //让缓存过期 1.列表缓存 2.总数的缓存 3.用户限购码缓存 232 + // 回补可使用次数
  233 + int result = cutDownPriceUserRecordMapper.updateIncreaseUseCount(requestBO.getUserId(), requestBO.getActivityId(), requestBO.getProductSkn());
  234 + // 清理缓存
218 return result; 235 return result;
219 } 236 }
220 237
@@ -248,8 +265,10 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { @@ -248,8 +265,10 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
248 CutDownPriceProductHelpUser helpUser = convertCutDownPriceProductHelpUser(cutPriceHelpUserRequestBO); 265 CutDownPriceProductHelpUser helpUser = convertCutDownPriceProductHelpUser(cutPriceHelpUserRequestBO);
249 helpUser.setCutPrice(cutPrice); 266 helpUser.setCutPrice(cutPrice);
250 helpUser.setCreateTime(DateUtils.getCurrentTimeSecond()); 267 helpUser.setCreateTime(DateUtils.getCurrentTimeSecond());
251 - // 插入表 268 + // 插入好友帮砍记录
252 cutPriceUserHelpMapper.addHelpUserInfo(helpUser); 269 cutPriceUserHelpMapper.addHelpUserInfo(helpUser);
  270 + // 修改用户发起砍价记录表中的帮砍次数
  271 + cutDownPriceUserRecordMapper.updateCutDownHelpCount(userId, activityId, productSkn);
253 // 清理缓存,用户帮砍记录列表、商品详情页 272 // 清理缓存,用户帮砍记录列表、商品详情页
254 clearCache(activityId, productSkn, userId); 273 clearCache(activityId, productSkn, userId);
255 return cutPrice; 274 return cutPrice;
@@ -364,14 +383,16 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { @@ -364,14 +383,16 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
364 activityProductBo.setHighPrice(cutDownPriceProductBo.getHighPrice()); 383 activityProductBo.setHighPrice(cutDownPriceProductBo.getHighPrice());
365 activityProductBo.setLowPrice(cutDownPriceProductBo.getLowPrice()); 384 activityProductBo.setLowPrice(cutDownPriceProductBo.getLowPrice());
366 activityProductBo.setJoinNum(cutDownPriceProductBo.getJoinNum()); 385 activityProductBo.setJoinNum(cutDownPriceProductBo.getJoinNum());
  386 + if(ArrayUtils.isNotEmpty(productBoArray)){
367 Map<Integer, ProductBo> productBoMap = Arrays.asList(productBoArray).stream().parallel().collect(Collectors.toMap(ProductBo::getErpProductId, (p) -> p)); 387 Map<Integer, ProductBo> productBoMap = Arrays.asList(productBoArray).stream().parallel().collect(Collectors.toMap(ProductBo::getErpProductId, (p) -> p));
368 -  
369 ProductBo productBo = productBoMap.get(cutDownPriceProductBo.getProductSkn()); 388 ProductBo productBo = productBoMap.get(cutDownPriceProductBo.getProductSkn());
370 if(productBo!=null){ 389 if(productBo!=null){
371 activityProductBo.setProductName(productBo.getProductName()); 390 activityProductBo.setProductName(productBo.getProductName());
372 activityProductBo.setDefaultImages(productBo.getDefaultImageUrl()); 391 activityProductBo.setDefaultImages(productBo.getDefaultImageUrl());
373 } 392 }
  393 + }
374 394
  395 + if(CollectionUtils.isNotEmpty(helpUserBos)){
375 BigDecimal hasCutPrice = new BigDecimal(0); 396 BigDecimal hasCutPrice = new BigDecimal(0);
376 for(CutDownPriceProductHelpUserBo helpUserBo : helpUserBos){ 397 for(CutDownPriceProductHelpUserBo helpUserBo : helpUserBos){
377 hasCutPrice = hasCutPrice.add(helpUserBo.getCutPrice()); 398 hasCutPrice = hasCutPrice.add(helpUserBo.getCutPrice());
@@ -379,6 +400,7 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { @@ -379,6 +400,7 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
379 } 400 }
380 activityProductBo.setHasCutPrice(hasCutPrice); 401 activityProductBo.setHasCutPrice(hasCutPrice);
381 activityProductBo.setHasJoinNum(helpUserBos.size()); 402 activityProductBo.setHasJoinNum(helpUserBos.size());
  403 + }
382 return activityProductBo; 404 return activityProductBo;
383 } 405 }
384 406