您的位置:首页 > 新闻 > 热点要闻 > 郑州seo询搜点网络效果佳_优秀个人网站案例_网站推广平台_磁力搜索

郑州seo询搜点网络效果佳_优秀个人网站案例_网站推广平台_磁力搜索

2024/12/26 23:22:24 来源:https://blog.csdn.net/qq_44637477/article/details/143950013  浏览:    关键词:郑州seo询搜点网络效果佳_优秀个人网站案例_网站推广平台_磁力搜索
郑州seo询搜点网络效果佳_优秀个人网站案例_网站推广平台_磁力搜索

1)首先要确保正确安装CouchDB软件(Windows系统)

2)pom.xml

<!-- couchdb --><dependency><groupId>org.ektorp</groupId><artifactId>org.ektorp</artifactId><version>1.5.0</version></dependency>

3)application.yml

# CouchDB非关系型数据库,与MongoDB类似
couchdb:host: http://127.0.0.1port: 5984username: adminpassword: wz123456database: test

4)配置文件CouchDBConfig.class

@Component
@Data
public class CouchDBConfig {@Value(value = "${couchdb.host}")private String host;@Value(value = "${couchdb.port}")private String port;@Value(value = "${couchdb.database}")private String database;@Value(value = "${couchdb.username}")private String username;@Value(value = "${couchdb.password}")private String password;@Bean(name = "CouchDbConnector")public CouchDbConnector couchDbConnector() throws Exception {HttpClient httpClient = new StdHttpClient.Builder().url(host + ":"+ port).username(username).connectionTimeout(10000).socketTimeout(1000000).password(password).build();CouchDbInstance couchDbInstance = new StdCouchDbInstance(httpClient);CouchDbConnector couchDbConnector = new StdCouchDbConnector(database, couchDbInstance);couchDbConnector.createDatabaseIfNotExists();System.out.println("注入成功");return couchDbConnector;}// 根据传入的数据库名称创建新的 CouchDbConnector 实例public CouchDbConnector getConnectorForDatabase(String databaseName) throws Exception {HttpClient httpClient = new StdHttpClient.Builder().url(host + ":" + port).username(username).connectionTimeout(10000).socketTimeout(1000000).password(password).build();CouchDbInstance couchDbInstance = new StdCouchDbInstance(httpClient);CouchDbConnector couchDbConnector = new StdCouchDbConnector(databaseName, couchDbInstance);couchDbConnector.createDatabaseIfNotExists(); // 确保目标数据库存在return couchDbConnector;}
}

5)定时启动服务,RandomlyGeneratEntityCongfig.GenerateEntity(12000);为数据随机生成,可自定义初始化

@Component
public class CouchDBDataReader {private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");@Autowiredprivate CouchDBConfig couchDBConfig;@Autowiredprivate CouchDbConnector couchDbConnector;/*** 定时任务启动,每隔5s,统一在AllAutoReader类中启动*/
//    @Scheduled(fixedRate = 10000)public void readCouchDBData(){String currentTime = LocalDateTime.now().format(formatter);System.out.println(currentTime+"readCouchDB操作开始");//        insertDevPointFiveToCouchDBData();
//        getLimitedDocuments();
//        countAllDocuments();insertDevToCouchDB(1000);insertDevToCouchDB(3000);insertDevToCouchDB(5000);
//        insertDevToCouchDB(10000);String currentTime2 = LocalDateTime.now().format(formatter);System.out.println(currentTime2+", CouchDB操作完成");}
/*** 获取CouchDB数据库指定test数据库中的所有文档*/public long countAllDocuments(){// 方式一:获取所有文档的 ID 列表
//        List<String> allDocIds = couchDbConnector.getAllDocIds();
//        System.out.println("CouchDB中总文档数量:" + allDocIds.size());// 方式二:获取数据库信息// 定义 CouchDB 数据库 URLString database= "test";String dbUrl = "http://localhost:5984/"+database;// 设置认证信息String username = "admin";String password = "wz123456";CustomDbInfo customDbInfo = getDBInfo(dbUrl,username,password);
//        System.out.println("CouchDB中当前数据库:"+customDbInfo.getDbName()+" ,总文档数量: "+ customDbInfo.getDocCount());return customDbInfo.getDocCount();}
/*** 将随机生成的数据插入到CouchDB中* 数量自定义设置*/
public void insertDevPointFiveToCouchDBData(){try{List<DevPointFiveSeDayShard> devPointFiveList = RandomlyGeneratEntityCongfig.GenerateEntity(12000);
//            System.out.println("生成数据量大小"+devPointFiveList.size());
//            System.out.println("生成数据"+devPointFiveList);List<DevPointForCouchDB> devPointForCouchDBList = devPointFiveList.stream().map(DevPointForCouchDB::new).collect(Collectors.toList());
//            System.out.println("转换后数据量"+devPointForCouchDBList);long startTime = System.currentTimeMillis();// 选择源数据库 直接选择默认配置的数据库testcouchDbConnector.executeBulk(devPointForCouchDBList);
//            // 选择目标数据库 指定数据库名targetDbName
//            // 根据传入的数据库名称获取相应的 CouchDbConnector
//            String targetDbName = "devpoint";
//            CouchDbConnector targetDbConnector = couchDBConfig.getConnectorForDatabase(targetDbName);
//            targetDbConnector.executeBulk(devPointForCouchDBList);long endTime = System.currentTimeMillis();System.out.println(LocalDateTime.now().format(formatter)+"存储CouchDB数据耗时:" + (endTime - startTime) + "ms"+"存储量:"+devPointForCouchDBList.size());long documentSize = countAllDocuments();System.out.println("CouchDB中总文档数量:" + documentSize);// 准备要写入的日志内容String logMessage = String.format("%s 存储CouchDB耗时: %d 毫秒, 数据量: %d , 数据总量达到:%d",LocalDateTime.now().format(formatter),(endTime - startTime), devPointFiveList.size(),documentSize);// 写入文件try (BufferedWriter writer = new BufferedWriter(new FileWriter("logs/insertCouchDBDB30000_log.txt", true))) {writer.write(logMessage);writer.newLine(); // 换行} catch (IOException e) {e.printStackTrace(); // 处理异常}}catch (Exception e){e.printStackTrace();}}
}

6)实体类DevPointFiveSeDayShard和DevPointForCouchDB

@Data
@Document()
@AllArgsConstructor
@NoArgsConstructor
public class DevPointFiveSeDayShard {/*** 设备id*/@Indexedprivate String productId;/*** 变量id*/@Indexedprivate String variableId;/*** 计算后的变量值,为Double.NaN此值为异常值*/private Double calcValue = Double.NaN;/*** 异常类型(0--正常 1--值异常 2--采集异常(取不到数据) 3--通讯异常 5--换表 6--清零)*/private int errType = 0;/*** 整条数据上报时间* yyyy-MM-dd HH:mm:ss*/@Indexedprivate Long reportDateTime;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DevPointForCouchDB {@JsonProperty("_id")private String id;  // CouchDB 文档 ID@JsonProperty("_rev")private String rev;  // CouchDB 文档版本private DevPointFiveSeDayShard data;  // 原始数据// 构造函数,生成唯一 ID,并封装数据public DevPointForCouchDB(DevPointFiveSeDayShard data) {this.id = UUID.randomUUID().toString();  // 自动生成唯一 IDthis.data = data;}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com