package jnpf.cultivate.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fantaibao.permission.handling.PermissionHandling;
import com.github.pagehelper.PageInfo;
import jnpf.base.ActionResult;
import jnpf.cultivate.mapper.CultivateUserViewMapper;
import jnpf.cultivate.mapper.TeachingRecordMapper;
import jnpf.cultivate.service.*;
import jnpf.cultivate.v2.util.CultivateMqSendUtil;
import jnpf.entity.cultivate.TeachingRecord;
import jnpf.entity.cultivate.TeachingSkill;
import jnpf.entity.cultivate.TeachingStudent;
import jnpf.enums.cultivate.TeachingRecordTypeEnum;
import jnpf.model.cultivate.dto.teaching.*;
import jnpf.model.cultivate.event.dto.file.FileEventDTO;
import jnpf.model.cultivate.po.teaching.CultivateFile;
import jnpf.model.cultivate.po.teaching.CultivateUserView;
import jnpf.model.cultivate.v2.teaching.model.V2Attachment;
import jnpf.model.cultivate.vo.teaching.*;
import jnpf.permission.UserApi;
import jnpf.permission.V2UserApi;
import jnpf.permission.eum.v2.OrganizeCategoryEnums;
import jnpf.permission.vo.v2.user.UserBoundVO;
import jnpf.util.EasyExcelUtil;
import jnpf.util.FtbUtil;
import jnpf.util.RandomUtil;
import jnpf.util.UserProvider;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionSynchronization;
import org.springframework.transaction.support.TransactionSynchronizationManager;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Service
public class TeachingRecordPracticeServiceImpl extends ServiceImpl<TeachingRecordMapper, TeachingRecord> implements TeachingRecordPracticeService {
    @Resource
    private V2UserApi v2UserApi;
    @Resource
    private PermissionHandling permissionHandling;
    @Resource
    private TeachingSkillService teachingSkillService;
    @Resource
    private CultivateUserViewMapper cultivateUserViewMapper;
    @Resource
    private TeachingStudentService teachingStudentService;
    @Resource
    private TeachingRecordService teachingRecordService;
    @Resource
    private CultivateFileService cultivateFileService;

    @Resource
    private CultivateMqSendUtil cultivateMqSendUtil;

    @Resource
    private UserApi userApiV1;

    @Override
    public List<StoreInfoListVo> getStoreList() {
        //获取练习记录
        List<TeachingRecord> recordList = lambdaQuery()
                .select(TeachingRecord::getStoreId, TeachingRecord::getStoreName)
                .eq(TeachingRecord::getType, TeachingRecordTypeEnum.LX.getCode())
                .eq(TeachingRecord::getDeleteMark, 0)
                .list();
        //返回门店下拉数据
        if (CollUtil.isNotEmpty(recordList)) {
            Map<String, TeachingRecord> storeListMap = recordList.stream().collect(Collectors.toMap(TeachingRecord::getStoreId, a -> a, (k1, k2) -> k1));
            return storeListMap.values().stream().map(record -> StoreInfoListVo.builder()
                    .storeId(record.getStoreId())
                    .storeName(record.getStoreName())
                    .build()).collect(Collectors.toList());
        }
        return List.of();
    }

    @Override
    public PageInfo<SummaryPageListVo> summaryPageList(TeachingBaseFilter pageDto) {
        pageDto.dateTimeFormat();
        Page<SummaryPageListVo> page = Page.of(Math.toIntExact(pageDto.getCurrentPage()), Math.toIntExact(pageDto.getPageSize()));
        List<SummaryPageListVo> pageListVoList = this.baseMapper.summaryPageList(page, pageDto);
        List<String> userIds = pageListVoList.stream().map(SummaryPageListVo::getUserId).collect(Collectors.toList());
        Map<String, UserBoundVO> userMap = getUserMap(userIds);
        setSummaryUserName(userMap, pageListVoList);
        //获取筛选范围内总的技能点集合
        LinkedList<SkillCountVo> skillList = this.baseMapper.summarySkillList(pageDto);
        //处理skillList数据;每条数据的长度不一样，要处理成一样的，并且保证顺序一致
        processSkillPointData(skillList, pageListVoList);
        PageInfo<SummaryPageListVo> pageInfo = new PageInfo<>(pageListVoList);
        pageInfo.setPageSize((int) pageDto.getPageSize());
        pageInfo.setPageNum((int) pageDto.getCurrentPage());
        pageInfo.setTotal(page.getTotal());
        return pageInfo;
    }

    private void setSummaryUserName(Map<String, UserBoundVO> userMap, List<SummaryPageListVo> pageListVoList) {
        pageListVoList.forEach(v -> {
            UserBoundVO user = userMap.get(v.getUserId());
            if (null != user) {
                v.setUserName(user.getUserName());
                v.setPostName(user.getPositionName());
            } else {
                v.setPostName(null);
            }
        });
    }

    private Map<String, UserBoundVO> getUserMap(List<String> userIds) {

        List<UserBoundVO> list;
        if (userIds.isEmpty()) {
            list = new ArrayList<>();
        } else {
            list = v2UserApi.userListAndCopy(userIds, null, UserProvider.getUser().getTenantId());
        }
        return list.stream().collect(Collectors.toMap(UserBoundVO::getId, Function.identity()));
    }

    @Override
    public void summaryExport(HttpServletResponse response, TeachingBaseFilter pageDto) throws Exception {
        pageDto.dateTimeFormat();
        Page<SummaryPageListVo> page = Page.of(Math.toIntExact(pageDto.getCurrentPage()), Math.toIntExact(100000L));
        List<SummaryPageListVo> summaryVoList = this.baseMapper.summaryPageList(page, pageDto);
        List<String> userIds = summaryVoList.stream().map(SummaryPageListVo::getUserId).collect(Collectors.toList());
        Map<String, UserBoundVO> userMap = getUserMap(userIds);
        setSummaryUserName(userMap, summaryVoList);
        //获取筛选范围内总的技能点集合
        LinkedList<SkillCountVo> skillList = this.baseMapper.summarySkillList(pageDto);
        //处理skillList数据;每条数据的长度不一样，要处理成一样的，并且保证顺序一致
        processSkillPointData(skillList, summaryVoList);
        //获取动态表头
        List<List<String>> list = new ArrayList<>();
        list.add(Collections.singletonList("门店名称"));
        list.add(Collections.singletonList("学员"));
        list.add(Collections.singletonList("学员岗位"));
        list.add(Collections.singletonList("练习总次数"));
        List<List<String>> headers = EasyExcelUtil.getHeaders(summaryVoList, list);
        //获取动态数据
        List<List<Object>> dataList = EasyExcelUtil.getDataList(summaryVoList);
        EasyExcelUtil.rankingExportData(dataList, headers, "练习汇总数据", "练习汇总数据表", response);
    }


    @Override
    public void recordExport(HttpServletResponse response, TeachingBaseFilter pageDto) throws Exception {
        pageDto.dateTimeFormat();
        Page<RecordPageListVo> page = Page.of(Math.toIntExact(pageDto.getCurrentPage()), Math.toIntExact(100000L));
        // 技能点分类过滤
        List<String> skillIds = teachingSkillService.querySkillIds(pageDto.getCategoryId());
        List<RecordPageListVo> pageListVoList;
        if (skillIds == null) {
            pageListVoList = new ArrayList<>();
        } else {
            pageListVoList = this.baseMapper.recordPageList(page, pageDto, skillIds);
            List<RecordExportListVo> exportListVoList = pageListVoList.stream().map(RecordPageListVo::convert).collect(Collectors.toList());
            EasyExcelUtil.export(response, "练习记录明细.xlsx", "练习记录明细表", RecordExportListVo.class, exportListVoList);
        }
    }

    @Override
    public PageInfo<RecordPageListVo> recordPageList(TeachingBaseFilter pageDto) {
        pageDto.dateTimeFormat();
        Page<RecordPageListVo> page = Page.of(Math.toIntExact(pageDto.getCurrentPage()), Math.toIntExact(pageDto.getPageSize()));
        // 技能点分类过滤
        List<String> skillIds = teachingSkillService.querySkillIds(pageDto.getCategoryId());
        if (skillIds == null) {
            return new PageInfo<>();
        }
        List<RecordPageListVo> pageListVoList = this.baseMapper.recordPageList(page, pageDto, skillIds);
        PageInfo<RecordPageListVo> pageInfo = new PageInfo<>(pageListVoList);
        pageInfo.setPageSize((int) pageDto.getPageSize());
        pageInfo.setPageNum((int) pageDto.getCurrentPage());
        pageInfo.setTotal(page.getTotal());
        return pageInfo;
    }

    @Override
    public Boolean recordBatchDelete(RecordBatchDeleteDto deleteDto) {
        LambdaQueryWrapper<TeachingRecord> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.in(TeachingRecord::getId, deleteDto.getIds());
        this.baseMapper.delete(queryWrapper);
        return Boolean.TRUE;
    }

    @Override
    public PageInfo<MyRecordPageListVo> myRecordPageList(MyRecordPageListDto pageDto) {
        pageDto.dateTimeFormat();
        Page<RecordPageListVo> page = Page.of(Math.toIntExact(pageDto.getCurrentPage()), Math.toIntExact(pageDto.getPageSize()));
        List<MyRecordPageListVo> pageListVoList = this.baseMapper.myRecordPageList(page, pageDto, UserProvider.getLoginUserId());
        PageInfo<MyRecordPageListVo> pageInfo = new PageInfo<>(pageListVoList);
        pageInfo.setPageSize((int) pageDto.getPageSize());
        pageInfo.setPageNum((int) pageDto.getCurrentPage());
        pageInfo.setTotal(page.getTotal());
        if (!pageInfo.getList().isEmpty()) {
            // 查询附件信息
            List<String> recordIdList = pageInfo.getList().stream().map(MyRecordPageListVo::getId).collect(Collectors.toList());
            Map<String, List<CultivateFile>> fileMap = teachingRecordService.getFileMap(recordIdList);
            // 查询是否浏览
            Set<String> viewedSet = teachingRecordService.getViewedSet(recordIdList, UserProvider.getLoginUserId());
            pageInfo.getList().forEach(v -> {
                List<CultivateFile> files = fileMap.get(v.getId());
                if (null != files && !files.isEmpty()) {
                    List<V2Attachment> attachments = new ArrayList<>();
                    files.forEach(file -> {
                        V2Attachment v2Attachment = cultivateFileService.convertToV2Attachment(file);
                        attachments.add(v2Attachment);
                    });
                    v.setAttachments(attachments);
                }
                if (viewedSet.contains(v.getId())) {
                    v.setViewed(true);
                }
            });
        }
        return pageInfo;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Boolean mySave(RecordSaveDto saveDto) throws Exception {
        TeachingRecord teachingRecord = RecordSaveDto.convert(saveDto);
        //查询用户主岗
        ActionResult<UserBoundVO> actionResult = v2UserApi.infoAndCopy(UserProvider.getUser().getUserId());

        Assert.isTrue(actionResult.getCode().equals(200), "查询登录用户主岗信息异常");
        UserBoundVO userInfo = actionResult.getData();
        if (null == userInfo) {
            throw new Exception("未查询到登录用户的主岗信息");
        }
        teachingRecord.setUserName(userInfo.getUserName());
        teachingRecord.setDeleteMark(0);
        teachingRecord.setTenantId(UserProvider.getUser().getTenantId());
        teachingRecord.setPostId(userInfo.getPositionId());
        teachingRecord.setPostName(userInfo.getPositionName());
        teachingRecord.setId(FtbUtil.getId());
        // 新增附件信息
        if (null != saveDto.getFileList() && !saveDto.getFileList().isEmpty()) {
            List<CultivateFile> fileList = teachingRecordService.changeToFileList(teachingRecord.getId(), saveDto.getFileList(), UserProvider.getLoginUserId(), FileEventDTO.FileType.PRACTICE);
            cultivateFileService.saveBatch(fileList);
        }
        boolean save = this.save(teachingRecord);
        // 注册事务同步器，在事务提交后发送MQ消息
        if (TransactionSynchronizationManager.isSynchronizationActive()) {
            TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
                @Override
                public void afterCommit() {
                    cultivateMqSendUtil.sendCompleteTeachingMessage(teachingRecord);
                }
            });
        }
        return save;
    }

    @Override
    public RecordInfoVo myInfo(String id) {
        TeachingRecord teachingRecord = this.getById(id);
        Assert.notNull(teachingRecord, "未查询到该记录");
        CultivateUserView cultivateUserView = cultivateUserViewMapper.selectOne(new LambdaQueryWrapper<CultivateUserView>().eq(CultivateUserView::getBizId, id));
        if (null == cultivateUserView) {
            cultivateUserView = new CultivateUserView(FtbUtil.getId(), id, UserProvider.getLoginUserId());
            cultivateUserViewMapper.insert(cultivateUserView);
        }
        TeachingSkill teachingSkill = teachingSkillService.getById(teachingRecord.getSkillId());
        Assert.notNull(teachingSkill, "未查询到技能点信息");
        RecordInfoVo vo = RecordInfoVo.convert(teachingRecord, teachingSkill);
        // 查询附件信息
        Map<String, List<CultivateFile>> fileMap = teachingRecordService.getFileMap(List.of(id));
        if (null != fileMap && !fileMap.isEmpty()) {
            List<CultivateFile> files = fileMap.get(id);
            List<V2Attachment> attachments = new ArrayList<>();
            files.forEach(file -> {
                V2Attachment v2Attachment = cultivateFileService.convertToV2Attachment(file);
                attachments.add(v2Attachment);
            });
            vo.setAttachments(attachments);
        }
        return vo;
    }

    @Override
    public Boolean myUpdate(RecordUpdateDto updateDto) {
        TeachingRecord teachingRecord = this.getById(updateDto.getId());
        Assert.notNull(teachingRecord, "未查询到该记录");
        RecordUpdateDto.convert(teachingRecord, updateDto);
        // 更新附件信息
        teachingRecordService.updateFileInfo(updateDto.getId(), updateDto.getFileList(), FileEventDTO.FileType.PRACTICE);
        return this.updateById(teachingRecord);
    }

    @Override
    public Boolean myDelete(String id) {
        return this.removeById(id);
    }

    @Override
    public ViewDataVo myViewData(ViewDataDto viewDataDto) {
        viewDataDto.dateTimeFormat();
        List<RecordViewDataModel> skillTable = this.baseMapper.getMySkillTable(viewDataDto, UserProvider.getLoginUserId());
        skillTable.sort(Comparator.comparing(RecordViewDataModel::getCount).reversed());
        return ViewDataVo.builder()
                .totalCount(CollUtil.isNotEmpty(skillTable) ? skillTable.stream().mapToInt(RecordViewDataModel::getCount).sum() : 0)
                .skillTable(skillTable)
                .build();
    }

    @Override
    public PageInfo<EmployeePageListVo> employeePageList(EmployeePageListDto pageDto) {
        pageDto.dateTimeFormat();
        Page<EmployeePageListVo> page = Page.of(Math.toIntExact(pageDto.getCurrentPage()), Math.toIntExact(pageDto.getPageSize()));
        List<EmployeePageListVo> pageListVoList = this.baseMapper.employeePageList(page, pageDto);
        PageInfo<EmployeePageListVo> pageInfo = new PageInfo<>(pageListVoList);
        pageInfo.setPageSize((int) pageDto.getPageSize());
        pageInfo.setPageNum((int) pageDto.getCurrentPage());
        pageInfo.setTotal(page.getTotal());
        return pageInfo;
    }

    @Override
    public List<EmployeeViewDataVo> employeeViewData(ViewDataDto viewDataDto) {
        viewDataDto.dateTimeFormat();
        List<EmployeeViewDataVo> employeeViewDataVoList = this.baseMapper.employeeViewData(viewDataDto);
        //获取筛选范围内总的技能点集合
        LinkedList<SkillCountVo> skillList = this.baseMapper.employeeSkillList(viewDataDto);
        //处理skillList数据;每条数据的长度不一样，要处理成一样的，并且保证顺序一致
        processSkillPointData1(skillList, employeeViewDataVoList);
        employeeViewDataVoList = BeanUtil.copyToList(employeeViewDataVoList, EmployeeViewDataVo.class).stream()
                .sorted(Comparator.comparing(EmployeeViewDataVo::getTotalCount).reversed()
                        .thenComparing(dto -> Optional.ofNullable(dto.getUserName()).orElse("")))
                .collect(Collectors.toList());
        AtomicInteger rank = new AtomicInteger(1);
        employeeViewDataVoList.forEach(vo -> vo.setRank(rank.getAndIncrement()));
        return employeeViewDataVoList;
    }

    @Override
    public TodaySummaryDataVo getTodaySummary(String storeId) {
        //获取有数组权限的用户集合
        List<String> userIdList = permissionHandling.getUserIdsByUserId(UserProvider.getUser().getUserId());
        LambdaQueryWrapper<TeachingRecord> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(TeachingRecord::getStoreId, storeId);
        if (CollUtil.isEmpty(userIdList)) {
            return new TodaySummaryDataVo();
        } else {
            queryWrapper.in(TeachingRecord::getUserId, userIdList);
        }
        queryWrapper.eq(TeachingRecord::getType, TeachingRecordTypeEnum.LX.getCode());
        queryWrapper.between(TeachingRecord::getDate, DateUtil.beginOfMonth(new Date()), DateUtil.endOfMonth(new Date()));
        queryWrapper.eq(TeachingRecord::getDeleteMark, 0);
        List<TeachingRecord> teachingRecordList = this.baseMapper.selectList(queryWrapper);
        if (CollUtil.isNotEmpty(teachingRecordList)) {
            return TodaySummaryDataVo.builder()
                    .totalCount(teachingRecordList.size())
                    .totalUserCount(teachingRecordList.stream().map(TeachingRecord::getUserId).distinct().count())
                    .build();
        }
        return new TodaySummaryDataVo();
    }

    @Override
    @Transactional
    public Boolean createSimulatedData(String tenantId) {
        List<TeachingSkill> skillList = teachingSkillService.lambdaQuery().eq(TeachingSkill::getDeleteMark, 0).list();
        Assert.notEmpty(skillList, "未查询到技能点信息");
        // 查询用户数据
        ActionResult<List<UserBoundVO>> usersBound = v2UserApi.getAllUserInfoBatch(List.of(), tenantId);
        Assert.isTrue(usersBound.getCode().equals(200), "查询用户门店信息异常");
        List<UserBoundVO> moreBoundInfoList = usersBound.getData();
        Assert.notEmpty(moreBoundInfoList, "未查询到用户组织门店信息");
        //排除掉没有门店信息的用户
        moreBoundInfoList.removeIf(item -> Objects.isNull(item.getOrganizeCategory()) || !item.getOrganizeCategory().equals(OrganizeCategoryEnums.STORE.getCode()) || StrUtil.isBlank(item.getPositionId()));
        Assert.notEmpty(moreBoundInfoList, "过滤后暂无用户！");
        String videoPath = "https://jnpf-resource-1304460613.cos.ap-chengdu.myqcloud.com/jnpf-resources/WebAnnexFile/20250903/20250903_153338__974453.mp4";
        BigDecimal videoDuration = BigDecimal.valueOf(71);
        int videoActionType = 1;
        Date currentDate = new Date();
        Collections.shuffle(skillList);
        List<TeachingSkill> skillList3 = skillList.stream().limit(3).collect(Collectors.toList());
        List<TeachingStudent> saveStudentList = new ArrayList<>();
        List<TeachingRecord> saveDataList = skillList3.stream()
                .flatMap(item -> moreBoundInfoList.stream().flatMap(user -> {
                    // 为每个门店生成数据
                    TeachingRecord lxRecord = TeachingRecord.builder()
                            .type(TeachingRecordTypeEnum.LX.getCode())
                            .skillId(item.getId())
                            .userId(user.getId())
                            .userName(user.getUserName())
                            .postId(user.getPositionId())
                            .postName(user.getPositionName())
                            .storeId(user.getOrganizeId())
                            .storeName(user.getOrganizeName())
                            .videoPath(videoPath)
                            .videoDuration(videoDuration)
                            .videoActionType(videoActionType)
                            .date(currentDate)
                            .build();
                    return Stream.of(lxRecord);
                })).collect(Collectors.toList());
        Map<String, List<UserBoundVO>> storeIdMap = moreBoundInfoList.stream().collect(Collectors.groupingBy(UserBoundVO::getOrganizeId));
        saveDataList.addAll(skillList3.stream()
                .flatMap(skill -> storeIdMap.entrySet().stream().flatMap(storeEntry -> {
                    String storeId = storeEntry.getKey();
                    List<UserBoundVO> storeUsers = storeEntry.getValue();
                    return storeUsers.stream().map(currentUser -> {
                        // 为当前用户生成数据
                        TeachingRecord djRecord = TeachingRecord.builder()
                                .type(TeachingRecordTypeEnum.DJ.getCode())
                                .skillId(skill.getId())
                                .userId(currentUser.getId())
                                .userName(currentUser.getUserName())
                                .postId(currentUser.getPositionId())
                                .postName(currentUser.getPositionName())
                                .storeId(storeId)
                                .storeName(currentUser.getOrganizeName())
                                .videoPath(videoPath)
                                .videoDuration(videoDuration)
                                .videoActionType(videoActionType)
                                .date(currentDate)
                                .build();
                        djRecord.setId(RandomUtil.uuId());
                        // 获取同一门店下除自己外的其他用户（最多4个）
                        List<UserBoundVO> otherStoreUsers = storeUsers.stream()
                                .filter(user -> !user.getId().equals(currentUser.getId()))
                                .limit(4).collect(Collectors.toList());
                        // 为djRecord添加学生（不包含自己）
                        if (!otherStoreUsers.isEmpty()) {
                            List<TeachingStudent> students = otherStoreUsers.stream()
                                    .map(otherUser -> TeachingStudent.builder()
                                            .recordId(djRecord.getId())
                                            .userId(otherUser.getId())
                                            .username(otherUser.getUserName())
                                            .postId(otherUser.getPositionId())
                                            .postName(otherUser.getPositionName())
                                            .creatorUserId(currentUser.getId())
                                            .creatorTime(currentDate)
                                            .build()).collect(Collectors.toList());
                            saveStudentList.addAll(students);
                        }
                        return djRecord;
                    });
                })).collect(Collectors.toList()));
        if (CollUtil.isNotEmpty(saveStudentList)) {
            this.teachingStudentService.saveBatch(saveStudentList);
        }
        if (CollUtil.isNotEmpty(saveDataList)) {
            this.saveBatch(saveDataList);
        }
        return true;
    }

    @Override
    public MyPracticeSummaryVo getMyPracticeSummary(String storeId) {
        LambdaQueryWrapper<TeachingRecord> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(TeachingRecord::getStoreId, storeId);
        queryWrapper.eq(TeachingRecord::getUserId, UserProvider.getLoginUserId());
        queryWrapper.eq(TeachingRecord::getType, 2);
        queryWrapper.eq(TeachingRecord::getDeleteMark, 0);
        List<TeachingRecord> teachingRecordList = this.list(queryWrapper);
        if (CollUtil.isEmpty(teachingRecordList)) {
            return new MyPracticeSummaryVo(0, BigDecimal.ZERO);
        }
        return MyPracticeSummaryVo.builder()
                .count(teachingRecordList.size())
                .duration(teachingRecordList.stream().map(TeachingRecord::getVideoDuration).reduce(BigDecimal.ZERO,
                        BigDecimal::add).divide(BigDecimal.valueOf(60), 2, RoundingMode.HALF_UP))
                .build();
    }

    /**
     * 处理skillList数据;每条数据的长度不一样，要处理成一样的，并且保证顺序一致
     *
     * @param skillList      技能点集合
     * @param pageListVoList 待处理数据
     */
    private void processSkillPointData1(LinkedList<SkillCountVo> skillList, List<EmployeeViewDataVo> pageListVoList) {
        //获取所有技能点,并且按照sort字段排序
        List<SkillCountVo> sortedSkillList = skillList.stream()
                .filter(item -> item.getDeleteMark().equals(0))
                .sorted(Comparator.comparing(SkillCountVo::getSort))
                .collect(Collectors.toList());
        //获取已删除的技能点
        List<SkillCountVo> deleteSkillList = skillList.stream()
                .filter(item -> item.getDeleteMark().equals(1))
                .sorted(Comparator.comparing(SkillCountVo::getSort))
                .collect(Collectors.toList());
        if (CollUtil.isNotEmpty(deleteSkillList)) {
            sortedSkillList.addAll(deleteSkillList);
        }
        LinkedHashMap<String, SkillCountVo> skillCountVoMap = sortedSkillList.stream().collect(Collectors.toMap(SkillCountVo::getName,
                skillCountVo -> skillCountVo, (k1, k2) -> k1, LinkedHashMap::new));
        Map<String, SkillCountVo> skillCountMap;
        for (EmployeeViewDataVo pageListVo : pageListVoList) {
            skillCountMap = pageListVo.getSkillList().stream().collect(Collectors.toMap(SkillCountVo::getName, skillCountVo -> skillCountVo, (k1, k2) -> k1));
            Map<String, SkillCountVo> finalSkillCountMap = skillCountMap;
            LinkedList<SkillCountVo> skillListData = new LinkedList<>();
            skillCountVoMap.forEach((name, skillCountVo) -> {
                if (finalSkillCountMap.containsKey(name)) {
                    skillListData.add(finalSkillCountMap.get(name));
                } else {
                    skillListData.add(SkillCountVo.builder()
                            .name(skillCountVo.getName())
                            .count(0)
                            .build());
                }
            });
            pageListVo.setSkillList(skillListData);
        }
    }

    /**
     * 处理skillList数据;每条数据的长度不一样，要处理成一样的，并且保证顺序一致
     *
     * @param skillList      技能点集合
     * @param pageListVoList 待处理数据
     */
    private void processSkillPointData(LinkedList<SkillCountVo> skillList, List<SummaryPageListVo> pageListVoList) {
        //获取所有技能点,并且按照sort字段排序
        List<SkillCountVo> sortedSkillList = skillList.stream()
                .filter(item -> item.getDeleteMark().equals(0))
                .sorted(Comparator.comparing(SkillCountVo::getSort))
                .collect(Collectors.toList());
        //获取已删除的技能点
        List<SkillCountVo> deleteSkillList = skillList.stream()
                .filter(item -> item.getDeleteMark().equals(1))
                .sorted(Comparator.comparing(SkillCountVo::getSort))
                .collect(Collectors.toList());
        if (CollUtil.isNotEmpty(deleteSkillList)) {
            sortedSkillList.addAll(deleteSkillList);
        }
        LinkedHashMap<String, SkillCountVo> skillCountVoMap = sortedSkillList.stream().collect(Collectors.toMap(SkillCountVo::getName, skillCountVo -> skillCountVo, (k1, k2) -> k1, LinkedHashMap::new));
        Map<String, SkillCountVo> skillCountMap;
        for (SummaryPageListVo pageListVo : pageListVoList) {
            skillCountMap = pageListVo.getSkillList().stream().collect(Collectors.toMap(SkillCountVo::getName, skillCountVo -> skillCountVo, (k1, k2) -> k1));
            Map<String, SkillCountVo> finalSkillCountMap = skillCountMap;
            LinkedList<SkillCountVo> skillListData = new LinkedList<>();
            skillCountVoMap.forEach((name, skillCountVo) -> {
                if (finalSkillCountMap.containsKey(name)) {
                    skillListData.add(finalSkillCountMap.get(name));
                } else {
                    skillListData.add(SkillCountVo.builder()
                            .name(skillCountVo.getName())
                            .count(0)
                            .build());
                }
            });
            pageListVo.setSkillList(skillListData);
        }
    }
}