Authored by wangshusheng

Merge branch 'dev6.8.2' into test6.8.2

Conflicts:
	dal/src/main/java/com/yoho/activity/dal/CutDownPriceActivityMapper.java
	service/src/main/resources/META-INF/spring/spring-interceptor-config.xml
... ... @@ -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);
... ...
... ... @@ -12,4 +12,5 @@ public interface CutDownPriceActivityMapper {
List<CutDownPriceActivity> selectCutDownPriceActivityList(@Param("list") List<Integer> activityId);
void updateCutDownPriceActivity(@Param("params") CutDownPriceActivity cutDownPriceActivity);
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);
}
... ...
... ... @@ -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);
}
... ...
... ... @@ -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;
}
... ...
... ... @@ -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;
}
}
... ...
package com.yoho.activity.dal.model;
public class CutdownPriceOrderRecord {
private Integer id;
private Integer userId;
private Integer createTime;
private Integer updateTime;
private Integer activityId;
private Integer productSkn;
private Integer status;
private String orderCode;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
public Integer getActivityId() {
return activityId;
}
public void setActivityId(Integer activityId) {
this.activityId = activityId;
}
public Integer getProductSkn() {
return productSkn;
}
public void setProductSkn(Integer productSkn) {
this.productSkn = productSkn;
}
public Integer getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Integer updateTime) {
this.updateTime = updateTime;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public String getOrderCode() {
return orderCode;
}
public void setOrderCode(String orderCode) {
this.orderCode = orderCode;
}
}
... ...
... ... @@ -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>
... ...
... ... @@ -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 product_skn = #{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 product_skn = #{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 product_skn = #{productSkn,jdbcType=INTEGER}
</update>
</mapper>
\ No newline at end of file
... ...
... ... @@ -4,7 +4,7 @@
<parent>
<groupId>com.yoho</groupId>
<artifactId>parent</artifactId>
<version>1.4.6-SNAPSHOT</version>
<version>1.4.8-SNAPSHOT</version>
</parent>
<groupId>com.yoho.dsf</groupId>
... ...
... ... @@ -4,8 +4,13 @@ import com.yoho.activity.dal.model.CutDownPriceProductHelpUser;
import com.yoho.activity.queue.ApiResponse;
import com.yoho.activity.queue.service.ICutDownPriceService;
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;
... ... @@ -34,14 +39,26 @@ 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
public Integer addCutPriceRecord(@RequestBody CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO) {
logger.info("CutDownProductPriceRest addCutPriceRecord params is{}", cutPriceHelpUserRequestBO);
int num = cutDownPriceService.addCutPriceRecord(cutPriceHelpUserRequestBO);
logger.info("CutDownProductPriceRest addCutPriceRecord success");
logger.info("CutDownProductPriceRest addCutPriceRecord success params is{}", cutPriceHelpUserRequestBO);
return num;
}
... ... @@ -53,7 +70,7 @@ public class CutDownProductPriceRest {
public PageResponseBo<CutDownPriceActivityProductBo> queryMyCutPriceListByPage(@RequestBody CutDownProductQueryRequest request) {
logger.info("CutDownProductPriceRest queryMyCutPriceList params is{}", request);
PageResponseBo<CutDownPriceActivityProductBo> responseBo = cutDownPriceService.queryMyCutPriceListByPage(request);
logger.info("CutDownProductPriceRest queryMyCutPriceList success");
logger.info("CutDownProductPriceRest queryMyCutPriceList success params is{}", request);
return responseBo;
}
... ... @@ -65,19 +82,19 @@ public class CutDownProductPriceRest {
public CutDownPriceActivityProductBo queryCutPriceProductDetail(@RequestBody CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO) {
logger.info("CutDownProductPriceRest queryCutPriceProductDetail params is{}", cutPriceHelpUserRequestBO);
CutDownPriceActivityProductBo productInfo = cutDownPriceService.queryCutProductInfo(cutPriceHelpUserRequestBO);
logger.info("CutDownProductPriceRest queryCutPriceProductDetail success");
logger.info("CutDownProductPriceRest queryCutPriceProductDetail success params is{}", cutPriceHelpUserRequestBO);
return productInfo;
}
/**
* 好友帮忙砍价
* 好友帮忙砍价,并自动发起一个砍价
*/
@RequestMapping("/addCutPriceHelpUserInfo")
@ResponseBody
public BigDecimal addCutPriceHelpUserInfo(@RequestBody CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO) {
logger.info("CutDownProductPriceRest addCutPriceHelpUserInfo params is{}", cutPriceHelpUserRequestBO);
BigDecimal cutPrice = cutDownPriceService.addHelpUserInfo(cutPriceHelpUserRequestBO);
logger.info("CutDownProductPriceRest addCutPriceHelpUserInfo success");
logger.info("CutDownProductPriceRest addCutPriceHelpUserInfo success params is{}", cutPriceHelpUserRequestBO);
return cutPrice;
}
... ... @@ -89,20 +106,72 @@ public class CutDownProductPriceRest {
public List<CutDownPriceProductHelpUserBo> queryCutPriceHelpUserInfos(@RequestBody CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO) {
logger.info("CutDownProductPriceRest queryCutPriceHelpUserInfos params is{}", cutPriceHelpUserRequestBO);
List<CutDownPriceProductHelpUserBo> helpUsers = cutDownPriceService.queryHelpInfo(cutPriceHelpUserRequestBO);
logger.info("CutDownProductPriceRest queryCutPriceHelpUserInfos success");
logger.info("CutDownProductPriceRest queryCutPriceHelpUserInfos success params is{}", cutPriceHelpUserRequestBO);
return helpUsers;
}
/**
* 给订单提供接口:查询砍价信息
* 如果没有砍价成功抛异常、基本信息是否有效、是否已使用过
* 直接调
*/
@RequestMapping("/queryCutPriceProductForOrder")
@ResponseBody
public CutDownPriceActivityProductBo queryCutPriceProductForOrder(@RequestBody CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO) {
logger.info("CutDownProductPriceRest queryCutPriceProductDetail params is{}", cutPriceHelpUserRequestBO);
CutDownPriceActivityProductBo productInfo = cutDownPriceService.queryCutProductInfo(cutPriceHelpUserRequestBO);
logger.info("CutDownProductPriceRest queryCutPriceProductDetail success");
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);
}
logger.info("CutDownProductPriceRest queryCutPriceProductForOrder params is{}", 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.getCanUseCount()==0){
logger.warn(" you have used this cutdown, params is {}", cutPriceHelpUserRequestBO);
throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_YOU_HAS_USED_CUTDOWNORDER_ERROR);
}
logger.info("CutDownProductPriceRest queryCutPriceProductForOrder success, params is {}", cutPriceHelpUserRequestBO);
return productInfo;
}
/**
* 给订单提供接口:砍价下单,每个用户只能使用一次
* 直接调
*/
@RequestMapping("/addCutPriceUseRecord")
@ResponseBody
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()) {
logger.warn("warning param userId or productSkn or activityId is null,req is {}", cutPriceHelpUserRequestBO);
throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_PARAM_ERROR);
}
cutDownPriceService.addCutPriceUseRecord(cutPriceHelpUserRequestBO);
logger.info("CutDownProductPriceRest addCutPriceUseRecord success");
return new VoidResponse(VoidResponse.CODE);
}
/**
* 给订单提供接口:取消砍价下单,修改状态,可以重新下单
* 直接调
*/
@RequestMapping("/cancelCutPriceUseRecord")
@ResponseBody
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);
}
cutDownPriceService.cancelCutPriceUseRecord(cutPriceHelpUserRequestBO);
logger.info("CutDownProductPriceRest cancelCutPriceUseRecord success");
return new VoidResponse(VoidResponse.CODE);
}
}
... ...
... ... @@ -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;
... ... @@ -17,9 +18,17 @@ public interface ICutDownPriceService {
CutDownPriceActivityProductBo queryCutProductInfo(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO);
CutDownPriceActivityProductBo queryCutProductInfoForOrder(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO);
BigDecimal addHelpUserInfo(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO);
int addCutPriceRecord(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO);
PageResponseBo<CutDownPriceActivityProductBo> queryMyCutPriceListByPage(CutDownProductQueryRequest request);
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);
... ...
... ... @@ -24,12 +24,16 @@ 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 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;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
... ... @@ -41,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
... ... @@ -61,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();
... ... @@ -91,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;
}
... ... @@ -105,6 +131,7 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
public CutDownPriceActivityProductBo queryCutProductInfo(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO) {
Integer activityId = cutPriceHelpUserRequestBO.getActivityId();
Integer productSkn = cutPriceHelpUserRequestBO.getProductSkn();
Integer userId = cutPriceHelpUserRequestBO.getUserId();
// 查询活动信息
CutDownPriceActivityBo activityBo = cutDownActivityService.queryActivityInfo(activityId);
checkValidActivity(activityBo, activityId);
... ... @@ -121,7 +148,48 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
request.setParams(Lists.newArrayList(productSkn));
ProductBo[] productBoArray = serviceCaller.call("product.batchQueryNamesAndImageBySkns", request, ProductBo[].class);
// 组装信息
return buildCutDownPriceActivityProductBo(activityBo, cutDownPriceProductBo, helpUserBos, productBoArray);
CutDownPriceActivityProductBo bo = buildCutDownPriceActivityProductBo(activityBo, cutDownPriceProductBo, helpUserBos, productBoArray);
bo.setCanUseCount(selectCutdownPriceOrderRecordCount(cutPriceHelpUserRequestBO));
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.setCanUseCount(record.getUseCount());
// 设置已砍价记录
bo.setHasJoinNum(record.getHelpCount());
}
return bo;
}
private int selectCutdownPriceOrderRecordCount(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO) {
Integer userId = cutPriceHelpUserRequestBO.getUserId();
int useCount = 0;
// 登陆情况下查询使用记录
if(userId!=null){
CutDownPriceUserRecord record = cutDownPriceUserRecordMapper.selectCutDownPriceUserRecord(userId, cutPriceHelpUserRequestBO.getActivityId(), cutPriceHelpUserRequestBO.getProductSkn());
if(record!=null){
useCount = record.getUseCount();
}
}
return useCount;
}
@Override
... ... @@ -157,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));
... ... @@ -170,11 +238,34 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
}
@Override
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);
}
// 清理缓存
}
@Override
public int cancelCutPriceUseRecord(CutPriceHelpUserRequestBO requestBO) {
// 回补可使用次数
int result = cutDownPriceUserRecordMapper.updateIncreaseUseCount(requestBO.getUserId(), requestBO.getActivityId(), requestBO.getProductSkn());
// 清理缓存
return result;
}
@Override
public BigDecimal addHelpUserInfo(CutPriceHelpUserRequestBO cutPriceHelpUserRequestBO) {
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);
... ... @@ -199,8 +290,20 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
CutDownPriceProductHelpUser helpUser = convertCutDownPriceProductHelpUser(cutPriceHelpUserRequestBO);
helpUser.setCutPrice(cutPrice);
helpUser.setCreateTime(DateUtils.getCurrentTimeSecond());
// 插入表
// 插入好友帮砍记录
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;
... ... @@ -231,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;
}
... ... @@ -259,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<>();
... ... @@ -287,20 +404,49 @@ 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){
if(null!=helpUserBo.getHelpUserId() && SYSTEM_HELP_ID!=helpUserBo.getHelpUserId()){
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,
... ... @@ -315,21 +461,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;
}
... ... @@ -384,9 +533,11 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
// 清理缓存,用户帮砍记录列表、商品详情页
private void clearCache(Integer activityId, Integer productSkn, Integer userId) {
// 取缓存
// 清理用户帮砍记录列表
String redisKeySuffix = userId + ":" + activityId + ":" + productSkn;
redisValueCache.delete(CacheKeyEnum.CUTDOWN_PRICE_HELP_USERLIST_INFO, redisKeySuffix);
// 清理我的砍价列表
redisHashCache.delete(CacheKeyEnum.CUTDOWN_PRICE_MYPRODUCTLIST_INFO.getCacheKey(), userId);
}
... ...
... ... @@ -44,6 +44,9 @@
<value>/addCutPriceHelpUserInfo</value>
<value>/queryCutPriceHelpUserInfos</value>
<value>/queryCutPriceProductForOrder</value>
<value>/addCutPriceUseRecord</value>
<value>/cancelCutPriceUseRecord</value>
<value>/queryEffectCutPriceActivity</value>
</list>
</property>
<property name="excludeMethods">
... ...