1、策略思想
List
if(CollectionUtil.isEmpty(sortPolicyCode)){
return level2Inventory;
}
level2Inventory.sort((a,b)->{
int ret = 0;
for (String s : sortPolicyCode) {
//其中s是spring的IOC的注解
ILevel2InventorySorter sorter = SpringBeanFactory.getBean(s,ILevel2InventorySorter.class);
ret = sorter.calculateSortNumber(a, b, orderType, warehouseId);
if(ret != 0){
break;
}
}
return ret;
});
return level2Inventory;
/**
通过
**/
private List
String format = String.format(formatKey, warehouseId, orderType);
List
if(CollectionUtil.isEmpty(policyCodes)){
List
if(CollectionUtil.isEmpty(policyDTOS)){
throw new WesPickingException(WesPickingErrorCode.POLICY_GROUP_CAN_NOT_FIND_POLICY.getCode(),WesPickingErrorCode.POLICY_GROUP_CAN_NOT_FIND_POLICY.getDesc(),PickingPolicyCodes.LEVEL2_INVENTORY_SORT_GROUP_CODE);
}
policyCodes = policyDTOS.stream().map(PolicyDTO::getPolicyCode).collect(Collectors.toList());
orderTypeWithPolicyCode.putIfAbsent(format,policyCodes);
}
return policyCodes;
}
@Override
public List
return DozerBeanUtil.mapList(this.policyManager.selectByGroupCode(warehouseId, policyGroupCode), PolicyDTO.class);
}
public List
return this.mapper.selectByGroupCode(warehouseId, policyGroupCode);
}
//比如按日期的排序
@Override
public int calculateSortNumber(Level2InventoryFlatDTO a, Level2InventoryFlatDTO b, String orderType, Long warehouseId) {
LotCompareReceivedDate input = new LotCompareReceivedDate();
input.setOrderType(orderType);
List
int ret = 0;
if(CollectionUtil.isNotEmpty(results)){
for (LotCompareReceivedDatePolicyResult result : results) {
//收货日期
Object af1 = FiledValueHelper.getFieldByClass(result.getFiledName(), a);
Object af2 = FiledValueHelper.getFieldByClass(result.getFiledName(), b); //>7 -1
try {
if(af1 !=null && af2 != null){
//取到收货日期1,和收货日期2
Date dateOne = DateUtil.str2DateTime(af1.toString(),DateUtil.DEFAULT_DATE_TIME_FORMAT);
Date dateTwo = DateUtil.str2DateTime(af2.toString(),DateUtil.DEFAULT_DATE_TIME_FORMAT);
Long timeOne = DateUtil.diffMilli(dateOne);
Long timeTwo = DateUtil.diffMilli(dateTwo);
long receivedDate = result.getReceivedDate()*86400000L;
LOGGER.info("inventoryLevel2 sort by lotAtt8 ");
ret = compareTo(timeTwo,timeOne,receivedDate);
}else{
LOGGER.warn("date1:{} and date1:{}",af1,af2);
}
} catch (Exception e) {
LOGGER.error("date convert is error :{} ",e.getMessage());
}
}
}
return ret;
}
@Override
public
PolicyDTO policyDTO = policyEngine.applyPolicy(warehouseId, policyCode, inputObj);
return PolicyUtil.convertResult(policyDTO, resultType);
}
/**
*
* @param warehouseId 仓库ID
* @param policyCode 策略代码
* @param inputObj 出库单类型
* @return
*/
@SuppressWarnings({ "unchecked" })
public PolicyDTO applyPolicy(Long warehouseId, String policyCode, Object inputObj) {
if (inputObj == null) {
throw new WesException(WesErrorCode.METHOD_ARGUMENT_CANNOT_NULL, "inputObj");
}
PolicyDTO policyDTO = policyCache.get(policyCode);
if (policyDTO == null) {
policyDTO = policyService.selectOneWithRuleByCode(warehouseId, policyCode);
if (policyDTO == null) {
throw new WesException(PolicyErrorCode.POLICY_NOT_FOUND, policyCode);
}
this.cachePolicy(policyDTO);
}
this.validateInput(policyDTO, inputObj);
KieBase kieBase = kieBaseCache.get(policyCode);
StatelessKieSession kSession = kieBase.newStatelessKieSession();
List
BatchExecutionCommand batchCommand = CommandFactory.newBatchExecution(commands);
Object input = this.convertInput(policyDTO, inputObj);
log.info("drools.input: " + input);
commands.add(CommandFactory.newInsert(new Pair