/**
   * 四种情况 1.删除打印完立即删除的文件,不删数据库,不删除关联,只是将path变为空 2.保存三天后删除待打印的文件,要删数据库,删除所有关联
   * 3.保存三天后删除已上传的文件,要删数据库,删除所有关联 4.保存三天后删除已打印中文件,不删数据库,不删除关联,将path变为空
   */
  public void timingDelete() {
    long start = System.currentTimeMillis();
    HashMap<String, Object> param1 = Maps.newHashMap();
    HashMap<String, Object> param2 = Maps.newHashMap();
    HashMap<String, Object> param3 = Maps.newHashMap();
    logger.info("PrintFileService timingDelete start..." + DateUtils.getNowTime());

    // 1.删除打印完立即删除的文件,不删数据库,不删除关联,只删除当前关联
    param1.put("status", 2); // 已打印
    param1.put("isDelete", 0); // 打印完立即删除
    List<Integer> pidsPrinted = printFileDao.findPidsPrinted(param1);
    logger.info("PrintFileServiceImpl timingDelete pidsPrinted:{} ", pidsPrinted);
    if (pidsPrinted.size() > 0) {
      for (int i = 0; i < pidsPrinted.size(); i++) {
        PrintFile temp = printFileDao.loadPrintFile(pidsPrinted.get(i));

        // 先删文件,只删除存在阿里云上面的文件
        OSSUtils.deleteObject(
            OSSUtils.getOSSClient(), temp.getPath().substring(CPConstant.OSS_URL.length()));

        // 不删数据,只是将path变为空
        temp.setPath("");
        printFileDao.updatePrintFile(temp);
      }
    }
    logger.info(
        "PrintFileServiceImpl timingDelete delete pidsPrinted success, the files path is null");
    try {
      Thread.sleep(2000);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    // 2.3.删除超过3天的待打印,已上传文件,需要将文件删除
    param2.put("overdueTime", DateUtils.getNowTime()); // 超过了三天
    param2.put("status1", "0"); // 已上传
    param2.put("status2", "1"); // 待打印
    List<Integer> pidsBy3Days = printFileDao.findPidsBy3Days(param2);
    logger.info("PrintFileServiceImpl timingDelete pidsBy3Days:{} ", pidsBy3Days);
    if (pidsBy3Days.size() > 0) {
      for (int i = 0; i < pidsBy3Days.size(); i++) {
        PrintFile temp = printFileDao.loadPrintFile(pidsBy3Days.get(i));
        // 先删除阿里云上的文件
        OSSUtils.deleteObject(
            OSSUtils.getOSSClient(), temp.getPath().substring(CPConstant.OSS_URL.length()));

        // 在删该文件下所有用户关联
        printFileDao.deleteUidsByPid(pidsBy3Days.get(i));
        // 删数据
        printFileDao.deletePrintFile(pidsBy3Days.get(i));
      }
    }
    logger.info(
        "PrintFileServiceImpl timingDelete delete pidsBy3Days success, the files is deleted");
    try {
      Thread.sleep(2000);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    // 4.保存三天后删除已打印中文件,不删数据库,不删除关联,将path变为空
    param3.put("overdueTime", DateUtils.getNowTime()); // 超过了三天
    param3.put("status", "2"); // 已打印
    param2.put("isDelete", "1"); // 打印完保存三天
    List<Integer> pidsBy3DaysPrinted = printFileDao.findPidsBy3DaysPrinted(param3);
    logger.info("PrintFileServiceImpl timingDelete pidsBy3DaysPrinted:{} ", pidsBy3DaysPrinted);
    if (pidsBy3DaysPrinted.size() > 0) {
      for (int i = 0; i < pidsBy3DaysPrinted.size(); i++) {
        PrintFile temp = printFileDao.loadPrintFile(pidsBy3DaysPrinted.get(i));
        // 先删除阿里云上的文件
        OSSUtils.deleteObject(
            OSSUtils.getOSSClient(), temp.getPath().substring(CPConstant.OSS_URL.length()));

        // 不删数据,只是将path变为空
        temp.setPath("");
        printFileDao.updatePrintFile(temp);
      }
    }
    logger.info(
        "PrintFileServiceImpl timingDelete delete pidsBy3DaysPrinted success! the files path is null");
    try {
      Thread.sleep(2000);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    logger.info(
        "PrintFileService timingDelete end... "
            + DateUtils.getNowTime()
            + " and it cost "
            + (System.currentTimeMillis() - start));
  }