|
|
|
@@ -17,9 +17,13 @@ import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Qualifier; |
|
|
|
import org.springframework.data.redis.core.RedisTemplate; |
|
|
|
import org.springframework.data.redis.core.ValueOperations; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
import java.util.Date; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
@RestController |
|
|
|
@RequestMapping("/api/wxCoupon") |
|
|
|
@@ -29,8 +33,10 @@ public class WxCouponController extends BaseController { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxCouponChannelService wxCouponChannelService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxCouponService wxCouponService; |
|
|
|
@Qualifier("couponDetailRedisTemplate") |
|
|
|
RedisTemplate<String, WxCouponCVo> cdRedisTemplate; |
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation("根据id(couponChannel)查询接口") |
|
|
|
@@ -49,10 +55,40 @@ public class WxCouponController extends BaseController { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId转换失败" + couponChannelId); |
|
|
|
} |
|
|
|
|
|
|
|
String key = "cc:" + couponChannelId; |
|
|
|
|
|
|
|
ValueOperations<String, WxCouponCVo> operations = cdRedisTemplate.opsForValue(); |
|
|
|
// 缓存 |
|
|
|
boolean hasKey = cdRedisTemplate.hasKey(key); |
|
|
|
if(hasKey) { |
|
|
|
// 从缓存获取用户信息 |
|
|
|
WxCouponCVo wxCouponCVo = operations.get(key); |
|
|
|
// 更新状态 |
|
|
|
WxCouponCVo couponCVo = wxCouponChannelService.findVoStatusDetail(couponChannelIdL); |
|
|
|
if (wxCouponCVo == null) { |
|
|
|
return new ResultData(ErrorCode.COUPON_IS_EMPTY); |
|
|
|
} |
|
|
|
wxCouponCVo.setRemainInventory(couponCVo.getRemainInventory()); |
|
|
|
wxCouponCVo.setStatus(couponCVo.getStatus()); |
|
|
|
// end of 更新状态 |
|
|
|
updateActivityStatus(wxCouponCVo); |
|
|
|
return new ResultData(wxCouponCVo); |
|
|
|
} |
|
|
|
|
|
|
|
WxCouponCVo wxCouponCVo = wxCouponChannelService.findDetailVo(couponChannelIdL); |
|
|
|
if (wxCouponCVo == null) |
|
|
|
if (wxCouponCVo == null) { |
|
|
|
return new ResultData(ErrorCode.COUPON_IS_EMPTY); |
|
|
|
} |
|
|
|
|
|
|
|
// 插入缓存 |
|
|
|
operations.set(key, wxCouponCVo, 3600, TimeUnit.SECONDS); |
|
|
|
|
|
|
|
updateActivityStatus(wxCouponCVo); |
|
|
|
|
|
|
|
return new ResultData(wxCouponCVo); |
|
|
|
} |
|
|
|
|
|
|
|
private void updateActivityStatus(WxCouponCVo wxCouponCVo) { |
|
|
|
if (wxCouponCVo.getTargetAd()!= null && |
|
|
|
wxCouponCVo.getTargetAd().equals(EnumCouponChannelType.COUPON_CHANNEL_ID_TIMED.getCode())) { |
|
|
|
Date now = new Date(); |
|
|
|
@@ -65,8 +101,6 @@ public class WxCouponController extends BaseController { |
|
|
|
wxCouponCVo.setActivityStatus(EnumCouponChannelActivityStatus.STARTED.getCode()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return new ResultData(wxCouponCVo); |
|
|
|
} |
|
|
|
|
|
|
|
} |