refactor(wms): 物料出库修改库存优化

dev
wanghao 1 week ago
parent 609ba5d991
commit a17d8778cb

@ -18,7 +18,11 @@ import org.springframework.stereotype.Repository;
@Repository
public interface WmsInventoryDetailsMapper extends BaseMapperPlus<WmsInventoryDetails, WmsInventoryDetailsVo> {
int updataDetailsByInventoryId(WmsInventoryDetails inventoryDetails);
int updataDetailsByInventoryId(@Param("inventoryDetailsId") Long inventoryDetailsId,
@Param("outStockAmount") Double outStockAmount,
@Param("nowDate") Date nowDate,
@Param("userId") Long userId,
@Param("delFlag") String delFlag);
int workAddUpdateInventory(WmsInventoryDetails inventoryDetails);

@ -72,11 +72,12 @@ public interface IWmsInventoryDetailsService {
WmsInventoryDetails queryInventory(WmsInventoryDetailsBo inventory);
Double workUpdateInventory(Long inventoryDetailsId, Double disposalQty);
WmsInventoryDetails selectDetailsById(Long sampleLedgerId);
Boolean workAddUpdateInventory(WmsInventoryDetails inventoryDetails);
Boolean inStoreAddInventoryAmount(Long warehouseId, Long projectId, String batchNumber, Long materialId, Double unitPrice, String unitName, Double inStockAmount,String changeType);
Boolean outStoreLossInventoryAmount(Long inventoryId, Double outStockAmount, Long warehouseId, String batchNumber, Long materielId, String changeType);
}

@ -162,25 +162,6 @@ public class WmsInventoryDetailsServiceImpl implements IWmsInventoryDetailsServi
return baseMapper.deleteByIds(ids) > 0;
}
@Override
public Double workUpdateInventory(Long inventoryDetailsId, Double disposalQty) {
WmsInventoryDetails inventory = baseMapper.selectById(inventoryDetailsId);
Double inventoryAmount = inventory.getInventoryAmount();
double lossQty = inventoryAmount - disposalQty;
if (lossQty < 0) {
throw new IllegalArgumentException("库存数量不足");
}
inventory.setInventoryAmount(lossQty);
if (lossQty == 0.0) {
inventory.setDelFlag("1");
}
inventory.setUpdateBy(LoginHelper.getUserId());
inventory.setUpdateTime(DateUtils.getNowDate());
baseMapper.updataDetailsByInventoryId(inventory);
return inventoryAmount;
}
@Override
public WmsInventoryDetails selectDetailsById(Long sampleLedgerId) {
@ -223,7 +204,7 @@ public class WmsInventoryDetailsServiceImpl implements IWmsInventoryDetailsServi
Double inventoryTableAmount = 0.0;
if (queryInventory != null) {
inventoryTableAmount = queryInventory.getInventoryAmount();
baseMapper.updateTableById(queryInventory.getInventoryDetailsId(), inStockAmount, DateUtils.getNowDate(), LoginHelper.getUserId()); // 更新库存数量
baseMapper.updateTableById(queryInventory.getInventoryDetailsId(), inStockAmount, DateUtils.getNowDate(), LoginHelper.getUserId()); // update增加库存数量
} else {
inventory.setUnitName(unitName);
inventory.setInventoryAmount(inStockAmount);
@ -263,4 +244,28 @@ public class WmsInventoryDetailsServiceImpl implements IWmsInventoryDetailsServi
return baseMapper.selectOne(lqw);
}
@Override
public Boolean outStoreLossInventoryAmount(Long inventoryId, Double outStockAmount, Long warehouseId,
String batchNumber, Long materielId, String changeType) {
WmsInventoryDetails inventory = baseMapper.selectById(inventoryId);
Double inventoryAmount = inventory.getInventoryAmount();
double lossQty = inventoryAmount - outStockAmount;
if (lossQty < 0) {
throw new IllegalArgumentException("库存数量不足");
}
baseMapper.updataDetailsByInventoryId(inventoryId, outStockAmount, DateUtils.getNowDate(), LoginHelper.getUserId(), lossQty == 0.0 ? "1" : "0");
//库存变动
WmsInventoryLedger wmsInventoryLedger = new WmsInventoryLedger();
wmsInventoryLedger.setWarehouseId(warehouseId);
wmsInventoryLedger.setBatchNumber(batchNumber);
wmsInventoryLedger.setMaterielId(materielId);
wmsInventoryLedger.setChangeType(changeType);//变动类型
wmsInventoryLedger.setLedgerState("0");
wmsInventoryLedger.setChangeAmount(outStockAmount);
wmsInventoryLedger.setInventoryAmount(inventoryAmount);
wmsInventoryLedgerMapper.insert(wmsInventoryLedger);
return true;
}
}

@ -22,6 +22,7 @@ import org.dromara.wms.mapper.WmsInventoryDetailsMapper;
import org.dromara.wms.mapper.WmsInventoryLedgerMapper;
import org.dromara.wms.mapper.WmsOutStockBillMapper;
import org.dromara.wms.mapper.WmsOutStockDetailsMapper;
import org.dromara.wms.service.IWmsInventoryDetailsService;
import org.dromara.wms.service.IWmsOutStockBillService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -44,8 +45,7 @@ public class WmsOutStockBillServiceImpl implements IWmsOutStockBillService {
private final WmsOutStockBillMapper baseMapper;
private final WmsOutStockDetailsMapper wmsOutStockDetailsMapper;
private final WmsInventoryDetailsMapper wmsInventoryDetailsMapper;
private final WmsInventoryLedgerMapper wmsInventoryLedgerMapper;
private final IWmsInventoryDetailsService inventoryDetailsService;
@DubboReference
private RemoteCodeRuleService remoteCodeRuleService;
@ -123,35 +123,12 @@ public class WmsOutStockBillServiceImpl implements IWmsOutStockBillService {
item.setOutStockBillId(outStockBillId);
// 从出库明细中获取库存ID
Long inventoryId = item.getInventoryDetailsId();
WmsInventoryDetails inventory = wmsInventoryDetailsMapper.selectById(inventoryId);
Double inventoryAmount = inventory.getInventoryAmount();
double lossQty = inventoryAmount - item.getOutStockAmount();
if (lossQty < 0) {
throw new IllegalArgumentException("库存数量不足");
}
inventory.setInventoryAmount(lossQty);
if (lossQty == 0.0){
inventory.setDelFlag("1");
}
inventory.setUpdateBy( LoginHelper.getUserId());
inventory.setUpdateTime(DateUtils.getNowDate());
wmsInventoryDetailsMapper.updataDetailsByInventoryId(inventory);
//库存变动
WmsInventoryLedger wmsInventoryLedger = new WmsInventoryLedger();
wmsInventoryLedger.setWarehouseId(item.getWarehouseId());
wmsInventoryLedger.setBatchNumber(item.getBatchNumber());
wmsInventoryLedger.setMaterielId(item.getMaterielId());
wmsInventoryLedger.setChangeType("3");//变动类型
wmsInventoryLedger.setLedgerState("0");
wmsInventoryLedger.setChangeAmount(item.getOutStockAmount());
wmsInventoryLedger.setInventoryAmount(inventoryAmount);
wmsInventoryLedgers.add(wmsInventoryLedger);
inventoryDetailsService.outStoreLossInventoryAmount(inventoryId,
item.getOutStockAmount(),item.getWarehouseId(),item.getBatchNumber(),item.getMaterielId(),"3");
});
//插入出库明细
wmsOutStockDetailsMapper.insert(outStockDetailsList);
//插入库存变动
wmsInventoryLedgerMapper.insert(wmsInventoryLedgers);
}
return flag;
}

@ -7,15 +7,13 @@
</resultMap>
<update id="updataDetailsByInventoryId" parameterType="org.dromara.wms.domain.WmsInventoryDetails">
<update id="updataDetailsByInventoryId" >
update wms_inventory_details
<set>
<if test="inventoryAmount != null">inventory_amount = #{inventoryAmount},</if>
<if test="delFlag != null">del_flag = #{delFlag},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</set>
where inventory_details_id = #{inventoryDetailsId}
set inventory_amount = inventory_amount - #{outStockAmount},
del_flag = #{delFlag},
update_by = #{userId},
update_time = #{nowDate}
where inventory_details_id = #{inventoryDetailsId}
</update>

Loading…
Cancel
Save