容量单位换算表大全(容量单位换算表大全五年级下册)

最近,许多读者对容量单位的转换表有疑问。有网友整理了相关内容,希望能回答你的疑惑。关于容量单位转换表,五年级第二册,秋红号(www.psychoses.cn)我们也为你找到了问题的答案。让我们花一分钟看看,希望对你有所帮助。

商品单位转换及计量单位转换

采购、销售、库存系统开发时,商品货物流转会遇到商品计量单位和计量单位的转换,如:700吨、7000公斤。制造商的产品一般不太可能既有重量单位又有体积单位,一个电子商务平台,商品来自多个制造商,种类繁多。若平台国际化,甚至国家都会出自己的标准。如何在一个系统中轻松兼容各种计量单位?这也是设计之初必须考虑的事情,会对以后的开发和维护产生重大影响,不容忽视。

实现系统开发单位转换的几种方案:

1、个人维护转换标准,缺点:不利于团队发展,如有修改,维护量大。

2、公共类或公共枚举维护换算标准,统一维护换算标准管理,将多人工作量变成一人。缺点:后期系统国际化,需要添加其他转换标准,需要修改,不够灵活。

3.数据库中规定,该方案可以增加灵活性和可扩展性,甚至不需要修改代码就可以直接在后台添加计量单位和计量单位的转换。单位表用于记录所有可能使用的计量单位。

设计表:

容量单位换算表大全(容量单位换算表大全五年级下册)

计量单位与计量单位之间的转换因子可以随时添加,以满足大多数需求。

Java单位转换功能

商品库存单位需求

容量单位换算表大全(容量单位换算表大全五年级下册)

同一商品一般有四级单位:一级单位、二级单位、三级单位、四级单位,从小到大:一级单位 < 二级单位 < 三级单位 < 四级单位。根据上表,单位转换值:上级转下级,下级=数量*上级单位转换值,单位转换值:下级转上级,从上到下转换。

建立匹配的模型类

package com.what21.app.service.unit;import lombok.Data;import java.math.BigDecimal;@Datapublic class Unit{ // ID private Long id; // 商品的ID private Long goodsId; // 单位名称 private String unitName; // 单位类型:1、一级单位,二、二级单位,三、三级单位 4、四级单位 private Integer unitType; // 同级单位能否有多个基础, 是否基础 0 否 1是 private Integer unitBasics; // 单位转换值 private Integer unitValue; // 单位兑换值 private BigDecimal unitExchangeRate; // 单位规格 private String unitSpecs;}

准备商品的单位

package com.what21.app.service.unit;import java.math.BigDecimal;import java.util.*;public class UnitConvertService{ /** * @param goodsId * @return */ public static List<Unit> getUnitList(Long goodsId){ List<Unit> unitList=new ArrayList<>(); // 一级单位 Unit unit1=new Unit(); unit1.setId(1L); unit1.setGoodsId(goodsId); unit1.setUnitType(1); unit1.setUnitName("克"); unit1.setUnitBasics(1); unit1.setUnitValue(1); unit1.setUnitExchangeRate(new BigDecimal(1)); unit1.setUnitSpecs("1g/克"); unitList.add(unit1); // 二级单位 Unit unit2=new Unit(); unit2.setId(2L); unit2.setGoodsId(goodsId); unit2.setUnitType(2); unit2.setUnitName("包"); unit2.setUnitBasics(1); unit2.setUnitValue(40); unit2.setUnitExchangeRate(new BigDecimal(40)); unit2.setUnitSpecs("40克/包"); unitList.add(unit2); // 三级单位 Unit unit3=new Unit(); unit3.setId(3L); unit3.setGoodsId(goodsId); unit3.setUnitType(3); unit3.setUnitName("盒"); unit3.setUnitBasics(1); unit3.setUnitValue(10); unit3.setUnitExchangeRate(new BigDecimal(400)); unit3.setUnitSpecs("(40g×10包)/盒"); unitList.add(unit3); // 四级单位 Unit unit4=new Unit(); unit4.setId(4L); unit4.setGoodsId(goodsId); unit4.setUnitType(4); unit4.setUnitName("箱"); unit4.setUnitBasics(1); unit4.setUnitValue(20); unit4.setUnitExchangeRate(new BigDecimal(8000)); unit4.setUnitSpecs("(40g×10包)/盒"); unitList.add(unit4); return unitList; }}

向下级/上级单位转换案例

package com.what21.app.service.unit;import java.util.LinkedHashMap;import java.util.List;public class UnitConvertDemo{ public static void main(String[]args){ // 准备商品 Long goodsId=1000L; // 准备商品单位列表 List<Unit> unitList=UnitConvertService.getUnitList(goodsId); // 准备商品单位分组(根据类型) LinkedHashMap<Integer, Unit> unitMap=UnitConvertTools.toUnitMapWithType(goodsId, unitList); System.out.println("unitMap=" unitMap); // 向下级单位转,数量乘以自身属性UnitValue int fourLevelNum=1; Unit unit4=unitMap.get(4); int threeLevelNum=fourLevelNum * unit4.getUnitValue(); Unit unit3=unitMap.get(3); int twoLevelNum=threeLevelNum * unit3.getUnitValue(); Unit unit2=unitMap.get(2); int oneLevelNum=twoLevelNum * unit2.getUnitValue(); Unit unit1=unitMap.get(1); System.out.print(fourLevelNum unit4.getUnitName() "======" threeLevelNum unit3.getUnitName() "======"); System.out.print(twoLevelNum unit2.getUnitName() "======" oneLevelNum unit1.getUnitName()); System.out.println(); // 1箱======20盒======200包======8000克 // 向上级单位转,数量除上级属性UnitValue oneLevelNum=8000; twoLevelNum=oneLevelNum / unit2.getUnitValue(); threeLevelNum=twoLevelNum / unit3.getUnitValue(); fourLevelNum=threeLevelNum / unit4.getUnitValue(); System.out.print(oneLevelNum unit1.getUnitName() "======" twoLevelNum unit2.getUnitName() "======"); System.out.print(threeLevelNum unit3.getUnitName() "======" fourLevelNum unit4.getUnitName()); System.out.println(); // 8000克======200包======20盒======1箱 }}

实现常用工具类

实现功能:1、商品单位按单位类型分组;2、计算各商品单位对应的单位兑换值,按商品单位
类型分组返回;3、上级单位类型及上级单位数量转换为最基本的单位的数量;4、上级单位类型及上级单位数量转换为指定的单位的数量;5、商品单位最小单位数量估算/折算成大单位(上级单位),按商品单位类型分组返回Map;6、商品单位最小单位数量估算/折算成大单位(上级单位),返回显示文本。

package com.what21.app.service.unit;import java.math.BigDecimal;import java.util.LinkedHashMap;import java.util.List;import java.util.Map;public final class UnitConvertTools { /** * 按类型分组返回保证顺序的Map(根据单位类型) * * @param goodsId * @param unitList * @return */ public static LinkedHashMap<Integer, Unit> toUnitMapWithType(Long goodsId, List<Unit> unitList) { LinkedHashMap<Integer, Unit> unitMap=new LinkedHashMap<>(); for (Unit unit : unitList) { if (goodsId==unit.getGoodsId()) { unitMap.put(unit.getUnitType(), unit); } } return unitMap; } /** * 计算每个单位类型对应的的兑换率(根据单位类型) * * @param unitGroupMap * @return */ public static LinkedHashMap<Integer, BigDecimal> toExchangeRateMapWithType(LinkedHashMap<Integer, Unit> unitGroupMap) { LinkedHashMap<Integer, BigDecimal> exchangeRateMap=new LinkedHashMap<>(); for (int unitType=unitGroupMap.size(); unitType >=1; unitType--) { BigDecimal exchangeRate=new BigDecimal(1); for (int toUnitType=unitType - 1; toUnitType >=1; toUnitType--) { Unit toUnit=unitGroupMap.get(toUnitType + 1); exchangeRate=exchangeRate.multiply(new BigDecimal(toUnit.getUnitValue())); } exchangeRateMap.put(unitType, exchangeRate); } return exchangeRateMap; } /** * 根据上级单位类型及单位数量转换为最基本的单位 * * @param goodsId * @param unitList * @param fromType * @param quantity * @return */ public static Integer toUnitStandardQuantity(Long goodsId, List<Unit> unitList, int fromType, int quantity) { int standardQuantity=0; LinkedHashMap<Integer, Unit> unitGroupMap=toUnitMapWithType(goodsId, unitList); for (int unitType=unitGroupMap.size(); unitType >=1; unitType--) { if (unitType==fromType) { if (fromType==1) { standardQuantity=quantity; } else { Unit unit=unitGroupMap.get(unitType); for (int toUnitType=unitType - 1; toUnitType >=1; toUnitType--) { if (standardQuantity==0) { standardQuantity=unit.getUnitValue() * quantity; } else { standardQuantity=standardQuantity * unit.getUnitValue() * quantity; } } } break; } } return standardQuantity; } /** * 根据上级单位类型及单位数量转换为最指定的单位 * * @param goodsId * @param unitList * @param fromType * @param quantity * @param toType * @return */ public static Integer toUnitStandardQuantity(Long goodsId, List<Unit> unitList, int fromType, int quantity, int toType) { int standardQuantity=0; LinkedHashMap<Integer, Unit> unitGroupMap=toUnitMapWithType(goodsId, unitList); for (int unitType=unitGroupMap.size(); unitType >=1; unitType--) { if (unitType==fromType) { if (fromType==1) { standardQuantity=quantity; } else { for (int toUnitType=unitType; toUnitType >=1; toUnitType--) { Unit unit=unitGroupMap.get(toUnitType); if (unit.getUnitType()==toType) { break; } if (standardQuantity==0) { standardQuantity=unit.getUnitValue() * quantity; } else { standardQuantity=standardQuantity * unit.getUnitValue() * quantity; } } } break; } } return standardQuantity; } /** * 最小单位【估算/折算】大单位,按类型分组返回Map * * @param goodsId * @param unitList * @param quantity * @return */ public static LinkedHashMap<Integer, Integer> toUnitEquivalentQuantityWithType(Long goodsId, List<Unit> unitList, int quantity) { LinkedHashMap<Integer, Integer> unitEquivalentQuantity=new LinkedHashMap<>(); LinkedHashMap<Integer, Unit> unitGroupMap=toUnitMapWithType(goodsId, unitList); Map<Integer, BigDecimal> exchangeRateMap=UnitConvertTools.toExchangeRateMapWithType(unitGroupMap); for (int unitType=unitGroupMap.size(); unitType >=1; unitType--) { unitEquivalentQuantity.put(unitType, 0); BigDecimal exchangeRate=exchangeRateMap.get(unitType); if ((quantity % exchangeRate.intValue())==0) { int number=(quantity / exchangeRate.intValue()); if (number > 0) { unitEquivalentQuantity.put(unitType, number); } break; } else { int number=(quantity / exchangeRate.intValue()); if (number > 0) { unitEquivalentQuantity.put(unitType, number); } quantity=quantity % exchangeRate.intValue(); } } return unitEquivalentQuantity; } /** * 最小单位【估算/折算】大单位,返回文本 * * @param goodsId====>商品的ID * @param unitList====>商品的单位列表 * @param quantity====>最小单位的数量 * @return */ public static String toUnitEquivalentQuantityText(Long goodsId, List<Unit> unitList, int quantity) { LinkedHashMap<Integer, Unit> unitGroupMap=toUnitMapWithType(goodsId, unitList); Map<Integer, BigDecimal> exchangeRateMap=UnitConvertTools.toExchangeRateMapWithType(unitGroupMap); StringBuilder stringBuilder=new StringBuilder(); for (int unitType=unitGroupMap.size(); unitType >=1; unitType--) { Unit computeUnit=unitGroupMap.get(unitType); BigDecimal exchangeRate=exchangeRateMap.get(unitType); if ((quantity % exchangeRate.intValue())==0) { int number=(quantity / exchangeRate.intValue()); if (number > 0) { stringBuilder.append((quantity / exchangeRate.intValue())).append(computeUnit.getUnitName()); } break; } else { int number=(quantity / exchangeRate.intValue()); if (number > 0) { stringBuilder.append(number).append(computeUnit.getUnitName()); } quantity=quantity % exchangeRate.intValue(); } } return stringBuilder.toString(); }}

常用的工具类实现测试

package com.what21.app.service.unit;import java.math.BigDecimal;import java.util.LinkedHashMap;import java.util.List;import java.util.Map;public class UnitConvertToolsTest { /** * @param args */ public static void main(String[] args) { // 准备商品 Long goodsId=1000L; // 准备商品单位列表 List<Unit> unitList=UnitConvertService.getUnitList(goodsId); //=======================================================================================// // >>>>>>>>>>>> 按类型分组返回保证顺序的Map(根据单位类型) LinkedHashMap<Integer, Unit> unitGroupMap=UnitConvertTools.toUnitMapWithType(goodsId, unitList); System.out.println("按类型分组返回保证顺序的Map(根据单位类型)=" + unitGroupMap); //=======================================================================================// // >>>>>>>>>>>> 计算每个单位类型对应的的兑换率(根据单位类型) Map<Integer, BigDecimal> exchangeRateMap=UnitConvertTools.toExchangeRateMapWithType(unitGroupMap); System.out.println("计算每个单位类型对应的的兑换率(根据单位类型)=" + exchangeRateMap); // {4=8000, 3=400, 2=40, 1=1} //=======================================================================================// // >>>>>>>>>>>> 根据上级单位类型及单位数量转换为最基本的单位 int fourLevelQuantity=1; int fourLevelTotal=UnitConvertTools.toUnitStandardQuantity(goodsId, unitList, 4, fourLevelQuantity); System.out.println("四级单位转一级单位,1" + unitGroupMap.get(4).getUnitName() + "=" + fourLevelTotal + unitGroupMap.get(1).getUnitName()); // 四级单位转一级单位,1箱=8000克 int threeLevelQuantity=1; int threeLevelTotal=UnitConvertTools.toUnitStandardQuantity(goodsId, unitList, 3, threeLevelQuantity); System.out.println("三级单位转一级单位,1" + unitGroupMap.get(3).getUnitName() + "=" + threeLevelTotal + unitGroupMap.get(1).getUnitName()); // 三级单位转一级单位,1盒=100克 int twoLevelQuantity=1; int twoLevelTotal=UnitConvertTools.toUnitStandardQuantity(goodsId, unitList, 2, twoLevelQuantity); System.out.println("二级单位转一级单位,1" + unitGroupMap.get(2).getUnitName() + "=" + twoLevelTotal + unitGroupMap.get(1).getUnitName()); // 二级单位转一级单位,1包=40克 int oneLevelQuantity=1; int oneLevelTotal=UnitConvertTools.toUnitStandardQuantity(goodsId, unitList, 1, oneLevelQuantity); System.out.println("一级单位转一级单位,1" + unitGroupMap.get(1).getUnitName() + "=" + oneLevelTotal + unitGroupMap.get(1).getUnitName()); // 一级单位转一级单位,1克=1克 //=======================================================================================// // >>>>>>>>>>>> 根据上级单位类型及单位数量转换为最指定的单位 int fourLevelQuantity21=1; int fourLevelTotal21=UnitConvertTools.toUnitStandardQuantity(goodsId, unitList, 4, fourLevelQuantity21, 2); System.out.println("四级单位转二级单位,1" + unitGroupMap.get(4).getUnitName() + "=" + fourLevelTotal21 + unitGroupMap.get(2).getUnitName()); // 四级单位转二级单位,1箱=200包 int fourLevelQuantity22=1; int fourLevelTotal22=UnitConvertTools.toUnitStandardQuantity(goodsId, unitList, 4, fourLevelQuantity22, 3); System.out.println("四级单位转三级单位,1" + unitGroupMap.get(4).getUnitName() + "=" + fourLevelTotal22 + unitGroupMap.get(3).getUnitName()); // 四级单位转三级单位,1箱=20盒 int threeLevelQuantity21=1; int threeLevelTotal21=UnitConvertTools.toUnitStandardQuantity(goodsId, unitList, 3, threeLevelQuantity21, 2); System.out.println("三级单位转二级单位,1" + unitGroupMap.get(3).getUnitName() + "=" + threeLevelTotal21 + unitGroupMap.get(2).getUnitName()); // 三级单位转二级单位,1盒=10包 //=======================================================================================// // >>>>>>>>>>>> 最小单位【估算/折算】大单位,按类型分组返回Map int quantity=8441; LinkedHashMap<Integer, Integer> unitEquivalentQuantityMap=UnitConvertTools.toUnitEquivalentQuantityWithType(goodsId, unitList, quantity); System.out.println("最小单位【估算/折算】大单位,按类型分组返回Map=" + unitEquivalentQuantityMap); // {4=1, 3=1, 2=1, 1=1} //=======================================================================================// // >>>>>>>>>>>> 最小单位【估算/折算】大单位,返回文本 int quantity2=8441; String unitEquivalentQuantity=UnitConvertTools.toUnitEquivalentQuantityText(goodsId, unitList, quantity2); System.out.println("计算单位向上折算返回文本=" + unitEquivalentQuantity); // 1箱1盒1包1克 }}

输出内容:

按类型分组返回保证顺序的Map(根据单位类型)={1=Unit(id=1, goodsId=1000, unitName=克, unitType=1, unitBasics=1, unitValue=1, unitExchangeRate=1, unitSpecs=1g/克), 2=Unit(id=2, goodsId=1000, unitName=包, unitType=2, unitBasics=1, unitValue=40, unitExchangeRate=40, unitSpecs=40克/包), 3=Unit(id=3, goodsId=1000, unitName=盒, unitType=3, unitBasics=1, unitValue=10, unitExchangeRate=400, unitSpecs=(40g×10包)/盒), 4=Unit(id=4, goodsId=1000, unitName=箱, unitType=4, unitBasics=1, unitValue=20, unitExchangeRate=8000, unitSpecs=(40g×10包)/盒)}计算每个单位类型对应的的兑换率(根据单位类型)={4=8000, 3=400, 2=40, 1=1}四级单位转一级单位,1箱=8000克三级单位转一级单位,1盒=100克二级单位转一级单位,1包=40克一级单位转一级单位,1克=1克四级单位转二级单位,1箱=200包四级单位转三级单位,1箱=20盒三级单位转二级单位,1盒=10包最小单位【估算/折算】大单位,按类型分组返回Map={4=1, 3=1, 2=1, 1=1}计算单位向上折算返回文本=1箱1盒1包1克

本文部分内容来自互联网,如有疑问请与我们联系。:https://www.psychoses.cn/uncategorized/41446.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022年10月17日 上午2:17
下一篇 2022年10月17日 上午3:07

相关推荐

  • 什么牌子的冰箱质量最好(现在什么牌子的冰箱质量最好)

    最近有很多读者朋友对什么牌子的冰箱质量最好有疑问。有网友整理了相关内容,希望能回答你的疑惑。什么牌子的冰箱质量最好,秋红号?(www.psychoses.cn)我们也为你找到了问题的答案。让我们花一分钟看看,希望对你有所帮助。 冰箱是我们家庭生活中非常重要的家用电器。合适的冰箱可以大大提高我们的家庭幸福感。哪个牌子的冰箱更好?以下是6个购买要点,让您轻松购买…

    未分类 2022年10月19日
    17900
  • 茅台醇浆怎么样(茅台醇浆怎么样好销吗)

    最近有很多读者朋友对茅台醇浆怎么样有疑问。有网友整理了相关内容,希望能回答你的疑惑。茅台酒怎么卖?(www.psychoses.cn)我们也为你找到了问题的答案。让我们花一分钟看看,希望对你有所帮助。 他来了 他提前来到618活动。 不用等优惠活动 大朋友 小朋友 你准备好了吗? 没错!首次直播优选苏谷 优惠力度极大,心动不动? 6月4日晚7点直播 期待您的…

    未分类 2022年10月30日
    10900
  • 左耳发热是什么预兆男(左耳发热是什么预兆男二十四时辰)

    最近有很多读者朋友对左耳发热的预兆男有疑问。有网友整理了相关内容,希望能回答你的疑惑。什么是左耳发热的预兆?24小时,秋红号(www.psychoses.cn)我们也为你找到了问题的答案。让我们花一分钟看看,希望对你有所帮助。 儿童耳痛比较常见,一般是感冒后引起的。但有些孩子不仅耳痛,而且伴有反复发烧,此时父母应该注意,孩子的病情可能相对严重,不仅有急性中耳…

    未分类 2022年10月25日
    18600
  • 聂荣瑧简介(聂荣瑧简介两弹一星)

    最近,许多读者对聂荣宇的简介有疑问。有网友整理了相关内容,希望能回答你的疑惑。聂荣宇介绍两弹一星,秋红号。(www.psychoses.cn)我们也为你找到了问题的答案。让我们花一分钟看看,希望对你有所帮助。 ?文/王树人 2019年12月29日是聂荣珍元帅诞辰120周年。聂荣震元帅是中国人民解放军的创始人之一,是经过长期考验的无产阶级革命家、军事家、党和国…

    未分类 2022年10月28日
    95800
  • 乌衣巷位于什么地方(乌衣巷是刘禹锡的诗作乌衣巷位于什么地方)

    最近,许多读者对乌衣巷的位置有疑问。有网友整理了相关内容,希望能回答你的疑惑。关于乌衣巷是刘禹锡的诗。乌衣巷在哪里?(www.psychoses.cn)我们也为你找到了问题的答案。让我们花一分钟看看,希望对你有所帮助。 你一定听过唐代大诗人刘禹锡的《金陵怀古乌衣巷》。你一定很熟悉乌衣巷口夕阳斜这句话。著名的乌衣巷位于江苏省南京市夫子庙景区文德桥南岸。这是一条…

    未分类 2022年10月26日
    19200

联系我们

86775565

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信