安卓手机系统升级-360xp盾甲

java递归函数
2023年4月1日发(作者:苹果手机录屏功能在哪里)

java递归函数⽣成部门层级树

⼀、数据库表结构

1、mysql数据库建表语句

------------------------------

--Tablestructurefort_sap_dept

------------------------------

DROPTABLEIFEXISTS`t_sap_dept`;

CREATETABLE`t_sap_dept`(

`add_user`varchar(32)NOTNULLCOMMENT'创建⼈',

`add_time`datetimeNOTNULLCOMMENT'创建时间',

`update_user`varchar(32)DEFAULTNULLCOMMENT'修改⼈',

`update_time`datetimeDEFAULTNULLCOMMENT'修改时间',

`valid_status`varchar(3)DEFAULTNULLCOMMENT'是否有效0⽆效1有效',

`delete_status`varchar(3)DEFAULTNULLCOMMENT'是否删除0未删除1已删除',

`org_id`varchar(32)NOTNULLCOMMENT'部门id',

`org_name`varchar(150)NOTNULLCOMMENT'部门名称',

`org_level`varchar(2)DEFAULTNULLCOMMENT'部门层级',

`status`varchar(3)DEFAULTNULLCOMMENT'是否启⽤0未启⽤1启⽤',

`sup_org_id`varchar(32)DEFAULTNULLCOMMENT'上级组织id',

`flag1`varchar(255)DEFAULTNULL,

`flag2`varchar(255)DEFAULTNULL,

`flag3`varchar(255)DEFAULTNULL,

`flag4`varchar(255)DEFAULTNULL,

PRIMARYKEY(`org_id`)

)ENGINE=InnoDBDEFAULTCHARSET=utf8;

2、mysql数据库插⼊语句

INSERTINTOt_sap_deptVALUES('system','2021-2-2417:12:53',NULL,NULL,'1','0','00030437','天猫信息服务有限',NULL,'1','00037534','D','','','U

');

INSERTINTOt_sap_deptVALUES('system','2021-2-2417:12:53',NULL,NULL,'1','0','00032794','技术管理科',NULL,'1','00030437','E','','008604000

2','U');

INSERTINTOt_sap_deptVALUES('system','2021-2-2417:12:53',NULL,NULL,'1','0','00032797','⽤户运营模块',NULL,'1','00030437','F','','0086090

002','U');

INSERTINTOt_sap_deptVALUES('system','2021-2-2417:12:53',NULL,NULL,'1','0','00034537','产品管理模块',NULL,'1','00030437','F','','0086040

001','U');

INSERTINTOt_sap_deptVALUES('system','2021-2-2417:12:53',NULL,NULL,'1','0','00037364','风控平台模块',NULL,'1','10000551','F','','','U');

INSERTINTOt_sap_deptVALUES('system','2021-2-2417:12:53',NULL,NULL,'1','0','10000548','技术⼆模块',NULL,'1','00032794','F','','008604000

2','U');

INSERTINTOt_sap_deptVALUES('system','2021-2-2417:12:53',NULL,NULL,'1','0','10000549','技术三模块',NULL,'1','00032794','F','','008604000

2','U');

INSERTINTOt_sap_deptVALUES('system','2021-2-2417:12:53',NULL,NULL,'1','0','10000550','运维模块',NULL,'1','00032794','F','',''

,'U');

INSERTINTOt_sap_deptVALUES('system','2021-2-2417:12:53',NULL,NULL,'1','0','10000551','业务发展⼀科',NULL,'1','00030437','E','','','U');

INSERTINTOt_sap_deptVALUES('system','2021-2-2417:12:53',NULL,NULL,'1','0','10000552','业务发展⼆科',NULL,'1','00030437','E','','','U');

INSERTINTOt_sap_deptVALUES('system','2021-2-2417:12:53',NULL,NULL,'1','0','10000553','技术⼀模块',NULL,'1','00032794','F','','008604000

2','U');

INSERTINTOt_sap_deptVALUES('system','2021-2-2417:12:53',NULL,NULL,'1','0','10000554','⾦融业务模块',NULL,'1','10000551','F','','','U');

3、mysql数据库插⼊截图

⼆、创建数据库实体类

1、创建实体类SapDept

;

tity;

;

/**

*部门表

*

*/

publicclassSapDeptextendsBaseEntity{

privatestaticfinallongserialVersionUID=5275435492439961860L;

/**

*状态-⽆效

*/

publicstaticStringSTATUS_FALSE="0";

/**

*状态-有效

*/

publicstaticStringSTATUS_TRUE="1";

/**删除状态0-未删除1-删除*/

privateStringdeleteStatus;

/**有效状态0-⽆效1-有效*/

privateStringvalidStatus;

/**新增⼈userId*/

privateStringaddUser;

/**新增时间*/

privateDateaddTime;

/**更新⼈userId*/

privateStringupdateUser;

/**更新时间*/

privateDateupdateTime;

/**部门ID*/

privateStringorgId;

/**部门名称*/

privateStringorgName;

/**上级部门ID*/

privateStringsupOrgId;

/**部门层级*/

privateStringorgLevel;

/**部门状态*/

privateStringstatus;

/**标记1*/

privateStringflag1;

/**标记2*/

privateStringflag2;

/**标记3*/

privateStringflag3;

/**标记4*/

privateStringflag4;

publicStringgetDeleteStatus(){

returndeleteStatus;

}

publicvoidsetDeleteStatus(StringdeleteStatus){

Status=deleteStatus;

}

publicStringgetValidStatus(){

returnvalidStatus;

}

publicvoidsetValidStatus(StringvalidStatus){

tatus=validStatus;

}

publicStringgetAddUser(){

returnaddUser;

}

publicvoidsetAddUser(StringaddUser){

r=addUser;

}

publicDategetAddTime(){

returnaddTime;

}

publicvoidsetAddTime(DateaddTime){

e=addTime;

}

publicStringgetUpdateUser(){

returnupdateUser;

}

publicvoidsetUpdateUser(StringupdateUser){

User=updateUser;

}

publicDategetUpdateTime(){

returnupdateTime;

}

publicvoidsetUpdateTime(DateupdateTime){

Time=updateTime;

}

publicStringgetOrgId(){

returnorgId;

}

publicvoidsetOrgId(StringorgId){

=orgId;

}

publicStringgetOrgName(){

returnorgName;

}

publicvoidsetOrgName(StringorgName){

e=orgName;

}

publicStringgetSupOrgId(){

returnsupOrgId;

}

publicvoidsetSupOrgId(StringsupOrgId){

Id=supOrgId;

}

publicStringgetOrgLevel(){

returnorgLevel;

}

publicvoidsetOrgLevel(StringorgLevel){

el=orgLevel;

}

publicStringgetStatus(){

returnstatus;

}

publicvoidsetStatus(Stringstatus){

=status;

}

publicStringgetFlag1(){

returnflag1;

}

publicvoidsetFlag1(Stringflag1){

1=flag1;

}

publicStringgetFlag2(){

returnflag2;

}

publicvoidsetFlag2(Stringflag2){

2=flag2;

}

publicStringgetFlag3(){

returnflag3;

}

publicvoidsetFlag3(Stringflag3){

publicvoidsetFlag3(Stringflag3){

3=flag3;

}

publicStringgetFlag4(){

returnflag4;

}

publicvoidsetFlag4(Stringflag4){

4=flag4;

}

}

2、数据库Mapper⽂件

<?xmlversion="1.0"encoding="UTF-8"?>

org_id,add_user,add_time,update_user,update_time,valid_status,delete_status,

org_name,org_level,status,sup_org_id,flag1,flag2,flag3,flag4

SELECT

FROMt_sap_dept

WHEREorg_id=#{orgId,jdbcType=VARCHAR}

SELECT

FROMt_sap_dept

ANDorg_id=#{orgId,jdbcType=VARCHAR}

ANDadd_user=#{addUser,jdbcType=VARCHAR}

ANDadd_time=#{addTime,jdbcType=TIMESTAMP}

ANDupdate_user=#{updateUser,jdbcType=VARCHAR}

ANDupdate_time=#{updateTime,jdbcType=TIMESTAMP}

ANDupdate_time=#{updateTime,jdbcType=TIMESTAMP}

ANDvalid_status=#{validStatus,jdbcType=VARCHAR}

ANDdelete_status=#{deleteStatus,jdbcType=VARCHAR}

ANDorg_name=#{orgName,jdbcType=VARCHAR}

ANDorg_level=#{orgLevel,jdbcType=VARCHAR}

ANDstatus=#{status,jdbcType=VARCHAR}

ANDsup_org_id=#{supOrgId,jdbcType=VARCHAR}

ANDflag1=#{flag1,jdbcType=VARCHAR}

ANDflag2=#{flag2,jdbcType=VARCHAR}

ANDflag3=#{flag3,jdbcType=VARCHAR}

ANDflag4=#{flag4,jdbcType=VARCHAR}

SELECT

FROMt_sap_dept

ANDorg_id=#{orgId,jdbcType=VARCHAR}

ANDadd_user=#{addUser,jdbcType=VARCHAR}

ANDadd_time=#{addTime,jdbcType=TIMESTAMP}

ANDupdate_user=#{updateUser,jdbcType=VARCHAR}

ANDupdate_time=#{updateTime,jdbcType=TIMESTAMP}

ANDvalid_status=#{validStatus,jdbcType=VARCHAR}

ANDdelete_status=#{deleteStatus,jdbcType=VARCHAR}

ANDorg_name=#{orgName,jdbcType=VARCHAR}

ANDorg_level=#{orgLevel,jdbcType=VARCHAR}

ANDorg_level=#{orgLevel,jdbcType=VARCHAR}

ANDstatus=#{status,jdbcType=VARCHAR}

ANDsup_org_id=#{supOrgId,jdbcType=VARCHAR}

ANDflag1=#{flag1,jdbcType=VARCHAR}

ANDflag2=#{flag2,jdbcType=VARCHAR}

ANDflag3=#{flag3,jdbcType=VARCHAR}

ANDflag4=#{flag4,jdbcType=VARCHAR}

DELETEFROMt_sap_dept

WHEREorg_id=#{orgId,jdbcType=VARCHAR}

INSERTINTOt_sap_dept(

org_id,add_user,add_time,update_user,update_time,valid_status,delete_status,

org_name,org_level,status,sup_org_id,flag1,flag2,flag3,flag4

)

VALUES(

#{orgId,jdbcType=VARCHAR},#{addUser,jdbcType=VARCHAR},#{addTime,jdbcType=TIMESTAMP},

#{updateUser,jdbcType=VARCHAR},#{updateTime,jdbcType=TIMESTAMP},#{validStatus,jdbcType=VARCHAR},

#{deleteStatus,jdbcType=VARCHAR},#{orgName,jdbcType=VARCHAR},#{orgLevel,jdbcType=VARCHAR},

#{status,jdbcType=VARCHAR},#{supOrgId,jdbcType=VARCHAR},#{flag1,jdbcType=VARCHAR},#{flag2,jdbcType=VARCHAR},

#{flag3,jdbcType=VARCHAR},#{flag4,jdbcType=VARCHAR}

)

INSERTINTOt_sap_dept

org_id,

add_user,

add_time,

update_user,

update_time,

valid_status,

delete_status,

org_name,

org_level,

status,

sup_org_id,

flag1,

flag2,

flag3,

flag4,

#{orgId,jdbcType=VARCHAR},

#{addUser,jdbcType=VARCHAR},

#{addTime,jdbcType=TIMESTAMP},

#{updateUser,jdbcType=VARCHAR},

#{updateTime,jdbcType=TIMESTAMP},

#{validStatus,jdbcType=VARCHAR},

#{deleteStatus,jdbcType=VARCHAR},

#{orgName,jdbcType=VARCHAR},

#{orgLevel,jdbcType=VARCHAR},

#{status,jdbcType=VARCHAR},

#{supOrgId,jdbcType=VARCHAR},

#{flag1,jdbcType=VARCHAR},

#{flag2,jdbcType=VARCHAR},

#{flag3,jdbcType=VARCHAR},

#{flag4,jdbcType=VARCHAR},

UPDATEt_sap_dept

add_user=#{addUser,jdbcType=VARCHAR},

add_time=#{addTime,jdbcType=TIMESTAMP},

update_user=#{updateUser,jdbcType=VARCHAR},

update_time=#{updateTime,jdbcType=TIMESTAMP},

valid_status=#{validStatus,jdbcType=VARCHAR},

delete_status=#{deleteStatus,jdbcType=VARCHAR},

org_name=#{orgName,jdbcType=VARCHAR},

org_level=#{orgLevel,jdbcType=VARCHAR},

status=#{status,jdbcType=VARCHAR},

sup_org_id=#{supOrgId,jdbcType=VARCHAR},

flag1=#{flag1,jdbcType=VARCHAR},

flag2=#{flag2,jdbcType=VARCHAR},

flag3=#{flag3,jdbcType=VARCHAR},

flag4=#{flag4,jdbcType=VARCHAR},

WHEREorg_id=#{orgId,jdbcType=VARCHAR}

UPDATEt_sap_dept

SETadd_user=#{addUser,jdbcType=VARCHAR},

add_time=#{addTime,jdbcType=TIMESTAMP},

update_user=#{updateUser,jdbcType=VARCHAR},

update_time=#{updateTime,jdbcType=TIMESTAMP},

valid_status=#{validStatus,jdbcType=VARCHAR},

delete_status=#{deleteStatus,jdbcType=VARCHAR},

org_name=#{orgName,jdbcType=VARCHAR},

org_level=#{orgLevel,jdbcType=VARCHAR},

org_level=#{orgLevel,jdbcType=VARCHAR},

status=#{status,jdbcType=VARCHAR},

sup_org_id=#{supOrgId,jdbcType=VARCHAR},

flag1=#{flag1,jdbcType=VARCHAR},

flag2=#{flag2,jdbcType=VARCHAR},

flag3=#{flag3,jdbcType=VARCHAR},

flag4=#{flag4,jdbcType=VARCHAR}

WHEREorg_id=#{orgId,jdbcType=VARCHAR}

INSERTINTOt_sap_dept(

org_id,add_user,add_time,update_user,update_time,valid_status,delete_status,

org_name,org_level,status,sup_org_id,flag1,flag2,flag3,flag4

)

VALUES

(

#{,jdbcType=VARCHAR},#{r,jdbcType=VARCHAR},#{e,jdbcType=TIMESTAMP},

#{User,jdbcType=VARCHAR},#{Time,jdbcType=TIMESTAMP},#{tatus,jdbcType=VARCHAR},

#{Status,jdbcType=VARCHAR},#{e,jdbcType=VARCHAR},#{el,jdbcType=VARCHAR},

#{,jdbcType=VARCHAR},#{Id,jdbcType=VARCHAR},#{1,jdbcType=VARCHAR},#{2,jdbcType=VARCHAR},

#{3,jdbcType=VARCHAR},#{4,jdbcType=VARCHAR}

)

SELECTcount(1)as"totalCount"FROMt_sap_dept

ANDsup_org_id=#{supOrgId,jdbcType=VARCHAR}

ANDvalid_status=#{validStatus,jdbcType=VARCHAR}

ANDdelete_status=#{deleteStatus,jdbcType=VARCHAR}

truncatetablet_sap_dept

SELECT

FROMt_sap_dept

WHEREvalid_status='1'anddelete_status='0'

0">

#{item,jdbcType=VARCHAR}

3、申明SapDeptService类

e;

t;

taVO;

;

/**

*同步集团部门服务接⼝

*

*/

publicinterfaceSapDeptService{

/**

*组织列表[天猫⽹络及其⼦部门]

*

*

*@return

*/

TreeVOfindOrgAllTree();

/**

*组织ID列表[天猫⽹络及其⼦部门]

*

*

*@return

*/

ListfindAllOrgIdList();

}

4、SapDeptService类实现

;

;

tionUtils;

Utils;

tDeptConfig;

tDao;

t;

taVO;

tService;

tils;

;

Factory;

ils;

red;

e;

ctional;

ist;

;

;

er;

tors;

/**

*同步集团员⼯信息到本地

*/

@Service

publicclassSapDeptServiceImplimplementsSapDeptService{

privatestaticLoggerlogger=ger();

@Autowired

privateSapRootDeptConfigsapRootDeptConfig;

@Autowired

privateSapDeptDaosapDeptDao;

@Override

TreeVOfindOrgAllTree(){

TreeVOtreeOrgVO=TreeVO();

//1、获取全部相关组织

SapDeptsapDept=newSapDept();

tus(_STATUS_TRUE);

idStatus(_STATUS_TRUE);

eteStatus(_STATUS_FALSE);

ListsapDeptList=(sapDept);

//根部门ID

StringrootOrgId=Id();

//2.获取根节点

ListrootOrgList=().filter(m->{

if((rootOrgId,Id())){

returntrue;

}else{

returnfalse;

}

}).collect(());

if(mpty(rootOrgList)){

SapDeptrootOrg=(0);

treeOrg(treeOrgVO,sapDeptList,rootOrg);

}

returntreeOrgVO;

}

/**

*获取组织⼈员树状结构

*

*@paramorgTreeVO返回类

*@paramsapDeptList组织列表

*@paramsupSapDept上级组织节点

*/

privatevoidtreeOrg(TreeVOorgTreeVO,ListsapDeptList,SapDeptsupSapDept){

operties(supSapDept,orgTreeVO);

ListorgNameVOList=().filter(m->(Id(),OrgId())).m

ap(m->{

TreeVOnodeOrgTreeVO=TreeVO();

operties(m,nodeOrgTreeVO);

treeOrg(nodeOrgTreeVO,sapDeptList,m);

returnnodeOrgTreeVO;

}).collect(());

Nodes(orgNameVOList);

}

@Override

publicListfindAllOrgIdList(){

ListorgIdList=newArrayList<>();

TreeVOorgAllTree=findOrgAllTree();

if(orgAllTree!=null){

(Id());

getChildNodeOrgId(orgIdList,Nodes());

}

returnorgIdList;

}

privatevoidgetChildNodeOrgId(ListorgIdList,ListorgNodes){

if(mpty(orgNodes)){

().forEach(newConsumer(){

@Override

@Override

publicvoidaccept(TreeVOorgALLTreeVO){

(Id());

getChildNodeOrgId(orgIdList,Nodes());

}

});

}

}

}

链接:.

更多推荐

java递归函数