提交 | 用户 | 时间
|
a6de49
|
1 |
package com.iailab.module.mcs.service.impl; |
H |
2 |
|
|
3 |
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
4 |
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
5 |
import com.iailab.common.enums.IsEnableEnum; |
|
6 |
import com.iailab.framework.common.page.PageData; |
|
7 |
import com.iailab.framework.common.service.impl.BaseServiceImpl; |
|
8 |
import com.iailab.framework.common.util.object.ConvertUtils; |
|
9 |
import com.iailab.common.utils.UnzipUtils; |
|
10 |
import com.iailab.module.mcs.dao.StModelDao; |
|
11 |
import com.iailab.module.mcs.dto.RelationLineDTO; |
|
12 |
import com.iailab.module.mcs.dto.RelationNodeDTO; |
|
13 |
import com.iailab.module.mcs.dto.StModelDTO; |
|
14 |
import com.iailab.module.mcs.entity.StModelEntity; |
|
15 |
import com.iailab.module.mcs.service.StModelService; |
|
16 |
import org.apache.commons.lang3.StringUtils; |
|
17 |
import org.springframework.stereotype.Service; |
|
18 |
import org.springframework.util.CollectionUtils; |
|
19 |
import org.springframework.web.multipart.MultipartFile; |
|
20 |
|
|
21 |
import java.io.File; |
|
22 |
import java.io.IOException; |
|
23 |
import java.util.*; |
|
24 |
import java.util.stream.Collectors; |
|
25 |
|
|
26 |
/** |
|
27 |
* @author lirm 1343021927@qq.com |
|
28 |
* @since 1.0.0 2023-05-10 |
|
29 |
*/ |
|
30 |
@Service |
|
31 |
public class StModelServiceImpl extends BaseServiceImpl<StModelDao, StModelEntity> implements StModelService { |
|
32 |
|
|
33 |
private final String PATH_ZIP = "/zip/"; |
|
34 |
|
|
35 |
@Override |
|
36 |
public PageData<StModelDTO> page(Map<String, Object> params) { |
|
37 |
IPage<StModelEntity> page = baseDao.selectPage( |
|
38 |
getPage(params, "create_date", false), |
|
39 |
getWrapper(params) |
|
40 |
); |
|
41 |
|
|
42 |
return getPageData(page, StModelDTO.class); |
|
43 |
} |
|
44 |
|
|
45 |
private QueryWrapper<StModelEntity> getWrapper(Map<String, Object> params) { |
|
46 |
String modelCode = (String) params.get("modelCode"); |
|
47 |
String modelName = (String) params.get("modelName"); |
|
48 |
String modelType = (String) params.get("modelType"); |
|
49 |
String isEnable = (String) params.get("isEnable"); |
|
50 |
|
|
51 |
QueryWrapper<StModelEntity> wrapper = new QueryWrapper<>(); |
|
52 |
wrapper.like(StringUtils.isNotBlank(modelName), "model_name", modelName) |
|
53 |
.like(StringUtils.isNotBlank(modelCode), "model_code", modelCode) |
|
54 |
.eq(StringUtils.isNotBlank(modelType), "model_type", modelType) |
|
55 |
.eq(StringUtils.isNotBlank(isEnable), "is_enable", isEnable); |
|
56 |
return wrapper; |
|
57 |
} |
|
58 |
|
|
59 |
@Override |
|
60 |
public void save(StModelDTO dto) { |
|
61 |
StModelEntity entity = ConvertUtils.sourceToTarget(dto, StModelEntity.class); |
|
62 |
insert(entity); |
|
63 |
} |
|
64 |
|
|
65 |
@Override |
|
66 |
public void update(StModelDTO dto) { |
|
67 |
StModelEntity entity = ConvertUtils.sourceToTarget(dto, StModelEntity.class); |
|
68 |
updateById(entity); |
|
69 |
} |
|
70 |
|
|
71 |
@Override |
|
72 |
public StModelDTO get(String id) { |
|
73 |
StModelEntity entity = baseDao.selectById(id); |
|
74 |
|
|
75 |
return ConvertUtils.sourceToTarget(entity, StModelDTO.class); |
|
76 |
} |
|
77 |
|
|
78 |
@Override |
|
79 |
public List<StModelDTO> getListAll(Map<String, Object> params) { |
|
80 |
String modelLoop = (String)params.get("modelLoop"); |
|
81 |
|
|
82 |
QueryWrapper<StModelEntity> wrapper = new QueryWrapper<>(); |
|
83 |
wrapper.eq("is_enable", IsEnableEnum.ENABLE.value()) |
|
84 |
.eq(StringUtils.isNotBlank(modelLoop), "model_loop", modelLoop) |
|
85 |
.orderByAsc("run_sort"); |
|
86 |
|
|
87 |
List<StModelEntity> list = baseDao.selectList(wrapper); |
|
88 |
return ConvertUtils.sourceToTarget(list, StModelDTO.class); |
|
89 |
} |
|
90 |
|
|
91 |
|
|
92 |
@Override |
|
93 |
public StModelDTO getByCode(String code) { |
|
94 |
QueryWrapper<StModelEntity> wrapper = new QueryWrapper<>(); |
|
95 |
wrapper.eq("model_code", code); |
|
96 |
wrapper.eq("is_enable",1); |
|
97 |
StModelEntity entity = baseDao.selectOne(wrapper); |
|
98 |
return ConvertUtils.sourceToTarget(entity, StModelDTO.class); |
|
99 |
} |
|
100 |
|
|
101 |
@Override |
|
102 |
public void deleteByIds(String[] ids) { |
|
103 |
baseDao.deleteBatchIds(Arrays.asList(ids)); |
|
104 |
} |
|
105 |
|
|
106 |
@Override |
|
107 |
public void enableByIds(String[] ids) { |
|
108 |
if (CollectionUtils.isEmpty(Arrays.asList(ids))) { |
|
109 |
return; |
|
110 |
} |
|
111 |
Arrays.asList(ids).forEach(item -> { |
|
112 |
StModelEntity entity = new StModelEntity(); |
|
113 |
entity.setId(item); |
|
114 |
entity.setIsEnable(IsEnableEnum.ENABLE.value()); |
|
115 |
baseDao.updateById(entity); |
|
116 |
}); |
|
117 |
} |
|
118 |
|
|
119 |
@Override |
|
120 |
public void disableByIds(String[] ids) { |
|
121 |
if (CollectionUtils.isEmpty(Arrays.asList(ids))) { |
|
122 |
return; |
|
123 |
} |
|
124 |
Arrays.asList(ids).forEach(item -> { |
|
125 |
StModelEntity entity = new StModelEntity(); |
|
126 |
entity.setId(item); |
|
127 |
entity.setIsEnable(IsEnableEnum.DISABLE.value()); |
|
128 |
baseDao.updateById(entity); |
|
129 |
}); |
|
130 |
} |
|
131 |
|
|
132 |
@Override |
|
133 |
public void updateTime(String id, Date runTime) { |
|
134 |
StModelEntity entity = new StModelEntity(); |
|
135 |
entity.setId(id); |
|
136 |
entity.setRunTime(runTime); |
|
137 |
baseDao.updateById(entity); |
|
138 |
} |
|
139 |
|
|
140 |
@Override |
|
141 |
public Map<String, Object> upload(MultipartFile file) throws IOException { |
|
142 |
Map<String, Object> result = new HashMap<>(); |
|
143 |
String modelPath = ""; |
|
144 |
String modelStart = ""; |
|
145 |
String uploadDir = modelPath + PATH_ZIP + file.getOriginalFilename(); |
|
146 |
File uploadFile = new File(uploadDir); |
|
147 |
if (!uploadFile.exists()) { |
|
148 |
uploadFile.mkdirs(); |
|
149 |
} |
|
150 |
file.transferTo(new File(uploadDir)); |
|
151 |
|
|
152 |
// 解压 |
|
153 |
UnzipUtils.unzipFile(uploadDir, modelPath + "/"); |
|
154 |
result.put("path", modelPath + "/" + file.getOriginalFilename().substring(0, file.getOriginalFilename().indexOf(".")) + "/" + modelStart); |
|
155 |
return result; |
|
156 |
} |
|
157 |
|
|
158 |
@Override |
|
159 |
public Map<String, Object> getRelation() { |
|
160 |
Map<String, Object> result = new HashMap<>(); |
|
161 |
List<RelationNodeDTO> nodes = new ArrayList<>(); |
|
162 |
List<RelationLineDTO> lines = new ArrayList<>(); |
|
163 |
List<StModelDTO> modelList = getListAll(new HashMap<>()); |
|
164 |
if (CollectionUtils.isEmpty(modelList)) { |
|
165 |
return result; |
|
166 |
} |
|
167 |
RelationNodeDTO rootNode = new RelationNodeDTO(); |
|
168 |
rootNode.setId("root"); |
|
169 |
rootNode.setText("模型库"); |
|
170 |
nodes.add(rootNode); |
|
171 |
List<String> parents = modelList.stream().map(t -> t.getModelParent()).distinct().collect(Collectors.toList()); |
|
172 |
Map<String, List<StModelDTO>> modelGroup = modelList.stream().collect(Collectors.groupingBy(StModelDTO::getModelParent)); |
|
173 |
for (int i = 0; i < parents.size(); i++) { |
|
174 |
RelationNodeDTO pNode = new RelationNodeDTO(); |
|
175 |
pNode.setId("p-" + i); |
|
176 |
pNode.setText(parents.get(i)); |
|
177 |
List<StModelDTO> groupList = modelGroup.get(parents.get(i)); |
|
178 |
for (int j = 0; j < groupList.size(); j++) { |
|
179 |
StModelDTO stModel = groupList.get(j); |
|
180 |
RelationNodeDTO mNode = new RelationNodeDTO(); |
|
181 |
mNode.setId(stModel.getId()); |
|
182 |
mNode.setText(stModel.getModelName()); |
|
183 |
mNode.setData(stModel); |
|
184 |
nodes.add(mNode); |
|
185 |
|
|
186 |
RelationLineDTO mLine = new RelationLineDTO(); |
|
187 |
mLine.setFrom(pNode.getId()); |
|
188 |
mLine.setTo(mNode.getId()); |
|
189 |
lines.add(mLine); |
|
190 |
} |
|
191 |
nodes.add(pNode); |
|
192 |
|
|
193 |
RelationLineDTO pLine = new RelationLineDTO(); |
|
194 |
pLine.setFrom("root"); |
|
195 |
pLine.setTo(pNode.getId()); |
|
196 |
lines.add(pLine); |
|
197 |
} |
|
198 |
result.put("nodes", nodes); |
|
199 |
result.put("lines", lines); |
|
200 |
return result; |
|
201 |
} |
|
202 |
} |