自动化立体仓库 - WMS系统
#
Junjie
1 天以前 96b883c6c47c1b02b84d1efbf93b2c8ddcca5ad3
src/main/java/com/zy/asrs/utils/MatUtils.java
@@ -1,8 +1,14 @@
package com.zy.asrs.utils;
import com.core.common.Cools;
import com.core.common.SpringUtils;
import com.core.exception.CoolException;
import com.zy.asrs.entity.Mat;
import com.zy.asrs.service.MatService;
import lombok.extern.slf4j.Slf4j;
import java.math.BigDecimal;
import java.math.RoundingMode;
/**
 * Created by vincent on 2022/4/23
@@ -27,4 +33,54 @@
        }
    }
    public static Double calcWeight(String matnr, Double anfme) {
        MatService matService = SpringUtils.getBean(MatService.class);
        //更新辅料
        Mat mat = matService.selectByMatnr(matnr);
        if (mat == null) {
            throw new CoolException("物料信息不存在");
        }
        //转换关系
        String origin = mat.getOrigin();
        if (Cools.isEmpty(origin)) {
            throw new CoolException("主辅数量转换公式不存在");
        }
        String[] split = origin.split("/");
        //辅单位
        BigDecimal anfmeBigDecimal = BigDecimal.valueOf(anfme);
        BigDecimal origin1 = new BigDecimal(split[1]);
        BigDecimal origin0 = new BigDecimal(split[0]);
        BigDecimal divideResult1 = anfmeBigDecimal.divide(origin1, 9, RoundingMode.HALF_UP);
        BigDecimal weightBigDecimal = divideResult1.divide(origin0, 9, RoundingMode.HALF_UP);
        return weightBigDecimal.doubleValue();
    }
    public static Double calcAnfmeFromWeight(String matnr, Double weight) {
        MatService matService = SpringUtils.getBean(MatService.class);
        //更新辅料
        Mat mat = matService.selectByMatnr(matnr);
        if (mat == null) {
            throw new CoolException("物料信息不存在");
        }
        //转换关系
        String origin = mat.getOrigin();
        if (Cools.isEmpty(origin)) {
            throw new CoolException("主辅数量转换公式不存在");
        }
        String[] split = origin.split("/");
        //辅单位
        BigDecimal weightBigDecimal = BigDecimal.valueOf(weight);
        BigDecimal origin1 = new BigDecimal(split[1]);
        BigDecimal origin0 = new BigDecimal(split[0]);
        BigDecimal multiplyResult1 = weightBigDecimal.multiply(origin1);
        BigDecimal anfmeBigDecimal = multiplyResult1.multiply(origin0);
        return anfmeBigDecimal.doubleValue();
    }
}