@@ -14,10 +14,16 @@ import com.klp.domain.bo.WmsMaterialCoilBo;
import com.klp.domain.vo.WmsCoilPackingDetailVo ;
import com.klp.domain.vo.WmsMaterialCoilVo ;
import com.klp.domain.WmsCoilPackingDetail ;
import com.klp.domain.WmsCoilPackingRecord ;
import com.klp.domain.WmsMaterialCoil ;
import com.klp.mapper.WmsCoilPackingDetailMapper ;
import com.klp.mapper.WmsCoilPackingRecordMapper ;
import com.klp.mapper.WmsMaterialCoilMapper ;
import com.klp.service.IWmsCoilPackingDetailService ;
import com.klp.service.IWmsMaterialCoilService ;
import org.springframework.transaction.annotation.Transactional ;
import java.math.BigDecimal ;
import java.util.* ;
import java.util.stream.Collectors ;
@@ -33,6 +39,8 @@ public class WmsCoilPackingDetailServiceImpl implements IWmsCoilPackingDetailSer
private final WmsCoilPackingDetailMapper baseMapper ;
private final IWmsMaterialCoilService iWmsMaterialCoilService ;
private final WmsCoilPackingRecordMapper recordMapper ;
private final WmsMaterialCoilMapper coilMapper ;
/**
* 查询钢卷打包明细(存储每个钢卷的库区/重量信息)
@@ -49,11 +57,11 @@ public class WmsCoilPackingDetailServiceImpl implements IWmsCoilPackingDetailSer
public TableDataInfo < WmsCoilPackingDetailVo > queryPageList ( WmsCoilPackingDetailBo bo , PageQuery pageQuery ) {
LambdaQueryWrapper < WmsCoilPackingDetail > lqw = buildQueryWrapper ( bo ) ;
Page < WmsCoilPackingDetailVo > result = baseMapper . selectVoPage ( pageQuery . build ( ) , lqw ) ;
if ( result . getRecords ( ) ! = null & & ! result . getRecords ( ) . isEmpty ( ) ) {
enrichCoilInfo ( result . getRecords ( ) ) ;
}
return TableDataInfo . build ( result ) ;
}
@@ -64,11 +72,11 @@ public class WmsCoilPackingDetailServiceImpl implements IWmsCoilPackingDetailSer
public List < WmsCoilPackingDetailVo > queryList ( WmsCoilPackingDetailBo bo ) {
LambdaQueryWrapper < WmsCoilPackingDetail > lqw = buildQueryWrapper ( bo ) ;
List < WmsCoilPackingDetailVo > list = baseMapper . selectVoList ( lqw ) ;
if ( list ! = null & & ! list . isEmpty ( ) ) {
enrichCoilInfo ( list ) ;
}
return list ;
}
@@ -78,18 +86,18 @@ public class WmsCoilPackingDetailServiceImpl implements IWmsCoilPackingDetailSer
. filter ( Objects : : nonNull )
. distinct ( )
. collect ( Collectors . toList ( ) ) ;
if ( coilIds . isEmpty ( ) ) {
return ;
}
WmsMaterialCoilBo coilBo = new WmsMaterialCoilBo ( ) ;
coilBo . setCoilIds ( StringUtils . join ( coilIds , " , " ) ) ;
List < WmsMaterialCoilVo > coilVoList = iWmsMaterialCoilService . queryList ( coilBo ) ;
Map < Long , WmsMaterialCoilVo > coilMap = coilVoList . stream ( )
. collect ( Collectors . toMap ( WmsMaterialCoilVo : : getCoilId , v - > v , ( a , b ) - > a ) ) ;
for ( WmsCoilPackingDetailVo detailVo : detailVos ) {
detailVo . setCoil ( coilMap . get ( detailVo . getCoilId ( ) ) ) ;
}
@@ -111,13 +119,40 @@ public class WmsCoilPackingDetailServiceImpl implements IWmsCoilPackingDetailSer
* 新增钢卷打包明细(存储每个钢卷的库区/重量信息)
*/
@Override
@Transactional ( rollbackFor = Exception . class )
public Boolean insertByBo ( WmsCoilPackingDetailBo bo ) {
Long packingId = bo . getPackingId ( ) ;
if ( packingId = = null ) {
throw new RuntimeException ( " 打包主表ID不能为空 " ) ;
}
Long coilId = bo . getCoilId ( ) ;
WmsMaterialCoil coil = coilMapper . selectById ( coilId ) ;
if ( coil = = null ) {
throw new RuntimeException ( " 钢卷不存在, coilId: " + coilId ) ;
}
bo . setFromWarehouseId ( coil . getWarehouseId ( ) ) ;
bo . setCoilGrossWeight ( coil . getGrossWeight ( ) ) ;
bo . setCoilNetWeight ( coil . getNetWeight ( ) ) ;
WmsCoilPackingDetail add = BeanUtil . toBean ( bo , WmsCoilPackingDetail . class ) ;
validEntityBeforeSave ( add ) ;
boolean flag = baseMapper . insert ( add ) > 0 ;
if ( flag ) {
bo . setDetailId ( add . getDetailId ( ) ) ;
updateRecordWeight ( packingId ) ;
WmsMaterialCoil updateCoil = new WmsMaterialCoil ( ) ;
updateCoil . setCoilId ( coilId ) ;
updateCoil . setWarehouseId ( bo . getToWarehouseId ( ) ) ;
if ( StringUtils . isNotBlank ( bo . getSaleName ( ) ) ) {
updateCoil . setSaleName ( bo . getSaleName ( ) ) ;
}
coilMapper . updateById ( updateCoil ) ;
}
return flag ;
}
@@ -125,27 +160,91 @@ public class WmsCoilPackingDetailServiceImpl implements IWmsCoilPackingDetailSer
* 修改钢卷打包明细(存储每个钢卷的库区/重量信息)
*/
@Override
@Transactional ( rollbackFor = Exception . class )
public Boolean updateByBo ( WmsCoilPackingDetailBo bo ) {
Long packingId = bo . getPackingId ( ) ;
if ( packingId = = null ) {
throw new RuntimeException ( " 打包主表ID不能为空 " ) ;
}
// coilId不能为null
if ( bo . getCoilId ( ) = = null ) {
throw new RuntimeException ( " 钢卷ID不能为空 " ) ;
}
WmsCoilPackingDetail update = BeanUtil . toBean ( bo , WmsCoilPackingDetail . class ) ;
validEntityBeforeSave ( update ) ;
return baseMapper . updateById ( update ) > 0 ;
boolean flag = baseMapper . updateById ( update ) > 0 ;
if ( flag ) {
updateRecordWeight ( packingId ) ;
WmsMaterialCoil updateCoil = new WmsMaterialCoil ( ) ;
updateCoil . setCoilId ( bo . getCoilId ( ) ) ;
updateCoil . setWarehouseId ( bo . getToWarehouseId ( ) ) ;
if ( StringUtils . isNotBlank ( bo . getSaleName ( ) ) ) {
updateCoil . setSaleName ( bo . getSaleName ( ) ) ;
}
coilMapper . updateById ( updateCoil ) ;
}
return flag ;
}
/**
* 保存前的数据校验
*/
private void validEntityBeforeSave ( WmsCoilPackingDetail entity ) {
//TODO 做一些数据校验,如唯一约束
}
/**
* 批量删除钢卷打包明细(存储每个钢卷的库区/重量信息)
*/
@Override
@Transactional ( rollbackFor = Exception . class )
public Boolean deleteWithValidByIds ( Collection < Long > ids , Boolean isValid ) {
if ( isValid ) {
//TODO 做一些业务上的校验,判断是否需要校验
if ( isValid ) {
}
List < WmsCoilPackingDetail > details = baseMapper . selectBatchIds ( ids ) ;
if ( details . isEmpty ( ) ) {
return false ;
}
Set < Long > packingIds = new HashSet < > ( ) ;
for ( WmsCoilPackingDetail detail : details ) {
packingIds . add ( detail . getPackingId ( ) ) ;
}
boolean flag = baseMapper . deleteBatchIds ( ids ) > 0 ;
if ( flag ) {
for ( Long packingId : packingIds ) {
updateRecordWeight ( packingId ) ;
}
}
return flag ;
}
private void updateRecordWeight ( Long packingId ) {
LambdaQueryWrapper < WmsCoilPackingDetail > lqw = Wrappers . lambdaQuery ( ) ;
lqw . eq ( WmsCoilPackingDetail : : getPackingId , packingId ) ;
List < WmsCoilPackingDetail > details = baseMapper . selectList ( lqw ) ;
BigDecimal totalGrossWeight = BigDecimal . ZERO ;
BigDecimal totalNetWeight = BigDecimal . ZERO ;
for ( WmsCoilPackingDetail detail : details ) {
totalGrossWeight = totalGrossWeight . add ( detail . getCoilGrossWeight ( ) ! = null ? detail . getCoilGrossWeight ( ) : BigDecimal . ZERO ) ;
totalNetWeight = totalNetWeight . add ( detail . getCoilNetWeight ( ) ! = null ? detail . getCoilNetWeight ( ) : BigDecimal . ZERO ) ;
}
WmsCoilPackingRecord record = recordMapper . selectById ( packingId ) ;
if ( record ! = null ) {
record . setCoilCount ( ( long ) details . size ( ) ) ;
record . setTotalGrossWeight ( totalGrossWeight ) ;
record . setTotalNetWeight ( totalNetWeight ) ;
recordMapper . updateById ( record ) ;
}
return baseMapper . deleteBatchIds ( ids ) > 0 ;
}
}