| | |
| | | package com.yeshi.fanli.dao.brand;
|
| | |
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | | 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.stereotype.Repository;
|
| | |
|
| | | import com.yeshi.fanli.dao.MongodbBaseDao;
|
| | | import com.yeshi.fanli.entity.brand.BrandGoodsCahe;
|
| | |
|
| | | @Repository
|
| | | public class BrandGoodsCaheDao extends MongodbBaseDao<BrandGoodsCahe> {
|
| | | |
| | | |
| | | /**
|
| | | * 新增
|
| | | * @param record
|
| | | */
|
| | | public void insert(BrandGoodsCahe record) {
|
| | | if (record == null) {
|
| | | return;
|
| | | }
|
| | | mongoTemplate.insert(record);
|
| | | }
|
| | | |
| | | /**
|
| | | * 查询商品列表
|
| | | * @param count
|
| | | * @param brandId
|
| | | * @return
|
| | | */
|
| | | public List<BrandGoodsCahe> getByBrandId(int start, int count, Long brandId){
|
| | | if (brandId == null) |
| | | return null;
|
| | | |
| | | Query query = new Query();
|
| | | query.addCriteria(Criteria.where("brandId").is(brandId));
|
| | | //分页
|
| | | query.skip(start).limit(count);
|
| | | //排序
|
| | | query.with(new Sort(Sort.Direction.DESC,"weight"));
|
| | | |
| | | return mongoTemplate.find(query, BrandGoodsCahe.class);
|
| | | }
|
| | | |
| | | |
| | | /**
|
| | | * 统计条数
|
| | | * @param brandId
|
| | | * @return
|
| | | */
|
| | | public long countByBrandId(Long brandId){
|
| | | if (brandId == null) |
| | | return 0;
|
| | | Query query = new Query();
|
| | | query.addCriteria(Criteria.where("brandId").is(brandId));
|
| | | return mongoTemplate.count(query, BrandGoodsCahe.class);
|
| | | }
|
| | | |
| | | |
| | | |
| | | /**
|
| | | * 品牌id
|
| | | * @param brandId
|
| | | */
|
| | | public void removeByBrandId(Long brandId) {
|
| | | Query query = new Query();
|
| | | query.addCriteria(Criteria.where("brandId").lt(brandId));
|
| | | mongoTemplate.remove(query, BrandGoodsCahe.class);
|
| | | }
|
| | | |
| | | |
| | | |
| | | /**
|
| | | * 删除根据时间
|
| | | * |
| | | * @param id
|
| | | * @return
|
| | | */
|
| | | public void removeByDate(Long brandId, Integer goodsType, Date createTime) {
|
| | | Query query = new Query();
|
| | | query.addCriteria(
|
| | | new Criteria().andOperator(
|
| | | Criteria.where("brandId").is(brandId),
|
| | | Criteria.where("goodsType").is(goodsType),
|
| | | Criteria.where("createTime").lt(createTime)
|
| | | )
|
| | | );
|
| | | mongoTemplate.remove(query, BrandGoodsCahe.class);
|
| | | }
|
| | | |
| | | |
| | | /**
|
| | | * 删除根据时间
|
| | | * |
| | | * @param id
|
| | | * @return
|
| | | */
|
| | | public void removeAgoByDate(Date createTime) {
|
| | | Query query = new Query();
|
| | | query.addCriteria(Criteria.where("createTime").lt(createTime));
|
| | | mongoTemplate.remove(query, BrandGoodsCahe.class);
|
| | | }
|
| | | }
|
| | | package com.yeshi.fanli.dao.brand; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | 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.stereotype.Repository; |
| | | |
| | | import com.yeshi.common.MongodbBaseDao; |
| | | import com.yeshi.fanli.entity.brand.BrandGoodsCahe; |
| | | |
| | | @Repository |
| | | public class BrandGoodsCaheDao extends MongodbBaseDao<BrandGoodsCahe> { |
| | | |
| | | |
| | | /** |
| | | * 新增 |
| | | * @param record |
| | | */ |
| | | public void insert(BrandGoodsCahe record) { |
| | | if (record == null) { |
| | | return; |
| | | } |
| | | mongoTemplate.insert(record); |
| | | } |
| | | |
| | | /** |
| | | * 查询商品列表 |
| | | * @param count |
| | | * @param brandId |
| | | * @return |
| | | */ |
| | | public List<BrandGoodsCahe> getByBrandId(int start, int count, Long brandId){ |
| | | if (brandId == null) |
| | | return null; |
| | | |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("brandId").is(brandId)); |
| | | //分页 |
| | | query.skip(start).limit(count); |
| | | //排序 |
| | | query.with(new Sort(Sort.Direction.DESC,"weight")); |
| | | |
| | | return mongoTemplate.find(query, BrandGoodsCahe.class); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 统计条数 |
| | | * @param brandId |
| | | * @return |
| | | */ |
| | | public long countByBrandId(Long brandId){ |
| | | if (brandId == null) |
| | | return 0; |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("brandId").is(brandId)); |
| | | return mongoTemplate.count(query, BrandGoodsCahe.class); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 品牌id |
| | | * @param brandId |
| | | */ |
| | | public void removeByBrandId(Long brandId) { |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("brandId").is(brandId)); |
| | | mongoTemplate.remove(query, BrandGoodsCahe.class); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 删除根据时间 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | public void removeByDate(Long brandId, Integer goodsType, Date createTime) { |
| | | Query query = new Query(); |
| | | query.addCriteria( |
| | | new Criteria().andOperator( |
| | | Criteria.where("brandId").is(brandId), |
| | | Criteria.where("goodsType").is(goodsType), |
| | | Criteria.where("createTime").lt(createTime) |
| | | ) |
| | | ); |
| | | mongoTemplate.remove(query, BrandGoodsCahe.class); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 删除根据时间 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | public void removeAgoByDate(Date createTime) { |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("createTime").lt(createTime)); |
| | | mongoTemplate.remove(query, BrandGoodsCahe.class); |
| | | } |
| | | } |