|
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import com.yonge.cooleshow.biz.dal.dao.StudentDao;
|
|
|
import com.yonge.cooleshow.biz.dal.entity.*;
|
|
|
import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
|
|
@@ -15,20 +16,27 @@ import com.yonge.cooleshow.biz.dal.mapper.UserTenantAlbumRecordMapper;
|
|
|
import com.yonge.cooleshow.biz.dal.service.TenantActivationCodeService;
|
|
|
import com.yonge.cooleshow.biz.dal.service.TenantAlbumService;
|
|
|
import com.yonge.cooleshow.biz.dal.vo.UserOrderDetailVo;
|
|
|
+import com.yonge.cooleshow.biz.dal.wrapper.StudentWrapper;
|
|
|
import com.yonge.cooleshow.biz.dal.wrapper.TenantActivationCodeWrapper;
|
|
|
import com.yonge.cooleshow.biz.dal.wrapper.TenantAlbumWrapper;
|
|
|
import com.yonge.cooleshow.common.enums.EActivationCode;
|
|
|
import com.yonge.toolset.base.exception.BizException;
|
|
|
+import com.yonge.toolset.utils.easyexcel.ExcelDataReaderProperty;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Calendar;
|
|
|
+import java.util.Comparator;
|
|
|
import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -193,7 +201,7 @@ public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivatio
|
|
|
Integer purchaseCycle = purchase.getPurchaseCycle();
|
|
|
|
|
|
|
|
|
- addUserTenantAlbumRecord(student.getUserId(), purchase,null);
|
|
|
+ addUserTenantAlbumRecord(student.getUserId(), purchase, null);
|
|
|
|
|
|
// 更新购买记录中激活码使用统计数量值
|
|
|
Integer activeCodeNumber = this.lambdaQuery()
|
|
@@ -211,7 +219,7 @@ public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivatio
|
|
|
/**
|
|
|
* 添加用户机构专辑激活记录
|
|
|
*
|
|
|
- * @param studentId 学生ID
|
|
|
+ * @param studentId 学生ID
|
|
|
* @param userOrderDetailVo 订单详情
|
|
|
*/
|
|
|
@Override
|
|
@@ -221,7 +229,79 @@ public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivatio
|
|
|
|
|
|
}
|
|
|
|
|
|
- private void addUserTenantAlbumRecord(Long studentId, TenantAlbumPurchase purchase, UserOrderDetailVo userOrderDetailVo) {
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void importActiveCode(List<ExcelDataReaderProperty<TenantActivationCodeWrapper.ImportTemplate>> dataList,
|
|
|
+ Long tenantId, Long userId) {
|
|
|
+ if (dataList.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ dataList.sort(Comparator.comparingInt(ExcelDataReaderProperty::getRowIndex));
|
|
|
+
|
|
|
+ List<String> errMsg = new ArrayList<>();
|
|
|
+ Set<String> codeSet = new HashSet<>();
|
|
|
+ Map<String, Integer> codeRowMap = new HashMap<>();
|
|
|
+ // 校验数据格式是否错误
|
|
|
+ for (ExcelDataReaderProperty<TenantActivationCodeWrapper.ImportTemplate> next : dataList) {
|
|
|
+ Integer rowIndex = next.getRowIndex();
|
|
|
+ TenantActivationCodeWrapper.ImportTemplate code = next.getClazz();
|
|
|
+
|
|
|
+ int msgRowNo = rowIndex + 1;
|
|
|
+ code.checkIsIllegal().forEach(err -> errMsg.add(String.format("第%s行%s", msgRowNo, err)));
|
|
|
+ if (codeSet.contains(code.getCode())) {
|
|
|
+ errMsg.add(String.format("第%s行%s", msgRowNo, "激活码重复"));
|
|
|
+ } else {
|
|
|
+ codeSet.add(code.getCode());
|
|
|
+ }
|
|
|
+ codeRowMap.put(code.getCode().trim(), msgRowNo);
|
|
|
+
|
|
|
+ if (errMsg.size() > 100) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!errMsg.isEmpty()) {
|
|
|
+ throw new BizException(String.join(",", errMsg));
|
|
|
+ }
|
|
|
+ // 校验激活码是否被使用
|
|
|
+ List<List<String>> codePartition = Lists.partition(new ArrayList<>(codeRowMap.keySet()), 50);
|
|
|
+ for (List<String> codes : codePartition) {
|
|
|
+ List<TenantActivationCode> activationCodes = this.lambdaQuery()
|
|
|
+ .eq(TenantActivationCode::getTenantId,tenantId)
|
|
|
+ .in(TenantActivationCode::getActivationCode, codes).list();
|
|
|
+
|
|
|
+ // 存在无效码或者已经使用过的码
|
|
|
+ if (codes.size() != activationCodes.size() ||
|
|
|
+ activationCodes.stream().anyMatch(TenantActivationCode::getActivationStatus)) {
|
|
|
+ Map<String, Boolean> codeStatusMap = activationCodes.stream()
|
|
|
+ .collect(Collectors.toMap(TenantActivationCode::getActivationCode,
|
|
|
+ TenantActivationCode::getActivationStatus));
|
|
|
+ for (String code : codes) {
|
|
|
+ if (!codeStatusMap.containsKey(code)) {
|
|
|
+ errMsg.add(String.format("第%s行%s", codeRowMap.get(code), "验证码无效"));
|
|
|
+ } else if (Boolean.TRUE.equals(codeStatusMap.get(code))) {
|
|
|
+ errMsg.add(String.format("第%s行%s", codeRowMap.get(code), "验证码已经激活"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!errMsg.isEmpty()) {
|
|
|
+ throw new BizException(String.join(",", errMsg));
|
|
|
+ }
|
|
|
+
|
|
|
+ for (List<String> codes : codePartition) {
|
|
|
+// this.lambdaUpdate()
|
|
|
+// .set(TenantActivationCode::getSendStatus,EActivationCode.SEND)
|
|
|
+// .set(TenantActivationCode::getActivationStatus,true)
|
|
|
+// .set(TenantActivationCode)
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addUserTenantAlbumRecord(Long studentId, TenantAlbumPurchase purchase,
|
|
|
+ UserOrderDetailVo userOrderDetailVo) {
|
|
|
|
|
|
|
|
|
UserTenantAlbumRecord userTenantAlbumRecord = new UserTenantAlbumRecord();
|
|
@@ -253,7 +333,6 @@ public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivatio
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
QueryWrapper<UserTenantAlbumRecord> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.lambda()
|
|
|
.eq(UserTenantAlbumRecord::getTenantId, userTenantAlbumRecord.getTenantId())
|