| | |
| | | package com.yeshi.fanli.dao.push;
|
| | |
|
| | | 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.BasicQuery;
|
| | | import org.springframework.data.mongodb.core.query.Criteria;
|
| | | import org.springframework.data.mongodb.core.query.Query;
|
| | | import org.springframework.stereotype.Repository;
|
| | |
|
| | | import com.mongodb.BasicDBObject;
|
| | | import com.mongodb.DBObject;
|
| | | import com.yeshi.common.MongodbBaseDao;
|
| | | import com.yeshi.fanli.entity.push.DeviceTokenXM;
|
| | |
|
| | | @Repository
|
| | | public class DeviceTokenXMDao extends MongodbBaseDao<DeviceTokenXM> {
|
| | | @Resource
|
| | | private MongoTemplate mongoTemplate;
|
| | |
|
| | | public List<DeviceTokenXM> listByUid(Long uid) {
|
| | | Query query = new Query();
|
| | | query.addCriteria(Criteria.where("uid").is(uid));
|
| | | return mongoTemplate.find(query, DeviceTokenXM.class);
|
| | | }
|
| | |
|
| | | public DeviceTokenXM selectByDeviceActiveId(Long deviceActiveId) {
|
| | | return mongoTemplate.findById(deviceActiveId, DeviceTokenXM.class);
|
| | | }
|
| | |
|
| | | public List<String> listRegId(int start, int count) {
|
| | | DBObject fieldsObject = new BasicDBObject();
|
| | | fieldsObject.put("registerId", true);
|
| | | BasicDBObject dbObject = new BasicDBObject();
|
| | | Query query = new BasicQuery(dbObject, fieldsObject);
|
| | | query.limit(count);
|
| | | query.skip(start);
|
| | | List<Order> orders = new ArrayList<>();
|
| | | orders.add(new Order(Direction.DESC, "updateTime"));
|
| | | query.with(new Sort(orders));
|
| | | List<DeviceTokenXM> resultList = mongoTemplate.find(query, DeviceTokenXM.class);
|
| | | List<String> regList = new ArrayList<>();
|
| | | if (resultList != null) {
|
| | | for (DeviceTokenXM xm : resultList)
|
| | | regList.add(xm.getRegisterId());
|
| | | }
|
| | | return regList;
|
| | | }
|
| | |
|
| | | public long countRegId() {
|
| | | return mongoTemplate.count(new Query(), DeviceTokenXM.class);
|
| | | }
|
| | |
|
| | | }
|
| | | package com.yeshi.fanli.dao.push; |
| | | |
| | | 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.BasicQuery; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | | import org.springframework.stereotype.Repository; |
| | | |
| | | import com.mongodb.BasicDBObject; |
| | | import com.mongodb.DBObject; |
| | | import com.yeshi.common.MongodbBaseDao; |
| | | import com.yeshi.fanli.entity.push.DeviceTokenXM; |
| | | |
| | | @Repository |
| | | public class DeviceTokenXMDao extends MongodbBaseDao<DeviceTokenXM> { |
| | | @Resource |
| | | private MongoTemplate mongoTemplate; |
| | | |
| | | public List<DeviceTokenXM> listByUid(Long uid) { |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("uid").is(uid)); |
| | | return mongoTemplate.find(query, DeviceTokenXM.class); |
| | | } |
| | | |
| | | public DeviceTokenXM selectByDeviceActiveId(Long deviceActiveId) { |
| | | return mongoTemplate.findById(deviceActiveId, DeviceTokenXM.class); |
| | | } |
| | | |
| | | public List<String> listRegId(int start, int count) { |
| | | DBObject fieldsObject = new BasicDBObject(); |
| | | fieldsObject.put("registerId", true); |
| | | BasicDBObject dbObject = new BasicDBObject(); |
| | | Query query = new BasicQuery(dbObject, fieldsObject); |
| | | query.limit(count); |
| | | query.skip(start); |
| | | List<Order> orders = new ArrayList<>(); |
| | | orders.add(new Order(Direction.DESC, "updateTime")); |
| | | query.with(new Sort(orders)); |
| | | List<DeviceTokenXM> resultList = mongoTemplate.find(query, DeviceTokenXM.class); |
| | | List<String> regList = new ArrayList<>(); |
| | | if (resultList != null) { |
| | | for (DeviceTokenXM xm : resultList) |
| | | regList.add(xm.getRegisterId()); |
| | | } |
| | | return regList; |
| | | } |
| | | |
| | | public long countRegId() { |
| | | return mongoTemplate.count(new Query(), DeviceTokenXM.class); |
| | | } |
| | | |
| | | } |