34 lines
1.4 KiB
Java
34 lines
1.4 KiB
Java
|
|
package org.example;
|
|||
|
|
|
|||
|
|
import org.json.JSONObject;
|
|||
|
|
import java.math.BigDecimal;
|
|||
|
|
|
|||
|
|
public class ScanDataUtil {
|
|||
|
|
/**
|
|||
|
|
* 解析扫码内容并构造请求体
|
|||
|
|
* @param scanStr 扫码内容,格式:入库单id_仓库id_物料id_数量
|
|||
|
|
* @param itemType 物品类型
|
|||
|
|
* @param itemId 物品ID
|
|||
|
|
* @param unit 单位
|
|||
|
|
* @param remark 备注(可选)
|
|||
|
|
* @param fromWarehouseId 源库位ID(可选)
|
|||
|
|
* @param recordType 记录类型(0/1)
|
|||
|
|
* @return JSON字符串
|
|||
|
|
*/
|
|||
|
|
public static String buildRequestJson(String scanStr, String itemType, String remark, Long fromWarehouseId, Integer recordType) {
|
|||
|
|
String[] parts = scanStr.split("_");
|
|||
|
|
if (parts.length != 4) throw new IllegalArgumentException("扫码内容格式不正确,应为:入库单id_仓库id_物料id_数量");
|
|||
|
|
JSONObject obj = new JSONObject();
|
|||
|
|
obj.put("stockIoId", Long.valueOf(parts[0]));
|
|||
|
|
obj.put("warehouseId", Long.valueOf(parts[1]));
|
|||
|
|
obj.put("itemId", Long.valueOf(parts[2]));
|
|||
|
|
obj.put("quantity", new BigDecimal(parts[3]));
|
|||
|
|
obj.put("itemType", itemType);
|
|||
|
|
obj.put("unit", 'g'); // 单位为null
|
|||
|
|
obj.put("batchNo", 100); // 批次号为null
|
|||
|
|
obj.put("remark", remark);
|
|||
|
|
obj.put("fromWarehouseId", fromWarehouseId);
|
|||
|
|
obj.put("recordType", recordType);
|
|||
|
|
return obj.toString();
|
|||
|
|
}
|
|||
|
|
}
|