| | |
| | | import org.springblade.core.oss.model.BladeFile; |
| | | import org.springblade.mdm.basesetting.machine.service.MachineService; |
| | | import org.springblade.mdm.basesetting.machine.entity.Machine; |
| | | import org.springblade.mdm.commons.service.MachineDirTranslator; |
| | | import org.springblade.mdm.machinefile.entity.MachineFile; |
| | | import org.springblade.mdm.machinefile.entity.MachineFileChangeHis; |
| | | import org.springblade.mdm.machinefile.mapper.MachineFileMapper; |
| | |
| | | import org.springblade.mdm.program.vo.CompareDataVO; |
| | | import org.springblade.mdm.statreport.vo.MachineFileExceptionQueryVO; |
| | | import org.springblade.mdm.utils.FileContentUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | private final MachineService machineService; |
| | | private final MachineFileChangeHisService machineFileChangeHisService; |
| | | private final OssTemplate ossTemplate; |
| | | |
| | | private MachineDirTranslator machineDirTranslator; |
| | | /** |
| | | * 获取文件全路径 |
| | | * @param id 数据id |
| | |
| | | |
| | | /** |
| | | * 获取基本路径 |
| | | * @param machine |
| | | * @param dirType |
| | | * @return |
| | | * @param machine 机床 |
| | | * @param dirType 目录类型 |
| | | * @return 目录基本路径 |
| | | */ |
| | | public static String getBasePath(Machine machine,String dirType){ |
| | | String dirPath; |
| | |
| | | existFileInDb.setProgramStatus(mf.getProgramStatus()); |
| | | existFileInDb.setFileCreateTime(mf.getFileCreateTime()); |
| | | existFileInDb.setFileModifyTime(mf.getFileModifyTime()); |
| | | existFileInDb.setStatus(MachineFile.STATUS_NORMAL); |
| | | if(!com.alibaba.excel.util.StringUtils.equals(existFileInDb.getMd5(),mf.getMd5())){ |
| | | //文件内容发生变化了,设置状态为初始状态 |
| | | existFileInDb.setStatus(MachineFile.STATUS_NORMAL); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 修改文件名成 |
| | | * 修改文件名称 |
| | | * @param id 文件id |
| | | * @param name 新名称 |
| | | */ |
| | | public void changeName(Long id, String name) { |
| | | public void changeName(Long id, String name) throws IOException { |
| | | MachineFile machineFile = getById(id); |
| | | if(machineFile.getName().equals(name)) { |
| | | return; |
| | | } |
| | | Machine machine = machineService.getByCode(machineFile.getMachineCode()); |
| | | String baseDir = machineDirTranslator.trans(getBasePath(machine,machineFile.getDirType())); |
| | | String targetFilePath = baseDir + File.separator + name; |
| | | Path filePath = Paths.get(targetFilePath); |
| | | |
| | | if(filePath.toFile().exists()) { |
| | | throw new ServiceException("同名文件已存在:"+name); |
| | | } |
| | | Files.move(Paths.get(baseDir+File.separator+machineFile.getName()),filePath); |
| | | baseMapper.deleteById(id); |
| | | } |
| | | |
| | | public MachineFile getByNameAndMachineInDir(String name, String machineCode, String dirType) { |