|
|
@@ -1,13 +1,17 @@
|
|
|
package com.izouma.nineth.service;
|
|
|
|
|
|
-import com.izouma.nineth.domain.*;
|
|
|
+import com.izouma.nineth.domain.MetaSign;
|
|
|
+import com.izouma.nineth.domain.MetaSignAward;
|
|
|
+import com.izouma.nineth.domain.MetaSignRecord;
|
|
|
import com.izouma.nineth.dto.*;
|
|
|
import com.izouma.nineth.enums.MetaAwardTypeEnum;
|
|
|
-import com.izouma.nineth.repo.*;
|
|
|
+import com.izouma.nineth.repo.MetaSignAwardDrawRecordRepo;
|
|
|
+import com.izouma.nineth.repo.MetaSignAwardRepo;
|
|
|
+import com.izouma.nineth.repo.MetaSignRecordRepo;
|
|
|
+import com.izouma.nineth.repo.MetaSignRepo;
|
|
|
import com.izouma.nineth.utils.DateTimeUtils;
|
|
|
import com.izouma.nineth.utils.JpaUtils;
|
|
|
import com.izouma.nineth.utils.SecurityUtils;
|
|
|
-import com.izouma.nineth.web.MetaUserGoldController;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
@@ -33,73 +37,61 @@ public class MetaSignRecordService {
|
|
|
|
|
|
private MetaSignRepo metaSignRepo;
|
|
|
|
|
|
- private MetaUserGoldController metaUserGoldController;
|
|
|
-
|
|
|
- private MetaAccessoriesPurchaseRecordRepo metaAccessoriesPurchaseRecordRepo;
|
|
|
-
|
|
|
- private MetaAccessoriesRepo metaAccessoriesRepo;
|
|
|
+ private MetaAwardReceiveService metaAwardReceiveService;
|
|
|
|
|
|
public Page<MetaSignRecord> all(PageQuery pageQuery) {
|
|
|
return metaSignRecordRepo.findAll(JpaUtils.toSpecification(pageQuery, MetaSignRecord.class), JpaUtils.toPageRequest(pageQuery));
|
|
|
}
|
|
|
|
|
|
@Transactional
|
|
|
- public MetaRestResult<MetaSignRecord> save() {
|
|
|
+ public MetaRestResult<MetaSignRecord> save(Long channelId) {
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DateTimeUtils.DATE_FORMAT);
|
|
|
Long userId = SecurityUtils.getAuthenticatedUser().getId();
|
|
|
LocalDate signTime = LocalDate.parse(LocalDate.now().format(formatter), formatter);
|
|
|
- MetaSignRecord dbMetaSignRecord = metaSignRecordRepo.findByUserIdAndSignTimeAndDel(userId, signTime, false);
|
|
|
+ MetaSignRecord dbMetaSignRecord = metaSignRecordRepo.findByUserIdAndChannelIdAndSignTimeAndDel(userId, channelId, signTime, false);
|
|
|
if (Objects.nonNull(dbMetaSignRecord)) {
|
|
|
- return MetaRestResult.returnError("今日已经签到,不可重复签到");
|
|
|
+ return MetaRestResult.returnError("该频道下今日已经签到,不可重复签到");
|
|
|
}
|
|
|
MetaSignRecord metaSignRecord = new MetaSignRecord();
|
|
|
metaSignRecord.setSignTime(signTime);
|
|
|
metaSignRecord.setUserId(userId);
|
|
|
- MetaServiceResult result = drawAward(userId);
|
|
|
+ metaSignRecord.setChannelId(channelId);
|
|
|
+ MetaServiceResult result = drawAward(userId, channelId);
|
|
|
if (!result.isSuccess()) {
|
|
|
+ // 奖励领取失败,签到记录正常保存
|
|
|
+ metaSignRecordRepo.save(metaSignRecord);
|
|
|
return MetaRestResult.returnError(result.getMessage());
|
|
|
}
|
|
|
return MetaRestResult.returnSuccess(result.getMessage(), metaSignRecordRepo.save(metaSignRecord));
|
|
|
}
|
|
|
|
|
|
@Transactional
|
|
|
- public MetaServiceResult drawAward(Long userId) {
|
|
|
+ public MetaServiceResult drawAward(Long userId, Long channelId) {
|
|
|
String yyyyMMDate = LocalDate.now().format(DateTimeFormatter.ofPattern(DateTimeUtils.DATE_FORMAT_YYYY_MM));
|
|
|
- MetaSign metaSign = metaSignRepo.findByDateAndDel(yyyyMMDate, false);
|
|
|
+ MetaSign metaSign = metaSignRepo.findByDateAndChannelIdAndDel(yyyyMMDate, channelId, false);
|
|
|
if (Objects.isNull(metaSign)) {
|
|
|
- return MetaServiceResult.returnError(String.format("当前月份[%S]未配置签到规则和每日签到奖励", yyyyMMDate));
|
|
|
- }
|
|
|
- if (MetaAwardTypeEnum.GOLD.equals(metaSign.getAwardType())) {
|
|
|
- // 给用户增加金币
|
|
|
- metaUserGoldController.changeNum(userId, metaSign.getGoldNum());
|
|
|
- return MetaServiceResult.returnSuccess("签到成功,金币奖励已自动加入金币余额");
|
|
|
+ return MetaServiceResult.returnError(String.format("当前月份[%S]未配置该频道的签到规则和每日签到奖励", yyyyMMDate));
|
|
|
}
|
|
|
- if (MetaAwardTypeEnum.ACCESSORIES.equals(metaSign.getAwardType())) {
|
|
|
- Long metaAccessoriesId = metaSign.getMetaAccessoriesId();
|
|
|
- MetaAccessories metaAccessories = metaAccessoriesRepo.findByIdAndDel(metaAccessoriesId, false);
|
|
|
- if (Objects.isNull(metaAccessories)) {
|
|
|
- return MetaServiceResult.returnError("签到失败,配饰奖励不存在");
|
|
|
- }
|
|
|
- MetaAccessoriesPurchaseRecord metaAccessoriesPurchaseRecord = metaAccessoriesPurchaseRecordRepo.findByUserIdAndMetaAccessoriesId(userId, metaAccessoriesId);
|
|
|
- if (Objects.isNull(metaAccessoriesPurchaseRecord)) {
|
|
|
- metaAccessoriesPurchaseRecordRepo.save(new MetaAccessoriesPurchaseRecord(userId, metaAccessoriesId));
|
|
|
- return MetaServiceResult.returnSuccess("签到成功,配饰奖励领取成功");
|
|
|
- }
|
|
|
- // 配饰已经存在,转化为对应金币
|
|
|
- metaUserGoldController.changeNum(userId, metaAccessories.getPrice());
|
|
|
- return MetaServiceResult.returnSuccess("签到成功,玩家已经拥有该配饰,奖励自动转化为金币");
|
|
|
+ MetaAwardTypeEnum awardType = metaSign.getAwardType();
|
|
|
+ MetaAwardReceiveDTO metaAwardReceiveDTO = new MetaAwardReceiveDTO();
|
|
|
+ metaAwardReceiveDTO.setAwardType(awardType);
|
|
|
+ metaAwardReceiveDTO.setUserId(userId);
|
|
|
+ metaAwardReceiveDTO.setRemark("每日签到");
|
|
|
+ MetaServiceResult buildAwardConfigResult = metaAwardReceiveService.buildAwardConfig(metaAwardReceiveDTO, metaSign.getMetaPropId(), metaSign.getGoldNum());
|
|
|
+ if (!buildAwardConfigResult.isSuccess()) {
|
|
|
+ return buildAwardConfigResult;
|
|
|
}
|
|
|
- return MetaServiceResult.returnSuccess("签到成功,NFT奖励将在指定时间统一发放给用户");
|
|
|
+ return metaAwardReceiveService.receive(metaAwardReceiveDTO);
|
|
|
}
|
|
|
|
|
|
- public MetaRestResult<MetaSignProgressDTO> signProgress() {
|
|
|
+ public MetaRestResult<MetaSignProgressDTO> signProgress(Long channelId) {
|
|
|
Long userId = SecurityUtils.getAuthenticatedUser().getId();
|
|
|
DateTimeFormatter yyyyMM = DateTimeFormatter.ofPattern(DateTimeUtils.DATE_FORMAT_YYYY_MM);
|
|
|
DateTimeFormatter yyyyMMdd = DateTimeFormatter.ofPattern(DateTimeUtils.DATE_FORMAT);
|
|
|
String yyyyMMDate = LocalDate.now().format(yyyyMM);
|
|
|
- List<MetaSignAward> metaSignAwards = metaSignAwardRepo.findByDateAndDel(yyyyMMDate, false);
|
|
|
+ List<MetaSignAward> metaSignAwards = metaSignAwardRepo.findByDateAndChannelIdAndDel(yyyyMMDate, channelId, false);
|
|
|
if (CollectionUtils.isEmpty(metaSignAwards)) {
|
|
|
- return MetaRestResult.returnError(String.format("当前月份[%S]未配置任何签到奖励", yyyyMMDate));
|
|
|
+ return MetaRestResult.returnError(String.format("当前月份[%S]未配置该频道任何签到奖励", yyyyMMDate));
|
|
|
}
|
|
|
List<Long> metaSignAwardIds = metaSignAwardDrawRecordRepo.findMetaSignAwardIdsByUserIdAndDateAndDel(userId, yyyyMMDate);
|
|
|
if (CollectionUtils.isNotEmpty(metaSignAwardIds)) {
|
|
|
@@ -110,7 +102,7 @@ public class MetaSignRecordService {
|
|
|
});
|
|
|
}
|
|
|
LocalDate yyyyMMddDate = LocalDate.parse(LocalDate.now().format(yyyyMMdd), yyyyMMdd);
|
|
|
- MetaSignRecord metaSignRecord = metaSignRecordRepo.findByUserIdAndSignTimeAndDel(userId, yyyyMMddDate, false);
|
|
|
+ MetaSignRecord metaSignRecord = metaSignRecordRepo.findByUserIdAndChannelIdAndSignTimeAndDel(userId, channelId, yyyyMMddDate, false);
|
|
|
String isSignIn = null;
|
|
|
if (Objects.isNull(metaSignRecord)) {
|
|
|
isSignIn = LocalDate.now().format(yyyyMMdd);
|
|
|
@@ -119,7 +111,7 @@ public class MetaSignRecordService {
|
|
|
LocalDate firstDay = LocalDate.now().with(TemporalAdjusters.firstDayOfMonth());
|
|
|
// 获取当前月的最后一天
|
|
|
LocalDate lastDay = LocalDate.now().with(TemporalAdjusters.lastDayOfMonth());
|
|
|
- List<LocalDate> metaSignRecords = metaSignRecordRepo.findSigns(firstDay, lastDay, userId);
|
|
|
+ List<LocalDate> metaSignRecords = metaSignRecordRepo.findSigns(firstDay, lastDay, userId, channelId);
|
|
|
List<SignInCalendar> signInCalendars = queryAllDatesOfMonth();
|
|
|
if (CollectionUtils.isNotEmpty(metaSignRecords)) {
|
|
|
signInCalendars.forEach(signInCalendar -> {
|
|
|
@@ -128,9 +120,9 @@ public class MetaSignRecordService {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
- MetaSign metaSign = metaSignRepo.findByDateAndDel(yyyyMMDate, false);
|
|
|
+ MetaSign metaSign = metaSignRepo.findByDateAndChannelIdAndDel(yyyyMMDate, channelId, false);
|
|
|
if (Objects.isNull(metaSign)) {
|
|
|
- return MetaRestResult.returnError(String.format("当前月份[%S]未配置签到规则和每日签到奖励", yyyyMMDate));
|
|
|
+ return MetaRestResult.returnError(String.format("当前月份[%S]未配置该频道签到规则和每日签到奖励", yyyyMMDate));
|
|
|
}
|
|
|
MetaSignProgressDTO metaSignProgressDTO = new MetaSignProgressDTO();
|
|
|
metaSignProgressDTO.setIsSignIn(isSignIn);
|