package com.yeshi.fanli.dao.dynamic;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import javax.annotation.Resource;
|
|
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort.Direction;
|
import org.springframework.data.domain.Sort.Order;
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
import org.springframework.data.mongodb.core.query.Criteria;
|
import org.springframework.data.mongodb.core.query.Query;
|
import org.springframework.data.mongodb.core.query.Update;
|
import org.springframework.stereotype.Repository;
|
|
import com.yeshi.fanli.dao.MongodbBaseDao;
|
import com.yeshi.fanli.entity.dynamic.WXMPDynamicInfo;
|
|
@Repository
|
public class WXMPDynamicInfoDao extends MongodbBaseDao<WXMPDynamicInfo> {
|
|
@Resource
|
private MongoTemplate mongoTemplate;
|
|
/**
|
*
|
* @Title: list
|
* @Description: 列表查询
|
* @param start
|
* @param count
|
* @return
|
* List<WXMPDynamicInfo> 返回类型
|
* @throws
|
*/
|
public List<WXMPDynamicInfo> list(int start, int count) {
|
Query query = new Query();
|
List<Order> orders = new ArrayList<>();
|
orders.add(new Order(Direction.DESC, "createTime"));
|
query.with(new Sort(orders));
|
query.skip(start);
|
query.limit(count);
|
return mongoTemplate.find(query, WXMPDynamicInfo.class);
|
}
|
|
/**
|
*
|
* @Title: count
|
* @Description: 数量查询
|
* @return
|
* long 返回类型
|
* @throws
|
*/
|
public long count() {
|
Query query = new Query();
|
return mongoTemplate.count(query, WXMPDynamicInfo.class);
|
}
|
|
/**
|
*
|
* @Title: addShareCount
|
* @Description: 添加分享次数
|
* @param id
|
* void 返回类型
|
* @throws
|
*/
|
public void addShareCount(String id) {
|
WXMPDynamicInfo info = get(id);
|
if (info == null) {
|
return;
|
}
|
Query query = new Query();
|
query.addCriteria(Criteria.where("id").is(id));
|
Update update = new Update();
|
if (info.getShareCount() != null)
|
update.set("shareCount", info.getShareCount() + 1);
|
else
|
update.set("shareCount", 1);
|
mongoTemplate.updateFirst(query, update, WXMPDynamicInfo.class);
|
}
|
|
}
|