Browse Source

增加策略接口

master
刘忱 2 years ago
parent
commit
fa262faec7
  1. 165
      win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/rule/RuleService.java
  2. 421
      win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/rule/RuleServiceImpl.java

165
win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/rule/RuleService.java

@ -75,4 +75,169 @@ public interface RuleService {
List<RuleImportExcelVo> importRuleList(List<RuleImportExcelVo> importTeam, Integer mode, boolean updatePart);
/**************** 规则接口 ****************/
/**
* 获取供应商送货策略
*
* @param supplierType 供应商类型
* @param supplierCode 供应商代码
* @param weekday 星期几
* @return
*/
RuleRespVO deliverGoods(String supplierType, String supplierCode, String weekday);
/**
* 获取采购收货任务拆分策略
*
* @param supplierType 供应商类型
* @param supplierCode 供应商代码
* @return
*/
RuleRespVO deliveryGoods(String supplierType, String supplierCode);
/**
* 获取检验策略
*
* @param supplierType 供应商类型
* @param itemCode 物品代码
* @return
*/
RuleRespVO inspect(String supplierType, String itemCode);
/**
* 获取到货检验任务拆分策略
*
* @param supplierType 供应商类型
* @param itemCode 物品代码
* @return
*/
RuleRespVO inspectSplit(String supplierType, String itemCode);
/**
* 获取上架策略
*
* @param supplierCode 供应商
* @param customerCode 客户
* @param abcClass ABC类
* @param itemType 物品类型
* @param itemGroup 物品分组
* @param project 项目
* @param itemCode 物品代码
* @param inventoryStatus 库存状态
* @param storageType 存储类型
* @param transactionType 库存事务
* @param weight 重量
* @param area 面积
* @param volume 体积
* @return
*/
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);
/**
* 获取存储容量策略
*
* @param itemGroup 物品分组
* @param project 项目
* @param itemCode 物品代码
* @param warehouseCode 仓库代码
* @param areaCode 库区代码
* @param locationGroupCode 库位组代码
* @param locationCode 库位代码
* @return
*/
RuleRespVO storageCapacity(String itemGroup, String project, String itemCode, String warehouseCode, String areaCode, String locationGroupCode,
String locationCode);
/**
* 获取下架策略
*
* @param supplierCode 供应商
* @param customerCode 客户
* @param abcClass ABC
* @param itemType 物品类型
* @param itemGroup 物品分组
* @param project 项目
* @param itemCode 物品代码
* @param inventoryStatus 库存状态
* @param storageType 存储类型
* @param transactionType 库存事务
* @return
*/
RuleRespVO offShelf(String supplierCode, String customerCode, String abcClass, String itemType, String itemGroup, String project,
String itemCode, String inventoryStatus, String storageType, String transactionType);
/**
* 获取补料策略
*
* @param itemGroup 物品分组
* @param project 项目
* @param itemCode 物品代码
* @param warehouseCode 仓库代码
* @param areaCode 库区代码
* @param locationGroupCode 库位组代码
* @param locationCode 库位代码
* @return
*/
RuleRespVO replenishment(String itemGroup, String project, String itemCode, String warehouseCode, String areaCode, String locationGroupCode, String locationCode);
/**
* 获取管理精度策略
*
* @param supplierCode 供应商
* @param customerCode 客户
* @param abcClass ABC
* @param itemType 物品类型
* @param itemGroup 物品分组
* @param project 项目
* @param itemCode 物品代码
* @param warehouseCode 仓库代码
* @param areaCode 库区代码
* @param locationGroupCode 库位组代码
* @param locationCode 库位代码
* @param ignoreListOfItem 物品忽略名单
* @param ignoreListOfLocation 库位忽略名单
* @return
*/
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);
/**
* 获取批次策略
*
* @param supplierCode 供应商
* @param customerCode 客户
* @param abcClass ABC
* @param itemType 物品类型
* @param itemGroup 物品分组
* @param project 项目
* @param itemCode 物品代码
* @return
*/
RuleRespVO batch(String supplierCode, String customerCode, String abcClass, String itemType, String itemGroup, String project, String itemCode);
/**
* 获取库位存储策略
*
* @param warehouseCode 仓库代码
* @param areaCode 库区代码
* @param locationGroupCode 库位组代码
* @param locationCode 库位代码
* @return
*/
RuleRespVO warehouseStorage(String warehouseCode, String areaCode, String locationGroupCode, String locationCode);
/**
* 获取器具容量策略
*
* @param containerType 器具类型
* @param itemGroup 物品分组
* @param projectCode 项目代码
* @param itemCode 物品代码
* @return
*/
RuleRespVO applianceCapacity(String containerType, String itemGroup, String projectCode, String itemCode);
}

421
win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/rule/RuleServiceImpl.java

@ -1,7 +1,12 @@
package com.win.module.wms.service.rule;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
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.win.framework.common.exception.ServiceException;
import com.win.framework.common.pojo.PageResult;
@ -15,9 +20,8 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.math.BigDecimal;
import java.util.*;
import static com.win.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.win.module.wms.enums.ErrorCodeConstants.*;
@ -96,13 +100,11 @@ public class RuleServiceImpl implements RuleService {
errorList.add(rule);
return;
}
// 判断如果不存在,在进行插入
RuleDO existRule = ruleMapper.selectByCode(rule.getCode());
if (existRule == null&& mode != 3) {
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.setId(existRule.getId());
ruleMapper.updateById(ruleDO);
@ -115,15 +117,14 @@ public class RuleServiceImpl implements RuleService {
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(() -> {
validateRuleExists(id);
// 校验code唯一
validateCodeExists(id,code);
validateStrategycode(strategycode);
validateStrategyCode(strategyCode);
validatePriority(priority);
});
}
@VisibleForTesting
@ -157,8 +158,8 @@ public class RuleServiceImpl implements RuleService {
}
}
@VisibleForTesting
private void validateStrategycode(String strategycode) {
if (strategycode.isEmpty()) {
private void validateStrategyCode(String strategyCode) {
if (strategyCode.isEmpty()) {
throw exception(RULE_STRATEGYCODE_NOT_EXISTS);
}
}
@ -169,7 +170,405 @@ public class RuleServiceImpl implements RuleService {
}
}
@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;
}
}

Loading…
Cancel
Save