/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights reserved. <a>http://www.cqcis.com</a>
 */
package com.crunii.micro.service.sysmgr.jdbc;

import cn.hutool.core.util.ObjectUtil;
import com.crunii.micro.common.constants.CommonConstants;
import com.crunii.micro.common.dto.PageReq;
import com.crunii.micro.common.dto.PageRsp;
import com.crunii.micro.common.utils.SqlUtil;
import com.alibaba.cloud.commons.lang.StringUtils;
import com.crunii.micro.core.annotation.InjectProperty;
import com.crunii.micro.domain.common.jdbc.BaseJdbcTemplate;
import com.crunii.micro.domain.common.jdbc.BaseNPJdbcTemplate;
import com.crunii.micro.domain.dto.Worker;
import com.crunii.micro.domain.entity.main.TsmOrg;
import com.crunii.micro.domain.util.CurrWorkerUtil;
import com.crunii.micro.service.sysmgr.api.domain.dto.OrgNode;
import com.crunii.micro.service.sysmgr.dto.ChildrenStatisticsRspVO;
import com.crunii.micro.service.sysmgr.dto.org.*;
import com.crunii.micro.service.sysmgr.dto.sysmgr.OrgDto;
import com.crunii.micro.service.sysmgr.dto.sysmgr.OrgTabulationDto;
import com.google.common.base.Joiner;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;


import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 田平 create 2017年8月11日下午12:44:04
 */
@Repository
public class OrgJdbcDao {

	@Resource(name = "mainJT")
	protected BaseJdbcTemplate JT;

	@Resource(name = "mainNPJT")
	protected BaseNPJdbcTemplate NPJT;

	private static final String checkOrgCodeSql = "select count(*) from tsm_org where org_code=? ";

	public boolean checkOrgCode(String orgCode) {
		return JT.queryForRawObject(Boolean.class, checkOrgCodeSql, orgCode);
	}

	private static final String getOrgChildrenSql =
			" SELECT a.*,(select pro.value_name from tsm_property_value pro,tsm_property property WHERE pro.prop_id=property.prop_id AND property.prop_code='region' and a.region = pro.value_code) region_name, " +
					" (select pro.value_name from tsm_property_value pro,tsm_property property WHERE pro.prop_id=property.prop_id AND property.prop_code='zone' and a.zone = pro.value_code) zone_name, " +
					" (select pro.value_name from tsm_property_value pro,tsm_property property WHERE pro.prop_id=property.prop_id AND property.prop_code='industryCategory' and a.industry_category = pro.value_code) industry_category_name, " +
					" (select pro.value_name from tsm_property_value pro,tsm_property property WHERE pro.prop_id=property.prop_id AND property.prop_code='orgCategoryTree' and a.org_category_tree = pro.value_code) org_category_tree_name, " +
					" (select pro.value_name from tsm_property_value pro,tsm_property property WHERE pro.prop_id=property.prop_id AND property.prop_code='ocylIndustryCategory' and a.ocyl_industry_category = pro.value_code) ocyl_industry_category_name, " +
					" (select pro.value_name from tsm_property_value pro,tsm_property property WHERE pro.prop_id=property.prop_id AND property.prop_code='ocylOrgCategory' and a.ocyl_org_category = pro.value_code) ocyl_org_category_name, " +
					" (select pro.value_name from tsm_property_value pro,tsm_property property WHERE pro.prop_id=property.prop_id AND property.prop_code='affiliatingSystem' and a.affiliating_system = pro.value_code) affiliatingSystemName, " +
					" (select pro.value_name from tsm_property_value pro,tsm_property property WHERE pro.prop_id=property.prop_id AND property.prop_code='ocylIsXztw' and a.ocyl_is_xztw = pro.value_code) ocyl_is_xztw_name, a.parent_org_code ," +
					" c.org_name as parentOrgName , " +
					" b.worker_name as managePeopleName,b.login_id as managePeople,case when (SELECT COUNT(*) FROM tsm_org b WHERE b.parent_org_id=a.org_id)>0 then FALSE ELSE TRUE end leaf " +
					" from tsm_org a " +
					" left join tsm_worker b on a.manage_people=b.login_id" +
					" left join tsm_org c on a.parent_org_id=c.org_id " +
					" WHERE a.parent_org_id=? order by a.sort_id asc ";

	private static String getOrgChildrenSql_new =
			" SELECT a.*,(select pro.value_name from tsm_property_value pro,tsm_property property WHERE pro.prop_id=property.prop_id AND property.prop_code='region' and a.region = pro.value_code) region_name, " +
					" (select pro.value_name from tsm_property_value pro,tsm_property property WHERE pro.prop_id=property.prop_id AND property.prop_code='zone' and a.zone = pro.value_code) zone_name, " +
					" (select pro.value_name from tsm_property_value pro,tsm_property property WHERE pro.prop_id=property.prop_id AND property.prop_code='industryCategory' and a.industry_category = pro.value_code) industry_category_name, " +
					" (select pro.value_name from tsm_property_value pro,tsm_property property WHERE pro.prop_id=property.prop_id AND property.prop_code='orgCategoryTree' and a.org_category_tree = pro.value_code) org_category_tree_name, " +
					" (select pro.value_name from tsm_property_value pro,tsm_property property WHERE pro.prop_id=property.prop_id AND property.prop_code='ocylIndustryCategory' and a.ocyl_industry_category = pro.value_code) ocyl_industry_category_name, " +
					" (select pro.value_name from tsm_property_value pro,tsm_property property WHERE pro.prop_id=property.prop_id AND property.prop_code='ocylOrgCategory' and a.ocyl_org_category = pro.value_code) ocyl_org_category_name, " +
					" (select pro.value_name from tsm_property_value pro,tsm_property property WHERE pro.prop_id=property.prop_id AND property.prop_code='affiliatingSystem' and a.affiliating_system = pro.value_code) affiliatingSystemName, " +
					" (select pro.value_name from tsm_property_value pro,tsm_property property WHERE pro.prop_id=property.prop_id AND property.prop_code='ocylIsXztw' and a.ocyl_is_xztw = pro.value_code) ocyl_is_xztw_name, a.parent_org_code ," +
					" c.org_name as parentOrgName , " +
					" b.worker_name as managePeopleName,b.login_id as managePeople,case when (SELECT COUNT(*) FROM tsm_org b WHERE b.parent_org_id=a.org_id)>0 then FALSE ELSE TRUE end leaf " +
					" from tsm_org a " +
					" left join tsm_worker b on a.manage_people=b.login_id" +
					" left join tsm_org c on a.parent_org_id=c.org_id " +
					" WHERE a.parent_org_id=? ";

	private static final String getOrgChildrenSqlByParentOrgId =
			"SELECT distinct(a.org_id),a.*,b.worker_name as managePeopleName,b.login_id as managePeople,case when (SELECT COUNT(*) FROM tsm_org b WHERE b.parent_org_id=a.org_id)>0 then FALSE ELSE TRUE end leaf "+
					" from tsm_org a " +
					" inner join tsm_worker_org_all twoa on a.org_id=twoa.org_id " +
					" left join tsm_worker b on a.manage_people=b.login_id " +
					" WHERE a.parent_org_id = ?  and twoa.worker_id = ? ";

	public List<OrgNode> getOrgChildren(Long parentOrgId) {
		return JT.queryForBeans(OrgNode.class, getOrgChildrenSql, parentOrgId);
	}

	public List<OrgNode> getOrgChildrenNew(Long parentOrgId, Integer registrationSystemType) {
		if (null != registrationSystemType){
			String sql = getOrgChildrenSql_new +" and a.registration_system_type = ?  order by a.sort_id asc";
			return JT.queryForBeans(OrgNode.class, sql, parentOrgId, registrationSystemType);
		}
		return JT.queryForBeans(OrgNode.class, getOrgChildrenSql, parentOrgId);
	}

	public List<OrgNode> getOrgChildrenByParentOrgId(Long parentOrgId) {
		Worker currWorker = CurrWorkerUtil.getCurrWorker();
		return JT.queryForBeans(OrgNode.class, getOrgChildrenSqlByParentOrgId, parentOrgId,currWorker.getLoginId());
	}

	public List<OrgNode> findOrg(OrgDto orgDto) {
		String sql = "SELECT a.*,case when (SELECT COUNT(*) FROM tsm_org WHERE parent_org_id=a.org_id)>0 then FALSE ELSE TRUE end leaf  FROM TSM_ORG a WHERE 1 = 1";
		List<Object> list = new ArrayList<>();
		if(StringUtils.isNotEmpty(orgDto.getOrgName())){
			sql += " and a.org_name LIKE concat('%',?,'%')";
			list.add(orgDto.getOrgName());
		}
		return JT.queryForBeans(OrgNode.class, sql, list.toArray());
	}

	public void deleteWorkerOrgAllByUserId(List<Integer> workerIds,Integer recursiveOrNot) {
		String strWorkerIds = Joiner.on(",").join(workerIds);
		String sql = "delete from tsm_worker_org_all WHERE worker_id in(" + strWorkerIds + ") and recursive_or_not = "+recursiveOrNot+" ";
		JT.update(sql);
	}

	public List<TsmOrg> listByParentOrgIds(String parentOrgIds) {
		if (org.apache.commons.lang3.StringUtils.isNotBlank(parentOrgIds)) {
			String sql = "SELECT * from tsm_org WHERE parent_org_id in(" + parentOrgIds + ") limit 150000";
			return JT.queryForBeans(TsmOrg.class, sql);
		}
		return new ArrayList<>();
	}

	public List<TsmOrg> findByOrgIds(List<Long> orgIds) {
		if (orgIds.size() > 0) {
			String strOrgIds = Joiner.on(",").join(orgIds);
			String sql = "SELECT * FROM tsm_org WHERE org_id IN(" + strOrgIds + ")";
			return JT.queryForBeans(TsmOrg.class, sql);
		}
		return new ArrayList<>();
	}

	public List<OrgTreeDto> findOrgAuthority(Worker worker, OrgTreeAuthorityReqDto param) {
		String sql = " select a.org_id,a.org_name from tsm_org a inner join tsm_worker_org_all m on a.org_id=m.org_id where m.worker_id= ? and a.state = 1 ";
		List<Object> argList = new ArrayList<>();
		argList.add(worker.getLoginId());
		if(StringUtils.isNotEmpty(param.getOrgName())){
			sql += " and a.org_name LIKE concat('%',?,'%')";
			argList.add(param.getOrgName());
		}
		sql +=" limit 100 ";
		return JT.queryForBeans(OrgTreeDto.class, sql, argList.toArray());
	}

	public List<OrgTreeDto> findOrgAuthorityParty(Worker worker, OrgTreeAuthorityReqDto param) {
		String sql = " select a.org_id,a.org_name from tsm_org a inner join tsm_worker_org_all m on a.org_id=m.org_id where a.data_sources = '智慧党建' AND  m.worker_id= ? and a.state = 1";
		List<Object> argList = new ArrayList<>();
		argList.add(worker.getLoginId());
		if(StringUtils.isNotEmpty(param.getOrgName())){
			sql += " and a.org_name LIKE concat('%',?,'%')";
			argList.add(param.getOrgName());
		}
		sql +=" limit 100 ";
		return JT.queryForBeans(OrgTreeDto.class, sql, argList.toArray());
	}

	public List<OrgTreeDto> findOrgAuthorityBySuperRole(OrgTreeAuthorityReqDto param) {
		String sql = " select a.org_id,a.org_name from tsm_org a where a.state = 1 ";
		List<Object> argList = new ArrayList<>();
		if(StringUtils.isNotEmpty(param.getOrgName())){
			sql += " and a.org_name LIKE concat('%',?,'%')";
			argList.add(param.getOrgName());
		}
		sql +=" limit 100 ";
		return JT.queryForBeans(OrgTreeDto.class, sql, argList.toArray());
	}

	public List<OrgTreeDto> findOrgChildrenTree(OrgTreeReqDto param) {
		StringBuilder sql = new StringBuilder("SELECT a.org_id,a.parent_org_id,a.org_code,a.parent_org_code,a.org_name,a.org_desc,a.sort_id,a.state,a.create_time,a.update_time, "
				+ " case when (SELECT COUNT(*) FROM tsm_org b WHERE b.parent_org_id=a.org_id)>0 then FALSE ELSE TRUE end leafs "
				+ " from tsm_org a WHERE a.state=1 ");
		List<Object> argList = new ArrayList<>();

		//上级组织id
		if(ObjectUtil.isNotEmpty(param.getParentOrgId())){
			sql.append(" and a.parent_org_id=? ");
			argList.add(param.getParentOrgId());
		}
		//组织名称模糊
		if(ObjectUtil.isNotEmpty(param.getOrgName())){
			sql.append(" and a.org_name LIKE concat('%',?,'%') ");
			argList.add(param.getOrgName());
		}
		//组织类型
		if(ObjectUtil.isNotEmpty(param.getOrgType())){
			sql.append(" and a.org_type=? ");
			argList.add(param.getOrgType());
		}
		//组织级别
		if(ObjectUtil.isNotEmpty(param.getOrgLevel())){
			sql.append(" and a.org_level=? ");
			argList.add(param.getOrgType());
		}

		return JT.queryForBeans(OrgTreeDto.class, sql.toString(), argList.toArray());
	}

	public List<TsmOrgDto> getOrgManageByUserId(OrgIds req) {
		String sql = " SELECT a.org_id,b.org_name,a.recursive_or_not from tsm_worker_org a LEFT JOIN tsm_org b ON a.org_id = b.org_id WHERE a.worker_id = ? and a.recursive_or_not = ? ";
		return JT.queryForBeans(TsmOrgDto.class, sql, req.getUserId(),req.getRecursiveOrNot());
	}

	public List<TsmOrg> listParentOrg(List<Long> parentOrgIds, List<Long> orgIds) {
		if (orgIds.size() > 0) {
			String strOrgIds = Joiner.on(",").join(orgIds);
			String sql = "SELECT org_id from tsm_org WHERE org_id in (SELECT parent_org_id from tsm_org WHERE org_id in (" + strOrgIds + "))";
			List<Long> ids = JT.queryForList(sql, Long.class);
			if (ids.size() > 0) {
				parentOrgIds.addAll(ids);
				listParentOrg(parentOrgIds, ids);
			}
		}
		return new ArrayList<>();
	}

	public void deleteWorkerOrgByUserId(List<Integer> workerIds, Integer recursiveOrNot) {
		String strWorkerIds = Joiner.on(",").join(workerIds);
		String sql = "delete from tsm_worker_org WHERE worker_id in(" + strWorkerIds + ") and recursive_or_not = "+recursiveOrNot+" ";
		JT.update(sql);
	}

	public List<OrgSameLeveDto> getSameLevelOrg(List<Long> orgIds) {
		String strOrgIds = Joiner.on(",").join(orgIds);
		String sql = "SELECT b.org_id,b.parent_org_id,wm_concat(a.org_id) sameLeveOrgIds from " +
				" tsm_org a RIGHT JOIN (SELECT org_id,parent_org_id from tsm_org WHERE org_id in (" + strOrgIds + ")) b " +
				" ON b.parent_org_id = a.parent_org_id GROUP BY b.org_id,b.parent_org_id";
		return JT.queryForBeans(OrgSameLeveDto.class, sql);
	}

	public List<OrgTreeDto> getOrgTreeAuthority(Worker worker, OrgTreeAuthorityReqDto req) {
		StringBuilder sql =new StringBuilder( " select a.org_id,a.org_name,m.recursive_or_not " +
				" from tsm_org a " +
				" inner join tsm_worker_org m on a.org_id=m.org_id " +
				" where a.state = 1 and m.recursive_or_not = 1 and m.worker_id= ?");
		List<Object> argList = new ArrayList<>();
		argList.add(worker.getLoginId());
		if (req!=null && StringUtils.isNotEmpty(req.getOrgCode())){
			sql.append(" and a.org_code=?");
			argList.add(req.getOrgCode());
		}
		return JT.queryForBeans(OrgTreeDto.class, sql.toString(), argList.toArray());
	}

	public List<OrgTreeDto> getOrgTreeAuthorityParty(Worker worker, OrgTreeAuthorityReqDto req) {
		StringBuilder sql =new StringBuilder( " select a.org_id,a.org_name,m.recursive_or_not " +
				" from tsm_org a " +
				" inner join tsm_worker_org m on a.org_id=m.org_id " +
				" where  a.data_sources = '智慧党建' AND a.state = 1 and m.recursive_or_not = 1 and m.worker_id= ? ");
		List<Object> argList = new ArrayList<>();
		argList.add(worker.getLoginId());
		if (req!=null && StringUtils.isNotEmpty(req.getOrgCode())){
			sql.append(" and a.org_code=?");
			argList.add(req.getOrgCode());
		}
		return JT.queryForBeans(OrgTreeDto.class, sql.toString(), argList.toArray());
	}

	public List<OrgTreeDto> getOrgTreeAuthorityBySuperRole(OrgTreeAuthorityReqDto req) {
		StringBuilder sql =new StringBuilder( " select org_id,org_name,'1' as recursive_or_not " +
				"from tsm_org where state = 1 and parent_org_id = '0' ");
		List<Object> argList = new ArrayList<>();
		if (req!=null && StringUtils.isNotEmpty(req.getOrgCode())){
			sql.append(" and org_code=?");
			argList.add(req.getOrgCode());
		}
		return JT.queryForBeans(OrgTreeDto.class, sql.toString(), argList.toArray());
	}

	public List<OrgTreeDto> getOrgChild(Worker worker, OrgTreeAuthorityReqDto req) {
		String sql = "";
		if(StringUtils.isNotEmpty(req.getOrgName())){
			sql = " SELECT distinct a.org_id,a.parent_org_id,a.org_code,a.parent_org_code,a.org_name,a.org_desc,a.sort_id,a.state,a.create_time, " +
					" a.update_time,case when (SELECT COUNT(*) FROM tsm_org b WHERE b.parent_org_id=a.org_id and b.state=1)>0 " +
					" then FALSE ELSE TRUE end leafs,m.recursive_or_not " +
					" from tsm_org a inner join tsm_worker_org_all m on a.org_id=m.org_id WHERE a.state = 1 and m.recursive_or_not = 1 and m.worker_id= ? and a.org_name LIKE concat('%',?,'%') order by a.sort_id";
			return JT.queryForBeans(OrgTreeDto.class, sql, worker.getLoginId(),req.getOrgName());
		} else {
			if (StringUtils.isNotEmpty(req.getOrgCode())){
				//团组织列表
				sql = " SELECT distinct a.org_id,a.parent_org_id,a.org_code,a.parent_org_code,a.org_name,a.org_desc,a.sort_id,a.state,a.create_time, " +
						" a.update_time,case when (SELECT COUNT(*) FROM tsm_org b WHERE b.parent_org_id=a.org_id and b.state=1 )>0  " +
						" then FALSE ELSE TRUE end leafs,m.recursive_or_not " +
						" from tsm_org a inner join tsm_worker_org_all m on a.org_id=m.org_id where a.state = 1 and m.recursive_or_not = 1 and m.worker_id= ? and a.org_code=? order by a.sort_id ";
				return JT.queryForBeans(OrgTreeDto.class, sql, worker.getLoginId(),req.getOrgCode());
			}
			sql = " select a.*,case when (SELECT COUNT(*) FROM tsm_org b WHERE b.parent_org_id=a.org_id and b.state=1)>0 "+
					"	then FALSE ELSE TRUE end leafs from  "+
					" (SELECT distinct a.org_id,a.parent_org_id,a.org_code,a.parent_org_code,a.org_name,a.org_desc,a.sort_id,a.state,a.create_time,  "+
					"	a.update_time,m.recursive_or_not  "+
					" from tsm_org a inner join tsm_worker_org_all m on a.org_id=m.org_id "+
					" where a.state=1  and m.recursive_or_not = 1 and m.worker_id= ? and a.parent_org_id=? order by a.sort_id) a";
			return JT.queryForBeans(OrgTreeDto.class, sql, worker.getLoginId(),req.getParentOrgId());
		}
	}


	public List<OrgTreeDto> getOrgChildParty(Worker worker, OrgTreeAuthorityReqDto req) {
		String sql = "";
		if(StringUtils.isNotEmpty(req.getOrgName())){
			sql = " SELECT a.org_id,a.parent_org_id,a.org_code,a.parent_org_code,a.org_name,a.org_desc,a.sort_id,a.state,a.create_time, " +
					" a.update_time,case when (SELECT COUNT(*) FROM tsm_org b WHERE b.data_sources = '智慧党建' AND b.parent_org_id=a.org_id and b.state=1)>0 " +
					" then FALSE ELSE TRUE end leafs,m.recursive_or_not " +
					" from tsm_org a inner join tsm_worker_org_all m on a.org_id=m.org_id WHERE  a.data_sources = '智慧党建' AND a.state = 1 and m.recursive_or_not = 1 and m.worker_id= ? and a.org_name LIKE concat('%',?,'%') order by a.sort_id";
			return JT.queryForBeans(OrgTreeDto.class, sql, worker.getLoginId(),req.getOrgName());
		} else {
			if (StringUtils.isNotEmpty(req.getOrgCode())){
				//团组织列表
				sql = " SELECT a.org_id,a.parent_org_id,a.org_code,a.parent_org_code,a.org_name,a.org_desc,a.sort_id,a.state,a.create_time, " +
						" a.update_time,case when (SELECT COUNT(*) FROM tsm_org b WHERE b.data_sources = '智慧党建' AND b.parent_org_id=a.org_id and b.state=1 )>0  " +
						" then FALSE ELSE TRUE end leafs,m.recursive_or_not " +
						" from tsm_org a inner join tsm_worker_org_all m on a.org_id=m.org_id where  a.data_sources = '智慧党建' AND a.state = 1 and m.recursive_or_not = 1 and m.worker_id= ? and a.org_code=? order by a.sort_id ";
				return JT.queryForBeans(OrgTreeDto.class, sql, worker.getLoginId(),req.getOrgCode());
			}
			sql = " SELECT a.org_id,a.parent_org_id,a.org_code,a.parent_org_code,a.org_name,a.org_desc,a.sort_id,a.state,a.create_time, " +
					" a.update_time,case when (SELECT COUNT(*) FROM tsm_org b WHERE  b.data_sources = '智慧党建' AND b.parent_org_id=a.org_id and b.state=1)>0 " +
					" then FALSE ELSE TRUE end leafs,m.recursive_or_not " +
					" from tsm_org a inner join tsm_worker_org_all m on a.org_id=m.org_id where  a.data_sources = '智慧党建' AND a.state = 1 and m.recursive_or_not = 1 and m.worker_id= ? and a.parent_org_id=? order by a.sort_id ";
			return JT.queryForBeans(OrgTreeDto.class, sql, worker.getLoginId(),req.getParentOrgId());
		}
	}

	public List<OrgTreeDto> getOrgChildBySuperRole(OrgTreeAuthorityReqDto req) {
		String sql;
		if(StringUtils.isNotEmpty(req.getOrgName())){
			sql = " SELECT distinct a.org_id,a.parent_org_id,a.org_code,a.parent_org_code,a.org_name,a.org_desc,a.sort_id,a.state," +
					"a.create_time, a.update_time,case when (SELECT COUNT(*) FROM tsm_org b WHERE b.parent_org_id=a.org_id and b.state=1)>0 " +
					"then FALSE ELSE TRUE end leafs, '1' as recursive_or_not from tsm_org a WHERE a.state = 1 " +
					"and a.org_name LIKE concat('%',?,'%') order by a.sort_id";
			return JT.queryForBeans(OrgTreeDto.class, sql,req.getOrgName());
		} else {
			if (StringUtils.isNotEmpty(req.getOrgCode())){
				//团组织列表
				sql = " SELECT distinct a.org_id,a.parent_org_id,a.org_code,a.parent_org_code,a.org_name,a.org_desc,a.sort_id," +
						"a.state,a.create_time,a.update_time,case when (SELECT COUNT(*) FROM tsm_org b WHERE b.parent_org_id=a.org_id " +
						"and b.state=1 )>0 then FALSE ELSE TRUE end leafs,'1' as recursive_or_not " +
						"from tsm_org a where a.state = 1 and a.org_code = ? order by a.sort_id ";
				return JT.queryForBeans(OrgTreeDto.class, sql, req.getOrgCode());
			}
			sql = " SELECT distinct a.org_id,a.parent_org_id,a.org_code,a.parent_org_code,a.org_name,a.org_desc,a.sort_id,a.state,a.create_time, " +
					" a.update_time,case when (SELECT COUNT(*) FROM tsm_org b WHERE b.parent_org_id=a.org_id and b.state=1)>0 " +
					" then FALSE ELSE TRUE end leafs, '1' as recursive_or_not " +
					" from tsm_org a where a.state = 1 and a.parent_org_id=? order by a.sort_id ";
			return JT.queryForBeans(OrgTreeDto.class, sql, req.getParentOrgId());
		}
	}

	/**
	 * 递归获取子组织id
	 */
	@Cacheable(value = "OrgIdCache", key = "#orgId", sync = true)
	public List<Long> getOrgIds(Long orgId){
		String recursionSql = "SELECT org_id FROM TSM_ORG START WITH parent_org_id = "+ orgId +" CONNECT BY PRIOR(org_id) = parent_org_id";
		return JT.queryForList(recursionSql, Long.class);
	}
	public PageRsp<ChildrenOrgRspVO> pageChildrenOrgNoSubordinate(PageReq<ChildrenOrgReqVO> req) {
		ChildrenOrgReqVO query = req.getQuery();
		StringBuilder sql=new StringBuilder("select a.*,c.worker_name as updateUserName,d.login_id as managePeople, d.worker_name as managePeopleName,b.org_name as parentOrgName," +
				" (select a.value_name from tsm_property_value a left join tsm_property b  on a.prop_id = b.prop_id where a.value_code=a.org_category_tree and b.prop_code='orgCategoryTree' ) as orgCategoryTreeName," +
				" (select a.value_name from tsm_property_value a left join tsm_property b  on a.prop_id = b.prop_id where a.value_code=a.ocyl_industry_category and b.prop_code='leagueIcType' ) as ocylIndustryCategoryName" +
				" from (select *from  tsm_org ts  where ts.parent_org_id =?) a " +
				" left join tsm_org b on a.parent_org_id=b.org_id" +
				" left join tsm_worker c on a.update_user_id=c.login_id " +
				" left join tsm_worker d on a.manage_people=d.login_id " +
				" where a.state=1");
//		StringBuilder sql=new StringBuilder("select a.*,c.worker_name as updateUserName,d.login_id as managePeople,  "
//				+ "d.worker_name as managePeopleName,b.org_name as parentOrgName,  "
//				+ "e.value_name as orgCategoryTreeName,  "
//				+ "g.value_name as ocylIndustryCategoryName  "
//				+ "     from tsm_org a   "
//				+ "     left join tsm_org b on a.parent_org_id=b.org_id  "
//				+ "     left join tsm_worker c on a.update_user_id=c.login_id   "
//				+ "     left join tsm_worker d on a.manage_people=d.login_id   "
//				+ "     left join tsm_property_value e on a.org_category_tree = e.value_code "
//				+ "     left join tsm_property f on  e.prop_id = f.prop_id  "
//				+ "     left join tsm_property_value g on a.ocyl_industry_category = g.value_code "
//				+ "     left join tsm_property h on  g.prop_id = h.prop_id "
//				+ "     where a.state=1 and f.prop_code='orgCategoryTree' and g.prop_code='leagueIcType'");
		StringBuilder sbCount=new StringBuilder("select count(*) from tsm_org a where a.state=1");
		List<Object> params = new ArrayList<>();
		if (ObjectUtil.isNotEmpty(query)){
			if (query.getParentOrgId()!=null){
				//sql.append(" and a.parent_org_id =? ");
				sbCount.append(" and a.parent_org_id =? ");
				params.add(query.getParentOrgId());
			}
			if (org.springframework.util.StringUtils.hasText(query.getOrgName())){
				sql.append(" and a.org_name like concat('%',?,'%') ");
				sbCount.append(" and a.org_name like concat('%',?,'%') ");
				params.add(query.getOrgName());
			}
			if (org.springframework.util.StringUtils.hasText(query.getOrgType())){
				sql.append(" and a.org_category_tree =? ");
				sbCount.append(" and a.org_category_tree =? ");
				params.add(query.getOrgType());
			}

		}
		sql.append(" order by a.sort_id ");
		int total = JT.queryForInt(sbCount.toString(), params.toArray());
		List<ChildrenOrgRspVO> workers = null;
		String dbType = JT.getDbType();
		if (total > 0) {
			//根据数据库类型设置limit
			SqlUtil.appendLimit(dbType, params, sql, req);
			workers = JT.queryForBeans(ChildrenOrgRspVO.class, sql.toString(), params.toArray());
		} else {
			workers = new ArrayList<>(0);
		}
		PageRsp<ChildrenOrgRspVO> page = new PageRsp<ChildrenOrgRspVO>();
		page.setPageNo(req.getPageNo());
		page.setPageSize(req.getPageSize());
		page.setTotalNum(total);
		page.setResult(workers);
		// 为手机计算是否由下一页
		page.next();
		return page;
	}

	public PageRsp<ChildrenOrgRspVO> pageChildrenOrg(PageReq<ChildrenOrgReqVO> req) {
		ChildrenOrgReqVO query = req.getQuery();
		StringBuilder sql=new StringBuilder("select a.*,c.worker_name as updateUserName,d.login_id as managePeople, d.worker_name as managePeopleName,b.org_name as parentOrgName," +
				" (select a.value_name from tsm_property_value a left join tsm_property b  on a.prop_id = b.prop_id where a.value_code=a.org_category_tree and b.prop_code='orgCategoryTree' ) as orgCategoryTreeName," +
				" (select a.value_name from tsm_property_value a left join tsm_property b  on a.prop_id = b.prop_id where a.value_code=a.ocyl_industry_category and b.prop_code='leagueIcType' ) as ocylIndustryCategoryName" +
				" from (select * from TSM_ORG m start with m.parent_org_id=? connect by m.parent_org_id=prior m.org_id) a " +
				" left join tsm_org b on a.parent_org_id=b.org_id" +
				" left join tsm_worker c on a.update_user_id=c.login_id " +
				" left join tsm_worker d on a.manage_people=d.login_id " +
				" where a.state=1");
		StringBuilder sbCount=new StringBuilder("select count(*) from (select * from TSM_ORG a start with a.parent_org_id=? connect by a.parent_org_id=prior a.org_id ) a where a.state=1");
		List<Object> params = new ArrayList<>();
		params.add(ObjectUtil.isNotEmpty(query)?query.getParentOrgId():0);
		if (ObjectUtil.isNotEmpty(query)){
			if (StringUtils.isNotEmpty(query.getOrgName())){
				sql.append(" and a.org_name like concat('%',?,'%') ");
				sbCount.append(" and a.org_name like concat('%',?,'%') ");
				params.add(query.getOrgName());
			}
			if (StringUtils.isNotEmpty(query.getOrgType())){
				sql.append(" and a.org_category_tree =? ");
				sbCount.append(" and a.org_category_tree =? ");
				params.add(query.getOrgType());
			}
		}
		sql.append(" order by a.sort_id ");
		int total = JT.queryForInt(sbCount.toString(), params.toArray());
		List<ChildrenOrgRspVO> workers = null;
		String dbType = JT.getDbType();
		if (total > 0) {
			//根据数据库类型设置limit
			SqlUtil.appendLimit(dbType, params, sql, req);
			workers = JT.queryForBeans(ChildrenOrgRspVO.class, sql.toString(), params.toArray());
		} else {
			workers = new ArrayList<>(0);
		}
		PageRsp<ChildrenOrgRspVO> page = new PageRsp<ChildrenOrgRspVO>();
		page.setPageNo(req.getPageNo());
		page.setPageSize(req.getPageSize());
		page.setTotalNum(total);
		page.setResult(workers);
		// 为手机计算是否由下一页
		page.next();
		return page;
	}

	public void deleteOrg(Long orgId) {
		String sql = "update tsm_org set state = ? where org_id = ?";
		JT.update(sql, CommonConstants.STATE_INVALID, orgId);
	}

	public int checkIsBelowOrg(Long orgId) {
		String sql = "select count(1) from tsm_org where parent_org_id = ? and state = ? ";
		return JT.queryForInt(sql, orgId, CommonConstants.STATE_VALID);
	}

	public int checkIsOrgWorker(Long orgId) {
		String sql = "select count(1) from tsm_worker where org_id = ? and state = ? ";
		return JT.queryForInt(sql, orgId, CommonConstants.STATE_VALID);
	}

	public void moveOrgSort(Long orgId, Long sort) {
		String sql = "update tsm_org set sort_id = ? where org_id = ? ";
		JT.update(sql, sort, orgId);
	}

	public TsmOrg getMovedOrgData(Long parentOrgId, Long sort, Integer moveType) {
		StringBuilder sql = new StringBuilder("select org_id, sort_id from tsm_org where parent_org_id = ? ");
		if (1 == moveType) {
			sql.append(" and sort_id < ? order by sort_id desc ");
		}
		if (2 == moveType) {
			sql.append(" and sort_id > ? order by sort_id asc ");
		}
		sql.append(" limit 1");
		System.out.println("getMovedOrgData的sql:" + sql);
		System.out.println("入参参数:parentOrgId:" + parentOrgId + ", sort:" + sort);
		return JT.queryForBean(TsmOrg.class, sql.toString(), parentOrgId, sort);
	}

	public TsmOrg getMovedOrgDataSubordinate(Long parentOrgId, Long sort, Integer moveType) {
		StringBuilder sql = new StringBuilder("select * from (select org_id, sort_id from tsm_org start with parent_org_id = ? " +
				"connect by prior org_id = parent_org_id) where ");
		if (1 == moveType) {
			sql.append(" sort_id < ? order by sort_id desc ");
		}
		if (2 == moveType) {
			sql.append(" sort_id > ? order by sort_id asc ");
		}
		sql.append(" limit 1");
		return JT.queryForBean(TsmOrg.class, sql.toString(), parentOrgId, sort);
	}

	public List<OrgTabulationExcel> exportOrgTabulation(OrgTabulationDto dto) {
		StringBuilder sb = new StringBuilder("select b.org_name as parentOrgName, a.org_name, " +
				"(select va.value_name from tsm_property_value va left join tsm_property pr on va.prop_id = pr.prop_id where " +
				"va.value_code=a.org_category_tree and pr.prop_code='orgCategoryTree') as orgCategoryTreeName," +
				"(select va.value_name from tsm_property_value va left join tsm_property pr on va.prop_id = pr.prop_id where " +
				"va.value_code=a.ocyl_industry_category and pr.prop_code='ocylIndustryCategory') as ocylIndustryCategoryName," +
				"a.ocyl_is_xztw,a.telephone,a.org_email, a.org_secretary,c.worker_name as managePeopleName,c.mobile AS managePeopleTelephone " +
				"from tsm_org a left join tsm_org b on a.parent_org_id=b.org_id left join tsm_worker c ON a.manage_people = " +
				"c.login_id where a.state = 1 ");
		List<Object> params = new ArrayList<>();
		if(StringUtils.isNotEmpty(dto.getOrgName())){
			sb.append(" and a.org_name like concat('%',?,'%')");
			params.add(dto.getOrgName());
		}
		if(StringUtils.isNotEmpty(dto.getOrgType())){
			sb.append(" and a.org_category_tree = ?");
			params.add(dto.getOrgType());
		}
		if (StringUtils.isNotEmpty(dto.getOrgId())){
			sb.append(" and a.parent_org_id =? ");
			params.add(dto.getOrgId());
		}
		sb.append(" ORDER BY a.sort_id asc");
		return JT.queryForBeans(OrgTabulationExcel.class, sb.toString(), params.toArray());
	}

	public List<OrgTabulationExcel> exportAllOrg(OrgTabulationDto dto, String orgId) {
		StringBuilder sb = new StringBuilder("select b.org_name as parentOrgName, a.org_name, " +
				"(select va.value_name from tsm_property_value va left join tsm_property pr on va.prop_id = pr.prop_id where " +
				"va.value_code=a.org_category_tree and pr.prop_code='orgCategoryTree') as orgCategoryTreeName," +
				"(select va.value_name from tsm_property_value va left join tsm_property pr on va.prop_id = pr.prop_id where " +
				"va.value_code=a.ocyl_industry_category and pr.prop_code='ocylIndustryCategory') as ocylIndustryCategoryName," +
				"a.ocyl_is_xztw,a.telephone,a.org_email, a.org_secretary,c.worker_name as managePeopleName,c.mobile AS managePeopleTelephone " +
				"from (select org_id,parent_org_id, org_name, org_category_tree,ocyl_industry_category,ocyl_is_xztw,telephone," +
				"org_email, org_secretary,manage_people from tsm_org where state = 1 ");
		List<Object> params = new ArrayList<>();
		if (StringUtils.isNotEmpty(dto.getOrgName())) {
			sb.append(" and org_name like concat('%',?,'%')");
			params.add(dto.getOrgName());
		}
		if (StringUtils.isNotEmpty(dto.getOrgType())) {
			sb.append(" and org_category_tree = ?");
			params.add(dto.getOrgType());
		}
		sb.append(" start with org_id = ? connect by prior org_id=parent_org_id) a left join tsm_org b on " +
				"a.parent_org_id=b.org_id left join tsm_worker c on a.manage_people = c.login_id order by " +
				"case when a.org_id = ? then 0 else a.org_id end asc");
		params.add(orgId);
		params.add(orgId);
		return JT.queryForBeans(OrgTabulationExcel.class, sb.toString(), params.toArray());
	}

	public void updateTsmWorkerOrgAll(List<Long> orgIdList, int loginId, int userId) {
		if(orgIdList.size() >0 ){
			String strOrgIds = Joiner.on(",").join(orgIdList);
			String sql = " INSERT INTO TSM_WORKER_ORG_ALL (org_id, org_code, worker_id,create_user_id,create_time,recursive_or_not) " +
					" select b.org_id,b.org_code,a.login_id,?,SYSDATE(),1 from tsm_worker a,(SELECT * FROM TSM_ORG START START WITH org_id in("+strOrgIds+") CONNECT BY PRIOR(org_id) = parent_org_id) b " +
					" where  a.login_id=? ";
			JT.update(sql, loginId,userId);
		}
	}

	public void updateCreateTsmWorkerOrgAll(String orgId, Integer loginId, Integer userId) {
		if(StringUtils.isNotEmpty(orgId)){
			String sql = " INSERT INTO TSM_WORKER_ORG_ALL (org_id, org_code, worker_id,create_user_id,create_time,recursive_or_not) " +
					" select b.org_id,b.org_code,a.login_id,?,SYSDATE(),1 from tsm_worker a,(SELECT * FROM TSM_ORG START START WITH org_id in("+orgId+") CONNECT BY PRIOR(org_id) = parent_org_id) b " +
					" where  a.login_id=? ";
			JT.update(sql, loginId,userId);
		}
	}

	public List<ChildrenStatisticsRspVO> getChildrenStatistics(ChildrenOrgReqVO query) {

		Long parentOrgId = query.getParentOrgId();
		StringBuilder sql=new StringBuilder("   select  rownum as num,a.* from (select b.worker_name managerName, \n" +
				"          b.mobile managerPhone, \n" +
				"          a.org_name,a.org_secretary, \n" +
				"          a.org_category_tree, \n" +
				"          a.org_short_called, \n" +
				"          a.ocyl_industry_category, \n" +
				"          a.org_full_name, \n" +
				"          a.telephone, \n" +
				"          a.ocyl_is_xztw,(select value_name \n" +
				"             from tsm_property_value a, \n" +
				"                  tsm_property b \n" +
				"            WHERE a.del_flag=0 \n" +
				"              and a.prop_id=b.prop_id \n" +
				"              AND b.prop_code='orgCategoryTree' \n" +
				"              and value_code=a.org_category_tree limit 1) ocylOrgCategoryValue \n" +
				"     from (select * \n" +
				"             from TSM_ORG m \n" +
				"                  start with m.org_id=?\n" +
				"                  connect by m.parent_org_id=prior m.org_id)a \n" +
				"left join TSM_WORKER b \n" +
				"       on a.manage_people=b.login_id \n" +
				"    where a.state=1 \n" +
				"      and (a.org_category_tree is null \n" +
				"                 or a.org_short_called is null \n" +
				"                 or a.ocyl_industry_category is null \n" +
				"                 or a.org_name is null \n" +
				"                 or a.telephone is null \n" +
				"                 or a.ocyl_is_xztw is null or  a.org_secretary is null or a.manage_people is null ) \n" +
				" order by a.sort_id) a ");
		List<Object> params = new ArrayList<>();
		params.add(parentOrgId);
		List<ChildrenStatisticsRspVO> childrenStatisticsRspVOS  = new ArrayList<>(0);;
		childrenStatisticsRspVOS = JT.queryForBeans(ChildrenStatisticsRspVO.class, sql.toString(), params.toArray());
		if (childrenStatisticsRspVOS.size()>0){

			for (ChildrenStatisticsRspVO childrenStatisticsRspVO : childrenStatisticsRspVOS) {
				String str="";
				if(StringUtils.isEmpty(childrenStatisticsRspVO.getTelephone())){
					str+="联系电话";
				}
				if(StringUtils.isEmpty(childrenStatisticsRspVO.getOrgCategoryTree())){
					if (str.equals("")){
						str+="组织类别";
					}else {
						str+=",组织类别";
					}
				}
				if(StringUtils.isEmpty(childrenStatisticsRspVO.getOrgShortCalled())){
					if (str.equals("")){
						str+="组织简称";
					}else {
						str+=",组织简称";
					}
				}
				if(StringUtils.isEmpty(childrenStatisticsRspVO.getOcylIndustryCategory())){
					if (str.equals("")){
						str+="所属行业类别";
					}else {
						str+=",所属行业类别";
					}
				}

				if(StringUtils.isEmpty(childrenStatisticsRspVO.getOrgName())){
					if (str.equals("")){
						str+="组织全称";
					}else {
						str+=",组织全称";
					}
				}
				if(StringUtils.isEmpty(childrenStatisticsRspVO.getOcylIsXztw())){
					if (str.equals("")){
						str+="乡镇街道团委";
					}else {
						str+=",乡镇街道团委";
					}
				}
				if(StringUtils.isEmpty(childrenStatisticsRspVO.getManagerPhone())){
					if (str.equals("")){
						str+="管理员联系电话";
					}else {
						str+=",管理员联系电话";
					}
				}

				if(StringUtils.isEmpty(childrenStatisticsRspVO.getManagerName())){
					if (str.equals("")){
						str+="组织管理员";
					}else {
						str+=",组织管理员";
					}
				}
				if(StringUtils.isEmpty(childrenStatisticsRspVO.getOrgSecretary())){
					if (str.equals("")){
						str+="组织书记";
					}else {
						str+=",组织书记";
					}
				}

				childrenStatisticsRspVO.setMessage(str);

			}
		}

		return childrenStatisticsRspVOS;
	}

	public PageRsp<ChildrenStatisticsRspVO> pageChildrenStatistics(PageReq<ChildrenOrgReqVO> req) {
		ChildrenOrgReqVO query = req.getQuery();
		Long parentOrgId = query.getParentOrgId();
		StringBuilder sql=new StringBuilder("select b.worker_name managerName,b.mobile managerPhone,a.org_secretary,a.org_name,a.org_category_tree,a.org_short_called,a.ocyl_industry_category,a.org_full_name,a.telephone,a.ocyl_is_xztw,(select value_name from tsm_property_value a,tsm_property b WHERE a.del_flag=0 and a.prop_id=b.prop_id AND b.prop_code='orgCategoryTree' and value_code=a.org_category_tree limit 1) ocylOrgCategoryValue from (select * from TSM_ORG m start with m.org_id=? connect by m.parent_org_id=prior m.org_id)a left join  TSM_WORKER b on a.manage_people=b.login_id where a.state=1 and (a.org_category_tree is null or a.org_short_called is null or a.ocyl_industry_category is null or a.org_name is null or a.telephone is null or a.ocyl_is_xztw is null or  a.org_secretary is null or a.manage_people is null ) order by a.sort_id");
		StringBuilder sbCount=new StringBuilder("select count(*) from (select a.org_name from (select * from TSM_ORG m start with m.org_id=? connect by m.parent_org_id=prior m.org_id)a left join  TSM_WORKER b on a.manage_people=b.login_id where a.state=1 and (a.org_category_tree is null or a.org_short_called is null or a.ocyl_industry_category is null or a.org_name is null or a.telephone is null or a.ocyl_is_xztw is null or  a.org_secretary is null or a.manage_people is null ) )");
		List<Object> params = new ArrayList<>();
		params.add(parentOrgId);
		int total = JT.queryForInt(sbCount.toString(), params.toArray());
		List<ChildrenStatisticsRspVO> childrenStatisticsRspVOS = null;
		String dbType = JT.getDbType();
		if (total > 0) {
			//根据数据库类型设置limit
			SqlUtil.appendLimit(dbType, params, sql, req);
			childrenStatisticsRspVOS = JT.queryForBeans(ChildrenStatisticsRspVO.class, sql.toString(), params.toArray());
		} else {
			childrenStatisticsRspVOS = new ArrayList<>(0);
		}
		if (childrenStatisticsRspVOS.size()>0){

			for (ChildrenStatisticsRspVO childrenStatisticsRspVO : childrenStatisticsRspVOS) {
				String str="";
				if(StringUtils.isEmpty(childrenStatisticsRspVO.getTelephone())){
					str+="联系电话";
				}
				if(StringUtils.isEmpty(childrenStatisticsRspVO.getOrgCategoryTree())){
					if (str.equals("")){
						str+="组织类别";
					}else {
						str+=",组织类别";
					}
				}
				if(StringUtils.isEmpty(childrenStatisticsRspVO.getOrgShortCalled())){
					if (str.equals("")){
						str+="组织简称";
					}else {
						str+=",组织简称";
					}
				}
				if(StringUtils.isEmpty(childrenStatisticsRspVO.getOcylIndustryCategory())){
					if (str.equals("")){
						str+="所属行业类别";
					}else {
						str+=",所属行业类别";
					}
				}

				if(StringUtils.isEmpty(childrenStatisticsRspVO.getOrgName())){
					if (str.equals("")){
						str+="组织全称";
					}else {
						str+=",组织全称";
					}
				}
				if(StringUtils.isEmpty(childrenStatisticsRspVO.getOcylIsXztw())){
					if (str.equals("")){
						str+="乡镇街道团委";
					}else {
						str+=",乡镇街道团委";
					}
				}
				if(StringUtils.isEmpty(childrenStatisticsRspVO.getManagerPhone())){
					if (str.equals("")){
						str+="管理员联系电话";
					}else {
						str+=",管理员联系电话";
					}
				}

				if(StringUtils.isEmpty(childrenStatisticsRspVO.getManagerName())){
					if (str.equals("")){
						str+="组织管理员";
					}else {
						str+=",组织管理员";
					}
				}
				if(StringUtils.isEmpty(childrenStatisticsRspVO.getOrgSecretary())){
					if (str.equals("")){
						str+="组织书记";
					}else {
						str+=",组织书记";
					}
				}

				childrenStatisticsRspVO.setMessage(str);

			}
		}
		PageRsp<ChildrenStatisticsRspVO> page = new PageRsp<ChildrenStatisticsRspVO>();
		page.setPageNo(req.getPageNo());
		page.setPageSize(req.getPageSize());
		page.setTotalNum(total);
		page.setResult(childrenStatisticsRspVOS);
		// 为手机计算是否由下一页
		page.next();
		return page;
	}

	/**
	 * 根据系统查询所属组织
	 * @param affiliatingSystem
	 * @return
	 */
	public List<OrgTreeDto> getOrgBySystem(String affiliatingSystem) {
		String sql="select  * from tsm_org where state=1 and affiliating_system=?";
		return JT.queryForBeans(OrgTreeDto.class, sql, affiliatingSystem);
	}

	public int selectCountByOrgParentId(Long orgId, Long parentOrgId) {
		String sql = "select count(1) from tsm_org where org_id != ? and parent_org_id = ? and state = ? ";
		return JT.queryForInt(sql, orgId, parentOrgId, CommonConstants.STATE_VALID);
	}

	public void updateLeaf(Integer leaf, Long orgId) {
		String sql = "update tsm_org set is_leaf = ? where org_id = ?";
		JT.update(sql, leaf, orgId);
	}

	/**
	 * 刷权限组织
	 * @param orgId
	 * @param parentOrgId
	 */
	public void updateWorkerAll(Long orgId,String orgCode, Long parentOrgId,Integer loginId) {
		String sql = "INSERT into TSM_WORKER_ORG_ALL(org_id,org_code,create_user_id,recursive_or_not,create_time,worker_id)" +
				" SELECT ?,?,?,1,CURDATE(),worker_id" +
				" FROM TSM_WORKER_ORG_ALL " +
				" WHERE org_id=?";
		JT.update(sql, orgId,orgCode,loginId,parentOrgId);
	}

	/**
	 * 团组织统计导出
	 * @author leixb
	 * @since 2024-01-24 11:18
     * @return List<OrgStatisticsVo>
	 */
	public List<OrgStatisticsVo> exportOrgStatistics() {
        String sql = " select a.org_name,\n"
            + " (select count(*) from (SELECT * FROM TSM_ORG START WITH org_id=a.org_id CONNECT BY PRIOR(org_id) = parent_org_id) b where b.state=1) sub_org_count,\n"
            + " (select count(*) from (SELECT * FROM TSM_ORG START WITH org_id=a.org_id CONNECT BY PRIOR(org_id) = parent_org_id) b where b.manage_people is null and state=1) null_admin_count\n"
            + " from tsm_org a where parent_org_id = 1674703692521037822 and state=1 order by sort_id; ";
		return JT.queryForBeans(OrgStatisticsVo.class, sql);
	}
}
