| | |
| | | import org.springblade.core.mp.base.BizServiceImpl; |
| | | import org.springblade.core.mp.support.Condition; |
| | | import org.springblade.core.tool.utils.BeanUtil; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.mdm.basesetting.machine.entity.Machine; |
| | | import org.springblade.mdm.basesetting.machine.entity.MachineSpec; |
| | | import org.springblade.mdm.basesetting.machine.mapper.MachineMapper; |
| | |
| | | import org.springblade.mdm.basesetting.machine.vo.MachineVO; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.FileSystemUtils; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.InvalidPathException; |
| | | import java.nio.file.Path; |
| | | import java.nio.file.Paths; |
| | | |
| | | @Service |
| | | public class MachineService extends BizServiceImpl<MachineMapper, Machine> { |
| | |
| | | } |
| | | return page; |
| | | } |
| | | |
| | | /** |
| | | * 查询详情 |
| | | * @param id 机床id |
| | | * @return |
| | | */ |
| | | public MachineVO detail(long id) { |
| | | Machine machine = this.getById(id); |
| | | |
| | | MachineVO vo = new MachineVO(); |
| | | BeanUtil.copyProperties(machine, vo); |
| | | |
| | | return vo; |
| | | } |
| | | |
| | | /** |
| | | * 产生机床回传结构数据 |
| | | * @param id |
| | | */ |
| | | public void genMachineFileBackDirs(Long id) throws IOException { |
| | | Machine machine = this.getById(id); |
| | | if(Func.isNotBlank(machine.getProgReceiveDir())){ |
| | | if(isLegalDirectoryPath(machine.getProgReceiveDir())) { |
| | | Path path = Paths.get(machine.getProgReceiveDir()); |
| | | Files.createDirectories(path); |
| | | }else{ |
| | | throw new RuntimeException("非法的目录格式"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 判断是否是合法的目录格式 |
| | | * @param path |
| | | * @return |
| | | */ |
| | | static boolean isLegalDirectoryPath(String path) { |
| | | // 基础检查 |
| | | if (path == null || path.trim().isEmpty()) { |
| | | return false; |
| | | } |
| | | |
| | | // 使用NIO检查路径格式 |
| | | Path nioPath; |
| | | try { |
| | | nioPath = Paths.get(path); |
| | | if (!nioPath.normalize().toString().equals(path)) { |
| | | return false; // 路径不规范 |
| | | } |
| | | } catch (InvalidPathException ex) { |
| | | return false; |
| | | } |
| | | |
| | | return true; |
| | | |
| | | } |
| | | } |