package com.dayou.service.impl;

import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dayou.bo.SimpleParentModel;
import com.dayou.dto.MajorStatisticalSelectDTO;
import com.dayou.dto.SimplePostModel;
import com.dayou.entity.Post;
import com.dayou.entity.User;
import com.dayou.mapper.DepartmentMapper;
import com.dayou.mapper.MajorStatisticalStatementMapper;
import com.dayou.mapper.PostMapper;
import com.dayou.mapper.UserPostMapper;
import com.dayou.service.IUserService;
import com.dayou.service.IMajorStatisticalStatementService;
import com.dayou.utils.LoginContext;
import com.dayou.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;

@Service
public class MajorStatisticalStatementServiceImpl implements IMajorStatisticalStatementService {

    @Autowired
    private IUserService userService;

    @Autowired
    private DepartmentMapper departmentMapper;

    @Autowired
    private UserPostMapper userPostMapper;

    @Autowired
    private MajorStatisticalStatementMapper majorStatisticalStatementMapper;

    /**
     * 查询大中型台账
     * @param page 分页
     * @param dto 查询条件
     * @return Page<MajorLedgerVO>
     */
    @Override
    public Page<MajorLedgerVO> getMajorLedgerVO(Page page, MajorStatisticalSelectDTO dto) {
        Page<MajorLedgerVO> majorLedgerVOPage = majorStatisticalStatementMapper.getMajorLedgerVO(page, dto);
        majorLedgerVOPage.setRecords(setMembers(majorLedgerVOPage.getRecords()));
        return majorLedgerVOPage;
    }

    /**
     * 导出大中型台账
     * @param dto 查询条件
     * @return List<MajorLedgerVO>
     */
    @Override
    public List<MajorLedgerVO> exportMajorLedgerVO(MajorStatisticalSelectDTO dto) {
        List<MajorLedgerVO> majorLedgerVOList = majorStatisticalStatementMapper.exportMajorLedgerVO(dto);
        majorLedgerVOList = setMembers(majorLedgerVOList);
        return majorLedgerVOList;
    }

    /**
     * 评估部绩效扣分查询
     * @param dto 查询dto
     * @return List<MajorPerformanceDeductionVO>
     */
    @Override
    public List<MajorPerformanceDeductionVO> getMajorPerformanceDeductionVO(MajorStatisticalSelectDTO dto) {
        return majorStatisticalStatementMapper.getMajorPerformanceDeductionVO(dto);
    }

    /**
     * 评估人员绩效扣分查询
     * @param dto 查询dto
     * @return List<MajorPerformanceDeductionVO>
     */
    @Override
    public List<MajorPerformanceDeductionVO> getMajorPerformanceDeductionVOByEvaluator(MajorStatisticalSelectDTO dto) {
        return majorStatisticalStatementMapper.getMajorPerformanceDeductionVOByEvaluator(dto);
    }

    /**
     * 根据部门id获取部门绩效扣分
     * @param dto 查询dto
     * @return List<MajorPerformanceDeductionVO>
     */
    @Override
    public List<MajorPerformanceDeductionVO> getMajorPerformanceDeductionVOByDepId(MajorStatisticalSelectDTO dto) {
        dto.setDepartmentId(departmentMapper.getDepartmentByUserId(LoginContext.getCurrentUserId()));
        return majorStatisticalStatementMapper.getMajorPerformanceDeductionVOByDepId(dto);
    }

    /**
     * 获取每种错误类型的数量
     * @param dto 查询dto
     * @return List<MajorErrorTypeCountVO>
     */
    @Override
    public List<MajorErrorTypeCountVO> getMajorErrorTypeCountVO(MajorStatisticalSelectDTO dto) {
        dto.setUserId(LoginContext.getUserId());
        List<SimplePostModel> post = userPostMapper.getPostList(dto.getUserId());
        // 判断当前用户是否是三审或四审人员
        boolean verifier = post.stream()
                .anyMatch(obj -> "三审人".equals(obj.getName()) || "复审人".equals(obj.getName()));
        // 判断当前用户是否是评估部经理,是则获取评估部id
        Optional<Long> dep = post.stream()
                .filter(obj -> "评估部经理".equals(obj.getName()))
                .map(SimplePostModel::getDepartmentId)
                .findFirst();
        dep.ifPresent(
                dto::setDepartmentId
        );
        // 达成是审核或部门经理任一条件都不是仅查看自己
        boolean self = !verifier && !ObjectUtil.isNotNull(dto.getDepartmentId());
        return majorStatisticalStatementMapper.getMajorErrorTypeCountVO(dto, self, ObjectUtil.isNotNull(dto.getDepartmentId()));
    }

    /**
     * 查询错误类型详情列表
     * @param page 分页
     * @param dto 查询dto
     * @return Page<MajorPerformanceDeductionDetailVO>
     */
    @Override
    public Page<MajorPerformanceDeductionDetailVO> getMajorErrorTypeDetailVO(Page page, MajorStatisticalSelectDTO dto) {
        Page<MajorPerformanceDeductionDetailVO> detailVOPage = majorStatisticalStatementMapper.getMajorErrorTypeDetailVO(page, dto);
        detailVOPage.setRecords(setDetailVOJSONInfo(detailVOPage.getRecords()));
        return detailVOPage;
    }

    /**
     * 导出错误类型详情列表
     * @param dto 查询dto
     * @return List<MajorPerformanceDeductionDetailVO>
     */
    @Override
    public List<MajorPerformanceDeductionDetailVO> exportMajorErrorTypeDetailVO(MajorStatisticalSelectDTO dto) {
        List<MajorPerformanceDeductionDetailVO> detailVOList = majorStatisticalStatementMapper.exportMajorErrorTypeDetailVO(dto);
        detailVOList = setDetailVOJSONInfo(detailVOList);
        return detailVOList;
    }

    /**
     * 查询错误详情列表
     * @param page 分页
     * @param dto 查询dto
     * @return Page<MajorPerformanceDeductionDetailVO>
     */
    @Override
    public Page<MajorPerformanceDeductionDetailVO> getMajorPerformanceDeductionDetailVO(Page page, MajorStatisticalSelectDTO dto) {
        Page<MajorPerformanceDeductionDetailVO> detailVOPage = majorStatisticalStatementMapper.getMajorPerformanceDeductionDetailVO(page, dto);
        detailVOPage.setRecords(setDetailVOJSONInfo(detailVOPage.getRecords()));
        return detailVOPage;
    }

    /**
     * 导出错误详情列表
     * @param dto 查询dto
     * @return List<MajorPerformanceDeductionDetailVO>
     */
    @Override
    public List<MajorPerformanceDeductionDetailVO> exportMajorPerformanceDeductionDetailVO(MajorStatisticalSelectDTO dto) {
        List<MajorPerformanceDeductionDetailVO> detailVOList = majorStatisticalStatementMapper.exportMajorPerformanceDeductionDetailVO(dto);
        detailVOList = setDetailVOJSONInfo(detailVOList);
        return detailVOList;
    }

    /**
     * 评估部效率查询
     * @param dto 查询dto
     * @return List<MajorEvaluateEfficiencyVO>
     */
    @Override
    public List<MajorEvaluateEfficiencyVO> getMajorEvaluateDepEfficiencyVO(MajorStatisticalSelectDTO dto) {
        List<MajorEvaluateEfficiencyVO> efficiencyVOList = majorStatisticalStatementMapper.getMajorEvaluateDepEfficiencyVO(dto);
        // 循环计算每个部门的同比、环比
        for (MajorEvaluateEfficiencyVO efficiencyVO : efficiencyVOList) {

            // 计算当期出单率
            if (efficiencyVO.getCurrentPeriodReportVolume() > 0 && (efficiencyVO.getInformalEvaluateCount() > 0 || efficiencyVO.getUnInformalEvaluateCount() > 0)) { // 当期出报告书大于0
                efficiencyVO.setCurrentPeriodOrderHasReportVolume((efficiencyVO.getCurrentPeriodReportVolume().doubleValue() / (efficiencyVO.getInformalEvaluateCount() + efficiencyVO.getUnInformalEvaluateCount())));
            } else {
                efficiencyVO.setCurrentPeriodOrderHasReportVolume(0.0);
            }
            // 计算同比出单率
            if (efficiencyVO.getYoYReportVolume() > 0 && efficiencyVO.getYoYOrderVolume() > 0) {
                efficiencyVO.setYoYOrderHasReportVolume(NumberUtil.round((efficiencyVO.getCurrentPeriodOrderHasReportVolume() - (efficiencyVO.getYoYReportVolume() / efficiencyVO.getYoYOrderVolume())) / (efficiencyVO.getYoYReportVolume() / efficiencyVO.getYoYOrderVolume()) * 100, 2).doubleValue());
            } else {
                efficiencyVO.setYoYOrderHasReportVolume(NumberUtil.round(efficiencyVO.getCurrentPeriodOrderHasReportVolume() * 100, 2).doubleValue());
            }
            // 计算环比出单率
            if (efficiencyVO.getQoQReportVolume() > 0 && efficiencyVO.getQoQOrderVolume() > 0) {
                efficiencyVO.setQoQOrderHasReportVolume(NumberUtil.round((efficiencyVO.getCurrentPeriodOrderHasReportVolume() - (efficiencyVO.getQoQReportVolume() / efficiencyVO.getQoQOrderVolume())) / (efficiencyVO.getQoQReportVolume() / efficiencyVO.getQoQOrderVolume()) * 100, 2).doubleValue());
            } else {
                efficiencyVO.setQoQOrderHasReportVolume(NumberUtil.round(efficiencyVO.getCurrentPeriodOrderHasReportVolume() * 100, 2).doubleValue());
            }
            efficiencyVO.setCurrentPeriodOrderHasReportVolume(NumberUtil.round(efficiencyVO.getCurrentPeriodOrderHasReportVolume() * 100, 2).doubleValue());

            // 同比计算(同比增长率 = (当期数据 - 去年同期数据) / 去年同期数据 * 100%) (保留两位小数)
            if (efficiencyVO.getYoYOrderVolume() > 0) {
                efficiencyVO.setYoYOrderVolume(NumberUtil.round(((efficiencyVO.getInformalEvaluateCount() + efficiencyVO.getUnInformalEvaluateCount()) - efficiencyVO.getYoYOrderVolume()) / efficiencyVO.getYoYOrderVolume() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setYoYOrderVolume((double) ((efficiencyVO.getInformalEvaluateCount() + efficiencyVO.getUnInformalEvaluateCount()) * 100));
            }
            if (efficiencyVO.getYoYStatementVolume() > 0) {
                efficiencyVO.setYoYStatementVolume(NumberUtil.round((efficiencyVO.getCurrentPeriodStatementVolume() - efficiencyVO.getYoYStatementVolume()) / efficiencyVO.getYoYStatementVolume() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setYoYStatementVolume((double) (efficiencyVO.getCurrentPeriodStatementVolume() * 100));
            }
            if (efficiencyVO.getYoYReportVolume() > 0) {
                efficiencyVO.setYoYReportVolume(NumberUtil.round((efficiencyVO.getCurrentPeriodReportVolume() - efficiencyVO.getYoYReportVolume()) / efficiencyVO.getYoYReportVolume() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setYoYReportVolume((double) (efficiencyVO.getCurrentPeriodReportVolume() * 100));
            }
            if (efficiencyVO.getYoYShouldAmountSum() > 0) {
                efficiencyVO.setYoYShouldAmountSum(NumberUtil.round((efficiencyVO.getCurrentPeriodShouldAmountSum() - efficiencyVO.getYoYShouldAmountSum()) / efficiencyVO.getYoYShouldAmountSum() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setYoYShouldAmountSum(efficiencyVO.getCurrentPeriodShouldAmountSum() * 100);
            }
            if (efficiencyVO.getYoYRealAmountSum() > 0) {
                efficiencyVO.setYoYRealAmountSum(NumberUtil.round((efficiencyVO.getCurrentPeriodRealAmountSum() - efficiencyVO.getYoYRealAmountSum()) / efficiencyVO.getYoYRealAmountSum() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setYoYRealAmountSum(efficiencyVO.getCurrentPeriodRealAmountSum() * 100);
            }

            // 环比计算(环比增长率 = (当期数据 - 前一期数据) / 前一期数据 * 100%) (保留两位小数)
            if (efficiencyVO.getQoQOrderVolume() > 0) {
                efficiencyVO.setQoQOrderVolume(NumberUtil.round(((efficiencyVO.getInformalEvaluateCount() + efficiencyVO.getUnInformalEvaluateCount()) - efficiencyVO.getQoQOrderVolume()) / efficiencyVO.getQoQOrderVolume() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setQoQOrderVolume((double) ((efficiencyVO.getInformalEvaluateCount() + efficiencyVO.getUnInformalEvaluateCount()) * 100));
            }
            if (efficiencyVO.getQoQStatementVolume() > 0) {
                efficiencyVO.setQoQStatementVolume(NumberUtil.round((efficiencyVO.getCurrentPeriodStatementVolume() - efficiencyVO.getQoQStatementVolume()) / efficiencyVO.getQoQStatementVolume() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setQoQStatementVolume((double) (efficiencyVO.getCurrentPeriodStatementVolume() * 100));
            }
            if (efficiencyVO.getQoQReportVolume() > 0) {
                efficiencyVO.setQoQReportVolume(NumberUtil.round((efficiencyVO.getCurrentPeriodReportVolume() - efficiencyVO.getQoQReportVolume()) / efficiencyVO.getQoQReportVolume() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setQoQReportVolume((double) (efficiencyVO.getCurrentPeriodReportVolume() * 100));
            }
            if (efficiencyVO.getQoQShouldAmountSum() > 0) {
                efficiencyVO.setQoQShouldAmountSum(NumberUtil.round((efficiencyVO.getCurrentPeriodShouldAmountSum() - efficiencyVO.getQoQShouldAmountSum()) / efficiencyVO.getQoQShouldAmountSum() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setQoQShouldAmountSum(efficiencyVO.getCurrentPeriodShouldAmountSum() * 100);
            }
            if (efficiencyVO.getQoQRealAmountSum() > 0) {
                efficiencyVO.setQoQRealAmountSum(NumberUtil.round((efficiencyVO.getCurrentPeriodRealAmountSum() - efficiencyVO.getQoQRealAmountSum()) / efficiencyVO.getQoQRealAmountSum() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setQoQRealAmountSum(efficiencyVO.getCurrentPeriodRealAmountSum() * 100);
            }
        }
        return efficiencyVOList;
    }

    /**
     * 评估人员效率查询
     * @param dto 查询dto
     * @return List<MajorEvaluateEfficiencyVO>
     */
    @Override
    public List<MajorEvaluateEfficiencyVO> getMajorEvaluatePerEfficiencyVO(MajorStatisticalSelectDTO dto) {
        List<MajorEvaluateEfficiencyVO> efficiencyVOList = majorStatisticalStatementMapper.getMajorEvaluatePerEfficiencyVO(dto);
        // 循环计算每个部门的同比、环比
        for (MajorEvaluateEfficiencyVO efficiencyVO : efficiencyVOList) {

            // 计算当期出单率
            if (efficiencyVO.getCurrentPeriodReportVolume() > 0 && (efficiencyVO.getInformalEvaluateCount() > 0 || efficiencyVO.getUnInformalEvaluateCount() > 0)) { // 当期出报告书大于0
                efficiencyVO.setCurrentPeriodOrderHasReportVolume((efficiencyVO.getCurrentPeriodReportVolume().doubleValue() / (efficiencyVO.getInformalEvaluateCount() + efficiencyVO.getUnInformalEvaluateCount())));
            } else {
                efficiencyVO.setCurrentPeriodOrderHasReportVolume(0.0);
            }
            // 计算同比出单率
            if (efficiencyVO.getYoYReportVolume() > 0 && efficiencyVO.getYoYOrderVolume() > 0) {
                efficiencyVO.setYoYOrderHasReportVolume(NumberUtil.round((efficiencyVO.getCurrentPeriodOrderHasReportVolume() - (efficiencyVO.getYoYReportVolume() / efficiencyVO.getYoYOrderVolume())) / (efficiencyVO.getYoYReportVolume() / efficiencyVO.getYoYOrderVolume()) * 100, 2).doubleValue());
            } else {
                efficiencyVO.setYoYOrderHasReportVolume(NumberUtil.round(efficiencyVO.getCurrentPeriodOrderHasReportVolume() * 100, 2).doubleValue());
            }
            // 计算环比出单率
            if (efficiencyVO.getQoQReportVolume() > 0 && efficiencyVO.getQoQOrderVolume() > 0) {
                efficiencyVO.setQoQOrderHasReportVolume(NumberUtil.round((efficiencyVO.getCurrentPeriodOrderHasReportVolume() - (efficiencyVO.getQoQReportVolume() / efficiencyVO.getQoQOrderVolume())) / (efficiencyVO.getQoQReportVolume() / efficiencyVO.getQoQOrderVolume()) * 100, 2).doubleValue());
            } else {
                efficiencyVO.setQoQOrderHasReportVolume(NumberUtil.round(efficiencyVO.getCurrentPeriodOrderHasReportVolume() * 100, 2).doubleValue());
            }
            efficiencyVO.setCurrentPeriodOrderHasReportVolume(NumberUtil.round(efficiencyVO.getCurrentPeriodOrderHasReportVolume() * 100, 2).doubleValue());

            // 同比计算(同比增长率 = (当期数据 - 去年同期数据) / 去年同期数据 * 100%) (保留两位小数)
            if (efficiencyVO.getYoYOrderVolume() > 0) {
                efficiencyVO.setYoYOrderVolume(NumberUtil.round(((efficiencyVO.getInformalEvaluateCount() + efficiencyVO.getUnInformalEvaluateCount()) - efficiencyVO.getYoYOrderVolume()) / efficiencyVO.getYoYOrderVolume() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setYoYOrderVolume((double) ((efficiencyVO.getInformalEvaluateCount() + efficiencyVO.getUnInformalEvaluateCount()) * 100));
            }
            if (efficiencyVO.getYoYStatementVolume() > 0) {
                efficiencyVO.setYoYStatementVolume(NumberUtil.round((efficiencyVO.getCurrentPeriodStatementVolume() - efficiencyVO.getYoYStatementVolume()) / efficiencyVO.getYoYStatementVolume() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setYoYStatementVolume((double) (efficiencyVO.getCurrentPeriodStatementVolume() * 100));
            }
            if (efficiencyVO.getYoYReportVolume() > 0) {
                efficiencyVO.setYoYReportVolume(NumberUtil.round((efficiencyVO.getCurrentPeriodReportVolume() - efficiencyVO.getYoYReportVolume()) / efficiencyVO.getYoYReportVolume() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setYoYReportVolume((double) (efficiencyVO.getCurrentPeriodReportVolume() * 100));
            }
            if (efficiencyVO.getYoYShouldAmountSum() > 0) {
                efficiencyVO.setYoYShouldAmountSum(NumberUtil.round((efficiencyVO.getCurrentPeriodShouldAmountSum() - efficiencyVO.getYoYShouldAmountSum()) / efficiencyVO.getYoYShouldAmountSum() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setYoYShouldAmountSum(efficiencyVO.getCurrentPeriodShouldAmountSum() * 100);
            }
            if (efficiencyVO.getYoYRealAmountSum() > 0) {
                efficiencyVO.setYoYRealAmountSum(NumberUtil.round((efficiencyVO.getCurrentPeriodRealAmountSum() - efficiencyVO.getYoYRealAmountSum()) / efficiencyVO.getYoYRealAmountSum() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setYoYRealAmountSum(efficiencyVO.getCurrentPeriodRealAmountSum() * 100);
            }

            // 环比计算(环比增长率 = (当期数据 - 前一期数据) / 前一期数据 * 100%) (保留两位小数)
            if (efficiencyVO.getQoQOrderVolume() > 0) {
                efficiencyVO.setQoQOrderVolume(NumberUtil.round(((efficiencyVO.getInformalEvaluateCount() + efficiencyVO.getUnInformalEvaluateCount()) - efficiencyVO.getQoQOrderVolume()) / efficiencyVO.getQoQOrderVolume() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setQoQOrderVolume((double) ((efficiencyVO.getInformalEvaluateCount() + efficiencyVO.getUnInformalEvaluateCount()) * 100));
            }
            if (efficiencyVO.getQoQStatementVolume() > 0) {
                efficiencyVO.setQoQStatementVolume(NumberUtil.round((efficiencyVO.getCurrentPeriodStatementVolume() - efficiencyVO.getQoQStatementVolume()) / efficiencyVO.getQoQStatementVolume() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setQoQStatementVolume((double) (efficiencyVO.getCurrentPeriodStatementVolume() * 100));
            }
            if (efficiencyVO.getQoQReportVolume() > 0) {
                efficiencyVO.setQoQReportVolume(NumberUtil.round((efficiencyVO.getCurrentPeriodReportVolume() - efficiencyVO.getQoQReportVolume()) / efficiencyVO.getQoQReportVolume() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setQoQReportVolume((double) (efficiencyVO.getCurrentPeriodReportVolume() * 100));
            }
            if (efficiencyVO.getQoQShouldAmountSum() > 0) {
                efficiencyVO.setQoQShouldAmountSum(NumberUtil.round((efficiencyVO.getCurrentPeriodShouldAmountSum() - efficiencyVO.getQoQShouldAmountSum()) / efficiencyVO.getQoQShouldAmountSum() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setQoQShouldAmountSum(efficiencyVO.getCurrentPeriodShouldAmountSum() * 100);
            }
            if (efficiencyVO.getQoQRealAmountSum() > 0) {
                efficiencyVO.setQoQRealAmountSum(NumberUtil.round((efficiencyVO.getCurrentPeriodRealAmountSum() - efficiencyVO.getQoQRealAmountSum()) / efficiencyVO.getQoQRealAmountSum() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setQoQRealAmountSum(efficiencyVO.getCurrentPeriodRealAmountSum() * 100);
            }
        }
        return efficiencyVOList;
    }

    /**
     * 效率详情列表查询
     * @param page 分页
     * @param dto 查询dto
     * @return Page<MajorEfficiencyDetailVO>
     */
    @Override
    public Page<MajorEfficiencyDetailVO> getMajorEfficiencyDetailVO(Page page, MajorStatisticalSelectDTO dto) {
        Page<MajorEfficiencyDetailVO> detailVOPage = majorStatisticalStatementMapper.getMajorEfficiencyDetailVO(page, dto);
        for (MajorEfficiencyDetailVO detailVO : detailVOPage.getRecords()){
            if (ObjectUtil.isNotNull(detailVO.getMembers())){
                JSONArray jsonArray = JSONArray.parseArray(detailVO.getMembers());
                List<Long> membersId = jsonArray.toJavaList(Long.class);
                String names = null;
                for (Long id : membersId) {
                    if (ObjectUtil.isNull(names)) {
                        names = userService.getById(id).getName() + '；';
                    } else {
                        names += userService.getById(id).getName() + '；';
                    }
                }
                detailVO.setMembers(names);
            }
        }
        return detailVOPage;
    }

    /**
     * 效率详情列表导出
     * @param dto 查询dto
     * @return List<MajorEfficiencyDetailVO>
     */
    @Override
    public List<MajorEfficiencyDetailVO> exportMajorEfficiencyDetailVO(MajorStatisticalSelectDTO dto) {
        return majorStatisticalStatementMapper.exportMajorEfficiencyDetailVO(dto);
    }

    /**
     * 项目部绩效查询
     * @param dto 查询dto
     * @return List<MajorEvaluateEfficiencyVO>
     */
    @Override
    public List<MajorDepPerformanceOverviewVO> getMajorDepPerformanceOverviewVO(MajorStatisticalSelectDTO dto) {
        List<MajorDepPerformanceOverviewVO> overviewVOList = majorStatisticalStatementMapper.getMajorDepPerformanceOverviewVO(dto);

        // 根据产值进行降序排序
        overviewVOList.sort(Comparator.comparing(MajorDepPerformanceOverviewVO::getOutputValue, Comparator.nullsLast(Comparator.reverseOrder())));
        // 排名赋分(第一名：10、第二名：8、第三名：7)
        for (int i = 0; i < overviewVOList.size(); i++){
            // 判断产值是否小于等于0
            if (overviewVOList.get(i).getOutputValue() < 1){ // 将产值计分设为0
                overviewVOList.get(i).setOutputValueScore(0);
            }else {
                switch (i) { // 按产值排名设定分数
                    case 0:
                        overviewVOList.get(i).setOutputValueScore(10);
                        break;
                    case 1:
                        overviewVOList.get(i).setOutputValueScore(8);
                        break;
                    case 2:
                        overviewVOList.get(i).setOutputValueScore(7);
                        break;
                }
            }
        }

        // 接单量进行降序排序
        overviewVOList.sort(Comparator.comparing(MajorDepPerformanceOverviewVO::getOrderVolume, Comparator.nullsLast(Comparator.reverseOrder())));
        // 排名赋分(第一名：10、第二名：8、第三名：7)
        for (int i = 0; i < overviewVOList.size(); i++){
            // 判断接单数是否小于等于0
            if (overviewVOList.get(i).getOrderVolume() < 1){ // 将接件计分设为0
                overviewVOList.get(i).setOrderVolumeScore(0);
            }else { // 按接件数排名设定份数
                switch (i) {
                    case 0:
                        overviewVOList.get(i).setOrderVolumeScore(10);
                        break;
                    case 1:
                        overviewVOList.get(i).setOrderVolumeScore(8);
                        break;
                    case 2:
                        overviewVOList.get(i).setOrderVolumeScore(7);
                        break;
                }
            }
        }

        // 报价效率进行降序排序
        overviewVOList.sort(Comparator.comparing(MajorDepPerformanceOverviewVO::getQuoteProcessingTime, Comparator.nullsLast(Comparator.reverseOrder())));
        // 排名赋分(第一名：10、第二名：8、第三名：7)时效值越小,得分越高
        for (int i = 0; i < overviewVOList.size(); i++){
            // 判断非金融报价是否不为null
            if (ObjectUtil.isNull(overviewVOList.get(i).getQuoteProcessingTime())){ // 将非金融报价效率计分设为0
                overviewVOList.get(i).setQuoteProcessingTimeScore(0);
            }else {
                switch (i) { // 按非金融报价效率排名设定份数
                    case 0:
                        overviewVOList.get(i).setQuoteProcessingTimeScore(7);
                        break;
                    case 1:
                        overviewVOList.get(i).setQuoteProcessingTimeScore(8);
                        break;
                    case 2:
                        overviewVOList.get(i).setQuoteProcessingTimeScore(10);
                        break;
                }
            }
        }

        // 报价准确度进行降序排序
        overviewVOList.sort(Comparator.comparing(MajorDepPerformanceOverviewVO::getQuotationAccuracy, Comparator.nullsLast(Comparator.reverseOrder())));
        // 排名赋分(第一名：10、第二名：8、第三名：7)报价准确度越接近1,得分越高
        for (int i = 0; i < overviewVOList.size(); i++){
            // 判断非金融报价是否不为null
            if (ObjectUtil.isNull(overviewVOList.get(i).getQuotationAccuracy())){ // 将非金融报价效率计分设为0
                overviewVOList.get(i).setQuotationAccuracyScore(0);
            }else {
                switch (i) { // 按非金融报价效率排名设定份数
                    case 0:
                        overviewVOList.get(i).setQuotationAccuracyScore(7);
                        break;
                    case 1:
                        overviewVOList.get(i).setQuotationAccuracyScore(8);
                        break;
                    case 2:
                        overviewVOList.get(i).setQuotationAccuracyScore(10);
                        break;
                }
            }
        }

        // 计算复审扣分与最后的时间累计分值
        for (MajorDepPerformanceOverviewVO overviewVO : overviewVOList){
            overviewVO.setReCheckTotalScore(overviewVO.getReCheckNormalMistakeCount() * 3 + overviewVO.getReCheckHardMistakeCount() * 8 + overviewVO.getReCheckFatalMistakeCount() * 41);
            overviewVO.setTimePointTotalScore(overviewVO.getOutputValueScore() + overviewVO.getOrderVolumeScore() + overviewVO.getQuoteProcessingTimeScore() - overviewVO.getReCheckTotalScore() + overviewVO.getQuotationAccuracyScore());
        }

        // 重新排序部门顺序
        overviewVOList.sort(Comparator.comparing(MajorDepPerformanceOverviewVO::getDepartmentId, Comparator.nullsLast(Comparator.naturalOrder())));
        return overviewVOList;
    }

    /**
     * 市场部效率查询
     * @param dto 查询dto
     * @return List<MajorMarketEfficiencyVO>
     */
    @Override
    public List<MajorMarketEfficiencyVO> getMajorsMarketDepEfficiencyVO(MajorStatisticalSelectDTO dto) {
        List<MajorMarketEfficiencyVO> efficiencyVOList = majorStatisticalStatementMapper.getMajorsMarketDepEfficiencyVO(dto);

        // 循环计算每个部门的同比、环比
        for (MajorMarketEfficiencyVO efficiencyVO : efficiencyVOList) {

            // 计算当期出单率
            if (efficiencyVO.getCurrentPeriodReportVolume() > 0 && efficiencyVO.getCurrentPeriodOrderVolume() > 0) { // 当期出报告书大于0
                efficiencyVO.setCurrentPeriodOrderHasReportVolume((efficiencyVO.getCurrentPeriodReportVolume().doubleValue() / efficiencyVO.getCurrentPeriodOrderVolume().doubleValue()));
            } else {
                efficiencyVO.setCurrentPeriodOrderHasReportVolume(0.0);
            }
            // 计算同比出单率
            if (efficiencyVO.getYoYReportVolume() > 0 && efficiencyVO.getYoYOrderVolume() > 0) {
                efficiencyVO.setYoYOrderHasReportVolume(NumberUtil.round((efficiencyVO.getCurrentPeriodOrderHasReportVolume() - (efficiencyVO.getYoYReportVolume() / efficiencyVO.getYoYOrderVolume())) / (efficiencyVO.getYoYReportVolume() / efficiencyVO.getYoYOrderVolume()) * 100, 2).doubleValue());
            } else {
                efficiencyVO.setYoYOrderHasReportVolume(NumberUtil.round(efficiencyVO.getCurrentPeriodOrderHasReportVolume() * 100, 2).doubleValue());
            }
            // 计算环比出单率
            if (efficiencyVO.getQoQReportVolume() > 0 && efficiencyVO.getQoQOrderVolume() > 0) {
                efficiencyVO.setQoQOrderHasReportVolume(NumberUtil.round((efficiencyVO.getCurrentPeriodOrderHasReportVolume() - (efficiencyVO.getQoQReportVolume() / efficiencyVO.getQoQOrderVolume())) / (efficiencyVO.getQoQReportVolume() / efficiencyVO.getQoQOrderVolume()) * 100, 2).doubleValue());
            } else {
                efficiencyVO.setQoQOrderHasReportVolume(NumberUtil.round(efficiencyVO.getCurrentPeriodOrderHasReportVolume() * 100, 2).doubleValue());
            }
            efficiencyVO.setCurrentPeriodOrderHasReportVolume(NumberUtil.round(efficiencyVO.getCurrentPeriodOrderHasReportVolume() * 100, 2).doubleValue());

            // 同比计算(同比增长率 = (当期数据 - 去年同期数据) / 去年同期数据 * 100%) (保留两位小数)
            if (efficiencyVO.getYoYOrderVolume() > 0) {
                efficiencyVO.setYoYOrderVolume(NumberUtil.round((efficiencyVO.getCurrentPeriodOrderVolume() - efficiencyVO.getYoYOrderVolume()) / efficiencyVO.getYoYOrderVolume() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setYoYOrderVolume((double) (efficiencyVO.getCurrentPeriodOrderVolume() * 100));
            }
            if (efficiencyVO.getYoYStatementVolume() > 0) {
                efficiencyVO.setYoYStatementVolume(NumberUtil.round((efficiencyVO.getCurrentPeriodStatementVolume() - efficiencyVO.getYoYStatementVolume()) / efficiencyVO.getYoYStatementVolume() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setYoYStatementVolume((double) (efficiencyVO.getCurrentPeriodStatementVolume() * 100));
            }
            if (efficiencyVO.getYoYReportVolume() > 0) {
                efficiencyVO.setYoYReportVolume(NumberUtil.round((efficiencyVO.getCurrentPeriodReportVolume() - efficiencyVO.getYoYReportVolume()) / efficiencyVO.getYoYReportVolume() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setYoYReportVolume((double) (efficiencyVO.getCurrentPeriodReportVolume() * 100));
            }
            if (efficiencyVO.getYoYShouldAmountSum() > 0) {
                efficiencyVO.setYoYShouldAmountSum(NumberUtil.round((efficiencyVO.getCurrentPeriodShouldAmountSum() - efficiencyVO.getYoYShouldAmountSum()) / efficiencyVO.getYoYShouldAmountSum() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setYoYShouldAmountSum(efficiencyVO.getCurrentPeriodShouldAmountSum() * 100);
            }
            if (efficiencyVO.getYoYRealAmountSum() > 0) {
                efficiencyVO.setYoYRealAmountSum(NumberUtil.round((efficiencyVO.getCurrentPeriodRealAmountSum() - efficiencyVO.getYoYRealAmountSum()) / efficiencyVO.getYoYRealAmountSum() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setYoYRealAmountSum(efficiencyVO.getCurrentPeriodRealAmountSum() * 100);
            }

            // 环比计算(环比增长率 = (当期数据 - 前一期数据) / 前一期数据 * 100%) (保留两位小数)
            if (efficiencyVO.getQoQOrderVolume() > 0) {
                efficiencyVO.setQoQOrderVolume(NumberUtil.round((efficiencyVO.getCurrentPeriodOrderVolume() - efficiencyVO.getQoQOrderVolume()) / efficiencyVO.getQoQOrderVolume() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setQoQOrderVolume((double) (efficiencyVO.getCurrentPeriodOrderVolume() * 100));
            }
            if (efficiencyVO.getQoQStatementVolume() > 0) {
                efficiencyVO.setQoQStatementVolume(NumberUtil.round((efficiencyVO.getCurrentPeriodStatementVolume() - efficiencyVO.getQoQStatementVolume()) / efficiencyVO.getQoQStatementVolume() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setQoQStatementVolume((double) (efficiencyVO.getCurrentPeriodStatementVolume() * 100));
            }
            if (efficiencyVO.getQoQReportVolume() > 0) {
                efficiencyVO.setQoQReportVolume(NumberUtil.round((efficiencyVO.getCurrentPeriodReportVolume() - efficiencyVO.getQoQReportVolume()) / efficiencyVO.getQoQReportVolume() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setQoQReportVolume((double) (efficiencyVO.getCurrentPeriodReportVolume() * 100));
            }
            if (efficiencyVO.getQoQShouldAmountSum() > 0) {
                efficiencyVO.setQoQShouldAmountSum(NumberUtil.round((efficiencyVO.getCurrentPeriodShouldAmountSum() - efficiencyVO.getQoQShouldAmountSum()) / efficiencyVO.getQoQShouldAmountSum() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setQoQShouldAmountSum(efficiencyVO.getCurrentPeriodShouldAmountSum() * 100);
            }
            if (efficiencyVO.getQoQRealAmountSum() > 0) {
                efficiencyVO.setQoQRealAmountSum(NumberUtil.round((efficiencyVO.getCurrentPeriodRealAmountSum() - efficiencyVO.getQoQRealAmountSum()) / efficiencyVO.getQoQRealAmountSum() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setQoQRealAmountSum(efficiencyVO.getCurrentPeriodRealAmountSum() * 100);
            }

            /*
             * 计算死单率
             * 死单率A = (下单数-出报告数) / (下单数)
             * 死单率B = (下单数-出预评数) / (下单数)
             * 死单率C = (下单数-收费项目数) / 下单数
             */
            if (efficiencyVO.getCurrentPeriodOrderVolume() > 0) {
                efficiencyVO.setDeadOrderVolumeA(NumberUtil.round((double) (efficiencyVO.getCurrentPeriodOrderVolume() - efficiencyVO.getCurrentPeriodReportVolume()) / efficiencyVO.getCurrentPeriodOrderVolume() * 100, 2).doubleValue());
                efficiencyVO.setDeadOrderVolumeB(NumberUtil.round((double) (efficiencyVO.getCurrentPeriodOrderVolume() - efficiencyVO.getCurrentPeriodStatementVolume()) / efficiencyVO.getCurrentPeriodOrderVolume() * 100, 2).doubleValue());
                efficiencyVO.setDeadOrderVolumeC(NumberUtil.round((double) (efficiencyVO.getCurrentPeriodOrderVolume() - efficiencyVO.getCurrentPeriodRealAmountOrderCount()) / efficiencyVO.getCurrentPeriodOrderVolume() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setDeadOrderVolumeA(0.0);
                efficiencyVO.setDeadOrderVolumeB(0.0);
                efficiencyVO.setDeadOrderVolumeC(0.0);
            }
        }
        return efficiencyVOList;
    }

    /**
     * 客户经理效率查询
     * @param dto 查询dto
     * @return List<MajorMarketEfficiencyVO>
     */
    @Override
    public List<MajorMarketEfficiencyVO> getMajorMarketPerEfficiencyVO(MajorStatisticalSelectDTO dto) {
        List<MajorMarketEfficiencyVO> efficiencyVOList = majorStatisticalStatementMapper.getMajorMarketPerEfficiencyVO(dto);

        // 循环计算每个部门的同比、环比
        for (MajorMarketEfficiencyVO efficiencyVO : efficiencyVOList) {

            // 计算当期出单率
            if (efficiencyVO.getCurrentPeriodReportVolume() > 0 && efficiencyVO.getCurrentPeriodOrderVolume() > 0) { // 当期出报告书大于0
                efficiencyVO.setCurrentPeriodOrderHasReportVolume((efficiencyVO.getCurrentPeriodReportVolume().doubleValue() / efficiencyVO.getCurrentPeriodOrderVolume().doubleValue()));
            } else {
                efficiencyVO.setCurrentPeriodOrderHasReportVolume(0.0);
            }
            // 计算同比出单率
            if (efficiencyVO.getYoYReportVolume() > 0 && efficiencyVO.getYoYOrderVolume() > 0) {
                efficiencyVO.setYoYOrderHasReportVolume(NumberUtil.round((efficiencyVO.getCurrentPeriodOrderHasReportVolume() - (efficiencyVO.getYoYReportVolume() / efficiencyVO.getYoYOrderVolume())) / (efficiencyVO.getYoYReportVolume() / efficiencyVO.getYoYOrderVolume()) * 100, 2).doubleValue());
            } else {
                efficiencyVO.setYoYOrderHasReportVolume(NumberUtil.round(efficiencyVO.getCurrentPeriodOrderHasReportVolume() * 100, 2).doubleValue());
            }
            // 计算环比出单率
            if (efficiencyVO.getQoQReportVolume() > 0 && efficiencyVO.getQoQOrderVolume() > 0) {
                efficiencyVO.setQoQOrderHasReportVolume(NumberUtil.round((efficiencyVO.getCurrentPeriodOrderHasReportVolume() - (efficiencyVO.getQoQReportVolume() / efficiencyVO.getQoQOrderVolume())) / (efficiencyVO.getQoQReportVolume() / efficiencyVO.getQoQOrderVolume()) * 100, 2).doubleValue());
            } else {
                efficiencyVO.setQoQOrderHasReportVolume(NumberUtil.round(efficiencyVO.getCurrentPeriodOrderHasReportVolume() * 100, 2).doubleValue());
            }
            efficiencyVO.setCurrentPeriodOrderHasReportVolume(NumberUtil.round(efficiencyVO.getCurrentPeriodOrderHasReportVolume() * 100, 2).doubleValue());

            // 同比计算(同比增长率 = (当期数据 - 去年同期数据) / 去年同期数据 * 100%) (保留两位小数)
            if (efficiencyVO.getYoYOrderVolume() > 0) {
                efficiencyVO.setYoYOrderVolume(NumberUtil.round((efficiencyVO.getCurrentPeriodOrderVolume() - efficiencyVO.getYoYOrderVolume()) / efficiencyVO.getYoYOrderVolume() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setYoYOrderVolume((double) (efficiencyVO.getCurrentPeriodOrderVolume() * 100));
            }
            if (efficiencyVO.getYoYStatementVolume() > 0) {
                efficiencyVO.setYoYStatementVolume(NumberUtil.round((efficiencyVO.getCurrentPeriodStatementVolume() - efficiencyVO.getYoYStatementVolume()) / efficiencyVO.getYoYStatementVolume() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setYoYStatementVolume((double) (efficiencyVO.getCurrentPeriodStatementVolume() * 100));
            }
            if (efficiencyVO.getYoYReportVolume() > 0) {
                efficiencyVO.setYoYReportVolume(NumberUtil.round((efficiencyVO.getCurrentPeriodReportVolume() - efficiencyVO.getYoYReportVolume()) / efficiencyVO.getYoYReportVolume() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setYoYReportVolume((double) (efficiencyVO.getCurrentPeriodReportVolume() * 100));
            }
            if (efficiencyVO.getYoYShouldAmountSum() > 0) {
                efficiencyVO.setYoYShouldAmountSum(NumberUtil.round((efficiencyVO.getCurrentPeriodShouldAmountSum() - efficiencyVO.getYoYShouldAmountSum()) / efficiencyVO.getYoYShouldAmountSum() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setYoYShouldAmountSum(efficiencyVO.getCurrentPeriodShouldAmountSum() * 100);
            }
            if (efficiencyVO.getYoYRealAmountSum() > 0) {
                efficiencyVO.setYoYRealAmountSum(NumberUtil.round((efficiencyVO.getCurrentPeriodRealAmountSum() - efficiencyVO.getYoYRealAmountSum()) / efficiencyVO.getYoYRealAmountSum() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setYoYRealAmountSum(efficiencyVO.getCurrentPeriodRealAmountSum() * 100);
            }

            // 环比计算(环比增长率 = (当期数据 - 前一期数据) / 前一期数据 * 100%) (保留两位小数)
            if (efficiencyVO.getQoQOrderVolume() > 0) {
                efficiencyVO.setQoQOrderVolume(NumberUtil.round((efficiencyVO.getCurrentPeriodOrderVolume() - efficiencyVO.getQoQOrderVolume()) / efficiencyVO.getQoQOrderVolume() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setQoQOrderVolume((double) (efficiencyVO.getCurrentPeriodOrderVolume() * 100));
            }
            if (efficiencyVO.getQoQStatementVolume() > 0) {
                efficiencyVO.setQoQStatementVolume(NumberUtil.round((efficiencyVO.getCurrentPeriodStatementVolume() - efficiencyVO.getQoQStatementVolume()) / efficiencyVO.getQoQStatementVolume() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setQoQStatementVolume((double) (efficiencyVO.getCurrentPeriodStatementVolume() * 100));
            }
            if (efficiencyVO.getQoQReportVolume() > 0) {
                efficiencyVO.setQoQReportVolume(NumberUtil.round((efficiencyVO.getCurrentPeriodReportVolume() - efficiencyVO.getQoQReportVolume()) / efficiencyVO.getQoQReportVolume() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setQoQReportVolume((double) (efficiencyVO.getCurrentPeriodReportVolume() * 100));
            }
            if (efficiencyVO.getQoQShouldAmountSum() > 0) {
                efficiencyVO.setQoQShouldAmountSum(NumberUtil.round((efficiencyVO.getCurrentPeriodShouldAmountSum() - efficiencyVO.getQoQShouldAmountSum()) / efficiencyVO.getQoQShouldAmountSum() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setQoQShouldAmountSum(efficiencyVO.getCurrentPeriodShouldAmountSum() * 100);
            }
            if (efficiencyVO.getQoQRealAmountSum() > 0) {
                efficiencyVO.setQoQRealAmountSum(NumberUtil.round((efficiencyVO.getCurrentPeriodRealAmountSum() - efficiencyVO.getQoQRealAmountSum()) / efficiencyVO.getQoQRealAmountSum() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setQoQRealAmountSum(efficiencyVO.getCurrentPeriodRealAmountSum() * 100);
            }

            /*
             * 计算死单率
             * 死单率A = (下单数-出报告数) / (下单数)
             * 死单率B = (下单数-出预评数) / (下单数)
             * 死单率C = (下单数-收费项目数) / 下单数
             */
            if (efficiencyVO.getCurrentPeriodOrderVolume() > 0) {
                efficiencyVO.setDeadOrderVolumeA(NumberUtil.round((double) (efficiencyVO.getCurrentPeriodOrderVolume() - efficiencyVO.getCurrentPeriodReportVolume()) / efficiencyVO.getCurrentPeriodOrderVolume() * 100, 2).doubleValue());
                efficiencyVO.setDeadOrderVolumeB(NumberUtil.round((double) (efficiencyVO.getCurrentPeriodOrderVolume() - efficiencyVO.getCurrentPeriodStatementVolume()) / efficiencyVO.getCurrentPeriodOrderVolume() * 100, 2).doubleValue());
                efficiencyVO.setDeadOrderVolumeC(NumberUtil.round((double) (efficiencyVO.getCurrentPeriodOrderVolume() - efficiencyVO.getCurrentPeriodRealAmountOrderCount()) / efficiencyVO.getCurrentPeriodOrderVolume() * 100, 2).doubleValue());
            } else {
                efficiencyVO.setDeadOrderVolumeA(0.0);
                efficiencyVO.setDeadOrderVolumeB(0.0);
                efficiencyVO.setDeadOrderVolumeC(0.0);
            }
        }
        return efficiencyVOList;
    }

    /**
     * 设置项目参与人
     * @param majorLedgerVOList 台账集合
     * @return List<MajorLedgerVO>
     */
    public List<MajorLedgerVO> setMembers(List<MajorLedgerVO> majorLedgerVOList){
        // 获取用户信息
        LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<User>()
                .select(User::getId, User::getName)
                .eq(User::getDeleted, false);
        List<User> userList = userService.list(lambdaQueryWrapper);
        for (MajorLedgerVO majorLedgerVO : majorLedgerVOList){
            if (ObjectUtil.isNotNull(majorLedgerVO.getMembers())) {
                JSONArray jsonArray = JSONArray.parseArray(majorLedgerVO.getMembers());
                List<Long> membersId = jsonArray.toJavaList(Long.class);
                String names = null;
                for (User user : userList) {
                    if (membersId.contains(user.getId())) {
                        if (ObjectUtil.isNull(names)) {
                            names = user.getName() + '；';
                        } else {
                            names += user.getName() + '；';
                        }
                    }
                }
                majorLedgerVO.setMembers(names);
            }
        }
        return majorLedgerVOList;
    }

    /**
     * 设置参与人信息
     *
     * @param detailVOList 查询出来的VO信息
     * @return List<AssetsPerformanceDeductionDetailVO>
     */
    public List<MajorPerformanceDeductionDetailVO> setDetailVOJSONInfo(List<MajorPerformanceDeductionDetailVO> detailVOList) {
        LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<User>()
                .select(User::getId, User::getName)
                .eq(User::getDeleted, false);
        List<User> userList = userService.list(lambdaQueryWrapper);
        for (MajorPerformanceDeductionDetailVO detailVO : detailVOList) {
            if (ObjectUtil.isNotNull(detailVO.getMembers())) {
                JSONArray jsonArray = JSONArray.parseArray(detailVO.getMembers());
                List<Long> membersId = jsonArray.toJavaList(Long.class);
                String names = null;
                for (User user : userList) {
                    if (membersId.contains(user.getId())) {
                        if (ObjectUtil.isNull(names)) {
                            names = user.getName() + '；';
                        } else {
                            names += user.getName() + '；';
                        }
                    }
                }
                detailVO.setMembers(names);
            }
        }
        return detailVOList;
    }
}
