Business system code automatic generation method and system

Through pre-trained natural language processing models and static code analysis and optimization, business system code is automatically generated, solving the problems of low development efficiency and poor adaptability, and achieving efficient and reliable code generation and system integration.

CN120704672APending Publication Date: 2025-09-26浪潮智慧科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510882124.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-27
Publication Date
2025-09-26

AI Technical Summary

Technical Problem

In existing technologies, business system development is inefficient, manual coding is time-consuming, and traditional code generation tools are difficult to adapt to complex business rules and heterogeneous system integration, lacking flexibility and versatility.

Method used

The requirement document is parsed through a pre-trained natural language processing model, structured requirement use cases are generated and a domain model is built. The optimal system framework is dynamically selected and converted into executable code modules. The code is then optimized through cohesion calculation and static code analysis.

Benefits of technology

It improves the development efficiency of business system code, reduces the probability of system defects, can adapt to complex business rules and heterogeneous system integration requirements, and improves code quality and maintainability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120704672A_ABST
    Figure CN120704672A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of code generation, and particularly relates to a business system code automatic generation method and system.The method comprises the steps that a natural language requirement document is analyzed through a pre-trained natural language processing model, a structured requirement case is generated, and a domain model is constructed; dynamically calculating an optimal system framework through a framework selection scoring algorithm to obtain a target framework; converting the domain model into a plurality of executable code modules of the target framework; calculating a module cohesion degree for the executable code module, and maintaining a current module structure when the module cohesion degree is greater than or equal to a set threshold value; otherwise, automatically splitting the executable code module, generating a distributed code module according to the coupling degree of the service capability unit, and recalculating the cohesion degree of the modules until the cohesion degrees of all the modules are greater than or equal to a set threshold value; and optimizing the generated code by adopting static code analysis in combination with reinforcement learning. The high cohesion and low coupling of the code are ensured, and the quality and maintainability of the code are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of code generation, and in particular relates to a method and system for automatically generating business system codes. Background Art

[0002] In the current field of business system development, most development work still relies heavily on manual coding, or is only aided by traditional code generation tools. This manual coding approach is inefficient, requiring developers to invest significant time and effort in writing foundational code. This not only increases development costs but also easily leads to system defects due to human error. For example, the development cycle of a medium-complexity CRM system typically takes three to six months, with up to 60% of this time consumed by writing foundational code, severely impacting system delivery speed and the company's business responsiveness.

[0003] At the same time, traditional code generation tools also have numerous shortcomings. These tools often only support simple business scenarios based on pre-built templates, with limited ability to process complex business rules, making them unable to meet the increasingly diverse business needs of enterprises. Furthermore, the code they generate is heavily dependent on specific frameworks, such as Spring Boot, lacking flexibility and versatility, making it difficult to adapt to the needs of enterprises integrating heterogeneous systems, and limiting system scalability and compatibility.

[0004] Therefore, there is an urgent need for a method to automatically generate business system code that can improve development efficiency, adapt to complex business rules and support heterogeneous system integration. Summary of the Invention

[0005] In view of the above-mentioned deficiencies in the prior art, the present invention provides a method and system for automatically generating business system codes to solve the above-mentioned technical problems.

[0006] In a first aspect, the technical solution of the present invention provides a method for automatically generating a business system code, comprising the following steps: S1. Use a pre-trained natural language processing model to parse natural language requirement documents, generate structured requirement use cases that include user scenarios, inputs, expected outputs, and business rules, and build a domain model that includes entities, relationships, business rules, and business processes. The domain model is represented by a graph data structure, where nodes represent entities and edges represent relationships between entities. S2. Based on the system integration requirements, business feature dimensions, and TPS information in the required use case, the optimal system framework is dynamically calculated through the framework selection scoring algorithm to obtain the target framework; S3. Convert the domain model into multiple executable code modules of the target framework based on the business processes and business rules in the domain model; S4. Calculate module cohesion for the executable code module. The module cohesion is calculated by calculating the call frequency and data sharing degree between the business capability units within the module. When the module cohesion is greater than or equal to a set threshold, maintain the current module structure. Otherwise, automatically split the executable code module, generate distributed code modules according to the coupling degree of the business capability units, and recalculate the module cohesion until the cohesion of all modules is greater than or equal to the set threshold. S5. Use static code analysis combined with reinforcement learning to optimize the generated code module.

[0007] As a further limitation of the technical solution of the present invention, parsing a natural language requirement document by a pre-trained natural language processing model specifically includes: Perform word segmentation, part-of-speech tagging, and named entity recognition on the requirement documents to extract key information; Use dependency parsing to identify sentence structures and extract business actions and their participants; Perform semantic analysis based on pre-trained natural language processing models to identify user scenarios, inputs, expected outputs, and business rules; and use regular expressions to assist in extracting structured information.

[0008] By performing word segmentation, part-of-speech tagging, and named entity recognition on the requirements document, key information can be accurately extracted, providing accurate foundational data for subsequent semantic analysis. Using dependency parsing to identify sentence structure helps accurately extract business actions and their participants, providing a deeper and more comprehensive understanding of the requirements document. Semantic analysis based on a pre-trained natural language processing model, combined with regular expressions to assist in extracting structured information, can more accurately identify user scenarios, inputs, expected outputs, and business rules, improving the accuracy and completeness of requirements analysis and providing a reliable basis for subsequent code generation.

[0009] As a further limitation of the technical solution of the present invention, constructing a domain model including entities, relationships and business processes specifically includes: Identify business objects and their attributes from requirement documents, and use domain knowledge graphs to assist entity recognition; Based on syntactic analysis and semantic role labeling, the relationship between entities is identified and stored in categories; The business process is decomposed into executable steps through the process deconstruction algorithm, and the dependencies and data flows between the steps are expressed using BPMN.

[0010] Identifying business objects and their attributes from requirements documents and using domain knowledge graphs to assist in entity recognition enables more accurate identification of business entities, ensuring the accuracy of entity definitions in the domain model. Identifying and categorizing relationships between entities based on syntactic analysis and semantic role annotation helps clearly express the associations between business entities, making the domain model more complete and accurate. Using a process deconstruction algorithm to decompose business processes into executable steps and using BPMN to represent the dependencies and data flows between steps, this intuitively displays business processes, facilitates subsequent code generation and system implementation, and improves development efficiency.

[0011] As a further limitation of the technical solution of the present invention, step S2 specifically includes: Extract system integration requirements, business feature dimensions and TPS information from demand use cases; Build a candidate framework library and collect benchmark data for each candidate framework, including CPU efficiency score, concurrent connection score (maximum sustainable connection score), latency performance score, and transaction volume per unit time; Calculate the comprehensive evaluation score of each candidate framework using the framework selection scoring algorithm based on the benchmark test data; The candidate frame with the highest score is selected as the target frame.

[0012] Extracting system integration requirements, business feature dimensions, and TPS information from the required use cases provides a comprehensive basis for framework selection. A library of candidate frameworks is constructed, and benchmark data is collected for each candidate framework, including CPU efficiency scores, concurrent connection scores, latency performance scores, and transaction volume per unit time. This allows for an objective assessment of each candidate framework's performance. Based on this benchmark data, a framework selection scoring algorithm is used to calculate a comprehensive evaluation score for each candidate framework. The highest-scoring candidate framework is selected as the target framework, ensuring that the selected framework meets the system's performance and business requirements, improving the system's overall performance and stability.

[0013] As a further limitation of the technical solution of the present invention, the calculation formula of the comprehensive evaluation score is as follows:

[0014] Where, Candidate framework, For the j The weight of the indicator, For the framework In the j Score of indicators; j The indicator score includes one of the following: CPU efficiency score, concurrent connection score, latency performance score, and normalized value of transaction volume per unit time; n is the total number of items.

[0015] By assigning weights to different indicators and calculating the normalized scores of the framework on each indicator, we can comprehensively consider multiple performance indicators of the framework and evaluate the pros and cons of the framework more scientifically and objectively. This provides an accurate calculation method for selecting the optimal system framework and ensures the rationality and accuracy of framework selection.

[0016] As a further limitation of the technical solution of the present invention, in step S3, the step of converting the domain model into multiple executable code modules of the target framework according to the business processes and business rules in the domain model includes: Extract entities, relationships, and business processes from the domain model. Entities include attribute definitions and constraints, relationships include the types of associations between entities, and business processes include business actions and their execution order. Based on the constraints and business processes in the domain model, identify business rules, including data validity rules, business logic rules, and process control rules; Convert the identified business rules into executable business logic methods, including input parameter definition, conditional judgment logic, exception handling mechanism and return value design; Map business logic methods to the target framework's code structure based on its syntax and functional characteristics, including annotation usage, class inheritance, interface implementation, and how to call specific framework components. Based on the adapted code structure, an executable code module is generated, which includes entity classes, business logic classes and data persistence configuration. The entity classes include the JPA annotations of the framework, the business logic classes include the method implementation after the business rules are converted, and the data persistence configuration includes transaction management and database interaction logic. Each executable code module corresponds to one or more business capability units.

[0017] Detailed information about entities, relationships, and business processes is extracted from the domain model, including the attribute definitions and constraints of entities, the association types of relationships, and the business actions of business processes and their execution order, providing comprehensive business information for subsequent code generation. Business rules are identified and converted into executable business logic methods, including input parameter definitions, conditional judgment logic, exception handling mechanisms, and return value design, ensuring that business rules can be accurately implemented in the code. According to the syntax specifications and functional characteristics of the target framework, the business logic methods are mapped to the code structure of the target framework, including the use of annotations, class inheritance relationships, interface implementations, and calling methods of framework-specific components, ensuring that the generated code meets the requirements of the target framework and improving the portability and compatibility of the code. Finally, an executable code module containing entity classes, business logic classes, and data persistence configuration is generated. Each module corresponds to one or more business capability units, making the code structure clear and easy to maintain and expand.

[0018] As a further limitation of the technical solution of the present invention, step S4 specifically includes: Calculating the cohesion of the executable code module, where the module cohesion is obtained by calculating the call frequency and data sharing degree between the business capability units in the module; When the cohesion falls below a preset threshold, module splitting is automatically performed: Identify a highly coupled subset based on the coupling degree analysis of business capability units; wherein the highly coupled subset consists of business capability units with a coupling degree greater than a coupling degree threshold; Split highly coupled subsets into independent distributed code modules according to business boundaries; Generate complete microservice architecture components for each distributed code module; Recalculate the cohesion of each distributed code module after splitting; iterate until the cohesion of all modules reaches the preset threshold.

[0019] By calculating the cohesion of executable code modules, the rationality of the module's internal structure can be accurately assessed. When the cohesion falls below a preset threshold, module splitting is automatically performed. Based on the coupling analysis of business capability units, highly coupled subsets are identified and then split into independent distributed code modules according to business boundaries. A complete microservice architecture component is generated for each distributed code module, ensuring that the split modules have high cohesion and low coupling. The cohesion of each split distributed code module is recalculated and iterated until the cohesion of all modules reaches the preset threshold. This ensures the rationality of the structure of the resulting code modules, improves the maintainability and scalability of the code, and reduces system complexity.

[0020] As a further limitation of the technical solution of the present invention, in step S4, the step of calculating the module cohesion of the executable code module includes: Use static code analysis tools to extract the call relationships between business capability units within the executable code module, build a call graph, and record the call relationships of each business capability unit; extract access to variables, data structures, or database tables, build a data flow graph, and record the data sharing relationships between each business capability unit; For each business capability unit i in the module, count the number of times it calls other business capability units, and normalize the number of calls to get the call frequency ; Count the number of times data is shared between business capability units and the type and quantity of data shared; Evaluate the importance of shared data in business logic through code comments, business rules, or domain knowledge graphs, and assign a weight value to the importance of shared data; Analyze the specific ways of data sharing and assign a scoring value to different sharing methods; The data sharing score is calculated by comprehensively considering the sharing frequency, sharing scope, sharing importance and sharing method; The cohesion of each module is calculated based on the calling frequency and data sharing score.

[0021] Static code analysis tools are used to extract the call relationships and data sharing between business capability units within executable code modules, constructing call graphs and data flow diagrams, providing detailed data support for calculating module cohesion. The number of calls to business capability units is counted and normalized. The number, type, and amount of shared data are counted. The importance of shared data in the business logic is assessed and weighted. Data sharing methods are analyzed and assigned scores. Taking these factors into account, a data sharing score is calculated, providing a comprehensive and accurate assessment of the degree of data sharing within the module. Finally, the cohesion of each module is calculated based on the call frequency and data sharing score, providing a scientific basis for module optimization.

[0022] As a further limitation of the technical solution of the present invention, data sharing score:

[0023] Module cohesion:

[0024] Where, is the weight coefficient, is the sharing frequency score, is the range score of the shared data, is the importance score of the shared data, is the score of sharing method; is the executable code module to be evaluated, For business capability units, is the call frequency, Data sharing score, is the call frequency weight coefficient, is the data sharing weight coefficient, The total number of business capability units in the module.

[0025] Formulas for calculating data sharing scores and module cohesion are presented. By assigning weight coefficients to different factors and comprehensively considering factors such as sharing frequency, sharing scope, sharing importance, and sharing methods, data sharing scores and module cohesion can be calculated more accurately. These formulas provide a standardized method for calculating module cohesion, ensuring the accuracy and reliability of the calculation results and providing strong support for module optimization.

[0026] In a second aspect, the technical solution of the present invention further provides a business system code automatic generation system, comprising: The requirements parsing module is used to parse natural language requirements documents using a pre-trained natural language processing model, generate structured requirements use cases that include user scenarios, inputs, expected outputs, and business rules, and build a domain model that includes entities, relationships, business rules, and business processes. The domain model is represented by a graph data structure, where nodes represent entities and edges represent relationships between entities. The framework selection module is used to dynamically calculate the optimal system framework through the framework selection scoring algorithm based on the system integration requirements, business feature dimensions and TPS information in the required use case, and obtain the target framework; The code generation module is used to convert the domain model into multiple executable code modules of the target framework according to the business processes and business rules in the domain model; The module optimization module is used to calculate the module cohesion of the executable code module. The module cohesion is obtained by calculating the call frequency and data sharing degree between the business capability units within the module. When the module cohesion is greater than or equal to the set threshold, the current module structure is maintained. Otherwise, the executable code module is automatically split, and distributed code modules are generated according to the coupling degree of the business capability units. The module cohesion is recalculated until the cohesion of all modules is greater than or equal to the set threshold. The code optimization module is used to optimize the generated code modules using static code analysis combined with reinforcement learning.

[0027] This system includes a requirements parsing module, a framework selection module, a code generation module, a module optimization module, and a code optimization module. Each module has a clear division of labor and works collaboratively. The requirements parsing module can accurately parse natural language requirements documents, generate structured requirements use cases and domain models, and provide an accurate requirements basis for subsequent code generation. The framework selection module can dynamically calculate the optimal system framework based on the requirements use cases, improving the system's flexibility and scalability. The code generation module can convert the domain model into an executable code module for the target framework, enabling automatic code generation. The module optimization module can calculate and optimize the cohesion of the executable code module to ensure high cohesion and low coupling of the code. The code optimization module can optimize the generated code using static code analysis combined with reinforcement learning, improving code performance and reliability. Through the collaborative work of various modules, the entire system achieves automatic generation and optimization of business system code, improves development efficiency, reduces the probability of system defects, and better adapts to complex business rules and heterogeneous system integration requirements.

[0028] The beneficial effects of the present invention are that, by parsing natural language requirement documents through a pre-trained natural language processing model, structured requirement use cases are automatically generated and a domain model is constructed, thereby avoiding the tediousness and error-proneness of manual parsing of requirement documents and greatly improving the accuracy and efficiency of requirement understanding. The optimal system framework is dynamically calculated according to the requirement use case, and the most suitable framework can be selected according to actual business needs, thereby improving the flexibility and scalability of the system. The domain model is converted into an executable code module, and by calculating and optimizing the module cohesion, the module is automatically split to generate a distributed code module, ensuring high cohesion and low coupling of the code, and improving the code quality and maintainability. Finally, static code analysis is combined with reinforcement learning to optimize the generated code, which further improves the performance and reliability of the code. Compared with traditional manual coding and code generation tools, this method significantly improves the development efficiency of business system code, reduces the probability of system defects, and can better adapt to complex business rules and heterogeneous system integration requirements. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0030] Figure 1 A schematic flow chart of a method according to an embodiment of the present invention.

[0031] Figure 2 A schematic block diagram of a system according to an embodiment of the present invention. DETAILED DESCRIPTION

[0032] In order to make the purpose, features, and advantages of the present invention more obvious and easy to understand, the technical solutions of the present invention will be clearly and completely described below in conjunction with the drawings in the specific embodiments. Obviously, the embodiments described below are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.

[0033] like Figure 1 As shown, an embodiment of the present invention provides a method for automatically generating a business system code, comprising the following steps: S1. Use a pre-trained natural language processing model to parse natural language requirement documents, generate structured requirement use cases that include user scenarios, inputs, expected outputs, and business rules, and construct a domain model that includes entities, relationships, business rules, and business processes. The domain model is represented as a graph data structure, with nodes representing entities and edges representing relationships between entities. Business rules are the constraints and logical rules defined in the domain model, and entity classes represent key concepts in the business. Business rules can be expressed through entity class methods; state machines can describe business processes through states and transitions. S2. Based on the system integration requirements, business feature dimensions, and TPS information in the required use case, the optimal system framework is dynamically calculated through the framework selection scoring algorithm to obtain the target framework; S3. Based on the business processes and business rules in the domain model, convert the domain model into multiple executable code modules of the target framework. Specifically, JPA annotations, business logic methods, and data persistence configurations for entity classes are generated through a rule-based engine. The rules of the rule engine are defined based on domain knowledge and programming language specifications. S4. Calculate module cohesion for the executable code module. The module cohesion is calculated by calculating the call frequency and data sharing degree between the business capability units within the module. When the module cohesion is greater than or equal to a set threshold, maintain the current module structure. Otherwise, automatically split the executable code module, generate distributed code modules according to the coupling degree of the business capability units, and recalculate the module cohesion until the cohesion of all modules is greater than or equal to the set threshold. S5. Use static code analysis combined with reinforcement learning to optimize the generated code module.

[0034] In some embodiments, in step S1, parsing the natural language requirement document using a pre-trained natural language processing model specifically includes: Perform word segmentation, part-of-speech tagging, and named entity recognition on the requirement documents to extract key information; Use dependency parsing to identify sentence structures and extract business actions and their participants; Perform semantic analysis based on pre-trained natural language processing models to identify user scenarios, inputs, expected outputs, and business rules; and use regular expressions to assist in extracting structured information.

[0035] In some embodiments, in step S1, constructing a domain model including entities, relationships, and business processes specifically includes: Identify business objects and their attributes from requirement documents, and use domain knowledge graphs to assist entity recognition; Based on syntactic analysis and semantic role labeling, the relationship between entities is identified and stored in categories; The business process is decomposed into executable steps through the process deconstruction algorithm, and the dependencies and data flows between the steps are expressed using BPMN.

[0036] The specific process of building a domain model is as follows: Perform text cleaning on the natural language requirement document to remove irrelevant content; use a word segmentation tool to split the document text into words or phrases; use a pre-trained natural language processing model to perform semantic analysis on the requirement document to identify user scenarios; extract the description of the user scenario, including the context and goals of the user operation; extract input conditions and expected output results from the user scenario description through dependency syntactic analysis and semantic role labeling; use a pre-trained natural language processing model to identify business rules in the requirement document and extract the business rules into a structured form; use named entity recognition technology to identify entities in the requirement document and extract the relationship between entities through dependency syntactic analysis; use a pre-trained natural language processing model to perform semantic analysis on the requirement document to extract the key steps and logical sequence of the business process; integrate the extracted user scenarios, inputs, expected outputs, business rules, entities and relationships into a domain model. In the embodiment of the present invention, the pre-trained natural language processing model adopts the BERT model of the bidirectional encoder based on the Transformer architecture, and the training process adopts existing conventional means.

[0037] In some embodiments, step S2 specifically includes: S21. Extract system integration requirements, business feature dimensions, and TPS information from the use case requirements; S22. Build a candidate framework library and collect benchmark data for each candidate framework, including CPU efficiency score, concurrent connection score (maximum sustainable connection score), latency performance score, and transaction volume per unit time. S23. Calculate the comprehensive evaluation score of each candidate framework using the framework selection scoring algorithm based on the benchmark test data. The calculation formula for the comprehensive evaluation score is as follows:

[0038] Where, Candidate framework, For the j The weight of the indicator, For the framework In the j Score of indicators; j The indicator score includes one of the following: CPU efficiency score, concurrent connection score, latency performance score, and normalized value of transaction volume per unit time; n is the total number of items.

[0039] S24. Select the candidate frame with the highest score as the target frame.

[0040] In some embodiments, in step S3, the step of converting the domain model into multiple executable code modules of the target framework according to the business processes and business rules in the domain model includes: S31. Extract entities, relationships, and business processes from the domain model, where entities include attribute definitions and constraints, relationships include association types between entities, and business processes include business actions and their execution order; S32. Based on the constraints and business processes in the domain model, identify business rules, including data validity rules, business logic rules, and process control rules; S33. Convert the identified business rules into executable business logic methods, including input parameter definition, conditional judgment logic, exception handling mechanism and return value design; S34. Map the business logic methods to the code structure of the target framework according to the syntax specifications and functional characteristics of the target framework, including the use of annotations, class inheritance relationships, interface implementations, and the calling methods of framework-specific components; S35. Based on the adapted code structure, an executable code module is generated, which includes entity classes, business logic classes and data persistence configuration. The entity classes include the JPA annotations of the framework, the business logic classes include the method implementation after the business rules are converted, and the data persistence configuration includes transaction management and database interaction logic. Each executable code module corresponds to one or more business capability units.

[0041] In an embodiment of the present invention, it is first necessary to parse the domain model. The specific steps include: using natural language processing technology to extract entities and their attributes from the domain model, where the attributes include data types and constraints (such as uniqueness and non-nullability); using graph algorithms to analyze the relationship types between entities (such as one-to-one, one-to-many, many-to-many), and generate a relationship mapping table; based on the business process description, extract business actions and their execution sequence, and construct a business process model (such as a BPMN flowchart).

[0042] The steps to identify business rules include: extracting data validity rules (such as field format and value range) from the constraints of the domain model; extracting business logic rules from the business process (such as the order amount must be greater than 0 and the user must be at least 18 years old); and extracting process control rules from the execution order of the business process (such as "orders can only be shipped after successful payment").

[0043] The steps to convert business rules into method logic include: converting data validity rules into input parameter verification methods (such as using annotations such as @Size and @Min); converting business logic rules into conditional judgment methods (such as if-else statements or strategy pattern implementation); and converting process control rules into the calling logic of the state machine or workflow engine.

[0044] The steps to adapt to the target framework include: adding framework-specific annotations to entity classes according to the target framework's annotation specifications (such as Spring Boot's @Entity and @Transactional); encapsulating business logic methods into corresponding classes (such as UserService and OrderRepository) according to the target framework's class design pattern (such as the Repository pattern); and configuring data persistence logic (such as save() and findById() methods) according to the target framework's database interaction method (such as JPA's CrudRepository).

[0045] The steps of generating the code module include: generating entity class code, including framework annotations (such as @Table(name="users")), field definitions and relationship mappings (such as @OneToMany); generating business logic class code, including methods after business rule conversion (such as validateOrder(), calculateDiscount()); generating data persistence configuration code, including transaction management annotations (such as @Transactional) and database connection configuration (such as JPA parameters in application.yml).

[0046] Here, the JPA annotations for the generated entity classes include: Add @Entity annotation to the entity class to identify the class as a JPA entity; Add @Table annotation to the entity class and specify the database table name; Add @Column annotation to the field and specify the database column name; For the primary key field, add the @Id annotation and, if necessary, the @GeneratedValue annotation. For foreign key relationship fields, add annotations such as @ManyToOne and @OneToMany to configure the relationship between entities.

[0047] Generating business logic methods includes: generating standard getter and setter methods; generating validation methods based on business rules, such as canWithdraw(); and implementing a defensive copy mechanism for collection class fields to ensure data security.

[0048] The generating of data persistence configuration code includes: generating data access object (DAO) or repository code for operating the database; generating data source configuration code to configure database connection information; generating relationship configuration code between entities, such as @ManyToOne, @OneToMany and other annotations.

[0049] In some embodiments, step S4 specifically includes: S41. Calculate the cohesion of the executable code module, where the module cohesion is obtained by calculating the call frequency and data sharing degree between business capability units within the module; S42. When the cohesion is lower than the preset threshold, module splitting is automatically performed: S43. Identify a high coupling subset based on the business capability unit coupling analysis; wherein the high coupling subset is composed of business capability units with a coupling degree greater than a coupling degree threshold; S44. Split the highly coupled subsets into independent distributed code modules according to business boundaries; S45. Generate a complete microservice architecture component for each distributed code module; S46. Recalculate the cohesion of each distributed code module after splitting; iterate until the cohesion of all modules reaches a preset threshold.

[0050] It should be noted here that the steps for calculating module cohesion for an executable code module include: S411. Use static code analysis tools to extract the call relationships between business capability units within the executable code module, construct a call graph, and record the call relationships of each business capability unit; extract access to variables, data structures, or database tables, construct a data flow graph, and record the data sharing relationships between each business capability unit; S412: For each business capability unit i in the module, count the number of times it calls other business capability units, and normalize the number of calls to obtain the call frequency. ; (Divide the number of calls by the highest number of calls in the module to get the call frequency); S413. Count the number of times data is shared between business capability units and the type and quantity of the shared data; S414. Evaluate the importance of shared data in business logic through code annotations, business rules, or domain knowledge graphs, and assign a weight value to the importance of the shared data; S415, analyzing specific data sharing methods and assigning a scoring value to different sharing methods; S416. Calculate the data sharing score by comprehensively considering the sharing frequency, sharing scope, sharing importance and sharing method; S417. Calculate the cohesion of each module based on the call frequency and data sharing score.

[0051] Here, the data sharing score:

[0052] Module cohesion:

[0053] Where, is the weight coefficient, is the sharing frequency score, is the range score of the shared data, is the importance score of the shared data, is the score of sharing method; is the executable code module to be evaluated, For business capability units, is the call frequency, Data sharing score, is the call frequency weight coefficient, is the data sharing weight coefficient, The total number of business capability orders in the module.

[0054] It should be further explained that the sharing frequency score reflects the frequency of calls between business capability units. The process of obtaining the sharing frequency score is as follows: The static code analysis tool is used to extract the call relationship between each business capability unit in the module and count the number of calls. Different scoring intervals are defined based on the number of calls. The specific implementation of the present invention is as follows: Call count > 100 times / hour: score 10 50 calls / hour < calls ≤ 100 calls / hour: score 8 20 calls / hour < Number of calls ≤ 50 calls / hour: Score 6 10 calls / hour < Number of calls ≤ 20 calls / hour: Score 4 Number of calls ≤ 10 times / hour: score 2.

[0055] The scope score of shared data reflects the types and quantity of shared data between business capability units. Here, the process of obtaining the scope score of shared data is as follows: Use static code analysis tools to extract the data types and quantities shared between business capability units within the module. Define different scoring intervals based on the types and quantities of shared data. Specifically, Shared data types > 5, shared data quantity > 10: Score 10 3 < shared data types ≤ 5, 5 < number of shared data ≤ 10: Score 8 1 type < ≤ 3 types of shared data, 1 item < ≤ 5 items of shared data: Score 6 Shared data type = 1, shared data quantity = 1: score 4.

[0056] The importance score of shared data reflects the criticality of shared data in the business logic. The process of obtaining the importance score of shared data is as follows: Evaluate the importance of shared data through code comments, business rules, or domain knowledge graphs. Define different scoring values ​​based on the importance of shared data. Specifically: Core data (such as order amount, user permissions): score 10 Important data (such as user information, order status): Rating 8 Auxiliary data (such as log information, audit data): Score 6 Temporary data (such as cached data): Score 4.

[0057] The scoring of the sharing method reflects the specific mechanism for sharing data between business capability units. The process of obtaining the scoring of the sharing method is as follows: Use static code analysis tools to extract the specific ways in which data is shared between business capability units within a module. Define different scoring values ​​based on the sharing methods. Specifically: Direct access to shared variables: Score 6 Passing via method parameters: Rating 8 Sharing via middleware or database: Score 10.

[0058] In an embodiment of the present invention, module splitting includes: using a community discovery algorithm to identify subsets of highly coupled business capability units; and generating a complete microservice architecture including entity classes, a business logic layer, and a data access layer for each subset.

[0059] The inter-module communication mechanism includes: Synchronous call: Feign-based REST client interface; Asynchronous communication: event-driven architecture based on Kafka; Data consistency: distributed transaction management configuration.

[0060] Specifically, the iterative optimization process includes: Recalculate the cohesion of the split sub-modules; Perform a second split on modules that still do not meet the threshold requirements; Dynamically adjust the split granularity until all modules meet the standards.

[0061] In some embodiments, static code analysis combined with reinforcement learning is used to optimize the generated code, and the specific steps include: S61. Use static code analysis tools to analyze the generated code and detect potential problems in the code; S62. Classify the detected problems into different categories and assign a priority to each problem based on the severity and impact of the problem; S63. Build a reinforcement learning model and define the state space, action space, and reward function. S64. Define a series of optimization operations, including code formatting, performance optimization, security enhancement, and readability improvement; S65. The reinforcement learning model selects an optimization operation based on the current code state, evaluates the optimization effect after executing the optimization operation, adjusts the reward value based on the optimization effect, and updates the policy network of the reinforcement learning model; the reward function of the reinforcement learning model comprehensively considers optimization effects such as performance improvement, code quality improvement, security enhancement, and readability improvement.

[0062] S66. Use static code analysis tools to reanalyze the optimized code to verify whether the optimization operation effectively solves the previously detected problems; static code analysis tools include SonarQube, Checkstyle, PMD, etc., which are used to detect potential problems in the code, including syntax errors, coding style issues, performance issues, security issues, etc.

[0063] S67. Output the optimized code as the final version and generate an optimization report to record the optimization operation and its effect.

[0064] Optimization operations include but are not limited to code formatting, loop optimization, object pooling, prevention of SQL injection, XSS attacks, variable naming, and comment addition.

[0065] like Figure 2 As shown, an embodiment of the present invention further provides a business system code automatic generation system, including: The requirements parsing module is used to parse natural language requirements documents using a pre-trained natural language processing model, generate structured requirements use cases that include user scenarios, inputs, expected outputs, and business rules, and build a domain model that includes entities, relationships, business rules, and business processes. The domain model is represented by a graph data structure, where nodes represent entities and edges represent relationships between entities. The framework selection module is used to dynamically calculate the optimal system framework through the framework selection scoring algorithm based on the system integration requirements, business feature dimensions and TPS information in the required use case, and obtain the target framework; The code generation module is used to convert the domain model into multiple executable code modules of the target framework according to the business processes and business rules in the domain model; The module optimization module is used to calculate the module cohesion of the executable code module. The module cohesion is obtained by calculating the call frequency and data sharing degree between the business capability units within the module. When the module cohesion is greater than or equal to the set threshold, the current module structure is maintained. Otherwise, the executable code module is automatically split, and distributed code modules are generated according to the coupling degree of the business capability units. The module cohesion is recalculated until the cohesion of all modules is greater than or equal to the set threshold. The code optimization module is used to optimize the generated code using static code analysis combined with reinforcement learning.

[0066] In some embodiments, the demand parsing module includes: Text preprocessing unit, used to perform word segmentation, part-of-speech tagging, and named entity recognition on the requirement document to extract key information; Semantic analysis unit, which uses dependency parsing to identify sentence structure, extract business actions and their participants, and perform semantic analysis based on a pre-trained natural language processing model to identify user scenarios, inputs, expected outputs, and business rules; The structured information extraction unit is used to use regular expressions to assist in extracting structured information.

[0067] In some embodiments, the demand parsing module further includes: Entity recognition unit, used to identify business objects and their attributes from requirement documents, using domain knowledge graphs to assist entity recognition; Relationship recognition unit, which is used to identify and classify relationships between entities based on syntactic analysis and semantic role labeling; The business process modeling unit is used to decompose business processes into executable steps through the process deconstruction algorithm and use BPMN to represent the dependencies and data flows between steps.

[0068] In some embodiments, the framework selection module includes: Requirements extraction unit, used to extract system integration requirements, business feature dimensions and TPS information from demand use cases; The candidate framework evaluation unit is used to build a candidate framework library and collect benchmark data for each candidate framework, including CPU efficiency score, concurrent connection score, latency performance score, and transaction volume per unit time; A scoring calculation unit, used to calculate the comprehensive evaluation score of each candidate framework using the framework selection scoring algorithm based on the benchmark test data; The frame selection unit is used to select the candidate frame with the highest score as the target frame.

[0069] In the scoring calculation unit of the framework selection module, the calculation formula for the comprehensive evaluation score is as follows:

[0070] Where, Candidate framework, For the j The weight of the indicator, For the framework In the j Score of indicators; jThe indicator score includes one of the following: CPU efficiency score, concurrent connection score, latency performance score, and normalized value of transaction volume per unit time; n is the total number of items.

[0071] In some embodiments, the code generation module includes: The domain model extraction unit is used to extract entities, relationships, and business processes from the domain model. Entities include attribute definitions and constraints, relationships include association types between entities, and business processes include business actions and their execution order. Business rule identification unit, used to identify business rules based on the constraints and business processes in the domain model, including data validity rules, business logic rules, and process control rules; Business logic conversion unit, used to convert identified business rules into executable business logic methods, including input parameter definition, condition judgment logic, exception handling mechanism and return value design; The code structure mapping unit is used to map business logic methods to the code structure of the target framework according to the syntax specifications and functional characteristics of the target framework, including the use of annotations, class inheritance relationships, interface implementations, and the calling methods of framework-specific components; The code module generation unit is used to generate an executable code module containing entity classes, business logic classes and data persistence configuration based on the adapted code structure. The entity class contains the JPA annotations of the framework, the business logic class contains the method implementation after the business rule conversion, and the data persistence configuration contains transaction management and database interaction logic. Each executable code module corresponds to one or more business capability units.

[0072] In some embodiments, the module optimization module includes: A cohesion calculation unit, configured to calculate the cohesion of an executable code module, wherein the module cohesion is obtained by calculating the call frequency and data sharing degree between business capability units within the module; The module splitting unit is used to automatically perform module splitting when the cohesion is lower than the preset threshold, including: A coupling degree analysis subunit, configured to identify a high coupling subset based on the coupling degree analysis of the business capability units, wherein the high coupling subset is composed of business capability units having a coupling degree greater than a coupling degree threshold; The distributed module generation subunit is used to split the highly coupled subsets into independent distributed code modules according to business boundaries and generate a complete microservice architecture component for each distributed code module; The cohesion recalculation subunit is used to recalculate the cohesion of each distributed code module after splitting, and iterate until the cohesion of all modules reaches a preset threshold.

[0073] In some embodiments, the cohesion calculation unit includes: The call relationship analysis subunit is used to use static code analysis tools to extract the call relationship between each business capability unit in the executable code module, build a call graph, and record the call relationship of each business capability unit; The data sharing analysis subunit is used to extract the access status of variables, data structures or database tables, build data flow diagrams, and record the data sharing relationship between each business capability unit; The call frequency calculation subunit is used to count the number of times each business capability unit i calls other business capability units within the module, and normalize the call counts to obtain the call frequency; The shared data statistics sub-unit is used to count the number of times data is shared between business capability units and the type and quantity of shared data; The data importance assessment subunit is used to evaluate the importance of shared data in business logic through code annotations, business rules, or domain knowledge graphs, and assign a weight value to the importance of shared data; Sharing method scoring subunit, used to analyze the specific method of data sharing and assign a scoring value to different sharing methods; The data sharing degree score calculation subunit is used to calculate the data sharing degree score by comprehensively considering the sharing frequency, sharing scope, sharing importance and sharing method; The cohesion calculation subunit is used to calculate the cohesion of each module based on the call frequency and data sharing score.

[0074] Although the present invention has been described in detail with reference to the accompanying drawings and in conjunction with preferred embodiments, the present invention is not limited thereto. Without departing from the spirit and essence of the present invention, persons of ordinary skill in the art may make various equivalent modifications or substitutions to the embodiments of the present invention, and such modifications or substitutions shall be within the scope of the present invention. Any changes or substitutions that can be easily conceived by persons skilled in the art within the technical scope disclosed in the present invention shall be within the scope of protection of the present invention.

Claims

1. A method for automatically generating business system codes, characterized in that: The steps include: S1. Use a pre-trained natural language processing model to parse natural language requirement documents, generate structured requirement use cases that include user scenarios, inputs, expected outputs, and business rules, and build a domain model that includes entities, relationships, business rules, and business processes. The domain model is represented by a graph data structure, where nodes represent entities, edges represent relationships between entities, entity class methods reflect business rules, and entity class state transitions represent business processes. S2. Based on the system integration requirements, business feature dimensions, and TPS information in the required use case, the optimal system framework is dynamically calculated through the framework selection scoring algorithm to obtain the target framework; S3. Convert the domain model into multiple executable code modules of the target framework based on the business processes and business rules in the domain model; S4. Calculating module cohesion for the executable code module, where the module cohesion is obtained by calculating the call frequency and data sharing degree between business capability units within the module; When the module cohesion is greater than or equal to the set threshold, the current module structure is maintained; otherwise, the executable code module is automatically split, and distributed code modules are generated according to the coupling degree of the business capability unit. The module cohesion is recalculated until the cohesion of all modules is greater than or equal to the set threshold. S5. Use static code analysis combined with reinforcement learning to optimize the generated code module.

2. The method for automatically generating business system codes according to claim 1, characterized in that: In step S1, the natural language requirement document is parsed using a pre-trained natural language processing model, specifically including: Perform word segmentation, part-of-speech tagging, and named entity recognition on the requirement documents to extract key information; Use dependency parsing to identify sentence structures and extract business actions and their participants; Perform semantic analysis based on pre-trained natural language processing models to identify user scenarios, inputs, expected outputs, and business rules; and use regular expressions to assist in extracting structured information.

3. The method for automatically generating business system codes according to claim 2, characterized in that: In step S1, a domain model including entities, relationships, and business processes is constructed, specifically including: Identify business objects and their attributes from requirement documents, and use domain knowledge graphs to assist entity recognition; Based on syntactic analysis and semantic role labeling, the relationships between entities are identified and stored in categories; The business process is decomposed into executable steps through the process deconstruction algorithm, and the dependencies and data flows between the steps are expressed using BPMN.

4. The method for automatically generating business system codes according to claim 3, characterized in that: Step S2 specifically includes: Extract system integration requirements, business feature dimensions and TPS information from demand use cases; Build a candidate framework library and collect benchmark data for each candidate framework, including CPU efficiency score, concurrent connection score (maximum sustainable connection score), latency performance score, and transaction volume per unit time; Calculate the comprehensive evaluation score of each candidate framework using the framework selection scoring algorithm based on the benchmark test data; The candidate frame with the highest score is selected as the target frame.

5. The method for automatically generating business system codes according to claim 4, characterized in that: The calculation formula for the comprehensive evaluation score is as follows: Where, Candidate framework, For the j The weight of the indicator, For the framework In the j Score of indicators; j The indicator score includes one of the following: CPU efficiency score, concurrent connection score, latency performance score, and normalized value of transaction volume per unit time; n is the total number of items.

6. The method for automatically generating business system codes according to claim 4, characterized in that: In step S3, the steps of converting the domain model into multiple executable code modules of the target framework according to the business processes and business rules in the domain model include: Extract entities, relationships, and business processes from the domain model. Entities include attribute definitions and constraints, relationships include the types of associations between entities, and business processes include business actions and their execution order. Based on the constraints and business processes in the domain model, identify business rules, including data validity rules, business logic rules, and process control rules; Convert the identified business rules into executable business logic methods, including input parameter definition, conditional judgment logic, exception handling mechanism and return value design; Map business logic methods to the target framework's code structure based on its syntax and functional characteristics, including annotation usage, class inheritance, interface implementation, and how to call specific framework components. Based on the adapted code structure, an executable code module is generated, which includes entity classes, business logic classes and data persistence configuration. The entity classes include the JPA annotations of the framework, the business logic classes include the method implementation after the business rules are converted, and the data persistence configuration includes transaction management and database interaction logic. Each executable code module corresponds to one or more business capability units.

7. The method for automatically generating business system codes according to claim 6, characterized in that: Step S4 specifically includes: Calculating the cohesion of the executable code module, where the module cohesion is obtained by calculating the call frequency and data sharing degree between the business capability units in the module; When the cohesion falls below a preset threshold, module splitting is automatically performed: Identify a highly coupled subset based on the coupling degree analysis of business capability units; wherein the highly coupled subset consists of business capability units with a coupling degree greater than a coupling degree threshold; Split highly coupled subsets into independent distributed code modules according to business boundaries; Generate complete microservice architecture components for each distributed code module; Recalculate the cohesion of each distributed code module after splitting; iterate until the cohesion of all modules reaches the preset threshold.

8. The method for automatically generating business system codes according to claim 7, characterized in that: In step S4, the step of calculating the module cohesion of the executable code module includes: Use static code analysis tools to extract the call relationships between business capability units within the executable code module, build a call graph, and record the call relationships of each business capability unit; extract access to variables, data structures, or database tables, build a data flow graph, and record the data sharing relationships between each business capability unit; For each business capability unit i in the module, count the number of times it calls other business capability units, and normalize the number of calls to get the call frequency ; Count the number of times data is shared between business capability units and the type and quantity of data shared; Evaluate the importance of shared data in business logic through code comments, business rules, or domain knowledge graphs, and assign a weight value to the importance of shared data; Analyze the specific ways of data sharing and assign a scoring value to different sharing methods; The data sharing score is calculated by comprehensively considering the sharing frequency, sharing scope, sharing importance and sharing method; The cohesion of each module is calculated based on the calling frequency and data sharing score.

9. The method for automatically generating business system codes according to claim 8, characterized in that: Data sharing score calculation formula: Module cohesion calculation formula: Where, is the weight coefficient, is the sharing frequency score, is the range score of the shared data, is the importance score of the shared data, is the score of sharing method; is the executable code module to be evaluated, For business capability units, is the call frequency, Data sharing score, is the call frequency weight coefficient, is the data sharing weight coefficient, The total number of business capability units in the module.

10. A business system code automatic generation system, characterized in that: include: The requirements parsing module is used to parse natural language requirements documents using a pre-trained natural language processing model, generate structured requirements use cases that include user scenarios, inputs, expected outputs, and business rules, and build a domain model that includes entities, relationships, business rules, and business processes. The domain model is represented by a graph data structure, where nodes represent entities and edges represent relationships between entities. The framework selection module is used to dynamically calculate the optimal system framework through the framework selection scoring algorithm based on the system integration requirements, business feature dimensions and TPS information in the required use case to obtain the target framework; The code generation module is used to convert the domain model into multiple executable code modules of the target framework according to the business processes and business rules in the domain model; A module optimization module is used to calculate the module cohesion of the executable code module, where the module cohesion is obtained by calculating the call frequency and data sharing degree between the business capability units in the module; When the module cohesion is greater than or equal to the set threshold, the current module structure is maintained; otherwise, the executable code module is automatically split, and distributed code modules are generated according to the coupling degree of the business capability unit. The module cohesion is recalculated until the cohesion of all modules is greater than or equal to the set threshold. The code optimization module is used to optimize the generated code modules using static code analysis combined with reinforcement learning.