Selaa lähdekoodia

所有入库操作添加当价格为0时取入库明细最近一次有价格的数据,库存添加原仓库id

koushanshan 1 vuosi sitten
vanhempi
commit
d61bf7140c

+ 9 - 0
src/main/java/com/dk/mdm/mapper/ivt/InboundItemMapper.java

@@ -91,5 +91,14 @@ public interface InboundItemMapper extends BaseMapper<InboundItem>{
      * @author : 寇珊珊
      */
     int deleteItemByFromId(@Param("fromId") String fromId);
+
+    /**
+     * @desc   : 查询入库价
+     * @date   : 2024/7/1 11:07
+     * @author : 寇珊珊
+     */
+    List<InboundItemResponse> selectPriceInto(InboundItemQuery inboundItemQuery);
+
+
 }
 

+ 16 - 0
src/main/java/com/dk/mdm/mapper/ivt/InboundItemMapper.xml

@@ -715,4 +715,20 @@
         DELETE FROM dkic_b.t_psi_inbound_item
         WHERE from_id = #{fromId}::uuid
     </delete>
+
+    <!--查询入库价-->
+    <select id="selectPriceInto"  resultMap="BaseResultMapResponse">
+        SELECT
+        ti.item_id,ti.price_into,ti.cost_price,ti.cost_amt
+        FROM dkic_b.t_psi_inbound_item ti
+        left join dkic_b.t_psi_inbound t ON ti.order_id = t.order_id
+        where  t.flg_valid
+        and ti.flg_valid
+        and ti.price_into > 0
+        and t.into_type != '外协入库'
+        and ti.wh_id #{whId}
+        and ti.sku_id =#{skuId}
+        and ti.non_std_code = #{nonStdCode}
+        order by make_time desc
+    </select>
 </mapper>

+ 4 - 0
src/main/java/com/dk/mdm/model/query/ivt/InboundItemQuery.java

@@ -327,6 +327,10 @@ public class InboundItemQuery extends PageInfo<InboundItemQuery>  {
     @ApiModelProperty(value = "入库状态")
     private List<String> intoStatusList;
 
+    @TableField(typeHandler = UuidTypeHandler.class)
+    @ApiModelProperty(value = "入库仓库")
+    private String whId;
+
     private static final long serialVersionUID = 1L;
 
 }

+ 3 - 0
src/main/java/com/dk/mdm/model/vo/ivt/InOutRecordVO.java

@@ -237,6 +237,9 @@ public class InOutRecordVO  {
     @TableField(typeHandler = UuidTypeHandler.class)
     private String makeStaff;
 
+    @ApiModelProperty(value = "原仓库ID")
+    @TableField(typeHandler = UuidTypeHandler.class)
+    private String whIdPri;
 
 
 

+ 4 - 0
src/main/java/com/dk/mdm/model/vo/ivt/InboundItemVO.java

@@ -278,6 +278,10 @@ public class InboundItemVO  {
     @ApiModelProperty(value = "成本核对标识")
     private Boolean flgCostCheck;
 
+    @ApiModelProperty(value = "原仓库ID")
+    @TableField(typeHandler = UuidTypeHandler.class)
+    private String whIdPri;
+
     private static final long serialVersionUID = 1L;
 
 }

+ 3 - 0
src/main/java/com/dk/mdm/model/vo/ivt/OutboundItemVO.java

@@ -337,6 +337,9 @@ public class OutboundItemVO {
     @ApiModelProperty(value = "修改订单总单信息(存未修改时候的出库中金额)")
     private  BigDecimal updateOrderOutingAmt;
 
+    @ApiModelProperty(value = "原仓库ID")
+    @TableField(typeHandler = UuidTypeHandler.class)
+    private String whIdPri;
 
 
     private static final long serialVersionUID = 1L;

+ 43 - 8
src/main/java/com/dk/mdm/service/ivt/inbound/InboundCheckService.java

@@ -70,6 +70,23 @@ public class InboundCheckService extends BaseService<Inbound> {
 
 
     /**
+     * @desc   : 查询入库价
+     * @date   : 2024/7/1 11:29
+     * @author : 寇珊珊
+     */
+    @Transactional(rollbackFor = {Exception.class})
+    public InboundItemResponse selectPriceInto(InboundItemVO inboundItemVO) {
+        List<InboundItemResponse> inboundItemResponses = inboundItemMapper.selectPriceInto(new InboundItemQuery().setSkuId(inboundItemVO.getSkuId())
+                .setNonStdCode(inboundItemVO.getNonStdCode())
+                .setWhId(inboundItemVO.getWhId()));
+        if (inboundItemResponses != null && inboundItemResponses.size() > 0) {
+            return inboundItemResponses.get(0);
+        }
+        return null;
+    }
+
+
+    /**
      * @desc : 盘盈入库新建、库存调整-入库  \ 新建商品档案->期初入库
      * @date : 2024/3/7 14:13
      * 入库中数量/金额  已入库数量/金额  由调用方传入
@@ -95,6 +112,32 @@ public class InboundCheckService extends BaseService<Inbound> {
         inboundVO.setItemList(inboundItemVOList);
         //endregion
 
+        //region 校验明细
+        if (inboundVO.getItemList().size() == 0) {
+            throw new BaseBusinessException(ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getCode(),
+                    ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage());
+        }
+        //endregion
+
+        //region  查询当前入库明细中是否存在未空或者0的入库价,如果存在去库存流水差最近一条有价格的数据赋值到当前明细
+        Boolean priceIntoFlag = false;
+        for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
+            if(inboundItemVO.getPriceInto()==null || inboundItemVO.getPriceInto().compareTo(BigDecimal.ZERO)==0){
+                priceIntoFlag = true;
+                //查询库存批次最近一条入库价
+                InboundItemResponse inboundItemResponse = this.selectPriceInto(inboundItemVO);
+                inboundItemVO.setPriceInto(inboundItemResponse != null ? inboundItemResponse.getPriceInto() : BigDecimal.ZERO);
+                inboundItemVO.setIntoingAmt(inboundItemResponse != null ? inboundItemResponse.getPriceInto().multiply(inboundItemVO.getIntoingQty()).setScale(2, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO);
+                inboundItemVO.setCostPrice(inboundItemResponse != null ? inboundItemResponse.getCostPrice() : BigDecimal.ZERO);
+                inboundItemVO.setCostAmt(inboundItemResponse != null ? inboundItemResponse.getCostPrice().multiply(inboundItemVO.getIntoingQty()).setScale(2, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO);
+            }
+        }
+        if(priceIntoFlag){
+            BigDecimal intoingAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
+            inboundVO.setIntoingAmt(intoingAmt);
+        }
+        //endregion
+
         //region  总单
         //获取 id/单号
         Map<String, Object> codeMap = new HashMap<>();
@@ -125,11 +168,6 @@ public class InboundCheckService extends BaseService<Inbound> {
         //endregion
 
         //region 明细
-        //校验明细
-        if (inboundVO.getItemList().size() == 0) {
-            throw new BaseBusinessException(ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getCode(),
-                    ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage());
-        }
         for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
             //region 明细
             //总单id
@@ -142,9 +180,6 @@ public class InboundCheckService extends BaseService<Inbound> {
                     .setIntoAmt(inboundItemVO.getIntoingAmt())
                     .setIntoingQty(BigDecimal.ZERO)
                     .setIntoingAmt(BigDecimal.ZERO)
-                    .setCostPrice(inboundItemVO.getPriceInto())
-                    .setCostAmt(inboundItemVO.getIntoQty()
-                            .multiply(inboundItemVO.getPriceInto()).setScale(2, BigDecimal.ROUND_HALF_UP))
             ;
 
             //入库状态

+ 46 - 6
src/main/java/com/dk/mdm/service/ivt/inbound/InboundOtherService.java

@@ -14,6 +14,7 @@ import com.dk.common.service.BaseService;
 import com.dk.mdm.infrastructure.convert.ivt.InboundConvert;
 import com.dk.mdm.infrastructure.convert.ivt.InboundItemConvert;
 import com.dk.mdm.mapper.common.CommonMapper;
+import com.dk.mdm.mapper.ivt.InOutRecordMapper;
 import com.dk.mdm.mapper.ivt.InboundItemMapper;
 import com.dk.mdm.mapper.ivt.InboundMapper;
 import com.dk.mdm.model.pojo.ivt.Inbound;
@@ -44,6 +45,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
+import java.util.stream.Collectors;
 
 
 /**
@@ -81,6 +83,7 @@ public class InboundOtherService extends BaseService<Inbound> {
     private InventoryService inventoryService;
 
 
+
     /**
      * @desc : 条件查询
      * @date : 2024/3/7 14:12
@@ -110,12 +113,54 @@ public class InboundOtherService extends BaseService<Inbound> {
     }
 
     /**
+     * @desc   : 查询入库价
+     * @date   : 2024/7/1 11:29
+     * @author : 寇珊珊
+     */
+    @Transactional(rollbackFor = {Exception.class})
+    public InboundItemResponse selectPriceInto(InboundItemVO inboundItemVO) {
+        List<InboundItemResponse> inboundItemResponses = inboundItemMapper.selectPriceInto(new InboundItemQuery().setSkuId(inboundItemVO.getSkuId())
+                .setNonStdCode(inboundItemVO.getNonStdCode())
+                .setWhId(inboundItemVO.getWhId()));
+        if (inboundItemResponses != null && inboundItemResponses.size() > 0) {
+            return inboundItemResponses.get(0);
+        }
+        return null;
+    }
+
+    /**
      * @desc : 其他入库新建
      * @date : 2024/3/7 14:13
      * @author : 寇珊珊
      */
     @Transactional(rollbackFor = {Exception.class})
     public ResponseResultVO<?> otherInboundInsert(InboundVO inboundVO) {
+        //校验明细
+        if (inboundVO.getItemList().size() == 0) {
+            throw new BaseBusinessException(ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getCode(),
+                    ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage());
+        }
+
+        //region  查询当前入库明细中是否存在未空或者0的入库价,如果存在去库存流水差最近一条有价格的数据赋值到当前明细
+        Boolean priceIntoFlag = false;
+        for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
+            if(inboundItemVO.getPriceInto()==null || inboundItemVO.getPriceInto().compareTo(BigDecimal.ZERO)==0){
+                priceIntoFlag = true;
+                //查询库存批次最近一条入库价
+                InboundItemResponse inboundItemResponse = this.selectPriceInto(inboundItemVO);
+                inboundItemVO.setPriceInto(inboundItemResponse != null ? inboundItemResponse.getPriceInto() : BigDecimal.ZERO);
+                inboundItemVO.setIntoingAmt(inboundItemResponse != null ? inboundItemResponse.getPriceInto().multiply(inboundItemVO.getIntoingQty()).setScale(2, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO);
+                inboundItemVO.setCostPrice(inboundItemResponse != null ? inboundItemResponse.getCostPrice() : BigDecimal.ZERO);
+                inboundItemVO.setCostAmt(inboundItemResponse != null ? inboundItemResponse.getCostPrice().multiply(inboundItemVO.getIntoingQty()).setScale(2, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO);
+            }
+        }
+        if(priceIntoFlag){
+            BigDecimal intoingAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
+            inboundVO.setIntoingAmt(intoingAmt);
+        }
+        //endregion
+
+
         //region  查询当前公司的系统参数  自动办理信息  并赋值
         Map<String, Object> map = new HashMap<>();
         map.put("cpId", inboundVO.getCpId());
@@ -162,11 +207,6 @@ public class InboundOtherService extends BaseService<Inbound> {
         //endregion
 
         //region 明细
-        //校验明细
-        if (inboundVO.getItemList().size() == 0) {
-            throw new BaseBusinessException(ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getCode(),
-                    ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage());
-        }
         for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
             //region 将库存需要的参数赋值
             inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName());
@@ -212,7 +252,6 @@ public class InboundOtherService extends BaseService<Inbound> {
         }
         //endregion
 
-
         return ResponseResultUtil.success(inboundVO);
     }
 
@@ -305,6 +344,7 @@ public class InboundOtherService extends BaseService<Inbound> {
                         InboundItem inboundItem = inboundItemConvert.convertToPo(inboundItemVO);
                         inboundItemMapper.insert(inboundItem);
                         inboundItemVO.setItemId(inboundItem.getItemId());
+
                         //region 将库存需要的参数赋值
                         inboundItemVO.setInventoryType(Constant.InventoryType.INBOUND.getName());
                         inboundItemVO.setInventoryDocCode(Constant.InventoryDocCode.OTHER_INBOUND.getValue());

+ 41 - 5
src/main/java/com/dk/mdm/service/ivt/inbound/InboundPurchaseService.java

@@ -118,6 +118,22 @@ public class InboundPurchaseService extends BaseService<Inbound> {
     }
 
     /**
+     * @desc   : 查询入库价
+     * @date   : 2024/7/1 11:29
+     * @author : 寇珊珊
+     */
+    @Transactional(rollbackFor = {Exception.class})
+    public InboundItemResponse selectPriceInto(InboundItemVO inboundItemVO) {
+        List<InboundItemResponse> inboundItemResponses = inboundItemMapper.selectPriceInto(new InboundItemQuery().setSkuId(inboundItemVO.getSkuId())
+                .setNonStdCode(inboundItemVO.getNonStdCode())
+                .setWhId(inboundItemVO.getWhId()));
+        if (inboundItemResponses != null && inboundItemResponses.size() > 0) {
+            return inboundItemResponses.get(0);
+        }
+        return null;
+    }
+
+    /**
      * @desc : 采购入库新建
      * @date : 2024/3/7 14:13
      * 入库中数量/金额  已入库数量/金额  由调用方传入
@@ -125,6 +141,31 @@ public class InboundPurchaseService extends BaseService<Inbound> {
      */
     @Transactional(rollbackFor = {Exception.class})
     public ResponseResultVO<?> purchaseInboundInsert(InboundVO inboundVO) {
+        //region 校验明细
+        if (inboundVO.getItemList().size() == 0) {
+            throw new BaseBusinessException(ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getCode(),
+                    ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage());
+        }
+        //endregion
+
+        //region  查询当前入库明细中是否存在未空或者0的入库价,如果存在去库存流水差最近一条有价格的数据赋值到当前明细
+        Boolean priceIntoFlag = false;
+        for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
+            if(inboundItemVO.getPriceInto()==null || inboundItemVO.getPriceInto().compareTo(BigDecimal.ZERO)==0){
+                priceIntoFlag = true;
+                //查询库存批次最近一条入库价
+                InboundItemResponse inboundItemResponse = this.selectPriceInto(inboundItemVO);
+                inboundItemVO.setPriceInto(inboundItemResponse != null ? inboundItemResponse.getPriceInto() : BigDecimal.ZERO);
+                inboundItemVO.setIntoingAmt(inboundItemResponse != null ? inboundItemResponse.getPriceInto().multiply(inboundItemVO.getIntoingQty()).setScale(2, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO);
+                inboundItemVO.setCostPrice(inboundItemResponse != null ? inboundItemResponse.getCostPrice() : BigDecimal.ZERO);
+                inboundItemVO.setCostAmt(inboundItemResponse != null ? inboundItemResponse.getCostPrice().multiply(inboundItemVO.getIntoingQty()).setScale(2, BigDecimal.ROUND_HALF_UP) : BigDecimal.ZERO);
+            }
+        }
+        if(priceIntoFlag){
+            BigDecimal intoingAmt = inboundVO.getItemList().stream().map(InboundItemVO::getIntoingAmt).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(6, BigDecimal.ROUND_HALF_UP);
+            inboundVO.setIntoingAmt(intoingAmt);
+        }
+        //endregion
 
         //region  查询当前公司的系统参数  自动办理信息  并赋值
         Map<String, Object> map = new HashMap<>();
@@ -206,11 +247,6 @@ public class InboundPurchaseService extends BaseService<Inbound> {
         //endregion
 
         //region 明细
-        //校验明细
-        if (inboundVO.getItemList().size() == 0) {
-            throw new BaseBusinessException(ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getCode(),
-                    ErrorCodeEnum.INBOUND_ITEM_NOT_EXIST.getMessage());
-        }
         for (InboundItemVO inboundItemVO : inboundVO.getItemList()) {
 
             //region 将库存需要的参数赋值

+ 2 - 1
src/main/java/com/dk/mdm/service/ivt/inventory/InventoryService.java

@@ -1162,7 +1162,8 @@ public class InventoryService extends BaseService<Inventory> {
             //region  校验库存  根据sku,仓库,非标号查询
             InventoryResponse inventoryResponse = inventoryMapper.selectByOther(new InventoryQuery()
                     .setSkuId(inOutRecordVO.getSkuId())
-                    .setWhId(inOutRecordVO.getWhId())
+                    //原库存id存在取原库存id
+                    .setWhId(inOutRecordVO.getWhIdPri()==null ? inOutRecordVO.getWhId() : inOutRecordVO.getWhIdPri())
                     .setNonStdCode(inOutRecordVO.getNonStdCode()));
             //库存是否存在
             if (inventoryResponse == null) {