package com.ruoyi.web.modules.industryservice.support;

import java.math.BigDecimal;
import java.math.RoundingMode;
import com.ruoyi.web.modules.industryservice.domain.BizRuralThreeAssets;

/**
 * 农村三资派生字段。
 * <p>固定资产 = 经营性固定资产 + 非经营性固定资产，保留 2 位小数；两者皆空则固定资产为空。</p>
 */
public final class RuralThreeAssetsDerivedSupport
{
    private RuralThreeAssetsDerivedSupport()
    {
    }

    public static void applyDerived(BizRuralThreeAssets row)
    {
        if (row == null)
        {
            return;
        }
        BigDecimal operating = row.getOperatingFixedAssets();
        BigDecimal nonOperating = row.getNonOperatingFixedAssets();
        if (operating == null && nonOperating == null)
        {
            row.setFixedAssets(null);
            return;
        }
        BigDecimal sum = BigDecimal.ZERO;
        if (operating != null)
        {
            sum = sum.add(operating);
        }
        if (nonOperating != null)
        {
            sum = sum.add(nonOperating);
        }
        row.setFixedAssets(sum.setScale(2, RoundingMode.HALF_UP));
    }
}
