feat(stock): 使用BigDecimal优化库存数量精度管理

- 将库存数量字段类型从String改为BigDecimal以提高数值计算精度
- 更新盘点差异记录中的数量字段为BigDecimal类型
- 修改库存维护记录的数量字段类型为BigDecimal
- 在库存服务中增加货位变更逻辑处理
- 修正出库数量和入库数量的初始化值为BigDecimal.ZERO
- 优化库存统计计算逻辑,确保数值准确性
- 统一数量相关字段的数据类型以增强系统稳定性
This commit is contained in:
liuhanqing
2025-12-09 14:52:23 +08:00
parent d42dae22ce
commit 2c8231fe8d
8 changed files with 49 additions and 28 deletions

View File

@@ -29,10 +29,10 @@ public class StockScreenServiceImpl implements IStockScreenService {
List<BasStock> list = basStockService.selectBasStockListApi(new BasStock()); List<BasStock> list = basStockService.selectBasStockListApi(new BasStock());
BigDecimal total = BigDecimal.ZERO; BigDecimal total = BigDecimal.ZERO;
for (BasStock s : list) { for (BasStock s : list) {
String q = s.getQuantity(); BigDecimal quantity = s.getQuantity();
if (q != null && !q.trim().isEmpty()) { if (quantity != null && quantity.doubleValue()!=0) {
try { try {
total = total.add(new BigDecimal(q.trim())); total = total.add(quantity);
} catch (Exception ignored) { } catch (Exception ignored) {
} }
} }
@@ -134,4 +134,4 @@ public class StockScreenServiceImpl implements IStockScreenService {
return 0; return 0;
} }
} }
} }

View File

@@ -29,6 +29,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@@ -196,7 +197,7 @@ public class CheckDifferenceRecordController extends BaseController {
newStock.setStockStatus("1"); // 设置库存状态为正常 newStock.setStockStatus("1"); // 设置库存状态为正常
newStock.setWarehouseId(record.getWarehouseId()); newStock.setWarehouseId(record.getWarehouseId());
newStock.setInType(""); newStock.setInType("");
newStock.setOutQuantity("0"); newStock.setOutQuantity(BigDecimal.ZERO);
newStock.setInDate(DateUtil.formatDateTime(DateUtil.date())); newStock.setInDate(DateUtil.formatDateTime(DateUtil.date()));
//供应商 //供应商
newStock.setPhase(checkDifferenceRecordAddInfo.getSpare3()); newStock.setPhase(checkDifferenceRecordAddInfo.getSpare3());

View File

@@ -6,6 +6,8 @@ import com.ruoyi.common.domain.ExtraField;
import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import java.math.BigDecimal;
/** /**
* 盘点差异对象 check_difference_record * 盘点差异对象 check_difference_record
* *
@@ -55,11 +57,11 @@ public class CheckDifferenceRecord extends BaseEntity
/** 原值 */ /** 原值 */
@Excel(name = "原值") @Excel(name = "原值")
private String oldQuantity; private BigDecimal oldQuantity;
/** 新值 */ /** 新值 */
@Excel(name = "新值") @Excel(name = "新值")
private String newQuantity; private BigDecimal newQuantity;
/** 操作方式 */ /** 操作方式 */
@Excel(name = "操作方式") @Excel(name = "操作方式")
@@ -210,22 +212,22 @@ public class CheckDifferenceRecord extends BaseEntity
return customer; return customer;
} }
public void setOldQuantity(String oldQuantity) public void setOldQuantity(BigDecimal oldQuantity)
{ {
this.oldQuantity = oldQuantity; this.oldQuantity = oldQuantity;
} }
public String getOldQuantity() public BigDecimal getOldQuantity()
{ {
return oldQuantity; return oldQuantity;
} }
public void setNewQuantity(String newQuantity) public void setNewQuantity(BigDecimal newQuantity)
{ {
this.newQuantity = newQuantity; this.newQuantity = newQuantity;
} }
public String getNewQuantity() public BigDecimal getNewQuantity()
{ {
return newQuantity; return newQuantity;
} }

View File

@@ -18,6 +18,7 @@ import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@@ -112,7 +113,7 @@ public class CheckDifferenceRecordServiceImpl implements ICheckDifferenceRecordS
return AjaxResult.error(MessageUtils.message("error.message9")); return AjaxResult.error(MessageUtils.message("error.message9"));
} }
checkDifferenceRecord.setCargoSpaceId(cargoSpaces.get(0).getCargoSpaceId()); checkDifferenceRecord.setCargoSpaceId(cargoSpaces.get(0).getCargoSpaceId());
checkDifferenceRecord.setOldQuantity("0"); checkDifferenceRecord.setOldQuantity(new BigDecimal(0));
}else if (checkDifferenceRecord.getRecordType()==3){ }else if (checkDifferenceRecord.getRecordType()==3){
BasStock basStock = basStockService.selectBasStockByStockId(checkDifferenceRecord.getStockId()); BasStock basStock = basStockService.selectBasStockByStockId(checkDifferenceRecord.getStockId());
if (!"1".equals(basStock.getProductStatus())){ if (!"1".equals(basStock.getProductStatus())){
@@ -121,7 +122,7 @@ public class CheckDifferenceRecordServiceImpl implements ICheckDifferenceRecordS
} }
basStock.setProductStatus("2"); basStock.setProductStatus("2");
basStockService.updateBasStock(basStock); basStockService.updateBasStock(basStock);
checkDifferenceRecord.setNewQuantity("0"); checkDifferenceRecord.setNewQuantity(new BigDecimal(0));
checkDifferenceRecord.setCargoSpaceId(basStock.getCargoSpaceId()); checkDifferenceRecord.setCargoSpaceId(basStock.getCargoSpaceId());
checkDifferenceRecord.setTrayCode(basStock.getTrayCode()); checkDifferenceRecord.setTrayCode(basStock.getTrayCode());
checkDifferenceRecord.setProductId(basStock.getProductId()); checkDifferenceRecord.setProductId(basStock.getProductId());

View File

@@ -402,12 +402,12 @@ public class MydoJobServiceImpl implements IMydoJobService {
stock.setStockId(basJobIdService.getJobId("KC")); stock.setStockId(basJobIdService.getJobId("KC"));
stock.setCargoSpaceId(mydoJob.getCargoSpaceId()); stock.setCargoSpaceId(mydoJob.getCargoSpaceId());
stock.setStockStatus("1"); stock.setStockStatus("1");
stock.setOutQuantity("0"); stock.setOutQuantity(BigDecimal.ZERO);
stock.setProductStatus(productStatus); stock.setProductStatus(productStatus);
stock.setLotNo(mydoJobDetail.getLotNo()); stock.setLotNo(mydoJobDetail.getLotNo());
stock.setInDate(DateUtil.formatDateTime(new Date())); stock.setInDate(DateUtil.formatDateTime(new Date()));
stock.setProductGuid(mydoJobDetail.getProductGuid()); stock.setProductGuid(mydoJobDetail.getProductGuid());
stock.setQuantity(mydoJobDetail.getInQuantity()); stock.setQuantity(Convert.toBigDecimal(mydoJobDetail.getInQuantity()));
stock.setJobId(mydoJob.getJobId()); stock.setJobId(mydoJob.getJobId());
stock.setTrayCode(mydoJob.getTrayCode()); stock.setTrayCode(mydoJob.getTrayCode());
stock.setWarehouseId(mydoJob.getWarehouseId()); stock.setWarehouseId(mydoJob.getWarehouseId());
@@ -471,7 +471,7 @@ public class MydoJobServiceImpl implements IMydoJobService {
if (basStock != null) { if (basStock != null) {
BigDecimal outQuantity = Convert.toBigDecimal(basStock.getOutQuantity()); BigDecimal outQuantity = Convert.toBigDecimal(basStock.getOutQuantity());
BigDecimal substract = outQuantity.subtract(Convert.toBigDecimal(detail.getOutQuantity())); BigDecimal substract = outQuantity.subtract(Convert.toBigDecimal(detail.getOutQuantity()));
basStock.setOutQuantity(String.valueOf(substract)); basStock.setOutQuantity(substract);
basStockMapper.updateBasStock(basStock); basStockMapper.updateBasStock(basStock);
} }
//修改单据数量 //修改单据数量
@@ -561,7 +561,7 @@ public class MydoJobServiceImpl implements IMydoJobService {
if (basStock != null) { if (basStock != null) {
BigDecimal outQuantity = Convert.toBigDecimal(basStock.getOutQuantity()); BigDecimal outQuantity = Convert.toBigDecimal(basStock.getOutQuantity());
BigDecimal substract = outQuantity.subtract(Convert.toBigDecimal(mydoJobDetail.getOutQuantity())); BigDecimal substract = outQuantity.subtract(Convert.toBigDecimal(mydoJobDetail.getOutQuantity()));
basStock.setOutQuantity(String.valueOf(substract)); basStock.setOutQuantity(substract);
basStockService.updateBasStock(basStock); basStockService.updateBasStock(basStock);
} }

View File

@@ -7,6 +7,7 @@ import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
/** /**
@@ -55,11 +56,11 @@ public class BasStockMaintainRecord extends BaseEntity
/** 初始数量 */ /** 初始数量 */
@Excel(name = "初始数量") @Excel(name = "初始数量")
private String oldQuantity; private BigDecimal oldQuantity;
/** 操作后数量 */ /** 操作后数量 */
@Excel(name = "操作后数量") @Excel(name = "操作后数量")
private String quantity; private BigDecimal quantity;
/** 操作 */ /** 操作 */
@Excel(name = "操作", dictType="stock_maintain_method") @Excel(name = "操作", dictType="stock_maintain_method")
@@ -210,22 +211,22 @@ public class BasStockMaintainRecord extends BaseEntity
return lotNo; return lotNo;
} }
public void setOldQuantity(String oldQuantity) public void setOldQuantity(BigDecimal oldQuantity)
{ {
this.oldQuantity = oldQuantity; this.oldQuantity = oldQuantity;
} }
public String getOldQuantity() public BigDecimal getOldQuantity()
{ {
return oldQuantity; return oldQuantity;
} }
public void setQuantity(String quantity) public void setQuantity(BigDecimal quantity)
{ {
this.quantity = quantity; this.quantity = quantity;
} }
public String getQuantity() public BigDecimal getQuantity()
{ {
return quantity; return quantity;
} }

View File

@@ -8,6 +8,7 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.ToString; import lombok.ToString;
import java.math.BigDecimal;
import java.util.List; import java.util.List;
/** /**
@@ -81,7 +82,7 @@ public class BasStock extends BaseEntity {
private String spare8; private String spare8;
private String voltage; private String voltage;
private String phase; private String phase;
private String netWeight; private String netWeight;
private String grossWeight; private String grossWeight;
@@ -94,7 +95,7 @@ public class BasStock extends BaseEntity {
* 库存数量 * 库存数量
*/ */
@Excel(name = "库存数量",sort=10) @Excel(name = "库存数量",sort=10)
private String quantity; private BigDecimal quantity;
/** /**
* 作业ID * 作业ID
@@ -153,7 +154,7 @@ public class BasStock extends BaseEntity {
/** /**
* 出库数量 * 出库数量
*/ */
private String outQuantity; private BigDecimal outQuantity;
/** /**
* 入库班组ID * 入库班组ID

View File

@@ -1,6 +1,7 @@
package com.ruoyi.stock.stock.service.impl; package com.ruoyi.stock.stock.service.impl;
import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.IdUtil;
import com.ruoyi.bas.cargoSpace.domain.BasCargoSpace;
import com.ruoyi.bas.cargoSpace.service.IBasCargoSpaceService; import com.ruoyi.bas.cargoSpace.service.IBasCargoSpaceService;
import com.ruoyi.common.annotation.DataScope; import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
@@ -116,8 +117,22 @@ public class BasStockServiceImpl implements IBasStockService
public int updateBasStock(BasStock basStock) public int updateBasStock(BasStock basStock)
{ {
BasStock oldBasStock = basStockMapper.selectBasStockByStockId(basStock.getStockId()); BasStock oldBasStock = basStockMapper.selectBasStockByStockId(basStock.getStockId());
insertMaintainRecord(oldBasStock,basStock,"2"); //修改库存记录
insertFreezeRecord(oldBasStock,basStock); insertMaintainRecord(oldBasStock, basStock, "2");
//修改冻结记录
insertFreezeRecord(oldBasStock, basStock);
//修改货位
if (!oldBasStock.getCargoSpaceId().equals(basStock.getCargoSpaceId())){
BasCargoSpace oldBasCargoSpace = basCargoSpaceService.selectBasCargoSpaceByCargoSpaceId(oldBasStock.getCargoSpaceId());
oldBasCargoSpace.setStatus("1");
oldBasCargoSpace.setTrayCode("");
basCargoSpaceService.updateBasCargoSpace(oldBasCargoSpace);
BasCargoSpace basCargoSpace = basCargoSpaceService.selectBasCargoSpaceByCargoSpaceId(basStock.getCargoSpaceId());
basCargoSpace.setStatus("2");
basCargoSpace.setTrayCode(oldBasCargoSpace.getTrayCode());
basCargoSpaceService.updateBasCargoSpace(basCargoSpace);
}
//修改货位
return basStockMapper.updateBasStock(basStock); return basStockMapper.updateBasStock(basStock);
} }