MemberServiceImpl.java 48.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
package com.subsidy.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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.common.configure.QXueYouConfig;
import com.subsidy.common.exception.HttpException;
import com.subsidy.dto.administer.VerifyCodeDTO;
import com.subsidy.dto.member.*;
import com.subsidy.mapper.*;
import com.subsidy.model.*;
import com.subsidy.service.MemberService;
import com.subsidy.util.*;
import com.subsidy.vo.administer.UserRoleVO;
import com.subsidy.vo.member.*;
import com.subsidy.vo.paper.QueryPapersVO;
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

//import com.subsidy.util.RedisUtil;

/**
 * <p>
 * 学生表 服务实现类
 * </p>
 *
 * @author DengMin
 * @since 2021-10-11
 */
@Service
public class MemberServiceImpl extends ServiceImpl<MemberMapper, MemberDO> implements MemberService {

    @Autowired
    private CourseContentMapper courseContentMapper;

    @Autowired
    private VodPlayHistoryMapper vodPlayHistoryMapper;

    @Autowired
    private FileDictMapper fileDictMapper;

    @Autowired
    private ExerciseDoneResultMapper exerciseDoneResultMapper;

    @Autowired
    private ClassMemberMappingMapper classMemberMappingMapper;

    @Autowired
    private PaperDictMapper paperDictMapper;

    @Autowired
    private ClassDictMapper classDictMapper;

    @Autowired
    private MemberDepartmentMappingMapper memberDepartmentMappingMapper;

    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    private CourseFieldMappingMapper courseFieldMappingMapper;

    @Autowired
    private CompanyDictMapper companyDictMapper;

    @Autowired
    private OprMemDictMapper oprMemDictMapper;

    @Autowired
    private JobDictMapper jobDictMapper;

    @Autowired
    private JobMemberMappingMapper jobMemberMappingMapper;

    @Autowired
    private DepartmentDictMapper departmentDictMapper;

    @Autowired
    private RotationImgDictMapper rotationImgDictMapper;

    @Autowired
    private ImageCheckRecordMapper imageCheckRecordMapper;

    @Autowired
    private SmsVerifyCodeMapper smsVerifyCodeMapper;

    @Autowired
    private ClassHourDictMapper classHourDictMapper;

    @Autowired
    private QXueYouConfig qXueYouConfig;

    public IPage<GetAllVO> getAll(GetAllDTO getAllDTO) {
        Page pager = new Page(getAllDTO.getPageNum(), getAllDTO.getPageSize());

        DepartmentDictDO departmentDictDO = departmentDictMapper.selectById(getAllDTO.getDepartmentId());

        IPage iPage = null;

        if (null != departmentDictDO.getParentId()) {
            iPage = this.baseMapper.getMembers(pager, getAllDTO.getDepartmentId(), getAllDTO.getUserName(), getAllDTO.getStatus(), getAllDTO.getStartDate(), getAllDTO.getEndDate());
        } else {
            iPage = this.baseMapper.getCompanyMember(pager, departmentDictDO.getCompanyId(), getAllDTO.getUserName(), getAllDTO.getStatus(), getAllDTO.getStartDate(), getAllDTO.getEndDate());
        }

        List<GetAllVO> getAllVOS = iPage.getRecords();
        for (GetAllVO getAllVO : getAllVOS) {
            //获取这个人所在的部门
            List<DepartmentDictDO> departmentDictDOS = this.baseMapper.getDepartments(getAllVO.getId());
            getAllVO.setDepartmentDictDOS(departmentDictDOS);

            //获取这个人所在的岗位
            List<JobDictDO> jobDictDOS = jobDictMapper.queryMemberJobs(getAllVO.getId());
            getAllVO.setJobDictDOS(jobDictDOS);
        }
        return iPage;
    }

    @Transactional(rollbackFor = Exception.class)
    public String deleteMember(MemberDO memberDO) {

        this.baseMapper.deleteById(memberDO.getId());
        classMemberMappingMapper.delete(new QueryWrapper<ClassMemberMappingDO>()
                .lambda()
                .eq(ClassMemberMappingDO::getMemberId, memberDO.getId()));
        memberDepartmentMappingMapper.delete(new QueryWrapper<MemberDepartmentMappingDO>()
                .lambda()
                .eq(MemberDepartmentMappingDO::getMemberId, memberDO.getId()));
        return ConstantUtils.DELETE_SUCCESS;
    }

    public String addMember(AddMemberDTO addMemberDTO) {

        Integer count = this.baseMapper.selectCount(new QueryWrapper<MemberDO>()
                .lambda()
                .eq(MemberDO::getTelephone, addMemberDTO.getTelephone()));

        if (count > 0) {
            throw new HttpException(20002);
        }

        Integer count1 = this.baseMapper.selectCount(new QueryWrapper<MemberDO>()
                .lambda()
                .eq(MemberDO::getAccountName, addMemberDTO.getAccountName())
                .eq(MemberDO::getCompanyId, addMemberDTO.getCompanyId()));

        if (count1 > 0) {
            throw new HttpException(20002);
        }

        MemberDO memberDO = new MemberDO();
        BeanUtils.copyProperties(addMemberDTO, memberDO);
        memberDO.setPassword("123456");
        memberDO.setStatus("启用");
        memberDO.setFirstLogin(0);
        //公司赋值
        memberDO.setCompanyId(addMemberDTO.getCompanyId());
        this.baseMapper.insert(memberDO);
        //redisUtil.set(RedisPrefixConstant.SUBSIDY_COMPANY_MEMBER_PREFIX + memberDO.getCompanyId() + ":" + memberDO.getAccountName(), memberDO);

        if (null != addMemberDTO.getDepartmentIds()) {
            //部门
            List<Long> longs = addMemberDTO.getDepartmentIds();

            for (Long lg : longs) {
                MemberDepartmentMappingDO memberDepartmentMappingDO = new MemberDepartmentMappingDO();
                memberDepartmentMappingDO.setMemberId(memberDO.getId());
                memberDepartmentMappingDO.setDepartmentId(lg);
                memberDepartmentMappingMapper.insert(memberDepartmentMappingDO);
            }
        }


        if (null != addMemberDTO.getJobIds()) {
            jobMemberMappingMapper.delete(new QueryWrapper<JobMemberMappingDO>()
                    .lambda()
                    .eq(JobMemberMappingDO::getMemberId, addMemberDTO.getId()));

            //岗位
            List<Long> longs = addMemberDTO.getJobIds();
            for (Long lg : longs) {
                JobMemberMappingDO jobMemberMappingDO = new JobMemberMappingDO();
                jobMemberMappingDO.setMemberId(memberDO.getId());
                jobMemberMappingDO.setJobId(lg);
                jobMemberMappingMapper.insert(jobMemberMappingDO);
            }
        }

        return ConstantUtils.ADD_SUCCESS;
    }

    public String updateMember(AddMemberDTO addMemberDTO) {

        Integer count = this.baseMapper.selectCount(new QueryWrapper<MemberDO>()
                .lambda()
                .eq(MemberDO::getTelephone, addMemberDTO.getTelephone())
                .ne(MemberDO::getId, addMemberDTO.getId()));

        if (count > 0) {
            throw new HttpException(20002);
        }

        Integer count1 = this.baseMapper.selectCount(new QueryWrapper<MemberDO>()
                .lambda()
                .eq(MemberDO::getAccountName, addMemberDTO.getAccountName())
                .eq(MemberDO::getCompanyId, addMemberDTO.getCompanyId())
                .ne(MemberDO::getId, addMemberDTO.getId()));

        if (count1 > 0) {
            throw new HttpException(20002);
        }

        MemberDO memberDO = new MemberDO();
        BeanUtils.copyProperties(addMemberDTO, memberDO);
        this.baseMapper.updateById(memberDO);
        //MemberDO memberDO1 = this.baseMapper.selectById(addMemberDTO.getId());
        //redisUtil.set(RedisPrefixConstant.SUBSIDY_COMPANY_MEMBER_PREFIX + memberDO.getCompanyId() + ":" + memberDO.getAccountName(), memberDO1);

        if (null != addMemberDTO.getDepartmentIds()) {
            memberDepartmentMappingMapper.delete(new QueryWrapper<MemberDepartmentMappingDO>()
                    .lambda()
                    .eq(MemberDepartmentMappingDO::getMemberId, addMemberDTO.getId()));

            //部门
            List<Long> longs = addMemberDTO.getDepartmentIds();
            for (Long lg : longs) {
                MemberDepartmentMappingDO memberDepartmentMappingDO = new MemberDepartmentMappingDO();
                memberDepartmentMappingDO.setMemberId(memberDO.getId());
                memberDepartmentMappingDO.setDepartmentId(lg);
                memberDepartmentMappingMapper.insert(memberDepartmentMappingDO);
            }
        }

        if (null != addMemberDTO.getJobIds()) {
            jobMemberMappingMapper.delete(new QueryWrapper<JobMemberMappingDO>()
                    .lambda()
                    .eq(JobMemberMappingDO::getMemberId, addMemberDTO.getId()));

            //岗位
            List<Long> longs = addMemberDTO.getJobIds();
            for (Long lg : longs) {
                JobMemberMappingDO jobMemberMappingDO = new JobMemberMappingDO();
                jobMemberMappingDO.setMemberId(memberDO.getId());
                jobMemberMappingDO.setJobId(lg);
                jobMemberMappingMapper.insert(jobMemberMappingDO);
            }
        }

        return ConstantUtils.SET_SUCCESS;
    }

    @Transactional(rollbackFor = Exception.class)
    public UserRoleVO login(VerifyCodeDTO verifyCodeDTO) {
        UserRoleVO userRoleVO = new UserRoleVO();

        //先从redis里拿   还得从数据库先查公司。。还是直接查人快
        MemberDO memberDO = this.baseMapper.selectOne(new QueryWrapper<MemberDO>()
                .lambda()
                .eq(MemberDO::getTelephone, verifyCodeDTO.getTelephone()));
        if (memberDO == null) {
            throw new HttpException(10010);
        }

        CompanyDictDO companyDictDO = companyDictMapper.selectById(memberDO.getCompanyId());

        if ("冻结".equals(memberDO.getStatus())) {
            OprMemDictDO oprMemDictDO = new OprMemDictDO();
            oprMemDictDO.setUserId(memberDO.getId());
            oprMemDictDO.setOprType("登录");
            oprMemDictDO.setResult(0);
            //oprMemDictDO.setUserName(memberDO.getUserName());
            //oprMemDictDO.setCreateDate(System.currentTimeMillis() + "");
            //oprMemDictDO.setLoginDateFormat(DateFormatUtil.format(new Date(), "yyyyMMdd"));
            //oprMemDictDO.setCompanyId(companyDictDO.getId());
            //oprMemDictDO.setCompanyName(companyDictDO.getCompanyName());
            //mongoTemplate.insert(oprMemDictDO);
            oprMemDictMapper.insert(oprMemDictDO);
            //redisUtil.set(RedisPrefixConstant.SUBSIDY_MEMBER_LOGIN_PREFIX + memberDO.getId() + ":" + memberDO.getUserName() + ":" + companyDictDO.getCompanyName() + ":" + LocalDateTime.now(), oprMemDictDO);
            throw new HttpException(10013);
        }

        //是否登陆过   1:是 0:否
        if (0 == memberDO.getFirstLogin()) {
            memberDO.setFirstLogin(1);
            this.baseMapper.updateById(memberDO);
            //redisUtil.set(RedisPrefixConstant.SUBSIDY_COMPANY_MEMBER_PREFIX + memberDO.getCompanyId() + ":" + memberDO.getAccountName(), memberDO);
        }
        BeanUtils.copyProperties(memberDO, userRoleVO);

        //String code = redisUtil.get(RedisPrefixConstant.SUBSIDY_TELEPHONE_PREFIX + verifyCodeDTO.getTelephone()).toString();
        SmsVerifyCodeDO smsCodeDO = smsVerifyCodeMapper.selectOne(new QueryWrapper<SmsVerifyCodeDO>()
                .lambda()
                .eq(SmsVerifyCodeDO::getTelephone, verifyCodeDTO.getTelephone())
                .eq(SmsVerifyCodeDO::getVerifyCode, verifyCodeDTO.getVerifyCode())
                .gt(SmsVerifyCodeDO::getCreateDate, LocalDateTime.now().minusMinutes(30L)));

        if (null == smsCodeDO || !verifyCodeDTO.getVerifyCode().equals(smsCodeDO.getVerifyCode())) {
            OprMemDictDO oprMemDictDO = new OprMemDictDO();
            oprMemDictDO.setUserId(memberDO.getId());
            oprMemDictDO.setOprType("登录");
            oprMemDictDO.setResult(0);
            //oprMemDictDO.setUserName(memberDO.getUserName());
            //oprMemDictDO.setCreateDate(System.currentTimeMillis() + "");
            //oprMemDictDO.setLoginDateFormat(DateFormatUtil.format(new Date(), "yyyyMMdd"));
            //oprMemDictDO.setCompanyId(companyDictDO.getId());
            //oprMemDictDO.setCompanyName(companyDictDO.getCompanyName());
            //mongoTemplate.insert(oprMemDictDO);
            oprMemDictMapper.insert(oprMemDictDO);
            throw new HttpException(70010);
        }
        //审计日志
        OprMemDictDO oprMemDictDO = new OprMemDictDO();
        oprMemDictDO.setUserId(memberDO.getId());
        oprMemDictDO.setOprType("登录");
        //oprMemDictDO.setUserName(memberDO.getUserName());
        oprMemDictDO.setResult(1);
        //oprMemDictDO.setCreateDate(System.currentTimeMillis() + "");
        //oprMemDictDO.setLoginDateFormat(DateFormatUtil.format(new Date(), "yyyyMMdd"));
        //oprMemDictDO.setCompanyId(companyDictDO.getId());
        //oprMemDictDO.setCompanyName(companyDictDO.getCompanyName());
        oprMemDictMapper.insert(oprMemDictDO);
        //mongoTemplate.insert(oprMemDictDO);
        userRoleVO.setCompanyId(companyDictDO.getId());
        userRoleVO.setSuperviseName(companyDictDO.getSuperviseName());
        userRoleVO.setCompanyName(companyDictDO.getCompanyName());
        userRoleVO.setLogo(companyDictDO.getLogo());
        userRoleVO.setQxyStatus(companyDictDO.getQxyStatus());
        List<RotationImgDictDO> rotationImgDictDOS = rotationImgDictMapper.selectList(new QueryWrapper<RotationImgDictDO>()
                .lambda()
                .eq(RotationImgDictDO::getCompanyId, companyDictDO.getId()));
        userRoleVO.setRotationImgDictDOS(rotationImgDictDOS);

        String token = JwtUtil.generateToken(memberDO.getId(), ConstantUtils.MOBILE_TERMINATE);
        //redisUtil.set(ConstantUtils.MOBILE_TERMINATE + "_" + memberDO.getId(), token);
        Localstorage.setUser(memberDO);
        userRoleVO.setToken(token);
        return userRoleVO;
    }

    public MemberVO passwordLogin(PasswordLoginDTO passwordLoginDTO) {
        /**
         * 先从redis里查
         */
        //MemberDO memberDO = (MemberDO) redisUtil.get(RedisPrefixConstant.SUBSIDY_COMPANY_MEMBER_PREFIX + passwordLoginDTO.getCompanyId() + ":" + passwordLoginDTO.getAccountName());
        MemberDO memberDO = null;
        if (null == memberDO) {
            /**
             * redis里没有,从数据库里查
             */
            memberDO = this.baseMapper.selectOne(new QueryWrapper<MemberDO>()
                    .lambda()
                    .eq(MemberDO::getCompanyId, passwordLoginDTO.getCompanyId())
                    .eq(MemberDO::getAccountName, passwordLoginDTO.getAccountName()));
            if (memberDO == null) {
                throw new HttpException(10017);
            }
        }

        CompanyDictDO companyDictDO = companyDictMapper.selectById(memberDO.getCompanyId());
        if (memberDO.getPassword().equals(passwordLoginDTO.getPassword()) && 1 == memberDO.getFirstLogin() && !"冻结".equals(memberDO.getStatus())) {
            MemberVO memberVO = new MemberVO();
            BeanUtils.copyProperties(memberDO, memberVO);
            memberVO.setCompanyId(companyDictDO.getId());
            memberVO.setCompanyName(companyDictDO.getCompanyName());
            memberVO.setQxyStatus(companyDictDO.getQxyStatus());
            OprMemDictDO oprMemDictDO = new OprMemDictDO();
            oprMemDictDO.setUserId(memberDO.getId());
            oprMemDictDO.setOprType("登录");
            oprMemDictDO.setResult(1);
            //oprMemDictDO.setUserName(memberDO.getUserName());
            //oprMemDictDO.setCreateDate(System.currentTimeMillis() + "");
            //oprMemDictDO.setLoginDateFormat(DateFormatUtil.format(new Date(), "yyyyMMdd"));
            //oprMemDictDO.setCompanyId(companyDictDO.getId());
            //oprMemDictDO.setCompanyName(companyDictDO.getCompanyName());
            //mongoTemplate.insert(oprMemDictDO);
            oprMemDictMapper.insert(oprMemDictDO);
            memberVO.setCompanyId(companyDictDO.getId());
            memberVO.setSuperviseName(companyDictDO.getSuperviseName());
            memberVO.setCompanyName(companyDictDO.getCompanyName());
            memberVO.setLogo(companyDictDO.getLogo());
            List<RotationImgDictDO> rotationImgDictDOS = rotationImgDictMapper.selectList(new QueryWrapper<RotationImgDictDO>()
                    .lambda()
                    .eq(RotationImgDictDO::getCompanyId, companyDictDO.getId()));
            memberVO.setRotationImgDictDOS(rotationImgDictDOS);
            //redisUtil.set(RedisPrefixConstant.SUBSIDY_COMPANY_MEMBER_PREFIX + passwordLoginDTO.getCompanyId() + ":" + passwordLoginDTO.getAccountName(), memberDO);
            //redisUtil.set(RedisPrefixConstant.SUBSIDY_MEMBER_LOGIN_PREFIX + memberDO.getId() + ":" + System.currentTimeMillis(), 1);

            String token = JwtUtil.generateToken(memberDO.getId(), ConstantUtils.MOBILE_TERMINATE);
            //redisUtil.set(ConstantUtils.MOBILE_TERMINATE + "_" + memberDO.getId(), token);
            Localstorage.setUser(memberDO);
            memberVO.setToken(token);
            return memberVO;
        } else {
            if (!memberDO.getPassword().equals(passwordLoginDTO.getPassword())) {
                OprMemDictDO oprMemDictDO = new OprMemDictDO();
                oprMemDictDO.setUserId(memberDO.getId());
                oprMemDictDO.setOprType("登录");
                oprMemDictDO.setResult(0);
                //oprMemDictDO.setUserName(memberDO.getUserName());
                //oprMemDictDO.setCreateDate(System.currentTimeMillis() + "");
                //oprMemDictDO.setLoginDateFormat(DateFormatUtil.format(new Date(), "yyyyMMdd"));
                //oprMemDictDO.setCompanyName(companyDictDO.getCompanyName());
                //oprMemDictDO.setCompanyId(companyDictDO.getId());
                //mongoTemplate.insert(oprMemDictDO);
                oprMemDictMapper.insert(oprMemDictDO);
                //redisUtil.set(RedisPrefixConstant.SUBSIDY_MEMBER_LOGIN_PREFIX + memberDO.getId() + ":" + System.currentTimeMillis(), oprMemDictDO);
                throw new HttpException(10016);
            }

            if (0 == memberDO.getFirstLogin()) {
                OprMemDictDO oprMemDictDO = new OprMemDictDO();
                oprMemDictDO.setUserId(memberDO.getId());
                oprMemDictDO.setOprType("登录");
                oprMemDictDO.setResult(0);
                //oprMemDictDO.setUserName(memberDO.getUserName());
                //oprMemDictDO.setCreateDate(System.currentTimeMillis() + "");
                //oprMemDictDO.setLoginDateFormat(DateFormatUtil.format(new Date(), "yyyyMMdd"));
                //oprMemDictDO.setCompanyName(companyDictDO.getCompanyName());
                //oprMemDictDO.setCompanyId(companyDictDO.getId());
                //mongoTemplate.insert(oprMemDictDO);
                oprMemDictMapper.insert(oprMemDictDO);
                //redisUtil.set(RedisPrefixConstant.SUBSIDY_MEMBER_LOGIN_PREFIX + memberDO.getId() + ":" + System.currentTimeMillis(), 0);
                throw new HttpException(10015);
            }

            if ("冻结".equals(memberDO.getStatus())) {
                throw new HttpException(10014);
            }
        }
        return null;
    }

    //    9a79cda9ef6f4a52a8
//    552a4147db2d4026bc4e9021acd614f8
    public static void main(String[] args) {
        String uuid = UUID.randomUUID().toString().replace("-", "");
        System.out.println(uuid);
    }

    public UserRoleVO qingxuetangLogin(QingxuetangLoginDTO qingxuetangLoginDTO) {

        UserRoleVO userRoleVO = new UserRoleVO();

        /**
         * 轻学堂秘钥
         * appId:b8fc3013c8ce409c90
         * appSecret:90876d91b3b7426c9184437a09358787
         */
        MemberDO memberDO = this.baseMapper.selectOne(new QueryWrapper<MemberDO>()
                .lambda()
                .eq(MemberDO::getTelephone, qingxuetangLoginDTO.getMobile()));

        if (memberDO == null) {
            throw new HttpException(10010);
        }

        /**
         * 时间戳有没有过期
         */
        if (qingxuetangLoginDTO.getTimestamp() - System.currentTimeMillis() >= 5 * 60 * 1000 || System.currentTimeMillis() - qingxuetangLoginDTO.getTimestamp() >= 5 * 60 * 1000) {
            OprMemDictDO oprMemDictDO = new OprMemDictDO();
            oprMemDictDO.setUserId(memberDO.getId());
            oprMemDictDO.setOprType("登录");
            oprMemDictDO.setResult(0);
            oprMemDictMapper.insert(oprMemDictDO);
            throw new HttpException(14002);
        }

        //鉴权逻辑 对不对
        String preAuthen = "";

        if (!StringUtils.isEmpty(qingxuetangLoginDTO.getNickname())) {
            preAuthen = "appId=b8fc3013c8ce409c90&authCorpId=" + qingxuetangLoginDTO.getAuthCorpId()
                    + "&authCorpName=" + qingxuetangLoginDTO.getAuthCorpName()
                    + "&mobile=" + qingxuetangLoginDTO.getMobile()
                    + "&nickname=" + qingxuetangLoginDTO.getNickname()
                    + "&openId=" + qingxuetangLoginDTO.getOpenId()
                    + "&timestamp=" + qingxuetangLoginDTO.getTimestamp()
                    + "&appSecret=90876d91b3b7426c9184437a09358787";
        } else {
            preAuthen = "appId=b8fc3013c8ce409c90&authCorpId=" + qingxuetangLoginDTO.getAuthCorpId()
                    + "&authCorpName=" + qingxuetangLoginDTO.getAuthCorpName()
                    + "&mobile=" + qingxuetangLoginDTO.getMobile()
                    + "&openId=" + qingxuetangLoginDTO.getOpenId()
                    + "&timestamp=" + qingxuetangLoginDTO.getTimestamp()
                    + "&appSecret=90876d91b3b7426c9184437a09358787";
        }

        String result = SecretUtils.getMD5String(preAuthen);
        if (!qingxuetangLoginDTO.getSign().equals(result)) {
            OprMemDictDO oprMemDictDO = new OprMemDictDO();
            oprMemDictDO.setUserId(memberDO.getId());
            oprMemDictDO.setOprType("登录");
            oprMemDictDO.setResult(0);
            oprMemDictMapper.insert(oprMemDictDO);
            throw new HttpException(14001);
        }

        CompanyDictDO companyDictDO = companyDictMapper.selectById(memberDO.getCompanyId());

        if ("冻结".equals(memberDO.getStatus())) {
            OprMemDictDO oprMemDictDO = new OprMemDictDO();
            oprMemDictDO.setUserId(memberDO.getId());
            oprMemDictDO.setOprType("登录");
            oprMemDictDO.setResult(0);
            oprMemDictMapper.insert(oprMemDictDO);
            throw new HttpException(10013);
        }

//        //是否登陆过   1:是 0:否
//        if (0 == memberDO.getFirstLogin()) {
//            OprMemDictDO oprMemDictDO = new OprMemDictDO();
//            oprMemDictDO.setUserId(memberDO.getId());
//            oprMemDictDO.setOprType("登录");
//            oprMemDictDO.setResult(0);
//            oprMemDictMapper.insert(oprMemDictDO);
//            throw new HttpException(10015);
//        }
        BeanUtils.copyProperties(memberDO, userRoleVO);

        //审计日志
        OprMemDictDO oprMemDictDO = new OprMemDictDO();
        oprMemDictDO.setUserId(memberDO.getId());
        oprMemDictDO.setOprType("登录");
        oprMemDictDO.setResult(1);
        oprMemDictMapper.insert(oprMemDictDO);
        userRoleVO.setCompanyId(companyDictDO.getId());
        userRoleVO.setSuperviseName(companyDictDO.getSuperviseName());
        userRoleVO.setCompanyName(companyDictDO.getCompanyName());
        userRoleVO.setLogo(companyDictDO.getLogo());
        userRoleVO.setQxyStatus(companyDictDO.getQxyStatus());
        List<RotationImgDictDO> rotationImgDictDOS = rotationImgDictMapper.selectList(new QueryWrapper<RotationImgDictDO>()
                .lambda()
                .eq(RotationImgDictDO::getCompanyId, companyDictDO.getId()));
        userRoleVO.setRotationImgDictDOS(rotationImgDictDOS);
        String token = JwtUtil.generateToken(memberDO.getId(), ConstantUtils.MOBILE_TERMINATE);
//        redisUtil.set(ConstantUtils.MOBILE_TERMINATE + "_" + memberDO.getId(), token);
        userRoleVO.setToken(token);
        return userRoleVO;
    }

    public UserRoleVO kunchiLogin(QingxuetangLoginDTO qingxuetangLoginDTO) {

        UserRoleVO userRoleVO = new UserRoleVO();

//        appId:9a79cda9ef6f4a52a8
//        appSecret:552a4147db2d4026bc4e9021acd614f8
        MemberDO memberDO = this.baseMapper.selectOne(new QueryWrapper<MemberDO>()
                .lambda()
                .eq(MemberDO::getTelephone, qingxuetangLoginDTO.getMobile()));

        if (memberDO == null) {
            throw new HttpException(10010);
        }

        /**
         * 时间戳有没有过期
         */
        if (qingxuetangLoginDTO.getTimestamp() - System.currentTimeMillis() >= 5 * 60 * 1000 || System.currentTimeMillis() - qingxuetangLoginDTO.getTimestamp() >= 5 * 60 * 1000) {
            OprMemDictDO oprMemDictDO = new OprMemDictDO();
            oprMemDictDO.setUserId(memberDO.getId());
            oprMemDictDO.setOprType("登录");
            oprMemDictDO.setResult(0);
            oprMemDictMapper.insert(oprMemDictDO);
            throw new HttpException(14002);
        }

        //鉴权逻辑 对不对
        String preAuthen = "appId=9a79cda9ef6f4a52a8"
                + "&authCorpName=" + qingxuetangLoginDTO.getAuthCorpName()
                + "&mobile=" + qingxuetangLoginDTO.getMobile()
                + "&nickname=" + qingxuetangLoginDTO.getNickname()
                + "&timestamp=" + qingxuetangLoginDTO.getTimestamp()
                + "&appSecret=552a4147db2d4026bc4e9021acd614f8";

        String result = SecretUtils.getMD5String(preAuthen);
        if (!qingxuetangLoginDTO.getSign().equals(result)) {
            OprMemDictDO oprMemDictDO = new OprMemDictDO();
            oprMemDictDO.setUserId(memberDO.getId());
            oprMemDictDO.setOprType("登录");
            oprMemDictDO.setResult(0);
            oprMemDictMapper.insert(oprMemDictDO);
            throw new HttpException(14001);
        }

        CompanyDictDO companyDictDO = companyDictMapper.selectById(memberDO.getCompanyId());

        if ("冻结".equals(memberDO.getStatus())) {
            OprMemDictDO oprMemDictDO = new OprMemDictDO();
            oprMemDictDO.setUserId(memberDO.getId());
            oprMemDictDO.setOprType("登录");
            oprMemDictDO.setResult(0);
            oprMemDictMapper.insert(oprMemDictDO);
            throw new HttpException(10013);
        }

//        //是否登陆过   1:是 0:否
//        if (0 == memberDO.getFirstLogin()) {
//            OprMemDictDO oprMemDictDO = new OprMemDictDO();
//            oprMemDictDO.setUserId(memberDO.getId());
//            oprMemDictDO.setOprType("登录");
//            oprMemDictDO.setResult(0);
//            oprMemDictMapper.insert(oprMemDictDO);
//            throw new HttpException(10015);
//        }
        BeanUtils.copyProperties(memberDO, userRoleVO);

        //审计日志
        OprMemDictDO oprMemDictDO = new OprMemDictDO();
        oprMemDictDO.setUserId(memberDO.getId());
        oprMemDictDO.setOprType("登录");
        oprMemDictDO.setResult(1);
        oprMemDictMapper.insert(oprMemDictDO);
        userRoleVO.setCompanyId(companyDictDO.getId());
        userRoleVO.setSuperviseName(companyDictDO.getSuperviseName());
        userRoleVO.setCompanyName(companyDictDO.getCompanyName());
        userRoleVO.setLogo(companyDictDO.getLogo());
        userRoleVO.setQxyStatus(companyDictDO.getQxyStatus());
        List<RotationImgDictDO> rotationImgDictDOS = rotationImgDictMapper.selectList(new QueryWrapper<RotationImgDictDO>()
                .lambda()
                .eq(RotationImgDictDO::getCompanyId, companyDictDO.getId()));
        userRoleVO.setRotationImgDictDOS(rotationImgDictDOS);
        String token = JwtUtil.generateToken(memberDO.getId(), ConstantUtils.MOBILE_TERMINATE);
//        redisUtil.set(ConstantUtils.MOBILE_TERMINATE + "_" + memberDO.getId(), token);
        userRoleVO.setToken(token);
        return userRoleVO;
    }

    public CheckStatusVO checkStatus(MemberDO memberDO) {

        CheckStatusVO checkStatusVO = new CheckStatusVO();
        MemberDO memberDO1 = this.baseMapper.selectById(memberDO.getId());

        if (StringUtils.isEmpty(memberDO1.getCheckImage())) {
            checkStatusVO.setImageStatus(false);
        } else {
            checkStatusVO.setImageStatus(true);
        }

        if (memberDO1.getFirstLogin() == 1) {
            checkStatusVO.setSMSStatus(true);
        } else {
            checkStatusVO.setSMSStatus(false);
        }

        if (StringUtils.isEmpty(memberDO1.getIdCardPhoto())) {
            checkStatusVO.setIdCardStatus(false);
        } else {
            checkStatusVO.setIdCardStatus(true);
        }

        return checkStatusVO;
    }

    public String updatePassword(MemberDO memberDO) {
        this.baseMapper.updateById(memberDO);
        //MemberDO memberDO1 = this.baseMapper.selectById(memberDO.getId());
        //redisUtil.set(RedisPrefixConstant.SUBSIDY_COMPANY_MEMBER_PREFIX + memberDO1.getCompanyId() + ":" + memberDO.getAccountName(), memberDO);
        return ConstantUtils.SET_SUCCESS;
    }

    public String removeCheckImage(MemberDO memberDO) {
        this.baseMapper.removeCheckImage(memberDO.getId());
        return ConstantUtils.DELETE_SUCCESS;
    }

    public List<MyCoursesVO> myCourses(MyCoursesDTO myCoursesDTO) {
        List<MyCoursesVO> myCoursesVOS = this.baseMapper.myCourses(myCoursesDTO.getMemberId(), myCoursesDTO.getStatus());
        for (MyCoursesVO myCoursesVO : myCoursesVOS) {
            List<FieldDictDO> fieldDictDOS = courseFieldMappingMapper.courseFields(myCoursesVO.getCourseId());
            myCoursesVO.setFieldDictDOS(fieldDictDOS);
            int count = imageCheckRecordMapper.selectCount(new QueryWrapper<ImageCheckRecordDO>()
                    .lambda()
                    .eq(ImageCheckRecordDO::getMemberId, myCoursesDTO.getMemberId())
                    .eq(ImageCheckRecordDO::getClassId, myCoursesVO.getClassId())
                    .isNull(ImageCheckRecordDO::getPaperId)
                    .eq(ImageCheckRecordDO::getCheckPlace, 0)
                    .eq(ImageCheckRecordDO::getResult, 1));

            int checkCnt = imageCheckRecordMapper.checkDailyCount(myCoursesDTO.getMemberId(), myCoursesVO.getClassId(), 1, null);
            myCoursesVO.setCheckCnt(checkCnt);

            if (count > 0) {
                myCoursesVO.setResult(1);
            } else {
                myCoursesVO.setResult(0);
            }
        }
        return myCoursesVOS;
    }

    public List<MyCoursesVO> myCertCourses(MyCoursesDTO myCoursesDTO) {
        List<MyCoursesVO> myCoursesVOS = this.baseMapper.myCourses(myCoursesDTO.getMemberId(), myCoursesDTO.getStatus());
        for (MyCoursesVO myCoursesVO : myCoursesVOS) {
            List<FieldDictDO> fieldDictDOS = courseFieldMappingMapper.courseFields(myCoursesVO.getCourseId());
            myCoursesVO.setFieldDictDOS(fieldDictDOS);
            int count = imageCheckRecordMapper.selectCount(new QueryWrapper<ImageCheckRecordDO>()
                    .lambda()
                    .eq(ImageCheckRecordDO::getMemberId, myCoursesDTO.getMemberId())
                    .eq(ImageCheckRecordDO::getClassId, myCoursesVO.getClassId())
                    .isNull(ImageCheckRecordDO::getPaperId)
                    .eq(ImageCheckRecordDO::getCheckPlace, 0)
                    .eq(ImageCheckRecordDO::getResult, 1));

            int checkCnt = imageCheckRecordMapper.checkDailyCount(myCoursesDTO.getMemberId(), myCoursesVO.getClassId(), 1, null);
            myCoursesVO.setCheckCnt(checkCnt);

            if (count > 0) {
                myCoursesVO.setResult(1);
            } else {
                myCoursesVO.setResult(0);
            }
        }
        return myCoursesVOS;
    }

    public ContentVodNewVO contentVod(ContentMemberDTO contentVodDTO) {

        ContentVodNewVO contentVodNewVO = new ContentVodNewVO();

        //课程详细信息
        ClassDictDO classDictDO = classDictMapper.selectById(contentVodDTO.getClassId());
        contentVodNewVO.setIsFastPlay(classDictDO.getIsFastPlay());
        contentVodNewVO.setIsOrder(classDictDO.getIsOrder());
        contentVodNewVO.setTestRule(classDictDO.getTestRule());


        List<ContentVodVO> contentVodVOS = new ArrayList<>();
        List<CourseContentDO> courseContentDOS = courseContentMapper.selectList(new QueryWrapper<CourseContentDO>()
                .lambda()
                .eq(CourseContentDO::getCourseId, contentVodDTO.getCourseId())
                .orderByAsc(CourseContentDO::getOrderNo));

        ClassDictDO classDictDO1 = classDictMapper.selectById(contentVodDTO.getClassId());

        //目录状态
        Boolean contentStatus = true;

        for (CourseContentDO courseContentDO : courseContentDOS) {
            ContentVodVO contentVodVO = new ContentVodVO();
            contentVodVO.setContent(courseContentDO.getContent());

            List<MemberVodVO> memberVodVOS = courseContentMapper.contentVodProcess(courseContentDO.getId(), contentVodDTO.getMemberId(), contentVodDTO.getClassId());

            Boolean flag = false;
            int i = 0;

            if (1 == classDictDO1.getIsOrder()) {
                for (MemberVodVO memberVodVO : memberVodVOS) {

                    if (i == 0 && contentStatus) {
                        //第一个视频默认打开
                        memberVodVO.setStatus(true);
                    } else if (memberVodVO.getPercent().equals("100")) {
                        //这个视频看完了,已解锁
                        memberVodVO.setStatus(true);
                    } else {
                        //这个视频没看完,未解锁
                        if (!flag) {
                            //这个视频可见 ===> 第一个没看完但可以看的视频
                            memberVodVO.setStatus(true);
                            flag = true;
                        } else {
                            memberVodVO.setStatus(false);
                        }
                        contentStatus = false;
                    }

                    i++;
                }
            } else {
                for (MemberVodVO memberVodVO : memberVodVOS) {
                    memberVodVO.setStatus(true);
                }
            }

            int playCount = 0;
            for (MemberVodVO memberVodVO : memberVodVOS) {
                if ("100".equals(memberVodVO.getPercent())) {
                    playCount++;
                }
            }

            contentVodVO.setPlayVods(playCount);
            contentVodVO.setMemberVodVOS(memberVodVOS);
            contentVodVO.setTotalVods(memberVodVOS.size());
            contentVodVOS.add(contentVodVO);
        }
        contentVodNewVO.setContentVodVOS(contentVodVOS);

        //最新的视频记录
        List<ContentVodNewVO> contentVodNewVOS = vodPlayHistoryMapper.memberRecentPlay(contentVodDTO.getClassId(), contentVodDTO.getMemberId());
        if (contentVodNewVOS.size() > 0) {
            contentVodNewVO.setId(contentVodNewVOS.get(0).getId());
            contentVodNewVO.setPlayRecord(contentVodNewVOS.get(0).getPlayRecord());
        }
        return contentVodNewVO;
    }

    public List<ContentFilesVO> contentFiles(ContentMemberDTO contentMemberDTO) {

        List<ContentFilesVO> contentFilesVOS = new ArrayList<>();

        List<CourseContentDO> courseContentDOS = courseContentMapper.selectList(new QueryWrapper<CourseContentDO>()
                .lambda()
                .eq(CourseContentDO::getCourseId, contentMemberDTO.getCourseId())
                .orderByAsc(CourseContentDO::getOrderNo));

        for (CourseContentDO courseContentDO : courseContentDOS) {

            ContentFilesVO contentFilesVO = new ContentFilesVO();
            contentFilesVO.setContent(courseContentDO.getContent());

            List<FileDictDO> fileDictDOS = fileDictMapper.selectList(new QueryWrapper<FileDictDO>()
                    .lambda()
                    .eq(FileDictDO::getContentId, courseContentDO.getId()));
            contentFilesVO.setFileDictDOS(fileDictDOS);

            contentFilesVOS.add(contentFilesVO);
        }

        return contentFilesVOS;
    }

    public IPage studyHistory(StudyHistoryDTO studyHistoryDTO) {
        Page pager = new Page(studyHistoryDTO.getPageNum(), studyHistoryDTO.getPageSize());
        return vodPlayHistoryMapper.studyHistory(pager, studyHistoryDTO.getMemberId());
    }

    public List<QueryPapersVO> getCourseTest(ContentMemberDTO contentMemberDTO) {

        //查看该班级下的测试卷子(有效卷子)
        ClassDictDO classDictDO = classDictMapper.selectById(contentMemberDTO.getClassId());
        List<QueryPapersVO> queryPapersVOS = paperDictMapper.queryPapers(contentMemberDTO.getCourseId(), null, 1);
        for (QueryPapersVO queryPapersVO : queryPapersVOS) {
            //多少人已完成
            Integer cnt = paperDictMapper.completeCount(queryPapersVO.getId(), contentMemberDTO.getClassId());
            queryPapersVO.setCompleteCnt(cnt);
            //自己成绩
            List<ExerciseDoneResultDO> exerciseDoneResultDOS = exerciseDoneResultMapper.getMaxScorePaper(queryPapersVO.getId(), contentMemberDTO.getMemberId(), contentMemberDTO.getClassId());

            if (exerciseDoneResultDOS.size() > 0) {
                queryPapersVO.setRightCounts(exerciseDoneResultDOS.get(0).getRightCounts());
                queryPapersVO.setTotalCount(exerciseDoneResultDOS.get(0).getTotalCounts());
                queryPapersVO.setResult(exerciseDoneResultDOS.get(0).getResult());
            } else {
                queryPapersVO.setResult("待完成");
            }

            int count = imageCheckRecordMapper.selectCount(new QueryWrapper<ImageCheckRecordDO>()
                    .lambda()
                    .eq(ImageCheckRecordDO::getMemberId, contentMemberDTO.getMemberId())
                    .eq(ImageCheckRecordDO::getClassId, contentMemberDTO.getClassId())
                    .eq(ImageCheckRecordDO::getPaperId, queryPapersVO.getId())
                    .eq(ImageCheckRecordDO::getClassPlace, 2)
                    .eq(ImageCheckRecordDO::getResult, 1));

            int checkCnt = imageCheckRecordMapper.checkDailyCount(contentMemberDTO.getMemberId(), contentMemberDTO.getClassId(), 2, queryPapersVO.getId());
            queryPapersVO.setCheckCnt(checkCnt);

            if (count > 0) {
                queryPapersVO.setCheckResult(1);
            } else {
                queryPapersVO.setCheckResult(0);
            }
            //截止时间
            queryPapersVO.setEndDate(classDictDO.getEndDate());
        }
        return queryPapersVOS;
    }

    public List<ExerciseDoneResultDO> getPaperDoneDetail(ExerciseDoneResultDO exerciseDoneResultDO) {
        return exerciseDoneResultMapper.selectList(new QueryWrapper<ExerciseDoneResultDO>()
                .lambda()
                .eq(ExerciseDoneResultDO::getMemberId, exerciseDoneResultDO.getMemberId())
                .eq(ExerciseDoneResultDO::getPaperId, exerciseDoneResultDO.getPaperId()));
    }

    public GetStudyInfoVO getStudyInfo(MemberDO memberDO) {

        GetStudyInfoVO getStudyInfoVO = new GetStudyInfoVO();

        //已学课程
        List<ClassMemberMappingDO> classMemberMappingDOS = classMemberMappingMapper.selectList(new QueryWrapper<ClassMemberMappingDO>()
                .lambda()
                .eq(ClassMemberMappingDO::getMemberId, memberDO.getId()));
        /**
         * 遍历课程,累计学习时长超过视频时长 则表示已学完
         */
        int i = 0; //已学课程
        for (ClassMemberMappingDO classMemberMappingDO : classMemberMappingDOS) {
            List<VodDictDO> vodDictDOS = classDictMapper.getClassVods(classMemberMappingDO.getClassId());
            for (VodDictDO vodDictDO : vodDictDOS) {
                int playLength = vodPlayHistoryMapper.memberVodTotalLength(classMemberMappingDO.getClassId(), memberDO.getId(), vodDictDO.getId());
                if (playLength < vodDictDO.getVodLength()) {
                    break;
                }
            }
            i++;
        }
        getStudyInfoVO.setStudyCourse(i);

        //累计学习时长
        int studyLength = vodPlayHistoryMapper.memberTotalLength(memberDO.getId());
        getStudyInfoVO.setStudyLength(studyLength);

        //第几天
        MemberDO memberDO1 = this.baseMapper.selectById(memberDO.getId());
        long diff = Duration.between(memberDO1.getCreateDate(), LocalDateTime.now()).toDays();
        getStudyInfoVO.setDiff(diff);

        return getStudyInfoVO;
    }

    public String checkTimes(ExerciseDoneResultDO exerciseDoneResultDO) {

        MemberDO memberDO = this.baseMapper.selectById(exerciseDoneResultDO.getMemberId());
        ClassHourDictDO classHourDictDO = classHourDictMapper.selectOne(new QueryWrapper<ClassHourDictDO>()
                .lambda()
                .eq(ClassHourDictDO::getCompanyId, memberDO.getCompanyId()));

        if (null != classHourDictDO) {
            Integer status = classHourDictDO.getRepeatStatus();
            if (1 == status) {
                int cnt = classHourDictDO.getRepeatTime();

                //查看这个人这个卷子做了几次
                Integer count = exerciseDoneResultMapper.selectCount(new QueryWrapper<ExerciseDoneResultDO>()
                        .lambda()
                        .eq(ExerciseDoneResultDO::getMemberId, exerciseDoneResultDO.getMemberId())
                        .eq(ExerciseDoneResultDO::getPaperId, exerciseDoneResultDO.getPaperId()));

                if (cnt <= count) {
                    throw new HttpException(60001);
                }
            }
        }
        return ConstantUtils.CHECK_STATUS;
    }

    public void importRedis() {
        List<MemberDO> memberDOS = this.baseMapper.selectList(null);
        for (MemberDO memberDO : memberDOS) {
            //redisUtil.set(RedisPrefixConstant.SUBSIDY_COMPANY_MEMBER_PREFIX + memberDO.getCompanyId() + ":" + memberDO.getAccountName(), memberDO);
        }
    }

    public String changeDepartments(ChangeDepartmentsDTO changeDepartmentsDTO) {

        List<Long> memberIds = changeDepartmentsDTO.getMemberIds();

        //清掉以前的部门
        for (Long lg : memberIds) {
            memberDepartmentMappingMapper.delete(new QueryWrapper<MemberDepartmentMappingDO>()
                    .lambda()
                    .eq(MemberDepartmentMappingDO::getMemberId, lg));
        }

        //加入新的部门
        List<Long> depIds = changeDepartmentsDTO.getDesDepId();
        for (Long lg : memberIds) {
            for (Long depId : depIds) {
                MemberDepartmentMappingDO memberDepartmentMappingDO = new MemberDepartmentMappingDO();
                memberDepartmentMappingDO.setMemberId(lg);
                memberDepartmentMappingDO.setDepartmentId(depId);
                memberDepartmentMappingMapper.insert(memberDepartmentMappingDO);
            }
        }
        return ConstantUtils.SET_SUCCESS;
    }

    public QxyVO qxy(MemberDO memberDO) {

        CloseableHttpClient client = null;
        CloseableHttpResponse response = null;
        String resValue = "";

        long timestamp = System.currentTimeMillis();
        String nonce = SecretUtils.getNonce(5);
        String appId = qXueYouConfig.getAppId();

        String appKey = qXueYouConfig.getSecurityKey();
        String mobile = memberDO.getTelephone();
        String signature = SecretUtils.gen(appKey, nonce, String.valueOf(timestamp), appId, mobile);
        try {
            client = HttpClients.createDefault();
            HttpUriRequest build = RequestBuilder
                    .post(qXueYouConfig.getUrl())
                    .addHeader("Content-Type", "application/json")
                    .setEntity(new StringEntity(""))
                    .addParameter("appId", appId)
                    .addParameter("mobile", mobile)
                    .addParameter("timestamp", String.valueOf(timestamp))
                    .addParameter("signature", signature)
                    .addParameter("nonce", nonce)
                    .build();
            //请求
            response = client.execute(build);
            HttpEntity entity = response.getEntity();

            if (entity != null) {
                resValue = EntityUtils.toString(entity, "UTF-8");
                ResultMode resMode = JSON.parseObject(resValue, ResultMode.class);
                QxyVO qxyVO = new QxyVO();
                qxyVO.setToken(resMode.getData().toString());
                return qxyVO;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new QxyVO();
    }

    @Transactional(rollbackFor = Exception.class)
    public UserRoleVO register(RegisterDTO registerDTO) {

        UserRoleVO userRoleVO = new UserRoleVO();

        //判断手机号是否已经注册
        int count = this.baseMapper.selectCount(new QueryWrapper<MemberDO>()
                .lambda()
                .eq(MemberDO::getTelephone, registerDTO.getTelephone()));
        if (count > 0) {
            throw new HttpException(10027);
        }

        SmsVerifyCodeDO smsCodeDO = smsVerifyCodeMapper.selectOne(new QueryWrapper<SmsVerifyCodeDO>()
                .lambda()
                .eq(SmsVerifyCodeDO::getTelephone, registerDTO.getTelephone())
                .eq(SmsVerifyCodeDO::getVerifyCode, registerDTO.getSmsCode())
                .gt(SmsVerifyCodeDO::getCreateDate, LocalDateTime.now().minusMinutes(30L)));

        if (null == smsCodeDO) {
            throw new HttpException(10003);
        }

        //赋值
        MemberDO memberDO = new MemberDO();
        BeanUtils.copyProperties(registerDTO,memberDO);
        memberDO.setFirstLogin(1);
        memberDO.setStatus("启用");
        HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
        //拼音小写
        format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
        //不带声调
        format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
        try {
            String accountName = PinyinHelper.toHanYuPinyinString(registerDTO.getUserName(), format, "", true);
            memberDO.setAccountName(accountName);
            memberDO.setPassword("123456");
        }catch (Exception e){
            e.printStackTrace();
        }
        this.baseMapper.insert(memberDO);

        //审计日志
        OprMemDictDO oprMemDictDO = new OprMemDictDO();
        oprMemDictDO.setUserId(memberDO.getId());
        oprMemDictDO.setOprType("登录");
        //oprMemDictDO.setUserName(memberDO.getUserName());
        oprMemDictDO.setResult(1);
        //oprMemDictDO.setCreateDate(System.currentTimeMillis() + "");
        //oprMemDictDO.setLoginDateFormat(DateFormatUtil.format(new Date(), "yyyyMMdd"));
        //oprMemDictDO.setCompanyId(companyDictDO.getId());
        //oprMemDictDO.setCompanyName(companyDictDO.getCompanyName());
        oprMemDictMapper.insert(oprMemDictDO);

        CompanyDictDO companyDictDO = companyDictMapper.selectById(registerDTO.getCompanyId());
        BeanUtils.copyProperties(memberDO,userRoleVO);
        userRoleVO.setCompanyId(companyDictDO.getId());
        userRoleVO.setSuperviseName(companyDictDO.getSuperviseName());
        userRoleVO.setCompanyName(companyDictDO.getCompanyName());
        userRoleVO.setLogo(companyDictDO.getLogo());
        userRoleVO.setQxyStatus(companyDictDO.getQxyStatus());
        List<RotationImgDictDO> rotationImgDictDOS = rotationImgDictMapper.selectList(new QueryWrapper<RotationImgDictDO>()
                .lambda()
                .eq(RotationImgDictDO::getCompanyId, companyDictDO.getId()));
        userRoleVO.setRotationImgDictDOS(rotationImgDictDOS);

        String token = JwtUtil.generateToken(memberDO.getId(), ConstantUtils.MOBILE_TERMINATE);
        //redisUtil.set(ConstantUtils.MOBILE_TERMINATE + "_" + memberDO.getId(), token);
        Localstorage.setUser(memberDO);
        userRoleVO.setToken(token);
        return userRoleVO;
    }
}