{"id":37016982,"url":"https://github.com/selwynshen/nics-easy-rules","last_synced_at":"2026-01-14T01:56:36.633Z","repository":{"id":57722666,"uuid":"159286776","full_name":"selwynshen/nics-easy-rules","owner":"selwynshen","description":"rules-engine, based on easy-rules","archived":false,"fork":false,"pushed_at":"2019-03-29T12:37:28.000Z","size":118,"stargazers_count":34,"open_issues_count":2,"forks_count":16,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-25T08:26:31.602Z","etag":null,"topics":["java","rule-engine","rules-engine","spring","yaml"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/selwynshen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-27T06:27:00.000Z","updated_at":"2025-06-19T15:35:56.000Z","dependencies_parsed_at":"2022-08-28T08:40:48.423Z","dependency_job_id":null,"html_url":"https://github.com/selwynshen/nics-easy-rules","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/selwynshen/nics-easy-rules","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selwynshen%2Fnics-easy-rules","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selwynshen%2Fnics-easy-rules/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selwynshen%2Fnics-easy-rules/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selwynshen%2Fnics-easy-rules/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/selwynshen","download_url":"https://codeload.github.com/selwynshen/nics-easy-rules/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selwynshen%2Fnics-easy-rules/sbom","scorecard":{"id":810623,"data":{"date":"2025-08-11","repo":{"name":"github.com/selwynshen/nics-easy-rules","commit":"5fb6731642ee28cb687e1f74506893b8a9eccb0f"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.6,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/21 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":0,"reason":"license file not detected","details":["Warn: project does not have a license file"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-23T13:04:57.079Z","repository_id":57722666,"created_at":"2025-08-23T13:04:57.080Z","updated_at":"2025-08-23T13:04:57.080Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28408692,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T00:40:43.272Z","status":"ssl_error","status_checked_at":"2026-01-14T00:40:42.636Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","rule-engine","rules-engine","spring","yaml"],"created_at":"2026-01-14T01:56:36.130Z","updated_at":"2026-01-14T01:56:36.617Z","avatar_url":"https://github.com/selwynshen.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Nics Easy Rules  简易规则引擎（基于easy-rules）\n基于[easy-rules](https://github.com/j-easy/easy-rules)改进开发的一个简单的规则引擎工具，适合判断条件比较多的项目使用，尤其是那种如果满足条件，则会执行一堆业务逻辑或者校验很频繁的业务场景。使用规则引擎可以解耦条件判断执行，让主业务方法看起来更清晰，维护起来也更容易。\n\n## 名词解释\n- **最小规则(Rule)**： 最基础的规则，包含条件（condition）和执行（action），可能存在复用\n- **规则组(GroupRule)**：最小规则的集合，用于完成一个业务逻辑的校验执行，内置Rules对象，用于最小规则的注册\n- **规则引擎(RulesEngine)**: 执行具体规则\n- **具体业务逻辑(Service)**：可以执行多个规则组，组成一个完整的业务逻辑处理\n\n## 针对easy-rules的改进点\n- 集成spring\n- 规则可复用，优先级可修改\n- 引入规则组概念\n- 增加基类，初步封装\n- 同组规则可进行中断或者跳过后续某个规则的执行\n- mvel的语法覆盖面还是不够广，因此摒弃，采用java代码实现业务，yml实现规则组灵活配置的形式\n\n## 项目依赖\n```xml\n\u003c!--nics-easy-rules--\u003e\n\u003cdependency\u003e\n    \u003cgroupId\u003ecom.github.selwynshen\u003c/groupId\u003e\n    \u003cartifactId\u003enics-easy-rules-spring\u003c/artifactId\u003e\n    \u003cversion\u003e1.1\u003c/version\u003e\n\u003c/dependency\u003e\n```\n## nics-easy-rules 配置(spring boot项目)\n新增配置类，RulesEngineFactoryBean用于生成默认的规则引擎对象，RulesDefinitionFactory用于初始化加载yml规则组配置，GroupRulesRegister用于给规则组对象配置规则\n```java\n@Configuration\npublic class EasyRulesConfigurer {\n\n    @Bean\n    RulesEngineFactoryBean rulesEngineFactoryBean()\n    {\n        //return new RulesEngineFactoryBean();\n        return new ProtoRulesEngineFactoryBean();\n    }\n\n    @Bean\n    @ConfigurationProperties(prefix = \"nics.easyrules\")\n    RulesDefinitionFactory rulesDefinitionFactory()\n    {\n        return new RulesDefinitionFactory();\n    }\n\n    @Bean\n    GroupRulesRegister groupRulesRegister()\n    {\n        return new GroupRulesRegister();\n    }\n}\n```\n项目application.properties添加如下配置\n```properties\nnics.easyrules.rules-locations=classpath:rules/*-rules.yml\n```\n最小规则类写法，Rule注解包含了该规则的名称，注释和优先级（可选）\n```java\n@Rule(name=\"orgNotExistRuleRule\", description = \"机构不存在规则\", priority = 1020)\n@Component\n@Scope(\"prototype\")\npublic class OrgNotExistRule extends AbstractRule {\n    //condition注解，表明这是一个条件方法，如果返回true，则执行下面action\n    @Condition\n    public boolean condition(AdvFacts facts)\n    {\n        return RandomUtils.nextBoolean();\n    }\n\n    //action注解，表明这是一个执行方法，如果上面condition返回true，则执行该方法\n    @Action\n    public void action(AdvFacts facts)\n    {\n        System.out.println(\"机构信息不全，报问题件\");\n        //结束后续规则的校验\n        facts.putEnd(true);\n        //跳过某个规则类的执行\n        facts.put(Constants.FACTS_SKIP_KEY, SocCatelogNotExistRule.class);\n    }\n}\n```\n规则组写法：\n```java\n@Component\npublic class EntryInvoiceGroupRules extends AbstractGroupRules {\n    @Override\n    public void registerRules(Rules rules) {\n        //使用了yml配置，不需要自己注册最小规则了，此方法体为空就行\n    }\n}\n```\n然后在resources/rules下面创建规则组配置文件，注意name就是bean的名称。通过配置文件的形式，可以动态进行规则的配置，无需修改代码。\n```yaml\ngroup:\n  name: entryInvoiceGroupRules\n  rules:\n    - name: hospitalNotDesignatedRule\n      priority: 2\n    - name: orgNotExistRule\n      priority: 3\n    - name: socCatelogNotExistRule\n      priority: 4\n```\n执行规则组的大致写法：\n```java\n@Autowired\nprivate RulesEngine rulesEngine;\n\nAdvFacts facts = new AdvFacts();\n//往facts里塞参数\nfacts.put(\"param\", \"case\");\nthis.rulesEngine.fire(entryInvoiceGroupRules.getRules(), facts);\n```\n## 案例\n[源码](https://github.com/selwynshen/nics-easy-rules-showcase)\n\n## 更新日志\n01/29/2019 (v1.1)\n1. 修复spring boot项目jar包执行时无法读取规则文件的bug\n2. 新增跳过指定规则的listener\n3. 规则引擎factory bean改成多例的\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fselwynshen%2Fnics-easy-rules","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fselwynshen%2Fnics-easy-rules","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fselwynshen%2Fnics-easy-rules/lists"}