From a7454d8a6325566753358b37ffabfae2faa0ca7f Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期三, 28 四月 2021 19:46:49 +0800 Subject: [PATCH] 拼多多授权调整,支持小程序跳转 --- fanli/src/main/java/com/yeshi/fanli/dao/dynamic/GoodsEvaluateDao.java | 338 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 294 insertions(+), 44 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/dao/dynamic/GoodsEvaluateDao.java b/fanli/src/main/java/com/yeshi/fanli/dao/dynamic/GoodsEvaluateDao.java index d6cfbb6..40ae84d 100644 --- a/fanli/src/main/java/com/yeshi/fanli/dao/dynamic/GoodsEvaluateDao.java +++ b/fanli/src/main/java/com/yeshi/fanli/dao/dynamic/GoodsEvaluateDao.java @@ -1,21 +1,24 @@ package com.yeshi.fanli.dao.dynamic; +import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.regex.Pattern; import javax.annotation.Resource; +import com.yeshi.fanli.entity.SystemEnum; import org.springframework.data.domain.Sort; 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.mongodb.BasicDBObject; -import com.mongodb.QueryOperators; import com.yeshi.fanli.entity.dynamic.GoodsEvaluate; +import com.yeshi.fanli.entity.dynamic.GoodsEvaluate.EvaluateEnum; import com.yeshi.fanli.util.StringUtil; +import org.yeshi.utils.TimeUtil; @Repository public class GoodsEvaluateDao { @@ -35,6 +38,20 @@ mongoTemplate.save(record); } + /** + * 鐘舵�佸垏鎹� + * @param id + * @param state + */ + public void updateSatate(String id, int state) { + Query query = new Query(); + query.addCriteria(Criteria.where("id").is(id)); + + Update update = Update.update("state", state); + mongoTemplate.updateMulti(query, update, GoodsEvaluate.class); + } + + /** * 鍒犻櫎 @@ -82,31 +99,63 @@ * * @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, SystemEnum system) { 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(system!=null) + list.add(Criteria.where("system").is(system)); + 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, SystemEnum system) { 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(system!=null) + list.add(Criteria.where("system").is(system)); + + 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); } @@ -114,75 +163,138 @@ * 鏌ヨ鏈夋晥 * @param start * @param count - * @param key * @return */ - public List<GoodsEvaluate> queryValid(int start, int count, int dynamicType) { + public List<GoodsEvaluate> queryValid(int start, int count, int dynamicType,SystemEnum system) { 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(system!=null) + list.add(Criteria.where("system").is(system)); + + 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")); + query.with(new Sort(Sort.Direction.DESC,"weight")).with(new Sort(Sort.Direction.DESC,"startTime")); return mongoTemplate.find(query, GoodsEvaluate.class); } /** * 缁熻鏈夋晥 - * @param key * @return */ - public long countValid(int dynamicType) { + public long countValid(int dynamicType,SystemEnum system) { 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(system!=null) + list.add(Criteria.where("system").is(system)); + + 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); } /** * 鏌ヨ鏈夋晥 - * @param start - * @param count - * @param key * @return */ - public List<GoodsEvaluate> querySingleExist() { + public List<GoodsEvaluate> querySingleExist(SystemEnum system) { 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(system!=null) + list.add(Criteria.where("system").is(system)); + + 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); } - + /** * 鏌ヨ鏈夋晥 - * @param start - * @param count - * @param key + * @param goodsType + * @param goodsId + * @param system * @return */ - public List<GoodsEvaluate> queryExist(int goodsType, Long goodsId) { + public List<GoodsEvaluate> queryExist(int goodsType, String goodsId,SystemEnum system) { 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)); + if(system!=null) + list.add(Criteria.where("system").is(system)); + 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); } /** * 鏌ヨ鏈夋晥 - * @param start - * @param count - * @param key + * @return + */ + public List<GoodsEvaluate> queryExistSingle(int goodsType, String goodsId,SystemEnum system) { + Query query = new Query(); + List<Criteria> list = new ArrayList<Criteria>(); + list.add(Criteria.where("dynamicType").is(1)); + list.add(Criteria.where("state").is(1)); + list.add(Criteria.where("type").is("single")); + if(system!=null) + list.add(Criteria.where("system").is(system)); + 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); + } + + + /** + * 鏌ヨ鏈夋晥 * @return */ public List<GoodsEvaluate> queryOverdue() { @@ -192,4 +304,142 @@ query.with(new Sort(Sort.Direction.ASC,"createTime")); return mongoTemplate.find(query, GoodsEvaluate.class); } + + + /** + * @return + */ + public List<GoodsEvaluate> removeDownGoods() { + Query query = new Query(); + 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); + } + + + /** + * 鏍规嵁璧峰鏃堕棿鏌ヨ + * @param date + * @return + */ + public List<GoodsEvaluate> listByStartTime(Date date) { + List<Criteria> list = new ArrayList<Criteria>(); + list.add(Criteria.where("dynamicType").is(1)); + list.add(Criteria.where("state").is(1)); + list.add(Criteria.where("startTime").gt(date)); + list.add(Criteria.where("startTime").lte(new Date())); + list.add(new Criteria().orOperator(Criteria.where("type").is("single"), + new Criteria().andOperator(Criteria.where("type").is("activity")))); + + Query query = new Query(); + 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.with(new Sort(Sort.Direction.DESC,"startTime")); + + return mongoTemplate.find(query, GoodsEvaluate.class); + } + + /** + * 鏌ヨ鏈夋晥-鍊掑簭 + * @param start + * @param count + * @return + */ + public List<GoodsEvaluate> queryValidSortASC(int start, int count, EvaluateEnum tyepEnum, boolean sortDesc) { + Date now = new Date(); + Query query = new Query(); + List<Criteria> list = new ArrayList<Criteria>(); + + list.add(Criteria.where("type").is(tyepEnum.name())); + list.add(Criteria.where("dynamicType").is(1)); + 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); + + if (sortDesc) { + query.with(new Sort(Sort.Direction.DESC,"startTime")); + } else { + query.with(new Sort(Sort.Direction.ASC,"startTime")); + } + + return mongoTemplate.find(query, GoodsEvaluate.class); + } + + + /** + * + * @param goodsType + * @param goodsId + * @param limitTime + * @return + */ + public List<GoodsEvaluate> queryExistLimitTime(int goodsType, String goodsId, Date limitTime) { + Query query = new Query(); + 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.goodsId").is(goodsId)); + list.add(Criteria.where("goods.goodsType").is(goodsType)); + + // 闄愬埗鏃堕棿鍐� + list.add(Criteria.where("startTime").gte(limitTime)); + + 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> queryValidZeroPoint(int start, int count) { + // 浠婃棩22鐐瑰彂鍦� 锛�0鐐逛笅鍗� + Date now = new Date(); + Date startTime = TimeUtil.parseYYYYMMDD_HHMM(TimeUtil.getGernalTime(now) + " 22:00"); + + Query query = new Query(); + List<Criteria> list = new ArrayList<Criteria>(); + + list.add(Criteria.where("zeroPoint").is(1)); + list.add(Criteria.where("dynamicType").is(1)); + list.add(Criteria.where("state").is(1)); + list.add(Criteria.where("startTime").is(startTime)); + list.add(new Criteria().orOperator(Criteria.where("type").is("single"), + new Criteria().andOperator(Criteria.where("type").is("activity")))); + + 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); + return mongoTemplate.find(query, GoodsEvaluate.class); + } + } -- Gitblit v1.8.0