admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
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
83
84
85
86
87
88
89
90
91
92
93
94
95
package com.yeshi.fanli.dao.pdd;
 
import com.yeshi.common.MongodbBaseDao;
import com.yeshi.fanli.entity.pdd.UserPDDAuthRecord;
import org.springframework.data.domain.Sort;
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 java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
@Repository
public class UserPDDAuthRecordDao extends MongodbBaseDao<UserPDDAuthRecord> {
 
    private Criteria[] getWheres(DaoQuery daoQuery) {
        List<Criteria> whereList = new ArrayList<>();
        if (daoQuery.success != null) {
            whereList.add(Criteria.where("success").is(daoQuery.success));
        }
        if (daoQuery.minCreateTime != null) {
            whereList.add(Criteria.where("createTime").gte(daoQuery.minCreateTime));
        }
 
        if (daoQuery.uid != null) {
            whereList.add(Criteria.where("uid").is(daoQuery.uid));
        }
        Criteria[] wheres = new Criteria[whereList.size()];
        whereList.toArray(wheres);
        return wheres;
    }
 
    public List<UserPDDAuthRecord> list(DaoQuery daoQuery) {
        Query query = new Query();
        query.addCriteria(new Criteria().andOperator(getWheres(daoQuery)));
        query.skip(daoQuery.start);
        query.limit(daoQuery.count);
 
        if (daoQuery.sortList != null && daoQuery.sortList.size() > 0)
            query.with(new Sort(daoQuery.sortList));
        return findList(query);
    }
 
    public long count(DaoQuery daoQuery) {
        Query query = new Query();
        query.addCriteria(new Criteria().andOperator(getWheres(daoQuery)));
        return count(query);
    }
 
    public void updateSelectiveByPrimaryKey(UserPDDAuthRecord record) {
        Query query = new Query();
        query.addCriteria(Criteria.where("id").is(record.getId()));
        Update update = new Update();
        if (record.getSuccess() != null) {
            update.set("success", record.getSuccess());
        }
 
        if (record.getCustomParams() != null) {
            update.set("customParams", record.getCustomParams());
        }
 
        if (record.getPid() != null) {
            update.set("pid", record.getPid());
        }
 
        if (record.getSuccessTime() != null) {
            update.set("successTime", record.getSuccessTime());
        }
 
        if (record.getUid() != null) {
            update.set("uid", record.getUid());
        }
 
        update(query, update);
    }
 
    public UserPDDAuthRecord selectByPidAndCustomParams(String pid, String customParams) {
        Query query = new Query();
        query.addCriteria(Criteria.where("pid").is(pid).and("customParams").is(customParams));
        return findOne(query);
    }
 
    public static class DaoQuery {
        public Boolean success;
        public Date minCreateTime;
        public int start;
        public int count;
        public Long uid;
        public List<Sort.Order> sortList;
    }
 
 
}