增加英文垃圾支持

master
panqihua 5 years ago
parent 460d84d5eb
commit 093f5a3b20
  1. 12
      src/main/java/com/community/pocket/entity/po/android/Garbage.java
  2. 9
      src/main/java/com/community/pocket/entity/vo/android/GarbageVo.java
  3. 7
      src/main/java/com/community/pocket/repository/android/GarbageDao.java
  4. 17
      src/test/java/com/community/pocket/DemoApplicationTests.java

@ -9,11 +9,13 @@ import org.springframework.data.mongodb.core.mapping.Document;
*/ */
@Document(TableName.garbage) @Document(TableName.garbage)
public class Garbage { public class Garbage {
//垃圾名 //垃圾中文
@Id @Id
private String name; private String name;
//分类信息 //分类信息
private Integer category; private Integer category;
//垃圾英文名
private String englishName;
public String getName() { public String getName() {
return name; return name;
@ -30,4 +32,12 @@ public class Garbage {
public void setCategory(Integer category) { public void setCategory(Integer category) {
this.category = category; this.category = category;
} }
public String getEnglishName() {
return englishName;
}
public void setEnglishName(String englishName) {
this.englishName = englishName;
}
} }

@ -3,6 +3,7 @@ package com.community.pocket.entity.vo.android;
public class GarbageVo { public class GarbageVo {
private String name; private String name;
private String sorting; private String sorting;
private String englishName;
public String getName() { public String getName() {
return name; return name;
@ -19,4 +20,12 @@ public class GarbageVo {
public void setSorting(String sorting) { public void setSorting(String sorting) {
this.sorting = sorting; this.sorting = sorting;
} }
public String getEnglishName() {
return englishName;
}
public void setEnglishName(String englishName) {
this.englishName = englishName;
}
} }

@ -1,8 +1,6 @@
package com.community.pocket.repository.android; package com.community.pocket.repository.android;
import com.community.pocket.entity.po.android.Garbage; import com.community.pocket.entity.po.android.Garbage;
import com.community.pocket.entity.vo.android.GarbageCateGory;
import com.community.pocket.entity.vo.android.GarbageVo;
import com.community.pocket.entity.vo.android.QueryGarbageForm; import com.community.pocket.entity.vo.android.QueryGarbageForm;
import com.community.pocket.repository.BaseDao; import com.community.pocket.repository.BaseDao;
import com.community.pocket.util.MessageService; import com.community.pocket.util.MessageService;
@ -13,7 +11,6 @@ import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -27,7 +24,9 @@ public class GarbageDao extends BaseDao<Garbage> {
//查询垃圾分类信息 //查询垃圾分类信息
public List<Garbage> query(QueryGarbageForm garbageForm) { public List<Garbage> query(QueryGarbageForm garbageForm) {
return mongoTemplate.find(new Query(Criteria.where("name").regex(Pattern.compile(".*" + garbageForm.getName() + ".*"))), entityClass()); return mongoTemplate.find(new Query(new Criteria()
.orOperator(Criteria.where("englishName").regex(Pattern.compile(".*" + garbageForm.getName())),
Criteria.where("name").regex(Pattern.compile(".*" + garbageForm.getName() + ".*")))), entityClass());
} }
@Override @Override

@ -27,9 +27,7 @@ import org.springframework.web.context.WebApplicationContext;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
@ -87,14 +85,15 @@ class DemoApplicationTests {
LOG.info(String.join(",", s)); LOG.info(String.join(",", s));
} }
@Test // 初始化垃圾数据
void loadData() throws FileNotFoundException { @Test
void loadData() throws FileNotFoundException {
Gson gson = new Gson(); Gson gson = new Gson();
MyGarbage g = gson.fromJson(new InputStreamReader(new FileInputStream("src/main/resources/garbage.json"), StandardCharsets.UTF_8), MyGarbage.class); MyGarbage g = gson.fromJson(new InputStreamReader(new FileInputStream("src/main/resources/garbage.json"), StandardCharsets.UTF_8), MyGarbage.class);
for (Garbage garbage : g.getList()) { for (Garbage garbage : g.getList()) {
garbageDao.save(garbage); garbageDao.save(garbage);
} }
} }
@Test @Test
void loadPriceData() { void loadPriceData() {
@ -165,4 +164,12 @@ class DemoApplicationTests {
.param("password", "123456") .param("password", "123456")
).andDo(MockMvcResultHandlers.print()).andReturn(); ).andDo(MockMvcResultHandlers.print()).andReturn();
} }
//测试垃圾分类查询
@Test
void queryGarbage() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get("/garbage/sorting")
.param("name", "安")
).andDo(MockMvcResultHandlers.print()).andReturn();
}
} }

Loading…
Cancel
Save