Universal and efficient operation log recording method
By using the Spring Boot framework and ThreadLocal variables in conjunction with the MyBatis plugin in the ride-hailing management system, and asynchronous message queue (MQ) to record operation logs, the problem of universality in operation log recording was solved, an efficient operation log recording method was implemented, and repetitive work was reduced when adding new interfaces.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-19
- Publication Date
- 2026-04-10
AI Technical Summary
In existing ride-hailing management systems, operation log recording is not universal or efficient enough, especially when adding new interfaces, the work is complicated and repetitive, and cannot meet complex business needs.
Using the Spring Boot framework, we obtain login user information and request parameters through interceptors, cache operation data using ThreadLocal variables, obtain operation type and level using MyBatis plugins, and record operation logs using asynchronous message queues (MQ), reducing intrusion into business processes.
It eliminates the need for repetitive development when adding new interfaces, provides a universal and efficient method for recording operation logs, and improves the universality and efficiency of operation log recording in the management system.
Smart Images

Figure CN121833640A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application belongs to the technical field of online car-hailing, and particularly relates to a general and efficient operation log recording method. BACKGROUND
[0002] With the development of online car-hailing business, the configuration of the background management system is becoming more and more complex, and has different importance according to different business and functions, for example, the opening and closing of the city for online car-hailing has a very important influence on online car-hailing business, which requires classification and recording of various operation parameters of the management background, operation personnel, operation category, operation level and the like.
[0003] Now the operation log of some important interfaces cannot meet the actual needs; there are many business interfaces, and some query or operation interfaces will be added in different periods, and the work of adding operation records is complicated and repetitive when adding interfaces, which is not a general and efficient solution. SUMMARY
[0004] The present application aims to provide a general and efficient operation log recording method to solve the problems in the background.
[0005] To achieve the above-mentioned purpose, the present application provides the following technical solution: a general and efficient operation log recording method, S1: a business personnel operates a related interface of a management system;
[0006] S2: first enter the system interceptor front-end notification;
[0007] S3: query operation personnel information;
[0008] S4: if the information cannot be found, it is considered that the personnel have not logged in, and the process is ended;
[0009] S5: after the personnel information is found, the personnel name is taken as name, the request IP is obtained as personnel information, the request URL is obtained, the request type method is obtained, the request parameter list parameter is obtained, and is recorded in the ThreadLocal type variable opThreadLocal;
[0010] S6: enter the business process;
[0011] S7: if there is a SQL to be executed, it is true, then enter the mybatis interceptor plug-in;
[0012] S8: obtain the type of the executed SQL statement as opType;
[0013] S9: SQL execution, after SQL execution is successful, the result is returned, and the level of operation can be judged according to the number of returned updates or the number of results obtained by query;
[0014] S10: Get the value of the operation type ops from opThreadLocal;
[0015] S11: If the weight of opType is greater than or equal to the weight of ops, set opType to the latest value of ops of opThreadLocal;
[0016] S12: Update the level value of opThreadLocal, if 1 row is updated successfully, the level is ONE, if n rows are updated successfully, the level is BATCH, and continue to execute from step S7;
[0017] S13: If the weight of opType is less than the weight of ops, continue to execute from step S7;
[0018] S14: Enter the interceptor post notification;
[0019] S15: Get the operation log collected in the above process from opThreadLocal;
[0020] S16: Send operation log MQ message;
[0021] S17: Record operation log system;
[0022] S18: Consume operation log MQ message, and store data.
[0023] Preferably, in step S5, the data structure is:
[0024]
[0025]
[0026] The name, ip, method, url, parameter, and timestamp parameters are put in by the pre-interceptor, the default value of ops is SELECT, the operation level is ONE by default, and ops and level are obtained and updated to opThreadLocal variable by mybatis interception plug-in during SQL execution.
[0027] Preferably, in step S8, the type of SQL execution is divided into four types, the weight of DELETE is 3, the weight of INSERT is 2, the weight of UPDATE is 1, and the weight of SELECT is 0.
[0028] Preferably, the SpringBoot Controller is used to process HTTP requests and provide the entry, process and result return of the web application.
[0029] Preferably, ThreadLocal is a class in Java, which is used to create thread-local variables; thread-local variables are a special type of variables, each thread has its own independent copy, and they do not affect each other.
[0030] Compared with the prior art, the beneficial effects of the present application are: the present application adopts the SpringBoot framework, uses the interceptor pre-notification to obtain the login personnel information such as name, request interface url and request parameters for all interface entries, uses the ThreadLocal variable marked as operationThreadLocal for caching, uses the mybatis to support the custom plug-in feature, classifies the operation type and operation level into the operationThreadLocal variable according to the class of the SQL of the operation data, and then uses the post-notification to obtain the complete operation record parameters before returning the result, finally, the operation information is recorded asynchronously by using the asynchronous sending MQ mode, so as to reduce the code invasiveness to the actual business process, realize the general and efficient recording of operation logs, and solve the general problem of operation log recording of the management system, without repeated development when the interface is added. BRIEF DESCRIPTION OF DRAWINGS
[0031] Figure 1 The flowchart of the present application is shown. DETAILED DESCRIPTION
[0032] The technical solutions in the embodiments of the present application will be described clearly and completely in combination with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor are within the protection scope of the present application.
[0033] Please refer to Figure 1 The present application provides a technical solution: a general and efficient operation log recording method, S1: a business personnel operates the related interface of the management system;
[0034] S2: first enter the system interceptor pre-notification;
[0035] S3: query operation personnel information;
[0036] S4: if not found, it is considered that there is no login, and the process is ended;
[0037] S5: After finding the personnel information, take the personnel name as name, get the request ip, and get the personnel information. Get the request url, request type method, request parameter list parameter, and record to ThreadLocal type variable opThreadLocal, and its data structure is:
[0038]
[0039] Description: The name, ip, method, method, url, parameter, and timestamp parameters are put in by the pre-interceptor, the default value of ops is SELECT, the operation level is ONE by default, and ops and level are obtained and updated to opThreadLocal variable by mybatis interception plug-in during SQL execution.
[0040] S6: Enter the business process;
[0041] S7: If there is a SQL to be executed, it is true, then enter the mybatis interceptor plug-in;
[0042] S8: Get the type of the executed SQL statement, recorded as opType. The type of SQL execution can be divided into four types, DELETE weight is 3, INSERT weight is 2, UPDATE weight is 1, and SELECT weight is 0.
[0043] S9: SQL execution, after successful SQL execution, the result will be returned, which can be used to update the number of rows or the number of results obtained by query to judge the level of operation level.
[0044] S10: Get the value of the operation type ops from opThreadLocal.
[0045] S11: If the weight of opType is greater than or equal to the weight of ops, set opType to the latest value of ops in opThreadLocal.
[0046] S12: Update the level value of opThreadLocal. If 1 row is successfully updated, the level is ONE, and if n rows are successfully updated, the level is BATCH, and continue to execute from step S7.
[0047] S13: If the weight of opType is less than the weight of ops, continue to execute from step S7.
[0048] S14: Enter the post-interceptor notification;
[0049] S15: Get the operation log collected by the above flow from opThreadLocal as shown in step S5,
[0050] S16: Send the operation log MQ message.
[0051] S17: Record the operation log system.
[0052] S18: Consume the operation log MQ message and store the data.
[0053] Although embodiments of the present application have been shown and described, it is to be understood that various modifications, substitutions, replacements and changes can be made to these embodiments without departing from the principles and spirit of the present application, and the scope of the present application is defined by the appended claims and their equivalents.
Claims
1. A general efficient method for recording an operation log, characterized by: S1: The service personnel operates the management system related interface; S2: First enter the system interceptor pre-notification; S3: Query the operator information; S4: If not found, it is considered that there is no login, and the process is ended; S5: After finding the personnel information, take the personnel name as name, get the request ip, and get the request url, request type method, and request parameter list parameter, and record them in the ThreadLocal type variable opThreadLocal; S6: Enter the business process; S7: If there is a SQL to be executed, set it to true, then enter the mybatis interceptor plug-in; S8: Get the type of the executed SQL statement as opType; S9: SQL execution, after successful SQL execution, the result will be returned, which can be used to update the number of rows or the number of results obtained by query to determine the level of operation level; S10: Get the value of the operation type ops from opThreadLocal; S11: If the weight of opType is greater than or equal to the weight of ops, set opType to the latest value of ops in opThreadLocal; S12: Update the level value of opThreadLocal, if 1 row is updated successfully, the level is ONE, if n rows are updated successfully, the level is BATCH, continue from step S7 to execute; S13: If the weight of opType is less than the weight of ops, continue from step S7 to execute; S14: Enter the interceptor post-notification; S15: Get the operation log collected in the above process from opThreadLocal; S16: Send operation log MQ message; S17: Record operation log system; S18: Consume operation log MQ message and store data.
2. The method of claim 1, wherein: In step S5, the data structure is: { "service_name":"srv_name", / / project name "name":"Zhang San", / / operator name "ip":"127.0.0.1", / / operator IP address "method":"POST", / / interface request type "url":"http: / / a.com / test", / / interface URL "parameter":"a=1&b=2", / / interface parameters "ops":"SELECT", / / operation type, DELETE, INSERT, UPDATE, SELECT "level":"ONE", / / operation level, ONE, BATH "timestamp":"1693576572" / / operation time } Wherein name, ip, method, url, parameter, timestamp parameter for pre-interceptor put, ops default value is SELECT, operation level default is ONE, ops and level for mybatis interception plug-in to get and update to opThreadLocal variable in the execution of SQL process.
3. The method of claim 1, wherein: In step S8, the type of SQL execution is divided into four types, DELETE weight is 3, INSERT weight is 2, UPDATE weight is 1, SELECT weight is 0.
4. The method of claim 1, wherein: SpringBoot Controller controller handles HTTP requests and provides the entry, process and result return of Web application.
5. The method of claim 1, wherein: ThreadLocal is a class in Java, which is used to create thread local variables; Thread local variable is a special type of variable, each thread has its own independent copy, and they do not affect each other.