Authored by chenchao

user coupon support modify end time

1 package com.yoho.ufo.coupon.controller; 1 package com.yoho.ufo.coupon.controller;
2 2
3 -import com.google.common.collect.Lists;  
4 import com.yoho.ufo.coupon.service.ICouponService; 3 import com.yoho.ufo.coupon.service.ICouponService;
5 import com.yoho.ufo.exception.PlatformException; 4 import com.yoho.ufo.exception.PlatformException;
6 import com.yoho.ufo.service.impl.BatchService; 5 import com.yoho.ufo.service.impl.BatchService;
@@ -8,7 +7,7 @@ import com.yoho.ufo.service.model.ApiResponse; @@ -8,7 +7,7 @@ import com.yoho.ufo.service.model.ApiResponse;
8 import com.yoho.ufo.service.model.ExportParam; 7 import com.yoho.ufo.service.model.ExportParam;
9 import com.yoho.ufo.util.HttpUtil; 8 import com.yoho.ufo.util.HttpUtil;
10 import com.yohobuy.ufo.coupon.req.*; 9 import com.yohobuy.ufo.coupon.req.*;
11 -import org.apache.commons.lang.StringUtils; 10 +import org.apache.commons.lang3.StringUtils;
12 import org.slf4j.Logger; 11 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory; 12 import org.slf4j.LoggerFactory;
14 import org.springframework.beans.factory.annotation.Autowired; 13 import org.springframework.beans.factory.annotation.Autowired;
@@ -128,12 +127,24 @@ public class CouponController { @@ -128,12 +127,24 @@ public class CouponController {
128 * @return 127 * @return
129 */ 128 */
130 @RequestMapping(value = "/queryUserCouponList") 129 @RequestMapping(value = "/queryUserCouponList")
131 - public com.yohobuy.ufo.model.common.ApiResponse queryUserCouponList(UserCouponQueryReq req) { 130 + public ApiResponse queryUserCouponList(UserCouponQueryReq req) {
132 LOGGER.info("enter queryCoupons,param is {}",req); 131 LOGGER.info("enter queryCoupons,param is {}",req);
133 - if(req.getUid() == null && org.apache.commons.lang3.StringUtils.isEmpty(req.getCouponCode())){  
134 - return new com.yohobuy.ufo.model.common.ApiResponse<>(Lists.newArrayList());  
135 - }  
136 - return new com.yohobuy.ufo.model.common.ApiResponse<>(couponService.queryUserCouponList(req)); 132 +
  133 + return new ApiResponse.ApiResponseBuilder().code(200)
  134 + .data(couponService.queryUserCouponList(req))
  135 + .message("发放记录查询成功")
  136 + .build();
  137 + }
  138 +
  139 +
  140 + @RequestMapping(value = "/updateUserCoupon")
  141 + public ApiResponse updateUserCoupon(UserCouponUpdateReq req) {
  142 + LOGGER.info("enter updateUserCoupon,req {}",req);
  143 + return new ApiResponse.ApiResponseBuilder()
  144 + .code(200)
  145 + .data(couponService.updateUserCoupon(req))
  146 + .message("用户券修改成功")
  147 + .build();
137 } 148 }
138 149
139 } 150 }
@@ -34,4 +34,5 @@ public interface ICouponService { @@ -34,4 +34,5 @@ public interface ICouponService {
34 */ 34 */
35 ApiResponse invalidateUserCoupon(UserCouponBaseRequest request); 35 ApiResponse invalidateUserCoupon(UserCouponBaseRequest request);
36 36
  37 + int updateUserCoupon(UserCouponUpdateReq userCouponUpdateReq);
37 } 38 }
@@ -402,6 +402,9 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{ @@ -402,6 +402,9 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{
402 402
403 public PageResponseBO<UidCouponQueryResp> queryUserCouponList(UserCouponQueryReq req) { 403 public PageResponseBO<UidCouponQueryResp> queryUserCouponList(UserCouponQueryReq req) {
404 LOGGER.info("enter queryUserCouponList, req is {}",req); 404 LOGGER.info("enter queryUserCouponList, req is {}",req);
  405 + if(req.getUid() == null && StringUtils.isEmpty(req.getCouponCode())){
  406 + return null;
  407 + }
405 int total = userCouponMapper.selectTotalByCondition(req); 408 int total = userCouponMapper.selectTotalByCondition(req);
406 if(0==total){ 409 if(0==total){
407 new PageResponseBO<>(total, Lists.newArrayList(), req.getRows(), req.getPage());; 410 new PageResponseBO<>(total, Lists.newArrayList(), req.getRows(), req.getPage());;
@@ -426,6 +429,54 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{ @@ -426,6 +429,54 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{
426 return new ApiResponse(); 429 return new ApiResponse();
427 } 430 }
428 431
  432 + @Override
  433 + public int updateUserCoupon(UserCouponUpdateReq userCouponUpdateReq) {
  434 +
  435 + PlatformException platformException = null;
  436 + Integer uid;
  437 + if (Objects.isNull(uid = userCouponUpdateReq.getUid())){
  438 + platformException = new PlatformException("uid is null", 401);
  439 + throwRuntimeExcetion(platformException);
  440 + }
  441 + Integer couponId;
  442 + if (Objects.isNull(couponId = userCouponUpdateReq.getCouponId())){
  443 + platformException = new PlatformException("couponId is null", 401);
  444 + throwRuntimeExcetion(platformException);
  445 + }
  446 + String couponCode;
  447 + if (StringUtils.isBlank(couponCode = userCouponUpdateReq.getCouponCode())){
  448 + platformException = new PlatformException("couponCode is null", 401);
  449 + throwRuntimeExcetion(platformException);
  450 + }
  451 +
  452 + Integer endtime;
  453 + if (Objects.isNull(endtime = userCouponUpdateReq.getEndTime())){
  454 + platformException = new PlatformException("endtime is null", 401);
  455 + throwRuntimeExcetion(platformException);
  456 + }
  457 +
  458 + if (endtime<=0){
  459 + platformException = new PlatformException("endtime is illegal", 401);
  460 + throwRuntimeExcetion(platformException);
  461 + }
  462 +
  463 + UserCoupon condition = new UserCoupon();
  464 + condition.setUid(uid);
  465 + condition.setCouponCode(couponCode);
  466 + condition.setCouponId(couponId);
  467 + condition.setEndTime(endtime);
  468 + int rows = userCouponMapper.updateEndTimeOfOneUser(condition);
  469 + if (rows == 0){
  470 + platformException = new PlatformException("修改失败", 401);
  471 + throwRuntimeExcetion(platformException);
  472 + }
  473 + return rows;
  474 + }
  475 +
  476 + private static void throwRuntimeExcetion(PlatformException platformException){
  477 + throw new RuntimeException(platformException);
  478 + }
  479 +
429 private List<UidCouponQueryResp> complateCouponInfo(List<UserCoupon> userCoupons) { 480 private List<UidCouponQueryResp> complateCouponInfo(List<UserCoupon> userCoupons) {
430 if (CollectionUtils.isEmpty(userCoupons)) { 481 if (CollectionUtils.isEmpty(userCoupons)) {
431 return Lists.newArrayList(); 482 return Lists.newArrayList();
@@ -23,4 +23,7 @@ public interface UserCouponMapper { @@ -23,4 +23,7 @@ public interface UserCouponMapper {
23 List<UserCouponNum> selectByCouponIdsAndStatus(@Param("couponIds") List<Integer> couponIds); 23 List<UserCouponNum> selectByCouponIdsAndStatus(@Param("couponIds") List<Integer> couponIds);
24 24
25 int selectTotalByCondition(@Param("param") UserCouponQueryReq param); 25 int selectTotalByCondition(@Param("param") UserCouponQueryReq param);
  26 +
  27 +
  28 + int updateEndTimeOfOneUser(UserCoupon userCoupon);
26 } 29 }
@@ -99,4 +99,11 @@ @@ -99,4 +99,11 @@
99 and status=#{param.status} 99 and status=#{param.status}
100 </if> 100 </if>
101 </select> 101 </select>
  102 +
  103 + <update id="updateEndTimeOfOneUser" parameterType="com.yoho.ufo.model.coupon.UserCoupon" >
  104 + update user_coupon set end_time = #{endTime}
  105 + where uid = #{uid,jdbcType=INTEGER}
  106 + and coupon_id = #{couponId,jdbcType=INTEGER}
  107 + and coupon_code = #{couponCode,jdbcType=VARCHAR}
  108 + </update>
102 </mapper> 109 </mapper>