重构优化促销模块。移除促销相关的mongo

This commit is contained in:
paulGao
2021-12-10 20:15:03 +08:00
parent 8a29ce048d
commit d9d19f8cbd
118 changed files with 2998 additions and 3885 deletions

View File

@@ -8,7 +8,6 @@ import cn.lili.common.security.context.UserContext;
import cn.lili.common.vo.PageVO;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.promotion.entity.dos.Coupon;
import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum;
import cn.lili.modules.promotion.entity.vos.CouponSearchParams;
import cn.lili.modules.promotion.entity.vos.CouponVO;
import cn.lili.modules.promotion.service.CouponService;
@@ -45,14 +44,14 @@ public class CouponStoreController {
page.setNotConvert(true);
String storeId = Objects.requireNonNull(UserContext.getCurrentUser()).getStoreId();
queryParam.setStoreId(storeId);
IPage<CouponVO> coupons = couponService.getCouponsByPageFromMongo(queryParam, page);
IPage<CouponVO> coupons = couponService.pageVOFindAll(queryParam, page);
return ResultUtil.data(coupons);
}
@ApiOperation(value = "获取优惠券详情")
@GetMapping("/{couponId}")
public ResultMessage<Coupon> getCouponList(@PathVariable String couponId) {
CouponVO coupon = OperationalJudgment.judgment(couponService.getCouponDetailFromMongo(couponId));
CouponVO coupon = OperationalJudgment.judgment(couponService.getDetail(couponId));
return ResultUtil.data(coupon);
}
@@ -62,20 +61,23 @@ public class CouponStoreController {
AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser());
couponVO.setStoreId(currentUser.getStoreId());
couponVO.setStoreName(currentUser.getStoreName());
couponService.add(couponVO);
return ResultUtil.data(couponVO);
if (couponService.savePromotions(couponVO)) {
return ResultUtil.data(couponVO);
}
return ResultUtil.error(ResultCode.COUPON_SAVE_ERROR);
}
@PutMapping(consumes = "application/json", produces = "application/json")
@ApiOperation(value = "修改优惠券")
public ResultMessage<Coupon> updateCoupon(@RequestBody CouponVO couponVO) {
OperationalJudgment.judgment(couponService.getCouponDetailFromMongo(couponVO.getId()));
OperationalJudgment.judgment(couponService.getById(couponVO.getId()));
AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser());
couponVO.setStoreId(currentUser.getStoreId());
couponVO.setStoreName(currentUser.getStoreName());
couponVO.setPromotionStatus(PromotionStatusEnum.NEW.name());
CouponVO coupon = couponService.updateCoupon(couponVO);
return ResultUtil.data(coupon);
if (couponService.updatePromotions(couponVO)) {
return ResultUtil.data(couponVO);
}
return ResultUtil.error(ResultCode.COUPON_SAVE_ERROR);
}
@DeleteMapping(value = "/{ids}")
@@ -87,19 +89,16 @@ public class CouponStoreController {
queryWrapper.eq(Coupon::getStoreId, storeId);
List<Coupon> list = couponService.list(queryWrapper);
List<String> filterIds = list.stream().map(Coupon::getId).collect(Collectors.toList());
for (String id : filterIds) {
couponService.deleteCoupon(id);
}
return ResultUtil.success();
return couponService.removePromotions(filterIds) ? ResultUtil.success() : ResultUtil.error(ResultCode.COUPON_DELETE_ERROR);
}
@ApiOperation(value = "修改优惠券状态")
@PutMapping("/status")
public ResultMessage<Object> updateCouponStatus(String couponIds, String promotionStatus) {
public ResultMessage<Object> updateCouponStatus(String couponIds, Long startTime, Long endTime) {
AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser());
String[] split = couponIds.split(",");
List<String> couponIdList = couponService.list(new LambdaQueryWrapper<Coupon>().in(Coupon::getId, Arrays.asList(split)).eq(Coupon::getStoreId, currentUser.getStoreId())).stream().map(Coupon::getId).collect(Collectors.toList());
if (couponService.updateCouponStatus(couponIdList, PromotionStatusEnum.valueOf(promotionStatus))) {
if (couponService.updateStatus(couponIdList, startTime, endTime)) {
return ResultUtil.success(ResultCode.COUPON_EDIT_STATUS_SUCCESS);
}
throw new ServiceException(ResultCode.COUPON_EDIT_STATUS_ERROR);

View File

@@ -8,7 +8,6 @@ import cn.lili.common.vo.PageVO;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.order.cart.entity.vo.FullDiscountVO;
import cn.lili.modules.promotion.entity.dos.FullDiscount;
import cn.lili.modules.promotion.entity.enums.PromotionStatusEnum;
import cn.lili.modules.promotion.entity.vos.FullDiscountSearchParams;
import cn.lili.modules.promotion.service.FullDiscountService;
import cn.lili.modules.system.utils.OperationalJudgment;
@@ -20,6 +19,7 @@ import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Collections;
import java.util.Objects;
/**
@@ -42,9 +42,10 @@ public class FullDiscountStoreController {
AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser());
fullDiscountVO.setStoreId(currentUser.getStoreId());
fullDiscountVO.setStoreName(currentUser.getStoreName());
fullDiscountVO.setPromotionStatus(PromotionStatusEnum.NEW.name());
FullDiscount fullDiscount = fullDiscountService.addFullDiscount(fullDiscountVO);
return ResultUtil.data(fullDiscount);
if (!fullDiscountService.savePromotions(fullDiscountVO)) {
return ResultUtil.error(ResultCode.PINTUAN_ADD_ERROR);
}
return ResultUtil.data(fullDiscountVO);
}
@ApiOperation(value = "通过id获取")
@@ -56,10 +57,10 @@ public class FullDiscountStoreController {
@ApiOperation(value = "根据条件分页查询满优惠活动")
@GetMapping
public ResultMessage<IPage<FullDiscountVO>> getFullDiscountByPage(FullDiscountSearchParams searchParams, PageVO page) {
public ResultMessage<IPage<FullDiscount>> getFullDiscountByPage(FullDiscountSearchParams searchParams, PageVO page) {
String storeId = Objects.requireNonNull(UserContext.getCurrentUser()).getStoreId();
searchParams.setStoreId(storeId);
IPage<FullDiscountVO> fullDiscountByPage = fullDiscountService.getFullDiscountByPageFromMongo(searchParams, page);
IPage<FullDiscount> fullDiscountByPage = fullDiscountService.pageFindAll(searchParams, page);
return ResultUtil.data(fullDiscountByPage);
}
@@ -70,15 +71,17 @@ public class FullDiscountStoreController {
AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser());
fullDiscountVO.setStoreId(currentUser.getStoreId());
fullDiscountVO.setStoreName(currentUser.getStoreName());
fullDiscountService.modifyFullDiscount(fullDiscountVO);
if (!fullDiscountService.updatePromotions(fullDiscountVO)) {
return ResultUtil.error(ResultCode.PINTUAN_EDIT_ERROR);
}
return ResultUtil.success(ResultCode.FULL_DISCOUNT_EDIT_SUCCESS);
}
@ApiOperation(value = "删除满优惠活动")
@DeleteMapping("/{id}")
public ResultMessage<String> deleteFullDiscount(@PathVariable String id) {
OperationalJudgment.judgment(fullDiscountService.getFullDiscount(id));
fullDiscountService.deleteFullDiscount(id);
OperationalJudgment.judgment(fullDiscountService.getById(id));
fullDiscountService.removePromotions(Collections.singletonList(id));
return ResultUtil.success(ResultCode.FULL_DISCOUNT_EDIT_DELETE);
}
@@ -88,10 +91,10 @@ public class FullDiscountStoreController {
@ApiImplicitParam(name = "id", value = "满额活动ID", required = true, paramType = "path"),
@ApiImplicitParam(name = "promotionStatus", value = "满额活动状态", required = true, paramType = "path")
})
@PutMapping("/status/{id}/{promotionStatus}")
public ResultMessage<Object> updateCouponStatus(@PathVariable String id, @PathVariable String promotionStatus) {
@PutMapping("/status/{id}")
public ResultMessage<Object> updateCouponStatus(@PathVariable String id, Long startTime, Long endTime) {
OperationalJudgment.judgment(fullDiscountService.getFullDiscount(id));
if (fullDiscountService.updateFullDiscountStatus(id, PromotionStatusEnum.valueOf(promotionStatus))) {
if (fullDiscountService.updateStatus(Collections.singletonList(id), startTime, endTime)) {
return ResultUtil.success(ResultCode.SUCCESS);
}
return ResultUtil.error(ResultCode.ERROR);

View File

@@ -8,7 +8,8 @@ import cn.lili.common.security.AuthUser;
import cn.lili.common.security.context.UserContext;
import cn.lili.common.vo.PageVO;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.promotion.entity.dto.PromotionGoodsDTO;
import cn.lili.modules.promotion.entity.dos.Pintuan;
import cn.lili.modules.promotion.entity.dos.PromotionGoods;
import cn.lili.modules.promotion.entity.vos.PintuanSearchParams;
import cn.lili.modules.promotion.entity.vos.PintuanVO;
import cn.lili.modules.promotion.entity.vos.PromotionGoodsSearchParams;
@@ -22,7 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.Collections;
import java.util.Objects;
/**
@@ -44,30 +45,28 @@ public class PintuanStoreController {
@GetMapping
@ApiOperation(value = "根据条件分页查询拼团活动列表")
public ResultMessage<IPage<PintuanVO>> getPintuanByPage(PintuanSearchParams queryParam, PageVO pageVo) {
public ResultMessage<IPage<Pintuan>> getPintuanByPage(PintuanSearchParams queryParam, PageVO pageVo) {
AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser());
queryParam.setStoreId(currentUser.getStoreId());
IPage<PintuanVO> pintuanByPageFromMongo = pintuanService.getPintuanByPageFromMongo(queryParam, pageVo);
return ResultUtil.data(pintuanByPageFromMongo);
return ResultUtil.data(pintuanService.pageFindAll(queryParam, pageVo));
}
@GetMapping(value = "/{id}")
@ApiOperation(value = "通过id获取")
public ResultMessage<PintuanVO> get(@PathVariable String id) {
PintuanVO pintuan = OperationalJudgment.judgment(pintuanService.getPintuanByIdFromMongo(id));
PintuanVO pintuan = OperationalJudgment.judgment(pintuanService.getPintuanVO(id));
return ResultUtil.data(pintuan);
}
@GetMapping("/goods/{pintuanId}")
@ApiOperation(value = "根据条件分页查询拼团活动商品列表")
public ResultMessage<IPage<PromotionGoodsDTO>> getPintuanGoodsByPage(@PathVariable String pintuanId, PageVO pageVo) {
public ResultMessage<IPage<PromotionGoods>> getPintuanGoodsByPage(@PathVariable String pintuanId, PageVO pageVo) {
AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser());
PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams();
searchParams.setStoreId(currentUser.getStoreId());
searchParams.setPromotionId(pintuanId);
searchParams.setPromotionType(PromotionTypeEnum.PINTUAN.name());
IPage<PromotionGoodsDTO> promotionGoods = promotionGoodsService.getPromotionGoods(searchParams, pageVo);
return ResultUtil.data(promotionGoods);
return ResultUtil.data(promotionGoodsService.pageFindAll(searchParams, pageVo));
}
@PostMapping(consumes = "application/json", produces = "application/json")
@@ -76,7 +75,7 @@ public class PintuanStoreController {
AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser());
pintuan.setStoreId(currentUser.getStoreId());
pintuan.setStoreName(currentUser.getStoreName());
if (pintuanService.addPintuan(pintuan)) {
if (pintuanService.savePromotions(pintuan)) {
return ResultUtil.success(ResultCode.PINTUAN_ADD_SUCCESS);
}
throw new ServiceException(ResultCode.PINTUAN_ADD_ERROR);
@@ -85,42 +84,32 @@ public class PintuanStoreController {
@PutMapping(consumes = "application/json", produces = "application/json")
@ApiOperation(value = "修改拼团活动")
public ResultMessage<String> editPintuan(@RequestBody @Validated PintuanVO pintuan) {
OperationalJudgment.judgment(pintuanService.getPintuanByIdFromMongo(pintuan.getId()));
OperationalJudgment.judgment(pintuanService.getById(pintuan.getId()));
AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser());
pintuan.setStoreId(currentUser.getStoreId());
pintuan.setStoreName(currentUser.getStoreName());
if (pintuanService.modifyPintuan(pintuan)) {
if (pintuanService.updatePromotions(pintuan)) {
return ResultUtil.success(ResultCode.PINTUAN_EDIT_SUCCESS);
}
throw new ServiceException(ResultCode.PINTUAN_EDIT_ERROR);
}
@PutMapping("/open/{pintuanId}")
@ApiOperation(value = "手动开启拼团活动")
@PutMapping("/status/{pintuanId}")
@ApiOperation(value = "操作拼团活动状态")
public ResultMessage<String> openPintuan(@PathVariable String pintuanId, Long startTime, Long endTime) {
OperationalJudgment.judgment(pintuanService.getPintuanByIdFromMongo(pintuanId));
if (pintuanService.openPintuan(pintuanId, new Date(startTime), new Date(endTime))) {
OperationalJudgment.judgment(pintuanService.getById(pintuanId));
if (pintuanService.updateStatus(Collections.singletonList(pintuanId), startTime, endTime)) {
return ResultUtil.success(ResultCode.PINTUAN_MANUAL_OPEN_SUCCESS);
}
throw new ServiceException(ResultCode.PINTUAN_MANUAL_OPEN_ERROR);
}
@PutMapping("/close/{pintuanId}")
@ApiOperation(value = "手动关闭拼团活动")
public ResultMessage<String> closePintuan(@PathVariable String pintuanId) {
OperationalJudgment.judgment(pintuanService.getPintuanByIdFromMongo(pintuanId));
if (pintuanService.closePintuan(pintuanId)) {
return ResultUtil.success(ResultCode.PINTUAN_MANUAL_CLOSE_SUCCESS);
}
throw new ServiceException(ResultCode.PINTUAN_MANUAL_CLOSE_ERROR);
}
@DeleteMapping("/{pintuanId}")
@ApiOperation(value = "手动删除拼团活动")
public ResultMessage<String> deletePintuan(@PathVariable String pintuanId) {
OperationalJudgment.judgment(pintuanService.getPintuanByIdFromMongo(pintuanId));
if (pintuanService.deletePintuan(pintuanId)) {
OperationalJudgment.judgment(pintuanService.getById(pintuanId));
if (pintuanService.removePromotions(Collections.singletonList(pintuanId))) {
return ResultUtil.success(ResultCode.PINTUAN_DELETE_SUCCESS);
}
throw new ServiceException(ResultCode.PINTUAN_DELETE_ERROR);

View File

@@ -8,7 +8,6 @@ import cn.lili.modules.promotion.entity.dos.Seckill;
import cn.lili.modules.promotion.entity.dos.SeckillApply;
import cn.lili.modules.promotion.entity.vos.SeckillApplyVO;
import cn.lili.modules.promotion.entity.vos.SeckillSearchParams;
import cn.lili.modules.promotion.entity.vos.SeckillVO;
import cn.lili.modules.promotion.service.SeckillApplyService;
import cn.lili.modules.promotion.service.SeckillService;
import cn.lili.modules.system.utils.OperationalJudgment;
@@ -38,8 +37,8 @@ public class SeckillStoreController {
@GetMapping
@ApiOperation(value = "获取秒杀活动列表")
public ResultMessage<IPage<SeckillVO>> getSeckillPage(SeckillSearchParams queryParam, PageVO pageVo) {
IPage<SeckillVO> seckillPage = seckillService.getSeckillByPageFromMongo(queryParam, pageVo);
public ResultMessage<IPage<Seckill>> getSeckillPage(SeckillSearchParams queryParam, PageVO pageVo) {
IPage<Seckill> seckillPage = seckillService.pageFindAll(queryParam, pageVo);
return ResultUtil.data(seckillPage);
}
@@ -48,14 +47,14 @@ public class SeckillStoreController {
public ResultMessage<IPage<SeckillApply>> getSeckillApplyPage(SeckillSearchParams queryParam, PageVO pageVo) {
String storeId = Objects.requireNonNull(UserContext.getCurrentUser()).getStoreId();
queryParam.setStoreId(storeId);
IPage<SeckillApply> seckillPage = seckillApplyService.getSeckillApplyFromMongo(queryParam, pageVo);
IPage<SeckillApply> seckillPage = seckillApplyService.getSeckillApply(queryParam, pageVo);
return ResultUtil.data(seckillPage);
}
@GetMapping("/{seckillId}")
@ApiOperation(value = "获取秒杀活动")
@ApiOperation(value = "获取秒杀活动信息")
public ResultMessage<Seckill> getSeckill(@PathVariable String seckillId) {
return ResultUtil.data(seckillService.getSeckillByIdFromMongo(seckillId));
return ResultUtil.data(seckillService.getById(seckillId));
}
@GetMapping("/apply/{seckillApplyId}")