| | |
| | | @Override |
| | | @DSTransactional(rollbackFor = Exception.class) |
| | | public void update(MpkFileDTO dto) { |
| | | // 判断py文件是否修改 |
| | | MpkFileEntity oldEntity = selectById(dto.getId()); |
| | | if (!oldEntity.getFilePath().equals(dto.getFilePath())) { |
| | | // 将备份的pyd文件,转移到MDK_PKGS环境变量下,并添加方法的默认参数(pyFile,模型路径) |
| | | String mdkPkgs = System.getenv("MDK_PKGS"); |
| | | String fileName = dto.getFilePath().substring(dto.getFilePath().lastIndexOf("\\") + 1,dto.getFilePath().lastIndexOf(".pyd")); |
| | | String pyFilePath = mdkPkgs + File.separator + dto.getPyModule().replace(".", File.separator) + File.separator + fileName + ".pyd"; |
| | | // 添加方法的默认参数(pyFile,模型路径) |
| | | String mdkPkgs = System.getenv("MDK_PKGS"); |
| | | String fileName = dto.getFilePath().substring(dto.getFilePath().lastIndexOf("\\") + 1,dto.getFilePath().lastIndexOf(".pyd")); |
| | | String pyFilePath = mdkPkgs + File.separator + dto.getPyModule().replace(".", File.separator) + File.separator + fileName + ".pyd"; |
| | | // 判断文件是否存在,不存在的话将备份的pyd文件,转移到MDK_PKGS环境变量下 |
| | | File pyFile = new File(pyFilePath); |
| | | if (!pyFile.exists()) { |
| | | FileUtil.mkParentDirs(pyFilePath); |
| | | FileUtil.copy(dto.getFilePath(), pyFilePath, true); |
| | | } |
| | | |
| | | // 添加/修改参数 |
| | | for (ModelMethodDTO method : dto.getModelMethods()) { |
| | | List<MethodSettingDTO> methodSettings = method.getMethodSettings(); |
| | | if (methodSettings.stream().anyMatch(e -> e.getSettingKey().equals(MdkConstant.PY_FILE_KEY))) { |
| | | methodSettings.forEach(e -> { |
| | | if (e.getSettingKey().equals(MdkConstant.PY_FILE_KEY)) { |
| | | e.setValue(dto.getPyModule() + "." + fileName); |
| | | } |
| | | }); |
| | | }else { |
| | | MethodSettingDTO setting = new MethodSettingDTO(); |
| | | setting.setId(UUID.randomUUID().toString()); |
| | | setting.setMethodId(method.getId()); |
| | | setting.setSettingKey(MdkConstant.PY_FILE_KEY); |
| | | setting.setValue(dto.getPyModule() + "." + fileName); |
| | | setting.setName("模型路径"); |
| | | setting.setType("input"); |
| | | setting.setValueType("string"); |
| | | methodSettings.add(setting); |
| | | } |
| | | // 添加/修改参数 |
| | | for (ModelMethodDTO method : dto.getModelMethods()) { |
| | | List<MethodSettingDTO> methodSettings = method.getMethodSettings(); |
| | | if (methodSettings.stream().anyMatch(e -> e.getSettingKey().equals(MdkConstant.PY_FILE_KEY))) { |
| | | methodSettings.forEach(e -> { |
| | | if (e.getSettingKey().equals(MdkConstant.PY_FILE_KEY)) { |
| | | e.setValue(dto.getPyModule() + "." + fileName); |
| | | } |
| | | }); |
| | | }else { |
| | | MethodSettingDTO setting = new MethodSettingDTO(); |
| | | setting.setId(UUID.randomUUID().toString()); |
| | | setting.setMethodId(method.getId()); |
| | | setting.setSettingKey(MdkConstant.PY_FILE_KEY); |
| | | setting.setValue(dto.getPyModule() + "." + fileName); |
| | | setting.setName("模型路径"); |
| | | setting.setType("input"); |
| | | setting.setValueType("string"); |
| | | methodSettings.add(setting); |
| | | } |
| | | } |
| | | |