From 88b54772dbcf5ecab1e2316e4e4626ac901b8908 Mon Sep 17 00:00:00 2001 From: yujian <yujian> Date: 星期二, 22 一月 2019 15:58:24 +0800 Subject: [PATCH] 邀请码添加返回状态 --- fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoV2ServiceImpl.java | 277 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 225 insertions(+), 52 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoV2ServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoV2ServiceImpl.java index 0b86e42..51df0e4 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoV2ServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/hongbao/HongBaoV2ServiceImpl.java @@ -6,9 +6,11 @@ import java.util.Comparator; import java.util.Date; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Set; import javax.annotation.Resource; @@ -26,6 +28,7 @@ import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoOrderMapper; import com.yeshi.fanli.dao.mybatis.taobao.TaoBaoWeiQuanOrderMapper; import com.yeshi.fanli.dto.HongBaoDTO; +import com.yeshi.fanli.entity.bus.msg.MsgOrderDetail; import com.yeshi.fanli.entity.bus.user.HongBao; import com.yeshi.fanli.entity.bus.user.HongBaoV2; import com.yeshi.fanli.entity.bus.user.UserInfo; @@ -41,6 +44,7 @@ import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService; import com.yeshi.fanli.service.inter.hongbao.HongBaoV2Service; import com.yeshi.fanli.service.inter.hongbao.ThreeSaleSerivce; +import com.yeshi.fanli.service.inter.msg.UserOrderMsgNotificationService; import com.yeshi.fanli.service.inter.order.CommonOrderService; import com.yeshi.fanli.service.inter.user.UserInfoService; import com.yeshi.fanli.service.inter.user.UserNotificationService; @@ -91,6 +95,18 @@ @Resource private PidOrderMapper pidOrderMapper; + + @Resource + private HongBaoManageService hongBaoManageService; + + @Resource + private ThreeSaleSerivce threeSaleSerivce; + + @Resource + private UserNotificationService userNotificationService; + + @Resource + private UserOrderMsgNotificationService userOrderMsgNotificationService; @Override public int insert(HongBaoV2 record) { @@ -346,61 +362,122 @@ } - @Resource - private HongBaoManageService hongBaoManageService; - - @Resource - private ThreeSaleSerivce threeSaleSerivce; - - @Resource - private UserNotificationService userNotificationService; - @Transactional @Override public void addHongBao(List<CommonOrder> commonOrderList, int type) throws HongBaoException { - + Set<Integer> stateSet = new HashSet<>();// 璁㈠崟鐘舵�丼et if (commonOrderList != null && commonOrderList.size() > 0) { - Map<Integer, HongBaoV2> notificationMap = new HashMap<>(); + Map<Integer, HongBaoOrder> notificationMap = new HashMap<>(); + int goodsCount = 0; + boolean hasAdd = false; for (CommonOrder commonOrder : commonOrderList) { + stateSet.add(commonOrder.getState()); + goodsCount += commonOrder.getCount(); if (commonOrder == null || commonOrder.getId() == null || commonOrder.getUserInfo() == null) throw new HongBaoException(1, "璁㈠崟淇℃伅涓嶅畬鏁�"); HongBaoOrder hongBaoOrder = hongBaoOrderMapper.selectByCommonOrderId(commonOrder.getId()); if (hongBaoOrder == null) { saveHongBao(commonOrder, type, notificationMap); + hasAdd = true; } else { - updateHongBao(hongBaoOrder, commonOrder, type); + updateHongBao(hongBaoOrder, commonOrder, type, notificationMap); } } /** * 閫氱煡鐢ㄦ埛鐨勮繑鍒╂儏鍐� */ - Iterator<Integer> its = notificationMap.keySet().iterator(); - while (its.hasNext()) { - Integer t = its.next(); - HongBaoV2 notify = notificationMap.get(t); - String orderId = commonOrderList.get(0).getOrderNo(); - Long uid = notify.getUserInfo().getId(); - BigDecimal money = notify.getMoney(); - switch (t) { - case HongBaoV2.TYPE_ZIGOU: - userNotificationService.orderFanliStatisticed(uid, orderId); - break; - case HongBaoV2.TYPE_SHARE_GOODS: - userNotificationService.orderShareStatisticed(uid, orderId, money); - break; - case HongBaoV2.TYPE_YIJI: - userNotificationService.orderInviteStatisticed(uid, orderId, money); - break; - case HongBaoV2.TYPE_ERJI: - userNotificationService.orderInviteStatisticed(uid, orderId, money); - break; + int state = getOrderState(stateSet); + if (hasAdd) { + Iterator<Integer> its = notificationMap.keySet().iterator(); + while (its.hasNext()) { + + Integer t = its.next(); + HongBaoV2 notify = notificationMap.get(t).getHongBaoV2(); + CommonOrder commonOrder = notificationMap.get(t).getCommonOrder(); + String orderId = commonOrderList.get(0).getOrderNo(); + Long uid = notify.getUserInfo().getId(); + BigDecimal money = notify.getMoney(); + switch (t) { + case HongBaoV2.TYPE_ZIGOU: + userNotificationService.orderFanliStatisticed(uid, orderId, goodsCount, MsgOrderDetail.STATE_FK, + null, money); + userOrderMsgNotificationService.orderFanLiStatistic(uid, orderId, commonOrder.getPayment(), + money, goodsCount, state); + break; + case HongBaoV2.TYPE_SHARE_GOODS: + userNotificationService.orderShareStatisticed(uid, orderId, goodsCount, MsgOrderDetail.STATE_FK, + null, money); + userOrderMsgNotificationService.orderShareStatistic(uid, orderId, commonOrder.getPayment(), + money, goodsCount, state); + break; + case HongBaoV2.TYPE_YIJI: + userNotificationService.orderInviteStatisticed(uid, orderId, goodsCount, + MsgOrderDetail.STATE_FK, null, money); + userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, commonOrder.getPayment(), + money, goodsCount, state); + break; + case HongBaoV2.TYPE_ERJI: + userNotificationService.orderInviteStatisticed(uid, orderId, goodsCount, + MsgOrderDetail.STATE_FK, null, money); + userOrderMsgNotificationService.orderInviteStatistic(uid, orderId, commonOrder.getPayment(), + money, goodsCount, state); + break; + } + } + } + + // 娣诲姞鏂扮増鏈�氱煡 + + if (!hasAdd) { + Iterator<Integer> its = notificationMap.keySet().iterator(); + while (its.hasNext()) { + Integer t = its.next(); + HongBaoV2 notify = notificationMap.get(t).getHongBaoV2(); + CommonOrder commonOrder = notificationMap.get(t).getCommonOrder(); + String orderId = commonOrderList.get(0).getOrderNo(); + Long uid = notify.getUserInfo().getId(); + BigDecimal money = notify.getMoney(); + switch (t) { + case HongBaoV2.TYPE_ZIGOU: + userOrderMsgNotificationService.orderFanLiStateChanged(uid, orderId, commonOrder.getPayment(), + money, state); + break; + case HongBaoV2.TYPE_SHARE_GOODS: + userOrderMsgNotificationService.orderShareStateChanged(uid, orderId, commonOrder.getPayment(), + money, state); + break; + case HongBaoV2.TYPE_YIJI: + userOrderMsgNotificationService.orderInviteStateChanged(uid, orderId, commonOrder.getPayment(), + money, state); + break; + case HongBaoV2.TYPE_ERJI: + userOrderMsgNotificationService.orderInviteStateChanged(uid, orderId, commonOrder.getPayment(), + money, state); + break; + } } } } + + } + + private int getOrderState(Set<Integer> states) { + if (states.size() == 1) + return states.iterator().next(); + Iterator<Integer> its = states.iterator(); + while (its.hasNext()) { + int tempState = its.next(); + if (tempState == CommonOrder.STATE_FK) + return CommonOrder.STATE_FK; + else if (tempState == CommonOrder.STATE_JS) + return CommonOrder.STATE_JS; + } + return CommonOrder.STATE_SX; } @Transactional - private void updateHongBao(HongBaoOrder hongBaoOrder, CommonOrder commonOrder, int type) throws HongBaoException { + private void updateHongBao(HongBaoOrder hongBaoOrder, CommonOrder commonOrder, int type, + Map<Integer, HongBaoOrder> notificationMap) throws HongBaoException { System.out.println(commonOrder.getOrderNo()); HongBaoV2 oldHongBao = hongBaoV2Mapper.selectByPrimaryKey(hongBaoOrder.getHongBaoV2().getId()); if (oldHongBao == null) @@ -428,6 +505,24 @@ hongBao.setMoney(new BigDecimal(0)); } hongBaoV2Mapper.updateByPrimaryKeySelective(hongBao); + + // 鍔犲叆閫氱煡 + if (notificationMap.get(type) == null) { + HongBaoV2 tempHongBao = new HongBaoV2(oldHongBao.getId()); + tempHongBao.setUserInfo(oldHongBao.getUserInfo()); + tempHongBao.setMoney(hongBao.getMoney()); + CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId()); + tempCommonOrder.setPayment(commonOrder.getPayment()); + notificationMap.put(type, new HongBaoOrder(tempCommonOrder, tempHongBao)); + } else { + // 澧炲姞浠樻閲戦涓庤祫閲� + HongBaoOrder tempHongBaoOrder = notificationMap.get(type); + tempHongBaoOrder.getCommonOrder() + .setPayment(tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment())); + tempHongBaoOrder.getHongBaoV2() + .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(hongBao.getMoney())); + notificationMap.put(type, tempHongBaoOrder); + } // 鑾峰彇瀛愮孩鍖� List<HongBaoV2> children = hongBaoV2Mapper.listChildrenById(hongBao.getId()); @@ -460,6 +555,25 @@ MoneyBigDecimalUtil.mul(hongBao.getMoney(), rate.divide(new BigDecimal(100)))); } hongBaoV2Mapper.updateByPrimaryKeySelective(childUpdate); + + // 鍔犲叆閫氱煡 + if (notificationMap.get(type) == null) { + HongBaoV2 tempHongBao = new HongBaoV2(child.getId()); + tempHongBao.setUserInfo(child.getUserInfo()); + tempHongBao.setMoney(child.getMoney()); + CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId()); + tempCommonOrder.setPayment(commonOrder.getPayment()); + notificationMap.put(type, new HongBaoOrder(tempCommonOrder, tempHongBao)); + } else { + // 澧炲姞浠樻閲戦涓庤祫閲� + HongBaoOrder tempHongBaoOrder = notificationMap.get(type); + tempHongBaoOrder.getCommonOrder().setPayment( + tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment())); + tempHongBaoOrder.getHongBaoV2() + .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(child.getMoney())); + notificationMap.put(type, tempHongBaoOrder); + } + } } else if (type == HongBaoV2.TYPE_SHARE_GOODS) { @@ -485,6 +599,23 @@ hongBao.setMoney(new BigDecimal(0)); } hongBaoV2Mapper.updateByPrimaryKeySelective(hongBao); + // 閫氱煡 + if (notificationMap.get(type) == null) { + HongBaoV2 tempHongBao = new HongBaoV2(hongBao.getId()); + tempHongBao.setUserInfo(hongBao.getUserInfo()); + tempHongBao.setMoney(hongBao.getMoney()); + CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId()); + tempCommonOrder.setPayment(commonOrder.getPayment()); + notificationMap.put(type, new HongBaoOrder(tempCommonOrder, tempHongBao)); + } else { + // 澧炲姞浠樻閲戦涓庤祫閲� + HongBaoOrder tempHongBaoOrder = notificationMap.get(type); + tempHongBaoOrder.getCommonOrder() + .setPayment(tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment())); + tempHongBaoOrder.getHongBaoV2() + .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(hongBao.getMoney())); + notificationMap.put(type, tempHongBaoOrder); + } // 鑾峰彇瀛愮孩鍖� List<HongBaoV2> children = hongBaoV2Mapper.listChildrenById(hongBao.getId()); @@ -527,7 +658,7 @@ } @Transactional - private void saveHongBao(CommonOrder commonOrder, int type, Map<Integer, HongBaoV2> notificationMap) + private void saveHongBao(CommonOrder commonOrder, int type, Map<Integer, HongBaoOrder> notificationMap) throws HongBaoException { if (type == HongBaoV2.TYPE_ZIGOU) {// 鑾峰彇鑷喘鐨勮繑鍒╂瘮渚� BigDecimal fanliRate = hongBaoManageService.getFanLiRate(commonOrder.getCreateTime().getTime()); @@ -561,10 +692,21 @@ hongBaoOrder.setHongBaoV2(hongBao); hongBaoOrderMapper.insertSelective(hongBaoOrder); // 鍔犲叆閫氱煡 - if (notificationMap.get(type) == null) - notificationMap.put(type, hongBao); - else { - notificationMap.get(type).setMoney(notificationMap.get(type).getMoney().add(hongBao.getMoney())); + if (notificationMap.get(type) == null) { + HongBaoV2 tempHongBao = new HongBaoV2(hongBao.getId()); + tempHongBao.setUserInfo(hongBao.getUserInfo()); + tempHongBao.setMoney(hongBao.getMoney()); + CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId()); + tempCommonOrder.setPayment(commonOrder.getPayment()); + notificationMap.put(type, new HongBaoOrder(tempCommonOrder, tempHongBao)); + } else { + // 澧炲姞浠樻閲戦涓庤祫閲� + HongBaoOrder tempHongBaoOrder = notificationMap.get(type); + tempHongBaoOrder.getCommonOrder() + .setPayment(tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment())); + tempHongBaoOrder.getHongBaoV2() + .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(hongBao.getMoney())); + notificationMap.put(type, tempHongBaoOrder); } UserInfo boss = threeSaleSerivce.getBoss(user.getId()); @@ -599,11 +741,21 @@ } hongBaoV2Mapper.insertSelective(firstHongbao); // 鐢ㄦ埛閫氱煡 - if (notificationMap.get(HongBaoV2.TYPE_YIJI) == null) - notificationMap.put(HongBaoV2.TYPE_YIJI, firstHongbao); - else { - notificationMap.get(HongBaoV2.TYPE_YIJI) - .setMoney(notificationMap.get(HongBaoV2.TYPE_YIJI).getMoney().add(firstHongbao.getMoney())); + if (notificationMap.get(HongBaoV2.TYPE_YIJI) == null) { + HongBaoV2 tempHongBao = new HongBaoV2(firstHongbao.getId()); + tempHongBao.setUserInfo(firstHongbao.getUserInfo()); + tempHongBao.setMoney(firstHongbao.getMoney()); + CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId()); + tempCommonOrder.setPayment(commonOrder.getPayment()); + notificationMap.put(HongBaoV2.TYPE_YIJI, new HongBaoOrder(tempCommonOrder, tempHongBao)); + } else { + // 澧炲姞浠樻閲戦涓庤祫閲� + HongBaoOrder tempHongBaoOrder = notificationMap.get(HongBaoV2.TYPE_YIJI); + tempHongBaoOrder.getCommonOrder() + .setPayment(tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment())); + tempHongBaoOrder.getHongBaoV2() + .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(firstHongbao.getMoney())); + notificationMap.put(HongBaoV2.TYPE_YIJI, tempHongBaoOrder); } // 鎻掑叆浜岀骇瀛愮孩鍖� @@ -637,11 +789,21 @@ hongBaoV2Mapper.insertSelective(secondHongbao); // 鐢ㄦ埛閫氱煡 - if (notificationMap.get(HongBaoV2.TYPE_ERJI) == null) - notificationMap.put(HongBaoV2.TYPE_ERJI, secondHongbao); - else { - notificationMap.get(HongBaoV2.TYPE_ERJI).setMoney( - notificationMap.get(HongBaoV2.TYPE_ERJI).getMoney().add(secondHongbao.getMoney())); + if (notificationMap.get(HongBaoV2.TYPE_ERJI) == null) { + HongBaoV2 tempHongBao = new HongBaoV2(secondHongbao.getId()); + tempHongBao.setUserInfo(secondHongbao.getUserInfo()); + tempHongBao.setMoney(secondHongbao.getMoney()); + CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId()); + tempCommonOrder.setPayment(commonOrder.getPayment()); + notificationMap.put(HongBaoV2.TYPE_ERJI, new HongBaoOrder(tempCommonOrder, tempHongBao)); + } else { + // 澧炲姞浠樻閲戦涓庤祫閲� + HongBaoOrder tempHongBaoOrder = notificationMap.get(HongBaoV2.TYPE_ERJI); + tempHongBaoOrder.getCommonOrder().setPayment( + tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment())); + tempHongBaoOrder.getHongBaoV2() + .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(secondHongbao.getMoney())); + notificationMap.put(HongBaoV2.TYPE_ERJI, tempHongBaoOrder); } } @@ -682,10 +844,21 @@ hongBaoOrder.setHongBaoV2(hongBao); hongBaoOrderMapper.insertSelective(hongBaoOrder); - if (notificationMap.get(type) == null) - notificationMap.put(type, hongBao); - else { - notificationMap.get(type).setMoney(notificationMap.get(type).getMoney().add(hongBao.getMoney())); + if (notificationMap.get(type) == null) { + HongBaoV2 tempHongBao = new HongBaoV2(hongBao.getId()); + tempHongBao.setUserInfo(hongBao.getUserInfo()); + tempHongBao.setMoney(hongBao.getMoney()); + CommonOrder tempCommonOrder = new CommonOrder(commonOrder.getId()); + tempCommonOrder.setPayment(commonOrder.getPayment()); + notificationMap.put(type, new HongBaoOrder(tempCommonOrder, tempHongBao)); + } else { + // 澧炲姞浠樻閲戦涓庤祫閲� + HongBaoOrder tempHongBaoOrder = notificationMap.get(type); + tempHongBaoOrder.getCommonOrder() + .setPayment(tempHongBaoOrder.getCommonOrder().getPayment().add(commonOrder.getPayment())); + tempHongBaoOrder.getHongBaoV2() + .setMoney(tempHongBaoOrder.getHongBaoV2().getMoney().add(hongBao.getMoney())); + notificationMap.put(type, tempHongBaoOrder); } // 淇敼缁熻鏁版嵁 -- Gitblit v1.8.0