| | |
| | | import com.ruoyi.framework.web.domain.R; |
| | | import com.ruoyi.procurementrecord.service.ProcurementRecordService; |
| | | import com.ruoyi.procurementrecord.utils.StockUtils; |
| | | import com.ruoyi.quality.dto.AutoJudgeAllResponse; |
| | | import com.ruoyi.quality.dto.AutoJudgeRequest; |
| | | import com.ruoyi.quality.dto.AutoJudgeResponse; |
| | | import com.ruoyi.quality.dto.BatchQuickInspectRequest; |
| | | import com.ruoyi.quality.dto.QualityInspectDto; |
| | | import com.ruoyi.quality.mapper.QualityInspectMapper; |
| | |
| | | import com.ruoyi.quality.pojo.QualityInspectParam; |
| | | import com.ruoyi.quality.pojo.QualityUnqualified; |
| | | import com.ruoyi.quality.utils.QualityInspectTemplateExportHelper; |
| | | import com.ruoyi.quality.utils.QualityJudgeUtil; |
| | | import com.ruoyi.stock.pojo.StockInRecord; |
| | | import com.ruoyi.stock.service.StockInRecordService; |
| | | import com.ruoyi.quality.service.IQualityInspectParamService; |
| | |
| | | qualityInspect.setUnqualifiedQuantity(BigDecimal.ZERO); |
| | | } |
| | | |
| | | // 合格直接入库 |
| | | if(qualityInspect.getQualifiedQuantity().compareTo(BigDecimal.ZERO) > 0){ |
| | | // 合格入库处理(根据检验类型区分) |
| | | // 过程检验(inspectType=1):入库到成品库 |
| | | // 出厂检验(inspectType=2):不做任何业务处理 |
| | | // 原材料检验(inspectType=0):正常质检入库 |
| | | Integer inspectType = qualityInspect.getInspectType(); |
| | | boolean shouldStockIn = inspectType == null || inspectType == 0 || inspectType == 1; |
| | | |
| | | if (shouldStockIn && qualityInspect.getQualifiedQuantity().compareTo(BigDecimal.ZERO) > 0) { |
| | | //仅添加入库记录 |
| | | StockInventoryDto stockInventoryDto = new StockInventoryDto(); |
| | | //如果是采购质检合格入库选用CUSTOMIZATION_UNSTOCK_OUT,其余合格入库选用QUALITYINSPECT_STOCK_IN |
| | | stockInventoryDto.setRecordType(String.valueOf(StockInQualifiedRecordTypeEnum.QUALITYINSPECT_STOCK_IN.getCode())); |
| | | if (ObjectUtils.isNotEmpty(qualityInspect.getPurchaseLedgerId())){ |
| | | //过程检验使用生产报工入库类型,其他质检使用质检入库类型 |
| | | if (inspectType != null && inspectType == 1) { |
| | | stockInventoryDto.setRecordType(String.valueOf(StockInQualifiedRecordTypeEnum.PRODUCTION_REPORT_STOCK_IN.getCode())); |
| | | } else if (ObjectUtils.isNotEmpty(qualityInspect.getPurchaseLedgerId())) { |
| | | //采购质检合格入库 |
| | | stockInventoryDto.setRecordType(String.valueOf(StockInQualifiedRecordTypeEnum.CUSTOMIZATION_UNSTOCK_OUT.getCode())); |
| | | } else { |
| | | stockInventoryDto.setRecordType(String.valueOf(StockInQualifiedRecordTypeEnum.QUALITYINSPECT_STOCK_IN.getCode())); |
| | | } |
| | | stockInventoryDto.setRecordId(qualityInspect.getId()); |
| | | stockInventoryDto.setProductModelId(qualityInspect.getProductModelId()); |
| | |
| | | // 4. 更新检验单 |
| | | qualityInspectMapper.updateById(qualityInspect); |
| | | |
| | | // 5. 合格入库处理 |
| | | if (qualified.compareTo(BigDecimal.ZERO) > 0) { |
| | | // 5. 合格入库处理(根据检验类型区分) |
| | | // 过程检验(inspectType=1):入库到成品库 |
| | | // 出厂检验(inspectType=2):不做任何业务处理 |
| | | // 原材料检验(inspectType=0):正常质检入库 |
| | | Integer inspectType = qualityInspect.getInspectType(); |
| | | boolean shouldStockIn = inspectType == null || inspectType == 0 || inspectType == 1; |
| | | |
| | | if (shouldStockIn && qualified.compareTo(BigDecimal.ZERO) > 0) { |
| | | StockInventoryDto stockInventoryDto = new StockInventoryDto(); |
| | | stockInventoryDto.setRecordType(String.valueOf(StockInQualifiedRecordTypeEnum.QUALITYINSPECT_STOCK_IN.getCode())); |
| | | if (ObjectUtils.isNotEmpty(qualityInspect.getPurchaseLedgerId())) { |
| | | //过程检验使用生产报工入库类型,其他质检使用质检入库类型 |
| | | if (inspectType != null && inspectType == 1) { |
| | | stockInventoryDto.setRecordType(String.valueOf(StockInQualifiedRecordTypeEnum.PRODUCTION_REPORT_STOCK_IN.getCode())); |
| | | } else if (ObjectUtils.isNotEmpty(qualityInspect.getPurchaseLedgerId())) { |
| | | stockInventoryDto.setRecordType(String.valueOf(StockInQualifiedRecordTypeEnum.CUSTOMIZATION_UNSTOCK_OUT.getCode())); |
| | | } else { |
| | | stockInventoryDto.setRecordType(String.valueOf(StockInQualifiedRecordTypeEnum.QUALITYINSPECT_STOCK_IN.getCode())); |
| | | } |
| | | stockInventoryDto.setRecordId(qualityInspect.getId()); |
| | | stockInventoryDto.setProductModelId(qualityInspect.getProductModelId()); |
| | |
| | | return qualityInspectTemplateExportHelper.analyzeTemplate(templatePath); |
| | | } |
| | | |
| | | @Override |
| | | public AutoJudgeResponse autoJudge(AutoJudgeRequest request) { |
| | | QualityJudgeUtil.JudgeResult result = QualityJudgeUtil.judge( |
| | | request.getTestValue(), |
| | | request.getStandardValue(), |
| | | request.getMinValue(), |
| | | request.getMaxValue(), |
| | | request.getJudgeType() |
| | | ); |
| | | return new AutoJudgeResponse(result.getQualified(), result.getMessage()); |
| | | } |
| | | |
| | | @Override |
| | | public AutoJudgeAllResponse autoJudgeAll(Long inspectId) { |
| | | List<QualityInspectParam> params = qualityInspectParamService.list( |
| | | Wrappers.<QualityInspectParam>lambdaQuery().eq(QualityInspectParam::getInspectId, inspectId)); |
| | | |
| | | AutoJudgeAllResponse response = new AutoJudgeAllResponse(); |
| | | List<AutoJudgeAllResponse.ParamJudgeResult> paramResults = new ArrayList<>(); |
| | | boolean hasRequiredUnqualified = false; |
| | | boolean hasNonRequiredUnqualified = false; |
| | | boolean allTextDescription = true; |
| | | boolean hasRequiredParam = false; |
| | | |
| | | for (QualityInspectParam param : params) { |
| | | AutoJudgeAllResponse.ParamJudgeResult paramResult = new AutoJudgeAllResponse.ParamJudgeResult(); |
| | | paramResult.setParamId(param.getId()); |
| | | paramResult.setParameterItem(param.getParameterItem()); |
| | | paramResult.setIsRequired(param.getIsRequired() != null && param.getIsRequired() == 1); |
| | | |
| | | if (paramResult.getIsRequired()) { |
| | | hasRequiredParam = true; |
| | | } |
| | | |
| | | String judgeType = param.getJudgeType(); |
| | | if (QualityJudgeUtil.JUDGE_TYPE_TEXT_DESCRIPTION.equals(judgeType)) { |
| | | paramResult.setIsQualified(null); |
| | | paramResult.setMessage("文字描述类型需手动判断"); |
| | | } else { |
| | | allTextDescription = false; |
| | | QualityJudgeUtil.JudgeResult result = QualityJudgeUtil.judge( |
| | | param.getTestValue(), |
| | | param.getStandardValue(), |
| | | param.getMinValue(), |
| | | param.getMaxValue(), |
| | | judgeType |
| | | ); |
| | | paramResult.setIsQualified(result.getQualified()); |
| | | paramResult.setMessage(result.getMessage()); |
| | | |
| | | // 更新参数项的判断结果 |
| | | if (result.getQualified() != null) { |
| | | param.setIsQualified(result.getQualified() ? 1 : 0); |
| | | qualityInspectParamService.updateById(param); |
| | | } |
| | | |
| | | // 检查必要判断参数是否不合格 |
| | | if (paramResult.getIsRequired() && Boolean.FALSE.equals(result.getQualified())) { |
| | | hasRequiredUnqualified = true; |
| | | } |
| | | // 检查非必要判断参数是否不合格 |
| | | if (!paramResult.getIsRequired() && Boolean.FALSE.equals(result.getQualified())) { |
| | | hasNonRequiredUnqualified = true; |
| | | } |
| | | } |
| | | paramResults.add(paramResult); |
| | | } |
| | | |
| | | response.setParamResults(paramResults); |
| | | response.setHasRequiredUnqualified(hasRequiredUnqualified); |
| | | response.setHasNonRequiredUnqualified(hasNonRequiredUnqualified); |
| | | response.setAllTextDescription(allTextDescription); |
| | | |
| | | // 确定整体判断结果 |
| | | if (allTextDescription) { |
| | | response.setAutoJudgeResult(null); |
| | | } else if (hasRequiredUnqualified) { |
| | | response.setAutoJudgeResult("不合格"); |
| | | } else if (hasNonRequiredUnqualified) { |
| | | // 必要参数都合格,但有非必要参数不合格 → 部分合格 |
| | | response.setAutoJudgeResult("部分合格"); |
| | | } else { |
| | | // 所有需要自动判断的参数项都合格,整体为合格 |
| | | response.setAutoJudgeResult("合格"); |
| | | } |
| | | |
| | | // 更新质检主表的自动判断结果 |
| | | QualityInspect inspect = qualityInspectMapper.selectById(inspectId); |
| | | if (inspect != null) { |
| | | inspect.setAutoJudgeResult(response.getAutoJudgeResult()); |
| | | qualityInspectMapper.updateById(inspect); |
| | | } |
| | | |
| | | return response; |
| | | } |
| | | |
| | | } |