@ -14,22 +14,25 @@ import com.foreverwin.mesnac.common.util.StringUtil;
import com.foreverwin.mesnac.meapi.dto.RouterStepDto ;
import com.foreverwin.mesnac.meapi.dto.SfcDto ;
import com.foreverwin.mesnac.meapi.model.Router ;
import com.foreverwin.mesnac.meapi.model.Sfc ;
import com.foreverwin.mesnac.meapi.service.OperationService ;
import com.foreverwin.mesnac.meapi.service.RouterService ;
import com.foreverwin.mesnac.meapi.service.RouterStepService ;
import com.foreverwin.mesnac.meapi.service.S hopOrder Service;
import com.foreverwin.mesnac.meapi.service.S fc Service;
import com.foreverwin.mesnac.production.dto.SplitSfcDto ;
import com.foreverwin.mesnac.production.mapper.SfcCrossMapper ;
import com.foreverwin.mesnac.production.mapper.SplitSfcMapper ;
import com.foreverwin.mesnac.production.model.SplitSfc ;
import com.foreverwin.mesnac.production.model.StepOperation ;
import com.foreverwin.mesnac.production.service.SfcCrossService ;
import com.foreverwin.mesnac.production.service.SplitSfcService ;
import com.foreverwin.modular.core.exception.BaseException ;
import com.foreverwin.modular.core.meext.MEServices ;
import com.foreverwin.modular.core.util.CommonMethods ;
import com.foreverwin.modular.core.util.FrontPage ;
import com.sap.me.nonconformance.* ;
import com.sap.me.production.SplitSerializeServiceInterface ;
import com.sap.me.production.SplitSfcDetail ;
import com.sap.me.production.SplitSfcRequest ;
import com.sap.me.production.SplitSfcResponse ;
import com.sap.me.production.* ;
import com.sap.me.status.StatusBOHandle ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Transactional ;
@ -58,10 +61,16 @@ public class SplitSfcServiceImpl extends ServiceImpl<SplitSfcMapper, SplitSfc> i
@Autowired
private InspectionTaskService inspectionTaskService ;
@Autowired
private ShopOrderService shopOrderService ;
private OperationService operationService ;
@Autowired
private SfcCrossMapper sfcCrossMapper ;
@Autowired
private RouterService routerService ;
@Autowired
private SfcService sfcService ;
@Autowired
private SfcCrossService sfcCrossService ;
@Autowired
private RouterStepService routerStepService ;
@Autowired
private CommonService commonService ;
@ -92,11 +101,15 @@ public class SplitSfcServiceImpl extends ServiceImpl<SplitSfcMapper, SplitSfc> i
//根据sfc找工单等信息
SfcDto sfcData = splitSfcMapper . getSfcData ( handle ) ;
if ( sfcData = = null ) {
throw new BaseException ( "未找到产品条码信息" ) ;
Sfc sfcServiceById = sfcService . getById ( handle ) ;
if ( ! sfcServiceById . getStatusBo ( ) . equals ( HandleEnum . STATUS . getHandle ( site , "405" ) ) ) {
throw new BaseException ( "未找到产品条码信息" ) ;
}
sfcData = splitSfcMapper . getCompleteSfcData ( handle ) . get ( 0 ) ;
}
String operation = sfcData . getOperation ( ) ;
String stepId = sfcData . getStepId ( ) ;
//查询质量异常记录数量
SplitSfcDto sfcDto = splitSfcMapper . getAbnormalQty ( site , dto . getSfc ( ) , operation , dto . getAbnormalNo ( ) ) ;
SplitSfcDto sfcDto = splitSfcMapper . getAbnormalQty ( site , dto . getSfc ( ) , stepId , dto . getAbnormalNo ( ) ) ;
if ( sfcDto = = null ) {
throw new BaseException ( "未找到闭环关闭的质量异常" ) ;
}
@ -181,12 +194,40 @@ public class SplitSfcServiceImpl extends ServiceImpl<SplitSfcMapper, SplitSfc> i
//根据sfc找工单等信息
SfcDto sfcData = splitSfcMapper . getSfcData ( handle ) ;
String operation = sfcData . getOperation ( ) ;
String operation ;
BigDecimal qty ;
String shopOrder ;
String stepId ;
String stepSequence ;
String resrce = null ;
boolean isComplete = false ;
String routerBoBySfc = null ;
String sfcRouterRef = null ;
if ( sfcData = = null ) {
throw new BaseException ( "未找到产品条码信息" ) ;
Sfc sfcServiceById = sfcService . getById ( handle ) ;
if ( ! sfcServiceById . getStatusBo ( ) . equals ( new StatusBOHandle ( site , "405" ) . getValue ( ) ) ) {
throw new BaseException ( "未找到产品条码信息" ) ;
}
StepOperation lastStep = sfcCrossMapper . findRouterLastOperationByRouterBo ( handle ) . get ( 0 ) ;
qty = new BigDecimal ( sfcServiceById . getQty ( ) . toString ( ) ) ;
operation = StringUtil . trimHandle ( lastStep . getOperationBo ( ) ) ;
shopOrder = StringUtil . trimHandle ( sfcServiceById . getShopOrderBo ( ) ) ;
stepId = lastStep . getStepId ( ) ;
stepSequence = String . valueOf ( lastStep . getSequence ( ) ) ;
routerBoBySfc = lastStep . getRouterBo ( ) ;
sfcRouterRef = lastStep . getHandle ( ) ;
resrce = lastStep . getResrce ( ) ;
isComplete = true ;
} else {
qty = BigDecimal . valueOf ( sfcData . getQty ( ) ) ;
operation = sfcData . getOperation ( ) ;
shopOrder = sfcData . getShopOrder ( ) ;
stepId = sfcData . getStepId ( ) ;
stepSequence = sfcData . getStepSequence ( ) ;
}
//查询质量异常记录数量 处置工艺路线及不良代码
SplitSfcDto splitSfcDto = splitSfcMapper . getAbnormalQty ( site , sfc , operation , abnormalNo ) ;
SplitSfcDto splitSfcDto = splitSfcMapper . getAbnormalQty ( site , sfc , stepId , abnormalNo ) ;
SfcDispatchDto sfcDispatchDto = new SfcDispatchDto ( ) ;
sfcDispatchDto . setSite ( site ) ;
sfcDispatchDto . setSfc ( sfc ) ;
@ -201,7 +242,7 @@ public class SplitSfcServiceImpl extends ServiceImpl<SplitSfcMapper, SplitSfc> i
if ( StringUtil . isBlank ( ncCode ) ) {
throw new BaseException ( "异常处置未选择不良代码" ) ;
}
BigDecimal sfcQty = new BigDecimal ( sfcData . getQty ( ) ) ;
BigDecimal sfcQty = qty ;
if ( new BigDecimal ( splitSfcDto . getNcQty ( ) ) . compareTo ( sfcQty ) > = 0 ) {
throw new BaseException ( "质量异常数量大于等于于产品条码的数量,不能拆分" ) ;
}
@ -213,7 +254,14 @@ public class SplitSfcServiceImpl extends ServiceImpl<SplitSfcMapper, SplitSfc> i
SplitSfcRequest splitSfcRequest = new SplitSfcRequest ( ) ;
try {
SplitSerializeServiceInterface splitService = MEServices . create ( "com.sap.me.production" , "SplitSerializeService" , site ) ;
NCProductionServiceInterface ncProductionService = MEServices . create ( "com.sap.me.nonconformance" , "NCProductionService" , site ) ;
if ( isComplete ) {
//修改状态
updateStatus ( site , handle , HandleEnum . STATUS . getHandle ( site , "402" ) ) ;
//调整步骤
splitSfcMapper . updateSfcRouterInUse ( sfcRouterRef , "true" , "false" ) ;
placeInQueueAtStep ( site , handle , routerBoBySfc , HandleEnum . OPERATION . getHandle ( site , operation ) , sfcRouterRef , qty , stepId ) ;
}
//拆sfc
List < SplitSfcDetail > newList = new ArrayList < > ( ) ;
SplitSfcDetail splitDetail = new SplitSfcDetail ( ) ;
@ -225,39 +273,19 @@ public class SplitSfcServiceImpl extends ServiceImpl<SplitSfcMapper, SplitSfc> i
SplitSfcResponse splitSfcResponse = splitSfcResponses . iterator ( ) . next ( ) ;
String newSfcRef = splitSfcResponse . getNewSfcRef ( ) ;
String newSfc = StringUtil . trimHandle ( newSfcRef ) ;
if ( abnormalMethod . equals ( "F" ) & & StringUtil . notBlank ( routerBo ) ) {
//记录不合格
CreateNCRequest createNCRequest = new CreateNCRequest ( ) ;
createNCRequest . setQty ( splitQty ) ;
createNCRequest . setSfcRef ( newSfcRef ) ;
ProductionContext productionContext = new ProductionContext ( ) ;
StepIdentifier stepIdentifier = new StepIdentifier ( ) ;
stepIdentifier . setStepId ( sfcData . getStepId ( ) ) ;
stepIdentifier . setOperationId ( sfcData . getOperation ( ) ) ;
productionContext . setStepIdentifier ( stepIdentifier ) ;
String resrceBo = commonService . getResrceByOperation ( operation ) ;
productionContext . setResourceRef ( resrceBo ) ;
createNCRequest . setProdCtx ( productionContext ) ;
createNCRequest . setNcCodeRef ( HandleEnum . NC_CODE . getHandle ( site , splitNcCode [ 0 ] ) ) ;
ncProductionService . createNC ( createNCRequest ) ;
//不合格处置特殊工艺路线
DispositionMultipleSfcsRequest dispositionSfcsRequest = new DispositionMultipleSfcsRequest ( ) ;
List < String > sfcs = new ArrayList < > ( ) ;
sfcs . add ( newSfcRef ) ;
dispositionSfcsRequest . setSfcs ( sfcs ) ;
dispositionSfcsRequest . setBypassStepValidation ( true ) ;
DispositionSelection dispositionSelection = new DispositionSelection ( ) ;
Router maxRevisionRouter = routerService . getMaxRevisionRouter ( site , StringUtil . trimHandle ( routerBo ) ) ;
dispositionSelection . setRouterRef ( maxRevisionRouter . getHandle ( ) ) ;
dispositionSfcsRequest . setDispositionSelection ( dispositionSelection ) ;
dispositionSfcsRequest . setProdCtx ( new ProductionContext ( ) ) ;
ncProductionService . dispositionMultipleSfcs ( dispositionSfcsRequest ) ;
List < RouterStepDto > routerOperationByRouterBo = routerStepService . findRouterOperationByRouterBo ( site , maxRevisionRouter . getHandle ( ) ) ;
if ( routerOperationByRouterBo . isEmpty ( ) ) {
throw new BaseException ( "处置工艺路线没有步骤" ) ;
}
sfcDispatchCommonService . saveSplitSfcDispatch ( site , CommonMethods . getUser ( ) , "R" , sfcData . getShopOrder ( ) , sfc , operation , sfcDispatchBySfc . getStepId ( ) , newSfc , maxRevisionRouter . getHandle ( ) , sfcData . getStepSequence ( ) ) ;
if ( isComplete ) {
//修改状态
updateStatus ( site , handle , HandleEnum . STATUS . getHandle ( site , "405" ) ) ;
splitSfcMapper . updateSfcRouterInUse ( sfcRouterRef , "false" , "true" ) ;
//Operation currentRevisionRef = operationService.getCurrentRevisionRef(site, operation);
//sfcCrossService.passAction(site,currentRevisionRef.getHandle(),resrce,handle,null);
//修改库存数量
commonService . updateInventory ( site , sfc , qty . subtract ( splitQty ) ) ;
}
if ( abnormalMethod . equals ( "F" ) & & StringUtil . notBlank ( routerBo ) ) {
//记录不合格和处置
recordNc ( site , shopOrder , sfc , operation , stepId , newSfc , stepSequence , splitQty , newSfcRef , splitNcCode , routerBo ) ;
}
//创建专检任务
Map < String , Object > paramMap = new HashMap < > ( ) ;
paramMap . put ( "CATEGORY" , Constants . INSPECTION_TYPE_P ) ;
@ -286,4 +314,61 @@ public class SplitSfcServiceImpl extends ServiceImpl<SplitSfcMapper, SplitSfc> i
return null ;
}
private void updateStatus ( String site , String sfcBo , String statusBo ) throws Exception {
SfcStateServiceInterface sfcStateServiceInterface = MEServices . create ( "com.sap.me.production" , "SfcStateService" , site ) ;
UpdateSfcStatusRequest updateSfcStatusRequest = new UpdateSfcStatusRequest ( ) ;
updateSfcStatusRequest . setSfcRef ( sfcBo ) ;
updateSfcStatusRequest . setStatusRef ( statusBo ) ;
sfcStateServiceInterface . updateSfcStatus ( updateSfcStatusRequest ) ;
}
private void placeInQueueAtStep ( String site , String sfcRef , String routerRef , String operationRef , String sfcRouterRef , BigDecimal qty , String stepId ) throws Exception {
SfcRoutingServiceInterface sfcRoutingService = MEServices . create ( "com.sap.me.production" , "SfcRoutingService" , site ) ;
PlaceInQueueAtStepRequest request = new PlaceInQueueAtStepRequest ( ) ;
request . setSfcRef ( sfcRef ) ;
request . setPlacementRouterRef ( routerRef ) ;
request . setPlacementOperationRef ( operationRef ) ;
request . setOperationSelectionType ( OperationSelectionType . CURRENT_OPERATION ) ;
request . setPlacementSfcRouterRef ( sfcRouterRef ) ;
request . setQuantity ( qty ) ;
request . setPlacementStepId ( stepId ) ;
sfcRoutingService . placeInQueueAtStep ( request ) ;
}
private void recordNc ( String site , String shopOrder , String sfc , String operation , String stepId , String newSfc , String stepSequence , BigDecimal splitQty , String newSfcRef , String [ ] splitNcCode , String routerBo ) throws Exception {
NCProductionServiceInterface ncProductionService = MEServices . create ( "com.sap.me.nonconformance" , "NCProductionService" , site ) ;
//记录不合格
CreateNCRequest createNCRequest = new CreateNCRequest ( ) ;
createNCRequest . setQty ( splitQty ) ;
createNCRequest . setSfcRef ( newSfcRef ) ;
ProductionContext productionContext = new ProductionContext ( ) ;
StepIdentifier stepIdentifier = new StepIdentifier ( ) ;
stepIdentifier . setStepId ( stepId ) ;
stepIdentifier . setOperationId ( operation ) ;
productionContext . setStepIdentifier ( stepIdentifier ) ;
String resrceBo = commonService . getResrceByOperation ( operation ) ;
productionContext . setResourceRef ( resrceBo ) ;
createNCRequest . setProdCtx ( productionContext ) ;
createNCRequest . setNcCodeRef ( HandleEnum . NC_CODE . getHandle ( site , splitNcCode [ 0 ] ) ) ;
ncProductionService . createNC ( createNCRequest ) ;
//不合格处置特殊工艺路线
DispositionMultipleSfcsRequest dispositionSfcsRequest = new DispositionMultipleSfcsRequest ( ) ;
List < String > sfcs = new ArrayList < > ( ) ;
sfcs . add ( newSfcRef ) ;
dispositionSfcsRequest . setSfcs ( sfcs ) ;
dispositionSfcsRequest . setBypassStepValidation ( true ) ;
DispositionSelection dispositionSelection = new DispositionSelection ( ) ;
Router maxRevisionRouter = routerService . getMaxRevisionRouter ( site , StringUtil . trimHandle ( routerBo ) ) ;
dispositionSelection . setRouterRef ( maxRevisionRouter . getHandle ( ) ) ;
dispositionSfcsRequest . setDispositionSelection ( dispositionSelection ) ;
dispositionSfcsRequest . setProdCtx ( new ProductionContext ( ) ) ;
ncProductionService . dispositionMultipleSfcs ( dispositionSfcsRequest ) ;
List < RouterStepDto > routerOperationByRouterBo = routerStepService . findRouterOperationByRouterBo ( site , maxRevisionRouter . getHandle ( ) ) ;
if ( routerOperationByRouterBo . isEmpty ( ) ) {
throw new BaseException ( "处置工艺路线没有步骤" ) ;
}
sfcDispatchCommonService . saveSplitSfcDispatch ( site , CommonMethods . getUser ( ) , "R" , shopOrder , sfc , operation , stepId , newSfc , maxRevisionRouter . getHandle ( ) , stepSequence ) ;
}
}