From 2d0fedf897b02dfc127772e0f99a39e07a9ba908 Mon Sep 17 00:00:00 2001 From: gongbiao Date: Thu, 14 Mar 2019 18:27:17 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=8B=BC=E5=9B=A2][=E4=BF=AE=E6=94=B9][?= =?UTF-8?q?=E6=88=91=E7=9A=84=E6=8B=BC=E5=9B=A2]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/iformall/mapper/WxOrderMapper.java | 3 ++ .../service/impl/WxOrderGroupServiceImpl.java | 40 +++++++------------ .../resources/mapper/WxOrderGroupMapper.xml | 5 ++- 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxOrderMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxOrderMapper.java index a842baf02..bac3c953a 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxOrderMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxOrderMapper.java @@ -2,6 +2,7 @@ package com.iformall.mapper; import com.iformall.common.CommonMapper; import com.iformall.domain.po.WxOrder; +import com.iformall.domain.po.WxOrderGroup; import com.iformall.domain.vo.*; import java.util.HashMap; @@ -44,4 +45,6 @@ public interface WxOrderMapper extends CommonMapper { void updateStatusByOrderGroupId(WxOrder order); + int updateOrderGroup(WxOrderGroup wxOrderGroup); + } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxOrderGroupServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxOrderGroupServiceImpl.java index b9215642b..cfa85da15 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxOrderGroupServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxOrderGroupServiceImpl.java @@ -68,39 +68,27 @@ public class WxOrderGroupServiceImpl implements WxOrderGroupService { Long notOrderGroupId = 0L; //查看是否首次拼团,orderGroupId不等于0代表不是首次拼团,因为第二个加入的拼团者肯定有团单号 if (!orderGroupId.equals(notOrderGroupId)) { - long time = System.currentTimeMillis() + RedisLock.TIMEOUT; - String timeStr = String.valueOf(time); - // 团单加锁 - String orderGroupIdStr = String.valueOf(orderGroupId); - WxOrderGroup wxOrderGroup = null; - while (!redisLock.lock(orderGroupIdStr, timeStr)) { - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - logger.error("订单休眠失败"); - } - } - wxOrderGroup = wxOrderGroupMapper.selectByPrimaryKey(orderGroupId); - if (wxOrderGroup.getRemainPeople() == 0) { - //修改订单状态后定时退款 + WxOrderGroup wxOrderGroup = new WxOrderGroup(); + wxOrderGroup.setId(orderGroupId); + wxOrderGroup.setUpdateDate(new Date()); + logger.info("非首次拼团,更新拼团信息"); + int row = wxOrderMapper.updateOrderGroup(wxOrderGroup); + if (row == 0) { + //参团失败 修改订单状态后定时退款 order.setOrderStatus(EnumOrderStatus.ORDER_STATUS_COOPERATING_FAILD.getCode()); wxOrderMapper.updateByPrimaryKeySelective(order); - redisLock.unlock(orderGroupIdStr, timeStr); throw new MallinkException(ErrorCode.ORDER_GROUP_COOPERATING_FAILD); } - redisLock.unlock(orderGroupIdStr, timeStr); - - logger.info("非首次拼团,更新拼团信息"); - int remainPeople = wxOrderGroup.getRemainPeople() - 1; + wxOrderGroup = wxOrderGroupMapper.selectByPrimaryKey(orderGroupId); + Integer remainPeople = wxOrderGroup.getRemainPeople(); int endPeople = 0; wxOrderGroup.setStatus(remainPeople == endPeople ? EnumOrderStatus.ORDER_STATUS_COOPERATING_COMPLETE.getCode() : wxOrderGroup.getStatus()); - wxOrderGroup.setRemainPeople(remainPeople); wxOrderGroup.setUpdateDate(new Date()); try { wxOrderGroupMapper.updateByPrimaryKeySelective(wxOrderGroup); } catch (Exception e) { logger.error("更新拼团信息失败", e); - throw new MallinkException(ErrorCode.DB_FAIL); + throw new MallinkException(ErrorCode.ORDER_GROUP_COOPERATING_FAILD); } //更新order order.setOrderStatus(wxOrderGroup.getStatus()); @@ -110,7 +98,7 @@ public class WxOrderGroupServiceImpl implements WxOrderGroupService { wxOrderMapper.updateByPrimaryKey(order); } catch (Exception e) { logger.error("更新订单信息失败", e); - throw new MallinkException(ErrorCode.DB_FAIL); + throw new MallinkException(ErrorCode.ORDER_GROUP_COOPERATING_FAILD); } if (remainPeople == endPeople) { //得到所有拼团的order @@ -127,7 +115,7 @@ public class WxOrderGroupServiceImpl implements WxOrderGroupService { wxOrderService.couponOrderSuccess(temp); } catch (Exception e) { logger.error("创建COUPON_ORDER失败", e); - throw new MallinkException(ErrorCode.DB_FAIL); + throw new MallinkException(ErrorCode.ORDER_GROUP_COOPERATING_FAILD); } } } @@ -155,7 +143,7 @@ public class WxOrderGroupServiceImpl implements WxOrderGroupService { wxOrderGroupMapper.insertSelective(wxOrderGroup); } catch (Exception e) { logger.error("创建拼团信息失败", e); - throw new MallinkException(ErrorCode.DB_FAIL); + throw new MallinkException(ErrorCode.ORDER_GROUP_COOPERATING_FAILD); } //更新order order.setOrderStatus(EnumOrderStatus.ORDER_STATUS_COOPERATING.getCode()); @@ -165,7 +153,7 @@ public class WxOrderGroupServiceImpl implements WxOrderGroupService { wxOrderMapper.updateByPrimaryKeySelective(order); } catch (Exception e) { logger.error("更新订单信息失败", e); - throw new MallinkException(ErrorCode.DB_FAIL); + throw new MallinkException(ErrorCode.ORDER_GROUP_COOPERATING_FAILD); } } diff --git a/mallinkService/src/main/resources/mapper/WxOrderGroupMapper.xml b/mallinkService/src/main/resources/mapper/WxOrderGroupMapper.xml index cf344278c..6d3a83a20 100644 --- a/mallinkService/src/main/resources/mapper/WxOrderGroupMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxOrderGroupMapper.xml @@ -90,6 +90,9 @@ order by o.id desc,o.order_status - + + + update wx_order_group set remain_people=remain_people-1,update_date=#{updateDate} where id=#{id} and remain_people>0 +