| | |
| | | import java.util.Objects; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| | | import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; |
| | | import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.qc.oqc.vo.MesQcOqcImportExcelVO; |
| | | import cn.iocoder.yudao.module.mes.controller.admin.qc.oqc.vo.MesQcOqcImportRespVO; |
| | |
| | | .setTemplateId(templateId) |
| | | .setSourceDocCode(sourceDocCode) |
| | | .setStatus(MesQcStatusEnum.DRAFT.getStatus()); |
| | | // 检测人员、检测日期、出货日期未填写时使用默认值,不影响流程 |
| | | if (oqc.getInspectorUserId() == null) { |
| | | oqc.setInspectorUserId(getLoginUserId()); |
| | | } |
| | | if (oqc.getInspectDate() == null) { |
| | | oqc.setInspectDate(LocalDateTime.now()); |
| | | } |
| | | if (oqc.getOutDate() == null) { |
| | | oqc.setOutDate(LocalDateTime.now()); |
| | | } |
| | | oqcMapper.insert(oqc); |
| | | |
| | | // 3. 从模板指标自动生成检验行 |
| | |
| | | // 校验物料、检测人员存在 |
| | | // 注:物料 ID 来自 MDM,客户 ID 来自 CRM |
| | | mdmItemApi.validateItemExists(reqVO.getItemId()); |
| | | adminUserApi.validateUser(reqVO.getInspectorUserId()); |
| | | // 校验检测人员存在(非必填,未填写时由创建逻辑默认当前登录人) |
| | | if (reqVO.getInspectorUserId() != null) { |
| | | adminUserApi.validateUser(reqVO.getInspectorUserId()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | return; |
| | | } |
| | | if (oqc.getSourceLineId() == null) { |
| | | throw new IllegalArgumentException( |
| | | "OQC 单[" + oqc.getId() + "] sourceDocType 非空但 sourceLineId 为空"); |
| | | throw exception(QC_OQC_SOURCE_LINE_REQUIRED); |
| | | } |
| | | |
| | | if (Objects.equals(oqc.getSourceDocType(), MesBizTypeConstants.WM_PRODUCT_SALES)) { |
| | | productSalesLineService.updateProductSalesLineWhenOqcFinish( |
| | | oqc.getSourceLineId(), oqc.getId(), oqc.getCheckResult()); |
| | | } else { |
| | | throw new IllegalArgumentException( |
| | | "OQC 单[" + oqc.getId() + "] sourceDocType=" + oqc.getSourceDocType() + " 无法识别,无法回写来源单据"); |
| | | throw exception(QC_OQC_SOURCE_DOC_TYPE_UNKNOWN, oqc.getSourceDocType()); |
| | | } |
| | | } |
| | | |
| | |
| | | return null; |
| | | } |
| | | // 未知来源类型应报错,而不是静默忽略 |
| | | throw exception(QC_OQC_SOURCE_DOC_TYPE_UNKNOWN); |
| | | throw exception(QC_OQC_SOURCE_DOC_TYPE_UNKNOWN, sourceDocType); |
| | | } |
| | | |
| | | @Override |
| | |
| | | try { |
| | | templateItem = templateItemService.getRequiredTemplateByItemIdAndType( |
| | | line.getItemId(), MesQcTypeEnum.OQC.getType()); |
| | | } catch (Exception e) { |
| | | } catch (cn.iocoder.yudao.framework.common.exception.ServiceException e) { |
| | | if (!java.util.Objects.equals(e.getCode(), QC_NO_TEMPLATE.getCode())) throw e; |
| | | // 获取物料信息,提供更明确的错误提示 |
| | | String itemInfo = getItemInfo(line.getItemId()); |
| | | throw exception(QC_NO_TEMPLATE_FOR_ITEM, itemInfo); |
| | | throw exception(QC_OQC_NO_TEMPLATE_FOR_ITEM, itemInfo); |
| | | } |
| | | Long templateId = templateItem.getTemplateId(); |
| | | |
| | | // 2. 生成检验单编码 |
| | | String code = "OQC" + System.currentTimeMillis(); |
| | | String code = "OQC" + java.util.UUID.randomUUID().toString().replace("-", ""); |
| | | |
| | | // 3. 创建 OQC 主表(待检验状态,初始数量为 0) |
| | | MesQcOqcDO oqc = new MesQcOqcDO(); |