|
|
@ -3,16 +3,16 @@ package com.xydl.cac.service.impl;
|
|
|
|
import com.xydl.cac.entity.NiecPoint;
|
|
|
|
import com.xydl.cac.entity.NiecPoint;
|
|
|
|
import com.xydl.cac.entity.NiecSensor;
|
|
|
|
import com.xydl.cac.entity.NiecSensor;
|
|
|
|
import com.xydl.cac.model.ConditionModel;
|
|
|
|
import com.xydl.cac.model.ConditionModel;
|
|
|
|
|
|
|
|
import com.xydl.cac.model.OnePage;
|
|
|
|
import com.xydl.cac.model.SensorDetail;
|
|
|
|
import com.xydl.cac.model.SensorDetail;
|
|
|
|
import com.xydl.cac.repository.NiecSensorRepository;
|
|
|
|
import com.xydl.cac.repository.NiecSensorRepository;
|
|
|
|
|
|
|
|
import com.xydl.cac.service.DataService;
|
|
|
|
import com.xydl.cac.service.NiecPointService;
|
|
|
|
import com.xydl.cac.service.NiecPointService;
|
|
|
|
import com.xydl.cac.service.NiecSensorService;
|
|
|
|
import com.xydl.cac.service.NiecSensorService;
|
|
|
|
import com.xydl.cac.util.DateUtil;
|
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
@ -30,7 +30,7 @@ public class NiecSensorServiceImpl implements NiecSensorService {
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
NiecPointService pointService;
|
|
|
|
NiecPointService pointService;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
|
DataService dataService;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<NiecSensor> listAll() {
|
|
|
|
public List<NiecSensor> listAll() {
|
|
|
@ -70,7 +70,7 @@ public class NiecSensorServiceImpl implements NiecSensorService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public SensorDetail getDetail(ConditionModel model) throws Exception {
|
|
|
|
public SensorDetail<Map<String, Object>> getDetail(ConditionModel model) throws Exception {
|
|
|
|
Optional<NiecSensor> optional = repository.findById(model.getId());
|
|
|
|
Optional<NiecSensor> optional = repository.findById(model.getId());
|
|
|
|
if (!optional.isPresent()) {
|
|
|
|
if (!optional.isPresent()) {
|
|
|
|
throw new Exception("未找到该装置");
|
|
|
|
throw new Exception("未找到该装置");
|
|
|
@ -93,58 +93,32 @@ public class NiecSensorServiceImpl implements NiecSensorService {
|
|
|
|
throw new Exception("该装置缺少业务点表配置信息");
|
|
|
|
throw new Exception("该装置缺少业务点表配置信息");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SensorDetail result = this.getData(sensor, points, model);
|
|
|
|
SensorDetail<Map<String, Object>> result = this.getData(sensor, points, model);
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public SensorDetail getData(NiecSensor sensor, List<NiecPoint> points, ConditionModel model) {
|
|
|
|
public SensorDetail<Map<String, Object>> getData(NiecSensor sensor, List<NiecPoint> points, ConditionModel model) {
|
|
|
|
SensorDetail result = new SensorDetail();
|
|
|
|
|
|
|
|
result.setSensor(sensor);
|
|
|
|
|
|
|
|
List<NiecPoint> pointList = new ArrayList<>();
|
|
|
|
List<NiecPoint> pointList = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
String sqlFrom = " FROM " + sensor.getTableName();
|
|
|
|
|
|
|
|
String sqlWhere = " WHERE " + sensor.getDevidFieldName() + "=" + sensor.getDevId();
|
|
|
|
|
|
|
|
if (model.getStartTime() != null) {
|
|
|
|
|
|
|
|
sqlWhere = sqlWhere + " AND " + sensor.getDtimeFieldName() + " >= '" + DateUtil.format(model.getStartTime()) + "'";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (model.getEndTime() != null) {
|
|
|
|
|
|
|
|
sqlWhere = sqlWhere + " AND " + sensor.getDtimeFieldName() + " < '" + DateUtil.format(model.getEndTime()) + "'";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String sqlOrder = " ORDER BY " + sensor.getDtimeFieldName() + " DESC";
|
|
|
|
|
|
|
|
String sqlLimit = "";
|
|
|
|
|
|
|
|
if (model.getPageNum() != null && model.getPageSize() != null) {
|
|
|
|
|
|
|
|
result.setPageNum(model.getPageNum());
|
|
|
|
|
|
|
|
result.setPageSize(model.getPageSize());
|
|
|
|
|
|
|
|
sqlLimit = String.format(" LIMIT %d,%d", (model.getPageNum() - 1) * model.getPageSize(), model.getPageSize());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String sqlSelect = "SELECT DATE_FORMAT(" + sensor.getDtimeFieldName() + ", '%Y-%m-%d %H:%i:%s') as acquisitionTime";
|
|
|
|
|
|
|
|
for (NiecPoint point : points) {
|
|
|
|
for (NiecPoint point : points) {
|
|
|
|
if (StringUtils.isNotBlank(point.getField())) {
|
|
|
|
if (StringUtils.isNotBlank(point.getField())) {
|
|
|
|
sqlSelect = sqlSelect + ", " + point.getField();
|
|
|
|
|
|
|
|
pointList.add(point);
|
|
|
|
pointList.add(point);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String sqlCount = "SELECT count(*)" + sqlFrom + sqlWhere;
|
|
|
|
SensorDetail<Map<String, Object>> result = new SensorDetail();
|
|
|
|
String sql = sqlSelect + sqlFrom + sqlWhere + sqlOrder + sqlLimit;
|
|
|
|
result.setSensor(sensor);
|
|
|
|
log.info(sql);
|
|
|
|
OnePage<Map<String, Object>> page = dataService.getDate(sensor, pointList, model);
|
|
|
|
|
|
|
|
result.initFrom(page);
|
|
|
|
Long count = jdbcTemplate.queryForObject(sqlCount, Long.class);
|
|
|
|
|
|
|
|
List<Map<String, Object>> content = jdbcTemplate.queryForList(sql);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (NiecPoint point : pointList) {
|
|
|
|
for (NiecPoint point : pointList) {
|
|
|
|
List<Object> dataList = new ArrayList<>();
|
|
|
|
List<Object> dataList = new ArrayList<>();
|
|
|
|
for (Map<String, Object> item : content) {
|
|
|
|
for (Map<String, Object> item : result.getContent()) {
|
|
|
|
Object value = item.get(point.getField());
|
|
|
|
Object value = item.get(point.getField());
|
|
|
|
dataList.add(value);
|
|
|
|
dataList.add(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
point.setData(dataList);
|
|
|
|
point.setData(dataList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
result.setTotal(count);
|
|
|
|
|
|
|
|
result.setPoints(pointList);
|
|
|
|
result.setPoints(pointList);
|
|
|
|
result.setContent(content);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|