| | |
| | | package com.yeshi.fanli.dao.dynamic; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.regex.Pattern; |
| | |
| | | * |
| | | * @return |
| | | */ |
| | | public List<GoodsEvaluate> query(int start, int count, String key, Integer state, int dynamicType) { |
| | | public List<GoodsEvaluate> query(int start, int count, String key, Integer state, int dynamicType, String typeEnum) { |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("dynamicType").is(dynamicType)); |
| | | List<Criteria> list = new ArrayList<Criteria>(); |
| | | list.add(Criteria.where("dynamicType").is(dynamicType)); |
| | | |
| | | if (state != null) { |
| | | query.addCriteria(Criteria.where("state").is(state)); |
| | | list.add(Criteria.where("state").is(state)); |
| | | } |
| | | |
| | | if (!StringUtil.isNullOrEmpty(typeEnum)) |
| | | list.add(Criteria.where("type").is(typeEnum)); |
| | | |
| | | if (!StringUtil.isNullOrEmpty(key)) |
| | | query.addCriteria(new Criteria().orOperator( |
| | | list.add(new Criteria().orOperator( |
| | | Criteria.where("title").regex(Pattern.compile("^.*" + key + ".*$", Pattern.CASE_INSENSITIVE)))); |
| | | |
| | | |
| | | if (list.size() > 0) { |
| | | Criteria[] cas = new Criteria[list.size()]; |
| | | for (int i = 0; i < list.size(); i++) |
| | | cas[i] = list.get(i); |
| | | query.addCriteria(new Criteria().andOperator(cas)); |
| | | } |
| | | |
| | | query.skip(start).limit(count); |
| | | query.with(new Sort(Sort.Direction.DESC,"weight")).with(new Sort(Sort.Direction.DESC,"createTime")); |
| | | return mongoTemplate.find(query, GoodsEvaluate.class); |
| | | } |
| | | |
| | | public long count(String key, Integer state, int dynamicType) { |
| | | public long count(String key, Integer state, int dynamicType, String typeEnum) { |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("dynamicType").is(dynamicType)); |
| | | |
| | | List<Criteria> list = new ArrayList<Criteria>(); |
| | | list.add(Criteria.where("dynamicType").is(dynamicType)); |
| | | |
| | | if (state != null) { |
| | | query.addCriteria(Criteria.where("state").is(state)); |
| | | list.add(Criteria.where("state").is(state)); |
| | | } |
| | | |
| | | if (!StringUtil.isNullOrEmpty(typeEnum)) |
| | | list.add(Criteria.where("type").is(typeEnum)); |
| | | |
| | | if (!StringUtil.isNullOrEmpty(key)) |
| | | query.addCriteria(new Criteria().orOperator( |
| | | list.add(new Criteria().orOperator( |
| | | Criteria.where("title").regex(Pattern.compile("^.*" + key + ".*$", Pattern.CASE_INSENSITIVE)))); |
| | | |
| | | if (list.size() > 0) { |
| | | Criteria[] cas = new Criteria[list.size()]; |
| | | for (int i = 0; i < list.size(); i++) |
| | | cas[i] = list.get(i); |
| | | query.addCriteria(new Criteria().andOperator(cas)); |
| | | } |
| | | |
| | | return mongoTemplate.count(query, GoodsEvaluate.class); |
| | | } |
| | | |
| | |
| | | public List<GoodsEvaluate> queryValid(int start, int count, int dynamicType) { |
| | | Date now = new Date(); |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("dynamicType").is(dynamicType)); |
| | | query.addCriteria(Criteria.where("state").is(1)); |
| | | query.addCriteria(Criteria.where("startTime").lte(now)); |
| | | query.addCriteria(Criteria.where("endTime").gte(now)); |
| | | List<Criteria> list = new ArrayList<Criteria>(); |
| | | |
| | | list.add(Criteria.where("dynamicType").is(dynamicType)); |
| | | list.add(Criteria.where("state").is(1)); |
| | | list.add(Criteria.where("startTime").lte(now)); |
| | | list.add(Criteria.where("endTime").gte(now)); |
| | | |
| | | if (list.size() > 0) { |
| | | Criteria[] cas = new Criteria[list.size()]; |
| | | for (int i = 0; i < list.size(); i++) |
| | | cas[i] = list.get(i); |
| | | query.addCriteria(new Criteria().andOperator(cas)); |
| | | } |
| | | |
| | | query.skip(start).limit(count); |
| | | query.with(new Sort(Sort.Direction.DESC,"weight")).with(new Sort(Sort.Direction.DESC,"startTime")); |
| | | return mongoTemplate.find(query, GoodsEvaluate.class); |
| | |
| | | public long countValid(int dynamicType) { |
| | | Date now = new Date(); |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("dynamicType").is(dynamicType)); |
| | | query.addCriteria(Criteria.where("state").is(1)); |
| | | query.addCriteria(Criteria.where("startTime").lte(now)); |
| | | query.addCriteria(Criteria.where("endTime").gte(now)); |
| | | List<Criteria> list = new ArrayList<Criteria>(); |
| | | |
| | | list.add(Criteria.where("dynamicType").is(dynamicType)); |
| | | list.add(Criteria.where("state").is(1)); |
| | | list.add(Criteria.where("startTime").lte(now)); |
| | | list.add(Criteria.where("endTime").gte(now)); |
| | | |
| | | if (list.size() > 0) { |
| | | Criteria[] cas = new Criteria[list.size()]; |
| | | for (int i = 0; i < list.size(); i++) |
| | | cas[i] = list.get(i); |
| | | query.addCriteria(new Criteria().andOperator(cas)); |
| | | } |
| | | return mongoTemplate.count(query, GoodsEvaluate.class); |
| | | } |
| | | |
| | |
| | | */ |
| | | public List<GoodsEvaluate> querySingleExist() { |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("dynamicType").is(1)); |
| | | query.addCriteria(Criteria.where("state").is(1)); |
| | | query.addCriteria(Criteria.where("goods.goodsType").is(1)); |
| | | List<Criteria> list = new ArrayList<Criteria>(); |
| | | |
| | | list.add(Criteria.where("dynamicType").is(1)); |
| | | list.add(Criteria.where("state").is(1)); |
| | | list.add(Criteria.where("goods.goodsType").is(1)); |
| | | |
| | | if (list.size() > 0) { |
| | | Criteria[] cas = new Criteria[list.size()]; |
| | | for (int i = 0; i < list.size(); i++) |
| | | cas[i] = list.get(i); |
| | | query.addCriteria(new Criteria().andOperator(cas)); |
| | | } |
| | | return mongoTemplate.find(query, GoodsEvaluate.class); |
| | | } |
| | | |
| | |
| | | */ |
| | | public List<GoodsEvaluate> queryExist(int goodsType, Long goodsId) { |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("dynamicType").is(1)); |
| | | query.addCriteria(Criteria.where("state").is(1)); |
| | | query.addCriteria(Criteria.where("imgList.goods.goodsId").is(goodsId)); |
| | | query.addCriteria(Criteria.where("imgList.goods.goodsType").is(goodsType)); |
| | | List<Criteria> list = new ArrayList<Criteria>(); |
| | | list.add(Criteria.where("dynamicType").is(1)); |
| | | list.add(Criteria.where("state").is(1)); |
| | | list.add(Criteria.where("imgList.goods.goodsId").is(goodsId)); |
| | | list.add(Criteria.where("imgList.goods.goodsType").is(goodsType)); |
| | | |
| | | if (list.size() > 0) { |
| | | Criteria[] cas = new Criteria[list.size()]; |
| | | for (int i = 0; i < list.size(); i++) |
| | | cas[i] = list.get(i); |
| | | query.addCriteria(new Criteria().andOperator(cas)); |
| | | } |
| | | |
| | | return mongoTemplate.find(query, GoodsEvaluate.class); |
| | | } |
| | | |
| | |
| | | */ |
| | | public List<GoodsEvaluate> removeDownGoods() { |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("type").is("single")); |
| | | query.addCriteria(Criteria.where("goods.state").is(1)); |
| | | List<Criteria> list = new ArrayList<Criteria>(); |
| | | list.add(Criteria.where("type").is("single")); |
| | | list.add(Criteria.where("goods.state").is(1)); |
| | | |
| | | if (list.size() > 0) { |
| | | Criteria[] cas = new Criteria[list.size()]; |
| | | for (int i = 0; i < list.size(); i++) |
| | | cas[i] = list.get(i); |
| | | query.addCriteria(new Criteria().andOperator(cas)); |
| | | } |
| | | |
| | | return mongoTemplate.find(query, GoodsEvaluate.class); |
| | | } |
| | | } |