@ -3869,156 +3869,85 @@ public class QcServiceImpl implements QcService {
}
}
/ * *
/ * *
* 任务重载
* 按物料属性设置重新生成 IQC 任务单和检验明细
* /
* /
@Override
@Override
@Transactional
@Transactional
public void iqcRecordOverLoad ( QcFAIRecordData data ) {
public void iqcRecordOverLoad ( QcFAIRecordData data ) {
/ / 新建对象存放主记录
QcFAIRecordData qcFAIRecordData = new QcFAIRecordData ( ) ;
for ( QcFAIRecordData recordData : data . getSubmitList ( ) ) {
for ( QcFAIRecordData recordData : data . getSubmitList ( ) ) {
/ / 删除明细记录信息
qcMapper . deleteIQCDetailedRecord ( recordData ) ;
qcMapper . deleteIQCDetailedRecord ( recordData ) ;
/ / 删除子明细记录信息
qcMapper . deleteIQCSubDetailedRecord ( recordData ) ;
qcMapper . deleteIQCSubDetailedRecord ( recordData ) ;
/ / 删除数据采集的数据
/ / qcMapper . deleteEquipmentDataAcquisition ( recordData ) ;
/ / 删除文件
qcMapper . deleteInspectionFiles ( recordData ) ;
qcMapper . deleteInspectionFiles ( recordData ) ;
/ / 拿到供应商编码
String supplierNo = "" ;
if ( StringUtils . isNotBlank ( recordData . getSupplierNo ( ) ) ) {
supplierNo = recordData . getSupplierNo ( ) ;
if ( recordData . getRollCount ( ) = = null ) {
recordData . setRollCount ( recordData . getRollQty ( ) = = null ? BigDecimal . ZERO : recordData . getRollQty ( ) ) ;
}
}
/ / 主记录信息赋值
qcFAIRecordData . setSite ( recordData . getSite ( ) ) ;
qcFAIRecordData . setBuNo ( recordData . getBuNo ( ) ) ;
qcFAIRecordData . setInspectionNo ( recordData . getInspectionNo ( ) ) ; / / 检验单号
qcFAIRecordData . setInspectionTypeNo ( recordData . getInspectionTypeNo ( ) ) ; / / 检验类型编码
qcFAIRecordData . setPartNo ( recordData . getPartNo ( ) ) ;
qcFAIRecordData . setPartDesc ( recordData . getPartDesc ( ) ) ;
qcFAIRecordData . setRollQty ( recordData . getRollQty ( ) ) ;
qcFAIRecordData . setSupplierNo ( supplierNo ) ;
qcFAIRecordData . setActionDate ( null ) ;
/ / 明细记录信息赋值
String partNo = recordData . getPartNo ( ) ;
String attributeType1 = "A" ;
String supplierNo = StringUtils . defaultString ( recordData . getSupplierNo ( ) , "" ) ;
String inspectionMethod = resolveIqcInspectionMethod ( recordData ) ;
String inspectionMethod = resolveIqcInspectionMethod ( recordData ) ;
/ / 优先按partNo走模板匹配 ( 与 selectTemplateByPartNo 逻辑保持一致 )
recordData . setInspectionTypeNo ( qcFAIRecordData . getInspectionTypeNo ( ) ) ;
List < QcFAIRecordData > partAttribute = null ;
if ( StringUtils . isBlank ( inspectionMethod ) ) {
partAttribute = qcMapper . selectTemplateByPartNoForOverLoad ( recordData ) ;
}
/ / 兼容老逻辑 : 未匹配到时回退到属性模板 ; 有检验方式时直接按检验方式匹配
if ( partAttribute = = null | | partAttribute . isEmpty ( ) ) {
partAttribute = qcMapper . selectPartAttributeByPartNo ( recordData . getSite ( ) , recordData . getBuNo ( ) , partNo , attributeType1 , qcFAIRecordData . getInspectionTypeNo ( ) , supplierNo , inspectionMethod ) ;
}
if ( partAttribute ! = null & & ! partAttribute . isEmpty ( ) ) {
/ / 检验周期
if ( partAttribute . get ( 0 ) . getInspectionCycle ( ) ! = null ) {
qcFAIRecordData . setInspectionCycle ( partAttribute . get ( 0 ) . getInspectionCycle ( ) ) ;
}
/ / 获取抽样数量
/ / 如果该检验模板有维护抽样方案
if ( StringUtils . isNotBlank ( partAttribute . get ( 0 ) . getSamplingProgrammeNo ( ) ) ) {
QcSamplingInspectionProgrammeData samplingInspectionProgrammeData = new QcSamplingInspectionProgrammeData ( ) ;
samplingInspectionProgrammeData . setSite ( partAttribute . get ( 0 ) . getSite ( ) ) ;
samplingInspectionProgrammeData . setBuNo ( partAttribute . get ( 0 ) . getBuNo ( ) ) ;
samplingInspectionProgrammeData . setSamplingProgrammeNo ( partAttribute . get ( 0 ) . getSamplingProgrammeNo ( ) ) ;
/ / 获取抽样方案维护的矩阵详情
List < QcSamplingInspectionProgrammeData > dataList = qcMapper . searchSamplingProgrammeDetails ( samplingInspectionProgrammeData ) ;
/ / 根据抽样方案确定抽样数
for ( QcSamplingInspectionProgrammeData programmeData : dataList ) {
if ( programmeData . getSamplingLevelNo ( ) . equals ( partAttribute . get ( 0 ) . getSamplingLevelNo ( ) ) & & ( recordData . getRollCount ( ) . compareTo ( programmeData . getMinQty ( ) ) > 0 | | recordData . getRollCount ( ) . compareTo ( programmeData . getMinQty ( ) ) = = 0 ) & & ( recordData . getRollCount ( ) . compareTo ( programmeData . getMaxQty ( ) ) < 0 | | recordData . getRollCount ( ) . compareTo ( programmeData . getMaxQty ( ) ) = = 0 ) ) {
qcFAIRecordData . setSamplingQty ( programmeData . getSamplingQty ( ) ) ;
}
}
} else if ( partAttribute . get ( 0 ) . getDefaultSamplingQuantity ( ) ! = null ) {
/ / 没有维护抽样方案 , 再根据默认抽样数来确定
qcFAIRecordData . setSamplingQty ( partAttribute . get ( 0 ) . getDefaultSamplingQuantity ( ) ) ;
} else if ( partAttribute . get ( 0 ) . getDefaultSamplingProportion ( ) ! = null ) {
/ / 也没有维护默认抽样数 , 最后根据默认抽样比例来确定
BigDecimal d = partAttribute . get ( 0 ) . getDefaultSamplingProportion ( ) . multiply ( recordData . getRollCount ( ) ) . divide ( new BigDecimal ( 100 ) , 3 , BigDecimal . ROUND_HALF_UP ) ;
qcFAIRecordData . setSamplingQty ( d ) ;
}
/ / 按模板批量写入明细 ( 默认值优先取 qc_part_attr_detailed )
for ( QcFAIRecordData template : partAttribute ) {
QcFAIRecordData detailData = new QcFAIRecordData ( ) ;
detailData . setSite ( recordData . getSite ( ) ) ;
detailData . setBuNo ( recordData . getBuNo ( ) ) ;
detailData . setInspectionNo ( qcFAIRecordData . getInspectionNo ( ) ) ;
detailData . setTemplateId ( template . getTemplateId ( ) ) ;
detailData . setSamplingLevelNo ( template . getSamplingLevelNo ( ) ) ;
detailData . setSamplingLevelDesc ( template . getSamplingLevelDesc ( ) ) ;
detailData . setSamplingProgrammeNo ( template . getSamplingProgrammeNo ( ) ) ;
detailData . setSamplingProgrammeDesc ( template . getSamplingProgrammeDesc ( ) ) ;
detailData . setAql ( template . getAql ( ) ) ;
detailData . setAc ( template . getAc ( ) ) ;
detailData . setRe ( template . getRe ( ) ) ;
detailData . setSamplingQty ( qcFAIRecordData . getSamplingQty ( ) ) ;
detailData . setPartNo ( partNo ) ;
qcMapper . saveIQCDetailedRecordByTemplate ( detailData ) ;
}
} else {
/ / 获取物料的类别编码
String familyId = qcMapper . selectFamilyIdByPartNo ( partNo , recordData . getSite ( ) ) ;
String attributeType2 = "B" ;
/ / 获取该类别属性下维护的IQC检验模板
List < QcFAIRecordData > familyAttribute = qcMapper . selectPartAttributeByPartNo ( recordData . getSite ( ) , recordData . getBuNo ( ) , familyId , attributeType2 , qcFAIRecordData . getInspectionTypeNo ( ) , supplierNo , inspectionMethod ) ;
if ( ! familyAttribute . isEmpty ( ) ) {
/ / 获取检验周期
if ( familyAttribute . get ( 0 ) . getInspectionCycle ( ) ! = null ) {
qcFAIRecordData . setInspectionCycle ( familyAttribute . get ( 0 ) . getInspectionCycle ( ) ) ;
}
/ / 获取抽样数量
/ / 如果该检验模板有维护抽样方案
if ( StringUtils . isNotBlank ( familyAttribute . get ( 0 ) . getSamplingProgrammeNo ( ) ) ) {
QcSamplingInspectionProgrammeData samplingInspectionProgrammeData = new QcSamplingInspectionProgrammeData ( ) ;
samplingInspectionProgrammeData . setSite ( familyAttribute . get ( 0 ) . getSite ( ) ) ;
samplingInspectionProgrammeData . setBuNo ( familyAttribute . get ( 0 ) . getBuNo ( ) ) ;
samplingInspectionProgrammeData . setSamplingProgrammeNo ( familyAttribute . get ( 0 ) . getSamplingProgrammeNo ( ) ) ;
/ / 获取抽样方案维护的矩阵详情
List < QcSamplingInspectionProgrammeData > dataList = qcMapper . searchSamplingProgrammeDetails ( samplingInspectionProgrammeData ) ;
/ / 根据抽样方案确定抽样数
for ( QcSamplingInspectionProgrammeData programmeData : dataList ) {
if ( programmeData . getSamplingLevelNo ( ) . equals ( familyAttribute . get ( 0 ) . getSamplingLevelNo ( ) ) & & ( recordData . getRollCount ( ) . compareTo ( programmeData . getMinQty ( ) ) > 0 | | recordData . getRollCount ( ) . compareTo ( programmeData . getMinQty ( ) ) = = 0 ) & & ( recordData . getRollCount ( ) . compareTo ( programmeData . getMaxQty ( ) ) < 0 | | recordData . getRollCount ( ) . compareTo ( programmeData . getMaxQty ( ) ) = = 0 ) ) {
qcFAIRecordData . setSamplingQty ( programmeData . getSamplingQty ( ) ) ;
}
}
} else if ( familyAttribute . get ( 0 ) . getDefaultSamplingQuantity ( ) ! = null ) {
/ / 没有维护抽样方案 , 再根据默认抽样数来确定
qcFAIRecordData . setSamplingQty ( familyAttribute . get ( 0 ) . getDefaultSamplingQuantity ( ) ) ;
} else if ( familyAttribute . get ( 0 ) . getDefaultSamplingProportion ( ) ! = null ) {
/ / 也没有维护默认抽样数 , 最后根据默认抽样比例来确定
qcFAIRecordData . setSamplingQty ( familyAttribute . get ( 0 ) . getDefaultSamplingProportion ( ) . multiply ( qcFAIRecordData . getRollCount ( ) ) . divide ( new BigDecimal ( 100 ) , 3 , BigDecimal . ROUND_HALF_UP ) ) ;
}
/ / 按模板批量写入明细 ( 默认值优先取 qc_part_attr_detailed )
for ( QcFAIRecordData template : familyAttribute ) {
QcFAIRecordData detailData = new QcFAIRecordData ( ) ;
detailData . setSite ( recordData . getSite ( ) ) ;
detailData . setBuNo ( recordData . getBuNo ( ) ) ;
detailData . setInspectionNo ( qcFAIRecordData . getInspectionNo ( ) ) ;
detailData . setTemplateId ( template . getTemplateId ( ) ) ;
detailData . setSamplingLevelNo ( template . getSamplingLevelNo ( ) ) ;
detailData . setSamplingLevelDesc ( template . getSamplingLevelDesc ( ) ) ;
detailData . setSamplingProgrammeNo ( template . getSamplingProgrammeNo ( ) ) ;
detailData . setSamplingProgrammeDesc ( template . getSamplingProgrammeDesc ( ) ) ;
detailData . setAql ( template . getAql ( ) ) ;
detailData . setAc ( template . getAc ( ) ) ;
detailData . setRe ( template . getRe ( ) ) ;
detailData . setSamplingQty ( qcFAIRecordData . getSamplingQty ( ) ) ;
detailData . setPartNo ( partNo ) ;
qcMapper . saveIQCDetailedRecordByTemplate ( detailData ) ;
}
}
String inspectionTypeNo = StringUtils . defaultIfBlank ( recordData . getInspectionTypeNo ( ) , "105" ) ;
QcFAIRecordData masterData = new QcFAIRecordData ( ) ;
masterData . setSite ( recordData . getSite ( ) ) ;
masterData . setBuNo ( recordData . getBuNo ( ) ) ;
masterData . setInspectionNo ( recordData . getInspectionNo ( ) ) ;
masterData . setInspectionTypeNo ( inspectionTypeNo ) ;
masterData . setPartNo ( recordData . getPartNo ( ) ) ;
masterData . setPartDesc ( recordData . getPartDesc ( ) ) ;
masterData . setRollQty ( recordData . getRollQty ( ) ) ;
masterData . setSupplierNo ( supplierNo ) ;
masterData . setActionDate ( null ) ;
List < QcFAIRecordData > templates = selectIqcTemplatesForReload ( recordData , inspectionTypeNo , supplierNo , inspectionMethod ) ;
if ( templates = = null | | templates . isEmpty ( ) ) {
String methodTip = StringUtils . isBlank ( inspectionMethod ) ? "" : "、检验方式【" + inspectionMethod + "】" ;
throw new RuntimeException ( "检验单【" + recordData . getInspectionNo ( ) + "】未找到物料【" + recordData . getPartNo ( ) + "】" + methodTip + "的IQC检验模板,请先在物料属性设置中维护" ) ;
}
applySamplingFromTemplate ( masterData , recordData , templates . get ( 0 ) ) ;
for ( QcFAIRecordData template : templates ) {
QcFAIRecordData sampling = new QcFAIRecordData ( ) ;
applySamplingFromTemplate ( sampling , recordData , template ) ;
QcFAIRecordData detailData = new QcFAIRecordData ( ) ;
detailData . setSite ( recordData . getSite ( ) ) ;
detailData . setBuNo ( recordData . getBuNo ( ) ) ;
detailData . setInspectionNo ( masterData . getInspectionNo ( ) ) ;
detailData . setTemplateId ( template . getTemplateId ( ) ) ;
detailData . setSamplingLevelNo ( template . getSamplingLevelNo ( ) ) ;
detailData . setSamplingLevelDesc ( template . getSamplingLevelDesc ( ) ) ;
detailData . setSamplingProgrammeNo ( template . getSamplingProgrammeNo ( ) ) ;
detailData . setSamplingProgrammeDesc ( template . getSamplingProgrammeDesc ( ) ) ;
detailData . setAql ( template . getAql ( ) ) ;
detailData . setAc ( template . getAc ( ) ) ;
detailData . setRe ( template . getRe ( ) ) ;
detailData . setSamplingQty ( sampling . getSamplingQty ( ) ! = null ? sampling . getSamplingQty ( ) : masterData . getSamplingQty ( ) ) ;
detailData . setPartNo ( recordData . getPartNo ( ) ) ;
qcMapper . saveIQCDetailedRecordByTemplate ( detailData ) ;
}
qcMapper . updateIQCRecord ( masterData ) ;
}
}
/ * *
* 按物料属性检验模板清单匹配 。 有供应商时优先供应商模板 , 没有再取未填供应商的模板 。
* /
private List < QcFAIRecordData > selectIqcTemplatesForReload ( QcFAIRecordData recordData , String inspectionTypeNo , String supplierNo , String inspectionMethod ) {
List < QcFAIRecordData > templates = selectIqcAttributeTemplates ( recordData . getSite ( ) , recordData . getBuNo ( ) , recordData . getPartNo ( ) , "A" , inspectionTypeNo , supplierNo , inspectionMethod ) ;
if ( templates = = null | | templates . isEmpty ( ) ) {
String familyId = qcMapper . selectFamilyIdByPartNo ( recordData . getPartNo ( ) , recordData . getSite ( ) ) ;
if ( StringUtils . isNotBlank ( familyId ) ) {
templates = selectIqcAttributeTemplates ( recordData . getSite ( ) , recordData . getBuNo ( ) , familyId , "B" , inspectionTypeNo , supplierNo , inspectionMethod ) ;
}
}
/ / 更新IQC主记录信息
qcMapper . updateIQCRecord ( qcFAIRecordData ) ;
}
}
return templates ;
}
private List < QcFAIRecordData > selectIqcAttributeTemplates ( String site , String buNo , String attributeNo , String attributeType , String inspectionTypeNo , String supplierNo , String inspectionMethod ) {
List < QcFAIRecordData > templates = null ;
if ( StringUtils . isNotBlank ( supplierNo ) ) {
templates = qcMapper . selectPartAttributeByPartNo ( site , buNo , attributeNo , attributeType , inspectionTypeNo , supplierNo , inspectionMethod ) ;
}
if ( templates = = null | | templates . isEmpty ( ) ) {
templates = qcMapper . selectPartAttributeByEmptySupplier ( site , buNo , attributeNo , attributeType , inspectionTypeNo , inspectionMethod ) ;
}
return templates ;
}
}
@Override
@Override