| @@ -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())) { | |||