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