|
@@ -8,17 +8,22 @@ 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.mapper.SysUserMapper;
|
|
|
import com.yonge.cooleshow.biz.dal.mapper.TenantActivationCodeMapper;
|
|
|
+import com.yonge.cooleshow.biz.dal.mapper.TenantAlbumPurchaseMapper;
|
|
|
import com.yonge.cooleshow.biz.dal.service.TenantActivationCodeService;
|
|
|
import com.yonge.cooleshow.biz.dal.wrapper.TenantActivationCodeWrapper;
|
|
|
import com.yonge.toolset.base.exception.BizException;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
+import org.redisson.api.RLock;
|
|
|
+import org.redisson.api.RedissonClient;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -37,6 +42,9 @@ public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivatio
|
|
|
@Autowired
|
|
|
private SysUserMapper sysUserMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private TenantAlbumPurchaseMapper tenantAlbumPurchaseMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 查询详情
|
|
|
*
|
|
@@ -135,4 +143,51 @@ public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivatio
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void active(String activationCode, Long studentId) {
|
|
|
+ Student student = studentDao.selectById(studentId);
|
|
|
+ if (student == null) {
|
|
|
+ throw new BizException("学生不存在");
|
|
|
+ }
|
|
|
+ Long tenantId = -1L;
|
|
|
+ if (student.getTenantId() != null) {
|
|
|
+ tenantId = student.getTenantId();
|
|
|
+ }
|
|
|
+
|
|
|
+ TenantActivationCode code = this.lambdaQuery().eq(TenantActivationCode::getTenantId, tenantId)
|
|
|
+ .eq(TenantActivationCode::getActivationCode, activationCode)
|
|
|
+ .last("limit 1").one();
|
|
|
+ if (code == null) {
|
|
|
+ throw new BizException("激活码不存在");
|
|
|
+ }
|
|
|
+ if (Boolean.TRUE.equals(code.getActivationStatus())) {
|
|
|
+ throw new BizException("激活码已经被使用");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 通过状态和ID同时判断更新是否存在竞争
|
|
|
+ boolean update = this.lambdaUpdate()
|
|
|
+ .set(TenantActivationCode::getActivationStatus, true)
|
|
|
+ .set(TenantActivationCode::getActivationUserId, student.getUserId())
|
|
|
+ .set(TenantActivationCode::getActivationTime, new Date())
|
|
|
+ .eq(TenantActivationCode::getId, code.getId())
|
|
|
+ .eq(TenantActivationCode::getActivationStatus, false)
|
|
|
+ .update();
|
|
|
+ if (!update) {
|
|
|
+ throw new BizException("激活码已经被使用");
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo 更新会员信息,如果更新异常,回滚激活码
|
|
|
+
|
|
|
+ // 更新购买记录中激活码使用统计数量值
|
|
|
+ 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);
|
|
|
+ }
|
|
|
}
|