Просмотр исходного кода

[拼团][修改][我的拼团]

release_toaliyun_real
gongbiao 7 лет назад
Родитель
Сommit
2d0fedf897
3 измененных файлов: 21 добавлений и 27 удалений
  1. +3
    -0
      mallinkService/src/main/java/com/iformall/mapper/WxOrderMapper.java
  2. +14
    -26
      mallinkService/src/main/java/com/iformall/service/impl/WxOrderGroupServiceImpl.java
  3. +4
    -1
      mallinkService/src/main/resources/mapper/WxOrderGroupMapper.xml

+ 3
- 0
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<WxOrder, Long> {

void updateStatusByOrderGroupId(WxOrder order);

int updateOrderGroup(WxOrderGroup wxOrderGroup);

}

+ 14
- 26
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);
}
}



+ 4
- 1
mallinkService/src/main/resources/mapper/WxOrderGroupMapper.xml Просмотреть файл

@@ -90,6 +90,9 @@
order by o.id desc,o.order_status
</select>

<update id="updateOrderGroup" parameterType="com.iformall.domain.po.WxOrderGroup">
update wx_order_group set remain_people=remain_people-1,update_date=#{updateDate} where id=#{id} and remain_people>0
</update>

</mapper>

Загрузка…
Отмена
Сохранить