• 配置筛选机


    在文章中,比较多的灵感来源于筛选谷物花生,筛选机等筛选机的结构

    比较多的开发工作中,涉及业务分支和同一业务不同逻辑的,会比较适合下面模型:从大到小(漏斗结构) 或从小到大(倒漏斗结构) 或一次性选择(选择维度,获取维度参数)

     维度:可以统一看成一个关键的参数或者多个参数组成的参数

    1.基于A维度下,做选择或者在维度下设计维度参数

    2.不做维度配置,但根据维度来做相同业务逻辑的不同操作

    具体表设计如下:

    配置同一业务的顶级类-->具体业务类--->获取具体的处理模型--->获取具体的参数表达式

    1. create table check_expression
    2. (
    3. id int auto_increment
    4. primary key,
    5. business_type varchar(20) null comment '业务类型',
    6. check_model varchar(20) null comment '校验模型',
    7. check_expression text null comment '表达式',
    8. check_expression_name varchar(200) null comment '表达式名称',
    9. status tinyint default 1 null comment '0-失效 1-生效',
    10. create_time datetime null comment '创建时间',
    11. create_by varchar(60) null comment '创建人',
    12. update_time datetime null comment '更新时间',
    13. update_by varchar(60) null comment '更新建人'
    14. )
    15. comment '校验表达式';
    16. create table check_config
    17. (
    18. id int auto_increment
    19. primary key,
    20. business_key varchar(100) null comment '业务key',
    21. business_type varchar(20) null comment '业务类型',
    22. business_name varchar(100) null comment '业务名称',
    23. check_word varchar(100) null comment '校验关键字',
    24. check_word_name varchar(100) null comment '校验关键字名称',
    25. check_model varchar(20) null comment '校验模型',
    26. check_model_name varchar(200) null comment '校验模型名称',
    27. check_class varchar(500) null comment '业务类',
    28. check_expression text null comment '校验表达式',
    29. check_order tinyint default 1 null comment '校验顺序',
    30. check_msg text null comment '提示语',
    31. status tinyint default 1 null comment '0-无效 1-生效',
    32. fresh_status tinyint default 0 null comment '0-未刷新 1-刷新中,2-已刷新',
    33. try_times tinyint default 0 null comment '刷新次数,线程池处理',
    34. fresh_time datetime default CURRENT_TIMESTAMP null comment '上次刷新时间',
    35. create_time datetime null comment '创建时间',
    36. create_by varchar(60) not null comment '创建人',
    37. update_time datetime null comment '更新时间',
    38. update_by varchar(60) null comment '更新建人'
    39. )
    40. comment '校验配置' auto_increment = 9;
    41. create index id_business_key
    42. on check_config (business_key);
    43. create index id_business_type
    44. on check_config (business_type);
    45. create index id_check_model
    46. on check_config (check_model);
    47. create index id_create_by
    48. on check_config (create_by);
    49. create index id_fresh_status
    50. on check_config (fresh_status);
    51. create index id_status
    52. on check_config (status);
    53. create table business_class
    54. (
    55. id int auto_increment
    56. primary key,
    57. business_type varchar(20) null comment '001-校验',
    58. business_model varchar(20) null comment '业务模型',
    59. business_name varchar(200) null comment '业务名称',
    60. business_class varchar(500) null comment '业务类',
    61. status tinyint default 1 null comment '生效状态',
    62. create_time datetime null comment '创建时间',
    63. create_by varchar(60) null comment '创建人',
    64. update_time datetime null comment '更新时间',
    65. update_by varchar(60) null comment '更新建人'
    66. )
    67. comment '业务配置类' auto_increment = 9;
    68. create index id_business_model
    69. on business_class (business_model);
    70. create index id_business_type
    71. on business_class (business_type);
    72. create index id_status
    73. on business_class (status);

    核心代码(此处仅展示配置化校验代码):

    思想:第一步获取核心配置

              第二步:根据配置做业务处理

    List<CheckConfig> checkList = checkConfigService.getCheckList(map, map.get("business_key"));
    boolean checkResult = checkConfigService.checkConfigList(checkList, map);

    1. public boolean checkConfigList(List<CheckConfig> checkList, Map<String, String> map) {
    2. if (CollectionUtils.isNotEmpty(checkList)) {
    3. for (CheckConfig checkConfig : checkList) {
    4. ICheckService checkService = CACHE_CHECK_CLASS.getIfPresent(checkConfig.getCheckClass());
    5. if (checkService == null) {
    6. checkService = SpringBeanUtils.getBeanByName(checkConfig.getCheckClass(), ICheckService.class);
    7. if (checkService == null) {
    8. throw new BusinessException(500, CommonUtils.getStringBuilder().append("checkConfigList bean未配置:").append(checkConfig.getCheckClass()).toString());
    9. }
    10. CACHE_CHECK_CLASS.put(checkConfig.getCheckClass(), checkService);
    11. }
    12. boolean param = checkService.checkParam(checkConfig, map);
    13. if (param) {
    14. map.put("check_code", CODE_500);
    15. map.put("check_result", Boolean.FALSE.toString());
    16. map.put("check_msg", checkConfig.getCheckMsg());
    17. map.put("remark", CHECK_NOTICE_MSG);
    18. return true;
    19. }
    20. }
    21. }
    22. return false;
    23. }

    以上文章读懂不是很简单也不是很难;能够理解对于开发会是非常便捷的,不仅能优化别人同时也能优化自己(毕竟在实际项目中运用)

  • 相关阅读:
    WinHex(四)
    在线教育行业介绍
    腾讯云发送短信
    始祖双碳新闻 | 2022年8月3日碳中和行业早知道
    Leetcode 451. Sort Characters By Frequency (用堆)
    GP232RL USB转串口芯片SSOP28完全兼容替代FT232RL
    移动硬盘频繁断开连接怎么办?
    Netty源码学习9——从Timer到ScheduledThreadPoolExecutor到HashedWheelTimer
    web课程设计网页规划与设计 基于HTML+CSS+JavaScript制作智能停车系统公司网站静态模板
    蓝桥杯之模拟与枚举day1
  • 原文地址:https://blog.csdn.net/haohaounique/article/details/125510695