From 263b034b4058bb7a36c709278abdc88ca1ba26c1 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期一, 30 三月 2026 18:01:25 +0800
Subject: [PATCH] feat: 生产成本导入数据入库
---
src/main/java/com/ruoyi/production/utils/UnitUtils.java | 66 +++++++++++++++++++++++++++++++++
1 files changed, 66 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/ruoyi/production/utils/UnitUtils.java b/src/main/java/com/ruoyi/production/utils/UnitUtils.java
new file mode 100644
index 0000000..6faf806
--- /dev/null
+++ b/src/main/java/com/ruoyi/production/utils/UnitUtils.java
@@ -0,0 +1,66 @@
+package com.ruoyi.production.utils;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * <br>
+ * 鍗曚綅杞崲宸ュ叿绫�
+ * </br>
+ *
+ * @author deslrey
+ * @version 1.0
+ * @since 2026/03/30 15:07
+ */
+public class UnitUtils {
+
+ private static final Set<String> WEIGHT_UNITS = new HashSet<>(Arrays.asList(
+ "鍗冨厠", "鍏枻", "kg", "KG", "kG",
+ "鍏�", "g", "G",
+ "鍚�", "t", "T"
+ ));
+
+ private static final Set<String> KG_UNITS = new HashSet<>(Arrays.asList("鍗冨厠", "鍏枻", "kg", "KG", "kG"));
+ private static final Set<String> G_UNITS = new HashSet<>(Arrays.asList("鍏�", "g", "G"));
+ private static final Set<String> TON_UNITS = new HashSet<>(Arrays.asList("鍚�", "t", "T"));
+
+ /**
+ * 鍒ゆ柇鏄惁涓洪噸閲忓崟浣�
+ */
+ public static boolean isWeightUnit(String unit) {
+ return unit != null && WEIGHT_UNITS.contains(unit.trim());
+ }
+
+ /**
+ * 濡傛灉鏄噸閲忓崟浣嶏紝缁熶竴杩斿洖鈥滃惃鈥濓紝鍚﹀垯杩斿洖鍘熷崟浣�
+ */
+ public static String normalizeUnit(String unit) {
+ if (isWeightUnit(unit)) {
+ return "鍚�";
+ }
+ return unit != null ? unit.trim() : "鏈煡鍗曚綅";
+ }
+
+ /**
+ * 濡傛灉鏄噸閲忓崟浣嶏紝鎶樼畻涓衡�滃惃鈥濓紝鍚﹀垯杩斿洖鍘熷��
+ */
+ public static BigDecimal convertValueToTon(BigDecimal value, String unit) {
+ if (value == null || unit == null) {
+ return value != null ? value : BigDecimal.ZERO;
+ }
+
+ String trimmedUnit = unit.trim();
+ if (KG_UNITS.contains(trimmedUnit)) {
+ return value.divide(new BigDecimal("1000"), 6, RoundingMode.HALF_UP);
+ } else if (G_UNITS.contains(trimmedUnit)) {
+ return value.divide(new BigDecimal("1000000"), 6, RoundingMode.HALF_UP);
+ } else if (TON_UNITS.contains(trimmedUnit)) {
+ return value;
+ }
+
+ return value;
+ }
+}
--
Gitblit v1.9.3