admin
2020-05-20 98b1a0affd69bbe63223c21fdd2c404e8bedfccb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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);
    }
 
}