You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.3 KiB
67 lines
2.3 KiB
package com.community.pocket.repository.android;
|
|
|
|
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.repository.BaseDao;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.data.mongodb.core.query.Criteria;
|
|
import org.springframework.data.mongodb.core.query.Query;
|
|
import org.springframework.stereotype.Repository;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.regex.Pattern;
|
|
|
|
//垃圾分类数据接口
|
|
@Repository
|
|
public class GarbageDao extends BaseDao<Garbage> {
|
|
private static final Logger LOG = LoggerFactory.getLogger(GarbageDao.class);
|
|
|
|
//查询垃圾分类信息
|
|
public List<GarbageVo> query(QueryGarbageForm garbageForm) {
|
|
List<GarbageVo> garbageVos = new ArrayList<>();
|
|
List<Garbage> garbageList = mongoTemplate.find(new Query(Criteria.where("name").regex(Pattern.compile(".*" + garbageForm.getName() + ".*"))), entityClass());
|
|
for (Garbage garbage : garbageList) {
|
|
GarbageVo garbageVo = new GarbageVo();
|
|
garbageVo.setName(garbage.getName());
|
|
switch (garbage.getCategory()) {
|
|
case 1:
|
|
garbageVo.setSorting(GarbageCateGory.type1.getName());
|
|
break;
|
|
case 2:
|
|
garbageVo.setSorting(GarbageCateGory.type2.getName());
|
|
break;
|
|
case 4:
|
|
garbageVo.setSorting(GarbageCateGory.type4.getName());
|
|
break;
|
|
case 8:
|
|
garbageVo.setSorting(GarbageCateGory.type8.getName());
|
|
break;
|
|
case 16:
|
|
garbageVo.setSorting(GarbageCateGory.type16.getName());
|
|
break;
|
|
}
|
|
garbageVos.add(garbageVo);
|
|
}
|
|
return garbageVos;
|
|
}
|
|
|
|
@Override
|
|
public Garbage save(Garbage garbage) {
|
|
try {
|
|
mongoTemplate.save(garbage);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
LOG.error(e.toString());
|
|
}
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public Class<Garbage> entityClass() {
|
|
return Garbage.class;
|
|
}
|
|
}
|
|
|