|
@@ -9,20 +9,23 @@ 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.enums.ClientEnum;
|
|
|
+import com.yonge.cooleshow.biz.dal.enums.SourceTypeEnum;
|
|
|
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.mapper.UserTenantAlbumRecordMapper;
|
|
|
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.Calendar;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -45,6 +48,9 @@ public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivatio
|
|
|
@Autowired
|
|
|
private TenantAlbumPurchaseMapper tenantAlbumPurchaseMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private UserTenantAlbumRecordMapper userTenantAlbumRecordMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 查询详情
|
|
|
*
|
|
@@ -165,11 +171,13 @@ public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivatio
|
|
|
throw new BizException("激活码已经被使用");
|
|
|
}
|
|
|
|
|
|
+ SysUser sysUser = sysUserMapper.selectById(studentId);
|
|
|
// 通过状态和ID同时判断更新是否存在竞争
|
|
|
boolean update = this.lambdaUpdate()
|
|
|
.set(TenantActivationCode::getActivationStatus, true)
|
|
|
.set(TenantActivationCode::getActivationUserId, student.getUserId())
|
|
|
.set(TenantActivationCode::getActivationTime, new Date())
|
|
|
+ .set(TenantActivationCode::getActivationPhone, sysUser.getPhone())
|
|
|
.eq(TenantActivationCode::getId, code.getId())
|
|
|
.eq(TenantActivationCode::getActivationStatus, false)
|
|
|
.update();
|
|
@@ -177,7 +185,50 @@ public class TenantActivationCodeServiceImpl extends ServiceImpl<TenantActivatio
|
|
|
throw new BizException("激活码已经被使用");
|
|
|
}
|
|
|
|
|
|
- // todo 更新会员信息,如果更新异常,回滚激活码
|
|
|
+ QueryWrapper<UserTenantAlbumRecord> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.lambda()
|
|
|
+ .eq(UserTenantAlbumRecord::getTenantId, student.getTenantId())
|
|
|
+ .eq(UserTenantAlbumRecord::getUserId, student.getUserId())
|
|
|
+ .eq(UserTenantAlbumRecord::getTenantAlbumId, code.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());
|
|
|
+
|
|
|
+ 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()) {
|
|
|
+ instance.setTime(new Date());
|
|
|
+ } else {
|
|
|
+ // 如果最后一次的时间的小于当前时间,则以当前时间为会员的开始时间
|
|
|
+ // 如果最后一次的时间的大于当前时间,则以最后一次的结束时间为记录的开始时间,相当会员续期
|
|
|
+ UserTenantAlbumRecord lastRecord = userTenantAlbumRecords.get(0);
|
|
|
+ Date lastEndTime = lastRecord.getEndTime();
|
|
|
+ if (lastEndTime.before(new Date())) {
|
|
|
+ instance.setTime(new Date());
|
|
|
+ } else {
|
|
|
+ instance.setTime(lastEndTime);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ userTenantAlbumRecord.setStartTime(instance.getTime());
|
|
|
+ instance.add(Calendar.MONTH, purchaseCycle);
|
|
|
+ userTenantAlbumRecord.setEndTime(instance.getTime());
|
|
|
+ userTenantAlbumRecordMapper.insert(userTenantAlbumRecord);
|
|
|
|
|
|
// 更新购买记录中激活码使用统计数量值
|
|
|
Integer activeCodeNumber = this.lambdaQuery()
|