|
@@ -1,20 +1,12 @@
|
|
package com.iohao.mmo.person.entity;
|
|
package com.iohao.mmo.person.entity;
|
|
|
|
|
|
-import com.hy.corecode.idgen.WFGIdGenerator;
|
|
|
|
|
|
+import com.iohao.mmo.hero.service.HeroService;
|
|
import com.iohao.mmo.person.service.PersonService;
|
|
import com.iohao.mmo.person.service.PersonService;
|
|
import jakarta.annotation.Resource;
|
|
import jakarta.annotation.Resource;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.junit.jupiter.api.Test;
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
-import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
|
-import org.springframework.data.mongodb.core.query.Query;
|
|
|
|
-
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Objects;
|
|
|
|
-
|
|
|
|
-import static org.springframework.data.mongodb.core.query.Criteria.where;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author 渔民小镇
|
|
* @author 渔民小镇
|
|
@@ -25,73 +17,23 @@ import static org.springframework.data.mongodb.core.query.Criteria.where;
|
|
public class PersonTest {
|
|
public class PersonTest {
|
|
@Resource
|
|
@Resource
|
|
MongoTemplate mongoTemplate;
|
|
MongoTemplate mongoTemplate;
|
|
- @Autowired
|
|
|
|
- private WFGIdGenerator idGenerator;
|
|
|
|
-
|
|
|
|
- @Test
|
|
|
|
- void test0() {
|
|
|
|
- for (int i = 0; i < 10; i++) {
|
|
|
|
- long next = idGenerator.next();
|
|
|
|
- log.info("next : {}", next);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ HeroService heroService;
|
|
|
|
+ @Resource
|
|
|
|
+ PersonService personService;
|
|
|
|
|
|
@Test
|
|
@Test
|
|
- void test1() {
|
|
|
|
-
|
|
|
|
- BasicsProperty person = new BasicsProperty();
|
|
|
|
- person.setId("abc");
|
|
|
|
- person.setAnger(1);
|
|
|
|
-
|
|
|
|
- mongoTemplate.save(person);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- Criteria criteria = where("anger").is(1);
|
|
|
|
- Query query = new Query(criteria);
|
|
|
|
-
|
|
|
|
- List<BasicsProperty> entities = mongoTemplate.find(query, BasicsProperty.class);
|
|
|
|
-
|
|
|
|
- log.info("students : {}", entities.size());
|
|
|
|
- for (BasicsProperty person1 : entities) {
|
|
|
|
- System.out.println(person1);
|
|
|
|
- }
|
|
|
|
|
|
+ void testHero() {
|
|
|
|
+ Hero firstHero = heroService.getFirstHero();
|
|
|
|
+ log.info("firstHero : {}", firstHero);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
@Test
|
|
@Test
|
|
void testPerson() {
|
|
void testPerson() {
|
|
- BasicsProperty basicProperty = PersonService.getBasicPropertyTemp();
|
|
|
|
-
|
|
|
|
- Hero hero = getHero(basicProperty);
|
|
|
|
-
|
|
|
|
- String heroId = "hero-1";
|
|
|
|
- Hero byId = mongoTemplate.findById(heroId, Hero.class);
|
|
|
|
- Objects.requireNonNull(byId);
|
|
|
|
- BasicsProperty plus = basicProperty.plus(byId.getBasicsProperty());
|
|
|
|
-
|
|
|
|
- Hero currentHero = new Hero();
|
|
|
|
- currentHero.setId(heroId);
|
|
|
|
- currentHero.setBasicsProperty(plus);
|
|
|
|
-
|
|
|
|
- Person person = new Person();
|
|
|
|
- person.setId("person-1");
|
|
|
|
- person.setBasicProperty(basicProperty);
|
|
|
|
- person.setHeroes(List.of(hero));
|
|
|
|
- person.setCurrentHero(currentHero);
|
|
|
|
-
|
|
|
|
- mongoTemplate.save(person);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private Hero getHero(BasicsProperty basicProperty) {
|
|
|
|
- Hero hero = new Hero();
|
|
|
|
- hero.setId("hero-1");
|
|
|
|
- hero.setBasicsProperty(basicProperty);
|
|
|
|
- mongoTemplate.save(hero);
|
|
|
|
|
|
+ long userId = 1;
|
|
|
|
+ personService.initPerson(userId);
|
|
|
|
+ Person personById = personService.getPersonById(userId);
|
|
|
|
|
|
- Hero hero2 = new Hero();
|
|
|
|
- hero2.setId("hero-2");
|
|
|
|
- hero2.setBasicsProperty(basicProperty);
|
|
|
|
- mongoTemplate.save(hero2);
|
|
|
|
- return hero;
|
|
|
|
|
|
+ log.info("personById : {}", personById);
|
|
}
|
|
}
|
|
}
|
|
}
|