| | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import com.yeshi.fanli.util.taobao.TaoBaoUtil; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | | import org.springframework.stereotype.Repository; |
| | |
| | | @Repository |
| | | public class TaoBaoGoodsUpdateDao extends MongodbBaseDao<TaoBaoGoodsBrief> { |
| | | |
| | | /** |
| | | * 根据商品ID删除 |
| | | * |
| | | * @param auctionid |
| | | */ |
| | | public void deleteByAuctionId(Long auctionid) { |
| | | Query query = new Query(); |
| | | Criteria ca = Criteria.where("auctionId").is(auctionid); |
| | | query.addCriteria(ca); |
| | | mongoTemplate.remove(query, TaoBaoGoodsBrief.class); |
| | | } |
| | | /** |
| | | * 根据商品ID删除 |
| | | * |
| | | * @param auctionId |
| | | */ |
| | | public void deleteByAuctionId(String auctionId) { |
| | | Query query = new Query(); |
| | | query.addCriteria(TaoBaoUtil.getAuctionIdEqualCriteria("goodsId",auctionId)); |
| | | mongoTemplate.remove(query, TaoBaoGoodsBrief.class); |
| | | } |
| | | |
| | | /** |
| | | * 根据商品ID获取 |
| | | * |
| | | * @param auctionid |
| | | * @return |
| | | */ |
| | | public TaoBaoGoodsBrief selectByAuctionId(Long auctionid) { |
| | | Query query = new Query(); |
| | | Criteria ca = Criteria.where("auctionId").is(auctionid); |
| | | query.addCriteria(ca); |
| | | return mongoTemplate.findOne(query, TaoBaoGoodsBrief.class); |
| | | } |
| | | /** |
| | | * 根据商品ID获取 |
| | | * |
| | | * @param auctionid |
| | | * @return |
| | | */ |
| | | public TaoBaoGoodsBrief selectByAuctionId(String auctionId) { |
| | | Query query = new Query(); |
| | | query.addCriteria(TaoBaoUtil.getAuctionIdEqualCriteria("auctionId",auctionId)); |
| | | |
| | | /** |
| | | * 批量查询 |
| | | * |
| | | * @param auctionIds |
| | | * @return |
| | | */ |
| | | public List<TaoBaoGoodsBrief> listByAuctionIds(List<String> auctionIds) { |
| | | if (auctionIds == null || auctionIds.size() == 0) |
| | | return null; |
| | | Query query = new Query(); |
| | | Criteria ca = new Criteria(); |
| | | Criteria[] cas = new Criteria[auctionIds.size()]; |
| | | for (int i = 0; i < auctionIds.size(); i++) { |
| | | cas[i] = Criteria.where("auctionId").is(auctionIds.get(i)); |
| | | } |
| | | query.addCriteria(ca.orOperator(cas)); |
| | | return mongoTemplate.find(query, TaoBaoGoodsBrief.class); |
| | | } |
| | | |
| | | /** |
| | | * 查询删除数据 |
| | | * |
| | | * @param date |
| | | * @param start |
| | | * @param count |
| | | * @return |
| | | */ |
| | | public int listAndRemoveByMaxUpdateTime(Date date, int start, int count) { |
| | | BasicDBObject fieldsObject = new BasicDBObject(); |
| | | fieldsObject.put("auctionId", 1); |
| | | Query query = new Query(); |
| | | // 时区问题,需加8小时 |
| | | Criteria ca = Criteria.where("updatetime").lt(new Date(date.getTime() + 1000 * 60 * 60 * 8L)); |
| | | query.skip(start); |
| | | query.limit(count); |
| | | query.addCriteria(ca); |
| | | List<TaoBaoGoodsBrief> goodsList = mongoTemplate.findAllAndRemove(query, TaoBaoGoodsBrief.class); |
| | | return goodsList.size(); |
| | | } |
| | | return mongoTemplate.findOne(query, TaoBaoGoodsBrief.class); |
| | | } |
| | | |
| | | /** |
| | | * 根据最大更新时间获取数据条数 |
| | | * |
| | | * @param date |
| | | * @return |
| | | */ |
| | | public long countByMaxUpdateTime(Date date) { |
| | | Query query = new Query(); |
| | | Criteria ca = Criteria.where("updatetime").lt(date); |
| | | query.addCriteria(ca); |
| | | return mongoTemplate.count(query, TaoBaoGoodsBrief.class); |
| | | } |
| | | /** |
| | | * 批量查询 |
| | | * |
| | | * @param auctionIds |
| | | * @return |
| | | */ |
| | | public List<TaoBaoGoodsBrief> listByAuctionIds(List<String> auctionIds) { |
| | | if (auctionIds == null || auctionIds.size() == 0) |
| | | return null; |
| | | Query query = new Query(); |
| | | Criteria ca = new Criteria(); |
| | | Criteria[] cas = new Criteria[auctionIds.size()]; |
| | | for (int i = 0; i < auctionIds.size(); i++) { |
| | | cas[i] = TaoBaoUtil.getAuctionIdEqualCriteria("auctionId", auctionIds.get(i)); |
| | | } |
| | | query.addCriteria(ca.orOperator(cas)); |
| | | return mongoTemplate.find(query, TaoBaoGoodsBrief.class); |
| | | } |
| | | |
| | | /** |
| | | * 查询删除数据 |
| | | * |
| | | * @param date |
| | | * @param start |
| | | * @param count |
| | | * @return |
| | | */ |
| | | public int listAndRemoveByMaxUpdateTime(Date date, int start, int count) { |
| | | BasicDBObject fieldsObject = new BasicDBObject(); |
| | | fieldsObject.put("auctionId", 1); |
| | | Query query = new Query(); |
| | | // 时区问题,需加8小时 |
| | | Criteria ca = Criteria.where("updatetime").lt(new Date(date.getTime() + 1000 * 60 * 60 * 8L)); |
| | | query.skip(start); |
| | | query.limit(count); |
| | | query.addCriteria(ca); |
| | | List<TaoBaoGoodsBrief> goodsList = mongoTemplate.findAllAndRemove(query, TaoBaoGoodsBrief.class); |
| | | return goodsList.size(); |
| | | } |
| | | |
| | | /** |
| | | * 根据最大更新时间获取数据条数 |
| | | * |
| | | * @param date |
| | | * @return |
| | | */ |
| | | public long countByMaxUpdateTime(Date date) { |
| | | Query query = new Query(); |
| | | Criteria ca = Criteria.where("updatetime").lt(date); |
| | | query.addCriteria(ca); |
| | | return mongoTemplate.count(query, TaoBaoGoodsBrief.class); |
| | | } |
| | | |
| | | } |