|
|
@@ -1,8 +1,14 @@
|
|
|
package com.izouma.nineth.service;
|
|
|
|
|
|
import com.izouma.nineth.domain.MetaGameCopy;
|
|
|
+import com.izouma.nineth.domain.MetaGameProcess;
|
|
|
+import com.izouma.nineth.domain.MetaZombie;
|
|
|
+import com.izouma.nineth.dto.MetaRestResult;
|
|
|
+import com.izouma.nineth.dto.MetaZombieDTO;
|
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
|
import com.izouma.nineth.repo.MetaGameCopyRepo;
|
|
|
+import com.izouma.nineth.repo.MetaGameProcessRepo;
|
|
|
+import com.izouma.nineth.repo.MetaZombieRepo;
|
|
|
import com.izouma.nineth.utils.JpaUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
@@ -11,6 +17,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.transaction.Transactional;
|
|
|
import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
@@ -18,6 +25,10 @@ public class MetaGameCopyService {
|
|
|
|
|
|
private MetaGameCopyRepo metaGameCopyRepo;
|
|
|
|
|
|
+ private MetaGameProcessRepo metaGameProcessRepo;
|
|
|
+
|
|
|
+ private MetaZombieRepo metaZombieRepo;
|
|
|
+
|
|
|
public Page<MetaGameCopy> all(PageQuery pageQuery) {
|
|
|
return metaGameCopyRepo.findAll(JpaUtils.toSpecification(pageQuery, MetaGameCopy.class), JpaUtils.toPageRequest(pageQuery));
|
|
|
}
|
|
|
@@ -38,4 +49,47 @@ public class MetaGameCopyService {
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public MetaRestResult<MetaGameProcess> saveProcess(MetaGameProcess metaGameProcess) {
|
|
|
+ if (Objects.isNull(metaGameProcess.getUserId())) {
|
|
|
+ return MetaRestResult.returnError("Illegal parameter : userId can not be null");
|
|
|
+ }
|
|
|
+ if (Objects.isNull(metaGameProcess.getMetaGameCopyId())) {
|
|
|
+ return MetaRestResult.returnError("Illegal parameter : metaGameCopyId can not be null");
|
|
|
+ }
|
|
|
+ if (Objects.isNull(metaGameProcess.getPlayerPos())) {
|
|
|
+ return MetaRestResult.returnError("Illegal parameter : playerPos can not be null");
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isEmpty((metaGameProcess.getMetaZombieDTOS()))) {
|
|
|
+ return MetaRestResult.returnError("Illegal parameter : metaZombieDTOS can not be null");
|
|
|
+ }
|
|
|
+ List<MetaZombieDTO> metaZombieDTOS = metaGameProcess.getMetaZombieDTOS();
|
|
|
+ int point = 0;
|
|
|
+ for (MetaZombieDTO metaZombieDTO : metaZombieDTOS) {
|
|
|
+ if (Objects.isNull(metaZombieDTO.getMetaZombieId())) {
|
|
|
+ return MetaRestResult.returnError("Illegal parameter : metaZombieId can not be null");
|
|
|
+ }
|
|
|
+ if (Objects.isNull(metaZombieDTO.getCreateIndex())) {
|
|
|
+ return MetaRestResult.returnError("Illegal parameter : createIndex can not be null");
|
|
|
+ }
|
|
|
+ if (Objects.isNull(metaZombieDTO.getType())) {
|
|
|
+ return MetaRestResult.returnError("Illegal parameter : type can not be null");
|
|
|
+ }
|
|
|
+ if (Objects.isNull(metaZombieDTO.getPos())) {
|
|
|
+ return MetaRestResult.returnError("Illegal parameter : pos can not be null");
|
|
|
+ }
|
|
|
+ if (metaZombieDTO.isKilled()) {
|
|
|
+ MetaZombie dbMetaZombie = metaZombieRepo.findById(metaZombieDTO.getMetaZombieId()).orElse(null);
|
|
|
+ if (Objects.isNull(dbMetaZombie)) {
|
|
|
+ return MetaRestResult.returnError("缺少僵尸配置");
|
|
|
+ }
|
|
|
+ if (dbMetaZombie.isDel()) {
|
|
|
+ return MetaRestResult.returnError("配置已被删除");
|
|
|
+ }
|
|
|
+ point = point + dbMetaZombie.getZombieIntegral();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ metaGameProcess.setPoint(point);
|
|
|
+ return MetaRestResult.returnSuccess(metaGameProcessRepo.save(metaGameProcess));
|
|
|
+ }
|
|
|
}
|