|
|
@@ -15,7 +15,6 @@ import com.sqx.common.utils.Constant;
|
|
|
import com.sqx.common.utils.PageUtils;
|
|
|
import com.sqx.common.utils.SpringContextUtils;
|
|
|
import com.sqx.modules.activity.bo.ShopActivityBO;
|
|
|
-import com.sqx.modules.activity.dao.ActivityDao;
|
|
|
import com.sqx.modules.activity.dao.ActivityShopDao;
|
|
|
import com.sqx.modules.activity.dto.ActivityGoodsDTO;
|
|
|
import com.sqx.modules.activity.dto.JoinActivityDTO;
|
|
|
@@ -38,7 +37,6 @@ import com.sqx.modules.sys.service.SysUserShopService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.apache.shiro.SecurityUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
@@ -57,9 +55,6 @@ import java.util.stream.Collectors;
|
|
|
@RequiredArgsConstructor
|
|
|
public class ActivityShopServiceImpl extends ServiceImpl<ActivityShopDao, ActivityShop> implements ActivityShopService {
|
|
|
|
|
|
- @Autowired
|
|
|
- private ActivityDao activityDao;
|
|
|
-
|
|
|
private final ActivityGoodsService activityGoodsService;
|
|
|
private final SysUserShopService sysUserShopService;
|
|
|
|
|
|
@@ -83,6 +78,9 @@ public class ActivityShopServiceImpl extends ServiceImpl<ActivityShopDao, Activi
|
|
|
|
|
|
List<ActivityShop> activityShops = new ArrayList<>();
|
|
|
for (Long shopId : dto.getShopIds()) {
|
|
|
+ // 自动退出活动
|
|
|
+ autoExitActivity(shopId);
|
|
|
+
|
|
|
// 判断当前店铺已经加入的活动数量
|
|
|
LambdaQueryWrapper<ActivityShop> queryWrapper = Wrappers.lambdaQuery();
|
|
|
queryWrapper.eq(ActivityShop::getShopId, shopId);
|
|
|
@@ -126,6 +124,34 @@ public class ActivityShopServiceImpl extends ServiceImpl<ActivityShopDao, Activi
|
|
|
return activityShops.stream().map(ActivityShop::getId).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 自动退出活动
|
|
|
+ * @param shopId 店铺id
|
|
|
+ */
|
|
|
+ private void autoExitActivity(Long shopId) {
|
|
|
+ LambdaQueryWrapper<ActivityShop> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(ActivityShop::getShopId, shopId);
|
|
|
+ List<ActivityShop> oldActivityShops = list(queryWrapper);
|
|
|
+
|
|
|
+ if (oldActivityShops.size() > 0) {
|
|
|
+ ActivityService activityService = SpringContextUtils.applicationContext.getBean(ActivityService.class);
|
|
|
+ List<ActivityVO> activityVOS = activityService.getActivityByIds(oldActivityShops.stream().map(ActivityShop::getActivityId).collect(Collectors.toList()));
|
|
|
+
|
|
|
+ Date currentDate = new Date();
|
|
|
+ activityVOS = activityVOS.stream().filter(e -> currentDate.after(e.getStartTime()) && currentDate.before(e.getEndTime())).collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 目前还未被删除的活动、且在有效期内的活动id集合
|
|
|
+ List<Long> existActivityIds = activityVOS.stream().map(ActivityVO::getId).collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<ActivityShop> waitDelList = oldActivityShops.stream().filter(e -> !existActivityIds.contains(e.getActivityId())).collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (waitDelList.size() > 0) {
|
|
|
+ this.removeByIds(waitDelList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
@Transactional
|
|
|
@Override
|
|
|
public void quitActivity(QuitActivityDTO dto) {
|