Authored by chenchao

user coupon support modify end time

package com.yoho.ufo.coupon.controller;
import com.google.common.collect.Lists;
import com.yoho.ufo.coupon.service.ICouponService;
import com.yoho.ufo.exception.PlatformException;
import com.yoho.ufo.service.impl.BatchService;
... ... @@ -8,7 +7,7 @@ import com.yoho.ufo.service.model.ApiResponse;
import com.yoho.ufo.service.model.ExportParam;
import com.yoho.ufo.util.HttpUtil;
import com.yohobuy.ufo.coupon.req.*;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -128,12 +127,24 @@ public class CouponController {
* @return
*/
@RequestMapping(value = "/queryUserCouponList")
public com.yohobuy.ufo.model.common.ApiResponse queryUserCouponList(UserCouponQueryReq req) {
public ApiResponse queryUserCouponList(UserCouponQueryReq req) {
LOGGER.info("enter queryCoupons,param is {}",req);
if(req.getUid() == null && org.apache.commons.lang3.StringUtils.isEmpty(req.getCouponCode())){
return new com.yohobuy.ufo.model.common.ApiResponse<>(Lists.newArrayList());
return new ApiResponse.ApiResponseBuilder().code(200)
.data(couponService.queryUserCouponList(req))
.message("发放记录查询成功")
.build();
}
return new com.yohobuy.ufo.model.common.ApiResponse<>(couponService.queryUserCouponList(req));
@RequestMapping(value = "/updateUserCoupon")
public ApiResponse updateUserCoupon(UserCouponUpdateReq req) {
LOGGER.info("enter updateUserCoupon,req {}",req);
return new ApiResponse.ApiResponseBuilder()
.code(200)
.data(couponService.updateUserCoupon(req))
.message("用户券修改成功")
.build();
}
}
... ...
... ... @@ -34,4 +34,5 @@ public interface ICouponService {
*/
ApiResponse invalidateUserCoupon(UserCouponBaseRequest request);
int updateUserCoupon(UserCouponUpdateReq userCouponUpdateReq);
}
... ...
... ... @@ -402,6 +402,9 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{
public PageResponseBO<UidCouponQueryResp> queryUserCouponList(UserCouponQueryReq req) {
LOGGER.info("enter queryUserCouponList, req is {}",req);
if(req.getUid() == null && StringUtils.isEmpty(req.getCouponCode())){
return null;
}
int total = userCouponMapper.selectTotalByCondition(req);
if(0==total){
new PageResponseBO<>(total, Lists.newArrayList(), req.getRows(), req.getPage());;
... ... @@ -426,6 +429,54 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{
return new ApiResponse();
}
@Override
public int updateUserCoupon(UserCouponUpdateReq userCouponUpdateReq) {
PlatformException platformException = null;
Integer uid;
if (Objects.isNull(uid = userCouponUpdateReq.getUid())){
platformException = new PlatformException("uid is null", 401);
throwRuntimeExcetion(platformException);
}
Integer couponId;
if (Objects.isNull(couponId = userCouponUpdateReq.getCouponId())){
platformException = new PlatformException("couponId is null", 401);
throwRuntimeExcetion(platformException);
}
String couponCode;
if (StringUtils.isBlank(couponCode = userCouponUpdateReq.getCouponCode())){
platformException = new PlatformException("couponCode is null", 401);
throwRuntimeExcetion(platformException);
}
Integer endtime;
if (Objects.isNull(endtime = userCouponUpdateReq.getEndTime())){
platformException = new PlatformException("endtime is null", 401);
throwRuntimeExcetion(platformException);
}
if (endtime<=0){
platformException = new PlatformException("endtime is illegal", 401);
throwRuntimeExcetion(platformException);
}
UserCoupon condition = new UserCoupon();
condition.setUid(uid);
condition.setCouponCode(couponCode);
condition.setCouponId(couponId);
condition.setEndTime(endtime);
int rows = userCouponMapper.updateEndTimeOfOneUser(condition);
if (rows == 0){
platformException = new PlatformException("修改失败", 401);
throwRuntimeExcetion(platformException);
}
return rows;
}
private static void throwRuntimeExcetion(PlatformException platformException){
throw new RuntimeException(platformException);
}
private List<UidCouponQueryResp> complateCouponInfo(List<UserCoupon> userCoupons) {
if (CollectionUtils.isEmpty(userCoupons)) {
return Lists.newArrayList();
... ...
... ... @@ -23,4 +23,7 @@ public interface UserCouponMapper {
List<UserCouponNum> selectByCouponIdsAndStatus(@Param("couponIds") List<Integer> couponIds);
int selectTotalByCondition(@Param("param") UserCouponQueryReq param);
int updateEndTimeOfOneUser(UserCoupon userCoupon);
}
... ...
... ... @@ -99,4 +99,11 @@
and status=#{param.status}
</if>
</select>
<update id="updateEndTimeOfOneUser" parameterType="com.yoho.ufo.model.coupon.UserCoupon" >
update user_coupon set end_time = #{endTime}
where uid = #{uid,jdbcType=INTEGER}
and coupon_id = #{couponId,jdbcType=INTEGER}
and coupon_code = #{couponCode,jdbcType=VARCHAR}
</update>
</mapper>
\ No newline at end of file
... ...