| | |
| | | package com.iailab.module.model.mpk.service.impl; |
| | | |
| | | import cn.hutool.core.io.FileUtil; |
| | | 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; |
| | | import com.iailab.framework.common.service.impl.BaseServiceImpl; |
| | | import com.iailab.framework.common.service.impl.CrudServiceImpl; |
| | | import com.iailab.framework.common.util.object.ConvertUtils; |
| | | import com.iailab.module.model.mpk.dao.MpkFileDao; |
| | |
| | | import com.iailab.module.model.mpk.dto.ProjectModelDTO; |
| | | import com.iailab.module.model.mpk.dto.ProjectPackageHistoryDTO; |
| | | import com.iailab.module.model.mpk.entity.ProjectEntity; |
| | | import com.iailab.module.model.mpk.entity.ProjectModelEntity; |
| | | import com.iailab.module.model.mpk.entity.ProjectPackageHistoryModelEntity; |
| | | import com.iailab.module.model.mpk.entity.ProjectPackageHistoryEntity; |
| | | import com.iailab.module.model.mpk.service.ProjectModelService; |
| | | import com.iailab.module.model.mpk.service.ProjectPackageHistoryModelService; |
| | | import com.iailab.module.model.mpk.service.ProjectPackageHistoryService; |
| | |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.io.File; |
| | | import java.util.*; |
| | |
| | | **/ |
| | | @Service |
| | | @Slf4j |
| | | public class ProjectServiceImpl extends CrudServiceImpl<ProjectDao, ProjectEntity, ProjectDTO> implements ProjectService { |
| | | public class ProjectServiceImpl extends BaseServiceImpl<ProjectDao, ProjectEntity> implements ProjectService { |
| | | |
| | | @Autowired |
| | | ProjectModelService projectModelService; |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @DSTransactional(rollbackFor = Exception.class) |
| | | public void save(ProjectDTO dto) { |
| | | ProjectEntity entity = ConvertUtils.sourceToTarget(dto, ProjectEntity.class); |
| | | String projectId = UUID.randomUUID().toString(); |
| | |
| | | //关联模型 |
| | | List<MpkFileDTO> models = dto.getModels(); |
| | | if (CollectionUtils.isNotEmpty(models)) { |
| | | List<ProjectModelEntity> projectModelList = new ArrayList<>(models.size()); |
| | | for (MpkFileDTO model : models) { |
| | | ProjectModelEntity projectModel = new ProjectModelEntity(); |
| | | projectModel.setId(UUID.randomUUID().toString()); |
| | | projectModel.setProjectId(projectId); |
| | | projectModel.setModelId(model.getId()); |
| | | projectModelList.add(projectModel); |
| | | } |
| | | projectModelService.insertBatch(projectModelList); |
| | | projectModelService.create(models,projectId); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @DSTransactional(rollbackFor = Exception.class) |
| | | public void update(ProjectDTO dto) { |
| | | ProjectEntity entity = ConvertUtils.sourceToTarget(dto, ProjectEntity.class); |
| | | entity.setUpdateTime(new Date()); |
| | |
| | | //关联模型 |
| | | List<MpkFileDTO> models = dto.getModels(); |
| | | if (CollectionUtils.isNotEmpty(models)) { |
| | | List<ProjectModelEntity> projectModelList = new ArrayList<>(models.size()); |
| | | for (MpkFileDTO model : models) { |
| | | ProjectModelEntity projectModel = new ProjectModelEntity(); |
| | | projectModel.setId(UUID.randomUUID().toString()); |
| | | projectModel.setProjectId(projectId); |
| | | projectModel.setModelId(model.getId()); |
| | | projectModelList.add(projectModel); |
| | | } |
| | | projectModelService.insertBatch(projectModelList); |
| | | projectModelService.create(models,projectId); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @DSTransactional(rollbackFor = Exception.class) |
| | | public void delete(String id) { |
| | | //删除备份文件 |
| | | Map<String,Object> map = new HashMap<>(); |
| | | map.put("projectId",id); |
| | | List<ProjectPackageHistoryDTO> list = projectPackageHistoryService.list(map); |
| | | List<ProjectPackageHistoryEntity> list = projectPackageHistoryService.list(map); |
| | | list.forEach(e -> { |
| | | File file = new File(e.getFilePath()); |
| | | if (file.exists()) { |
| | |
| | | return new PageData<>(list,total); |
| | | } |
| | | |
| | | @Override |
| | | public QueryWrapper<ProjectEntity> getWrapper(Map<String, Object> params){ |
| | | String id = (String)params.get("id"); |
| | | String projectName = (String)params.get("projectName"); |