package com.ximai.mes.util;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class BusinessUtil {
    public static BigDecimal getTheStandardTime(String stdWorkingTimeUom, BigDecimal stdWorkingTime, BigDecimal quantity) {
        long seconds = 0;
        if ("HOUR".equals(stdWorkingTimeUom)) {
            seconds = stdWorkingTime.longValue() * 60 * 60;
        } else if ("MINUTE".equals(stdWorkingTimeUom)) {
            seconds = stdWorkingTime.longValue() * 60;
        } else {
            seconds = stdWorkingTime.longValue();
        }

        if (seconds == 0) {
            return BigDecimal.ZERO;
        }

        // (数量 100/ 时间 10) == 时间1 * 10数量 每秒单位数量
        double l = new BigDecimal(quantity.longValue() / seconds).setScale(3, RoundingMode.DOWN).doubleValue();
        if (l > 0) {
            return new BigDecimal(l);
        } else {
            return BigDecimal.ZERO;
        }
    }
}
