From 232320b0bdbf97e984b0d309274a9995a862c5b3 Mon Sep 17 00:00:00 2001 From: hurui <177768073@qq.com> Date: Wed, 29 Sep 2021 09:55:56 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hai/service/impl/HighOrderServiceImpl.java | 18 ++++++++++++++++++ .../pay/impl/GoodsOrderServiceImpl.java | 13 +++++++++++++ 2 files changed, 31 insertions(+) diff --git a/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java index 94e2356a..5aa9a14a 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java @@ -85,6 +85,12 @@ public class HighOrderServiceImpl implements HighOrderService { @Resource private HighOrderService highOrderService; + @Resource + private HighActivityInfoService highActivityInfoService; + + @Resource + private HighActivityUserLotteryNumService highActivityUserLotteryNumService; + @Override @Transactional(propagation= Propagation.REQUIRES_NEW) public void insertOrder(HighOrder highOrder) throws Exception { @@ -275,6 +281,12 @@ public class HighOrderServiceImpl implements HighOrderService { highUserCoupon.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用 highUserCouponMapper.insert(highUserCoupon); } + + // 查询卡券是否有活动 + Map activity = highActivityInfoService.getNewActivityByCouponId(coupon.getId()); + if (activity != null && MapUtils.getLong(activity, "id") != null) { + highActivityUserLotteryNumService.addLotteryNum(MapUtils.getLong(activity, "id"),highOrder.getMemId(), 1); + } } } @@ -429,6 +441,12 @@ public class HighOrderServiceImpl implements HighOrderService { highUserCoupon.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用 highUserCouponMapper.insert(highUserCoupon); } + + // 查询卡券是否有活动 + Map activity = highActivityInfoService.getNewActivityByCouponId(coupon.getId()); + if (activity != null && MapUtils.getLong(activity, "id") != null) { + highActivityUserLotteryNumService.addLotteryNum(MapUtils.getLong(activity, "id"),order.getMemId(), 1); + } } if (highChildOrder.getGoodsType() == 2) { diff --git a/hai-service/src/main/java/com/hai/service/pay/impl/GoodsOrderServiceImpl.java b/hai-service/src/main/java/com/hai/service/pay/impl/GoodsOrderServiceImpl.java index fe80585a..53285717 100644 --- a/hai-service/src/main/java/com/hai/service/pay/impl/GoodsOrderServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/pay/impl/GoodsOrderServiceImpl.java @@ -22,6 +22,7 @@ import com.hai.model.ResultProfitSharing; import com.hai.service.*; import com.hai.service.pay.NotifyService; import com.hai.service.pay.PayService; +import org.apache.commons.collections4.MapUtils; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpPost; @@ -81,6 +82,12 @@ public class GoodsOrderServiceImpl implements PayService { @Resource private HighCouponCodeOtherMapper highCouponCodeOtherMapper; + @Resource + private HighActivityInfoService highActivityInfoService; + + @Resource + private HighActivityUserLotteryNumService highActivityUserLotteryNumService; + @Resource private NotifyService notifyService; @@ -199,6 +206,12 @@ public class GoodsOrderServiceImpl implements PayService { highUserCoupon.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用 highUserCouponMapper.insert(highUserCoupon); } + + // 查询卡券是否有活动 + Map activity = highActivityInfoService.getNewActivityByCouponId(coupon.getId()); + if (activity != null && MapUtils.getLong(activity, "id") != null) { + highActivityUserLotteryNumService.addLotteryNum(MapUtils.getLong(activity, "id"),order.getMemId(), 1); + } } if (highChildOrder.getGoodsType() == 2) { From 3bda0d2d34182175034212dac73677b7ba240915 Mon Sep 17 00:00:00 2001 From: yuanye Date: Wed, 29 Sep 2021 17:08:49 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B4=BB=E5=8A=A8=E5=A5=96=E5=8A=B1?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/HighActivityController.java | 118 ++++++++++-------- .../hai/enum_type/ActivityAwardStatus.java | 32 +++++ .../hai/service/HighActivityAwardService.java | 51 +++----- .../hai/service/HighActivityPrizeService.java | 14 +++ .../service/HighDiscountAgentCodeService.java | 13 ++ .../impl/HighActivityAwardServiceImpl.java | 82 +++++++++--- .../HighDiscountAgentCodeServiceImpl.java | 11 ++ 7 files changed, 221 insertions(+), 100 deletions(-) create mode 100644 hai-service/src/main/java/com/hai/enum_type/ActivityAwardStatus.java create mode 100644 hai-service/src/main/java/com/hai/service/HighActivityPrizeService.java diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighActivityController.java b/hai-bweb/src/main/java/com/bweb/controller/HighActivityController.java index fc5ae656..f5a8493f 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighActivityController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighActivityController.java @@ -7,7 +7,11 @@ import com.hai.common.exception.SysCode; import com.hai.common.security.SessionObject; import com.hai.common.security.UserCenter; import com.hai.common.utils.ResponseMsgUtil; +import com.hai.entity.HighActivityAward; import com.hai.entity.HighActivityInfo; +import com.hai.entity.HighActivityPrize; +import com.hai.enum_type.ActivityAwardStatus; +import com.hai.enum_type.ActivityInfoStatus; import com.hai.model.HighUserModel; import com.hai.model.ResponseData; import com.hai.service.HighActivityAwardService; @@ -16,6 +20,7 @@ import com.hai.service.HighActivityUserLotteryNumService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; @@ -23,8 +28,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; -import java.util.HashMap; -import java.util.Map; +import java.util.*; /** * @@ -40,75 +44,89 @@ public class HighActivityController { @Resource private UserCenter userCenter; - @Resource - private HighActivityInfoService highActivityInfoService; - @Resource private HighActivityAwardService highActivityAwardService; @Resource private HighActivityUserLotteryNumService highActivityUserLotteryNumService; - @RequestMapping(value="/edit",method = RequestMethod.POST) + @RequestMapping(value="/editActivityAward",method = RequestMethod.POST) @ResponseBody - @ApiOperation(value = "用户抽奖业务") + @ApiOperation(value = "新增中奖名次") public ResponseData userLottery(@RequestBody JSONObject body, HttpServletRequest request) { try { - // 用户 - SessionObject sessionObject = userCenter.getSessionObject(request); - HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); - if (body == null || body.getLong("activityId") == null) { - log.error("HighActivityController --> lottery() error!", "参数错误"); + if (body == null + || body.getLong("activityInfoId") == null + || StringUtils.isBlank(body.getString("img")) + || StringUtils.isBlank(body.getString("name")) + || body.getInteger("num") == null + ) { + log.error("HighActivityController -> editActivityAward() error!","参数错误"); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); } - return ResponseMsgUtil.success(highActivityUserLotteryNumService.userLottery(body.getLong("activityId"),userInfoModel.getHighUser().getId())); + HighActivityPrize activityPrize; + List activityPrizes = new ArrayList<>(); - } catch (Exception e) { - log.error("HighActivityController -> userLottery() error!",e); - return ResponseMsgUtil.exception(e); - } - } + // 组装奖品 + if (body.getJSONArray("activityPrizes") != null && body.getJSONArray("activityPrizes").size() > 0) { + for (Object object : body.getJSONArray("ruleArray")) { + JSONObject activityObject = (JSONObject)object; + if ( + activityObject.getInteger("prizeType") == null || + activityObject.getLong("prizeId") == null || + StringUtils.isBlank(activityObject.getString("prizeName")) || + activityObject.getInteger("prizeNum") == null + ) { + log.error("HighActivityController -> editActivityAward() error!","参数错误"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); + } - @RequestMapping(value="/getActivityByCoupon",method = RequestMethod.GET) - @ResponseBody - @ApiOperation(value = "根据卡券查询活动信息") - public ResponseData getActivityByCoupon(@RequestParam(name = "couponId", required = true) Long couponId) { - try { - // 查询活动 - Map activity = highActivityInfoService.getNewActivityByCouponId(couponId); - if (activity != null) { - Map map = new HashMap<>(); - map.put("activityInfo", activity); - map.put("activityAward", highActivityAwardService.getListByActivityId(MapUtils.getLong(activity, "id"))); - return ResponseMsgUtil.success(map); + activityPrize = new HighActivityPrize(); + + activityPrize.setPrizeType(activityObject.getInteger("prizeType")); + activityPrize.setPrizeId(activityObject.getLong("prizeId")); + activityPrize.setPrizeName(activityObject.getString("prizeName")); + activityPrize.setPrizeNum(activityObject.getInteger("prizeNum")); + activityPrize.setExt1(activityObject.getString("agentId")); + activityPrizes.add(activityPrize); + + } } - return ResponseMsgUtil.success(null); - } catch (Exception e) { - log.error("HighActivityController -> getActivityByCoupon() error!",e); - return ResponseMsgUtil.exception(e); - } - } + HighActivityAward highActivityAward; - @RequestMapping(value="/getDetail",method = RequestMethod.GET) - @ResponseBody - @ApiOperation(value = "查询活动详情") - public ResponseData getDetail(@RequestParam(name = "activityId", required = true) Long activityId) { - try { - // 查询活动 - HighActivityInfo detail = highActivityInfoService.getDetailById(activityId); - if (detail != null) { - Map map = new HashMap<>(); - map.put("activityInfo", detail); - map.put("activityAward", highActivityAwardService.getListByActivityId(detail.getId())); - return ResponseMsgUtil.success(map); + if (body.getLong("id") != null) { + highActivityAward = highActivityAwardService.getDetailById(body.getLong("id")); + if (highActivityAward == null) { + log.error("HighActivityInfoController -> editActivityInfo() error!","未找到活动信息"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到活动信息"); + } + if (highActivityAward.getStatus().equals(ActivityAwardStatus.status0.getNumber())) { + log.error("HighActivityInfoController -> editActivityInfo() error!","状态错误"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.STATUS_ERROR, ""); + } + } else { + highActivityAward = new HighActivityAward(); } - return ResponseMsgUtil.success(null); + + // 组装奖励 + highActivityAward.setActivityInfoId(body.getLong("activityInfoId")); + highActivityAward.setImg(body.getString("img")); + highActivityAward.setName(body.getString("name")); + highActivityAward.setNum(body.getInteger("num")); + + + highActivityAwardService.editHighActivateAward(highActivityAward , activityPrizes); + + return ResponseMsgUtil.success("1"); + } catch (Exception e) { - log.error("HighActivityController -> getDetail() error!",e); + log.error("HighActivityController -> userLottery() error!",e); return ResponseMsgUtil.exception(e); } } + + } diff --git a/hai-service/src/main/java/com/hai/enum_type/ActivityAwardStatus.java b/hai-service/src/main/java/com/hai/enum_type/ActivityAwardStatus.java new file mode 100644 index 00000000..c993bca0 --- /dev/null +++ b/hai-service/src/main/java/com/hai/enum_type/ActivityAwardStatus.java @@ -0,0 +1,32 @@ +package com.hai.enum_type; + +public enum ActivityAwardStatus { + status0(0, "删除"), + status1(1, "正常"), + ; + + private Integer number; + + private String name; + + ActivityAwardStatus(int number, String name) { + this.number = number; + this.name = name; + } + + public Integer getNumber() { + return number; + } + + public void setNumber(Integer number) { + this.number = number; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/hai-service/src/main/java/com/hai/service/HighActivityAwardService.java b/hai-service/src/main/java/com/hai/service/HighActivityAwardService.java index 0f9f87c5..45989a96 100644 --- a/hai-service/src/main/java/com/hai/service/HighActivityAwardService.java +++ b/hai-service/src/main/java/com/hai/service/HighActivityAwardService.java @@ -21,44 +21,23 @@ public interface HighActivityAwardService { List getListByActivityId(Long activityId); /** - * @params highActivityAward - * @return void - * @author sum1dream - * @description 编辑活动奖励名次 - * @date 2021/9/28 11:35 下午 - * @version: 1.0.0 - */ - void editHighActivateAward(HighActivityAward highActivityAward); - - /** - * @params highActivityPrize - * @return void - * @author sum1dream - * @description 编辑活动奖品 - * @date 2021/9/28 11:37 下午 - * @version: 1.0.0 - */ - void editHighActivatePrize(HighActivityPrize highActivityPrize); + * @Author Sum1Dream + * @name getDetailById.java + * @Description // 查询详情 + * @Date 10:22 2021/9/29 + * @Param [id] + * @return com.hai.entity.HighActivityAward + **/ + HighActivityAward getDetailById(Long id); /** - * @params HighActivityAwardSerialNum + * @Author Sum1Dream + * @name editHighActivateAward.java + * @Description //编辑活动奖励名次 + * @Date 9:33 2021/9/29 + * @Param [highActivityAward] * @return void - * @author sum1dream - * @description 增加活动将池 - * @date 2021/9/28 11:38 下午 - * @version: 1.0.0 - */ - void addHighActivityAwardSerialNum(HighActivityAwardSerialNum highActivityAwardSerialNum); - - /** - * @params HighActivityAwardActualPrize - * @return void - * @author sum1dream - * @description 增加实际奖品 - * @date 2021/9/28 11:40 下午 - * @version: 1.0.0 - */ - void addHighActivityAwardActualPrize(HighActivityAwardActualPrize highActivityAwardActualPrize); - + **/ + void editHighActivateAward(HighActivityAward highActivityAward , List highActivityPrizes) throws Exception ; } diff --git a/hai-service/src/main/java/com/hai/service/HighActivityPrizeService.java b/hai-service/src/main/java/com/hai/service/HighActivityPrizeService.java new file mode 100644 index 00000000..189be0ed --- /dev/null +++ b/hai-service/src/main/java/com/hai/service/HighActivityPrizeService.java @@ -0,0 +1,14 @@ +package com.hai.service; + +import com.hai.entity.HighActivityAward; + +import java.util.List; + +/** + * 活动奖励 + * @author hurui + */ +public interface HighActivityPrizeService { + + +} diff --git a/hai-service/src/main/java/com/hai/service/HighDiscountAgentCodeService.java b/hai-service/src/main/java/com/hai/service/HighDiscountAgentCodeService.java index a3c60cee..d8539d52 100644 --- a/hai-service/src/main/java/com/hai/service/HighDiscountAgentCodeService.java +++ b/hai-service/src/main/java/com/hai/service/HighDiscountAgentCodeService.java @@ -40,6 +40,17 @@ public interface HighDiscountAgentCodeService { **/ List getDiscountCode(Map map); + + /** + * @Author Sum1Dream + * @name getDiscountCodeByDiscountAgentId.java + * @Description // 根据关系id 查询 未领取的卡券 + * @Date 14:20 2021/9/29 + * @Param [discountAgentId] + * @return java.util.List + **/ + List getDiscountCodeByDiscountAgentId(Long discountAgentId , Integer num); + /** * @Author 胡锐 * @Description 根据id 查询二维码 @@ -47,6 +58,8 @@ public interface HighDiscountAgentCodeService { **/ HighDiscountAgentCode getCodeById(Long id); + + /** * 查询已分配的优惠券总数 * @param discountAgentId diff --git a/hai-service/src/main/java/com/hai/service/impl/HighActivityAwardServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighActivityAwardServiceImpl.java index 5868abb9..0d73e77e 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighActivityAwardServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighActivityAwardServiceImpl.java @@ -1,14 +1,23 @@ package com.hai.service.impl; +import com.hai.common.utils.DateUtil; +import com.hai.common.utils.IDGenerator; import com.hai.dao.HighActivityAwardActualPrizeMapper; import com.hai.dao.HighActivityAwardMapper; import com.hai.dao.HighActivityAwardSerialNumMapper; import com.hai.dao.HighActivityPrizeMapper; import com.hai.entity.*; +import com.hai.enum_type.ActivityAwardStatus; +import com.hai.enum_type.ActivityInfoStatus; import com.hai.service.HighActivityAwardService; +import com.hai.service.HighDiscountAgentCodeService; +import com.hai.service.HighDiscountAgentRelService; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.util.Date; import java.util.List; @Service("activityAwardService") @@ -21,10 +30,14 @@ public class HighActivityAwardServiceImpl implements HighActivityAwardService { private HighActivityPrizeMapper highActivityPrizeMapper; @Resource - private HighActivityAwardSerialNumMapper highActivityAwardSerialNumMapper; + private HighActivityAwardSerialNumMapper highActivityAwardSerialNumM; @Resource - private HighActivityAwardActualPrizeMapper highActivityAwardActualPrizeMapper; + private HighDiscountAgentRelService highDiscountAgentRelService; + + @Resource + private HighDiscountAgentCodeService highDiscountAgentCodeService; + @Override public List getListByActivityId(Long activityId) { @@ -34,22 +47,63 @@ public class HighActivityAwardServiceImpl implements HighActivityAwardService { } @Override - public void editHighActivateAward(HighActivityAward highActivityAward) { - highActivityAwardMapper.insert(highActivityAward); - } + @Transactional(rollbackFor=Exception.class,propagation= Propagation.REQUIRES_NEW) + public void editHighActivateAward(HighActivityAward highActivityAward, List highActivityPrizes) throws Exception { + + // 增加奖励 + if (highActivityAward.getId() == null) { + highActivityAward.setCreateTime(new Date()); + highActivityAward.setUpdateTime(new Date()); + highActivityAward.setStatus(ActivityAwardStatus.status1.getNumber()); + highActivityAwardMapper.insert(highActivityAward); + } else { + highActivityAward.setUpdateTime(new Date()); + highActivityAwardMapper.updateByPrimaryKey(highActivityAward); + } + + HighActivityAwardSerialNum serialNum; + + HighActivityAwardActualPrize actualPrize; + + for (int i = 0; i < highActivityAward.getNum(); i++) { + serialNum = new HighActivityAwardSerialNum(); + serialNum.setActivityInfoId(highActivityAward.getActivityInfoId()); + serialNum.setActivityAwardId(highActivityAward.getId()); + serialNum.setSerialNum("HFA" + DateUtil.date2String(new Date(),"yyyyMMddHHmmss") + IDGenerator.nextId(5)); + serialNum.setStatus(1); + serialNum.setCreateTime(new Date()); + highActivityAwardSerialNumM.insert(serialNum); + + // 增加奖品 + for (HighActivityPrize list : highActivityPrizes) { + list.setActivityAwardId(highActivityAward.getId()); + list.setCreateTime(new Date()); + list.setStatus(1); + highActivityPrizeMapper.insert(list); + HighDiscountAgentRel discountAgentRel = highDiscountAgentRelService.getRelByDiscountAgent(list.getPrizeId() , Long.valueOf(list.getExt1())); + + List codeList = highDiscountAgentCodeService.getDiscountCodeByDiscountAgentId(discountAgentRel.getId() , list.getPrizeNum()); + + for (HighDiscountAgentCode agentCode: codeList) { + actualPrize = new HighActivityAwardActualPrize(); + actualPrize.setActivityAwardPrizeId(list.getId()); + actualPrize.setActivityAwardSerialNumId(serialNum.getId()); + actualPrize.setActualPrizeType(2); + actualPrize.setActualPrizeId(agentCode.getId()); + actualPrize.setStatus(1); + actualPrize.setCreateTime(new Date()); + } + + } + + } + - @Override - public void editHighActivatePrize(HighActivityPrize highActivityPrize) { - highActivityPrizeMapper.insert(highActivityPrize); - } - @Override - public void addHighActivityAwardSerialNum(HighActivityAwardSerialNum highActivityAwardSerialNum) { - highActivityAwardSerialNumMapper.insert(highActivityAwardSerialNum); } @Override - public void addHighActivityAwardActualPrize(HighActivityAwardActualPrize highActivityAwardActualPrize) { - highActivityAwardActualPrizeMapper.insert(highActivityAwardActualPrize); + public HighActivityAward getDetailById(Long id) { + return highActivityAwardMapper.selectByPrimaryKey(id); } } diff --git a/hai-service/src/main/java/com/hai/service/impl/HighDiscountAgentCodeServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighDiscountAgentCodeServiceImpl.java index 45722aaf..d345bc13 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighDiscountAgentCodeServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighDiscountAgentCodeServiceImpl.java @@ -91,6 +91,17 @@ public class HighDiscountAgentCodeServiceImpl implements HighDiscountAgentCodeSe return list; } + @Override + public List getDiscountCodeByDiscountAgentId(Long discountAgentId , Integer num) { + + HighDiscountAgentCodeExample example = new HighDiscountAgentCodeExample(); + HighDiscountAgentCodeExample.Criteria criteria = example.createCriteria(); + criteria.andDiscountAgentIdEqualTo(discountAgentId).andStatusEqualTo(1); + example.setLimit(num); + example.setOrderByClause("create_time desc"); + return highDiscountAgentCodeMapper.selectByExample(example); + } + @Override public HighDiscountAgentCode getCodeById(Long id) { return highDiscountAgentCodeMapper.selectByPrimaryKey(id);