From 3670774f2ba43c075a475ef4fb46ac9e349bb082 Mon Sep 17 00:00:00 2001 From: liriming <1343021927@qq.com> Date: 星期一, 23 九月 2024 08:35:37 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/service/impl/MpkFileServiceImpl.java | 164 +++++++++++++++--------------------------------------- 1 files changed, 46 insertions(+), 118 deletions(-) diff --git a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/service/impl/MpkFileServiceImpl.java b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/service/impl/MpkFileServiceImpl.java index 6ef8959..97193fc 100644 --- a/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/service/impl/MpkFileServiceImpl.java +++ b/iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mpk/service/impl/MpkFileServiceImpl.java @@ -4,6 +4,7 @@ import cn.hutool.core.util.RuntimeUtil; import cn.hutool.core.util.ZipUtil; import com.alibaba.fastjson.JSON; +import com.baomidou.dynamic.datasource.annotation.DSTransactional; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.iailab.framework.common.page.PageData; @@ -31,7 +32,6 @@ import org.springframework.util.CollectionUtils; import org.springframework.web.multipart.MultipartFile; -import javax.annotation.PostConstruct; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; @@ -52,16 +52,13 @@ @Autowired private GeneratorCodeHistoryService generatorCodeHistoryService; - @Autowired - private ProjectModelService projectModelService; + @Autowired private ProjectPackageHistoryService projectPackageHistoryService; + @Autowired private ModelMethodService modelMethodService; - @Autowired - private MethodSettingService methodSettingService; - @Autowired - private SettingSelectService settingSelectService; + @Autowired private ProjectPackageHistoryModelService projectPackageHistoryModelService; @@ -93,7 +90,7 @@ return ConvertUtils.sourceToTarget(entityList, MpkFileDTO.class); } - private QueryWrapper<MpkFileEntity> getWrapper(Map<String, Object> params){ + private QueryWrapper<MpkFileEntity> getWrapper(Map<String, Object> params) { String pyName = (String) params.get("pyName"); String pyType = (String) params.get("pyType"); String remark = (String) params.get("remark"); @@ -113,86 +110,29 @@ } @Override - @Transactional(rollbackFor = Exception.class) + @DSTransactional(rollbackFor = Exception.class) public void save(MpkFileDTO dto) { MpkFileEntity entity = ConvertUtils.sourceToTarget(dto, MpkFileEntity.class); - String mpkId = UUID.randomUUID().toString(); - entity.setId(mpkId); + entity.setId(UUID.randomUUID().toString()); entity.setCreator(SecurityFrameworkUtils.getLoginUserId()); entity.setCreateDate(new Date()); insert(entity); - - // 添加模型方法 - insertModelMethod(dto.getModelMethods(),mpkId); + modelMethodService.insertList(dto.getModelMethods(), entity.getId()); } @Override - @Transactional(rollbackFor = Exception.class) + @DSTransactional(rollbackFor = Exception.class) public void update(MpkFileDTO dto) { MpkFileEntity entity = ConvertUtils.sourceToTarget(dto, MpkFileEntity.class); entity.setUpdater(SecurityFrameworkUtils.getLoginUserId()); entity.setUpdateDate(new Date()); updateById(entity); - - String mpkId = dto.getId(); - // 删除模型方法 会级联删除setting和select - deleteModelMethod(mpkId); - - // 添加模型方法 - insertModelMethod(dto.getModelMethods(),mpkId); - } - - private void insertModelMethod(List<ModelMethodDTO> modelMethods, String mpkId) { - List<MethodSettingDTO> methodSettingList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(modelMethods)) { - modelMethods.forEach(e -> { - String methodId = UUID.randomUUID().toString(); - e.setId(methodId); - e.setMpkFileId(mpkId); - - e.getMethodSettings().forEach(s -> { - s.setId(UUID.randomUUID().toString()); - s.setMethodId(methodId); - methodSettingList.add(s); - }); - - }); - modelMethodService.insertBatch(ConvertUtils.sourceToTarget(modelMethods, ModelMethodEntity.class)); - - //添加setting - insertMethodSetting(methodSettingList); - } - } - - private void insertMethodSetting(List<MethodSettingDTO> methodSettings) { - List<SettingSelectEntity> settingSelectList = new ArrayList<>(); - if (!CollectionUtils.isEmpty(methodSettings)) { - methodSettings.forEach(e -> { - String settingId = UUID.randomUUID().toString(); - e.setId(settingId); - - e.getSettingSelects().forEach(s -> { - s.setId(UUID.randomUUID().toString()); - s.setSettingId(settingId); - settingSelectList.add(ConvertUtils.sourceToTarget(s,SettingSelectEntity.class)); - }); - - }); - methodSettingService.insertBatch(ConvertUtils.sourceToTarget(methodSettings, MethodSettingEntity.class)); - - //添加select - settingSelectService.insertBatch(settingSelectList); - } - } - - private void deleteModelMethod(String mpkId) { - Map<String,Object> map = new HashMap<>(); - map.put("mpkFileId", mpkId); - modelMethodService.deleteByMap(map); + modelMethodService.deleteModelMethod(entity.getId()); + modelMethodService.insertList(dto.getModelMethods(), entity.getId()); } @Override - @Transactional(rollbackFor = Exception.class) + @DSTransactional(rollbackFor = Exception.class) public void delete(String id) { //删除源文件 @@ -206,8 +146,8 @@ } //删除备份文件 - Map<String,Object> map1 = new HashMap<>(); - map1.put("mdkId",id); + Map<String, Object> map1 = new HashMap<>(); + map1.put("mdkId", id); List<GeneratorCodeHistoryDTO> list = generatorCodeHistoryService.list(map1); list.forEach(e -> { File file = new File(e.getFilePath()); @@ -219,18 +159,6 @@ //删除 会级联删除掉关联表 deleteById(id); - - //删除生成历史 -// generatorCodeHistoryService.deleteByMap(map1); - - //删除关联项目 -// Map<String,Object> map = new HashMap<>(); -// map.put("modelId",id); -// projectModelService.deleteByMap(map); - - //删除模型方法 -// deleteModelMethod(id); - } @Override @@ -278,13 +206,13 @@ } @Override - @Transactional(rollbackFor = Exception.class) - public byte[] packageModel(List<String> ids,String projectId,String projectName,String zipFileName,String log,String version) throws IOException, InterruptedException { + @DSTransactional(rollbackFor = Exception.class) + public byte[] packageModel(List<String> ids, String projectId, String projectName, String zipFileName, String log, String version) throws IOException, InterruptedException { List<MpkFileDTO> entities = baseDao.selectByIds(ids); //模板数据 Map<String, Object> map = new HashMap<>(); - map.put("entities",entities); + map.put("entities", entities); VelocityContext context = new VelocityContext(map); //临时文件夹 @@ -301,17 +229,17 @@ //生成menu.xml文件 Map<String, Map<String, List<MpkFileDTO>>> collect = entities.stream().collect(Collectors.groupingBy(MpkFileDTO::getMenuName, Collectors.groupingBy(e -> StringUtils.isNotBlank(e.getGroupName()) ? e.getGroupName() : "default_group"))); Map<String, Object> map1 = new HashMap<>(); - map1.put("collects",collect); + map1.put("collects", collect); File xmlFile = new File(dirPath.getAbsolutePath() + File.separator + "menu.xml"); - GenUtils.drawTemplate("menu.xml.vm",new VelocityContext(map1),xmlFile); + GenUtils.drawTemplate("menu.xml.vm", new VelocityContext(map1), xmlFile); //生成cpp文件 File cppFile = new File(dirPath.getAbsolutePath() + File.separator + UUID.randomUUID() + ".cpp"); - GenUtils.drawTemplate("pkg.cpp.vm",context,cppFile); + GenUtils.drawTemplate("pkg.cpp.vm", context, cppFile); //生成Jni.cpp文件 File jniCppFile = new File(dirPath.getAbsolutePath() + File.separator + UUID.randomUUID() + "Jni.cpp"); - GenUtils.drawTemplate("pkg.Jni.cpp.vm",context,jniCppFile); + GenUtils.drawTemplate("pkg.Jni.cpp.vm", context, jniCppFile); //生成dll文件 String dllSavePath = dirPath.getAbsolutePath() + File.separator + "IAIL.MDK.Mid.Windows.dll"; @@ -328,35 +256,35 @@ for (MpkFileDTO entity : entities) { //封装模板数据 Map<String, Object> data = new HashMap<>(); - data.put("pkgName",entity.getPkgName()); - data.put("modelMethods",entity.getModelMethods()); - data.put("pyName",entity.getPyName()); - data.put("pyModule",entity.getPyModule()); + data.put("pkgName", entity.getPkgName()); + data.put("modelMethods", entity.getModelMethods()); + data.put("pyName", entity.getPyName()); + data.put("pyModule", entity.getPyModule()); VelocityContext dataContext = new VelocityContext(data); //生成java文件 File javaFile = new File(dirPath.getAbsolutePath() + File.separator + "IAILMDK" + File.separator + entity.getPkgName().replace(".", File.separator) + File.separator + entity.getPyName() + ".java"); - GenUtils.drawTemplate("abstract.java.vm",dataContext,javaFile); + GenUtils.drawTemplate("abstract.java.vm", dataContext, javaFile); javaFilePaths.add(javaFile.getAbsolutePath()); //生成Impl.java文件 File implJavaFile = new File(dirPath.getAbsolutePath() + File.separator + "IAILMDK" + File.separator + entity.getPkgName().replace(".", File.separator) + File.separator + MdkConstant.IMPL + File.separator + entity.getPyName() + "Impl.java"); - GenUtils.drawTemplate("impl.java.vm",dataContext,implJavaFile); + GenUtils.drawTemplate("impl.java.vm", dataContext, implJavaFile); javaFilePaths.add(implJavaFile.getAbsolutePath()); // 添加python源文件 - String pyFilePath = dirPath.getAbsolutePath() + File.separator + "py" + File.separator + entity.getPyName() + ".pyd"; + String pyFilePath = dirPath.getAbsolutePath() + File.separator + "py" + File.separator + entity.getPyName() + ".pyd"; FileUtil.mkParentDirs(pyFilePath); - FileUtil.copy(entity.getFilePath(),pyFilePath,true); + FileUtil.copy(entity.getFilePath(), pyFilePath, true); } //utils + env java文件 File utilsJavaFile = new File(dirPath.getAbsolutePath() + File.separator + "IAILMDK" + File.separator + "utils" + File.separator + "AlgsUtils.java"); FileUtil.mkParentDirs(utilsJavaFile); - FileUtil.copy("bak/AlgsUtils.java",utilsJavaFile.getAbsolutePath(),true); + FileUtil.copy("bak/AlgsUtils.java", utilsJavaFile.getAbsolutePath(), true); javaFilePaths.add(utilsJavaFile.getAbsolutePath()); File envJavaFile = new File(dirPath.getAbsolutePath() + File.separator + "IAILMDK" + File.separator + "common" + File.separator + "Environment.java"); FileUtil.mkParentDirs(envJavaFile); - FileUtil.copy("bak/Environment.java",envJavaFile.getAbsolutePath(),true); + FileUtil.copy("bak/Environment.java", envJavaFile.getAbsolutePath(), true); javaFilePaths.add(envJavaFile.getAbsolutePath()); // 生成class文件 createClassFile(javaFilePaths); @@ -375,10 +303,10 @@ dto.setModelNames(entities.stream().map(MpkFileDTO::getPyName).collect(Collectors.joining(","))); dto.setCreateTime(new Date()); // 生成更新日志 - createLog(projectId,projectName,dirPath.getAbsolutePath(),dto,version); + createLog(projectId, projectName, dirPath.getAbsolutePath(), dto, version); // 打zip包 String zipPath = mpkBakFilePath + File.separator + zipFileName; - ZipUtil.zip(dirPath.getAbsolutePath(),zipPath); + ZipUtil.zip(dirPath.getAbsolutePath(), zipPath); byte[] bytes = FileUtil.readBytes(zipPath); // 记录打包日志 dto.setFilePath(zipPath); @@ -409,7 +337,7 @@ } @Override - public Map<String,String> savePyFile(MultipartFile file) throws IOException { + public Map<String, String> savePyFile(MultipartFile file) throws IOException { File dir = new File(mpkBakFilePath); if (!dir.exists()) { dir.mkdirs(); @@ -420,32 +348,32 @@ // 保存 file.transferTo(saveFile); - Map<String,String> result = new HashMap<>(2); - result.put("filePath",saveFile.getAbsolutePath()); + Map<String, String> result = new HashMap<>(2); + result.put("filePath", saveFile.getAbsolutePath()); result.put("fileName", fileName); return result; } - private void createLog(String projectId,String projectName,String dirPath,ProjectPackageHistoryDTO dto,String version) throws IOException { - Map<String,Object> map = new HashMap<>(); - map.put("projectId",projectId); + private void createLog(String projectId, String projectName, String dirPath, ProjectPackageHistoryDTO dto, String version) throws IOException { + Map<String, Object> map = new HashMap<>(); + map.put("projectId", projectId); List<ProjectPackageHistoryDTO> list = projectPackageHistoryService.list(map); list.add(dto); // 按照日期分组再排序 HashMap<String, List<ProjectPackageHistoryDTO>> dataMap = list.stream().collect( Collectors.groupingBy(e -> DateUtils.format(e.getCreateTime(), DateUtils.DATE_PATTERN_POINT), - LinkedHashMap::new, - Collectors.collectingAndThen(Collectors.toList(), e -> e.stream().sorted(Comparator.comparing(ProjectPackageHistoryDTO::getCreateTime)).collect(Collectors.toList())))); + LinkedHashMap::new, + Collectors.collectingAndThen(Collectors.toList(), e -> e.stream().sorted(Comparator.comparing(ProjectPackageHistoryDTO::getCreateTime)).collect(Collectors.toList())))); Map<String, Object> data = new HashMap<>(); - data.put("dataMap",dataMap); - data.put("projectName",projectName); - data.put("version",version); - data.put("now",DateUtils.format(new Date(),DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); + data.put("dataMap", dataMap); + data.put("projectName", projectName); + data.put("version", version); + data.put("now", DateUtils.format(new Date(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)); File logFile = new File(dirPath + File.separator + "更新日志.txt"); - GenUtils.drawTemplate("log.txt.vm",data,logFile); + GenUtils.drawTemplate("log.txt.vm", data, logFile); } private void pkgJar(String dirPath) throws InterruptedException { -- Gitblit v1.9.3