feat(wms/coil): 新增钢卷理论长度字段并优化理论计算逻辑
1. 在钢卷物料实体类、业务对象、值对象及导出VO中新增理论长度(theoreticalLength)字段,并在映射文件中补充数据库映射关系 2. 重构理论计算工具方法,将原有的calculateTheoreticalThickness方法扩展为calculateTheoretical,支持同时计算理论厚度和理论长度 3. 理论长度计算公式:理论长度 = 净重(吨) × 1000 / 7.85 / 规格厚度(mm) / 规格宽度(mm) / 1000 4. 优化规格信息提取逻辑,统一从物品规格中解析厚度和宽度,避免重复代码 5. 在新增、修改、分卷、批量分卷等业务方法中调用新的计算逻辑,确保理论长度字段的自动填充
This commit is contained in:
@@ -219,6 +219,11 @@ public class WmsMaterialCoil extends BaseEntity {
|
||||
*/
|
||||
private BigDecimal theoreticalThickness;
|
||||
|
||||
/**
|
||||
* 理论长度(单位:米)
|
||||
*/
|
||||
private BigDecimal theoreticalLength;
|
||||
|
||||
/**
|
||||
* 镀铬卷号
|
||||
*/
|
||||
|
||||
@@ -387,6 +387,11 @@ public class WmsMaterialCoilBo extends BaseEntity {
|
||||
*/
|
||||
private BigDecimal theoreticalThickness;
|
||||
|
||||
/**
|
||||
* 理论长度(单位:米)
|
||||
*/
|
||||
private BigDecimal theoreticalLength;
|
||||
|
||||
/**
|
||||
* 镀铬卷号
|
||||
*/
|
||||
|
||||
@@ -215,6 +215,12 @@ public class WmsMaterialCoilExportVo {
|
||||
@ExcelProperty(value = "理论厚度")
|
||||
private BigDecimal theoreticalThickness;
|
||||
|
||||
/**
|
||||
* 理论长度(单位:米)
|
||||
*/
|
||||
@ExcelProperty(value = "理论长度")
|
||||
private BigDecimal theoreticalLength;
|
||||
|
||||
/**
|
||||
* 镀铬卷号
|
||||
*/
|
||||
|
||||
@@ -345,6 +345,11 @@ public class WmsMaterialCoilVo extends BaseEntity {
|
||||
*/
|
||||
private BigDecimal theoreticalThickness;
|
||||
|
||||
/**
|
||||
* 理论长度(单位:米)
|
||||
*/
|
||||
private BigDecimal theoreticalLength;
|
||||
|
||||
/**
|
||||
* 镀铬卷号
|
||||
*/
|
||||
|
||||
@@ -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.setTheoreticalThickness(theoretical);
|
||||
BigDecimal volume = weight.multiply(new BigDecimal("1000")).divide(new BigDecimal("7.85"), 10, RoundingMode.HALF_UP);
|
||||
|
||||
// 计算理论厚度(需要实测长度)
|
||||
if (bo.getTheoreticalThickness() == 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); // 当前数据
|
||||
|
||||
@@ -43,6 +43,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="specId" column="spec_id"/>
|
||||
<result property="versionId" column="version_id"/>
|
||||
<result property="theoreticalThickness" column="theoretical_thickness"/>
|
||||
<result property="theoreticalLength" column="theoretical_length"/>
|
||||
<result property="chromePlateCoilNo" column="chrome_plate_coil_no"/>
|
||||
|
||||
</resultMap>
|
||||
@@ -131,6 +132,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
mc.exclusive_status,
|
||||
mc.transfer_type,
|
||||
mc.theoretical_thickness,
|
||||
mc.theoretical_length,
|
||||
mc.chrome_plate_coil_no,
|
||||
mc.sale_name AS saleName,
|
||||
w.warehouse_name AS warehouseName,
|
||||
@@ -230,6 +232,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
mc.exclusive_status,
|
||||
mc.transfer_type,
|
||||
mc.theoretical_thickness,
|
||||
mc.theoretical_length,
|
||||
mc.chrome_plate_coil_no,
|
||||
mc.sale_name AS saleName,
|
||||
su.nick_name AS saleNickName,
|
||||
@@ -562,6 +565,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
mc.transfer_type AS transferType,
|
||||
-- 理论厚度
|
||||
mc.theoretical_thickness AS theoreticalThickness,
|
||||
-- 理论长度
|
||||
mc.theoretical_length AS theoreticalLength,
|
||||
-- 镀铬卷号
|
||||
mc.chrome_plate_coil_no AS chromePlateCoilNo,
|
||||
-- 库存状态(中文显示)
|
||||
@@ -652,6 +657,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
mc.sale_name AS saleName,
|
||||
mc.transfer_type AS transferType,
|
||||
mc.theoretical_thickness AS theoreticalThickness,
|
||||
mc.theoretical_length AS theoreticalLength,
|
||||
mc.chrome_plate_coil_no AS chromePlateCoilNo,
|
||||
CASE
|
||||
WHEN mc.status = 0 THEN '在库'
|
||||
@@ -772,6 +778,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
mc.sale_name AS saleName,
|
||||
mc.transfer_type AS transferType,
|
||||
mc.theoretical_thickness AS theoreticalThickness,
|
||||
mc.theoretical_length AS theoreticalLength,
|
||||
mc.chrome_plate_coil_no AS chromePlateCoilNo,
|
||||
CASE
|
||||
WHEN mc.status = 0 THEN '在库'
|
||||
|
||||
Reference in New Issue
Block a user