this.sql="select t.id,t.subcompanyname,t.supsubcomid,("+this.subCompanyCountSql+(getDetachSql("").equals("")?"":" and "+getDetachSql(""))+syncSearchSql+"),"+
this.sql="select t.id,t.subcompanyname,t.supsubcomid,("+this.subCompanyCountSql+(getDetachSql("").equals("")?"":" and "+getDetachSql(""))+"),"+
"(select COUNT(id) from "+subCompanyTabName+" where supsubcomid = t.id "+syncSearchSql+") as supCount"+
hasnextsql+",t.tlevel from "+subCompanyTabName+" t where "+appointCompanySql+"(t.canceled IS NULL OR t.canceled !='1') and t.id != t.supsubcomid "+(this.cg.length>0?StringUtil.vString(this.cg[0]):"")+supcompanyConditionSql+syncSearchSql+" order by t.supsubcomid,t.showorder,t.subcompanyname";
this.rs.executeSql(this.sql);
this.rs.execute(this.sql);
rs.writeLog("init:"+this.sql);
MOrgChartbean=null;
MOrgChartbean;
while(this.rs.next()){
intsubHasNext=this.rs.getInt(6);
intdeptHasNext=this.rs.getInt(7);
@ -122,7 +114,7 @@ public class DanikorOrgChartManager {
"("+this.departmentCountSql+(getDetachSql("").equals("")?"":" and"+getDetachSql(""))+"),t.supdepid,(select COUNT(id) from "+departmentTableName+" where supdepid = t.id) as supCount," +
"("+this.departmentCountSql+(getDetachSql("").equals("")?"":" and"+getDetachSql(""))+"),t.supdepid,(select COUNT(id) from "+departmentTableName+" where supdepid = t.id " +syncSearchSql+") as supCount," +
"(case when t.supdepid != 0 and (select COUNT(id) from "+departmentTableName+" where id = t.supdepid)=0 then 0 else 1 end) as isExist"+
hasNextSql+",t.tlevel from "+departmentTableName+" t where "+checkSupdepid+appendSql+" and (t.canceled IS NULL OR t.canceled !='1') and (t.canceled IS NULL OR t.canceled !='1') order by t.subcompanyid1 asc , t.supdepid asc , t.showorder asc, t.departmentname asc";
this.rs.executeSql(this.sql);
hasNextSql+",t.tlevel from "+departmentTableName+" t where "+checkSupdepid+appendSql+" and (t.canceled IS NULL OR t.canceled !='1') and (t.canceled IS NULL OR t.canceled !='1') "+syncSearchSql+" order by t.subcompanyid1 asc , t.supdepid asc , t.showorder asc, t.departmentname asc";
Stringsubsql=",(select distinct 1 as hasnext from "+subCompanyTabName+" s where (s.supsubcomid=t.id and (s.CANCELED IS NULL OR s.CANCELED !='1')) ) as hassubnext";
Stringdeptsql=",(select distinct 1 as hasnext from "+departmentTableName+" d where (d.subcompanyid1=t.id and (d.CANCELED IS NULL OR d.CANCELED !='1')) ) as hasdeptnext";
@ -355,28 +337,35 @@ public class DanikorOrgChartManager {
Stringsql=",(select distinct 1 as hasnext from "+departmentTableName+" d where d.supdepid=t.id and (CANCELED IS NULL OR CANCELED !='1')) as hasnext";
StringwhereSql;
if(isCurrentDate){
departmentTableName="hrmdepartment";
whereSql="where d.supdepid=t.id and (CANCELED IS NULL OR CANCELED !='1')";
}else{
departmentTableName="hrmdepartment_back";
whereSql="where d.supdepid=t.id and (CANCELED IS NULL OR CANCELED !='1')"+syncSearchSql;
}
Stringsql=",(select distinct 1 as hasnext from "+departmentTableName+" d "+whereSql+") as hasnext";
if(isMysql){
//8.0版本的mysql distinct 1 的时候会出现多条数据
sql=",(select distinct if(d.supdepid is null,null,1) as hasnext from "+departmentTableName+" d where d.supdepid=t.id and (CANCELED IS NULL OR CANCELED !='1')) as hasnext";
sql=",(select distinct if(d.supdepid is null,null,1) as hasnext from "+departmentTableName+" d " +whereSql+") as hasnext";
sql.append(" WITH RECURSIVE allSub AS ( SELECT ID FROM ");
sql.append(arg1).append(" WHERE ID = ").append(arg0).append(" UNION ALL SELECT a.ID FROM ").append(arg1)
@ -401,9 +390,9 @@ public class DanikorOrgChartManager {
}
sql.append("select a.idCount,b.id from (").append(StringUtil.replace(arg4,"{ids}",arg5.toString())).append(") a, (").append(arg5.toString()).append(") b ");
@ -457,123 +431,49 @@ public class DanikorOrgChartManager {
privatevoidinitCountSql(){
StringasNamefora=useAppDetach?"hrmresource":"a";
StringasNameforb=useAppDetach?"hrmresource":"b";
StringasNameforc=useAppDetach?"hrmresource":"c";
if(this.isPOrg){
if(StringUtil.isNull(this.cmd)){
if(this.isCurrentDate){
this.companyCountSql="select COUNT(id) from HrmResource where 1=1 "+this.status;
this.subCompanyCountSql="select COUNT("+asNamefora+".id) from HrmResource "+asNamefora+" right join HrmDepartment b on "+asNamefora+".departmentid = b.id where "+asNamefora+".subcompanyid1=t.id and (b.canceled IS NULL OR b.canceled !='1') "+this.status;
this.departmentCountSql="select COUNT(id) from HrmResource where departmentid=t.id "+this.status;
}elseif(this.cmd.equals("doc")){
this.companyCountSql="select COUNT(id) from DocDetail where (maincategory >= 1 or maincategory <= -1) and (subcategory >= 1 or subcategory <= -1) and (seccategory >= 1 or seccategory <= -1) "+this.docStatus;
this.subCompanyCountSql="select COUNT(a.id) from DocDetail a where a.ownerid in (select id from HrmResource where subcompanyid1 = t.id) and (a.maincategory >= 1 or a.maincategory <= -1) and (a.subcategory >= 1 or a.subcategory <= -1) and (a.seccategory >= 1 or a.seccategory <= -1) "+this.docStatus;
this.departmentCountSql="select COUNT(a.id) from DocDetail a where a.ownerid in (select id from HrmResource where departmentid = t.id) and (a.maincategory >= 1 or a.maincategory <= -1) and (a.subcategory >= 1 or a.subcategory <= -1) and (a.seccategory >= 1 or a.seccategory <= -1) "+this.docStatus;
}elseif(this.cmd.equals("customer")){
this.companyCountSql="select COUNT(id) from CRM_CustomerInfo where (deleted is null or deleted!=1) "+this.customerType+this.customerStatus;
this.subCompanyCountSql="select COUNT(id) from CRM_CustomerInfo where manager in (select id from HrmResource where subcompanyid1 = t.id) and (deleted is null or deleted!=1) "+this.customerType+this.customerStatus;
this.departmentCountSql="select COUNT(id) from CRM_CustomerInfo where manager in (select id from HrmResource where departmentid = t.id) and (deleted is null or deleted!=1) "+this.customerType+this.customerStatus;
}elseif(this.cmd.equals("project")){
this.companyCountSql="select COUNT(id) from Prj_ProjectInfo where 1=1 "+this.workType+this.projectStatus;
this.subCompanyCountSql="select COUNT(id) from Prj_ProjectInfo where manager in (select id from HrmResource where subcompanyid1 = t.id) "+this.workType+this.projectStatus;
this.departmentCountSql="select COUNT(id) from Prj_ProjectInfo where manager in (select id from HrmResource where departmentid = t.id) "+this.workType+this.projectStatus;
}
}else{
if(StringUtil.isNull(this.cmd)){
this.companyCountSql="select COUNT(a.id) from HrmResourceVirtual a right join HrmResource "+asNameforb+" on a.resourceid = "+asNameforb+".id where a.subcompanyid in ( select id from hrmsubcompanyVirtual where companyid = "+this.cvBean.getId()+" ) "+this.status;
this.subCompanyCountSql="select COUNT(a.id) from HrmResourceVirtual a right join HrmDepartmentVirtual b on a.departmentid = b.id right join HrmResource "+asNameforc+" on a.resourceid = "+asNameforc+".id where a.subcompanyid = t.id and (b.canceled IS NULL OR b.canceled !='1') "+this.status;
this.departmentCountSql="select COUNT(a.id) from HrmResourceVirtual a right join HrmResource "+asNameforc+" on a.resourceid = "+asNameforc+".id where a.departmentid=t.id "+this.status;
}elseif(this.cmd.equals("doc")){
this.companyCountSql="select COUNT(id) from DocDetail where ownerid in (select resourceid from HrmResourceVirtual where subcompanyid in (select id from hrmsubcompanyVirtual where companyid = "+this.cvBean.getId()+")) and (maincategory >= 1 or maincategory <= -1) and (subcategory >= 1 or subcategory <= -1) and (seccategory >= 1 or seccategory <= -1) "+this.docStatus;
this.subCompanyCountSql="select COUNT(a.id) from DocDetail a where a.ownerid in (select id from HrmResourceVirtual where subcompanyid = t.id) and (a.maincategory >= 1 or a.maincategory <= -1) and (a.subcategory >= 1 or a.subcategory <= -1) and (a.seccategory >= 1 or a.seccategory <= -1) "+this.docStatus;
this.departmentCountSql="select COUNT(a.id) from DocDetail a where a.ownerid in (select id from HrmResourceVirtual where departmentid = t.id) and (a.maincategory >= 1 or a.maincategory <= -1) and (a.subcategory >= 1 or a.subcategory <= -1) and (a.seccategory >= 1 or a.seccategory <= -1) "+this.docStatus;
}elseif(this.cmd.equals("customer")){
this.companyCountSql="select COUNT(id) from CRM_CustomerInfo where (deleted is null or deleted!=1) and manager in (select resourceid from HrmResourceVirtual where subcompanyid in (select id from hrmsubcompanyVirtual where companyid = "+this.cvBean.getId()+")) "+this.customerType+this.customerStatus;
this.subCompanyCountSql="select COUNT(id) from CRM_CustomerInfo where manager in (select id from HrmResourceVirtual where subcompanyid = t.id) and (deleted is null or deleted!=1) "+this.customerType+this.customerStatus;
this.departmentCountSql="select COUNT(id) from CRM_CustomerInfo where manager in (select id from HrmResourceVirtual where departmentid = t.id) and (deleted is null or deleted!=1) "+this.customerType+this.customerStatus;
}elseif(this.cmd.equals("project")){
this.companyCountSql="select COUNT(id) from Prj_ProjectInfo where manager in (select resourceid from HrmResourceVirtual where subcompanyid in (select id from hrmsubcompanyVirtual where companyid = "+this.cvBean.getId()+")) "+this.workType+this.projectStatus;
this.subCompanyCountSql="select COUNT(id) from Prj_ProjectInfo where manager in (select id from HrmResourceVirtual where subcompanyid = t.id) "+this.workType+this.projectStatus;
this.departmentCountSql="select COUNT(id) from Prj_ProjectInfo where manager in (select id from HrmResourceVirtual where departmentid = t.id) "+this.workType+this.projectStatus;
}
this.companyCountSql="select COUNT(id) from HrmResource_back where 1=1 "+this.status+syncSearchSql;
this.subCompanyCountSql="select COUNT("+asNamefora+".id) from HrmResource_back "+asNamefora+" right join HrmDepartment_back b on "+asNamefora+".departmentid = b.id and "+asNamefora+".sync_date = b.sync_date where "+asNamefora+".subcompanyid1=t.id and (b.canceled IS NULL OR b.canceled !='1') "+this.status+getSyncSearchSql("b");
this.departmentCountSql="select COUNT(id) from HrmResource_back where departmentid=t.id "+this.status+syncSearchSql;
}
}
privateStringinitSubDepartmentCountSql(){
Stringsql="";
StringasNameforb=useAppDetach?"hrmresource":"b";
StringasNameforc=useAppDetach?"hrmresource":"c";
if(this.isPOrg){
if(StringUtil.isNull(this.cmd)){
Stringsql;
if(this.isCurrentDate){
sql=("select COUNT(id)as idCount from HrmResource where departmentid in ({ids}) "+this.status);
}elseif(this.cmd.equals("doc")){
sql=("select COUNT(a.id)as idCount from DocDetail a where a.ownerid in (select id from HrmResource where departmentid in ({ids})) and (a.maincategory >= 1 or a.maincategory <= -1) and (a.subcategory >= 1 or a.subcategory <= -1) and (a.seccategory >= 1 or a.seccategory <= -1) "+this.docStatus);
}elseif(this.cmd.equals("customer")){
sql=("select COUNT(id)as idCount from CRM_CustomerInfo where manager in (select id from HrmResource where departmentid in ({ids})) and (deleted is null or deleted!=1) "+this.customerType+this.customerStatus);
}elseif(this.cmd.equals("project")){
sql=("select COUNT(id)as idCount from Prj_ProjectInfo where manager in (select id from HrmResource where departmentid in ({ids})) "+this.workType+this.projectStatus);
}
}else{
if(StringUtil.isNull(this.cmd)){
sql=("select COUNT(a.id)as idCount from HrmResourceVirtual a right join HrmResource "+asNameforc+" on a.resourceid = "+asNameforc+".id where a.departmentid in ({ids}) "+this.status);
}elseif(this.cmd.equals("doc")){
sql=("select COUNT(a.id)as idCount from DocDetail a where a.ownerid in (select a.resourceid from HrmResourceVirtual a right join HrmResource b on a.resourceid = b.id where a.departmentid in ({ids})) and (a.maincategory >= 1 or a.maincategory <= -1) and (a.subcategory >= 1 or a.subcategory <= -1) and (a.seccategory >= 1 or a.seccategory <= -1) "+this.docStatus);
}elseif(this.cmd.equals("customer")){
sql=("select COUNT(id)as idCount from CRM_CustomerInfo where manager in (select a.resourceid from HrmResourceVirtual a right join HrmResource b on a.resourceid = b.id where a.departmentid in ({ids})) and (deleted is null or deleted!=1) "+this.customerType+this.customerStatus);
}elseif(this.cmd.equals("project")){
sql=("select COUNT(id)as idCount from Prj_ProjectInfo where manager in (select a.resourceid from HrmResourceVirtual a right join HrmResource b on a.resourceid = b.id where a.departmentid in ({ids})) "+this.workType+this.projectStatus);
}
sql=("select COUNT(id)as idCount from HrmResource_back where departmentid in ({ids}) "+this.status+syncSearchSql);
}
returnsql;
}
privateStringinitSubCompanyCountSql(){
Stringsql="";
StringasNameforb=useAppDetach?"hrmresource":"b";
StringasNameforc=useAppDetach?"hrmresource":"c";
if(this.isPOrg){
if(StringUtil.isNull(this.cmd)){
sql=("select COUNT(id) as idCount from HrmResource where subcompanyid1 in ({ids}) "+this.status);
}elseif(this.cmd.equals("doc")){
sql=("select COUNT(a.id)as idCount from DocDetail a where a.ownerid in (select id from HrmResource where subcompanyid1 in ({ids})) and (a.maincategory >= 1 or a.maincategory <= -1) and (a.subcategory >= 1 or a.subcategory <= -1) and (a.seccategory >= 1 or a.seccategory <= -1) "+this.docStatus);
}elseif(this.cmd.equals("customer")){
sql=("select COUNT(id)as idCount from CRM_CustomerInfo where manager in (select id from HrmResource where subcompanyid1 in ({ids})) and (deleted is null or deleted!=1) "+this.customerType+this.customerStatus);
}elseif(this.cmd.equals("project")){
sql=("select COUNT(id)as idCount from Prj_ProjectInfo where manager in (select id from HrmResource where subcompanyid1 in ({ids})) "+this.workType+this.projectStatus);
}
Stringsql;
if(isCurrentDate){
sql=("select COUNT(id) as idCount from HrmResource where subcompanyid1 in ({ids}) "+status);
}else{
if(StringUtil.isNull(this.cmd)){
sql=("select COUNT(a.id)as idCount from HrmResourceVirtual a right join HrmResource "+asNameforc+" on a.resourceid = "+asNameforc+".id where a.subcompanyid in ({ids}) "+this.status);
}elseif(this.cmd.equals("doc")){
sql=("select COUNT(a.id)as idCount from DocDetail a where a.ownerid in (select a.resourceid from HrmResourceVirtual a right join HrmResource b on a.resourceid = b.id where a.subcompanyid in ({ids})) and (a.maincategory >= 1 or a.maincategory <= -1) and (a.subcategory >= 1 or a.subcategory <= -1) and (a.seccategory >= 1 or a.seccategory <= -1) "+this.docStatus);
}elseif(this.cmd.equals("customer")){
sql=("select COUNT(id)as idCount from CRM_CustomerInfo where manager in (select a.resourceid from HrmResourceVirtual a right join HrmResource b on a.resourceid = b.id where a.subcompanyid in ({ids})) and (deleted is null or deleted!=1) "+this.customerType+this.customerStatus);
}elseif(this.cmd.equals("project")){
sql=("select COUNT(id)as idCount from Prj_ProjectInfo where manager in (select a.resourceid from HrmResourceVirtual a right join HrmResource b on a.resourceid = b.id where a.subcompanyid in ({ids})) "+this.workType+this.projectStatus);
}
sql=("select COUNT(a.id)as idCount from HrmResource_back a where a.subcompanyid in ({ids}) "+status+syncSearchSql);
}
returnsql;
}
publicintgetCompanyResourceCount(){
this.rs.executeSql(this.companyCountSql+((getDetachSql("").equals(""))?" and 1=1":(" and "+getDetachSql(""))));
this.rs.execute(this.companyCountSql+((getDetachSql("").equals(""))?" and 1=1":(" and "+getDetachSql(""))));