@ -6,10 +6,15 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page ;
import com.gaotao.common.utils.PageUtils ;
import com.gaotao.common.utils.R ;
import com.gaotao.modules.api.entity.IfsInventoryPart ;
import com.gaotao.modules.api.service.IfsApiIssueAndReturnService ;
import com.gaotao.modules.base.entity.SOScheduledRoutingData ;
import com.gaotao.modules.notify.entity.* ;
import com.gaotao.modules.notify.entity.dto.GroupKey ;
import com.gaotao.modules.notify.entity.dto.NewUnissueNotifyDto ;
import com.gaotao.modules.notify.entity.dto.ShoporderAndMaterialDto ;
import com.gaotao.modules.notify.entity.dto.UnissueNotifyHeadDataDto ;
import com.gaotao.modules.notify.entity.vo.ShopOrderAndMaterialVo ;
import com.gaotao.modules.notify.entity.vo.ShopOrderMaterialVo ;
import com.gaotao.modules.notify.entity.vo.ShopOrderVo ;
import com.gaotao.modules.notify.mapper.UnissueNotifyHeaderMapper ;
@ -21,6 +26,7 @@ import com.gaotao.modules.sys.entity.SysUserEntity;
import com.gaotao.modules.trans.entity.TransNoControl ;
import com.gaotao.modules.trans.service.TransNoControlService ;
import org.apache.shiro.SecurityUtils ;
import org.springframework.beans.BeanUtils ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Transactional ;
@ -29,9 +35,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody ;
import java.math.BigDecimal ;
import java.util.Date ;
import java.util.List ;
import java.util.Set ;
import java.util.* ;
import java.util.stream.Collectors ;
@Service
@ -239,5 +243,143 @@ public class UnissueNotifyHeaderServiceImpl implements UnissueNotifyHeaderServic
return i ;
}
@Override
public List < ShopOrderAndMaterialVo > getUnissueShopOrderAndMaterialByShoporder ( UnissueNotifyHeadDataDto data ) throws Exception {
List < ShopOrderVo > orderInfo = ifsApiIssueAndReturnService . getWorkOrderInfo ( data . getOrderNo ( ) , data . getSite ( ) , data . getReleaseNo ( ) , data . getSequenceNo ( ) ) ;
List < ShopOrderVo > shopOrderVos = orderInfo . stream ( )
. filter ( so - > "Started" . equalsIgnoreCase ( so . getObjstate ( ) ) )
. toList ( ) ;
if ( orderInfo . size ( ) > 0 & & shopOrderVos . size ( ) = = 0 ) {
throw new Exception ( "生产订单" + data . getOrderNo ( ) + "状态不允许发货,请检查!" ) ;
}
if ( shopOrderVos ! = null & & shopOrderVos . size ( ) > 0 ) {
List < ShopOrderAndMaterialVo > orderAndMaterialVos = new ArrayList < > ( ) ;
List < ShopOrderMaterialVo > materialVos = ifsApiIssueAndReturnService . getShopOrderMaterial ( data . getOrderNo ( ) , data . getSite ( ) , data . getReleaseNo ( ) , data . getSequenceNo ( ) ) ;
List < ShopOrderMaterialVo > shopOrderMaterial = materialVos . stream ( ) . filter ( m - > "Reserve And Backflush" . equals ( m . getReserveIssueMethod ( ) ) ) . collect ( Collectors . toList ( ) ) ;
for ( ShopOrderMaterialVo shopOrderVo : shopOrderMaterial ) {
ShopOrderAndMaterialVo vo = new ShopOrderAndMaterialVo ( ) ;
BeanUtils . copyProperties ( shopOrderVo , vo ) ;
vo . setStatus ( shopOrderVos . get ( 0 ) . getStatus ( ) ) ;
vo . setPartNo ( shopOrderVos . get ( 0 ) . getPartNo ( ) ) ;
vo . setPartDesc ( shopOrderVos . get ( 0 ) . getPartDesc ( ) ) ;
vo . setLotSize ( shopOrderVos . get ( 0 ) . getLotSize ( ) ) ;
vo . setStartDate ( shopOrderVos . get ( 0 ) . getStartDate ( ) ) ;
vo . setFinishDate ( shopOrderVos . get ( 0 ) . getFinishDate ( ) ) ;
vo . setNeedDate ( shopOrderVos . get ( 0 ) . getNeedDate ( ) ) ;
vo . setCloseCode ( shopOrderVos . get ( 0 ) . getCloseCode ( ) ) ;
vo . setCloseTolerance ( shopOrderVos . get ( 0 ) . getCloseTolerance ( ) ) ;
vo . setQtyComplete ( shopOrderVos . get ( 0 ) . getQtyComplete ( ) ) ;
vo . setObjstate ( shopOrderVos . get ( 0 ) . getObjstate ( ) ) ;
vo . setCloseCodeDb ( shopOrderVos . get ( 0 ) . getCloseCodeDb ( ) ) ;
orderAndMaterialVos . add ( vo ) ;
}
return orderAndMaterialVos ;
}
return null ;
}
@Override
public String saveNewUnissueNotifyOrderList ( NewUnissueNotifyDto data ) throws Exception {
if ( data . getMaterialList ( ) ! = null & & data . getMaterialList ( ) . size ( ) > 0 ) {
Map < GroupKey , List < ShoporderAndMaterialDto > > mainGroupMap = data . getMaterialList ( ) . stream ( )
. collect ( Collectors . groupingBy (
dto - > new GroupKey (
dto . getOrderNo ( ) ,
dto . getReleaseNo ( ) ,
dto . getSequenceNo ( )
)
) ) ;
/ / 用于存储最终结果 : 父集合和子集合
List < UnissueNotifyOrderList > parentList = new ArrayList < > ( ) ;
List < UnissueNotifyOrderMaterialList > childList = new ArrayList < > ( ) ;
int num = 0 ;
BigDecimal nextItem = BigDecimal . ZERO ;
/ / 步骤2 : 遍历每个分组 , 生成父对象和子对象
for ( Map . Entry < GroupKey , List < ShoporderAndMaterialDto > > entry : mainGroupMap . entrySet ( ) ) {
GroupKey groupKey = entry . getKey ( ) ;
List < ShoporderAndMaterialDto > groupDtos = entry . getValue ( ) ;
/ / 2 . 1 生成父对象的唯一 itemNo ( 确保全局唯一 , 这里用 UUID 简化 )
if ( num = = 0 ) {
UnissueNotifyOrderList parentData = new UnissueNotifyOrderList ( ) ;
parentData . setSite ( data . getSite ( ) ) ;
parentData . setNotifyNo ( data . getNotifyNo ( ) ) ;
nextItem = unissueNotifyHeaderMapper . getNextItemForUnissueNotifyOrderList ( parentData ) ;
} else {
nextItem = nextItem . add ( BigDecimal . ONE ) ;
}
/ / 2 . 2 构建SOIssueNotifyOrderList
UnissueNotifyOrderList parent = buildParent ( data . getNotifyNo ( ) , data . getSite ( ) , groupKey , groupDtos , nextItem ) ;
parentList . add ( parent ) ;
/ / 2 . 3 遍历分组内的 dto , 按 lineItemNo 生成子对象 ( SOIssueNotifyOrderMaterialList )
List < UnissueNotifyOrderMaterialList > children = buildChildren ( data . getNotifyNo ( ) , data . getSite ( ) , groupDtos , nextItem ) ;
childList . addAll ( children ) ;
num + + ;
}
List < String > items = new ArrayList < > ( ) ;
/ / 保存父类
for ( UnissueNotifyOrderList parentItem : parentList ) {
int i = unissueNotifyHeaderMapper . saveUnissueNotifyOrderList ( parentItem ) ;
items . add ( parentItem . getItemNo ( ) . toString ( ) ) ;
}
/ / 保存子类
unissueNotifyHeaderMapper . deleteUnissueNotifyOrderMaterialInList ( data . getNotifyNo ( ) , data . getSite ( ) , items ) ;
unissueNotifyOrderMaterialListMapper . batchSaveUnissueNotifyOrderMaterialListData ( childList ) ;
return "200" ;
} else {
throw new RuntimeException ( "物料列表不能为空" ) ;
}
}
private static UnissueNotifyOrderList buildParent ( String notifyNo , String site , GroupKey groupKey , List < ShoporderAndMaterialDto > groupDtos , BigDecimal parentItemNo ) {
UnissueNotifyOrderList parent = new UnissueNotifyOrderList ( ) ;
parent . setNotifyNo ( notifyNo ) ;
parent . setSite ( site ) ;
parent . setItemNo ( parentItemNo ) ;
parent . setSoorderNo ( groupKey . getOrderNo ( ) ) ;
parent . setReleaseNo ( groupKey . getReleaseNo ( ) ) ;
parent . setSequenceNo ( groupKey . getSequenceNo ( ) ) ;
/ / 从分组内第一个 dto 提取共同属性 ( 假设同一分组内这些属性一致 )
ShoporderAndMaterialDto firstDto = groupDtos . get ( 0 ) ;
parent . setNeedDate ( new Date ( ) ) ;
return parent ;
}
/ * *
* 构建子对象列表 , 关联父对象的 itemNo
* /
private static List < UnissueNotifyOrderMaterialList > buildChildren ( String notifyNo , String site , List < ShoporderAndMaterialDto > groupDtos , BigDecimal parentItemNo ) {
return groupDtos . stream ( )
. map ( dto - > {
UnissueNotifyOrderMaterialList child = new UnissueNotifyOrderMaterialList ( ) ;
child . setNotifyNo ( notifyNo ) ;
child . setSite ( site ) ;
child . setItemNo ( parentItemNo ) ;
/ / 设置细分核心字段 ( lineItemNo )
child . setBomItemNo ( dto . getLineItemNo ( ) . toString ( ) ) ;
/ / 提取详细属性
child . setComponentPartNo ( dto . getComponentPartNo ( ) ) ;
child . setQtyToUnissue ( dto . getApplyQty ( ) ) ;
if ( dto . getApplyQty ( ) ! = null ) {
child . setQtyToUnissueOriginal ( dto . getApplyQty ( ) ) ;
}
child . setUnissueType ( "BOM物料" ) ;
child . setComponentPartDesc ( dto . getComponentPartDesc ( ) ) ;
return child ;
} )
/ / 按 lineItemNo 排序 ( 可选 , 确保子项顺序 )
. sorted ( Comparator . comparing ( UnissueNotifyOrderMaterialList : : getBomItemNo ) )
. collect ( Collectors . toList ( ) ) ;
}
}