|
@@ -8,7 +8,8 @@ import com.qs.mp.admin.domain.param.CdKeyCreateParam;
|
|
|
import com.qs.mp.admin.mapper.CdKeyGroupMapper;
|
|
|
import com.qs.mp.admin.service.*;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.qs.mp.common.constant.Constants;
|
|
|
+import com.qs.mp.channel.domain.Channel;
|
|
|
+import com.qs.mp.channel.service.IChannelService;
|
|
|
import com.qs.mp.common.enums.*;
|
|
|
import com.qs.mp.common.exception.ServiceException;
|
|
|
import com.qs.mp.common.utils.LogUtil;
|
|
@@ -62,15 +63,23 @@ public class CdKeyGroupServiceImpl extends ServiceImpl<CdKeyGroupMapper, CdKeyGr
|
|
|
@Autowired
|
|
|
private IAsyncTaskService asyncTaskService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IChannelService channelService;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public String createCdKeyGroup(CdKeyCreateParam param) {
|
|
|
-
|
|
|
+ Channel channel = channelService.getById(param.getChannelId());
|
|
|
+ if (channel == null) {
|
|
|
+ LogUtil.error(logger,"门店不存在,channelId:{0}", param.getChannelId());
|
|
|
+ throw new ServiceException("门店不存在");
|
|
|
+ }
|
|
|
// 生成兑换码组
|
|
|
CdKeyGroup cdKeyGroup = mapperFacade.map(param, CdKeyGroup.class);
|
|
|
cdKeyGroup.setGroupId(bizIdGenerator.newId());
|
|
|
- cdKeyGroup.setStatus(CdKeyGroupStatusEnum.WAITING.getValue());
|
|
|
+ cdKeyGroup.setStatus(CdKeyGroupStatusEnum.WAITING);
|
|
|
+ cdKeyGroup.setSiteName(channel.getName());
|
|
|
cdKeyGroup.setCreatedTime(new Date());
|
|
|
cdKeyGroup.setUpdatedTime(new Date());
|
|
|
this.save(cdKeyGroup);
|
|
@@ -84,39 +93,39 @@ public class CdKeyGroupServiceImpl extends ServiceImpl<CdKeyGroupMapper, CdKeyGr
|
|
|
CdKeyGroupGoods groupGoods = new CdKeyGroupGoods();
|
|
|
BeanUtils.copyProperties(cdKeyGroupGoods, groupGoods);
|
|
|
groupGoods.setGroupId(cdKeyGroup.getGroupId());
|
|
|
- if (CdKeyGroupGoodsTypeEnum.COUPON.getValue().equals(cdKeyGroupGoods.getType())) {
|
|
|
+ if (CdKeyGroupGoodsTypeEnum.COUPON.equals(cdKeyGroupGoods.getType())) {
|
|
|
Coupon coupon = couponService.getById(groupGoods.getRefId());
|
|
|
if (coupon == null) {
|
|
|
LogUtil.error(logger,"关联优惠券信息不存在,groupId:{0}", cdKeyGroup.getGroupId());
|
|
|
throw new ServiceException("关联优惠券信息不存在");
|
|
|
}
|
|
|
groupGoods.setTitle(coupon.getTitle());
|
|
|
- groupGoods.setPicUrl(coupon.getPicUrl());
|
|
|
+ groupGoods.setPicUrl(cdKeyGroupGoods.getPicUrl());
|
|
|
groupGoods.setValue(coupon.getDiscount());
|
|
|
groupGoods.setQuantity(cdKeyGroupGoods.getQuantity());
|
|
|
- } else if (CdKeyGroupGoodsTypeEnum.COUPON_PKG.getValue().equals(cdKeyGroupGoods.getType())) {
|
|
|
+ } else if (CdKeyGroupGoodsTypeEnum.COUPON_PKG.equals(cdKeyGroupGoods.getType())) {
|
|
|
CouponPkg couponPkg = couponPkgService.getById(groupGoods.getRefId());
|
|
|
if (couponPkg == null) {
|
|
|
LogUtil.error(logger,"关联券包信息不存在,groupId:{0}", cdKeyGroup.getGroupId());
|
|
|
throw new ServiceException("关联券包信息不存在");
|
|
|
}
|
|
|
groupGoods.setTitle(couponPkg.getTitle());
|
|
|
- groupGoods.setPicUrl(couponPkg.getPicUrl());
|
|
|
+ groupGoods.setPicUrl(cdKeyGroupGoods.getPicUrl());
|
|
|
groupGoods.setValue(couponPkg.getFacePrice());
|
|
|
groupGoods.setQuantity(cdKeyGroupGoods.getQuantity());
|
|
|
- } else if (CdKeyGroupGoodsTypeEnum.GOODS.getValue().equals(cdKeyGroupGoods.getType())) {
|
|
|
+ } else if (CdKeyGroupGoodsTypeEnum.GOODS.equals(cdKeyGroupGoods.getType())) {
|
|
|
Goods goods = goodsService.getById(cdKeyGroupGoods.getRefId());
|
|
|
if (goods == null) {
|
|
|
LogUtil.error(logger, "关联商品信息不存在,groupId:{0}", cdKeyGroup.getGroupId());
|
|
|
throw new ServiceException("关联商品信息不存在");
|
|
|
}
|
|
|
groupGoods.setTitle(goods.getTitle());
|
|
|
- groupGoods.setPicUrl(goods.getPicUrl());
|
|
|
+ groupGoods.setPicUrl(cdKeyGroupGoods.getPicUrl());
|
|
|
groupGoods.setValue(goods.getValue());
|
|
|
groupGoods.setQuantity(cdKeyGroupGoods.getQuantity());
|
|
|
} else {
|
|
|
groupGoods.setTitle("盲豆");
|
|
|
- groupGoods.setPicUrl(Constants.MANGDOU_PIC);
|
|
|
+ groupGoods.setPicUrl(cdKeyGroupGoods.getPicUrl());
|
|
|
groupGoods.setQuantity(cdKeyGroupGoods.getQuantity());
|
|
|
}
|
|
|
cdKeyGroupGoodsList.add(groupGoods);
|
|
@@ -145,13 +154,13 @@ public class CdKeyGroupServiceImpl extends ServiceImpl<CdKeyGroupMapper, CdKeyGr
|
|
|
for (int i = 0; i < cdKeyGroupGoods.getQuantity(); i++) {
|
|
|
// 为每一个商品生成兑换码
|
|
|
CdKey cdKey = new CdKey();
|
|
|
- cdKey.setCdKey(bizIdGenerator.newId());
|
|
|
+ cdKey.setKeyId(bizIdGenerator.newIdWithUidSharding(groupId));
|
|
|
cdKey.setGroupId(groupId);
|
|
|
cdKey.setRefId(cdKeyGroupGoods.getRefId());
|
|
|
cdKey.setType(cdKeyGroupGoods.getType());
|
|
|
cdKey.setPicUrl(cdKeyGroupGoods.getPicUrl());
|
|
|
cdKey.setStatus(CdKeyStatusEnum.UNCASHED.getValue());
|
|
|
- cdKey.setCdKey(cdKeyGenerate());
|
|
|
+ cdKey.setCdKey(cdKeyGenerate(cdKey.getKeyId()));
|
|
|
cdKey.setCreateTime(new Date());
|
|
|
cdKeyList.add(cdKey);
|
|
|
}
|
|
@@ -167,7 +176,7 @@ public class CdKeyGroupServiceImpl extends ServiceImpl<CdKeyGroupMapper, CdKeyGr
|
|
|
|
|
|
}
|
|
|
|
|
|
- private String cdKeyGenerate() {
|
|
|
+ private String cdKeyGenerate(String keyId) {
|
|
|
// 生成16位大写字母和数字的随机卡密码的逻辑
|
|
|
// 可以使用随机数生成器或者其他方式实现
|
|
|
String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|