|
|
@@ -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"));
|