| | |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.yeshi.fanli.entity.SystemEnum; |
| | | import com.yeshi.fanli.util.taobao.TaoBaoUtil; |
| | | import org.springframework.data.domain.Sort; |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | |
| | | import org.springframework.stereotype.Repository; |
| | | |
| | | 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 { |
| | | |
| | | @Resource |
| | | private MongoTemplate mongoTemplate; |
| | | @Resource |
| | | private MongoTemplate mongoTemplate; |
| | | |
| | | /** |
| | | * 新增 |
| | | * |
| | | * @param record |
| | | */ |
| | | public void save(GoodsEvaluate record) { |
| | | if (record == null) { |
| | | return; |
| | | } |
| | | mongoTemplate.save(record); |
| | | } |
| | | /** |
| | | * 新增 |
| | | * |
| | | * @param record |
| | | */ |
| | | public void save(GoodsEvaluate record) { |
| | | if (record == null) { |
| | | return; |
| | | } |
| | | mongoTemplate.save(record); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 状态切换 |
| | | * |
| | | * @param record |
| | | */ |
| | | 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); |
| | | } |
| | | /** |
| | | * 状态切换 |
| | | * |
| | | * @param id |
| | | * @param state |
| | | */ |
| | | public void updateSatate(String id, int state) { |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("id").is(id)); |
| | | |
| | | |
| | | |
| | | /** |
| | | * 删除 |
| | | * @param record |
| | | */ |
| | | public void remove(GoodsEvaluate record) { |
| | | if (record == null) { |
| | | return; |
| | | } |
| | | mongoTemplate.remove(record); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 根据id查询数据 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | public GoodsEvaluate getById(String id) { |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("id").is(id)); |
| | | return mongoTemplate.findOne(query, GoodsEvaluate.class); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 删除 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | public void deleteById(String id) { |
| | | GoodsEvaluate info = getById(id); |
| | | if (info == null) { |
| | | return; |
| | | } |
| | | mongoTemplate.remove(info); |
| | | } |
| | | Update update = Update.update("state", state); |
| | | mongoTemplate.updateMulti(query, update, GoodsEvaluate.class); |
| | | } |
| | | |
| | | /** |
| | | * 查询 |
| | | * |
| | | * @return |
| | | */ |
| | | public List<GoodsEvaluate> query(int start, int count, String key, Integer state, int dynamicType, String typeEnum) { |
| | | Query query = new Query(); |
| | | List<Criteria> list = new ArrayList<Criteria>(); |
| | | list.add(Criteria.where("dynamicType").is(dynamicType)); |
| | | |
| | | if (state != null) { |
| | | list.add(Criteria.where("state").is(state)); |
| | | } |
| | | |
| | | if (!StringUtil.isNullOrEmpty(typeEnum)) |
| | | list.add(Criteria.where("type").is(typeEnum)); |
| | | |
| | | if (!StringUtil.isNullOrEmpty(key)) |
| | | 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, String typeEnum) { |
| | | Query query = new Query(); |
| | | List<Criteria> list = new ArrayList<Criteria>(); |
| | | list.add(Criteria.where("dynamicType").is(dynamicType)); |
| | | |
| | | if (state != null) { |
| | | list.add(Criteria.where("state").is(state)); |
| | | } |
| | | |
| | | if (!StringUtil.isNullOrEmpty(typeEnum)) |
| | | list.add(Criteria.where("type").is(typeEnum)); |
| | | |
| | | if (!StringUtil.isNullOrEmpty(key)) |
| | | 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); |
| | | } |
| | | /** |
| | | * 删除 |
| | | * |
| | | * @param record |
| | | */ |
| | | public void remove(GoodsEvaluate record) { |
| | | if (record == null) { |
| | | return; |
| | | } |
| | | mongoTemplate.remove(record); |
| | | } |
| | | |
| | | /** |
| | | * 查询有效 |
| | | * @param start |
| | | * @param count |
| | | * @param key |
| | | * @return |
| | | */ |
| | | public List<GoodsEvaluate> queryValid(int start, int count, int dynamicType) { |
| | | Date now = new Date(); |
| | | Query query = new Query(); |
| | | 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)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 根据id查询数据 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | public GoodsEvaluate getById(String id) { |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("id").is(id)); |
| | | return mongoTemplate.findOne(query, GoodsEvaluate.class); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 删除 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | public void deleteById(String id) { |
| | | GoodsEvaluate info = getById(id); |
| | | if (info == null) { |
| | | return; |
| | | } |
| | | mongoTemplate.remove(info); |
| | | } |
| | | |
| | | /** |
| | | * 查询 |
| | | * |
| | | * @return |
| | | */ |
| | | public List<GoodsEvaluate> query(int start, int count, String key, Integer state, int dynamicType, String typeEnum, SystemEnum system) { |
| | | Query query = new Query(); |
| | | List<Criteria> list = new ArrayList<Criteria>(); |
| | | list.add(Criteria.where("dynamicType").is(dynamicType)); |
| | | |
| | | if (state != null) { |
| | | 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)) |
| | | 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,"startTime")); |
| | | return mongoTemplate.find(query, GoodsEvaluate.class); |
| | | } |
| | | query.with(new Sort(Sort.Direction.DESC, "weight")).with(new Sort(Sort.Direction.DESC, "createTime")); |
| | | return mongoTemplate.find(query, GoodsEvaluate.class); |
| | | } |
| | | |
| | | /** |
| | | * 统计有效 |
| | | * @param key |
| | | * @return |
| | | */ |
| | | public long countValid(int dynamicType) { |
| | | Date now = new Date(); |
| | | Query query = new Query(); |
| | | 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); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 查询有效 |
| | | * @param start |
| | | * @param count |
| | | * @param key |
| | | * @return |
| | | */ |
| | | public List<GoodsEvaluate> querySingleExist() { |
| | | 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.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); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 查询有效 |
| | | * @param start |
| | | * @param count |
| | | * @param key |
| | | * @return |
| | | */ |
| | | public List<GoodsEvaluate> queryExist(int goodsType, String goodsId) { |
| | | 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("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 long count(String key, Integer state, int dynamicType, String typeEnum, SystemEnum system) { |
| | | Query query = new Query(); |
| | | List<Criteria> list = new ArrayList<Criteria>(); |
| | | list.add(Criteria.where("dynamicType").is(dynamicType)); |
| | | |
| | | |
| | | /** |
| | | * 查询有效 |
| | | * @param start |
| | | * @param count |
| | | * @param key |
| | | * @return |
| | | */ |
| | | public List<GoodsEvaluate> queryExistSingle(int goodsType, String goodsId) { |
| | | 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")); |
| | | 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> queryOverdue() { |
| | | Date now = new Date(); |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("endTime").lte(now)); |
| | | query.with(new Sort(Sort.Direction.ASC,"createTime")); |
| | | return mongoTemplate.find(query, GoodsEvaluate.class); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 查询有效 |
| | | * @param start |
| | | * @param count |
| | | * @param key |
| | | * @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); |
| | | } |
| | | |
| | | |
| | | if (state != null) { |
| | | 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)) |
| | | 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); |
| | | } |
| | | |
| | | /** |
| | | * 查询有效 |
| | | * |
| | | * @param start |
| | | * @param count |
| | | * @return |
| | | */ |
| | | public List<GoodsEvaluate> queryValid(int start, int count, int dynamicType, SystemEnum system) { |
| | | Date now = new Date(); |
| | | Query query = new Query(); |
| | | 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, "startTime")); |
| | | return mongoTemplate.find(query, GoodsEvaluate.class); |
| | | } |
| | | |
| | | /** |
| | | * 统计有效 |
| | | * |
| | | * @return |
| | | */ |
| | | public long countValid(int dynamicType, SystemEnum system) { |
| | | Date now = new Date(); |
| | | Query query = new Query(); |
| | | 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); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 查询有效 |
| | | * |
| | | * @return |
| | | */ |
| | | public List<GoodsEvaluate> querySingleExist(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("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 goodsType |
| | | * @param goodsId |
| | | * @param system |
| | | * @return |
| | | */ |
| | | public List<GoodsEvaluate> queryExist(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)); |
| | | if (system != null) |
| | | list.add(Criteria.where("system").is(system)); |
| | | list.add(TaoBaoUtil.getAuctionIdEqualCriteria( "imgList.goods.goodsId",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> 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(TaoBaoUtil.getAuctionIdEqualCriteria( "imgList.goods.goodsId",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() { |
| | | Date now = new Date(); |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("endTime").lte(now)); |
| | | 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(TaoBaoUtil.getAuctionIdEqualCriteria("goods.goodsId",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); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 查询已经存在的数据 |
| | | * |
| | | * @param identifyCode |
| | | * @param limitTime |
| | | * @return |
| | | */ |
| | | public GoodsEvaluate selectExistLimitTime(String identifyCode, 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("identifyCode").is(identifyCode)); |
| | | |
| | | // 限制时间内 |
| | | 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.findOne(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); |
| | | } |
| | | |
| | | } |