|
|
@@ -1,20 +1,24 @@
|
|
|
package com.izouma.nineth.service;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import com.izouma.nineth.config.Constants;
|
|
|
import com.izouma.nineth.domain.*;
|
|
|
import com.izouma.nineth.dto.MetaRestResult;
|
|
|
import com.izouma.nineth.dto.MetaServiceResult;
|
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
|
+import com.izouma.nineth.enums.MetaPropOperationType;
|
|
|
import com.izouma.nineth.enums.MetaTaskStatus;
|
|
|
import com.izouma.nineth.enums.MetaTaskTarget;
|
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
|
import com.izouma.nineth.repo.*;
|
|
|
import com.izouma.nineth.utils.JpaUtils;
|
|
|
import com.izouma.nineth.utils.MetaUtils;
|
|
|
+import com.izouma.nineth.utils.SecurityUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
|
|
import javax.transaction.Transactional;
|
|
|
import java.time.LocalDateTime;
|
|
|
@@ -34,6 +38,8 @@ public class MetaUserTaskProgressNewService {
|
|
|
private MetaTaskToUserNewService metaTaskToUserNewService;
|
|
|
private MetaTaskBindRepo metaTaskBindRepo;
|
|
|
private MetaTaskNewRepo metaTaskNewRepo;
|
|
|
+ private MetaUserPropService metaUserPropService;
|
|
|
+ private MetaPropRepo metaPropRepo;
|
|
|
|
|
|
public Page<MetaUserTaskProgressNew> all(PageQuery pageQuery) {
|
|
|
return metaUserTaskProgressNewRepo.findAll(JpaUtils.toSpecification(pageQuery, MetaUserTaskProgressNew.class), JpaUtils.toPageRequest(pageQuery));
|
|
|
@@ -144,7 +150,8 @@ public class MetaUserTaskProgressNewService {
|
|
|
*
|
|
|
* @param metaTaskToUserNew 任务领取记录
|
|
|
*/
|
|
|
- private void completeTask(MetaTaskToUserNew metaTaskToUserNew) {
|
|
|
+ @Transactional
|
|
|
+ public void completeTask(MetaTaskToUserNew metaTaskToUserNew) {
|
|
|
metaTaskToUserNew.setFinishTime(LocalDateTime.now());
|
|
|
metaTaskToUserNew.setStatus(MetaTaskStatus.COMPLETION);
|
|
|
metaTaskToUserNewRepo.save(metaTaskToUserNew);
|
|
|
@@ -193,4 +200,46 @@ public class MetaUserTaskProgressNewService {
|
|
|
}
|
|
|
return MetaServiceResult.returnSuccess();
|
|
|
}
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ public MetaRestResult<Void> destroyProp(@PathVariable Long metaTaskToUserNewId) {
|
|
|
+ Long userId = SecurityUtils.getAuthenticatedUser().getId();
|
|
|
+ MetaTaskToUserNew metaTaskToUserNew = metaTaskToUserNewRepo.findByIdAndAndPigeonholeAndDel(metaTaskToUserNewId, false, false);
|
|
|
+ if (Objects.isNull(metaTaskToUserNew)) {
|
|
|
+ return MetaRestResult.returnError("无用户领取任务记录");
|
|
|
+ }
|
|
|
+ if (!userId.equals(metaTaskToUserNew.getUserId())) {
|
|
|
+ return MetaRestResult.returnError("当前用户数据不一致!");
|
|
|
+ }
|
|
|
+ if (!metaTaskToUserNew.getStatus().equals(MetaTaskStatus.PROGRESS)) {
|
|
|
+ return MetaRestResult.returnError(String.format("状态错误:当前任务状态为[%S]", metaTaskToUserNew.getStatus().getDescription()));
|
|
|
+ }
|
|
|
+ // 校验基础任务
|
|
|
+ MetaAtomTask metaAtomTask = metaAtomTaskRepo.findByIdAndDel(metaTaskToUserNew.getAtomTaskId(), false);
|
|
|
+ if (Objects.isNull(metaAtomTask)) {
|
|
|
+ return MetaRestResult.returnError("基础任务信息为空");
|
|
|
+ }
|
|
|
+ if (!MetaTaskTarget.COLLECT_PROP.equals(metaAtomTask.getTargetType())) {
|
|
|
+ return MetaRestResult.returnError("非收集道具类任务");
|
|
|
+ }
|
|
|
+ String targetConfig = metaAtomTask.getTargetConfig();
|
|
|
+ String[] split = targetConfig.split(",");
|
|
|
+ if (split.length != 2) {
|
|
|
+ return MetaRestResult.returnError("目标配置不合法,收集道具类任务 目标配置为:道具id,数量 例如:1,2");
|
|
|
+ }
|
|
|
+ MetaRestResult<MetaUserProp> restResult;
|
|
|
+ try {
|
|
|
+ int num = Integer.parseInt(split[1]);
|
|
|
+ String remark = String.format("玩家 %s 于 %s 通过任务领取记录 %s 销毁 %s 个道具", userId, LocalDateTime.now(), metaTaskToUserNewId, num);
|
|
|
+ restResult = metaUserPropService.operate(userId, Long.parseLong(split[0]), MetaPropOperationType.DESTROY, num, remark);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return MetaRestResult.returnError(String.format("销毁道具发生异常:%s ", e.getMessage()));
|
|
|
+ }
|
|
|
+ if (Constants.MetaRestCode.success != restResult.getCode()) {
|
|
|
+ return MetaRestResult.returnError(restResult.getMessage());
|
|
|
+ }
|
|
|
+ // 完成任务
|
|
|
+ completeTask(metaTaskToUserNew);
|
|
|
+ return MetaRestResult.returnSuccess("道具销毁成功");
|
|
|
+ }
|
|
|
}
|