package jnpf.cultivate.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jnpf.base.UserInfo;
import jnpf.cultivate.mapper.*;
import jnpf.cultivate.service.FtbCultivateExamService;
import jnpf.cultivate.service.FtbCultivatePromotionNewService;
import jnpf.cultivate.service.FtbCultivateStoreStatisticService;
import jnpf.cultivate.utils.UserApiV2Util;
import jnpf.emnus.MiniAppEnum;
import jnpf.emnus.WorkStatusEnum;
import jnpf.emnus.WorkTypeEnum;
import jnpf.entity.cultivate.CultivateIdentifyApply;
import jnpf.model.cultivate.dto.storestatistics.*;
import jnpf.model.cultivate.dto.storestatistics.dto.StoreCultivateTaskDto;
import jnpf.model.cultivate.dto.storestatistics.dto.StoreOfflineTrainDto;
import jnpf.model.cultivate.po.exam.FtbCultivateExam;
import jnpf.model.cultivate.po.exam.FtbCultivateExamUser;
import jnpf.model.cultivate.po.position.FtbCultivatePosition;
import jnpf.model.cultivate.po.promotion.FtbCultivatePromotionPostNew;
import jnpf.model.cultivate.resp.AppExamListVo;
import jnpf.model.cultivate.v2.apply.req.V2IdentifyApplyListAppReq;
import jnpf.model.cultivate.v2.apply.vo.V2IdentifyApplyListAppVo;
import jnpf.model.cultivate.vo.common.InnerPowerUserVO;
import jnpf.model.cultivate.vo.position.FtbCultivateStoreCountVO;
import jnpf.model.cultivate.vo.position.FtbCultivateWorkerCountVO;
import jnpf.model.cultivate.vo.position.FtbPersonTrainingStatisticsVO;
import jnpf.model.cultivate.vo.position.FtbStoreManagerTrainingStatisticsVO;
import jnpf.model.enums.CourseEnums;
import jnpf.model.thousandsfaces.TodayWorkVo;
import jnpf.permission.vo.v2.user.UserBoundVO;
import jnpf.util.UserProvider;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;

@Service
@Slf4j
public class FtbCultivateStoreStatisticsServiceImpl implements FtbCultivateStoreStatisticService {
    private static final String IDENTITY_CODE = "startEvaluation";//鉴定权限编码
    private static final String EXAM_CODE = "startMarking";//批阅考试权限编码

    @Autowired
    CultivateIdentifyApplyTableBackupsMapper cultivateIdentifyApplyTableBackupsMapper;
    @Autowired
    FtbCultivatePromotionMemberNewMapper ftbCultivatePromotionMemberNewMapper;
    @Autowired
    FtbCultivatePromotionNewMapper ftbCultivatePromotionNewMapper;
    @Autowired
    private FtbCultivateLearnTaskAssignmentMapper assignmentMapper;
    @Autowired
    private CultivateIdentifyApplyMapper identifyApplyMapper;
    @Autowired
    private FtbCultivateExamUserMapper ftbCultivateExamUserMapper;
    @Autowired
    private FtbCultivateOfflineTrainMapper ftbCultivateOfflineTrainMapper;
    /**
     * 考试服务
     */
    @Autowired
    private FtbCultivateExamService examService;
    @Autowired
    private FtbCultivatePositionStatisticesMapper ftbCultivatePositionStatisticesMapper;
    @Autowired
    private UserApiV2Util userApiV2Util;
    @Autowired
    private FtbCultivatePromotionNewService promotionService;

    @Autowired
    private FtbCultivateCourseMapper ftbCultivateCourseMapper;

    @Autowired
    private FtbCultivatePositionCourceLearningMapper ftbCultivatePositionCourceLearningMapper;

    @Autowired
    private FtbCultivatePositionMapper ftbCultivatePositionMapper;

    @Autowired
    private FtbCultivatePositionCourseMapper ftbCultivatePositionCourseMapper;


    @Override
    public FtbCultivateStoreCountVO getCultivateCount(FtbCultivateStoreStatisticsReq req) {

        FtbCultivateStoreCountVO returnDto = new FtbCultivateStoreCountVO();
//        获取当前登录的用户id
        String userId = UserProvider.getLoginUserId();

        UserInfo userInfo = UserProvider.getUser();
        String mainPositionId = "";
        String gradeId = "";
        UserBoundVO userPrimaryBoundOne = userApiV2Util.getUserPrimaryBoundOne(userId, userInfo.getTenantId());

        // 判断用户绑定信息是否为null
        if (userPrimaryBoundOne == null || StringUtils.isBlank(userPrimaryBoundOne.getPositionId())) {
            returnDto.setPositionNotLearnedCount(0L);
            returnDto.setPositionTotleLearnedCount(0L);
            returnDto.setPositionCompleteLearnedCount(0L);
            return returnDto;
        }

        mainPositionId = userPrimaryBoundOne.getPositionId();
        gradeId = userPrimaryBoundOne.getGradeId();

        // 根据V2岗位学习匹配规则查询课程
        selectCourseNumByV2Rule(returnDto, mainPositionId, gradeId, userId);

        return returnDto;

    }


    /**
     * 根据V2岗位学习匹配规则查询课程数量
     * 匹配规则：
     * 1. 如果岗位未配置到职级（isConfiguredToGrade=0）：查询该岗位下的所有课程
     * 2. 如果岗位配置到职级（isConfiguredToGrade=1）：
     * - 用户有职级：查询该岗位+该职级的课程
     * - 用户无职级：返回空结果
     *
     * @param returnDto  返回对象
     * @param positionId 岗位ID
     * @param gradeId    职级ID
     * @param userId     用户ID
     */
    private void selectCourseNumByV2Rule(FtbCultivateStoreCountVO returnDto, String positionId, String gradeId, String userId) {
        // 1. 查询岗位学习配置
        LambdaQueryWrapper<FtbCultivatePosition> positionWrapper = Wrappers.lambdaQuery();
        positionWrapper.eq(FtbCultivatePosition::getPostId, positionId)
                .eq(FtbCultivatePosition::getEnabledMark, 0)
                .eq(FtbCultivatePosition::getIsGrounding, 1); // 只查询上架的岗位学习
        FtbCultivatePosition cultivatePosition = ftbCultivatePositionMapper.selectOne(positionWrapper);

        if (cultivatePosition == null) {
            // 该岗位尚未配置岗位学习
            returnDto.setPositionNotLearnedCount(0L);
            returnDto.setPositionTotleLearnedCount(0L);
            returnDto.setPositionCompleteLearnedCount(0L);
            return;
        }

        // 2. 如果配置到职级但用户无职级，返回空结果
        if (cultivatePosition.getIsConfiguredToGrade() == 1 && StringUtils.isBlank(gradeId)) {
            returnDto.setPositionNotLearnedCount(0L);
            returnDto.setPositionTotleLearnedCount(0L);
            returnDto.setPositionCompleteLearnedCount(0L);
            return;
        }

        // 3. 使用XML关联查询获取所有课程ID列表（直接JOIN课程表过滤）
        List<String> courseIds = ftbCultivatePositionCourseMapper.queryCourseIdsByPositionAndGrade(
                cultivatePosition.getId(),
                cultivatePosition.getIsConfiguredToGrade(),
                gradeId
        );

        // 4. 统计课程总数
        Long courseTotleNum = CollUtil.isEmpty(courseIds) ? 0L : (long) courseIds.size();

        if (courseTotleNum == 0) {
            returnDto.setPositionNotLearnedCount(0L);
            returnDto.setPositionTotleLearnedCount(0L);
            returnDto.setPositionCompleteLearnedCount(0L);
            return;
        }

        // 5. 根据课程ID列表和用户ID统计已学习课程数（state=1表示已完成）
        Long studyCourseTotleNum = ftbCultivatePositionCourceLearningMapper.countCompletedCoursesByUserAndCourseIds(
                courseIds,
                userId
        );

        if (studyCourseTotleNum == null) {
            studyCourseTotleNum = 0L;
        }

        Long noStudyCourseNum = courseTotleNum - studyCourseTotleNum;

        returnDto.setPositionNotLearnedCount(noStudyCourseNum);
        returnDto.setPositionTotleLearnedCount(courseTotleNum);
        returnDto.setPositionCompleteLearnedCount(studyCourseTotleNum);
    }

    /**
     * 根据V2岗位学习匹配规则查询个人培训统计的课程数量
     * 匹配规则：
     * 1. 如果岗位未配置到职级（isConfiguredToGrade=0）：查询该岗位下的所有课程
     * 2. 如果岗位配置到职级（isConfiguredToGrade=1）：
     * - 用户有职级：查询该岗位+该职级的课程
     * - 用户无职级：返回空结果
     *
     * @param vo         个人培训统计VO
     * @param positionId 岗位ID
     * @param gradeId    职级ID
     * @param userId     用户ID
     */
    private void selectPersonCourseNumByV2Rule(FtbPersonTrainingStatisticsVO vo, String positionId, String gradeId, String userId) {
        // 1. 查询岗位学习配置
        LambdaQueryWrapper<FtbCultivatePosition> positionWrapper = Wrappers.lambdaQuery();
        positionWrapper.eq(FtbCultivatePosition::getPostId, positionId)
                .eq(FtbCultivatePosition::getEnabledMark, 0)
                .eq(FtbCultivatePosition::getIsGrounding, 1); // 只查询上架的岗位学习
        FtbCultivatePosition cultivatePosition = ftbCultivatePositionMapper.selectOne(positionWrapper);

        if (cultivatePosition == null) {
            // 该岗位尚未配置岗位学习
            vo.setCourseTotalCnt(0L);
            vo.setCourseCompleteCnt(0L);
            vo.setCourseStudyMinute("0");
            return;
        }

        // 2. 如果配置到职级但用户无职级，返回空结果
        if (cultivatePosition.getIsConfiguredToGrade() == 1 && StringUtils.isBlank(gradeId)) {
            vo.setCourseTotalCnt(0L);
            vo.setCourseCompleteCnt(0L);
            vo.setCourseStudyMinute("0");
            return;
        }

        // 3. 使用XML关联查询获取所有课程ID列表（直接JOIN课程表过滤）
        List<String> courseIds = ftbCultivatePositionCourseMapper.queryCourseIdsByPositionAndGrade(
                cultivatePosition.getId(),
                cultivatePosition.getIsConfiguredToGrade(),
                gradeId
        );

        // 4. 统计课程总数
        Long courseTotleNum = CollUtil.isEmpty(courseIds) ? 0L : (long) courseIds.size();

        if (courseTotleNum == 0) {
            vo.setCourseTotalCnt(0L);
            vo.setCourseCompleteCnt(0L);
            vo.setCourseStudyMinute("0");
            return;
        }

        // 5. 根据课程ID列表和用户ID统计已学习课程数（state=1表示已完成）
        Long studyCourseTotleNum = ftbCultivatePositionCourceLearningMapper.countCompletedCoursesByUserAndCourseIds(
                courseIds,
                userId
        );

        if (studyCourseTotleNum == null) {
            studyCourseTotleNum = 0L;
        }

        // 6. 设置课程总数和已完成数
        vo.setCourseTotalCnt(courseTotleNum);
        vo.setCourseCompleteCnt(studyCourseTotleNum);

        // 7. 统计学习时长（分钟）
        if (CollUtil.isNotEmpty(courseIds)) {
            Long studyTime = ftbCultivatePositionCourceLearningMapper.queryStudyTime(courseIds, userId);
            if (studyTime != null && studyTime > 0) {
                Long result = studyTime / 60;
                vo.setCourseStudyMinute(result.toString());
            } else {
                vo.setCourseStudyMinute("0");
            }
        } else {
            vo.setCourseStudyMinute("0");
        }
    }


    /**
     * 我的考试列表
     *
     * @param req
     * @return
     */
    @Override
    public List<TodayWorkVo> queryMyExamList(StoreStatisticsMyExamReq req) {
        //今日工作-我的考试<已知的岗位考试及自定义考试>列表
        //待完成(待考试)/已逾期(已逾期)/已完成(已完成)
        //获取当前用户信息
        String loginUserId = UserProvider.getLoginUserId();
        List<AppExamListVo> ftbCultivateExamUsers = ftbCultivateExamUserMapper.storeMyExamList(loginUserId);
        if (CollUtil.isEmpty(ftbCultivateExamUsers)) {
            return new ArrayList<>();
        }
        String today = DateUtil.format(new Date(), "yyyy-MM-dd");
        List<TodayWorkVo> returnList = new ArrayList<>();
        for (AppExamListVo entity : ftbCultivateExamUsers) {

            TodayWorkVo todayWorkVo = new TodayWorkVo();
            todayWorkVo.setWorkType(WorkTypeEnum.MY_EXAM);
            todayWorkVo.setCreatorTime(entity.getCreateTime());
            Map<String, String> paramMap = new HashMap<>();
            paramMap.put("examId", entity.getExamId());
            paramMap.put("userExamId", entity.getId());
//            0待考试，1待批阅，2已逾期，3合格，4不合格 5优秀
            if (entity.getStatus().equals(0)) {
                todayWorkVo.setMiniApp(MiniAppEnum.EXAM_TODO_DETAIL);
                if (entity.getExamType().equals(0)) {
                    todayWorkVo.setCreatorTime(entity.getCreateTime());
                    todayWorkVo.setWorkStatus(WorkStatusEnum.TO_DO);
                } else {
                    if (entity.getStartTime() == null) {
                        todayWorkVo.setCreatorTime(entity.getCreateTime());
                        todayWorkVo.setWorkStatus(WorkStatusEnum.TO_DO);
                    } else if (entity.getStartTime().getTime() > new Date().getTime()) {
                        continue;
                    } else {
                        todayWorkVo.setCreatorTime(entity.getCreateTime());
                        todayWorkVo.setWorkStatus(WorkStatusEnum.TO_DO);
                    }
                }
            } else if (entity.getStatus().equals(1)) {
                todayWorkVo.setMiniApp(MiniAppEnum.EXAM_TODO_DETAIL);
                todayWorkVo.setCreatorTime(entity.getFinishTime());
                String completeTime = DateUtil.format(entity.getFinishTime(), "yyyy-MM-dd");
                if (today.equals(completeTime)) {
                    todayWorkVo.setWorkStatus(WorkStatusEnum.FINISHED);
                } else {
                    continue;
                }
            } else if (List.of(3, 4, 5).contains(entity.getStatus())) {
                todayWorkVo.setMiniApp(MiniAppEnum.EXAM_RESULT_DETAIL);
                todayWorkVo.setCreatorTime(entity.getFinishTime());
                String completeTime = DateUtil.format(entity.getFinishTime(), "yyyy-MM-dd");
                if (today.equals(completeTime)) {
                    todayWorkVo.setWorkStatus(WorkStatusEnum.FINISHED);
                } else {
                    continue;
                }
            } else if (entity.getStatus().equals(2)) {
                todayWorkVo.setMiniApp(MiniAppEnum.EXAM_TODO_DETAIL);
                todayWorkVo.setCreatorTime(entity.getLastModifyTime());
                String lastModifyTime = DateUtil.format(entity.getLastModifyTime(), "yyyy-MM-dd");
                if (today.equals(lastModifyTime)) {
                    todayWorkVo.setWorkStatus(WorkStatusEnum.OVERDUE);
                } else {
                    continue;
                }
            }
//
            todayWorkVo.setTitle(entity.getExamName());
            todayWorkVo.setFinishDate(entity.getEndTime());
            todayWorkVo.setWorkId(entity.getId());
            todayWorkVo.setExtraJson(JSONUtil.toJsonStr(paramMap));
            returnList.add(todayWorkVo);
        }
        return returnList;
    }

    /**
     * 待我批阅
     *
     * @param req
     * @return
     */
    @Override
    public List<TodayWorkVo> queryWaitMyReadOver(StoreStatisticsWaitMyCheckExamReq req) {
        //待完成(待批阅)/已完成(已批阅)
        //带我批阅
        String userId = UserProvider.getLoginUserId();
        String tenantId = UserProvider.getUser().getTenantId();
        UserBoundVO userPrimaryBoundOne = userApiV2Util.getUserPrimaryBoundOne(userId, tenantId);

        List<String> btnList = userApiV2Util.queryUserBtnPermissionList(userPrimaryBoundOne);
        if (!btnList.contains(EXAM_CODE)) {
            return new ArrayList<>();
        }
        List<String> powerUserIdsForTrain = userApiV2Util.getPowerUserIdsForTrain(userId, tenantId);
        //今日开始时间
        Date todayStartTime = DateUtil.beginOfDay(new Date());
        //今日结束时间
        Date todayEndTime = DateUtil.endOfDay(new Date());
        List<TodayWorkVo> returnList = new ArrayList<>();
        Set<String> examIdList = new HashSet<>();
        Map<String, FtbCultivateExam> examMap = new HashMap<>();
        LambdaQueryWrapper<FtbCultivateExamUser> wrapper = new LambdaQueryWrapper<FtbCultivateExamUser>()
                .select(FtbCultivateExamUser::getId, FtbCultivateExamUser::getStatus, FtbCultivateExamUser::getUserId, FtbCultivateExamUser::getFinishTime, FtbCultivateExamUser::getExamId, FtbCultivateExamUser::getExamSource, FtbCultivateExamUser::getReviewerUserIds, FtbCultivateExamUser::getLastModifyTime)
                .eq(FtbCultivateExamUser::getStatus, 1) //（0待考试，1待批阅，2已逾期，3合格，4不合格 5优秀）
                .eq(FtbCultivateExamUser::getIsJoinCount, 0)
                .in(CollUtil.isNotEmpty(powerUserIdsForTrain), FtbCultivateExamUser::getUserId, powerUserIdsForTrain)
                .eq(FtbCultivateExamUser::getEnabledMark, CourseEnums.EnabledMarkType.VALID.getCode());
        List<FtbCultivateExamUser> ftbCultivateExamUsers = ftbCultivateExamUserMapper.selectList(wrapper);

        LambdaQueryWrapper<FtbCultivateExamUser> wrapperTodayComplate = new LambdaQueryWrapper<FtbCultivateExamUser>()
                .select(FtbCultivateExamUser::getId, FtbCultivateExamUser::getStatus, FtbCultivateExamUser::getUserId, FtbCultivateExamUser::getFinishTime, FtbCultivateExamUser::getExamId, FtbCultivateExamUser::getExamSource, FtbCultivateExamUser::getReviewerUserIds, FtbCultivateExamUser::getLastModifyTime)
                .in(FtbCultivateExamUser::getStatus, 3, 4, 5) //（0待考试，1待批阅，2已逾期，3合格，4不合格 5优秀）
                .eq(FtbCultivateExamUser::getIsJoinCount, 0)
                .eq(FtbCultivateExamUser::getReviewerUserId, userId)
                .between(FtbCultivateExamUser::getLastModifyTime, todayStartTime, todayEndTime)
                .eq(FtbCultivateExamUser::getEnabledMark, CourseEnums.EnabledMarkType.VALID.getCode());
        List<FtbCultivateExamUser> complateList = ftbCultivateExamUserMapper.selectList(wrapperTodayComplate);

        if (CollectionUtil.isNotEmpty(complateList)) {
            for (FtbCultivateExamUser entity : complateList) {
                examIdList.add(entity.getExamId());
            }
        }
        if (CollectionUtil.isNotEmpty(ftbCultivateExamUsers)) {
            for (FtbCultivateExamUser entity : ftbCultivateExamUsers) {
                examIdList.add(entity.getExamId());
            }
        }
        if (CollUtil.isNotEmpty(examIdList)) {
            LambdaQueryWrapper<FtbCultivateExam> wrapper1 = new LambdaQueryWrapper<FtbCultivateExam>()
                    .select(FtbCultivateExam::getId, FtbCultivateExam::getExamId, FtbCultivateExam::getExamName, FtbCultivateExam::getReviewerAppoint, FtbCultivateExam::getReviewerAppointListConfig, FtbCultivateExam::getReviewer)
                    .in(FtbCultivateExam::getId, examIdList)
                    .eq(FtbCultivateExam::getEnabledMark, CourseEnums.EnabledMarkType.VALID.getCode());
            List<FtbCultivateExam> ftbCultivateExams = examService.list(wrapper1);
            if (CollectionUtil.isNotEmpty(ftbCultivateExams)) {
                for (FtbCultivateExam exam : ftbCultivateExams) {
                    examMap.put(exam.getId(), exam);
                }
            }
        }


        if (CollectionUtil.isNotEmpty(ftbCultivateExamUsers)) {

            for (FtbCultivateExamUser entity : ftbCultivateExamUsers) {
                FtbCultivateExam ftbCultivateExam = examMap.get(entity.getExamId());
                if (ftbCultivateExam != null) {
                    TodayWorkVo todayWorkVo = new TodayWorkVo();
                    todayWorkVo.setWorkType(WorkTypeEnum.MARK_EXAM);
                    todayWorkVo.setCreatorTime(entity.getFinishTime());
                    //0待考试，1待批阅，2已逾期，3合格，4不合格 5优秀
                    todayWorkVo.setWorkStatus(WorkStatusEnum.TO_DO);
                    todayWorkVo.setTitle(ftbCultivateExam.getExamName());
                    todayWorkVo.setFinishDate(entity.getEndTime());
                    todayWorkVo.setWorkId(entity.getId());
                    todayWorkVo.setMiniApp(MiniAppEnum.EXAM_CHECK_DETAIL);
                    Map<String, String> paramMap = new HashMap<>();
                    paramMap.put("examId", entity.getExamId());
                    paramMap.put("id", entity.getId());
                    todayWorkVo.setExtraJson(JSONUtil.toJsonStr(paramMap));
                    returnList.add(todayWorkVo);
                }

            }
        }
        //今日完成批阅
        if (CollectionUtil.isNotEmpty(complateList)) {

            for (FtbCultivateExamUser entity : complateList) {
                FtbCultivateExam ftbCultivateExam = examMap.get(entity.getExamId());
                if (ftbCultivateExam != null) {
                    TodayWorkVo todayWorkVo = new TodayWorkVo();
                    todayWorkVo.setWorkType(WorkTypeEnum.TRAIN);
                    todayWorkVo.setCreatorTime(entity.getFinishTime());
                    //0待考试，1待批阅，2已逾期，3合格，4不合格 5优秀
                    todayWorkVo.setWorkStatus(WorkStatusEnum.FINISHED);
                    todayWorkVo.setTitle(ftbCultivateExam.getExamName());
                    todayWorkVo.setFinishDate(entity.getEndTime());
                    todayWorkVo.setWorkId(entity.getId());
                    todayWorkVo.setMiniApp(MiniAppEnum.EXAM_DETAIL);
                    Map<String, String> paramMap = new HashMap<>();
                    paramMap.put("id", entity.getId());
                    todayWorkVo.setExtraJson(JSONUtil.toJsonStr(paramMap));
                    returnList.add(todayWorkVo);
                }

            }
        }
        return returnList;
    }


    @Override
    public List<TodayWorkVo> queryOfflineTrainList(StoreOfflineTrainReq req) {
        //今日工作-待参与及参与中的线下培训<负责人及参与人均属于相关人员>列表
        //待完成(未开始、进行中)/已完成(已结束)
        List<TodayWorkVo> returnList = new ArrayList<>();
        String userId = UserProvider.getLoginUserId();
        //今日开始时间
        Date todayStartTime = DateUtil.beginOfDay(new Date());
        //今日结束时间
        Date todayEndTime = DateUtil.endOfDay(new Date());
        String today = DateUtil.format(new Date(), "yyyy-MM-dd");
        //查询参与人员
        List<StoreOfflineTrainDto> storeOfflineTrainDtos = ftbCultivateOfflineTrainMapper.queryMyOfflineTrainList(userId, todayStartTime, todayEndTime);
        if (CollUtil.isNotEmpty(storeOfflineTrainDtos)) {

            for (StoreOfflineTrainDto entity : storeOfflineTrainDtos) {
                TodayWorkVo todayWorkVo = new TodayWorkVo();
                todayWorkVo.setWorkType(WorkTypeEnum.OFFLINE_TRAIN);

                //0未开始，1已结束，2进行中
                if ((entity.getTrainStartTime().getTime() <= new Date().getTime()) && (entity.getTrainEndTime().getTime() >= new Date().getTime())) {
                    todayWorkVo.setWorkStatus(WorkStatusEnum.TO_DO);
                    todayWorkVo.setCreatorTime(entity.getTrainStartTime());
                }
                //未开始
                else if (entity.getTrainStartTime().getTime() > new Date().getTime()) {
                    continue;
                }
                //如果当前时间大于结束时间 一完成
                else if (entity.getTrainEndTime().getTime() < new Date().getTime()) {
                    todayWorkVo.setCreatorTime(entity.getTrainEndTime());
                    String endTime = DateUtil.format(entity.getTrainEndTime(), "yyyy-MM-dd");
                    if (today.equals(endTime)) {
                        todayWorkVo.setWorkStatus(WorkStatusEnum.FINISHED);
                    } else {
                        continue;
                    }
                }
                todayWorkVo.setTitle(entity.getName());
                todayWorkVo.setFinishDate(entity.getTrainEndTime());
                todayWorkVo.setWorkId(entity.getId());
                todayWorkVo.setMiniApp(MiniAppEnum.TRAIN_TASK_OFFLINE_DETAIL);
                Map<String, String> paramMap = new HashMap<>();
                paramMap.put("id", entity.getId());
                todayWorkVo.setExtraJson(JSONUtil.toJsonStr(paramMap));
                returnList.add(todayWorkVo);
            }
        }
        //查询负责人
        List<StoreOfflineTrainDto> headerList = ftbCultivateOfflineTrainMapper.queryMyOfflineTrainingHeader(userId, todayStartTime, todayEndTime);
        if (CollUtil.isNotEmpty(headerList)) {

            for (StoreOfflineTrainDto entity : headerList) {
                TodayWorkVo todayWorkVo = new TodayWorkVo();
                todayWorkVo.setWorkType(WorkTypeEnum.OFFLINE_TRAIN);

                //0未开始，1已结束，2进行中，3已撤回
                //判断当前时间是否再开始和结束时间范围内
                if ((entity.getTrainStartTime().getTime() <= new Date().getTime()) && (entity.getTrainEndTime().getTime() >= new Date().getTime())) {
                    todayWorkVo.setWorkStatus(WorkStatusEnum.TO_DO);
                    todayWorkVo.setCreatorTime(entity.getTrainStartTime());
                }
                //未开始
                else if (entity.getTrainStartTime().getTime() > new Date().getTime()) {
                    continue;
                } else if (entity.getTrainEndTime().getTime() < new Date().getTime()) {
                    todayWorkVo.setCreatorTime(entity.getTrainEndTime());
                    String endTime = DateUtil.format(entity.getTrainEndTime(), "yyyy-MM-dd");
                    if (today.equals(endTime)) {
                        todayWorkVo.setWorkStatus(WorkStatusEnum.FINISHED);
                    } else {
                        continue;
                    }
                }

                todayWorkVo.setTitle(entity.getName());
                todayWorkVo.setFinishDate(entity.getTrainEndTime());
                todayWorkVo.setWorkId(entity.getId());
                todayWorkVo.setMiniApp(MiniAppEnum.TRAIN_TASK_OFFLINE_DETAIL);
                Map<String, String> paramMap = new HashMap<>();
                paramMap.put("id", entity.getId());
                todayWorkVo.setExtraJson(JSONUtil.toJsonStr(paramMap));
                returnList.add(todayWorkVo);
            }
        }
        return returnList;
    }

    @Override
    public List<TodayWorkVo> storeMyTaskList(StoreOfflineTrainReq req) {
        //今日工作-我的任务（当日开始的培训任务）列表
        //待完成(待开始)/已逾期(已逾期)/已完成(已完成)
        String userId = UserProvider.getLoginUserId();
        List<StoreCultivateTaskDto> list = assignmentMapper.storeMyTaskList(userId);
        if (CollUtil.isEmpty(list)) {
            return new ArrayList<>();
        }
        List<TodayWorkVo> returnList = new ArrayList<>();
        String today = DateUtil.format(new Date(), "yyyy-MM-dd");
        for (StoreCultivateTaskDto entity : list) {
            TodayWorkVo todayWorkVo = new TodayWorkVo();
            todayWorkVo.setWorkType(WorkTypeEnum.TRAIN);
            //学习状态 0未开始，1进行中，2已完成，3已逾期
            if (entity.getStudyStats().equals(1)) {
                todayWorkVo.setCreatorTime(entity.getCreateTime());
                todayWorkVo.setWorkStatus(WorkStatusEnum.TO_DO);
            } else if (entity.getStudyStats().equals(0)) {
                if (entity.getTaskType().equals(1)) {
                    if ((entity.getTimeLimitStartTime().getTime() <= new Date().getTime()) && (entity.getTimeLimitEndTime().getTime() >= new Date().getTime())) {
                        todayWorkVo.setCreatorTime(entity.getTimeLimitStartTime());
                        todayWorkVo.setWorkStatus(WorkStatusEnum.TO_DO);
                    } else {
                        continue;
                    }
                } else {
                    todayWorkVo.setCreatorTime(entity.getCreateTime());
                    todayWorkVo.setWorkStatus(WorkStatusEnum.TO_DO);
                }
            } else if (entity.getStudyStats().equals(2)) {
                todayWorkVo.setCreatorTime(entity.getLearningEndTime());
                String learnEndTime = DateUtil.format(entity.getLearningEndTime(), "yyyy-MM-dd");
                if (learnEndTime != null && today.equals(learnEndTime)) {
                    todayWorkVo.setWorkStatus(WorkStatusEnum.FINISHED);
                } else {
                    continue;
                }
            } else if (entity.getStudyStats().equals(3)) {
                todayWorkVo.setCreatorTime(entity.getTimeLimitEndTime());
                String limitEndTime = DateUtil.format(entity.getTimeLimitEndTime(), "yyyy-MM-dd");
                if (limitEndTime != null && today.equals(limitEndTime)) {
                    todayWorkVo.setWorkStatus(WorkStatusEnum.OVERDUE);
                } else {
                    continue;
                }
            }
            Map<String, String> paramMap = new HashMap<>();
            paramMap.put("id", entity.getTaskId());
            todayWorkVo.setTitle(entity.getTaskName());
            todayWorkVo.setFinishDate(entity.getTimeLimitEndTime());
            todayWorkVo.setWorkId(entity.getId());
            todayWorkVo.setMiniApp(MiniAppEnum.TRAIN_TASK_DETAIL);
            todayWorkVo.setExtraJson(JSONUtil.toJsonStr(paramMap));
            returnList.add(todayWorkVo);
        }
        return returnList;
    }

    /**
     * 今日工作-我的鉴定列表
     *
     * @param req
     * @return
     */
    @Override
    public List<TodayWorkVo> storeMyIdentityList(StoreIdentityReq req) {
        String loginUserId = UserProvider.getLoginUserId();
        List<TodayWorkVo> returnList = new ArrayList<>();

        if (StringUtils.isEmpty(loginUserId)) {
            return returnList;
        }
        List<String> userIds = new ArrayList<>();
        //权限 + 鉴定人是自己的
        List<String> powerUserIds = userApiV2Util.getPermissionUserIds();
        List<String> myUserIds = this.identifyApplyMapper.queryMyIdentifyUserList(loginUserId);

        //待我鉴定的
        Page<V2IdentifyApplyListAppVo> waitMyIdentifyPage = Page.of(1000, -1);
        V2IdentifyApplyListAppReq waitMyIdentifyReq = new V2IdentifyApplyListAppReq();
        waitMyIdentifyPage = this.identifyApplyMapper.queryAppIdentifyApplyListWaiting(waitMyIdentifyPage, waitMyIdentifyReq, powerUserIds, myUserIds, loginUserId);


        processCultivateIdentifyApply(waitMyIdentifyPage.getRecords(), WorkStatusEnum.TO_DO, MiniAppEnum.ACTUAL_IDENTIFY_TODO_DETAIL, WorkTypeEnum.ACTUAL_IDENTIFY, returnList);
        //查询今日已完成的鉴定列表
        Page<V2IdentifyApplyListAppVo> todayCompletePage = Page.of(1000, -1);
        V2IdentifyApplyListAppReq todayCompleteReq = new V2IdentifyApplyListAppReq();
        // 设置今天的开始和结束时间
        todayCompleteReq.setStartTime(DateUtil.beginOfDay(new Date()));
        todayCompleteReq.setEndTime(DateUtil.endOfDay(new Date()));
        todayCompletePage = this.identifyApplyMapper.queryAppIdentifyApplyListComplete(todayCompletePage, todayCompleteReq, userIds, loginUserId);
        processCultivateIdentifyApply(todayCompletePage.getRecords(), WorkStatusEnum.FINISHED, MiniAppEnum.ACTUAL_IDENTIFY_DETAIL, WorkTypeEnum.ACTUAL_IDENTIFY, returnList);


        return returnList;
    }

    /**
     * 处理培育认定申请工作项
     *
     * @param planList     培育认定申请列表
     * @param workStatus   工作状态枚举
     * @param miniAppEnum  小程序枚举
     * @param workTypeEnum 工作类型枚举
     * @param result       结果列表，用于存储处理后的今日工作项
     */
    private void processCultivateIdentifyApply(List<V2IdentifyApplyListAppVo> planList, WorkStatusEnum
            workStatus, MiniAppEnum miniAppEnum, WorkTypeEnum workTypeEnum, List<TodayWorkVo> result) {
        if (CollUtil.isEmpty(planList)) {
            return;
        }
        List<TodayWorkVo> todayWorkVos = new ArrayList<>();
        for (V2IdentifyApplyListAppVo identifyApply : planList) {
            TodayWorkVo todayWorkVo = new TodayWorkVo();
            Map<String, String> paramMap = new HashMap<>();
            paramMap.put("id", identifyApply.getId());
            if (WorkStatusEnum.FINISHED == workStatus) {
                todayWorkVo.setCreatorTime(identifyApply.getCreatorTime());
                todayWorkVo.setFinishDate(identifyApply.getIdentifyTime());
            } else {
                todayWorkVo.setCreatorTime(identifyApply.getCreatorTime());
                paramMap.put("flag", "0");
            }
            todayWorkVo.setWorkType(workTypeEnum);
            todayWorkVo.setWorkStatus(workStatus);
            todayWorkVo.setTitle(identifyApply.getTableName());
            todayWorkVo.setWorkId(identifyApply.getId());
            todayWorkVo.setMiniApp(miniAppEnum);
            todayWorkVo.setExtraJson(JSONUtil.toJsonStr(paramMap));
            todayWorkVos.add(todayWorkVo);
        }
        result.addAll(todayWorkVos);
    }

    /**
     * 获取员工学习统计
     *
     * @param req
     * @return
     */
    public FtbCultivateWorkerCountVO getWorkerCultivateCount(FtbCultivateStoreStatisticsReq req) {
        FtbCultivateWorkerCountVO returnDto = new FtbCultivateWorkerCountVO();
        String userId = UserProvider.getLoginUserId();
        //未完成的通用课程数量
        returnDto.setNoStudyCommonCourseNum(ftbCultivateCourseMapper.queryNoStudyCommonCourseNum(userId));
        //未完成的考试的数量
        returnDto.setNoCompleteExamNum(ftbCultivateExamUserMapper.queryMyWaitingExamNum(userId));
        return returnDto;
    }

    /**
     * 个人培训统计
     *
     * @param req 统计参数
     * @return
     */
    @Override
    public FtbPersonTrainingStatisticsVO personTrainingStatistics(FtbCultivateStoreStatisticsReq req) {
        String userId = UserProvider.getLoginUserId();
        String tenantId = UserProvider.getUser().getTenantId();
        FtbPersonTrainingStatisticsVO vo = new FtbPersonTrainingStatisticsVO();
        vo.initData();
        //1、学习任务
        Long taskCompleteCnt = assignmentMapper.queryTaskNum(userId, 2, req);
        vo.setTaskCompleteCnt(taskCompleteCnt);
        Long taskTotalCnt = assignmentMapper.queryTaskNum(userId, 0, req);
        vo.setTaskTotalCnt(taskTotalCnt);
        BigDecimal taskCompleteRate = BigDecimal.ZERO;
        if (taskTotalCnt > 0) {
            taskCompleteRate = new BigDecimal(taskCompleteCnt).divide(new BigDecimal(taskTotalCnt), 4, RoundingMode.HALF_UP);
        }
        vo.setTaskCompleteRate(UserApiV2Util.dealWithRate(taskCompleteRate, ""));
        //2、岗位学习
        String mainPositionId = "";
        String gradeId = "";
        UserBoundVO userPrimaryBoundOne = userApiV2Util.getUserPrimaryBoundOne(userId, tenantId);
        if (userPrimaryBoundOne != null) {
            mainPositionId = userPrimaryBoundOne.getPositionId();
            gradeId = userPrimaryBoundOne.getGradeId();
        }

        // 根据V2岗位学习匹配规则查询课程数量
        selectPersonCourseNumByV2Rule(vo, mainPositionId, gradeId, userId);

//        3、考试
        List<AppExamListVo> ftbCultivateExamUsers = ftbCultivateExamUserMapper.storeMyExamList(userId);
        if (CollUtil.isNotEmpty(ftbCultivateExamUsers)) {
            Long examPassCnt = calPassCnt(ftbCultivateExamUsers);
            Long examTotalCnt = calTotalCnt(ftbCultivateExamUsers);
            if (examTotalCnt > 0) {
                vo.setExamPassRate(UserApiV2Util.dealWithRate(new BigDecimal(examPassCnt).divide(new BigDecimal(examTotalCnt), 4, RoundingMode.HALF_UP), ""));
            } else {
                vo.setExamPassRate(UserApiV2Util.dealWithRate(BigDecimal.ZERO, ""));
            }
            vo.setExamCnt(Long.valueOf(ftbCultivateExamUsers.size()));
        }

        //鉴定
        LambdaQueryWrapper<CultivateIdentifyApply> myWraper = Wrappers.lambdaQuery();
        myWraper.eq(CultivateIdentifyApply::getBeIdentifyUserId, userId);
        myWraper.isNotNull(CultivateIdentifyApply::getTableId);
        myWraper.eq(CultivateIdentifyApply::getIsVisible, 0);
        myWraper.eq(CultivateIdentifyApply::getDeleteMark, 0);
        List<CultivateIdentifyApply> myList = identifyApplyMapper.selectList(myWraper);
        if (CollUtil.isNotEmpty(myList)) {
            Long identificationPassCnt = calIdentifyPassCnt(myList);
            Long identificationTotalCnt = calIdentifyTotalCnt(myList);
            if (identificationTotalCnt > 0) {
                vo.setIdentificationPassRate(UserApiV2Util.dealWithRate(new BigDecimal(identificationPassCnt).divide(new BigDecimal(identificationTotalCnt), 4, RoundingMode.HALF_UP), ""));
            } else {
                vo.setIdentificationPassRate(UserApiV2Util.dealWithRate(BigDecimal.ZERO, ""));
            }
            vo.setIdentificationCnt((long) myList.size());
        }
        return vo;
    }

    /**
     * 计算培育认定申请列表中状态为1的记录总数
     *
     * @param myList 培育认定申请列表
     * @return 状态为1的培育认定申请记录总数
     */
    private Long calIdentifyTotalCnt(List<CultivateIdentifyApply> myList) {
        Long identificationTotalCnt = 0L;
        for (CultivateIdentifyApply cultivateIdentifyApply : myList) {
            if (cultivateIdentifyApply.getStatus() == 1) {
                identificationTotalCnt++;
            }
        }
        return identificationTotalCnt;
    }

    /**
     * 计算认证通过的数量
     *
     * @param myList 认证申请列表
     * @return 认证通过的数量
     */
    private Long calIdentifyPassCnt(List<CultivateIdentifyApply> myList) {
        Long identificationPassCnt = 0L;
        for (CultivateIdentifyApply my : myList) {
            if (my.getStatus() == 1 && (my.getResult() == 1 || my.getResult() == 0)) {
                identificationPassCnt++;
            }
        }
        return identificationPassCnt;
    }


    /**
     * 计算考试用户总数
     *
     * @param ftbCultivateExamUsers 考试用户列表
     * @return 不包含状态为1和2的用户数量
     */
    private Long calTotalCnt(List<AppExamListVo> ftbCultivateExamUsers) {
        Long examTotalCnt = 0L;
        for (AppExamListVo ftbCultivateExamUser : ftbCultivateExamUsers) {
            if (ftbCultivateExamUser.getStatus() != 1 && ftbCultivateExamUser.getStatus() != 2) {
                examTotalCnt++;
            }
        }
        return examTotalCnt;
    }

    /**
     * 计算考试通过人数
     *
     * @param ftbCultivateExamUsers 考试用户列表
     * @return 通过考试的人数
     */
    private Long calPassCnt(List<AppExamListVo> ftbCultivateExamUsers) {
        Long examPassCnt = 0L;
        for (AppExamListVo ftbCultivateExamUser : ftbCultivateExamUsers) {
            if (ftbCultivateExamUser.getStatus() == 3 || ftbCultivateExamUser.getStatus() == 5) {
                examPassCnt++;
            }
        }
        return examPassCnt;
    }

    /**
     * 工作台-店长界面统计
     *
     * @param req 统计参数
     * @return 统计结果
     */
    @Override
    public FtbStoreManagerTrainingStatisticsVO storeManagerTrainingStatistics(FtbCultivateStoreStatisticsReq req) {

        List<String> powerUserIds = new ArrayList<>();
        InnerPowerUserVO innerPowerUserVO = userApiV2Util.getLoginManagerUserIdsForEncode();
        if (innerPowerUserVO.getCode().equals(1)) {
            powerUserIds = innerPowerUserVO.getUserIds();
        } else if (innerPowerUserVO.getCode().equals(2)) {
            powerUserIds.add("-1");
        }

        FtbStoreManagerTrainingStatisticsVO vo = new FtbStoreManagerTrainingStatisticsVO();
        String userId = UserProvider.getLoginUserId();
        String tenantId = UserProvider.getUser().getTenantId();
        vo.initData();
        //1、学习任务
        Long taskCompleteCnt = assignmentMapper.queryTaskNum(userId, 2, req);
        Long taskTotalCnt = assignmentMapper.queryTaskNum(userId, 0, req);
        BigDecimal taskCompleteRate = BigDecimal.ZERO;
        if (taskTotalCnt > 0) {
            taskCompleteRate = new BigDecimal(taskCompleteCnt).divide(new BigDecimal(taskTotalCnt), 4, RoundingMode.HALF_UP);
        }
        vo.setTaskCompleteRate(UserApiV2Util.dealWithRate(taskCompleteRate, ""));
        //2、岗位学习
        String mainPositionId = "";
        UserBoundVO userPrimaryBoundOne = userApiV2Util.getUserPrimaryBoundOne(userId, tenantId);
        if (userPrimaryBoundOne != null) {
            mainPositionId = userPrimaryBoundOne.getPositionId();
        }
        String pomotionId = ftbCultivatePromotionMemberNewMapper.queryHasStudyMap(mainPositionId);
        List<String> courseIds = new ArrayList<>();
        if (StringUtils.isEmpty(pomotionId)) {
            Long courseTotleNum = ftbCultivatePositionStatisticesMapper.courseTotleNum(List.of(mainPositionId));
            // 已学习课程数
            List<String> studyCourseList = ftbCultivatePositionStatisticesMapper.queryComplateCourseLists(List.of(mainPositionId), userId);
            if (CollUtil.isNotEmpty(studyCourseList)) {
                courseIds = studyCourseList;
                vo.setCourseCompleteCnt(Long.valueOf(courseIds.size()));
            }
            vo.setCourseTotalCnt(courseTotleNum);
        } else {
            Integer currentLearningStage = ftbCultivatePromotionMemberNewMapper.queryCurrLevel(userId, pomotionId);
            if (currentLearningStage == null || currentLearningStage <= 1) {
                Long courseTotleNum = ftbCultivatePositionStatisticesMapper.courseTotleNum(List.of(mainPositionId));
                // 已学习课程数
                List<String> studyCourseList = ftbCultivatePositionStatisticesMapper.queryComplateCourseLists(List.of(mainPositionId), userId);
                if (CollUtil.isNotEmpty(studyCourseList)) {
                    courseIds = studyCourseList;
                    vo.setCourseCompleteCnt(Long.valueOf(courseIds.size()));
                }
                vo.setCourseTotalCnt(courseTotleNum);
            } else {
                List<FtbCultivatePromotionPostNew> promotionList = ftbCultivatePromotionNewMapper.selectAllPromoteList(pomotionId);
                Map<Integer, List<FtbCultivatePromotionPostNew>> stepMap = new HashMap<>();
                if (CollUtil.isNotEmpty(promotionList)) {
                    stepMap = promotionList.stream().collect(Collectors.groupingBy(FtbCultivatePromotionPostNew::getLevel));
                }
                if (CollUtil.isNotEmpty(stepMap)) {
                    Long completeNum = 0L;
                    Long totalNum = 0L;
                    //遍历stepMap
                    for (Map.Entry<Integer, List<FtbCultivatePromotionPostNew>> entry : stepMap.entrySet()) {
                        Set<String> positionSet = new HashSet<>();
                        if (entry.getValue().size() <= 1) {
                            for (FtbCultivatePromotionPostNew promotionPostNew : entry.getValue()) {
                                positionSet.add(promotionPostNew.getPostId());
                            }
                        } else {
                            List<Map<String, Object>> maps = ftbCultivatePromotionNewMapper.queryUserChosesPostsWitId(userId, entry.getKey(), pomotionId);
                            if (CollUtil.isNotEmpty(maps)) {
                                for (Map<String, Object> map : maps) {
                                    positionSet.add(map.get("postId").toString());
                                }
                            }
                        }
                        if (CollUtil.isEmpty(positionSet)) {
                            positionSet.add("-1");
                        }
                        Long courseTotalNum = ftbCultivatePositionStatisticesMapper.courseTotleNum(new ArrayList<>(positionSet));
                        // 已学习课程数
                        List<String> studyCourseList = ftbCultivatePositionStatisticesMapper.queryComplateCourseLists(new ArrayList<>(positionSet), userId);
                        if (CollUtil.isNotEmpty(studyCourseList)) {
                            courseIds.addAll(studyCourseList);
                            completeNum += studyCourseList.size();
                        }

                        totalNum += courseTotalNum;
                        //累计就再这里
                        if (currentLearningStage <= entry.getKey()) {
                            boolean isComplete = false;
                            Integer currLevelCompleteNum = 0;
                            for (FtbCultivatePromotionPostNew promotionPostNew : entry.getValue()) {
                                try {
                                    String s = promotionService.innerCheckStudying(entry.getKey(), userId, promotionPostNew.getPostId(), pomotionId);
                                    if (s == null) {
                                        currLevelCompleteNum++;
                                        if (currLevelCompleteNum >= promotionPostNew.getSelectCourseNumber()) {
                                            isComplete = true;
                                            break;
                                        }
                                    }
                                } catch (Exception e) {
                                    log.error("统计已经学习的课程数，检查是否在学习中userid={},postion={},promotionId={}", userId, promotionPostNew.getPostId(), pomotionId);
                                    isComplete = false;
                                }
                            }
                            if (!isComplete) {
                                break;
                            }
                        }
                    }
                    vo.setCourseCompleteCnt(completeNum);
                    vo.setCourseTotalCnt(totalNum);
                }
            }
        }
        //3、考试
        Long myAllReadOverCnt = ftbCultivateExamUserMapper.queryAllMyReadOver(userId);
        Long myPassReadOverCnt = ftbCultivateExamUserMapper.queryPassMyReadOver(userId);
        BigDecimal examPassRate = BigDecimal.ZERO;
        if (myAllReadOverCnt > 0) {
            examPassRate = new BigDecimal(myPassReadOverCnt).divide(new BigDecimal(myAllReadOverCnt), 4, RoundingMode.HALF_UP);
        }
        vo.setExamPassRate(UserApiV2Util.dealWithRate(examPassRate, ""));
        //4、鉴定
        //查询一下已经完成的鉴定
        LambdaQueryWrapper<CultivateIdentifyApply> identifyLambdaQueryWrapper = Wrappers.lambdaQuery();
        identifyLambdaQueryWrapper.eq(CultivateIdentifyApply::getIdentifyUserId, userId);
        identifyLambdaQueryWrapper.isNotNull(CultivateIdentifyApply::getTableId);
        identifyLambdaQueryWrapper.eq(CultivateIdentifyApply::getDeleteMark, 0);
        identifyLambdaQueryWrapper.eq(CultivateIdentifyApply::getIsVisible, 0);
        identifyLambdaQueryWrapper.eq(CultivateIdentifyApply::getStatus, 1);
        Long completeIdentifyNum = identifyApplyMapper.selectCount(identifyLambdaQueryWrapper);
        vo.setIdentificationPassCnt(completeIdentifyNum);

        Long waitAndOverIdentifyNum = 0L;
        List<String> btnList = userApiV2Util.queryUserBtnPermissionList(userPrimaryBoundOne);
        if (btnList.contains(IDENTITY_CODE)) {
            //根据权限查询待我鉴定和待我鉴定过期的 + completeIdentifyNum
            LambdaQueryWrapper<CultivateIdentifyApply> identifyWrapper = Wrappers.lambdaQuery();
            identifyWrapper.isNotNull(CultivateIdentifyApply::getTableId);
            identifyWrapper.eq(CultivateIdentifyApply::getDeleteMark, 0);
            identifyWrapper.eq(CultivateIdentifyApply::getIsVisible, 0);
            identifyWrapper.ne(CultivateIdentifyApply::getStatus, 1);
            if (CollUtil.isNotEmpty(powerUserIds)) {
                identifyWrapper.in(CultivateIdentifyApply::getBeIdentifyUserId, powerUserIds);
            }
            waitAndOverIdentifyNum = identifyApplyMapper.selectCount(identifyWrapper);
        }
        vo.setIdentificationTotalCnt(completeIdentifyNum + waitAndOverIdentifyNum);
        return vo;
    }


    private void processPositionCourse() {
        //                if (CollUtil.isNotEmpty(stepMap)) {
//                    Long completeNum = 0L;
//                    Long totalNum = 0L;
//                    for (Map.Entry<Integer, List<FtbCultivatePromotionPostNew>> entry : stepMap.entrySet()) {
//                        Set<String> positionSet = new HashSet<>();
//                        Long level = Long.valueOf(entry.getKey());
//                        if (level.equals(1L)) {
//                            for (FtbCultivatePromotionPostNew promotionPostNew : entry.getValue()) {
//                                positionSet.add(promotionPostNew.getPostId());
//                            }
//                        } else {
//                            List<Map<String, Object>> maps = ftbCultivatePromotionNewMapper.queryUserChosesPostsWitId(userId, entry.getKey(), pomotionId);
//                            if (CollUtil.isNotEmpty(maps)) {
//                                for (Map<String, Object> map : maps) {
//                                    positionSet.add(map.get("postId").toString());
//                                }
//                            }
//                        }
//                        Long courseTotalNum = ftbCultivatePositionStatisticesMapper.courseTotleNum(new ArrayList<>(positionSet));
//                        // 已学习课程数
//                        List<String> studyCourseList = ftbCultivatePositionStatisticesMapper.queryComplateCourseLists(new ArrayList<>(positionSet), userId);
//                        if (CollUtil.isNotEmpty(studyCourseList)) {
//                            courseIds.addAll(studyCourseList);
//                            completeNum += studyCourseList.size();
//                        }
//
//                        totalNum += courseTotalNum;
//                        //累计就再这里
//                        if (level >= currentLearningStage) {
//                            break;
//                        }
//                        if(level.equals(1L)){
//                          List<String> needStudyCourse =  ftbCultivatePositionStatisticesMapper.queryAllNeedStudyCourseForPost(new ArrayList<>(positionSet));
//                          if(CollUtil.isNotEmpty(needStudyCourse)){
//                              boolean result = containsAll(studyCourseList, needStudyCourse); // 返回true
//                              if(!result){
//                                  break;
//                              }
//                          }
//                        }
//                    }
//                    vo.setCourseCompleteCnt(completeNum);
//                    vo.setCourseTotalCnt(totalNum);
//                }
    }
}
