| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- import 'dart:io';
- import 'package:get/get_rx/src/rx_types/rx_types.dart';
- import 'package:injectable/injectable.dart';
- import 'package:keyboard/base/app_base_request.dart';
- import '../../di/get_it.dart';
- import '../../utils/async_util.dart';
- import '../../utils/atmob_log.dart';
- import '../../utils/http_handler.dart';
- import '../api/atmob_api.dart';
- import '../api/request/intimacy_analyze_request.dart';
- import '../api/request/intimacy_reply_analyze_request.dart';
- import '../api/response/intimacy_analyze_chat_config_response.dart';
- import '../api/response/intimacy_analyze_config_response.dart';
- import '../api/response/intimacy_analyze_reply_config_response.dart';
- import '../api/response/intimacy_analyze_response.dart';
- /// 亲密度分析Repository层
- @LazySingleton()
- class IntimacyAnalyzeRepository {
- final String tag = "IntimacyAnalyzeRepository";
- final AtmobApi atmobApi;
- /// 亲密度配置
- Rxn<IntimacyAnalyzeConfigResponse> intimacyAnalyzeConfig =
- Rxn<IntimacyAnalyzeConfigResponse>();
- /// 对话分析配置
- Rxn<IntimacyAnalyzeChatConfigResponse> intimacyAnalyzeChatConfig =
- Rxn<IntimacyAnalyzeChatConfigResponse>();
- /// 识图回复配置
- Rxn<IntimacyAnalyzeReplyConfigResponse> intimacyAnalyzeReplyConfig =
- Rxn<IntimacyAnalyzeReplyConfigResponse>();
- IntimacyAnalyzeRepository(this.atmobApi) {
- AtmobLog.d(tag, '$tag...init');
- // 初始化时,刷新配置
- _refreshIntimacyAnalyzeConfig();
- _refreshIntimacyAnalyzeChatConfig();
- _refreshIntimacyAnalyzeReplyConfig();
- }
- /// 从Getx的依赖注入中,获取实例,适合在没有依赖注入上下文的地方使用
- IntimacyAnalyzeRepository getInstance() {
- return getIt.get<IntimacyAnalyzeRepository>();
- }
- /// 刷新亲密度配置
- void _refreshIntimacyAnalyzeConfig() {
- AsyncUtil.retry(
- () => requestIntimacyAnalyzeConfig(),
- Duration(seconds: 3),
- maxRetry: 100,
- ).then((IntimacyAnalyzeConfigResponse configResponse) {
- AtmobLog.d(tag, "获取亲密度配置成功: ${configResponse.toJson()}");
- intimacyAnalyzeConfig.value = configResponse;
- });
- }
- /// 刷新对话分析配置
- void _refreshIntimacyAnalyzeChatConfig() {
- AsyncUtil.retry(
- () => requestIntimacyAnalyzeChatConfig(),
- Duration(seconds: 3),
- maxRetry: 100,
- ).then((IntimacyAnalyzeChatConfigResponse configResponse) {
- AtmobLog.d(tag, "获取对话分析配置成功: ${configResponse.toJson()}");
- intimacyAnalyzeChatConfig.value = configResponse;
- });
- }
- /// 刷新识图回复配置
- void _refreshIntimacyAnalyzeReplyConfig() {
- AsyncUtil.retry(
- () => requestIntimacyAnalyzeReplyConfig(),
- Duration(seconds: 3),
- maxRetry: 100,
- ).then((IntimacyAnalyzeReplyConfigResponse configResponse) {
- AtmobLog.d(tag, "获取识图回复配置成功: ${configResponse.toJson()}");
- intimacyAnalyzeReplyConfig.value = configResponse;
- });
- }
- /// 获取亲密度配置
- Future<IntimacyAnalyzeConfigResponse> requestIntimacyAnalyzeConfig() {
- return atmobApi
- .getIntimacyAnalyzeConfig(AppBaseRequest())
- .then(HttpHandler.handle(true));
- }
- /// 获取对话分析配置
- Future<IntimacyAnalyzeChatConfigResponse> requestIntimacyAnalyzeChatConfig() {
- return atmobApi
- .getIntimacyAnalyzeChatConfig(AppBaseRequest())
- .then(HttpHandler.handle(true));
- }
- /// 获取识图回复配置
- Future<IntimacyAnalyzeReplyConfigResponse>
- requestIntimacyAnalyzeReplyConfig() {
- return atmobApi
- .getIntimacyAnalyzeReplyConfig(AppBaseRequest())
- .then(HttpHandler.handle(true));
- }
- /// 分析亲密度
- Future<IntimacyAnalyzeResponse> getIntimacyAnalyze(
- IntimacyAnalyzeRequest request,
- ) {
- return atmobApi.getIntimacyAnalyze(request).then(HttpHandler.handle(true));
- }
- // /// 识图回复
- // Future<Object> intimacyReplyAnalyze(
- // IntimacyReplyAnalyzeRequest request,
- // ) {
- // return atmobApi
- // .intimacyReplyAnalyze(request)
- // .then(HttpHandler.handle(true));
- // }
- }
|