@ -14,13 +14,9 @@ import com.hw.mes.api.domain.MesBaseBarcodeInfo;
import com.hw.mes.api.domain.MesBaseMaterialInfo ;
import com.hw.mes.domain.MesOrderBind ;
import com.hw.mes.domain.MesSaleOrder ;
import com.hw.mes.mapper.MesBaseBarcodeInfoMapper ;
import com.hw.mes.mapper.MesBaseMaterialInfoMapper ;
import com.hw.mes.mapper.MesSaleOrderMapper ;
import com.hw.mes.service.IMesBaseMaterialInfoService ;
import com.hw.mes.mapper.* ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
import com.hw.mes.mapper.MesPurchaseOrderMapper ;
import com.hw.mes.domain.MesPurchaseOrder ;
import com.hw.mes.service.IMesPurchaseOrderService ;
import org.springframework.transaction.annotation.Transactional ;
@ -45,6 +41,9 @@ public class MesPurchaseOrderServiceImpl implements IMesPurchaseOrderService {
@Autowired
private MesSaleOrderMapper mesSaleOrderMapper ;
@Autowired
private MesOrderBindMapper mesOrderBindMapper ;
/ * *
* 查 询 采 购 订 单 信 息
*
@ -237,13 +236,13 @@ public class MesPurchaseOrderServiceImpl implements IMesPurchaseOrderService {
/ * *
* 保 存 销 售 订 单 绑 定 采 购 订 单
* @param saleOrderId
* @param purchaseOrderIds
* @param purchaseOrderList
* @return
* /
@Override
public int saveSalesBindPurchase ( Long saleOrderId , Long [ ] purchaseOrderIds ) {
List < MesOrderBind > orderBindList = new ArrayList < > ( ) ;
@Transactional ( rollbackFor = ServiceException . class )
public int saveSalesBindPurchase ( List < MesPurchaseOrder > purchaseOrderList ) {
Long saleOrderId = purchaseOrderList . get ( 0 ) . getSaleOrderId ( ) ;
if ( StringUtils . isNull ( saleOrderId ) ) {
return 0 ;
}
@ -254,41 +253,69 @@ public class MesPurchaseOrderServiceImpl implements IMesPurchaseOrderService {
String productName = mesSaleOrder . getMaterialName ( ) ;
Date currentDate = new Date ( ) ;
String userName = SecurityUtils . getUsername ( ) ;
for ( Long purchaseOrderId : purchaseOrderIds ) {
MesOrderBind orderBind = new MesOrderBind ( ) ;
MesPurchaseOrder mesPurchaseOrder = mesPurchaseOrderMapper . selectMesPurchaseOrderByPurchaseOrderId ( purchaseOrderId ) ;
Long materialId = mesPurchaseOrder . getMaterialId ( ) ;
String materialCode = mesPurchaseOrder . getMaterialCode ( ) ;
String materialName = mesPurchaseOrder . getMaterialName ( ) ;
String poNo = mesPurchaseOrder . getPoNo ( ) ;
BigDecimal orderAmount = mesPurchaseOrder . getOrderAmount ( ) ;
orderBind . setSafeFlag ( MesConstants . MES_ORDER_BIND_SAFE_FLAG_NO ) ;
orderBind . setSaleOrderId ( saleOrderId ) ;
orderBind . setSaleOrderCode ( saleorderCode ) ;
orderBind . setProductId ( productId ) ;
orderBind . setProductCode ( productCode ) ;
orderBind . setProductName ( productName ) ;
orderBind . setPurchaseOrderId ( purchaseOrderId ) ;
orderBind . setMaterialId ( materialId ) ;
orderBind . setMaterialCode ( materialCode ) ;
orderBind . setMaterialName ( materialName ) ;
orderBind . setBindAmount ( orderAmount ) ;
orderBind . setPoNo ( poNo ) ;
orderBind . setCreateTime ( currentDate ) ;
orderBind . setCreateBy ( userName ) ;
orderBindList . add ( orderBind ) ;
for ( MesPurchaseOrder purchaseOrder : purchaseOrderList ) {
Long purchaseOrderId = purchaseOrder . getPurchaseOrderId ( ) ;
MesOrderBind selectOrderBind = new MesOrderBind ( ) ;
selectOrderBind . setSafeFlag ( MesConstants . MES_ORDER_BIND_SAFE_FLAG_NO ) ;
selectOrderBind . setSaleOrderId ( saleOrderId ) ;
selectOrderBind . setPurchaseOrderId ( purchaseOrderId ) ;
List < MesOrderBind > bindList = mesOrderBindMapper . selectMesOrderBindList ( selectOrderBind ) ;
if ( bindList . size ( ) = = 0 ) {
MesOrderBind orderBind = new MesOrderBind ( ) ;
MesPurchaseOrder mesPurchaseOrder = mesPurchaseOrderMapper . selectMesPurchaseOrderByPurchaseOrderId ( purchaseOrderId ) ;
Long materialId = mesPurchaseOrder . getMaterialId ( ) ;
String materialCode = mesPurchaseOrder . getMaterialCode ( ) ;
String materialName = mesPurchaseOrder . getMaterialName ( ) ;
String poNo = mesPurchaseOrder . getPoNo ( ) ;
BigDecimal orderAmount = mesPurchaseOrder . getOrderAmount ( ) ;
orderBind . setSafeFlag ( MesConstants . MES_ORDER_BIND_SAFE_FLAG_NO ) ;
orderBind . setSaleOrderId ( saleOrderId ) ;
orderBind . setSaleOrderCode ( saleorderCode ) ;
orderBind . setProductId ( productId ) ;
orderBind . setProductCode ( productCode ) ;
orderBind . setProductName ( productName ) ;
orderBind . setPurchaseOrderId ( purchaseOrderId ) ;
orderBind . setMaterialId ( materialId ) ;
orderBind . setMaterialCode ( materialCode ) ;
orderBind . setMaterialName ( materialName ) ;
orderBind . setBindAmount ( purchaseOrder . getSaleBindAmount ( ) ) ;
orderBind . setPoNo ( poNo ) ;
orderBind . setCreateTime ( currentDate ) ;
orderBind . setCreateBy ( userName ) ;
mesOrderBindMapper . insertMesOrderBind ( orderBind ) ;
} else {
MesOrderBind bind = bindList . get ( 0 ) ;
bind . setBindAmount ( purchaseOrder . getSaleBindAmount ( ) ) ;
bind . setUpdateBy ( SecurityUtils . getUsername ( ) ) ;
bind . setUpdateTime ( DateUtils . getNowDate ( ) ) ;
mesOrderBindMapper . updateMesOrderBind ( bind ) ;
}
}
return mesPurchaseOrderMapper . batchMesOrderBind ( orderBindList ) ;
return 1 ;
}
/ * *
* 删 除 销 售 订 单 绑 定 采 购 订 单
* @param orderBindIds
*
* @param saleOrderId
* @param purchaseOrderIds
* @return
* /
@Override
public int removeSalesBindPurchase ( Long [ ] orderBindIds ) {
@Transactional ( rollbackFor = ServiceException . class )
public int removeSalesBindPurchase ( Long saleOrderId , Long [ ] purchaseOrderIds ) {
List < Long > list = new ArrayList < > ( ) ;
for ( Long purchaseOrderId : purchaseOrderIds ) {
MesOrderBind selectOrderBind = new MesOrderBind ( ) ;
selectOrderBind . setSafeFlag ( MesConstants . MES_ORDER_BIND_SAFE_FLAG_NO ) ;
selectOrderBind . setSaleOrderId ( saleOrderId ) ;
selectOrderBind . setPurchaseOrderId ( purchaseOrderId ) ;
List < MesOrderBind > bindList = mesOrderBindMapper . selectMesOrderBindList ( selectOrderBind ) ;
if ( bindList . size ( ) > 0 ) {
list . add ( bindList . get ( 0 ) . getOrderBindId ( ) ) ;
}
}
Long [ ] orderBindIds = list . toArray ( new Long [ 0 ] ) ;
return mesPurchaseOrderMapper . deleteMesOrderBindByOrderBindIds ( orderBindIds ) ;
}