|
@ -1,7 +1,12 @@ |
|
|
package com.win.module.wms.service.rule; |
|
|
package com.win.module.wms.service.rule; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
import cn.hutool.core.util.StrUtil; |
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
|
|
import cn.hutool.json.JSONArray; |
|
|
|
|
|
import cn.hutool.json.JSONObject; |
|
|
|
|
|
import cn.hutool.json.JSONUtil; |
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
import com.google.common.annotations.VisibleForTesting; |
|
|
import com.google.common.annotations.VisibleForTesting; |
|
|
import com.win.framework.common.exception.ServiceException; |
|
|
import com.win.framework.common.exception.ServiceException; |
|
|
import com.win.framework.common.pojo.PageResult; |
|
|
import com.win.framework.common.pojo.PageResult; |
|
@ -15,9 +20,8 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport; |
|
|
import org.springframework.validation.annotation.Validated; |
|
|
import org.springframework.validation.annotation.Validated; |
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
import javax.annotation.Resource; |
|
|
import java.util.ArrayList; |
|
|
import java.math.BigDecimal; |
|
|
import java.util.Collection; |
|
|
import java.util.*; |
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
import static com.win.framework.common.exception.util.ServiceExceptionUtil.exception; |
|
|
import static com.win.framework.common.exception.util.ServiceExceptionUtil.exception; |
|
|
import static com.win.module.wms.enums.ErrorCodeConstants.*; |
|
|
import static com.win.module.wms.enums.ErrorCodeConstants.*; |
|
@ -96,13 +100,11 @@ public class RuleServiceImpl implements RuleService { |
|
|
errorList.add(rule); |
|
|
errorList.add(rule); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 判断如果不存在,在进行插入
|
|
|
// 判断如果不存在,在进行插入
|
|
|
RuleDO existRule = ruleMapper.selectByCode(rule.getCode()); |
|
|
RuleDO existRule = ruleMapper.selectByCode(rule.getCode()); |
|
|
if (existRule == null&& mode != 3) { |
|
|
if (existRule == null&& mode != 3) { |
|
|
ruleMapper.insert(RuleConvert.INSTANCE.convert(rule)); |
|
|
ruleMapper.insert(RuleConvert.INSTANCE.convert(rule)); |
|
|
} |
|
|
} else if (existRule != null && mode != 2) {// 如果存在,判断是否允许更新
|
|
|
else if (existRule != null && mode != 2) {// 如果存在,判断是否允许更新
|
|
|
|
|
|
RuleDO ruleDO = RuleConvert.INSTANCE.convert(rule); |
|
|
RuleDO ruleDO = RuleConvert.INSTANCE.convert(rule); |
|
|
ruleDO.setId(existRule.getId()); |
|
|
ruleDO.setId(existRule.getId()); |
|
|
ruleMapper.updateById(ruleDO); |
|
|
ruleMapper.updateById(ruleDO); |
|
@ -115,15 +117,14 @@ public class RuleServiceImpl implements RuleService { |
|
|
return errorList; |
|
|
return errorList; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void validateRuleForCreateOrUpdate(Long id, String code, String strategycode,Integer priority) { |
|
|
private void validateRuleForCreateOrUpdate(Long id, String code, String strategyCode,Integer priority) { |
|
|
// 关闭数据权限,避免因为没有数据权限,查询不到数据,进而导致唯一校验不正确
|
|
|
// 关闭数据权限,避免因为没有数据权限,查询不到数据,进而导致唯一校验不正确
|
|
|
DataPermissionUtils.executeIgnore(() -> { |
|
|
DataPermissionUtils.executeIgnore(() -> { |
|
|
validateRuleExists(id); |
|
|
validateRuleExists(id); |
|
|
// 校验code唯一
|
|
|
// 校验code唯一
|
|
|
validateCodeExists(id,code); |
|
|
validateCodeExists(id,code); |
|
|
validateStrategycode(strategycode); |
|
|
validateStrategyCode(strategyCode); |
|
|
validatePriority(priority); |
|
|
validatePriority(priority); |
|
|
|
|
|
|
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
@VisibleForTesting |
|
|
@VisibleForTesting |
|
@ -157,19 +158,417 @@ public class RuleServiceImpl implements RuleService { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@VisibleForTesting |
|
|
@VisibleForTesting |
|
|
private void validateStrategycode(String strategycode) { |
|
|
private void validateStrategyCode(String strategyCode) { |
|
|
if (strategycode.isEmpty()) { |
|
|
if (strategyCode.isEmpty()) { |
|
|
throw exception(RULE_STRATEGYCODE_NOT_EXISTS); |
|
|
throw exception(RULE_STRATEGYCODE_NOT_EXISTS); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@VisibleForTesting |
|
|
@VisibleForTesting |
|
|
private void validatePriority(Integer priority) { |
|
|
private void validatePriority(Integer priority) { |
|
|
if (priority == null) { |
|
|
if (priority == null) { |
|
|
throw exception(RULE_PRIORITY_NOT_EXISTS); |
|
|
throw exception(RULE_PRIORITY_NOT_EXISTS); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public RuleRespVO deliverGoods(String supplierType, String supplierCode, String weekday) { |
|
|
|
|
|
QueryWrapper<RuleDO> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
|
queryWrapper.eq("strategy_code", "S001"); |
|
|
|
|
|
queryWrapper.orderByDesc("priority"); |
|
|
|
|
|
List<RuleDO> ruleDOList = ruleMapper.selectList(queryWrapper); |
|
|
|
|
|
for(RuleDO ruleDO : ruleDOList) { |
|
|
|
|
|
String condition = ruleDO.getCondition(); |
|
|
|
|
|
//condition为空是默认规则,直接返回
|
|
|
|
|
|
if(condition == null || condition.isEmpty()) { |
|
|
|
|
|
return RuleConvert.INSTANCE.convert(ruleDO); |
|
|
|
|
|
} |
|
|
|
|
|
JSONArray conditionArray = JSONUtil.parseArray(condition); |
|
|
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
|
|
params.put("SupplierType", supplierType); |
|
|
|
|
|
params.put("SupplierCode", supplierCode); |
|
|
|
|
|
params.put("Weekday", weekday); |
|
|
|
|
|
if(this.forEachParams(params, conditionArray)) { |
|
|
|
|
|
return RuleConvert.INSTANCE.convert(ruleDO); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public RuleRespVO deliveryGoods(String supplierType, String supplierCode) { |
|
|
|
|
|
QueryWrapper<RuleDO> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
|
queryWrapper.eq("strategy_code", "S002"); |
|
|
|
|
|
queryWrapper.orderByDesc("priority"); |
|
|
|
|
|
List<RuleDO> ruleDOList = ruleMapper.selectList(queryWrapper); |
|
|
|
|
|
for(RuleDO ruleDO : ruleDOList) { |
|
|
|
|
|
String condition = ruleDO.getCondition(); |
|
|
|
|
|
//condition为空是默认规则,直接返回
|
|
|
|
|
|
if(condition == null || condition.isEmpty()) { |
|
|
|
|
|
return RuleConvert.INSTANCE.convert(ruleDO); |
|
|
|
|
|
} |
|
|
|
|
|
JSONArray conditionArray = JSONUtil.parseArray(condition); |
|
|
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
|
|
params.put("SupplierType", supplierType); |
|
|
|
|
|
params.put("SupplierCode", supplierCode); |
|
|
|
|
|
if(this.forEachParams(params, conditionArray)) { |
|
|
|
|
|
return RuleConvert.INSTANCE.convert(ruleDO); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public RuleRespVO inspect(String supplierType, String itemCode) { |
|
|
|
|
|
QueryWrapper<RuleDO> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
|
queryWrapper.eq("strategy_code", "S003"); |
|
|
|
|
|
queryWrapper.orderByDesc("priority"); |
|
|
|
|
|
List<RuleDO> ruleDOList = ruleMapper.selectList(queryWrapper); |
|
|
|
|
|
for(RuleDO ruleDO : ruleDOList) { |
|
|
|
|
|
String condition = ruleDO.getCondition(); |
|
|
|
|
|
if(condition == null || condition.isEmpty()) { |
|
|
|
|
|
return RuleConvert.INSTANCE.convert(ruleDO); |
|
|
|
|
|
} |
|
|
|
|
|
JSONArray conditionArray = JSONUtil.parseArray(condition); |
|
|
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
|
|
params.put("SupplierType", supplierType); |
|
|
|
|
|
params.put("ItemCode", itemCode); |
|
|
|
|
|
if(this.forEachParams(params, conditionArray)) { |
|
|
|
|
|
return RuleConvert.INSTANCE.convert(ruleDO); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public RuleRespVO inspectSplit(String supplierType, String itemCode) { |
|
|
|
|
|
QueryWrapper<RuleDO> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
|
queryWrapper.eq("strategy_code", "S004"); |
|
|
|
|
|
queryWrapper.orderByDesc("priority"); |
|
|
|
|
|
List<RuleDO> ruleDOList = ruleMapper.selectList(queryWrapper); |
|
|
|
|
|
for(RuleDO ruleDO : ruleDOList) { |
|
|
|
|
|
String condition = ruleDO.getCondition(); |
|
|
|
|
|
if(condition == null || condition.isEmpty()) { |
|
|
|
|
|
return RuleConvert.INSTANCE.convert(ruleDO); |
|
|
|
|
|
} |
|
|
|
|
|
JSONArray conditionArray = JSONUtil.parseArray(condition); |
|
|
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
|
|
params.put("SupplierType", supplierType); |
|
|
|
|
|
params.put("ItemCode", itemCode); |
|
|
|
|
|
if(this.forEachParams(params, conditionArray)) { |
|
|
|
|
|
return RuleConvert.INSTANCE.convert(ruleDO); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public RuleRespVO grounding(String supplierCode, String customerCode, String abcClass, String itemType, String itemGroup, String project, String itemCode, String inventoryStatus, String storageType, String transactionType, String weight, String area, String volume) { |
|
|
|
|
|
QueryWrapper<RuleDO> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
|
queryWrapper.eq("strategy_code", "S005"); |
|
|
|
|
|
queryWrapper.orderByDesc("priority"); |
|
|
|
|
|
List<RuleDO> ruleDOList = ruleMapper.selectList(queryWrapper); |
|
|
|
|
|
for(RuleDO ruleDO : ruleDOList) { |
|
|
|
|
|
String condition = ruleDO.getCondition(); |
|
|
|
|
|
if(condition == null || condition.isEmpty()) { |
|
|
|
|
|
return RuleConvert.INSTANCE.convert(ruleDO); |
|
|
|
|
|
} |
|
|
|
|
|
JSONArray conditionArray = JSONUtil.parseArray(condition); |
|
|
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
|
|
params.put("SupplierType", supplierCode); |
|
|
|
|
|
params.put("CustomerCode", customerCode); |
|
|
|
|
|
params.put("AbcClass", abcClass); |
|
|
|
|
|
params.put("ItemType", itemType); |
|
|
|
|
|
params.put("ItemGroup", itemGroup); |
|
|
|
|
|
params.put("Project", project); |
|
|
|
|
|
params.put("ItemCode", itemCode); |
|
|
|
|
|
params.put("InventoryStatus", inventoryStatus); |
|
|
|
|
|
params.put("StorageType", storageType); |
|
|
|
|
|
params.put("TransactionType", transactionType); |
|
|
|
|
|
params.put("Weight", weight); |
|
|
|
|
|
params.put("Area", area); |
|
|
|
|
|
params.put("Volume", volume); |
|
|
|
|
|
if(this.forEachParams(params, conditionArray)) { |
|
|
|
|
|
return RuleConvert.INSTANCE.convert(ruleDO); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public RuleRespVO storageCapacity(String itemGroup, String project, String itemCode, String warehouseCode, String areaCode, String locationGroupCode, String locationCode) { |
|
|
|
|
|
QueryWrapper<RuleDO> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
|
queryWrapper.eq("strategy_code", "S006"); |
|
|
|
|
|
queryWrapper.orderByDesc("priority"); |
|
|
|
|
|
List<RuleDO> ruleDOList = ruleMapper.selectList(queryWrapper); |
|
|
|
|
|
for(RuleDO ruleDO : ruleDOList) { |
|
|
|
|
|
String condition = ruleDO.getCondition(); |
|
|
|
|
|
if(condition == null || condition.isEmpty()) { |
|
|
|
|
|
return RuleConvert.INSTANCE.convert(ruleDO); |
|
|
|
|
|
} |
|
|
|
|
|
JSONArray conditionArray = JSONUtil.parseArray(condition); |
|
|
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
|
|
params.put("ItemGroup", itemGroup); |
|
|
|
|
|
params.put("Project", project); |
|
|
|
|
|
params.put("ItemCode", itemCode); |
|
|
|
|
|
params.put("WarehouseCode", warehouseCode); |
|
|
|
|
|
params.put("AreaCode", areaCode); |
|
|
|
|
|
params.put("LocationGroupCode", locationGroupCode); |
|
|
|
|
|
params.put("LocationCode", locationCode); |
|
|
|
|
|
if(this.forEachParams(params, conditionArray)) { |
|
|
|
|
|
return RuleConvert.INSTANCE.convert(ruleDO); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public RuleRespVO offShelf(String supplierCode, String customerCode, String abcClass, String itemType, String itemGroup, String project, String itemCode, String inventoryStatus, String storageType, String transactionType) { |
|
|
|
|
|
QueryWrapper<RuleDO> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
|
queryWrapper.eq("strategy_code", "S007"); |
|
|
|
|
|
queryWrapper.orderByDesc("priority"); |
|
|
|
|
|
List<RuleDO> ruleDOList = ruleMapper.selectList(queryWrapper); |
|
|
|
|
|
for(RuleDO ruleDO : ruleDOList) { |
|
|
|
|
|
String condition = ruleDO.getCondition(); |
|
|
|
|
|
if(condition == null || condition.isEmpty()) { |
|
|
|
|
|
return RuleConvert.INSTANCE.convert(ruleDO); |
|
|
|
|
|
} |
|
|
|
|
|
JSONArray conditionArray = JSONUtil.parseArray(condition); |
|
|
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
|
|
params.put("SupplierCode", supplierCode); |
|
|
|
|
|
params.put("CustomerCode", customerCode); |
|
|
|
|
|
params.put("AbcClass", abcClass); |
|
|
|
|
|
params.put("ItemType", itemType); |
|
|
|
|
|
params.put("ItemGroup", itemGroup); |
|
|
|
|
|
params.put("Project", project); |
|
|
|
|
|
params.put("ItemCode", itemCode); |
|
|
|
|
|
params.put("InventoryStatus", inventoryStatus); |
|
|
|
|
|
params.put("StorageType", storageType); |
|
|
|
|
|
params.put("TransactionType", transactionType); |
|
|
|
|
|
if(this.forEachParams(params, conditionArray)) { |
|
|
|
|
|
return RuleConvert.INSTANCE.convert(ruleDO); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public RuleRespVO replenishment(String itemGroup, String project, String itemCode, String warehouseCode, String areaCode, String locationGroupCode, String locationCode) { |
|
|
|
|
|
QueryWrapper<RuleDO> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
|
queryWrapper.eq("strategy_code", "S008"); |
|
|
|
|
|
queryWrapper.orderByDesc("priority"); |
|
|
|
|
|
List<RuleDO> ruleDOList = ruleMapper.selectList(queryWrapper); |
|
|
|
|
|
for(RuleDO ruleDO : ruleDOList) { |
|
|
|
|
|
String condition = ruleDO.getCondition(); |
|
|
|
|
|
if(condition == null || condition.isEmpty()) { |
|
|
|
|
|
return RuleConvert.INSTANCE.convert(ruleDO); |
|
|
|
|
|
} |
|
|
|
|
|
JSONArray conditionArray = JSONUtil.parseArray(condition); |
|
|
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
|
|
params.put("Project", project); |
|
|
|
|
|
params.put("ItemCode", itemCode); |
|
|
|
|
|
params.put("WarehouseCode", warehouseCode); |
|
|
|
|
|
params.put("AreaCode", areaCode); |
|
|
|
|
|
params.put("LocationGroupCode", locationGroupCode); |
|
|
|
|
|
params.put("LocationCode", locationCode); |
|
|
|
|
|
if(this.forEachParams(params, conditionArray)) { |
|
|
|
|
|
return RuleConvert.INSTANCE.convert(ruleDO); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public RuleRespVO management(String supplierCode, String customerCode, String abcClass, String itemType, String itemGroup, String project, String itemCode, String warehouseCode, String areaCode, String locationGroupCode, String locationCode, String ignoreListOfItem, String ignoreListOfLocation) { |
|
|
|
|
|
QueryWrapper<RuleDO> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
|
queryWrapper.eq("strategy_code", "S009"); |
|
|
|
|
|
queryWrapper.orderByDesc("priority"); |
|
|
|
|
|
List<RuleDO> ruleDOList = ruleMapper.selectList(queryWrapper); |
|
|
|
|
|
for(RuleDO ruleDO : ruleDOList) { |
|
|
|
|
|
String condition = ruleDO.getCondition(); |
|
|
|
|
|
if(condition == null || condition.isEmpty()) { |
|
|
|
|
|
return RuleConvert.INSTANCE.convert(ruleDO); |
|
|
|
|
|
} |
|
|
|
|
|
JSONArray conditionArray = JSONUtil.parseArray(condition); |
|
|
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
|
|
params.put("SupplierCode", supplierCode); |
|
|
|
|
|
params.put("CustomerCode", customerCode); |
|
|
|
|
|
params.put("AbcClass", abcClass); |
|
|
|
|
|
params.put("ItemType", itemType); |
|
|
|
|
|
params.put("ItemGroup", itemGroup); |
|
|
|
|
|
params.put("Project", project); |
|
|
|
|
|
params.put("ItemCode", itemCode); |
|
|
|
|
|
params.put("WarehouseCode", warehouseCode); |
|
|
|
|
|
params.put("AreaCode", areaCode); |
|
|
|
|
|
params.put("LocationGroupCode", locationGroupCode); |
|
|
|
|
|
params.put("LocationCode", locationCode); |
|
|
|
|
|
params.put("IgnoreListOfItem", ignoreListOfItem); |
|
|
|
|
|
params.put("IgnoreListOfLocation", ignoreListOfLocation); |
|
|
|
|
|
if(this.forEachParams(params, conditionArray)) { |
|
|
|
|
|
return RuleConvert.INSTANCE.convert(ruleDO); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public RuleRespVO batch(String supplierCode, String customerCode, String abcClass, String itemType, String itemGroup, String project, String itemCode) { |
|
|
|
|
|
QueryWrapper<RuleDO> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
|
queryWrapper.eq("strategy_code", "S010"); |
|
|
|
|
|
queryWrapper.orderByDesc("priority"); |
|
|
|
|
|
List<RuleDO> ruleDOList = ruleMapper.selectList(queryWrapper); |
|
|
|
|
|
for(RuleDO ruleDO : ruleDOList) { |
|
|
|
|
|
String condition = ruleDO.getCondition(); |
|
|
|
|
|
if(condition == null || condition.isEmpty()) { |
|
|
|
|
|
return RuleConvert.INSTANCE.convert(ruleDO); |
|
|
|
|
|
} |
|
|
|
|
|
JSONArray conditionArray = JSONUtil.parseArray(condition); |
|
|
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
|
|
params.put("SupplierCode", supplierCode); |
|
|
|
|
|
params.put("CustomerCode", customerCode); |
|
|
|
|
|
params.put("AbcClass", abcClass); |
|
|
|
|
|
params.put("ItemType", itemType); |
|
|
|
|
|
params.put("ItemGroup", itemGroup); |
|
|
|
|
|
params.put("Project", project); |
|
|
|
|
|
params.put("ItemCode", itemCode); |
|
|
|
|
|
if(this.forEachParams(params, conditionArray)) { |
|
|
|
|
|
return RuleConvert.INSTANCE.convert(ruleDO); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public RuleRespVO warehouseStorage(String warehouseCode, String areaCode, String locationGroupCode, String locationCode) { |
|
|
|
|
|
QueryWrapper<RuleDO> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
|
queryWrapper.eq("strategy_code", "S011"); |
|
|
|
|
|
queryWrapper.orderByDesc("priority"); |
|
|
|
|
|
List<RuleDO> ruleDOList = ruleMapper.selectList(queryWrapper); |
|
|
|
|
|
for(RuleDO ruleDO : ruleDOList) { |
|
|
|
|
|
String condition = ruleDO.getCondition(); |
|
|
|
|
|
if(condition == null || condition.isEmpty()) { |
|
|
|
|
|
return RuleConvert.INSTANCE.convert(ruleDO); |
|
|
|
|
|
} |
|
|
|
|
|
JSONArray conditionArray = JSONUtil.parseArray(condition); |
|
|
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
|
|
params.put("WarehouseCode", warehouseCode); |
|
|
|
|
|
params.put("AreaCode", areaCode); |
|
|
|
|
|
params.put("LocationGroupCode", locationGroupCode); |
|
|
|
|
|
params.put("LocationCode", locationCode); |
|
|
|
|
|
if(this.forEachParams(params, conditionArray)) { |
|
|
|
|
|
return RuleConvert.INSTANCE.convert(ruleDO); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public RuleRespVO applianceCapacity(String containerType, String itemGroup, String projectCode, String itemCode) { |
|
|
|
|
|
QueryWrapper<RuleDO> queryWrapper = new QueryWrapper<>(); |
|
|
|
|
|
queryWrapper.eq("strategy_code", "S012"); |
|
|
|
|
|
queryWrapper.orderByDesc("priority"); |
|
|
|
|
|
List<RuleDO> ruleDOList = ruleMapper.selectList(queryWrapper); |
|
|
|
|
|
for(RuleDO ruleDO : ruleDOList) { |
|
|
|
|
|
String condition = ruleDO.getCondition(); |
|
|
|
|
|
if(condition == null || condition.isEmpty()) { |
|
|
|
|
|
return RuleConvert.INSTANCE.convert(ruleDO); |
|
|
|
|
|
} |
|
|
|
|
|
JSONArray conditionArray = JSONUtil.parseArray(condition); |
|
|
|
|
|
Map<String, String> params = new HashMap<>(); |
|
|
|
|
|
params.put("ContainerType", containerType); |
|
|
|
|
|
params.put("ItemGroup", itemGroup); |
|
|
|
|
|
params.put("ProjectCode", projectCode); |
|
|
|
|
|
params.put("ItemCode", itemCode); |
|
|
|
|
|
if(this.forEachParams(params, conditionArray)) { |
|
|
|
|
|
return RuleConvert.INSTANCE.convert(ruleDO); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 循环校验参数 |
|
|
|
|
|
* @param params 参数 |
|
|
|
|
|
* @param conditionArray 条件json数组 |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
private boolean forEachParams(Map<String, String> params, JSONArray conditionArray) { |
|
|
|
|
|
for(int i = 0; i < conditionArray.size(); i++) { |
|
|
|
|
|
JSONObject conditionObject = conditionArray.getJSONObject(0); |
|
|
|
|
|
for (String key : params.keySet()) { |
|
|
|
|
|
if(key.equals(conditionObject.get("ParamCode"))) { |
|
|
|
|
|
boolean result = this.checkCondition(conditionObject, key, params.get(key)); |
|
|
|
|
|
if(!result) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 判断条件 |
|
|
|
|
|
* @param conditionObject 条件json |
|
|
|
|
|
* @param paramCode 条件key |
|
|
|
|
|
* @param paramValue 条件value |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
private boolean checkCondition(JSONObject conditionObject, String paramCode, String paramValue) { |
|
|
|
|
|
if(conditionObject.get("ParamCode").equals(paramCode)) { |
|
|
|
|
|
String operator = conditionObject.get("ParamCode").toString(); |
|
|
|
|
|
String value = conditionObject.get("Value").toString(); |
|
|
|
|
|
if(paramValue != null && paramValue.isEmpty()) { |
|
|
|
|
|
if(operator.equals("==")) { |
|
|
|
|
|
if(!value.equals(paramValue)) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
} else if(operator.equals("!=")) { |
|
|
|
|
|
if(value.equals(paramValue)) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
} else if(operator.equals(">")) { |
|
|
|
|
|
BigDecimal value1 = new BigDecimal(paramValue); |
|
|
|
|
|
BigDecimal value2 = new BigDecimal(value); |
|
|
|
|
|
if(value1.compareTo(value2) <= 0) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
} else if(operator.equals("<")) { |
|
|
|
|
|
BigDecimal value1 = new BigDecimal(paramValue); |
|
|
|
|
|
BigDecimal value2 = new BigDecimal(value); |
|
|
|
|
|
if(value1.compareTo(value2) >= 0) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
} else if(operator.equals(">=")) { |
|
|
|
|
|
BigDecimal value1 = new BigDecimal(paramValue); |
|
|
|
|
|
BigDecimal value2 = new BigDecimal(value); |
|
|
|
|
|
if(value1.compareTo(value2) < 0) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
} else if(operator.equals("<=")) { |
|
|
|
|
|
BigDecimal value1 = new BigDecimal(paramValue); |
|
|
|
|
|
BigDecimal value2 = new BigDecimal(value); |
|
|
|
|
|
if(value1.compareTo(value2) > 0) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
} else if(operator.equals("IN")) { |
|
|
|
|
|
List<String> valueList = Arrays.asList(value.split(",")); |
|
|
|
|
|
if(!valueList.contains(paramValue)) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
} else if(operator.equals("NOT IN")) { |
|
|
|
|
|
List<String> valueList = Arrays.asList(value.split(",")); |
|
|
|
|
|
if(valueList.contains(paramValue)) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if(operator.equals("NULL")) { |
|
|
|
|
|
return paramValue == null || paramValue.isEmpty(); |
|
|
|
|
|
} else if(operator.equals("NOT NULL")) { |
|
|
|
|
|
return paramValue != null && !paramValue.isEmpty(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|