CN-121764889-B - Business object change identification and log generation system and method based on annotation driving
Abstract
The invention discloses a business object change identification and log generation system and method based on annotation driving, wherein the system is based on a four-layer architecture design and comprises an annotation driving module, a type strategy module, a reflection processing module and an ID conversion module, wherein the annotation driving module is used for configuring relevant parameters of annotation and supporting log output and field comparison, the type strategy module is used for realizing a strategy mode through comparison enumeration, each data type corresponds to a comparison function type interface, the reflection processing module is used for acquiring all fields of a current class and a parent class thereof through recursive scanning and supporting complete field scanning of inheritance relations, the class field caching mechanism is used for avoiding repeated reflection operation, the ID conversion module is used for defining unified ID conversion specifications through the function type conversion interface and providing multiple conversion realization classes and configuring a conversion interface single-instance caching mechanism. The scheme realizes automatic identification, type conversion and log generation of service field change, supports unified processing of multiple data types, and remarkably improves development efficiency and maintainability of a system.
Inventors
- LIU YONG
- YUAN YI
- WANG JINLONG
- ZHANG JING
- HU SHU
Assignees
- 成都房联云码科技有限公司
Dates
- Publication Date
- 20260512
- Application Date
- 20260304
Claims (6)
- 1. The annotation-driven business object change identification and log generation system is characterized by comprising the following modules based on a four-layer architecture design: The annotation driving module is used for comparing annotation related parameters based on the annotation statement configuration CompareAnnotation of the @ Target and the @ report element and supporting log output and field comparison; The type policy module is used for realizing a policy mode through CompareEnum comparison enumeration, wherein each data type enumeration constant corresponds to one comparison function type interface, the CompareEnum comparison enumeration comprises STRING, NUMBER, DATE, SELECT, OTHER _ ID, RELATION, BOOLEAN and CUSTOM enumeration constants, and the corresponding comparison function type interface is stored by taking the enumeration constants as keys through a preset data structure; The reflection processing module is used for acquiring all fields of the current Class and the parent Class thereof through recursive scanning and supporting complete field scanning of inheritance relation, avoiding repeated reflection operation through a Class field caching mechanism, wherein the recursive scanning is provided with iteration conditions, the Class field caching mechanism adopts a global static caching container, takes a Class object as a key and takes a field list as a value, preferentially searches from the caching container when receiving a target Class object, executes recursive scanning when not hitting, and stores a result into a cache; The ID conversion module defines unified ID conversion specifications through a functional conversion interface, provides a plurality of conversion realization classes and configures a conversion interface single instance caching mechanism, wherein the conversion interface single instance caching mechanism is based on a caching container, takes Class objects of conversion classes as keys, takes conversion Class single instance instances as values, preferentially acquires the conversion Class instances from the caching container when ID conversion is required to be executed, and stores the conversion Class instances into a cache through reflection instantiation when the conversion Class instances are not hit; The four-layer architecture specifically includes: Defining CompareAnnotation annotation classes of comparison annotations, defining configuration parameters including field names, comparison types, time formats, dictionary enumerations and conversion classes, and adopting Java meta annotation statement CompareAnnotation to compare field-level scope of action of the annotations and a reservation strategy in running; and a type processing layer for realizing processing strategies of different data types through CompareEnum comparison enumeration and supporting STRING, NUMBER, DATE, SELECT, OTHER _ ID, RELATION, BOOLEAN and CUSTOM data types, wherein the processing of the data types specifically comprises the following steps: The STRING type is that the unified processing of null value and null STRING is realized, and whether the non-null STRING is equal is judged; NUMBER type, converting the value into Double type, reserving 2 bits of decimal and comparing; DATE type, converting the DATE object into character string according to the format appointed by timeType time format parameter and comparing; the selection type is that a dictionary query interface is called through configuration service, dictionary codes are converted into Chinese names and then are compared; the type of the OTHER_ID is that the ID is converted into a corresponding name through a conversion class interface appointed by the ID conversion class; RELATION, identifying adding and deleting operations of the associated objects, and generating a format log; BOOLEAN type, namely converting Boolean value into Chinese description and comparing; CUSTOM type, reserved CUSTOM processing interface, support user to expand processing logic by implementing specific function The reflection execution layer dynamically acquires the field value of the object by using a comparison tool class through a Java reflection mechanism to realize accurate comparison of field levels; And the log output layer is used for generating a standardized change log and persisting the standardized change log into the updated field entity table.
- 2. The annotation-driven business object change recognition and log generation system of claim 1, wherein the annotation-driven module CompareAnnotation compares annotation-related parameters including CompareAnnotation to annotation support field display name, comparison type, time format, dictionary type, ID conversion class, and enable function.
- 3. The annotation-driven business object change recognition and log generation system of claim 1, wherein the updated field entity table in the log output layer comprises at least a business object ID, a field display name, a pre-change value, a post-change value, an operator ID, and an operation time.
- 4. The annotation-driven business object change identification and log generation method based on the annotation-driven business object change identification and log generation system according to any one of claims 1-3, which is characterized by comprising the following steps: Step S1, initializing a change log; S2, FIELD scanning and reflection, receiving a target Class object, checking whether a FIELD list of the Class exists in a Class FIELD cache of the Class CLASS_FIELD from a global static cache container, if the Class CLASS_FIELD is hit, directly returning to the FIELD list, if the Class CLASS_FIELD is not hit, acquiring declaration FIELDs of the current Class and all father classes thereof by combining iteration conditions in a recursion scanning mode, storing the result into the list, and returning to the complete FIELD list; Step S3, changing comparison, traversing the annotation field, and calling a corresponding processing strategy according to CompareEnum comparison enumeration types to generate a change log; s4, log persistence, namely packaging change information into an update field entity object, and storing the update field entity object into a database through an interface of a Java persistence layer API; And S5, updating the cache, updating the field cache and the conversion interface cache.
- 5. The method for identifying and generating a log based on annotation-driven business object changes as claimed in claim 4, wherein said step S1 comprises the steps of: S11, a business service calls a method for starting and updating a business log service, and business objects and body codes before and after changing are transmitted; step S12, calling a change log merging method, further calling Java object comparison tool class, and executing core comparison logic; Step S13, judging according to the comparison result, if no change exists, generating a content no-change log, and if change exists, generating a detailed change log and a change list in JSON format; Step S14, judging the submitting state, if true, directly writing into the database, and if false, storing the log object into the Redis cache.
- 6. The annotation-driven business object change identification and log generation method according to claim 5, wherein said step S3 further comprises: Acquiring a corresponding double-parameter comparison function according to CompareEnum comparison enumeration parameter values of comparison notes of the field CompareAnnotation, and transmitting the value of the field in the new and old business entity objects into the double-parameter comparison function to acquire a comparison result; When CompareEnum is compared with the enumeration parameter value to obtain the OTHER_ID, according to the transitionClass ID conversion Class parameter value, the Class object of the conversion Class is used as a key to obtain a corresponding conversion Class single instance from the cache container, the ID is converted into a name, and the comparison result is updated.
Description
Business object change identification and log generation system and method based on annotation driving Technical Field The invention relates to the technical field of enterprise business data change tracking, in particular to a business object change identification and log generation system and method based on annotation driving. Background Enterprise business data change tracking aims at recording 'who, when, what data, what changes are made' so as to meet the requirements of problem investigation, audit compliance, data rollback and the like. The current enterprise-level business system has the following technical defects in terms of processing business data change tracking: (1) The traditional scheme needs to manually write field comparison logic in each business method, has low development efficiency, and in complex business objects containing 50+ fields, the manual comparison code quantity can reach 500+ lines, and the development time is increased by 3-5 times; (2) The service logic and the change monitoring logic are tightly coupled, so that the maintainability of the code is poor, when the service field changes, the change monitoring code needs to be synchronously modified at multiple positions, and the maintenance cost is increased by more than 40%; (3) The prior art needs to write a great amount of type judgment and conversion logic when processing the change identification of different data types (character strings, numbers, dates, dictionary values, associated objects and the like), has high code complexity and is easy to generate conversion errors; (4) The expandability is insufficient, when a new data type or a change rule needs to be supported, the core comparison logic needs to be modified, the opening and closing principle is violated, the system expandability is poor, and a plurality of core classes need to be modified when a new data type is added; (5) The log formats are not uniform, namely, the change log formats of different service modules are not uniform, so that unified data analysis and audit are difficult to carry out, and the manageability and compliance requirements of the system are affected. These defects lead to the problems of high development cost, difficult maintenance, poor expansibility and the like when enterprises implement business data change tracking, and seriously affect the development efficiency and operation and maintenance quality of the system. Disclosure of Invention Aiming at the technical problems, the invention provides a system and a method for identifying the change of a business object and generating the log based on annotation driving, which realize the automatic identification, type conversion and log generation of the change of a business field by constructing a business object change identification framework based on the annotation driving and combining a Java reflection mechanism and a function programming idea. The system adopts a strategy mode and a factory mode design, supports unified processing of various data types, and remarkably improves development efficiency and maintainability of the system. The invention is realized by adopting the following technical scheme: In a first aspect, the annotation-driven business object change identification and log generation system is based on a four-layer architecture design, and specifically comprises the following modules: The annotation driving module is used for configuring CompareAnnotation contrast annotation related parameters and supporting log output and field contrast; Wherein CompareAnnotation contrast notes adopt @ Target (element type. Field) and @ restation (restime) meta notes declarations, and related parameters thereof include columnName, compareEnum, timeType, dictionaryCodeEnum, transitionClass and enableFunction (i.e., field display name, contrast type, time format, dictionary type, ID conversion class and enabling function); The type policy module is used for realizing a policy mode through CompareEnum comparison enumeration, and each data type corresponds to one comparison function interface; Wherein CompareEnum the contrast enumeration data type contains STRING, NUMBER, DATE, SELECT, OTHER _ ID, RELATION, BOOLEAN, CUSTOM enumeration constants, and stores corresponding contrast function type interfaces by taking the enumeration constants as keys through EnumMap < CompareEnum, biFunction < Object, compareResult > > data structures; The reflection processing module is used for acquiring all fields of the current class and the parent class thereof through recursive scanning and supporting complete field scanning of inheritance relations; Wherein the recursive scanning uses clazz.get superclass () as an iterative condition until object Class, the Class Field caching mechanism employs a globally static ConcurrentHashMap < Class <? taking the Class object as a key and the Field List as a value, preferentially searching from the cache container when receiving the target Class object, execut