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;
|
}
|
|
|
}
|