liriming
2024-09-23 3670774f2ba43c075a475ef4fb46ac9e349bb082
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;
@@ -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) {
        //删除源文件
@@ -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,7 +206,7 @@
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    @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);