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