添加 开展活动接口

This commit is contained in:
2024-07-19 15:40:54 +08:00
parent aa1eb7411e
commit c46f65600f
7 changed files with 165 additions and 18 deletions

View File

@@ -141,4 +141,12 @@ public interface AccountService extends IService<Account> {
Boolean collectQuestionnaires(String questionnaireInfo);
void refreshCreditsWeekly();
List<Account> getExpiredUserBySystemUser(Integer systemUserNum);
String getActivityBenefits();
void toVisitor(Account account);
List<Long> setUserValidToDayEnd();
}

View File

@@ -44,12 +44,10 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
@@ -392,7 +390,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
// account.setUserName(accountAddDTO.getUserName());
// account.setIsTrial(accountAddDTO.getIsTrial());
account.setValidStartTime(Long.valueOf(accountAddDTO.getValidStartTime()));
account.setValidEndTime(Long.valueOf(accountAddDTO.getValidEndTime()));
account.setValidEndTime(toDayEnd(Long.parseLong(accountAddDTO.getValidEndTime())));
account.setUserPassword("Third-000000");
account.setLanguage(Language.ENGLISH.name());
account.setCreateDate(new Date());
@@ -439,7 +437,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
Account accountSelect = accountMapper.selectOne(queryTotal);
Assert.notNull(accountSelect, "oldUserName does not exist!");
account.setValidEndTime(Long.valueOf(accountEditDTO.getNewValidEndTime()));
account.setValidEndTime(toDayEnd(Long.parseLong(accountEditDTO.getNewValidEndTime())));
}
Account accountSelect = accountMapper.selectOne(queryTotal);
Assert.notNull(accountSelect, "oldAccount does not exist!");
@@ -541,9 +539,9 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
account.setSystemUser(3);
account.setValidStartTime(System.currentTimeMillis());
if (link) {
account.setValidEndTime(Instant.now().plus(14, ChronoUnit.DAYS).toEpochMilli());
account.setValidEndTime(toDayEnd(Instant.now().plus(14, ChronoUnit.DAYS).toEpochMilli()));
} else {
account.setValidEndTime(Instant.now().plus(5, ChronoUnit.DAYS).toEpochMilli());
account.setValidEndTime(toDayEnd(Instant.now().plus(5, ChronoUnit.DAYS).toEpochMilli()));
}
accountMapper.updateById(account);
} else {
@@ -553,9 +551,9 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
account.setLanguage(Language.ENGLISH.name());
account.setValidStartTime(System.currentTimeMillis());
if (link) {
account.setValidEndTime(Instant.now().plus(14, ChronoUnit.DAYS).toEpochMilli());
account.setValidEndTime(toDayEnd(Instant.now().plus(14, ChronoUnit.DAYS).toEpochMilli()));
} else {
account.setValidEndTime(Instant.now().plus(5, ChronoUnit.DAYS).toEpochMilli());
account.setValidEndTime(toDayEnd(Instant.now().plus(5, ChronoUnit.DAYS).toEpochMilli()));
}
account.setCreateDate(new Date());
account.setIsTrial(1);
@@ -602,7 +600,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
account.setIsTrial(1);
account.setIsBeginner(1);
account.setValidStartTime(System.currentTimeMillis());
account.setValidEndTime(Instant.now().plus(5, ChronoUnit.DAYS).toEpochMilli());
account.setValidEndTime(toDayEnd(Instant.now().plus(5, ChronoUnit.DAYS).toEpochMilli()));
accountMapper.updateById(account);
} else {
account.setUserName(trialOrder.getUserName());
@@ -610,7 +608,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
account.setUserEmail(trialOrder.getEmail());
account.setLanguage(Language.ENGLISH.name());
account.setValidStartTime(System.currentTimeMillis());
account.setValidEndTime(Instant.now().plus(5, ChronoUnit.DAYS).toEpochMilli());
account.setValidEndTime(toDayEnd(Instant.now().plus(5, ChronoUnit.DAYS).toEpochMilli()));
account.setCreateDate(new Date());
account.setIsTrial(1);
account.setIsBeginner(1);
@@ -975,7 +973,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
Account account = new Account();
account.setId(accountId);
account.setCredits(new BigDecimal(value));
account.setValidEndTime(endTime);
account.setValidEndTime(toDayEnd(endTime));
accountMapper.updateById(account);
}
@@ -1133,11 +1131,11 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
country,
account.getValidStartTime().toString(),
account.getValidEndTime().toString(), 0,new BigDecimal(credits),systemUserType));
if (b) log.info("付费新用户新增成功!");
if (b) log.info("付费新用户 {} 新增成功!", email);
} else {
userInfo.setValidEndTime(account.getValidEndTime());
userInfo.setValidEndTime(toDayEnd(account.getValidEndTime()));
baseMapper.updateById(userInfo);
log.info("付费用户续订成功");
log.info("付费用户 {} 续订成功", email);
}
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
@@ -1197,7 +1195,7 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
validityExtension = specifiedDateTime.plusDays(1);
}
// 获取一个月之后的时间的 Unix 毫秒级时间戳
account.setValidEndTime(validityExtension.toInstant().toEpochMilli());
account.setValidEndTime(toDayEnd(validityExtension.toInstant().toEpochMilli()));
return account;
}
@@ -1266,4 +1264,89 @@ public class AccountServiceImpl extends ServiceImpl<AccountMapper, Account> impl
baseMapper.update(null,accountUpdateWrapper);
}
@Override
public String getActivityBenefits(){
Long id = UserContext.getUserHolder().getId();
// 1、 判断用户的身份 正式用户 无福利
Account account = baseMapper.selectById(id);
Integer systemUser = account.getSystemUser();
Instant now = Instant.now();
ZoneId zoneId = ZoneId.of("Asia/Shanghai");
ZonedDateTime specifiedDateTime;
if (systemUser.equals(1)){
long validEndTime = Objects.isNull(account.getValidEndTime()) ? now.toEpochMilli() : account.getValidEndTime();
specifiedDateTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(validEndTime), zoneId);
account.setValidEndTime(toDayEnd(specifiedDateTime.plusDays(30).toInstant().toEpochMilli()));
}else if (systemUser.equals(4)){
throw new BusinessException("You have participated in the event", 1);
}else if (systemUser.equals(0) || systemUser.equals(3)){
// 2、赋予游客或试用用户 以正式用户的权限 即 积分置为6000有效期30天
// 将 Instant 转换为 ZonedDateTime使用指定时区
specifiedDateTime = ZonedDateTime.ofInstant(now, zoneId);
account.setIsTrial(0);
account.setSystemUser(4);
account.setCredits(BigDecimal.valueOf(6000));
account.setValidStartTime(now.toEpochMilli());
account.setValidEndTime(toDayEnd(specifiedDateTime.plusDays(30).toInstant().toEpochMilli()));
}
account.setUpdateDate(new Date());
baseMapper.updateById(account);
return "参与成功";
}
// 将指定unix时间置为当天的235959
public long toDayEnd(long unixTimestampMillis){
// 将UNIX时间戳转换为LocalDateTime对象
LocalDateTime dateTime = Instant.ofEpochMilli(unixTimestampMillis)
.atZone(ZoneId.systemDefault())
.toLocalDateTime();
// 获取日期部分并设置时间为23:59:59
LocalDate date = dateTime.toLocalDate();
LocalDateTime endOfDay = date.atTime(LocalTime.of(23, 59, 59));
// 将LocalDateTime对象转换为UNIX时间戳以毫秒为单位 北京时间
return endOfDay.toInstant(ZoneOffset.ofHours(8)).toEpochMilli();
}
/**
* 获取指定身份过期用户
* @param systemUserNum
* @return
*/
public List<Account> getExpiredUserBySystemUser(Integer systemUserNum){
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
long now = Instant.now().toEpochMilli();
queryWrapper.eq("system_user", systemUserNum)
.isNotNull("valid_end_time")
.lt("valid_end_time", now);
return baseMapper.selectList(queryWrapper);
}
public void toVisitor(Account account){
accountMapper.toVisitor(account.getId(), new Date());
}
public List<Long> setUserValidToDayEnd(){
// 获取当前未过期的用户并将其有效期设置为过期当日的235959
QueryWrapper<Account> queryWrapper = new QueryWrapper<>();
long now = Instant.now().toEpochMilli();
queryWrapper.isNotNull("valid_end_time").gt("valid_end_time", now);
List<Account> accounts = baseMapper.selectList(queryWrapper);
ArrayList<Long> ids = new ArrayList<>();
for (Account account: accounts) {
account.setValidEndTime(toDayEnd(account.getValidEndTime()));
ids.add(account.getId());
updateById(account);
}
return ids;
}
}