/** 测试主索引是否存在该文件及获得MD5* */
 public YandeCG testGetIndexByID(String _id) {
   YandeCG yanedCG = new YandeCG();
   yanedCG.setMd5("InNULL");
   try {
     logger.info("查询ID: " + _id + " 的MD5值");
     System.out.println("查询ID:" + _id);
     DBObject dBObject = collection.findOne(new BasicDBObject("id", Integer.parseInt(_id)));
     if (null == dBObject) {
       logger.warn("撞库失败 没有查询到指定对象 ID: " + Integer.parseInt(_id));
       return yanedCG;
     } else {
       yanedCG.setId(Integer.parseInt(dBObject.get("id").toString()));
       yanedCG.setTags(dBObject.get("tags").toString());
       yanedCG.setMd5(dBObject.get("md5").toString());
       yanedCG.setDownComplete(Boolean.parseBoolean(dBObject.get("downComplete").toString()));
       yanedCG.setSource(dBObject.get("source").toString());
       yanedCG.setFile_url(dBObject.get("file_url").toString());
       yanedCG.setFile_size(dBObject.get("file_size").toString());
       yanedCG.setLocal_url("Has Save in Server");
       logger.info("查询到指定对象 ID: " + Integer.parseInt(_id));
       return yanedCG;
     }
   } catch (Exception e) {
     logger.error(e.getMessage());
   }
   return yanedCG;
 }
 /**
  * 获取指定分页数据记录用于下载
  *
  * @author felixsion *
  */
 @Override
 public List<YandeCG> getTenNumFileToDownLoad(int startPags, int endPages) {
   List<YandeCG> yandeCGList = new ArrayList<YandeCG>();
   DBCursor cur = collection.find(new BasicDBObject("downComplete", Boolean.FALSE));
   int num = 0;
   while (cur.hasNext() && num >= startPags && num < endPages) {
     DBObject dBObject = cur.next();
     System.out.println(dBObject);
     ++num;
     YandeCG yanedCG = new YandeCG();
     yanedCG.setId(Integer.parseInt(dBObject.get("id").toString()));
     yanedCG.setTags(dBObject.get("tags").toString());
     yanedCG.setMd5(dBObject.get("md5").toString());
     yanedCG.setDownComplete(Boolean.parseBoolean(dBObject.get("downComplete").toString()));
     yanedCG.setSource(dBObject.get("source").toString());
     yanedCG.setFile_url(dBObject.get("file_url").toString());
     yanedCG.setFile_size(dBObject.get("file_size").toString());
     yandeCGList.add(yanedCG);
     logger.info("已经获取到第 " + num + " 个未下载任务 图像ID:" + dBObject.get("id").toString());
   }
   /** 判断是否已经加载数据* */
   if (num == 0) {
     logger.warn("未获取到未下载数据列表 此次获取未下载数据失败 检查数据库是否为全部下载状态");
   }
   cur.close();
   return yandeCGList;
 }
 /**
  * 查询YandeCG表中所有文件
  *
  * @author felixerio *
  */
 @Override
 public List<YandeCG> listAllYandeCG() {
   try {
     List<YandeCG> yandeCGList = new ArrayList<YandeCG>();
     DBCursor cur = collection.find();
     int num = 1;
     while (cur.hasNext()) {
       YandeCG yanedCG = new YandeCG();
       DBObject dBObject = cur.next();
       yanedCG.setId(Integer.parseInt(dBObject.get("id").toString()));
       yanedCG.setTags(dBObject.get("tags").toString());
       yanedCG.setMd5(dBObject.get("md5").toString());
       yanedCG.setDownComplete(Boolean.parseBoolean(dBObject.get("downComplete").toString()));
       yanedCG.setSource(dBObject.get("source").toString());
       yanedCG.setFile_url(dBObject.get("file_url").toString());
       yanedCG.setFile_size(dBObject.get("file_size").toString());
       yandeCGList.add(yanedCG);
       num++;
     }
     logger.info("批量获取全部数据数据任务 完成处理 " + num + " 个任务");
     cur.close();
     return yandeCGList;
   } catch (Exception e) {
     logger.error(e.getMessage());
   }
   return null;
 }
  /**
   * 查询特定条件文件函数 查询根据 Tags(标签) Tags支持复合条件查询
   *
   * @author felixerio *
   */
  @Override
  public List<YandeCG> querySpecifiedConditionsForTags(List<String> tags) {
    String query[] = tags.toArray(new String[tags.size()]);
    Pattern pattern = Pattern.compile("^.*" + " chikotam" + ".*$", Pattern.CASE_INSENSITIVE);
    Pattern pattern2 = Pattern.compile("^.*" + " minori" + ".*$", Pattern.CASE_INSENSITIVE);

    Pattern pattern3 = Pattern.compile("^.*" + "chikotam " + ".*$", Pattern.CASE_INSENSITIVE);
    Pattern pattern4 = Pattern.compile("^.*" + "minori " + ".*$", Pattern.CASE_INSENSITIVE);

    DBObject queryCondition = new BasicDBObject();
    BasicDBList condList = new BasicDBList();
    queryCondition.put("tags", pattern);
    condList.add(queryCondition);

    DBObject queryCondition2 = new BasicDBObject();
    BasicDBList condList2 = new BasicDBList();
    queryCondition2.put("tags", pattern2);
    condList.add(queryCondition2);

    BasicDBObject searchCond = new BasicDBObject();
    searchCond.put("$and", condList);

    DBCursor cur = collection.find(searchCond);
    logger.info("批量获取指定Tags数据数据任务 查询到 " + cur.size() + " 条数据");
    int num = 1;
    List<YandeCG> yandeCGList = new ArrayList<YandeCG>();
    while (cur.hasNext()) {
      YandeCG yanedCG = new YandeCG();
      DBObject dBObject = cur.next();
      yanedCG.setId(Integer.parseInt(dBObject.get("id").toString()));
      yanedCG.setTags(dBObject.get("tags").toString());
      yanedCG.setMd5(dBObject.get("md5").toString());
      yanedCG.setDownComplete(Boolean.parseBoolean(dBObject.get("downComplete").toString()));
      yanedCG.setSource(dBObject.get("source").toString());
      yanedCG.setFile_url(dBObject.get("file_url").toString());
      yanedCG.setFile_size(dBObject.get("file_size").toString());
      yandeCGList.add(yanedCG);
      logger.info("批量获取指定Tags数据数据任务 完成处理第 " + num + " 个任务");
      num++;
    }
    cur.close();
    return yandeCGList;
  }