2 次代碼提交 59831ed4ec ... f206c4e49b

作者 SHA1 備註 提交日期
  xiaomi f206c4e49b Merge remote-tracking branch 'origin/master' 1 年之前
  xiaomi 17a07a1161 in方法和out方法(还未写完) 1 年之前

+ 7 - 0
sd-business/src/main/java/com/sd/business/entity/in/po/InOutStorageBom.java

@@ -41,4 +41,11 @@ public class InOutStorageBom extends BasePo implements InOutFun {
     @DecimalMin(value = "0.01", message = "出入库数量必须大于0")
     private BigDecimal quantity;
 
+    @DecimalMin(value = "0.01",message = "入库单价必须大于0")
+    private BigDecimal getUnitPrice;
+
+    @Override
+    public BigDecimal getUnitPrice() {
+        return null;
+    }
 }

+ 63 - 0
sd-business/src/main/java/com/sd/business/entity/in/po/InOutStorageDetails.java

@@ -0,0 +1,63 @@
+package com.sd.business.entity.in.po;
+
+import com.ruoyi.common.core.domain.BasePo;
+import com.baomidou.mybatisplus.annotation.TableName;
+import java.math.BigDecimal;
+import java.util.Date;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * <p>
+ * 出入库详情表
+ * </p>
+ *
+ * @author 
+ * @since 2023-07-25
+ */
+@Getter
+@Setter
+@TableName("in_out_storage_details")
+public class InOutStorageDetails extends BasePo {
+
+    /**
+     * 出入库id
+     */
+    private Long inOutStorageId;
+
+    /**
+     * 类型:1入库 0出库
+     */
+    private Long type;
+
+    /**
+     * 库存id
+     */
+    private Long inventoryId;
+
+    /**
+     * 仓库id
+     */
+    private Long warehouseId;
+
+    /**
+     * bom规格id
+     */
+    private Long bomSpecId;
+
+    /**
+     * 入库金额
+     */
+    private BigDecimal inSumPrice;
+
+    /**
+     * 入库单价
+     */
+    private BigDecimal inUnitPrice;
+
+    /**
+     * 入库数量
+     */
+    private BigDecimal quantity;
+
+}

+ 6 - 0
sd-business/src/main/java/com/sd/business/entity/inventory/bo/InOutFun.java

@@ -14,4 +14,10 @@ public interface InOutFun {
      */
     BigDecimal getQuantity();
 
+    /**
+     * 入库单价
+     * @return
+     */
+    BigDecimal getUnitPrice();
+
 }

+ 16 - 0
sd-business/src/main/java/com/sd/business/mapper/inventory/InventoryMapper.java

@@ -3,12 +3,14 @@ package com.sd.business.mapper.inventory;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.common.utils.wrapper.IWrapper;
+import com.sd.business.entity.in.po.InOutStorageDetails;
 import com.sd.business.entity.inventory.po.Inventory;
 import com.sd.business.entity.inventory.vo.InventoryVo;
 import com.sd.business.entity.inventory.vo.QuantityByDepartmentVo;
 import com.sd.business.entity.inventory.vo.QuantityByWarehouseVo;
 import org.apache.ibatis.annotations.Param;
 
+import java.math.BigDecimal;
 import java.util.List;
 
 
@@ -39,4 +41,18 @@ public interface InventoryMapper extends BaseMapper<Inventory> {
      */
     List<QuantityByDepartmentVo> getQuantityByDepartment();
 
+    /**
+     * 根据规格id获取结存数量
+     */
+    BigDecimal getNum(@Param("bomSpecId") Long bomSpecId,Long warehouseId);
+
+    /**
+     * 根据规格id获取结存金额
+     */
+    BigDecimal getprice(@Param("bomSpecId") Long bomSpecId, Long warehouseId);
+
+    /**
+     * 获取出入库详情表的数据
+     */
+    List<InOutStorageDetails> getInOutDetails(Long warehouseId, Long departmentId, Long bomSpecId);
 }

+ 57 - 1
sd-business/src/main/java/com/sd/business/service/inventory/impl/InventoryServiceImpl.java

@@ -1,11 +1,17 @@
 package com.sd.business.service.inventory.impl;
 
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.collection.CollectionUtil;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.wrapper.IWrapper;
+import com.ruoyi.system.utils.UserUtil;
 import com.sd.business.entity.bom.po.Bom;
 import com.sd.business.entity.bom.po.BomSpec;
+import com.sd.business.entity.bom.vo.BomSpecVo;
+import com.sd.business.entity.in.po.InOutStorageDetails;
 import com.sd.business.entity.inventory.bo.InOutFun;
 import com.sd.business.entity.inventory.dto.InventorySelectDto;
 import com.sd.business.entity.inventory.po.Inventory;
@@ -16,8 +22,11 @@ import com.sd.business.entity.inventory.vo.QuantityByWarehouseVo;
 import com.sd.business.mapper.inventory.InventoryMapper;
 import com.sd.business.service.bom.BomSpecService;
 import com.sd.business.service.inventory.InventoryService;
+import lombok.RequiredArgsConstructor;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
 
 import java.math.BigDecimal;
 import java.util.ArrayList;
@@ -41,6 +50,9 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
     @Autowired
     private BomSpecService bomSpecService;
 
+    @Autowired
+    private InventoryMapper inventoryMapper;
+
     @Override
     public Page<InventoryVo> getPage(InventorySelectDto dto, String tableName) {
         IWrapper<Inventory> wrapper = getWrapper();
@@ -85,7 +97,26 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
             for (InOutFun inOutFun : list) {
                 Long bomSpecId = inOutFun.getBomSpecId();
                 BigDecimal quantity = inOutFun.getQuantity();
+                BigDecimal unitPrice = inOutFun.getUnitPrice();
                 Inventory inventory = map.get(bomSpecId);
+
+                //结存数量
+                BigDecimal balanceNum = inventoryMapper.getNum(bomSpecId,warehouseId);
+                if (balanceNum == null){
+                    balanceNum = BigDecimal.ZERO;
+                }
+                //结存金额
+                BigDecimal balancePrice = inventoryMapper.getprice(bomSpecId,warehouseId);
+                if (balancePrice == null){
+                    balancePrice = BigDecimal.ZERO;
+                }
+
+                //计算最新的结存数量和结存金额
+                balanceNum = balanceNum.add(quantity);
+                BigDecimal balancep = quantity.multiply(unitPrice);
+                balancePrice = balancePrice.add(balancep);
+                BigDecimal balanceUnitPrice = balancePrice.divide(balanceNum,2,BigDecimal.ROUND_HALF_UP);
+
                 if (inventory != null) {
                     inventory.setQuantity(inventory.getQuantity().add(quantity));
                 } else {
@@ -94,6 +125,8 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
                     inventory.setDepartmentId(departmentId);
                     inventory.setBomSpecId(bomSpecId);
                     inventory.setQuantity(quantity);
+                    inventory.setBalanceUnitPrice(balanceUnitPrice);
+
                     inventoryList.add(inventory);
                     map.put(bomSpecId, inventory);
                 }
@@ -124,7 +157,30 @@ public class InventoryServiceImpl extends ServiceImpl<InventoryMapper, Inventory
             }
 
             for (Inventory inventory : inventoryList) {
-                inventory.setQuantity(inventory.getQuantity().subtract(map.get(inventory.getBomSpecId())));
+
+                //获取出入详情表中的信息
+                List<InOutStorageDetails> detailsList = inventoryMapper.getInOutDetails(inventory.getWarehouseId(),inventory.getDepartmentId(),inventory.getBomSpecId());
+                if (CollUtil.isEmpty(detailsList)){
+                    throw new ServiceException("库存为空");
+                }
+                //按照时间进行排序后获取最早入库的数据
+                //TODO 该地方可能用循环
+                InOutStorageDetails inOutDetails = detailsList.get(0);
+                BigDecimal quantity = inOutDetails.getQuantity();
+
+                int i = inventory.getQuantity().compareTo(quantity);
+                if (i >= 0){
+
+                    inventory.setQuantity(inventory.getQuantity().subtract(map.get(inventory.getBomSpecId())));
+
+                }
+
+
+
+
+
+
+
             }
             updateBatchById(inventoryList);
         }

+ 49 - 0
sd-business/src/main/resources/mapper/inventory/InventoryMapper.xml

@@ -41,4 +41,53 @@
         order by d.id
     </select>
 
+    <select id="getNum" resultType="decimal">
+        select sum(ifnull(i.quantity, 0))
+        from in_out_storage_details i
+        <where>
+            <if test="bomSpecId != null">
+                and bom_spec_id = #{bomSpecId}
+            </if>
+            <if test="warehouseId != null">
+                and warehouse_id = #{warehouseId}
+            </if>
+            and type = 1
+        </where>
+    </select>
+
+    <select id="getprice" resultType="decimal">
+        select sum(ifnull(i.in_sum_price, 0))
+        from in_out_storage_details i
+        <where>
+            <if test="bomSpecId != null">
+                and  bom_spec_id = #{bomSpecId}
+            </if>
+            <if test="warehouseId != null">
+                and warehouse_id = #{warehouseId}
+            </if>
+            and type = 1
+        </where>
+    </select>
+
+    <select id="getInOutDetails" resultType="com.sd.business.entity.in.po.InOutStorageDetails">
+        select i.quantity,
+               i.in_unit_price,
+               i.in_sum_price
+        from in_out_storage_details i
+        <where>
+            <if test="bomSpecId != null">
+                and bom_spec_id = #{bomSpecId}
+            </if>
+            <if test="warehouseId != null">
+                and warehouse_id = #{warehouseId}
+            </if>
+            <if test="departmentId != null">
+                and department_id = #{departmentId}
+            </if>
+            and type = 1
+            and quantity > 0
+        </where>
+        order by i.create
+    </select>
+
 </mapper>