|
|
@ -3,11 +3,20 @@ package com.win.module.wms.until.job; |
|
|
|
import cn.hutool.core.exceptions.UtilException; |
|
|
|
import cn.hutool.json.JSONObject; |
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.win.framework.common.exception.ErrorCode; |
|
|
|
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; |
|
|
|
import com.win.module.wms.dal.dataobject.expectout.ExpectoutDO; |
|
|
|
import com.win.module.wms.dal.dataobject.itembasic.ItembasicDO; |
|
|
|
import com.win.module.wms.dal.dataobject.location.LocationDO; |
|
|
|
import com.win.module.wms.dal.mysql.balance.BalanceMapper; |
|
|
|
import com.win.module.wms.dal.mysql.expectout.ExpectoutMapper; |
|
|
|
import com.win.module.wms.dal.mysql.location.LocationMapper; |
|
|
|
import com.win.module.wms.service.itembasic.ItembasicService; |
|
|
|
import com.win.module.wms.service.location.LocationService; |
|
|
|
import com.win.module.wms.service.rule.RuleService; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
@ -29,6 +38,17 @@ public class JobUtils { |
|
|
|
|
|
|
|
@Resource |
|
|
|
private LocationService locationService; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private LocationMapper locationMapper; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private BalanceMapper balanceMapper; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private ExpectoutMapper expectoutMapper ; |
|
|
|
@Resource |
|
|
|
private RuleService ruleService; |
|
|
|
/** |
|
|
|
* 解析JSON串,返回两个对象的集合 |
|
|
|
* |
|
|
@ -222,4 +242,347 @@ public class JobUtils { |
|
|
|
throw exception(INVENTORY_STATUS_AND_BUSINESS_OUT_INVENTORY_STATUS_NOT_EQUALS_OR_NULL); |
|
|
|
} |
|
|
|
} |
|
|
|
//调用公共方法查询库位信息
|
|
|
|
public LocationDO selectLocation(String pcode) { |
|
|
|
QueryWrapper queryWrapper = new QueryWrapper(); |
|
|
|
queryWrapper.eq("code",pcode); |
|
|
|
LocationDO locationDO = locationMapper.selectOne(queryWrapper); |
|
|
|
if(locationDO != null && "TRUE".equals(locationDO.getAvailable())){ |
|
|
|
return locationDO; |
|
|
|
}else { |
|
|
|
throw exception(LOCATION_NOT_EXISTS); |
|
|
|
} |
|
|
|
} |
|
|
|
public LocationDO selectLocationExist(String locationCode) { |
|
|
|
LocationDO locationDO = selectLocation(locationCode); |
|
|
|
return locationDO; |
|
|
|
} |
|
|
|
public RuleRespVO selectLocationStrategyRule(String warehouseCode, String areaCode, String locationGroupCode, String plocationCode) { |
|
|
|
RuleRespVO ruleRespVO = ruleService.warehouseStorage(warehouseCode,areaCode,locationGroupCode,plocationCode); |
|
|
|
return ruleRespVO; |
|
|
|
} |
|
|
|
public RuleRespVO selectLocationAndModRelation(String pitemCode) { |
|
|
|
RuleRespVO grounding = ruleService.grounding(null, null, null, null, null, null, pitemCode, null, null, null, null, null, null); |
|
|
|
if(grounding != null){ |
|
|
|
return grounding; |
|
|
|
}else { |
|
|
|
throw exception(LOCATION_ITEMCODE_AND_LOCATIONCODE_NOT_EXISTS); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//跟据管理模式查詢數量
|
|
|
|
//按數量查找 TB2-BY_QUANTITY
|
|
|
|
public List<BalanceDO> selectnumber(String itemcode, String inventorystatus, String locationcode){ |
|
|
|
QueryWrapper queryWrapper = new QueryWrapper(); |
|
|
|
queryWrapper.eq("item_code",itemcode); |
|
|
|
queryWrapper.eq("inventory_status",inventorystatus); |
|
|
|
queryWrapper.eq("location_code",locationcode); |
|
|
|
List<BalanceDO> balanceDO = balanceMapper.selectList(queryWrapper); |
|
|
|
if(!balanceDO.isEmpty()){ |
|
|
|
|
|
|
|
return balanceDO; |
|
|
|
} |
|
|
|
else{ |
|
|
|
throw exception(new ErrorCode(123,"物料号" + itemcode + "庫存狀態" + inventorystatus + "在"+ locationcode +"庫位中未查找到库存记录" )); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
//按批次查找 TB2-BY_BATCH
|
|
|
|
|
|
|
|
public List<BalanceDO> selectbatch(String itemcode, String batch ,String inventorystatus,String locationcode) { |
|
|
|
QueryWrapper queryWrapper = new QueryWrapper(); |
|
|
|
queryWrapper.eq("item_code",itemcode); |
|
|
|
queryWrapper.eq("batch",batch); |
|
|
|
queryWrapper.eq("inventory_status",inventorystatus); |
|
|
|
queryWrapper.eq("location_code",locationcode); |
|
|
|
|
|
|
|
List<BalanceDO> balanceDO = balanceMapper.selectList(queryWrapper); |
|
|
|
if(!balanceDO.isEmpty()){ |
|
|
|
|
|
|
|
return balanceDO; |
|
|
|
} |
|
|
|
else{ |
|
|
|
throw exception(new ErrorCode(124,"物料号" + itemcode +"批次"+ batch + "庫存狀態" + inventorystatus + "在"+ locationcode +"庫位中未查找到库存记录" )); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//按包裝查找 TB2-BY_PACKGING
|
|
|
|
public List<BalanceDO> selectpackaging(String itemcode, String packingnumber, String batch ,String inventorystatus,String locationcode) { |
|
|
|
QueryWrapper queryWrapper = new QueryWrapper(); |
|
|
|
queryWrapper.eq("item_code",itemcode); |
|
|
|
queryWrapper.eq("packing_number",packingnumber); |
|
|
|
queryWrapper.eq("batch",batch); |
|
|
|
queryWrapper.eq("inventory_status",inventorystatus); |
|
|
|
queryWrapper.eq("location_code",locationcode); |
|
|
|
|
|
|
|
List<BalanceDO> balanceDO = balanceMapper.selectList(queryWrapper); |
|
|
|
if(!balanceDO.isEmpty()){ |
|
|
|
|
|
|
|
return balanceDO; |
|
|
|
} |
|
|
|
else{ |
|
|
|
throw exception(new ErrorCode(128,"物料号" + itemcode + "箱码" +packingnumber + "批次"+ batch + "庫存狀態" + inventorystatus + "在"+ locationcode +"庫位中未查找到库存记录" )); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
//按唯一码查找 TB2-BY_UNIQUE_ID
|
|
|
|
public List<BalanceDO> selectuniqueid(String packingnumber,String locationcode , String inventorystatus){ |
|
|
|
QueryWrapper queryWrapper = new QueryWrapper(); |
|
|
|
queryWrapper.eq("packing_number",packingnumber); |
|
|
|
queryWrapper.eq("inventory_status",inventorystatus); |
|
|
|
queryWrapper.eq("location_code",locationcode); |
|
|
|
List<BalanceDO> balanceDO = balanceMapper.selectList(queryWrapper); |
|
|
|
if(!balanceDO.isEmpty()){ |
|
|
|
|
|
|
|
return balanceDO; |
|
|
|
} |
|
|
|
else{ |
|
|
|
throw exception(new ErrorCode(129,"唯一码" + packingnumber + "庫存狀態" + inventorystatus + "在"+ locationcode +"庫位中未查找到库存记录" )); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TB1 查询库存
|
|
|
|
public List<BalanceDO> selectlocation (String itemcode, String packingnumber, String batch, String locationcode, String status ){ |
|
|
|
RuleRespVO managementtRule = ruleService.management( null, null,null,null,null, null,itemcode,null,null, |
|
|
|
null, locationcode,null,null); |
|
|
|
List<BalanceDO> balanceDO = null; |
|
|
|
if( "{\"ManagementPrecision\":\"BY_QUANTITY\"}".equals( managementtRule.getConfiguration())){ |
|
|
|
balanceDO = selectnumber(itemcode, status, locationcode ); |
|
|
|
|
|
|
|
} |
|
|
|
else if("{\"ManagementPrecision\":\"BY_BATCH\"}".equals(managementtRule.getConfiguration())){ |
|
|
|
balanceDO = selectbatch(itemcode,batch,status,locationcode); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if("{\"ManagementPrecision\":\"BY_PACKAGING\"}".equals(managementtRule.getConfiguration())) { |
|
|
|
balanceDO = selectpackaging(itemcode,packingnumber, batch, status, locationcode); |
|
|
|
} |
|
|
|
|
|
|
|
else if("{\"ManagementPrecision\":\"BY_UNIQUE_ID\"}".equals(managementtRule.getConfiguration())) { |
|
|
|
balanceDO = selectuniqueid(packingnumber, locationcode,status); |
|
|
|
} |
|
|
|
|
|
|
|
return balanceDO; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//按數量查找 BY_BATCH
|
|
|
|
public List<ExpectoutDO> selectnumbernew(String itemcode, String inventorystatus, String locationcode ){ |
|
|
|
QueryWrapper queryWrapper = new QueryWrapper(); |
|
|
|
queryWrapper.eq("item_code",itemcode); |
|
|
|
queryWrapper.eq("inventory_status",inventorystatus); |
|
|
|
queryWrapper.eq("location_code",locationcode); |
|
|
|
List<ExpectoutDO> expectoutDO = expectoutMapper.selectList(queryWrapper); |
|
|
|
|
|
|
|
|
|
|
|
if(!expectoutDO.isEmpty()){ |
|
|
|
|
|
|
|
return expectoutDO; |
|
|
|
} |
|
|
|
else{ |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
//按批次查詢 BY_BATCH
|
|
|
|
public List<ExpectoutDO> selectbatchnew(String itemcode,String batch ,String inventorystatus,String locationcode ){ |
|
|
|
QueryWrapper queryWrapper = new QueryWrapper(); |
|
|
|
queryWrapper.eq("item_code",itemcode); |
|
|
|
queryWrapper.eq("batch",batch); |
|
|
|
queryWrapper.eq("inventory_status",inventorystatus); |
|
|
|
queryWrapper.eq("location_code",locationcode); |
|
|
|
List<ExpectoutDO> expectoutDO = expectoutMapper.selectList(queryWrapper); |
|
|
|
|
|
|
|
|
|
|
|
if(!expectoutDO.isEmpty()){ |
|
|
|
|
|
|
|
return expectoutDO; |
|
|
|
} |
|
|
|
else{ |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
//按包裝 BY_PACKAGING
|
|
|
|
public List<ExpectoutDO> selectpackingnew(String itemcode, String packingnumber ,String batch ,String inventorystatus,String locationcode ){ |
|
|
|
QueryWrapper queryWrapper = new QueryWrapper(); |
|
|
|
queryWrapper.eq("item_code",itemcode); |
|
|
|
queryWrapper.eq("batch",batch); |
|
|
|
queryWrapper.eq("packing_number",packingnumber); |
|
|
|
queryWrapper.eq("inventory_status",inventorystatus); |
|
|
|
queryWrapper.eq("location_code",locationcode); |
|
|
|
List<ExpectoutDO> expectoutDO = expectoutMapper.selectList(queryWrapper); |
|
|
|
|
|
|
|
|
|
|
|
if(!expectoutDO.isEmpty()){ |
|
|
|
|
|
|
|
return expectoutDO; |
|
|
|
} |
|
|
|
else{ |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
//按唯一码查詢 BY_UNIQUE_ID
|
|
|
|
public List<ExpectoutDO> selectuniqeidnew( String packingnumber ,String locationcode ,String inventorystatus ){ |
|
|
|
QueryWrapper queryWrapper = new QueryWrapper(); |
|
|
|
queryWrapper.eq("packing_number",packingnumber); |
|
|
|
queryWrapper.eq("inventory_status",inventorystatus); |
|
|
|
queryWrapper.eq("location_code",locationcode); |
|
|
|
List<ExpectoutDO> expectoutDO = expectoutMapper.selectList(queryWrapper); |
|
|
|
|
|
|
|
|
|
|
|
if(!expectoutDO.isEmpty()){ |
|
|
|
|
|
|
|
return expectoutDO; |
|
|
|
} |
|
|
|
else{ |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
//跟据管理模式查询预计库存 TEO1
|
|
|
|
public List<ExpectoutDO> selectlocationnew (String itemcode, String packingnumber, String batch, String locationcode, String status ){ |
|
|
|
RuleRespVO managementtRule = ruleService.management( null, null,null,null,null, null,itemcode,null,null, |
|
|
|
null, locationcode,null,null); |
|
|
|
List<ExpectoutDO> expectoutDO = null; |
|
|
|
if( "{\"ManagementPrecision\":\"BY_QUANTITY\"}".equals( managementtRule.getConfiguration())){ |
|
|
|
expectoutDO = selectnumbernew(itemcode, status, locationcode ); |
|
|
|
|
|
|
|
} |
|
|
|
else if("{\"ManagementPrecision\":\"BY_BATCH\"}".equals(managementtRule.getConfiguration())){ |
|
|
|
expectoutDO = selectbatchnew(itemcode,batch,status,locationcode); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if("{\"ManagementPrecision\":\"BY_PACKAGING\"}".equals(managementtRule.getConfiguration())) { |
|
|
|
expectoutDO = selectpackingnew(itemcode,packingnumber, batch, status, locationcode); |
|
|
|
} |
|
|
|
|
|
|
|
else if("{\"ManagementPrecision\":\"BY_UNIQUE_ID\"}".equals(managementtRule.getConfiguration())) { |
|
|
|
expectoutDO = selectuniqeidnew(packingnumber, locationcode,status); |
|
|
|
} |
|
|
|
|
|
|
|
return expectoutDO; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//查询可用库存 TB3
|
|
|
|
|
|
|
|
public BigDecimal CountLocaltion(String itemcode,String packingnumber,String batch,String locationcode,String status ){ |
|
|
|
List<ExpectoutDO> expectoutDO = selectlocationnew(itemcode,packingnumber,batch,locationcode,status); |
|
|
|
List<BalanceDO> balanceDO = selectlocation(itemcode,packingnumber,batch,locationcode,status); |
|
|
|
|
|
|
|
//double sum = expectoutDO.stream().mapToDouble(ExpectoutDO::getQty).sum();
|
|
|
|
BigDecimal esum = BigDecimal.valueOf(expectoutDO.stream().mapToDouble(expectoutDO1 -> expectoutDO1.getQty().doubleValue()).sum()); |
|
|
|
BigDecimal bsum =BigDecimal.valueOf(balanceDO.stream().mapToDouble(balanceDO1 -> balanceDO1.getQty().doubleValue()).sum()); |
|
|
|
BigDecimal sum = bsum.subtract(esum); |
|
|
|
return sum; |
|
|
|
} |
|
|
|
//有无库存效验
|
|
|
|
|
|
|
|
public String LocaltionExist(String itemcode, String packingnumber,String batch,String locationcode,String status,BigDecimal requstqty){ |
|
|
|
BigDecimal enableqty = CountLocaltion(itemcode,packingnumber,batch,locationcode,status); |
|
|
|
if(requstqty.compareTo(enableqty) > 0){ |
|
|
|
throw exception(new ErrorCode(1256,"请求数量" + requstqty + "大于库存数量" + enableqty)); |
|
|
|
} |
|
|
|
else{ |
|
|
|
return "成功"; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//查询储存容量
|
|
|
|
|
|
|
|
public String selectlocationstrategy(String itemcode, String locationcode){ |
|
|
|
RuleRespVO storagecapacityrule = ruleService.storageCapacity(null,null,itemcode,null,null,null,locationcode); |
|
|
|
String[] StorageQty = storagecapacityrule.getConfiguration().split(","); |
|
|
|
String[] StorageQty1 = StorageQty[1].split(":"); |
|
|
|
String StorageQty2 = StorageQty1[1]; |
|
|
|
if("-1".equals(StorageQty2)){ |
|
|
|
return "不可以存放"; |
|
|
|
} |
|
|
|
return "可以存放"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//库存不应该存在
|
|
|
|
public List<BalanceDO> locationNoExist(String itemcode,String packingnumber,String locationcode,String inventorystatus){ |
|
|
|
RuleRespVO managementtRule = ruleService.management( null, null,null,null,null, null,itemcode,null,null, |
|
|
|
null, locationcode,null,null); |
|
|
|
List<BalanceDO> balanceDO = null; |
|
|
|
if("{\"ManagementPrecision\":\"BY_UNIQUE_ID\"}".equals(managementtRule.getConfiguration())){ |
|
|
|
balanceDO = selectuniqueid(packingnumber, locationcode,inventorystatus); |
|
|
|
return balanceDO; |
|
|
|
|
|
|
|
} |
|
|
|
else{ |
|
|
|
throw exception(new ErrorCode(1256,"校验通过" )); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
//查询库位BQ-QL
|
|
|
|
public String selectlocation(String code){ |
|
|
|
QueryWrapper queryWrapper = new QueryWrapper(); |
|
|
|
queryWrapper.eq("code",code); |
|
|
|
LocationDO locationDO = locationMapper.selectOne(queryWrapper); |
|
|
|
if(locationDO==null&&"TRUE".equals(locationDO.getAvailable())){ |
|
|
|
return "TURE"; |
|
|
|
} |
|
|
|
else{ |
|
|
|
return "FALSE"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//从库位未被其他任务占用,有可用库存
|
|
|
|
public String locationExistnew(String itemcode, String packingnumber,String batch,String fromlocationcode,String status,BigDecimal requstqty ){ |
|
|
|
if(fromlocationcode.isEmpty()){ |
|
|
|
return "不需要其他校验"; |
|
|
|
} |
|
|
|
String Yesorno = selectlocation(fromlocationcode); |
|
|
|
if("TURE".equals(Yesorno)){ |
|
|
|
|
|
|
|
String END = LocaltionExist(itemcode,packingnumber,batch,fromlocationcode,status,requstqty); |
|
|
|
return END; |
|
|
|
} |
|
|
|
else{ |
|
|
|
return "效验通过"; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|