提交 | 用户 | 时间
|
a6de49
|
1 |
package com.iailab.module.data.point.service.impl; |
H |
2 |
|
|
3 |
import com.alibaba.fastjson.JSONArray; |
|
4 |
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
6bf63b
|
5 |
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
L |
6 |
import com.iailab.framework.common.pojo.PageResult; |
|
7 |
import com.iailab.framework.common.util.object.ConvertUtils; |
a6de49
|
8 |
import com.iailab.module.data.common.enums.CommonConstant; |
H |
9 |
import com.iailab.module.data.common.enums.IsEnableEnum; |
|
10 |
import com.iailab.module.data.point.common.IncreaseCodeEnum; |
|
11 |
import com.iailab.module.data.point.common.PointTypeEnum; |
6bf63b
|
12 |
import com.iailab.module.data.point.dao.DaPointDao; |
a6de49
|
13 |
import com.iailab.module.data.point.dto.DaMeasurePointDTO; |
H |
14 |
import com.iailab.module.data.point.dto.DaPointDTO; |
|
15 |
import com.iailab.module.data.point.entity.DaPointEntity; |
|
16 |
import com.iailab.module.data.point.service.DaMathPointService; |
6bf63b
|
17 |
import com.iailab.module.data.point.service.DaMeasurePointService; |
a6de49
|
18 |
import com.iailab.module.data.point.service.DaPointService; |
H |
19 |
import com.iailab.module.data.point.service.DaSequenceNumService; |
6bf63b
|
20 |
import com.iailab.module.data.point.vo.DaPointPageReqVO; |
a6de49
|
21 |
import org.apache.commons.lang3.StringUtils; |
H |
22 |
import org.springframework.stereotype.Service; |
|
23 |
import org.springframework.transaction.annotation.Transactional; |
|
24 |
import org.springframework.util.CollectionUtils; |
|
25 |
|
6bf63b
|
26 |
import javax.annotation.Resource; |
a6de49
|
27 |
import java.util.*; |
H |
28 |
|
|
29 |
/** |
6bf63b
|
30 |
* @author lirm |
a6de49
|
31 |
* @Description |
6bf63b
|
32 |
* @createTime 2024年09月2日 |
a6de49
|
33 |
*/ |
H |
34 |
@Service |
6bf63b
|
35 |
public class DaPointServiceImpl extends ServiceImpl<DaPointDao, DaPointEntity> implements DaPointService { |
a6de49
|
36 |
|
H |
37 |
@Resource |
|
38 |
private DaMeasurePointService daMeasurePointService; |
|
39 |
|
|
40 |
@Resource |
|
41 |
private DaMathPointService daMathPointService; |
|
42 |
|
|
43 |
@Resource |
|
44 |
private DaSequenceNumService daSequenceNumService; |
6bf63b
|
45 |
|
L |
46 |
@Resource |
|
47 |
private DaPointDao daPointDao; |
|
48 |
|
a6de49
|
49 |
|
H |
50 |
@Override |
6bf63b
|
51 |
public PageResult<DaPointEntity> queryPage(DaPointPageReqVO reqVO) { |
L |
52 |
return daPointDao.selectPage(reqVO); |
a6de49
|
53 |
} |
H |
54 |
|
|
55 |
@Override |
6bf63b
|
56 |
public DaPointDTO info(String id) { |
L |
57 |
DaPointEntity entity = daPointDao.selectById(id); |
a6de49
|
58 |
DaPointDTO result = ConvertUtils.sourceToTarget(entity, DaPointDTO.class); |
H |
59 |
if (PointTypeEnum.MEASURE_POINT.getCode().equals(result.getPointType())) { |
|
60 |
DaMeasurePointDTO measurePoint = daMeasurePointService.getByPoint(id); |
|
61 |
result.setMeasurePoint(measurePoint); |
|
62 |
List<String> sourceOption = new ArrayList<>(); |
|
63 |
sourceOption.add(measurePoint.getSourceType()); |
|
64 |
sourceOption.add(measurePoint.getSourceId()); |
|
65 |
sourceOption.add(measurePoint.getTagNo()); |
|
66 |
result.setSourceOption(sourceOption); |
|
67 |
} else if (PointTypeEnum.CALCULATE_POINT.getCode().equals(result.getPointType())) { |
|
68 |
result.setMathPoint(daMathPointService.getByPoint(id)); |
|
69 |
} |
|
70 |
return result; |
|
71 |
} |
|
72 |
|
|
73 |
@Override |
|
74 |
public List<DaPointDTO> list(Map<String, Object> params) { |
|
75 |
String page = (String) params.get("page"); |
|
76 |
String limit = (String) params.get("limit"); |
|
77 |
String pointType = (String)params.get("pointType"); |
|
78 |
List<String> pointNos = new ArrayList<>(); |
|
79 |
if (params.get("pointNos") != null) { |
|
80 |
pointNos = JSONArray.parseArray(JSONArray.toJSONString(params.get("pointNos")), String.class); |
|
81 |
} |
|
82 |
String pointNoLike = (String)params.get("pointNoLike"); |
|
83 |
QueryWrapper<DaPointEntity> queryWrapper = new QueryWrapper(); |
|
84 |
queryWrapper.eq(StringUtils.isNotBlank(pointType), "point_type", pointType) |
|
85 |
.in(!CollectionUtils.isEmpty(pointNos),"point_no", pointNos) |
|
86 |
.like(StringUtils.isNotBlank(pointNoLike), "point_no", pointNoLike) |
|
87 |
.last("limit 1, 10"); |
6bf63b
|
88 |
List<DaPointEntity> list = daPointDao.selectList(queryWrapper); |
a6de49
|
89 |
return ConvertUtils.sourceToTarget(list, DaPointDTO.class); |
H |
90 |
} |
|
91 |
|
|
92 |
@Override |
|
93 |
@Transactional(rollbackFor = Exception.class) |
|
94 |
public void add(DaPointDTO dataPoint) { |
|
95 |
DaPointEntity daPointEntity = ConvertUtils.sourceToTarget(dataPoint, DaPointEntity.class); |
|
96 |
daPointEntity.setId(UUID.randomUUID().toString()); |
|
97 |
if (PointTypeEnum.MEASURE_POINT.getName().equals(dataPoint.getPointType())) { |
|
98 |
DaMeasurePointDTO measurePoint = new DaMeasurePointDTO(); |
|
99 |
measurePoint.setSourceType(dataPoint.getSourceOption().get(0)); |
|
100 |
measurePoint.setSourceId(dataPoint.getSourceOption().get(1)); |
|
101 |
measurePoint.setTagNo(dataPoint.getSourceOption().get(2)); |
|
102 |
daMeasurePointService.add(measurePoint, daPointEntity.getId()); |
|
103 |
daPointEntity.setPointNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.POINT_M.name())); |
|
104 |
} else if (PointTypeEnum.CALCULATE_POINT.getName().equals(dataPoint.getPointType())) { |
|
105 |
daMathPointService.add(dataPoint.getMathPoint(), daPointEntity.getId()); |
|
106 |
daPointEntity.setPointNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.POINT_C.name())); |
|
107 |
} else if (PointTypeEnum.CONSTANT.getName().equals(dataPoint.getPointType())) { |
|
108 |
daPointEntity.setPointNo(daSequenceNumService.getAndIncreaseByCode(IncreaseCodeEnum.POINT_F.name())); |
|
109 |
} |
|
110 |
daPointEntity.setIsEnable(CommonConstant.IS_ENABLE); |
|
111 |
daPointEntity.setCreateTime(new Date()); |
6bf63b
|
112 |
daPointDao.insert(daPointEntity); |
a6de49
|
113 |
} |
H |
114 |
|
|
115 |
@Override |
|
116 |
@Transactional(rollbackFor = Exception.class) |
|
117 |
public void update(DaPointDTO dataPoint) { |
|
118 |
DaPointEntity daPointEntity = ConvertUtils.sourceToTarget(dataPoint, DaPointEntity.class); |
|
119 |
daPointEntity.setUpdateTime(new Date()); |
6bf63b
|
120 |
daPointDao.updateById(daPointEntity); |
a6de49
|
121 |
if (PointTypeEnum.MEASURE_POINT.getName().equals(dataPoint.getPointType())) { |
H |
122 |
DaMeasurePointDTO measurePoint = dataPoint.getMeasurePoint(); |
|
123 |
measurePoint.setSourceType(dataPoint.getSourceOption().get(0)); |
|
124 |
measurePoint.setSourceId(dataPoint.getSourceOption().get(1)); |
|
125 |
measurePoint.setTagNo(dataPoint.getSourceOption().get(2)); |
|
126 |
daMeasurePointService.update(measurePoint); |
|
127 |
} else if (PointTypeEnum.CALCULATE_POINT.equals(dataPoint.getPointType())) { |
|
128 |
daMathPointService.update(dataPoint.getMathPoint()); |
|
129 |
} |
|
130 |
} |
|
131 |
|
|
132 |
@Override |
|
133 |
@Transactional(rollbackFor = Exception.class) |
|
134 |
public void delete(String[] ids) { |
6bf63b
|
135 |
daPointDao.deleteBatchIds(Arrays.asList(ids)); |
a6de49
|
136 |
daMeasurePointService.deleteByPoint(ids); |
H |
137 |
daMathPointService.deleteByPoint(ids); |
|
138 |
} |
|
139 |
|
|
140 |
@Override |
|
141 |
public List<DaPointDTO> getConstantPoint(String freq) { |
|
142 |
Map<String, Object> params = new HashMap<>(); |
|
143 |
params.put("pointType", PointTypeEnum.CONSTANT.getCode()); |
|
144 |
params.put("isEnable", CommonConstant.IS_ENABLE); |
|
145 |
params.put("minfreqid", freq); |
6bf63b
|
146 |
return daPointDao.getConstantPoint(params); |
a6de49
|
147 |
} |
H |
148 |
|
|
149 |
@Override |
|
150 |
public List<DaPointDTO> getConstantPoint(List<String> pointNos) { |
|
151 |
Map<String, Object> params = new HashMap<>(); |
|
152 |
params.put("pointType", PointTypeEnum.CONSTANT.getCode()); |
|
153 |
params.put("isEnable", CommonConstant.IS_ENABLE); |
|
154 |
params.put("pointNos", pointNos); |
6bf63b
|
155 |
return daPointDao.getConstantPoint(params); |
a6de49
|
156 |
} |
H |
157 |
|
|
158 |
@Override |
|
159 |
public List<DaPointDTO> getMeasurePoint(String freq) { |
|
160 |
Map<String, Object> params = new HashMap<>(); |
|
161 |
params.put("pointType", PointTypeEnum.MEASURE_POINT.getCode()); |
|
162 |
params.put("isEnable", CommonConstant.IS_ENABLE); |
|
163 |
params.put("minfreqid", freq); |
6bf63b
|
164 |
return daPointDao.getMeasurePoint(params); |
a6de49
|
165 |
} |
H |
166 |
|
|
167 |
@Override |
|
168 |
public List<DaPointDTO> getMeasurePoint(List<String> pointNos) { |
|
169 |
Map<String, Object> params = new HashMap<>(); |
|
170 |
params.put("pointType", PointTypeEnum.MEASURE_POINT.getCode()); |
|
171 |
params.put("isEnable", CommonConstant.IS_ENABLE); |
|
172 |
params.put("pointNos", pointNos); |
6bf63b
|
173 |
return daPointDao.getMeasurePoint(params); |
a6de49
|
174 |
} |
H |
175 |
|
|
176 |
@Override |
|
177 |
public DaPointDTO getMeasurePointByNo(String pointNo) { |
|
178 |
Map<String, Object> params = new HashMap<>(); |
|
179 |
params.put("pointType", PointTypeEnum.MEASURE_POINT.getCode()); |
|
180 |
params.put("pointNo", pointNo); |
6bf63b
|
181 |
List<DaPointDTO> list = daPointDao.getMeasurePoint(params); |
a6de49
|
182 |
if (CollectionUtils.isEmpty(list)) { |
H |
183 |
return null; |
|
184 |
} |
|
185 |
return list.get(0); |
|
186 |
} |
|
187 |
|
|
188 |
@Override |
|
189 |
public List<DaPointDTO> getMathPoint(String freq) { |
|
190 |
Map<String, Object> params = new HashMap<>(); |
|
191 |
params.put("pointType", PointTypeEnum.CALCULATE_POINT.getCode()); |
|
192 |
params.put("isEnable", CommonConstant.IS_ENABLE); |
|
193 |
params.put("minfreqid", freq); |
6bf63b
|
194 |
return daPointDao.getMathPoint(params); |
a6de49
|
195 |
} |
H |
196 |
|
|
197 |
@Override |
|
198 |
public List<DaPointDTO> getMathPoint(List<String> pointNos) { |
|
199 |
Map<String, Object> params = new HashMap<>(); |
|
200 |
params.put("pointType", PointTypeEnum.CALCULATE_POINT.getCode()); |
|
201 |
params.put("isEnable", CommonConstant.IS_ENABLE); |
|
202 |
params.put("pointNos", pointNos); |
6bf63b
|
203 |
return daPointDao.getMathPoint(params); |
a6de49
|
204 |
} |
H |
205 |
|
|
206 |
@Override |
|
207 |
public DaPointDTO getByNo(String pointNo) { |
|
208 |
QueryWrapper<DaPointEntity> wrapper = new QueryWrapper<>(); |
|
209 |
wrapper.eq("point_no", pointNo); |
6bf63b
|
210 |
DaPointEntity entity = daPointDao.selectOne(wrapper); |
a6de49
|
211 |
return ConvertUtils.sourceToTarget(entity, DaPointDTO.class); |
H |
212 |
} |
|
213 |
|
|
214 |
@Override |
|
215 |
public List<DaPointDTO> getByNos(List<String> pointNos) { |
|
216 |
QueryWrapper<DaPointEntity> wrapper = new QueryWrapper<>(); |
|
217 |
wrapper.in("point_no", pointNos); |
6bf63b
|
218 |
List<DaPointEntity> list = daPointDao.selectList(wrapper); |
a6de49
|
219 |
return ConvertUtils.sourceToTarget(list, DaPointDTO.class); |
H |
220 |
} |
|
221 |
|
|
222 |
@Override |
|
223 |
public void updateDefaultValue(DaPointDTO dto) { |
|
224 |
QueryWrapper<DaPointEntity> wrapper = new QueryWrapper<>(); |
|
225 |
wrapper.eq("point_no", dto.getPointNo()); |
|
226 |
DaPointEntity entity = new DaPointEntity(); |
|
227 |
entity.setDefaultValue(dto.getDefaultValue()); |
6bf63b
|
228 |
daPointDao.update(entity, wrapper); |
a6de49
|
229 |
} |
H |
230 |
|
|
231 |
@Override |
|
232 |
public void enableByIds(String[] ids) { |
|
233 |
if (CollectionUtils.isEmpty(Arrays.asList(ids))) { |
|
234 |
return; |
|
235 |
} |
|
236 |
Arrays.asList(ids).forEach(item -> { |
|
237 |
DaPointEntity entity = new DaPointEntity(); |
|
238 |
entity.setId(item); |
|
239 |
entity.setIsEnable(IsEnableEnum.ENABLE.value()); |
6bf63b
|
240 |
daPointDao.updateById(entity); |
a6de49
|
241 |
}); |
H |
242 |
} |
|
243 |
|
|
244 |
@Override |
|
245 |
public void disableByIds(String[] ids) { |
|
246 |
if (CollectionUtils.isEmpty(Arrays.asList(ids))) { |
|
247 |
return; |
|
248 |
} |
|
249 |
Arrays.asList(ids).forEach(item -> { |
|
250 |
DaPointEntity entity = new DaPointEntity(); |
|
251 |
entity.setId(item); |
|
252 |
entity.setIsEnable(IsEnableEnum.DISABLE.value()); |
6bf63b
|
253 |
daPointDao.updateById(entity); |
a6de49
|
254 |
}); |
H |
255 |
} |
|
256 |
} |