|
|
|
@ -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<HighDiscountCouponRel> 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("操作成功"); |
|
|
|
|
|
|
|
|
|