| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- import 'package:application/service/api.dart';
- import 'package:application/service/map_watch.dart';
- import 'package:application/logger.dart';
- import 'package:get/get.dart';
- import '../home_controller.dart';
- export 'package:application/service/map_watch.dart';
- class ActiveInfo{
- var id = 0;
- var name = '';
- var cpAllCount = 0;
- var userList = <UserInfo>[];
- UserInfo? getUserById(int id){
- for (final one in userList){
- if(one.data.userId==id){
- return one;
- }
- }
- return null;
- }
- }
- class UserInfo{
- var data = ToOrienteerInGameInfo();
- }
- extension ActiveInfoExt on ToActionInfo{
- ActiveInfo into(){
- return ActiveInfo()
- ..id = actId
- ..name = actName
- ..cpAllCount=totalControlNum
- ..userList = userList.map((e) => e.into()).toList()
- ;
- }
- }
- extension UserInfoExt on ToOrienteerInGameInfo{
- UserInfo into(){
- return UserInfo()
- ..data = this
- ;
- }
- }
- class FieldControlController extends GetxController{
- HomeController get _home => Get.find();
- MapWatchService? get mapWatch => MapWatchService.instance;
- final activeList = <ActiveInfo>[].obs;
- @override
- void onInit() {
- super.onInit();
- workFlushData();
- }
- Future<void> workFlushData()async{
- await flushDataFirstTime();
- while(!isClosed){
- try{
- await flushData();
- }catch(e){
- error(e);
- }
- await 1.seconds.delay();
- }
- }
- Future<void> flushDataFirstTime()async{
- final r = await ApiService.to.stub.toUserDetailQueryV2(
- ToUserDetailQueryRequestV2(
- mapId: mapWatch?.id.toInt(),
- isFullQuery: true,
- ));
- activeList.value = r.list.map((e) => e.into()).toList();
- }
- ActiveInfo? getActiveById(int id){
- for (final one in activeList){
- if(one.id==id){
- return one;
- }
- }
- return null;
- }
- Future<void> flushData()async{
- final r = await ApiService.to.stub.toUserDetailQueryV2(ToUserDetailQueryRequestV2(
- mapId: mapWatch?.id.toInt()));
- final newList = <ActiveInfo>[];
- for(final one in r.list){
- final act = one.into();
- final old = getActiveById(act.id);
- if(old != null){
- act.name=old.name;
- act.cpAllCount=old.cpAllCount;
- for(final user in act.userList){
- final oUser = old.getUserById(user.data.userId);
- if(oUser != null){
- user.data = ToOrienteerInGameInfo(
- userId: user.data.userId,
- baseInfo: oUser.data.baseInfo,
- gpsInfo: user.data.gpsInfo,
- hrInfo: user.data.hrInfo,
- gameSaveInfo: user.data.gameSaveInfo,
- courseBaseInfo: oUser.data.courseBaseInfo,
- otherInfo: user.data.otherInfo,
- );
- }
- }
- }
- newList.add(act);
- }
- activeList.value = newList;
- }
- }
|