Code generation method and device

By obtaining the target business model in the target business scenario and using the code engineering scaffolding to generate relevant code and service configuration files, the problem that code generation in the existing technology cannot fully meet business needs is solved, and an efficient and flexible code generation process is achieved.

CN119415101APending Publication Date: 2025-02-11SICHUAN RURAL COMMERCIAL UNITED BANK CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411433633.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-14
Publication Date
2025-02-11

AI Technical Summary

Technical Problem

When generating code, the existing technology cannot fully meet business needs, and developers still need to carry out a lot of manual coding, which affects the progress of software development.

Method used

By obtaining the target business model in the target business scenario, using pre-set code engineering scaffolding to generate the initial source code and business service level code in the microservice architecture, and generate the associated service configuration files based on these codes, and finally the code and service are used to generate the code and service. The configuration file is encapsulated into the initial source code to generate target source code that meets the target business model.

Benefits of technology

Simplifies the process of generating target source code, avoids a large number of complex and repetitive code encoding work, improves the efficiency of converting business models into code, and realizes adaptability to the code through the modification of service configuration files, and meets the new Business requirements.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119415101A_ABST
    Figure CN119415101A_ABST
Patent Text Reader

Abstract

The invention provides a code generation method and device, and the method comprises the steps: obtaining a target business model in a target business scene; based on the target business model, generating an initial source code and a code of a business service level in the micro-service architecture through a preset code engineering scaffold; generating a service configuration file associated with the code of the business service level according to the code of the business service level in the micro-service architecture; according to the method, the code of the business service level in the micro-service architecture and the service configuration file are packaged into the initial source code to determine the target source code for satisfying the target business model, so that complex analysis is not needed in a code generation project, and the code generation efficiency is improved. In this way, various data contained in the target business model can be mapped to the corresponding business service levels respectively, the process of generating the target source code is simplified, and a large amount of complex and repeated code coding work is avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to a code generation method and device. Background Art

[0002] At present, in order to reduce software development costs, business requirements can be converted to generate code. Usually, business requirements are converted through design models (such as Unified Modeling Language) to generate program code. However, the code generated by this method can generally only generate basic interfaces and classes, which cannot fully meet business needs. Developers still need to do a lot of manual coding work, and they also need to modify, test and integrate in the target business scenarios, which results in a lot of complex and tedious development work, affecting the progress of software development. Summary of the invention

[0003] The present disclosure provides a code generation method and device to solve one of the technical problems in the related art at least to a certain extent. The technical solution of the present disclosure is as follows:

[0004] According to a first aspect of an embodiment of the present disclosure, a code generation method is provided, comprising: obtaining a target business model in a target business scenario; based on the target business model, generating initial source code and code at a business service level in a microservice architecture through a pre-set code engineering scaffold; generating a service configuration file associated with the code at the business service level in the microservice architecture according to the code at the business service level in the microservice architecture, wherein the service configuration file is used to represent a file loaded when executing the code at the business service level in the microservice architecture; encapsulating the code at the business service level in the microservice architecture and the service configuration file into the initial source code to determine an executable target source code for satisfying the target business model.

[0005] According to a second aspect of an embodiment of the present disclosure, a code generation device is provided, comprising: a first acquisition module, used to acquire a target business model under a target business scenario; a first generation module, used to generate, based on the target business model, an initial source code and a code at a business service level in a microservice architecture through a pre-set code engineering scaffold; a second generation module, used to generate, based on the code at the business service level in the microservice architecture, a service configuration file associated with the code at the business service level, wherein the service configuration file is used to represent a file loaded when executing the code at the business service level in the microservice architecture; a first determination module, used to encapsulate the code at the business service level in the microservice architecture and the service configuration file into the initial source code, so as to determine an executable target source code for satisfying the target business model.

[0006] According to a third aspect of an embodiment of the present disclosure, an electronic device is provided, comprising: a processor; and a memory for storing instructions executable by the processor; wherein the processor is configured to execute the instructions to implement the code generation method as described in the embodiment of the first aspect of the present disclosure.

[0007] According to a fourth aspect of an embodiment of the present disclosure, a computer-readable storage medium is provided. When instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the code generation method as described in the embodiment of the first aspect of the present disclosure.

[0008] According to a fifth aspect of an embodiment of the present disclosure, a computer program product is provided, including: a computer program, wherein when the computer program is executed by a processor, the code generation method as described in the embodiment of the first aspect of the present disclosure is implemented.

[0009] The technical solution provided by the embodiments of the present disclosure brings at least the following beneficial effects:

[0010] In this technical solution, a target business model under a target business scenario is obtained; based on the target business model, an initial source code and a code at the business service level in a microservice architecture are generated through a pre-set code engineering scaffolding; a service configuration file associated with the code at the business service level in the microservice architecture is generated according to the code at the business service level in the microservice architecture, wherein the service configuration file is used to represent a file loaded when the code at the business service level in the microservice architecture is executed; the code at the business service level in the microservice architecture and the service configuration file are encapsulated into the initial source code to determine an executable target source code for satisfying the target business model; thereby, based on the target business model, a pre-set code engineering scaffolding is used to generate a service configuration file associated with the code at the business service level Since the code engineering scaffolding includes various mapping relationships between the target business model and the business service level in the microservice architecture, in the code generation project, various data contained in the target business model can be mapped to the corresponding business service level without complex analysis, which simplifies the process of generating the target source code and avoids a lot of complex and repetitive code coding work. In addition, through the code engineering scaffolding, various data contained in the target business model can be fully and fully converted into business service level code, so as to generate the target source code that meets the business model and improve the efficiency of converting the business model into code; wherein, according to the code of the business service level in the microservice architecture, the business service level is generated. The service configuration file associated with the code is used to represent the file loaded when executing the code of the business service layer in the microservice architecture. When the microservice architecture is started, the code of the business service layer is executed by loading the service configuration file. When the current business needs change, directly modifying the code of the business service layer will cause inconsistencies between the code and the business model, and it will be difficult to maintain and modify it later. By modifying the service configuration file, the adaptive adjustment of the code is achieved to meet the new business needs, taking into account the freshness between the code and the business model; in addition, the code of the business service layer and the service configuration file in the microservice architecture are encapsulated into the initial source code to Before determining the executable target source code for satisfying the target business model, the implementation layer code is generated according to the business service layer code in the microservice architecture, thereby separating the business service layer code from the implementation layer code in the code architecture. The business service layer code is generated through the code engineering scaffolding. When migrating the target source code to a new business scenario, the business service layer code can be re-covered through the code engineering scaffolding. The implementation layer code only needs to be modified according to the new business service layer code to satisfy the business model in the new business scenario, thereby achieving efficient generation of the target source code that satisfies the business model and further improving the flexibility of target source code generation.

[0011] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] The above and / or additional aspects and advantages of the present disclosure will become apparent and easily understood from the following description of the embodiments in conjunction with the accompanying drawings, in which:

[0013] Figure 1 is a flowchart of a code generation method shown in the first embodiment of the present disclosure;

[0014] Figure 2 is a flowchart of a code generation method shown in the second embodiment of the present disclosure;

[0015] Figure 3 is a flowchart of a code generation method shown in the third embodiment of the present disclosure;

[0016] Figure 4 is a flowchart of a code generation method shown in the fourth embodiment of the present disclosure;

[0017] Figure 5 It is a framework schematic diagram corresponding to the mapping relationship between the business model and the microservice architecture included in the code engineering scaffold shown in the fifth embodiment of the present disclosure;

[0018] Figure 6 is a schematic diagram of the structure of a code generating device shown in the sixth embodiment of the present disclosure;

[0019] Figure 7 It is a schematic structural diagram of an electronic device shown in an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION

[0020] In order to enable ordinary persons in the art to better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings.

[0021] It should be noted that the terms "first", "second", etc. in the specification and claims of the present disclosure and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present disclosure described herein can be implemented in an order other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.

[0022] It should be noted that in the technical solution of the present disclosure, the collection, storage, use, processing, transmission, provision and disclosure of user personal information are all carried out with the user's consent, and are in compliance with the relevant laws and regulations and do not violate public order and good morals.

[0023] In view of the above problems, the present disclosure proposes a code generation method and device.

[0024] The code generation method and device according to the embodiments of the present disclosure are described below with reference to the accompanying drawings.

[0025] Figure 1 A flowchart of a code generation method provided by an embodiment of the present disclosure.

[0026] like Figure 1 As shown, the code generation method includes the following steps:

[0027] Step 101: Obtain a target business model under a target business scenario.

[0028] It can be understood that the business scenario is the construction environment in which the business is located, for example, the financial business scenario is the construction environment in which the financial business is located. This embodiment does not specifically limit the target business scenario.

[0029] In addition, it should be noted that business personnel related to the target business scenario analyze the information contained in the target business scenario and perform modeling to determine the business modeling results, wherein the business modeling results are the target business model.

[0030] In addition, it should be noted that different target business scenarios have different target business models under the target business scenarios.

[0031] Step 102 , based on the target business model, generate the initial source code and the code of the business service level in the microservice architecture through the pre-set code engineering scaffolding.

[0032] It should be noted that the target business model at least includes a product model, a process model and a data model, and the business service layer includes an interface layer, an application layer, a domain layer and a permanent layer.

[0033] In addition, it should be noted that the pre-set code engineering scaffolding contains multiple mapping relationships.

[0034] In order to accurately convert the target business model into the initial source code and the code at the business service level in the microservice architecture, as a possible implementation method, based on the target business model, the initial source code and the code at the business service level in the microservice architecture are generated through various mapping relationships contained in the pre-set code engineering scaffolding.

[0035] As an example, based on the first data contained in the product model, a code conversion tool is used to generate initial source code; based on the target business model, various mapping relationships contained in the code engineering scaffolding are used to determine the interface layer and application layer that have a mapping relationship with the product model in the business service layer, the domain layer that has a mapping relationship with the process model in the business service layer, and the domain layer that has a mapping relationship with the data model in the business service layer; according to the business service layer that has a mapping relationship with the product model in the business service layer, the code of the interface layer and the code of the application layer are determined, and according to the business service layer that has a mapping relationship with the process model in the business service layer and the business service layer that has a mapping relationship with the data model in the business service layer, the code of the domain layer is determined; the code of the domain layer is deduced to determine the code of the permanent layer; according to the code of the interface layer, the code of the application layer, the code of the domain layer, and the code of the permanent layer, the code of the business service layer in the microservice architecture is determined.

[0036] In order to completely generate the code of the interface layer, the application layer, the domain layer and the permanent layer, as a possible implementation method, the code of the interface layer and the application layer are determined according to the business service layer that has a mapping relationship with the product model in the business service layer, and the code of the domain layer is determined according to the business service layer that has a mapping relationship with the process model in the business service layer and the business service layer that has a mapping relationship with the data model in the business service layer.

[0037] As an example, according to the mapping relationship between the product model and the interface layer, the second data contained in the product model is mapped to the interface layer, and the code of the interface layer is generated through a code conversion tool. According to the mapping relationship between the product model and the application layer, the second data contained in the product model is mapped to the application layer, and the code of the application layer is generated through a code conversion tool. According to the mapping relationship between the process model and the domain layer, the data contained in the process model is mapped to the domain layer, and the code of the domain layer is generated through a code conversion tool. According to the mapping relationship between the data model and the domain layer, the data contained in the data model is mapped to the domain layer, and the code of the domain layer is generated through a code conversion tool.

[0038] In addition, it should be noted that the first data contained in the product model is used to represent part of the data contained in the product model. For example, assuming that the product model contains basic products, business capabilities, ancillary services, product functions, business functions and service function data, among which the basic products, business capabilities and ancillary services can be divided into a group of data, which is the first data contained in the product model, and product functions, business functions and service functions can be divided into another group of data, which is the second data contained in the product model.

[0039] Step 103: Generate a service configuration file associated with the code at the business service level according to the code at the business service level in the microservice architecture.

[0040] The service configuration file is used to represent the file loaded when executing the code at the business service level in the microservice architecture.

[0041] Step 104 , encapsulate the business service level code and service configuration files in the microservice architecture into the initial source code to determine an executable target source code for satisfying the target business model.

[0042] In order to quickly execute the code at the business service level in the microservice architecture by loading the service configuration file, as an example, the service configuration file is encapsulated into the microservice architecture; and the code at the business service level in the microservice architecture and the service configuration file are encapsulated into the initial source code.

[0043] In summary, the target business model under the target business scenario is obtained; based on the target business model, the initial source code and the code of the business service level in the microservice architecture are generated through the pre-set code engineering scaffolding; according to the code of the business service level in the microservice architecture, a service configuration file associated with the code of the business service level is generated, wherein the service configuration file is used to represent the file loaded when the code of the business service level in the microservice architecture is executed; the code of the business service level in the microservice architecture and the service configuration file are encapsulated into the initial source code to determine the executable target source code for satisfying the target business model, thereby, based on the target business model, Through the pre-set code engineering scaffolding, since the code engineering scaffolding contains various mapping relationships between the target business model and the business service level in the microservice architecture, in the code generation project, there is no need for complex analysis, and the various data contained in the target business model can be mapped to the corresponding business service level, which simplifies the process of generating the target source code and avoids a large amount of complex and repetitive code coding work. Moreover, through the code engineering scaffolding, the various data contained in the target business model can be perfectly and fully converted into business service level code, so as to generate the target source code that meets the business model, thereby improving the efficiency of converting the business model into code.

[0044] In order to clearly illustrate how to generate a service configuration file associated with the code at the business service level according to the code at the business service level in the microservice architecture in the above embodiment, the present disclosure proposes another code generation method.

[0045] Figure 2 It is a flowchart of the code generation method shown in the second embodiment of the present disclosure.

[0046] like Figure 2 As shown, the code generation method includes the following steps:

[0047] Step 201: Obtain a target business model in a target business scenario.

[0048] Step 202 , based on the target business model, generates initial source code and business service level code in the microservice architecture through a pre-set code engineering scaffold.

[0049] Step 203: Determine a product model that has a mapping relationship with the interface layer code and the application layer code according to the interface layer code and the application layer code in the microservice architecture.

[0050] For example, assume that the product model includes basic products, business capabilities, ancillary services, product functions, business functions and service function data, among which there is a mapping relationship between product functions, business functions and service functions and the interface layer and application layer.

[0051] Step 204 : Determine, based on the second data included in the product model, a service configuration file in a first set format to be loaded when executing the code of the interface layer and the code of the application layer in the microservice architecture.

[0052] For example, if the business function or service function is saved in a service configuration file in json format, the service configuration file in json format can be directly loaded and run when starting the microservice architecture.

[0053] In addition, it should be noted that the specific format of the service configuration file in the first set format may be determined according to actual conditions, and this embodiment does not specifically limit it.

[0054] Step 205: According to the code of the domain layer in the microservice architecture, determine the process model that has a mapping relationship with the code of the domain layer.

[0055] For example, assume that the process model includes business activities, tasks, and processes, where there is a mapping relationship between the business activities, tasks, and processes and the domain layer.

[0056] Step 206 : Determine, based on the data included in the process model, a service configuration file in a second set format to be loaded when executing the code of the domain layer and the code of the persistent layer in the microservice architecture.

[0057] For example, business activities generate the code of the domain layer in the microservice architecture based on the target business model through the pre-set code engineering scaffolding and save it in XML format. When the microservice architecture is started, the service configuration file in XML format can be directly loaded and run.

[0058] In addition, it should be noted that the specific format of the service configuration file in the second set format may be determined according to actual conditions, and this embodiment does not specifically limit it.

[0059] It should be understood that since the code of the permanent layer is determined by deducing the code of the domain layer, when the service configuration file of the second setting format is loaded, not only the code of the domain layer in the microservice architecture can be executed, but also the code of the permanent layer in the microservice architecture can be executed.

[0060] Step 207 , encapsulate the business service level code and service configuration files in the microservice architecture into the initial source code to determine an executable target source code for satisfying the target business model.

[0061] In order to quickly execute the code of the business service level in the microservice architecture by loading the first set format service configuration file and the second set format service configuration file, as an example, the first set format service configuration file and the second set format service configuration file are encapsulated into the microservice architecture; and the first set format service configuration file and the second set format service configuration file in the microservice architecture are encapsulated into the initial source code.

[0062] It should be noted that the execution process of step 201, step 202 and step 207 can be implemented in any way in the embodiments of the present disclosure, and the embodiments of the present disclosure do not limit this and will not be described in detail.

[0063] In summary, according to the code of the interface layer and the code of the application layer in the microservice architecture, a product model that has a mapping relationship with the code of the interface layer and the code of the application layer is determined; based on the second data contained in the product model, a service configuration file of a first set format loaded when executing the code of the interface layer and the code of the application layer in the microservice architecture is determined; according to the code of the domain layer in the microservice architecture, a process model that has a mapping relationship with the code of the domain layer is determined; according to the code of the domain layer in the microservice architecture, a process model that has a mapping relationship with the code of the domain layer is determined. Therefore, when the microservice architecture is started, the execution of the code at the business service level is realized by loading the service configuration file. When the current business needs change, directly modifying the code at the business service level will cause inconsistencies between the code and the business model, and it is difficult to maintain and modify it later. By modifying the service configuration file, adaptive adjustment of the code is achieved to meet new business needs, taking into account the freshness between the code and the business model.

[0064] In order to clearly illustrate that in the above embodiment, before encapsulating the business service layer code and service configuration files in the microservice architecture into the initial source code to determine the executable target source code for satisfying the target business model, the present disclosure proposes another code generation method.

[0065] Figure 3 It is a flowchart of the code generation method shown in the third embodiment of the present disclosure.

[0066] like Figure 3 As shown, the code generation method includes the following steps:

[0067] Step 301: Obtain a target business model under a target business scenario.

[0068] Step 302 , based on the target business model, generate initial source code and business service level code in the microservice architecture through a pre-set code engineering scaffold.

[0069] Step 303: Generate a service configuration file associated with the code at the business service level according to the code at the business service level in the microservice architecture.

[0070] Step 304, based on the code of the business service layer in the microservice architecture, generate implementation classes for the interface layer, application layer and domain layer, and based on the implementation classes, generate code for the implementation layer.

[0071] It is important to understand that when generating the target source code, the code of the business service layer in the microservice architecture includes the interface layer code, application layer code, domain layer code and permanent layer code. The code of the business service layer includes the most basic interfaces and classes in the target business model of software development. This part of the code is prone to repeated development and is cumbersome. Through the code engineering scaffolding, the code of the business service layer can be quickly generated. In order to adapt to new business needs in different business scenarios, the code of the implementation layer is generated based on the code of the business service layer, and the code of the business service layer and the code of the implementation layer are separated and encapsulated into the target source code. Therefore, when migrating the target source code to a new business scenario, the code of the business service layer can be re-covered through the code engineering scaffolding. It is only necessary to modify the code of the implementation layer according to the new code of the business service layer to meet the business model in the new business scenario, and the target source code that meets the business model is efficiently generated, while further improving the flexibility of target source code generation.

[0072] Step 305: Encapsulate the code of the implementation layer into the initial source code.

[0073] In addition, it should be noted that in order to separate the implementation layer and the business service layer at the level, when encapsulating the code of the implementation layer into the initial source code, the implementation layer and the microservice architecture are respectively encapsulated into the initial source code.

[0074] Step 306 , encapsulate the business service level code and service configuration files in the microservice architecture into the initial source code to determine an executable target source code for satisfying the target business model.

[0075] It should be noted that the execution process of steps 301 to 303 and step 306 can be implemented in any manner in the embodiments of the present disclosure, and the embodiments of the present disclosure do not limit this and will not be described in detail.

[0076] In order to enable the business service layer code and the implementation layer code in the microservice architecture to be fully executed when a request instruction to execute the target source code is received, as a possible implementation method, the microservice architecture is started, and a service configuration file in a first set format and a service configuration file in a second set format are loaded to execute the business service layer code and the implementation layer code.

[0077] As an example, in response to a request instruction to execute a target source code, a microservice architecture is started; when the microservice architecture is started, a service configuration file in a first set format and a service configuration file in a second set format are loaded; according to the service configuration file in the second set format, the code of the domain layer and the code of the permanent layer are executed; according to the service configuration file in the first set format, the code of the interface layer and the code of the application layer are executed; and the code of the implementation layer is executed.

[0078] In summary, by generating implementation classes for the interface layer, application layer and domain layer according to the code of the business service layer in the microservice architecture, and generating the code of the implementation layer according to the implementation class, the code of the implementation layer is encapsulated into the initial source code, thereby separating the code of the business service layer from the code of the implementation layer in the code architecture, and the code of the business service layer is generated through the code engineering scaffolding. When the target source code is migrated to a new business scenario, the code of the business service layer can be re-covered through the code engineering scaffolding. It is only necessary to modify the code of the implementation layer according to the new business service layer code to meet the business model in the new business scenario, thereby achieving efficient generation of the target source code that meets the business model, and further improving the flexibility of target source code generation.

[0079] In order to clearly explain how to modify the first target source code when migrating the target source code to a new business scenario in the above embodiment to meet the business model in the new business scenario, the present disclosure proposes another code generation method.

[0080] Figure 4 It is a flowchart of the code generation method shown in the fourth embodiment of the present disclosure.

[0081] like Figure 4 As shown, the code generation method includes the following steps:

[0082] Step 401: Obtain a first business model in a first business scenario.

[0083] Step 402 : Based on the first business model, a first initial source code and a first code at the business service level in the microservice architecture are generated through a preset code engineering scaffold.

[0084] It should be understood that, when generating the first target source code, the code of the business service layer and the code of the implementation layer in the microservice architecture are separated and encapsulated into the first target source code. Therefore, when migrating the first target source code to a new business scenario, only the code of the implementation layer needs to be modified to meet the business model in the new business scenario, further improving the flexibility of generating source code based on the business model.

[0085] Step 403: Generate a first service configuration file associated with the first code at the business service level according to the first code at the business service level in the microservice architecture.

[0086] The first service configuration file is used to represent the file loaded when executing the first code of the business service level in the microservice architecture.

[0087] Step 404 , encapsulate the first code of the business service level in the microservice architecture and the first service configuration file into the first initial source code to determine an executable first target source code for satisfying the first business model.

[0088] Step 405: if the first target source code is migrated to the second business scenario, the first target source code is modified to determine an executable second target source code for satisfying a second business model in the second business scenario.

[0089] In order to make the modified first target source code meet the second business model under the second business scenario, as a possible implementation method, the first code of the business service layer in the first target source code is overwritten by a pre-set code engineering scaffolding, and the code of the implementation layer is modified to complete the modification of the first target source code.

[0090] As an example, a second business model under a second business scenario is obtained; based on the second business model, a second initial source code and a second code at the business service level in a microservice architecture are generated through a pre-set code engineering scaffold; according to the newly generated second code at the business service level in the microservice architecture, the first code at the business service level in the first target source code is overwritten to determine the second code at the business service level in the first target source code; according to the second code at the business service level in the first target source code, a second service configuration file associated with the second code at the business service level is generated; the first service configuration file in the first target source code is modified into a second service configuration file to complete the modification of the first target source code, and the modified first target source code is used as the second target source code.

[0091] In addition, it should be noted that the first code of the business service level is not the same as the second code of the business service level, and the first service configuration file is not the same as the second service configuration file.

[0092] It should be noted that the execution process of steps 401 to 405 can be implemented in any manner in the embodiments of the present disclosure, and the embodiments of the present disclosure do not limit this and will not be described in detail.

[0093] In summary, a first business model in a first business scenario is obtained, and based on the first business model, a first initial source code and a first code at the business service level in a microservice architecture are generated through a pre-set code engineering scaffolding. According to the first code at the business service level in the microservice architecture, a first service configuration file associated with the first code at the business service level is generated, and the first code at the business service level in the microservice architecture and the first service configuration file are encapsulated into the first initial source code to determine an executable first target source code for satisfying the first business model. If the first target source code is migrated to a second business scenario, the first target source code is modified to determine an executable second target source code for satisfying the second business model in the second business scenario. Thus, not only the business needs in the target business scenario are met, but also when the target business scenario changes, the corresponding code can be generated through the pre-set code engineering scaffolding to adapt to the new business needs in the changed target business scenario, thereby avoiding a large amount of complex and repetitive code coding work and improving the efficiency of converting business models into codes.

[0094] For example, the framework diagram corresponding to the mapping relationship between the business model contained in the code engineering scaffold and the microservice architecture can be as follows: Figure 5As shown, it is assumed that the target business model is a financial business model, wherein there is a mapping relationship between the second data (product function, business function and service function) contained in the product model and the interface layer, there is a mapping relationship between the product model and the application layer (application service), there is a mapping relationship between the data (steps) contained in the process model and the domain layer (domain service), and there is a mapping relationship between the data model and the domain layer (domain model).

[0095] As an example, based on the first data (basic products, business capabilities and ancillary services) contained in the product model, a code conversion tool is used to generate initial source code; according to the mapping relationship between the second data (product functions, business functions and service functions) contained in the product model and the interface layer, the second data (product functions, business functions and service functions) contained in the product model is mapped to the interface layer, and the code of the interface layer is generated by the code conversion tool; and according to the mapping relationship between the product model and the application layer (application service), the second data contained in the product model is mapped to the application layer, and the code of the application layer is generated by the code conversion tool; according to the data (steps) contained in the process model The mapping relationship between the data model and the domain layer (domain service) is used to map the data (steps) contained in the process model to the domain layer (domain service), and the code of the domain layer (domain service) is generated through a code conversion tool. According to the mapping relationship between the data model and the domain layer (domain model), the business object entities contained in the data model are mapped to the domain layer (domain model), and the code of the domain layer (domain model) is generated through a code conversion tool to determine the code of the domain layer; the code of the domain layer is deduced to determine the code of the permanent layer; according to the code of the interface layer, the code of the application layer, the code of the domain layer and the code of the permanent layer, the code of the business service level in the microservice architecture is determined.

[0096] In addition, it should be noted that if the business function or service function is saved in a service configuration file in json format, the service configuration file in json format can be directly loaded and run when starting the microservice architecture.

[0097] In addition, it should be noted that business activities are saved in XML format, so when starting the microservice architecture, the service configuration file in XML format can be directly loaded and run.

[0098] In addition, it should be noted that the process engine is used to parse the service configuration file when starting the microservice architecture.

[0099] In addition, it should be noted that Figure 5The financial business model is divided into three categories: product model, process model, and data model. The product model includes basic products, business capabilities, ancillary services, product functions, business functions, and service functions. Basic products are a group of financial saleable products with similar product functions and business processing rules. Business capabilities are a group of business objects associated together according to certain specific rules and a closed set of multiple logical processing of these business objects. Ancillary services are a group of service functions attached to financial saleable products, with similar service functions and business processing rules. Product functions are the necessary functions of products that can be provided to customers independently, for example, account opening, account closing, deposit and withdrawal of deposit products. Business functions are non-product functions that can be provided to customers independently, for example, adding new customers, accumulating customer limits, updating account status, and stopping / unstopping accounts. Service functions are optional functions attached to products that can be provided to customers independently, for example, distributing media, changing passwords, and changing authentication methods of deposit products.

[0100] In addition, it should be noted that the process model includes business activities, tasks and processes. Business activities are triggered by business events and include a series of tasks. Through the arrangement of tasks, end-to-end operations in different scenarios can be met. Tasks are operations that roles complete to create or update specified business entities during the execution of business activities. Steps are the most granular description of the process model, including business rules and business information.

[0101] In addition, it should be noted that the data model includes business objects and entities. Business objects are a set of highly cohesive and loosely coupled business entities, which are composed of basic entities and all their subordinate attribute entities and relationship entities. Entities are derived from business information needs. They are abstract or concrete things managed and maintained by business needs. They are the basic data concepts for storing business information.

[0102] Corresponding to the code generation method provided in the above embodiment, the present disclosure also provides a code generation device. Since the code generation device provided in the embodiment of the present disclosure corresponds to the code generation method provided in the above embodiment, the implementation method of the code generation method is also applicable to the code generation device provided in the embodiment of the present disclosure, and will not be described in detail in the embodiment of the present disclosure.

[0103] Figure 6 It is a schematic diagram of the structure of a code generating device shown in the sixth embodiment of the present disclosure.

[0104] like Figure 6 As shown, the code generating device 600 includes: a first acquisition module 601 , a first generation module 602 , a second generation module 603 and a first determination module 604 .

[0105] Among them, the first acquisition module 601 is used to obtain the target business model under the target business scenario; the first generation module 602 is used to generate the initial source code and the code of the business service level in the microservice architecture based on the target business model through a pre-set code engineering scaffolding; the second generation module 603 is used to generate a service configuration file associated with the code of the business service level in the microservice architecture according to the code of the business service level in the microservice architecture, wherein the service configuration file is used to represent the file loaded when executing the code of the business service level in the microservice architecture; the first determination module 604 is used to encapsulate the code of the business service level in the microservice architecture and the service configuration file into the initial source code to determine the executable target source code for satisfying the target business model.

[0106] As a possible implementation of the embodiment of the present disclosure, the target business model includes at least a product model, a process model and a data model, and the business service layer includes an interface layer, an application layer, a domain layer and a permanent layer. The first generation module 602 is used to generate an initial source code based on the first data contained in the product model through a code conversion tool; based on the target business model, the interface layer and the application layer that have a mapping relationship with the product model in the business service layer, the domain layer that has a mapping relationship with the process model in the business service layer, and the domain layer that has a mapping relationship with the data model in the business service layer are determined through various mapping relationships contained in the code engineering scaffolding; according to the business service layer that has a mapping relationship with the product model in the business service layer, the code of the interface layer and the code of the application layer are determined, and according to the business service layer that has a mapping relationship with the process model in the business service layer and the business service layer that has a mapping relationship with the data model in the business service layer, the code of the domain layer is determined; the code of the domain layer is derived to determine the code of the permanent layer; according to the code of the interface layer, the code of the application layer, the code of the domain layer and the code of the permanent layer, the code of the business service layer in the microservice architecture is determined.

[0107] As a possible implementation of the embodiment of the present disclosure, the first generating module 602 is further specifically configured to:

[0108] According to the mapping relationship between the product model and the interface layer, the second data included in the product model is mapped to the interface layer, and a code conversion tool is used to generate code for the interface layer; and according to the mapping relationship between the product model and the application layer, the second data included in the product model is mapped to the application layer, and a code conversion tool is used to generate code for the application layer;

[0109] According to the mapping relationship between the process model and the domain layer, the data contained in the process model is mapped to the domain layer, and the code of the domain layer is generated through a code conversion tool. According to the mapping relationship between the data model and the domain layer, the data contained in the data model is mapped to the domain layer, and the code of the domain layer is generated through a code conversion tool.

[0110] As a possible implementation method of the embodiment of the present disclosure, the second generation module 603 is used to determine a product model that has a mapping relationship with the code of the interface layer and the code of the application layer based on the code of the interface layer and the code of the application layer in the microservice architecture; based on the second data included in the product model, to determine a service configuration file in a first set format that is loaded when executing the code of the interface layer and the code of the application layer in the microservice architecture.

[0111] As a possible implementation method of the embodiment of the present disclosure, the second generation module 603 is used to determine a process model that has a mapping relationship with the code of the domain layer based on the code of the domain layer in the microservice architecture; based on the data contained in the process model, to determine a service configuration file of a second set format to be loaded when executing the code of the domain layer and the code of the permanent layer in the microservice architecture.

[0112] As a possible implementation method of the embodiment of the present disclosure, the first determination module 604 is used to encapsulate the service configuration file in the first set format and the service configuration file in the second set format into the microservice architecture; and encapsulate the service configuration file in the first set format and the service configuration file in the second set format in the microservice architecture into the initial source code.

[0113] As a possible implementation of the embodiment of the present disclosure, the code generation device 600 further includes: an implementation layer module, a response module and a migration module.

[0114] Among them, before the first determination module 604, the implementation layer module is used to generate implementation classes for the interface layer, application layer and domain layer according to the code of the business service layer in the microservice architecture; generate the code of the implementation layer according to the implementation class; and encapsulate the code of the implementation layer into the initial source code.

[0115] As a possible implementation method of the embodiment of the present disclosure, a response module is used to start the microservice architecture in response to a request instruction to execute the target source code; when starting the microservice architecture, a service configuration file in a first set format and a service configuration file in a second set format are loaded; according to the service configuration file in the second set format, the code of the domain layer and the code of the permanent layer are executed; according to the service configuration file in the first set format, the code of the interface layer and the code of the application layer are executed; and the code of the implementation layer is executed.

[0116] As a possible implementation method of the embodiment of the present disclosure, a migration module is used to obtain a first business model in a first business scenario; based on the first business model, a first initial source code and a first code at a business service level in a microservice architecture are generated through a pre-set code engineering scaffold; according to the first code at the business service level in the microservice architecture, a first service configuration file associated with the first code at the business service level is generated, wherein the first service configuration file is used to represent a file loaded when executing the first code at the business service level in the microservice architecture; the first code at the business service level in the microservice architecture and the first service configuration file are encapsulated into the first initial source code to determine an executable first target source code for satisfying the first business model; if the first target source code is migrated to a second business scenario, the first target source code is modified to determine an executable second target source code for satisfying the second business model in the second business scenario.

[0117] As a possible implementation method of an embodiment of the present disclosure, a migration module is used to obtain a second business model in a second business scenario; based on the second business model, a second initial source code and a second code at the business service level in the microservice architecture are generated through a pre-set code engineering scaffold; according to the newly generated second code at the business service level in the microservice architecture, the first code at the business service level in the first target source code is overwritten to determine the second code at the business service level in the first target source code; according to the second code at the business service level in the first target source code, a second service configuration file associated with the second code at the business service level is generated; the first service configuration file in the first target source code is modified into a second service configuration file to complete the modification of the first target source code, and the modified first target source code is used as the second target source code.

[0118] The code generation device of the embodiment of the present disclosure obtains the target business model in the target business scenario; based on the target business model, generates the initial source code and the code of the business service layer in the microservice architecture through a pre-set code engineering scaffold; generates a service configuration file associated with the code of the business service layer according to the code of the business service layer in the microservice architecture, wherein the service configuration file is used to represent the file loaded when the code of the business service layer in the microservice architecture is executed; the code of the business service layer in the microservice architecture and the service configuration file are encapsulated into the initial source code to determine the executable target source code for satisfying the target business model, thereby, based on The target business model, through the pre-set code engineering scaffolding, contains various mapping relationships between the target business model and the business service level in the microservice architecture. In the code generation project, there is no need for complex analysis to map the various data contained in the target business model to the corresponding business service level, which simplifies the process of generating the target source code and avoids a lot of complex and repetitive code coding work. Moreover, through the code engineering scaffolding, the various data contained in the target business model can be perfectly and fully converted into business service level code, so as to generate the target source code that meets the business model and improve the efficiency of converting the business model into code.

[0119] In an exemplary embodiment, an electronic device is also provided.

[0120] Among them, electronic equipment includes:

[0121] processor;

[0122] a memory for storing processor-executable instructions;

[0123] The processor is configured to execute instructions to implement the code generation method proposed in any of the aforementioned embodiments.

[0124] As an example, Figure 7 is a schematic diagram of the structure of an electronic device 700 shown in an exemplary embodiment of the present disclosure, such as Figure 7 As shown, the electronic device 700 may further include:

[0125] The memory 710 and the processor 720, a bus 730 connecting different components (including the memory 710 and the processor 720), the memory 710 stores a computer program, and when the processor 720 executes the program, the code generation method described in the embodiment of the present disclosure is implemented.

[0126] Bus 730 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor or a local bus using any of a variety of bus architectures. For example, these architectures include but are not limited to Industry Standard Architecture (ISA) bus, Micro Channel Architecture (MAC) bus, Enhanced ISA bus, Video Electronics Standards Association (VESA) local bus and Peripheral Component Interconnect (PCI) bus.

[0127] The electronic device 700 typically includes a variety of electronic device readable media. These media can be any available media that can be accessed by the electronic device 700, including volatile and non-volatile media, removable and non-removable media.

[0128] The memory 710 may also include computer system readable media in the form of volatile memory, such as random access memory (RAM) 740 and / or cache memory 750. The server 700 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 760 may be used to read and write non-removable, non-volatile magnetic media ( Figure 7 not shown, often referred to as a "hard drive packager"). Although Figure 7 Not shown, a disk driver package for reading and writing a removable non-volatile disk (e.g., a "floppy disk"), and an optical disk driver package for reading and writing a removable non-volatile optical disk (e.g., a CD-ROM, a DVD-ROM, or other optical media) may be provided. In these cases, each driver package can be connected to the bus 730 via one or more data medium interfaces. The memory 710 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of the various embodiments of the present disclosure.

[0129] A program / utility 780 having a set (at least one) of program modules 770 may be stored, for example, in the memory 710, such program modules 770 including but not limited to an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment. The program modules 770 generally perform the functions and / or methods of the embodiments described in the present disclosure.

[0130] The electronic device 700 may also communicate with one or more external devices 760 (e.g., keyboard, pointing device, display 791, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 700, and / or communicate with any device that enables the electronic device 700 to communicate with one or more other computing devices (e.g., network card, modem, etc.). Such communication may be performed through an input / output (I / O) interface 792. In addition, the electronic device 700 may also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN) and / or public network, such as the Internet) through a network adapter 793. As shown, the network adapter 793 communicates with other modules of the electronic device 700 through a bus 730. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 700, including but not limited to: microcode, device driver package, redundant processing unit, external disk driver package array, RAID system, tape driver package, and data backup storage system, etc.

[0131] The processor 720 executes various functional applications and data processing by running the programs stored in the memory 710 .

[0132] It should be noted that the implementation process and technical principles of the electronic device of this embodiment refer to the aforementioned explanation of the code generation method of the embodiment of the present disclosure, which will not be repeated here.

[0133] In an exemplary embodiment, a computer-readable storage medium including instructions is also provided, such as a memory including instructions, and the above instructions can be executed by a processor of an electronic device to complete the code generation method proposed in any of the above embodiments. Optionally, the computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.

[0134] In an exemplary embodiment, a computer program product is further provided, including a computer program / instruction, wherein the computer program / instruction, when executed by a processor, implements the code generation method proposed in any of the above embodiments.

[0135] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. The present disclosure is intended to cover any variations, uses or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The description and examples are to be considered exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.

[0136] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims

1. A code generation method, characterized in that: The following steps are involved: Obtain the target business model under the target business scenario; Based on the target business model, generate initial source code and business service level code in the microservice architecture through a pre-set code engineering scaffold; Generate a service configuration file associated with the code of the business service layer in the microservice architecture according to the code of the business service layer in the microservice architecture, wherein the service configuration file is used to represent a file loaded when the code of the business service layer in the microservice architecture is executed; The code of the business service level in the microservice architecture and the service configuration file are encapsulated into the initial source code to determine an executable target source code for satisfying the target business model.

2. The method according to claim 1, characterized in that The target business model at least includes a product model, a process model and a data model, the business service level includes an interface layer, an application layer, a domain layer and a permanent layer, and the code engineering scaffolding pre-set based on the target business model is used to generate the initial source code and the code of the business service level in the microservice architecture, including: Based on the first data included in the product model, using a code conversion tool to generate the initial source code; Based on the target business model, the interface layer and the application layer in the business service level that have a mapping relationship with the product model, the domain layer in the business service level that has a mapping relationship with the process model, and the domain layer in the business service level that has a mapping relationship with the data model are determined through various mapping relationships contained in the code engineering scaffolding; According to the business service layer in the business service level that has a mapping relationship with the product model, determine the code of the interface layer and the code of the application layer, and according to the business service layer in the business service level that has a mapping relationship with the process model and the business service layer in the business service level that has a mapping relationship with the data model, determine the code of the domain layer; Deducing the code of the domain layer to determine the code of the permanent layer; The code of the business service layer in the microservice architecture is determined according to the code of the interface layer, the code of the application layer, the code of the domain layer and the code of the permanent layer.

3. The method according to claim 2, characterized in that The step of determining the code of the interface layer and the code of the application layer according to the business service layer that has a mapping relationship with the product model in the business service level, and determining the code of the domain layer according to the business service layer that has a mapping relationship with the process model in the business service level and the business service layer that has a mapping relationship with the data model in the business service level, includes: According to the mapping relationship between the product model and the interface layer, the second data included in the product model is mapped to the interface layer, and the code of the interface layer is generated by the code conversion tool; and according to the mapping relationship between the product model and the application layer, the second data included in the product model is mapped to the application layer, and the code of the application layer is generated by the code conversion tool; According to the mapping relationship between the process model and the domain layer, the data contained in the process model is mapped to the domain layer, and the code of the domain layer is generated by the code conversion tool; and according to the mapping relationship between the data model and the domain layer, the data contained in the data model is mapped to the domain layer, and the code of the domain layer is generated by the code conversion tool.

4. The method according to claim 1, characterized in that: The generating, according to the code of the business service level in the microservice architecture, a service configuration file associated with the code of the business service level, wherein the service configuration file is used to represent a file loaded when the code of the business service level in the microservice architecture is executed, including: According to the code of the interface layer and the code of the application layer in the microservice architecture, determining the product model having a mapping relationship with the code of the interface layer and the code of the application layer; Based on the second data included in the product model, a service configuration file in a first set format loaded when executing the code of the interface layer and the code of the application layer in the microservice architecture is determined.

5. The method according to claim 1, characterized in that: The generating, according to the code of the business service level in the microservice architecture, a service configuration file associated with the code of the business service level, wherein the service configuration file is used to represent a file loaded when the code of the business service level in the microservice architecture is executed, including: According to the code of the domain layer in the microservice architecture, determine the process model that has a mapping relationship with the code of the domain layer; Based on the data included in the process model, a service configuration file in a second set format is determined to be loaded when executing the code of the domain layer and the code of the permanent layer in the microservice architecture.

6. The method according to any one of claims 1 to 5, characterized in that: The method comprises: Encapsulating the service configuration file in the first setting format and the service configuration file in the second setting format into the microservice architecture; And encapsulating the service configuration file in the first setting format and the service configuration file in the second setting format in the microservice architecture into the initial source code.

7. The method according to claim 1, characterized in that Before encapsulating the business service level code and the service configuration file in the microservice architecture into the initial source code to determine an executable target source code for satisfying the target business model, the method includes: Generate implementation classes for the interface layer, the application layer, and the domain layer according to the code of the business service layer in the microservice architecture; Generate implementation layer code according to the implementation class; The code of the implementation layer is encapsulated into the initial source code.

8. The method according to any one of claims 1 to 7, characterized in that: The method comprises: In response to a request instruction to execute the target source code, starting the microservice architecture; When starting the microservice architecture, loading a service configuration file in the first setting format and a service configuration file in the second setting format; Execute the code of the domain layer and the code of the persistent layer according to the service configuration file of the second setting format; Execute the code of the interface layer and the code of the application layer according to the service configuration file of the first setting format; Execute the code of the implementation layer.

9. The method according to any one of claims 1 to 8, characterized in that: The method further comprises: Obtaining a first business model in a first business scenario; Based on the first business model, generating a first initial source code and a first code at the business service level in the microservice architecture through the preset code engineering scaffolding; Generate a first service configuration file associated with the first code of the business service layer in the microservice architecture according to the first code of the business service layer in the microservice architecture, wherein the first service configuration file is used to represent a file loaded when executing the first code of the business service layer in the microservice architecture; Encapsulating the first code of the business service level in the microservice architecture and the first service configuration file into the first initial source code to determine an executable first target source code for satisfying the first business model; If the first target source code is migrated to a second business scenario, the first target source code is modified to determine an executable second target source code for satisfying a second business model in the second business scenario.

10. The method according to claim 9, characterized in that If the first target source code is migrated to the second business scenario, the first target source code is modified to determine an executable second target source code for satisfying the second business model in the second business scenario, including: Acquire the second business model under the second business scenario; Based on the second business model, generating a second initial source code and a second code at the business service level in the microservice architecture through the preset code engineering scaffolding; Overwriting the first code of the business service layer in the first target source code according to the newly generated second code of the business service layer in the microservice architecture to determine the second code of the business service layer in the first target source code; generating, according to the second code of the business service level in the first target source code, a second service configuration file associated with the second code of the business service level; The first service configuration file in the first target source code is modified into the second service configuration file to complete the modification of the first target source code, and the modified first target source code is used as the second target source code.

11. A code generating device, characterized in that: The following steps are involved: A first acquisition module is used to acquire a target business model under a target business scenario; A first generation module is used to generate initial source code and business service level code in a microservice architecture based on the target business model through a pre-set code engineering scaffold; A second generating module is used to generate a service configuration file associated with the code of the business service layer in the microservice architecture according to the code of the business service layer in the microservice architecture, wherein the service configuration file is used to represent a file loaded when the code of the business service layer in the microservice architecture is executed; The first determination module is used to encapsulate the code of the business service level and the service configuration file in the microservice architecture into the initial source code to determine an executable target source code for satisfying the target business model.