@ -2,6 +2,7 @@ package com.win.module.wms.util;
import cn.hutool.json.JSONObject ;
import cn.hutool.json.JSONUtil ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
import com.win.module.wms.controller.rule.vo.RuleRespVO ;
import com.win.module.wms.dal.dataobject.balance.BalanceDO ;
import com.win.module.wms.dal.dataobject.businesstype.BusinesstypeDO ;
@ -725,4 +726,153 @@ public class JobUtils {
return true ;
}
/ * *
* 根据批次策略 / 下架策略 返回 库存余额DO
* @param itemCode
* @param inventoryStatus
* @param projectCode
* @param qty
* @return
* /
public List < BalanceDO > getBalanceByBatchOffShelf ( String itemCode , String inventoryStatus , String projectCode , BigDecimal qty ) {
// 批次策略
RuleRespVO ruleRespVOBatch = ruleService . batch ( null , null , null , null , null , projectCode , itemCode ) ;
JSONObject jsonObjectBatch = JSONUtil . parseObj ( ruleRespVOBatch . getConfiguration ( ) ) ;
// 下架策略
RuleRespVO ruleRespVOOffShelf = ruleService . offShelf ( null , null , null , null , null , projectCode , itemCode , inventoryStatus , null , null ) ;
JSONObject jsonObjectOffShelf = JSONUtil . parseObj ( ruleRespVOOffShelf . getConfiguration ( ) ) ;
// 查询库存余额
QueryWrapper queryWrapper = new QueryWrapper ( ) ;
queryWrapper . select ( "item_code" , "batch" , "SUM(qty) as qty" , "packing_number" , "container_number" , "warehouse_code" , "area_code" , "location_group_code" , "location_code" , "produce_date" , "arrive_date" ) ;
if ( itemCode ! = null & & ! itemCode . equals ( "" ) ) {
queryWrapper . eq ( "item_code" , itemCode ) ;
} else {
return null ;
}
if ( inventoryStatus ! = null & & ! inventoryStatus . equals ( "" ) ) {
queryWrapper . eq ( "inventory_status" , inventoryStatus ) ;
} else {
return null ;
}
// 根据下架策略 作为查询库存余额条件
// 仓库
if ( jsonObjectOffShelf . get ( "WarehouseCode" ) ! = null & & ! jsonObjectOffShelf . get ( "WarehouseCode" ) . equals ( "" ) ) {
queryWrapper . eq ( "warehouse_code" , jsonObjectOffShelf . get ( "WarehouseCode" ) ) ;
}
// 库区
if ( jsonObjectOffShelf . get ( "AreaCode" ) ! = null & & ! jsonObjectOffShelf . get ( "AreaCode" ) . equals ( "" ) ) {
queryWrapper . eq ( "area_code" , jsonObjectOffShelf . get ( "AreaCode" ) ) ;
}
// 库位组
if ( jsonObjectOffShelf . get ( "LocationGroupCode" ) ! = null & & ! jsonObjectOffShelf . get ( "LocationGroupCode" ) . equals ( "" ) ) {
queryWrapper . eq ( "location_group_code" , jsonObjectOffShelf . get ( "LocationGroupCode" ) ) ;
}
// 库位
if ( jsonObjectOffShelf . get ( "LocationCode" ) ! = null & & ! jsonObjectOffShelf . get ( "LocationCode" ) . equals ( "" ) ) {
queryWrapper . eq ( "location_code" , jsonObjectOffShelf . get ( "LocationCode" ) ) ;
}
// 根据下架策略 作为查询库存余额分组
// 发料包装类型——按 包装
if ( jsonObjectOffShelf . get ( "IssueStorageType" ) ! = null & & jsonObjectOffShelf . get ( "IssueStorageType" ) . equals ( "1" ) ) {
queryWrapper . groupBy ( "packing_number" ) ;
}
// 发料包装类型——按 容器
if ( jsonObjectOffShelf . get ( "IssueStorageType" ) ! = null & & jsonObjectOffShelf . get ( "IssueStorageType" ) . equals ( "2" ) ) {
queryWrapper . groupBy ( "container_number" ) ;
}
// 发料包装类型——按 单件
if ( jsonObjectOffShelf . get ( "IssueStorageType" ) ! = null & & jsonObjectOffShelf . get ( "IssueStorageType" ) . equals ( "3" ) ) {
queryWrapper . groupBy ( "item_code" , "batch" , "qty" , "packing_number" , "container_number" , "warehouse_code" , "area_code" , "location_group_code" , "location_code" , "expire_date" , "produce_date" , "arrive_date" ) ;
}
// 根据批次策略 作为查询库存余额排序
// 批次类型——按 生产时间
if ( jsonObjectBatch . get ( "BatchType" ) ! = null & & jsonObjectBatch . get ( "BatchType" ) . equals ( "0" ) ) {
// ASC = 0,正向
if ( jsonObjectBatch . get ( "BatchDirection" ) ! = null & & jsonObjectBatch . get ( "BatchDirection" ) . equals ( "0" ) ) {
queryWrapper . orderByAsc ( "produce_date" ) ;
}
// DESC = 1,逆向
if ( jsonObjectBatch . get ( "BatchDirection" ) ! = null & & jsonObjectBatch . get ( "BatchDirection" ) . equals ( "1" ) ) {
queryWrapper . orderByDesc ( "produce_date" ) ;
}
}
// 批次类型——按 到货时间
if ( jsonObjectBatch . get ( "BatchType" ) ! = null & & jsonObjectBatch . get ( "BatchType" ) . equals ( "1" ) ) {
// ASC = 0,正向
if ( jsonObjectBatch . get ( "BatchDirection" ) ! = null & & jsonObjectBatch . get ( "BatchDirection" ) . equals ( "0" ) ) {
queryWrapper . orderByAsc ( "arrive_date" ) ;
}
// DESC = 1,逆向
if ( jsonObjectBatch . get ( "BatchDirection" ) ! = null & & jsonObjectBatch . get ( "BatchDirection" ) . equals ( "1" ) ) {
queryWrapper . orderByDesc ( "arrive_date" ) ;
}
}
// 批次类型——按 失效时间
if ( jsonObjectBatch . get ( "BatchType" ) ! = null & & jsonObjectBatch . get ( "BatchType" ) . equals ( "2" ) ) {
// ASC = 0,正向
if ( jsonObjectBatch . get ( "BatchDirection" ) ! = null & & jsonObjectBatch . get ( "BatchDirection" ) . equals ( "0" ) ) {
queryWrapper . orderByAsc ( "expire_date" ) ;
}
// DESC = 1,逆向
if ( jsonObjectBatch . get ( "BatchDirection" ) ! = null & & jsonObjectBatch . get ( "BatchDirection" ) . equals ( "1" ) ) {
queryWrapper . orderByDesc ( "expire_date" ) ;
}
}
// 批次类型——按 供应商批次
if ( jsonObjectBatch . get ( "BatchType" ) ! = null & & jsonObjectBatch . get ( "BatchType" ) . equals ( "3" ) ) {
// TODO: 供应商批次 ??? 不知道怎么搞了
}
// 批次类型——按 供应商优先级
if ( jsonObjectBatch . get ( "BatchType" ) ! = null & & jsonObjectBatch . get ( "BatchType" ) . equals ( "4" ) ) {
// TODO: 供应商优先级 ??? 不知道怎么搞了
}
// 批次类型——按 其它批次
if ( jsonObjectBatch . get ( "BatchType" ) ! = null & & jsonObjectBatch . get ( "BatchType" ) . equals ( "5" ) ) {
// ASC = 0,正向
if ( jsonObjectBatch . get ( "BatchDirection" ) ! = null & & jsonObjectBatch . get ( "BatchDirection" ) . equals ( "0" ) ) {
queryWrapper . orderByAsc ( "batch" ) ;
}
// DESC = 1,逆向
if ( jsonObjectBatch . get ( "BatchDirection" ) ! = null & & jsonObjectBatch . get ( "BatchDirection" ) . equals ( "1" ) ) {
queryWrapper . orderByDesc ( "batch" ) ;
}
}
// 数量排序方向 正向
if ( jsonObjectOffShelf . get ( "QtyOrderDirection" ) ! = null & & jsonObjectOffShelf . get ( "QtyOrderDirection" ) . equals ( "ASC" ) ) {
queryWrapper . orderByAsc ( "qty" ) ;
}
// 数量排序方向 逆向
if ( jsonObjectOffShelf . get ( "QtyOrderDirection" ) ! = null & & jsonObjectOffShelf . get ( "QtyOrderDirection" ) . equals ( "DESC" ) ) {
queryWrapper . orderByDesc ( "qty" ) ;
}
// 任务子表数据
List < BalanceDO > balanceDOListJob = new ArrayList < > ( ) ;
List < BalanceDO > balanceDOList = balanceMapper . selectList ( queryWrapper ) ;
BigDecimal countQty = new BigDecimal ( 0 . 000000 ) ;
for ( BalanceDO balanceDO : balanceDOList ) {
// 查询 预计出 求和 数量
// TODO: 后续完善 根据 管理精度查询
QueryWrapper queryWrapperExpectout = new QueryWrapper ( ) ;
queryWrapperExpectout . select ( "SUM(qty) as qty" ) ;
queryWrapperExpectout . eq ( "item_code" , balanceDO . getItemCode ( ) ) ;
if ( balanceDO . getPackingNumber ( ) ! = null & & ! balanceDO . getPackingNumber ( ) . equals ( "" ) ) queryWrapperExpectout . eq ( "packing_number" , balanceDO . getPackingNumber ( ) ) ;
if ( balanceDO . getBatch ( ) ! = null & & ! balanceDO . getBatch ( ) . equals ( "" ) ) queryWrapperExpectout . eq ( "batch" , balanceDO . getBatch ( ) ) ;
queryWrapperExpectout . groupBy ( "item_code" , "packing_number" , "batch" ) ;
ExpectoutDO expectoutDO = expectoutMapper . selectOne ( queryWrapperExpectout ) ;
BigDecimal countQtyExpectout = new BigDecimal ( 0 . 000000 ) ;
if ( expectoutDO ! = null ) {
countQtyExpectout = expectoutDO . getQty ( ) ;
}
// balanceDO.getQty().subtract(countQtyExpectout) 扣减预计出数量
countQty = countQty . add ( balanceDO . getQty ( ) . subtract ( countQtyExpectout ) ) ;
balanceDOListJob . add ( balanceDO ) ;
// 数据列表循环累加 直到总和大于等于当前物品的qty {countQty >= balanceDO.getQty()}
if ( countQty . compareTo ( qty ) ! = - 1 ) {
break ;
}
}
return balanceDOListJob ;
}
}