提交 | 用户 | 时间
|
449017
|
1 |
package com.iailab.module.model.mpk.service.impl; |
D |
2 |
|
|
3 |
import cn.hutool.core.io.FileUtil; |
|
4 |
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
5 |
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
6 |
import com.iailab.framework.common.page.PageData; |
|
7 |
import com.iailab.framework.common.service.impl.CrudServiceImpl; |
|
8 |
import com.iailab.framework.common.util.object.ConvertUtils; |
|
9 |
import com.iailab.module.model.mpk.dao.MpkFileDao; |
|
10 |
import com.iailab.module.model.mpk.dao.ProjectDao; |
|
11 |
import com.iailab.module.model.mpk.dto.MpkFileDTO; |
|
12 |
import com.iailab.module.model.mpk.dto.ProjectDTO; |
|
13 |
import com.iailab.module.model.mpk.dto.ProjectModelDTO; |
|
14 |
import com.iailab.module.model.mpk.dto.ProjectPackageHistoryDTO; |
|
15 |
import com.iailab.module.model.mpk.entity.ProjectEntity; |
|
16 |
import com.iailab.module.model.mpk.entity.ProjectModelEntity; |
|
17 |
import com.iailab.module.model.mpk.entity.ProjectPackageHistoryModelEntity; |
|
18 |
import com.iailab.module.model.mpk.service.ProjectModelService; |
|
19 |
import com.iailab.module.model.mpk.service.ProjectPackageHistoryModelService; |
|
20 |
import com.iailab.module.model.mpk.service.ProjectPackageHistoryService; |
|
21 |
import com.iailab.module.model.mpk.service.ProjectService; |
|
22 |
import lombok.extern.slf4j.Slf4j; |
|
23 |
import org.apache.commons.collections.CollectionUtils; |
|
24 |
import org.apache.commons.lang3.StringUtils; |
|
25 |
import org.springframework.beans.factory.annotation.Autowired; |
|
26 |
import org.springframework.stereotype.Service; |
|
27 |
import org.springframework.transaction.annotation.Transactional; |
|
28 |
|
|
29 |
import java.io.File; |
|
30 |
import java.util.*; |
|
31 |
import java.util.stream.Collectors; |
|
32 |
|
|
33 |
/** |
|
34 |
* @description: 项目表 |
|
35 |
* @author: dzd |
|
36 |
* @date: 2024/8/22 14:40 |
|
37 |
**/ |
|
38 |
@Service |
|
39 |
@Slf4j |
|
40 |
public class ProjectServiceImpl extends CrudServiceImpl<ProjectDao, ProjectEntity, ProjectDTO> implements ProjectService { |
|
41 |
|
|
42 |
@Autowired |
|
43 |
ProjectModelService projectModelService; |
|
44 |
@Autowired |
|
45 |
ProjectPackageHistoryService projectPackageHistoryService; |
|
46 |
@Autowired |
|
47 |
ProjectPackageHistoryModelService projectPackageHistoryModelService; |
|
48 |
@Autowired |
|
49 |
MpkFileDao mpkFileDao; |
|
50 |
|
|
51 |
@Override |
|
52 |
public PageData<ProjectDTO> page(Map<String, Object> params) { |
|
53 |
IPage<ProjectDTO> page = baseDao.getPageList( |
|
54 |
getPage(params, null, false), |
|
55 |
params |
|
56 |
); |
|
57 |
|
|
58 |
return getPageData(page, ProjectDTO.class); |
|
59 |
} |
|
60 |
|
|
61 |
@Override |
|
62 |
public List<ProjectDTO> list(Map<String, Object> params) { |
|
63 |
List<ProjectEntity> entityList = baseDao.selectList(getWrapper(params).orderByDesc("create_time")); |
|
64 |
|
|
65 |
return ConvertUtils.sourceToTarget(entityList, ProjectDTO.class); |
|
66 |
} |
|
67 |
|
|
68 |
@Override |
|
69 |
public ProjectDTO get(String id) { |
|
70 |
ProjectEntity entity = baseDao.selectById(id); |
|
71 |
ProjectDTO dto = ConvertUtils.sourceToTarget(entity, ProjectDTO.class); |
|
72 |
|
|
73 |
Map<String,Object> map = new HashMap<>(); |
|
74 |
map.put("projectId",id); |
|
75 |
List<ProjectModelDTO> projectModelList = projectModelService.list(map); |
|
76 |
dto.setModels(projectModelList.stream().map(e -> { |
|
77 |
MpkFileDTO mdkFileDTO = new MpkFileDTO(); |
|
78 |
mdkFileDTO.setId(e.getModelId()); |
|
79 |
return mdkFileDTO; |
|
80 |
}).collect(Collectors.toList())); |
|
81 |
|
|
82 |
return dto; |
|
83 |
} |
|
84 |
|
|
85 |
@Override |
|
86 |
@Transactional(rollbackFor = Exception.class) |
|
87 |
public void save(ProjectDTO dto) { |
|
88 |
ProjectEntity entity = ConvertUtils.sourceToTarget(dto, ProjectEntity.class); |
|
89 |
String projectId = UUID.randomUUID().toString(); |
|
90 |
entity.setId(projectId); |
|
91 |
entity.setCreateTime(new Date()); |
|
92 |
insert(entity); |
|
93 |
|
|
94 |
//关联模型 |
|
95 |
List<MpkFileDTO> models = dto.getModels(); |
|
96 |
if (CollectionUtils.isNotEmpty(models)) { |
|
97 |
List<ProjectModelEntity> projectModelList = new ArrayList<>(models.size()); |
|
98 |
for (MpkFileDTO model : models) { |
|
99 |
ProjectModelEntity projectModel = new ProjectModelEntity(); |
|
100 |
projectModel.setId(UUID.randomUUID().toString()); |
|
101 |
projectModel.setProjectId(projectId); |
|
102 |
projectModel.setModelId(model.getId()); |
|
103 |
projectModelList.add(projectModel); |
|
104 |
} |
|
105 |
projectModelService.insertBatch(projectModelList); |
|
106 |
} |
|
107 |
} |
|
108 |
|
|
109 |
@Override |
|
110 |
@Transactional(rollbackFor = Exception.class) |
|
111 |
public void update(ProjectDTO dto) { |
|
112 |
ProjectEntity entity = ConvertUtils.sourceToTarget(dto, ProjectEntity.class); |
|
113 |
entity.setUpdateTime(new Date()); |
|
114 |
updateById(entity); |
|
115 |
|
|
116 |
String projectId = dto.getId(); |
|
117 |
//删除关联 |
|
118 |
Map<String,Object> map = new HashMap<>(); |
|
119 |
map.put("projectId",projectId); |
|
120 |
projectModelService.deleteByMap(map); |
|
121 |
|
|
122 |
//关联模型 |
|
123 |
List<MpkFileDTO> models = dto.getModels(); |
|
124 |
if (CollectionUtils.isNotEmpty(models)) { |
|
125 |
List<ProjectModelEntity> projectModelList = new ArrayList<>(models.size()); |
|
126 |
for (MpkFileDTO model : models) { |
|
127 |
ProjectModelEntity projectModel = new ProjectModelEntity(); |
|
128 |
projectModel.setId(UUID.randomUUID().toString()); |
|
129 |
projectModel.setProjectId(projectId); |
|
130 |
projectModel.setModelId(model.getId()); |
|
131 |
projectModelList.add(projectModel); |
|
132 |
} |
|
133 |
projectModelService.insertBatch(projectModelList); |
|
134 |
} |
|
135 |
} |
|
136 |
|
|
137 |
@Override |
|
138 |
@Transactional(rollbackFor = Exception.class) |
|
139 |
public void delete(String id) { |
|
140 |
|
|
141 |
//删除 |
|
142 |
baseDao.deleteById(id); |
|
143 |
|
|
144 |
//删除模型关联 |
|
145 |
Map<String,Object> map = new HashMap<>(); |
|
146 |
map.put("projectId",id); |
|
147 |
projectModelService.deleteByMap(map); |
|
148 |
|
|
149 |
//删除备份文件 |
|
150 |
List<ProjectPackageHistoryDTO> list = projectPackageHistoryService.list(map); |
|
151 |
list.forEach(e -> { |
|
152 |
File file = new File(e.getFilePath()); |
|
153 |
if (file.exists()) { |
|
154 |
file.delete(); |
|
155 |
log.info("删除打包备份文件:" + e.getFilePath()); |
|
156 |
} |
|
157 |
}); |
|
158 |
|
|
159 |
//删除打包历史 |
|
160 |
projectPackageHistoryService.deleteByMap(map); |
|
161 |
|
|
162 |
//删除打包历史模型关联 |
|
163 |
projectPackageHistoryModelService.deleteByMap(map); |
|
164 |
} |
|
165 |
|
|
166 |
@Override |
|
167 |
public PageData<MpkFileDTO> getProjectModel(Map<String, Object> params) { |
|
168 |
String projectId = (String) params.get("projectId"); |
|
169 |
|
|
170 |
int total = mpkFileDao.getProjectModelCount(projectId); |
|
171 |
if (total == 0) { |
|
172 |
return new PageData<>(new ArrayList<>(), 0); |
|
173 |
} |
|
174 |
int page = Integer.parseInt((String) params.get("page")); |
|
175 |
int pageSize = Integer.parseInt((String) params.get("pageSize")); |
|
176 |
int offset = (page - 1)*pageSize; |
|
177 |
params.put("offset",offset); |
|
178 |
params.put("pageSize",pageSize); |
|
179 |
List<MpkFileDTO> list = mpkFileDao.getProjectModel(params); |
|
180 |
|
|
181 |
return new PageData<>(list,total); |
|
182 |
} |
|
183 |
|
|
184 |
@Override |
|
185 |
public QueryWrapper<ProjectEntity> getWrapper(Map<String, Object> params){ |
|
186 |
String id = (String)params.get("id"); |
|
187 |
String projectName = (String)params.get("projectName"); |
|
188 |
|
|
189 |
QueryWrapper<ProjectEntity> wrapper = new QueryWrapper<>(); |
|
190 |
wrapper.eq(StringUtils.isNotBlank(id), "id", id) |
|
191 |
.like(StringUtils.isNotBlank(projectName),"project_name",projectName); |
|
192 |
|
|
193 |
return wrapper; |
|
194 |
} |
|
195 |
|
|
196 |
|
|
197 |
} |