iailab-module-model/iailab-module-model-biz/db/mysql.sql
@@ -40,18 +40,6 @@ INDEX idx_itemid (itemid) ) engine = innodb default character set utf8mb4 COMMENT = '预测项输出表'; create table t_mm_item_result ( id varchar(36) not null, outputid varchar(36), datatime datetime, datavalue decimal(19, 3), primary key (id), UNIQUE KEY `unique_outputid_datatime` (`outputid`,`datatime`), KEY `idx_outputid_datatime` (`outputid`,`datatime`) USING BTREE ) engine = innodb default character set utf8mb4 COMMENT = '预测结果表'; create table t_mm_item_type ( id varchar(36) not null, @@ -164,18 +152,6 @@ INDEX idx_outputid (outputid), INDEX idx_predicttime (predicttime) ) engine = innodb default character set utf8mb4 COMMENT = '预测JSON数据表'; create table t_mm_item_result_last_point ( id varchar(36) not null, outputid varchar(36), datatime datetime, datavalue decimal(19, 3), primary key (id), INDEX idx_outputid (outputid), INDEX idx_datatime (datatime) ) engine = innodb default character set utf8mb4 COMMENT = '预测T+L数据表'; create table t_mm_item_accuracy_rate ( iailab-module-model/iailab-module-model-biz/pom.xml
@@ -151,6 +151,13 @@ <version>${velocity.version}</version> </dependency> <!-- influxdb --> <dependency> <groupId>com.influxdb</groupId> <artifactId>influxdb-client-java</artifactId> <version>6.8.0</version> </dependency> </dependencies> iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/common/enums/DataTypeEnum.java
@@ -16,6 +16,8 @@ FLOAT("float"), FLOAT_LAST("float_last"), BOOLEAN("boolean"); private String code; iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/influxdb/common/config/InfluxDBInstance.java
对比新文件 @@ -0,0 +1,71 @@ package com.iailab.module.model.influxdb.common.config; import com.iailab.framework.tenant.core.context.TenantContextHolder; import com.influxdb.client.InfluxDBClient; import com.influxdb.client.InfluxDBClientFactory; import com.influxdb.client.domain.Bucket; import com.influxdb.client.domain.Organization; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import java.util.HashSet; import java.util.Set; /** * @author PanZhibao * @Description * @createTime 2023年04月25日 17:13:00 */ @Component public class InfluxDBInstance { @Value("${influx-db.org}") public String org; /*@Value("${influx-db.bucket}") public String bucket;*/ @Value("${influx-db.token}") public String token; @Value("${influx-db.url}") public String url; private Set<String> isExistBucket = new HashSet<>(); private final static String BUCKET_NAME = "bucket_model_"; private Logger logger = LoggerFactory.getLogger(getClass()); private InfluxDBClient client; public InfluxDBClient getClient() { try { if (client == null) { client = InfluxDBClientFactory.create(url, token.toCharArray()); } } catch (Exception ex) { ex.printStackTrace(); logger.error("创建InfluxDBClient失败!"); } return client; } public String getBucket() { String bucketName = BUCKET_NAME + TenantContextHolder.getRequiredTenantId(); // 判断Bucket是否存在,不存在则创建 if (!isExistBucket.contains(bucketName)) { Bucket bucketByName = client.getBucketsApi().findBucketByName(bucketName); if (null == bucketByName) { Organization organization = client.getOrganizationsApi().findOrganizations().stream().filter(e -> e.getName().equals(org)).findFirst().orElseThrow(() -> new RuntimeException("influxdb:org不存在,org:" + org)); client.getBucketsApi().createBucket(bucketName,organization); }else { isExistBucket.add(bucketName); } } return bucketName; } } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/influxdb/common/enums/DataMeasurement.java
对比新文件 @@ -0,0 +1,16 @@ package com.iailab.module.model.influxdb.common.enums; /** * 数据表 * * @author PanZhibao * @Description * @createTime 2023年04月24日 15:13:00 */ public enum DataMeasurement { t_md_sim_value, t_md_last_sim_value, t_md_dig_value, t_md_bool_value, t_md_str_value, } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/influxdb/common/utils/MeasurementUtils.java
对比新文件 @@ -0,0 +1,26 @@ package com.iailab.module.model.influxdb.common.utils; import com.iailab.module.model.common.enums.DataTypeEnum; import com.iailab.module.model.influxdb.common.enums.DataMeasurement; /** * @author PanZhibao * @Description * @createTime 2023年05月08日 10:25:00 */ public class MeasurementUtils { public static String getMeasurement(String type) { if (DataTypeEnum.FLOAT.getCode().equals(type)) { return DataMeasurement.t_md_sim_value.name(); } else if (DataTypeEnum.INT.getCode().equals(type)) { return DataMeasurement.t_md_dig_value.name(); } else if (DataTypeEnum.BOOLEAN.getCode().equals(type)) { return DataMeasurement.t_md_bool_value.name(); } else if (DataTypeEnum.FLOAT_LAST.getCode().equals(type)) { return DataMeasurement.t_md_last_sim_value.name(); } else { return DataMeasurement.t_md_str_value.name(); } } } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/influxdb/pojo/InfluxModelResultLastSimPOJO.java
对比新文件 @@ -0,0 +1,18 @@ package com.iailab.module.model.influxdb.pojo; import com.influxdb.annotations.Column; import com.influxdb.annotations.Measurement; import lombok.Data; /** * @description: * @author: dzd * @date: 2025/1/7 13:43 **/ @Data @Measurement(name = "t_md_last_sim_value") public class InfluxModelResultLastSimPOJO extends InfluxModelResultPOJO { @Column private Double value; } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/influxdb/pojo/InfluxModelResultPOJO.java
对比新文件 @@ -0,0 +1,25 @@ package com.iailab.module.model.influxdb.pojo; import com.influxdb.annotations.Column; import lombok.Data; import java.io.Serializable; import java.time.Instant; /** * @description: * @author: dzd * @date: 2025/1/7 13:43 **/ @Data public class InfluxModelResultPOJO implements Serializable { private static final long serialVersionUID = 1L; @Column(tag = true) private String outPutId; @Column(timestamp = true) private Instant timestamp; private String type; } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/influxdb/pojo/InfluxModelResultSimPOJO.java
对比新文件 @@ -0,0 +1,18 @@ package com.iailab.module.model.influxdb.pojo; import com.influxdb.annotations.Column; import com.influxdb.annotations.Measurement; import lombok.Data; /** * @description: * @author: dzd * @date: 2025/1/7 13:43 **/ @Data @Measurement(name = "t_md_sim_value") public class InfluxModelResultSimPOJO extends InfluxModelResultPOJO { @Column private Double value; } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/influxdb/service/InfluxDBService.java
对比新文件 @@ -0,0 +1,17 @@ package com.iailab.module.model.influxdb.service; import com.iailab.module.model.influxdb.pojo.InfluxModelResultPOJO; import com.iailab.module.model.influxdb.vo.InfluxModelResultVO; import java.util.Date; import java.util.List; /** * InfluxDB操作类 */ public interface InfluxDBService { void asyncWriteModelResults(List<InfluxModelResultPOJO> pointValues); List<InfluxModelResultVO> queryModelResults(InfluxModelResultPOJO pojo, Date startTime, Date endTime); } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/influxdb/service/impl/InfluxDBServiceImpl.java
对比新文件 @@ -0,0 +1,81 @@ package com.iailab.module.model.influxdb.service.impl; import com.iailab.module.model.influxdb.common.config.InfluxDBInstance; import com.iailab.module.model.influxdb.common.utils.MeasurementUtils; 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.influxdb.client.QueryApi; import com.influxdb.client.WriteApi; import com.influxdb.client.domain.WritePrecision; import com.influxdb.query.FluxRecord; import com.influxdb.query.FluxTable; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import javax.annotation.PostConstruct; import javax.annotation.Resource; import java.util.*; /** * InfluxDB操作类 */ @Slf4j @Service public class InfluxDBServiceImpl implements InfluxDBService { @Resource private InfluxDBInstance influxDBInstance; private WriteApi writeApi; private QueryApi queryApi; @PostConstruct private void init() { writeApi = influxDBInstance.getClient().makeWriteApi(); queryApi = influxDBInstance.getClient().getQueryApi(); } @Override public void asyncWriteModelResults(List<InfluxModelResultPOJO> pointValues) { if (!CollectionUtils.isEmpty(pointValues)) { pointValues.forEach(item -> { String bucket = influxDBInstance.getBucket(); writeApi.writeMeasurement(bucket, influxDBInstance.org, WritePrecision.MS, item); }); } writeApi.flush(); } @Override public List<InfluxModelResultVO> queryModelResults(InfluxModelResultPOJO pojo, Date startTime, Date endTime) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.MILLISECOND, 0); String start = startTime.getTime() - calendar.getTime().getTime() + "ms"; if (endTime==null){ endTime= new Date(); } String stop = endTime.getTime() - calendar.getTime().getTime() + "ms"; List<InfluxModelResultVO> dataList = new ArrayList<>(); String measurement = MeasurementUtils.getMeasurement(pojo.getType()); StringBuilder sb = new StringBuilder(); sb.append("from(bucket:\"" + influxDBInstance.getBucket() + "\") "); sb.append("|> range(start: ").append(start).append(", stop: ").append(stop).append(") "); sb.append("|> filter(fn: (r) => r[\"_measurement\"] == \"" + measurement + "\")"); sb.append("|> filter(fn: (r) => r[\"_field\"] == \"value\")"); sb.append("|> filter(fn: (r) => r[\"outPutId\"] == \"" + pojo.getOutPutId() + "\")"); sb.append("|> sort(columns: [\"_time\"]) "); sb.append("|> yield(name: \"mean\")"); log.info("influxdbSql===============" + sb); List<FluxTable> tables = queryApi.query(sb.toString(), influxDBInstance.org); for (FluxTable table : tables) { List<FluxRecord> records = table.getRecords(); for (FluxRecord record : records) { InfluxModelResultVO vo = new InfluxModelResultVO(record.getValueByKey("_value"),record.getTime()); dataList.add(vo); } } return dataList; } } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/influxdb/vo/InfluxModelResultVO.java
对比新文件 @@ -0,0 +1,24 @@ package com.iailab.module.model.influxdb.vo; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import java.io.Serializable; import java.time.Instant; /** * @description: * @author: dzd * @date: 2025/1/7 9:41 **/ @Data @NoArgsConstructor @AllArgsConstructor public class InfluxModelResultVO implements Serializable { private static final long serialVersionUID = 1L; private Object value; private Instant timestamp; } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/dao/MmItemResultDao.java
文件已删除 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/dao/MmItemResultLastPointDao.java
文件已删除 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/dto/MmPredictItemDTO.java
@@ -31,8 +31,6 @@ private List<MmModelParamEntity> mmModelParamList; private List<MmItemResultEntity> mmItemResultList; /** * 计算预测项真实数据点 */ iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/entity/MmItemResultEntity.java
文件已删除 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/entity/MmItemResultLastPointEntity.java
文件已删除 iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/MmItemResultLastPointService.java
@@ -1,8 +1,5 @@ package com.iailab.module.model.mcs.pre.service; import com.iailab.framework.common.service.BaseService; import com.iailab.module.model.mcs.pre.entity.MmItemResultLastPointEntity; import java.util.Date; import java.util.List; @@ -11,7 +8,7 @@ * @Description * @createTime 2024年11月14日 */ public interface MmItemResultLastPointService extends BaseService<MmItemResultLastPointEntity> { public interface MmItemResultLastPointService { List<Object[]> getData(String outputid, Date startTime, Date endTime, String timeFormat); } iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemResultLastPointServiceImpl.java
@@ -1,14 +1,15 @@ 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; @@ -19,24 +20,21 @@ * @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, 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(), timeFormat); 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; iailab-module-model/iailab-module-model-biz/src/main/java/com/iailab/module/model/mcs/pre/service/impl/MmItemResultServiceImpl.java
@@ -1,18 +1,20 @@ package com.iailab.module.model.mcs.pre.service.impl; import com.alibaba.fastjson.JSONArray; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.iailab.framework.common.util.date.DateUtils; import com.iailab.module.model.mcs.pre.dao.MmItemResultDao; import com.iailab.module.model.common.enums.DataTypeEnum; import com.iailab.module.model.influxdb.pojo.InfluxModelResultLastSimPOJO; import com.iailab.module.model.influxdb.pojo.InfluxModelResultPOJO; import com.iailab.module.model.influxdb.pojo.InfluxModelResultSimPOJO; import com.iailab.module.model.influxdb.service.InfluxDBService; import com.iailab.module.model.influxdb.vo.InfluxModelResultVO; import com.iailab.module.model.mcs.pre.entity.MmItemOutputEntity; import com.iailab.module.model.mcs.pre.entity.MmItemResultEntity; import com.iailab.module.model.mcs.pre.entity.MmItemResultJsonEntity; import com.iailab.module.model.mcs.pre.service.MmItemResultJsonService; import com.iailab.module.model.mcs.pre.service.MmItemResultService; import com.iailab.module.model.mdk.vo.DataValueVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import java.math.BigDecimal; import java.util.*; @@ -23,28 +25,27 @@ * @date 2021年05月28日 10:34 */ @Service public class MmItemResultServiceImpl extends ServiceImpl<MmItemResultDao, MmItemResultEntity> implements MmItemResultService { private final int max_group_count = 100; private final String T_MM_ITEM_RESULT = "T_MM_ITEM_RESULT"; public class MmItemResultServiceImpl implements MmItemResultService { @Autowired private MmItemResultDao mmItemResultDao; private MmItemResultJsonService mmItemResultJsonService; @Autowired private InfluxDBService influxDBService; @Override public void savePredictValue(Map<String, List<DataValueVO>> predictValueMap, int t, String nIndex, Date predictTime) { List<MmItemResultEntity> importList = new ArrayList<>(); List<MmItemResultEntity> lastList = new ArrayList<>(); List<InfluxModelResultPOJO> importList = new ArrayList<>(); List<InfluxModelResultPOJO> lastList = new ArrayList<>(); List<MmItemResultJsonEntity> resultJsonList = new ArrayList<>(); for (Map.Entry<String, List<DataValueVO>> entry : predictValueMap.entrySet()) { for (DataValueVO dataVo : entry.getValue()) { MmItemResultEntity importData = new MmItemResultEntity(); importData.setId(String.valueOf(UUID.randomUUID())); importData.setOutputid(entry.getKey()); importData.setDatatime(dataVo.getDataTime()); importData.setDatavalue(new BigDecimal(dataVo.getDataValue())); importList.add(importData); InfluxModelResultSimPOJO pojo = new InfluxModelResultSimPOJO(); pojo.setValue(dataVo.getDataValue()); pojo.setTimestamp(dataVo.getDataTime().toInstant()); pojo.setOutPutId(entry.getKey()); pojo.setType(DataTypeEnum.FLOAT.getCode()); importList.add(pojo); } List<DataValueVO> lastVoList = new ArrayList<>(); @@ -62,58 +63,39 @@ } for (DataValueVO dataVo : lastVoList) { MmItemResultEntity importData = new MmItemResultEntity(); importData.setId(String.valueOf(UUID.randomUUID())); importData.setOutputid(entry.getKey()); importData.setDatatime(dataVo.getDataTime()); importData.setDatavalue(new BigDecimal(dataVo.getDataValue())); lastList.add(importData); InfluxModelResultLastSimPOJO pojo = new InfluxModelResultLastSimPOJO(); pojo.setValue(dataVo.getDataValue()); pojo.setTimestamp(dataVo.getDataTime().toInstant()); pojo.setOutPutId(entry.getKey()); pojo.setType(DataTypeEnum.FLOAT.getCode()); lastList.add(pojo); } MmItemResultJsonEntity resultJson = new MmItemResultJsonEntity(); resultJson.setId(UUID.randomUUID().toString()); resultJson.setOutputid(entry.getKey()); resultJson.setPredicttime(predictTime); List<Double> jsonValueList = entry.getValue().stream().map(valueVO -> { return valueVO.getDataValue(); }).collect(Collectors.toList()); List<Double> jsonValueList = entry.getValue().stream().map(valueVO -> valueVO.getDataValue()).collect(Collectors.toList()); resultJson.setJsonvalue(JSONArray.toJSONString(jsonValueList)); Map<String, Object> map4 = new HashMap(2); map4.put("TABLENAME", "T_MM_ITEM_RESULT_JSON"); map4.put("entity", resultJson); mmItemResultDao.savePredictJsonValue(map4); // Map<String, Object> params = new HashMap(4); // params.put("TABLENAME", T_MM_ITEM_RESULT); // params.put("OUTPUTID", entry.getKey()); // params.put("STARTTIME", importList.get(0).getDatatime()); // params.put("ENDTIME", importList.get(importList.size() - 1).getDatatime()); // mmItemResultDao.deletePredictValue(params); resultJsonList.add(resultJson); } // 存在则修改,不存在插入 mmItemResultDao.saveOrUpdateItemResult(importList); Map<String, Object> map3 = new HashMap<>(2); map3.put("TABLENAME", "T_MM_ITEM_RESULT_LAST_POINT"); map3.put("list", lastList); mmItemResultDao.savePredictValue(map3); // json结果存入mysql mmItemResultJsonService.insertBatch(resultJsonList); // double结果存入influxdb influxDBService.asyncWriteModelResults(importList); influxDBService.asyncWriteModelResults(lastList); } @Override public List<DataValueVO> getPredictValue(String outputid, Date startTime, Date endTime) { List<DataValueVO> result = new ArrayList<>(); QueryWrapper<MmItemResultEntity> queryWrapper = new QueryWrapper<MmItemResultEntity>() .eq("outputid", outputid) .between("datatime", startTime, endTime) .orderByAsc("datatime"); List<MmItemResultEntity> list = mmItemResultDao.selectList(queryWrapper); if (CollectionUtils.isEmpty(list)) { return result; } result = list.stream().map(t -> { InfluxModelResultPOJO pojo = new InfluxModelResultPOJO(); pojo.setType(DataTypeEnum.FLOAT.getCode()); pojo.setOutPutId(outputid); List<InfluxModelResultVO> influxModelResultVOS = influxDBService.queryModelResults(pojo, startTime, endTime); List<DataValueVO> result = influxModelResultVOS.stream().map(t -> { DataValueVO dv = new DataValueVO(); dv.setDataTime(t.getDatatime()); dv.setDataValue(t.getDatavalue().doubleValue()); dv.setDataTime(Date.from(t.getTimestamp())); dv.setDataValue(Double.valueOf(t.getValue().toString())); return dv; }).collect(Collectors.toList()); return result; @@ -122,18 +104,14 @@ @Override public List<Object[]> getData(String outputid, Date startTime, Date endTime, String timeFormat) { List<Object[]> result = new ArrayList<>(); QueryWrapper<MmItemResultEntity> queryWrapper = new QueryWrapper<MmItemResultEntity>() .eq("outputid", outputid) .between("datatime", startTime, endTime) .orderByAsc("datatime"); List<MmItemResultEntity> list = mmItemResultDao.selectList(queryWrapper); if (CollectionUtils.isEmpty(list)) { return result; } list.forEach(item -> { InfluxModelResultPOJO pojo = new InfluxModelResultPOJO(); pojo.setType(DataTypeEnum.FLOAT.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(), timeFormat); dataItem[1] = item.getDatavalue().setScale(2, BigDecimal.ROUND_HALF_UP); 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; @@ -141,16 +119,15 @@ @Override public void savePredictValue(Map<MmItemOutputEntity, Double> predictDoubleValues, Date predictTime) { List<InfluxModelResultPOJO> list = new ArrayList<>(); for (Map.Entry<MmItemOutputEntity, Double> entry : predictDoubleValues.entrySet()) { MmItemResultJsonEntity resultJson = new MmItemResultJsonEntity(); resultJson.setId(UUID.randomUUID().toString()); resultJson.setOutputid(entry.getKey().getId()); resultJson.setPredicttime(predictTime); resultJson.setCumulant(String.valueOf(entry.getValue())); Map<String, Object> map4 = new HashMap(2); map4.put("TABLENAME", "T_MM_ITEM_RESULT_JSON"); map4.put("entity", resultJson); mmItemResultDao.savePredictJsonValue(map4); InfluxModelResultSimPOJO pojo = new InfluxModelResultSimPOJO(); pojo.setValue(entry.getValue()); pojo.setTimestamp(predictTime.toInstant()); pojo.setOutPutId(entry.getKey().getId()); pojo.setType(DataTypeEnum.FLOAT.getCode()); list.add(pojo); } influxDBService.asyncWriteModelResults(list); } } iailab-module-model/iailab-module-model-biz/src/main/resources/application-dev.yaml
@@ -52,3 +52,10 @@ bak-file-path: D:\DLUT\mpkBakFile bak-resources: D:\DLUT\mpkResources model-file-path: D:\DLUT\MDK\Model\miail\ influx-db: org: iailab token: NloIinwybvMwKlJ8SGOAqboXH72EhdQEsnnV7kwtstVu6sbt24LNJ0bVICepeAtl2pxpd1Hj8gDLj9m4hnB7Fw== url: http://127.0.0.1:8086 username: dzd password: qwer1234 iailab-module-model/iailab-module-model-biz/src/main/resources/application.yml
@@ -181,7 +181,6 @@ - t_dm_module - t_dm_module_item - t_mm_item_output - t_mm_item_result - t_mm_item_type - t_mm_model_arith_settings - t_mm_model_param @@ -191,7 +190,6 @@ - t_mm_predict_model - t_mm_result_table - t_mm_item_result_json - t_mm_item_result_last_point - t_mm_item_accuracy_rate - t_mm_item_accuracy_his - t_mm_predict_alarm_config iailab-module-model/iailab-module-model-biz/src/main/resources/mapper/mcs/MmItemResultDao.xml
文件已删除 iailab-module-model/iailab-module-model-biz/src/test/java/com/iailab/InfluxDBTest.java
对比新文件 @@ -0,0 +1,67 @@ package com.iailab; import com.iailab.module.model.common.enums.DataTypeEnum; import com.iailab.module.model.influxdb.pojo.InfluxModelResultPOJO; import com.iailab.module.model.influxdb.pojo.InfluxModelResultSimPOJO; import com.iailab.module.model.influxdb.service.InfluxDBService; import com.iailab.module.model.influxdb.vo.InfluxModelResultVO; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; import javax.annotation.Resource; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; /** * @author PanZhibao * @Description * @createTime 2023年12月10日 12:19:00 */ @SpringBootTest public class InfluxDBTest { @Resource private InfluxDBService influxDBService; @Test public void testWrite() { try { List<InfluxModelResultPOJO> pointValues = new ArrayList<>(); InfluxModelResultSimPOJO pojo = new InfluxModelResultSimPOJO(); pojo.setOutPutId("0001"); pojo.setType(DataTypeEnum.FLOAT.getCode()); pojo.setTimestamp(new Date().toInstant()); pojo.setValue(Double.valueOf(0.001)); pointValues.add(pojo); InfluxModelResultSimPOJO pojo1 = new InfluxModelResultSimPOJO(); pojo1.setOutPutId("0002"); pojo1.setType(DataTypeEnum.FLOAT.getCode()); pojo1.setTimestamp(new Date().toInstant()); pojo1.setValue(Double.valueOf(0.002)); pointValues.add(pojo1); influxDBService.asyncWriteModelResults(pointValues); } catch (Exception ex) { ex.printStackTrace(); } } @Test public void testQuery() { InfluxModelResultPOJO pojo = new InfluxModelResultPOJO(); pojo.setType("float"); pojo.setOutPutId("0001"); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.HOUR_OF_DAY, -1); List<InfluxModelResultVO> influxModelResultVOS = influxDBService.queryModelResults(pojo, calendar.getTime(), Calendar.getInstance().getTime()); System.out.println("value=" + influxModelResultVOS); } }