dev-discount
袁野 4 years ago
commit 496662b9a3
  1. 54
      hai-bweb/src/main/java/com/bweb/controller/HighCouponController.java
  2. 11
      hai-service/src/main/java/com/hai/model/HighCouponModel.java
  3. 5
      hai-service/src/main/java/com/hai/service/impl/HighCouponServiceImpl.java

@ -21,10 +21,7 @@ import com.hai.model.HighCouponHandselModel;
import com.hai.model.HighCouponModel;
import com.hai.model.ResponseData;
import com.hai.model.UserInfoModel;
import com.hai.service.HighApproveService;
import com.hai.service.HighCouponCodeService;
import com.hai.service.HighCouponService;
import com.hai.service.HighMerchantService;
import com.hai.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
@ -38,6 +35,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Auther: 胡锐
@ -60,6 +58,9 @@ public class HighCouponController {
@Resource
private HighCouponService highCouponService;
@Resource
private HighCouponHandselService highCouponHandselService;
@Resource
private HighCouponCodeService highCouponCodeService;
@ -155,28 +156,41 @@ public class HighCouponController {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
// 查询卡券
HighCouponModel coupon = highCouponService.getCouponById(highCoupon.getId());
if (coupon == null) {
log.error("HighCouponController -> updateCoupon() error!","未找到卡卷信息");
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, "");
}
// 是否赠送卡卷
if (highCoupon.getIsPresent() == true) {
if (highCoupon.getHandselCouponList() == null || highCoupon.getHandselCouponList().size() == 0) {
log.error("HighCouponController -> updateCoupon() error!","请选择赠送卡卷名单");
if (highCoupon.getHandselCouponId() == null || highCoupon.getHandselCouponId().size() == 0) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.SELECT_HANDSEL_COUPON_ERROR, "");
}
for (HighCouponHandsel handsel : highCoupon.getHandselCouponList()) {
// 如果没有id 就是需要增加的
if (handsel.getId() == null) {
handsel.setCreateTime(new Date());
handsel.setStatus(1); // 状态 0:删除 1:正常
handsel.setOperatorId(userInfoModel.getSecUser().getId());
handsel.setOperatorName(userInfoModel.getSecUser().getUserName());
HighCouponHandselModel highCouponHandsel;
// 上传数据与数据库对比,需要新增的数据
for (Long couponId : highCoupon.getHandselCouponId()) {
List<HighCouponHandselModel> collect = coupon.getHandselCouponList().stream().filter(o -> o.getHandselCouponId().equals(couponId)).collect(Collectors.toList());
if (collect == null || collect.size() == 0) {
highCouponHandsel = new HighCouponHandselModel();
highCouponHandsel.setHandselCouponId(couponId);
highCouponHandsel.setCreateTime(new Date());
highCouponHandsel.setStatus(1);
highCouponHandsel.setOperatorId(userInfoModel.getSecUser().getId());
highCouponHandsel.setOperatorName(userInfoModel.getSecUser().getUserName());
highCoupon.getHandselCouponList().add(highCouponHandsel);
}
}
}
// 查询卡券
HighCouponModel coupon = highCouponService.getCouponById(highCoupon.getId());
if (coupon == null) {
log.error("HighCouponController -> updateCoupon() error!","未找到卡卷信息");
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, "");
// 上传数据与数据库对比,需要删除的数据
for (HighCouponHandsel handsel : coupon.getHandselCouponList()) {
List<Long> collect = highCoupon.getHandselCouponId().stream().filter(o -> o.equals(handsel.getHandselCouponId())).collect(Collectors.toList());
if (collect == null || collect.size() == 0) {
handsel.setStatus(0);
}
}
}
// 查询商户
@ -190,7 +204,7 @@ public class HighCouponController {
highCoupon.setOperatorId(userInfoModel.getSecUser().getId());
highCoupon.setOperatorName(userInfoModel.getSecUser().getUserName());
highCoupon.setUpdateTime(new Date());
highCoupon.setStatus(3); // 状态:0.删除 1.编辑中 2.已上架 3.已下架 101.上架审批中 102.上架审批驳回
highCouponService.updateCoupon(highCoupon);
return ResponseMsgUtil.success(highCoupon);

@ -12,6 +12,9 @@ import java.util.List;
*/
public class HighCouponModel extends HighCoupon {
// 商户名称
private String merchantName;
// 库存数量
private Integer stockCount;
@ -21,6 +24,14 @@ public class HighCouponModel extends HighCoupon {
// 赠送卡卷
private List<HighCouponHandselModel> handselCouponList;
public String getMerchantName() {
return merchantName;
}
public void setMerchantName(String merchantName) {
this.merchantName = merchantName;
}
public Integer getStockCount() {
return stockCount;
}

@ -20,6 +20,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Auther: 胡锐
@ -41,6 +42,9 @@ public class HighCouponServiceImpl implements HighCouponService {
@Resource
private HighCouponCodeService highCouponCodeService;
@Resource
private HighMerchantService highMerchantService;
@Resource
private HighApproveService highApproveService;
@ -291,6 +295,7 @@ public class HighCouponServiceImpl implements HighCouponService {
if (coupons != null && coupons.size() > 0) {
List<HighCouponModel> models = JSON.parseArray(JSON.toJSONString(coupons), HighCouponModel.class);
for (HighCouponModel highCouponModel : models) {
highCouponModel.setMerchantName(highMerchantService.getMerchantById(highCouponModel.getMerchantId()).getMerchantName());
highCouponModel.setStockCount(highCouponCodeService.getStockCountByCoupon(highCouponModel.getId()));
}
return models;

Loading…
Cancel
Save