From 8f3f3e9c00b81117abfdd9c74a7133bbbcc5f914 Mon Sep 17 00:00:00 2001 From: Stormeye Wu Date: Tue, 10 Sep 2019 10:26:02 +0800 Subject: [PATCH] =?UTF-8?q?[C][=E4=BF=AE=E6=94=B9]:coupon/detail=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WxCouponController.java | 41 +++++++++++++------ .../com/iformall/mapper/WxCouponMapper.java | 1 + .../com/iformall/service/WxCouponService.java | 2 + .../service/impl/WxCouponServiceImpl.java | 6 +++ .../main/resources/mapper/WxCouponMapper.xml | 10 +++++ 5 files changed, 48 insertions(+), 12 deletions(-) diff --git a/mallinkCApi/src/main/java/com/iformall/controller/WxCouponController.java b/mallinkCApi/src/main/java/com/iformall/controller/WxCouponController.java index 502710f08..10b47e864 100644 --- a/mallinkCApi/src/main/java/com/iformall/controller/WxCouponController.java +++ b/mallinkCApi/src/main/java/com/iformall/controller/WxCouponController.java @@ -34,6 +34,9 @@ public class WxCouponController extends BaseController { @Autowired private WxCouponChannelService wxCouponChannelService; + @Autowired + private WxCouponService couponService; + @Autowired @Qualifier("couponDetailRedisTemplate") RedisTemplate cdRedisTemplate; @@ -42,14 +45,18 @@ public class WxCouponController extends BaseController { @ApiOperation("根据id(couponChannel)查询接口") @GetMapping("/detail") @ApiImplicitParams({ - @ApiImplicitParam(name = "couponChannelId", value = "couponChannelId", dataType = "String", paramType = "query", required = true)}) - public ResultData detailC(String couponChannelId) { + @ApiImplicitParam(name = "couponChannelId", value = "couponChannelId", dataType = "String", paramType = "query", required = true), + @ApiImplicitParam(name = "couponId", value = "couponId", dataType = "String", paramType = "query", required = false)}) + public ResultData detailC(String couponChannelId, String couponId) { if (StringUtils.isBlank(couponChannelId) || couponChannelId.equalsIgnoreCase(Constant.UNDEFINED)) { - return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId为空"); + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId/couponId为空"); } - Long couponChannelIdL = 0L; + Long couponChannelIdL = 0L, couponIdL = 0L; try { couponChannelIdL = Long.valueOf(couponChannelId); + if (StringUtils.isNotBlank(couponId) && !couponId.equalsIgnoreCase(Constant.UNDEFINED)) { + couponIdL = Long.valueOf(couponId); + } } catch (NumberFormatException e) { logger.error("id转换失败" + couponChannelId); return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId转换失败" + couponChannelId); @@ -60,16 +67,26 @@ public class WxCouponController extends BaseController { ValueOperations operations = cdRedisTemplate.opsForValue(); // 缓存 boolean hasKey = cdRedisTemplate.hasKey(key); - if(hasKey) { + if (hasKey) { // 从缓存获取用户信息 WxCouponCVo wxCouponCVo = operations.get(key); - // 更新状态 - WxCouponCVo couponCVo = wxCouponChannelService.findVoStatusDetail(couponChannelIdL); - if (wxCouponCVo == null) { - return new ResultData(ErrorCode.COUPON_IS_EMPTY); + if (couponIdL > 0L) { + // 更新状态 + WxCouponCVo couponCVo = couponService.getVoStatusById(couponIdL); + if (wxCouponCVo == null) { + return new ResultData(ErrorCode.COUPON_IS_EMPTY); + } + wxCouponCVo.setRemainInventory(couponCVo.getRemainInventory()); + wxCouponCVo.setStatus(couponCVo.getStatus()); + } else { + // 更新状态 + WxCouponCVo couponCVo = wxCouponChannelService.findVoStatusDetail(couponChannelIdL); + if (wxCouponCVo == null) { + return new ResultData(ErrorCode.COUPON_IS_EMPTY); + } + wxCouponCVo.setRemainInventory(couponCVo.getRemainInventory()); + wxCouponCVo.setStatus(couponCVo.getStatus()); } - wxCouponCVo.setRemainInventory(couponCVo.getRemainInventory()); - wxCouponCVo.setStatus(couponCVo.getStatus()); // end of 更新状态 updateActivityStatus(wxCouponCVo); return new ResultData(wxCouponCVo); @@ -89,7 +106,7 @@ public class WxCouponController extends BaseController { } private void updateActivityStatus(WxCouponCVo wxCouponCVo) { - if (wxCouponCVo.getTargetAd()!= null && + if (wxCouponCVo.getTargetAd() != null && wxCouponCVo.getTargetAd().equals(EnumCouponChannelType.COUPON_CHANNEL_ID_TIMED.getCode())) { Date now = new Date(); diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxCouponMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxCouponMapper.java index ebac5cc58..6b2b499d2 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxCouponMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxCouponMapper.java @@ -18,6 +18,7 @@ public interface WxCouponMapper extends CommonMapper { WxCouponCVo findVoDetail(@Param("id")Long id); + WxCouponCVo findVoStatusDetail(@Param("id")Long id); Integer reduceInventory(@Param("id")Long id,@Param("number")Integer number,@Param("remainInventory")Integer remainInventory); diff --git a/mallinkService/src/main/java/com/iformall/service/WxCouponService.java b/mallinkService/src/main/java/com/iformall/service/WxCouponService.java index dffc887e8..308922c7a 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxCouponService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxCouponService.java @@ -56,6 +56,8 @@ public interface WxCouponService { WxCouponCVo getVoById(Long id); + + WxCouponCVo getVoStatusById(Long id); /** * 保存或更新实体 * diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java index 7ce5b17f4..a26b7c95e 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponServiceImpl.java @@ -170,6 +170,12 @@ import java.util.stream.Collectors; return wxCouponCVo; } + @Override + public WxCouponCVo getVoStatusById(Long id) { + WxCouponCVo wxCouponCVo = wxCouponMapper.findVoStatusDetail(id); + return wxCouponCVo; + } + private Long parseMerchantId(JSONObject merchantParam){ return Long.valueOf(merchantParam.getString("id")); diff --git a/mallinkService/src/main/resources/mapper/WxCouponMapper.xml b/mallinkService/src/main/resources/mapper/WxCouponMapper.xml index 6dccc799b..4eddf76f7 100644 --- a/mallinkService/src/main/resources/mapper/WxCouponMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCouponMapper.xml @@ -98,6 +98,10 @@ `press_limit_num`, `press_limit_hours`, `auto_refund`,`credit_price`,`credit_refund`,`put_apply_status`,`stock_apply_status`,`cancle_apply_status`,`conditions`,approval_type + + `id`,`remain_inventory`,`status` + + where 1 = 1 @@ -510,6 +514,12 @@ where id = #{id} + update wx_coupon SET remain_inventory = remain_inventory - #{number} where id = #{id} and remain_inventory= #{remainInventory}