在这里插入图片描述

项目概述

智能成本控制管理系统是一个基于Kotlin Multiplatform (KMP)和OpenHarmony平台开发的综合性成本管理解决方案。该系统通过实时监测和分析企业成本的关键指标,包括成本控制率、预算执行率、成本降低率、成本偏差率和成本效益比等,为企业财务和运营部门提供科学的成本管理决策支持和成本优化建议。

成本控制是企业利润的直接来源,直接影响到企业的竞争力和盈利能力。传统的成本管理往往依赖事后分析和人工统计,存在成本难以实时控制、偏差难以及时发现、优化空间难以识别等问题。本系统通过引入先进的数据分析和成本优化技术,实现了对企业成本的全面、实时、精准的监测和评估。该系统采用KMP技术栈,使得核心的成本评估算法可以在Kotlin中编写,然后编译为JavaScript在Web端运行,同时通过ArkTS在OpenHarmony设备上调用,实现了跨平台的统一解决方案。

核心功能特性

1. 多维度成本指标监测

系统能够同时监测成本控制率、预算执行率、成本降低率、成本偏差率和成本效益比五个关键成本指标。这些指标的组合分析可以全面反映企业的成本管理状况。成本控制率衡量成本管理的有效性;预算执行率反映预算的合理性;成本降低率体现成本优化的成果;成本偏差率反映成本的波动程度;成本效益比衡量成本投入的回报。

2. 智能成本评估算法

系统采用多维度评估算法,综合考虑各个成本指标的相对重要性,给出客观的成本评分。通过建立成本指标与企业效益之间的映射关系,系统能够快速识别成本问题和优化空间。这种算法不仅考虑了单个指标的影响,还充分考虑了指标之间的相互关系和制约条件。

3. 分级成本管理建议

系统根据当前的成本状况,生成分级的管理建议。对于成本管理良好的企业,系统建议保持现有策略;对于存在成本问题的企业,系统会提出具体的改善方案,包括改善的方向、预期效果等。这种分级方式确保了管理建议的针对性和实用性。

4. 成本优化支持

系统能够计算企业的成本优化指数,包括控制风险、预算风险、效益风险等。通过这种量化的评估,企业可以清晰地了解成本的优化空间,为决策提供有力支撑。

技术架构

Kotlin后端实现

使用Kotlin语言编写核心的成本评估算法和优化分析模型。Kotlin的简洁语法和强大的类型系统使得复杂的算法实现既易于维护又能保证运行时的安全性。通过@JsExport注解,将Kotlin函数导出为JavaScript,实现跨平台调用。

JavaScript中间层

Kotlin编译生成的JavaScript代码作为中间层,提供了Web端的数据处理能力。这一层负责接收来自各种数据源的输入,进行数据验证和转换,然后调用核心的评估算法。

ArkTS前端展示

在OpenHarmony设备上,使用ArkTS编写用户界面。通过调用JavaScript导出的函数,实现了与后端逻辑的无缝集成。用户可以通过直观的界面输入成本指标,实时查看评估结果和管理建议。

应用场景

本系统适用于各类企业的成本管理部门,特别是:

  • 制造企业的成本管理中心
  • 企业的财务管理部门
  • 项目管理部门的成本控制
  • 企业的运营管理部门

Kotlin实现代码

智能成本控制管理系统核心算法

@JsExport
fun smartCostControlSystem(inputData: String): String {
    val parts = inputData.trim().split(" ")
    if (parts.size != 5) {
        return "格式错误\n请输入: 成本控制率(%) 预算执行率(%) 成本降低率(%) 成本偏差率(%) 成本效益比(%)\n例如: 92 88 15 5 120"
    }
    
    val costControlRate = parts[0].toDoubleOrNull()
    val budgetExecutionRate = parts[1].toDoubleOrNull()
    val costReductionRate = parts[2].toDoubleOrNull()
    val costVarianceRate = parts[3].toDoubleOrNull()
    val costBenefitRatio = parts[4].toDoubleOrNull()
    
    if (costControlRate == null || budgetExecutionRate == null || costReductionRate == null || costVarianceRate == null || costBenefitRatio == null) {
        return "数值错误\n请输入有效的数字"
    }
    
    // 参数范围验证
    if (costControlRate < 0 || costControlRate > 100) {
        return "成本控制率应在0-100%之间"
    }
    if (budgetExecutionRate < 0 || budgetExecutionRate > 100) {
        return "预算执行率应在0-100%之间"
    }
    if (costReductionRate < 0 || costReductionRate > 100) {
        return "成本降低率应在0-100%之间"
    }
    if (costVarianceRate < 0 || costVarianceRate > 100) {
        return "成本偏差率应在0-100%之间"
    }
    if (costBenefitRatio < 0 || costBenefitRatio > 500) {
        return "成本效益比应在0-500%之间"
    }
    
    // 计算各指标的评分
    val controlScore = costControlRate.toInt()
    val budgetScore = budgetExecutionRate.toInt()
    val reductionScore = calculateReductionScore(costReductionRate)
    val varianceScore = calculateVarianceScore(costVarianceRate)
    val benefitScore = calculateBenefitScore(costBenefitRatio)
    
    // 加权综合评分
    val overallScore = (controlScore * 0.30 + budgetScore * 0.25 + reductionScore * 0.20 + varianceScore * 0.15 + benefitScore * 0.10).toInt()
    
    // 成本等级判定
    val costLevel = when {
        overallScore >= 90 -> "🟢 优秀"
        overallScore >= 75 -> "🟡 良好"
        overallScore >= 60 -> "🟠 一般"
        else -> "🔴 需改进"
    }
    
    // 计算成本优化指标
    val controlRisk = (100 - costControlRate) / 2
    val budgetRisk = kotlin.math.abs(100 - budgetExecutionRate) / 2
    val reductionRisk = (20 - costReductionRate) * 2
    val varianceRisk = costVarianceRate * 2
    val benefitRisk = (150 - costBenefitRatio) / 2
    val totalRisk = (controlRisk + budgetRisk + reductionRisk + varianceRisk + benefitRisk) / 5
    
    // 生成详细报告
    return buildString {
        appendLine("╔════════════════════════════════════════╗")
        appendLine("║    💰 智能成本控制管理系统评估报告    ║")
        appendLine("╚════════════════════════════════════════╝")
        appendLine()
        appendLine("📊 成本指标监测")
        appendLine("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
        appendLine("成本控制率: ${(costControlRate * 100).toInt() / 100.0}%")
        appendLine("预算执行率: ${(budgetExecutionRate * 100).toInt() / 100.0}%")
        appendLine("成本降低率: ${(costReductionRate * 100).toInt() / 100.0}%")
        appendLine("成本偏差率: ${(costVarianceRate * 100).toInt() / 100.0}%")
        appendLine("成本效益比: ${(costBenefitRatio * 100).toInt() / 100.0}%")
        appendLine()
        appendLine("⭐ 指标评分")
        appendLine("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
        appendLine("控制率评分: $controlScore/100")
        appendLine("预算率评分: $budgetScore/100")
        appendLine("降低率评分: $reductionScore/100")
        appendLine("偏差率评分: $varianceScore/100")
        appendLine("效益比评分: $benefitScore/100")
        appendLine()
        appendLine("🎯 综合评估")
        appendLine("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
        appendLine("综合成本评分: $overallScore/100")
        appendLine("成本等级: $costLevel")
        appendLine("综合优化指数: ${(totalRisk * 100).toInt() / 100.0}/100")
        appendLine()
        appendLine("⚠️ 风险分析")
        appendLine("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
        appendLine("控制风险: ${(controlRisk * 100).toInt() / 100.0}%")
        appendLine("预算风险: ${(budgetRisk * 100).toInt() / 100.0}%")
        appendLine("降低风险: ${(reductionRisk * 100).toInt() / 100.0}%")
        appendLine("偏差风险: ${(varianceRisk * 100).toInt() / 100.0}%")
        appendLine("效益风险: ${(benefitRisk * 100).toInt() / 100.0}%")
        appendLine()
        appendLine("💡 成本管理建议")
        appendLine("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
        
        // 控制率建议
        if (costControlRate < 85) {
            appendLine("  📉 成本控制率偏低")
            appendLine("     - 加强成本监控")
            appendLine("     - 完善控制制度")
            appendLine("     - 提升控制能力")
        } else if (costControlRate >= 95) {
            appendLine("  ✅ 成本控制率处于优秀水平")
            appendLine("     - 继续保持高控制率")
            appendLine("     - 深化成本管理")
        }
        
        // 预算建议
        if (budgetExecutionRate < 80 || budgetExecutionRate > 100) {
            appendLine("  📋 预算执行率偏离目标")
            appendLine("     - 优化预算计划")
            appendLine("     - 加强预算管理")
            appendLine("     - 提升执行精度")
        } else if (budgetExecutionRate >= 90 && budgetExecutionRate <= 100) {
            appendLine("  ✅ 预算执行率处于优秀水平")
            appendLine("     - 继续保持高执行率")
            appendLine("     - 深化预算管理")
        }
        
        // 降低率建议
        if (costReductionRate < 10) {
            appendLine("  📉 成本降低率偏低")
            appendLine("     - 加强成本优化")
            appendLine("     - 挖掘降低空间")
            appendLine("     - 实施改善项目")
        } else if (costReductionRate >= 20) {
            appendLine("  ✅ 成本降低率处于优秀水平")
            appendLine("     - 继续保持高降低率")
            appendLine("     - 深化成本优化")
        }
        
        // 偏差建议
        if (costVarianceRate > 10) {
            appendLine("  🔴 成本偏差率过高")
            appendLine("     - 分析偏差原因")
            appendLine("     - 制定纠正措施")
            appendLine("     - 加强成本控制")
        } else if (costVarianceRate < 5) {
            appendLine("  ✅ 成本偏差率处于优秀水平")
            appendLine("     - 继续保持低偏差")
            appendLine("     - 深化成本管理")
        }
        
        // 效益建议
        if (costBenefitRatio < 100) {
            appendLine("  💸 成本效益比偏低")
            appendLine("     - 提升成本效益")
            appendLine("     - 优化成本投入")
            appendLine("     - 增加收益产出")
        } else if (costBenefitRatio >= 150) {
            appendLine("  💎 成本效益比处于优秀水平")
            appendLine("     - 继续保持高效益")
            appendLine("     - 深化成本优化")
        }
        
        appendLine()
        appendLine("📋 改善方案")
        appendLine("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
        when {
            overallScore < 60 -> {
                appendLine("🔴 需要重点改进 - 建议立即采取行动")
                appendLine("  1. 进行全面的成本诊断")
                appendLine("  2. 制定成本改善计划")
                appendLine("  3. 加强成本管理")
                appendLine("  4. 优化成本结构")
                appendLine("  5. 建立管理制度")
            }
            overallScore < 75 -> {
                appendLine("🟠 存在改进空间 - 建议逐步改进")
                appendLine("  1. 优化成本控制")
                appendLine("  2. 加强预算管理")
                appendLine("  3. 提升降低效果")
                appendLine("  4. 降低成本偏差")
            }
            overallScore < 90 -> {
                appendLine("🟡 成本状况良好 - 继续优化")
                appendLine("  1. 微调成本策略")
                appendLine("  2. 持续改进效率")
                appendLine("  3. 定期成本审查")
            }
            else -> {
                appendLine("🟢 成本状况优秀 - 保持现状")
                appendLine("  1. 维持现有管理")
                appendLine("  2. 定期成本审核")
                appendLine("  3. 持续优化管理")
            }
        }
        
        appendLine()
        appendLine("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
        appendLine("✅ 评估完成 | 时间戳: ${System.currentTimeMillis()}")
    }
}

// 成本降低率评分函数
private fun calculateReductionScore(rate: Double): Int {
    return when {
        rate >= 20 -> 100
        rate >= 15 -> 85
        rate >= 10 -> 70
        else -> 40
    }
}

// 成本偏差率评分函数
private fun calculateVarianceScore(rate: Double): Int {
    return when {
        rate <= 5 -> 100
        rate <= 10 -> 85
        rate <= 15 -> 70
        else -> 40
    }
}

// 成本效益比评分函数
private fun calculateBenefitScore(ratio: Double): Int {
    return when {
        ratio >= 150 -> 100
        ratio >= 120 -> 85
        ratio >= 100 -> 70
        else -> 40
    }
}

代码说明

上述Kotlin代码实现了智能成本控制管理系统的核心算法。smartCostControlSystem函数是主入口,接收一个包含五个成本指标的字符串输入。函数首先进行输入验证,确保数据的有效性和范围的合理性。

然后,它计算各指标的评分,其中成本控制率和预算执行率直接使用输入值,而成本降低率、成本偏差率和成本效益比需要通过专门的评分函数计算。这种设计使得系统能够灵活处理不同类型的成本数据。

系统使用加权平均法计算综合评分,其中成本控制率的权重最高(30%),因为它是成本管理的直接体现。预算执行率的权重为25%,成本降低率的权重为20%,成本偏差率的权重为15%,成本效益比的权重为10%。

最后,系统根据综合评分判定成本等级,并生成详细的评估报告。同时,系统还计算了各类成本优化指数,为企业提供量化的优化建议。


JavaScript编译版本

// 智能成本控制管理系统 - JavaScript版本
function smartCostControlSystem(inputData) {
    const parts = inputData.trim().split(" ");
    if (parts.length !== 5) {
        return "格式错误\n请输入: 成本控制率(%) 预算执行率(%) 成本降低率(%) 成本偏差率(%) 成本效益比(%)\n例如: 92 88 15 5 120";
    }
    
    const costControlRate = parseFloat(parts[0]);
    const budgetExecutionRate = parseFloat(parts[1]);
    const costReductionRate = parseFloat(parts[2]);
    const costVarianceRate = parseFloat(parts[3]);
    const costBenefitRatio = parseFloat(parts[4]);
    
    // 数值验证
    if (isNaN(costControlRate) || isNaN(budgetExecutionRate) || isNaN(costReductionRate) || 
        isNaN(costVarianceRate) || isNaN(costBenefitRatio)) {
        return "数值错误\n请输入有效的数字";
    }
    
    // 范围检查
    if (costControlRate < 0 || costControlRate > 100) {
        return "成本控制率应在0-100%之间";
    }
    if (budgetExecutionRate < 0 || budgetExecutionRate > 100) {
        return "预算执行率应在0-100%之间";
    }
    if (costReductionRate < 0 || costReductionRate > 100) {
        return "成本降低率应在0-100%之间";
    }
    if (costVarianceRate < 0 || costVarianceRate > 100) {
        return "成本偏差率应在0-100%之间";
    }
    if (costBenefitRatio < 0 || costBenefitRatio > 500) {
        return "成本效益比应在0-500%之间";
    }
    
    // 计算各指标评分
    const controlScore = Math.floor(costControlRate);
    const budgetScore = Math.floor(budgetExecutionRate);
    const reductionScore = calculateReductionScore(costReductionRate);
    const varianceScore = calculateVarianceScore(costVarianceRate);
    const benefitScore = calculateBenefitScore(costBenefitRatio);
    
    // 加权综合评分
    const overallScore = Math.floor(
        controlScore * 0.30 + budgetScore * 0.25 + reductionScore * 0.20 + 
        varianceScore * 0.15 + benefitScore * 0.10
    );
    
    // 成本等级判定
    let costLevel;
    if (overallScore >= 90) {
        costLevel = "🟢 优秀";
    } else if (overallScore >= 75) {
        costLevel = "🟡 良好";
    } else if (overallScore >= 60) {
        costLevel = "🟠 一般";
    } else {
        costLevel = "🔴 需改进";
    }
    
    // 计算成本优化指标
    const controlRisk = (100 - costControlRate) / 2;
    const budgetRisk = Math.abs(100 - budgetExecutionRate) / 2;
    const reductionRisk = (20 - costReductionRate) * 2;
    const varianceRisk = costVarianceRate * 2;
    const benefitRisk = (150 - costBenefitRatio) / 2;
    const totalRisk = (controlRisk + budgetRisk + reductionRisk + varianceRisk + benefitRisk) / 5;
    
    // 生成报告
    let report = "";
    report += "╔════════════════════════════════════════╗\n";
    report += "║    💰 智能成本控制管理系统评估报告    ║\n";
    report += "╚════════════════════════════════════════╝\n\n";
    
    report += "📊 成本指标监测\n";
    report += "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
    report += `成本控制率: ${(Math.round(costControlRate * 100) / 100).toFixed(2)}%\n`;
    report += `预算执行率: ${(Math.round(budgetExecutionRate * 100) / 100).toFixed(2)}%\n`;
    report += `成本降低率: ${(Math.round(costReductionRate * 100) / 100).toFixed(2)}%\n`;
    report += `成本偏差率: ${(Math.round(costVarianceRate * 100) / 100).toFixed(2)}%\n`;
    report += `成本效益比: ${(Math.round(costBenefitRatio * 100) / 100).toFixed(2)}%\n\n`;
    
    report += "⭐ 指标评分\n";
    report += "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
    report += `控制率评分: ${controlScore}/100\n`;
    report += `预算率评分: ${budgetScore}/100\n`;
    report += `降低率评分: ${reductionScore}/100\n`;
    report += `偏差率评分: ${varianceScore}/100\n`;
    report += `效益比评分: ${benefitScore}/100\n\n`;
    
    report += "🎯 综合评估\n";
    report += "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
    report += `综合成本评分: ${overallScore}/100\n`;
    report += `成本等级: ${costLevel}\n`;
    report += `综合优化指数: ${(Math.round(totalRisk * 100) / 100).toFixed(2)}/100\n\n`;
    
    report += "⚠️ 风险分析\n";
    report += "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
    report += `控制风险: ${(Math.round(controlRisk * 100) / 100).toFixed(2)}%\n`;
    report += `预算风险: ${(Math.round(budgetRisk * 100) / 100).toFixed(2)}%\n`;
    report += `降低风险: ${(Math.round(reductionRisk * 100) / 100).toFixed(2)}%\n`;
    report += `偏差风险: ${(Math.round(varianceRisk * 100) / 100).toFixed(2)}%\n`;
    report += `效益风险: ${(Math.round(benefitRisk * 100) / 100).toFixed(2)}%\n\n`;
    
    report += "💡 成本管理建议\n";
    report += "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
    
    // 控制率建议
    if (costControlRate < 85) {
        report += "  📉 成本控制率偏低\n";
        report += "     - 加强成本监控\n";
        report += "     - 完善控制制度\n";
        report += "     - 提升控制能力\n";
    } else if (costControlRate >= 95) {
        report += "  ✅ 成本控制率处于优秀水平\n";
        report += "     - 继续保持高控制率\n";
        report += "     - 深化成本管理\n";
    }
    
    // 预算建议
    if (budgetExecutionRate < 80 || budgetExecutionRate > 100) {
        report += "  📋 预算执行率偏离目标\n";
        report += "     - 优化预算计划\n";
        report += "     - 加强预算管理\n";
        report += "     - 提升执行精度\n";
    } else if (budgetExecutionRate >= 90 && budgetExecutionRate <= 100) {
        report += "  ✅ 预算执行率处于优秀水平\n";
        report += "     - 继续保持高执行率\n";
        report += "     - 深化预算管理\n";
    }
    
    // 降低率建议
    if (costReductionRate < 10) {
        report += "  📉 成本降低率偏低\n";
        report += "     - 加强成本优化\n";
        report += "     - 挖掘降低空间\n";
        report += "     - 实施改善项目\n";
    } else if (costReductionRate >= 20) {
        report += "  ✅ 成本降低率处于优秀水平\n";
        report += "     - 继续保持高降低率\n";
        report += "     - 深化成本优化\n";
    }
    
    // 偏差建议
    if (costVarianceRate > 10) {
        report += "  🔴 成本偏差率过高\n";
        report += "     - 分析偏差原因\n";
        report += "     - 制定纠正措施\n";
        report += "     - 加强成本控制\n";
    } else if (costVarianceRate < 5) {
        report += "  ✅ 成本偏差率处于优秀水平\n";
        report += "     - 继续保持低偏差\n";
        report += "     - 深化成本管理\n";
    }
    
    // 效益建议
    if (costBenefitRatio < 100) {
        report += "  💸 成本效益比偏低\n";
        report += "     - 提升成本效益\n";
        report += "     - 优化成本投入\n";
        report += "     - 增加收益产出\n";
    } else if (costBenefitRatio >= 150) {
        report += "  💎 成本效益比处于优秀水平\n";
        report += "     - 继续保持高效益\n";
        report += "     - 深化成本优化\n";
    }
    
    report += "\n📋 改善方案\n";
    report += "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
    
    if (overallScore < 60) {
        report += "🔴 需要重点改进 - 建议立即采取行动\n";
        report += "  1. 进行全面的成本诊断\n";
        report += "  2. 制定成本改善计划\n";
        report += "  3. 加强成本管理\n";
        report += "  4. 优化成本结构\n";
        report += "  5. 建立管理制度\n";
    } else if (overallScore < 75) {
        report += "🟠 存在改进空间 - 建议逐步改进\n";
        report += "  1. 优化成本控制\n";
        report += "  2. 加强预算管理\n";
        report += "  3. 提升降低效果\n";
        report += "  4. 降低成本偏差\n";
    } else if (overallScore < 90) {
        report += "🟡 成本状况良好 - 继续优化\n";
        report += "  1. 微调成本策略\n";
        report += "  2. 持续改进效率\n";
        report += "  3. 定期成本审查\n";
    } else {
        report += "🟢 成本状况优秀 - 保持现状\n";
        report += "  1. 维持现有管理\n";
        report += "  2. 定期成本审核\n";
        report += "  3. 持续优化管理\n";
    }
    
    report += "\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
    report += `✅ 评估完成 | 时间戳: ${Date.now()}\n`;
    
    return report;
}

// 评分函数
function calculateReductionScore(rate) {
    if (rate >= 20) return 100;
    if (rate >= 15) return 85;
    if (rate >= 10) return 70;
    return 40;
}

function calculateVarianceScore(rate) {
    if (rate <= 5) return 100;
    if (rate <= 10) return 85;
    if (rate <= 15) return 70;
    return 40;
}

function calculateBenefitScore(ratio) {
    if (ratio >= 150) return 100;
    if (ratio >= 120) return 85;
    if (ratio >= 100) return 70;
    return 40;
}

JavaScript版本说明

JavaScript版本是由Kotlin代码编译而来的,提供了完全相同的功能。在Web环境中,这个JavaScript函数可以直接被调用,用于处理来自前端表单的数据。相比Kotlin版本,JavaScript版本使用了原生的JavaScript语法,如parseFloatparseIntMath.floor等,确保了在浏览器环境中的兼容性。

该版本保留了所有的业务逻辑和计算方法,确保了跨平台的一致性。通过这种方式,开发者只需要维护一份Kotlin代码,就可以在多个平台上运行相同的业务逻辑。


ArkTS调用实现

import { smartCostControlSystem } from './hellokjs'

@Entry
@Component
struct SmartCostControlPage {
  @State costControlRate: string = "92"
  @State budgetExecutionRate: string = "88"
  @State costReductionRate: string = "15"
  @State costVarianceRate: string = "5"
  @State costBenefitRatio: string = "120"
  @State result: string = ""
  @State isLoading: boolean = false

  build() {
    Column() {
      // 顶部标题栏
      Row() {
        Text("💰 智能成本控制管理系统")
          .fontSize(20)
          .fontWeight(FontWeight.Bold)
          .fontColor('#FFFFFF')
      }
      .width('100%')
      .height(60)
      .backgroundColor('#F57C00')
      .justifyContent(FlexAlign.Center)
      .padding({ left: 16, right: 16 })

      // 主体内容
      Scroll() {
        Column() {
          // 参数输入部分
          Column() {
            Text("📊 成本指标输入")
              .fontSize(16)
              .fontWeight(FontWeight.Bold)
              .fontColor('#F57C00')
              .margin({ bottom: 12 })
              .padding({ left: 12, top: 12 })

            // 2列网格布局
            Column() {
              // 第一行
              Row() {
                Column() {
                  Text("成本控制率(%)")
                    .fontSize(12)
                    .fontWeight(FontWeight.Bold)
                    .margin({ bottom: 4 })
                  TextInput({ placeholder: "92", text: this.costControlRate })
                    .height(40)
                    .width('100%')
                    .onChange((value: string) => { this.costControlRate = value })
                    .backgroundColor('#FFFFFF')
                    .border({ width: 1, color: '#F57C00' })
                    .borderRadius(4)
                    .padding(8)
                    .fontSize(12)
                }.width('48%').padding(6)
                Blank().width('4%')
                Column() {
                  Text("预算执行率(%)")
                    .fontSize(12)
                    .fontWeight(FontWeight.Bold)
                    .margin({ bottom: 4 })
                  TextInput({ placeholder: "88", text: this.budgetExecutionRate })
                    .height(40)
                    .width('100%')
                    .onChange((value: string) => { this.budgetExecutionRate = value })
                    .backgroundColor('#FFFFFF')
                    .border({ width: 1, color: '#F57C00' })
                    .borderRadius(4)
                    .padding(8)
                    .fontSize(12)
                }.width('48%').padding(6)
              }.width('100%').justifyContent(FlexAlign.SpaceBetween)

              // 第二行
              Row() {
                Column() {
                  Text("成本降低率(%)")
                    .fontSize(12)
                    .fontWeight(FontWeight.Bold)
                    .margin({ bottom: 4 })
                  TextInput({ placeholder: "15", text: this.costReductionRate })
                    .height(40)
                    .width('100%')
                    .onChange((value: string) => { this.costReductionRate = value })
                    .backgroundColor('#FFFFFF')
                    .border({ width: 1, color: '#F57C00' })
                    .borderRadius(4)
                    .padding(8)
                    .fontSize(12)
                }.width('48%').padding(6)
                Blank().width('4%')
                Column() {
                  Text("成本偏差率(%)")
                    .fontSize(12)
                    .fontWeight(FontWeight.Bold)
                    .margin({ bottom: 4 })
                  TextInput({ placeholder: "5", text: this.costVarianceRate })
                    .height(40)
                    .width('100%')
                    .onChange((value: string) => { this.costVarianceRate = value })
                    .backgroundColor('#FFFFFF')
                    .border({ width: 1, color: '#F57C00' })
                    .borderRadius(4)
                    .padding(8)
                    .fontSize(12)
                }.width('48%').padding(6)
              }.width('100%').justifyContent(FlexAlign.SpaceBetween).margin({ top: 8 })

              // 第三行
              Row() {
                Column() {
                  Text("成本效益比(%)")
                    .fontSize(12)
                    .fontWeight(FontWeight.Bold)
                    .margin({ bottom: 4 })
                  TextInput({ placeholder: "120", text: this.costBenefitRatio })
                    .height(40)
                    .width('100%')
                    .onChange((value: string) => { this.costBenefitRatio = value })
                    .backgroundColor('#FFFFFF')
                    .border({ width: 1, color: '#F57C00' })
                    .borderRadius(4)
                    .padding(8)
                    .fontSize(12)
                }.width('48%').padding(6)
                Blank().width('52%')
              }.width('100%').margin({ top: 8 })
            }
            .width('100%')
            .padding({ left: 6, right: 6, bottom: 12 })
          }
          .width('100%')
          .padding(12)
          .backgroundColor('#FFE0B2')
          .borderRadius(8)
          .margin({ bottom: 12 })

          // 按钮区域
          Row() {
            Button("开始评估")
              .width('48%')
              .height(44)
              .fontSize(14)
              .fontWeight(FontWeight.Bold)
              .backgroundColor('#F57C00')
              .fontColor(Color.White)
              .borderRadius(6)
              .onClick(() => {
                this.executeEvaluation()
              })

            Blank().width('4%')

            Button("重置参数")
              .width('48%')
              .height(44)
              .fontSize(14)
              .fontWeight(FontWeight.Bold)
              .backgroundColor('#FFB74D')
              .fontColor(Color.White)
              .borderRadius(6)
              .onClick(() => {
                this.costControlRate = "92"
                this.budgetExecutionRate = "88"
                this.costReductionRate = "15"
                this.costVarianceRate = "5"
                this.costBenefitRatio = "120"
                this.result = ""
              })
          }
          .width('100%')
          .justifyContent(FlexAlign.Center)
          .padding({ left: 12, right: 12, bottom: 12 })

          // 结果显示部分
          Column() {
            Text("📋 评估结果")
              .fontSize(16)
              .fontWeight(FontWeight.Bold)
              .fontColor('#F57C00')
              .margin({ bottom: 12 })
              .padding({ left: 12, right: 12, top: 12 })

            if (this.isLoading) {
              Column() {
                LoadingProgress()
                  .width(50)
                  .height(50)
                  .color('#F57C00')
                Text("正在评估...")
                  .fontSize(14)
                  .fontColor('#F57C00')
                  .margin({ top: 16 })
              }
              .width('100%')
              .height(200)
              .justifyContent(FlexAlign.Center)
              .alignItems(HorizontalAlign.Center)
            } else if (this.result.length > 0) {
              Scroll() {
                Text(this.result)
                  .fontSize(11)
                  .fontColor('#F57C00')
                  .fontFamily('monospace')
                  .width('100%')
                  .padding(12)
                  .lineHeight(1.6)
              }
              .width('100%')
              .height(400)
            } else {
              Column() {
                Text("💰")
                  .fontSize(64)
                  .opacity(0.2)
                  .margin({ bottom: 16 })
                Text("暂无评估结果")
                  .fontSize(14)
                  .fontColor('#F57C00')
                Text("请输入成本指标后点击开始评估")
                  .fontSize(12)
                  .fontColor('#FFB74D')
                  .margin({ top: 8 })
              }
              .width('100%')
              .height(200)
              .justifyContent(FlexAlign.Center)
              .alignItems(HorizontalAlign.Center)
            }
          }
          .layoutWeight(1)
          .width('100%')
          .padding(12)
          .backgroundColor('#F5F5F5')
          .borderRadius(8)
        }
        .width('100%')
        .padding(12)
      }
      .layoutWeight(1)
    }
    .width('100%')
    .height('100%')
    .backgroundColor('#FAFAFA')
  }

  private executeEvaluation() {
    const controlStr = this.costControlRate.trim()
    const budgetStr = this.budgetExecutionRate.trim()
    const reductStr = this.costReductionRate.trim()
    const varStr = this.costVarianceRate.trim()
    const benefStr = this.costBenefitRatio.trim()

    if (!controlStr || !budgetStr || !reductStr || !varStr || !benefStr) {
      this.result = "❌ 请填写全部成本指标"
      return
    }

    this.isLoading = true

    setTimeout((): void => {
      try {
        const inputStr = `${controlStr} ${budgetStr} ${reductStr} ${varStr} ${benefStr}`
        const result = smartCostControlSystem(inputStr)
        this.result = result
        console.log("[SmartCostControlSystem] 评估完成")
      } catch (error) {
        this.result = `❌ 执行出错: ${error}`
        console.error("[SmartCostControlSystem] 错误:", error)
      } finally {
        this.isLoading = false
      }
    }, 500)
  }
}

ArkTS调用说明

ArkTS是OpenHarmony平台上的主要开发语言,它基于TypeScript进行了扩展,提供了更好的性能和类型安全。在上述代码中,我们创建了一个完整的UI界面,用于输入成本指标并显示评估结果。

页面采用了分层设计:顶部是标题栏,中间是参数输入区域,下方是评估结果显示区。参数输入区使用了2列网格布局,使得界面紧凑而不失清晰。每个输入框都有对应的标签和默认值,方便用户快速操作。

executeEvaluation方法是关键的交互逻辑。当用户点击"开始评估"按钮时,该方法会收集所有输入参数,组合成一个字符串,然后调用从JavaScript导出的smartCostControlSystem函数。函数返回的结果会被显示在下方的滚动区域中。同时,系统使用isLoading状态来显示加载动画,提升用户体验。


系统集成与部署

编译流程

  1. Kotlin编译:使用KMP的Gradle插件,将Kotlin代码编译为JavaScript
  2. JavaScript生成:生成的JavaScript文件包含了所有的业务逻辑
  3. ArkTS集成:在ArkTS项目中导入JavaScript文件,通过import语句引入函数
  4. 应用打包:将整个应用打包为OpenHarmony应用安装包

部署建议

  • 在企业的财务管理中心部署该系统的Web版本
  • 在各个部门部署OpenHarmony设备,运行该系统的移动版本
  • 建立数据同步机制,确保各设备间的数据一致性
  • 定期备份评估数据,用于后续的成本分析和改进

总结

智能成本控制管理系统通过整合Kotlin、JavaScript和ArkTS三种技术,提供了一个完整的、跨平台的成本管理解决方案。该系统不仅能够实时监测企业成本的关键指标,还能够进行智能分析和管理建议,为企业提供了强有力的技术支撑。

通过本系统的应用,企业可以显著提高成本管理的效率和效果,优化成本结构,降低成本水平,提升成本效益。同时,系统生成的详细报告和建议也为企业的持续改进提供了数据支撑。

在未来,该系统还可以进一步扩展,集成更多的成本数据、引入人工智能算法进行更精准的成本预测、建立与企业资源规划系统的联动机制等,使其成为一个更加智能、更加完善的成本管理平台。

欢迎加入开源鸿蒙跨平台社区:https://openharmonycrossplatform.csdn.net

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐