Merge branch 'main' of http://27.223.88.102:33000/chenx/qhmes
This commit is contained in:
@@ -43,6 +43,7 @@ import org.jeecg.modules.xslmes.service.MesXslStompNotifyService;
|
||||
import org.jeecg.modules.xslmes.vo.MesXslRawMaterialCardBriefVO;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@@ -405,12 +406,7 @@ public class MesXslDesktopAnonController {
|
||||
if (oConvertUtils.isEmpty(mesXslWeightRecord.getPlateNumber())) {
|
||||
return Result.error("车牌号不能为空");
|
||||
}
|
||||
// 净重自动计算
|
||||
if (mesXslWeightRecord.getGrossWeight() != null && mesXslWeightRecord.getTareWeight() != null) {
|
||||
mesXslWeightRecord.setNetWeight(
|
||||
mesXslWeightRecord.getGrossWeight().subtract(mesXslWeightRecord.getTareWeight()));
|
||||
}
|
||||
applyWeightBillType(mesXslWeightRecord);
|
||||
applyWeightNetAndBillType(mesXslWeightRecord);
|
||||
applyMaterialTypeDefault(mesXslWeightRecord);
|
||||
weightRecordService.save(mesXslWeightRecord);
|
||||
stompNotify.publishWeightRecordChanged("add", mesXslWeightRecord.getId());
|
||||
@@ -423,12 +419,7 @@ public class MesXslDesktopAnonController {
|
||||
if (oConvertUtils.isEmpty(mesXslWeightRecord.getId())) {
|
||||
return Result.error("主键不能为空");
|
||||
}
|
||||
// 净重自动计算
|
||||
if (mesXslWeightRecord.getGrossWeight() != null && mesXslWeightRecord.getTareWeight() != null) {
|
||||
mesXslWeightRecord.setNetWeight(
|
||||
mesXslWeightRecord.getGrossWeight().subtract(mesXslWeightRecord.getTareWeight()));
|
||||
}
|
||||
applyWeightBillType(mesXslWeightRecord);
|
||||
applyWeightNetAndBillType(mesXslWeightRecord);
|
||||
applyMaterialTypeDefault(mesXslWeightRecord);
|
||||
boolean ok = weightRecordService.updateById(mesXslWeightRecord);
|
||||
if (!ok) {
|
||||
@@ -839,18 +830,47 @@ public class MesXslDesktopAnonController {
|
||||
|
||||
// ─────────────────────────── 车辆私有辅助 ────────────────────────────
|
||||
|
||||
private void applyWeightNetAndBillType(MesXslWeightRecord record) {
|
||||
sanitizeNonPositiveWeightsToNull(record);
|
||||
if (isEffectiveWeight(record.getGrossWeight()) && isEffectiveWeight(record.getTareWeight())) {
|
||||
BigDecimal net = record.getGrossWeight().subtract(record.getTareWeight());
|
||||
record.setNetWeight(net.compareTo(BigDecimal.ZERO) >= 0 ? net : BigDecimal.ZERO);
|
||||
} else {
|
||||
record.setNetWeight(null);
|
||||
}
|
||||
applyWeightBillType(record);
|
||||
}
|
||||
|
||||
/** 将 ≤0 的重量视为未录入,避免 JSON/Numeric 占位 0 被当成已称皮重、误判称重完成 */
|
||||
private static void sanitizeNonPositiveWeightsToNull(MesXslWeightRecord record) {
|
||||
if (record.getGrossWeight() != null && record.getGrossWeight().compareTo(BigDecimal.ZERO) <= 0) {
|
||||
record.setGrossWeight(null);
|
||||
}
|
||||
if (record.getTareWeight() != null && record.getTareWeight().compareTo(BigDecimal.ZERO) <= 0) {
|
||||
record.setTareWeight(null);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isEffectiveWeight(BigDecimal w) {
|
||||
return w != null && w.compareTo(BigDecimal.ZERO) > 0;
|
||||
}
|
||||
|
||||
private void applyWeightBillType(MesXslWeightRecord record) {
|
||||
if (record.getGrossWeight() != null && record.getTareWeight() != null) {
|
||||
boolean g = isEffectiveWeight(record.getGrossWeight());
|
||||
boolean t = isEffectiveWeight(record.getTareWeight());
|
||||
if (g && t) {
|
||||
record.setBillType("2");
|
||||
return;
|
||||
}
|
||||
if (record.getGrossWeight() != null) {
|
||||
if (g) {
|
||||
record.setBillType("1");
|
||||
return;
|
||||
}
|
||||
if (record.getTareWeight() != null) {
|
||||
if (t) {
|
||||
record.setBillType("3");
|
||||
return;
|
||||
}
|
||||
record.setBillType(null);
|
||||
}
|
||||
|
||||
private void applyMaterialTypeDefault(MesXslWeightRecord record) {
|
||||
|
||||
@@ -72,9 +72,9 @@ public class MesXslWeightRecordController extends JeecgController<MesXslWeightRe
|
||||
String seq = String.format("%03d", new Random().nextInt(1000));
|
||||
mesXslWeightRecord.setBillNo("BDH-" + dateStr + seq);
|
||||
}
|
||||
computeBillType(mesXslWeightRecord);
|
||||
applyMaterialTypeDefault(mesXslWeightRecord);
|
||||
computeNetWeight(mesXslWeightRecord);
|
||||
computeBillType(mesXslWeightRecord);
|
||||
mesXslWeightRecordService.save(mesXslWeightRecord);
|
||||
stompNotifyService.publishWeightRecordChanged("add", mesXslWeightRecord.getId());
|
||||
return Result.OK("添加成功!");
|
||||
@@ -85,9 +85,9 @@ public class MesXslWeightRecordController extends JeecgController<MesXslWeightRe
|
||||
@RequiresPermissions("xslmes:mes_xsl_weight_record:edit")
|
||||
@RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
|
||||
public Result<String> edit(@RequestBody MesXslWeightRecord mesXslWeightRecord) {
|
||||
computeBillType(mesXslWeightRecord);
|
||||
applyMaterialTypeDefault(mesXslWeightRecord);
|
||||
computeNetWeight(mesXslWeightRecord);
|
||||
computeBillType(mesXslWeightRecord);
|
||||
mesXslWeightRecordService.updateById(mesXslWeightRecord);
|
||||
stompNotifyService.publishWeightRecordChanged("edit", mesXslWeightRecord.getId());
|
||||
return Result.OK("编辑成功!");
|
||||
@@ -137,26 +137,47 @@ public class MesXslWeightRecordController extends JeecgController<MesXslWeightRe
|
||||
}
|
||||
|
||||
private void computeNetWeight(MesXslWeightRecord record) {
|
||||
sanitizeNonPositiveWeightsToNull(record);
|
||||
BigDecimal gross = record.getGrossWeight();
|
||||
BigDecimal tare = record.getTareWeight();
|
||||
if (gross != null && tare != null) {
|
||||
if (isEffectiveWeight(gross) && isEffectiveWeight(tare)) {
|
||||
BigDecimal net = gross.subtract(tare);
|
||||
record.setNetWeight(net.compareTo(BigDecimal.ZERO) >= 0 ? net : BigDecimal.ZERO);
|
||||
} else {
|
||||
record.setNetWeight(null);
|
||||
}
|
||||
}
|
||||
|
||||
private void computeBillType(MesXslWeightRecord record) {
|
||||
if (record.getGrossWeight() != null && record.getTareWeight() != null) {
|
||||
boolean g = isEffectiveWeight(record.getGrossWeight());
|
||||
boolean t = isEffectiveWeight(record.getTareWeight());
|
||||
if (g && t) {
|
||||
record.setBillType("2");
|
||||
return;
|
||||
}
|
||||
if (record.getGrossWeight() != null) {
|
||||
if (g) {
|
||||
record.setBillType("1");
|
||||
return;
|
||||
}
|
||||
if (record.getTareWeight() != null) {
|
||||
if (t) {
|
||||
record.setBillType("3");
|
||||
return;
|
||||
}
|
||||
record.setBillType(null);
|
||||
}
|
||||
|
||||
/** 将 ≤0 的重量视为未录入,避免占位 0 误判称重完成 */
|
||||
private static void sanitizeNonPositiveWeightsToNull(MesXslWeightRecord record) {
|
||||
if (record.getGrossWeight() != null && record.getGrossWeight().compareTo(BigDecimal.ZERO) <= 0) {
|
||||
record.setGrossWeight(null);
|
||||
}
|
||||
if (record.getTareWeight() != null && record.getTareWeight().compareTo(BigDecimal.ZERO) <= 0) {
|
||||
record.setTareWeight(null);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isEffectiveWeight(BigDecimal w) {
|
||||
return w != null && w.compareTo(BigDecimal.ZERO) > 0;
|
||||
}
|
||||
|
||||
private void applyMaterialTypeDefault(MesXslWeightRecord record) {
|
||||
|
||||
Reference in New Issue
Block a user