ApplicationDataManager.java 35.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070
package com.sunvote.txpad;

import android.text.TextUtils;
import android.widget.TextView;

import com.sunvote.sunvotesdk.BaseStationManager;
import com.sunvote.sunvotesdk.basestation.DefaultKeyEventCallBack;
import com.sunvote.sunvotesdk.basestation.KeyBoard;
import com.sunvote.txpad.bean.Paper;
import com.sunvote.txpad.bean.PaperScore;
import com.sunvote.txpad.bean.Question;
import com.sunvote.txpad.bean.QuestionSudentAnswer;
import com.sunvote.txpad.bean.ResponseDataBean;
import com.sunvote.txpad.bean.Student;
import com.sunvote.txpad.bean.StudentQuestionAnswer;
import com.sunvote.txpad.bean.StudentScore;
import com.sunvote.txpad.cache.FileCache;
import com.sunvote.txpad.cache.SpCache;
import com.sunvote.util.LogUtil;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import cn.sunars.sdk.SunARS;

/**
 * Created by Elvis on 2017/9/21.
 * Email:Eluis@psunsky.com
 * 版权所有:长沙中天电子设计开发有限公司
 * Description: 易测(ETest)
 */
public class ApplicationDataManager {

    public static final String TAG = "ApplicationDataManager";
    public static final int MODE_CLASS_STUDENT = 1;
    public static final int MODE_NO_CLASS_STUDENT = 2;
    private static final ApplicationDataManager ourInstance = new ApplicationDataManager();
    protected SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    /**
     * 注册到基站,监听所有信息的处理,对逻辑的处理。
     */
    private DefaultKeyEventCallBack keyEventCallBack = new DefaultKeyEventCallBack() {
        @Override
        public void keyEventKeyResultInfo(final String keyId, final String info, final float time) {
            super.keyEventKeyResultInfo(keyId,info,time);
            if ("1".equals(info)) {
                Student oldStudent = null;
                boolean beSign = isStudentKeyIdSign(keyId);
                if(beSign){
                    oldStudent = findStudentKeyId(keyId);
                }
               Student newStudent = addStudentKeyIdSign(keyId);
                if (oldStudent != null && newStudent != null) {
                    if(!oldStudent.equals(newStudent)){
                        KeyBoard keyBoard = oldStudent.getKeyBoard();
                        if (keyBoard != null) {
                            if (keyId.equals(keyBoard.getKeyId())) {
                                keyBoard.setKeySn(null);
                                keyBoard.setKeyId(null);
                                keyBoard.setSign(false);
                            }
                        }
                    }
//                    cleanStudentKeyIdSign(keyId);
                }
                saveStudentSignInfo();
                LogUtil.i(TAG, "sign " + (newStudent != null ? "success":"fail") + "! keyId:" + keyId + ",info:" + info + ",time:" + time);
            } else {
                answer(keyId, info);
            }

        }

        @Override
        public void keyEventKeyResultStats(String keyId, String info, float time) {
            super.keyEventKeyResultStats(keyId, info, time);
            if (BaseStationManager.getInstance().getBaseStationInfo().getMode() == SunARS.VoteType_KeyPadTest) {
                setKeyboardOnline(keyId, info);
            }
        }

        @Override
        public void keyEventKeyResultLoginInfo(final String keyId, final String info, float time) {
            cleanKeyIdSign(keyId);
            String ret = keyIdSign(info, keyId);
            if (ret == null) {
                BaseStationManager.getInstance().sendKeyboradSignFail(keyId);
                LogUtil.i(TAG,keyId + " 签到失败,"+ info);
            } else if (!ret.equals(keyId)) {
                BaseStationManager.getInstance().sendKeyboradSignFail(keyId);
//                BaseStationManager.getInstance().sendKeyboradSignFail(ret);
                LogUtil.i(TAG,keyId + " 签到失败," + info);
//                LogUtil.i(TAG,ret + " 签到失败,"+ info);
//                cleanKeyIdSign(keyId);
            }else{
                LogUtil.i(TAG,ret + " 签到成功,"+ info);
            }
            saveStudentSignInfo();
        }
    };

    private ApplicationDataManager() {
    }

    public static void sendKeyboradSignSuccess(String keyID){
        BaseStationManager.getInstance().sendKeyboradSignSuccess(keyID);
    }

    public static ApplicationDataManager getInstance() {
        return ourInstance;
    }

    /**
     * 注册基站数据监听,为基站数据处理
     */
    public void registerKeyEventCallBack() {
        BaseStationManager.getInstance().registerKeyEventCallBack(keyEventCallBack);
    }

    /**
     * 取消基站数据监听
     */
    public void unRegisterKeyEventCallBack() {
        BaseStationManager.getInstance().unRegisterKeyEventCallBack(keyEventCallBack);
    }

    /**
     * 获取当前签到模式
     * @return
     */
    public int  getMode(){
        return SpCache.getInstance().getInt(Constants.SAVE_SIGN_MODE_KEY,3);
    }

    /**
     * 答题结果
     * 首先根据key 找到对应的学生。
     * 然后根据info找到问题编号,根据编号找到对应的问题
     * 在学生中对应的问题,填写答案
     * 在问题中,添加该学生的答案
     *
     * @param keyId 键盘ID
     * @param info  键盘答题信息
     */
    private void answer(String keyId, String info) {
        Student student = findStudentByKeyId(keyId);
        Question question = findQuestionByInfo(info);
        String answer = getQuestionAnswerByInfo(info);
        if (student != null && question != null) {
            fillQuestionAnswer(student, question, answer);
            fillStudentAnswer(student, question, answer);
            ApplicationData.getInstance().commit();
            LogUtil.i("Answer", "answer success! , keyId:" + keyId + ",Info: " + info);
        }
    }

    /**
     * 该键盘是否签到
     *
     * @param keyId 键盘信息
     * @return 是否已签到
     */
    private boolean isStudentKeyIdSign(String keyId) {
        List<Student> studentList = ApplicationData.getInstance().getStudentList();
        for (Student student : studentList) {
            KeyBoard keyBoard = student.getKeyBoard();
            if (keyBoard != null) {
                if (keyId.equals(student.getKeypadId())) {
                    return keyBoard.isSign();
                }
            }
        }
        return false;
    }
    /**
     * 该键盘是否签到
     *
     * @param keyId 键盘信息
     * @return 是否已签到
     */
    public Student findStudentKeyId(String keyId) {
        List<Student> studentList = ApplicationData.getInstance().getStudentList();
        for (Student student : studentList) {
            if(keyId.equals(student.getKeypadId())){
                return student;
            }
        }
        return null;
    }

    /**
     * 该键盘是否签到
     *
     * @param keyId 键盘信息
     * @return 是否已签到
     */
    private void cleanStudentKeyIdSign(String keyId) {
        List<Student> studentList = ApplicationData.getInstance().getStudentList();
        for (Student student : studentList) {
            KeyBoard keyBoard = student.getKeyBoard();
            if (keyBoard != null) {
                if (keyId.equals(keyBoard.getKeyId())) {
                    keyBoard.setKeyId(null);
                    keyBoard.setSign(false);
                }
            }
        }
    }

    /**
     * 自动配对键盘签到信息
     *
     * @param keyId
     * @return
     */
    private Student addStudentKeyIdSign(String keyId) {
        List<Student> studentList = ApplicationData.getInstance().getStudentList();
        for (Student student : studentList) {
            KeyBoard keyBoard = student.getKeyBoard();
            if (keyId.equals(student.getKeypadId())) {
                    keyBoard.setKeyId(keyId);
                    keyBoard.setSign(true);
                    student.setSignReady(false);
                    return student;
            }
        }
        return null;
    }

    /**
     * 判断该键盘是否已签到
     *
     * @param keyId 键盘ID
     * @return 是否已签到
     */
    private boolean isStudentKeyIDSign(String keyId) {
        List<Student> studentList = ApplicationData.getInstance().getStudentList();
        for (Student student : studentList) {
            KeyBoard keyBoard = student.getKeyBoard();
            if (keyBoard != null) {
                if (keyId.equals(keyBoard.getKeyId())) {
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * 添加学生签到信息
     *
     * @param keyId TODO
     * @return
     */
    private boolean addStudentSnSign(String keyId) {
        List<Student> studentList = ApplicationData.getInstance().getStudentList();
        for (Student student : studentList) {
            KeyBoard keyBoard = student.getKeyBoard();
            if (keyBoard != null) {
                if (keyBoard.getKeyId() == null) {
                    keyBoard.setKeyId(keyId);
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * 获取已签到学生人数
     *
     * @return 已签到人数
     */
    public int getSignStudent() {
        int count = 0;
        List<Student> studentList = ApplicationData.getInstance().getStudentList();
        if (studentList != null) {
            for (Student student : studentList) {
                KeyBoard keyBoard = student.getKeyBoard();
                if (keyBoard != null) {
                    if (keyBoard.isSign()) {
                        count++;
                    }
                }
            }
        }
        return count;
    }

    /**
     * 获取绑定键盘人数
     * @param mode
     * @return
     */
    public int getBlindKeyboardCount(int mode){
        int count = 0;
        List<Student> studentList = ApplicationData.getInstance().getStudentList();
        if (studentList != null) {
            for (Student student : studentList) {
               switch (mode){
                   case 1:
                       if(!TextUtils.isEmpty(student.getKeyBoard().getKeyId())){
                            count ++;
                        }
                       break;
                   case 2:
                       if(!TextUtils.isEmpty(student.getKeyBoard().getKeySn())){
                           count ++;
                       }
                       break;
                   case 3:
                       if(!TextUtils.isEmpty(student.getKeypadId())){
                           count ++;
                       }
                       break;
               }
            }
        }
        return count;
    }

    /**
     * 获取键盘弱电人数
     *
     * @return 人数
     */
    public int getKeyboarWeak() {
        int count = 0;
        List<Student> studentList = ApplicationData.getInstance().getStudentList();
        if (studentList != null) {
            for (Student student : studentList) {
                KeyBoard keyBoard = student.getKeyBoard();
                if (keyBoard != null) {
                    if (keyBoard.isWeak()) {
                        count++;
                    }
                }
            }
        }
        return count;
    }

    /**
     * 获取键盘签到冲突个数
     *
     * @return 学生人数
     */
    public int getKeyboardConflict() {
        int count = 0;
        List<Student> studentList = ApplicationData.getInstance().getStudentList();
        if (studentList != null) {
            for (Student student : studentList) {
                KeyBoard keyBoard = student.getKeyBoard();
                if (keyBoard != null) {
                    if (keyBoard.isConflict()) {
                        count++;
                    }
                }
            }
        }
        return count;
    }

    /**
     * 清除签到信息
     */
    public void clearSign() {
        List<Student> studentList = ApplicationData.getInstance().getStudentList();
        if (studentList != null) {
            for (Student student : studentList) {
                KeyBoard keyBoard = student.getKeyBoard();
                if (keyBoard != null) {
                    keyBoard.setKeyId(null);
                    keyBoard.setKeySn(null);
                    keyBoard.setSign(false);
                    keyBoard.setConflict(false);
                }
            }
        }
        saveStudentSignInfo();
    }

    /**
     * UID 后台签到
     *
     * @param no    学生学号
     * @param keyId 键盘编号
     * @return 键盘编号,成功返回当前编号,失败返回旧的编号
     */
    public String keyIdSign(String no, String keyId) {
        List<Student> studentList = ApplicationData.getInstance().getStudentList();
        if (studentList != null) {
            for (Student student : studentList) {
                if (student.getStudentUID() != null && student.getStudentUID().equals(no)) {
                    KeyBoard keyBoard = student.getKeyBoard();
                    int mode = SpCache.getInstance().getInt(Constants.SAVE_SIGN_MODE_KEY, 3);
                    if(mode == 1) {
                        if (TextUtils.isEmpty(keyBoard.getKeyId())) {
                            keyBoard.setKeyId(keyId);
                            keyBoard.setSign(true);
                            keyBoard.setConflict(false);
                            return keyId;
                        } else {
//                            keyBoard.setConflict(true);
                            String keyIdOld = keyBoard.getKeyId();
//                            keyBoard.setKeyId(null);
//                            keyBoard.setSign(false);
                            return keyIdOld;
                        }
                    }else if(mode == 2){
                        if (TextUtils.isEmpty(keyBoard.getKeySn())) {
                            keyBoard.setKeySn(keyId);
                            keyBoard.setSign(true);
                            keyBoard.setConflict(false);
                            return keyId;
                        } else {
//                            keyBoard.setConflict(true);
                            String keyIdOld = keyBoard.getKeyId();
//                            keyBoard.setKeySn(null);
//                            keyBoard.setSign(false);
                            return keyIdOld;
                        }
                    }
                }
            }
        }
        return null;
    }

    /**
     * UID 清除签到
     *
     * @param keyId 键盘编号
     * @return 键盘编号,成功返回当前编号,失败返回旧的编号
     */
    public boolean cleanKeyIdSign(String keyId) {
        List<Student> studentList = ApplicationData.getInstance().getStudentList();
        if (studentList != null) {
            for (Student student : studentList) {
                    KeyBoard keyBoard = student.getKeyBoard();
                    if (keyId.equals(keyBoard.getKeyId()) || keyId.equals(keyBoard.getKeySn())) {
                        keyBoard.setKeyId(null);
                        keyBoard.setKeySn(null);
                        keyBoard.setSign(false);
                        keyBoard.setConflict(false);
                        return true;
                    }
            }
        }
        return false;
    }

    /**
     * 指定具体的编号键盘在线
     *
     * @param keyId 键盘编号
     * @param info  键盘信息
     */
    public void setKeyboardOnline(String keyId, String info) {
        List<Student> studentList = ApplicationData.getInstance().getStudentList();
        if (studentList != null) {
            for (Student student : studentList) {
                switch (getMode()){
                    case 1:{
                        if (keyId.equals(student.getKeyBoard().getKeyId())) {
                            student.getKeyBoard().setOnline(true);
                            String[] strs = info.split(",");
                            if (strs.length >= 3) {
                                float dm = Float.parseFloat(strs[2]);
                                if (dm < 2.4f) {
                                    student.getKeyBoard().setWeak(true);
                                }
                            }
                            return;
                        }
                        break;
                    }
                    case 2: {
                        if (keyId.equals(student.getKeyBoard().getKeySn())) {
                            student.getKeyBoard().setOnline(true);
                            String[] strs = info.split(",");
                            if (strs.length >= 3) {
                                float dm = Float.parseFloat(strs[2]);
                                if (dm < 2.4f) {
                                    student.getKeyBoard().setWeak(true);
                                }
                            }
                            return;
                        }
                        break;
                    }
                    case 3:{
                        if (keyId.equals(student.getKeypadId())) {
                            student.getKeyBoard().setOnline(true);
                            String[] strs = info.split(",");
                            if (strs.length >= 3) {
                                float dm = Float.parseFloat(strs[2]);
                                if (dm < 2.4f) {
                                    student.getKeyBoard().setWeak(true);
                                }
                            }
                            return;
                        }
                        break;
                    }
                }

            }
        }
        Student student = new Student();
        switch (getMode()){
            case 1: student.getKeyBoard().setKeyId(keyId); break;
            case 2: student.getKeyBoard().setKeySn(keyId); break;
            case 3: student.setKeypadId(keyId); break;
        }
        student.getKeyBoard().setOnline(true);
        studentList.add(student);
        ApplicationData.getInstance().setStudentList(studentList);
    }

    /**
     * 设置所有键盘都为离线状态
     */
    public void setOfflineAllKeyboard() {
        List<Student> studentList = ApplicationData.getInstance().getStudentList();
        List<Student> temp = new ArrayList<>();
        if (studentList != null) {
            for (Student student : studentList) {
                student.getKeyBoard().setOnline(false);
                student.getKeyBoard().setWeak(false);
                if (TextUtils.isEmpty(student.getStudentId())) {
                    temp.add(student);
                }
            }
        }
        for (Student student : temp) {
            studentList.remove(student);
        }
        ApplicationData.getInstance().setStudentList(studentList);
    }

    /**
     * 获取当前学生数量
     *
     * @return
     */
    public int getStudentCount() {
        int count = 0;
        List<Student> studentList = ApplicationData.getInstance().getStudentList();
        if (studentList != null) {
            count = studentList.size();
        }
        return count;
    }

    /**
     * 获取当前在线学生总数
     *
     * @return 在线学生总数
     */
    public int getOnlineStudentCount() {
        int count = 0;
        List<Student> studentList = ApplicationData.getInstance().getStudentList();
        if (studentList != null) {
            for (Student student : studentList) {
                if (student.getKeyBoard().isOnline()) {
                    count++;
                }
            }
        }
        return count;
    }

    /**
     * 获取学生键盘弱电个数
     *
     * @return
     */
    public int getWeakStudentCount() {
        int count = 0;
        List<Student> studentList = ApplicationData.getInstance().getStudentList();
        if (studentList != null) {
            for (Student student : studentList) {
                if (student.getKeyBoard().isWeak()) {
                    count++;
                }
            }
        }
        return count;
    }

    /**
     * 获取当前考试试卷
     *
     * @return
     */
    public Paper getCurrentPaper() {
        return ApplicationData.getInstance().getClassPaper();
    }

    /**
     * 通过键盘ID,查找对应学生
     *
     * @param keyId 键盘ID
     * @return 学生个人信息
     */
    public Student findStudentByKeyId(String keyId) {
        List<Student> studentList = ApplicationData.getInstance().getStudentList();
        int mode = SpCache.getInstance().getInt(Constants.SAVE_SIGN_MODE_KEY, 3);
        if (studentList != null) {
            for (Student student : studentList) {
                if(mode == 1){
                    if(keyId.equals(student.getKeyBoard().getKeyId())){
                        return student;
                    }
                }
                if(mode == 2){
                    if(keyId.equals(student.getKeyBoard().getKeySn())){
                        return student;
                    }
                }
                if(mode == 3){
                    if(keyId.equals(student.getKeypadId())){
                        return student;
                    }
                }
            }
        }
        return null;
    }

    /**
     * 通过键盘返回信息,查找对应回答的问题
     *
     * @param info 键盘提交信息
     * @return 问题
     */
    public Question findQuestionByInfo(String info) {
        if (info.contains(":")) {
            String[] infos = info.split(":");
            int id = Integer.parseInt(infos[0]);
            if (id <= getCurrentPaper().getQuesCount() && id > 0) {
                return getTrueQuestionList(getCurrentPaper().getQuestionList()).get(id - 1);
            }
        }
        return null;
    }

    public List<Question> getTrueQuestionList(List<Question> questions){
        List<Question> ret = new ArrayList<>();
        for(Question question:questions){
            ret.addAll(getFromQuestion(question));
        }
        return ret;
    }

    private List<Question> getFromQuestion(Question question){
        List<Question> ret = new ArrayList<>();
        if(question != null){
            if(question.getType() == 1){
                ret.add(question);
            }else{
                List<Question> list = question.getSubQuestions();
                if(list != null){
                    for(Question question1:list){
                        ret.addAll(getFromQuestion(question1));
                    }
                }
            }
        }
        return ret;
    }

    /**
     * 通过键盘提交的信息,获取该问题的答案
     *
     * @param info 键盘提交的信息
     * @return
     */
    public String getQuestionAnswerByInfo(String info) {
        if (info.contains(":")) {
            String[] infos = info.split(":");
            if (infos.length == 2) {
                return infos[1];
            }
        }
        return "";
    }

    /**
     * 填充学生所回答问题的答案
     *
     * @param student  学生
     * @param question 问题
     * @param answer   答案
     */
    private void fillStudentAnswer(Student student, Question question, String answer) {
        List<StudentQuestionAnswer> questionAnswerList = student.getStudentQuestionAnswerList();
        if (questionAnswerList != null) {
            for (StudentQuestionAnswer answer1 : questionAnswerList) {
                if (question.equals(answer1.getQuestion())) {
                    answer1.setAnswer(answer);
                }
            }

        }
    }

    /**
     * 填充问题所对应学生的答案
     *
     * @param student  学生
     * @param question 问题
     * @param answer   答案
     */
    private void fillQuestionAnswer(Student student, Question question, String answer) {
        List<QuestionSudentAnswer> answerList = question.getStudentAnswer();
        if (answerList != null) {
            for (QuestionSudentAnswer questionSudentAnswer : answerList) {
                if (student.equals(questionSudentAnswer.getStudent())) {
                    questionSudentAnswer.setAnswer(answer);
                }
            }
        }
    }

    /**
     * 初始化学生问题答案
     */
    public void fillStudentQuestion() {
        List<Question> questions = getTrueQuestionList(getCurrentPaper().getQuestionList());
        List<Student> studentList = ApplicationData.getInstance().getStudentList();
        if (studentList != null && questions != null) {
            for (Student student : studentList) {
                student.getStudentQuestionAnswerList().clear();
                for (Question question : questions) {
                    student.getStudentQuestionAnswerList().add(new StudentQuestionAnswer(question, ""));
                }
            }
        }

    }

    /**
     * 初始化问题对应学生的答案
     */
    public void fillQuestionStudent() {
        List<Question> questions = getCurrentPaper().getQuestionList();
        List<Student> studentList = ApplicationData.getInstance().getStudentList();
        if (studentList != null && questions != null) {
            for (Question question : questions) {
                fillQS(studentList, question);
            }
        }
    }

    private void fillQS(List<Student> studentList, Question question) {
        question.getStudentAnswer().clear();
        for (Student student : studentList) {
            question.getStudentAnswer().add(new QuestionSudentAnswer(student, ""));
        }
        List<Question> questions = question.getSubQuestions();
        if(questions != null){
            for(Question question1:questions){
                fillQS(studentList,question1);
            }
        }
    }



    /**
     * 获取全部完成答题的学生人数
     *
     * @return
     */
    public int getCompeleteExamStudent() {
        int count = 0;
        List<Student> studentList = ApplicationData.getInstance().getStudentList();
        if (studentList != null) {
            for (Student student : studentList) {
                List<StudentQuestionAnswer> answers = student.getStudentQuestionAnswerList();
                boolean compelete = true;
                for (StudentQuestionAnswer answer : answers) {
                    if (TextUtils.isEmpty(answer.getAnswer())) {
                        compelete = false;
                        break;
                    }
                }
                if(answers.size() == 0){
                    compelete = false;
                }
                if (compelete) {
                    count++;
                }
            }
        }
        return count;
    }

    /**
     * 获取正在做题(已开始并且未完成)的人数
     *
     * @return
     */
    public int getAnsweringExamStudent() {
        int count = 0;
        List<Student> studentList = ApplicationData.getInstance().getStudentList();
        if (studentList != null) {
            for (Student student : studentList) {
                List<StudentQuestionAnswer> answers = student.getStudentQuestionAnswerList();
                boolean answered = false;
                boolean noanswer = false;
                if (answers != null) {
                    for (StudentQuestionAnswer answer : answers) {
                        if (TextUtils.isEmpty(answer.getAnswer())) {
                            noanswer = true;
                        } else {
                            answered = true;
                        }
                    }
                }
                if (answered && noanswer) {
                    count++;
                }
            }
        }
        return count;
    }


    /**
     * 获取当前还没有回答任何问题的学生人数
     *
     * @return 人数
     */
    public int getNoanswerExamStudent() {
        int count = 0;
        List<Student> studentList = ApplicationData.getInstance().getStudentList();
        for (Student student : studentList) {
            List<StudentQuestionAnswer> answers = student.getStudentQuestionAnswerList();
            boolean noanswer = true;
            for (StudentQuestionAnswer answer : answers) {
                if (!TextUtils.isEmpty(answer.getAnswer())) {
                    noanswer = false;
                    break;
                }
            }
            if (noanswer) {
                count++;
            }
        }
        return count;
    }

    /**
     * 根据考试情况,生成一次考试成绩
     *
     * @return 一次报表试卷
     */
    public PaperScore transferPaperScore() {
        PaperScore paperScore = new PaperScore();
        paperScore.setClassName(ApplicationData.getInstance().getClassStudent().getClassName());
        paperScore.setPaperScore(ApplicationData.getInstance().getClassPaper().getTotalScore());
        paperScore.setPaperId(getCurrentPaper().getPaperId());
        paperScore.setPaperName(getCurrentPaper().getPaperName());
        paperScore.setReportTime(simpleDateFormat.format(new Date()));
        paperScore.setRightRate(getListRate());
        paperScore.setPaperType(getCurrentPaper().getPaperType());
        paperScore.setUserId(ApplicationData.getInstance().getLoginInfo().getUserId());
        List<StudentScore> list = getStudentExamInfo();
        paperScore.setDetail(list);
        paperScore.setClassAverage(getAvlStudentScore(list));
        return paperScore;
    }

    public float getAvlStudentScore(List<StudentScore> list) {
        float avl = 0f;
        int count = 0 ;
        if (list != null) {
            for (StudentScore studentScore : list) {
                if(ApplicationDataHelper.getInstance().isEffectiveStduent(studentScore)) {
                    int socre = studentScore.getScore();
                    avl += socre;
                    count++;
                }
            }
            if(count > 0){
                avl = avl / count;
            }
        }
        return avl;
    }

    /**
     * 获取学生结果答题情况
     *
     * @return
     */
    private List<StudentScore> getStudentExamInfo() {

        List<StudentScore> ret = new ArrayList<>();
        List<Student> students = ApplicationData.getInstance().getStudentList();
        if (students != null) {
            for (Student student : students) {
                StudentScore studentScore = new StudentScore();
//                studentScore.setKeyId(student.getKeyBoard().getKeyId());
//                studentScore.setKeySn(student.getKeyBoard().getKeySn());
                studentScore.setStudentId(student.getStudentId());
                studentScore.setStudentName(student.getStudentName());
                List<String> list = new ArrayList<>();
                int totalScore = 0;
                List<StudentQuestionAnswer> studentQuestionAnswer = student.getStudentQuestionAnswerList();
                for (StudentQuestionAnswer answer : studentQuestionAnswer) {
                    String answerStr = answer.getAnswer();
                    if (answer.getAnswer().equals(answer.getQuestion().getAnswers())) {
                        answerStr += ",1,1";//如"A,0"表示选择A答错,"B,1"表示选择B答对)
                        totalScore += answer.getQuestion().getScore();
                    } else {
                        answerStr += ",0";
                        if(isEffect(student)){
                            answerStr += ",1";
                        }else{
                            answerStr += ",0";
                        }
                    }
                    list.add(answerStr);
                }
                studentScore.setScore(totalScore);
                studentScore.setTotalScore(studentScore.getSubjectiveScore() + studentScore.getScore());
                studentScore.setAnswer(list);
                ret.add(studentScore);
            }
        }
        return ret;
    }

    /**
     * 获取试卷单题成绩
     *
     * @return
     */
    private List<String> getListRate() {
        List<String> ret = new ArrayList<>();
        List<Question> questions = getTrueQuestionList(getCurrentPaper().getQuestionList());
        int all = getSignStudent(ApplicationData.getInstance().getStudentList());
        if (questions != null) {
            for (Question question : questions) {
                List<QuestionSudentAnswer> questionSudentAnswers = question.getStudentAnswer();
                int right = 0;
                for (QuestionSudentAnswer answer : questionSudentAnswers) {
                    if (answer.getAnswer().equals(question.getAnswers())) {
                        right++;
                    }
                }
                ret.add(progressText(right, all));
            }
        }
        return ret;
    }


    public int getSignStudent(List<Student> students){
        int ret = 0 ;

        for(Student student:students){
            boolean isEffect = isEffect(student);
            if(isEffect){
                ret ++ ;
            }
        }

        return ret;
    }

    public boolean isEffect(Student student) {
        boolean isEffect = false ;
        List<StudentQuestionAnswer> studentQuestionAnswerList = student.getStudentQuestionAnswerList();
        for(StudentQuestionAnswer studentQuestionAnswer:studentQuestionAnswerList){
            if(!TextUtils.isEmpty(studentQuestionAnswer.getAnswer())){
                isEffect = true;
            }
        }
        if(student.getKeyBoard().isSign()){
            isEffect = true;
        }
        return isEffect;
    }

    /**
     * 转换百分数,保留一位小数
     *
     * @param reply
     * @param all
     * @return
     */
    public String progressText(float reply, float all) {
        float f1 = reply;
        float f2 = all;
        if (f2 == 0) {
            f2 = 1;
        }
        float f3 = (f1 / f2);
        f3 = f3 + 0.0005f;
        int i3 = (int) (f3 * 1000);
        return (i3 / 10) + "." + (i3 % 10) + "";
    }

    /**
     * 保存学生绑定键盘信息
     */
    public void saveStudentSignInfo(){
        ResponseDataBean<List<Student>> responseDataBean = new ResponseDataBean<>();
        responseDataBean.setCode("0");
        responseDataBean.setMsg("");
        responseDataBean.setData(ApplicationData.getInstance().getStudentList());
        FileCache.getFileCache().saveEncryptObject("getStudentList&" + ApplicationData.getInstance().getClassStudent().getClassId(),responseDataBean);
    }

    public boolean isKeyIdExist(String keyID){
        List<Student> studentList = ApplicationData.getInstance().getStudentList();
        if(studentList != null){
            for(Student student:studentList){
                if(keyID.equals(student.getKeyBoard().getKeyId())){
                    return true;
                }
            }
        }
        return false;
    }

    public boolean isKeySnExist(String keySN){
        List<Student> studentList = ApplicationData.getInstance().getStudentList();
        if(studentList != null){
            for(Student student:studentList){
                if(keySN.equals(student.getKeyBoard().getKeySn())){
                    return true;
                }
            }
        }
        return false;
    }

    public boolean isUIDExist(String uid){
        List<Student> studentList = ApplicationData.getInstance().getStudentList();
        if(studentList != null){
            for(Student student:studentList){
                if(uid.equals(student.getStudentUID())){
                    return true;
                }
            }
        }
        return false;
    }

    public boolean isKeyboardSnExist(String keySn){
        List<Student> studentList = ApplicationData.getInstance().getStudentList();
        if(studentList != null){
            for(Student student:studentList){
                if(keySn.equals(student.getKeypadId())){
                    return true;
                }
            }
        }
        return false;
    }
}