|
@@ -5,11 +5,7 @@ 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.yonge.cooleshow.biz.dal.dao.StudentDao;
|
|
|
-import com.yonge.cooleshow.biz.dal.entity.Student;
|
|
|
-import com.yonge.cooleshow.biz.dal.entity.SysUser;
|
|
|
-import com.yonge.cooleshow.biz.dal.entity.TenantActivationCode;
|
|
|
-import com.yonge.cooleshow.biz.dal.entity.TenantAlbumPurchase;
|
|
|
-import com.yonge.cooleshow.biz.dal.entity.UserTenantAlbumRecord;
|
|
|
+import com.yonge.cooleshow.biz.dal.entity.*;
|
|
|
import com.yonge.cooleshow.biz.dal.enums.ClientEnum;
|
|
|
import com.yonge.cooleshow.biz.dal.enums.SourceTypeEnum;
|
|
|
import com.yonge.cooleshow.biz.dal.mapper.SysUserMapper;
|
|
@@ -17,7 +13,11 @@ import com.yonge.cooleshow.biz.dal.mapper.TenantActivationCodeMapper;
|
|
|
import com.yonge.cooleshow.biz.dal.mapper.TenantAlbumPurchaseMapper;
|
|
|
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.TenantActivationCodeWrapper;
|
|
|
+import com.yonge.cooleshow.biz.dal.wrapper.TenantAlbumWrapper;
|
|
|
+import com.yonge.cooleshow.common.enums.EActivationCode;
|
|
|
import com.yonge.toolset.base.exception.BizException;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
@@ -51,6 +51,9 @@ public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivatio
|
|
|
@Autowired
|
|
|
private UserTenantAlbumRecordMapper userTenantAlbumRecordMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private TenantAlbumService tenantAlbumService;
|
|
|
+
|
|
|
/**
|
|
|
* 查询详情
|
|
|
*
|
|
@@ -138,7 +141,7 @@ public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivatio
|
|
|
for (Long studentId : studentIds) {
|
|
|
for (TenantActivationCode tenantActivationCode : tenantActivationCodes) {
|
|
|
boolean update = this.lambdaUpdate()
|
|
|
- .set(TenantActivationCode::getSendStatus, "SEND")
|
|
|
+ .set(TenantActivationCode::getSendStatus, EActivationCode.SEND.getCode())
|
|
|
.set(TenantActivationCode::getActivationPhone, idPhoneMap.get(studentId))
|
|
|
.eq(TenantActivationCode::getActivationStatus, false)
|
|
|
.eq(TenantActivationCode::getId, tenantActivationCode.getId())
|
|
@@ -151,6 +154,7 @@ public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivatio
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void active(String activationCode, Long studentId) {
|
|
|
Student student = studentDao.selectById(studentId);
|
|
|
if (student == null) {
|
|
@@ -184,32 +188,86 @@ public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivatio
|
|
|
if (!update) {
|
|
|
throw new BizException("激活码已经被使用");
|
|
|
}
|
|
|
+ Long tenantAlbumPurchaseId = code.getTenantAlbumPurchaseId();
|
|
|
+ TenantAlbumPurchase purchase = tenantAlbumPurchaseMapper.selectById(tenantAlbumPurchaseId);
|
|
|
+ Integer purchaseCycle = purchase.getPurchaseCycle();
|
|
|
+
|
|
|
+
|
|
|
+ addUserTenantAlbumRecord(student.getUserId(), purchase,null);
|
|
|
+
|
|
|
+ // 更新购买记录中激活码使用统计数量值
|
|
|
+ Integer activeCodeNumber = this.lambdaQuery()
|
|
|
+ .eq(TenantActivationCode::getTenantId, tenantId)
|
|
|
+ .eq(TenantActivationCode::getTenantAlbumPurchaseId, code.getTenantAlbumPurchaseId())
|
|
|
+ .eq(TenantActivationCode::getActivationStatus, true).count();
|
|
|
+
|
|
|
+ TenantAlbumPurchase tenantAlbumPurchase = new TenantAlbumPurchase();
|
|
|
+ tenantAlbumPurchase.setId(code.getTenantAlbumPurchaseId());
|
|
|
+ tenantAlbumPurchase.setActiveQuantity(activeCodeNumber);
|
|
|
+ tenantAlbumPurchaseMapper.updateById(tenantAlbumPurchase);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加用户机构专辑激活记录
|
|
|
+ *
|
|
|
+ * @param studentId 学生ID
|
|
|
+ * @param userOrderDetailVo 订单详情
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void addUserTenantAlbumRecord(Long studentId, UserOrderDetailVo userOrderDetailVo) {
|
|
|
+ addUserTenantAlbumRecord(studentId, null, userOrderDetailVo);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addUserTenantAlbumRecord(Long studentId, TenantAlbumPurchase purchase, UserOrderDetailVo userOrderDetailVo) {
|
|
|
+
|
|
|
+
|
|
|
+ UserTenantAlbumRecord userTenantAlbumRecord = new UserTenantAlbumRecord();
|
|
|
+ if (userOrderDetailVo != null) {
|
|
|
+
|
|
|
+ TenantAlbumWrapper.TenantAlbumContent tenantAlbumContent = JSON
|
|
|
+ .parseObject(JSON.toJSONString(userOrderDetailVo.getBizContent()), TenantAlbumWrapper.TenantAlbumContent.class);
|
|
|
+
|
|
|
+ userTenantAlbumRecord.setTenantId(tenantAlbumContent.getTenantId());
|
|
|
+ userTenantAlbumRecord.setUserId(studentId);
|
|
|
+ userTenantAlbumRecord.setTenantAlbumId(tenantAlbumContent.getTenantAlbumId());
|
|
|
+ userTenantAlbumRecord.setOrderNo(userOrderDetailVo.getOrderNo());
|
|
|
+ userTenantAlbumRecord.setSourceType(SourceTypeEnum.ORDER);
|
|
|
+ userTenantAlbumRecord.setClientType(ClientEnum.STUDENT);
|
|
|
+ userTenantAlbumRecord.setSubOrderNo(userOrderDetailVo.getSubOrderNo());
|
|
|
+ userTenantAlbumRecord.setCreateBy(studentId);
|
|
|
+ userTenantAlbumRecord.setTimes(tenantAlbumContent.getBuyCycle());
|
|
|
+ } else if (purchase != null) {
|
|
|
+
|
|
|
+ userTenantAlbumRecord.setTenantId(purchase.getTenantId());
|
|
|
+ userTenantAlbumRecord.setUserId(studentId);
|
|
|
+ userTenantAlbumRecord.setTenantAlbumId(purchase.getTenantAlbumId());
|
|
|
+ userTenantAlbumRecord.setOrderNo(purchase.getId().toString());
|
|
|
+ userTenantAlbumRecord.setSourceType(SourceTypeEnum.TENANT);
|
|
|
+ userTenantAlbumRecord.setClientType(ClientEnum.STUDENT);
|
|
|
+ userTenantAlbumRecord.setSubOrderNo(purchase.getId().toString());
|
|
|
+ userTenantAlbumRecord.setCreateBy(studentId);
|
|
|
+ userTenantAlbumRecord.setTimes(purchase.getPurchaseCycle());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
QueryWrapper<UserTenantAlbumRecord> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.lambda()
|
|
|
- .eq(UserTenantAlbumRecord::getTenantId, student.getTenantId())
|
|
|
- .eq(UserTenantAlbumRecord::getUserId, student.getUserId())
|
|
|
- .eq(UserTenantAlbumRecord::getTenantAlbumId, code.getTenantAlbumId())
|
|
|
+ .eq(UserTenantAlbumRecord::getTenantId, userTenantAlbumRecord.getTenantId())
|
|
|
+ .eq(UserTenantAlbumRecord::getUserId, studentId)
|
|
|
+ .eq(UserTenantAlbumRecord::getTenantAlbumId, userTenantAlbumRecord.getTenantAlbumId())
|
|
|
.eq(UserTenantAlbumRecord::getClientType, ClientEnum.STUDENT)
|
|
|
.orderByDesc(UserTenantAlbumRecord::getEndTime);
|
|
|
List<UserTenantAlbumRecord> userTenantAlbumRecords = userTenantAlbumRecordMapper.selectList(queryWrapper);
|
|
|
|
|
|
- UserTenantAlbumRecord userTenantAlbumRecord = new UserTenantAlbumRecord();
|
|
|
- userTenantAlbumRecord.setTenantId(student.getTenantId());
|
|
|
- userTenantAlbumRecord.setUserId(student.getUserId());
|
|
|
- userTenantAlbumRecord.setTenantAlbumId(code.getTenantAlbumId());
|
|
|
- userTenantAlbumRecord.setOrderNo("");
|
|
|
- userTenantAlbumRecord.setSourceType(SourceTypeEnum.TENANT);
|
|
|
- userTenantAlbumRecord.setClientType(ClientEnum.STUDENT);
|
|
|
- userTenantAlbumRecord.setSubOrderNo("");
|
|
|
- userTenantAlbumRecord.setCreateBy(student.getUserId());
|
|
|
+ userTenantAlbumRecord.setUserId(studentId);
|
|
|
+ userTenantAlbumRecord.setCreateBy(studentId);
|
|
|
|
|
|
- Long tenantAlbumPurchaseId = code.getTenantAlbumPurchaseId();
|
|
|
- TenantAlbumPurchase purchase = tenantAlbumPurchaseMapper.selectById(tenantAlbumPurchaseId);
|
|
|
- Integer purchaseCycle = purchase.getPurchaseCycle();
|
|
|
|
|
|
userTenantAlbumRecord.setType("MONTH");
|
|
|
- userTenantAlbumRecord.setTimes(purchaseCycle);
|
|
|
|
|
|
Calendar instance = Calendar.getInstance();
|
|
|
if (userTenantAlbumRecords.isEmpty()) {
|
|
@@ -226,19 +284,8 @@ public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivatio
|
|
|
}
|
|
|
}
|
|
|
userTenantAlbumRecord.setStartTime(instance.getTime());
|
|
|
- instance.add(Calendar.MONTH, purchaseCycle);
|
|
|
+ instance.add(Calendar.MONTH, userTenantAlbumRecord.getTimes());
|
|
|
userTenantAlbumRecord.setEndTime(instance.getTime());
|
|
|
userTenantAlbumRecordMapper.insert(userTenantAlbumRecord);
|
|
|
-
|
|
|
- // 更新购买记录中激活码使用统计数量值
|
|
|
- Integer activeCodeNumber = this.lambdaQuery()
|
|
|
- .eq(TenantActivationCode::getTenantId, tenantId)
|
|
|
- .eq(TenantActivationCode::getTenantAlbumPurchaseId, code.getTenantAlbumPurchaseId())
|
|
|
- .eq(TenantActivationCode::getActivationStatus, true).count();
|
|
|
-
|
|
|
- TenantAlbumPurchase tenantAlbumPurchase = new TenantAlbumPurchase();
|
|
|
- tenantAlbumPurchase.setId(code.getTenantAlbumPurchaseId());
|
|
|
- tenantAlbumPurchase.setActiveQuantity(activeCodeNumber);
|
|
|
- tenantAlbumPurchaseMapper.updateById(tenantAlbumPurchase);
|
|
|
}
|
|
|
}
|