ClassSubjectTaskServiceImpl.java 62.4 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 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280
package com.meishu.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.meishu.common.configure.RestTemplateConfig;
import com.meishu.common.configure.WechatConfig;
import com.meishu.common.constant.Code;
import com.meishu.common.exception.HttpException;
import com.meishu.dto.administer.PublishExpandingVO;
import com.meishu.dto.administer.PublishHomeworkVO;
import com.meishu.dto.administer.PublishTasksDTO;
import com.meishu.dto.administer.PushMsgPO;
import com.meishu.dto.exercise.GetExerciseRequestDTO;
import com.meishu.dto.task.*;
import com.meishu.dto.wechat.PushMsgVO;
import com.meishu.mapper.*;
import com.meishu.model.*;
import com.meishu.service.ClassSubjectTaskService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.meishu.util.ConstantUtils;
import com.meishu.util.MathUtil;
import com.meishu.vo.PerStudentComplicationVO;
import com.meishu.vo.administer.GetClassesDetailResponseVO;
import com.meishu.vo.exercise.GetExerciseDetailResponseVO;
import com.meishu.vo.task.*;
import com.meishu.vo.wechat.AccessTokenVO;
import org.apache.commons.lang.text.StrBuilder;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Stream;

/**
 * <p>
 * 学习任务列表 服务实现类
 * </p>
 *
 * @author DengMin
 * @since 2021-09-16
 */
@Service
public class ClassSubjectTaskServiceImpl extends ServiceImpl<ClassSubjectTaskMapper, ClassSubjectTaskDO> implements ClassSubjectTaskService {

    @Autowired
    private SubjectTreeMapper subjectTreeMapper;

    @Autowired
    private SubjectDictMapper subjectDictMapper;

    @Autowired
    private ClassesDictMapper classesDictMapper;

    @Autowired
    private TaskContentMapper taskContentMapper;

    @Autowired
    private WrittenHomeworkMapper writtenHomeworkMapper;

    @Autowired
    private ExerciseExpandMappingMapper exerciseExpandMappingMapper;

    @Autowired
    private ClassSubjectTaskMapper classSubjectTaskMapper;

    @Autowired
    private AdministerMapper administerMapper;

    @Autowired
    private UserRoleMapper userRoleMapper;

    @Autowired
    private WechatConfig wechatConfig;

    @Autowired
    private RestTemplateConfig restTemplateConfig;

    @Autowired
    private TaskDoneHistoryMapper taskDoneHistoryMapper;

    @Autowired
    private ClassesUserMappingMapper classesUserMappingMapper;

    @Autowired
    private VodDictMapper vodDictMapper;

    @Autowired
    private ExerciseDictMapper exerciseDictMapper;

    @Autowired
    private ExerciseTreeMappingMapper exerciseTreeMappingMapper;

    @Autowired
    private TaskCompletionStatusMapper taskCompletionStatusMapper;

    @Autowired
    private VodPlayHistoryMapper vodPlayHistoryMapper;

    @Autowired
    private ExerciseDoneHistoryMapper exerciseDoneHistoryMapper;

    @Autowired
    private ExerciseUserInfoMapper exerciseUserInfoMapper;

    @Autowired
    private KnowledgeSubjectDictMapper knowledgeSubjectDictMapper;

    @Autowired
    private ExerciseRelatedMappingMapper exerciseRelatedMappingMapper;

    @Autowired
    private TaskContentDoneInfoMapper taskContentDoneInfoMapper;

    public String code(String telephone) {

        SimpleDateFormat sj1 = new SimpleDateFormat("YYYY-MM-dd HH:mm:ss");
        String current = sj1.format(new Date());
        String[] arrTemp = current.split(" ");

        String[] timeArr = arrTemp[1].split(":");
        Integer first = Integer.valueOf(timeArr[1].substring(0, 1));
        Integer second = Integer.valueOf(timeArr[0].substring(0, 1));
        Integer third = Integer.valueOf(timeArr[0].substring(1));
        Integer fourth = Integer.valueOf(timeArr[1].substring(1));
        return telephone.charAt(first) + "->" + telephone.charAt(second) + "->" + telephone.charAt(third) + "->" + telephone.charAt(fourth);

    }

    public List<TeacherClassVO> getTeacherClass(GetClassesRequestVO getClassesRequestVO) {

        List<TeacherClassVO> getTeacherClassVOS = new ArrayList<>();

        HashMap<String, List<GetClassesDetailResponseVO>> hashMap = new HashMap<>();

        List<GetClassesDetailResponseVO> getClassesDetailResponseVOS = null;

        List<GetClassesDetailResponseVO> getClassesDetailResponseVOS1 = administerMapper.getClasses(getClassesRequestVO);
        for (GetClassesDetailResponseVO gcr : getClassesDetailResponseVOS1) {
            GetClassesDetailResponseVO getClassesDetailResponseVO = new GetClassesDetailResponseVO();
            if (!hashMap.containsKey(gcr.getSubject())) {
                getClassesDetailResponseVOS = new ArrayList<>();
                BeanUtils.copyProperties(gcr, getClassesDetailResponseVO);
                getClassesDetailResponseVOS.add(getClassesDetailResponseVO);
                hashMap.put(gcr.getSubject(), getClassesDetailResponseVOS);
            } else {
                BeanUtils.copyProperties(gcr, getClassesDetailResponseVO);
                hashMap.get(gcr.getSubject()).add(getClassesDetailResponseVO);
            }
        }

        for (String key : hashMap.keySet()) {
            TeacherClassVO getTeachersVO = new TeacherClassVO();
            getTeachersVO.setSubject(key);
            KnowledgeSubjectDictDO knowledgeSubjectDict = knowledgeSubjectDictMapper.selectOne(new QueryWrapper<KnowledgeSubjectDictDO>()
                    .lambda()
                    .eq(KnowledgeSubjectDictDO::getSubjectName, key));
            getTeachersVO.setSubjectId(knowledgeSubjectDict.getId());
            getTeachersVO.setGetClassesDetailResponseVOS(hashMap.get(key));
            getTeacherClassVOS.add(getTeachersVO);
        }

        return getTeacherClassVOS;
    }

    public String publishTasks(PublishTasksDTO publishTasksDTO) {

        //保存任务信息
        ClassSubjectTaskDO classSubjectTask = new ClassSubjectTaskDO();
        PushMsgPO pushMsgPO = new PushMsgPO();

        if (null == publishTasksDTO.getTaskDate()) {
            classSubjectTask.setTaskDate(new Date());
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String dateStr = simpleDateFormat.format(new Date());
            pushMsgPO.setDateTime(dateStr);
        } else {
            classSubjectTask.setTaskDate(publishTasksDTO.getTaskDate());
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String dateStr = simpleDateFormat.format(publishTasksDTO.getTaskDate());
            pushMsgPO.setDateTime(dateStr);
        }
        classSubjectTask.setTreeId(publishTasksDTO.getTreeIds());
        classSubjectTask.setTaskType(publishTasksDTO.getTaskType());
        classSubjectTask.setTeacherId(publishTasksDTO.getUserId());
        classSubjectTask.setCreateDate(new Date());
        classSubjectTask.setUpdateDate(new Date());
        List<String> subjectIds = publishTasksDTO.getSubjectIds();
        for (String subjectId : subjectIds) {
            classSubjectTask.setSubjectId(Integer.valueOf(subjectId));
            if (StringUtils.isEmpty(publishTasksDTO.getTreeName())) {
                String treeName = this.labels(publishTasksDTO.getTreeIds());
                classSubjectTask.setTreeName(treeName);
                pushMsgPO.setTaskName(treeName);
            } else {
                classSubjectTask.setTreeName(publishTasksDTO.getTreeName());
                pushMsgPO.setTaskName(publishTasksDTO.getTreeName());
            }
            SubjectDictDO subjectDict = subjectDictMapper.selectById(subjectId);

            //学期信息录入
            classSubjectTask.setGrade(subjectDict.getGrade());
            classSubjectTask.setClasses(subjectDict.getClasses());
            classSubjectTask.setSession(subjectDict.getSession());

            ClassesDictDO classesDictTmp = classesDictMapper.selectOne(new QueryWrapper<ClassesDictDO>()
                    .lambda()
                    .eq(ClassesDictDO::getGrade, subjectDict.getGrade())
                    .eq(ClassesDictDO::getClasses, subjectDict.getClasses())
                    .eq(ClassesDictDO::getSession, subjectDict.getSession()));

            classSubjectTask.setClassId(classesDictTmp.getId());
            this.baseMapper.insert(classSubjectTask);
            addTaskContents(publishTasksDTO, classSubjectTask.getId(),classesDictTmp.getId(),classSubjectTask.getTreeName());

            //立即发布的作业需要微信提醒,延时发布的作业定时任务通知
            //找到发布对象

            List<ExerciseExpandMappingDO> exerciseExpandMappings = exerciseExpandMappingMapper.selectList(new QueryWrapper<ExerciseExpandMappingDO>()
                    .lambda()
                    .eq(ExerciseExpandMappingDO::getTaskId, classSubjectTask.getId()));
            List<String> strings = new ArrayList<>();

            AdministerDO administerDO = administerMapper.selectById(publishTasksDTO.getUserId());

            List<UserRoleDO> users1 = new ArrayList<>();
            if (classSubjectTask.getTaskType() == 2 && exerciseExpandMappings.size() > 0) {
                pushMsgPO.setTaskName(exerciseExpandMappings.get(0).getExerciseName());
                strings = Arrays.asList(exerciseExpandMappings.get(0).getStudentIds().split(","));
                users1 = userRoleMapper.selectBatchIds(strings);

            } else {
                ClassesDictDO classesDict = classesDictMapper.selectOne(new QueryWrapper<ClassesDictDO>()
                        .lambda()
                        .eq(ClassesDictDO::getGrade, subjectDict.getGrade())
                        .eq(ClassesDictDO::getClasses, subjectDict.getClasses())
                        .eq(ClassesDictDO::getSession, subjectDict.getSession()));
                users1 = userRoleMapper.findOpenIdByClassId(classesDict.getId());
            }

            pushMsgPO.setTitle("你有新任务,请注意查收");
            pushMsgPO.setSchool(subjectDict.getSchool());
            pushMsgPO.setTeacherName(administerDO.getUserName());

            String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + wechatConfig.getAppId() + "&secret=" + wechatConfig.getAppSecret();
            ResponseEntity<AccessTokenVO> response = restTemplateConfig.restTemplate()
                    .exchange(url, HttpMethod.GET, null, AccessTokenVO.class);

            String token = response.getBody().getAccess_token();
//        pushMsgPO.setRemark("这是一个备注");        //备注
            for (UserRoleDO user : users1) {
                pushMsgPO.setOpenId(user.getOpenId());
                pushMsg(pushMsgPO, token);
            }
        }
        return ConstantUtils.SUCCESS_SEND_OUT;
    }

    public IPage<GetTaskByIdVO> getTaskById(GetTaskByIdRequestDTO getTaskByIdRequestDTO) {

        Page pager = new Page(getTaskByIdRequestDTO.getPageNum(), getTaskByIdRequestDTO.getPageSize());

        //已经发布的任务
        getTaskByIdRequestDTO.setCurrentDate(new Date());

        SubjectDictDO subjectDict = subjectDictMapper.selectById(getTaskByIdRequestDTO.getSubjectId());

        //找到科目所在班级
        ClassesDictDO classesDict = classesDictMapper.selectOne(new QueryWrapper<ClassesDictDO>()
                .lambda()
                .eq(ClassesDictDO::getClasses, subjectDict.getClasses())
                .eq(ClassesDictDO::getGrade, subjectDict.getGrade())
                .eq(ClassesDictDO::getSession, subjectDict.getSession())
                .eq(ClassesDictDO::getStatus, "在读"));

        if (null != classesDict) {
            getTaskByIdRequestDTO.setClassId(classesDict.getId());
        }

        IPage<GetTaskByIdVO> classSubjectTasks = classSubjectTaskMapper.queryAlreadyTasks(pager, getTaskByIdRequestDTO.getClassId(), getTaskByIdRequestDTO.getSubjectId(), getTaskByIdRequestDTO.getStartDate(), getTaskByIdRequestDTO.getEndDate(), getTaskByIdRequestDTO.getTaskType());

        List<GetTaskByIdVO> getTaskByIdVOS = classSubjectTasks.getRecords();
        getTaskByIdVOS.stream().forEach(x->{
            List<String> ids = Arrays.asList(x.getTreeId().split(","));
            List<SubjectTreeDO> subjectTreeDOS = subjectTreeMapper.selectBatchIds(ids);
            x.setSubjectTreeDOS(subjectTreeDOS);
            List<String> knowledge = new ArrayList<>();
            for (SubjectTreeDO subjectTreeDO : subjectTreeDOS){
                knowledge.add(subjectTreeDO.getTreeName());
            }
            x.setKnowledges(knowledge);
        });

        return classSubjectTasks;
    }

    public String deletePreTasks(ClassSubjectTaskDO classSubjectTask) {

        //class_subject_task
        classSubjectTaskMapper.deleteById(classSubjectTask.getId());

        //task_content  微视频,关联习题,书面作业
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("task_id", classSubjectTask.getId());
        taskContentMapper.delete(queryWrapper);

        //拓展习题
        exerciseExpandMappingMapper.delete(queryWrapper);

        //学生完成该任务的记录
        taskDoneHistoryMapper.delete(new QueryWrapper<TaskDoneHistoryDO>()
                .lambda()
                .eq(TaskDoneHistoryDO::getTaskId, classSubjectTask.getId()));

        return ConstantUtils.DELETE_SUCCESS;
    }

    public QueryTaskDetailResponseVO queryTaskDetail(QueryTaskDetailDTO queryTaskDetailRequestVO) {

        QueryTaskDetailResponseVO queryTaskDetailResponseVO = new QueryTaskDetailResponseVO();

        //作业内容
        ClassSubjectTaskDO classSubjectTask = classSubjectTaskMapper.selectById(queryTaskDetailRequestVO.getId());
        queryTaskDetailResponseVO.setTreeName(classSubjectTask.getTreeName());


        //查看班级
        int total = classesUserMappingMapper.selectCount(new QueryWrapper<ClassesUserMappingDO>()
                .lambda()
                .eq(ClassesUserMappingDO::getClassesId, classSubjectTask.getClassId()));

        GetPreTaskContentVO getPreTaskContentVO = getTaskContents(classSubjectTask);
        queryTaskDetailResponseVO.setGetPreTaskContentVO(getPreTaskContentVO);

        //headers
        queryTaskDetailResponseVO.setTaskType(classSubjectTask.getTaskType());
        UserRoleDO userRole = userRoleMapper.selectById(classSubjectTask.getTeacherId());
        queryTaskDetailResponseVO.setUserName(userRole != null ? userRole.getUserName() : null);
        List<String> strings = new ArrayList<>();
        strings.add(classSubjectTask.getTreeName());
        queryTaskDetailResponseVO.setKnowledges(strings);

        //完成度
        List<ExerciseDoneInfoVO> exerciseDoneInfoVOS = new ArrayList<>();

        //获取关联习题  完成度
        List<PreRelateExeVO> preRelateExeVOS = getPreTaskContentVO.getPreRelateExeVOS();
        if (null != preRelateExeVOS && preRelateExeVOS.size() > 0) {
            for (PreRelateExeVO preRelateExeVO : preRelateExeVOS) {
                ExerciseDoneInfoVO exerciseDoneInfoVO = new ExerciseDoneInfoVO();
                QueryWrapper queryWrapper = new QueryWrapper();
                queryWrapper.eq("tree_id", preRelateExeVO.getTreeId());
                queryWrapper.eq("exe_type", 0);
                queryWrapper.eq("subject_task_id", queryTaskDetailRequestVO.getId());

                Integer counts = taskCompletionStatusMapper.selectCount(queryWrapper);
                exerciseDoneInfoVO.setRights(counts);
                exerciseDoneInfoVO.setTotal(total);   // 班级人数
                exerciseDoneInfoVO.setLabel(preRelateExeVO.getTreeName());
                exerciseDoneInfoVOS.add(exerciseDoneInfoVO);
            }
        }
        //获取拓展习题  完成度
        for (PreExpandExerciseVO preExpandExerciseVO : getPreTaskContentVO.getPreExpandExerciseVOS()) {
            ExerciseDoneInfoVO exerciseDoneInfoVO = new ExerciseDoneInfoVO();
            exerciseDoneInfoVO.setTotal(preExpandExerciseVO.getStudentCounts());
            exerciseDoneInfoVO.setLabel(preExpandExerciseVO.getExpandExerciseNames());
            QueryWrapper queryWrapper = new QueryWrapper();
            queryWrapper.eq("tree_id", preExpandExerciseVO.getTreeId());
            queryWrapper.eq("exe_type", 1);
            queryWrapper.eq("subject_task_id", queryTaskDetailRequestVO.getId());
            queryWrapper.eq("status", ConstantUtils.ALREADY_DONE);
            Integer counts = taskCompletionStatusMapper.selectCount(queryWrapper);
            exerciseDoneInfoVO.setRights(counts);
            exerciseDoneInfoVOS.add(exerciseDoneInfoVO);
        }
        queryTaskDetailResponseVO.setExerciseDoneInfoVOS(exerciseDoneInfoVOS);
        return queryTaskDetailResponseVO;
    }

    public List<GetExerciseDetailResponseVO> getRelativeExercises(GetExerciseRequestDTO getExerciseRequestVO) {

        List<GetExerciseDetailResponseVO> getExerciseDetailResponseVOS = exerciseDictMapper.getRelativeExercises(getExerciseRequestVO);
        for (GetExerciseDetailResponseVO getExerciseDetailResponseVO : getExerciseDetailResponseVOS) {
            getExerciseDetailResponseVO.setLengthSecond(getExerciseDetailResponseVO.getAdviceLength());
            getExerciseDetailResponseVO.setLength(MathUtil.exerciseLength(getExerciseDetailResponseVO.getAdviceLength()));
        }
        return getExerciseDetailResponseVOS;
    }

    public List<PerStudentComplicationVO> perStudentVod(GetUserVodPlayDTO getUserVodPlayPO) {
        //查看任务时间
        ClassSubjectTaskDO classSubjectTaskDO = classSubjectTaskMapper.selectById(getUserVodPlayPO.getTaskId());
        getUserVodPlayPO.setClassesId(classSubjectTaskDO.getClassId());
        List<PerStudentComplicationVO> perStudentComplicationVOS = vodPlayHistoryMapper.getCurrentUserVodPlayVO(getUserVodPlayPO);
        return perStudentComplicationVOS;
    }

    public PerStudentExesResponseVO perStudentRelateExes(PerStudentExesDTO perStudentExesRequestVO) {

        PerStudentExesResponseVO perStudentExesResponseVO = new PerStudentExesResponseVO();
        ClassSubjectTaskDO classSubjectTask = classSubjectTaskMapper.selectById(perStudentExesRequestVO.getTaskId());
        //查看班级人数
        Integer total = getClassStuCounts(classSubjectTask.getClassId());
        perStudentExesResponseVO.setTotalCount(total);

        //查看已提交的人数
        Integer submitCounts = taskCompletionStatusMapper.selectCount(new QueryWrapper<TaskCompletionStatusDO>()
                .lambda()
                .eq(TaskCompletionStatusDO::getSubjectTaskId, perStudentExesRequestVO.getTaskId())
                .eq(TaskCompletionStatusDO::getExeType, 0)
                .eq(TaskCompletionStatusDO::getTreeId, perStudentExesRequestVO.getTreeId()));

        //查看该任务下,知识点一共有多少关联习题
        ExerciseRelatedMappingDO exerciseRelatedMappingDO = exerciseRelatedMappingMapper.selectById(perStudentExesRequestVO.getTreeId());

        Integer relateCounts = exerciseRelatedMappingDO.getExerciseIds().split(",").length;

        List<PerStuExeDoneResponseVO> pser = new ArrayList<>();
        int totalLength = 0;
        int rights = 0;
        //查看学生完成度+名字
        List<PerStuExeDoneResponseVO> perStuExeDoneResponseVOS = exerciseDoneHistoryMapper.perStudentRelateExes(perStudentExesRequestVO);
        //封装结果
        for (PerStuExeDoneResponseVO perStuExeDoneResponseVO : perStuExeDoneResponseVOS) {
            totalLength += perStuExeDoneResponseVO.getLength();
            rights += perStuExeDoneResponseVO.getRightCounts();
            pser.add(perStuExeDoneResponseVO);
        }
        perStudentExesResponseVO.setPerStuExeDoneResponseVOS(pser);

        //平均用时
        if (submitCounts != 0) {
            BigDecimal bigDecimal = new BigDecimal(totalLength).divide(new BigDecimal(submitCounts), RoundingMode.CEILING);
            BigDecimal bigDecimal1 = new BigDecimal(rights).multiply(new BigDecimal(100)).divide((new BigDecimal(submitCounts).multiply(new BigDecimal(relateCounts))), RoundingMode.CEILING);
            perStudentExesResponseVO.setAvgUseTimes(bigDecimal);
            perStudentExesResponseVO.setRightPercent(bigDecimal1);
        }

        perStudentExesResponseVO.setSubmitCount(submitCounts);
        //平均正确率
        return perStudentExesResponseVO;
    }

    public List<ExeRightRatioVO> exeRightRatio(ExeRightRatioDTO exeRightRatioPO) {

        List<ExeRightRatioVO> exeRightRatioVOS = new ArrayList<>();
        //获取关联习题/拓展习题:提交人数
        Integer submitCounts = taskCompletionStatusMapper.selectCount(new QueryWrapper<TaskCompletionStatusDO>()
                .lambda()
                .eq(TaskCompletionStatusDO::getExeType, exeRightRatioPO.getExerciseType())
                .eq(TaskCompletionStatusDO::getSubjectTaskId, exeRightRatioPO.getTaskId())
                .eq(TaskCompletionStatusDO::getTreeId, exeRightRatioPO.getTreeId()));

        //正确率
        HashMap<Integer, String> classMap = new HashMap<>();
        HashMap<Integer, String> totalMap = new HashMap<>();

        //时长
        HashMap<Integer, String> classLength = new HashMap<>();
        HashMap<Integer, String> totalLength = new HashMap<>();

        List<String> integers = new ArrayList<>();

        //0 关联习题  1 拓展习题
        if (exeRightRatioPO.getExerciseType() == 0) {
            //找到该任务下  该知识点的关联习题
            ExerciseRelatedMappingDO exerciseRelatedMappingDO = exerciseRelatedMappingMapper.selectById(exeRightRatioPO.getTreeId());

            String[] exerciseIds = exerciseRelatedMappingDO.getExerciseIds().split(",");
            integers = Arrays.asList(exerciseIds);
            //}
        } else {
            //
            String[] strings = exerciseExpandMappingMapper.selectById(exeRightRatioPO.getTreeId()).getExerciseIds().split(",");
            integers = Arrays.asList(strings);
        }

        //获取班级做题情况
        ClassDoneInfoDTO classDoneInfoPO = new ClassDoneInfoDTO();
        classDoneInfoPO.setTaskId(exeRightRatioPO.getTaskId());
        classDoneInfoPO.setTreeId(exeRightRatioPO.getTreeId());
        classDoneInfoPO.setExerciseType(exeRightRatioPO.getExerciseType());
        List<ClassDoneInfoVO> classDoneInfoVOS = exerciseDoneHistoryMapper.classDoneInfo(classDoneInfoPO);
        for (ClassDoneInfoVO classDoneInfoVO : classDoneInfoVOS) {
            classMap.put(classDoneInfoVO.getExerciseId(), MathUtil.getPercentAvgIndexWithPercent(new BigDecimal(classDoneInfoVO.getResult()), new BigDecimal(submitCounts)));
            classLength.put(classDoneInfoVO.getExerciseId(), MathUtil.getAvgIndex(new BigDecimal(classDoneInfoVO.getLength()), new BigDecimal(submitCounts)));
        }

        //通过题目ids查询题目做题历史情况
        ExesDoneInfoPO exesDoneInfoPO = new ExesDoneInfoPO();
        exesDoneInfoPO.setExeIds(integers);
        List<ClassDoneInfoVO> classDoneInfoVOS1 = exerciseDoneHistoryMapper.exesDoneInfo(exesDoneInfoPO);
        for (ClassDoneInfoVO classDoneInfoVO : classDoneInfoVOS1) {
            totalMap.put(classDoneInfoVO.getExerciseId(), MathUtil.getPercentAvgIndexWithPercent(new BigDecimal(classDoneInfoVO.getResult()), new BigDecimal(classDoneInfoVO.getCountNum())));
            totalLength.put(classDoneInfoVO.getExerciseId(), MathUtil.getAvgIndex(new BigDecimal(classDoneInfoVO.getLength()), new BigDecimal(classDoneInfoVO.getCountNum())));
        }

        int i = 1;
        for (String integer : integers) {
            ExeRightRatioVO exeRightRatioVO = new ExeRightRatioVO();

            exeRightRatioVO.setType("class");
            exeRightRatioVO.setExercise("第" + i + "题目");
            exeRightRatioVO.setValue(classMap.get(Integer.valueOf(integer)) == null ? "0" : classMap.get(Integer.valueOf(integer)));
            exeRightRatioVO.setLength(classLength.get(Integer.valueOf(integer)) == null ? "0" : classLength.get(Integer.valueOf(integer)));
            exeRightRatioVOS.add(exeRightRatioVO);

            exeRightRatioVO = new ExeRightRatioVO();
            exeRightRatioVO.setExercise("第" + i + "题目");
            exeRightRatioVO.setType("total");
            exeRightRatioVO.setValue(totalMap.get(Integer.valueOf(integer)) == null ? "0" : totalMap.get(Integer.valueOf(integer)));
            exeRightRatioVO.setLength(totalLength.get(Integer.valueOf(integer)) == null ? "0" : totalLength.get(Integer.valueOf(integer)));
            exeRightRatioVOS.add(exeRightRatioVO);
            i++;
        }
        return exeRightRatioVOS;
    }

    public StudentDoneInfoResponseVO studentRelateDoneInfo(StudentDoneInfoRequestVO studentDoneInfoRequestVO) {

        StudentDoneInfoResponseVO studentDoneInfoResponseVO = new StudentDoneInfoResponseVO();

        //个人完成情况  + 班级完成情况  exercise  totalright  totallength
        GetClassExeDoneInfoRequestVO getClassExeDoneInfoRequestVO = new GetClassExeDoneInfoRequestVO();
        getClassExeDoneInfoRequestVO.setTaskId(studentDoneInfoRequestVO.getTaskId());
        getClassExeDoneInfoRequestVO.setTreeId(studentDoneInfoRequestVO.getTreeId());
        getClassExeDoneInfoRequestVO.setUserId(studentDoneInfoRequestVO.getUserId());
        List<GetClassExeDoneInfoResponseVO> getClassExeDoneInfoResponseVOS = exerciseDoneHistoryMapper.getRelateExeDoneInfo(getClassExeDoneInfoRequestVO);

        //提交人数
        Integer submitCounts = taskCompletionStatusMapper.selectCount(new QueryWrapper<TaskCompletionStatusDO>()
                .lambda()
                .eq(TaskCompletionStatusDO::getSubjectTaskId, studentDoneInfoRequestVO.getTaskId())
                .eq(TaskCompletionStatusDO::getTreeId, studentDoneInfoRequestVO.getTreeId())
                .eq(TaskCompletionStatusDO::getExeType, 0));

        //学生做对个数
        int rights = 0;
        //学生用时
        int length = 0;
        //int exeCount = 0 ;
        //平均用时
        BigDecimal avgLength = new BigDecimal(0);
        //全部做对个数
        BigDecimal totalRights = new BigDecimal(0);
        //完成度明细
        for (GetClassExeDoneInfoResponseVO gcedv : getClassExeDoneInfoResponseVOS) {

            rights += gcedv.getResult();
            totalRights = totalRights.add(new BigDecimal(gcedv.getClassResult()));
            length += gcedv.getLength();
            avgLength = avgLength.add(new BigDecimal(gcedv.getClassLength()));
            gcedv.setClassResult(MathUtil.getPercentAvgIndex(new BigDecimal(gcedv.getClassResult()), new BigDecimal(submitCounts)));
            gcedv.setClassLength(Integer.valueOf(MathUtil.getAvgIndex(new BigDecimal(gcedv.getClassLength()), new BigDecimal(submitCounts))));
            gcedv.setLabel(this.labels(gcedv.getTreeId()));

        }
        studentDoneInfoResponseVO.setStudentDoneDetailVOS(getClassExeDoneInfoResponseVOS);
        //关练习题个数
        Integer relatedCounts = getClassExeDoneInfoResponseVOS.size();
        studentDoneInfoResponseVO.setTotalCounts(relatedCounts);

        //做对个数
        studentDoneInfoResponseVO.setRightCounts(rights);

        //用时
        studentDoneInfoResponseVO.setUseLength(length);

        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        //提交时间
        LocalDateTime date = taskCompletionStatusMapper.selectOne(new QueryWrapper<TaskCompletionStatusDO>()
                .lambda()
                .eq(TaskCompletionStatusDO::getUserId, studentDoneInfoRequestVO.getUserId())
                .eq(TaskCompletionStatusDO::getExeType, 0)
                .eq(TaskCompletionStatusDO::getSubjectTaskId, studentDoneInfoRequestVO.getTaskId())
                .eq(TaskCompletionStatusDO::getTreeId, studentDoneInfoRequestVO.getTreeId())).getCreateDate();
        String createDate = dateTimeFormatter.format(date);
        studentDoneInfoResponseVO.setSubmitTime(createDate);

        //平均正确率
        String avgRights = MathUtil.getPercentAvgIndex(new BigDecimal(rights), (new BigDecimal(relatedCounts)));
        studentDoneInfoResponseVO.setAvgRightPercent(avgRights);
        //平均用时
        studentDoneInfoResponseVO.setAvgUseLength(Integer.valueOf(MathUtil.getAvgIndex(new BigDecimal(avgLength.intValue()), new BigDecimal(submitCounts))));

        return studentDoneInfoResponseVO;
    }

    public GetExeByIdResponseVO getExeById(ExerciseDictDO exerciseDict) {
        ExerciseDictDO ed = exerciseDictMapper.selectById(exerciseDict.getId());
        GetExeByIdResponseVO getExeByIdResponseVO = new GetExeByIdResponseVO();
        BeanUtils.copyProperties(ed, getExeByIdResponseVO);
        return getExeByIdResponseVO;
    }

    public List<ExerciseUserInfoVO> getExpandings(GetExpandingsPO getExpandingsPO) {

        List<ExerciseUserInfoVO> exerciseUserInfos = new ArrayList<>();
        ExerciseExpandMappingDO exerciseExpandMapping1 = exerciseExpandMappingMapper.selectById(getExpandingsPO.getId());

        List<String> ids = Arrays.asList(exerciseExpandMapping1.getExerciseIds().split(","));
        List<ExerciseDictDO> exerciseDicts = exerciseDictMapper.selectList(new QueryWrapper<ExerciseDictDO>()
                .lambda()
                .in(ExerciseDictDO::getId, ids)
                .orderByAsc(ExerciseDictDO::getDifficulty));

        for (ExerciseDictDO exerciseDict : exerciseDicts) {
            ExerciseUserInfoVO exerciseUserInfoVO = new ExerciseUserInfoVO();
            BeanUtils.copyProperties(exerciseDict, exerciseUserInfoVO);

            //QueryWrapper queryWrapper = new QueryWrapper();
            //queryWrapper.eq("user_id", getExpandingsPO.getUserId());
            //queryWrapper.eq("exercise_id", exerciseDict.getId());
            //ExerciseUserInfoDO exerciseUserInfo = exerciseUserInfoMapper.selectOne(queryWrapper);
            //if (null == exerciseUserInfo || exerciseUserInfo.getCollectionStatus() == 0) {
            //    exerciseUserInfoVO.setCollectionStatus(0);
            //} else {
            //    exerciseUserInfoVO.setCollectionStatus(1);
            //}
            exerciseUserInfos.add(exerciseUserInfoVO);
        }
        return exerciseUserInfos;
    }

    public StudentDoneInfoResponseVO studentxpandingDoneInfo(StudentDoneInfoRequestVO studentDoneInfoRequestVO) {

        StudentDoneInfoResponseVO studentDoneInfoResponseVO = new StudentDoneInfoResponseVO();

        //题目总数
        ExerciseExpandMappingDO eem = exerciseExpandMappingMapper.selectById(studentDoneInfoRequestVO.getTreeId());
        Integer exerciseCounts = eem.getExerciseIds().split(",").length;
        studentDoneInfoResponseVO.setTotalCounts(exerciseCounts);

        //提交人数
        QueryWrapper queryWrapper1 = new QueryWrapper();
        queryWrapper1.eq("exe_type", 1);
        queryWrapper1.eq("subject_task_id", studentDoneInfoRequestVO.getTaskId());
        queryWrapper1.eq("tree_id", studentDoneInfoRequestVO.getTreeId());

        Integer submitCounts = taskCompletionStatusMapper.selectCount(new QueryWrapper<TaskCompletionStatusDO>()
                .lambda()
                .eq(TaskCompletionStatusDO::getExeType, 1)
                .eq(TaskCompletionStatusDO::getTreeId, studentDoneInfoRequestVO.getTreeId())
                .eq(TaskCompletionStatusDO::getSubjectTaskId, studentDoneInfoRequestVO.getTaskId()));
        List<String> userIds = Arrays.asList(eem.getStudentIds().split(","));

        int rightCounts = 0;
        int avgLength = 0;
        int useLength = 0;
        BigDecimal totalRights = new BigDecimal(0);
        //完成度明细 + 班级总正确数,总用时
        GetClassExeDoneInfoRequestVO getClassExeDoneInfoRequestVO = new GetClassExeDoneInfoRequestVO();
        getClassExeDoneInfoRequestVO.setTreeId(studentDoneInfoRequestVO.getTreeId());
        getClassExeDoneInfoRequestVO.setUserId(studentDoneInfoRequestVO.getUserId());
        getClassExeDoneInfoRequestVO.setTaskId(studentDoneInfoRequestVO.getTaskId());
        getClassExeDoneInfoRequestVO.setUserIds(userIds);
        List<GetClassExeDoneInfoResponseVO> getClassExeDoneInfoResponseVOS = exerciseDoneHistoryMapper.getExpandingExeDoneInfo(getClassExeDoneInfoRequestVO);
        for (GetClassExeDoneInfoResponseVO getClassExeDoneInfoResponseVO : getClassExeDoneInfoResponseVOS) {
            rightCounts += getClassExeDoneInfoResponseVO.getResult();
            useLength += Integer.valueOf(getClassExeDoneInfoResponseVO.getLength());
            totalRights = totalRights.add(new BigDecimal(getClassExeDoneInfoResponseVO.getClassResult()));
            avgLength += Integer.valueOf(getClassExeDoneInfoResponseVO.getClassLength());
            getClassExeDoneInfoResponseVO.setClassResult(MathUtil.getPercentAvgIndex(new BigDecimal(getClassExeDoneInfoResponseVO.getClassResult()), new BigDecimal(submitCounts)));
            getClassExeDoneInfoResponseVO.setClassLength(Integer.valueOf(MathUtil.getAvgIndex(new BigDecimal(getClassExeDoneInfoResponseVO.getClassLength()), new BigDecimal(submitCounts))));
            getClassExeDoneInfoResponseVO.setLabel(this.labels(getClassExeDoneInfoResponseVO.getTreeId()));
        }
        studentDoneInfoResponseVO.setStudentDoneDetailVOS(getClassExeDoneInfoResponseVOS);

        //用时
        studentDoneInfoResponseVO.setUseLength(useLength);

        //正确率==>做对个数
        studentDoneInfoResponseVO.setRightCounts(rightCounts);

        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        //提交时间
        LocalDateTime date = taskCompletionStatusMapper.selectOne(new QueryWrapper<TaskCompletionStatusDO>()
                .lambda()
                .eq(TaskCompletionStatusDO::getUserId, studentDoneInfoRequestVO.getUserId())
                .eq(TaskCompletionStatusDO::getTreeId, studentDoneInfoRequestVO.getTreeId())
                .eq(TaskCompletionStatusDO::getExeType, 1)).getCreateDate();

        String createDate = dateTimeFormatter.format(date);
        studentDoneInfoResponseVO.setSubmitTime(createDate);
        //平均用时
        studentDoneInfoResponseVO.setAvgUseLength(Integer.valueOf(MathUtil.getAvgIndex(new BigDecimal(avgLength), new BigDecimal(submitCounts))));

        //平均正确率
        String avgRights = MathUtil.getPercentAvgIndex(totalRights, (new BigDecimal(exerciseCounts).multiply(new BigDecimal(submitCounts))));
        studentDoneInfoResponseVO.setAvgRightPercent(avgRights);
        return studentDoneInfoResponseVO;
    }

    public PerStudentExesResponseVO perStudentExpandingExes(PerStudentExesRequestVO perStudentExesRequestVO) {

        PerStudentExesResponseVO perStudentExesResponseVO = new PerStudentExesResponseVO();

        ExerciseExpandMappingDO exerciseExpandMapping = exerciseExpandMappingMapper.selectById(perStudentExesRequestVO.getTreeId());

        //该作业总人数
        List<String> totalCounts = Arrays.asList(exerciseExpandMapping.getStudentIds().split(","));
        perStudentExesResponseVO.setTotalCount(totalCounts.size());

        //提交人数
        Integer submitCounts = taskCompletionStatusMapper.selectCount(new QueryWrapper<TaskCompletionStatusDO>()
                .lambda()
                .eq(TaskCompletionStatusDO::getExeType, 1)
                .eq(TaskCompletionStatusDO::getSubjectTaskId, perStudentExesRequestVO.getTaskId())
                .eq(TaskCompletionStatusDO::getTreeId, perStudentExesRequestVO.getTreeId()));
        perStudentExesResponseVO.setSubmitCount(submitCounts);

        int totalRithts = 0;
        int totalLength = 0;

        //题目个数
        int exeCounts = exerciseExpandMapping.getExerciseIds().split(",").length;

        //完成度明细
        perStudentExesRequestVO.setUserIds(totalCounts);
        List<PerStuExeDoneResponseVO> perStuExeDoneResponseVOS = exerciseDoneHistoryMapper.perStudentExpandingExes(perStudentExesRequestVO);
        for (PerStuExeDoneResponseVO psed : perStuExeDoneResponseVOS) {
            totalRithts += psed.getRightCounts();
            totalLength += psed.getLength();
            psed.setTotalCounts(exeCounts);
        }
        perStudentExesResponseVO.setPerStuExeDoneResponseVOS(perStuExeDoneResponseVOS);

        //正确率  +    平均用时
        if (submitCounts != 0) {
            BigDecimal bigDecimal1 = new BigDecimal(totalRithts).multiply(new BigDecimal(100)).divide((new BigDecimal(submitCounts).multiply(new BigDecimal(exeCounts))), RoundingMode.CEILING);
            perStudentExesResponseVO.setRightPercent(bigDecimal1);
            BigDecimal bigDecimal = new BigDecimal(totalLength).divide(new BigDecimal(submitCounts), RoundingMode.CEILING);
            perStudentExesResponseVO.setAvgUseTimes(bigDecimal);
        }


        return perStudentExesResponseVO;
    }

    public List<GetVodDetailResponseVO> getRecommendVodByTreeId(GetRecommendVodByTreeIdVO getRecommendVodByTreeIdVO) {
        List<GetVodDetailResponseVO> getVodDetailResponseVOS = new ArrayList<>();
        List<Integer> relatedVods = JSON.parseArray(getRecommendVodByTreeIdVO.getTreeIds(), Integer.class);

        getRecommendVodByTreeIdVO.setTreeIdInteger(relatedVods);

        List<VodDictDO> vodDicts = vodDictMapper.getRecommendVodByTreeId(getRecommendVodByTreeIdVO);
        for (VodDictDO vodDict : vodDicts) {
            GetVodDetailResponseVO getVodDetailResponseVO = new GetVodDetailResponseVO();
            BeanUtils.copyProperties(vodDict, getVodDetailResponseVO);
            getVodDetailResponseVO.setLengthSecond(vodDict.getVodLength());
            AdministerDO vodUserAlias = administerMapper.selectById(vodDict.getAdministerId());
            if (vodUserAlias != null) {
                getVodDetailResponseVO.setUserName(vodUserAlias.getUserName());
            }
            getVodDetailResponseVOS.add(getVodDetailResponseVO);
        }
        return getVodDetailResponseVOS;
    }

    public List<GetExercisesInfoByIdsResponseVO> getRecommendExeByTreeId(GetRecommendExeByTreeIdVO getRecommendExeByTreeIdVO) {

        List<GetExercisesInfoByIdsResponseVO> getExercisesInfoByIdsResponseVOS = new ArrayList<>();
        List<Integer> relatedExes = JSON.parseArray(getRecommendExeByTreeIdVO.getTreeIds(), Integer.class);

        for (Integer integer : relatedExes) {
            GetExercisesInfoByIdsResponseVO getExercisesInfoByIdsResponseVO = new GetExercisesInfoByIdsResponseVO();

            List<ExerciseDictDO> exerciseDicts = exerciseTreeMappingMapper.getRelatedExercise(integer);
            if (exerciseDicts.size() == 0) {
                continue;
            }
            getExercisesInfoByIdsResponseVO.setExeCounts(exerciseDicts.size());
            int len = 0;
            for (ExerciseDictDO ed : exerciseDicts) {
                len += ed.getAdviceLength();
            }
            getExercisesInfoByIdsResponseVO.setTreeId(integer);
            getExercisesInfoByIdsResponseVO.setLength(MathUtil.exerciseLength(len));
            getExercisesInfoByIdsResponseVO.setLengthSecond(len);
            SubjectTreeDO knowledgeTree = subjectTreeMapper.selectById(integer);
            if (knowledgeTree != null) {
                getExercisesInfoByIdsResponseVO.setLabel(knowledgeTree.getTreeName());
            }
            getExercisesInfoByIdsResponseVOS.add(getExercisesInfoByIdsResponseVO);
        }
        return getExercisesInfoByIdsResponseVOS;
    }

    public List<SubjectTreeDO> allNodes(SubjectTreeDO knowledgeTree) {

        //SubjectTreeDO subjectTreeDO1 = subjectTreeMapper.selectById(knowledgeTree.getId());

        //获取某科目下的所有父节点
        List<SubjectTreeDO> knowledgeTrees = subjectTreeMapper.selectList(new QueryWrapper<SubjectTreeDO>()
                .lambda()
                .eq(SubjectTreeDO::getSubjectId, knowledgeTree.getSubjectId())
                .isNull(SubjectTreeDO::getParentId));

        //只展示三级节点

        for (SubjectTreeDO kn : knowledgeTrees) {
            //二级节点
            List<SubjectTreeDO> subjectTreeDOS = subjectTreeMapper.selectList(new QueryWrapper<SubjectTreeDO>()
                    .lambda()
                    .eq(SubjectTreeDO::getParentId, kn.getId()));
            kn.setChildren(subjectTreeDOS);

            for (SubjectTreeDO subjectTreeDO : subjectTreeDOS) {
                List<SubjectTreeDO> subjectTreeDOS1 = subjectTreeMapper.selectList(new QueryWrapper<SubjectTreeDO>()
                        .lambda()
                        .eq(SubjectTreeDO::getParentId, subjectTreeDO.getId()));
                subjectTreeDO.setChildren(subjectTreeDOS1);
            }
            //kn.setChildren(getChildNodes(kn));
        }

        return knowledgeTrees;
    }

    public List<UserRoleDO> getClassStudents(GetClassStudentsDTO getClassStudentsDTO) {
        return this.baseMapper.getClassStudents(getClassStudentsDTO);
    }

    public List<ExerciseDictDO> queryTaskRelatedExercise(TaskContentDO taskContentDO){
        ExerciseRelatedMappingDO exerciseRelatedMappingDO =exerciseRelatedMappingMapper.selectById(taskContentDO.getContentId());
        return exerciseDictMapper.selectBatchIds(Arrays.asList(exerciseRelatedMappingDO.getExerciseIds().split(",")));
    }


    /**
     * 关联习题处理
     */
    public void data(){

        List<TaskContentDO> taskContentDOS = taskContentMapper.selectList(new QueryWrapper<TaskContentDO>()
        .lambda()
        .eq(TaskContentDO::getContentType,"1")
        .isNull(TaskContentDO::getDeleteDate));

        for (TaskContentDO taskContentDO : taskContentDOS){

            ExerciseRelatedMappingDO exerciseRelatedMappingDO = new ExerciseRelatedMappingDO();

            exerciseRelatedMappingDO.setTaskId(taskContentDO.getTaskId());
            exerciseRelatedMappingDO.setTreeId(taskContentDO.getContentId());

            ClassSubjectTaskDO classSubjectTaskDO = classSubjectTaskMapper.selectById(taskContentDO.getTaskId());
            if (null != classSubjectTaskDO){
                //exerciseRelatedMappingDO.setExerciseName(classSubjectTaskDO.getTreeName());
                SubjectTreeDO subjectTreeDO = subjectTreeMapper.selectById(taskContentDO.getContentId());
                exerciseRelatedMappingDO.setExerciseName(subjectTreeDO.getTreeName());

                //班级里的人
                List<ClassesUserMappingDO> classesUserMappingDOS = classesUserMappingMapper.selectList(new QueryWrapper<ClassesUserMappingDO>()
                        .lambda()
                        .eq(ClassesUserMappingDO::getClassesId,classSubjectTaskDO.getClassId()));

                if (classesUserMappingDOS.size()>0){
                    StringBuilder temp = new StringBuilder();

                    for (ClassesUserMappingDO classesUserMappingDO : classesUserMappingDOS){
                        temp.append(classesUserMappingDO.getUserId());
                        temp.append(",");
                    }

                    String stuentIds = temp.toString().substring(0,temp.length()-1);
                    exerciseRelatedMappingDO.setStudentIds(stuentIds);
                }

                //题目去重
                Set<String> sets = new HashSet<>();
                List<ExerciseDoneHistoryDO> exerciseDoneHistoryDOS = exerciseDoneHistoryMapper.selectList(new QueryWrapper<ExerciseDoneHistoryDO>()
                        .lambda()
                        .eq(ExerciseDoneHistoryDO::getTaskSubjectId,taskContentDO.getTaskId())
                        .eq(ExerciseDoneHistoryDO::getContentId,taskContentDO.getContentId()));
                if (exerciseDoneHistoryDOS.size()>0){
                    for (ExerciseDoneHistoryDO exerciseDoneHistoryDO : exerciseDoneHistoryDOS){
                        sets.add(String.valueOf(exerciseDoneHistoryDO.getExerciseId()));
                    }

                    StringBuilder stringBuilder = new StringBuilder();
                    for (String str : sets){
                        stringBuilder.append(str);
                        stringBuilder.append(",");
                    }
                    String exerciseids = stringBuilder.toString().substring(0,stringBuilder.length()-1);
                    exerciseRelatedMappingDO.setExerciseIds(exerciseids);
                }
                exerciseRelatedMappingMapper.insert(exerciseRelatedMappingDO);

                //更新history的contentId
                ExerciseDoneHistoryDO exerciseDoneHistoryDO = new ExerciseDoneHistoryDO();
                exerciseDoneHistoryDO.setContentId(exerciseRelatedMappingDO.getId());
                exerciseDoneHistoryMapper.update(exerciseDoneHistoryDO,new QueryWrapper<ExerciseDoneHistoryDO>()
                        .lambda()
                        .eq(ExerciseDoneHistoryDO::getContentId,taskContentDO.getContentId())
                        .eq(ExerciseDoneHistoryDO::getTaskSubjectId,taskContentDO.getTaskId()));

                //task_completion_status
                TaskCompletionStatusDO taskCompletionStatusDO = new TaskCompletionStatusDO();
                taskCompletionStatusDO.setTreeId(exerciseRelatedMappingDO.getId());
                taskCompletionStatusMapper.update(taskCompletionStatusDO,new QueryWrapper<TaskCompletionStatusDO>()
                .lambda()
                .eq(TaskCompletionStatusDO::getSubjectTaskId,taskContentDO.getTaskId())
                .eq(TaskCompletionStatusDO::getExeType,0)
                .eq(TaskCompletionStatusDO::getTreeId,taskContentDO.getContentId()));

                //task_content_done_info
                TaskContentDoneInfoDO taskContentDoneInfoDO = new TaskContentDoneInfoDO();
                taskContentDoneInfoDO.setContentId(exerciseRelatedMappingDO.getId());
                taskContentDoneInfoMapper.update(taskContentDoneInfoDO,new QueryWrapper<TaskContentDoneInfoDO>()
                .lambda()
                .eq(TaskContentDoneInfoDO::getTaskId,taskContentDO.getTaskId())
                .eq(TaskContentDoneInfoDO::getContentType,1)
                .eq(TaskContentDoneInfoDO::getContentId,taskContentDO.getContentId()));

                //更新taskContent的contentId
                taskContentDO.setContentId(exerciseRelatedMappingDO.getId());
                taskContentMapper.updateById(taskContentDO);
            }

        }
    }


    ///**
    // *  遍历子节点并赋值
    // */
    //public List<SubjectTreeDO> getChildNodes(SubjectTreeDO knowledgeTree) {
    //
    //    //查找该父节点下的子节点
    //    List<SubjectTreeDO> knowledgeTrees = subjectTreeMapper.selectList(new QueryWrapper<SubjectTreeDO>()
    //            .lambda()
    //            .eq(SubjectTreeDO::getParentId, knowledgeTree.getId())
    //            .orderByAsc(SubjectTreeDO::getTreeOrder));
    //
    //    for (SubjectTreeDO kn : knowledgeTrees) {
    //        kn.setChildren(getChildNodes(kn));
    //    }
    //    if (knowledgeTrees.size() == 0) {
    //        return null;
    //    }
    //    return knowledgeTrees;
    //}

    /**
     * 获取某个班级的学生人数
     *
     * @return
     */
    public Integer getClassStuCounts(Integer classId) {
        return classesUserMappingMapper.selectCount(new QueryWrapper<ClassesUserMappingDO>()
                .lambda()
                .eq(ClassesUserMappingDO::getClassesId, classId));
    }

    private GetPreTaskContentVO getTaskContents(ClassSubjectTaskDO cst) {
        GetPreTaskContentVO getPreTaskIdResponseVO = new GetPreTaskContentVO();

        List<TaskContentDO> taskContents = taskContentMapper.selectList(new QueryWrapper<TaskContentDO>()
                .lambda()
                .eq(TaskContentDO::getTaskId, cst.getId()));
        if (taskContents.size() > 0) {
            //微视频
            List<Integer> vodIntegers = new ArrayList<>();
            //关联习题
            List<Integer> relateIds = new ArrayList<>();
            //书面作业
            List<Integer> homeIntegers = new ArrayList<>();
            for (TaskContentDO tc : taskContents) {
                if (tc.getContentType() == 0) {
                    vodIntegers.add(tc.getContentId());
                }
                if (tc.getContentType() == 1) {
                    relateIds.add(tc.getContentId());
                }
                if (tc.getContentType() == 3) {
                    homeIntegers.add(tc.getContentId());
                }
            }
            //微视频列表
            if (vodIntegers.size() > 0) {
                List<PreVodInfoVO> preVodInfoVOS = new ArrayList<>();
                List<VodDictDO> vodDicts = vodDictMapper.selectBatchIds(vodIntegers);
                for (VodDictDO vodDict : vodDicts) {
                    PreVodInfoVO preVodInfoVO = new PreVodInfoVO();
                    BeanUtils.copyProperties(vodDict, preVodInfoVO);
                    AdministerDO administerDO = administerMapper.selectById(vodDict.getAdministerId());

                    if (null != administerDO) {
                        preVodInfoVO.setTeacherName(administerDO.getUserName());
                    }
                    //preVodInfoVO.setTreeId(vodDict.getTreeId());
                    preVodInfoVO.setLength(MathUtil.vodLength(vodDict.getVodLength()));
                    preVodInfoVO.setLengthSecond(vodDict.getVodLength());
                    preVodInfoVO.setVodId(vodDict.getId());
                    preVodInfoVOS.add(preVodInfoVO);
                }
                getPreTaskIdResponseVO.setPreVodInfoVOS(preVodInfoVOS);
            }


            //关联习题
//            String ids[] = cst.getTreeId().split(",");
            List<PreRelateExeVO> preRelateExeVOS = new ArrayList<>();
            for (Integer str : relateIds) {
                ExerciseRelatedMappingDO exerciseRelatedMappingDO = exerciseRelatedMappingMapper.selectById(str);
                List<ExerciseDictDO> relatedExes = exerciseDictMapper.selectBatchIds(Arrays.asList(exerciseRelatedMappingDO.getExerciseIds().split(",")));
                PreRelateExeVO preRelateExeVO = new PreRelateExeVO();
                preRelateExeVO.setExeCounts(relatedExes.size());
                preRelateExeVO.setTreeName(subjectTreeMapper.selectById(exerciseRelatedMappingDO.getTreeId()).getTreeName());
                int length = 0;
                for (ExerciseDictDO ed : relatedExes) {
                    length += ed.getAdviceLength();
                }
                preRelateExeVO.setTreeId(Integer.valueOf(str));
                preRelateExeVO.setLength(MathUtil.exerciseLength(length));
                preRelateExeVO.setLengthSecond(length);
                preRelateExeVOS.add(preRelateExeVO);
            }
            getPreTaskIdResponseVO.setPreRelateExeVOS(preRelateExeVOS);

            //书面作业
            PreHomeWorkInfoVO preHomeWorkInfoVO = new PreHomeWorkInfoVO();
            if (homeIntegers.size() > 0) {
                List<WrittenHomeworkDO> writtenHomeworks = writtenHomeworkMapper.selectBatchIds(homeIntegers);
                List<WrittenHomeworkDO> whs = new ArrayList<>();
                for (WrittenHomeworkDO writtenHomework : writtenHomeworks) {
                    if (writtenHomework.getHomeworkType() == 2) {
                        preHomeWorkInfoVO.setNotice(writtenHomework.getHomeworkContent());
                    } else {
                        writtenHomework.setHomeworkContent(URLDecoder.decode(writtenHomework.getHomeworkContent()));
                        whs.add(writtenHomework);
                    }
                    preHomeWorkInfoVO.setLengthSecond(writtenHomework.getAdviceLength());
                    preHomeWorkInfoVO.setFileName(writtenHomework.getFileName());
                }
                preHomeWorkInfoVO.setWrittenHomeworks(whs);
                preHomeWorkInfoVO.setLength(MathUtil.exerciseLength(writtenHomeworks.get(0).getAdviceLength()));

                preHomeWorkInfoVO.setHomeworksCounts(writtenHomeworks.size());
                getPreTaskIdResponseVO.setPreHomeWorkInfoVO(preHomeWorkInfoVO);
            }
            //知识点
//            List<String> treeIds = Arrays.asList(cst.getTreeId().split(","));
//            List<KnowledgeTree> knowledgeTrees = knowledgeTreeMapper.selectBatchIds(treeIds);
//            getPreTaskIdResponseVO.setKnowledgeTrees(knowledgeTrees);
        }

        //拓展习题
        List<PreExpandExerciseVO> preExpandExerciseVOS = new ArrayList<>();
        QueryWrapper queryWrapper1 = new QueryWrapper();
        queryWrapper1.eq("task_id", cst.getId());
        List<ExerciseExpandMappingDO> exerciseExpandMappings = exerciseExpandMappingMapper.selectList(queryWrapper1);
        for (ExerciseExpandMappingDO eem : exerciseExpandMappings) {
            PreExpandExerciseVO preExpandExerciseVO = new PreExpandExerciseVO();
            int length = 0;
            String[] exerciseIds = eem.getExerciseIds().split(",");
            for (String str : exerciseIds) {
                length += exerciseDictMapper.selectById(str).getAdviceLength();
            }
            preExpandExerciseVO.setExerciseCounts(exerciseIds.length);
            preExpandExerciseVO.setLength(MathUtil.exerciseLength(length));
            String[] studentIds = eem.getStudentIds().split(",");
            preExpandExerciseVO.setTreeId(eem.getId());
            preExpandExerciseVO.setExpandExerciseNames(eem.getExerciseName());
            preExpandExerciseVO.setStudentCounts(studentIds.length);
            preExpandExerciseVO.setLengthSecond(length);
            preExpandExerciseVOS.add(preExpandExerciseVO);
        }
        getPreTaskIdResponseVO.setPreExpandExerciseVOS(preExpandExerciseVOS);

        getPreTaskIdResponseVO.setTaskType(cst.getTaskType());
        UserRoleDO userRole = userRoleMapper.selectById(cst.getTeacherId());
        getPreTaskIdResponseVO.setTeacherName(userRole != null ? userRole.getUserName() : null);
        getPreTaskIdResponseVO.setTaskId(cst.getId());
        return getPreTaskIdResponseVO;
    }


    public void pushMsg(PushMsgPO pushMsgPO, String token) {

        String msgUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + token;

        String input = "{\n" +
                "    \"touser\":\"" + pushMsgPO.getOpenId() + "\",\n" +
                "    \"template_id\":\"" + wechatConfig.getTemplateId() + "\",\n" +
                "    \"url\":\"" + wechatConfig.getMsgUrl() + "\",\n" +
                "    \"data\":{\n" +
                "        \"first\":{\n" +
                "            \"value\":\"" + pushMsgPO.getTitle() + "\",\n" +
                "            \"color\":\"#173177\"\n" +
                "        },\n" +
                "        \"keyword1\":{\n" +
                "            \"value\":\"" + pushMsgPO.getSchool() + "\",\n" +
                "            \"color\":\"#173177\"\n" +
                "        },\n" +
                "        \"keyword2\":{\n" +
                "            \"value\":\"" + pushMsgPO.getTeacherName() + "\",\n" +
                "            \"color\":\"#173177\"\n" +
                "        },\n" +
                "        \"keyword3\":{\n" +
                "            \"value\":\"" + pushMsgPO.getTaskName() + "\",\n" +
                "            \"color\":\"#173177\"\n" +
                "        },\n" +
                "        \"keyword4\":{\n" +
                "            \"value\":\"" + pushMsgPO.getDateTime() + "\",\n" +
                "            \"color\":\"#173177\"\n" +
//                "        },\n" +
//                "        \"remark\":{\n" +
//                "            \"value\":\""+pushMsgPO.getRemark()+"\",\n" +
//                "            \"color\":\"#173177\"\n" +
                "        }\n" +
                "    }\n" +
                "}";


        HttpHeaders headers = new HttpHeaders();

        ResponseEntity<PushMsgVO> responseEntity = restTemplateConfig.restTemplate()
                .exchange(msgUrl, HttpMethod.POST, new HttpEntity<>(input.getBytes(), headers), PushMsgVO.class);
    }

    //新增微视频 书面作业  关联习题  拓展习题
    public void addTaskContents(PublishTasksDTO publishTasksDTO, Integer taskId,Integer classId,String taskName) {

            //保存微视频作业
            String[] vodIds = publishTasksDTO.getVodIds().split(",");
            if (!StringUtils.isEmpty(publishTasksDTO.getVodIds()) && vodIds.length > 0) {
                for (String integer : vodIds) {
                    TaskContentDO tc = new TaskContentDO();
                    tc.setTaskId(taskId);
                    tc.setContentType(0);
                    tc.setContentId(Integer.valueOf(integer));
                    tc.setCreateDate(LocalDateTime.now());
                    tc.setUpdateDate(LocalDateTime.now());
                    taskContentMapper.insert(tc);
                }
            }

            //保存关联习题
            //关联知识点
//            String[] treeIds = publishTasksRequestVO.getTreeIds().split(",");
            //老师布置的关联习题
            List<String> relatedIds = Arrays.asList(publishTasksDTO.getRelatedIds().split(","));
            if (!StringUtils.isEmpty(publishTasksDTO.getRelatedIds()) && relatedIds.size() > 0) {
                for (String integer : relatedIds) {
                    //布置关联习题
                    ExerciseRelatedMappingDO exerciseRelatedMappingDO = new ExerciseRelatedMappingDO();
                    exerciseRelatedMappingDO.setTaskId(taskId);
                    exerciseRelatedMappingDO.setTreeId(Integer.valueOf(integer));
                    exerciseRelatedMappingDO.setExerciseName(taskName);

                    List<ExerciseTreeMappingDO> exerciseTreeMappingDOS = exerciseTreeMappingMapper.selectList(new QueryWrapper<ExerciseTreeMappingDO>()
                    .lambda()
                    .eq(ExerciseTreeMappingDO::getTreeId,integer)
                    .eq(ExerciseTreeMappingDO::getStatus,1));

                    StringBuilder stringBuilder = new StringBuilder();

                    for (ExerciseTreeMappingDO exerciseTreeMappingDO : exerciseTreeMappingDOS){
                        stringBuilder.append(exerciseTreeMappingDO.getExerciseId());
                        stringBuilder.append(",");
                    }
                    String exerciseIds = stringBuilder.toString().substring(0,stringBuilder.length()-1);
                    exerciseRelatedMappingDO.setExerciseIds(exerciseIds);


                    List<ClassesUserMappingDO> classesUserMappingDOS = classesUserMappingMapper.selectList(new QueryWrapper<ClassesUserMappingDO>()
                            .lambda()
                            .eq(ClassesUserMappingDO::getClassesId,classId));
                    StrBuilder strBuilder = new StrBuilder();
                    for (ClassesUserMappingDO classesUserMappingDO : classesUserMappingDOS){
                        strBuilder.append(classesUserMappingDO.getUserId());
                        strBuilder.append(",");
                    }
                    String userIds = strBuilder.toString().substring(0,strBuilder.length()-1);
                    exerciseRelatedMappingDO.setStudentIds(userIds);
                    exerciseRelatedMappingMapper.insert(exerciseRelatedMappingDO);

                    TaskContentDO tc = new TaskContentDO();
                    tc.setTaskId(taskId);
                    tc.setContentType(1);
                    tc.setContentId(exerciseRelatedMappingDO.getId());
                    tc.setCreateDate(LocalDateTime.now());
                    tc.setUpdateDate(LocalDateTime.now());
                    taskContentMapper.insert(tc);

                }
            }




            //拓展习题
            List<PublishExpandingVO> publishExpandingVOS = publishTasksDTO.getPublishExpandingVOS();
            if (publishExpandingVOS.size() > 0) {
                for (PublishExpandingVO pev : publishExpandingVOS) {
                    ExerciseExpandMappingDO eem = new ExerciseExpandMappingDO();
                    eem.setTaskId(taskId);
                    eem.setExerciseIds(pev.getExpandingExeIds());
                    eem.setStudentIds(pev.getExpandingStudents());
                    eem.setExerciseName(pev.getExpandingName());
                    eem.setCreateDate(LocalDateTime.now());
                    eem.setUpdateDate(LocalDateTime.now());
                    exerciseExpandMappingMapper.insert(eem);
                    TaskContentDO taskContent = new TaskContentDO();
                    taskContent.setTaskId(taskId);
                    taskContent.setContentType(2);
                    taskContent.setContentId(eem.getId());
                    taskContent.setCreateDate(LocalDateTime.now());
                    taskContent.setUpdateDate(LocalDateTime.now());
                    taskContentMapper.insert(taskContent);
                }

            }

            //附件作业
            List<PublishHomeworkVO> publishHomeworkVOS = publishTasksDTO.getPublishHomeworkVOS();
            if (publishHomeworkVOS.size() > 0) {
                for (PublishHomeworkVO phk : publishHomeworkVOS) {
                    WrittenHomeworkDO writtenHomework = new WrittenHomeworkDO();
                    writtenHomework.setHomeworkType(phk.getHomeworkType());
                    writtenHomework.setHomeworkContent(phk.getHomeworkContent());
                    writtenHomework.setFileName(phk.getFileName());
                    writtenHomework.setAdviceLength(publishTasksDTO.getAdviceLength());
                    writtenHomework.setFileSize(phk.getFileSize());
                    writtenHomework.setFileType(phk.getFileType());
                    writtenHomework.setCreateDate(LocalDateTime.now());
                    writtenHomework.setUpdateDate(LocalDateTime.now());
                    writtenHomeworkMapper.insert(writtenHomework);
                    TaskContentDO taskContent = new TaskContentDO();
                    taskContent.setContentType(3);
                    taskContent.setTaskId(taskId);
                    taskContent.setContentId(writtenHomework.getId());
                    taskContent.setUpdateDate(LocalDateTime.now());
                    taskContent.setCreateDate(LocalDateTime.now());
                    taskContentMapper.insert(taskContent);
                }
            }

    }

    public String labels(String ids) {
        StringBuilder sb = new StringBuilder();
        if (!StringUtils.isEmpty(ids)) {
            String[] arr = ids.split(",");
            if (arr.length > 0) {
                for (String str : arr) {
                    SubjectTreeDO knowledgeTree = subjectTreeMapper.selectById(str);
                    if (null != knowledgeTree) {
                        sb.append(knowledgeTree.getTreeName()).append(";");
                    }
                }
                return sb.substring(0, sb.length() - 1);
            } else {
                return "";
            }
        } else {
            return "";
        }

    }

}