import { IrsBrokerVoteDto } from '@amc-udk/types' export const VoteUtils = { /** * 根据预评分值计算实际评分值 * @param votes * @param maxPoints */ calculateActualPoints: ( votes: IrsBrokerVoteDto[] | { [key: string]: IrsBrokerVoteDto }, maxPoints: any, ) => { let votesToCal = [] if (Array.isArray(votes)) { votesToCal = votes } else { votesToCal = Object.values(votes) } const preVotePointsTotal = votesToCal.reduce((prev, curr) => { return prev + curr.preVotePoints }, 0) votesToCal.forEach(dto => { if (dto.preVotePoints !== undefined && preVotePointsTotal > 0) { dto.actualPoints = (dto.preVotePoints * maxPoints) / preVotePointsTotal } }) }, }