| | |
| | | // 2. 根据配置校验必填参数并清空不需要的参数 |
| | | MesWmBatchDO batch = MesWmBatchDO.builder().itemId(reqVO.getItemId()).build(); |
| | | if (config != null) { |
| | | // ========== 必填校验(flag=true 表示该字段为必填) ========== |
| | | // 生产日期 |
| | | if (Boolean.TRUE.equals(config.getProduceDateFlag())) { |
| | | if (ObjUtil.isNull(reqVO.getProduceDate())) { |
| | | throw exception(WM_BATCH_PRODUCE_DATE_REQUIRED); |
| | | } |
| | | batch.setProduceDate(reqVO.getProduceDate()); |
| | | if (Boolean.TRUE.equals(config.getProduceDateFlag()) && ObjUtil.isNull(reqVO.getProduceDate())) { |
| | | throw exception(WM_BATCH_PRODUCE_DATE_REQUIRED); |
| | | } |
| | | // 入库日期 |
| | | if (Boolean.TRUE.equals(config.getReceiptDateFlag())) { |
| | | if (ObjUtil.isNull(reqVO.getReceiptDate())) { |
| | | throw exception(WM_BATCH_RECEIPT_DATE_REQUIRED); |
| | | } |
| | | batch.setReceiptDate(reqVO.getReceiptDate()); |
| | | if (Boolean.TRUE.equals(config.getReceiptDateFlag()) && ObjUtil.isNull(reqVO.getReceiptDate())) { |
| | | throw exception(WM_BATCH_RECEIPT_DATE_REQUIRED); |
| | | } |
| | | // 有效期 |
| | | if (Boolean.TRUE.equals(config.getExpireDateFlag())) { |
| | | if (ObjUtil.isNull(reqVO.getExpireDate())) { |
| | | throw exception(WM_BATCH_EXPIRE_DATE_REQUIRED); |
| | | } |
| | | batch.setExpireDate(reqVO.getExpireDate()); |
| | | if (Boolean.TRUE.equals(config.getExpireDateFlag()) && ObjUtil.isNull(reqVO.getExpireDate())) { |
| | | throw exception(WM_BATCH_EXPIRE_DATE_REQUIRED); |
| | | } |
| | | // 供应商 |
| | | if (Boolean.TRUE.equals(config.getVendorFlag())) { |
| | | if (ObjUtil.isNull(reqVO.getVendorId())) { |
| | | throw exception(WM_BATCH_VENDOR_REQUIRED); |
| | | } |
| | | batch.setVendorId(reqVO.getVendorId()); |
| | | if (Boolean.TRUE.equals(config.getVendorFlag()) && ObjUtil.isNull(reqVO.getVendorId())) { |
| | | throw exception(WM_BATCH_VENDOR_REQUIRED); |
| | | } |
| | | // 客户 |
| | | if (Boolean.TRUE.equals(config.getClientFlag())) { |
| | | if (ObjUtil.isNull(reqVO.getClientId())) { |
| | | throw exception(WM_BATCH_CLIENT_REQUIRED); |
| | | } |
| | | batch.setClientId(reqVO.getClientId()); |
| | | if (Boolean.TRUE.equals(config.getClientFlag()) && ObjUtil.isNull(reqVO.getClientId())) { |
| | | throw exception(WM_BATCH_CLIENT_REQUIRED); |
| | | } |
| | | // 采购订单编号 |
| | | if (Boolean.TRUE.equals(config.getPurchaseOrderCodeFlag())) { |
| | | if (ObjUtil.isNull(reqVO.getPurchaseOrderCode())) { |
| | | throw exception(WM_BATCH_PURCHASE_ORDER_CODE_REQUIRED); |
| | | } |
| | | batch.setPurchaseOrderCode(reqVO.getPurchaseOrderCode()); |
| | | if (Boolean.TRUE.equals(config.getPurchaseOrderCodeFlag()) && ObjUtil.isNull(reqVO.getPurchaseOrderCode())) { |
| | | throw exception(WM_BATCH_PURCHASE_ORDER_CODE_REQUIRED); |
| | | } |
| | | // 销售订单编号 |
| | | if (Boolean.TRUE.equals(config.getSalesOrderCodeFlag())) { |
| | | if (ObjUtil.isNull(reqVO.getSalesOrderCode())) { |
| | | throw exception(WM_BATCH_CUSTOMER_ORDER_CODE_REQUIRED); |
| | | } |
| | | batch.setSalesOrderCode(reqVO.getSalesOrderCode()); |
| | | if (Boolean.TRUE.equals(config.getSalesOrderCodeFlag()) && ObjUtil.isNull(reqVO.getSalesOrderCode())) { |
| | | throw exception(WM_BATCH_CUSTOMER_ORDER_CODE_REQUIRED); |
| | | } |
| | | // 生产工单 |
| | | if (Boolean.TRUE.equals(config.getWorkOrderFlag())) { |
| | | if (ObjUtil.isNull(reqVO.getWorkOrderId())) { |
| | | throw exception(WM_BATCH_WORK_ORDER_REQUIRED); |
| | | } |
| | | batch.setWorkOrderId(reqVO.getWorkOrderId()); |
| | | if (Boolean.TRUE.equals(config.getWorkOrderFlag()) && ObjUtil.isNull(reqVO.getWorkOrderId())) { |
| | | throw exception(WM_BATCH_WORK_ORDER_REQUIRED); |
| | | } |
| | | // 生产任务 |
| | | if (Boolean.TRUE.equals(config.getTaskFlag())) { |
| | | if (ObjUtil.isNull(reqVO.getTaskId())) { |
| | | throw exception(WM_BATCH_TASK_REQUIRED); |
| | | } |
| | | batch.setTaskId(reqVO.getTaskId()); |
| | | if (Boolean.TRUE.equals(config.getTaskFlag()) && ObjUtil.isNull(reqVO.getTaskId())) { |
| | | throw exception(WM_BATCH_TASK_REQUIRED); |
| | | } |
| | | // 工作站 |
| | | if (Boolean.TRUE.equals(config.getWorkstationFlag())) { |
| | | if (ObjUtil.isNull(reqVO.getWorkstationId())) { |
| | | throw exception(WM_BATCH_WORKSTATION_REQUIRED); |
| | | } |
| | | batch.setWorkstationId(reqVO.getWorkstationId()); |
| | | if (Boolean.TRUE.equals(config.getWorkstationFlag()) && ObjUtil.isNull(reqVO.getWorkstationId())) { |
| | | throw exception(WM_BATCH_WORKSTATION_REQUIRED); |
| | | } |
| | | // 工具 |
| | | if (Boolean.TRUE.equals(config.getToolFlag())) { |
| | | if (ObjUtil.isNull(reqVO.getToolId())) { |
| | | throw exception(WM_BATCH_TOOL_REQUIRED); |
| | | } |
| | | batch.setToolId(reqVO.getToolId()); |
| | | if (Boolean.TRUE.equals(config.getToolFlag()) && ObjUtil.isNull(reqVO.getToolId())) { |
| | | throw exception(WM_BATCH_TOOL_REQUIRED); |
| | | } |
| | | // 模具 |
| | | if (Boolean.TRUE.equals(config.getMoldFlag())) { |
| | | if (ObjUtil.isNull(reqVO.getMoldId())) { |
| | | throw exception(WM_BATCH_MOLD_REQUIRED); |
| | | } |
| | | batch.setMoldId(reqVO.getMoldId()); |
| | | if (Boolean.TRUE.equals(config.getMoldFlag()) && ObjUtil.isNull(reqVO.getMoldId())) { |
| | | throw exception(WM_BATCH_MOLD_REQUIRED); |
| | | } |
| | | // 生产批号 |
| | | if (Boolean.TRUE.equals(config.getLotNumberFlag())) { |
| | | if (ObjUtil.isNull(reqVO.getLotNumber())) { |
| | | throw exception(WM_BATCH_LOT_NUMBER_REQUIRED); |
| | | } |
| | | batch.setLotNumber(reqVO.getLotNumber()); |
| | | if (Boolean.TRUE.equals(config.getLotNumberFlag()) && ObjUtil.isNull(reqVO.getLotNumber())) { |
| | | throw exception(WM_BATCH_LOT_NUMBER_REQUIRED); |
| | | } |
| | | // 质量状态 |
| | | if (Boolean.TRUE.equals(config.getQualityStatusFlag())) { |
| | | if (ObjUtil.isNull(reqVO.getQualityStatus())) { |
| | | throw exception(WM_BATCH_QUALITY_STATUS_REQUIRED); |
| | | } |
| | | batch.setQualityStatus(reqVO.getQualityStatus()); |
| | | if (Boolean.TRUE.equals(config.getQualityStatusFlag()) && ObjUtil.isNull(reqVO.getQualityStatus())) { |
| | | throw exception(WM_BATCH_QUALITY_STATUS_REQUIRED); |
| | | } |
| | | } |
| | | // 无批次配置时,使用传入的参数(宽松模式,适用于自定义入库等场景) |
| | | else { |
| | | if (reqVO.getProduceDate() != null) { |
| | | batch.setProduceDate(reqVO.getProduceDate()); |
| | | } |
| | | if (reqVO.getReceiptDate() != null) { |
| | | batch.setReceiptDate(reqVO.getReceiptDate()); |
| | | } |
| | | if (reqVO.getExpireDate() != null) { |
| | | batch.setExpireDate(reqVO.getExpireDate()); |
| | | } |
| | | if (reqVO.getVendorId() != null) { |
| | | batch.setVendorId(reqVO.getVendorId()); |
| | | } |
| | | if (reqVO.getClientId() != null) { |
| | | batch.setClientId(reqVO.getClientId()); |
| | | } |
| | | |
| | | // ========== 保存字段(无论有无配置,只要调用方传了就保存) ========== |
| | | if (reqVO.getProduceDate() != null) { |
| | | batch.setProduceDate(reqVO.getProduceDate()); |
| | | } |
| | | if (reqVO.getReceiptDate() != null) { |
| | | batch.setReceiptDate(reqVO.getReceiptDate()); |
| | | } |
| | | if (reqVO.getExpireDate() != null) { |
| | | batch.setExpireDate(reqVO.getExpireDate()); |
| | | } |
| | | if (reqVO.getVendorId() != null) { |
| | | batch.setVendorId(reqVO.getVendorId()); |
| | | } |
| | | if (reqVO.getClientId() != null) { |
| | | batch.setClientId(reqVO.getClientId()); |
| | | } |
| | | if (reqVO.getPurchaseOrderCode() != null) { |
| | | batch.setPurchaseOrderCode(reqVO.getPurchaseOrderCode()); |
| | | } |
| | | if (reqVO.getSalesOrderCode() != null) { |
| | | batch.setSalesOrderCode(reqVO.getSalesOrderCode()); |
| | | } |
| | | if (reqVO.getWorkOrderId() != null) { |
| | | batch.setWorkOrderId(reqVO.getWorkOrderId()); |
| | | } |
| | | if (reqVO.getTaskId() != null) { |
| | | batch.setTaskId(reqVO.getTaskId()); |
| | | } |
| | | if (reqVO.getWorkstationId() != null) { |
| | | batch.setWorkstationId(reqVO.getWorkstationId()); |
| | | } |
| | | if (reqVO.getToolId() != null) { |
| | | batch.setToolId(reqVO.getToolId()); |
| | | } |
| | | if (reqVO.getMoldId() != null) { |
| | | batch.setMoldId(reqVO.getMoldId()); |
| | | } |
| | | if (reqVO.getLotNumber() != null) { |
| | | batch.setLotNumber(reqVO.getLotNumber()); |
| | | } |
| | | if (reqVO.getQualityStatus() != null) { |
| | | batch.setQualityStatus(reqVO.getQualityStatus()); |
| | | } |
| | | |
| | | // 3.1 情况一:传入了 batchCode,查询是否存在该批次号 |