Use scenarios where java enumeration management members have a linked list relationship

scenes to be used:

In the development, there is a need for user import data verification. It is necessary to verify whether a person’s in-service phase is filled in incorrectly

Verification requirements

Personnel form verification: The content filled in the in-service stage must be defined in advance in the in-service stage.

Verification of other tables: 1. According to the job number association, it must be consistent with the in-service stage of the personnel table.

                      2. If there is a promotion date in the employee table, and there are daily detailed data in the import table, the data beyond the promotion date is required to be consistent with the next stage of the in-service stage defined in the employee table.

In-service stage: training period, practical period, internship 1, internship 2, formal

Processing logic:

1. Define in-service enumeration class

public enum Phase { 
    PXQ("training period"), 
    SCQ("practical period"), 
    SX1("internship 1"), 
    SX2("internship 2"), 
    ZSQ("formal"); 
    private static Phase[] vals = values(); 
    /** 
     * Get the previous in-service phase 
     * @return 
     */ 
    public Phase previous() { 
        return vals[(this.ordinal()-1)% vals.length]; 
    } 
    /** 
     * Get the next An in-service phase 
     * @return 
     */ 
    public Phase next() { 
        if (this.ordinal() == vals.length-1) { 
            return vals[this.ordinal()]; 
        } 
        return vals[(this.ordinal() + 1)% vals.length]; 
    }
    private String desc;//Chinese description 
            if (phase.toString( ).equals(v_phase)) { 
                return phase; 
            }
    /** 
     * Private structure to prevent external calls 
     * @param desc 
     */ 
    private Phase(String desc){ 
        this.desc=desc; 
    } 
    /** 
     * Override 
     * @return 
     */ 
    @Override 
    public String toString() { 
        return desc; 
    } 

    /** 
     * Get the in-service phase 
     * @param v_phase 
     * @return 
     */ 
    public static Phase getPhase(String v_phase) { 
        for (Phase phase:vals) { 
        } 
        return null; 
    } 
}

2. Data verification use

2.1 Personnel table verification

if (sheetName.equals( "personnel data-HR" )) { //personnel data-HR table only verifies the in-service phase
    //Gets the in-service phase and verifies if (titleMap.get( "in-service phase" )!= null ) { Cell cell = row.getCell(titleMap.get( "In-service phase" ), Row . MissingCellPolicy . RETURN_BLANK_AS_NULL ); if ( cell != null ) { String v_phase = cell .getStringCellValue().trim(); if (v_phase.equals( "Official period" )) { //Compatible with official period and formal v_phase = "Official" ;
    
        
        
            
            
                
            }
            Phase phase = Phase . GetPhase (v_phase);
            if ( phase == null ) {
                messageInfoList.add(sheetName+ "The first " +j+ " row of the sheetName + "The column of the [On-the-job stage] column is incorrect, please fill in the correct in-service stage" ) ;
            }
        }
    }
}

2.2 Other table verification

Here the adhesive portion of the code, logic is that if the date field is probably going to talk to the promotion of the officer is present alignment table, the date is less than the life of service direct comparison stage, is greater than promotion by date Phase .next () ratio for the next stage .

if (peopleCheckVO.getV_regular_date()!=null&&titleMap.get("日期")!=null){
    cell = row.getCell(titleMap.get("日期"), Row.MissingCellPolicy.RETURN_BLANK_AS_NULL);
    if (cell!=null) {
        final long time = cell.getDateCellValue().getTime();
        if (time>=peopleCheckVO.getV_regular_date()) {
            Phase phase = Phase.getPhase(peopleCheckVO.getV_phase());
            if ( phase != null ) {
                String v_phase_rel = phase .next().toString();
                if (!v_phase.equals( v_phase_rel )){
                    messageInfoList.add(sheetName+ "The first of the sheet" +j+ "There is a problem in the row [In-Service Phase] column because it conflicts with the data in the HR table of personnel data, please modify it" );
                }
            }
        } else {
            if (!v_phase.equals( peopleCheckVO .getV_phase())){
                messageInfoList.add( sheetName+ "The " +j+ " row of the table has a problem with the column [In-Service Stage] because it conflicts with the data in the HR table of personnel data, please modify it" );
            }
        }
    }
} else {
    if (!v_phase.equals( peopleCheckVO .getV_phase())){
        messageInfoList.add(sheetName+ "The first " +j+ " row of the table [On-the-job stage] column has a problem because it is related to the HR table of personnel data Data conflicts, please modify" );
    }
}

to sum up:

The use of enumeration class greatly facilitates our maintenance of the string list, making our code more robust and more conducive to expansion.

Guess you like

Origin blog.csdn.net/wangpei930228/article/details/108848201