CN111930365A - Qt-based application program rapid development framework, development method and operation method - Google Patents
- ️Fri Nov 13 2020
技术领域technical field
本发明涉及应用程序开发领域,尤其涉及一种基于Qt的应用程序快速开发框架、开发方法及运行方法。The invention relates to the field of application program development, in particular to a Qt-based application program rapid development framework, development method and operation method.
背景技术Background technique
Qt是一个开源的支持跨平台的C++应用程序开发库,具有支持平台广泛、功能完整、开源、执行效率高、界面开发简单、开发工具完备等特性。Qt库对现用应用开发提供了多方位支持,涵盖了核心非图形、图形组件、多媒体功能及图形组件、网络编程、数据库操作、并发、XML支持、图表及数据可视化组件、支持2D/3D图形渲染、支持蓝牙硬件、传感器硬件、近场通信硬件、支持 CAN 和 Modbus 协议串行工业总线等数百个面向对象的良好封装的类。Qt is an open source C++ application development library that supports cross-platform. It has a wide range of supported platforms, complete functions, open source, high execution efficiency, simple interface development, and complete development tools. The Qt library provides multi-faceted support for the development of existing applications, covering core non-graphics, graphic components, multimedia functions and graphic components, network programming, database operations, concurrency, XML support, charts and data visualization components, and support for 2D/3D graphics Rendering, support for bluetooth hardware, sensor hardware, near field communication hardware, serial industrial bus support for CAN and Modbus protocols, hundreds of well-packaged object-oriented classes.
目前使用Qt框架开发应用软件主要存在以下问题:Qt拥有数百个功能完备的类,开发人员想要快速上手,且要全方位掌握使用技巧为开发所用,其难度不低。同时,开发人员在开发每一个业务时,往往都需从数据通讯、数据库访问等底层业务开始,更要兼顾开发保障缓存、事务、日志、安全、权限等基础业务,而多节点间通讯的应用开发更是涉及Socket编程、协议设计、数据封包解包、序列化反序列化等底层业务,即便可以规避通信底层业务的开发,但仍需要按照特定要求封装及共享服务接口类。由于不得不面对这些基础性非业务类功能,不仅使得开发人员很难聚焦于核心业务的开发,而且大大增加了应用软件开发、测试及维护的工作量,降低开发效率,同时增加开发测试维护难度,对开发人员的技能要求相应提高。At present, there are the following problems in using the Qt framework to develop application software: Qt has hundreds of classes with complete functions. Developers want to get started quickly, and they must master all-round skills for development, which is not low. At the same time, when developing each business, developers often need to start from the underlying business such as data communication and database access, and also need to take into account the development of basic businesses such as caching, transactions, logs, security, and permissions, while the application of multi-node communication Development involves Socket programming, protocol design, data packet unpacking, serialization and deserialization and other underlying services. Even if the development of communication underlying services can be avoided, it is still necessary to encapsulate and share service interface classes according to specific requirements. Having to face these basic non-business functions not only makes it difficult for developers to focus on core business development, but also greatly increases the workload of application software development, testing and maintenance, reduces development efficiency, and increases development, testing and maintenance. Difficulty, the skill requirements for developers are correspondingly increased.
发明内容SUMMARY OF THE INVENTION
本发明的主要目的在于提出一种基于Qt的应用程序快速开发框架、开发方法及运行方法,旨在解决现有基于Qt的应用程序开发效率低且难道大的技术问题。The main purpose of the present invention is to propose a Qt-based application program rapid development framework, development method and operation method, aiming to solve the technical problems of low development efficiency and large size of the existing Qt-based application program.
为实现上述目的,本发明提供一种基于Qt的应用程序快速开发框架,所述开发框架采用客户端与服务端架构,所述开发框架包括:To achieve the above purpose, the present invention provides a Qt-based application rapid development framework, the development framework adopts a client-side and server-side architecture, and the development framework includes:
设备驱动层,封装有多种设备驱动库并统一访问接口,用于实现同外部硬件设备的通信连接、数据采集及控制指令下发;The device driver layer is encapsulated with a variety of device driver libraries and unified access interfaces, which are used to realize the communication connection with external hardware devices, data acquisition and control command issuance;
存储层,封装有关系数据库和缓存数据库,用于作为应用程序的数据存储库,其中,所述关系数据库用于业务数据及历史数据存储,所述缓存数据库用于数据缓存及实时数据存储;The storage layer is encapsulated with a relational database and a cache database, and is used as a data repository for applications, wherein the relational database is used for business data and historical data storage, and the cache database is used for data caching and real-time data storage;
核心层,封装有多种非业务基础服务类库,用于提供应用程序所需的多种底层基础服务;The core layer, which encapsulates a variety of non-business basic service class libraries, is used to provide various underlying basic services required by the application;
模型层,封装有应用程序所需的业务模型类以及各业务模型类对应的业务规则和验证规则,用于提供实现具体业务功能所需的业务模型;The model layer encapsulates the business model classes required by the application and the business rules and validation rules corresponding to each business model class, and is used to provide the business models required to implement specific business functions;
服务层,封装有各业务模型类对应的业务服务类,用于实现具体业务功能处理;The service layer, which encapsulates the business service classes corresponding to each business model class, is used to implement specific business function processing;
调度层,用于提供轻量级消息队列以实现异步进行日志收集并存储,以及还提供线程调度和算法执行业务服务;The scheduling layer is used to provide a lightweight message queue for asynchronous log collection and storage, as well as thread scheduling and algorithm execution business services;
交互层,用于接收客户端向服务端发起的请求以及对请求数据进行非业务功能处理,并转发服务端向客户端做出的响应。The interaction layer is used to receive the request initiated by the client to the server, perform non-business function processing on the request data, and forward the response from the server to the client.
可选地,所述底层基础服务包括以下基础服务中的任意一种或多种:Optionally, the underlying basic services include any one or more of the following basic services:
缓存服务、消息服务、远程接口服务、异常服务、安全服务、事务服务、持久化服务、数据转换服务、数据校验服务、网络服务、线程服务、定时任务服务、国际化服务、日志服务。Cache service, message service, remote interface service, exception service, security service, transaction service, persistence service, data conversion service, data verification service, network service, thread service, timed task service, internationalization service, log service.
可选地,所述服务端用于通过以太网与外部硬件设备进行通信,并进行数据处理、运算和存储;所述客户端用于人机交互,以供进行数据收集、现场状态显示,并可对现场状态进行操作请求。Optionally, the server is used for communicating with external hardware devices through Ethernet, and performs data processing, computing and storage; the client is used for human-computer interaction for data collection, on-site status display, and An operation request can be made on the field status.
可选地,所述交互层的非业务功能处理包括:检验客户端发起的业务服务请求的合法性、正确性、操作权限以及执行缓存获取并记录操作日志;Optionally, the non-business function processing of the interaction layer includes: verifying the legality, correctness, and operation authority of the business service request initiated by the client, and performing cache acquisition and recording operation logs;
其中,若客户端发起的业务服务请求命中缓存,则返回命中的缓存结果,否则分解请求并进行事务管理以及向调度层分配业务服务请求,并将请求处理结果记入缓存以及向客户端返回记入的缓存结果。Among them, if the business service request initiated by the client hits the cache, the hit cache result is returned, otherwise the request is decomposed, transaction management is performed, and the business service request is allocated to the scheduling layer, and the request processing result is recorded in the cache and returned to the client. Incoming cached results.
可选地,所述开发框架的支持环境由操作系统及语言框架构成,所述语言框架采用C++语言及Qt库。Optionally, the support environment of the development framework is composed of an operating system and a language framework, and the language framework adopts C++ language and Qt library.
进一步地,为实现上述目的,本发明还提供一种采用上述任一项所述开发框架的应用程序开发方法,所述开发方法包括:Further, in order to achieve the above purpose, the present invention also provides an application development method using the development framework described in any of the above, the development method comprising:
获取所述开发框架的工程副本并作为新应用开发的基础工程;Obtain a project copy of the development framework and use it as a basic project for new application development;
根据新应用的设计文档,编写业务模型类,并将所述业务模型类封装到所述工程副本对应的开发框架模型层中;According to the design document of the new application, write a business model class, and encapsulate the business model class into the development framework model layer corresponding to the project copy;
根据新应用的设计文档,编写业务服务类,并将所述业务服务类封装到所述工程副本对应的开发框架服务层中;According to the design document of the new application, write a business service class, and encapsulate the business service class into the development framework service layer corresponding to the project copy;
根据新应用的设计文档,编辑图形用户界面,所述图形用户界面通过Qt信号与槽机制获取用户请求,并调用交互层接口传递请求数据以及从业务服务类中获取响应数据并通过图形用户界面呈现给用户;According to the design document of the new application, edit the graphical user interface, the graphical user interface obtains user requests through the Qt signal and slot mechanism, and calls the interaction layer interface to transfer the request data and obtain the response data from the business service class and present it through the graphical user interface to the user;
将封装有编写的业务模型类和业务服务类的所述开发框架的工程副本以及编辑的图形用户界面打包编译为可执行文件并进行测试后,将所述可执行文件作为新的互通多节点应用部署到目标节点上运行。After the project copy of the development framework encapsulated with the written business model class and business service class and the edited graphical user interface are packaged and compiled into an executable file and tested, the executable file is used as a new interoperable multi-node application Deploy to the target node to run.
进一步地,为实现上述目的,本发明还提供一种采用上述开发框架开发的应用程序的运行方法,应用于多节点通信网络,所述运行方法包括:Further, in order to achieve the above purpose, the present invention also provides a method for running an application developed by the above-mentioned development framework, which is applied to a multi-node communication network, and the running method includes:
客户端收集数据并构建操作模型对象,调用核心层的数据转换服务类将所述操作模型对象转换为请求数据对象;The client collects data and constructs an operation model object, and calls the data conversion service class of the core layer to convert the operation model object into a request data object;
客户端根据所述请求数据对象,通知相应的观察者进行处理,并调用客户端代理类传递请求数据;The client notifies the corresponding observer to process according to the request data object, and calls the client proxy class to transmit the request data;
客户端代理类接收到所述请求数据后,调用QtRO模块序列化所述请求数据,并通过网络传递至服务端代理类;After the client proxy class receives the request data, it calls the QtRO module to serialize the request data, and transmits it to the server proxy class through the network;
服务端代理类通过网络接收到序列化的请求数据后,调用QtRO模块将所述请求数据反序列化,并将反序列化后的所述请求数据传递至服务端交互层的非业务核心处理类中;After the server proxy class receives the serialized request data through the network, it calls the QtRO module to deserialize the request data, and transfers the deserialized request data to the non-business core processing class of the server interaction layer middle;
服务端交互层的非业务核心处理类接收到所述请求数据后,依次完成操作日志记录、用户安全校验、权限检查、参数校验、缓存获取,若命中缓存,则返回命中的缓存结果,否则构建资源类,并调用核心层的事务服务类进行事务管理以及调用调度层的服务路由类传递所述请求数据;After the non-business core processing class of the server interaction layer receives the request data, it sequentially completes operation log recording, user security verification, permission checking, parameter verification, and cache acquisition. If the cache is hit, the hit cache result is returned. Otherwise, the resource class is constructed, and the transaction service class of the core layer is called for transaction management and the service routing class of the scheduling layer is called to transmit the request data;
服务端调度层的服务路由类接收到所述请求数据后,获取所述请求数据中待调用服务类接口的元数据,并调用核心层的数据转换服务类,根据所述元数据,将所述请求数据中的参数数据转换为待调用服务类接口的具体业务模型对象,并调用服务端服务层的具体业务服务类进行处理;After receiving the request data, the service routing class of the server scheduling layer obtains the metadata of the service class interface to be called in the request data, and calls the data conversion service class of the core layer, and according to the metadata, converts the The parameter data in the request data is converted into the specific business model object of the service class interface to be called, and the specific business service class of the server service layer is called for processing;
服务端服务层的具体业务服务类接收到调度层传递的参数后,进行具体业务功能处理,其中,所述参数包括资源对象和具体业务模型对象;After receiving the parameters transmitted by the scheduling layer, the specific business service class of the server-side service layer performs specific business function processing, wherein the parameters include resource objects and specific business model objects;
服务端交互层以服务类接口的元数据、请求关键参数为关键字,将业务处理结果记入缓存,生成响应数据并通过网络返回客户端。The server interaction layer uses the metadata of the service class interface and the key parameters of the request as keywords, records the business processing results in the cache, generates response data and returns it to the client through the network.
可选地,所述请求数据具体包括:服务类接口的元数据、用户安全信息、数据查询参数以及请求参数;Optionally, the request data specifically includes: metadata of the service class interface, user security information, data query parameters and request parameters;
其中,所述元数据包括服务名、接口方法名;所述用户安全信息包括用户名、加密密钥;所述数据查询参数包括指令过滤条件、排序字段、输出字段和分页信息;所述请求参数为数组类型且每个数组元素均为属性可扩展的单条参数数据。Wherein, the metadata includes service name and interface method name; the user security information includes user name and encryption key; the data query parameters include instruction filter conditions, sorting fields, output fields and paging information; the request parameters It is an array type and each array element is a single piece of parameter data that is property-expandable.
可选地,所述响应数据包括正常响应数据与异常响应数据;Optionally, the response data includes normal response data and abnormal response data;
所述正常响应数据包括服务类接口的元数据、响应数据总数目、本次返回数据总数目以及单条响应数据;所述单条响应数据为数组类型且每个数组元素均为属性可扩展的数据;The normal response data includes the metadata of the service class interface, the total number of response data, the total number of returned data this time, and a single piece of response data; the single piece of response data is an array type and each array element is attribute-expandable data;
所述异常响应数据包括服务类接口的元数据、错误码以及具体错误描述信息,其中,所述元数据包括服务名、接口方法名。The exception response data includes metadata of the service class interface, an error code and specific error description information, wherein the metadata includes a service name and an interface method name.
可选地,所述服务端交互层的非业务核心处理类对所述请求数据进行处理具体包括:Optionally, the processing of the request data by the non-business core processing class of the server interaction layer specifically includes:
服务端交互层的非业务核心处理类解析所述请求数据,得到请求解析结果数据;The non-business core processing class of the server interaction layer parses the request data, and obtains the request parsing result data;
将所述请求解析结果数据中的服务类接口的元数据、请求参数、用户名、日期时间以及其他相关信息作为操作日志,并调用调度层的轻量级消息队列异步完成操作日志的记录;Taking the metadata of the service class interface, request parameters, user name, date and time and other relevant information in the request parsing result data as the operation log, and calling the lightweight message queue of the scheduling layer to asynchronously complete the recording of the operation log;
调用核心层的安全服务类对所述请求解析结果数据中的用户安全信息进行校验,若通过校验,则继续后续步骤,否则返回异常响应数据;Call the security service class of the core layer to verify the user security information in the request parsing result data, and if the verification is passed, continue the subsequent steps, otherwise return abnormal response data;
调用核心层的安全服务类对所述请求解析结果数据中的服务类接口的元数据进行权限检查,若通过检查,则继续后续步骤,否则返回异常响应数据;Invoke the security service class of the core layer to perform permission check on the metadata of the service class interface in the request parsing result data, if the check is passed, continue the subsequent steps, otherwise return abnormal response data;
调用核心层的数据校验服务类对所述请求解析结果数据中的请求参数执行具体业务模型对象的校验规则检查,若通过检查,则继续后续步骤,否则返回异常响应数据;Invoke the data verification service class of the core layer to perform the verification rule check of the specific business model object on the request parameter in the request parsing result data, if the verification is passed, continue the subsequent steps, otherwise return the abnormal response data;
根据所述请求解析结果数据中的服务类接口的元数据、请求参数,调用核心层的缓存服务类获取对应的缓存数据,若命中缓存,则将命中的缓存结果作为正常响应数据返回客户端,否则继续后续步骤;According to the metadata and request parameters of the service class interface in the request parsing result data, the cache service class of the core layer is called to obtain the corresponding cache data, and if the cache is hit, the hit cache result is returned to the client as normal response data, Otherwise continue to the next steps;
构建资源类,并调用核心层的事务服务类进行事务管理以及调用调度层的服务路由类传递所述请求数据。Build a resource class, call the transaction service class of the core layer for transaction management, and call the service routing class of the scheduling layer to transmit the request data.
本发明提供的基于Qt框架并适用于开发互通多节点应用软件的快速开发框架采用分层架构,包括交互层、调度层、服务层、模型层、核心层、设备驱动层和存储层。在开发具体的互通多节点应用软件时,只需要开发服务层和模型层功能即可,其余五层的功能均由框架提供。本发明开发框架封装了多节点间数据通信、数据库访问、缓存、事务、日志、安全、权限等非业务基础功能,避免了非业务基础功能的开发工作,开发人员只需要专注于核心业务的模型类与服务类的开发,便可提交按需定制的互通多节点应用软件,进而降低了开发人员技术门槛,提高了开发测试维护效率,缩短了应用软件开发周期,提升了互通多节点应用软件质量。The rapid development framework based on the Qt framework and suitable for developing interoperable multi-node application software provided by the present invention adopts a layered structure, including an interaction layer, a scheduling layer, a service layer, a model layer, a core layer, a device driver layer and a storage layer. When developing specific interoperable multi-node application software, it is only necessary to develop the functions of the service layer and the model layer, and the functions of the other five layers are provided by the framework. The development framework of the invention encapsulates non-business basic functions such as multi-node data communication, database access, cache, transaction, log, security, authority, etc., avoiding the development of non-business basic functions, and developers only need to focus on the core business model For the development of classes and services, you can submit on-demand interoperable multi-node application software, thereby lowering the technical threshold for developers, improving the efficiency of development, testing and maintenance, shortening the application software development cycle, and improving the quality of interoperable multi-node application software. .
附图说明Description of drawings
图1为本发明基于Qt的应用程序快速开发框架一实施例的架构图;Fig. 1 is a framework diagram of an embodiment of a Qt-based application rapid development framework of the present invention;
图2为本发明基于开发框架的应用程序开发方法一实施例的流程示意图;2 is a schematic flowchart of an embodiment of an application development method based on a development framework of the present invention;
图3为本发明基于开发框架开发的应用程序的运行方法一实施例的流程示意图;3 is a schematic flowchart of an embodiment of a method for running an application developed based on a development framework of the present invention;
图4为本发明基于开发框架开发的应用程序的运行方法一实施例中交互层非业务核心处理的流程示意图。FIG. 4 is a schematic flowchart of non-business core processing in the interaction layer in an embodiment of an application program running method developed based on a development framework of the present invention.
本发明目的的实现、功能特点及优点将结合实施例,参照附图做进一步说明。The realization, functional characteristics and advantages of the present invention will be further described with reference to the accompanying drawings in conjunction with the embodiments.
具体实施方式Detailed ways
应当理解,此处所描述的具体实施例仅仅用以解释本发明,并不用于限定本发明。It should be understood that the specific embodiments described herein are only used to explain the present invention, but not to limit the present invention.
参照图1,图1为本发明基于Qt的应用程序快速开发框架一实施例的架构图,本实施例具体为应用于互通多节点应用软件的快速开发框架。Referring to FIG. 1 , FIG. 1 is an architecture diagram of an embodiment of a Qt-based application rapid development framework of the present invention. This embodiment is specifically a rapid development framework applied to intercommunication multi-node application software.
本实施例公开的应用程序快速开发框架采用分层架构,主要分为七层,分别是交互层、调度层、服务层、模型层、核心层、设备驱动层和存储层。在开发具体的互通多节点应用软件时,只需要开发人员开发服务层和模型层功能,而其余五层的功能均由框架提供。下面将分别简要介绍框架内置各层的功能作用。The application rapid development framework disclosed in this embodiment adopts a layered architecture, which is mainly divided into seven layers, namely an interaction layer, a scheduling layer, a service layer, a model layer, a core layer, a device driver layer and a storage layer. When developing specific interoperable multi-node application software, developers only need to develop the functions of the service layer and the model layer, while the functions of the other five layers are provided by the framework. The following will briefly introduce the functions of the built-in layers of the framework.
(1)设备驱动层(1) Device driver layer
本实施例中,设备驱动层封装有多种设备驱动库并统一访问接口,用于实现同外部硬件设备的通信连接、数据采集及控制指令下发。In this embodiment, the device driver layer is encapsulated with a variety of device driver libraries and unified access interfaces, which are used to realize communication connection with external hardware devices, data collection and control instruction issuance.
设备驱动层通过封装设备设施驱动库,统一访问接口,来实现同设备设施的连接、数据采集及控制指令下发,通过驱动库访问方式不仅可以屏蔽不同设备设施要求的物理网络及通信协议的差异性,而且还可以提高控制稳定性,缩短应用开发调试周期。The device driver layer encapsulates the device and facility driver library and unifies the access interface to realize the connection with the equipment and facilities, data acquisition and control command issuance. The access method through the driver library can not only shield the physical network and communication protocol differences required by different equipment and facilities It can also improve the control stability and shorten the application development and debugging cycle.
(2)存储层(2) Storage layer
本实施例中,存储层封装有关系数据库和缓存数据库,用于作为应用程序的数据存储库,其中,所述关系数据库用于业务数据及历史数据存储,所述缓存数据库用于数据缓存及实时数据存储。In this embodiment, the storage layer encapsulates a relational database and a cache database, which are used as data storage for applications, wherein the relational database is used for business data and historical data storage, and the cache database is used for data caching and real-time data storage. data storage.
存储层采用关系数据库和缓存数据库两种存储库。关系数据库具有运行速度快、可移植性强、支持多种存储引擎、管理功能丰富易用的特点,在具体应用中用于业务数据及历史数据的存储。而缓存数据库采用一种Key-Value类型的高性能非关系内存数据库,具有速度快、丰富数据类型、操作原子性,在具体应用中用于数据缓存及实时数据存储。The storage layer uses both relational databases and cache databases. The relational database has the characteristics of fast running speed, strong portability, support for multiple storage engines, rich and easy-to-use management functions, and is used for the storage of business data and historical data in specific applications. The cache database adopts a high-performance non-relational memory database of Key-Value type, which has fast speed, rich data types, and operation atomicity. It is used for data caching and real-time data storage in specific applications.
(3)核心层(3) Core layer
本实施例中,核心层封装有多种非业务基础服务类库,用于提供应用程序所需的多种底层基础服务。In this embodiment, the core layer is encapsulated with a variety of non-business basic service class libraries for providing a variety of underlying basic services required by the application.
核心层是多方位的基础工具服务类库,实现缓存、消息、远程接口、异常、安全、事务、持久、数据转换、数据校验、网络、线程、定时、国际化、日志等方面必备的底层功能。The core layer is a multi-faceted basic tool service class library, which is necessary to implement cache, message, remote interface, exception, security, transaction, persistence, data conversion, data verification, network, thread, timing, internationalization, log, etc. low-level functionality.
可选的,在一具体实施例中,所述底层基础服务包括以下基础服务中的任意一种或多种:Optionally, in a specific embodiment, the underlying basic service includes any one or more of the following basic services:
缓存服务、消息服务、远程接口服务、异常服务、安全服务、事务服务、持久化服务、数据转换服务、数据校验服务、网络服务、线程服务、定时任务服务、国际化服务、日志服务。Cache service, message service, remote interface service, exception service, security service, transaction service, persistence service, data conversion service, data verification service, network service, thread service, timed task service, internationalization service, log service.
(4)模型层(4) Model layer
本实施例中,模型层封装有应用程序所需的业务模型类以及各业务模型类对应的业务规则和验证规则,用于提供实现具体业务功能所需的业务模型。In this embodiment, the model layer encapsulates the business model classes required by the application program and the business rules and verification rules corresponding to each business model class, and is used to provide the business models required to realize specific business functions.
模型层主要是关注系统的业务领域,建立相应业务模型对象,并提供业务规则和验证规则。The model layer mainly focuses on the business domain of the system, establishes corresponding business model objects, and provides business rules and verification rules.
(5)服务层(5) Service layer
本实施例中,服务层封装有各业务模型类对应的业务服务类,用于实现具体业务功能处理。In this embodiment, the service layer encapsulates business service classes corresponding to each business model class, and is used to implement specific business function processing.
服务层从各业务场景出发,分别提供各种业务模型的业务处理功能。Starting from each business scenario, the service layer provides business processing functions for various business models.
(6)调度层(6) Scheduling layer
本实施例中,调度层用于提供轻量级消息队列以实现异步进行日志收集并存储,以及还提供线程调度和算法执行业务服务。In this embodiment, the scheduling layer is used to provide a lightweight message queue to implement asynchronous log collection and storage, and also to provide thread scheduling and algorithm execution business services.
调度层提供轻量化消息队列,主要用于异步高速进行日志收集并存储。同时提供线程调度及算法执行业务服务功能,提高系统资源利用率,高效并发执行更多的请求处理。The scheduling layer provides a lightweight message queue, which is mainly used for asynchronous high-speed log collection and storage. At the same time, it provides thread scheduling and algorithm execution business service functions, improves system resource utilization, and executes more request processing efficiently and concurrently.
(7)交互层(7) Interactive layer
本实施例中,交互层用于接收客户端向服务端发起的请求以及对请求数据进行非业务功能处理,并转发服务端向客户端做出的响应。In this embodiment, the interaction layer is configured to receive the request initiated by the client to the server, perform non-business function processing on the request data, and forward the response from the server to the client.
可选的,在一具体实施例中,所述交互层的非业务功能处理包括:检验客户端发起的业务服务请求的合法性、正确性、操作权限以及执行缓存获取并记录操作日志;Optionally, in a specific embodiment, the non-business function processing of the interaction layer includes: verifying the legality, correctness, and operation authority of the business service request initiated by the client, and performing cache acquisition and recording operation logs;
其中,若客户端发起的业务服务请求命中缓存,则返回命中的缓存结果,否则分解请求并进行事务管理以及向调度层分配业务服务请求,并将请求处理结果记入缓存以及向客户端返回记入的缓存结果。Among them, if the business service request initiated by the client hits the cache, the hit cache result is returned, otherwise the request is decomposed, transaction management is performed, and the business service request is allocated to the scheduling layer, and the request processing result is recorded in the cache and returned to the client. Incoming cached results.
交互层接收所有的客户端向服务器端发出的请求,并发送服务器端向客户端做出的响应,同时检验请求的合法性、操作权限、正确性、记录操作日志;如果缓存命中,则返回缓存结果;否则,分解请求,提供事务管理,并向调度层分配业务服务请求,结果记入缓存,并返回结果。The interaction layer receives all requests sent by the client to the server, and sends the response from the server to the client. At the same time, it checks the validity of the request, operation authority, correctness, and records the operation log; if the cache hits, it returns the cache Result; otherwise, the request is decomposed, transaction management is provided, and the business service request is allocated to the scheduling layer, the result is recorded in the cache, and the result is returned.
可选的,在一具体实施例中,所述开发框架的支持环境由操作系统及语言框架构成,整个系统采用C++语言及Qt库进行开发设计,利用Qt库的跨平台特性,只需在目标操作系统中重新编译,无需修改代码,便可获得特定目标操作系统上的应用系统。Optionally, in a specific embodiment, the support environment of the development framework is composed of an operating system and a language framework, and the entire system is developed and designed using the C++ language and the Qt library. Recompile in the operating system, without modifying the code, you can obtain the application system on the specific target operating system.
此外,本实施例的开发框架采用客户端/服务端架构。服务端与硬件设备通过以太网进行通信,并进行数据处理、运算和存储。客户端用于人机交互,如用户信息收集、现场状态显示,并可以对现场的开关、状态进行操作请求。In addition, the development framework of this embodiment adopts a client/server architecture. The server communicates with hardware devices through Ethernet, and performs data processing, computing and storage. The client is used for human-computer interaction, such as user information collection, on-site status display, and operation requests for on-site switches and statuses.
本实施例的客户端具体由事件层、模型层、业务层构成,客户端同样基于C++语言或Qt库开发设计。服务端与客户端共同通过接口层,在以太网中进行请求及响应。The client in this embodiment is specifically composed of an event layer, a model layer, and a business layer, and the client is also developed and designed based on the C++ language or the Qt library. The server and the client jointly pass the interface layer to request and respond in the Ethernet.
本实施例公开的应用开发框架封装了多节点间数据通信、数据库访问、缓存、事务、日志、安全、权限等非业务基础功能,并屏蔽了这些非业务基础功能的开发工作。由于框架内置了这些必要的非业务基础功能,进而使得开发人员可以轻松上手,只专注于核心业务的开发,便可提交按需定制的互通多节点应用软件,降低了开发人员技术门槛,提高了开发测试维护效率,缩短了应用软件开发周期,提升了互通多节点应用软件质量。The application development framework disclosed in this embodiment encapsulates non-business basic functions such as multi-node data communication, database access, cache, transaction, log, security, and authority, and shields the development of these non-business basic functions. Since the framework has built-in these necessary non-business basic functions, developers can easily get started and only focus on the development of core business, and can submit on-demand customized interoperable multi-node application software, which reduces the technical threshold of developers and improves the The efficiency of development, testing and maintenance shortens the application software development cycle and improves the quality of interoperable multi-node application software.
参照图2,图2为本发明基于开发框架的应用程序开发方法一实施例的流程示意图。Referring to FIG. 2, FIG. 2 is a schematic flowchart of an embodiment of an application development method based on a development framework of the present invention.
本实施例中,基于上述实施例中的开发框架实现应用程序开发的开发方法包括以下步骤:In this embodiment, the development method for implementing application development based on the development framework in the foregoing embodiment includes the following steps:
步骤S101,获取所述开发框架的工程副本并作为新应用开发的基础工程;Step S101, obtaining a project copy of the development framework and using it as a basic project for new application development;
本实施例中,由于开发框架的工程副本中已经包含了开发应用程序必备的底层非业务基础功能库与机制,因此将开发框架的工程副本作为新应用开发的基础工程可以减少大量的非业务模块的开发。对于开发框架已在上述实施例中做了详细说明,因此不再赘述。In this embodiment, since the engineering copy of the development framework already contains the underlying non-business basic function libraries and mechanisms necessary for developing applications, using the engineering copy of the development framework as the basic engineering for new application development can reduce a large number of non-business basic functions. Development of modules. The development framework has been described in detail in the above-mentioned embodiments, so it is not repeated here.
步骤S102,根据新应用的设计文档,编写业务模型类,并将所述业务模型类封装到所述工程副本对应的开发框架模型层中;Step S102, write a business model class according to the design document of the new application, and encapsulate the business model class into the development framework model layer corresponding to the project copy;
本实施例中,先根据新应用的设计文档编写业务模型类,然后再将编写好的业务模型类封装到工程副本对应的开发框架模型层中。In this embodiment, the business model class is first written according to the design document of the new application, and then the written business model class is encapsulated into the development framework model layer corresponding to the project copy.
本实施例对于业务模型类的编写方式不限,既可以是由开发人员基于软件开发应用开发,也可以是预先设计好编写各种不同业务模型类的编写脚本,然后通过批量任务的方式调用多个编写脚本分别编写不同的业务模型类。There is no limitation on the way of writing business model classes in this embodiment. It can be developed by developers based on software development applications, or it can be pre-designed writing scripts for writing various business model classes, and then call multiple tasks through batch tasks. Each script is written separately for different business model classes.
本实施例中,在编写出业务模型类后,开发框架核心层的持久化服务还可以自动根据业务模型类的元数据,提供数据库增删改查基本功能,以供业务服务类调用。In this embodiment, after the business model class is written, the persistence service in the core layer of the development framework can also automatically provide basic functions of database addition, deletion, modification, and query according to the metadata of the business model class for the business service class to call.
步骤S103,根据新应用的设计文档,编写业务服务类,并将所述业务服务类封装到所述工程副本对应的开发框架服务层中;Step S103, according to the design document of the new application, write a business service class, and encapsulate the business service class into the development framework service layer corresponding to the project copy;
本实施例对于业务服务类的编写方式不限,既可以是由开发人员基于软件开发应用开发,也可以是预先设计好编写各种不同业务服务类的编写脚本,然后通过批量任务的方式调用多个编写脚本分别编写不同的业务服务类。There is no limitation on the way of writing business service classes in this embodiment. It can be developed by developers based on software development and application development, or it can be pre-designed to write scripts for various business service classes, and then call multiple tasks through batch tasks. Each script is written to write different business service classes.
本实施例的业务服务类可以直接调用本地其它服务类接口,也可以调用交互层接口从指定外部节点调用指定服务类接口。框架会根据业务服务类中的统一接口标签自动将本地接口登记为交互接口。The business service class in this embodiment may directly call other local service class interfaces, or may call the interaction layer interface to call the specified service class interface from the specified external node. The framework will automatically register the local interface as the interactive interface according to the unified interface label in the business service class.
步骤S104,根据新应用的设计文档,编辑图形用户界面,所述图形用户界面通过Qt信号与槽机制获取用户请求,并调用交互层接口传递请求数据以及从业务服务类中获取响应数据并通过图形用户界面呈现给用户;Step S104, according to the design document of the new application, edit the graphical user interface, the graphical user interface obtains the user request through the Qt signal and slot mechanism, and calls the interaction layer interface to transfer the request data and obtain the response data from the business service class and pass the graphical user request. The user interface is presented to the user;
本实施例对于图形用户界面的编写方式不限,既可以是由开发人员基于软件开发应用开发,也可以是预先设计好编写各种不同图形用户界面的编写脚本,然后通过批量任务的方式调用多个编写脚本分别编写不同的图形用户界面。There is no limitation on the way of writing the GUI in this embodiment. It can be developed by developers based on software development and application development, or it can be pre-designed to write scripts for writing various GUIs, and then call multiple tasks through batch tasks. Each script is written separately to write a different GUI.
本实施例中,编写的图形用户界面具体通过以下方式实现人机交互功能:采用Qt信号与槽机制获取用户请求,并调用交互层接口传递请求数据以及从业务服务类中获取响应数据并通过图形用户界面呈现给用户。In this embodiment, the written graphical user interface specifically implements the human-computer interaction function in the following ways: using the Qt signal and slot mechanism to obtain user requests, and calling the interaction layer interface to transfer the request data and obtain the response data from the business service class and pass the graphic The user interface is presented to the user.
步骤S105,将封装有编写的业务模型类和业务服务类的所述开发框架的工程副本以及编辑的图形用户界面打包编译为可执行文件并进行测试后,将所述可执行文件作为新的互通多节点应用部署到目标节点上运行。Step S105, after the project copy of the development framework encapsulated with the written business model class and business service class and the edited graphical user interface are packaged and compiled into an executable file and tested, the executable file is used as a new interoperable file. Multi-node applications are deployed to run on target nodes.
本实施例中,在完成步骤S102-S104后,将封装有编写的业务模型类和业务服务类的所述开发框架的工程副本以及编辑的图形用户界面打包编译为可执行文件,然后对该可执行文件进行测试,测试符合设计要求后即可部署到目标节点上运行。In this embodiment, after completing steps S102-S104, the project copy of the development framework encapsulated with the written business model class and business service class and the edited graphical user interface are packaged and compiled into an executable file, and then the executable file is packaged and compiled. Execute the file for testing. After the test meets the design requirements, it can be deployed to the target node to run.
由上述开发过程可知,新应用程序的开发工作仅需基于框架,完成业务模型类、业务服务类以及图形用户界面的编写与封装,整个过程只涉及到核心业务,而像多节点间数据通信、数据库访问、缓存、事务、日志、安全、权限等非业务基础功能,则全部由框架提供封装,开发过程中无需关心这些非业务基础功能的实现,进而减轻了开发工作量,提升了开发效率。It can be seen from the above development process that the development of new applications only needs to be based on the framework to complete the writing and encapsulation of business model classes, business service classes and graphical user interfaces. Non-business basic functions such as database access, caching, transactions, logs, security, and permissions are all provided and encapsulated by the framework. During the development process, there is no need to care about the implementation of these non-business basic functions, thereby reducing the development workload and improving development efficiency.
参照图3,图3为本发明基于开发框架开发的应用程序的运行方法一实施例的流程示意图。Referring to FIG. 3 , FIG. 3 is a schematic flowchart of an embodiment of a method for running an application developed based on a development framework of the present invention.
本实施例中,基于上述实施例中的开发框架开发的应用程序具体应用于服务端,也即作为服务端应用与客户端进行业务交互,本实施例具体说明开发框架在单次业务服务请求执行响应的过程与机制。In this embodiment, the application program developed based on the development framework in the above-mentioned embodiment is specifically applied to the server, that is, it is used as a server application to perform business interaction with the client. This embodiment specifically illustrates that the development framework executes a single business service request The process and mechanism of the response.
本实施例中,基于上述实施例中的开发框架开发的应用程序的运行方法具体包括以下步骤:In this embodiment, the method for running an application developed based on the development framework in the above embodiment specifically includes the following steps:
步骤S201,客户端收集数据并构建操作模型对象,调用核心层的数据转换服务类将所述操作模型对象转换为请求数据对象;Step S201, the client collects data and constructs an operation model object, and invokes the data conversion service class of the core layer to convert the operation model object into a request data object;
本实施例中,客户端收集数据,然后构建操作模型对象OperationObject,并借由核心层数据转换服务类JsonMessage转换为请求数据对象QJsonObject。In this embodiment, the client collects data, then constructs an operation model object OperationObject, and converts it into a request data object QJsonObject by using the core layer data conversion service class JsonMessage.
步骤S202,客户端根据所述请求数据对象,通知相应的观察者进行处理,并调用客户端代理类传递请求数据;Step S202, the client notifies the corresponding observer to process according to the request data object, and calls the client proxy class to transmit the request data;
本实施例中,客户端JsonData类根据请求数据对象,通知相应的观察者进行处理,同时调用服务代理类发出请求数据对象QJsonObject,也即请求数据。In this embodiment, the client JsonData class notifies the corresponding observer to process according to the request data object, and at the same time calls the service proxy class to send the request data object QJsonObject, that is, the request data.
可选的,在一具体实施例中,所述请求数据具体包括:服务类接口的元数据、用户安全信息、数据查询参数以及请求参数;Optionally, in a specific embodiment, the request data specifically includes: metadata of the service class interface, user security information, data query parameters and request parameters;
其中,所述元数据包括服务名、接口方法名;所述用户安全信息包括用户名、加密密钥;所述数据查询参数包括指令过滤条件、排序字段、输出字段和分页信息;所述请求参数为数组类型且每个数组元素均为属性可扩展的单条参数数据。Wherein, the metadata includes service name and interface method name; the user security information includes user name and encryption key; the data query parameters include instruction filter conditions, sorting fields, output fields and paging information; the request parameters It is an array type and each array element is a single piece of parameter data that is property-expandable.
步骤S203,客户端代理类接收到所述请求数据后,调用QtRO模块序列化所述请求数据,并通过网络传递至服务端代理类;Step S203, after the client proxy class receives the request data, it calls the QtRO module to serialize the request data, and transmits it to the server proxy class through the network;
本实施例中,客户端ClientReplica类是开发框架依托QtRO模块开发的客户端代理类,接收到请求数据对象后,借由QtRO模块的序列化及网络传输功能将请求数据对象QJsonObject发送至服务端。In this embodiment, the client ClientReplica class is a client proxy class developed by the development framework relying on the QtRO module. After receiving the request data object, it sends the request data object QJsonObject to the server through the serialization and network transmission functions of the QtRO module.
QtRO模块(Qt Remote Object简称QtRO)专门用于进程间通信(IPC)。QtRO本质上是一个点对点的通信网络,每个进程通过QRemoteObjectNode接入QtRO网络。The QtRO module (Qt Remote Object for short QtRO) is dedicated to inter-process communication (IPC). QtRO is essentially a point-to-point communication network, and each process accesses the QtRO network through QRemoteObjectNode.
步骤S204,服务端代理类通过网络接收到序列化的请求数据后,调用QtRO模块将所述请求数据反序列化,并将反序列化后的所述请求数据传递至服务端交互层的非业务核心处理类中;Step S204, after the server proxy class receives the serialized request data through the network, it calls the QtRO module to deserialize the request data, and transmits the deserialized request data to the non-service of the server interaction layer. In the core processing class;
本实施例中,服务端交互层ServerSource类同样也是框架依托QtRO模块开发的服务端代理类,通过网络接收到请求数据对象QJsonObject,并反序列化为请求数据对象QJsonObject,并传递到服务端交互层非业务核心处理类中。In this embodiment, the ServerSource class of the server interaction layer is also a server proxy class developed by the framework relying on the QtRO module. It receives the request data object QJsonObject through the network, deserializes it into the request data object QJsonObject, and transmits it to the server interaction layer. In the non-business core processing class.
步骤S205,服务端交互层的非业务核心处理类接收到所述请求数据后,依次完成操作日志记录、用户安全校验、权限检查、参数校验、缓存获取,若命中缓存,则返回命中的缓存结果,否则构建资源类,并调用核心层的事务服务类进行事务管理以及调用调度层的服务路由类传递所述请求数据;Step S205, after receiving the request data, the non-business core processing class of the server interaction layer sequentially completes operation log recording, user security verification, authority checking, parameter verification, and cache acquisition, and returns the hit if the cache is hit. Cache the result, otherwise build a resource class, and call the transaction service class of the core layer for transaction management and call the service routing class of the scheduling layer to transmit the request data;
本实施例中,服务端交互层非业务核心处理类DataAccess接收到请求数据对象QJsonObject后,依次完成操作日志记录、用户安全校验、权限检查、参数校验、缓存获取、构建资源类并统一进行事务管理,调用调度层的服务路由执行功能,返回并缓存结果。In this embodiment, after receiving the request data object QJsonObject, the non-business core processing class of the server interaction layer, DataAccess, sequentially completes operation log recording, user security verification, permission checking, parameter verification, cache acquisition, and resource class construction, and performs unified processing. Transaction management, calling the service routing execution function of the scheduling layer, returning and caching the results.
步骤S206,服务端调度层的服务路由类接收到所述请求数据后,获取所述请求数据中待调用服务类接口的元数据,并调用核心层的数据转换服务类,根据所述元数据,将所述请求数据中的参数数据转换为待调用服务类接口的具体业务模型对象,并调用服务端服务层的具体业务服务类进行处理;Step S206, after receiving the request data, the service routing class of the server scheduling layer obtains the metadata of the service class interface to be called in the request data, and calls the data conversion service class of the core layer, and according to the metadata, Convert the parameter data in the request data into the specific business model object of the service class interface to be called, and call the specific business service class of the server service layer for processing;
本实施例中,服务端调度层的服务路由类Dispatch接收到请求数据对象QJsonObject后,从中得到要调用服务接口的元数据;同时,使用框架核心层数据转换功能,将请求数据对象QJsonObject中的参数数据转换为服务类接口的具体业务模型对象,最终完成动态调用具体业务服务类接口操作。In this embodiment, after receiving the request data object QJsonObject, the service routing class Dispatch of the server scheduling layer obtains the metadata of the service interface to be called from it; at the same time, it uses the data conversion function of the framework core layer to convert the parameters in the request data object QJsonObject The data is converted into the specific business model object of the service class interface, and finally the operation of dynamically calling the specific business service class interface is completed.
步骤S207,服务端服务层的具体业务服务类接收到调度层传递的参数后,进行具体业务功能处理,其中,所述参数包括资源对象和具体业务模型对象;Step S207, after receiving the parameters transmitted by the scheduling layer, the specific business service class of the server-side service layer performs specific business function processing, wherein the parameters include resource objects and specific business model objects;
本实施例中,具体业务服务类接收到调度层传递的参数,包括资源对象Resource和具体业务模型对象,进行具体的业务功能处理,如需要,可使用资源对象Resource的功能完成持久化操作。In this embodiment, the specific business service class receives the parameters transmitted by the scheduling layer, including the resource object Resource and the specific business model object, and performs specific business function processing. If necessary, the function of the resource object Resource can be used to complete the persistence operation.
步骤S208,服务端交互层以服务类接口的元数据、请求关键参数为关键字,将业务处理结果记入缓存,生成响应数据并通过网络返回客户端。Step S208, the server interaction layer uses the metadata of the service class interface and the key request parameters as keywords, records the business processing result in the cache, generates response data and returns it to the client through the network.
本实施例中,在服务层的业务服务类对客户端发起的请求进行具体业务功能处理后,交互层再以服务类接口的元数据、请求关键参数为关键字,将业务处理结果记入缓存,并生成本次请求对应的响应数据以及通过网络将响应数据返回客户端,从而完成单次业务服务请求、执行与响应的全过程。In this embodiment, after the business service class of the service layer performs specific business function processing on the request initiated by the client, the interaction layer uses the metadata of the service class interface and the key parameters of the request as keywords, and records the business processing result in the cache , and generate the response data corresponding to this request and return the response data to the client through the network, so as to complete the whole process of a single business service request, execution and response.
可选的,在一具体实施例中,所述响应数据包括:Optionally, in a specific embodiment, the response data includes:
(1)正常响应数据(1) Normal response data
正常响应数据具体包括服务类接口的元数据、响应数据总数目、本次返回数据总数目以及单条响应数据;所述单条响应数据为数组类型且每个数组元素均为属性可扩展的数据;The normal response data specifically includes the metadata of the service class interface, the total number of response data, the total number of returned data this time, and a single piece of response data; the single piece of response data is an array type and each array element is attribute-expandable data;
(2)异常响应数据(2) Abnormal response data
异常响应数据具体包括服务类接口的元数据、错误码以及具体错误描述信息,其中,所述元数据包括服务名、接口方法名。The exception response data specifically includes metadata of the service class interface, an error code, and specific error description information, where the metadata includes a service name and an interface method name.
图4为本发明基于开发框架开发的应用程序的运行方法一实施例中交互层非业务核心处理的流程示意图。FIG. 4 is a schematic flowchart of the non-business core processing of the interaction layer in an embodiment of the method for running an application developed based on the development framework of the present invention.
本实施例中,所述服务端交互层的非业务核心处理类对所述请求数据进行处理具体包括:In this embodiment, the processing of the request data by the non-business core processing class of the server interaction layer specifically includes:
步骤S301,服务端交互层的非业务核心处理类解析所述请求数据,得到请求解析结果数据;Step S301, the non-business core processing class of the server interaction layer parses the request data, and obtains request parsing result data;
本实施例中,服务端交互层接收到客户端传递过来的请求数据后,调用非业务核心处理类解析该请求数据,得到请求解析结果数据。In this embodiment, after receiving the request data transmitted by the client, the server interaction layer invokes the non-business core processing class to parse the request data, and obtains request parsing result data.
本实施例中,基于客户端与服务端交互的基本设计流程,交互层需要依次对请求数据进行操作日志记录、用户安全校验、权限检查、请求参数校验,最后再获取缓存。In this embodiment, based on the basic design process of interaction between the client and the server, the interaction layer needs to sequentially perform operation log recording, user security verification, permission checking, and request parameter verification on the request data, and finally obtain the cache.
步骤S302,将所述请求解析结果数据中的服务类接口的元数据、请求参数、用户名、日期时间以及其他相关信息作为操作日志,并调用调度层的轻量级消息队列异步完成操作日志的记录;Step S302, take the metadata of the service class interface, request parameters, user name, date and time and other relevant information in the request parsing result data as the operation log, and call the lightweight message queue of the scheduling layer to asynchronously complete the operation log. Record;
本实施例中,在解析出服务类接口的元数据、请求参数、用户名、日期时间以及其他相关信息等信息后,将上述信息作为操作日志,并通过框架中轻量级消息队列异步完成操作日志的记录。In this embodiment, after the metadata, request parameters, user name, date and time, and other related information of the service class interface are parsed, the above information is used as the operation log, and the operation is asynchronously completed through the lightweight message queue in the framework log records.
步骤S303,调用核心层的安全服务类对所述请求解析结果数据中的用户安全信息进行校验,若通过校验,则继续后续步骤,否则返回异常响应数据;Step S303, calling the security service class of the core layer to verify the user security information in the request parsing result data, if the verification is passed, continue the subsequent steps, otherwise return abnormal response data;
本实施例中,在解析出用户安全信息后,通过框架中核心层安全服务完成用户安全校验操作,比如账户密码验证等。如果通过校验,继续后续步骤;否则,直接返回异常响应结果。In this embodiment, after the user security information is parsed, the user security verification operation, such as account password verification, is completed through the core layer security service in the framework. If the verification is passed, continue to the next steps; otherwise, return the abnormal response result directly.
步骤S304,调用核心层的安全服务类对所述请求解析结果数据中的服务类接口的元数据进行权限检查,若通过检查,则继续后续步骤,否则返回异常响应数据;Step S304, calling the security service class of the core layer to perform permission check on the metadata of the service class interface in the request parsing result data, if the check is passed, continue the subsequent steps, otherwise return abnormal response data;
本实施例中,在解析出服务类接口的元数据,通过框架中核心层安全服务完成对用户当前服务接口请求的权限检查,不同的服务名、接口方法名对应有不同的权限,因此在实际处理请求之前需要进行鉴权。如果通过检查,继续后续步骤;否则,直接返回异常响应结果。In this embodiment, after parsing the metadata of the service class interface, the permission check of the user's current service interface request is completed through the core layer security service in the framework. Different service names and interface method names correspond to different permissions, so in practice Authentication is required before processing the request. If it passes the check, continue to the next steps; otherwise, return the abnormal response result directly.
步骤S305,调用核心层的数据校验服务类对所述请求解析结果数据中的请求参数执行具体业务模型对象的校验规则检查,若通过检查,则继续后续步骤,否则返回异常响应数据;Step S305, calling the data verification service class of the core layer to perform the verification rule check of the specific business model object on the request parameter in the request parsing result data, if the check is passed, continue the subsequent steps, otherwise return abnormal response data;
本实施例中,在解析出请求参数后,通过框架中核心层校验服务执行业务模型对象中校验规则,以对请求参数进行检查,比如数据类型检查、数值区间检查等。如果通过检查,继续后续步骤;否则,直接返回异常响应结果。In this embodiment, after the request parameters are parsed, the validation rules in the business model object are executed through the core layer validation service in the framework to check the request parameters, such as data type check, value range check, and the like. If it passes the check, continue to the next steps; otherwise, return the abnormal response result directly.
步骤S306,根据所述请求解析结果数据中的服务类接口的元数据、请求参数,调用核心层的缓存服务类获取对应的缓存数据,若命中缓存,则将命中的缓存结果作为正常响应数据返回客户端,否则继续后续步骤;Step S306, according to the metadata and request parameters of the service class interface in the request parsing result data, call the cache service class of the core layer to obtain the corresponding cache data, and if the cache is hit, return the hit cache result as normal response data client, otherwise continue to the next steps;
本实施例中,在解析出服务类接口的元数据、请求参数后,通过框架中核心层缓存服务获取存储层中数据库内缓存数据。如果命中缓存,直接将命中的缓存结果作为正常响应数据返回,否则,继续后续步骤。In this embodiment, after the metadata and request parameters of the service class interface are parsed, the cached data in the database in the storage layer is obtained through the core layer cache service in the framework. If the cache is hit, directly return the hit cache result as normal response data, otherwise, continue to the next steps.
步骤S307,构建资源类,并调用核心层的事务服务类进行事务管理以及调用调度层的服务路由类传递所述请求数据。In step S307, a resource class is constructed, and the transaction service class of the core layer is invoked for transaction management and the service routing class of the scheduling layer is invoked to transmit the request data.
本实施例中,如果请求数据未命中缓存,则说明服务端不存在对应的响应数据,因此,交互层需要构建资源类,然后通过框架中核心层的持久化服务获取数据库链接、设备链接并统一管理链接,进一步调用核心层的事务服务类进行事务管理。In this embodiment, if the request data does not hit the cache, it means that there is no corresponding response data on the server side. Therefore, the interaction layer needs to build a resource class, and then obtain the database link and device link through the persistence service of the core layer in the framework and unify them. Manage the link, and further call the transaction service class of the core layer for transaction management.
事务管理是对于一系列数据库操作进行管理,一个事务包含一个或多个SQL语句,是逻辑管理的工作单元,一个事务是对数据库进行读和写的一个序列。通过构建资源类并进行事务管理,从而可在存储层数据库中生成新的资源对象及新缓存数据,以便实现后续具体的业务功能处理。Transaction management is to manage a series of database operations. A transaction contains one or more SQL statements and is a unit of work for logical management. A transaction is a sequence of reading and writing to the database. By constructing resource classes and performing transaction management, new resource objects and new cached data can be generated in the storage layer database, so as to realize subsequent specific business function processing.
本步骤中,在完成事务管理后,交互层进一步调用调度层的服务路由类传递客户端的请求数据,以便调度层使用框架核心层的数据转换功能,将请求数据中的参数数据转换为服务类接口的具体业务模型对象,最终完成动态调用具体业务服务类接口操作,最后具体业务服务类根据调度层传递的参数,包括资源对象Resource和具体业务模型对象,进行具体的业务功能处理,如需要,还可使用资源对象Resource的功能完成持久化操作。最后,服务端交互层以服务类接口的元数据、请求关键参数为关键字,将业务处理结果记入缓存,生成响应数据并通过网络返回客户端。In this step, after completing the transaction management, the interaction layer further calls the service routing class of the scheduling layer to transmit the client's request data, so that the scheduling layer uses the data conversion function of the framework core layer to convert the parameter data in the request data into the service class interface The specific business model object, and finally complete the dynamic call of the specific business service class interface operation, and finally the specific business service class performs specific business function processing according to the parameters passed by the scheduling layer, including the resource object Resource and the specific business model object, if necessary, also Persistence operations can be completed using the functions of the resource object Resource. Finally, the server interaction layer uses the metadata of the service class interface and the key parameters of the request as keywords, records the business processing results into the cache, generates response data and returns it to the client through the network.
所属领域的技术人员可以清楚地了解到,如果本发明以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本发明各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(read-only memory, ROM)、随机存取存储器(random access memory,RAM)、磁碟或者光盘等各种可以存储程序代码的介质。Those skilled in the art can clearly understand that if the present invention is implemented in the form of software functional units and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium , including several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes: a U disk, a removable hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk and other media that can store program codes. .
以上所述,以上实施例仅用以说明本发明的技术方案,而非对其限制;尽管参照前述实施例对本发明进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本发明各实施例技术方案的精神和范围。As mentioned above, the above embodiments are only used to illustrate the technical solutions of the present invention, but not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand: The technical solutions described in the embodiments are modified, or some technical features thereof are equivalently replaced; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions in the embodiments of the present invention.