|
@@ -1,20 +1,15 @@
|
|
|
package com.yonge.cooleshow.biz.dal.service.impl;
|
|
|
|
|
|
-import cn.hutool.core.lang.Snowflake;
|
|
|
-import cn.hutool.core.lang.UUID;
|
|
|
-import cn.hutool.core.lang.generator.SnowflakeGenerator;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
|
|
|
+import com.yonge.cooleshow.auth.api.entity.SysUser;
|
|
|
import com.yonge.cooleshow.biz.dal.entity.*;
|
|
|
-import com.yonge.cooleshow.biz.dal.enums.OrderStatusEnum;
|
|
|
import com.yonge.cooleshow.biz.dal.service.*;
|
|
|
import com.yonge.cooleshow.biz.dal.vo.UserOrderDetailVo;
|
|
|
import com.yonge.cooleshow.biz.dal.wrapper.UserPaymentOrderWrapper;
|
|
|
-import com.yonge.cooleshow.common.enums.EActivationCode;
|
|
|
import com.yonge.toolset.base.exception.BizException;
|
|
|
-import com.yonge.toolset.base.util.StringUtil;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -23,10 +18,13 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import com.yonge.cooleshow.biz.dal.wrapper.TenantAlbumWrapper;
|
|
|
import com.yonge.cooleshow.biz.dal.mapper.TenantAlbumMapper;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import springfox.documentation.spring.web.json.Json;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Collection;
|
|
|
import java.util.List;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -53,10 +51,10 @@ public class TenantAlbumServiceImpl extends ServiceImpl<TenantAlbumMapper, Tenan
|
|
|
private UserOrderService userOrderService;
|
|
|
|
|
|
@Autowired
|
|
|
- private TenantActivationCodeService tenantActivationCodeService;
|
|
|
+ private SysUserFeignService sysUserFeignService;
|
|
|
|
|
|
@Autowired
|
|
|
- private TenantAlbumPurchaseService tenantAlbumPurchaseService;
|
|
|
+ private TenantAlbumMusicService tenantAlbumMusicService;
|
|
|
|
|
|
/**
|
|
|
* 查询详情
|
|
@@ -76,9 +74,9 @@ public class TenantAlbumServiceImpl extends ServiceImpl<TenantAlbumMapper, Tenan
|
|
|
* @return IPage<TenantAlbum>
|
|
|
*/
|
|
|
@Override
|
|
|
- public IPage<TenantAlbum> selectPage(IPage<TenantAlbum> page, TenantAlbumWrapper.TenantAlbumQuery query) {
|
|
|
-
|
|
|
- return page.setRecords(baseMapper.selectPage(page, query));
|
|
|
+ public IPage<TenantAlbumWrapper.TenantAlbum> selectPage(IPage<TenantAlbumWrapper.TenantAlbum> page, TenantAlbumWrapper.TenantAlbumQuery query) {
|
|
|
+ List<TenantAlbumWrapper.TenantAlbum> albums = baseMapper.selectPage(page, query);
|
|
|
+ return page.setRecords(albums);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -87,9 +85,10 @@ public class TenantAlbumServiceImpl extends ServiceImpl<TenantAlbumMapper, Tenan
|
|
|
* @return Boolean
|
|
|
*/
|
|
|
@Override
|
|
|
- public Boolean add(TenantAlbumWrapper.TenantAlbum tenantAlbum) {
|
|
|
+ public Boolean add(TenantAlbum tenantAlbum) {
|
|
|
|
|
|
- return this.save(JSON.parseObject(tenantAlbum.jsonString(), TenantAlbum.class));
|
|
|
+ //return this.save(JSON.parseObject(tenantAlbum.jsonString(), TenantAlbum.class));
|
|
|
+ return this.save(tenantAlbum);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -116,10 +115,9 @@ public class TenantAlbumServiceImpl extends ServiceImpl<TenantAlbumMapper, Tenan
|
|
|
throw new BizException("订单商品信息为空");
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- TenantAlbumWrapper.TenantAlbumContent tenantAlbumContent = JSON
|
|
|
- .parseObject(orderGoodsInfo.getBizContent(), TenantAlbumWrapper.TenantAlbumContent.class);
|
|
|
- if (tenantAlbumContent == null) {
|
|
|
+ TenantAlbumWrapper.TenantAlbumBuy tenantAlbumBuy = JSON
|
|
|
+ .parseObject(JSON.toJSONString(orderGoodsInfo.getBizContent()), TenantAlbumWrapper.TenantAlbumBuy.class);
|
|
|
+ if (tenantAlbumBuy == null) {
|
|
|
log.error("订单创建前检测,订单商品信息为空");
|
|
|
throw new BizException("订单商品信息为空");
|
|
|
}
|
|
@@ -131,7 +129,6 @@ public class TenantAlbumServiceImpl extends ServiceImpl<TenantAlbumMapper, Tenan
|
|
|
log.error("订单创建前检测,专辑不存在,bizId={}", orderGoodsInfo.getBizId());
|
|
|
throw new BizException("订单商品信息为空");
|
|
|
}
|
|
|
- tenantAlbumContent.setBuyCycle(tenantAlbum.getPurchaseCycle());
|
|
|
|
|
|
// 查询专辑所在机构
|
|
|
List<TenantAlbumRef> refList =
|
|
@@ -164,10 +161,8 @@ public class TenantAlbumServiceImpl extends ServiceImpl<TenantAlbumMapper, Tenan
|
|
|
}
|
|
|
price = tenantAlbum.getSalePrice();
|
|
|
userOrderDetail.setMerchId(tenantInfo.getId());
|
|
|
- tenantAlbumContent.setBuyMultiple(1);
|
|
|
- tenantAlbumContent.setBuyNumber(1);
|
|
|
- tenantAlbumContent.setBuyCycle(tenantAlbumContent.getBuyCycle());
|
|
|
- tenantAlbumContent.setTenantId(tenantInfo.getId());
|
|
|
+ tenantAlbumBuy.setBuyCycle(1);
|
|
|
+ tenantAlbumBuy.setBuyNumber(1);
|
|
|
break;
|
|
|
}
|
|
|
|
|
@@ -184,8 +179,6 @@ public class TenantAlbumServiceImpl extends ServiceImpl<TenantAlbumMapper, Tenan
|
|
|
}
|
|
|
price = tenantAlbum.getOriginalPrice();
|
|
|
userOrderDetail.setMerchId(0L);
|
|
|
- tenantAlbumContent.setTenantId(tenantStaff.getTenantId());
|
|
|
- tenantAlbumContent.setBuyCycle(tenantAlbumContent.getBuyCycle()*tenantAlbumContent.getBuyMultiple());
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -194,10 +187,9 @@ public class TenantAlbumServiceImpl extends ServiceImpl<TenantAlbumMapper, Tenan
|
|
|
|
|
|
userOrderDetail.setGoodUrl(userOrderService.getGoodUrlByType(orderGoodsInfo.getGoodType()));
|
|
|
userOrderDetail.setBizId(tenantAlbum.getId());
|
|
|
- userOrderDetail.setBizContent(JSON.toJSONString(tenantAlbumContent));
|
|
|
userOrderDetail.setGoodNum(orderGoodsInfo.getGoodNum());
|
|
|
userOrderDetail.setOriginalPrice(price.multiply(new BigDecimal(orderGoodsInfo.getGoodNum()))
|
|
|
- .multiply(new BigDecimal(tenantAlbumContent.getBuyMultiple())));
|
|
|
+ .multiply(new BigDecimal(tenantAlbumBuy.getBuyCycle())));
|
|
|
userOrderDetail.setCouponAmount(BigDecimal.ZERO);
|
|
|
userOrderDetail.setExpectPrice(userOrderDetail.getOriginalPrice());
|
|
|
userOrderDetail.setActualPrice(userOrderDetail.getExpectPrice().subtract(userOrderDetail.getCouponAmount()));
|
|
@@ -216,45 +208,69 @@ public class TenantAlbumServiceImpl extends ServiceImpl<TenantAlbumMapper, Tenan
|
|
|
public void orderSuccess(UserOrderDetailVo userOrderDetailVo) {
|
|
|
|
|
|
// 学生 插入机构专辑购买数据
|
|
|
- // 学生购买机构专辑
|
|
|
- switch (userOrderDetailVo.getOrderClient()) {
|
|
|
- case STUDENT: {
|
|
|
- tenantActivationCodeService.addUserTenantAlbumRecord(userOrderDetailVo.getUserId(),userOrderDetailVo);
|
|
|
|
|
|
- break;
|
|
|
- }
|
|
|
|
|
|
- case TENANT: {
|
|
|
- // 机构 插入机构专辑购买记录,生成机构专辑激活码
|
|
|
-
|
|
|
- TenantAlbumWrapper.TenantAlbumContent tenantAlbumContent = JSON
|
|
|
- .parseObject(userOrderDetailVo.getBizContent(), TenantAlbumWrapper.TenantAlbumContent.class);
|
|
|
- TenantAlbumPurchase tenantAlbumPurchase = new TenantAlbumPurchase();
|
|
|
- tenantAlbumPurchase.setTenantId(tenantAlbumContent.getTenantId());
|
|
|
- tenantAlbumPurchase.setTenantAlbumId(userOrderDetailVo.getBizId());
|
|
|
- tenantAlbumPurchase.setPurchaseTime(userOrderDetailVo.getCreateTime());
|
|
|
- tenantAlbumPurchase.setPurchaseQuantity(userOrderDetailVo.getGoodNum());
|
|
|
- tenantAlbumPurchase.setPurchaseCycle(tenantAlbumContent.getBuyCycle());
|
|
|
- tenantAlbumPurchase.setActiveQuantity(0);
|
|
|
- tenantAlbumPurchase.setPurchasePrice(userOrderDetailVo.getActualPrice());
|
|
|
- tenantAlbumPurchase.setPurchaseStatus(OrderStatusEnum.PAID.getCode());
|
|
|
- tenantAlbumPurchaseService.save(tenantAlbumPurchase);
|
|
|
-
|
|
|
- List<TenantActivationCode> tenantActivationCodes = new ArrayList<>();
|
|
|
- for (int i = 0; i < userOrderDetailVo.getGoodNum(); i++) {
|
|
|
- TenantActivationCode tenantActivationCode = new TenantActivationCode();
|
|
|
- tenantActivationCode.setTenantId(tenantAlbumContent.getTenantId());
|
|
|
- tenantActivationCode.setTenantAlbumId(tenantAlbumContent.getTenantAlbumId());
|
|
|
- tenantActivationCode.setTenantAlbumPurchaseId(tenantAlbumPurchase.getId());
|
|
|
-// tenantActivationCode.setActivationCode(StringUtil.DeciamlToThirtySix(IdWorker.get32UUID()));
|
|
|
- tenantActivationCode.setActivationCode(IdWorker.get32UUID());
|
|
|
- tenantActivationCode.setSendStatus(EActivationCode.WAIT);
|
|
|
- tenantActivationCodes.add(tenantActivationCode);
|
|
|
- }
|
|
|
- tenantActivationCodeService.saveBatch(tenantActivationCodes);
|
|
|
- break;
|
|
|
- }
|
|
|
+ // 机构 插入机构专辑购买记录,生成机构专辑激活码
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增机构专辑
|
|
|
+ * @param album
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Boolean insertTenantAlbum(TenantAlbumWrapper.TenantAlbum album) {
|
|
|
+ SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
|
+ TenantInfo tenantInfo = tenantInfoService.lambdaQuery().eq(TenantInfo::getUserId, sysUser.getId())
|
|
|
+ .last("limit 1").one();
|
|
|
+ if (tenantInfo == null) {
|
|
|
+ throw new BizException("非法请求");
|
|
|
+ }
|
|
|
+
|
|
|
+ //给机构专辑赋值
|
|
|
+ TenantAlbum tenantAlbum = new TenantAlbum();
|
|
|
+ tenantAlbum.setName(album.getName());
|
|
|
+ tenantAlbum.setDescribe(album.getDescribe());
|
|
|
+ tenantAlbum.setCoverImg(album.getCoverImg());
|
|
|
+ tenantAlbum.setPurchaseCycle(album.getPurchaseCycle());
|
|
|
+ tenantAlbum.setSalePrice(album.getSalePrice());
|
|
|
+
|
|
|
+ //tenantAlbumService.addTenantAlbum(tenantAlbum);
|
|
|
+ add(tenantAlbum);
|
|
|
+ //关联表赋值
|
|
|
+ //tenantAlbumService.addTenantId(album.getTenantId());
|
|
|
+ TenantAlbumRef ref = new TenantAlbumRef();
|
|
|
+ ref.setTenantAlbumId(album.getId());
|
|
|
+ ref.setTenantId(album.getTenantId());
|
|
|
+ tenantAlbumRefService.add(ref);
|
|
|
+ //曲目表赋值
|
|
|
+ List<TenantAlbumWrapper.TenantAlbum.MusicSheetData> data = album.getMusicSheetData();
|
|
|
+
|
|
|
+ List<TenantAlbumMusic> tenantAlbumMusics = album.getMusicSheetData().stream().map(next -> {
|
|
|
+
|
|
|
+ AtomicInteger sort = new AtomicInteger(0);
|
|
|
+ return next.getMusicSheetIdList().stream().map(tenantAlbumMusic -> {
|
|
|
+
|
|
|
+ TenantAlbumMusic tenantAlbumMusic1 = new TenantAlbumMusic();
|
|
|
+ //tenantAlbumMusic1.setId(tenantAlbumMusic);
|
|
|
+ tenantAlbumMusic1.setSubjectType(next.getSubjectType());
|
|
|
+ tenantAlbumMusic1.setTenantId(album.getTenantId());
|
|
|
+ tenantAlbumMusic1.setMusicSheetId(tenantAlbumMusic);
|
|
|
+ tenantAlbumMusic1.setDelFlag(true);
|
|
|
+ tenantAlbumMusic1.setTenantAlbumId(tenantAlbum.getId());
|
|
|
+ tenantAlbumMusic1.setSortNumber(sort.getAndIncrement());
|
|
|
+ return tenantAlbumMusic1;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ }).flatMap(Collection::stream).collect(Collectors.toList());
|
|
|
+
|
|
|
+ if(!tenantAlbumMusics.isEmpty()){
|
|
|
+ tenantAlbumMusicService.saveBatch(tenantAlbumMusics,100);
|
|
|
}
|
|
|
|
|
|
+ return true;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|