From b3c7f5e2c5a388a38df1c7445e2be7e9072b1241 Mon Sep 17 00:00:00 2001 From: liuchen864 <23082234@qq.com> Date: Thu, 19 Oct 2023 12:33:23 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=9B=BD=E9=99=85=E5=8C=96=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=E6=A0=A1=E9=AA=8C=E5=92=8CErrorCode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/util/ServiceExceptionUtil.java | 3 ++- .../common/util/i18n}/MessageUtil.java | 11 +++++++--- .../web/config/WinWebAutoConfiguration.java | 21 +++++++++++++++++++ .../src/main/resources/application.yaml | 1 + 4 files changed, 32 insertions(+), 4 deletions(-) rename win-framework/{win-spring-boot-starter-web/src/main/java/com/win/framework/web/core/util => win-common/src/main/java/com/win/framework/common/util/i18n}/MessageUtil.java (61%) diff --git a/win-framework/win-common/src/main/java/com/win/framework/common/exception/util/ServiceExceptionUtil.java b/win-framework/win-common/src/main/java/com/win/framework/common/exception/util/ServiceExceptionUtil.java index 7a0ecdee..e16f6543 100644 --- a/win-framework/win-common/src/main/java/com/win/framework/common/exception/util/ServiceExceptionUtil.java +++ b/win-framework/win-common/src/main/java/com/win/framework/common/exception/util/ServiceExceptionUtil.java @@ -4,6 +4,7 @@ import com.win.framework.common.exception.ErrorCode; import com.win.framework.common.exception.ServiceException; import com.win.framework.common.exception.enums.GlobalErrorCodeConstants; import com.google.common.annotations.VisibleForTesting; +import com.win.framework.common.util.i18n.MessageUtil; import lombok.extern.slf4j.Slf4j; import java.util.Map; @@ -77,7 +78,7 @@ public class ServiceExceptionUtil { } public static ServiceException exception0(Integer code, String messagePattern, Object... params) { - String message = doFormat(code, messagePattern, params); + String message = doFormat(code, MessageUtil.message(messagePattern), params); return new ServiceException(code, message); } diff --git a/win-framework/win-spring-boot-starter-web/src/main/java/com/win/framework/web/core/util/MessageUtil.java b/win-framework/win-common/src/main/java/com/win/framework/common/util/i18n/MessageUtil.java similarity index 61% rename from win-framework/win-spring-boot-starter-web/src/main/java/com/win/framework/web/core/util/MessageUtil.java rename to win-framework/win-common/src/main/java/com/win/framework/common/util/i18n/MessageUtil.java index c2d1d054..c0684c5b 100644 --- a/win-framework/win-spring-boot-starter-web/src/main/java/com/win/framework/web/core/util/MessageUtil.java +++ b/win-framework/win-common/src/main/java/com/win/framework/common/util/i18n/MessageUtil.java @@ -1,13 +1,14 @@ -package com.win.framework.web.core.util; +package com.win.framework.common.util.i18n; import cn.hutool.extra.spring.SpringUtil; import org.springframework.context.MessageSource; +import org.springframework.context.NoSuchMessageException; import org.springframework.context.i18n.LocaleContextHolder; public class MessageUtil { /** - * 根据消息键和参数 获取消息 委托给spring messageSource + * 根据消息键和参数 获取消息 委托给spring messageSource,获取不到则返回code * * @param code 消息键 * @param args 参数 @@ -15,7 +16,11 @@ public class MessageUtil { */ public static String message(String code, Object... args) { MessageSource messageSource = SpringUtil.getBean(MessageSource.class); - return messageSource.getMessage(code, args, LocaleContextHolder.getLocale()); + try { + return messageSource.getMessage(code, args, LocaleContextHolder.getLocale()); + } catch (NoSuchMessageException ignored) { + return code; + } } } diff --git a/win-framework/win-spring-boot-starter-web/src/main/java/com/win/framework/web/config/WinWebAutoConfiguration.java b/win-framework/win-spring-boot-starter-web/src/main/java/com/win/framework/web/config/WinWebAutoConfiguration.java index 27ff857f..4e32a26f 100644 --- a/win-framework/win-spring-boot-starter-web/src/main/java/com/win/framework/web/config/WinWebAutoConfiguration.java +++ b/win-framework/win-spring-boot-starter-web/src/main/java/com/win/framework/web/config/WinWebAutoConfiguration.java @@ -16,14 +16,18 @@ import org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfigu import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.boot.web.servlet.FilterRegistrationBean; +import org.springframework.context.MessageSource; import org.springframework.context.annotation.Bean; import org.springframework.util.AntPathMatcher; +import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.client.RestTemplate; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import org.springframework.web.filter.CorsFilter; +import org.springframework.web.servlet.LocaleResolver; import org.springframework.web.servlet.config.annotation.*; +import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver; import javax.annotation.Resource; import javax.servlet.Filter; @@ -46,6 +50,23 @@ public class WinWebAutoConfiguration implements WebMvcConfigurer { configurePathMatch(configurer, webProperties.getAdminApi()); } + /** + * 设置validator国际化 + * @param messageSource + * @return + */ + @Bean + public LocalValidatorFactoryBean defaultValidator(MessageSource messageSource) { + LocalValidatorFactoryBean factoryBean = new LocalValidatorFactoryBean(); + factoryBean.setValidationMessageSource(messageSource); + return factoryBean; + } + + @Bean + public LocaleResolver localeResolver() { + return new AcceptHeaderLocaleResolver(); + } + /** * 设置 API 前缀,仅仅匹配 controller 包下的 * diff --git a/win-server/src/main/resources/application.yaml b/win-server/src/main/resources/application.yaml index 41e4959d..1259540c 100644 --- a/win-server/src/main/resources/application.yaml +++ b/win-server/src/main/resources/application.yaml @@ -4,6 +4,7 @@ spring: # i18 message 配置,对应 MessageSourceProperties 配置类 messages: basename: i18n/bpm,i18n/infra,i18n/mes,i18n/report,i18n/scp,i18n/system,i18n/wms # 文件路径基础名 + encoding: UTF-8 profiles: include: druid From fa262faec7eda228d3fa7e6db3fdea7c26257a49 Mon Sep 17 00:00:00 2001 From: liuchen864 <23082234@qq.com> Date: Thu, 19 Oct 2023 15:34:11 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=AD=96=E7=95=A5?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/wms/service/rule/RuleService.java | 165 +++++++ .../wms/service/rule/RuleServiceImpl.java | 423 +++++++++++++++++- 2 files changed, 576 insertions(+), 12 deletions(-) diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/rule/RuleService.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/rule/RuleService.java index 9909b13e..26718a60 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/rule/RuleService.java +++ b/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 importRuleList(List 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); + } diff --git a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/rule/RuleServiceImpl.java b/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/rule/RuleServiceImpl.java index 0b5a5fd4..7cb20824 100644 --- a/win-module-wms/win-module-wms-biz/src/main/java/com/win/module/wms/service/rule/RuleServiceImpl.java +++ b/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,19 +158,417 @@ 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); } } @VisibleForTesting - private void validatePriority(Integer priority) { + private void validatePriority(Integer priority) { if (priority == null) { throw exception(RULE_PRIORITY_NOT_EXISTS); } } + @Override + public RuleRespVO deliverGoods(String supplierType, String supplierCode, String weekday) { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("strategy_code", "S001"); + queryWrapper.orderByDesc("priority"); + List 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 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 queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("strategy_code", "S002"); + queryWrapper.orderByDesc("priority"); + List 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 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 queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("strategy_code", "S003"); + queryWrapper.orderByDesc("priority"); + List 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 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 queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("strategy_code", "S004"); + queryWrapper.orderByDesc("priority"); + List 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 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 queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("strategy_code", "S005"); + queryWrapper.orderByDesc("priority"); + List 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 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 queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("strategy_code", "S006"); + queryWrapper.orderByDesc("priority"); + List 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 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 queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("strategy_code", "S007"); + queryWrapper.orderByDesc("priority"); + List 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 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 queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("strategy_code", "S008"); + queryWrapper.orderByDesc("priority"); + List 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 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 queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("strategy_code", "S009"); + queryWrapper.orderByDesc("priority"); + List 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 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 queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("strategy_code", "S010"); + queryWrapper.orderByDesc("priority"); + List 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 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 queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("strategy_code", "S011"); + queryWrapper.orderByDesc("priority"); + List 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 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 queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("strategy_code", "S012"); + queryWrapper.orderByDesc("priority"); + List 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 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 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 valueList = Arrays.asList(value.split(",")); + if(!valueList.contains(paramValue)) { + return false; + } + } else if(operator.equals("NOT IN")) { + List 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; + } }