|
|
@@ -7,17 +7,28 @@ import 'package:keyboard/base/base_controller.dart';
|
|
|
import 'package:keyboard/resource/string.gen.dart';
|
|
|
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
|
|
|
|
|
|
+import '../../../../data/api/request/intimacy_reply_chat_request.dart';
|
|
|
+import '../../../../data/api/response/intimacy_chat_analyze_response.dart';
|
|
|
import '../../../../data/bean/option_select_config.dart';
|
|
|
import '../../../../data/bean/option_select_item.dart';
|
|
|
import '../../../../data/bean/upload_info.dart';
|
|
|
+import '../../../../data/repository/account_repository.dart';
|
|
|
+import '../../../../data/repository/intimacy_analyze_repository.dart';
|
|
|
+import '../../../../utils/atmob_log.dart';
|
|
|
+import '../../../../utils/error_handler.dart';
|
|
|
+import '../../../../utils/http_handler.dart';
|
|
|
import '../../../../utils/image_picker_util.dart';
|
|
|
import '../../../../utils/intimacy_analyze_config_helper.dart';
|
|
|
+import '../../../../utils/toast_util.dart';
|
|
|
import '../../../../utils/upload/upload_file_manager.dart';
|
|
|
import '../../../../utils/upload/upload_scene_type.dart';
|
|
|
+import '../../../store/store_page.dart';
|
|
|
|
|
|
/// 对话分析Controller
|
|
|
@injectable
|
|
|
class ConversationAnalysisController extends BaseController {
|
|
|
+ final String _tag = "ConversationAnalysisController";
|
|
|
+
|
|
|
/// 上传场景
|
|
|
final UploadSceneType uploadSceneType = UploadSceneType.conversationAnalysis;
|
|
|
|
|
|
@@ -27,6 +38,12 @@ class ConversationAnalysisController extends BaseController {
|
|
|
/// 文件上传管理器
|
|
|
UploadFileManager uploadFileManager;
|
|
|
|
|
|
+ /// 亲密度分析模块的Repository
|
|
|
+ IntimacyAnalyzeRepository intimacyAnalyzeRepository;
|
|
|
+
|
|
|
+ /// 用户信息Repository
|
|
|
+ AccountRepository accountRepository;
|
|
|
+
|
|
|
/// 是否是上传页
|
|
|
Rx<bool> isUploadPage = false.obs;
|
|
|
|
|
|
@@ -40,26 +57,11 @@ class ConversationAnalysisController extends BaseController {
|
|
|
RxList<OptionSelectConfig> optionSelectConfigList =
|
|
|
<OptionSelectConfig>[].obs;
|
|
|
|
|
|
- /// 报告数据
|
|
|
- RxString reportData =
|
|
|
- '''
|
|
|
- **性格匹配度**
|
|
|
-
|
|
|
- ● 互补型:一方外向活泼,另一方沉稳内敛,形成动态平衡。
|
|
|
- ● 相似型:三观一致,兴趣重叠,减少摩擦但需警惕新鲜感流失。
|
|
|
- ● 关键结论:差异是火花的来源,但核心价值观需一致(如家庭观、金钱观)。
|
|
|
-
|
|
|
- **沟通模式分析**
|
|
|
+ /// 当前选择的选项
|
|
|
+ Rxn<OptionSelectItem> currentSelectOption = Rxn();
|
|
|
|
|
|
- ● 语言风格:幽默调侃型 vs 理性分析型 → 需找到共同表达方式。
|
|
|
- ● 冲突解决:回避型 vs 直面型 → 建议建立“冷静-沟通”机制。
|
|
|
- ● 情感需求:一方需要高频互动,另一方偏好独立空间 → 需协商平衡点。
|
|
|
-
|
|
|
- **爱情语言测试**
|
|
|
-
|
|
|
- ● 根据盖瑞·查普曼的“五种爱之语”理论,分析双方的情感表达偏好:
|
|
|
- ● 你的主要爱语:肯定的言辞(如情话、鼓励)
|
|
|
- '''.obs;
|
|
|
+ /// 报告数据
|
|
|
+ RxString reportData = ''.obs;
|
|
|
|
|
|
/// 上传图片列表
|
|
|
RxList<UploadInfo> uploadInfoList = <UploadInfo>[].obs;
|
|
|
@@ -67,6 +69,8 @@ class ConversationAnalysisController extends BaseController {
|
|
|
ConversationAnalysisController(
|
|
|
this.intimacyAnalyzeConfigHelper,
|
|
|
this.uploadFileManager,
|
|
|
+ this.intimacyAnalyzeRepository,
|
|
|
+ this.accountRepository,
|
|
|
);
|
|
|
|
|
|
@override
|
|
|
@@ -115,12 +119,17 @@ class ConversationAnalysisController extends BaseController {
|
|
|
|
|
|
/// 选中选项
|
|
|
void selectOption(OptionSelectConfig rowConfig, OptionSelectItem optionItem) {
|
|
|
- // 先全部反选
|
|
|
- rowConfig.options =
|
|
|
- rowConfig.options.map((ele) {
|
|
|
- ele.selected = false;
|
|
|
- return ele;
|
|
|
- }).toList();
|
|
|
+ // 更新当前选中项
|
|
|
+ currentSelectOption.value = optionItem;
|
|
|
+
|
|
|
+ // 将所有预测方向都反选
|
|
|
+ for (var config in optionSelectConfigList) {
|
|
|
+ config.options =
|
|
|
+ config.options.map((ele) {
|
|
|
+ ele.selected = false;
|
|
|
+ return ele;
|
|
|
+ }).toList();
|
|
|
+ }
|
|
|
// 再勾选当前的选中项
|
|
|
optionItem.selected = true;
|
|
|
// 由于Rx响应式变量,无法监听对象中嵌套对象的某个属性的变化,导致页面不会刷新,需要手动刷新页面
|
|
|
@@ -132,8 +141,51 @@ class ConversationAnalysisController extends BaseController {
|
|
|
|
|
|
/// 点击查看分析按钮
|
|
|
void clickLookAnalyseBtn(BuildContext context) async {
|
|
|
- // TODO hezihao,要请求接口,进行分析,出报告,现在先让通过
|
|
|
- hasReport.value = true;
|
|
|
+ // 非Vip,跳转到商店页
|
|
|
+ bool isVip = accountRepository.memberStatusInfo.value?.isMember ?? false;
|
|
|
+ if (!isVip) {
|
|
|
+ ToastUtil.show(StringName.needVipTip);
|
|
|
+ StorePage.start();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 上传的图片后端地址
|
|
|
+ List<String> imageList =
|
|
|
+ uploadInfoList.map((item) {
|
|
|
+ return item.fileBackendPath ?? "";
|
|
|
+ }).toList();
|
|
|
+ // 选择的标题
|
|
|
+ String title = currentSelectOption.value?.name ?? "";
|
|
|
+
|
|
|
+ if (imageList.isEmpty) {
|
|
|
+ ToastUtil.show(StringName.noUploadConversationImageTip);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (title.isEmpty) {
|
|
|
+ ToastUtil.show(StringName.noChooseOptionTip);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ IntimacyChatAnalyzeResponse response = await intimacyAnalyzeRepository
|
|
|
+ .intimacyChatAnalyze(IntimacyChatAnalyzeRequest(imageList, title));
|
|
|
+ String reportContent = response.choices?[0].delta?.content ?? "";
|
|
|
+ reportData.value = reportContent;
|
|
|
+ hasReport.value = true;
|
|
|
+ } catch (error) {
|
|
|
+ AtmobLog.e(_tag, error.toString());
|
|
|
+ if (error is ServerErrorException) {
|
|
|
+ // 需要Vip权限
|
|
|
+ if (error.code == 1005) {
|
|
|
+ ToastUtil.show(error.message);
|
|
|
+ StorePage.start();
|
|
|
+ } else {
|
|
|
+ ToastUtil.show(error.message);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ErrorHandler.toastError(error);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// 点击上传按钮
|