Code generation method and device based on domain-driven design mode

By introducing a code generation method based on domain-driven design patterns into the code generation tool, the problem that existing tools generate code cannot meet development needs is solved, and efficient financial project development is achieved.

CN119396388APending Publication Date: 2025-02-07CHINA PING AN PROPERTY INSURANCE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411480202.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-22
Publication Date
2025-02-07

AI Technical Summary

Technical Problem

The existing code generation tools are not designed based on the domain-driven design pattern (DDD), which results in the automatic generated code not meeting the needs of developers, thereby reducing the development efficiency of financial projects.

Method used

A code generation method and device based on a domain-driven design pattern is provided, the method includes inputting code generation parameters through a visual interface, connecting to a database, obtaining target table information, and generating code files at each level that conform to the DDD pattern using a template engine.

Benefits of technology

The generated code conforms to the domain-driven design model, meets the needs of developers, improves the development efficiency of financial projects, and reduces the time for developers to manually write and debug duplicate code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119396388A_ABST
    Figure CN119396388A_ABST
Patent Text Reader

Abstract

The invention discloses a code generation method and device based on a domain-driven design mode, and aims to generate a code file based on the domain-driven design mode according to code generation parameters configured by developers, so that the time of manually writing repeated codes by the developers is shortened, and the development efficiency of financial projects is improved. The method comprises the steps that in response to a code generation instruction, code generation parameters input by a user based on a visual interface are determined; calling a database connection service based on a JDBC database connection or other database connections, wherein the database connection service is connected with a target database according to the database information; obtaining target table information in the target database according to the target table name, wherein the target table information comprises the target table name, a field name and a data type; and calling a template engine, and according to the code language and the code configuration information of each level, generating and storing a code file of each level corresponding to the domain-driven design mode.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of Internet technology, and in particular to a code generation method and device based on a domain-driven design pattern. Background Art

[0002] DDD (Domain-Driven Design) is a methodology that focuses on solving software modeling problems in complex business domains. DDD aims to help development teams better understand and cope with the complexity of business domains by building software architecture around business domains and introducing core concepts such as domain models, common languages, and bounded contexts. However, the implementation process of DDD is relatively difficult and requires the development team to have deep knowledge and experience in the business domain. In addition, the complex modeling process of DDD may lead to an increase in system complexity, code volume, and object conversion, thereby reducing the efficiency of financial project development.

[0003] In related technologies, in order to improve the efficiency of financial project development, developers usually focus their main efforts on the implementation of business logic, and rely on code generation tools to automatically generate non-core codes, thereby reducing the coding workload of developers.

[0004] In the process of implementing this application, the applicant found that the related technology has at least the following problems:

[0005] Existing code generation tools are not designed based on the DDD development model, so the automatically generated code cannot meet the needs of developers. This requires developers to make adaptive modifications to these automatically generated codes, which in turn leads to low efficiency and slow progress in financial project development. Summary of the invention

[0006] In view of this, the present application provides a code generation method and device based on the domain-driven design pattern, the main purpose of which is to solve the problem that the existing code generation tools are not designed based on the DDD development pattern, so the automatically generated code cannot meet the needs of developers. This requires developers to make adaptive modifications to these automatically generated codes, which in turn leads to the problem of low efficiency and slow progress in financial project development.

[0007] According to a first aspect of the present application, a code generation method based on a domain-driven design pattern is provided, the method comprising:

[0008] In response to a code generation instruction, determining code generation parameters input by a user based on a visual interface, wherein the code generation instruction is initiated based on a code generation button in the visual interface, and the code generation parameters include database information, target table name, code language, and code configuration information of each level corresponding to a domain-driven design pattern, wherein the levels corresponding to the domain-driven design pattern include an application interface layer, an application service layer, a domain layer, and an infrastructure layer;

[0009] Calling a database connection service based on a JDBC database connection or other database connection, wherein the database connection service connects to a target database according to the database information;

[0010] Acquire target table information in the target database according to the target table name, wherein the target table information includes the target table name, field name and data type;

[0011] The template engine is called, and based on the template engine and the code language, a code file of each level corresponding to the domain-driven design pattern is generated, and the code file of each level is stored according to the code configuration information of each level.

[0012] Optionally, before determining, in response to the code generation instruction, the code generation parameters input by the user based on the visual interface, the method further includes:

[0013] Constructing the visualization interface so that the user can input the database information, the target table name, the code language and the code configuration information of each level based on the visualization interface;

[0014] When it is detected that the user triggers a confirmation button based on the visual interface, a code generation instruction is generated.

[0015] Optionally, calling a database connection service based on a JDBC database connection or other database connection, wherein the database connection service connects to a target database according to the database information, includes:

[0016] Calling a database connection service based on a JDBC database connection or other database connection, wherein the database connection service connects to a target database according to a database address in the database information, and sends a user name and password in the database information to the target database for access verification;

[0017] If prompt information indicating that the access verification is passed is received, the target table name is sent to the target database to obtain target table information corresponding to the target table name;

[0018] If prompt information indicating that the access verification has not passed is received, first prompt information indicating that the database connection has failed is generated, and the first prompt information is displayed on the visual interface.

[0019] Optionally, if prompt information indicating that the access verification is passed is received, after sending the target table name to the target database to obtain target table information corresponding to the target table name, the method further includes:

[0020] If the target table information is obtained in the target database, the template engine is called to generate a code file of each level corresponding to the domain-driven design pattern based on the template engine;

[0021] If the target table information is not obtained in the target database, second prompt information for indicating that the table information acquisition fails is generated, and the second prompt information is displayed on the visualization interface.

[0022] Optionally, the calling of the template engine generates, based on the template engine and the code language, a code file of each level corresponding to the domain-driven design pattern, and stores the code file of each level according to the code configuration information of each level, including:

[0023] The code files at each level corresponding to the domain-driven design pattern include application interface layer code files, application service layer code files, domain layer code files, and infrastructure layer code files;

[0024] Calling a template engine so that the template engine adopts the code language, and generates a domain object code file, a persistent object code file, a repository interface code file, and a mapper interface code file respectively according to the target table information, so as to obtain the domain layer code file and the infrastructure layer code file, and determining the first configuration information corresponding to the domain layer code file and the second configuration information corresponding to the infrastructure layer code file in the code configuration information of each level, adding a suffix to the object and / or class in the domain layer code file according to the suffix information in the first configuration information, adding a suffix to the object and / or class in the infrastructure layer code file according to the suffix information in the second configuration information, storing the domain layer code file according to the storage path information in the first configuration information, and storing the infrastructure layer code file according to the storage path information in the second configuration information;

[0025] The template engine is called to make the template engine determine a plurality of predefined code templates according to the code language, and based on the plurality of predefined code templates, the target table information and the configuration information, generate and store the application interface layer code file and the application service layer code file.

[0026] Optionally, calling a template engine so that the template engine determines a plurality of predefined code templates according to the code language, and generates and stores the application interface layer code file and the application service layer code file based on the plurality of predefined code templates, the target table information and the configuration information, comprises:

[0027] Calling a template engine, so that the template engine determines a plurality of predefined code templates according to the code language, and updates each of the predefined code templates using the target table name, the field name, and the data type in the target table information, to obtain a plurality of code files to be configured, wherein the plurality of code files to be configured include an application interface layer code file to be configured and an application service layer code file to be configured;

[0028] Call the template engine to enable the template engine to determine the third configuration information corresponding to the application interface layer code file and the fourth configuration information corresponding to the application service layer code file in the code configuration information of each layer, fill in the variables in the application interface layer code file to be configured according to the third configuration information, fill in the variables in the application service layer code file to be configured according to the fourth configuration information, obtain the application interface layer code file and the application service layer code file and store them.

[0029] Optionally, after the target table information and the code configuration information of each level are used to generate and store the code files of each level corresponding to the domain-driven design pattern, the method further includes:

[0030] Based on the log framework, the generation process of the code file of each level corresponding to the domain-driven design pattern is recorded to obtain a code generation log, and the code generation log is stored in the corresponding storage space according to the preset storage rules.

[0031] According to a second aspect of the present application, a code generation device based on a domain-driven design pattern is provided, the device comprising:

[0032] A determination module, configured to determine, in response to a code generation instruction, code generation parameters input by a user based on a visual interface, wherein the code generation instruction is initiated based on a code generation button in the visual interface, and the code generation parameters include database information, a target table name, a code language, and code configuration information of each level corresponding to a domain-driven design pattern, wherein the levels corresponding to the domain-driven design pattern include an application interface layer, an application service layer, a domain layer, and an infrastructure layer;

[0033] A connection module, used to call a database connection service based on a JDBC database connection or other database connection, wherein the database connection service connects to a target database according to the database information;

[0034] An acquisition module, used for acquiring target table information in the target database according to the target table name, wherein the target table information includes the target table name, field name and data type;

[0035] The calling module is used to call the template engine, generate the code files of each level corresponding to the domain-driven design pattern based on the template engine and the code language, and store the code files of each level according to the code configuration information of each level.

[0036] Optionally, the device further comprises:

[0037] A generating module, used for constructing the visual interface, so that the user can input the database information, the target table name, the code language and the code configuration information of each level based on the visual interface;

[0038] The identification module is used to generate a code generation instruction when it is detected that the user triggers the confirmation button based on the visual interface.

[0039] Optionally, the connection module is used to call a database connection service based on a JDBC database connection or other database connection, and the database connection service connects to a target database according to a database address in the database information, and sends a user name and password in the database information to the target database for access verification; if a prompt message indicating that the access verification is successful is received, the target table name is sent to the target database to obtain target table information corresponding to the target table name; if a prompt message indicating that the access verification is unsuccessful is received, a first prompt message is generated to indicate that the database connection has failed, and the first prompt message is displayed on the visual interface.

[0040] Optionally, the connection module is also used to call the template engine if the target table information is obtained in the target database, and generate a code file for each level corresponding to the domain-driven design pattern based on the template engine; if the target table information is not obtained in the target database, generate a second prompt information indicating that the table information acquisition failed, and display the second prompt information on the visual interface.

[0041] Optionally, the calling module is used to call the template engine so that the template engine adopts the code language to generate domain object code files, persistent object code files, repository interface code files and mapper interface code files respectively according to the target table information based on the code files of each level corresponding to the domain-driven design pattern, and obtain the domain layer code files and the infrastructure layer code files, and determine the first configuration information corresponding to the domain layer code files and the second configuration information corresponding to the infrastructure layer code files in the code configuration information of each level. The method comprises the steps of: adding a suffix to objects and / or classes in the domain layer code file according to the suffix information in the first configuration information, adding a suffix to objects and / or classes in the infrastructure layer code file according to the suffix information in the second configuration information, storing the domain layer code file according to the storage path information in the first configuration information, and storing the infrastructure layer code file according to the storage path information in the second configuration information; calling a template engine so that the template engine determines a plurality of predefined code templates according to the code language, and generates and stores the application interface layer code file and the application service layer code file based on the plurality of predefined code templates, the target table information and the configuration information.

[0042] Optionally, the calling module is used to call the template engine so that the template engine determines multiple predefined code templates according to the code language, updates each of the predefined code templates using the target table name, the field name and the data type in the target table information, and obtains multiple code files to be configured, wherein the multiple code files to be configured include application interface layer code files to be configured and application service layer code files to be configured; calls the template engine so that the template engine determines third configuration information corresponding to the application interface layer code files and fourth configuration information corresponding to the application service layer code files in the code configuration information of each level, fills in variables in the application interface layer code files to be configured according to the third configuration information, fills in variables in the application service layer code files to be configured according to the fourth configuration information, obtains the application interface layer code files and the application service layer code files and stores them.

[0043] Optionally, the device further comprises:

[0044] A recording module is used to record the generation process of the code file of each level corresponding to the domain-driven design pattern based on a log framework, obtain a code generation log, and store the code generation log in a corresponding storage space according to a preset storage rule.

[0045] According to a third aspect of the present application, a computer device is provided, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of any one of the methods described in the first aspect when executing the computer program.

[0046] According to a fourth aspect of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of any one of the methods described in the first aspect are implemented.

[0047] By means of the above technical scheme, the present application provides a code generation method and device based on a domain-driven design pattern. In the present application, the user can trigger the code generation button based on the visual interface, send the code generation instruction to the code generation system, and the code generation system responds to the code generation instruction to determine the code generation parameters input by the user based on the visual interface, wherein the code generation parameters include database information, target table name, code language, and code configuration information of each level corresponding to the domain-driven design pattern, and the level corresponding to the domain-driven design pattern includes application interface layer, application service layer, domain layer, and infrastructure layer. Next, the code generation system calls the database connection service based on the JDBC database connection or other database connection, and the database connection service connects to the target database according to the database information. Further, the target table name, field name, and data type in the target database are obtained as the target table information according to the target table name. Finally, the code generation system calls the template engine, and generates and stores the code files of each level corresponding to the domain-driven design pattern according to the code language and the code configuration information of each level. In large-scale financial projects, the development of projects usually needs to follow strict industry standards and best practices. The hierarchical structure of the domain-driven design pattern ensures the standardization and modularization of the code, which is easy to maintain and upgrade. On this basis, the embodiment of the present application enables developers to quickly configure code generation parameters through a visual interface, and then generate code files for each level corresponding to the domain-driven design pattern based on the code generation parameters configured by the developer, reducing the time for developers to manually write and debug repetitive code, allowing developers to focus more on code development of core functions, thereby improving the development efficiency of the overall financial project.

[0048] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means 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 present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present application. Also, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:

[0050] Figure 1 A schematic diagram of a code generation method based on a domain-driven design pattern provided in an embodiment of the present application is shown;

[0051] Figure 2 A schematic diagram of a visual interface of a code generation method based on a domain-driven design pattern provided in an embodiment of the present application is shown;

[0052] Figure 3 A schematic diagram of the structure of a code generation device based on a domain-driven design pattern provided in an embodiment of the present application is shown;

[0053] Figure 4 A schematic diagram of the device structure of a computer device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION

[0054] The exemplary embodiments of the present application will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present application are shown in the accompanying drawings, it should be understood that the present application can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present application and to fully convey the scope of the present application to those skilled in the art.

[0055] Domain-Driven Design (DDD) is a software design methodology that focuses on solving modeling and implementation problems in complex business domains. The core idea of ​​DDD is to take the business domain as the core of the design and integrate the concepts and rules of the business domain into the software system to meet business needs. DDD usually adopts a four-layer architecture, including the application interface layer, application service layer, domain layer and infrastructure layer. Among them, the application interface layer is used to provide services to the outside; the application service layer contains application services, which are responsible for use case process scheduling and transaction control; the domain layer contains domain objects and domain services, which are used to focus on core business; the infrastructure layer is used to provide data persistence, anti-corrosion layer implementation, third-party libraries, messages and other content. DDD requires each subdomain to have high cohesion and low coupling, and the external interface is implemented through the anti-corrosion layer and adapter. The scenario of applying DDD is mainly used to solve complex business problems, and its main benefits are reflected in the later demand upgrade and code maintenance. However, the application of DDD will increase the complexity of the software system, the amount of code and the complexity of object conversion, which will lead to a decrease in short-term development efficiency. At present, in order to improve development efficiency and allow developers to focus their main efforts on the implementation of financial business logic, developers usually use code generation tools to automatically generate some non-core codes to reduce the coding workload of developers. However, the applicant recognizes that the existing commonly used code generation tools only support the Java language and are not based on the DDD development model, and cannot fully meet the needs of this scenario. Therefore, the embodiment of the present application provides a code generation method based on the domain-driven design pattern, such as Figure 1 As shown, the method includes:

[0056] 101. In response to a code generation instruction, determine code generation parameters input by a user based on a visual interface, wherein the code generation instruction is initiated based on a code generation button in the visual interface, and the code generation parameters include database information, target table name, code language, and code configuration information for each level corresponding to a domain-driven design pattern, and the levels corresponding to the domain-driven design pattern include an application interface layer, an application service layer, a domain layer, and an infrastructure layer.

[0057] This application designs a code generation plug-in that can automatically generate DDD code. The code generation plug-in is tightly integrated with IntelliJ IDEA, allowing developers to directly use the code generation plug-in in a familiar environment to automatically generate code files, reducing the learning cost. The code generation plug-in provides an intuitive and easy-to-use visual interface, based on which users can enter code generation parameters. In actual application, the visual interface is as follows: Figure 2As shown in the figure, users can enter database information, target table name, code language and code configuration information for each level corresponding to the domain-driven design pattern in the visual interface according to the prompts. When the user clicks the confirmation button (GenerateCode), the visual interface will generate code generation instructions, and this information will be carried by the code generation instructions and passed to the code generation system. It should be noted that Figure 2 As shown, the code language needs to be selected by the developer according to the project needs and team requirements. This application provides two code languages: Java and Go. Figure 2 As shown, the code configuration information of each layer is different. Developers can input according to the prompt information to avoid code generation failure due to parameter omission. For example, the application interface layer needs to enter the package path, controller name, DTO name and converter name, the application service layer needs to enter the package path and service name, the domain layer needs to enter the package path, VO name, domain service name, repository interface and converter name, and the infrastructure layer needs to enter the package path, mapper name and PO name.

[0058] 102. Based on the JDBC database connection or other database connection, the database connection service is called, and the database connection service connects to the target database according to the database information.

[0059] In this step, the code generation plug-in first reads the database information and obtains the database address of the target database and the credentials for accessing the database, i.e., the user name and password. The code generation system calls the data connection service to make a connection request to the database address. Specifically, the database connection service can be called based on JDBC database connection or other database connection to make a connection request to the database address. After successfully establishing a network connection with the target database through the database connection service, the code generation system sends the user name and password as identity credentials to the target database so that the target database can confirm whether the user has access rights through an internal verification mechanism.

[0060] First, the database connection service is called based on the JDBC database connection or other database connection, and the database connection service connects to the target database according to the database address in the database information. Specifically, the code generation plug-in first initializes the JDBC database connection or other database connection. For example, the project currently being developed is an online banking system. Many functions in the online banking system need to connect to the database of user information, and subsequent operations are performed through the obtained user account information. If the target database storing user information is a MySQL database, the system will load com.mysql.cj.jdbc.Driver for initialization. Further, the database information entered by the user in the visual interface is obtained, such as database address: jdbc:mysql: / / db.example.com:3306 / bank, user name: bank_user, password: !123. Next, a connection request is sent to the database server of the target database according to the database address in the database information, and the server's response is waited for to confirm whether the connection is successful.

[0061] Subsequently, the user name and password in the database information are sent to the target database for access verification. Specifically, after successfully establishing a connection with the target database, the code generation plug-in sends the user input user name "bank_user" and password "!123" to the target database through the JDBC connection object. After receiving the user name "bank_user" and password "!123", the target database uses its internal authentication mechanism such as the SHA-512 encryption algorithm to verify the user name and password. If the user name and password are correct, the target database will return a prompt message indicating that the access verification has passed, and then execute the following step S23. If the user name or password is incorrect, the target database will return a prompt message indicating that the access verification has not passed, and then execute the following step S24.

[0062] Finally, if a prompt message indicating that the access verification has passed is received, the target table name is sent to the target database to obtain the target table information corresponding to the target table name. Specifically, after receiving the prompt message indicating that the access verification has passed, the code generation plug-in sends the target table name entered by the user, such as user_accounts, to the target database, and requests to obtain the target table information of the table. It should be noted that the target table information includes the target table name, field name and data type. If a prompt message indicating that the access verification has not passed is received, a first prompt message is generated to indicate that the database connection has failed, and the first prompt message is displayed on the visual interface. Specifically, after receiving the prompt message indicating that the access verification has not passed, the code generation plug-in generates the first prompt message. During the actual operation process, the content of the first prompt message can be "Database connection failed: User name or password is incorrect." Etc. This application does not specifically limit the content of the first prompt message. Then, the first prompt message is displayed on the visual interface to inform the user that the information entered is incorrect and the user name and password need to be rechecked.

[0063] 103. Obtain target table information in the target database according to the target table name, where the target table information includes the target table name, field name, and data type.

[0064] Furthermore, the code generation plug-in can use an SQL query statement to send a query request to the target database, and the query request carries the target table name entered by the user. If the target database queries the corresponding target table information according to the target table name, the target table information is passed to the code generation system, and the code generation system calls the template engine to generate a code file for each level corresponding to the domain-driven design pattern based on the template engine. It should be noted that the target table information includes the target table name, field name and data type. For example, the information of the user_accounts table is returned from the database, and the return result may include the following content target table name: user_accounts, field name: balance, data type: DECIMAL (10, 2), indicating the balance of the user account. If the target database does not query the corresponding target table information according to the target table name, the target database will pass a prompt message indicating that the target has not been queried to the code generation system, and then the code generation system generates a second prompt message for indicating that the table information failed to be obtained. The content in the second prompt message may be "Failed to obtain the label information: the target table name is wrong." And so on. This application does not specifically limit the content of the second prompt message. Then, the second prompt information is displayed in the visual interface, informing the user that the information entered is incorrect and the target table name needs to be rechecked. For example, a developer tries to obtain the structural information of a bank account table to generate code. The code generation system sends a data query request to the target database by executing an SQL query. If the query is successful, the underlying code file is generated based on the obtained target table information. If the query fails, the code generation system will promptly generate the corresponding second prompt information and feedback it to the user in the visual interface to ensure that the user understands the problem and makes appropriate adjustments.

[0065] 104. Call the template engine to generate and store the code files of each level corresponding to the domain-driven design pattern according to the code language and the code configuration information of each level.

[0066] In order to adapt to the needs of different projects and teams, the code generation plug-in provided in this application can generate code files in Java language and code files in Go language. However, considering the large grammatical differences between different code languages, the generated code files must conform to the grammatical rules and structure of the specific language. Developers also need to select the required code language in the visual interface provided by the code generation plug-in. It should be noted that the code files of each level corresponding to the domain-driven design pattern include application interface layer code files, application service layer code files, domain layer code files and infrastructure layer code files. The template engine can be a FreeMarker engine or a Velocity engine.

[0067] 1. Generate and store domain layer code files and infrastructure layer code files.

[0068] In an embodiment of the present application, the code generation system calls the template engine, uses the code language selected by the developer, and replaces the variables in different code templates according to the target table information to obtain domain object code files, persistent object code files, Repository interface code files, and Mapper interface code files, which are domain layer code files and infrastructure layer code files. Furthermore, the first configuration information corresponding to the domain layer code file and the second configuration information corresponding to the infrastructure layer code file are determined in the code configuration information of each level. In the actual operation process, the first configuration information includes the package path, VO name, domain service name, repository interface, and converter name, and the second configuration information includes the package path, mapper name, and PO name. According to the suffix information in the first configuration information, i.e., the VO name, domain service name, repository interface and converter name, add suffixes to the objects and / or classes in the domain layer code file; according to the suffix information in the second configuration information, i.e., the mapper name and PO name, add suffixes to the objects and / or classes in the infrastructure layer code file; according to the storage path information in the first configuration information, i.e., the package path, the domain layer code files are stored; according to the storage path information in the second configuration information, i.e., the package path, the infrastructure layer code files are stored.

[0069] 2. Generate and store application interface layer code files and application service layer code files.

[0070] In an embodiment of the present application, the code generation system calls a template engine, determines multiple predefined code templates according to the code language, and generates and stores application interface layer code files and application service layer code files based on multiple predefined code templates, target table information and configuration information.

[0071] Specifically, the template engine is called, and multiple predefined code templates associated with the code language selected by the developer are determined, and the target table name, field name and data type in the target table information are used to update each predefined code template to obtain multiple code files to be configured, and the multiple code files to be configured include the application interface layer code files to be configured and the application service layer code files to be configured. Subsequently, the template engine is called to determine the third configuration information corresponding to the application interface layer code files and the fourth configuration information corresponding to the application service layer code files in the code configuration information of each level. In the actual operation process, the third configuration information is the package path, controller name, DTO name and converter name, and the fourth configuration information is the package path and service name. Fill in the variables in the application interface layer code files to be configured according to the third configuration information, and fill in the variables in the application service layer code files to be configured according to the fourth configuration information. Variables are placeholders in the code files to be configured, that is, the application interface layer code files and the application service layer code files can be obtained and stored by replacing the corresponding placeholders with configuration information.

[0072] It should be noted that after generating the code files at each level corresponding to the domain-driven design pattern, the generation process of the code files at each level corresponding to the domain-driven design pattern can also be recorded based on the log framework to obtain the code generation log, and the code generation log is stored in the corresponding storage space according to the preset storage rules. The log file records the detailed process and operation of each code file generation, including the generation time, generation content, operator, etc., thereby improving the transparency and traceability of system operations. Provide support for subsequent system maintenance, code auditing, and troubleshooting.

[0073] The method provided in the embodiment of the present application is that the user can trigger the code generation button based on the visual interface, send the code generation instruction to the code generation system, and the code generation system responds to the code generation instruction to determine the code generation parameters input by the user based on the visual interface, wherein the code generation parameters include database information, target table name, code language and code configuration information of each level corresponding to the domain-driven design pattern, and the level corresponding to the domain-driven design pattern includes application interface layer, application service layer, domain layer and infrastructure layer. Next, the code generation system calls the database connection service based on the JDBC database connection or other database connection, and the database connection service connects to the target database according to the database information. Further, the target table name, field name and data type in the target database are obtained as the target table information according to the target table name. Finally, the code generation system calls the template engine, and generates and stores the code files of each level corresponding to the domain-driven design pattern according to the code language and the code configuration information of each level. In large-scale financial projects, the development of projects usually needs to follow strict industry standards and best practices. The hierarchical structure of the domain-driven design pattern ensures the standardization and modularization of the code, which is easy to maintain and upgrade. On this basis, the embodiment of the present application enables developers to quickly configure code generation parameters through a visual interface, and then generate code files for each level corresponding to the domain-driven design pattern based on the code generation parameters configured by the developer, reducing the time for developers to manually write and debug repetitive code, allowing developers to focus more on code development of core functions, thereby improving the development efficiency of the overall financial project.

[0074] Further, as Figure 1 The specific implementation of the method, the embodiment of the present application provides a code generation device based on the domain driven design pattern, such as Figure 3 As shown, the device includes: a determination module 301, a connection module 302, an acquisition module 303, and a calling module 304.

[0075] The determination module 301 is used to determine, in response to a code generation instruction, code generation parameters input by a user based on a visual interface, wherein the code generation instruction is initiated based on a code generation button in the visual interface, and the code generation parameters include database information, target table name, code language, and code configuration information of each level corresponding to a domain-driven design pattern, wherein the levels corresponding to the domain-driven design pattern include an application interface layer, an application service layer, a domain layer, and an infrastructure layer;

[0076] The connection module 302 is used to call a database connection service based on a JDBC database connection or other database connection, and the database connection service connects to a target database according to the database information;

[0077] The acquisition module 303 is used to acquire the target table information in the target database according to the target table name, wherein the target table information includes the target table name, field name and data type;

[0078] The calling module 304 is used to call the template engine, generate a code file of each level corresponding to the domain-driven design pattern based on the template engine and the code language, and store the code file of each level according to the code configuration information of each level.

[0079] In a specific application scenario, the device further includes: a generation module 405 and an identification module 406 .

[0080] The generating module 305 is used to construct the visual interface so that the user can input the database information, the target table name, the code language and the code configuration information of each level based on the visual interface;

[0081] The identification module 306 is used to generate a code generation instruction when it is detected that the user triggers the confirmation button based on the visual interface.

[0082] In a specific application scenario, the connection module 302 is used to call a database connection service based on a JDBC database connection or other database connection. The database connection service connects to a target database according to a database address in the database information, and sends a user name and password in the database information to the target database for access verification. If a prompt message indicating that the access verification is successful is received, the target table name is sent to the target database to obtain the target table information corresponding to the target table name. If a prompt message indicating that the access verification is unsuccessful is received, a first prompt message indicating that the database connection has failed is generated, and the first prompt message is displayed on the visual interface.

[0083] In a specific application scenario, the connection module 302 is also used to call the template engine if the target table information is obtained in the target database, and generate a code file for each level corresponding to the domain-driven design pattern based on the template engine; if the target table information is not obtained in the target database, generate a second prompt information indicating that the table information acquisition failed, and display the second prompt information on the visual interface.

[0084] In a specific application scenario, the calling module 304 is used to call the template engine so that the template engine adopts the code language to generate the domain object code file, the persistent object code file, the repository interface code file and the mapper interface code file according to the target table information, obtain the domain layer code file and the infrastructure layer code file, and determine the first configuration information corresponding to the domain layer code file and the first configuration information corresponding to the infrastructure layer code file in the code configuration information of each level. the second configuration information, adding a suffix to the objects and / or classes in the domain layer code file according to the suffix information in the first configuration information, adding a suffix to the objects and / or classes in the infrastructure layer code file according to the suffix information in the second configuration information, storing the domain layer code file according to the storage path information in the first configuration information, and storing the infrastructure layer code file according to the storage path information in the second configuration information; calling a template engine so that the template engine determines a plurality of predefined code templates according to the code language, and generates and stores the application interface layer code file and the application service layer code file based on the plurality of predefined code templates, the target table information and the configuration information.

[0085] In a specific application scenario, the calling module 304 is used to call the template engine so that the template engine determines multiple predefined code templates according to the code language, and uses the target table name, the field name and the data type in the target table information to update each of the predefined code templates to obtain multiple code files to be configured, and the multiple code files to be configured include application interface layer code files to be configured and application service layer code files to be configured; call the template engine so that the template engine determines the third configuration information corresponding to the application interface layer code file and the fourth configuration information corresponding to the application service layer code file in the code configuration information of each level, fills the variables in the application interface layer code file to be configured according to the third configuration information, and fills the variables in the application service layer code file to be configured according to the fourth configuration information, and obtains and stores the application interface layer code file and the application service layer code file.

[0086] In a specific application scenario, the device further includes: a recording module 307 .

[0087] The recording module 307 is used to record the generation process of the code file of each level corresponding to the domain-driven design pattern based on the log framework, obtain the code generation log, and store the code generation log in the corresponding storage space according to the preset storage rules.

[0088] It should be noted that for other corresponding descriptions of the functional units involved in the code generation device based on the domain-driven design pattern provided in the embodiment of the present application, please refer to Figure 1 to Figure 2 The corresponding description in will not be repeated here.

[0089] In an exemplary embodiment, see Figure 4 , and also provides a device, which includes a communication bus, a processor, a memory and a communication interface, and may also include an input and output interface and a display device, wherein each functional unit can communicate with each other through the bus. The memory stores a computer program, and the processor is used to execute the program stored in the memory and execute the code generation method based on the domain-driven design pattern in the above embodiment.

[0090] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of the code generation method based on a domain-driven design pattern.

[0091] Through the description of the above implementation methods, those skilled in the art can clearly understand that the present application can be implemented by hardware, or by means of software plus a necessary general hardware platform. Based on such an understanding, the technical solution of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.), including a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each implementation scenario of the present application.

[0092] Those skilled in the art will appreciate that the accompanying drawings are merely schematic diagrams of a preferred implementation scenario, and the modules or processes in the accompanying drawings are not necessarily required for implementing the present application.

[0093] Those skilled in the art will appreciate that the modules in the device in the implementation scenario can be distributed in the device in the implementation scenario according to the implementation scenario description, or can be changed accordingly and located in one or more devices different from the implementation scenario. The modules in the above implementation scenario can be combined into one module, or can be further split into multiple sub-modules.

[0094] The above application serial numbers are for description only and do not represent the advantages or disadvantages of the implementation scenarios.

[0095] The above disclosure only discloses several specific implementation scenarios of the present application. However, the present application is not limited thereto, and any changes that can be conceived by technicians in this field should fall within the scope of protection of the present application.

Claims

1. A code generation method based on domain-driven design pattern, characterized in that: include: In response to a code generation instruction, determining code generation parameters input by a user based on a visual interface, wherein the code generation instruction is initiated based on a code generation button in the visual interface, and the code generation parameters include database information, target table name, code language, and code configuration information of each level corresponding to a domain-driven design pattern, wherein the levels corresponding to the domain-driven design pattern include an application interface layer, an application service layer, a domain layer, and an infrastructure layer; Calling a database connection service based on a JDBC database connection or other database connection, wherein the database connection service connects to a target database according to the database information; Acquire target table information in the target database according to the target table name, wherein the target table information includes the target table name, field name and data type; The template engine is called to generate and store code files of each level corresponding to the domain-driven design pattern according to the code language and the code configuration information of each level.

2. The method according to claim 1, characterized in that Before determining, in response to the code generation instruction, the code generation parameters input by the user based on the visual interface, the method further includes: Constructing the visualization interface so that the user can input the database information, the target table name, the code language and the code configuration information of each level based on the visualization interface; When it is detected that the user triggers a confirmation button based on the visual interface, a code generation instruction is generated.

3. The method according to claim 1, characterized in that The calling of the database connection service based on the JDBC database connection or other database connection, wherein the database connection service connects to the target database according to the database information, includes: Calling a database connection service based on a JDBC database connection or other database connection, wherein the database connection service connects to a target database according to a database address in the database information, and sends a user name and password in the database information to the target database for access verification; If prompt information indicating that the access verification is passed is received, the target table name is sent to the target database to obtain target table information corresponding to the target table name; If prompt information indicating that the access verification has not passed is received, first prompt information indicating that the database connection has failed is generated, and the first prompt information is displayed on the visual interface.

4. The method according to claim 3, characterized in that: If prompt information indicating that the access verification is passed is received, after sending the target table name to the target database to obtain target table information corresponding to the target table name, the method further includes: If the target table information is obtained in the target database, the template engine is called to generate a code file of each level corresponding to the domain-driven design pattern based on the template engine; If the target table information is not obtained in the target database, second prompt information for indicating that the table information acquisition fails is generated, and the second prompt information is displayed on the visualization interface.

5. The method according to claim 1, characterized in that The calling template engine generates and stores the code files of each level corresponding to the domain-driven design pattern according to the code language and the code configuration information of each level, including: The code files at each level corresponding to the domain-driven design pattern include application interface layer code files, application service layer code files, domain layer code files, and infrastructure layer code files; Calling a template engine so that the template engine adopts the code language, and generates a domain object code file, a persistent object code file, a repository interface code file, and a mapper interface code file respectively according to the target table information, so as to obtain the domain layer code file and the infrastructure layer code file, and determining the first configuration information corresponding to the domain layer code file and the second configuration information corresponding to the infrastructure layer code file in the code configuration information of each level, adding a suffix to the object and / or class in the domain layer code file according to the suffix information in the first configuration information, adding a suffix to the object and / or class in the infrastructure layer code file according to the suffix information in the second configuration information, storing the domain layer code file according to the storage path information in the first configuration information, and storing the infrastructure layer code file according to the storage path information in the second configuration information; The template engine is called to make the template engine determine a plurality of predefined code templates according to the code language, and based on the plurality of predefined code templates, the target table information and the configuration information, generate and store the application interface layer code file and the application service layer code file.

6. The method according to claim 5, characterized in that The calling of the template engine so that the template engine determines a plurality of predefined code templates according to the code language, and generates and stores the application interface layer code file and the application service layer code file based on the plurality of predefined code templates, the target table information and the configuration information, including: Calling a template engine, so that the template engine determines a plurality of predefined code templates according to the code language, and updates each of the predefined code templates using the target table name, the field name, and the data type in the target table information, to obtain a plurality of code files to be configured, wherein the plurality of code files to be configured include an application interface layer code file to be configured and an application service layer code file to be configured; Call the template engine to enable the template engine to determine the third configuration information corresponding to the application interface layer code file and the fourth configuration information corresponding to the application service layer code file in the code configuration information of each layer, fill in the variables in the application interface layer code file to be configured according to the third configuration information, fill in the variables in the application service layer code file to be configured according to the fourth configuration information, obtain the application interface layer code file and the application service layer code file and store them.

7. The method according to claim 1, characterized in that After the target table information and the code configuration information of each level are used to generate and store the code files of each level corresponding to the domain-driven design pattern, the method further includes: Based on the log framework, the generation process of the code file of each level corresponding to the domain-driven design pattern is recorded to obtain a code generation log, and the code generation log is stored in the corresponding storage space according to the preset storage rules.

8. A code generation device based on a domain-driven design pattern, characterized in that: include: A determination module, configured to determine, in response to a code generation instruction, code generation parameters input by a user based on a visual interface, wherein the code generation instruction is initiated based on a code generation button in the visual interface, and the code generation parameters include database information, a target table name, a code language, and code configuration information of each level corresponding to a domain-driven design pattern, wherein the levels corresponding to the domain-driven design pattern include an application interface layer, an application service layer, a domain layer, and an infrastructure layer; A connection module, used to call a database connection service based on a JDBC database connection or other database connection, wherein the database connection service connects to a target database according to the database information; An acquisition module, used for acquiring target table information in the target database according to the target table name, wherein the target table information includes the target table name, field name and data type; The calling module is used to call the template engine to generate and store the code files of each level corresponding to the domain-driven design pattern according to the code language and the code configuration information of each level.

9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.