From 04f09e52ffd4681bdfd85e51acd3da0d1280c3d3 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期六, 16 四月 2022 16:07:10 +0800 Subject: [PATCH] bug修复 --- src/main/java/com/yeshi/buwan/dao/base/MongodbBaseDao.java | 179 ++++++++++++++++++++++++++++++++--------------------------- 1 files changed, 98 insertions(+), 81 deletions(-) diff --git a/src/main/java/com/yeshi/buwan/dao/base/MongodbBaseDao.java b/src/main/java/com/yeshi/buwan/dao/base/MongodbBaseDao.java index 8759407..0c231fb 100644 --- a/src/main/java/com/yeshi/buwan/dao/base/MongodbBaseDao.java +++ b/src/main/java/com/yeshi/buwan/dao/base/MongodbBaseDao.java @@ -5,7 +5,11 @@ import javax.annotation.Resource; +import com.yeshi.buwan.domain.VideoType; import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.aggregation.Aggregation; +import org.springframework.data.mongodb.core.aggregation.AggregationOperation; +import org.springframework.data.mongodb.core.aggregation.AggregationResults; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Update; @@ -13,95 +17,108 @@ @Repository public abstract class MongodbBaseDao<T> { - @Resource - protected MongoTemplate mongoTemplate; + @Resource + protected MongoTemplate mongoTemplate; - /** - * 鎻掑叆鏁版嵁 - * - * @param bean - * @return - */ - public T save(T bean) { - mongoTemplate.save(bean); - return bean; - } + /** + * 鎻掑叆鏁版嵁 + * + * @param bean + * @return + */ + public T save(T bean) { + mongoTemplate.save(bean); + return bean; + } - /** - * 鏍规嵁涓婚敭鏇存柊鏁版嵁 - * - * @param query - * @param update - */ - public void update(Query query, Update update) { - mongoTemplate.upsert(query, update, this.getEntityClass()); - } + /** + * 鏍规嵁涓婚敭鏇存柊鏁版嵁 + * + * @param query + * @param update + */ + public void update(Query query, Update update) { + mongoTemplate.upsert(query, update, this.getEntityClass()); + } - /** - * 鏌ヨ涓�涓暟鎹� - * - * @param query - * @return - */ - public T findOne(Query query) { - return (T) mongoTemplate.findOne(query, this.getEntityClass()); - } + /** + * 鏌ヨ涓�涓暟鎹� + * + * @param query + * @return + */ + public T findOne(Query query) { + return (T) mongoTemplate.findOne(query, this.getEntityClass()); + } - /** - * 鏌ヨ澶氫釜鏁版嵁 - * - * @param query - * @return - */ - public List<T> findList(Query query) { - return mongoTemplate.find(query, this.getEntityClass()); - } - - - /** - * 缁熻鏁伴噺 - * - * @param query - * @return - */ - public long count(Query query) { - return mongoTemplate.count(query, this.getEntityClass()); - } + /** + * 鏌ヨ澶氫釜鏁版嵁 + * + * @param query + * @return + */ + public List<T> findList(Query query) { + return mongoTemplate.find(query, this.getEntityClass()); + } - /** - * 涓婚敭鏌ヨ - * - * @param id - * @return - */ - public T get(Object id) { - return (T) mongoTemplate.findById(id, this.getEntityClass()); - } - /** - * 閫氳繃涓婚敭鍒犻櫎 - * - * @param id - */ - public void delete(Object id) { - Query query = Query.query(Criteria.where("id").is(id)); - mongoTemplate.remove(query, getEntityClass()); - } + /** + * 缁熻鏁伴噺 + * + * @param query + * @return + */ + public long count(Query query) { + return mongoTemplate.count(query, this.getEntityClass()); + } - public void delete(Query query) { - mongoTemplate.remove(query, getEntityClass()); - } + /** + * 涓婚敭鏌ヨ + * + * @param id + * @return + */ + public T get(Object id) { + return (T) mongoTemplate.findById(id, this.getEntityClass()); + } - public void deleteByPrimaryKey(Object id) { - Query query = Query.query(Criteria.where("_id").is(id)); - mongoTemplate.remove(query, getEntityClass()); - } + /** + * 閫氳繃涓婚敭鍒犻櫎 + * + * @param id + */ + public void delete(Object id) { + Query query = Query.query(Criteria.where("id").is(id)); + mongoTemplate.remove(query, getEntityClass()); + } - @SuppressWarnings("unchecked") - protected Class<T> getEntityClass() { - Class<T> tClass = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()) - .getActualTypeArguments()[0]; - return tClass; - } + public void delete(Query query) { + mongoTemplate.remove(query, getEntityClass()); + } + + public void deleteByPrimaryKey(Object id) { + Query query = Query.query(Criteria.where("_id").is(id)); + mongoTemplate.remove(query, getEntityClass()); + } + + @SuppressWarnings("unchecked") + protected Class<T> getEntityClass() { + Class<T> tClass = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()) + .getActualTypeArguments()[0]; + return tClass; + } + + + /** + * 鑱氬悎鏌ヨ + * + * @param opts + * @param output + * @return + */ + public AggregationResults aggregate(List<? extends AggregationOperation> opts, Class output) { + Aggregation aggregation = Aggregation.newAggregation(opts); + return mongoTemplate.aggregate(aggregation, this.getEntityClass(), output); + } } -- Gitblit v1.8.0