| | |
| | | @Component("DeleteWorkOrderImgTask") |
| | | public class DeleteWorkOrderImgTask { |
| | | private final ISysConfigService configService; |
| | | |
| | | public static String imgSaveBasePath = "/opt/zgyw/uploadPath"; |
| | | public void delWorkOrderImg() { |
| | | String basePath = PlatformConfig.getUploadPath() + "/profile"; |
| | | |
| | | String basePath = PlatformConfig.getUploadPath(); |
| | | log.info("开始删除工单照片"); |
| | | log.info("删除路径:{}",basePath); |
| | | log.info("删除主路径:{}",basePath); // /opt/zgyw/uploadPath/upload |
| | | log.info("静态设置地址:{}",imgSaveBasePath); |
| | | //字典查询需要删除时间在几个月前的照片 |
| | | String dictLabel = configService.selectConfigByKey("del.workorder.time"); |
| | | log.info("清理时间:{}月",dictLabel); |
| | | if (StringUtils.isEmpty(dictLabel)) { |
| | | log.error("未设置删除时间范围"); |
| | | return; |
| | | log.info("未设置删除时间范围");; |
| | | dictLabel = "6"; |
| | | log.info("默认6月前的图片"); |
| | | } |
| | | |
| | | //获得当前时间 |
| | | LocalDate nowDate = LocalDate.now(); |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | //计算 ? 月前的日期 ? 用字典存入系统中 |
| | | LocalDate sixMonthAgo = nowDate.minusMonths(Long.parseLong("6")); |
| | | LocalDate sixMonthAgo = nowDate.minusMonths(Long.parseLong(dictLabel)); |
| | | //读取服务器中的文件夹名 |
| | | File directory = new File(basePath); |
| | | File directory = new File(imgSaveBasePath); |
| | | //检测路径存在 并且是一个目录 |
| | | if (directory.exists() && directory.isDirectory()) { |
| | | //获得 目录集合 |
| | | File[] files = directory.listFiles(); |
| | | if (files != null) { |
| | | for (File file : files) { |
| | |
| | | File[] allContents = directoryToBeDeleted.listFiles(); |
| | | if (allContents != null) { |
| | | for (File file : allContents) { |
| | | // deleteDirectory(file); |
| | | deleteDirectory(file); |
| | | log.error("打印文件名:{}",file.getName()); |
| | | } |
| | | } |
| | | // directoryToBeDeleted.delete(); |
| | | log.error("打印目录名:{}", directoryToBeDeleted.getName()); |
| | | directoryToBeDeleted.delete(); |
| | | log.error("打印文件名:{}", directoryToBeDeleted.getName()); |
| | | } |
| | | |
| | | |