| | |
| | | */ |
| | | private static final String UNIT_TYPE_TON = "吨"; |
| | | /** |
| | | * 计量单位类型「N千克」:每托盘装 N 个袋码 |
| | | * 计量单位类型「N袋」:每托盘装 N 个袋码 |
| | | */ |
| | | private static final Pattern KG_TYPE_PATTERN = Pattern.compile("^(\\d{1,5})千克$"); |
| | | private static final Pattern BAG_TYPE_PATTERN = Pattern.compile("^(\\d{1,5})袋$"); |
| | | |
| | | @Resource |
| | | private MesCodeRedisDAO codeRedisDao; |
| | |
| | | MesMdmItemDO item = mdmItemService.validateItemExists(generateReqVO.getItemId()); |
| | | String type = getUnitType(item); |
| | | |
| | | // 2. 按类型换算袋码数量:N千克 = 每托 N 袋 × 托盘数;吨 = 直接输入袋码数(无托盘) |
| | | // 2. 按类型换算袋码数量:N袋 = 每托 N 袋 × 托盘数;吨 = 直接输入袋码数(无托盘) |
| | | boolean ton = UNIT_TYPE_TON.equals(type); |
| | | int perPallet = ton ? 0 : parseKgPerPallet(type); |
| | | int perPallet = ton ? 0 : parseBagsPerPallet(type); |
| | | int totalCount; |
| | | int palletCount = 0; |
| | | if (ton) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 读取品种主计量单位的类型(48千克/100千克/吨),未配置或无法识别时报错 |
| | | * 读取品种主计量单位的类型(48袋/100袋/吨),未配置或无法识别时报错 |
| | | */ |
| | | private String getUnitType(MesMdmItemDO item) { |
| | | String type = null; |
| | |
| | | if (type == null) { |
| | | throw exception(PRO_BAG_CODE_ITEM_TYPE_NOT_CONFIGURED); |
| | | } |
| | | if (!UNIT_TYPE_TON.equals(type) && !KG_TYPE_PATTERN.matcher(type).matches()) { |
| | | if (!UNIT_TYPE_TON.equals(type) && !BAG_TYPE_PATTERN.matcher(type).matches()) { |
| | | throw exception(PRO_BAG_CODE_ITEM_TYPE_NOT_CONFIGURED); |
| | | } |
| | | return type; |
| | | } |
| | | |
| | | /** |
| | | * 解析「N千克」类型得出每托盘袋数 |
| | | * 解析「N袋」类型得出每托盘袋数 |
| | | */ |
| | | private int parseKgPerPallet(String type) { |
| | | Matcher matcher = KG_TYPE_PATTERN.matcher(type); |
| | | private int parseBagsPerPallet(String type) { |
| | | Matcher matcher = BAG_TYPE_PATTERN.matcher(type); |
| | | if (!matcher.matches()) { |
| | | throw exception(PRO_BAG_CODE_ITEM_TYPE_NOT_CONFIGURED); |
| | | } |