| | |
| | | package org.springblade.mdm.task; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springblade.mdm.basesetting.machine.MachineService; |
| | | import org.springblade.mdm.basesetting.machine.service.MachineService; |
| | | import org.springblade.mdm.basesetting.machine.entity.Machine; |
| | | import org.springblade.mdm.commons.service.ParamService; |
| | | import org.springblade.mdm.gkw.programnode.entity.MachineFile; |
| | | import org.springblade.mdm.gkw.programnode.service.MachineFileService; |
| | | import org.springblade.mdm.machinefile.entity.MachineFile; |
| | | import org.springblade.mdm.machinefile.service.MachineFileService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.EnableScheduling; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | |
| | | @Autowired |
| | | private ParamService paramService; |
| | | /** |
| | | * 文件默认保存小时数 |
| | | * 文件默认保存小时数,0不限制 |
| | | */ |
| | | private static final int DEFAULT_HOUR = 8; |
| | | // 每5秒执行一次 |
| | | //@Scheduled(fixedRate = 1000000) |
| | | //@Scheduled(cron = "0 1 0 * * ?") // 每天上午0点1分执行 |
| | | //@Scheduled(cron = "0 */3 * * * ?") |
| | | //@Scheduled(cron = "0 15 19 * * ?") //test |
| | | //@Scheduled(cron = "${task.cron.machine_file_scan}") |
| | | @Scheduled(cron = "${task.cron.machine_rec_move:0 3 * * * ?}") |
| | | private static final int DEFAULT_HOUR = 0; |
| | | |
| | | //@Scheduled(cron = "${task.cron.machine_rec_move:0 3 * * * ?}") |
| | | /* |
| | | public void execute() { |
| | | String networkType = paramService.getParamValue(ParamService.NETWORK_TYPE,ParamService.NETWORK_TYPE_SHEMI); |
| | | |
| | | if(!ParamService.NETWORK_TYPE_SHEMI.equals(networkType)){ |
| | | //非涉密网,才扫描目录文件 |
| | | moveOverTimeFiles(); |
| | | moveValidateFiles(); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 扫描数据库记录,超时则移动文件 |
| | | */ |
| | | public void moveOverTimeFiles() { |
| | | |
| | | public void moveValidateFiles() { |
| | | List<Machine> machines = machineService.getEnableMachines(); |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | for (Machine machine : machines) { |
| | | int remainHours = machine.getReceiveDirExpiryHours() != null ?machine.getReceiveDirExpiryHours():DEFAULT_HOUR; |
| | | LocalDateTime earlyTime = now.minusHours(remainHours); |
| | | List<MachineFile> overTimeFiles = this.machineFileService.lambdaQuery().lt(MachineFile::getFileCreateTime,earlyTime) |
| | | .eq(MachineFile::getDirType,MachineFile.DIR_TYPE_REC) |
| | | .eq(MachineFile::getMachineCode,machine.getCode()).list(); |
| | | |
| | | for(MachineFile overTimeFile : overTimeFiles){ |
| | | //LocalDateTime earlyTime = now.minusHours(remainHours); |
| | | List<MachineFile> pendingFiles = this.machineFileService.lambdaQuery() |
| | | .eq(MachineFile::getDirType,MachineFile.DIR_TYPE_REC) |
| | | .eq(MachineFile::getExceptionType,MachineFile.EXCEPTION_OK) |
| | | .eq(MachineFile::getMachineCode,machine.getCode()).list(); |
| | | //.lt(MachineFile::getFileCreateTime,earlyTime) |
| | | |
| | | for(MachineFile overTimeFile : pendingFiles){ |
| | | try { |
| | | moveFileToTemp(overTimeFile, machine); |
| | | }catch(Exception e){ |
| | | log.error("移动rec文件失败:"+overTimeFile.getName(),e); |
| | | log.error("移动rec文件失败:{}",overTimeFile.getName(),e); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 文件移动到temp |
| | | * @param overTimeFile |
| | | */ |
| | | private void moveFileToTemp(MachineFile overTimeFile,Machine machine) throws IOException { |
| | | String srcFilepath = MachineFileService.getBasePath(machine,overTimeFile.getDirType())+ File.separator+overTimeFile.getName(); |
| | | Path source = Paths.get(srcFilepath); |
| | |
| | | // 使用 REPLACE_EXISTING 选项来覆盖已存在的文件 |
| | | Files.move(source, target, StandardCopyOption.REPLACE_EXISTING); |
| | | } |
| | | */ |
| | | } |