Browse Source

fix 商品详情

release_toaliyun_real
winter 4 years ago
parent
commit
791901377e
11 changed files with 282 additions and 0 deletions
  1. +183
    -0
      mallinkCApi/src/main/java/com/iformall/controller/WxCouponController.java
  2. +6
    -0
      mallinkService/src/main/java/com/iformall/domain/po/WxCoupon.java
  3. +3
    -0
      mallinkService/src/main/java/com/iformall/mapper/WxCouponChannelMapper.java
  4. +2
    -0
      mallinkService/src/main/java/com/iformall/mapper/WxCouponMapper.java
  5. +1
    -0
      mallinkService/src/main/java/com/iformall/service/WxCouponChannelService.java
  6. +4
    -0
      mallinkService/src/main/java/com/iformall/service/WxCouponService.java
  7. +5
    -0
      mallinkService/src/main/java/com/iformall/service/impl/WxCouponChannelServiceImpl.java
  8. +10
    -0
      mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java
  9. +60
    -0
      mallinkService/src/main/java/com/iformall/service/util/CouponCacheUtils.java
  10. +4
    -0
      mallinkService/src/main/resources/mapper/WxCouponChannelMapper.xml
  11. +4
    -0
      mallinkService/src/main/resources/mapper/WxCouponMapper.xml

+ 183
- 0
mallinkCApi/src/main/java/com/iformall/controller/WxCouponController.java View File

@@ -1,13 +1,17 @@
package com.iformall.controller;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import com.iformall.enums.EnumCouponType;
import com.iformall.enums.EnumMerchantStatus;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
@@ -20,6 +24,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.iformall.common.ErrorCode;
import com.iformall.common.ResultData;
import com.iformall.domain.po.WxCoupon;
@@ -31,7 +36,9 @@ import com.iformall.enums.EnumCouponChannelType;
import com.iformall.service.WxCouponChannelService;
import com.iformall.service.WxCouponService;
import com.iformall.service.WxMerchantService;
import com.iformall.service.util.CouponCacheUtils;
import com.iformall.utils.Constant;
import com.iformall.utils.RedisCacheUtils;
import com.iformall.utils.RedisLock;

import io.swagger.annotations.Api;
@@ -55,6 +62,166 @@ public class WxCouponController extends BaseController {
@Autowired
@Qualifier("couponDetailRedisTemplate")
RedisTemplate<String, WxCouponCVo> cdRedisTemplate;
@Autowired
@Qualifier("objectCommonRedisTemplate")
RedisTemplate<String, Object> redisTemplate;
@ApiOperation("根据id(couponChannel)查询详情接口")
@GetMapping("/couponDetail")
@ApiImplicitParams({
@ApiImplicitParam(name = "couponChannelId", value = "couponChannelId", dataType = "String", paramType = "query", required = true)})
public ResultData couponDetail(String couponChannelId) {
if ((StringUtils.isBlank(couponChannelId) || couponChannelId.equalsIgnoreCase(Constant.UNDEFINED))
) {
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId为空");
}
Long couponChannelIdL = 0L;

try {
if (StringUtils.isNotBlank(couponChannelId) && !couponChannelId.equalsIgnoreCase(Constant.UNDEFINED)) {
couponChannelIdL = Long.valueOf(couponChannelId);
}
} catch (NumberFormatException e) {
logger.error("id转换失败" + couponChannelId);
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId转换失败" + couponChannelId);
}

if(couponChannelIdL <= 0){
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId为空");
}

WxCouponChannel couponChannel = CouponCacheUtils.getCouponChannelCache(redisTemplate, couponChannelIdL);
if (null == couponChannel) {
couponChannel = wxCouponChannelService.getById(couponChannelIdL,this.getTenantInfo().getTenantId());
if (null == couponChannel) {
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId无效" + couponChannelId);
}
CouponCacheUtils.setCouponChannelCache(redisTemplate, couponChannelIdL, couponChannel);
}
WxCoupon coupon = CouponCacheUtils.getCouponCache(redisTemplate, couponChannel.getCouponId());
if (null == coupon) {
coupon = couponService.getById(couponChannel.getCouponId(),couponChannel.getTenantId());
if (null == coupon) {
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannel找不到coupon" + couponChannelId);
}
if(EnumCouponType.COUPON_GIFT.getCode().equals(coupon.getType())){
WxCoupon couponQ = new WxCoupon();
couponQ.updateTenantInfo(coupon);
List<Long> longs = JSON.parseArray(coupon.getGiftList(), Long.class);
if(longs != null && longs.size() > 0){
couponQ.setIds(longs);
coupon.setGiftCouponList(couponService.list(couponQ));
}
}
CouponCacheUtils.setCouponCache(redisTemplate, couponChannel.getCouponId(), coupon);
}
updateActivityStatus(coupon,couponChannel);
coupon.setCouponChannel(couponChannel);
return new ResultData(coupon);
}
@ApiOperation("根据id(couponChannel)查询库存价格接口")
@GetMapping("/couponPriceAndStock")
@ApiImplicitParams({
@ApiImplicitParam(name = "couponChannelId", value = "couponChannelId", dataType = "String", paramType = "query", required = true)})
public ResultData couponPriceAndStock(String couponChannelId) {
if ((StringUtils.isBlank(couponChannelId) || couponChannelId.equalsIgnoreCase(Constant.UNDEFINED))
) {
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId为空");
}
Long couponChannelIdL = 0L;

try {
if (StringUtils.isNotBlank(couponChannelId) && !couponChannelId.equalsIgnoreCase(Constant.UNDEFINED)) {
couponChannelIdL = Long.valueOf(couponChannelId);
}
} catch (NumberFormatException e) {
logger.error("id转换失败" + couponChannelId);
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId转换失败" + couponChannelId);
}

if(couponChannelIdL <= 0){
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId为空");
}

WxCouponChannel channelPriceAndStock = wxCouponChannelService.getPriceAndStock(this.getTenantInfo(), couponChannelIdL);
if (null != channelPriceAndStock.getChannelPrice() && null != channelPriceAndStock.getChannelStock()) {
return new ResultData(new StringBuffer("{").append("\"salePrice\":").append(channelPriceAndStock.getChannelPrice())
.append(",\"remainInventory\":").append(channelPriceAndStock.getChannelStock()).append("}"));
}else {
WxCoupon coupon = couponService.getPriceAndStock(channelPriceAndStock.getCouponId(),this.getTenantInfo().getTenantId());
StringBuffer sb = new StringBuffer("{\"salePrice\":");
if (null != channelPriceAndStock.getChannelPrice()) {
sb.append(channelPriceAndStock.getChannelPrice());
}else {
sb.append(coupon.getSalePrice());
}
sb.append(",\"remainInventory\":");
if (null != channelPriceAndStock.getChannelStock()) {
sb.append(channelPriceAndStock.getChannelStock());
}else {
sb.append(coupon.getRemainInventory());
}
sb.append("}");
return new ResultData(sb.toString());
}
}
@ApiOperation("根据id(couponChannel)查询商品商户接口")
@GetMapping("/couponMerchant")
@ApiImplicitParams({
@ApiImplicitParam(name = "couponChannelId", value = "couponChannelId", dataType = "String", paramType = "query", required = true)})
public ResultData couponMerchant(String couponChannelId) {
if ((StringUtils.isBlank(couponChannelId) || couponChannelId.equalsIgnoreCase(Constant.UNDEFINED))
) {
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId为空");
}
Long couponChannelIdL = 0L;

try {
if (StringUtils.isNotBlank(couponChannelId) && !couponChannelId.equalsIgnoreCase(Constant.UNDEFINED)) {
couponChannelIdL = Long.valueOf(couponChannelId);
}
} catch (NumberFormatException e) {
logger.error("id转换失败" + couponChannelId);
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId转换失败" + couponChannelId);
}

if(couponChannelIdL <= 0){
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId为空");
}

WxCouponChannel couponChannel = CouponCacheUtils.getCouponChannelCache(redisTemplate, couponChannelIdL);
if (null == couponChannel) {
couponChannel = wxCouponChannelService.getById(couponChannelIdL,this.getTenantInfo().getTenantId());
if (null == couponChannel) {
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId无效" + couponChannelId);
}
CouponCacheUtils.setCouponChannelCache(redisTemplate, couponChannelIdL, couponChannel);
}
List<WxMerchantVo> volist = CouponCacheUtils.getCouponMerchantCache(redisTemplate, couponChannel.getId());
if (null == volist) {
List<Long> couponIdList = new ArrayList<Long>();
couponIdList.add(couponChannel.getCouponId());
Map<Long, List<WxMerchantVo>> couponMerchantVoMap = merchantService.findCouponMerchantVoList(couponIdList, couponChannel,true);
List<WxMerchantVo> merchantList = couponMerchantVoMap.get(couponChannel.getCouponId());
if (merchantList != null) {
merchantList = merchantList.stream().filter(
m->m.getMerchantStatus().equals(EnumMerchantStatus.VALID.getCode()))
.collect(Collectors.toList());
}
if (null != merchantList && merchantList.size() > 0 ) {
CouponCacheUtils.setCouponMerchantCache(redisTemplate, couponChannel.getCouponId(), merchantList);
}
}
return new ResultData(volist);
}

@ApiOperation("根据id(couponChannel)查询接口")
@GetMapping("/detail")
@@ -306,5 +473,21 @@ public class WxCouponController extends BaseController {
}
}
}
private void updateActivityStatus(WxCoupon coupon,WxCouponChannel couponChannel) {
if (coupon.getType().equals(EnumCouponType.COUPON_PREORDER.getCode()) ||
(couponChannel.getTargetAd() != null && couponChannel.getTargetAd().equals(EnumCouponChannelType.COUPON_CHANNEL_ID_TIMED.getCode()))
) {
Date now = new Date();

if (couponChannel.getBeginTime().getTime() > now.getTime()) {
coupon.setActStatus(EnumCouponChannelActivityStatus.PREPARED.getCode());
} else if (couponChannel.getEndTime().getTime() < now.getTime()) {
coupon.setActStatus(EnumCouponChannelActivityStatus.ENDED.getCode());
} else {
coupon.setActStatus(EnumCouponChannelActivityStatus.STARTED.getCode());
}
}
}

}

+ 6
- 0
mallinkService/src/main/java/com/iformall/domain/po/WxCoupon.java View File

@@ -215,6 +215,8 @@ public class WxCoupon extends TenantEntity {
@TableField(exist = false)
@io.swagger.annotations.ApiModelProperty(value="投放渠道id",name="couponChannelId")
private Long couponChannelId;
@TableField(exist = false)
private WxCouponChannel couponChannel;

//营销分析
@TableField(exist = false)
@@ -239,6 +241,10 @@ public class WxCoupon extends TenantEntity {
@TableField(exist = false)
private List<WxCoupon> giftCouponList;
@TableField(exist = false)
@io.swagger.annotations.ApiModelProperty(value = "现时抢购状态", name = "actStatus")
private Integer actStatus;

@TableField(exist = false)
@SortColumn(column = "press_count")


+ 3
- 0
mallinkService/src/main/java/com/iformall/mapper/WxCouponChannelMapper.java View File

@@ -3,6 +3,7 @@ package com.iformall.mapper;
import java.util.*;
import com.iformall.common.CommonMapper;
import com.iformall.domain.po.WxTopic;
import com.iformall.domain.po.base.TenantEntity;
import com.iformall.domain.po.WxCouponChannel;
import org.apache.ibatis.annotations.Param;

@@ -65,5 +66,7 @@ public interface WxCouponChannelMapper extends CommonMapper<WxCouponChannel, Str
Integer clearChannelStock(@Param("id")Long id,@Param("tenantId")String tenantId);
Integer setChannelPrice(@Param("id")Long id,@Param("tenantId")String tenantId,@Param("price")Integer price);
WxCouponChannel getPriceAndStock(@Param("id")Long id,@Param("tenantId")String tenantId);

}

+ 2
- 0
mallinkService/src/main/java/com/iformall/mapper/WxCouponMapper.java View File

@@ -30,6 +30,8 @@ public interface WxCouponMapper extends CommonMapper<WxCoupon, Long> {
List<Long> findSendCouponIds(@Param("expired")Integer expired,@Param("tenantId")String tenantId);

WxCoupon selectById(@Param("id")Long id,@Param("tenantId")String tenantId);
WxCoupon getPriceAndStock(@Param("id")Long id,@Param("tenantId")String tenantId);

WxCouponCVo findVoDetail(@Param("id")Long id,@Param("tenantId")String tenantId);
WxCouponCVo findVoStatusDetail(@Param("id")Long id,@Param("tenantId")String tenantId);


+ 1
- 0
mallinkService/src/main/java/com/iformall/service/WxCouponChannelService.java View File

@@ -67,6 +67,7 @@ public interface WxCouponChannelService {
void setChannelStock(WxCouponChannel record,Integer number);
void releaseChannelStock(WxCouponChannel record);
void setChannelPrice(WxCouponChannel record);
WxCouponChannel getPriceAndStock(TenantEntity tenantEntity,Long couponChannelId);

ResultData getCouponChannelPoi(TenantEntity tenantInfo, Long id);
}

+ 4
- 0
mallinkService/src/main/java/com/iformall/service/WxCouponService.java View File

@@ -16,6 +16,8 @@ public interface WxCouponService {


ResultData list(TenantEntity tenantEntity,WxCoupon wxCoupon, Integer pageNum, Integer pageSize);
List<WxCoupon> list(WxCoupon wxCoupon);

/**
* 根据实体查询分页列表
@@ -66,6 +68,8 @@ public interface WxCouponService {
* @return
*/
WxCoupon getById(Long id,String tenantId);
WxCoupon getPriceAndStock(Long id,String tenantId);

WxCoupon getHtmlById(Long id,String tenantId);



+ 5
- 0
mallinkService/src/main/java/com/iformall/service/impl/WxCouponChannelServiceImpl.java View File

@@ -740,5 +740,10 @@ public class WxCouponChannelServiceImpl implements WxCouponChannelService {
return new ResultData(ErrorCode.SYS_NULLPOINTER_ERROR.getCode(),"未找到可用的数据");
}

@Override
public WxCouponChannel getPriceAndStock(TenantEntity tenantEntity, Long couponChannelId) {
return wxCouponChannelMapper.getPriceAndStock(couponChannelId, tenantEntity.getTenantId());
}

}


+ 10
- 0
mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java View File

@@ -187,6 +187,11 @@ public class WxCouponServiceImpl implements WxCouponService {
}
return new ResultData(page);
}
@Override
public List<WxCoupon> list(WxCoupon wxCoupon){
return wxCouponMapper.findList(wxCoupon);
}

@Override
public PageInfo<WxCoupon> listAsPage(WxCoupon record, Integer pageIndex, Integer pageSize) {
@@ -228,6 +233,11 @@ public class WxCouponServiceImpl implements WxCouponService {
public WxCoupon getById(Long id,String tenantId) {
return wxCouponMapper.selectById(id,tenantId);
}
@Override
public WxCoupon getPriceAndStock(Long id,String tenantId) {
return wxCouponMapper.getPriceAndStock(id,tenantId);
}

@Override
public WxCoupon getHtmlById(Long id,String tenantId) {


+ 60
- 0
mallinkService/src/main/java/com/iformall/service/util/CouponCacheUtils.java View File

@@ -0,0 +1,60 @@
package com.iformall.service.util;

import java.util.List;

import org.springframework.data.redis.core.RedisTemplate;

import com.iformall.domain.po.WxCoupon;
import com.iformall.domain.po.WxCouponChannel;
import com.iformall.domain.vo.WxMerchantVo;
import com.iformall.utils.RedisCacheUtils;

public class CouponCacheUtils {
public static void removeCouponChannelCache(RedisTemplate<String, Object> template,Long couponChannelId) {
String key = "couponChannelDetail:"+couponChannelId;
RedisCacheUtils.removeCache(template, key);
}
public static void setCouponChannelCache(RedisTemplate<String, Object> template,Long couponChannelId,WxCouponChannel couponChannel) {
String key = "couponChannelDetail:"+couponChannelId;
RedisCacheUtils.cache(template, key, couponChannel, 24*3600);
}
public static WxCouponChannel getCouponChannelCache(RedisTemplate<String, Object> template,Long couponChannelId) {
String key = "couponChannelDetail:"+couponChannelId;
return RedisCacheUtils.getCacheObject(template, key,WxCouponChannel.class);
}

public static void removeCouponCache(RedisTemplate<String, Object> template,Long couponId) {
String key = "couponDetail:"+couponId;
RedisCacheUtils.removeCache(template, key);
}
public static void setCouponCache(RedisTemplate<String, Object> template,Long couponId,WxCoupon coupon) {
String key = "couponDetail:"+couponId;
RedisCacheUtils.cache(template, key, coupon, 24*3600);
}
public static WxCoupon getCouponCache(RedisTemplate<String, Object> template,Long couponId) {
String key = "couponDetail:"+couponId;
return RedisCacheUtils.getCacheObject(template, key,WxCoupon.class);
}
public static void removeCouponMerchantCache(RedisTemplate<String, Object> template,Long couponId) {
String key = "couponMerchant:"+couponId;
RedisCacheUtils.removeCache(template, key);
}
public static void setCouponMerchantCache(RedisTemplate<String, Object> template,Long couponId,List<WxMerchantVo> merchantList) {
String key = "couponMerchant:"+couponId;
RedisCacheUtils.cache(template, key, merchantList, 24*3600);
}
public static List<WxMerchantVo> getCouponMerchantCache(RedisTemplate<String, Object> template,Long couponId) {
String key = "couponMerchant:"+couponId;
return RedisCacheUtils.getCacheListObject(template, key,WxMerchantVo.class);
}
}

+ 4
- 0
mallinkService/src/main/resources/mapper/WxCouponChannelMapper.xml View File

@@ -356,5 +356,9 @@
<update id="setChannelPrice">
update wx_coupon_channel SET channel_price = #{price} where id = #{id} and tenant_id =#{tenantId}
</update>
<select id="getPriceAndStock" parameterType="java.util.HashMap" resultMap="BaseResultMap">
select id,coupon_id,channel_stock,channel_price from wx_coupon_channel where `id` = #{id} and `tenant_id` = #{tenantId}
</select>

</mapper>

+ 4
- 0
mallinkService/src/main/resources/mapper/WxCouponMapper.xml View File

@@ -325,6 +325,10 @@
select <include refid="allColumns"/> ,c.html from wx_coupon c where id = #{id} and tenant_id = #{tenantId}
</select>
<select id="getPriceAndStock" parameterType="java.util.HashMap" resultMap="BaseResultMap">
select c.sale_price,c.price,c.remain_inventory,c.inventory from wx_coupon c where id = #{id} and tenant_id = #{tenantId}
</select>
<select id="findTenantSimpleList" parameterType="com.iformall.domain.po.WxCoupon" resultMap="BaseResultMap">
select id,title,sale_price,use_price,price,tail_price,orig_price,auto_refund,business,subsidy_type,source_type,type,unit,cover_img,
sub_title,item_group,valid_type,valid_start_date,valid_end_date,pick_start_date,pick_end_date


Loading…
Cancel
Save