Business data processing method and device, electronic equipment and computer readable storage medium
By introducing domain models and aggregation root encapsulation of business processing behaviors in the traditional three-layer architecture, the problem of high coupling between business logic and data model is solved, business processing efficiency and system scalability are improved, and more efficient business data processing is achieved.
Patent Information
- Application Number
- CN202411107944.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-13
- Publication Date
- 2024-11-26
AI Technical Summary
In the back-end development of traditional three-layer architecture, the business logic and data model are highly coupled, resulting in low business processing efficiency and difficult maintenance. In the high concurrency and large data volume scenarios, the performance bottleneck is serious, making it difficult to meet the real-time and scalability requirements. .
Introduce a domain model in domain-driven design (DDD), encapsulate business processing behaviors through aggregation roots, unified management of business logic and data model decoupling, and adopt a four-layer architecture to decompose business logic into multiple sub-domains with clear boundaries and responsibilities. , and perform business processing through aggregation roots to avoid logical interleaving.
Improve business processing efficiency, reduce system complexity, enhance system scalability and maintenance, avoid logical interleaving and data inconsistency, and improve response speed and performance.
Smart Images

Figure CN119025534A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of computer technology, and specifically to a business data processing method, device, electronic device, and computer-readable storage medium. Background Art
[0002] Back-end development usually adopts the traditional three-tier architecture. Under this architecture, business logic is usually scattered in the service layer, resulting in a high degree of coupling between the business logic in the service layer and the data model. During the business processing, operations such as creation, editing, and listing of activities are mainly handled by the service layer, resulting in the service layer being filled with a large amount of code about activity status changes and rule checks, with intertwined logic, low business processing efficiency and difficulty in maintenance. Introducing domain services or application services in domain-driven design (DDD) can assist in managing business logic, but there is currently no solution to apply DDD to business logic management. Summary of the invention
[0003] In view of the above problems, the embodiments of the present application provide a business data processing method, device, electronic device and computer-readable storage medium for efficient business processing.
[0004] According to one aspect of an embodiment of the present application, a business data processing method is provided, including: obtaining business request data; if the business request data represents a query type request, accessing a database to perform business processing based on the business request data; if the business request data represents a non-query type request, obtaining a target aggregate root corresponding to the business request data, and performing business processing based on a target business processing behavior corresponding to the target aggregate root, different aggregate roots corresponding to different business processing behaviors.
[0005] In an optional manner, the target business processing behavior includes a target verification behavior and a target state change behavior; the business processing based on the target business processing behavior corresponding to the target aggregate root further includes: verifying the business request data based on the target verification behavior to obtain a verification result; if the verification result indicates that the verification is passed, then modifying the state data of the target business processing object in the target aggregate root based on the target state change behavior.
[0006] In an optional manner, the target business processing behavior includes an integrity verification behavior, and the integrity verification behavior includes at least one of a field non-null check, a data range check, and an association relationship check; after modifying the state data of the target business processing object in the target aggregate root based on the target state change behavior, the method also includes: performing an integrity verification on the state data of the modified business processing object in the target aggregate root to obtain an integrity verification result; if the integrity verification result indicates that the integrity verification passes, then updating the data in the database based on the modified state data of the target business processing object.
[0007] In an optional manner, the business request data represents the modification of the target business processing object to a first state; the verification of the business request data based on the target verification behavior further includes: verifying the format of the business request data; and / or, performing a business logic verification based on the second state and the first state of the target business processing object in the business request data; and / or, verifying the permissions of the business request data.
[0008] In an optional manner, the business logic verification is performed based on the second state and the first state of the target business processing object in the business request data, and further includes: verifying whether the second state can be modified to the first state; if the second state can be modified to the first state, the business logic verification passes.
[0009] In an optional manner, the verifying the authority of the service request data further includes: obtaining a user identifier of a sender of the service request data;
[0010] Verify whether the authority preset by the user identifier includes modifying the status data of the target business processing object; if so, verify the authority of the business request data.
[0011] In an optional manner, the accessing of a database to perform business processing based on the business request data further includes: obtaining a query index for the business request data; calling a data access interface, and searching the database for data corresponding to the query index through the data access interface.
[0012] According to another aspect of an embodiment of the present application, a business data processing device is provided, including: a business request data acquisition module, used to acquire business request data; a first business processing module, used to access a database to perform business processing based on the business request data if the business request data represents a query type request; a second business processing module, used to acquire a target aggregate root corresponding to the business request data if the business request data represents a non-query type request, and perform business processing based on a target business processing behavior corresponding to the target aggregate root, different aggregate roots corresponding to different business processing behaviors.
[0013] According to one aspect of an embodiment of the present application, an electronic device is provided, including: a controller; and a memory for storing one or more programs, which, when the one or more programs are executed by the controller, execute the above-mentioned business data processing method.
[0014] According to one aspect of an embodiment of the present application, a computer-readable storage medium is also provided, on which computer-readable instructions are stored. When the computer-readable instructions are executed by a processor of a computer, the computer executes the above-mentioned business data processing method.
[0015] According to one aspect of the embodiments of the present application, a computer program product or a computer program is also provided, the computer program product or the computer program includes a computer instruction, and the computer instruction is stored in a computer-readable storage medium. The processor of the computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the above-mentioned business data processing method.
[0016] The embodiment of the present application analyzes the business request data and can directly modify the database for the business request data of query requests; for the business request data of non-query requests, the corresponding target aggregate root is obtained and business processing is performed through the target aggregate root. The business processing behavior corresponding to the business request data is uniformly encapsulated in the target aggregate root, and business processing can be performed directly according to the target business processing behavior corresponding to the target aggregate root, avoiding logical interleaving and improving business processing efficiency.
[0017] The above description is only an overview of the technical solution of the embodiment of the present application. In order to more clearly understand the technical means of the embodiment of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the embodiment of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The drawings herein are incorporated into the specification and constitute a part of the specification, illustrate embodiments consistent with the present application, and are used together with the specification to explain the principles of the present application. Obviously, the drawings described below are only some embodiments of the present application, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0019] Figure 1 It is an implementation environment diagram shown in an exemplary embodiment of the present application.
[0020] Figure 2 It is a flowchart of a business data processing method shown in an exemplary embodiment of the present application.
[0021] Figure 3 It is a four-layer architecture diagram shown in an exemplary embodiment of the present application.
[0022] Figure 4 It is a flowchart of a business data processing method shown in another exemplary embodiment of the present application.
[0023] Figure 5 It is a structural diagram of a business data processing device shown in an exemplary embodiment of the present application.
[0024] Figure 6 It is a structural diagram of a computer system of an electronic device shown in an exemplary embodiment of the present application. DETAILED DESCRIPTION
[0025] Here, exemplary embodiments will be described in detail, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are only examples of devices and methods consistent with some aspects of the present application as detailed in the attached claims.
[0026] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0027] The flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps can be decomposed, and some operations / steps can be combined or partially combined, so the actual execution order may change according to actual conditions.
[0028] The term "multiple" as used in this application refers to two or more than two. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the related objects are in an "or" relationship.
[0029] Backend development usually adopts the traditional three-tier architecture. In this architecture, business logic is usually scattered in the service layer, resulting in a high degree of coupling between business logic and data model, increased system complexity, and difficult maintenance. In addition, the three-tier architecture often has performance bottlenecks when dealing with high concurrency and large data volume scenarios, making it difficult to meet the requirements of real-time and scalability.
[0030] Take a traditional three-tier e-commerce platform as an example. In the activity management module, the creation, editing, and delisting of activities are mainly handled by the service layer. The activity state change logic is scattered in multiple service methods. Each state change requires calling the database to verify the activity parameters and then update the state. This method works when the business logic is simple, but as the platform scales up, the number of activity types increases, and the complexity of business rules increases dramatically, problems gradually emerge: chaotic business logic: the service layer is full of codes for activity state changes and rule checks, and the logic is intertwined and difficult to maintain; data inconsistency: post-data verification is prone to omission errors, resulting in the temporary storage of activity states that do not comply with the rules, causing user confusion; slow response: during peak hours, frequent database read and write operations lead to performance bottlenecks, and user operation feedback is seriously delayed.
[0031] Domain models can solve the above problems, but domain models need to perform data integrity verification. Data integrity verification is usually implemented by hard coding or configuration files. This method has the following problems: verification rules are not easy to maintain. Modifying verification rules requires modifying code or configuration files, which is prone to errors; verification efficiency is low. When the amount of data is large, the verification process may occupy a large amount of system resources and affect system performance.
[0032] Based on this, a business data processing method is proposed in this embodiment, which introduces a domain model into the service layer to assist the service layer in performing business logic processing.
[0033] Please refer to Figure 1 , Figure 1 This is an implementation scenario diagram proposed in this embodiment, which includes a terminal and a server, and the terminal and the server are in communication connection. It can be understood that Figure 1 The number of terminals and servers in the embodiment is exemplary. In other embodiments, other numbers of terminals and servers may be included.
[0034] In one embodiment, the terminal can accept business request data and send the business request data to the server, which obtains the business request data; if the business request data represents a query request, the database is accessed to perform business processing based on the business request data; if the business request data represents a non-query request, the target aggregate root corresponding to the business request data is obtained, and business processing is performed based on the target business processing behavior corresponding to the target aggregate root. Different aggregate roots correspond to different business processing behaviors. The server can also feed back the business processing results obtained after the business request behavior is completed to the terminal, and display them through the terminal's visual interface.
[0035] It can be understood that the service request data may be a request sent to a certain application in the terminal.
[0036] In some embodiments, the terminal may be a visualization device such as a mobile phone, a vehicle-mounted terminal, a television, a tablet, a computer, etc.; the server side may be a device with data processing capabilities such as a server cluster and a cloud server.
[0037] Understandably, Figure 1 Although an implementation scenario diagram is shown, it is for illustrative purposes only. In other embodiments, there may be other implementation scenarios, which are not specifically limited here.
[0038] One aspect of the present application provides a method for processing business data. Figure 2 , Figure 2 is a flowchart of a business data processing method shown in an exemplary embodiment of the present application. The business data processing method can be applied to Figure 1 The server side in the embodiment includes at least S210 to S230, which are described in detail as follows:
[0039] S210: Obtain service request data.
[0040] In this embodiment, business request data is accepted, and the business request data may represent a query type request, such as querying data of a certain query indicator, and may also represent a non-query type request for modifying a state corresponding to a certain business process.
[0041] It can be understood that the business request data is a request issued to a certain application or a certain platform. For example, for an e-commerce platform, a query request is to query the data of a certain order, the data of a certain product, etc., and a non-query request is to modify, create, or delete an order, etc.; of course, it can be other platforms and applications, and there is no specific restriction at this time.
[0042] In some embodiments, reference may be made to Figure 3The four-layer architecture shown in the figure, in this embodiment, the application or platform is developed through the four-layer architecture, from top to bottom are the user interface layer, service layer, domain layer and basic layer, the four-layer architecture is obtained by introducing domain-driven design (DDD) on the three-layer architecture, and is further refined into a four-layer architecture on the basis of DDD. The user interface layer is the interface part for users to interact with applications or platforms, which can be a web interface, a mobile application interface or a desktop application. It is responsible for receiving business request data, calling the application service layer to process user requests, and presenting the results to users; the service layer entrusts the business request data to the domain layer for processing. The domain layer is the core and encapsulates complex business logic. The interaction with the database is handled by the infrastructure layer to keep the business logic pure; the infrastructure layer provides the infrastructure services required to support the operation of the application, including database access, message queues, external service calls, logging, etc.
[0043] In this four-layer architecture, the business logic is accurately expressed by establishing a domain model, and the complex business domain is decomposed into multiple sub-domains with clear boundaries and responsibilities. The core elements include entity, value object, aggregate, domain event, etc.
[0044] Entities and value objects in aggregates are very basic domain objects. Entities generally correspond to business objects, which have business attributes and business behaviors; while value objects are mainly attribute collections that describe the state and characteristics of entities. However, both entities and value objects are only individualized objects, and their behaviors reflect individual capabilities. Aggregates are composed of entities and value objects that are closely related to business and logic. Aggregates are the basic units of data modification and persistence. Each aggregate corresponds to a warehouse to achieve data persistence.
[0045] Aggregates belong to the domain layer in the DDD layered architecture. The domain layer contains multiple aggregations that jointly implement the core business logic.
[0046] The aggregate root is the manager of the aggregate. The aggregate root is also called the root entity. It is not only an entity, but also the manager of the aggregate. As an entity itself, it has the attributes and business behaviors of the entity and realizes its own business logic. As the manager of the aggregate, it is responsible for coordinating the entities and value objects within the aggregate to complete the common business logic in accordance with fixed business rules. The aggregate root is between aggregates. As the external interface of the aggregate, it accepts external tasks and requests in the form of aggregate root ID (identifier) association, and realizes business collaboration between aggregates within the context. In other words, aggregates are associated and referenced through the aggregate root identifier. If you need to access entities of other aggregates, you must first access the aggregate root and then navigate to the entities inside the aggregate. External objects cannot directly access entities in the aggregate. If there is an order aggregate, the order is the aggregate root. The aggregate also contains entities such as sender information and product information. Other aggregate root data can be found through the entity. For example, the sender information can be used to find the entities and value objects under the aggregate whose aggregate root is the sender information.
[0047] That is, an aggregate A has multiple entities, and the multiple entities include an aggregate root. The other entities in aggregate A except the aggregate root may be the aggregate roots of other aggregates, and aggregate A references other aggregates through the other aggregate roots.
[0048] In this embodiment, during back-end development, in-depth domain analysis is performed to identify core business concepts, define domain models, and clarify entities, value objects, aggregate roots, etc. to ensure that the model can accurately reflect business logic and rules for domain modeling. The resulting application or platform can perform business processing through the business data processing method proposed in this embodiment.
[0049] Different aggregations can be set for different businesses. In this way, the corresponding aggregation can be determined according to the business request data, and then the business processing behavior encapsulated in the aggregation can be performed according to the aggregation root in the corresponding aggregation. There are entities and value objects in the aggregation.
[0050] DDD can be further refined as follows Figure 3 The four-layer architecture in the above diagram is used for aggregation design. For aggregation, each aggregate root is responsible for managing a set of related entities and value objects, encapsulating business processing behaviors, ensuring data consistency within transaction boundaries, and introducing domain events to achieve cross-aggregate communication and enhance the loose coupling of the system. Finally, based on the bounded context theory of DDD, the system is split into multiple microservices. Each microservice is responsible for one or several closely related sub-domains, improving the scalability and maintainability of the system.
[0051] Each microservice corresponds to Figure 3 The four-layer structure shown in the figure independently processes business request data. Figure 3In the architecture, the domain services of the domain layer can only be called by the service layer, and the service layer can only be called by the user interface layer. In this architecture, services are encapsulated or combined layer by layer, and the dependencies are clear.
[0052] For DDD, the outputs of different stages are the inputs of the next stage. It can be seen that there are business analysis stage, strategic design stage and tactical design stage in this architecture. The business analysis stage outputs business events, business logic and business classification described in a unified language for the strategic design stage, while the strategic design stage inputs the domain model and boundary context for the tactical design stage to facilitate microservice splitting and model mapping.
[0053] Specifically, in the business analysis phase, the business problem domain and business use cases are comprehensively sorted out, the unified language in the business is clarified, domain events, domain objects and their corresponding domain behaviors are discovered in the business domain, and their respective associations are determined; in the strategic design phase, the DDD theory is used to divide the business domain (the result of business analysis) and build a domain model, and the corresponding bounded context is sorted out through a unified domain language. In the process of building the domain model, the corresponding aggregates, entities and value objects need to be sorted out; in the tactical design phase, the domain model is used as the input for tactical design, and the bounded context is used as the boundary for microservice division to split microservices. Domain stratification is performed in each microservice to achieve the mapping of the domain model to the code structure, thereby realizing the true implementation of DDD and code output.
[0054] In this way, multiple aggregates can be considered to exist in the domain layer. Each aggregate includes a corresponding target aggregate root. The target aggregate root is encapsulated with the corresponding business processing behavior. When business request data comes in, the corresponding target aggregate root is determined, and the corresponding business processing can be performed through the business processing behavior encapsulated in the aggregate.
[0055] S220: If the service request data represents a query type request, access a database to perform service processing based on the service request data.
[0056] like Figure 4 As shown in the figure, the user interface layer (Facade pattern) Business request data can be received through the application or platform, the service layer receives the business request data from the user interface layer and transmits it to the domain layer. The domain service in the domain layer calls the entity to process the business request data.
[0057] It can be understood that data objects between different layers can be converted to use the data requirements of the layer. For example, if the data object in the domain layer is DO (domain object) and the data object in the service layer is DTO (data transfer object), DTO-DO conversion is performed between the service layer and the domain layer.
[0058] The domain layer will first confirm whether the business request data is a query request, and perform different business processing according to different types of requests.
[0059] If it is a query request, the database is accessed for business processing based on the business request data. In some trial theories, such as obtaining the query index of the business request data, calling the data access interface, and searching the database for data corresponding to the query index through the data access interface. The data access interface can be an interface such as a repository, which interacts directly with the database through the repository to obtain the query result.
[0060] It is understandable that this type of query request does not need to be processed accordingly through aggregation.
[0061] Call the data access interface and search the database for data corresponding to the query indicator through the data access interface.
[0062] S230: If the business request data represents a non-query request, the target aggregate root corresponding to the business request data is obtained, and business processing is performed based on the target business processing behavior corresponding to the target aggregate root. Different aggregate roots correspond to different business processing behaviors.
[0063] In other embodiments, if the business request data represents a non-query request, the target aggregate root corresponding to the business request data is obtained.
[0064] In this embodiment, different business request data corresponds to different aggregate roots, and different aggregate roots correspond to different business processing behaviors.
[0065] In this embodiment, the business processing behaviors in the aggregation are encapsulated in the aggregate root, including verification behaviors, state change behaviors, etc., and a unified interface is provided to the outside through the aggregate root to achieve decoupling of business logic and data model.
[0066] Through this aggregate root, for specific activity types (such as limited-time sales, points redemption), different behaviors can be dynamically loaded for the business processing behaviors encapsulated in the aggregate root. For example, before a limited-time sale is put on the shelves, the aggregate root will add an automatic check to see if there is sufficient inventory, and automatically decide whether to continue putting the product on the shelves based on the configuration of the rule engine.
[0067] In a specific embodiment, for an e-commerce platform, the aggregate root corresponding to the order processing business request is designed as a core module. It is not just a simple data container, but carries rich business logic. For example, the aggregate root contains the following key entities and value objects: Order entity (Order): stores basic information of the order, such as order number, user ID, creation time, product list, total price, etc. The order entity is the root node of the aggregate root, has a unique identifier, and controls the modification of the order status; Product entity (Product): Although the product information exists as a value object in the order, in the aggregate root design, it is decoupled from the product service by referencing the product ID to ensure the lightweight of order processing; User entity (User): associates user information through user ID for operations such as permission verification and address confirmation, but also maintains lightweight reference to avoid over-coupling; Business logic method: defines methods within the aggregate root, such as: the calculation total price method is used to dynamically calculate the total amount of the order, including logic such as discounts and coupon applications; the payment processing method processes the payment logic to ensure the security and atomicity of the payment process. These methods encapsulate complex business rules and provide a simple interface to the outside world.
[0068] In this embodiment, the target business processing behavior includes target verification behavior and target state change behavior. After determining the target aggregate root, the business request data is verified based on the target verification behavior to obtain a verification result; if the verification result indicates that the verification is passed, the state data of the target business processing object in the target aggregate root is modified based on the target state change behavior.
[0069] If the verification fails, an error message is returned to indicate the user who issued the service request data.
[0070] It can be understood that the business request data represents the modification of the target business processing object to a first state; the target business processing object is the object that needs to undergo business processing modification processing on the business request data, and may also refer to an entity in the aggregate corresponding to the target aggregate root. The target verification row may include verifying the format of the business request data; and / or, performing business logic verification based on the second state and the first state of the target business processing object in the business request data; and / or, verifying the permissions of the business request data.
[0071] It can be understood that when the verification of the target verification behavior is one or more, a passed verification means that all the verifications included in the target verification behavior are passed, such as the target verification behavior includes verifying the format of the business request data and performing a business logic verification based on the second state and the first state of the target business processing object in the business request data; then the verification of the format of the business request data and the business logic verification based on the second state and the first state of the target business processing object in the business request data are both passed, which can indicate that the verification result obtained by verifying the business request data based on the target verification behavior represents a passed verification.
[0072] Performing a business logic check based on the second state and the first state of the target business processing object in the business request data can be regarded as checking whether the second state can be modified to the first state; if the second state can be modified to the first state, the business logic check passes.
[0073] The first state is the state of the target business processing object after the business request data is processed, and the second state is the state of the target business processing object before the business request data is processed. For example, if the target business processing object is inventory, the inventory is reduced by 8 in the first state, and the inventory is 6 in the second state, then the second state cannot be modified to the first state, indicating that the business logic verification fails.
[0074] Verifying the permissions of the business request data can be regarded as confirming whether the user who issues the business request data has the permission to perform the business processing corresponding to the business request data. At this time, the user ID of the party issuing the business request data can be obtained; verifying whether the permissions preset by the user ID include modifying the status data of the target business processing object; if included, the permissions of the business request data are verified and passed.
[0075] It can be understood that for different user identifiers, the corresponding business processing authority of the user representation is pre-set, so that the user identifier of the sender of the business request data can be obtained to determine whether the authority of the business request data is verified.
[0076] In some embodiments, the target business processing behavior includes an integrity verification behavior, and the integrity verification behavior includes at least one of a field non-null check, a data range check, and an association relationship check; after modifying the state data of the target business processing object in the target aggregate root based on the target state change behavior, the method also includes: performing an integrity verification on the state data of the modified business processing object in the target aggregate root to obtain an integrity verification result; if the integrity verification result indicates that the integrity verification passes, then updating the data in the database based on the modified state data of the target business processing object.
[0077] In this embodiment, the aggregate definition corresponding to the aggregate root has integrity verification behavior, including field non-null check, data range check, association relationship check, etc., which can be flexibly configured through annotations or configuration files.
[0078] It can be understood that the integrity verification behavior can be performed before and after modifying the state data of the target business processing object in the target aggregate root.
[0079] After the integrity check, to ensure consistency in the database, such as Figure 4 As shown, the domain layer calls the basic layer and updates the status data of the target business processing object in the database of the basic layer.
[0080] In one embodiment, if the business request data represents a non-query request, the business request data is verified in the domain layer based on the target verification behavior. After the verification passes, the state of the target business processing object is changed first, and then the integrity verification behavior of the domain model is called. If it passes, the data access interface layer will continue to be called to interact with the database to store or modify the data of the target business processing object. If the integrity verification fails, an exception will generally be thrown and returned to the user. In addition, if it is necessary to communicate with external resources (such as the middle platform) or use remote calls to other service data, the service layer will complete this task through the adapter.
[0081] In this embodiment, through the above-mentioned business processing method, the business request data for user operations that do not modify the database, that is, business request data representing query type requests, remains open; for operations that may change database data, that is, non-query type requests, a rigorous check is maintained, that is, the target aggregate root completes multi-step checks and status changes, and only after passing, the database is allowed to be modified, rather than directly modifying the database when there is a request. This can prevent database data problems and reduce the frequent input and output access to the database by erroneous data and operations, and consume database connection resources.
[0082] In this embodiment, all verification behaviors are encapsulated together through the target aggregate root when designing the domain model, rather than being written separately and fragmentedly into the code logic of each logical layer like a three-tier architecture, thereby preventing omissions of verification logic and reducing redundancy.
[0083] For example, to participate in an event, it is necessary to ensure that the event is in progress, the user is the car owner, the user has not participated in this event before, the user is not a blacklisted user, and so on. If two classes have this requirement at the same time, the same verification rules need to be written multiple times, which causes redundancy. In this embodiment, the target aggregate root encapsulation is managed uniformly.
[0084] It should be noted that when designing the aggregate root encapsulation, the integrity requirements of the activity should be maintained to define the boundaries of the domain and ensure the consistency of the business logic within the domain; through the aggregate root, multiple business processing behaviors related to the integrity of the activity are encapsulated together. These business processing behaviors include publishing configuration, publishing time, publishing type, activity name, image identification, activity status and non-null check of activity time, etc. This encapsulation ensures the cohesion of the business logic and makes external callers not need to care about the specific implementation of these rules.
[0085] Since the business processing behavior, that is, the business logic, is encapsulated in the aggregate root, when the business processing behavior changes, it is only necessary to modify the business processing behavior encapsulated in the aggregate root without changing the code of other parts, which greatly improves the maintainability of the system.
[0086] DDD emphasizes maintaining consistency between domain objects through aggregate roots, and other entities in the aggregate roots can interact with other aggregates to jointly maintain the consistency of activities.
[0087] And the business processing process based on aggregate roots is based on memory, that is, it does not interact with the database, but is completed directly at the domain layer. The business processing method based on memory is faster than the operation based on the database. This helps to improve the response speed of the system; and by performing business processing in memory, the database can be accessed without access, which can not only improve performance, but also reduce the load on the database; and when this method is used in a business request data processing, the memory-based operation can be more easily combined with the business request management to ensure the consistency and integrity of the data.
[0088] In this embodiment, by concentrating the integrity verification behavior in the aggregate root, it can be ensured that all integrity verification behaviors are uniformly managed and executed, which helps to reduce omissions and errors and improve the reliability of the system; and the call of the aggregate root can be implemented in a public way, and it can be called in multiple places (for example, when creating, updating or verifying activities). This reusability reduces code redundancy and improves development efficiency; as the business develops, new integrity verification behaviors may need to be added. Since all integrity verification behaviors are concentrated in the aggregate root method, adding new rules only requires modifying the integrity verification behavior without changing the code of other parts. This improves the scalability of the system.
[0089] The business data processing method proposed in this embodiment not only reflects the advantages of the DDD architecture, but also demonstrates the importance of memory-based business processing and unified integrity verification, which helps to improve the performance, maintainability, consistency and scalability of business data processing.
[0090] Another aspect of the present application also provides a business data processing device, such as Figure 5 As shown, Figure 5 FIG. 5 is a schematic diagram of a business data processing device according to an exemplary embodiment of the present application. The business data processing device 500 includes:
[0091] The service request data acquisition module 510 is used to acquire service request data.
[0092] The first business processing module 530 is configured to access a database to perform business processing based on the business request data if the business request data represents a query type request.
[0093] The second business processing module 550 is used to obtain the target aggregate root corresponding to the business request data if the business request data represents a non-query request, and perform business processing based on the target business processing behavior corresponding to the target aggregate root. Different aggregate roots correspond to different business processing behaviors.
[0094] In an optional manner, the target business processing behavior includes a target verification behavior and a target state change behavior; the second business processing module 550 further includes: a verification unit, used to verify the business request data based on the target verification behavior to obtain a verification result; a state change unit, used to modify the state data of the target business processing object in the target aggregate root based on the target state change behavior if the verification result indicates that the verification has passed.
[0095] In an optional manner, the target business processing behavior includes an integrity verification behavior, and the integrity verification behavior includes at least one of a field non-null check, a data range check, and an association relationship check; the second business processing module 550 also includes: an integrity verification unit, which is used to perform an integrity verification on the status data of the modified business processing object in the target aggregate root to obtain an integrity verification result; a data modification unit, which is used to update the data in the database based on the status data of the modified target business processing object if the integrity verification result indicates that the integrity verification has passed.
[0096] In an optional manner, the business request data represents the modification of the target business processing object to a first state; the verification unit further includes: a first verification module for verifying the format of the business request data; and / or, a second verification module for performing business logic verification based on the second state and the first state of the target business processing object in the business request data; and / or, a third verification module for verifying the permissions of the business request data.
[0097] In an optional manner, the second verification section further includes: a first verification sub-section, used to verify whether the second state can be modified to the first state; and a second verification sub-section, used to verify that the business logic passes if the second state can be modified to the first state.
[0098] In an optional manner, the third verification section further includes: a user identification acquisition sub-section, used to obtain the user identification of the sender of the business request data; a third verification sub-section, used to verify whether the permissions preset by the user identification include modifying the status data of the target business processing object; and a fourth verification sub-section, used to verify the permissions of the business request data if included.
[0099] In an optional manner, the first service processing module 530 further includes:
[0100] The query index acquisition unit is used to obtain the query index of the business request data; the first business processing unit is used to call the data access interface and search the data corresponding to the query index in the database through the data access interface.
[0101] The business data processing device of the present application analyzes the business request data. For the business request data of query requests, the database can be directly modified; for the business request data of non-query requests, the corresponding target aggregate root is obtained, and business processing is performed through the target aggregate root. The business processing behavior corresponding to the business request data is uniformly encapsulated in the target aggregate root, and business processing can be performed directly according to the target business processing behavior corresponding to the target aggregate root, avoiding logical interleaving and improving business processing efficiency.
[0102] It should be noted that the business data processing device provided in the above embodiment and the business data processing method provided in the above embodiment belong to the same concept, wherein the specific manner in which each module and unit performs operations has been described in detail in the method embodiment and will not be repeated here.
[0103] Another aspect of the present application provides an electronic device, including: a controller; a memory for storing one or more programs, when the one or more programs are executed by the controller, to execute the above-mentioned business data processing method.
[0104] See also Figure 6 , Figure 6 1 is a schematic diagram of the structure of a computer system of an electronic device shown in an exemplary embodiment of the present application, which shows a schematic diagram of the structure of a computer system of an electronic device suitable for implementing an embodiment of the present application.
[0105] It should be noted that Figure 6 The computer system 600 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0106] like Figure 6As shown, the computer system 600 includes a central processing unit (CPU) 601, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 602 or the program loaded from the storage part 608 to the random access memory (RAM) 603, such as executing the method in the above embodiment. In the RAM 603, various programs and data required for system operation are also stored. The CPU 601, ROM 602 and RAM 603 are connected to each other through a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0107] The following components are connected to the I / O interface 605: an input section 606 including a keyboard, a mouse, etc.; an output section 607 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the I / O interface 605 as needed. A removable medium 611, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 610 as needed so that a computer program read therefrom is installed into the storage section 608 as needed.
[0108] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a computer program for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication section 609, and / or installed from a removable medium 611. When the computer program is executed by a central processing unit (CPU) 601, various functions defined in the system of the present application are executed.
[0109] It should be noted that the computer-readable medium shown in the embodiment of the present application can be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium can be, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it. In the present application, a computer-readable signal medium can include a data signal propagated in a baseband or as a part of a carrier wave, wherein a computer-readable computer program is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate, or transmit programs for use by or in conjunction with an instruction execution system, apparatus, or device. The computer program contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0110] The flowchart and block diagram in the accompanying drawings illustrate the possible architecture, functions and operations of the system, method and computer program product according to various embodiments of the present application. Wherein, each box in the flowchart or block diagram can represent a module, a program segment, or a part of the code, and the above-mentioned module, program segment, or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order than the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0111] The units involved in the embodiments described in this application may be implemented by software or hardware, and the units described may also be set in a processor. The names of these units do not constitute limitations on the units themselves in some cases.
[0112] Another aspect of the present application further provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, the vehicle light control method as described above is implemented. The computer-readable storage medium may be included in the electronic device described in the above embodiment, or may exist independently without being assembled into the electronic device.
[0113] Another aspect of the present application also provides a computer program product or a computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the vehicle light control method provided in each of the above embodiments.
[0114] According to one aspect of an embodiment of the present application, a computer system is also provided, including a central processing unit (CPU), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) or a program loaded from a storage portion into a random access memory (RAM), such as executing the method in the above embodiment. In RAM, various programs and data required for system operation are also stored. CPU, ROM and RAM are connected to each other via a bus. An input / output (I / O) interface is also connected to the bus.
[0115] The following components are connected to the I / O interface: an input part including a keyboard, a mouse, etc.; an output part including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker; a storage part including a hard disk, etc.; and a communication part including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication part performs communication processing via a network such as the Internet. A drive is also connected to the I / O interface as needed. Removable media, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., are installed on the drive as needed so that the computer program read therefrom is installed into the storage part as needed.
[0116] The above content is only a preferred exemplary embodiment of the present application and is not intended to limit the implementation scheme of the present application. A person skilled in the art can easily make corresponding changes or modifications based on the main concept and spirit of the present application. Therefore, the scope of protection of the present application shall be based on the scope of protection required by the claims.
Claims
1. A business data processing method, It is characterized in that include: Get business request data; If the service request data represents a query type request, accessing a database to perform service processing based on the service request data; If the business request data represents a non-query request, the target aggregate root corresponding to the business request data is obtained, and business processing is performed based on the target business processing behavior corresponding to the target aggregate root. Different aggregate roots correspond to different business processing behaviors.
2. The method according to claim 1, It is characterized in that The target business processing behavior includes a target verification behavior and a target state change behavior; the business processing based on the target business processing behavior corresponding to the target aggregate root further includes: Verify the service request data based on the target verification behavior to obtain a verification result; If the verification result indicates that the verification has passed, the state data of the target business processing object in the target aggregate root is modified based on the target state change behavior.
3. The method according to claim 2, It is characterized in that The target business processing behavior includes an integrity check behavior, and the integrity check behavior includes at least one of a field non-null check, a data range check, and an association relationship check; After modifying the state data of the target business processing object in the target aggregate root based on the target state change behavior, the method further includes: Performing integrity check on the state data of the modified business processing object in the target aggregate root to obtain an integrity check result; If the integrity check result indicates that the integrity check has passed, the data in the database is updated based on the modified state data of the target business processing object.
4. The method according to claim 2, It is characterized in that The service request data represents that the target service processing object is modified to a first state; and the verifying the service request data based on the target verification behavior further includes: Verifying the format of the service request data; and / or, Performing a business logic check based on the second state of the target business processing object in the business request data and the first state; and / or, The authority of the business request data is verified.
5. The method according to claim 4, It is characterized in that The performing business logic verification based on the second state of the target business processing object in the business request data and the first state further includes: Checking whether the second state can be modified to the first state; If the second state can be modified to the first state, the business logic verification passes.
6. The method according to claim 4, It is characterized in that The checking of the authority of the service request data further includes: Obtaining a user ID of a sender of the service request data; Verifying whether the preset authority of the user identifier includes modifying the status data of the target business processing object; If included, the authority of the business request data is verified and passed.
7. The method according to claim 1, It is characterized in that The step of accessing a database to perform business processing based on the business request data further includes: Obtaining query indicators of the business request data; A data access interface is called, and data corresponding to the query index is searched in the database through the data access interface.
8. A business data processing device, It is characterized in that include: A business request data acquisition module, used to acquire business request data; A first business processing module, configured to access a database to perform business processing based on the business request data if the business request data represents a query type request; The second business processing module is used to obtain the target aggregate root corresponding to the business request data if the business request data represents a non-query request, and perform business processing based on the target business processing behavior corresponding to the target aggregate root. Different aggregate roots correspond to different business processing behaviors.
9. An electronic device, It is characterized in that include: Controller; A memory for storing one or more programs, which, when executed by a controller, enables the controller to implement the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, It is characterized in that Computer-readable instructions are stored thereon, and when the computer-readable instructions are executed by a processor of a computer, the computer is caused to execute the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Warehouse management modeling method and system based on domain-driven design
CN112668968A
Design method and device of electric power marketing domain model
CN114048641A
