From eddcc9de41ea6e11533e417db9135f545f87162c Mon Sep 17 00:00:00 2001 From: tanlongsheng <252620078@qq.com> Date: Wed, 16 Jul 2025 17:02:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=83=AD=E5=8A=9B=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/meeting_mine_controller.dart | 68 +++++++++++++++++-- .../bottomSheet/statistics_bottom_sheet.dart | 20 +++++- .../meeting/views/meeting_mine_view.dart | 37 +++++++--- 3 files changed, 108 insertions(+), 17 deletions(-) diff --git a/lib/modules/meeting/controllers/meeting_mine_controller.dart b/lib/modules/meeting/controllers/meeting_mine_controller.dart index 907ae480e..b219cc602 100644 --- a/lib/modules/meeting/controllers/meeting_mine_controller.dart +++ b/lib/modules/meeting/controllers/meeting_mine_controller.dart @@ -1,9 +1,13 @@ +import 'package:common_utils/common_utils.dart'; import 'package:get/get.dart'; -import 'meeting_home_controller.dart'; +import '../../../data/services/db/sqflite_api.dart'; +import '../../profile/controllers/profile_controller.dart'; class MeetingMineController extends GetxController { - final _controller = Get.find(); + final profileCtrl = Get.find(); + + Map statistics = {}; RxInt days = 0.obs; RxInt numberFiles = 0.obs; @@ -12,15 +16,69 @@ class MeetingMineController extends GetxController { RxInt maxNumberFiles = 0.obs; RxDouble maxHourage = 0.0.obs; + int averageNumberFiles = 0; + @override void onInit() { super.onInit(); _getStatistics(); } - void _getStatistics() { - numberFiles.value = _controller.originalDataList.length; + void _getStatistics() async { + List dataList = await SqfliteApi.getMeetingList(); + numberFiles.value = dataList.length; + statistics = {}; + + for (var element in dataList) { + DateTime creationtime = + DateTime.fromMillisecondsSinceEpoch(element['creationtime']); + int dayOfYear = DateUtil.getDayOfYear(creationtime); + + if (!statistics.containsKey(dayOfYear)) { + statistics[dayOfYear] = { + 'creationtime': creationtime, + 'count': 0, + 'seconds': 0, + }; + } + statistics[dayOfYear]['count']++; + statistics[dayOfYear]['seconds'] += element['seconds']; + } + + int currentD = 1; + int maxD = 1; + int previous = 0; + int h = 0; + int maxH = 0; + int maxN = 0; + int minN = 0; + statistics.forEach((key, value) { + h += value['seconds'] as int; + if (key + 1 == previous) { + currentD++; + if (currentD > maxD) { + maxD = currentD; + } + } else { + currentD = 1; + } + previous = key; + if (value['count'] > maxN) { + maxN = value['count']; + } + if (value['count'] < minN || minN == 0) { + minN = value['count']; + } + if (value['seconds'] > maxH) { + maxH = value['seconds']; + } + }); - for (var element in _controller.originalDataList) {} + days.value = statistics.length; + hourage.value = double.parse((h / 60 / 60).toStringAsFixed(2)); + continuousDays.value = maxD; + maxNumberFiles.value = maxN; + maxHourage.value = double.parse((maxH / 60 / 60).toStringAsFixed(2)); + averageNumberFiles = (maxN + minN) ~/ 2; } } diff --git a/lib/modules/meeting/views/bottomSheet/statistics_bottom_sheet.dart b/lib/modules/meeting/views/bottomSheet/statistics_bottom_sheet.dart index 667bf370a..2eb8d1f38 100644 --- a/lib/modules/meeting/views/bottomSheet/statistics_bottom_sheet.dart +++ b/lib/modules/meeting/views/bottomSheet/statistics_bottom_sheet.dart @@ -171,8 +171,26 @@ class _StatisticsBottomSheetState extends State { ), itemCount: 364, itemBuilder: (BuildContext context, int index) { + final col = index % 52; + final row = index ~/ 52; + final vIndex = row + col * 7; + + int type = 0; + if (_mineController.statistics + .containsKey(vIndex + 1)) { + if (_mineController.statistics[vIndex + 1]['count'] <= + _mineController.averageNumberFiles) { + type = 1; + } else { + type = 2; + } + } return Container( - color: Colors.grey[200], + color: type == 0 + ? Colors.grey[200] + : type == 1 + ? Colors.red[100] + : Colors.red, ); }, ), diff --git a/lib/modules/meeting/views/meeting_mine_view.dart b/lib/modules/meeting/views/meeting_mine_view.dart index ae0337965..a2cef03c5 100644 --- a/lib/modules/meeting/views/meeting_mine_view.dart +++ b/lib/modules/meeting/views/meeting_mine_view.dart @@ -3,7 +3,6 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'dart:io'; import '../../../routes/app_routes.dart'; -import '../../profile/controllers/profile_controller.dart'; import '../controllers/meeting_mine_controller.dart'; import 'bottomSheet/statistics_bottom_sheet.dart'; @@ -96,8 +95,6 @@ class MeetingMineView extends GetView { } Widget _head() { - final ProfileController profileCtrl = - Get.find(); // 从GetX中获取ProfileController实例 return Padding( padding: EdgeInsets.symmetric(vertical: 20.w), child: GestureDetector( @@ -114,14 +111,19 @@ class MeetingMineView extends GetView { ), child: CircleAvatar( radius: 25.w, - backgroundImage: profileCtrl.localAvatar.value.isNotEmpty - ? FileImage(File(profileCtrl.localAvatar.value)) - : (profileCtrl.userInfo.value.avatar.isNotEmpty - ? NetworkImage(profileCtrl.userInfo.value.avatar) + backgroundImage: controller + .profileCtrl.localAvatar.value.isNotEmpty + ? FileImage( + File(controller.profileCtrl.localAvatar.value)) + : (controller + .profileCtrl.userInfo.value.avatar.isNotEmpty + ? NetworkImage( + controller.profileCtrl.userInfo.value.avatar) : null) as ImageProvider?, backgroundColor: Colors.grey[200], - child: (profileCtrl.localAvatar.value.isEmpty && - profileCtrl.userInfo.value.avatar.isEmpty) + child: (controller.profileCtrl.localAvatar.value.isEmpty && + controller + .profileCtrl.userInfo.value.avatar.isEmpty) ? Icon( Icons.person, size: 25.r, @@ -133,7 +135,7 @@ class MeetingMineView extends GetView { Expanded( child: Obx( () => Text( - profileCtrl.userInfo.value.name, + controller.profileCtrl.userInfo.value.name, style: TextStyle( color: Colors.black87, fontSize: 20.sp, @@ -203,9 +205,22 @@ class MeetingMineView extends GetView { ), itemCount: 364, itemBuilder: (BuildContext context, int index) { + int type = 0; + if (controller.statistics.containsKey(index + 1)) { + if (controller.statistics[index + 1]['count'] <= + controller.averageNumberFiles) { + type = 1; + } else { + type = 2; + } + } return Container( decoration: BoxDecoration( - color: Colors.grey[200], + color: type == 0 + ? Colors.grey[200] + : type == 1 + ? Colors.red[100] + : Colors.red, borderRadius: BorderRadius.circular(2.w), ), );