| | |
| | | package org.springblade.mdm.task; |
| | | |
| | | import com.alibaba.excel.util.StringUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.codec.digest.DigestUtils; |
| | | import org.springblade.mdm.basesetting.machine.MachineService; |
| | | import org.springblade.mdm.basesetting.machine.entity.Machine; |
| | | import org.springblade.mdm.basesetting.machine.service.MachineService; |
| | | import org.springblade.mdm.commons.service.ParamService; |
| | | import org.springblade.mdm.machinefile.entity.MachineFile; |
| | | import org.springblade.mdm.machinefile.service.MachineFileScanService; |
| | | import org.springblade.mdm.machinefile.service.MachineFileService; |
| | | import org.springblade.mdm.program.service.ProgramAnnotationService; |
| | | import org.springblade.mdm.utils.FileContentUtil; |
| | | import org.springblade.system.pojo.entity.DictBiz; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.EnableScheduling; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Path; |
| | | import java.nio.file.Paths; |
| | | import java.nio.file.attribute.BasicFileAttributes; |
| | | import java.nio.file.attribute.FileTime; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Slf4j |
| | | @Component |
| | |
| | | private ParamService paramService; |
| | | @Autowired |
| | | private ProgramAnnotationService programAnnotationService; |
| | | @Autowired |
| | | private MachineFileScanService machineFileScanService; |
| | | // 每5秒执行一次 |
| | | //@Scheduled(fixedRate = 1000000) |
| | | //@Scheduled(cron = "0 1 0 * * ?") // 每天上午0点1分执行 |
| | |
| | | |
| | | if(!ParamService.NETWORK_TYPE_SHEMI.equals(networkType)){ |
| | | //非涉密网,才扫描目录文件 |
| | | scanMachineFile(); |
| | | machineFileScanService.scanMachineFile(); |
| | | } |
| | | |
| | | } |
| | |
| | | /** |
| | | * 扫描所有机床的配置之目录 |
| | | */ |
| | | /* |
| | | public void scanMachineFile() { |
| | | List<Machine> machines = machineService.lambdaQuery().eq(Machine::getStatus,Machine.STATUS_ENABLE).list(); |
| | | for (Machine machine : machines) { |
| | | |
| | | //扫描新闻界 |
| | | //扫描新文件 |
| | | try { |
| | | scanDir(machine,MachineFile.DIR_TYPE_REC); |
| | | }catch(Exception e) { |
| | | log.error("REC扫描文件异常,机床"+machine.getCode(),e); |
| | | log.error("REC扫描文件异常,机床{}", machine.getCode(), e); |
| | | } |
| | | try { |
| | | scanDir(machine,MachineFile.DIR_TYPE_SEND); |
| | | }catch(Exception e) { |
| | | log.error("SEND扫描文件异常,机床"+machine.getCode(),e); |
| | | log.error("SEND扫描文件异常,机床{}", machine.getCode(), e); |
| | | } |
| | | try { |
| | | scanDir(machine,MachineFile.DIR_TYPE_TEMP); |
| | | }catch(Exception e) { |
| | | log.error("TEMP扫描文件异常,机床"+machine.getCode(),e); |
| | | log.error("TEMP扫描文件异常,机床{}", machine.getCode(), e); |
| | | } |
| | | |
| | | //清理数据库,删除文件不存在的数据 |
| | | try { |
| | | clearDeletedReccords(machine,MachineFile.DIR_TYPE_REC); |
| | | }catch(Exception e) { |
| | | log.error("REC扫描文件异常,机床"+machine.getCode(),e); |
| | | log.error("REC扫描文件异常,机床{}", machine.getCode(), e); |
| | | } |
| | | try { |
| | | clearDeletedReccords(machine,MachineFile.DIR_TYPE_SEND); |
| | | }catch(Exception e) { |
| | | log.error("SEND扫描文件异常,机床"+machine.getCode(),e); |
| | | log.error("SEND扫描文件异常,机床{}", machine.getCode(), e); |
| | | } |
| | | try { |
| | | clearDeletedReccords(machine,MachineFile.DIR_TYPE_TEMP); |
| | | }catch(Exception e) { |
| | | log.error("TEMP扫描文件异常,机床"+machine.getCode(),e); |
| | | log.error("TEMP扫描文件异常,机床{}", machine.getCode(), e); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | */ |
| | | |
| | | /** |
| | | * 扫描目录 |
| | |
| | | * @param dirType 目录类型 |
| | | * @throws IOException |
| | | */ |
| | | /* |
| | | public void scanDir(Machine machine,String dirType) throws IOException { |
| | | String basePath = MachineFileService.getBasePath(machine,dirType); |
| | | if(basePath == null) { |
| | |
| | | |
| | | |
| | | } |
| | | |
| | | */ |
| | | /** |
| | | * 读取文件中的程序状态 |
| | | * @param filePath 文件路径 |
| | |
| | | * @return 状态的整数之和 |
| | | * @throws IOException |
| | | */ |
| | | /* |
| | | int readProgramStatus(Path filePath,String machineGroupCode,List<DictBiz> annotatiionList) throws IOException { |
| | | int programStatus = MachineFile.PROGRAM_STATUS_UNKNOWN; |
| | | try(InputStream ins = Files.newInputStream(filePath)){ |
| | |
| | | |
| | | return programStatus; |
| | | } |
| | | |
| | | */ |
| | | /** |
| | | * 清理已经删除了文件的记录 |
| | | * @param machine |
| | | * @param dirType |
| | | * @throws IOException |
| | | */ |
| | | /* |
| | | void clearDeletedReccords(Machine machine,String dirType) throws IOException { |
| | | List<MachineFile> machineFiles = this.machineFileService.lambdaQuery().eq(MachineFile::getDirType,dirType) |
| | | .eq(MachineFile::getMachineCode,machine.getCode()).list(); |
| | |
| | | this.machineFileService.updateById(mf); |
| | | } |
| | | } |
| | | } |
| | | }*/ |
| | | } |