private int num=0;
Private String parentcode = null;
Private String ReturnCode = null;
/**
* Query the top outfield, if the current department's superior department has been outfield, then return to the topmost orgcode, if not the outfield, return to the original Orgcode,
* If there is an outfield in the middle and its parent department is not an outfield, return to the department code of the Outfield. And find all the departments under this department based on ReturnCode.
* SQL mainly uses Where--contact--with to recursively find
* @author 272343 Lili Wu
* @param
* @date 2017-6-12
* @return
*/
@Override
Public String Querycenterorsales (
String Orgcode) {
TODO auto-generated Method Stub
if (num = = 0) {
Divisiondepartmententity parententity = queryparent (Orgcode);
Parentcode = Parententity.getparentorgcode ();
SYSTEM.OUT.PRINTLN ("Initial value, Parentcode" + Parentcode);
Setting the initial ReturnCode
ReturnCode = Orgcode;
SYSTEM.OUT.PRINTLN ("Initial value, Orgcode" + Orgcode);
}
Query up to five times up
if (num<5) {
View the top department information for the current department
Divisiondepartmententity parent=queryparent (Parentcode);
num=num+1;
SYSTEM.OUT.PRINTLN ("Query nth times" + num);
If the upper section is an outfield, transfercenter is the field in the T_bas_org table
if ("Y". Equals (Parent.gettransfercenter ())) {
Get the Parentcode value for the parameter values of the next round of queries
Parentcode=parent.getparentorgcode ();
System.out.println ("Is outfield, parentcode" + Parentcode);
To re-assign a value to Returuncode
Returncode=parent.getcode ();
System.out.println ("Is outfield, returncode" + ReturnCode);
}else{
If not the outfield, to determine whether it is the first query, if not the first time, return to ReturnCode, end the program
if (!returncode.equals (Orgcode) &&num!=1) {
System.out.println ("Not outfield, ReturnCode" + ReturnCode);
return ReturnCode;
}
}
function recursive call, call function itself
Querycenterorsales (Parentcode);
}
If it's always the outfield, at the top, return the field values that are finally assigned
return ReturnCode;
}
Java Recursive invocation instance