MemberServiceImpl.java 36.9 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
package com.subsidy.service.impl;

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.RedisPrefixConstant;
import com.subsidy.common.exception.HttpException;
import com.subsidy.dto.administer.VerifyCodeDTO;
import com.subsidy.dto.member.*;
import com.subsidy.mapper.ClassDictMapper;
import com.subsidy.mapper.ClassHourDictMapper;
import com.subsidy.mapper.ClassMemberMappingMapper;
import com.subsidy.mapper.CompanyDictMapper;
import com.subsidy.mapper.CourseContentMapper;
import com.subsidy.mapper.CourseFieldMappingMapper;
import com.subsidy.mapper.DepartmentDictMapper;
import com.subsidy.mapper.ExerciseDoneResultMapper;
import com.subsidy.mapper.FileDictMapper;
import com.subsidy.mapper.JobDictMapper;
import com.subsidy.mapper.JobMemberMappingMapper;
import com.subsidy.mapper.MemberDepartmentMappingMapper;
import com.subsidy.mapper.MemberMapper;
import com.subsidy.mapper.OprMemDictMapper;
import com.subsidy.mapper.PaperDictMapper;
import com.subsidy.mapper.RotationImgDictMapper;
import com.subsidy.mapper.SmsVerifyCodeMapper;
import com.subsidy.mapper.VodDictMapper;
import com.subsidy.mapper.VodPlayHistoryMapper;
import com.subsidy.model.ClassDictDO;
import com.subsidy.model.ClassHourDictDO;
import com.subsidy.model.ClassMemberMappingDO;
import com.subsidy.model.CompanyDictDO;
import com.subsidy.model.CourseContentDO;
import com.subsidy.model.DepartmentDictDO;
import com.subsidy.model.ExerciseDoneResultDO;
import com.subsidy.model.FieldDictDO;
import com.subsidy.model.FileDictDO;
import com.subsidy.model.JobDictDO;
import com.subsidy.model.JobMemberMappingDO;
import com.subsidy.model.MemberDO;
import com.subsidy.model.MemberDepartmentMappingDO;
import com.subsidy.model.OprMemDictDO;
import com.subsidy.model.RotationImgDictDO;
import com.subsidy.model.SmsVerifyCodeDO;
import com.subsidy.model.VodDictDO;
import com.subsidy.service.MemberService;
import com.subsidy.util.ConstantUtils;
//import com.subsidy.util.RedisUtil;
import com.subsidy.util.JwtUtil;
import com.subsidy.util.RedisUtil;
import com.subsidy.vo.administer.UserRoleVO;
import com.subsidy.vo.member.ContentFilesVO;
import com.subsidy.vo.member.ContentVodNewVO;
import com.subsidy.vo.member.ContentVodVO;
import com.subsidy.vo.member.GetAllVO;
import com.subsidy.vo.member.GetStudyInfoVO;
import com.subsidy.vo.member.MemberStudyPageVO;
import com.subsidy.vo.member.MemberVO;
import com.subsidy.vo.member.MemberVodVO;
import com.subsidy.vo.member.MyCoursesVO;
import com.subsidy.vo.member.StudyPageVO;
import com.subsidy.vo.paper.QueryPapersVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.AsyncResult;
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.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * <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 VodDictMapper vodDictMapper;

    @Autowired
    private SmsVerifyCodeMapper smsVerifyCodeMapper;

    @Autowired
    private ClassHourDictMapper classHourDictMapper;

    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.setCompanyName(companyDictDO.getCompanyName());
        userRoleVO.setLogo(companyDictDO.getLogo());
        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 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());
            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.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);
            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;
    }

    public UserRoleVO qingxuetangLogin(QingxuetangLoginDTO qingxuetangLoginDTO) {

        UserRoleVO userRoleVO = new UserRoleVO();

        //鉴权逻辑

        //先从redis里拿   还得从数据库先查公司。。还是直接查人快
        MemberDO memberDO = this.baseMapper.selectOne(new QueryWrapper<MemberDO>()
                .lambda()
                .eq(MemberDO::getTelephone, qingxuetangLoginDTO.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);

        //审计日志
        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.setCompanyName(companyDictDO.getCompanyName());
        userRoleVO.setLogo(companyDictDO.getLogo());
        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 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 MemberStudyPageVO studyPage(MemberDO memberDO) {

        MemberStudyPageVO memberStudyPageVO = new MemberStudyPageVO();

        List<StudyPageVO> studyPageVOS = this.baseMapper.studyPage(memberDO);

        final ExecutorService newCachedThreadPool = Executors.newCachedThreadPool();
        for (StudyPageVO studyPageVO : studyPageVOS) {
            //查看课程下有几节课
            List<VodDictDO> vodDictDOS = courseContentMapper.getCourseVods(studyPageVO.getId());
            studyPageVO.setTotalVods(vodDictDOS.size());
            newCachedThreadPool.submit(() -> studyPageTask1(studyPageVO, vodDictDOS, memberDO.getId()));
        }
        newCachedThreadPool.shutdown();

        memberStudyPageVO.setStudyPageVOS(studyPageVOS);
        return memberStudyPageVO;
    }

    public Future<StudyPageVO> studyPageTask1(StudyPageVO studyPageVO, List<VodDictDO> vodDictDOS, Long memberId) {

        int i = 0;

        //该成员完成了几个视频
        for (VodDictDO vodDictDO : vodDictDOS) {
            int completeVodOrNot = vodPlayHistoryMapper.completeVodOrNot(memberId, vodDictDO.getId(), studyPageVO.getClassId());
            i += completeVodOrNot;
        }
        studyPageVO.setDoneVods(i);
        ////该班级课程下有多少人
        //Integer count = classMemberMappingMapper.selectCount(new QueryWrapper<ClassMemberMappingDO>()
        //        .lambda()
        //        .eq(ClassMemberMappingDO::getClassId, studyPageVO.getClassId()));
        //studyPageVO.setTotalMember(count);

        return new AsyncResult<>(studyPageVO);
    }

    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);
        }
        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("待完成");
            }
            //截止时间
            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;
    }

}