zoujiajian 1 年之前
父節點
當前提交
ee3015b539

+ 1 - 1
netflix-dao/src/main/resources/mapper/GroupsMapper.xml

@@ -112,7 +112,7 @@
         select gt.id
         from `groups_trips` gt
                  inner join account a on a.id = gt.account_id
-        where gt.id != #{groupsId}
+        where gt.id != #{groupId}
           and gt.sku_id = #{skuId}
           and gt.status = 'validity'
           and a.expiry_time >= #{expiryTime}

+ 1 - 2
netflix-service/src/main/java/com/cyksj/service/relation/impl/GroupRelationFrontServiceImpl.java

@@ -53,7 +53,6 @@ import com.ejlchina.searcher.util.MapUtils;
 import com.github.rholder.retry.*;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.dao.DuplicateKeyException;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -1031,7 +1030,7 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 		}
 		//若无移至空车队
 		if (newRelation == null) {
-			newRelation = changeTickerRelation.getEmptyGroupsRelation(renewalView.getRelationId(), renewalView.getUserId(), renewalView.getSkuId());
+			newRelation = changeTickerRelation.getEmptyGroupsRelation(renewalView.getUserId(), renewalView.getRelationId(), renewalView.getSkuId());
 		}
 		if (newRelation == null) {
 			throw BusinessRuntimeException.getInstance("更换异常,请重新提交");

+ 20 - 8
netflix-service/src/main/java/com/cyksj/service/relation/impl/GroupsRelationChangeServiceImpl.java

@@ -8,16 +8,15 @@ import com.cyksj.mapper.GoodsDonSkuMapper;
 import com.cyksj.mapper.GroupsMapper;
 import com.cyksj.mapper.GroupsRelationMapper;
 import com.cyksj.mapper.OrderDonMapper;
-import com.cyksj.model.entity.GoodsDonSku;
-import com.cyksj.model.entity.GroupsRelation;
-import com.cyksj.model.entity.GroupsTrips;
-import com.cyksj.model.entity.OrderDon;
+import com.cyksj.model.entity.*;
 import com.cyksj.redis.RedisService;
 import com.cyksj.service.groups.GroupsFuncService;
+import com.cyksj.service.relation.GroupRelationClearService;
 import com.cyksj.service.relation.GroupsRelationChangeService;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 /**
  * 项目名: yhlxj2
@@ -41,7 +40,10 @@ public class GroupsRelationChangeServiceImpl implements GroupsRelationChangeServ
 
 	private final OrderDonMapper orderDonMapper;
 
+	private final GroupRelationClearService relationClearService;
+
 	@Override
+	@Transactional(rollbackFor = Throwable.class)
 	public GroupsRelation changeTicket(Long userId, Long oriRelationId, Long itemGroupsId, Long skuId) {
 		GroupsRelation relation = getRelationThisTrips(userId, itemGroupsId, 1);
 		if (relation == null) {
@@ -52,6 +54,7 @@ public class GroupsRelationChangeServiceImpl implements GroupsRelationChangeServ
 	}
 
 	@Override
+	@Transactional(rollbackFor = Throwable.class)
 	public GroupsRelation getEmptyGroupsRelation(Long userId, Long oriRelationId, Long skuId) {
 		return getEmptyGroupsRelationIfRetry(userId, oriRelationId, skuId, 1);
 	}
@@ -75,9 +78,12 @@ public class GroupsRelationChangeServiceImpl implements GroupsRelationChangeServ
 		if (relation == null) {
 			return null;
 		}
-		if (!redisService.setNx(RedisKey.GROUPS_RELATION_NUM_KEY + relation.getId(), userId, 60 * 5L)) {
+		if (!redisService.setNx(RedisKey.GROUPS_RELATION_NUM_KEY + relation.getId(), userId, 60 * 2L)) {
 			retryNum++;
-			return getEmptyGroupsRelationIfRetry(skuId, oriRelationId, userId, retryNum);
+			if (retryNum >= 7) {
+				return null;
+			}
+			return getEmptyGroupsRelationIfRetry(userId, oriRelationId, skuId, retryNum);
 		}
 		syncGroupsRelation(oriRelationId, relation);
 		return relation;
@@ -95,7 +101,7 @@ public class GroupsRelationChangeServiceImpl implements GroupsRelationChangeServ
 			return null;
 		}
 		Long relationId = relation.getId();
-		if (!redisService.setNx(RedisKey.GROUPS_RELATION_NUM_KEY + relationId, userId, 60 * 5L)) {
+		if (!redisService.setNx(RedisKey.GROUPS_RELATION_NUM_KEY + relationId, userId, 60 * 2L)) {
 			if (retryNum == 7){
 				log.error("该车队人员已满,请选择另一车队");
 				return null;
@@ -115,11 +121,17 @@ public class GroupsRelationChangeServiceImpl implements GroupsRelationChangeServ
 
 	public void syncGroupsRelation(Long oriRelationId, GroupsRelation newRelation) {
 		GroupsRelation oriRelation = relationMapper.selectById(oriRelationId);
+		relationClearService.clearTicket(oriRelation, UserTicketClearedRecord.Source.change_ticket);
+
+		Long newRelationId = newRelation.getId();
 		BeanUtil.copyProperties(oriRelation, newRelation);
+		newRelation.setId(newRelationId);
+		newRelation.setCreatedTime(null);
+		newRelation.setUpdateTime(null);
 		relationMapper.updateById(newRelation);
 		OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
 				.eq(OrderDon::getRelationId, oriRelationId)
-				.eq(OrderDon::getUserId, oriRelation.getUserId())
+				.eq(OrderDon::getUserId, newRelation.getUserId())
 				.notIn(OrderDon::getStatus, Constant.noOrderStatus)
 				.orderByDesc(OrderDon::getId)
 				.last("limit 1"));