| | |
| | | package com.iailab.module.model.mcs.pre.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.iailab.framework.common.service.impl.BaseServiceImpl; |
| | | import com.iailab.framework.common.util.date.DateUtils; |
| | | import com.iailab.module.model.mcs.pre.dao.MmItemResultLastPointDao; |
| | | import com.iailab.module.model.mcs.pre.entity.MmItemResultLastPointEntity; |
| | | import com.iailab.module.model.common.enums.DataTypeEnum; |
| | | import com.iailab.module.model.influxdb.pojo.InfluxModelResultPOJO; |
| | | import com.iailab.module.model.influxdb.service.InfluxDBService; |
| | | import com.iailab.module.model.influxdb.vo.InfluxModelResultVO; |
| | | import com.iailab.module.model.mcs.pre.service.MmItemResultLastPointService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | |
| | | * @createTime 2024年11月14日 |
| | | */ |
| | | @Service |
| | | public class MmItemResultLastPointServiceImpl extends BaseServiceImpl<MmItemResultLastPointDao, MmItemResultLastPointEntity> |
| | | implements MmItemResultLastPointService { |
| | | public class MmItemResultLastPointServiceImpl implements MmItemResultLastPointService { |
| | | @Autowired |
| | | private InfluxDBService influxDBService; |
| | | |
| | | @Override |
| | | public List<Object[]> getData(String outputid, Date startTime, Date endTime) { |
| | | public List<Object[]> getData(String outputid, Date startTime, Date endTime, String timeFormat) { |
| | | List<Object[]> result = new ArrayList<>(); |
| | | QueryWrapper<MmItemResultLastPointEntity> queryWrapper = new QueryWrapper<MmItemResultLastPointEntity>() |
| | | .eq("outputid", outputid) |
| | | .between("datatime", startTime, endTime) |
| | | .orderByAsc("datatime"); |
| | | List<MmItemResultLastPointEntity> list = baseDao.selectList(queryWrapper); |
| | | if (CollectionUtils.isEmpty(list)) { |
| | | return result; |
| | | } |
| | | list.forEach(item -> { |
| | | InfluxModelResultPOJO pojo = new InfluxModelResultPOJO(); |
| | | pojo.setType(DataTypeEnum.FLOAT_LAST.getCode()); |
| | | pojo.setOutPutId(outputid); |
| | | List<InfluxModelResultVO> influxModelResultVOS = influxDBService.queryModelResults(pojo, startTime, endTime); |
| | | influxModelResultVOS.forEach(item -> { |
| | | Object[] dataItem = new Object[2]; |
| | | dataItem[0] = DateUtils.format(item.getDatatime(), DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND); |
| | | dataItem[1] = item.getDatavalue(); |
| | | dataItem[0] = DateUtils.format(Date.from(item.getTimestamp()), timeFormat); |
| | | dataItem[1] = BigDecimal.valueOf(Double.valueOf(item.getValue().toString())).setScale(2, BigDecimal.ROUND_HALF_UP); |
| | | result.add(dataItem); |
| | | }); |
| | | return result; |