fix(wms): 出库单更改库存

dev
wanghao 2 weeks ago
parent b00db229b9
commit 862fedcda8

@ -82,4 +82,5 @@ public class WmsInventoryDetailsBo extends BaseEntity {
* *
*/ */
private String unitName; private String unitName;
private String delFlag;
} }

@ -20,4 +20,6 @@ import org.springframework.stereotype.Repository;
@Repository @Repository
public interface WmsInventoryDetailsMapper extends BaseMapperPlus<WmsInventoryDetails, WmsInventoryDetailsVo> { public interface WmsInventoryDetailsMapper extends BaseMapperPlus<WmsInventoryDetails, WmsInventoryDetailsVo> {
int updataDetailsByInventoryId(WmsInventoryDetails inventoryDetails);
} }

@ -5,24 +5,29 @@ import com.github.yulichang.toolkit.JoinWrappers;
import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.github.yulichang.wrapper.MPJLambdaWrapper;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboReference; import org.apache.dubbo.config.annotation.DubboReference;
import org.dromara.common.core.utils.DateUtils;
import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StringUtils; import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo; import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.system.api.RemoteCodeRuleService; import org.dromara.system.api.RemoteCodeRuleService;
import org.dromara.wms.domain.WmsInventoryDetails; import org.dromara.wms.domain.WmsInventoryDetails;
import org.dromara.wms.domain.WmsInventoryLedger;
import org.dromara.wms.domain.WmsOutStockBill; import org.dromara.wms.domain.WmsOutStockBill;
import org.dromara.wms.domain.WmsOutStockDetails; import org.dromara.wms.domain.WmsOutStockDetails;
import org.dromara.wms.domain.bo.WmsOutStockBillBo; import org.dromara.wms.domain.bo.WmsOutStockBillBo;
import org.dromara.wms.domain.vo.WmsInventoryDetailsVo;
import org.dromara.wms.domain.vo.WmsOutStockBillVo; import org.dromara.wms.domain.vo.WmsOutStockBillVo;
import org.dromara.wms.mapper.WmsInventoryDetailsMapper; import org.dromara.wms.mapper.WmsInventoryDetailsMapper;
import org.dromara.wms.mapper.WmsInventoryLedgerMapper;
import org.dromara.wms.mapper.WmsOutStockBillMapper; import org.dromara.wms.mapper.WmsOutStockBillMapper;
import org.dromara.wms.mapper.WmsOutStockDetailsMapper; import org.dromara.wms.mapper.WmsOutStockDetailsMapper;
import org.dromara.wms.service.IWmsOutStockBillService; import org.dromara.wms.service.IWmsOutStockBillService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -39,9 +44,10 @@ public class WmsOutStockBillServiceImpl implements IWmsOutStockBillService {
private final WmsOutStockBillMapper baseMapper; private final WmsOutStockBillMapper baseMapper;
private final WmsOutStockDetailsMapper wmsOutStockDetailsMapper; private final WmsOutStockDetailsMapper wmsOutStockDetailsMapper;
private final WmsInventoryDetailsMapper wmsInventoryDetailsMapper;
private final WmsInventoryLedgerMapper wmsInventoryLedgerMapper;
@DubboReference @DubboReference
private RemoteCodeRuleService remoteCodeRuleService; private RemoteCodeRuleService remoteCodeRuleService;
private final WmsInventoryDetailsMapper wmsInventoryDetailsMapper;
/** /**
* *
@ -112,19 +118,40 @@ public class WmsOutStockBillServiceImpl implements IWmsOutStockBillService {
if (flag) { if (flag) {
Long outStockBillId = add.getOutStockBillId(); Long outStockBillId = add.getOutStockBillId();
List<WmsOutStockDetails> outStockDetailsList = bo.getOutStockDetailsList(); List<WmsOutStockDetails> outStockDetailsList = bo.getOutStockDetailsList();
List<WmsInventoryLedger> wmsInventoryLedgers = new ArrayList<>();
outStockDetailsList.forEach(item -> { outStockDetailsList.forEach(item -> {
item.setOutStockBillId(outStockBillId); item.setOutStockBillId(outStockBillId);
// 从出库明细中获取库存ID // 从出库明细中获取库存ID
Long inventoryId = item.getInventoryDetailsId(); Long inventoryId = item.getInventoryDetailsId();
WmsInventoryDetails inventory = wmsInventoryDetailsMapper.selectById(inventoryId); WmsInventoryDetails inventory = wmsInventoryDetailsMapper.selectById(inventoryId);
if (inventory.getInventoryAmount()<item.getOutStockAmount()) { Double inventoryAmount = inventory.getInventoryAmount();
double lossQty = inventoryAmount - item.getOutStockAmount();
if (lossQty < 0) {
throw new IllegalArgumentException("库存数量不足"); 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);
}); });
//插入出库明细 //插入出库明细
wmsOutStockDetailsMapper.insert(outStockDetailsList); wmsOutStockDetailsMapper.insert(outStockDetailsList);
//插入库存变动
wmsInventoryLedgerMapper.insert(wmsInventoryLedgers);
} }
return flag; return flag;
} }

@ -6,9 +6,16 @@
<resultMap type="org.dromara.wms.domain.vo.WmsInventoryDetailsVo" id="WmsInventoryDetailsResult"> <resultMap type="org.dromara.wms.domain.vo.WmsInventoryDetailsVo" id="WmsInventoryDetailsResult">
</resultMap> </resultMap>
<select id="selectCustomWmsInventoryDetailsVoList" resultMap="WmsInventoryDetailsResult">
select inventory_details_id, tenant_id, location_code, warehouse_id, materiel_id, batch_number, inventory_amount, locked_amount, remark, del_flag, create_dept, create_by, create_time, update_by, update_time from wms_inventory_details t <update id="updataDetailsByInventoryId" parameterType="org.dromara.wms.domain.WmsInventoryDetails">
${ew.getCustomSqlSegment} update wms_inventory_details
</select> <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}
</update>
</mapper> </mapper>

Loading…
Cancel
Save