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