|
|
@ -69,6 +69,7 @@ import java.util.stream.Collectors; |
|
|
@Service |
|
|
@Service |
|
|
@Slf4j |
|
|
@Slf4j |
|
|
public class QcServiceImpl implements QcService { |
|
|
public class QcServiceImpl implements QcService { |
|
|
|
|
|
private static final String TEMPLATE_SUPPLIER_WILDCARD = "*"; |
|
|
|
|
|
|
|
|
//记录日志使用 |
|
|
//记录日志使用 |
|
|
private static final Logger logger = LoggerFactory.getLogger(HttpClientUtil.class); |
|
|
private static final Logger logger = LoggerFactory.getLogger(HttpClientUtil.class); |
|
|
@ -5473,29 +5474,32 @@ public class QcServiceImpl implements QcService { |
|
|
return "免检物料,无需生成IQC"; |
|
|
return "免检物料,无需生成IQC"; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
List<TemplateDTO> templates = getTemplates(detail); |
|
|
|
|
|
|
|
|
List<TemplateDTO> templates = deduplicateTemplates(getTemplates(detail)); |
|
|
if (templates == null || templates.isEmpty()) { |
|
|
if (templates == null || templates.isEmpty()) { |
|
|
throw new RuntimeException("未维护此物料的检验模板"); |
|
|
throw new RuntimeException("未维护此物料的检验模板"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
String inspectionNo = genInspectionNo(detail.getSite()); |
|
|
String inspectionNo = genInspectionNo(detail.getSite()); |
|
|
updateInspectRequestDetail(detail, inspectionNo); |
|
|
updateInspectRequestDetail(detail, inspectionNo); |
|
|
insertMain(detail, partAttr, inspectionNo); |
|
|
|
|
|
|
|
|
BigDecimal mainSamplingQty = resolveSamplingQty(detail.getQty(), partAttr, templates); |
|
|
|
|
|
insertMain(detail, partAttr, inspectionNo, mainSamplingQty); |
|
|
|
|
|
Set<String> insertedItemNoSet = new HashSet<>(); |
|
|
|
|
|
|
|
|
for (TemplateDTO template : templates) { |
|
|
for (TemplateDTO template : templates) { |
|
|
|
|
|
|
|
|
// 查询模板明细 |
|
|
// 查询模板明细 |
|
|
List<TemplateDetailDTO> items = |
|
|
|
|
|
|
|
|
List<TemplateDetailDTO> items = deduplicateTemplateItems( |
|
|
getTemplateDetail(template.getTemplateId(), |
|
|
getTemplateDetail(template.getTemplateId(), |
|
|
detail.getSite(), |
|
|
detail.getSite(), |
|
|
partAttr.getBuNo(), |
|
|
partAttr.getBuNo(), |
|
|
"*"); |
|
|
|
|
|
|
|
|
TEMPLATE_SUPPLIER_WILDCARD)); |
|
|
|
|
|
|
|
|
if (items == null || items.isEmpty()) { |
|
|
if (items == null || items.isEmpty()) { |
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
insertDetail(detail, partAttr, template, items, inspectionNo); |
|
|
|
|
|
|
|
|
BigDecimal detailSamplingQty = resolveSamplingQty(detail.getQty(), partAttr, template); |
|
|
|
|
|
insertDetail(detail, partAttr, template, items, inspectionNo, detailSamplingQty, insertedItemNoSet); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return inspectionNo; |
|
|
return inspectionNo; |
|
|
@ -5521,7 +5525,7 @@ public class QcServiceImpl implements QcService { |
|
|
return qcMapper.listByPart( |
|
|
return qcMapper.listByPart( |
|
|
detail.getSite(), |
|
|
detail.getSite(), |
|
|
detail.getPartNo(), |
|
|
detail.getPartNo(), |
|
|
"*"); |
|
|
|
|
|
|
|
|
TEMPLATE_SUPPLIER_WILDCARD); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// ================= 查询模板明细 ================= |
|
|
// ================= 查询模板明细 ================= |
|
|
@ -5532,9 +5536,115 @@ public class QcServiceImpl implements QcService { |
|
|
return qcMapper.listDetail(templateId, site, buNo, supplierNo); |
|
|
return qcMapper.listDetail(templateId, site, buNo, supplierNo); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 计算检验单主记录抽样数:优先使用模板抽样方案,取第一个可命中的抽样数; |
|
|
|
|
|
* 若未命中则回退物料属性的默认抽样数/默认抽样比例。 |
|
|
|
|
|
*/ |
|
|
|
|
|
private BigDecimal resolveSamplingQty(BigDecimal rollQty, |
|
|
|
|
|
PartAttrDTO partAttr, |
|
|
|
|
|
List<TemplateDTO> templates) { |
|
|
|
|
|
if (templates != null && !templates.isEmpty()) { |
|
|
|
|
|
for (TemplateDTO template : templates) { |
|
|
|
|
|
BigDecimal samplingQty = resolveSamplingQty(rollQty, partAttr, template); |
|
|
|
|
|
if (samplingQty != null) { |
|
|
|
|
|
return samplingQty; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return resolveSamplingQty(rollQty, partAttr, (TemplateDTO) null); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 去重模板(按 templateId),避免重复模板导致重复插入明细。 |
|
|
|
|
|
*/ |
|
|
|
|
|
private List<TemplateDTO> deduplicateTemplates(List<TemplateDTO> templates) { |
|
|
|
|
|
if (templates == null || templates.isEmpty()) { |
|
|
|
|
|
return templates; |
|
|
|
|
|
} |
|
|
|
|
|
Map<String, TemplateDTO> uniqueMap = new LinkedHashMap<>(); |
|
|
|
|
|
for (TemplateDTO template : templates) { |
|
|
|
|
|
if (template == null || StringUtils.isBlank(template.getTemplateId())) { |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
uniqueMap.putIfAbsent(template.getTemplateId(), template); |
|
|
|
|
|
} |
|
|
|
|
|
return new ArrayList<>(uniqueMap.values()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 去重模板明细(按 itemNo),避免同一模板重复项目导致主键冲突。 |
|
|
|
|
|
*/ |
|
|
|
|
|
private List<TemplateDetailDTO> deduplicateTemplateItems(List<TemplateDetailDTO> items) { |
|
|
|
|
|
if (items == null || items.isEmpty()) { |
|
|
|
|
|
return items; |
|
|
|
|
|
} |
|
|
|
|
|
Map<String, TemplateDetailDTO> uniqueMap = new LinkedHashMap<>(); |
|
|
|
|
|
for (TemplateDetailDTO item : items) { |
|
|
|
|
|
if (item == null || StringUtils.isBlank(item.getItemNo())) { |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
uniqueMap.putIfAbsent(item.getItemNo(), item); |
|
|
|
|
|
} |
|
|
|
|
|
return new ArrayList<>(uniqueMap.values()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 计算单个模板的抽样数:抽样方案矩阵 > 默认抽样数 > 默认抽样比例 |
|
|
|
|
|
*/ |
|
|
|
|
|
private BigDecimal resolveSamplingQty(BigDecimal rollQty, |
|
|
|
|
|
PartAttrDTO partAttr, |
|
|
|
|
|
TemplateDTO template) { |
|
|
|
|
|
BigDecimal samplingQty = null; |
|
|
|
|
|
|
|
|
|
|
|
if (rollQty != null |
|
|
|
|
|
&& template != null |
|
|
|
|
|
&& StringUtils.isNotBlank(template.getSamplingProgrammeNo()) |
|
|
|
|
|
&& StringUtils.isNotBlank(template.getSamplingLevelNo()) |
|
|
|
|
|
&& StringUtils.isNotBlank(partAttr.getSite()) |
|
|
|
|
|
&& StringUtils.isNotBlank(partAttr.getBuNo())) { |
|
|
|
|
|
QcSamplingInspectionProgrammeData searchCriteria = new QcSamplingInspectionProgrammeData(); |
|
|
|
|
|
searchCriteria.setSite(partAttr.getSite()); |
|
|
|
|
|
searchCriteria.setBuNo(partAttr.getBuNo()); |
|
|
|
|
|
searchCriteria.setSamplingProgrammeNo(template.getSamplingProgrammeNo()); |
|
|
|
|
|
List<QcSamplingInspectionProgrammeData> programmeDataList = qcMapper.searchSamplingProgrammeDetails(searchCriteria); |
|
|
|
|
|
for (QcSamplingInspectionProgrammeData programmeData : programmeDataList) { |
|
|
|
|
|
if (template.getSamplingLevelNo().equals(programmeData.getSamplingLevelNo()) |
|
|
|
|
|
&& programmeData.getMinQty() != null |
|
|
|
|
|
&& programmeData.getMaxQty() != null |
|
|
|
|
|
&& rollQty.compareTo(programmeData.getMinQty()) >= 0 |
|
|
|
|
|
&& rollQty.compareTo(programmeData.getMaxQty()) <= 0) { |
|
|
|
|
|
samplingQty = programmeData.getSamplingQty(); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (samplingQty == null |
|
|
|
|
|
&& template != null |
|
|
|
|
|
&& template.getDefaultSamplingQuantity() != null) { |
|
|
|
|
|
samplingQty = template.getDefaultSamplingQuantity(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (samplingQty == null |
|
|
|
|
|
&& template != null |
|
|
|
|
|
&& template.getDefaultSamplingProportion() != null |
|
|
|
|
|
&& rollQty != null) { |
|
|
|
|
|
samplingQty = template.getDefaultSamplingProportion() |
|
|
|
|
|
.multiply(rollQty) |
|
|
|
|
|
.divide(new BigDecimal(100), 3, BigDecimal.ROUND_HALF_UP); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (samplingQty == null && partAttr.getDefaultSamplingQuantity() != null) { |
|
|
|
|
|
samplingQty = partAttr.getDefaultSamplingQuantity(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return samplingQty; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private void insertMain(MyInspectionListVO detail, |
|
|
private void insertMain(MyInspectionListVO detail, |
|
|
PartAttrDTO partAttr, |
|
|
PartAttrDTO partAttr, |
|
|
String inspectionNo) { |
|
|
|
|
|
|
|
|
String inspectionNo, |
|
|
|
|
|
BigDecimal samplingQty) { |
|
|
|
|
|
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
|
|
|
|
|
@ -5551,7 +5661,7 @@ public class QcServiceImpl implements QcService { |
|
|
|
|
|
|
|
|
map.put("rollQty", detail.getQty()); |
|
|
map.put("rollQty", detail.getQty()); |
|
|
|
|
|
|
|
|
map.put("samplingQty", partAttr.getDefaultSamplingQuantity()); |
|
|
|
|
|
|
|
|
map.put("samplingQty", samplingQty); |
|
|
|
|
|
|
|
|
map.put("buNo", partAttr.getBuNo()); |
|
|
map.put("buNo", partAttr.getBuNo()); |
|
|
|
|
|
|
|
|
@ -5569,9 +5679,19 @@ public class QcServiceImpl implements QcService { |
|
|
PartAttrDTO partAttr, |
|
|
PartAttrDTO partAttr, |
|
|
TemplateDTO template, |
|
|
TemplateDTO template, |
|
|
List<TemplateDetailDTO> items, |
|
|
List<TemplateDetailDTO> items, |
|
|
String inspectionNo) { |
|
|
|
|
|
|
|
|
String inspectionNo, |
|
|
|
|
|
BigDecimal samplingQty, |
|
|
|
|
|
Set<String> insertedItemNoSet) { |
|
|
|
|
|
|
|
|
for (TemplateDetailDTO i : items) { |
|
|
for (TemplateDetailDTO i : items) { |
|
|
|
|
|
if (StringUtils.isBlank(i.getItemNo())) { |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
if (insertedItemNoSet.contains(i.getItemNo())) { |
|
|
|
|
|
log.warn("createIqc 跳过重复项目: inspectionNo={}, templateId={}, itemNo={}", |
|
|
|
|
|
inspectionNo, template.getTemplateId(), i.getItemNo()); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
|
|
|
|
|
@ -5594,9 +5714,10 @@ public class QcServiceImpl implements QcService { |
|
|
map.put("site", detail.getSite()); |
|
|
map.put("site", detail.getSite()); |
|
|
map.put("buNo", partAttr.getBuNo()); |
|
|
map.put("buNo", partAttr.getBuNo()); |
|
|
|
|
|
|
|
|
map.put("samplingQty", partAttr.getDefaultSamplingQuantity()); |
|
|
|
|
|
|
|
|
map.put("samplingQty", samplingQty); |
|
|
|
|
|
|
|
|
qcMapper.insertDetail(map); |
|
|
qcMapper.insertDetail(map); |
|
|
|
|
|
insertedItemNoSet.add(i.getItemNo()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|