@@ -700,6 +700,8 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
qw . eq ( StringUtils . isNotBlank ( bo . getActualThickness ( ) ) , " mc.actual_thickness " , bo . getActualThickness ( ) ) ;
// 理论厚度
qw . eq ( bo . getTheoreticalThickness ( ) ! = null , " mc.theoretical_thickness " , bo . getTheoreticalThickness ( ) ) ;
// 理论长度
qw . eq ( bo . getTheoreticalLength ( ) ! = null , " mc.theoretical_length " , bo . getTheoreticalLength ( ) ) ;
// 镀铬卷号
qw . like ( StringUtils . isNotBlank ( bo . getChromePlateCoilNo ( ) ) , " mc.chrome_plate_coil_no " , bo . getChromePlateCoilNo ( ) ) ;
// 生产开始时间
@@ -1034,55 +1036,66 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
}
/**
* 根据净重(吨)、实测长度(mm)、物品规格宽度(mm) 自动计算理论厚度(mm)
* 公式: 理论厚度 = 净重(吨) × 1000 / ( 7.85 × 实测长度(mm) × 宽度(mm))
* 根据净重(吨)、规格厚度和宽度 自动计算理论厚度(mm)和理论长度(m)
* 理论厚度 = 净重(吨) × 1000 / 7.85 / 实测长度(mm) / 宽度(mm) / 1000
* 理论长度 = 净重(吨) × 1000 / 7.85 / 厚度(mm) / 宽度(mm) / 1000
*/
private void calculateTheoreticalThickness ( WmsMaterialCoilBo bo ) {
if ( bo . getTheoreticalThickness ( ) ! = null ) {
return ;
}
if ( bo . getNetWeight ( ) = = null | | bo . getActualLength ( ) = = null ) {
private void calculateTheoretical ( WmsMaterialCoilBo bo ) {
if ( bo . getNetWeight ( ) = = null ) {
return ;
}
if ( StringUtils . isBlank ( bo . getItemType ( ) ) | | bo . getItemId ( ) = = null ) {
return ;
}
String specThickness = null ;
String specWidth = null ;
try {
String specification = null ;
if ( " raw_material " . equals ( bo . getItemType ( ) ) ) {
WmsRawMaterial rm = rawMaterialMapper . selectById ( bo . getItemId ( ) ) ;
if ( rm ! = null & & StringUtils . isNotBlank ( rm . getSpecification ( ) ) ) {
String [ ] parts = rm . getSpecification ( ) . split ( " \\ * " ) ;
if ( parts . length > = 2 ) {
specWidth = parts [ parts . length - 1 ] . trim ( ) ;
}
if ( rm ! = null ) {
specification = rm . getSpecification ( ) ;
}
} else if ( " product " . equals ( bo . getItemType ( ) ) ) {
WmsProduct p = productMapper . selectById ( bo . getItemId ( ) ) ;
if ( p ! = null & & StringUtils . isNotBlank ( p . getSpecification ( ) ) ) {
String [ ] parts = p . getSpecification ( ) . split ( " \\ * " ) ;
if ( parts . length > = 2 ) {
specWidth = parts [ parts . length - 1 ] . trim ( ) ;
}
if ( p ! = null ) {
specification = p . getSpecification ( ) ;
}
}
if ( StringUtils . isNotBlank ( specification ) ) {
String [ ] parts = specification . split ( " \\ * " ) ;
if ( parts . length > = 2 ) {
specThickness = parts [ 0 ] . trim ( ) ;
specWidth = parts [ parts . length - 1 ] . trim ( ) ;
}
}
} catch ( Exception e ) {
log . warn ( " 查询物品规格失败, itemType: {}, itemId: {} " , bo . getItemType ( ) , bo . getItemId ( ) , e ) ;
return ;
}
if ( StringUtils . isBlank ( specWidth ) ) {
if ( StringUtils . isBlank ( specThickness ) | | StringUtils . isBlank ( specWidth) ) {
return ;
}
try {
BigDecimal weight = bo . getNetWeight ( ) ;
BigDecimal length = new BigDecimal ( bo . getActualLength ( ) ) ;
BigDecimal thickness = new BigDecimal ( specThickness ) ;
BigDecimal width = new BigDecimal ( specWidth ) ;
BigDecimal numerator = weight . multiply ( new BigDecimal ( " 1000 " ) ) ;
BigDecimal denominator = new BigDecimal ( " 7.85 " ) . multiply ( length ) . multiply ( width ) ;
BigDecimal theoretical = numerator . divide ( denominator , 3 , RoundingMode . HALF_UP ) ;
bo . s etTheoreticalThickness( theoretical ) ;
BigDecimal volume = weight . multiply ( new BigDecimal ( " 1000 " ) ) . divide ( new BigDecimal ( " 7.85 " ) , 10 , RoundingMode . HALF_UP ) ;
// 计算理论厚度(需要实测长度)
if ( bo . g etTheoreticalThickness( ) = = null & & bo . getActualLength ( ) ! = null ) {
BigDecimal length = new BigDecimal ( bo . getActualLength ( ) ) ;
BigDecimal theoreticalThickness = volume . divide ( length , 10 , RoundingMode . HALF_UP ) . divide ( width , 3 , RoundingMode . HALF_UP ) . divide ( new BigDecimal ( " 1000 " ) , 3 , RoundingMode . HALF_UP ) ;
bo . setTheoreticalThickness ( theoreticalThickness ) ;
}
// 计算理论长度
if ( bo . getTheoreticalLength ( ) = = null ) {
BigDecimal theoreticalLength = volume . divide ( thickness , 10 , RoundingMode . HALF_UP ) . divide ( width , 10 , RoundingMode . HALF_UP ) . divide ( new BigDecimal ( " 1000 " ) , 3 , RoundingMode . HALF_UP ) ;
bo . setTheoreticalLength ( theoreticalLength ) ;
}
} catch ( Exception e ) {
log . warn ( " 计算理论厚度失败 " , e ) ;
log . warn ( " 计算理论厚度/长度 失败 " , e ) ;
}
}
@@ -1455,7 +1468,7 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
bo . setActualWarehouseId ( null ) ;
}
// 3. 插入钢卷数据
calculateTheoreticalThickness ( bo ) ;
calculateTheoretical ( bo ) ;
WmsMaterialCoil add = BeanUtil . toBean ( bo , WmsMaterialCoil . class ) ;
if ( bo . getDataType ( ) ! = null & & bo . getDataType ( ) = = 10 ) {
add . setDataType ( 10 ) ;
@@ -1671,7 +1684,7 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
}
}
validateCoilWeight ( bo . getGrossWeight ( ) , bo . getNetWeight ( ) ) ;
calculateTheoreticalThickness ( bo ) ;
calculateTheoretical ( bo ) ;
// 直接更新钢卷属性
WmsMaterialCoil updateCoil = BeanUtil . toBean ( bo , WmsMaterialCoil . class ) ;
validEntityBeforeSave ( updateCoil ) ;
@@ -1765,7 +1778,7 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
baseMapper . update ( null , updateWrapper ) ;
// 2. 创建新记录
calculateTheoreticalThickness ( bo ) ;
calculateTheoretical ( bo ) ;
WmsMaterialCoil newCoil = BeanUtil . toBean ( bo , WmsMaterialCoil . class ) ;
newCoil . setCoilId ( null ) ; // 清空ID, 让数据库自动生成新ID
newCoil . setDataType ( 1 ) ; // 设置为当前数据
@@ -2013,7 +2026,7 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
? newCoilBo . getActualWarehouseId ( ) : null ;
validateActualWarehouseForAssign ( newCoilBo . getActualWarehouseId ( ) , ignoreOccupiedId ) ;
}
calculateTheoreticalThickness ( newCoilBo ) ;
calculateTheoretical ( newCoilBo ) ;
WmsMaterialCoil newCoil = BeanUtil . toBean ( newCoilBo , WmsMaterialCoil . class ) ;
newCoil . setCoilId ( null ) ;
newCoil . setDataType ( 1 ) ;
@@ -2142,7 +2155,7 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
if ( bo . getActualWarehouseId ( ) ! = null ) {
validateActualWarehouseForAssign ( bo . getActualWarehouseId ( ) , null ) ;
}
calculateTheoreticalThickness ( bo ) ;
calculateTheoretical ( bo ) ;
WmsMaterialCoil newCoil = BeanUtil . toBean ( bo , WmsMaterialCoil . class ) ;
newCoil . setCoilId ( null ) ;
newCoil . setDataType ( 1 ) ;
@@ -5000,7 +5013,7 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
}
// 5. 创建子钢卷(参考普通分卷逻辑,但不设置母卷为历史数据)
calculateTheoreticalThickness ( childCoilBo ) ;
calculateTheoretical ( childCoilBo ) ;
WmsMaterialCoil childCoil = BeanUtil . toBean ( childCoilBo , WmsMaterialCoil . class ) ;
childCoil . setCoilId ( null ) ;
childCoil . setDataType ( 1 ) ; // 当前数据