From 381763e0ed37e3a6c291e78eb85475b594b57892 Mon Sep 17 00:00:00 2001 From: xiaohanzi Date: Sat, 30 May 2020 16:45:49 +0800 Subject: [PATCH] update --- .../controller/WxCouponController.java | 86 ++++++++++++++++--- 1 file changed, 73 insertions(+), 13 deletions(-) diff --git a/mallinkCApi/src/main/java/com/iformall/controller/WxCouponController.java b/mallinkCApi/src/main/java/com/iformall/controller/WxCouponController.java index 465541e83..b227e818f 100644 --- a/mallinkCApi/src/main/java/com/iformall/controller/WxCouponController.java +++ b/mallinkCApi/src/main/java/com/iformall/controller/WxCouponController.java @@ -1,29 +1,36 @@ package com.iformall.controller; +import java.lang.reflect.InvocationTargetException; +import java.util.Date; +import java.util.concurrent.TimeUnit; + +import org.apache.commons.beanutils.BeanUtils; +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.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + import com.iformall.common.ErrorCode; import com.iformall.common.ResultData; import com.iformall.domain.po.WxCoupon; +import com.iformall.domain.po.WxCouponChannel; import com.iformall.domain.vo.WxCouponCVo; import com.iformall.enums.EnumCouponChannelActivityStatus; import com.iformall.enums.EnumCouponChannelType; import com.iformall.service.WxCouponChannelService; import com.iformall.service.WxCouponService; import com.iformall.utils.Constant; + import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; -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") @@ -79,7 +86,8 @@ public class WxCouponController extends BaseController { wxCouponCVo.setStatus(couponCVo.getStatus()); } else { // 更新状态 - WxCouponCVo couponCVo = wxCouponChannelService.findVoStatusDetail(couponChannelIdL); + //WxCouponCVo couponCVo = wxCouponChannelService.findVoStatusDetail(couponChannelIdL); + WxCouponCVo couponCVo = generateWxCouponCVo(couponChannelIdL); if (wxCouponCVo == null) { return new ResultData(ErrorCode.COUPON_IS_EMPTY); } @@ -91,7 +99,17 @@ public class WxCouponController extends BaseController { return new ResultData(wxCouponCVo); } - WxCouponCVo wxCouponCVo = wxCouponChannelService.findDetailVo(couponChannelIdL); + //WxCouponCVo wxCouponCVo = wxCouponChannelService.findDetailVo(couponChannelIdL); + WxCouponCVo wxCouponCVo = null; + try { + wxCouponCVo = generateWxCouponCVoex(couponChannelIdL); + } catch (IllegalAccessException e) { + logger.error("coupon detail fail,copyproperties error" + couponChannelId,e); + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "coupon detail fail,copyproperties error" + couponChannelId); + } catch (InvocationTargetException e) { + logger.error("coupon detail fail,copyproperties error" + couponChannelId,e); + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "coupon detail fail,copyproperties error" + couponChannelId); + } if (wxCouponCVo == null) { return new ResultData(ErrorCode.COUPON_IS_EMPTY); } @@ -103,7 +121,49 @@ public class WxCouponController extends BaseController { return new ResultData(wxCouponCVo); } + + private WxCouponCVo generateWxCouponCVo(Long couponChannelIdL) { + WxCouponChannel cc = wxCouponChannelService.getById(couponChannelIdL); + if (cc == null) { + return null; + } + + WxCoupon c = couponService.getById(cc.getCouponId()); + if (c == null) { + return null; + } + + WxCouponCVo couponCVo = new WxCouponCVo(); + couponCVo.setId(cc.getId()); + couponCVo.setCouponId(cc.getCouponId()); + couponCVo.setRemainInventory(c.getRemainInventory()); + couponCVo.setStatus(c.getStatus()); + return couponCVo; + } + + private WxCouponCVo generateWxCouponCVoex(Long couponChannelIdL) throws IllegalAccessException, InvocationTargetException { + WxCouponChannel cc = wxCouponChannelService.getById(couponChannelIdL); + if (cc == null) { + return null; + } + + WxCoupon c = couponService.getById(cc.getCouponId()); + if (c == null) { + c = new WxCoupon(); + } + + WxCouponCVo wxcv = new WxCouponCVo(); + BeanUtils.copyProperties(wxcv, c); + wxcv.setId(cc.getId()); + wxcv.setCouponId(cc.getCouponId()); + wxcv.setTargetAd(cc.getTargetAd()); + wxcv.setBeginTime(cc.getBeginTime()); + wxcv.setEndTime(cc.getEndTime()); + wxcv.setQrCode(cc.getQrCode()); + return wxcv; + } + private void updateActivityStatus(WxCouponCVo wxCouponCVo) { if (wxCouponCVo.getTargetAd() != null && wxCouponCVo.getTargetAd().equals(EnumCouponChannelType.COUPON_CHANNEL_ID_TIMED.getCode())) {