Code generation method and device based on AI, computer equipment and storage medium
By analyzing business demands to generate enterprise-specific code frameworks, this method addresses the inefficiencies of existing AI tools, enhancing code generation efficiency and maintainability.
Patent Information
- Application Number
- CN202510390043.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-31
- Publication Date
- 2025-07-15
AI Technical Summary
Existing AI code generation tools cannot generate code that meets enterprise specifications based on the specific needs of the enterprise, resulting in a large amount of manual intervention when using AI tools, which cannot effectively improve R&D efficiency.
By analyzing and defining data models, business needs are transformed into data structures, a code knowledge base is built and business needs are matched, missing functional modules are identified, business processes are mapped to technical service orchestration, basic code frameworks are generated, and code is optimized.
It realizes efficient code generation and optimization, improves development efficiency, shortens product launch cycle, enhances market competitiveness, and ensures seamless connection between business logic and technology, and the readability and maintainability of code.
Smart Images

Figure CN120315692A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and particularly to an AI-based code generation method, apparatus, computer device, and storage medium. Background Art
[0002] With the deepening of enterprise digital transformation, software R & D has become an important part of the core competitiveness of enterprises. However, in the actual software R & D process, enterprises often face many challenges in the combination of knowledge management and AI technology. At present, although enterprises have accumulated a certain knowledge base, in actual applications, the utilization rate of these knowledge bases is low, and their value cannot be fully exerted. Especially in the context of the rapid development of current AI technology, the model reasoning ability of AI has not been fully combined with the existing business capabilities of enterprises, resulting in enterprises being unable to effectively use AI technology to improve R & D efficiency.
[0003] The application of existing AI tools in the software engineering process still has significant limitations. These tools usually lack systematic integration and are difficult to deeply integrate with the business characteristics, development specifications, and engineering processes of enterprises. For example, existing AI code generation tools can only provide general code capabilities and cannot generate code that meets enterprise specifications according to the specific needs of enterprises. This general AI capability is difficult to meet the personalized needs of enterprises, resulting in enterprises still needing to invest a large amount of manual intervention when using AI tools and being unable to truly improve R & D efficiency. Summary of the Invention
[0004] To solve the above technical problems, the present invention provides an AI-based code generation method, which adopts the following technical solutions, including:
[0005] Analyze and define the data model, and convert the business requirements into data structures;
[0006] Construct a code knowledge base, match the business requirements with the code knowledge base, and identify the missing function modules in the code knowledge base;
[0007] According to the missing function modules, identify the process logic in the business requirements, and map the business process to technical service orchestration;
[0008] Generate a basic code framework according to the mapping result of the business process to technical service orchestration;
[0009] Generate the implementation code of the business service according to the basic code framework, serialize the business process into executable code, and generate the code for interacting with the user interface;
[0010] Optimize the generated code.
[0011] Preferably, the steps of analyzing and defining a data model to transform business requirements into a data structure specifically include:
[0012] Define the data model using UML, where the data model includes entity classes, attributes, and relationship elements;
[0013] Construct a data model parser, and use the defined data model to transform the business requirements into a data structure recognizable by a computer.
[0014] Preferably, the steps of constructing a code knowledge base, matching the business requirements with the code knowledge base, and identifying missing functional modules in the code knowledge base specifically include:
[0015] Obtain historical code and construct a code knowledge base;
[0016] Match the business requirements with the constructed code knowledge base;
[0017] Based on the matching result of the business requirements and the code knowledge base, identify the missing functional modules in the code knowledge base.
[0018] Preferably, the steps of identifying the process logic in the business requirements according to the missing functional modules and mapping the business process to technical service orchestration specifically include:
[0019] Identify each step in the business requirements, and use a sequence labeling model to mark the process steps in the business requirements;
[0020] Based on the missing functional modules, map the business process to technical service orchestration.
[0021] Preferably, the steps of generating a basic code framework according to the mapping result from the business process to technical service orchestration specifically include:
[0022] Create a project structure according to the mapping result from the business process to technical service orchestration;
[0023] According to the project structure, generate business object code through the data model;
[0024] Generate a basic code framework according to the business object code.
[0025] Preferably, the steps of generating implementation code for business services according to the basic code framework, serializing the business process into executable code, and generating code for interacting with the user interface specifically include:
[0026] According to the basic code framework, define service interfaces through service orchestration, and transform the service steps in the orchestration into interface methods;
[0027] Serialize the business process into executable code;
[0028] Generate code for interacting with the user interface and perform user interface integration.
[0029] Preferably, the step of optimizing the generated code specifically includes:
[0030] Perform static code checking;
[0031] Automatically create test cases for the code after static code checking;
[0032] Test the code through the test cases to optimize the running efficiency of the generated code.
[0033] To solve the above technical problems, the present invention also provides an AI-based code generation device, which adopts the following technical solutions, including:
[0034] An analysis and definition module for analyzing and defining data models and converting business requirements into data structures;
[0035] A matching and recognition module for constructing a code knowledge base, matching the business requirements with the code knowledge base, and identifying missing functional modules in the code knowledge base;
[0036] A mapping module for identifying the process logic in the business requirements according to the missing functional modules and mapping the business process to technical service orchestration;
[0037] A basic code framework generation module for generating a basic code framework according to the mapping result of the business process to technical service orchestration;
[0038] A code generation module for generating implementation code for business services according to the basic code framework, serializing the business process into executable code, and generating code for interacting with the user interface;
[0039] An optimization module for optimizing the generated code.
[0040] To solve the above technical problems, the present invention also provides a computer device, which adopts the following technical solutions, including a memory and a processor. Computer-readable instructions are stored in the memory, and when the processor executes the computer-readable instructions, the steps of the above AI-based code generation method are implemented.
[0041] To solve the above technical problems, the present invention also provides a computer-readable storage medium, which adopts the following technical solutions. Computer-readable instructions are stored on the computer-readable storage medium, and when the computer-readable instructions are executed by a processor, the steps of the above-described AI-based code generation method are implemented.
[0042] Compared with the prior art, the present invention mainly has the following beneficial effects:
[0043] (1) Analyzing and defining the data model is the cornerstone, which ensures that business requirements are accurately transformed into data structures, laying a solid foundation for subsequent development;
[0044] (2) Building a code knowledge base and matching business requirements can quickly identify and fill the functional gaps in the knowledge base, avoiding the cumbersome work of starting from scratch;
[0045] (3) According to the missing functional modules, analyze the process logic of business requirements and map these processes to technical service orchestration. This process not only optimizes service composition but also ensures seamless docking between business logic and technical implementation;
[0046] (4) Based on the mapping results from business processes to technical service orchestration, the generated basic code framework not only conforms to business logic but also is easy to expand and maintain. On this basis, further generate the implementation code of business services, serialize complex business processes into clear and executable code, and at the same time generate code for interacting with the user interface, greatly improving the user experience;
[0047] (5) Optimize the generated code, which not only improves the running efficiency of the code but also enhances the readability and maintainability of the code;
[0048] (6) It has the advantages of high efficiency, accuracy, easy expansion, etc., can improve development efficiency, shorten the product launch cycle, and enhance market competitiveness. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] To more clearly illustrate the solutions in the present invention, the following will briefly introduce the drawings required for the description of the embodiments of the present invention. Obviously, the following-described drawings are some embodiments of the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0050] Figure 1 is a flowchart of an embodiment of the AI-based code generation method of the present invention;
[0051] Figure 2 is a schematic diagram of the data model used in the AI-based code generation method of the present invention;
[0052] Figure 3 It is a schematic diagram of the detailed design of the interface used in the AI-based code generation method of the present invention;
[0053] Figure 4 It is a schematic diagram of the implementation of the method logic enhanced by AI used in the AI-based code generation method of the present invention;
[0054] Figure 5 It is a schematic diagram of the structure of an embodiment of the AI-based code generation device of the present invention;
[0055] Figure 6 It is a schematic diagram of the structure of an embodiment of the computer device of the present invention. Detailed implementation manners
[0056] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those of ordinary skill in the technical field to which this invention belongs; the terms used in the specification of this application are only for the purpose of describing specific embodiments and are not intended to limit the present invention; the terms "including" and "having" and any variations thereof in the specification and claims of the present invention and the above drawings are intended to cover non-exclusive inclusion. The terms "first", "second", etc. in the specification and claims of the present invention or the above drawings are used to distinguish different objects and not to describe a specific order.
[0057] Reference to "embodiment" herein means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the present invention. The phrase appears in various places in the specification and does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment mutually exclusive with other embodiments. Those skilled in the art will explicitly and implicitly understand that the embodiments described herein can be combined with other embodiments.
[0058] In order to enable those skilled in the art of this technology to better understand the solution of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings.
[0059] It should be noted that the AI-based code generation method provided by the embodiments of the present invention is generally executed by a server / terminal device. Correspondingly, the AI-based code generation device is generally disposed in the server / terminal device.
[0060] It should be understood that the numbers of terminal devices, networks, and servers are merely illustrative. According to actual needs, there can be any number of terminal devices, networks, and servers.
[0061] Embodiment 1
[0062] Please refer to Figure 1, showing a flowchart of an embodiment of the AI-based code generation method of the present invention. The AI-based code generation method includes the following steps:
[0063] Step S1, analyze and define the data model, and convert the business requirements into data structures.
[0064] In this embodiment, the electronic device (such as a server / terminal device) on which the AI-based code generation method runs can receive an AI-based code generation request through a wired connection or a wireless connection. It should be noted that the above wireless connection methods may include, but are not limited to, 3G / 4G / 5G connections, WiFi connections, Bluetooth connections, WiMAXX connections, Zigbee connections, UWB (ultra wideband) connections, and other currently known or future-developed wireless connection methods.
[0065] Specifically, step S1 further includes the steps of:
[0066] S11, use UML to define the data model, and the data model includes entity classes, attributes, and relationship elements.
[0067] The data model is the basis of software development, which defines the data structure and behavior of the system.
[0068] When defining the data model, UML (Unified Modeling Language) provides an efficient and intuitive graphical method, which can clearly show elements such as entity classes, attributes, and relationships.
[0069] Define entity classes through UML class diagrams. These classes represent distinguishable objects in the real world, such as users, products, etc. Each entity class has a unique name and follows the naming convention of UML.
[0070] Define attributes for each entity class. The attributes describe the characteristics or states of the entity, such as the name and age of a user. In UML, attributes are usually written below the class name, and the data type and visibility are indicated.
[0071] Describe the relationships between entity classes through relationships in UML. These relationships include one-to-one, one-to-many, many-to-many, etc. For example, there may be a one-to-many relationship between a user and an order, indicating that a user can have multiple orders. In a UML class diagram, the relationship is represented by a line and an arrow, and the arrow points to indicate the direction of the relationship.
[0072] By defining the data model through UML, the entity classes, attributes, and relationships can be clearly shown, which helps the development team better understand the business logic and improve the development efficiency and code quality.
[0073] S12. Build a data model parser, and use the defined data model to transform business requirements into a data structure recognizable by a computer.
[0074] A data model parser is a tool specifically used to convert a data model in a certain format into a data structure that a computer can recognize and process.
[0075] Based on the defined data model, develop a parser to parse and transform data, including writing code that can recognize and extract each component in the data model, and the logic to convert these components into a data structure recognizable by a computer.
[0076] After completing the development of the parser, conduct tests to ensure its accuracy and efficiency. Problems found during the testing process need to be repaired and optimized to improve the reliability and performance of the parser.
[0077] Using the defined data model, the data model parser can transform business requirements into a data structure recognizable by a computer. The parser should be able to extract information such as entity classes, attributes, relationships, etc., so as to support subsequent operations such as data storage, processing, and analysis. This transformation process not only improves the degree of automation of data processing, but also ensures the accuracy and consistency of data, providing strong support for business decision-making.
[0078] According to the results of data model parsing, determine the attributes of each entity class. Attributes include data types, constraint conditions, etc.
[0079] Figure 2 It is a schematic diagram of the data model used in the AI-based code generation method of the present invention. As Figure 2 shown, the data model in this embodiment has service names and business domain options, and has options such as module names, model names, and model codes, and can configure tables, specifically involving database attributes, page attributes, tree attributes, and advanced attributes, etc. The data model can be analyzed and defined according to actual needs to transform business requirements into data structures.
[0080] According to the definition of functional modules in the enterprise AI knowledge base, determine the functional modules required for each entity class. Functional modules include basic operations such as addition, deletion, query, and modification.
[0081] Step S2. Build a code knowledge base, match business requirements with the code knowledge base, and identify the missing functional modules in the code knowledge base.
[0082] A code knowledge base refers to a system that centrally stores, manages, and shares various code resources, documents, and development guidelines generated during the software development process. It can include source code, module libraries, API documents, development frameworks, and design patterns, etc. The code knowledge base ensures the historical records and collaborative editing of code through a version control system (such as Git), and at the same time uses search and classification functions to improve the efficiency of information retrieval. Developers can obtain the required resources from it to accelerate the project development process, and it also helps in the inheritance of knowledge and team collaboration.
[0083] In specific implementation, step S2 further includes the steps of:
[0084] S21, Obtain historical code and build a code knowledge base.
[0085] First, the source and scope of the code should be determined, including internal version control systems (such as Git), open-source project platforms, and historical backups, etc. Through these channels, systematically collect relevant code resources through the network. Subsequently, classify and organize the collected code, and file it according to dimensions such as functional modules, programming languages, or project phases to ensure the traceability and understandability of the code. On this basis, use automated tools or scripts to parse the code structure, extract key information (such as function definitions, class relationships, etc.), and generate documents or graphs. At the same time, establish a code search and retrieval mechanism to facilitate developers to quickly locate the required code snippets. Finally, continuously maintain and update the knowledge base, and according to the development of new projects and technological iterations, continuously supplement and improve the code resources to ensure the timeliness and practicality of the knowledge base.
[0086] S22, Match the business requirements with the already built code knowledge base.
[0087] First, analyze the business requirements to clarify the functional requirements, performance requirements, and potential technical constraints. Subsequently, use metadata management tools such as tags, comments, and version control systems to systematically sort out the code knowledge base to ensure the retrievability and reusability of the code. Through modes such as keyword search and semantic matching, quickly locate the code modules or components related to the business requirements. At the same time, consider the scalability and compatibility of the code, and make necessary adjustments and optimizations to the selected code to meet the specific needs of the business. In addition, establish a continuous integration and continuous deployment process to ensure that changes in business requirements can be promptly reflected in the code library, realizing the seamless connection and efficient iteration between business requirements and code knowledge.
[0088] In specific implementation, the set theory method can be used to calculate the difference set between the requirement ability set and the knowledge base ability set to match the business requirements with the already built code knowledge base. The requirement ability set refers to the set of various abilities required to achieve the goal or task, while the knowledge base ability set is the set of various abilities already stored or provided in the knowledge base.
[0089] Both the required capability set and the knowledge base capability set can be regarded as sets composed of several elements (i.e., capabilities). The difference set operation in set theory is defined as the set composed of the remaining elements after removing all elements that also belong to another set from one set.
[0090] The specific calculation process is as follows: First, the difference set operation function of the set can be used, such as the set.difference() method in Python, or the Stream API and the removeAll() method of the collection class in Java, to check each capability element in the required capability set one by one to determine whether it also exists in the knowledge base capability set. For the capability elements that do not exist in the knowledge base capability set, include them in the difference set result.
[0091] Through this method, the business requirements can be accurately matched with the already constructed code knowledge base, and the capability elements that are missing in the required capability set but need to be supplemented in the knowledge base can be calculated, thus providing strong support for the subsequent construction of functional modules or the update of the knowledge base.
[0092] S23. Identify the missing functional modules in the code knowledge base according to the matching result of the business requirements and the code knowledge base.
[0093] In the matching result, if some business requirements cannot find directly corresponding modules in the code knowledge base, it indicates that there are missing functions. For example, if the business requirements emphasize a highly customized data processing process, and the knowledge base only contains general data processing algorithms, then the functional modules optimized for specific business scenarios are missing.
[0094] Furthermore, through the dependency relationship between modules and data flow analysis, potential functional gaps can be revealed. For example, if new business requirements introduce new data types, and the existing storage and retrieval modules in the knowledge base cannot effectively support these data types, it means that the expansion of the storage and retrieval functions is necessary.
[0095] By accurately positioning the missing functions, a solid foundation is laid for the subsequent development and integration work.
[0096] Step S3. Identify the process logic in the business requirements according to the missing functional modules, and map the business process to the technical service orchestration.
[0097] In specific implementation, step S3 further includes the steps:
[0098] S31. Identify each step in the business requirements and use a sequence annotation model to mark the process steps in the business requirements.
[0099] Sequence labeling models are a type of model in natural language processing, used to label each element (such as words) in a text sequence. These labels can be part-of-speech, named entities, semantic roles, etc., aiming to extract useful information from the text. Sequence labeling models can output a sequence of labels, and there is usually certain structural information among these labels, which enables the model to achieve high performance when dealing with sequence labeling problems. Commonly used sequence labeling models include Hidden Markov Model (HMM), Maximum Entropy Model (MaxEnt), and Conditional Random Field (CRF), etc.
[0100] Preprocess the business requirement text, including steps such as word segmentation and stop word removal, to ensure that the sequence labeling model can accurately understand the text content. Select a suitable sequence labeling model, such as Hidden Markov Model (HMM) or Conditional Random Field (CRF), etc., which perform well in dealing with sequence data.
[0101] In the model training stage, use the labeled business requirement data to train the sequence labeling model so that it can learn the labeling rules for different steps. After training, input the business requirement text to be recognized into the sequence labeling model, and the sequence labeling model will label each word according to the learned rules, thereby identifying each process step.
[0102] By adopting a sequence labeling model, control flow extraction can be carried out to extract control structures such as sequence, branch, and loop among business requirement steps. Analyze the timing relationship and conditional expressions among business requirement steps.
[0103] The sequence labeling model can also perform abnormal flow identification to identify the abnormal handling paths in the business process. Analyze conditional statements such as "if... then..." in the requirement document.
[0104] Post-process the output result of the sequence labeling model, convert the labeling result into an easy-to-understand format, such as combining the labeled words or phrases into a complete step description. In this way, each step in the business requirement can be accurately identified, providing strong support for subsequent business process design and optimization.
[0105] S32. Map the business process to technical service orchestration according to the missing functional modules.
[0106] Technical service orchestration refers to the orderly combination and scheduling of a series of technical services according to specific business logics and rules to achieve the automation and efficient execution of complex business processes.
[0107] When faced with missing functional modules, artificial intelligence can help identify and supplement these key components through intelligent analysis and prediction. Based on big data and machine learning algorithms, AI can recommend or automatically generate corresponding technical service modules to fill these functional gaps.
[0108] In the process of mapping business processes to technical service orchestration, AI can perform refined task splitting and process design. Through predefined rules or learned patterns, AI can intelligently determine the execution order and conditions of each technical service to ensure the smooth operation of the entire business process.
[0109] Dependency graph algorithms can also be used for parallelism analysis to identify service steps that can be executed in parallel. Data flow analysis is used to identify tasks with no dependencies.
[0110] Reinforcement learning optimization can also be used to design cache strategies, designing cache strategies for frequently accessed data. Determine cache timing and invalidation strategies based on data access pattern analysis.
[0111] Fault tolerance settings can also be based on pattern matching and code injection, designing retry and compensation mechanisms for key service steps. Automatically inject fault tolerance code according to the service importance level.
[0112] In addition, AI can continuously optimize the technical service orchestration plan. Through real-time monitoring and data analysis, it can discover potential bottlenecks and inefficiencies and propose optimization suggestions. In this way, not only can the execution efficiency of business processes be improved, but also the operating costs can be reduced and the market competitiveness of enterprises can be enhanced.
[0113] Step S4, generate a basic code framework according to the mapping result of the business process to the technical service orchestration.
[0114] Specifically implemented, step S4 further includes the steps:
[0115] S41, create a project structure according to the mapping result of the business process to the technical service orchestration.
[0116] Adopt a parameterized code generation template. Select a template, choose a suitable project template according to the project type. Match the most suitable template based on project metadata.
[0117] Generate a directory, create a standardized source code directory structure. Generate a directory with a layered architecture according to enterprise specifications.
[0118] Build configurations using dependency relationship inference algorithms, generate build scripts and dependency management files. Automatically analyze project requirements to generate appropriate dependency configurations.
[0119] S42, generate business object code through a data model according to the project structure.
[0120] Use a template engine to generate corresponding class definitions for each business entity. Automatically generate class names, attributes, and basic methods based on the data model.
[0121] Use design patterns to instantiate and implement relationships between entities, such as associations, aggregations, etc. Generate reference code according to the relationship type.
[0122] Based on the rule engine to verify the logic, inject the attribute verification logic based on business rules. Extract relevant rules from the business rule library to generate verification code.
[0123] S43. Generate a basic code framework according to the business object code.
[0124] Adopt an ORM framework to integrate and generate DAOs, and generate data access objects for each business entity. Automatically generate CRUD operations according to the persistence design.
[0125] Use the query pattern analysis method to query methods, and generate customized query methods according to business query requirements. Analyze common query patterns to generate optimized query code.
[0126] Perform transaction management based on aspect-oriented programming, and inject appropriate transaction management code. Generate transaction declarations according to the transaction boundaries determined by service orchestration.
[0127] Step S5. Generate the implementation code of the business service according to the basic code framework, serialize the business process into executable code, and generate the code for interacting with the user interface.
[0128] In specific implementation, step S5 further includes the steps:
[0129] S51. According to the basic code framework, define the service interface through service orchestration, and convert the service steps in the orchestration into interface methods.
[0130] Generate service interfaces with contract priority, and define service interfaces according to service orchestration. Convert the service steps in the orchestration into interface methods.
[0131] Use a workflow engine to implement services, combine function modules to implement specific service logic. Assemble function module calls according to the orchestration design.
[0132] Figure 3 It is a schematic diagram of the detailed design of the interface used in the AI-based code generation method of the present invention. As Figure 3As shown in the figure, the functional design specification (service orchestration) is illustrated as follows. Interface coding, interface name, version number of the current interface design, etc. can be designed. For example, the implementation logic of the atomic (functional module) task interface in this embodiment includes: adding a new supplier access and adding an access evaluation workflow. In the process of adding a new supplier access, data verification, determination of whether evaluation is required, and insertion of supplier access data can be designed. The specific interface design can be determined according to the actual project requirements, and the detailed specific content of the interface is not limited here.
[0133] Adapt the code based on the type conversion rules to generate adaptation code between different components. Automatically handle parameter conversion for interface mismatches.
[0134] S52, serialize the business process into executable code.
[0135] Use structured code to generate the control flow, converting structures such as sequence, branch, and loop in the business process into code. Implement the control flow using the structured programming mode.
[0136] Use the state design pattern for state management to generate state management code for the business process. Implement process state tracking based on the state pattern or state machine.
[0137] Perform exception handling based on the exception handling pattern library, injecting the exception handling logic of the business process. Generate try-catch blocks and compensation logic according to the analysis of the exception flow.
[0138] Figure 4 It is a schematic diagram of the method logic implemented by the AI-enhanced method used in the AI-based code generation method of the present invention. As Figure 4 shown, through the logical reasoning ability of AI, identify the semantics and context of service orchestration, and match the functional modules in the existing knowledge base. For example, the existing functional modules in the knowledge base are as follows:
[0139]
[0140] Utilize the code generation ability of AI, combined with development tools, to automatically generate code files according to atomic capabilities and service orchestration, ensuring that the generated code complies with enterprise specifications and improving development efficiency and accuracy.
[0141] Perform logical complementation on the basic code to generate a complete code implementation. As Figure 4As shown, the code generation and matching process involves three functional modules (string verification CheckUtil.ckstring, exception throwing prompt serviceException, blacklist checking supBlacklistService.ckInBlacklist), and these functional modules are all automatically recognized and matched by AI. In this embodiment, deepseek is used as the AI tool, and the analysis results of deepseek are as follows:
[0142] "Save the supplier access data and details, and then start the workflow. I also need to pay attention to exception handling to ensure that all possible errors can be correctly captured and thrown, thereby triggering a transaction rollback. It may be necessary to add new service methods, such as checkCategoryExists, checkinBlacklist, saveEvaluationTemplate, etc., or add this logic to the existing services. Finally, integrate these steps to ensure that the code structure is clear and the logic is correct". Deepseek made the following enhanced method logic implementation as Figure 4 shown.
[0143] S53, Generate the code for interacting with the user interface and perform user interface integration.
[0144] Use the contract-first method to generate API endpoints and generate RESTful API endpoints for front-end interaction. Automatically generate endpoints that conform to the OpenAPI specification according to the service interface.
[0145] Use code generation to perform data binding and generate code for converting front-end and back-end data formats. Automatically generate serialization / deserialization logic based on the type system.
[0146] Based on the publish-subscribe pattern for event handling, generate the back-end processing code corresponding to the user interface events. Map UI events to corresponding service calls.
[0147] Step S6, Optimize the generated code.
[0148] Specifically, step S6 further includes the steps of:
[0149] S61, Perform static code checking.
[0150] Integrate multiple static analysis tools to build a unified code quality evaluation model. Check whether the code complies with the enterprise coding specifications. Use static analysis tools to scan for code specification violations. Analyze metrics such as the cyclomatic complexity of the code. Calculate code metrics and mark the exceeding parts. Check for potential security vulnerabilities in the code. Use SAST tools to identify common security anti-patterns.
[0151] S62 automatically creates test cases for the code after static code checking.
[0152] Adopt an attribute-based test generation approach, combining symbolic execution and fuzz testing methods. Generate basic test cases based on interface contracts. Deduce test inputs and outputs from method preconditions and postconditions.
[0153] Identify the boundary conditions of parameters to generate boundary tests. Use symbolic execution techniques to explore input boundaries.
[0154] Generate test cases for exception scenarios. Analyze the exception handling paths in the code to generate corresponding tests.
[0155] S63 tests the code through test cases to optimize the running efficiency of the generated code.
[0156] Adopt a performance modeling approach for hotspot analysis to predict the performance hotspots of the code. Predict performance bottlenecks based on algorithm complexity and data scale.
[0157] Propose optimization suggestions based on the rule engine, provide performance optimization suggestions such as caching, asynchrony, etc. Match applicable optimization strategies from the optimization pattern library.
[0158] Use the parallel mode recognition method for concurrency optimization: identify concurrency optimization opportunities such as parallel computing. Use data flow analysis to identify parallelizable parts.
[0159] Implementing this embodiment has the following beneficial effects:
[0160] (1) Analyzing and defining the data model is the cornerstone, which ensures that business requirements are accurately transformed into data structures, laying a solid foundation for subsequent development;
[0161] (2) Building a code knowledge base and matching business requirements can quickly identify and fill in the functional gaps in the knowledge base, avoiding the cumbersome work of starting from scratch;
[0162] (3) According to the missing functional modules, analyze the process logic of business requirements and map these processes to technical service orchestration. This process not only optimizes service composition but also ensures seamless docking between business logic and technical implementation;
[0163] (4) Based on the mapping results from business processes to technical service orchestration, the generated basic code framework not only conforms to business logic but is also easy to expand and maintain. On this basis, further generate the implementation code of business services, serialize complex business processes into clear and executable code, and at the same time generate code for interacting with the user interface, greatly improving the user experience;
[0164] (5) Optimize the generated code, which not only improves the running efficiency of the code, but also enhances the readability and maintainability of the code;
[0165] (6) It has advantages such as high efficiency, accuracy, and easy extensibility, which can improve development efficiency, shorten the product launch cycle, and enhance market competitiveness.
[0166] The present invention can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld devices or portable devices, tablet devices, multi-processor systems, microprocessor-based systems, set-top boxes, programmable consumer electronic devices, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, and so on. The present invention can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present invention can also be practiced in a distributed computing environment, where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0167] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through computer-readable instructions. These computer-readable instructions can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above methods. Among them, the aforementioned storage medium can be a non-volatile storage medium such as a magnetic disk, an optical disk, a read-only memory (ROM), etc., or a random access memory (RAM), etc.
[0168] It should be understood that although the steps in the flowchart of the accompanying drawings are displayed sequentially according to the indication of the arrows, these steps do not necessarily need to be executed sequentially according to the indication of the arrows. Unless there is a clear indication in this article, the execution of these steps has no strict order limit, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages. These sub-steps or stages do not necessarily need to be executed at the same moment, but can be executed at different moments, and their execution order does not necessarily need to be sequential, but can be executed alternately or alternately with at least a part of other steps or sub-steps or stages of other steps.
[0169] Embodiment 2
[0170] Further reference Figure 5, as an implementation of the method described above Figure 1 An embodiment of a code generation device based on AI is provided in the present invention. This device embodiment corresponds to Figure 1 the method embodiment shown, and this device can be specifically applied to various electronic devices.
[0171] As Figure 5 shown, the AI-based code generation device 70 in this embodiment includes: an analysis and definition module 71, a matching and recognition module 72, a mapping module 73, a basic code framework generation module 74, a code generation module 75, and an optimization module 76. Among them:
[0172] The analysis and definition module 71 is used to analyze and define the data model and transform the business requirements into data structures;
[0173] The matching and recognition module 72 is used to build a code knowledge base, match the business requirements with the code knowledge base, and identify the missing functional modules in the code knowledge base;
[0174] The mapping module 73 is used to identify the process logic in the business requirements according to the missing functional modules and map the business process to the technical service orchestration;
[0175] The basic code framework generation module 74 is used to generate a basic code framework according to the mapping result from the business process to the technical service orchestration;
[0176] The code generation module 75 is used to generate the implementation code of the business service according to the basic code framework, serialize the business process into executable code, and generate the code for interacting with the user interface;
[0177] The optimization module 76 is used to optimize the generated code.
[0178] Implementing this embodiment has the following beneficial effects:
[0179] (1) Analyzing and defining the data model is the cornerstone, which ensures that business requirements are accurately transformed into data structures, laying a solid foundation for subsequent development;
[0180] (2) Building a code knowledge base and matching business requirements can quickly identify and fill the functional gaps in the knowledge base, avoiding the cumbersome work of starting from scratch;
[0181] (3) According to the missing functional modules, analyzing the process logic of business requirements and mapping these processes to the technical service orchestration not only optimizes the service combination but also ensures the seamless connection between business logic and technical implementation;
[0182] (4) Based on the mapping result from the business process to the technical service orchestration, the generated basic code framework not only conforms to the business logic but is also easy to expand and maintain. On this basis, the implementation code of the business service is further generated, serializing the complex business process into clear and executable code, and at the same time generating the code for interacting with the user interface, greatly enhancing the user experience;
[0183] (5) Optimize the generated code, which not only improves the running efficiency of the code but also enhances the readability and maintainability of the code;
[0184] (6) It has the advantages of high efficiency, precision, easy expansion, etc., can improve the development efficiency, shorten the product launch cycle, and enhance the market competitiveness.
[0185] Embodiment Three
[0186] To solve the above technical problems, the embodiment of the present invention also provides a computer device. Specifically, please refer to Figure 6 , Figure 6 which is the basic structural block diagram of the computer device in this embodiment.
[0187] The above computer device 8 includes a memory 81, a processor 82, and a network interface 83 that are communicatively connected to each other through a system bus. It should be noted that only the computer device 8 with components such as a memory 81, a processor 82, and a network interface 83 is shown in the figure. However, it should be understood that it is not required to implement all the shown components, and more or fewer components can be alternatively implemented. Among them, those skilled in the art of this technology can understand that a computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to a microprocessor, an application specific integrated circuit (ASIC), a field-programmable gate array (FPGA), a digital signal processor (DSP), an embedded device, etc.
[0188] The above computer device can be a desktop computer, a notebook, a palm computer, a cloud server, and other computing devices. The above computer device can perform human-computer interaction with the user through a keyboard, a mouse, a remote control, a touchpad, a voice control device, and other means.
[0189] The above-mentioned memory 81 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (such as SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the above-mentioned memory 81 may be an internal storage unit of the computer device 8, such as the hard disk or memory of the computer device 8. In other embodiments, the above-mentioned memory 81 may also be an external storage device of the computer device 8, such as a plug-in hard disk equipped on the computer device 8, a Smart Media Card (SMC), a Secure Digital (SD) card, a FlashCard, etc. Of course, the above-mentioned memory 81 may also include both the internal storage unit and the external storage device of the computer device 8. In this embodiment, the above-mentioned memory 81 is generally used to store the operating system and various application software installed on the computer device 8, such as computer-readable instructions of the AI-based code generation method. In addition, the above-mentioned memory 81 may also be used to temporarily store various data that have been output or will be output.
[0190] In some embodiments, the above-mentioned processor 82 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips. The processor 82 is generally used to control the overall operation of the computer device 8. In this embodiment, the above-mentioned processor 82 is used to run the computer-readable instructions stored in the above-mentioned memory 81 or process data, such as running the computer-readable instructions of the above-mentioned AI-based code generation method.
[0191] The above-mentioned network interface 83 may include a wireless network interface or a wired network interface, and the network interface 83 is generally used to establish a communication connection between the computer device 8 and other electronic devices.
[0192] Implementing this embodiment has the following beneficial effects:
[0193] (1) Analyzing and defining the data model is the cornerstone, which ensures that business requirements are accurately transformed into data structures, laying a solid foundation for subsequent development;
[0194] (2) Building a code knowledge base and matching business requirements can quickly identify and fill in the functional gaps in the knowledge base, avoiding the cumbersome work of starting from scratch;
[0195] (3) Analyze the process logic of business requirements based on the missing functional modules and map these processes to technical service orchestration. This process not only optimizes service composition but also ensures seamless docking between business logic and technical implementation;
[0196] (4) Based on the mapping results from business processes to technical service orchestration, the generated basic code framework conforms to business logic and is easy to expand and maintain. On this basis, further generate the implementation code for business services, serialize complex business processes into clear and executable code, and at the same time generate code for interacting with the user interface, greatly enhancing the user experience;
[0197] (5) Optimize the generated code, which not only improves the running efficiency of the code but also enhances its readability and maintainability;
[0198] (6) It has the advantages of high efficiency, accuracy, easy expansion, etc., can improve development efficiency, shorten the product launch cycle, and enhance market competitiveness.
[0199] Embodiment 4
[0200] The present invention also provides another implementation manner, that is, to provide a computer-readable storage medium, the computer-readable storage medium stores computer-readable instructions, and the computer-readable instructions can be executed by at least one processor so that the at least one processor executes the steps of the AI-based code generation method as described above.
[0201] Implementing this embodiment has the following beneficial effects:
[0202] (1) Analyzing and defining the data model is the cornerstone, which ensures that business requirements are accurately transformed into data structures, laying a solid foundation for subsequent development;
[0203] (2) Building a code knowledge base and matching business requirements can quickly identify and fill the functional gaps in the knowledge base, avoiding the cumbersome work of starting from scratch;
[0204] (3) Analyze the process logic of business requirements based on the missing functional modules and map these processes to technical service orchestration. This process not only optimizes service composition but also ensures seamless docking between business logic and technical implementation;
[0205] (4) Based on the mapping results from business processes to technical service orchestration, the generated basic code framework conforms to business logic and is easy to expand and maintain. On this basis, further generate the implementation code for business services, serialize complex business processes into clear and executable code, and at the same time generate code for interacting with the user interface, greatly enhancing the user experience;
[0206] (5) Optimize the generated code, which not only improves the running efficiency of the code, but also enhances the readability and maintainability of the code;
[0207] (6) It has advantages such as high efficiency, accuracy, and easy extensibility, which can improve development efficiency, shorten the product launch cycle, and enhance market competitiveness.
[0208] Through the description of the above embodiments, those skilled in the art can clearly understand that the above-described embodiment methods can be implemented by means of software plus a necessary general hardware platform. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions for causing a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods of the various embodiments of the present invention.
[0209] Obviously, the above-described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. The accompanying drawings show preferred embodiments of the present invention, but do not limit the patent scope of the present invention. The present invention can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present invention more thorough and comprehensive. Although the present invention has been described in detail with reference to the foregoing embodiments, for those skilled in the art, they can still modify the technical solutions described in the foregoing specific embodiments, or perform equivalent replacements on some of the technical features. Any equivalent structure directly or indirectly using the content of the specification and drawings of the present invention in other related technical fields is equally within the scope of the patent protection of the present invention.
Claims
1. An AI-based code generation method, characterized in that Including the following steps: Analyze and define the data model, and transform the business requirements into data structures; Build a code knowledge base, match the business requirements with the code knowledge base, and identify the missing functional modules in the code knowledge base; According to the missing functional modules, identify the process logic in the business requirements, and map the business process to the technology service orchestration; Generate a basic code framework according to the mapping result from the business process to the technology service orchestration; According to the basic code framework, generate the implementation code of the business service, serialize the business process into executable code, and generate the code for interacting with the user interface; Optimize the generated code.
2. The AI-based code generation method according to claim 1, wherein The step of analyzing and defining the data model and transforming the business requirements into data structures specifically includes: Use UML to define the data model, and the data model includes entity classes, attributes, and relationship elements; Build a data model parser, and use the defined data model to transform the business requirements into computer-recognizable data structures.
3. The AI-based code generation method according to claim 1, wherein The step of building a code knowledge base, matching the business requirements with the code knowledge base, and identifying the missing functional modules in the code knowledge base specifically includes: Obtain historical code and build a code knowledge base; Match the business requirements with the already built code knowledge base; According to the matching result of the business requirements and the code knowledge base, identify the missing functional modules in the code knowledge base.
4. The AI-based code generation method according to claim 1, wherein The step of identifying the process logic in the business requirements according to the missing functional modules and mapping the business process to the technology service orchestration specifically includes: Identify each step in the business requirements, and use a sequence annotation model to mark the process steps in the business requirements; According to the missing functional modules, map the business process to the technology service orchestration.
5. The AI-based code generation method according to claim 1, wherein The step of generating a basic code framework according to the mapping result from the business process to the technology service orchestration specifically includes: Create a project structure according to the mapping result from the business process to the technology service orchestration; According to the project structure, generate business object code through the data model; Generate a basic code framework according to the business object code.
6. The AI-based code generation method according to claim 1, wherein The step of generating the implementation code of the business service according to the basic code framework, serializing the business process into executable code, and generating the code for interacting with the user interface specifically includes: According to the basic code framework, define service interfaces through service orchestration, and transform the service steps in the orchestration into interface methods; Serialize the business process into executable code; Generate the code for interacting with the user interface and perform user interface integration.
7. The AI-based code generation method according to any one of claims 1 to 6, characterized in that The step of optimizing the generated code specifically includes: Perform static code checking; Automatically create test cases for the code after static code checking; Test the code through the test cases to optimize the running efficiency of the generated code.
8. An AI-based code generation device, characterized in that, Including: An analysis and definition module for analyzing and defining the data model and transforming the business requirements into data structures; A matching and identification module for building a code knowledge base, matching the business requirements with the code knowledge base, and identifying the missing functional modules in the code knowledge base; A mapping module, configured to identify the process logic in the business requirements according to the missing functional modules, and map the business process to technical service orchestration; A basic code framework generation module, configured to generate a basic code framework according to the mapping result from the business process to technical service orchestration; A code generation module, configured to generate the implementation code of the business service according to the basic code framework, serialize the business process into executable code, and generate the code for interacting with the user interface; An optimization module, configured to optimize the generated code.
9. A computer device, characterized in that, It includes a memory and a processor. Computer-readable instructions are stored in the memory. When the processor executes the computer-readable instructions, the steps of the AI-based code generation method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium, characterized in that, Computer-readable instructions are stored on the computer-readable storage medium. When the computer-readable instructions are executed by the processor, the steps of the AI-based code generation method according to any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Code generation method and system based on business requirements
CN120762651A
