| | |
| | | import com.iailab.framework.security.core.util.SecurityFrameworkUtils; |
| | | import com.iailab.framework.tenant.core.context.TenantContextHolder; |
| | | import com.iailab.module.infra.api.config.ConfigApi; |
| | | import com.iailab.module.model.mcs.pre.service.MmModelArithSettingsService; |
| | | import com.iailab.module.model.mcs.sche.service.StScheduleModelSettingService; |
| | | import com.iailab.module.model.mpk.common.MdkConstant; |
| | | import com.iailab.module.model.mpk.common.utils.CmdUtils; |
| | | import com.iailab.module.model.mpk.common.utils.DllUtils; |
| | |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.net.URLClassLoader; |
| | | import java.nio.file.Files; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | private ProjectPackageHistoryModelService projectPackageHistoryModelService; |
| | | |
| | | @Autowired |
| | | private MmModelArithSettingsService mmModelArithSettingsService; |
| | | |
| | | @Autowired |
| | | private StScheduleModelSettingService stScheduleModelSettingService; |
| | | |
| | | @Autowired |
| | | private ConfigApi configApi; |
| | | |
| | | @Value("${mpk.bak-file-path}") |
| | |
| | | |
| | | @Value("${mpk.bak-resources}") |
| | | private String mpkResources; |
| | | |
| | | @Value("${mpk.delete-bak-file-cache}") |
| | | private Boolean isDeleteBakFile; |
| | | |
| | | @PostConstruct |
| | | void init() { |
| | | if (isDeleteBakFile) { |
| | | //删除无用备份pyd文件 |
| | | try { |
| | | deleteBakFile(); |
| | | } catch (Exception e) { |
| | | log.error("删除多余备份pyd文件失败",e); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | private void deleteBakFile() { |
| | | // 租户目录下的无用pyd |
| | | File bakDir = new File(mpkBakFilePath); |
| | | if (bakDir.exists() && bakDir.isDirectory()) { |
| | | File[] tenantDirs = bakDir.listFiles(dir -> dir.isDirectory() && !dir.getName().equals(MdkConstant.PROJECT_PUBLISH) && !dir.getName().equals(MdkConstant.PROJECT_UNPUBLISH) && dir.getName().matches("^[1-9]\\d*$")); |
| | | |
| | | if (tenantDirs != null && !CollectionUtils.isEmpty(Arrays.asList(tenantDirs))) { |
| | | for (File tenantDir : tenantDirs) { |
| | | File[] pydFiles = tenantDir.listFiles(file -> file.isFile() && file.getName().endsWith(".pyd")); |
| | | if (pydFiles == null || CollectionUtils.isEmpty(Arrays.asList(pydFiles))) { |
| | | continue; |
| | | } |
| | | TenantContextHolder.setTenantId(Long.valueOf(tenantDir.getName())); |
| | | List<MpkFileEntity> fileEntityList = baseDao.selectList(new QueryWrapper<>()); |
| | | List<String> filePathList = fileEntityList.stream().map(MpkFileEntity::getFilePath).collect(Collectors.toList()); |
| | | for (File pydFile : pydFiles) { |
| | | if (!filePathList.contains(pydFile.getAbsolutePath())) { |
| | | log.info("删除多余备份pyd文件:" + pydFile.getAbsoluteFile()); |
| | | pydFile.delete(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | // |
| | | // |
| | | // // 环境变量MDK_PKGS下pyd文件 |
| | | // String mdkPkgs = System.getenv("MDK_PKGS"); |
| | | // File pkgsDir = new File(mdkPkgs); |
| | | // List<File> pydFiles = getPydFiles(pkgsDir); |
| | | |
| | | } |
| | | |
| | | private List<File> getPydFiles(File pkgsDir) { |
| | | List<File> result = new ArrayList<>(); |
| | | if (pkgsDir.exists() && pkgsDir.isDirectory()) { |
| | | File[] files = pkgsDir.listFiles(); |
| | | if (files != null) { |
| | | for (File file : files) { |
| | | if (file.isDirectory()) { |
| | | // 递归调用获取子目录下的 .pyd 文件 |
| | | result.addAll(getPydFiles(file)); |
| | | } else if (file.isFile() && file.getName().endsWith(".pyd")) { |
| | | result.add(file); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public PageData<MpkFileDTO> page(Map<String, Object> params) { |
| | |
| | | methodSettings.add(setting); |
| | | } |
| | | } |
| | | |
| | | // 修改预测项pyFile参数 |
| | | mmModelArithSettingsService.updatePyFile(dto.getPyModule(),fileName); |
| | | // 修改调度项pyFile参数 |
| | | stScheduleModelSettingService.updatePyFile(dto.getPyModule(),fileName); |
| | | |
| | | MpkFileEntity entity = ConvertUtils.sourceToTarget(dto, MpkFileEntity.class); |
| | | entity.setUpdater(SecurityFrameworkUtils.getLoginUserId()); |
| | |
| | | String jarSavePath = pkgJar(dirPath.getAbsolutePath()); |
| | | //备份jar文件,用于后续运行 |
| | | String jarBakPath = mpkTenantBakFilePath + File.separator + MdkConstant.JAR + File.separator + entity.getPyName() + ".jar"; |
| | | FileUtil.mkParentDirs(dllBakPath); |
| | | FileUtil.mkParentDirs(jarBakPath); |
| | | FileUtil.copy(jarSavePath, jarBakPath, true); |
| | | // 打zip包 |
| | | String zipPath = mpkTenantBakFilePath + File.separator + zipFileName; |