package com.greenorange.promotion.service.project.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.greenorange.promotion.common.ErrorCode;
import com.greenorange.promotion.common.ResultUtils;
import com.greenorange.promotion.exception.ThrowUtils;
import com.greenorange.promotion.mapper.ProjectCommissionMapper;
import com.greenorange.promotion.mapper.SubUserProjectCommissionMapper;
import com.greenorange.promotion.model.dto.projectCommission.ProjectCommissionUniteUpdateRequest;
import com.greenorange.promotion.model.dto.projectCommission.ProjectCommissionUpdateRequest;
import com.greenorange.promotion.model.dto.subUserProjectCommission.SubUserProjectCommissionUpdateRequest;
import com.greenorange.promotion.model.entity.ProjectCommission;
import com.greenorange.promotion.model.entity.ProjectDetail;
import com.greenorange.promotion.model.entity.SubUserProjectCommission;
import com.greenorange.promotion.model.entity.UserMainInfo;
import com.greenorange.promotion.service.common.CommonService;
import com.greenorange.promotion.service.project.ProjectCommissionService;
import com.greenorange.promotion.service.project.ProjectDetailService;
import com.greenorange.promotion.service.project.SubUserProjectCommissionService;
import com.greenorange.promotion.service.userInfo.UserMainInfoService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

/**
* @author 35880
* @description 针对表【project_commission(项目明细抽佣表)】的数据库操作Service实现
* @createDate 2025-05-09 18:42:17
*/
@Service
public class ProjectCommissionServiceImpl extends ServiceImpl<ProjectCommissionMapper, ProjectCommission>
    implements ProjectCommissionService{

    @Resource
    private SubUserProjectCommissionService subUserProjectCommissionService;

    @Resource
    private ProjectDetailService projectDetailService;

    @Resource
    private CommonService commonService;

    @Resource
    private UserMainInfoService userMainInfoService;

    @Resource
    private SubUserProjectCommissionMapper subUserProjectCommissionMapper;




    /**
     * 修改项目的抽佣比例
     */
    @Override
    @Transactional
    public void updateProjectCommissionRate(ProjectCommissionUpdateRequest projectCommissionUpdateRequest) {
        Long id = projectCommissionUpdateRequest.getId();
        BigDecimal currentCommissionRate = projectCommissionUpdateRequest.getCurrentCommissionRate();
        // 获取当前项目明细抽佣信息
        ProjectCommission projectCommission = this.getById(id);
        ThrowUtils.throwIf(projectCommission == null, ErrorCode.OPERATION_ERROR, "项目明细抽佣信息不存在");
        Long projectDetailId = projectCommission.getProjectDetailId();
        ProjectDetail projectDetail = projectDetailService.getById(projectDetailId);
        BigDecimal maxCommissionRate = projectDetail.getMaxCommissionRate();
        ThrowUtils.throwIf(currentCommissionRate.compareTo(maxCommissionRate) > 0, ErrorCode.OPERATION_ERROR, "当前抽佣比例不能大于最大抽佣比例");
        BigDecimal projectMinSettlementPrice = projectDetail.getProjectMinSettlementPrice();
        // 查询项目明细列表
        List<ProjectCommission> projectCommissionList = commonService.findByFieldEqTargetField(ProjectCommission::getProjectDetailId, projectDetailId, this);
        List<SubUserProjectCommission> subUserProjectCommissions = commonService.convertList(projectCommissionList, SubUserProjectCommission.class);
        for (SubUserProjectCommission subUserProjectCommission : subUserProjectCommissions) {
            subUserProjectCommission.setSubUserId(-1L);
        }
        List<SubUserProjectCommission> subProjectCommissions = commonService.findByFieldEqTargetField(SubUserProjectCommission::getProjectDetailId, projectDetailId, subUserProjectCommissionService);
        subProjectCommissions.addAll(subUserProjectCommissions);
        sortSubProjectCommissions(subProjectCommissions);
        Iterator<SubUserProjectCommission> iterator = subProjectCommissions.iterator();
        Long initSubUserId = projectCommission.getUserId();
        // 1.封装一个Map集合（键：下级用户id，值：当前用户的单价）
        Map<Long, BigDecimal> subUserUnitPriceMap = new HashMap<>();
        while (iterator.hasNext()) {
            SubUserProjectCommission commission = iterator.next();
            if (!Objects.equals(commission.getUserId(), initSubUserId)) {
                if (commission.getSubUserId() != -1L) subUserUnitPriceMap.put(commission.getSubUserId(), calculateFinalPrice(commission.getMyUnitPrice(), commission.getCurrentCommissionRate()).max(projectMinSettlementPrice));
                iterator.remove(); // 使用迭代器的 remove() 方法移除
            } else {
                break;
            }
        }

        // 开始更新集合
        for (SubUserProjectCommission subProjectCommission : subProjectCommissions) {
            Long userId = subProjectCommission.getUserId();
            Long subUserId = subProjectCommission.getSubUserId();
            // 初始化map
            if (userId.equals(initSubUserId)) {
                subProjectCommission.setCurrentCommissionRate(currentCommissionRate);
                if (subUserId != -1L) subUserUnitPriceMap.put(subUserId, calculateFinalPrice(subProjectCommission.getMyUnitPrice(), subProjectCommission.getCurrentCommissionRate()).max(projectMinSettlementPrice));
            } else {
                BigDecimal unitPrice = subUserUnitPriceMap.get(userId);
                subProjectCommission.setMyUnitPrice(unitPrice);
                if (subUserId != -1L) subUserUnitPriceMap.put(subUserId, calculateFinalPrice(unitPrice, subProjectCommission.getCurrentCommissionRate()).max(projectMinSettlementPrice));
            }
        }
        long startTime = System.currentTimeMillis();
        // 更新当前用户的项目明细抽佣表和下级用户项目明细抽佣表
        List<SubUserProjectCommission> subUserProCommissions = subProjectCommissions.stream()
                .filter(subProjectCommission -> subProjectCommission.getSubUserId() != -1L && subProjectCommission.getUserId().equals(initSubUserId)).toList();
        subUserProjectCommissionService.updateBatchById(subUserProCommissions);

        List<SubUserProjectCommission> projectCommissions = subProjectCommissions.stream()
                .filter(subProjectCommission -> subProjectCommission.getSubUserId() == -1L && subProjectCommission.getUserId().equals(initSubUserId)).toList();
        List<ProjectCommission> projectCommissionsList = commonService.convertList(projectCommissions, ProjectCommission.class);
        this.updateBatchById(projectCommissionsList);
        // 获取结束时间戳
        long endTime = System.currentTimeMillis();
        // 计算执行时间
        long executionTime = endTime - startTime;
        System.out.println("程序执行时间: " + executionTime + " 毫秒");


        startTime = System.currentTimeMillis();
        // 更新下级用户项目明细记录
        List<SubUserProjectCommission> subUserProjectCommissionList = subProjectCommissions.stream().filter(subProjectCommission -> subProjectCommission.getSubUserId() != -1L).toList();
//        subUserProjectCommissionService.updateBatchById(subUserProjectCommissionList);
        batchUpdateSubUserMyUnitPrice(subUserProjectCommissionList);

        // 更新用户项目明细抽佣记录
        List<SubUserProjectCommission> restProjectCommissions = subProjectCommissions.stream().filter(subProjectCommission -> subProjectCommission.getSubUserId() == -1L).toList();
        List<ProjectCommission> proCommissions = commonService.convertList(restProjectCommissions, ProjectCommission.class);
//        this.updateBatchById(proCommissions);
        batchUpdateMyUnitPrice(proCommissions);

        // 获取结束时间戳
        endTime = System.currentTimeMillis();
        // 计算执行时间
        executionTime = endTime - startTime;
        System.out.println("程序执行时间: " + executionTime + " 毫秒");
    }





    /**
     * 修改下级用户的项目明细抽佣比例
     */
    @Override
    @Transactional
    public void updateSubUserProjectCommissionRate(SubUserProjectCommissionUpdateRequest subUserProjectCommissionUpdateRequest) {
        Long id = subUserProjectCommissionUpdateRequest.getId();
        BigDecimal currentCommissionRate = subUserProjectCommissionUpdateRequest.getCurrentCommissionRate();
        // 获取当前项目明细信息
        SubUserProjectCommission subUserProjectCommission = subUserProjectCommissionService.getById(id);
        ThrowUtils.throwIf(subUserProjectCommission == null, ErrorCode.OPERATION_ERROR, "下级用户项目明细抽佣信息不存在");
        Long projectDetailId = subUserProjectCommission.getProjectDetailId();
        ProjectDetail projectDetail = projectDetailService.getById(projectDetailId);
        BigDecimal maxCommissionRate = projectDetail.getMaxCommissionRate();
        ThrowUtils.throwIf(currentCommissionRate.compareTo(maxCommissionRate) > 0, ErrorCode.OPERATION_ERROR, "当前抽佣比例不能大于最大抽佣比例");
        BigDecimal projectMinSettlementPrice = projectDetail.getProjectMinSettlementPrice();
        // 查询项目明细列表
        List<ProjectCommission> projectCommissionList = commonService.findByFieldEqTargetField(ProjectCommission::getProjectDetailId, projectDetailId, this);
        List<SubUserProjectCommission> subUserProjectCommissions = commonService.convertList(projectCommissionList, SubUserProjectCommission.class);
        for (SubUserProjectCommission subProjectCommission : subUserProjectCommissions) {
            subProjectCommission.setSubUserId(-1L);
        }
        List<SubUserProjectCommission> subProjectCommissions = commonService.findByFieldEqTargetField(SubUserProjectCommission::getProjectDetailId, projectDetailId, subUserProjectCommissionService);
        subProjectCommissions.addAll(subUserProjectCommissions);
        sortSubProjectCommissions(subProjectCommissions);
        Iterator<SubUserProjectCommission> iterator = subProjectCommissions.iterator();
        Long initSubUserId = subUserProjectCommission.getUserId();
        // 1.封装一个Map集合（键：下级用户id，值：当前用户的单价）
        Map<Long, BigDecimal> subUserUnitPriceMap = new HashMap<>();
        while (iterator.hasNext()) {
            SubUserProjectCommission commission = iterator.next();
            if (!Objects.equals(commission.getUserId(), initSubUserId)) {
                if (commission.getSubUserId() != -1L) subUserUnitPriceMap.put(commission.getSubUserId(), calculateFinalPrice(commission.getMyUnitPrice(), commission.getCurrentCommissionRate()).max(projectMinSettlementPrice));
                iterator.remove(); // 使用迭代器的 remove() 方法移除
            } else {
                break;
            }
        }

        // 开始更新集合
        for (SubUserProjectCommission subProjectCommission : subProjectCommissions) {
            Long userId = subProjectCommission.getUserId();
            Long subUserId = subProjectCommission.getSubUserId();
            // 初始化map
            if (userId.equals(initSubUserId)) {
                // 仅设置单条抽佣比例
                if (subProjectCommission.getId().equals(id)) subProjectCommission.setCurrentCommissionRate(currentCommissionRate);
                if (subUserId != -1L) subUserUnitPriceMap.put(subUserId, calculateFinalPrice(subProjectCommission.getMyUnitPrice(), subProjectCommission.getCurrentCommissionRate()).max(projectMinSettlementPrice));
            } else {
                BigDecimal unitPrice = subUserUnitPriceMap.get(userId);
                subProjectCommission.setMyUnitPrice(unitPrice);
                if (subUserId != -1L) subUserUnitPriceMap.put(subUserId, calculateFinalPrice(unitPrice, subProjectCommission.getCurrentCommissionRate()).max(projectMinSettlementPrice));
            }
        }

        long startTime = System.currentTimeMillis();
        // 更新当前用户的下级用户项目明细抽佣表
        List<SubUserProjectCommission> subUserProCommissions = subProjectCommissions.stream()
                .filter(subProjectCommission -> subProjectCommission.getSubUserId() != -1L && subProjectCommission.getUserId().equals(initSubUserId)).toList();
        subUserProjectCommissionService.updateBatchById(subUserProCommissions);

        // 获取结束时间戳
        long endTime = System.currentTimeMillis();
        // 计算执行时间
        long executionTime = endTime - startTime;
        System.out.println("程序执行时间: " + executionTime + " 毫秒");

        startTime = System.currentTimeMillis();
        // 更新下级用户项目明细记录
        List<SubUserProjectCommission> subUserProjectCommissionList = subProjectCommissions.stream().filter(subProjectCommission -> subProjectCommission.getSubUserId() != -1L).toList();
//        subUserProjectCommissionService.updateBatchById(subUserProjectCommissionList);
        batchUpdateSubUserMyUnitPrice(subUserProjectCommissionList);

        // 更新用户项目明细抽佣记录
        List<SubUserProjectCommission> projectCommissions = subProjectCommissions.stream().filter(subProjectCommission -> subProjectCommission.getSubUserId() == -1L).toList();
        List<ProjectCommission> proCommissions = commonService.convertList(projectCommissions, ProjectCommission.class);
//        this.updateBatchById(proCommissions);
        batchUpdateMyUnitPrice(proCommissions);

        endTime = System.currentTimeMillis();
        // 计算执行时间
        executionTime = endTime - startTime;
        System.out.println("程序执行时间: " + executionTime + " 毫秒");
    }



    /**
     * 小程序用户一键设置项目的的抽佣比例
     */
    @Override
    @Transactional
    public void uniteProjectCommissionRate(ProjectCommissionUniteUpdateRequest projectCommissionUniteUpdateRequest, HttpServletRequest request) {
        long startTime = System.currentTimeMillis();

        Long userId = (Long) request.getAttribute("userId");
        BigDecimal uniteCommissionRate = projectCommissionUniteUpdateRequest.getUniteCommissionRate();
        ThrowUtils.throwIf(uniteCommissionRate.compareTo(BigDecimal.valueOf(10)) > 0, ErrorCode.OPERATION_ERROR, "抽佣比例不能大于10%");

        // 修改项目的统一抽佣比例
        LambdaUpdateWrapper<UserMainInfo> userMainInfoLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        userMainInfoLambdaUpdateWrapper.eq(UserMainInfo::getUserId, userId).set(UserMainInfo::getUniteRate, uniteCommissionRate);
        userMainInfoService.update(userMainInfoLambdaUpdateWrapper);

        LambdaQueryWrapper<ProjectCommission> projectCommissionLambdaQueryWrapper = new LambdaQueryWrapper<>();
        projectCommissionLambdaQueryWrapper.eq(ProjectCommission::getUserId, userId);
        List<ProjectCommission> projectCommissionList = this.list(projectCommissionLambdaQueryWrapper);

        List<ProjectDetail> projectDetailList = commonService.findByFieldInTargetField(projectCommissionList, projectDetailService, ProjectCommission::getProjectDetailId, ProjectDetail::getId);
        // 封装map集合（键：项目明细id, 值：项目明细最大抽佣比例）
        Map<Long, BigDecimal> map = new HashMap<>();
        Map<Long, BigDecimal> minPriceMap = new HashMap<>();
        for (ProjectDetail projectDetail : projectDetailList) {
            map.put(projectDetail.getId(), projectDetail.getMaxCommissionRate());
            minPriceMap.put(projectDetail.getId(), projectDetail.getProjectMinSettlementPrice());
        }
        for (ProjectCommission projectCommission : projectCommissionList) {
            Long projectDetailId = projectCommission.getProjectDetailId();
            BigDecimal maxCommissionRate = map.get(projectDetailId);
            BigDecimal setCommissionRate = uniteCommissionRate.compareTo(maxCommissionRate) > 0 ? maxCommissionRate : uniteCommissionRate;
            projectCommission.setCurrentCommissionRate(setCommissionRate);
        }
        this.updateBatchById(projectCommissionList);

        // 获取结束时间戳
        long endTime = System.currentTimeMillis();
        // 计算执行时间
        long executionTime = endTime - startTime;
        System.out.println("程序执行时间: " + executionTime + " 毫秒");

        startTime = System.currentTimeMillis();

        // 修改下级用户的项目明细抽佣比例
        LambdaQueryWrapper<SubUserProjectCommission> subUserProjectCommissionLambdaQueryWrapper = new LambdaQueryWrapper<>();
        subUserProjectCommissionLambdaQueryWrapper.eq(SubUserProjectCommission::getUserId, userId);
        List<SubUserProjectCommission> subUserProjectCommissionList = subUserProjectCommissionService.list(subUserProjectCommissionLambdaQueryWrapper);
        for (SubUserProjectCommission subUserProjectCommission : subUserProjectCommissionList) {
            Long projectDetailId = subUserProjectCommission.getProjectDetailId();
            BigDecimal maxCommissionRate = map.get(projectDetailId);
            BigDecimal setCommissionRate = uniteCommissionRate.compareTo(maxCommissionRate) > 0 ? maxCommissionRate : uniteCommissionRate;
            subUserProjectCommission.setCurrentCommissionRate(setCommissionRate);
        }
        subUserProjectCommissionService.updateBatchById(subUserProjectCommissionList);
        // 更新项目明细抽佣表和下级项目明细抽佣表的单价
        List<ProjectCommission> projectCommissions = this.list();
        List<SubUserProjectCommission> subUserProjectCommissions = commonService.convertList(projectCommissions, SubUserProjectCommission.class);
        for (SubUserProjectCommission subProjectCommission : subUserProjectCommissions) {
            subProjectCommission.setSubUserId(-1L);
        }
        List<SubUserProjectCommission> subProjectCommissions = subUserProjectCommissionService.list();

        // 获取结束时间戳
        endTime = System.currentTimeMillis();
        // 计算执行时间
        executionTime = endTime - startTime;
        System.out.println("程序执行时间: " + executionTime + " 毫秒");


        subProjectCommissions.addAll(subUserProjectCommissions);
        sortProjectDetailAndSubProjectCommissions(subProjectCommissions);
        // 1.封装一个Map集合（键：项目明细-下级用户id，值：当前用户的单价）
        Iterator<SubUserProjectCommission> iterator = subProjectCommissions.iterator();
        Map<String, BigDecimal> subUserUnitPriceMap = new HashMap<>();
        while (iterator.hasNext()) {
            SubUserProjectCommission commission = iterator.next();
            Long projectDetailId = commission.getProjectDetailId();
            BigDecimal projectMinSettlementPrice = minPriceMap.get(projectDetailId);
            if (commission.getUserId() < userId) {
                if (commission.getSubUserId() != -1L) subUserUnitPriceMap.put(projectDetailId + "-" + commission.getSubUserId(), calculateFinalPrice(commission.getMyUnitPrice(), commission.getCurrentCommissionRate()).max(projectMinSettlementPrice));
                iterator.remove(); // 使用迭代器的 remove() 方法移除
            }
        }


        for (SubUserProjectCommission subProjectCommission : subProjectCommissions) {
            Long projectDetailId = subProjectCommission.getProjectDetailId();
            BigDecimal projectMinSettlementPrice = minPriceMap.get(projectDetailId);
            Long uid = subProjectCommission.getUserId();
            Long subUserId = subProjectCommission.getSubUserId();
            if (uid.equals(userId)) {
                if (subUserId != -1L) subUserUnitPriceMap.put(projectDetailId + "-" + subUserId, calculateFinalPrice(subProjectCommission.getMyUnitPrice(), subProjectCommission.getCurrentCommissionRate()).max(projectMinSettlementPrice));
            } else {
                BigDecimal unitPrice = subUserUnitPriceMap.get(projectDetailId + "-" + uid);
                subProjectCommission.setMyUnitPrice(unitPrice);
                if (subUserId != -1L) subUserUnitPriceMap.put(projectDetailId + "-" + subUserId, calculateFinalPrice(unitPrice, subProjectCommission.getCurrentCommissionRate()).max(projectMinSettlementPrice));
            }
        }


        // 更新下级用户项目明细记录
        List<SubUserProjectCommission> subCommissionList = subProjectCommissions.stream()
                .filter(subProjectCommission -> subProjectCommission.getSubUserId() != -1L).toList();
        // 获取开始时间戳
        startTime = System.currentTimeMillis();
//        subUserProjectCommissionService.updateBatchById(subCommissionList);
        batchUpdateSubUserMyUnitPrice(subCommissionList);

        // 获取结束时间戳
        endTime = System.currentTimeMillis();
        // 计算执行时间
        executionTime = endTime - startTime;
        System.out.println("程序执行时间: " + executionTime + " 毫秒");


        startTime = System.currentTimeMillis();

        // 批量更新用户项目明细抽佣记录
        List<SubUserProjectCommission> proCommissions = subProjectCommissions.stream().filter(subProjectCommission -> subProjectCommission.getSubUserId() == -1L).toList();
        List<ProjectCommission> proCommissionList = commonService.convertList(proCommissions, ProjectCommission.class);
//        this.updateBatchById(proCommissionList);
        batchUpdateMyUnitPrice(proCommissionList);

        // 获取结束时间戳
        endTime = System.currentTimeMillis();
        // 计算执行时间
        executionTime = endTime - startTime;
        System.out.println("程序执行时间: " + executionTime + " 毫秒");

    }




    @Override
    @Transactional
    public void batchUpdateSubUserMyUnitPrice(List<SubUserProjectCommission> subCommissionList) {
        if (subCommissionList == null || subCommissionList.isEmpty()) {
            return;
        }
        StringBuilder sql = new StringBuilder("UPDATE sub_user_project_commission SET myUnitPrice = CASE id ");

        // 为每个记录构建 WHEN 条件
        for (SubUserProjectCommission subUserProjectCommission : subCommissionList) {
            sql.append("WHEN ").append(subUserProjectCommission.getId())
                    .append(" THEN ").append(subUserProjectCommission.getMyUnitPrice()).append(" ");
        }

        sql.append("END WHERE id IN (");

        // 添加所有 ID 到 WHERE 条件
        for (int i = 0; i < subCommissionList.size(); i++) {
            sql.append(subCommissionList.get(i).getId());
            if (i < subCommissionList.size() - 1) {
                sql.append(",");
            }
        }
        sql.append(");");

        // 执行 SQL 语句
        subUserProjectCommissionMapper.executeUpdate(sql.toString());
    }



    @Override
    @Transactional
    public void batchUpdateMyUnitPrice(List<ProjectCommission> projectCommissionList) {
        if (projectCommissionList == null || projectCommissionList.isEmpty()) {
            return;
        }
        StringBuilder sql = new StringBuilder("UPDATE project_commission SET myUnitPrice = CASE id ");

        // 为每条记录构建 WHEN ... THEN ...
        for (ProjectCommission pc : projectCommissionList) {
            sql.append("WHEN ").append(pc.getId())
                    .append(" THEN ").append(pc.getMyUnitPrice()).append(" ");
        }

        sql.append("END WHERE id IN (");
        // 拼接所有 id 到 IN 列表
        for (int i = 0; i < projectCommissionList.size(); i++) {
            sql.append(projectCommissionList.get(i).getId());
            if (i < projectCommissionList.size() - 1) {
                sql.append(",");
            }
        }
        sql.append(")");

        // 执行拼好的 SQL
        this.baseMapper.executeUpdate(sql.toString());
    }




    @Override
    // 封装排序方法
    public void sortSubProjectCommissions(List<SubUserProjectCommission> subProjectCommissions) {
        // 先根据userId升序排序
        // 如果userId相同，再根据subUserId升序排序
        Collections.sort(subProjectCommissions, Comparator.comparingLong(SubUserProjectCommission::getUserId).thenComparingLong(SubUserProjectCommission::getSubUserId));
    }

    @Override
    // 封装排序方法
    public void sortProjectDetailAndSubProjectCommissions(List<SubUserProjectCommission> subProjectCommissions) {
        // 先根据userId升序排序
        // 如果userId相同，再根据subUserId升序排序
        Collections.sort(subProjectCommissions, Comparator.comparingLong(SubUserProjectCommission::getProjectDetailId).thenComparingLong(SubUserProjectCommission::getUserId).thenComparingLong(SubUserProjectCommission::getSubUserId));
    }


    @Override
    // 封装方法：根据价格和抽佣比例计算最终价格
    public BigDecimal calculateFinalPrice(BigDecimal price, BigDecimal commissionRate) {
        // 计算抽佣比例对应的系数
        BigDecimal commissionFactor = BigDecimal.ONE.subtract(commissionRate.divide(BigDecimal.valueOf(100)));

        // 计算最终价格
        return price.multiply(commissionFactor);
    }



}




