service-store/src/main/java/com/java110/store/bmo/allocation/impl/AllocationBMOImpl.java
@@ -5,7 +5,6 @@
import com.java110.dto.resource.ResourceStoreDto;
import com.java110.dto.resource.ResourceStoreTimesDto;
import com.java110.dto.store.StorehouseDto;
import com.java110.intf.common.IAllocationStorehouseUserInnerServiceSMO;
import com.java110.intf.store.*;
import com.java110.po.purchase.ResourceStorePo;
import com.java110.po.resource.ResourceStoreTimesPo;
@@ -15,13 +14,11 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.List;
@Service
public class AllocationBMOImpl implements IAllocationBMO {
    @Autowired
    private IAllocationStorehouseApplyInnerServiceSMO allocationStorehouseApplyInnerServiceSMOImpl;
    @Autowired
    private IStorehouseInnerServiceSMO storehouseInnerServiceSMOImpl;
@@ -33,30 +30,16 @@
    private IResourceStoreInnerServiceSMO resourceStoreInnerServiceSMOImpl;
    @Autowired
    private IAllocationStorehouseUserInnerServiceSMO allocationStorehouseUserInnerServiceSMOImpl;
    @Autowired
    private IUserStorehouseInnerServiceSMO userStorehouseInnerServiceSMOImpl;
    @Autowired
    private IAllocationStorehouseApplyV1InnerServiceSMO allocationStorehouseApplyV1InnerServiceSMOImpl;
    @Autowired
    private IAllocationStorehouseV1InnerServiceSMO allocationStorehouseV1InnerServiceSMOImpl;
    @Autowired
    private IResourceStoreV1InnerServiceSMO resourceStoreV1InnerServiceSMOImpl;
    @Override
    public void doToAllocationStorehouse(AllocationStorehouseDto tmpAllocationStorehouseDto, int allocationStock) {
    public void doToAllocationStorehouse(AllocationStorehouseDto tmpAllocationStorehouseDto, double allocationStock) {
        //查询z 仓库
        StorehouseDto storehouseDto = new StorehouseDto();
        storehouseDto.setShId(tmpAllocationStorehouseDto.getShIdz());
        List<StorehouseDto> targetStorehouseDtos = storehouseInnerServiceSMOImpl.queryStorehouses(storehouseDto);
        Assert.listOnlyOne(targetStorehouseDtos, "目标仓库不存在");
        Assert.listOnlyOne(targetStorehouseDtos,"目标仓库不存在");
        // todo -------------------------------------------------原仓库中做扣除 (start)-----------------------------------------------------//
        // todo 原仓库中扣除 数量
        ResourceStoreDto resourceStoreDto = new ResourceStoreDto();
@@ -67,7 +50,6 @@
        if (resourceStoreDtoAs == null || resourceStoreDtoAs.size() < 1) {
            return;
        }
        ResourceStoreTimesDto resourceStoreTimesDto = new ResourceStoreTimesDto();
        resourceStoreTimesDto.setTimesId(tmpAllocationStorehouseDto.getTimesId());
        resourceStoreTimesDto.setShId(tmpAllocationStorehouseDto.getShIda());
@@ -76,9 +58,7 @@
        if (resourceStoreTimesDtoAs == null || resourceStoreTimesDtoAs.size() < 1) {
            return;
        }
        int stockA = Integer.parseInt(resourceStoreDtoAs.get(0).getStock());
        double stockA = Double.parseDouble(resourceStoreDtoAs.get(0).getStock());
        //todo 库存不够时,只能调拨 库存,这种场景应该执行不到 前文做了校验
        if (stockA < allocationStock) {
            allocationStock = stockA;
@@ -88,14 +68,11 @@
        resourceStorePo.setStoreId(resourceStoreDtoAs.get(0).getStoreId());
        resourceStorePo.setStock(allocationStock * -1 + "");// 这里去扣出
        resourceStoreInnerServiceSMOImpl.updateResourceStore(resourceStorePo);
        stockA = Integer.parseInt(resourceStoreTimesDtoAs.get(0).getStock());
        stockA = Double.parseDouble(resourceStoreTimesDtoAs.get(0).getStock());
        //todo 库存不够时,只能调拨 库存,这种场景应该执行不到 前文做了校验
        if (stockA < allocationStock) {
            allocationStock = stockA;
        }
        ResourceStoreTimesPo resourceStoreTimesPo = new ResourceStoreTimesPo();
        resourceStoreTimesPo.setPrice(resourceStoreTimesDtoAs.get(0).getPrice());
        resourceStoreTimesPo.setShId(resourceStoreTimesDtoAs.get(0).getShId());
@@ -106,7 +83,6 @@
        // todo -------------------------------------------------原仓库中做扣除 (end)-----------------------------------------------------//
        // todo -------------------------------------------------目标仓库中做增加 (start)-----------------------------------------------------//
        //todo 查询目标仓库中 库存
        resourceStoreDto = new ResourceStoreDto();
        resourceStoreDto.setResCode(resourceStoreDtoAs.get(0).getResCode());
@@ -120,26 +96,25 @@
            tmpResourceStorePo.setStock(allocationStock + "");
            tmpResourceStorePo.setShId(tmpAllocationStorehouseDto.getShIdz());
            tmpResourceStorePo.setCommunityId(targetStorehouseDtos.get(0).getCommunityId());
            BigDecimal miniUnitStock = new BigDecimal(resourceStoreDtoAs.get(0).getMiniUnitStock()); //获取最小计量单位数量
            BigDecimal stock = new BigDecimal(tmpResourceStorePo.getStock()); //获取物品库存
            BigDecimal miniStock = miniUnitStock.multiply(stock); //计算最小计量单位总数
            tmpResourceStorePo.setMiniStock(String.valueOf(miniStock));
            resourceStoreV1InnerServiceSMOImpl.saveResourceStore(tmpResourceStorePo);
            // todo 添加 times
            ResourceStoreTimesPo tmpResourceStoreTimesPo = BeanConvertUtil.covertBean(resourceStoreTimesDtoAs.get(0), ResourceStoreTimesPo.class);
            tmpResourceStoreTimesPo.setTimesId(GenerateCodeFactory.getGeneratorId("11"));
            tmpResourceStoreTimesPo.setStock(allocationStock + "");
            tmpResourceStoreTimesPo.setShId(tmpAllocationStorehouseDto.getShIdz());
            tmpResourceStoreTimesPo.setCommunityId(targetStorehouseDtos.get(0).getCommunityId());
            resourceStoreTimesV1InnerServiceSMOImpl.saveResourceStoreTimes(tmpResourceStoreTimesPo);
            return;
        }
        resourceStorePo = new ResourceStorePo();
        resourceStorePo.setResId(resourceStoreDtoZs.get(0).getResId());
        resourceStorePo.setStoreId(resourceStoreDtoZs.get(0).getStoreId());
        resourceStorePo.setStock(allocationStock + "");// 这里去扣出
        resourceStorePo.setStock(allocationStock + "");// 这里去添加到目标仓库
        resourceStoreInnerServiceSMOImpl.updateResourceStore(resourceStorePo);
        resourceStoreTimesPo = new ResourceStoreTimesPo();
        resourceStoreTimesPo.setPrice(resourceStoreTimesDtoAs.get(0).getPrice());
        resourceStoreTimesPo.setShId(resourceStoreDtoZs.get(0).getShId());
@@ -150,7 +125,5 @@
        resourceStoreTimesPo.setApplyOrderId(tmpAllocationStorehouseDto.getApplyId());
        resourceStoreTimesV1InnerServiceSMOImpl.saveOrUpdateResourceStoreTimes(resourceStoreTimesPo);
        // todo -------------------------------------------------目标仓库中做增加 (end)-----------------------------------------------------//
    }
}