Code generation method for processing database files, file processing method and device
Through automated code generation methods, the target requirements configuration files and template methods are used to generate database access objects, file processing classes and scheduling task classes, which solves the problem of low efficiency in database file processing in the existing technology, and realizes efficient database file processing and simplified development process.
Patent Information
- Application Number
- CN202411814717.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-11
- Publication Date
- 2025-03-18
- Estimated Expiration
- 2044-12-11
AI Technical Summary
In the prior art, database file processing is inefficient, and a large amount of redundant and repeated code is required to implement references to database access objects, resulting in unfavorable development and maintenance.
By obtaining the target requirements configuration file in a preset format, using file parsing tool class to obtain the target requirements data, and using template methods to generate database access objects, file processing classes and scheduling task classes based on the data and keywords, realizing automated code generation and database file processing.
It realizes the business requirements of 0-encoded file generation and parsing, improves the efficiency of database file processing, reduces the workload of developers, and simplifies subsequent development, testing and maintenance processes.
Smart Images

Figure CN119292612B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a code generation method for processing database files, a file processing method and a device. Background Art
[0002] When generating a database file from data in a database according to requirements, or storing existing file data into data according to requirements, the existing technology manually encapsulates the code of DAO (Data Access Object) database access objects for a certain table separately, and the amount of code will increase with the increase in the number of tables. If these DAO database access objects are to be referenced, more redundant and repetitive codes are required to implement them, which has low implementation efficiency and is very disadvantageous for subsequent development, testing and maintenance. Summary of the invention
[0003] In view of this, the embodiments of the present application provide a code generation method, a file processing method and a device for processing database files, which can effectively solve the problem of low efficiency of database file processing in the prior art.
[0004] In a first aspect, an embodiment of the present application provides a code generation method for processing a database file, comprising:
[0005] Obtain a target demand configuration file in a preset format, and parse the target demand configuration file using a file parsing tool class to obtain target demand data;
[0006] Generate the code of the database access object corresponding to the target demand configuration file by using a preset code generator using a template method according to the target demand data and the keywords determined based on the target demand data;
[0007] According to the target demand data and the keywords, a file processing class generation method constructed in advance is used to generate a file processing class corresponding to the target demand configuration file using the template method;
[0008] According to the target demand data and the keywords, the template method is adopted to utilize a preset distributed task scheduling platform to generate a scheduling task class corresponding to the target demand configuration file; the scheduling task class is used to start the database file processing task corresponding to the target demand configuration file according to the keyword, so as to obtain a database access object according to the keyword matching, and then interact with the database through the database access object, and to obtain the file processing class according to the keyword matching, and then parse or generate a database file through the file processing class.
[0009] In some embodiments, the step of using a template method and a preset code generator to generate the code of the database access object corresponding to the target demand configuration file according to the target demand data and the keywords determined based on the target demand data includes:
[0010] The codes of the data operation object, the data operation interface and the data operation warehouse in the database access object are respectively generated by using a preset code generator; wherein the data operation object and the corresponding data operation interface corresponding to the target demand configuration file are associated with the corresponding data operation warehouse in the form of parameters; and the data operation warehouse inherits the pre-built warehouse base class;
[0011] The method also includes: when constructing the warehouse base class, taking the data operation object and the data operation interface as parameters, and according to the current business demand logic, expanding the data operation method in the code generator to obtain a data operation extension method corresponding to the data operation object; the data operation extension method is used to operate and maintain the database through the corresponding data operation object and the data operation interface.
[0012] In some embodiments, the code generator is a template code generator in the mybatisplus framework;
[0013] The method of extending the data operation method in the code generator according to the current business demand logic to obtain a data operation extension method corresponding to the data operation object includes:
[0014] Extract common business fields based on each data operation object;
[0015] According to the common business fields and based on the current business demand logic, the data operation method in the service implementation class in the template code generator is extended to obtain the data operation extension method.
[0016] In some embodiments, the target demand configuration file is an Excel file; the target demand data includes a plurality of business fields parsed from the Excel file; the keyword is determined according to a file identifier in the target demand data;
[0017] The using of a preset code generator to respectively generate codes of a data operation object, a data operation interface and a data operation warehouse in the database access object comprises:
[0018] According to the file identifier and access class keyword in the target demand data, the data operation object, the data operation interface and the data operation warehouse class are named respectively using camel case naming method, so that the database access object corresponding to the target demand configuration file is used according to the name when executing the database file processing task;
[0019] According to each business field in the target demand data, the attributes of the data operation object are generated accordingly.
[0020] In some embodiments, the step of generating a scheduling task class corresponding to the target demand configuration file by using the template method and a preset distributed task scheduling platform according to the target demand data and the keyword includes:
[0021] According to the pre-constructed scheduling interface and the file processing type in the target demand data, a generation file scheduling task implementation class or a parsing file scheduling task implementation class and a scheduling task entry class in the scheduling task class are generated, and according to the file identifier and task identifier in the target demand data, the camel case naming method is used to name the scheduling task entry class, the generation file scheduling task implementation class and the parsing file scheduling task implementation class respectively; wherein the keyword is determined according to the file identifier;
[0022] The scheduling task entry class is used to match and call the corresponding scheduling task implementation class according to the file identifier in the target demand data and the file processing type; the generation file scheduling task implementation class is used to match the corresponding file generation implementation class according to the keyword when executing the database file processing task; the parsing file scheduling task implementation class is used to match the corresponding file parsing implementation class according to the keyword when executing the database file processing task;
[0023] The scheduling interface is pre-constructed based on the file processing time in the target demand data and on the distributed task scheduling platform, so as to execute the database file processing task according to the file processing time.
[0024] In some embodiments, the data operation warehouse class includes a file parsing processing warehouse class and a file generation processing warehouse class;
[0025] The method of generating a file processing class corresponding to the target demand configuration file using the template method by using a pre-built file processing class generation method (file generation and parsing processing class method) according to the target demand data and the keyword includes:
[0026] Generate a file generation implementation class and a file parsing implementation class included in the file processing class by using a pre-built file processing class generation method, and name the file generation implementation class and the file parsing implementation class respectively by using camel case naming method according to the file identifier and the corresponding processing class identifier in the target demand data;
[0027] The file generation implementation class depends on the file generation processing warehouse class and inherits the pre-built file generation process base class; the file generation process base class is used to generate a file header, generate file data and upload to a server; the file generation processing warehouse class is used to associate the data operation object and the data operation interface used;
[0028] The file parsing implementation class depends on the file parsing processing warehouse class and inherits the pre-built file parsing process base class; the file parsing process base class is used to implement pre-parsing processing, parsing file data and post-parsing processing; the file parsing processing warehouse class is used to associate the data operation object and the data operation interface used;
[0029] The file parsing processing warehouse class and the file generating processing warehouse class both inherit the pre-determined warehouse base class;
[0030] The method further comprises: when constructing the warehouse base class, encapsulating a common file processing method to generate and parse database files in various forms.
[0031] In a second aspect, an embodiment of the present application provides a database file processing method, including:
[0032] Parsing the target demand configuration file to obtain target demand data; using the keyword matching determined according to the target demand data to start the distributed scheduling task class;
[0033] The scheduling task class obtains a database access object according to the keyword matching, and then interacts with the database through the database access object, and obtains a file processing class according to the keyword matching, and then parses or generates a database file through the file processing class.
[0034] In some embodiments, the scheduling task class includes a generation file scheduling task implementation class, a parsing file scheduling task implementation class, and a scheduling task entry class;
[0035] The file processing class includes a file generation implementation class and a file parsing implementation class;
[0036] The database access object includes a data operation object, a data operation interface and a data operation warehouse;
[0037] The scheduling task class is specifically used for:
[0038] Matching a target scheduling task implementation class in each of the generated file scheduling task implementation classes and each of the parsed file scheduling task implementation classes based on the file processing time in the target demand data by using the scheduling task entry class and the file processing type in the target demand data;
[0039] The target scheduling task implementation class matches the target implementation class in each file generation implementation class and each file parsing implementation class according to the keyword and the file processing type;
[0040] The target implementation class interacts with the database using the database access object that matches the keyword, and performs file processing corresponding to the file processing type to parse or generate a database file.
[0041] In some embodiments, if the target implementation class is a file generation implementation class; the file generation implementation class is used to use the data operation object and the data operation interface used when the file generation processing warehouse class it depends on associates the operation data, and uses the file generation process base class it inherits to generate a file header, generate file data and upload to the server;
[0042] If the target implementation class is the file parsing implementation class; the file parsing implementation class is used to utilize the file parsing processing warehouse class it depends on, the data operation object and the data operation interface used when associating the operation data, and utilize the file parsing process base class it inherits to implement pre-parsing processing, parsing file data and post-parsing processing.
[0043] In a third aspect, an embodiment of the present application provides a terminal device, comprising a processor and a memory, the memory storing a computer program, the processor being used to execute the computer program to implement a code generation method for processing database files provided in the first aspect of the present application to generate code for processing database files, or to execute the computer program to implement a database file processing method provided in the second aspect of the present application to process database files.
[0044] The embodiments of the present application have the following beneficial effects:
[0045] This application can achieve the entire file generation and parsing business needs with zero coding in the true sense. Developers only need to focus on specific business needs and organize the required configuration files for generating or parsing files according to the specifications. In this way, the problem of low efficiency of database file processing in the prior art can be effectively solved. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0047] Figure 1 A flow chart showing a method for generating codes for processing database files according to an embodiment of the present application is shown;
[0048] Figure 2 A flowchart of a database file processing method according to an embodiment of the present application is shown;
[0049] Figure 3 Another flow chart of the code generation method for processing database files according to an embodiment of the present application is shown;
[0050] Figure 4 A schematic diagram of the structure of a code generation device for processing database files according to an embodiment of the present application is shown;
[0051] Figure 5 A flow chart of a database file processing method according to an embodiment of the present application is shown.
[0052] Description of main component symbols:
[0053] 210 - target demand data parsing module; 220 - database access object generation module; 230 - file processing class generation module; 240 - scheduling task class generation module. DETAILED DESCRIPTION
[0054] The technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments.
[0055] The components of the embodiments of the present application generally described and shown in the drawings herein may be arranged and designed in various configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.
[0056] Hereinafter, the terms "including", "having" and their cognates that can be used in various embodiments of the present application are intended only to indicate specific features, numbers, steps, operations, elements, components or a combination of the foregoing items, and should not be understood as first excluding the existence of one or more other features, numbers, steps, operations, elements, components or a combination of the foregoing items or increasing the possibility of one or more features, numbers, steps, operations, elements, components or a combination of the foregoing items. In addition, the terms "first", "second", "third" and the like are only used to distinguish descriptions and cannot be understood as indicating or implying relative importance.
[0057] Unless otherwise defined, all terms (including technical terms and scientific terms) used herein have the same meanings as those generally understood by those skilled in the art to which the various embodiments of the present application belong. The terms (such as those defined in generally used dictionaries) will be interpreted as having the same meanings as the contextual meanings in the relevant technical field and will not be interpreted as having idealized meanings or overly formal meanings unless clearly defined in the various embodiments of the present application.
[0058] In conjunction with the accompanying drawings, some embodiments of the present application are described in detail below. In the absence of conflict, the following embodiments and features in the embodiments can be combined with each other.
[0059] It should be noted that, in this embodiment, EasyExcel is a tool class for excel processing.
[0060] mybatisplus is an enhanced framework based on MyBatis and Spring Boot, designed to simplify daily CRUD operations, data validation, logical deletion, paging and other functions. mybatisplus provides a series of convenient methods that enable developers to quickly build and run complex database operations while maintaining good code quality and maintainability.
[0061] AutoGenerator is a very popular code generator, mainly used to automatically generate Java code based on templates, especially in enterprise projects. By using AutoGenerator, developers can quickly create the project's infrastructure, including data operation objects (Entity), data access interfaces (Mapper, Service, Controller), etc., thus saving a lot of time on code generation and focusing on the development of business logic.
[0062] Data operation objects: automatically generate data operation objects based on database tables and support field-level customization.
[0063] Mapper interface: Automatically generate the corresponding Mapper interface according to the data operation object. In modern software development, especially when using ORM (object-relational mapping) framework, `Mapper` interface is a common design pattern used to decouple database operations from business objects. `Mapper` interface is often used in conjunction with persistence layer frameworks (such as MyBatis, JPA, Hibernate, etc.), providing a concise way to perform database operations while keeping the code clean and maintainable. The main functions of the Mapper interface include: 1) CRUD operations. CRUD operations include query (Select): query data according to conditions; insert (Insert): insert new records into the database; update (Update): update existing records; delete (Delete): delete records. 2) Transaction management; Transaction control: support transaction start, commit and rollback. 3) Parameter binding; Automatic parameter binding: automatically map the attribute values of Java objects to parameters in SQL statements. Manual parameter binding: explicitly specify parameter values in SQL statements. 4) Result mapping; Automatic result mapping: Automatically map query results to Java objects. Manual result mapping: Explicitly define how to map query results to Java objects. 5) Namespace; Namespace isolation: Different `Mapper` interfaces use different namespaces to avoid naming conflicts. 6) Service interface and implementation class: Automatically generate Service interface and corresponding implementation class, including basic CRUD operations.
[0064] A data operation repository is a component or module used to manage and execute database operations in software development. It usually encapsulates CRUD (Create, Read, Update, Delete) operations on the database and provides a unified interface for application calls. The design purpose of the data operation repository is to simplify database access logic and enhance the maintainability and testability of the code.
[0065] The main goal of the template method is to allow subclasses to implement different behaviors of the algorithm while maintaining the algorithm framework. It defines the "skeleton" of an algorithm (the main steps of the algorithm) and leaves some steps to subclasses to implement, allowing subclasses to implement certain steps in different ways without changing the structure of the algorithm. The Template Method pattern includes the following key components: (1: Abstract class or interface: defines the skeleton of an algorithm, containing a template method and other abstract methods or hook methods. (2: Template method: This is the main step of the algorithm, some of which are left empty, waiting for subclasses to implement. (3: Abstract method / hook method: These methods are implemented by subclasses, and they allow subclasses to implement different behaviors of the algorithm. Hook methods are often used to allow subclasses to add additional operations before or after certain specific steps.
[0066] The encapsulation and implementation of database access object codes in the prior art is only to manually encapsulate the DAO database access object according to a table. Once a new table is created, the DAO database access object needs to be manually encapsulated again, and the implementation method is inefficient. At present, there is an urgent need in the art for a method to realize the generation of the whole process code from table building, DAO data access, timed scheduling, data encapsulation, generation or parsing of files. Therefore, the present application provides a code generation method, file processing method and device for processing database files, which can effectively solve the problem of low efficiency of database file processing in the prior art.
[0067] The code generation method for processing database files is described below in conjunction with some specific embodiments.
[0068] Figure 1 A flow chart of a method for generating code for processing a database file according to an embodiment of the present application is shown. Exemplarily, the method for generating code for processing a database file includes the following steps:
[0069] S110, obtaining a target requirement configuration file in a preset format, and using a file parsing tool class to parse the target requirement configuration file to obtain target requirement data.
[0070] Exemplarily, the target demand configuration file is an Excel file; the file parsing tool class is the Excel processing tool class EasyExcel provided by Alibaba, and EasyExcel is used to parse the target demand data in the Excel file.
[0071] For example, by pre-building the code generator entry CodeGenerator. The code generator entry CodeGenerator is used to drive the entire code generation process. For example, build the ExcelReader method, call EasyExcel in the ExcelReader method to parse the Excel file, store the parsed Excel data into memory, and assemble subsequent process parameters. CodeGenerator sets a periodic task to periodically detect whether there is a new requirement configuration file. If a new requirement configuration file is detected, the ExcelReader method is called to parse it.
[0072] Specifically, ExcelReader parses the data in the Excel file into memory and assembles subsequent process parameters. For example, the Excel processing tool class EasyExcel provided by Alibaba is used to parse Excel data.
[0073] EasyExcel input: an excel file prepared in the format of Table 1 (a sheet, sheet1) and Table 2 (including at least one sheet, the sheet name corresponds to the English name of sheet1) in the local path specified by the local project. Output of parsed excel file: assemble the subsequent process parameter CodeParam (that is, parse the details of sheet1 and table 2 into memory, including parsing the data in sheet1 to obtain the java object BaseParams, which includes the database table type, the Chinese name of the database table, the English name of the database table, the file processing type, whether there is a file header, the file separator, whether there is an OK file, the file path and the file processing time, etc. Parse at least one sheet corresponding to Table 2 to obtain the Java object DetailParams, convert the English name of the table buffer_compensate_apply into the camel case naming method CompensationApply as the entity name (the name of the data operation object Entity) for subsequent use, and also convert the specific field names in Table 2 into camel case for subsequent use. DetailParams includes multiple fields, field types and lengths, field comments, whether it is required to be transmitted (whether to upload to the database), etc.
[0074] Exemplarily, the target demand configuration file includes: database table type, database table Chinese name, database table English name, file processing type, whether there is a file header, file separator, whether there is an OK file, file path and file processing time, etc., as shown in Table 1. The database table type includes but is not limited to oracle, mysql and pg, etc.
[0075] Table 1 Target demand profile 1
[0076]
[0077] The target requirement configuration file also includes: multiple fields, field type and length, field annotation, whether it is required to be transmitted (whether to upload to the database), etc. For example, as shown in Table 2, it includes field name, type and length, field annotation, whether it is required to be transmitted, etc.
[0078] Table 2 Target demand profile 2
[0079]
[0080] Furthermore, the method also includes generating table creation statements for each database type according to the target demand configuration file. Exemplarily, the table type, the Chinese name of the table, the English name of the table, and each field in the table are parsed from the excel file to generate table creation statements for each database type. It can be understood that according to the table creation DDL (data definition language) statement syntax specifications of different databases, the table creation statement templates for each database type are encapsulated, and the fields in the table creation statement are implemented using the EasyExcel tool class in java.
[0081] For example, construct table creation statement templates such as ExcelToMySqlGenerator template method, ExcelToOracleGenerator template method, and ExcelToPgGenerator template method, and then call the corresponding table creation statement template according to the table type of the database (for example, the mysql type database corresponds to the ExcelToMySqlGenerator template method) to generate the table creation statement of the corresponding table type, and finally obtain the table creation statement of each database type, and execute the statement to create the table in the underlying configured database. In this way, the applicability of this application can be improved.
[0082] ExcelToMySqlGenerator: According to the excel data, such as the English name of the table in BaseParams, the table type and the specific field information in Table 2, read the Generator of different databases to generate the ddl statements of each database, output them to the specified project directory and execute them. Taking Table 1 and Table 2 as examples, the input of ExcelToMySqlGenerator is: the above-mentioned DetailParams; the output is: generate the ddl statement of the compensation application form (if there are multiple), output to the project directory / res / oracle / ddl / yyyyMMdd / generatorSQL.sql (if it is mysql, the directory is / res / mysql / ddl / yyyyMMdd / generatorSQL.sql. If there are multiple tables, the ddl table creation statements will also be summarized and output to the specified directory file according to the table type. yyyyMMdd is the current date). At the same time, execute the script in the local database to build the corresponding table.
[0083] S120: Generate a code of a database access object corresponding to the target requirement configuration file by using a preset code generator using a template method according to the target requirement data and keywords determined based on the target requirement data.
[0084] Exemplarily, the target demand data includes at least two items of the table type of the database, the Chinese name of the table of the database, the English name of the table of the database, the file processing type, whether there is a file header, a file separator, whether there is an OK file, a file path, a file processing time, and various fields. Preferably, the keyword is determined according to the English name of the table. For example, if the English name of the table is buffer_compensate_apply, the keyword is determined to be CompensateApply.
[0085] For example, the keyword can be determined according to the English name of the table in the target demand data. The database access object can be named according to the keyword.
[0086] S130, according to the target demand data and the keyword, using a pre-built file processing class generation method (file generation and parsing processing class method) and adopting the template method to generate a file processing class corresponding to the target demand configuration file.
[0087] Exemplarily, the file processing class can be named according to the keyword. According to the file processing type in the target demand data, it can be determined to generate multiple types of file processing classes. S140, according to the target demand data and the keyword, the template method is used to use the preset distributed task scheduling platform to generate a scheduling task class corresponding to the target demand configuration file; the scheduling task class is used to start the database file processing task corresponding to the target demand configuration file according to the keyword, so as to obtain the database access object according to the keyword matching, and then interact with the database through the database access object, and obtain the file processing class according to the keyword matching, and then parse or generate the database file through the file processing class. That is, the database access object that matches the keyword is used to interact with the database and the file processing class that matches the keyword is used to parse or generate the database file.
[0088] It is understandable that the scheduled task class can be named according to the keyword. Multiple types of scheduled task classes can be generated according to the file processing type in the target demand data. The scheduled task class is periodically executed according to the file processing time in the target demand data.
[0089] In one embodiment, in step S120, the code of the database access object corresponding to the target demand configuration file is generated by using a preset code generator using a template method according to the target demand data and the keywords determined based on the target demand data, including:
[0090] S121, using a preset code generator to respectively generate the codes of the data operation object Entity, the data operation interface Mapper and the data operation warehouse Repository in the database access object. Among them, the data operation object Entity and the corresponding data operation interface Mapper corresponding to the target demand configuration file are associated with the corresponding data operation warehouse Repository in the form of parameters. The data operation warehouse Repository inherits the pre-built warehouse base class BaseRepository. The warehouse base class BaseRepository sets the first generic parameter and the second generic parameter; the first generic parameter inherits the interface base class BaseMapper of the data operation interface Mapper; the second generic parameter inherits the object base class BaseEntity of the data operation object Entity. Among them, the parameter of the interface base class BaseMapper is also the second generic parameter.
[0091] Furthermore, the code generator is the template code generator AutoGenerator in the mybatisplus framework. It can be understood that the interface base class BaseMapper and the object base class BaseEntity are both inherited from the ServiceImpl class. The ServiceImpl class comes from mybatisplus. For example, public class BaseRepository <M extends BaseMapper <e>, E extends BaseEntity>extends ServiceImplsh, E>{}.
[0092] Exemplarily, table is the table object in the EasyExcel tool class, serviceImplName is the property of table, and the English name of the table can be obtained through table.serviceImplName. Use table.serviceImplName as the name of the data operation warehouse Repository, for example, table.serviceImplName=CompensateApplyRepository. The data operation warehouse Repository inherits the warehouse base class BaseRepository, and passes the data operation object Entity and the data operation interface Mapper as parameter values to the warehouse base class BaseRepository, thereby associating the data operation object Entity, the data operation interface Mapper and the data operation warehouse Repository of the same target demand configuration file. For example, public class $table.serviceImplName} extends BaseRepository<${table.mapperName}, ${entity}>{}.
[0093] Exemplarily, this application uses AutoGenerator and the automatic code generation class provided by MybatisPlus to generate the data operation object Entity of the table (target demand configuration file), the data operation interface Mapper (the template method implementation of Servicelmpl is modified in the Mapper class, and the corresponding template file repository.ry.java.ftl is modified), and the data operation warehouse Repository of the corresponding table is generated. Among them, CodeGenerator calls the AutoGenerator method according to the updated demand configuration file. Taking the data in Table 1 and Table 2 as an example, AutoGenerator uses the automatic code generation class provided by MybatisPlus to read the database table generated by ExcelToMySqlGenerator and the like, generate the Entity of the corresponding table, the Mapper class, and the Repository class of the corresponding table. Specifically, the input of AutoGenerator is the target requirement data obtained by parsing the target requirement configuration file, such as DetailParams+BaseParam; the output is: traverse the DetailParams list, and insert the specific code files of the CompensationApplyEntity class, CompensationApplyMapper class, and the corresponding CompensationApplyRepository class corresponding to each data into the corresponding directory of the project, the CompensationApplyEntity is inserted into the Entity directory to store the Entity entity, the CompensationApplyMapper is inserted into the Mapper directory, and the CompensationApplyRepository class is inserted into the Repository directory. The Chinese name is used as a variable to generate the class description.
[0094] The method also includes: S150, when constructing the warehouse base class BaseRepository, taking the data operation object Entity and the data operation interface Mapper as parameters, and according to the current business demand logic, extending the data operation method in the code generator to obtain the data operation extension method CRUD corresponding to the data operation object Entity; the data operation extension method CRUD is used to operate and maintain the database through the corresponding data operation object Entity and the data operation interface Mapper.
[0095] Furthermore, the code generator is the template code generator AutoGenerator in the mybatisplus framework.
[0096] In step S150, according to the current business demand logic, the data operation method in the code generator is extended to obtain the data operation extension method CRUD corresponding to the data operation object Entity, including:
[0097] S151, extracting common business fields according to each data operation object Entity;
[0098] S152, according to the common business fields and based on the current business demand logic, the data operation method CRUD in the service implementation class ServiceImpl in the template code generator AutoGenerator is extended to obtain the data operation extension method CRUD.
[0099] Specifically, ServiceImpl is transformed into a specific Repository implementation object that inherits BaseRepositry. By using abstract Entity and Mapper, all methods for querying entity objects in different database files (for example, querying data volume, querying data details, updating data, etc.) are universal, avoiding specifying specific objects and redundant and repetitive code to implement CRUD operations.
[0100] Furthermore, the target demand configuration file is an Excel file; the target demand data includes multiple business fields parsed from the Excel file; the keyword is determined according to the file identifier in the target demand data, and the file identifier is determined according to the English name of the table.
[0101] In step S121, the preset code generator is used to generate the codes of the data operation object Entity, the data operation interface Mapper and the data operation repository Repository in the database access object respectively, including:
[0102] According to the file identifier (corresponding to the English name of the table) and the access class keywords (such as Entity, Mapper, Repository) in the target demand data, the data operation object Entity, the data operation interface Mapper, and the data operation warehouse class Repository are named using camel case naming method, so that the database access object corresponding to the target demand configuration file can be used according to the name when executing the database file processing task. For example, according to the target demand configuration file shown in Table 1, the file identifier is the last two fields in the English name buffer_compensate_apply of the table, combined with the access class keywords Entity, Mapper, and Repository, the data operation object Entity generated using camel case naming method is CompensateApplyEntity, the data operation interface Mapper generated is CompensateApplyMapper, and the data operation warehouse Repository generated is CompensateApplyRepository.
[0103] According to each business field in the target demand data, the attributes of the data operation object are generated accordingly.
[0104] In one embodiment, in step S140, the generating of the scheduling task class corresponding to the target demand configuration file by using the template method and the preset distributed task scheduling platform according to the target demand data and the keyword includes:
[0105] According to the pre-constructed scheduling interface BaseJob and the file processing type in the target demand data, a generation file scheduling task implementation class or a parsing file scheduling task implementation class and a scheduling task entry class in the scheduling task class are generated, and according to the file identifier (corresponding to the English name of the table) and the task identifier (for example, Generate_FileJob) in the target demand data, the camel case naming method is used to name the scheduling task entry class (for example, Generate+keywords determined by the English name of the table+FileJob), the generation file scheduling task implementation class (for example, Generate+keywords determined by the English name of the table+FileJoblmpl) and the parsing file scheduling task implementation class; wherein the keyword is determined according to the file identifier; wherein the scheduling task entry class includes a file generation entry class and a file parsing entry class.
[0106] The scheduling task entry class is used to match and call the corresponding scheduling task implementation class according to the file identifier (corresponding table English name) in the target demand data and the file processing type; the file generation scheduling task implementation class is used to match the corresponding file generation implementation class according to the keyword when executing the database file processing task; the file parsing scheduling task implementation class is used to match the corresponding file parsing implementation class according to the keyword when executing the database file processing task.
[0107] The scheduling interface BaseJob is pre-constructed based on the file processing time in the target demand data and on the distributed task scheduling platform, so as to execute the database file processing task according to the file processing time.
[0108] Exemplarily, the distributed task scheduling platform is xxljob. The distributed task scheduling platform uses xxljob. xxljob is an open source distributed task scheduling platform and is also the mainstream framework currently used in the world. The purpose of using this code here is that for the generation of each file, the final entry startup method of parsing adopts the method of scheduled task scheduling, and only encapsulates the implementation of the framework's public code for the application layer executor Executor (the scheduling center Scheduler is mainly used to configure scheduling tasks, and the specific configuration task frequency is determined according to the file processing time.
[0109] In this application, the scheduling interface BaseJob and the prototype base class BaseHandlerJob are repackaged:
[0110] 1) Public task execution interface BaseJob (scheduling interface BaseJob), which has only one method, the execute method, which is inherited by all task executors. This method also defines the public parameters JobParam for task execution. The public parameters include the elements for generating and parsing files: such as the specified date or date range, public business primary key, file type, file directory, file name, etc. Because the scheduling tasks for various types of files are generally controlled by the file type + specific date business primary key. The scheduling interface BaseJob depends on the prototype base class BaseHandlerJob.
[0111] 2) Public execution prototype base class BaseHandlerJob, which is the core controller of the scheduling task, can be used to expand or customize the file processing task at the scheduling level. This prototype base class introduces the previous scheduling interface BaseJob. This prototype base class also has a core method jobHandle method. This core method jobHandle mainly performs different aspect processing for different task input parameters JobParam, such as pre-processing (whether to lock), post-processing (processing after running the task), exception handling mechanism (whether to retry or warn, etc.), and cyclic execution of the excute method according to the time interval or business primary key dimension. The prototype base class BaseHandlerJob specifies the job lock and specific implementation class of the specific implementation class, and encapsulates the basic method of executing tasks with specified parameters, such as: specifying the time period for executing the file processing task or the task of specifying the time. The specific implementation class is also named according to the English name of the parsed table, and will call the final file processing implementation class according to the parsed file processing type matching.
[0112] When encapsulating the specific business implementation class that uses the scheduling interface BaseJob, the scheduling task entry class (referred to as the Job entry class) and the execution class JobImpl (the file scheduling task implementation class GenerateXXXFileJobImpl_1 and the parsing file scheduling task implementation class GenerateXXXFileJobImpl_2) of the specified file processing task will be generated according to the English name of the table parsed from the target demand configuration file. The specific execution class JobImpl implements the specific task execution method excute of the BaseJob interface. The specific implementation process of the execution class JobImpl is implemented by introducing the subsequent warehouse base class BaseRepository.
[0113] 3) The job entry class is actually the standard code of the xxljob executor. The job entry class depends on the prototype base class BaseHandlerJob. Because it depends on the prototype base class BaseHandlerJob, this application can set the job lock in the job entry class and set the specific execution class jobImpl of the job. The job entry class generates the file generation entry class GenerateXXXFileJob_1 and the file parsing entry class (GenerateCompensationApplyFileJob_2) according to the file processing type parsed from the target demand configuration file. Since the underlying job scheduling is implemented using xxljob, the parsed table name is directly parsed into the job's Bean name, and the initialization script of the xxljob scheduling platform is generated.
[0114] like Figure 2 As shown, the file generation entry class GenerateXXXFileJob_1 is used to call the corresponding file generation scheduling task implementation class GenerateXXXFileJobLmpl_1 according to the keyword. The file parsing entry class is used to call the corresponding file parsing scheduling task implementation class according to the keyword.
[0115] The file generation scheduling task implementation class GenerateXXXFileJobLmpl_1 is used to match the corresponding file generation implementation class according to the keyword when executing the database file processing task. The file parsing scheduling task implementation class is used to match the corresponding file parsing implementation class according to the keyword when executing the database file processing task.
[0116] Exemplarily, the scheduling task class generator ExcelToJobGenerator method is pre-encapsulated, and the ExcelToJobGenerator method is used to generate the parsing file scheduling task implementation class, the generation file scheduling task implementation class and the scheduling task entry class using xxl-job. Among them, CodeGenerator calls the AutoGenerator method according to the updated demand configuration file to generate the parsing file scheduling task implementation class, the generation file scheduling task implementation class and the scheduling task entry class corresponding to the demand configuration file.
[0117] Taking Table 1 and Table 2 as examples, the input of ExcelToJobgenerator is BaseParams. ExcelToJobgenerator will generate the dml script of the xxl-job scheduling center based on the Chinese name of BaseParams and the English name of the table. The processing time field in Table 1 will be used here to automatically configure the scheduling task of the xxl-job scheduling center file during subsequent deployment. According to the English name and Chinese name of the table in BaseParams, the CompensationApplyJob class and the CompensationApplyJobImpl class are generated, and the processing time field is generated. According to / res / xxl / dml / yyyyMMdd / xxljob.sql, the script required for the initialization task configuration of xxlJob is generated.
[0118] Furthermore, the data operation warehouse class includes a file parsing processing warehouse class and a file generation processing warehouse class.
[0119] In step S130, the method of generating a file processing class corresponding to the target demand configuration file using the template method using a pre-built file processing class generation method (file generation and parsing processing class method) according to the target demand data and the keyword includes:
[0120] The file generation implementation class and the file parsing implementation class included in the file processing class are generated using a pre-built file processing class generation method, and the file generation implementation class and the file parsing implementation class are named using camel case naming according to the file identifier in the target demand data and the corresponding processing class identifier (for example, Generator). The file generation implementation class and the file parsing implementation class are named using camel case naming according to the file identifier in the target demand data (the keyword determined according to the table English name) and the corresponding processing class identifier (for example, Generator). For example, if the keyword is CompensateApply according to the table English name, then it is named CompensateApplyGenerator.
[0121] Among them, the file generation implementation class XXXGenerator_1 depends on the file generation processing warehouse class XXXRepository_1, and inherits the pre-built file generation process base class BaseDataFileGenerator; the file generation process base class is used to generate file headers, generate file data and upload to the server; the file generation processing warehouse class is used to associate the data operation object Entity and the data operation interface Mapper. The file generation process base class BaseDataFileGenerator is specifically used to:
[0122] 1) Generate a file header. Implement the specific file header generation method of the specified repository (query the specified table to obtain the data volume of the file);
[0123] 2) Generate file data rows. Query the specified table from the database by paging (specify the method provided by Repository) and split each data value according to the delimiter, loop and concatenate them line by line to generate a local file;
[0124] 3) Generate a file tail. Concatenate the specified data to the end of the file;
[0125] 4) Upload the file to the specified sftp server directory. The file name is the date concatenated with the English name of the table (converted to camel case); generate an ok file with the same name according to the ok file configuration.
[0126] The file parsing implementation class XXXRepository_2 depends on the file parsing processing repository class XXXRepository_2, and inherits the pre-built file parsing process base class BaseTransferFilegenerator; the file parsing process base class is used to implement pre-parsing processing, parsing file data and post-parsing processing; the file parsing processing repository class XXXRepository_2 is used to associate the data operation object Entity and the data operation interface Mapper. The file parsing process base class BaseTransferFilegenerator is specifically used for:
[0127] 1) Find the specified sftp server directory according to the ok file configuration (the file name is the date concatenated with the English name of the table (converted to camel case).ok);
[0128] 2) If there is an OK file (checked or not according to the configuration), download the file to the local computer from the specified SFTP directory; parse the file header according to the file header and separator (if any); parse the specific data lines of the file line by line according to the file data lines and separators, and store them in the specified table created previously.
[0129] The file parsing processing warehouse class XXXRepository_2 and the file generating processing warehouse class XXXRepository_1 both inherit the pre-existing warehouse base class BaseRepository;
[0130] The method further comprises: when constructing the repository base class BaseRepository, encapsulating a common file processing method to generate and parse database files in various forms.
[0131] Exemplarily, a file processing class generator ExcelToFileGenerator method is pre-packaged, and the ExcelToFileGenerator method is used to take a keyword as a parameter to generate a file generation implementation class and a file parsing implementation class.
[0132] Generate file generation implementation class and file parsing implementation class, according to the delimiter (commonly used are "|", "~@~", etc.), whether there is a file header, whether there is a file tail, ok file, and specific file path (go to sfp to obtain the specific directory of the file) parsed from the target demand configuration file, as parameters of the file generation process base class BaseDataFileGenerator or the file parsing process base class BaseTransferFileGenerator to generate or unpack the file. Among them, CodeGenerator calls the ExcelToFileGenerator method according to the updated demand configuration file.
[0133] For example, the input of ExcelToFileGenerator is BaseParams. ExcelToFileGenerator will use the file header, delimiter, file tail, ok file and specific file path (get the specific directory of the file through sftp) in Table 1 as the parameters of BaseDateFileGenrator or BaseTransferFileGenerator to generate or parse the file. Generate the corresponding file processing class according to the Chinese name, such as CompensationApplyGenerator. Determine the inheritance class of the generated class according to the file processing type. If it is to generate a file, it inherits BaseDataFileGenerator. If it is to parse a file, it inherits BaseTransferFilegenerator.
[0134] In short, if Figure 3 As shown, in the code generation method for processing database files of the present application, the target demand configuration file is parsed using ExcelReader according to the updated (added, modified) target demand configuration file through the code generator entry CodeGenerator regularly; and then the table creation statement is generated according to the table type (corresponding database type) using the ExcelToMySqlGenerator template method, the ExcelToOracleGenerator template method or the ExcelToPgGenerator template method; then, using AutoGenerator, the automatic code generation class provided by MybatisPlus is used to generate the data operation object Entity of the table, the data operation interface Mapper and the data operation warehouse Repository. Then, the ExcelToJobGenerator method uses xxl-job to generate the parsing file scheduling task implementation class, the generation file scheduling task implementation class and the scheduling task entry class. Finally, the file generation implementation class and the file parsing implementation class are generated by the ExcelToFileGenerator method, thereby obtaining the code for processing database files.
[0135] Figure 4 A schematic diagram of a code generation device for processing database files according to an embodiment of the present application is shown. Exemplarily, the code generation device for processing database files includes: a target demand data parsing module 210, a database access object generation module 220, a file processing class generation module 230 and a scheduling task class generation module 240.
[0136] The target demand data parsing module 210 is used to obtain a target demand configuration file in a preset format, and parse the target demand configuration file using a file parsing tool class to obtain target demand data;
[0137] A database access object generation module 220, configured to generate a code of a database access object corresponding to the target demand configuration file by using a preset code generator using a template method according to the target demand data and keywords determined based on the target demand data;
[0138] The file processing class generation module 230 is used to generate the file processing class corresponding to the target demand configuration file by using the pre-built file processing class generation method (file generation and parsing processing class method) according to the target demand data and the keyword and adopting the template method;
[0139] The scheduling task class generation module 240 is used to generate a scheduling task class corresponding to the target demand configuration file based on the target demand data and the keyword, using the template method and a preset distributed task scheduling platform; the scheduling task class is used to start the database file processing task corresponding to the target demand configuration file according to the keyword, so as to obtain a database access object according to the keyword matching, and then interact with the database through the database access object, and to obtain the file processing class according to the keyword matching, and then parse or generate a database file through the file processing class.
[0140] It can be understood that the device of this embodiment corresponds to the code generation method for processing database files in the above embodiment, and the optional items in the above embodiment are also applicable to this embodiment, so they will not be described repeatedly here.
[0141] Figure 5 A flow chart of a database file processing method according to an embodiment of the present application is shown. Exemplarily, the database file processing method uses the above-mentioned code generation method for processing database files to process database files. The database file processing method includes the following steps:
[0142] S210, parsing the target demand configuration file to obtain target demand data; using the keyword matching determined according to the target demand data to start the distributed scheduling task class.
[0143] Demonstratively, after being deployed to the formal environment, the generatorSQL.sql in the above path will be automatically scanned to the underlying configured database to execute statements and create table statements. After being deployed to the formal environment, the above xxljob.sql will be automatically scanned to the xxl scheduling platform database to execute the dml script to initialize the scheduling task. Thus, the overall code flow is executed, and the scheduling task initialized by the xxl scheduling platform will initiate scheduling according to the configured timing, and generate or parse files. Among them, if the file is generated, the data source in the specific data table depends on big data, or other data warehouse platform synchronization data; if the file is parsed, the specific data source is the data parsed from the sftp specified directory.
[0144] The scheduling task class obtains a database access object according to the keyword matching, and then interacts with the database through the database access object, and obtains the file processing class according to the keyword matching, and then parses or generates a database file through the file processing class. That is, the scheduling task class interacts with the database using the database access object matching the keyword, and parses or generates the database file using the file processing class matching the keyword to complete the database file processing task.
[0145] Furthermore, the scheduling task class includes a generation file scheduling task implementation class, a parsing file scheduling task implementation class and a scheduling task entry class;
[0146] The file processing class includes a file generation implementation class and a file parsing implementation class;
[0147] The database access object includes a data operation object Entity, a data operation interface Mapper and a data operation warehouse Repository;
[0148] The scheduling task class is specifically used for:
[0149] Matching a target scheduling task implementation class in each of the generated file scheduling task implementation classes and each of the parsed file scheduling task implementation classes based on the file processing time in the target demand data by using the scheduling task entry class and the file processing type in the target demand data;
[0150] The target scheduling task implementation class matches the target implementation class in each file generation implementation class and each file parsing implementation class according to the keyword and the file processing type;
[0151] The target implementation class interacts with the database using the database access object that matches the keyword, and performs file processing corresponding to the file processing type to parse or generate a database file.
[0152] Furthermore, the scheduling task entry class includes a file generation entry class and a file parsing entry class.
[0153] like Figure 2 As shown, if the file processing type is to generate a file, the file generation entry class is determined to be called; if the file processing type is to parse a file, the file parsing entry class is called.
[0154] Furthermore, if the target implementation class is a file generation implementation class; the file generation implementation class is used to use the data operation object Entity and the data operation interface Mapper used when associating the operation data with the file generation processing warehouse class XXXRepository_1 it depends on, and to use the file generation process base class BaseDataFileGenerator it inherits to generate a file header, generate file data and upload to the server;
[0155] If the target implementation class is the file parsing implementation class; the file parsing implementation class is used to utilize the file parsing processing repository class XXXRepository_2 on which it depends, the data operation object Entity and the data operation interface Mapper used when associating the operation data, and utilizes the file parsing process base class BaseTransferFilegenerator it inherits to implement pre-parsing processing, parsing file data and post-parsing processing.
[0156] This application realizes the entire file generation and parsing business needs with true zero coding. Developers only need to focus on specific business needs and organize the excel tables for generating or parsing files according to the specifications. They can even directly produce tables at the demand level, and the business personnel can directly import the demand excel. The warehouse base class abstracts the business entities, integrates the basic implementation of all DAO data access layers, and generates or parses the core methods of various data files based on abstract business entities, which greatly simplifies the code logic and hierarchy. This integrated abstract DAO object processing base warehouse class can also be used in many other business scenarios that require similar processing of different DAO objects.
[0157] The embodiment of the present application also provides a database file processing device. Exemplarily, the database file processing device includes: a parsing and scheduling module.
[0158] A parsing and scheduling module is used to parse the target demand configuration file to obtain the target demand data; use the keyword matching determined according to the target demand data to start the distributed scheduling task class;
[0159] The scheduling task class obtains the database access object according to the keyword matching, and then interacts with the database through the database access object, and obtains the file processing class according to the keyword matching, and then parses or generates a database file through the file processing class.
[0160] It can be understood that the device of this embodiment corresponds to the database file processing method of the above embodiment, and the optional items in the above embodiment are also applicable to this embodiment, so they will not be described repeatedly here.
[0161] The present application also provides a terminal device. Exemplarily, the terminal device includes a processor and a memory, wherein the memory stores a computer program, and the processor runs the computer program to enable the terminal device to execute the functions of the various modules in the above-mentioned code generation method for processing database files or the above-mentioned code generation device for processing database files, or to enable the terminal device to execute the above-mentioned database file processing method or the functions of the various modules in the above-mentioned database file processing device.
[0162] Among them, the processor can be an integrated circuit chip with signal processing capabilities. The processor can be a general-purpose processor, including a central processing unit (CPU), a graphics processing unit (GPU), a network processor (NP), a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or at least one of other programmable logic devices, discrete gates or transistor logic devices, and discrete hardware components. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc., which can implement or execute the methods, steps and logic block diagrams disclosed in the embodiments of the present application.
[0163] The memory may be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electric erasable programmable read-only memory (EEPROM), etc. The memory is used to store a computer program, and the processor may execute the computer program accordingly after receiving an execution instruction.
[0164] The present application also provides a computer-readable storage medium for storing the computer program used in the above terminal device. For example, the computer-readable storage medium may include but is not limited to: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.
[0165] In several embodiments provided in the present application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and structure diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of a code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in an alternative implementation, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the structure diagram and / or the flow diagram, and the combination of boxes in the structure diagram and / or the flow diagram, can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.
[0166] In addition, the functional modules or units in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
[0167] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling a computer device (which can be a smart phone, a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application.
[0168] The above description is only a specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application.< / e>
Claims
1. A code generation method for processing a database file, characterized in that: include: Obtain a target demand configuration file in a preset format, and parse the target demand configuration file using a file parsing tool class to obtain target demand data; According to the target demand data and the keywords determined based on the target demand data, a template method is used to generate the code of the database access object corresponding to the target demand configuration file by using a preset code generator, specifically including: using a preset code generator to respectively generate the codes of the data operation object, the data operation interface and the data operation warehouse in the database access object; wherein the data operation object and the corresponding data operation interface corresponding to the target demand configuration file are associated with the corresponding data operation warehouse in the form of parameters; According to the target demand data and the keywords, a file processing class generation method constructed in advance is used to generate a file processing class corresponding to the target demand configuration file using the template method; According to the target demand data and the keyword, the template method is used to use a preset distributed task scheduling platform to generate a scheduling task class corresponding to the target demand configuration file; the scheduling task class is used to start the database file processing task corresponding to the target demand configuration file according to the keyword, so as to obtain the database access object according to the keyword matching, and then interact with the database through the database access object, and to obtain the file processing class according to the keyword matching, and then parse or generate a database file through the file processing class; The using of a preset code generator to respectively generate codes of a data operation object, a data operation interface and a data operation warehouse in the database access object comprises: According to the file identifier and access class keyword in the target demand data, the data operation object, the data operation interface and the data operation warehouse class are named respectively using camel case naming method, so that the database access object corresponding to the target demand configuration file is used according to the name when executing the database file processing task; According to each business field in the target demand data, the attributes of the data operation object are generated accordingly; according to the target demand data and the keyword, the template method is used to use a preset distributed task scheduling platform to generate a scheduling task class corresponding to the target demand configuration file, including: According to the pre-constructed scheduling interface and the file processing type in the target demand data, a generation file scheduling task implementation class or a parsing file scheduling task implementation class and a scheduling task entry class in the scheduling task class are generated, and according to the file identifier and task identifier in the target demand data, the scheduling task entry class, the generation file scheduling task implementation class and the parsing file scheduling task implementation class are named respectively using camel case naming method; wherein the keyword is determined according to the file identifier; the scheduling task entry class is used to match and call the corresponding scheduling task implementation class according to the file identifier and the file processing type in the target demand data; the generation file scheduling task implementation class is used to match the corresponding file generation implementation class according to the keyword when executing the database file processing task; the parsing file scheduling task implementation class is used to match the corresponding file parsing implementation class according to the keyword when executing the database file processing task; wherein the scheduling interface is based on the file processing time in the target demand data and pre-constructed based on the distributed task scheduling platform, so as to execute the database file processing task according to the file processing time; The data operation warehouse class includes a file parsing processing warehouse class and a file generation processing warehouse class; The method of generating a file processing class corresponding to the target demand configuration file by using a pre-built file processing class generation method and a template method according to the target demand data and the keyword includes: generating a file generation implementation class and a file parsing implementation class included in the file processing class by using a pre-built file processing class generation method, and naming the file generation implementation class and the file parsing implementation class respectively by using camel case naming method according to the file identifier in the target demand data and the corresponding processing class identifier; wherein the file generation implementation class depends on the file generation processing warehouse class and inherits the pre-built file generation process base class; the file generation process base class is used to generate a file header, generate file data and upload to a server; the file generation processing warehouse class is used to associate the data operation object and the data operation interface used; the file parsing implementation class depends on the file parsing processing warehouse class and inherits the pre-built file parsing process base class; the file parsing process base class is used to implement parsing pre-processing, parsing file data and parsing post-processing; the file parsing processing warehouse class is used to associate the data operation object and the data operation interface used; the file parsing processing warehouse class and the file generation processing warehouse class both inherit the pre-built warehouse base class.
2. The code generation method for processing database files according to claim 1, characterized in that: The data operation warehouse inherits the pre-built warehouse base class; The method also includes: when constructing the warehouse base class, taking the data operation object and the data operation interface as parameters, and according to the current business demand logic, expanding the data operation method in the code generator to obtain a data operation extension method corresponding to the data operation object; the data operation extension method is used to operate and maintain the database through the corresponding data operation object and the data operation interface.
3. The code generation method for processing database files according to claim 2, characterized in that: The code generator is a template code generator in the mybatisplus framework; The method of extending the data operation method in the code generator according to the current business demand logic to obtain the data operation extension method corresponding to the data operation object includes: Extract common business fields based on each data operation object; According to the common business fields and based on the current business demand logic, the data operation method in the service implementation class in the template code generator is extended to obtain the data operation extension method.
4. The code generation method for processing database files according to claim 2, characterized in that: The target demand configuration file is an Excel file; the target demand data includes a plurality of business fields parsed from the Excel file; and the keyword is determined according to a file identifier in the target demand data.
5. The code generation method for processing database files according to claim 1, characterized in that: The method further comprises: when constructing the warehouse base class, encapsulating a common file processing method to generate and parse database files in various forms.
6. A database file processing method, characterized in that: include: The database file processing method uses the code obtained by the code generation method for processing a database file according to any one of claims 1 to 5 to process the database file, specifically comprising: Parsing the target demand configuration file to obtain target demand data; using the keyword matching determined according to the target demand data to start the distributed scheduling task class; The scheduling task class obtains a database access object according to the keyword matching, and then interacts with the database through the database access object, and obtains a file processing class according to the keyword matching, and then parses or generates a database file through the file processing class.
7. The database file processing method according to claim 6, characterized in that: The scheduling task class includes a generation file scheduling task implementation class, a parsing file scheduling task implementation class and a scheduling task entry class; The file processing class includes a file generation implementation class and a file parsing implementation class; The database access object includes a data operation object, a data operation interface and a data operation warehouse; The scheduling task class is specifically used for: Matching a target scheduling task implementation class in each of the generated file scheduling task implementation classes and each of the parsed file scheduling task implementation classes based on the file processing time in the target demand data by using the scheduling task entry class and the file processing type in the target demand data; The target scheduling task implementation class matches the target implementation class in each file generation implementation class and each file parsing implementation class according to the keyword and the file processing type; The target implementation class interacts with the database using the database access object that matches the keyword, and performs file processing corresponding to the file processing type to parse or generate a database file.
8. The database file processing method according to claim 7, characterized in that: If the target implementation class is a file generation implementation class; the file generation implementation class is used to use the data operation object and the data operation interface used when the file generation processing warehouse class it depends on associates the operation data, and uses the file generation process base class it inherits to generate a file header, generate file data and upload to the server; If the target implementation class is the file parsing implementation class; the file parsing implementation class is used to utilize the file parsing processing warehouse class it depends on, the data operation object and the data operation interface used when associating the operation data, and utilize the file parsing process base class it inherits to implement pre-parsing processing, parsing file data and post-parsing processing.
9. A terminal device, characterized in that: The terminal device includes a processor and a memory, the memory stores a computer program, and the processor is used to execute the computer program to implement the code generation method for processing database files described in any one of claims 1-5 to generate code for processing database files, or execute the computer program to implement the database file processing method described in any one of claims 6-8 to process database files.
Citation Information
Patent Citations
Business code generation method and apparatus
CN107122183A
Method and device for generating front-end code file and rear-end code file for accessing database
CN114281331A