| | |
| | | package com.yeshi.fanli.dao.dynamic;
|
| | |
|
| | | import java.util.List;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | 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.entity.dynamic.InviteMaterial;
|
| | |
|
| | | @Repository
|
| | | public class InviteMaterialDao {
|
| | |
|
| | | @Resource
|
| | | private MongoTemplate mongoTemplate;
|
| | |
|
| | | /**
|
| | | * 新增
|
| | | * |
| | | * @param record
|
| | | */
|
| | | public void insert(InviteMaterial record) {
|
| | | if (record == null) {
|
| | | return;
|
| | | }
|
| | | mongoTemplate.insert(record);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 更新状态
|
| | | * |
| | | * @param record
|
| | | */
|
| | | public void updateState(int state, String id) {
|
| | | Query query = new Query();
|
| | | query.addCriteria(Criteria.where("id").is(id));
|
| | | Update update = Update.update("state", state);
|
| | | mongoTemplate.updateMulti(query, update, InviteMaterial.class);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 更新信息
|
| | | * |
| | | * @param record
|
| | | */
|
| | | public void update(InviteMaterial record) {
|
| | | if (record == null) {
|
| | | return;
|
| | | }
|
| | | Query query = new Query();
|
| | | query.addCriteria(Criteria.where("id").is(record.getId()));
|
| | | Update update = Update.update("picture", record.getPicture()).set("text", record.getText()).set("state",
|
| | | record.getState());
|
| | | mongoTemplate.updateMulti(query, update, InviteMaterial.class);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 根据id查询数据
|
| | | * |
| | | * @param id
|
| | | * @return
|
| | | */
|
| | | public InviteMaterial getById(String id) {
|
| | | Query query = new Query();
|
| | | query.addCriteria(Criteria.where("id").is(id));
|
| | | return mongoTemplate.findOne(query, InviteMaterial.class);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 删除
|
| | | * |
| | | * @param id
|
| | | * @return
|
| | | */
|
| | | public void deleteById(String id) {
|
| | | InviteMaterial info = getById(id);
|
| | | if (info == null) {
|
| | | return;
|
| | | }
|
| | | mongoTemplate.remove(info);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 查询所有数据
|
| | | * |
| | | * @param clazz
|
| | | * @return
|
| | | */
|
| | | public List<InviteMaterial> query(int start, int count) {
|
| | | Query query = new Query();
|
| | | // 分页
|
| | | query.skip(start).limit(count);
|
| | | List<InviteMaterial> list = mongoTemplate.find(query, InviteMaterial.class);
|
| | | return list;
|
| | | }
|
| | |
|
| | | public long count() {
|
| | | Query query = new Query();
|
| | | return mongoTemplate.count(query, InviteMaterial.class);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 根据状态查询
|
| | | * @param state
|
| | | * @return
|
| | | */
|
| | | public List<InviteMaterial> queryByState(int state) {
|
| | | Query query = new Query();
|
| | | query.addCriteria(Criteria.where("state").is(state));
|
| | | List<InviteMaterial> list = mongoTemplate.find(query, InviteMaterial.class);
|
| | | return list;
|
| | | }
|
| | | |
| | | |
| | | |
| | | /**
|
| | | * 查询所有数据
|
| | | * |
| | | * @param clazz
|
| | | * @return
|
| | | */
|
| | | public List<InviteMaterial> queryAll() {
|
| | | return (List<InviteMaterial>) mongoTemplate.findAll(InviteMaterial.class);
|
| | | }
|
| | |
|
| | | }
|
| | | package com.yeshi.fanli.dao.dynamic; |
| | | |
| | | import java.util.List; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | 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.entity.dynamic.InviteMaterial; |
| | | |
| | | @Repository |
| | | public class InviteMaterialDao { |
| | | |
| | | @Resource |
| | | private MongoTemplate mongoTemplate; |
| | | |
| | | /** |
| | | * 新增 |
| | | * |
| | | * @param record |
| | | */ |
| | | public void insert(InviteMaterial record) { |
| | | if (record == null) { |
| | | return; |
| | | } |
| | | mongoTemplate.insert(record); |
| | | } |
| | | |
| | | /** |
| | | * 更新状态 |
| | | * |
| | | * @param record |
| | | */ |
| | | public void updateState(int state, String id) { |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("id").is(id)); |
| | | Update update = Update.update("state", state); |
| | | mongoTemplate.updateMulti(query, update, InviteMaterial.class); |
| | | } |
| | | |
| | | /** |
| | | * 更新信息 |
| | | * |
| | | * @param record |
| | | */ |
| | | public void update(InviteMaterial record) { |
| | | if (record == null) { |
| | | return; |
| | | } |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("id").is(record.getId())); |
| | | Update update = Update.update("picture", record.getPicture()).set("text", record.getText()).set("state", |
| | | record.getState()); |
| | | mongoTemplate.updateMulti(query, update, InviteMaterial.class); |
| | | } |
| | | |
| | | /** |
| | | * 根据id查询数据 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | public InviteMaterial getById(String id) { |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("id").is(id)); |
| | | return mongoTemplate.findOne(query, InviteMaterial.class); |
| | | } |
| | | |
| | | /** |
| | | * 删除 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | public void deleteById(String id) { |
| | | InviteMaterial info = getById(id); |
| | | if (info == null) { |
| | | return; |
| | | } |
| | | mongoTemplate.remove(info); |
| | | } |
| | | |
| | | /** |
| | | * 查询所有数据 |
| | | * |
| | | * @param clazz |
| | | * @return |
| | | */ |
| | | public List<InviteMaterial> query(int start, int count) { |
| | | Query query = new Query(); |
| | | // 分页 |
| | | query.skip(start).limit(count); |
| | | List<InviteMaterial> list = mongoTemplate.find(query, InviteMaterial.class); |
| | | return list; |
| | | } |
| | | |
| | | public long count() { |
| | | Query query = new Query(); |
| | | return mongoTemplate.count(query, InviteMaterial.class); |
| | | } |
| | | |
| | | /** |
| | | * 根据状态查询 |
| | | * @param state |
| | | * @return |
| | | */ |
| | | public List<InviteMaterial> queryByState(int state) { |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("state").is(state)); |
| | | List<InviteMaterial> list = mongoTemplate.find(query, InviteMaterial.class); |
| | | return list; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 查询所有数据 |
| | | * |
| | | * @param clazz |
| | | * @return |
| | | */ |
| | | public List<InviteMaterial> queryAll() { |
| | | return (List<InviteMaterial>) mongoTemplate.findAll(InviteMaterial.class); |
| | | } |
| | | |
| | | } |