|
@@ -1,6 +1,7 @@
|
|
package com.citu.module.promotion.service.luck;
|
|
package com.citu.module.promotion.service.luck;
|
|
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
import com.citu.framework.common.pojo.PageResult;
|
|
import com.citu.framework.common.pojo.PageResult;
|
|
import com.citu.framework.common.util.object.BeanUtils;
|
|
import com.citu.framework.common.util.object.BeanUtils;
|
|
import com.citu.module.product.api.spu.ProductSpuApi;
|
|
import com.citu.module.product.api.spu.ProductSpuApi;
|
|
@@ -12,12 +13,14 @@ import com.citu.module.promotion.convert.luck.LuckLotteryConvert;
|
|
import com.citu.module.promotion.dal.dataobject.luck.LuckLotteryDO;
|
|
import com.citu.module.promotion.dal.dataobject.luck.LuckLotteryDO;
|
|
import com.citu.module.promotion.dal.mysql.luck.LuckLotteryMapper;
|
|
import com.citu.module.promotion.dal.mysql.luck.LuckLotteryMapper;
|
|
import com.citu.module.promotion.enums.luck.LuckLotteryFactorEnum;
|
|
import com.citu.module.promotion.enums.luck.LuckLotteryFactorEnum;
|
|
|
|
+import com.citu.module.promotion.enums.luck.LuckStatusEnum;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Objects;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.citu.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
import static com.citu.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
@@ -45,6 +48,22 @@ public class LuckLotteryServiceImpl implements LuckLotteryService {
|
|
if (null != luckLotteryDO) {
|
|
if (null != luckLotteryDO) {
|
|
throw exception(LUCK_LOTTERY_NAME_USED, createReqVO.getName());
|
|
throw exception(LUCK_LOTTERY_NAME_USED, createReqVO.getName());
|
|
}
|
|
}
|
|
|
|
+ if (LuckLotteryFactorEnum.ORDER_PRODUCT_PAY_SUCCESS.getFactor()
|
|
|
|
+ .equals(createReqVO.getFactor())) {
|
|
|
|
+ // 下单指定商品支付成功
|
|
|
|
+ if (CollUtil.isEmpty(createReqVO.getFactorInfo())) {
|
|
|
|
+ // 不存在
|
|
|
|
+ throw exception(LUCK_LOTTERY_PRODUCT_NOT_SELECTED);
|
|
|
|
+ }
|
|
|
|
+ for (String spuId : createReqVO.getFactorInfo()) {
|
|
|
|
+ LuckLotteryDO luckLottery = luckLotteryMapper.getLuckLotteryListBySpuId(spuId,null);
|
|
|
|
+ if (null != luckLottery) {
|
|
|
|
+ // 已经存在
|
|
|
|
+ throw exception(LUCK_LOTTERY_PRODUCT_USED);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
LuckLotteryDO luckLottery = BeanUtils.toBean(createReqVO, LuckLotteryDO.class);
|
|
LuckLotteryDO luckLottery = BeanUtils.toBean(createReqVO, LuckLotteryDO.class);
|
|
luckLotteryMapper.insert(luckLottery);
|
|
luckLotteryMapper.insert(luckLottery);
|
|
// 返回
|
|
// 返回
|
|
@@ -54,7 +73,29 @@ public class LuckLotteryServiceImpl implements LuckLotteryService {
|
|
@Override
|
|
@Override
|
|
public void updateLuckLottery(LuckLotterySaveReqVO updateReqVO) {
|
|
public void updateLuckLottery(LuckLotterySaveReqVO updateReqVO) {
|
|
// 校验存在
|
|
// 校验存在
|
|
- validateLuckLotteryExists(updateReqVO.getId());
|
|
|
|
|
|
+ LuckLotteryDO luckLottery = validateLuckLotteryExists(updateReqVO.getId());
|
|
|
|
+ LuckLotteryDO exist = luckLotteryMapper.selectByName(updateReqVO.getName());
|
|
|
|
+ if (null != exist &&
|
|
|
|
+ !Objects.equals(luckLottery.getId(), exist.getId())) {
|
|
|
|
+ throw exception(LUCK_LOTTERY_NAME_USED, updateReqVO.getName());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (LuckLotteryFactorEnum.ORDER_PRODUCT_PAY_SUCCESS.getFactor()
|
|
|
|
+ .equals(updateReqVO.getFactor())) {
|
|
|
|
+ // 下单指定商品支付成功
|
|
|
|
+ if (CollUtil.isEmpty(updateReqVO.getFactorInfo())) {
|
|
|
|
+ // 不存在
|
|
|
|
+ throw exception(LUCK_LOTTERY_PRODUCT_NOT_SELECTED);
|
|
|
|
+ }
|
|
|
|
+ for (String spuId : updateReqVO.getFactorInfo()) {
|
|
|
|
+ LuckLotteryDO spuExist = luckLotteryMapper.getLuckLotteryListBySpuId(spuId,null);
|
|
|
|
+ if (null != spuExist && !Objects.equals(luckLottery.getId(), spuExist.getId())) {
|
|
|
|
+ // 已经存在
|
|
|
|
+ throw exception(LUCK_LOTTERY_PRODUCT_USED);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
// 更新
|
|
// 更新
|
|
LuckLotteryDO updateObj = BeanUtils.toBean(updateReqVO, LuckLotteryDO.class);
|
|
LuckLotteryDO updateObj = BeanUtils.toBean(updateReqVO, LuckLotteryDO.class);
|
|
luckLotteryMapper.updateById(updateObj);
|
|
luckLotteryMapper.updateById(updateObj);
|
|
@@ -129,7 +170,7 @@ public class LuckLotteryServiceImpl implements LuckLotteryService {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public List<LuckLotteryDO> getLuckLotteryListByTime(Long spuId, LocalDateTime startTime, LocalDateTime endTime) {
|
|
public List<LuckLotteryDO> getLuckLotteryListByTime(Long spuId, LocalDateTime startTime, LocalDateTime endTime) {
|
|
- return luckLotteryMapper.getLuckLotteryListByTime(spuId,startTime, endTime);
|
|
|
|
|
|
+ return luckLotteryMapper.getLuckLotteryListByTime(spuId, startTime, endTime);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -140,4 +181,9 @@ public class LuckLotteryServiceImpl implements LuckLotteryService {
|
|
}
|
|
}
|
|
return luckLottery;
|
|
return luckLottery;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public LuckLotteryDO getLuckLotteryListBySpuId(String spuId) {
|
|
|
|
+ return luckLotteryMapper.getLuckLotteryListBySpuId(spuId, LuckStatusEnum.ENABLE.getStatus());
|
|
|
|
+ }
|
|
}
|
|
}
|