diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighDiscountCouponRelController.java b/hai-bweb/src/main/java/com/bweb/controller/HighDiscountCouponRelController.java index f25b5493..c1687b5f 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighDiscountCouponRelController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighDiscountCouponRelController.java @@ -5,19 +5,24 @@ import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; import com.hai.common.utils.ResponseMsgUtil; +import com.hai.entity.HighCoupon; import com.hai.entity.HighDiscountCouponRel; import com.hai.model.ResponseData; import com.hai.service.HighAgentService; +import com.hai.service.HighCouponService; import com.hai.service.HighDiscountCouponRelService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.Date; +import java.util.List; /** * @Auther: 胡锐 @@ -34,6 +39,9 @@ public class HighDiscountCouponRelController { @Resource private HighDiscountCouponRelService highDiscountCouponRelService; + @Resource + private HighCouponService highCouponService; + @RequestMapping(value="/insertDiscountCoupon",method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "增加优惠券和卡券关系") @@ -41,25 +49,36 @@ public class HighDiscountCouponRelController { try { JSONObject jsonObject = JSONObject.parseObject(reqBody); Long discountId = jsonObject.getLong("discountId"); - Long couponId = jsonObject.getLong("couponId"); + String couponIdStr = jsonObject.getString("couponId"); - if (discountId == null || couponId == null) { + if (discountId == null || StringUtils.isBlank(couponIdStr)) { log.error("HighDiscountCouponRelController -> insertDiscountCoupon() error!","参数错误"); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } - // 是否存在 - if (highDiscountCouponRelService.getRelByDiscountCoupon(discountId,couponId) != null) { - log.error("HighDiscountCouponRelController -> insertDiscountCoupon() error!","重复增加"); - throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "重复增加"); + String[] couponId = couponIdStr.split(","); + List list = new ArrayList<>(); + HighDiscountCouponRel rel; + for (String id : couponId) { + // 查询卡券消息 + HighCoupon coupon = highCouponService.getCouponById(Long.parseLong(id)); + if (coupon == null) { + log.error("HighDiscountCouponRelController -> insertDiscountCoupon() error!","未找到卡券信息"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, ""); + } + // 是否存在 + if (highDiscountCouponRelService.getRelByDiscountCoupon(discountId,Long.parseLong(id)) != null) { + log.error("HighDiscountCouponRelController -> insertDiscountCoupon() error!","重复增加" + coupon.getCouponName()); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "重复增加" + coupon.getCouponName()); + } + rel =new HighDiscountCouponRel(); + rel.setDiscountId(discountId); + rel.setCouponId(Long.parseLong(id)); + rel.setStatus(1); + rel.setCreateTime(new Date()); + list.add(rel); } - - HighDiscountCouponRel rel = new HighDiscountCouponRel(); - rel.setDiscountId(discountId); - rel.setCouponId(couponId); - rel.setStatus(1); - rel.setCreateTime(new Date()); - highDiscountCouponRelService.insertDiscountCoupon(rel); + highDiscountCouponRelService.insertDiscountCouponList(list); return ResponseMsgUtil.success("操作成功"); diff --git a/hai-schedule/src/main/java/com/hai/schedule/HighCouponSchedule.java b/hai-schedule/src/main/java/com/hai/schedule/HighCouponSchedule.java index 77d4d9ab..455c2fa9 100644 --- a/hai-schedule/src/main/java/com/hai/schedule/HighCouponSchedule.java +++ b/hai-schedule/src/main/java/com/hai/schedule/HighCouponSchedule.java @@ -31,6 +31,8 @@ public class HighCouponSchedule { for (HighUserCoupon highUserCoupon : userCoupons) { highUserCoupon.setStatus(0); // 状态 0:已过期 1:未使用 2:已使用 highUserCouponService.updateUserCoupon(highUserCoupon); + + } } } diff --git a/hai-service/src/main/java/com/hai/common/exception/ErrorCode.java b/hai-service/src/main/java/com/hai/common/exception/ErrorCode.java index 5a6aabf3..bedb3473 100644 --- a/hai-service/src/main/java/com/hai/common/exception/ErrorCode.java +++ b/hai-service/src/main/java/com/hai/common/exception/ErrorCode.java @@ -80,7 +80,7 @@ public enum ErrorCode { PHONE_NUM_EXISTED("2108","电话号码已被使用"), MERCHANT_STATUS_ERROR("2109","商户状态不正常,请联系管理员"), SELECT_HANDSEL_COUPON_ERROR("2110","请选择赠送卡卷名单"), - NOT_FOUND_COUPON("2111","未找到卡卷信息"), + NOT_FOUND_COUPON("2111","未找到卡券信息"), WRITE_COUPON_NUMBER_ERROR("2112","请填写卡卷数量"), COUPON_UNABLE_UP_SHELF("2113","卡卷状态错误"), NOT_FOUND_APPROVE("2114","未找到审批记录"), diff --git a/hai-service/src/main/java/com/hai/service/HighDiscountCouponRelService.java b/hai-service/src/main/java/com/hai/service/HighDiscountCouponRelService.java index ca170011..89539628 100644 --- a/hai-service/src/main/java/com/hai/service/HighDiscountCouponRelService.java +++ b/hai-service/src/main/java/com/hai/service/HighDiscountCouponRelService.java @@ -17,7 +17,7 @@ public interface HighDiscountCouponRelService { * @Description 增加 * @Date 2021/4/3 23:12 **/ - void insertDiscountCoupon(HighDiscountCouponRel highDiscountCouponRel); + void insertDiscountCouponList(List highDiscountCouponRelList); /** * @Author 胡锐 diff --git a/hai-service/src/main/java/com/hai/service/impl/HighDiscountCouponRelServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighDiscountCouponRelServiceImpl.java index a65958d3..f6f4be09 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighDiscountCouponRelServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighDiscountCouponRelServiceImpl.java @@ -12,6 +12,8 @@ import com.hai.service.HighCouponService; import com.hai.service.HighDiscountCouponRelService; import com.hai.service.HighDiscountService; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.List; @@ -31,8 +33,11 @@ public class HighDiscountCouponRelServiceImpl implements HighDiscountCouponRelSe private HighCouponService highCouponService; @Override - public void insertDiscountCoupon(HighDiscountCouponRel highDiscountCouponRel) { - highDiscountCouponRelMapper.insert(highDiscountCouponRel); + @Transactional(propagation= Propagation.REQUIRES_NEW) + public void insertDiscountCouponList(List highDiscountCouponRelList) { + for (HighDiscountCouponRel rel : highDiscountCouponRelList) { + highDiscountCouponRelMapper.insert(rel); + } } @Override