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.dto.AssetsStatisticalSelectDTO;
import com.dayou.entity.AssetsEvaluationMethod;
import com.dayou.entity.User;
import com.dayou.mapper.AssetsEvaluationMethodMapper;
import com.dayou.mapper.AssetsStatisticalStatementMapper;
import com.dayou.service.IAssetsStatisticalStatementService;
import com.dayou.service.IUserService;
import com.dayou.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Service
public class AssetsStatisticalStatementServiceImpl implements IAssetsStatisticalStatementService {

    @Autowired
    private AssetsStatisticalStatementMapper assetsStatisticalStatementMapper;

    @Autowired
    private AssetsEvaluationMethodMapper assetsEvaluationMethodMapper;

    @Autowired
    private IUserService userService;

    /**
     * 获取资产台账
     *
     * @param dto 查询dto
     * @return Page<AssetsLedgerVO>
     */
    @Override
    public Page<AssetsLedgerVO> getAssetsLedgerVO(AssetsStatisticalSelectDTO dto, Page page) {
        Page<AssetsLedgerVO> assetsLedgerVOPage = assetsStatisticalStatementMapper.getAssetsLedgerVO(page, dto);
        // 获取评估方法信息
        List<AssetsEvaluationMethod> evaluationMethodList = assetsEvaluationMethodMapper.getAssetsEvaluationMethod();
        // 获取用户信息
        LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<User>()
                .select(User::getId, User::getName)
                .eq(User::getDeleted, false);
        List<User> userList = userService.list(lambdaQueryWrapper);
        // 设置评估方法与签字人等信息
        for (AssetsLedgerVO assetsLedgerVO : assetsLedgerVOPage.getRecords()) {
            assetsLedgerVO = setVOJSONInfo(assetsLedgerVO, evaluationMethodList, userList);
        }
        return assetsLedgerVOPage;
    }

    /**
     * 资产台账导出
     *
     * @param dto 查询dto
     * @return Page<AssetsLedgerVO>
     */
    @Override
    public List<AssetsLedgerVO> assetsLedgerVOExport(AssetsStatisticalSelectDTO dto) {
        List<AssetsLedgerVO> assetsLedgerVOList = assetsStatisticalStatementMapper.assetsLedgerVOExport(dto);
        // 获取评估方法信息
        List<AssetsEvaluationMethod> evaluationMethodList = assetsEvaluationMethodMapper.getAssetsEvaluationMethod();
        // 获取用户信息
        LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<User>()
                .select(User::getId, User::getName)
                .eq(User::getDeleted, false);
        List<User> userList = userService.list(lambdaQueryWrapper);
        // 设置评估方法与签字人等信息
        for (AssetsLedgerVO assetsLedgerVO : assetsLedgerVOList) {
            assetsLedgerVO = setVOJSONInfo(assetsLedgerVO, evaluationMethodList, userList);
        }
        return assetsLedgerVOList;
    }

    /**
     * 评估部绩效扣分查询
     *
     * @param dto 查询dto
     * @return Page<AssetsPerformanceDeductionVO>
     */
    @Override
    public List<AssetsPerformanceDeductionVO> getAssetsPerformanceDeductionVO(AssetsStatisticalSelectDTO dto) {
        return assetsStatisticalStatementMapper.getAssetsPerformanceDeductionVO(dto);
    }

    /**
     * 评估部绩效扣分导出
     *
     * @param dto 查询dto
     * @return Page<AssetsPerformanceDeductionVO>
     */
    @Override
    public List<AssetsPerformanceDeductionVO> assetsPerformanceDeductionVOExport(AssetsStatisticalSelectDTO dto) {
        return assetsStatisticalStatementMapper.assetsPerformanceDeductionVOExport(dto);
    }

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

    /**
     * 错误详情列表导出
     *
     * @param dto 查询dto
     * @return Page<AssetsPerformanceDeductionDetailVO>
     */
    @Override
    public List<AssetsPerformanceDeductionDetailVO> assetsPerformanceDeductionDetailExport(AssetsStatisticalSelectDTO dto) {
        List<AssetsPerformanceDeductionDetailVO> detailVOList = assetsStatisticalStatementMapper.assetsPerformanceDeductionDetailExport(dto);
        detailVOList = setDetailVOJSONInfo(detailVOList);
        return detailVOList;
    }

    /**
     * 评估人员绩效扣分查询
     *
     * @param dto 查询dto
     * @return List<AssetsPerformanceDeductionVO>
     */
    @Override
    public List<AssetsPerformanceDeductionVO> getAssetsPerformanceDeductionVOByEvaluator(AssetsStatisticalSelectDTO dto) {
        return assetsStatisticalStatementMapper.getAssetsPerformanceDeductionVOByEvaluator(dto);
    }

    /**
     * 评估人员绩效扣分导出
     *
     * @param dto 查询dto
     * @return List<AssetsPerformanceDeductionVO>
     */
    @Override
    public List<AssetsPerformanceDeductionVO> assetsPerformanceDeductionVOByEvaluatorExport(AssetsStatisticalSelectDTO dto) {
        return assetsStatisticalStatementMapper.assetsPerformanceDeductionVOByEvaluatorExport(dto);
    }

    /**
     * 评估部效率查询
     *
     * @param dto 查询dto
     * @return List<AssetsEvaluateDepEfficiencyVO>
     */
    @Override
    public List<AssetsEvaluateEfficiencyVO> getAssetsEvaluateDepEfficiencyVO(AssetsStatisticalSelectDTO dto) {
        List<AssetsEvaluateEfficiencyVO> efficiencyVOList = assetsStatisticalStatementMapper.getAssetsEvaluateDepEfficiencyVO(dto);

        // 循环计算每个部门的同比、环比
        for (AssetsEvaluateEfficiencyVO 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.getYoYOrderVolume() > 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);
            }
        }
        return efficiencyVOList;
    }

    /**
     * 评估人员效率查询
     *
     * @param dto 查询dto
     * @return List<AssetsEvaluateDepEfficiencyVO>
     */
    @Override
    public List<AssetsEvaluateEfficiencyVO> getAssetsEvaluatePerEfficiencyVO(AssetsStatisticalSelectDTO dto) {
        List<AssetsEvaluateEfficiencyVO> efficiencyVOList = assetsStatisticalStatementMapper.getAssetsEvaluatePerEfficiencyVO(dto);

        // 循环计算每个部门的同比、环比
        for (AssetsEvaluateEfficiencyVO 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);
            }
        }
        return efficiencyVOList;
    }

    /**
     * 效率详情列表查询
     * @param page 分页
     * @param dto 查询dto
     * @return Page<AssetsEvaluateEfficiencyDetailVO>
     */
    @Override
    public Page<AssetsEfficiencyDetailVO> getAssetsEvaEffDetailVO(Page page, AssetsStatisticalSelectDTO dto) {
        Page<AssetsEfficiencyDetailVO> detailVOPage = assetsStatisticalStatementMapper.getAssetsEvaEffDetailVO(page, dto);
        for (AssetsEfficiencyDetailVO 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 Page<AssetsEvaluateEfficiencyDetailVO>
     */
    @Override
    public List<AssetsEfficiencyDetailVO> assetsEvaEffDetailVOExport(AssetsStatisticalSelectDTO dto) {
        return assetsStatisticalStatementMapper.assetsEvaEffDetailVOExport(dto);
    }

    /**
     * 市场部效率查询
     * @param dto 查询dto
     * @return List<AssetsMarketEfficiencyVO>
     */
    @Override
    public List<AssetsMarketEfficiencyVO> getAssetsMarketDepEfficiencyVO(AssetsStatisticalSelectDTO dto) {
        List<AssetsMarketEfficiencyVO> efficiencyVOList = assetsStatisticalStatementMapper.getAssetsMarketDepEfficiencyVO(dto);

        // 循环计算每个部门的同比、环比
        for (AssetsMarketEfficiencyVO 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<AssetsMarketEfficiencyVO>
     */
    @Override
    public List<AssetsMarketEfficiencyVO> getAssetsMarketPerEfficiencyVO(AssetsStatisticalSelectDTO dto) {
        List<AssetsMarketEfficiencyVO> efficiencyVOList = assetsStatisticalStatementMapper.getAssetsMarketPerEfficiencyVO(dto);

        // 循环计算每个部门的同比、环比
        for (AssetsMarketEfficiencyVO 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<AssetsCustomerEfficiencyVO>
     */
    @Override
    public List<AssetsCustomerEfficiencyVO> getAssetsCustomerTotalEfficiencyVO(AssetsStatisticalSelectDTO dto) {
        List<AssetsCustomerEfficiencyVO> efficiencyVOList = assetsStatisticalStatementMapper.getAssetsCustomerTotalEfficiencyVO(dto);

        // 循环计算每个部门的同比、环比
        for (AssetsCustomerEfficiencyVO 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());

            // 计算当期收费折扣率
            if (efficiencyVO.getCurrentDiscountVolume() > 0) {
                efficiencyVO.setCurrentDiscountVolume(efficiencyVO.getCurrentDiscountVolume() / efficiencyVO.getCurrentPeriodOrderVolume());
            } else {
                efficiencyVO.setCurrentDiscountVolume(0.0);
            }

            // 计算同比收费折扣率
            if (efficiencyVO.getYoYDiscountVolume() > 0) {
                efficiencyVO.setCurrentDiscountVolume(NumberUtil.round( (efficiencyVO.getCurrentDiscountVolume() - (efficiencyVO.getYoYDiscountVolume() / efficiencyVO.getYoYOrderVolume())) /(efficiencyVO.getYoYDiscountVolume() / efficiencyVO.getYoYOrderVolume()) * 100, 2).doubleValue());
            } else {
                efficiencyVO.setCurrentDiscountVolume(0.0);
            }

            // 计算环比收费折扣率
            if (efficiencyVO.getQoQDiscountVolume() > 0) {
                efficiencyVO.setCurrentDiscountVolume(NumberUtil.round((efficiencyVO.getCurrentDiscountVolume() - (efficiencyVO.getQoQDiscountVolume() / efficiencyVO.getQoQOrderVolume())) /(efficiencyVO.getQoQDiscountVolume() / efficiencyVO.getQoQOrderVolume()) * 100, 2).doubleValue());
            } else {
                efficiencyVO.setCurrentDiscountVolume(0.0);
            }
            efficiencyVO.setCurrentDiscountVolume(NumberUtil.round(efficiencyVO.getCurrentDiscountVolume() * 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);
            }
        }
        return efficiencyVOList;
    }

    /**
     * 资产客户效率值(客户经理)查询
     * @param dto 查询dto
     * @return List<AssetsCustomerEfficiencyVO>
     */
    @Override
    public List<AssetsCustomerEfficiencyVO> getAssetsCustomerManagerEfficiencyVO(AssetsStatisticalSelectDTO dto) {
        List<AssetsCustomerEfficiencyVO> efficiencyVOList = assetsStatisticalStatementMapper.getAssetsCustomerManagerEfficiencyVO(dto);

        // 循环计算每个部门的同比、环比
        for (AssetsCustomerEfficiencyVO 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());

            // 计算当期收费折扣率
            if (efficiencyVO.getCurrentDiscountVolume() > 0) {
                efficiencyVO.setCurrentDiscountVolume(efficiencyVO.getCurrentDiscountVolume() / efficiencyVO.getCurrentPeriodOrderVolume());
            } else {
                efficiencyVO.setCurrentDiscountVolume(0.0);
            }

            // 计算同比收费折扣率
            if (efficiencyVO.getYoYDiscountVolume() > 0) {
                efficiencyVO.setCurrentDiscountVolume(NumberUtil.round( (efficiencyVO.getCurrentDiscountVolume() - (efficiencyVO.getYoYDiscountVolume() / efficiencyVO.getYoYOrderVolume())) /(efficiencyVO.getYoYDiscountVolume() / efficiencyVO.getYoYOrderVolume()) * 100, 2).doubleValue());
            } else {
                efficiencyVO.setCurrentDiscountVolume(0.0);
            }

            // 计算环比收费折扣率
            if (efficiencyVO.getQoQDiscountVolume() > 0) {
                efficiencyVO.setCurrentDiscountVolume(NumberUtil.round((efficiencyVO.getCurrentDiscountVolume() - (efficiencyVO.getQoQDiscountVolume() / efficiencyVO.getQoQOrderVolume())) /(efficiencyVO.getQoQDiscountVolume() / efficiencyVO.getQoQOrderVolume()) * 100, 2).doubleValue());
            } else {
                efficiencyVO.setCurrentDiscountVolume(0.0);
            }
            efficiencyVO.setCurrentDiscountVolume(NumberUtil.round(efficiencyVO.getCurrentDiscountVolume() * 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);
            }
        }
        return efficiencyVOList;
    }

    /**
     * 设置评估方法与签字人等信息
     *
     * @param assetsLedgerVO       查询出来的VO信息
     * @param evaluationMethodList 评估方法信息
     * @param userList             用户信息
     * @return AssetsLedgerVO
     */
    public AssetsLedgerVO setVOJSONInfo(AssetsLedgerVO assetsLedgerVO, List<AssetsEvaluationMethod> evaluationMethodList, List<User> userList) {
        // 正则表达式匹配任何在[]内的值
        Pattern pattern = Pattern.compile("\\[(.*?)\\]");

        // 获取评估方法
        if (ObjectUtil.isNotNull(assetsLedgerVO.getEvaluationMethods())) {
            Matcher matcher = pattern.matcher(assetsLedgerVO.getEvaluationMethods());
            List<String> methodIdsList = new ArrayList<>();
            while (matcher.find()) {
                // 将匹配的整个字符串添加到列表中
                methodIdsList.add(matcher.group(0));
            }
            // 新建字符串用来装处理后的方法名
            String evaluationMethodNames = null;
            // 获取方法id
            for (String methodIds : methodIdsList) {
                // 将JSON格式的id数组转成集合
                JSONArray jsonArray = JSONArray.parseArray(methodIds);
                List<Long> idList = jsonArray.toJavaList(Long.class);
                // 通过id进行匹配并返回方法名
                int index = 0;
                for (AssetsEvaluationMethod evaluationMethod : evaluationMethodList) {
                    if (idList.contains(evaluationMethod.getId())) {
                        if (ObjectUtil.isNotNull(evaluationMethodNames)) {
                            evaluationMethodNames += evaluationMethod.getMethodName();
                            index++;
                        } else {
                            evaluationMethodNames = evaluationMethod.getMethodName();
                            index++;
                        }
                        if (index < idList.size()) {
                            evaluationMethodNames += '，';
                        } else {
                            evaluationMethodNames += '；';
                        }
                    }
                }
            }
            assetsLedgerVO.setEvaluationMethods(evaluationMethodNames.toString());
        }

        // 获取最终选择的评估方法
        if (ObjectUtil.isNotNull(assetsLedgerVO.getChoiceEvaluationMethods())) {
            Matcher choiceMatcher = pattern.matcher(assetsLedgerVO.getChoiceEvaluationMethods());
            List<String> choiceMethodIdsList = new ArrayList<>();
            while (choiceMatcher.find()) {
                // 将匹配的整个字符串添加到列表中
                choiceMethodIdsList.add(choiceMatcher.group(0));
            }
            // 新建字符串用来装处理后的方法名
            String choiceEvaluationMethodNames = null;
            // 获取方法id
            for (String methodIds : choiceMethodIdsList) {
                // 将JSON格式的id数组转成集合
                JSONArray jsonArray = JSONArray.parseArray(methodIds);
                List<Long> idList = jsonArray.toJavaList(Long.class);
                // 通过id进行匹配并返回方法名
                int index = 0;
                for (AssetsEvaluationMethod evaluationMethod : evaluationMethodList) {
                    if (idList.contains(evaluationMethod.getId())) {
                        if (ObjectUtil.isNotNull(choiceEvaluationMethodNames)) {
                            choiceEvaluationMethodNames += evaluationMethod.getMethodName();
                            index++;
                        } else {
                            choiceEvaluationMethodNames = evaluationMethod.getMethodName();
                            index++;
                        }
                        if (index < idList.size()) {
                            choiceEvaluationMethodNames += '，';
                        } else {
                            choiceEvaluationMethodNames += '；';
                        }
                    }
                }
            }
            assetsLedgerVO.setChoiceEvaluationMethods(choiceEvaluationMethodNames.toString());
        }

        // 获取签字人
        if (ObjectUtil.isNotNull(assetsLedgerVO.getSignatory())) {
            String signatoryNames = null;
            JSONArray jsonArray = JSONArray.parseArray(assetsLedgerVO.getSignatory());
            List<Long> signatoryIdList = jsonArray.toJavaList(Long.class);
            int index = 0;
            for (User user : userList) {
                if (signatoryIdList.contains(user.getId())) {
                    if (ObjectUtil.isNotNull(signatoryNames)) {
                        signatoryNames += user.getName();
                        index++;
                    } else {
                        signatoryNames = user.getName();
                        index++;
                    }
                    if (index < signatoryIdList.size()) {
                        signatoryNames += '，';
                    } else {
                        signatoryNames += '；';
                    }
                }
            }
            assetsLedgerVO.setSignatory(signatoryNames);
        }

        return assetsLedgerVO;
    }

    /**
     * 设置参与人信息
     *
     * @param detailVOList 查询出来的VO信息
     * @return List<AssetsPerformanceDeductionDetailVO>
     */
    public List<AssetsPerformanceDeductionDetailVO> setDetailVOJSONInfo(List<AssetsPerformanceDeductionDetailVO> detailVOList) {
        LambdaQueryWrapper<User> lambdaQueryWrapper = new LambdaQueryWrapper<User>()
                .select(User::getId, User::getName)
                .eq(User::getDeleted, false);
        List<User> userList = userService.list(lambdaQueryWrapper);
        for (AssetsPerformanceDeductionDetailVO 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;
    }
}
