Переглянути джерело

Merge remote-tracking branch 'origin/master'

24282 1 рік тому
батько
коміт
d071bac350

+ 0 - 7
sd-business/src/main/java/com/sd/business/mapper/in/InOutStorageMapper.java

@@ -24,11 +24,4 @@ public interface InOutStorageMapper extends BaseMapper<InOutStorage> {
      * 出入库分页
      */
     Page<InOutStorageVo> getPage(@Param("page") Page<Object> page, @Param("ew") IWrapper<InOutStorage> wrapper);
-
-    /**
-     * 查询bom消耗量
-     * @param wrapper
-     * @return
-     */
-    BigDecimal getOutStorageQuantity(@Param("ew") IWrapper<InOutStorage> wrapper);
 }

+ 14 - 0
sd-business/src/main/java/com/sd/business/mapper/order/OrderMapper.java

@@ -7,6 +7,8 @@ import com.sd.business.entity.order.po.OrderInfo;
 import com.sd.business.entity.order.vo.OrderInfoVo;
 import org.apache.ibatis.annotations.Param;
 
+import java.math.BigDecimal;
+
 /**
  * <p>
  * 订单 Mapper 接口
@@ -22,4 +24,16 @@ public interface OrderMapper extends BaseMapper<OrderInfo> {
      */
     Page<OrderInfoVo> getPage(@Param("page") Page<Object> page, @Param("ew") IWrapper<OrderInfo> wrapper);
 
+
+    /**
+     * 获取订单sku 出库数量
+     * @return
+     */
+    BigDecimal getOrderSkuOutStorageQuantity(@Param("ew") IWrapper<OrderInfo> wrapper);
+
+    /**
+     * 获取订单sku bom出库数量
+     * @return
+     */
+    BigDecimal getOrderSkuBomOutStorageQuantity(@Param("ew") IWrapper<OrderInfo> wrapper);
 }

+ 4 - 4
sd-business/src/main/java/com/sd/business/service/department/impl/DepartmentServiceImpl.java

@@ -58,10 +58,10 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
         wrapper.apply(ObjectUtil.isNotEmpty(dto.getPriceBillingStandardId()),
                 "find_in_set({0}, d.price_billing_standard_id)", dto.getPriceBillingStandardId());
 
-        List<Long> detpIdList = sysUserService.getDetpIdListByUserId(SecurityUtils.getUserId());
-        if (detpIdList.size() > 0) {
-            wrapper.in("d", Department::getId, detpIdList);
-        }
+//        List<Long> detpIdList = sysUserService.getDetpIdListByUserId(SecurityUtils.getUserId());
+//        if (detpIdList.size() > 0) {
+//            wrapper.in("d", Department::getId, detpIdList);
+//        }
 
         Page<DepartmentVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
         return page;

+ 0 - 11
sd-business/src/main/java/com/sd/business/service/in/InOutStorageService.java

@@ -8,8 +8,6 @@ import com.sd.business.entity.in.dto.InOutStorageSelectDto;
 import com.sd.business.entity.in.po.InOutStorage;
 import com.sd.business.entity.in.vo.InOutStorageVo;
 
-import java.math.BigDecimal;
-
 
 /**
  * <p>
@@ -40,13 +38,4 @@ public interface InOutStorageService extends BaseService<InOutStorage> {
      * 调拨入库
      */
     void addAllot(AddAllotDto dto);
-
-    /**
-     * 查询bom消耗数量
-     *
-     * @param bomSpecId
-     * @param days      天数
-     */
-    BigDecimal getOutStorageQuantityByBomSpecIdAndDays(Long bomSpecId, Integer days);
-
 }

+ 0 - 15
sd-business/src/main/java/com/sd/business/service/in/impl/InOutStorageServiceImpl.java

@@ -1,7 +1,6 @@
 package com.sd.business.service.in.impl;
 
 import cn.hutool.core.bean.BeanUtil;
-import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson2.JSON;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
@@ -28,8 +27,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import java.math.BigDecimal;
-import java.util.Date;
 import java.util.List;
 
 
@@ -133,16 +130,4 @@ public class InOutStorageServiceImpl extends ServiceImpl<InOutStorageMapper, InO
 
     }
 
-    @Override
-    public BigDecimal getOutStorageQuantityByBomSpecIdAndDays(Long bomSpecId, Integer days) {
-        Date date = DateUtil.date();
-        Date offsetDay = DateUtil.offsetDay(date, -days);
-        IWrapper<InOutStorage> wrapper = getWrapper();
-        wrapper.eq("ios", InOutStorage::getType, InOutTypeEnum.OUT.getKey());
-        wrapper.eq("ios", InOutStorage::getDetailType, OutDetailTypeEnum.PRODUCTION.getKey());
-        wrapper.eq("iosb", InOutStorageBom::getBomSpecId, bomSpecId);
-        wrapper.ge("iosb", InOutStorageBom::getCreateTime, offsetDay);
-        return this.baseMapper.getOutStorageQuantity(wrapper);
-    }
-
 }

+ 10 - 0
sd-business/src/main/java/com/sd/business/service/order/OrderService.java

@@ -11,6 +11,8 @@ import com.sd.business.entity.order.vo.CompareVo;
 import com.sd.business.entity.order.vo.OrderInfoVo;
 import com.sd.business.entity.order.vo.SkuSpecPriceVo;
 
+import java.math.BigDecimal;
+
 /**
  * <p>
  * 订单 服务类
@@ -81,4 +83,12 @@ public interface OrderService extends BaseService<OrderInfo> {
      */
     CompareVo compare(OrderSelectDto dto);
 
+    /**
+     * 获取订单bom的出库数量
+     * @param bomSpecId bom规格id
+     * @param days 查询多少天前的数据
+     * @return
+     */
+    BigDecimal getOrderBomSpecOutStorageQuantity(Long bomSpecId, Integer days);
+
 }

+ 35 - 5
sd-business/src/main/java/com/sd/business/service/order/impl/OrderServiceImpl.java

@@ -2,6 +2,7 @@ package com.sd.business.service.order.impl;
 
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.convert.Convert;
+import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.dynamic.datasource.annotation.DSTransactional;
@@ -34,6 +35,7 @@ import com.sd.business.entity.order.vo.*;
 import com.sd.business.entity.price.po.PriceBillingStandard;
 import com.sd.business.entity.price.po.PriceBillingStandardDetail;
 import com.sd.business.entity.sku.po.SkuSpec;
+import com.sd.business.entity.statement.po.StatementOfAccount;
 import com.sd.business.entity.warehouse.constant.WarehouseConstant;
 import com.sd.business.mapper.order.OrderMapper;
 import com.sd.business.service.bom.BomService;
@@ -44,6 +46,7 @@ import com.sd.business.service.order.*;
 import com.sd.business.service.price.PriceBillingStandardDetailService;
 import com.sd.business.service.price.PriceBillingStandardService;
 import com.sd.business.service.sku.SkuSpecService;
+import com.sd.business.service.statement.StatementOfAccountService;
 import com.sd.framework.util.Assert;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -98,6 +101,9 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
     private InOutStorageService inOutStorageService;
 
     @Autowired
+    private StatementOfAccountService statementOfAccountService;
+
+    @Autowired
     private ISysUserService sysUserService;
 
     @Override
@@ -119,11 +125,11 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
                 .or(r -> r.eq("o", OrderInfo::getSource, 1))
         );
 
-        List<Long> detpIdList = sysUserService.getDetpIdListByUserId(SecurityUtils.getUserId());
-        if (detpIdList.size() > 0) {
-            wrapper.in("o", OrderInfo::getDepartmentId, detpIdList);
-            wrapper.eq("o", OrderInfo::getCreateUser, SecurityUtils.getUserId());
-        }
+//        List<Long> detpIdList = sysUserService.getDetpIdListByUserId(SecurityUtils.getUserId());
+//        if (detpIdList.size() > 0) {
+//            wrapper.in("o", OrderInfo::getDepartmentId, detpIdList);
+//            wrapper.eq("o", OrderInfo::getCreateUser, SecurityUtils.getUserId());
+//        }
 
         if (Objects.equals(dto.getLinkedStatementOfAccount(), 0)) {
             wrapper.isNull("o.statement_of_account_id");
@@ -621,6 +627,30 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderInfo> implem
         return compareVo;
     }
 
+    @Override
+    public BigDecimal getOrderBomSpecOutStorageQuantity(Long bomSpecId, Integer days) {
+        Date date = DateUtil.date();
+        Date offsetDay = DateUtil.offsetDay(date, -days);
+
+        // 根据对账时间获取有对账单的订单
+        List<StatementOfAccount> list = statementOfAccountService.list(q -> q.ge(StatementOfAccount::getTimePeriod, offsetDay));
+        List<Long> accountIds = list.stream().map(StatementOfAccount::getId).collect(Collectors.toList());
+
+        Map<Long, BomSpecBo> bomSpecBo = skuSpecService.getBomSpecBoByIdList(Collections.singleton(bomSpecId));
+        IWrapper<OrderInfo> wrapper = getWrapper();
+        wrapper.ge("o", OrderInfo::getStatus, OrderStatusEnum.IN_PRODUCTION.getKey());
+        wrapper.in("o", OrderInfo::getStatementOfAccountId, accountIds);
+        if (ObjectUtil.equal(bomSpecBo.get(bomSpecId).getClassifyParentId(), 1L)) {
+            // 查询主材消耗数量
+            wrapper.eq("os", OrderSku::getBomSpecId, bomSpecId);
+            return this.baseMapper.getOrderSkuOutStorageQuantity(wrapper);
+        } else {
+            // 查询包材消耗数量
+            wrapper.eq("osb", OrderSkuBom::getBomSpecId, bomSpecId);
+            return this.baseMapper.getOrderSkuBomOutStorageQuantity(wrapper);
+        }
+    }
+
     /**
      * 删除订单以及订单关联数据
      */

+ 9 - 6
sd-business/src/main/java/com/sd/business/service/purchase/impl/PurchaseBomServiceImpl.java

@@ -24,6 +24,7 @@ import com.sd.business.service.bom.BomClassifyService;
 import com.sd.business.service.bom.BomSpecService;
 import com.sd.business.service.in.InOutStorageService;
 import com.sd.business.service.inventory.InventoryService;
+import com.sd.business.service.order.OrderService;
 import com.sd.business.service.purchase.PurchaseBomService;
 import com.sd.framework.util.Assert;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -57,6 +58,9 @@ public class PurchaseBomServiceImpl extends ServiceImpl<PurchaseBomMapper, Purch
 
     @Autowired
     private InOutStorageService inOutStorageService;
+    
+    @Autowired
+    private OrderService orderService;
 
     @Autowired
     private InventoryService inventoryService;
@@ -156,17 +160,16 @@ public class PurchaseBomServiceImpl extends ServiceImpl<PurchaseBomMapper, Purch
             // 当前库存数
             BigDecimal inventoryQuantity = ObjectUtil.isEmpty(inventory) ? new BigDecimal("0") : inventory.getQuantity();
             // 近7天消耗量
-            BigDecimal quantitySevenDays = inOutStorageService.getOutStorageQuantityByBomSpecIdAndDays(record.getId(), 7);
+            BigDecimal quantitySevenDays = orderService.getOrderBomSpecOutStorageQuantity(record.getId(), 7);
             // 近30天消耗量
-            BigDecimal quantityThirtyDays = inOutStorageService.getOutStorageQuantityByBomSpecIdAndDays(record.getId(), 30);
+            BigDecimal quantityThirtyDays = orderService.getOrderBomSpecOutStorageQuantity(record.getId(), 30);
 
             // 40天安全库存
             BigDecimal safetyInventoryQuantity = quantityThirtyDays.divide(new BigDecimal("30"), 2, RoundingMode.HALF_UP)
                     .multiply(new BigDecimal("40")).setScale(0, RoundingMode.HALF_UP);
 
-
             // 近14天消耗量
-            BigDecimal quantityTwoWeek = inOutStorageService.getOutStorageQuantityByBomSpecIdAndDays(record.getId(), 14);
+            BigDecimal quantityTwoWeek = orderService.getOrderBomSpecOutStorageQuantity(record.getId(), 14);
             // 近两周减去近一周的消耗量为上周数量
             BigDecimal quantityLastWeek = quantityTwoWeek.subtract(quantitySevenDays);
             // 周环比率
@@ -218,8 +221,8 @@ public class PurchaseBomServiceImpl extends ServiceImpl<PurchaseBomMapper, Purch
             purchaseBomBoard.setSafetyInventoryQuantity(safetyInventoryQuantity);
             purchaseBomBoard.setOutStorageQuantitySevenDays(quantitySevenDays);
             purchaseBomBoard.setOutStorageQuantityThirtyDays(quantityThirtyDays);
-            purchaseBomBoard.setOutStorageQuantityFifteenDays(inOutStorageService.getOutStorageQuantityByBomSpecIdAndDays(record.getId(), 15));
-            purchaseBomBoard.setOutStorageQuantitySixtyDays(inOutStorageService.getOutStorageQuantityByBomSpecIdAndDays(record.getId(), 60));
+            purchaseBomBoard.setOutStorageQuantityFifteenDays(orderService.getOrderBomSpecOutStorageQuantity(record.getId(), 15));
+            purchaseBomBoard.setOutStorageQuantitySixtyDays(orderService.getOrderBomSpecOutStorageQuantity(record.getId(), 60));
             purchaseBomBoard.setOutStorageWeekOnWeekRatio(weekOnWeekRatio);
             purchaseBomBoard.setNextDeliveryDays((int) nextDeliveryDays);
             list.add(purchaseBomBoard);

+ 0 - 8
sd-business/src/main/resources/mapper/in/InOutStorageMapper.xml

@@ -26,12 +26,4 @@
             ${ew.customSqlSegment}
     </select>
 
-    <select id="getOutStorageQuantity" resultType="java.math.BigDecimal">
-        select
-            ifnull(sum(iosb.quantity), 0)
-        from in_out_storage ios
-                 left join in_out_storage_bom iosb on ios.id = iosb.in_out_storage_id
-            ${ew.customSqlSegment}
-    </select>
-
 </mapper>

+ 18 - 0
sd-business/src/main/resources/mapper/order/OrderMapper.xml

@@ -54,4 +54,22 @@
             ${ew.customSqlSegment}
     </select>
 
+       <select id="getOrderSkuOutStorageQuantity" resultType="java.math.BigDecimal">
+            select
+                ifnull(sum(os.quantity), 0)
+            from
+                order_info o
+                LEFT JOIN order_sku os on o.id = os.order_id
+                ${ew.customSqlSegment}
+       </select>
+
+       <select id="getOrderSkuBomOutStorageQuantity" resultType="java.math.BigDecimal">
+            select
+                ifnull(sum(os.quantity * osb.quantity), 0)
+            from
+                order_info o
+                LEFT JOIN order_sku os on o.id = os.order_id
+                LEFT JOIN order_sku_bom osb on os.id = osb.order_sku_id
+                ${ew.customSqlSegment}
+       </select>
 </mapper>