package com.iailab.module.data.point.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.iailab.framework.common.service.impl.BaseServiceImpl;
|
import com.iailab.module.data.common.enums.DataQualityEnum;
|
import com.iailab.module.data.influxdb.pojo.InfluxPointValueDigPOJO;
|
import com.iailab.module.data.influxdb.pojo.InfluxPointValuePOJO;
|
import com.iailab.module.data.influxdb.pojo.InfluxPointValueSimPOJO;
|
import com.iailab.module.data.point.dao.DaPointCollectStatusDao;
|
import com.iailab.module.data.point.entity.DaPointCollectStatusEntity;
|
import com.iailab.module.data.point.service.DaPointCollectStatusService;
|
import org.springframework.stereotype.Service;
|
import org.springframework.util.CollectionUtils;
|
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.UUID;
|
|
/**
|
* @author PanZhibao
|
* @Description
|
* @createTime 2024年12月13日
|
*/
|
@Service
|
public class DaPointCollectStatusServiceImpl extends BaseServiceImpl<DaPointCollectStatusDao, DaPointCollectStatusEntity>
|
implements DaPointCollectStatusService {
|
|
public void recordStatus(String pointNo, String collectValue, Date collectTime) {
|
QueryWrapper<DaPointCollectStatusEntity> queryWrapper = new QueryWrapper<>();
|
queryWrapper.eq("point_no", pointNo);
|
DaPointCollectStatusEntity entity = baseDao.selectOne(queryWrapper);
|
if (entity == null) {
|
entity = new DaPointCollectStatusEntity();
|
entity.setId(UUID.randomUUID().toString());
|
entity.setPointNo(pointNo);
|
entity.setCollectValue(collectValue);
|
entity.setCollectQuality(DataQualityEnum.getEumByValue(collectValue).getCode());
|
entity.setCollectTime(collectTime);
|
baseDao.insert(entity);
|
} else {
|
entity.setCollectValue(collectValue);
|
entity.setCollectQuality(DataQualityEnum.getEumByValue(collectValue).getCode());
|
entity.setCollectTime(collectTime);
|
baseDao.updateById(entity);
|
}
|
|
}
|
|
public void recordStatusList(List<InfluxPointValuePOJO> pointValues, Date collectTime) {
|
List<String> listGood = new ArrayList<>();
|
List<String> listBad = new ArrayList<>();
|
Object collectValue = null;
|
for (InfluxPointValuePOJO pointValue : pointValues) {
|
if (pointValue instanceof InfluxPointValueSimPOJO) {
|
InfluxPointValueSimPOJO pvo = (InfluxPointValueSimPOJO) pointValue;
|
collectValue = pvo.getValue();
|
} else if (pointValue instanceof InfluxPointValueDigPOJO) {
|
InfluxPointValueDigPOJO pvo = (InfluxPointValueDigPOJO) pointValue;
|
collectValue = pvo.getValue();
|
} else {
|
continue;
|
}
|
switch (DataQualityEnum.getEumByValue(collectValue)) {
|
case GOOD:
|
listGood.add(pointValue.getPoint());
|
break;
|
case BAD:
|
listBad.add(pointValue.getPoint());
|
break;
|
default:
|
break;
|
}
|
}
|
if (!CollectionUtils.isEmpty(listGood)) {
|
QueryWrapper<DaPointCollectStatusEntity> queryWrapper = new QueryWrapper<>();
|
queryWrapper.in("point_no", listGood);
|
DaPointCollectStatusEntity entity = new DaPointCollectStatusEntity();
|
entity.setCollectTime(collectTime);
|
entity.setCollectQuality(DataQualityEnum.GOOD.getCode());
|
baseDao.update(entity, queryWrapper);
|
}
|
if (!CollectionUtils.isEmpty(listBad)) {
|
QueryWrapper<DaPointCollectStatusEntity> queryWrapper = new QueryWrapper<>();
|
queryWrapper.in("point_no", listBad);
|
DaPointCollectStatusEntity entity = new DaPointCollectStatusEntity();
|
entity.setCollectTime(collectTime);
|
entity.setCollectQuality(DataQualityEnum.BAD.getCode());
|
baseDao.update(entity, queryWrapper);
|
}
|
}
|
}
|