NC65 部门预算DAO类
NC65 部门预算DAO类
package nc.impl.hrp.psndeptbudget;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import nc.bs.dao.DAOException;
import nc.bs.logging.Logger;
import nc.bs.om.pub.LegacyDao;
import nc.hr.frame.persistence.AppendBeanArrayProcessor;
import nc.hr.frame.persistence.PersistenceDAO;
import nc.hr.utils.InSQLCreator;
import nc.itf.hr.frame.PersistenceDbException;
import nc.itf.om.IAOSQueryService.OrgQueryMode;
import nc.jdbc.framework.SQLParameter;
import nc.jdbc.framework.processor.BaseProcessor;
import nc.jdbc.framework.processor.BeanListProcessor;
import nc.jdbc.framework.processor.ColumnListProcessor;
import nc.jdbc.framework.processor.ColumnProcessor;
import nc.jdbc.framework.processor.ResultSetProcessor;
import nc.vo.hi.psndoc.PsnJobVO;
import nc.vo.hi.psndoc.PsnOrgVO;
import nc.vo.hr.append.AppendableVO;
import nc.vo.hr.tools.pub.GeneralVO;
import nc.vo.hrp.psndeptbudget.DeptBudgetVO;
import nc.vo.hrp.psndeptbudget.PostBudgetVO;
import nc.vo.hrp.psnorgbudget.OrgBudgetVO;
import nc.vo.hrp.pub.PsnBudgetCountParseFormulaUtils;
import nc.vo.hrp.pub.PsnBudgetParseFormulaUtils;
import nc.vo.hrpbm.util.REUtil;
import nc.vo.jcom.lang.StringUtil;
import nc.vo.om.aos.AOSFeaturedOrgVO;
import nc.vo.om.aos.SuperVOHelper;
import nc.vo.om.pub.SQLJoinPartHelper;
import nc.vo.org.AdminOrgVO;
import nc.vo.org.OrgVO;
import nc.vo.pub.BusinessException;
import nc.vo.pubapp.util.VOSortUtils;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
/**
* <br>
* 部门预算DAO类
*/
public class DeptBudgetDao extends LegacyDao
{
private String prepareDeptBudgetQuerySQL(String[] deptPKs, String[] psnclPKs, InSQLCreator inSQLCreator) throws BusinessException
{
StringBuilder querySQL = new StringBuilder();
String psnJobTable = PsnJobVO.getDefaultTableName();
String psnOrgTable = PsnOrgVO.getDefaultTableName();
String psnJobPrefix = psnJobTable + ".";
String psnOrgPrefix = psnOrgTable + ".";
// select count(distinct hi_psnjob.pk_psndoc)
querySQL.append(" select count(distinct ").append(psnJobPrefix).append(PsnJobVO.PK_PSNDOC).append(") as psnsum, ")
.append(psnJobPrefix).append(PsnJobVO.PK_DEPT);
// from hi_psnjob inner join hi_psnorg on hi_psnjob.pk_psnorg = hi_psnorg.pk_psnorg
querySQL.append(" from ").append(psnJobTable);
querySQL.append(SQLJoinPartHelper.getSQLInnerJoinPart(PsnOrgVO.class, psnJobTable, PsnJobVO.PK_PSNORG));
// where pk_psnjob.pk_dept = deptPK
querySQL.append(" where ").append(psnJobPrefix).append(PsnJobVO.PK_DEPT).append(" in (").append(inSQLCreator.getInSQL(deptPKs))
.append(")");
// and pk_psnjob.ismainjob = 'Y'
querySQL.append(" and ").append(psnJobPrefix).append(PsnJobVO.ISMAINJOB).append(" = 'Y'");
// and pk_psnjob.endflag = 'N'
querySQL.append(" and ").append(psnJobPrefix).append(PsnJobVO.ENDFLAG).append(" = 'N'");
// and hi_psnorg.psntype = 0
querySQL.append(" and ").append(psnOrgPrefix).append(PsnOrgVO.PSNTYPE).append(" = 0");
// and hi_psnorg.indocflag = 'Y'
querySQL.append(" and ").append(psnOrgPrefix).append(PsnOrgVO.INDOCFLAG).append(" = 'Y'");
// and pk_psncl in (...)
String whereInsql = inSQLCreator.getInSQL(psnclPKs);
if (StringUtils.isNotEmpty(whereInsql))
{
querySQL.append(" and ");
querySQL.append(psnJobPrefix).append(PsnJobVO.PK_PSNCL).append(" in (").append(whereInsql).append(")");
}
querySQL.append(" group by ").append(psnJobPrefix).append(PsnJobVO.PK_DEPT);
return querySQL.toString();
}
/**
* 批量查询岗位的占编人数
* @throws BusinessException
*/
private String preparePostBudgetQuerySQL(PostBudgetVO[] postBudgetVOs, String[] psnclPKs, InSQLCreator inSQLCreator)
throws BusinessException
{
String inPostSql = "";
inPostSql = inSQLCreator.getInSQL(postBudgetVOs, PostBudgetVO.PK_POST);
StringBuilder querySQL = new StringBuilder();
String psnJobTable = PsnJobVO.getDefaultTableName();
String psnOrgTable = PsnOrgVO.getDefaultTableName();
String psnJobPrefix = psnJobTable + ".";
String psnOrgPrefix = psnOrgTable + ".";
// select count(distinct hi_psnjob.pk_psndoc)
querySQL.append(" select count(distinct ").append(psnJobPrefix).append(PsnJobVO.PK_PSNDOC).append(") as count, ");
querySQL.append(psnJobPrefix).append(PsnJobVO.PK_POST);
// from hi_psnjob inner join hi_psnorg on hi_psnjob.pk_psnorg = hi_psnorg.pk_psnorg
querySQL.append(" from ").append(psnJobTable);
querySQL.append(SQLJoinPartHelper.getSQLInnerJoinPart(PsnOrgVO.class, psnJobTable, PsnJobVO.PK_PSNORG));
// where pk_psnjob.pk_post = deptPK
querySQL.append(" where ").append(psnJobPrefix).append(PsnJobVO.PK_POST).append(" in (").append(inPostSql).append(")");
// and pk_psnjob.ismainjob = 'Y'
querySQL.append(" and ").append(psnJobPrefix).append(PsnJobVO.ISMAINJOB).append(" = 'Y'");
// and pk_psnjob.endflag = 'N'
querySQL.append(" and ").append(psnJobPrefix).append(PsnJobVO.ENDFLAG).append(" = 'N'");
// and hi_psnorg.psntype = 0
querySQL.append(" and ").append(psnOrgPrefix).append(PsnOrgVO.PSNTYPE).append(" = 0");
// and hi_psnorg.indocflag = 'Y'
querySQL.append(" and ").append(psnOrgPrefix).append(PsnOrgVO.INDOCFLAG).append(" = 'Y'");
// and pk_psncl in (...)
String whereInSql = inSQLCreator.getInSQL(psnclPKs);
if (StringUtils.isNotEmpty(whereInSql))
{
querySQL.append(" and ");
querySQL.append(psnJobPrefix).append(PsnJobVO.PK_PSNCL).append(" in (").append(whereInSql).append(")");
}
querySQL.append(" group by ").append(psnJobPrefix).append(PsnJobVO.PK_POST);
return querySQL.toString();
}
private String preparePostBudgetQuerySQL(String postPK, String[] psnclPKs, InSQLCreator inSQLCreator) throws BusinessException
{
StringBuilder querySQL = new StringBuilder();
String psnJobTable = PsnJobVO.getDefaultTableName();
String psnOrgTable = PsnOrgVO.getDefaultTableName();
String psnJobPrefix = psnJobTable + ".";
String psnOrgPrefix = psnOrgTable + ".";
// select count(distinct hi_psnjob.pk_psndoc)
querySQL.append(" select count(distinct ").append(psnJobPrefix).append(PsnJobVO.PK_PSNDOC).append(") ");
// from hi_psnjob inner join hi_psnorg on hi_psnjob.pk_psnorg = hi_psnorg.pk_psnorg
querySQL.append(" from ").append(psnJobTable);
querySQL.append(SQLJoinPartHelper.getSQLInnerJoinPart(PsnOrgVO.class, psnJobTable, PsnJobVO.PK_PSNORG));
// where pk_psnjob.pk_post = deptPK
querySQL.append(" where ").append(psnJobPrefix).append(PsnJobVO.PK_POST).append(" = '").append(postPK).append("'");
// and pk_psnjob.ismainjob = 'Y'
querySQL.append(" and ").append(psnJobPrefix).append(PsnJobVO.ISMAINJOB).append(" = 'Y'");
// and pk_psnjob.endflag = 'N'
querySQL.append(" and ").append(psnJobPrefix).append(PsnJobVO.ENDFLAG).append(" = 'N'");
// and hi_psnorg.psntype = 0
querySQL.append(" and ").append(psnOrgPrefix).append(PsnOrgVO.PSNTYPE).append(" = 0");
// and hi_psnorg.indocflag = 'Y'
querySQL.append(" and ").append(psnOrgPrefix).append(PsnOrgVO.INDOCFLAG).append(" = 'Y'");
// and pk_psncl in (...)
String whereSql = inSQLCreator.getInSQL(psnclPKs);
if (StringUtils.isNotEmpty(whereSql))
{
querySQL.append(" and ");
querySQL.append(psnJobPrefix).append(PsnJobVO.PK_PSNCL).append(" in (").append(whereSql).append(")");
}
return querySQL.toString();
}
/**
* 为查询业务单元准备SQL<br>
* @param querySQL
* @param innerCode
* @return
*/
private SQLParameter prepareQueryOrgSQL(StringBuilder querySQL, String innerCode, OrgQueryMode mode)
{
// SQL初始化
querySQL.append("select ");
querySQL.append("org_orgs.*, org_adminorg.pk_adminorg, org_adminorg.pk_fatherorg ");
querySQL.append(", org_adminorg.innercode as aosinnercode ");
querySQL.append("from ");
querySQL.append("org_orgs inner join org_adminorg on org_orgs.pk_org = org_adminorg.pk_adminorg ");
// SQLParameter初始化
SQLParameter parameter = new SQLParameter();
switch (mode)
{
case All :
querySQL.append("where ");
querySQL.append("org_adminorg.innercode like ? ");
parameter.addParam(innerCode + "%");
break;
case Independent :
querySQL.append("where ");
querySQL.append("org_adminorg.innercode like ? ");
querySQL.append("and (org_orgs.orgtype4 = 'N' or org_adminorg.innercode = ?) ");
querySQL.append("and org_adminorg.pk_adminorg not in ( ");
querySQL.append("select ");
querySQL.append("aosm.pk_adminorg ");
querySQL.append("from ");
querySQL.append("( select ");
querySQL.append("aos.code, aos.innercode, len(aos.innercode) as innercodelen ");
querySQL.append("from ");
querySQL.append("org_orgs org inner join org_adminorg aos on org.pk_org = aos.pk_adminorg ");
querySQL.append("where ");
querySQL.append("aos.innercode like ? and aos.innercode <> ? and orgtype4 = 'Y' ) ");
querySQL.append(" sub_hrorg, org_adminorg aosm ");
querySQL.append("where ");
querySQL.append("sub_hrorg.innercode = substring(aosm.innercode , 1, sub_hrorg.innercodelen)) ");
parameter.addParam(innerCode + "%");
parameter.addParam(innerCode);
parameter.addParam(innerCode + "%");
parameter.addParam(innerCode);
break;
case Step_By_Step_Sub_Only :
case Step_By_Step :
case Real_Step_By_Step :
querySQL.append("where ");
querySQL.append(" org_adminorg.PK_FATHERORG in (select PK_ADMINORG from org_adminorg where INNERCODE = ?) ");
querySQL.append(" OR org_adminorg.PK_ADMINORG = (select PK_ADMINORG from org_adminorg where INNERCODE = ?) ");
querySQL.append(" or org_adminorg.PK_ADMINORG in (select org_adminorg.PK_ADMINORG from org_orgs ");
querySQL.append(" inner join org_adminorg on org_orgs.pk_org = org_adminorg.pk_adminorg ");
querySQL.append(" where org_adminorg.PK_FATHERORG in (select org_adminorg.PK_ADMINORG from org_orgs ");
querySQL.append(" inner join org_adminorg on org_orgs.pk_org = org_adminorg.pk_adminorg ");
querySQL
.append(" where org_adminorg.PK_FATHERORG in (select PK_ADMINORG from org_adminorg where INNERCODE = ?) AND org_orgs.ORGTYPE4 = 'Y') ");
querySQL.append(" and org_orgs.ORGTYPE4 = 'N')");
parameter.addParam(innerCode);
parameter.addParam(innerCode);
parameter.addParam(innerCode);
break;
}
return parameter;
}
/**
* 根据公式分类查询出对应的占编人员的工作记录主键
*/
public List<String> queryByFormulaPostBudget(String deptPK, String[] psnclPKs, String wherePart) throws DAOException
{
StringBuilder querySQL = new StringBuilder();
String fromPart = "", lastSql = "";
InSQLCreator inSQLCreator = new InSQLCreator();
List<String> returnList = null;
try
{
if (StringUtils.isEmpty(wherePart))
{
querySQL.append(" hi_psnjob.pk_dept " + " = '" + deptPK + "'");
}
else
{
ArrayList selectPartItems = new ArrayList();
Vector<String> vectorTableNames = REUtil.getUsedTable(selectPartItems, wherePart);
fromPart = PsnBudgetParseFormulaUtils.joinTables(vectorTableNames);
querySQL.append("(" + wherePart + ") and hi_psnjob.pk_dept " + " = '" + deptPK + "'");
String whereInSql = "";
whereInSql = inSQLCreator.getInSQL(psnclPKs);
if (StringUtils.isNotEmpty(whereInSql))
{
querySQL.append(" and ");
querySQL.append("hi_psnjob.pk_psncl").append(" in (").append(whereInSql).append(")");
}
}
lastSql = "select distinct hi_psnjob.pk_psnjob from " + fromPart + " where " + querySQL.toString();
returnList = (List<String>) getBaseDAO().executeQuery(lastSql, new ColumnListProcessor());
}
catch (BusinessException ex)
{
Logger.error(ex.getMessage());
}
finally
{
try
{
if (inSQLCreator != null)
{
inSQLCreator.clear();
}
}
catch (BusinessException ex)
{
Logger.error(ex.getMessage());
}
}
return returnList;
}
public DeptBudgetVO queryLatestDeptBudget(String pk_dept) throws DAOException
{
try
{
String wherePart =
" select pk_org_budget from hrp_orgbudget where pk_org_budget in( select pk_org_budget from hrp_deptbudget where pk_dept = ? and pk_dimension = '"
+ OrgBudgetVO.PK_PostDimension + "' ) and publish_state = 1 order by budget_year desc,budget_version desc ";
SQLParameter para = new SQLParameter();
para.addParam(pk_dept);
OrgBudgetVO[] vo = new PersistenceDAO().retrieveBySQL(OrgBudgetVO.class, wherePart, para);
VOSortUtils.descSort(vo, new String[]{OrgBudgetVO.BUDGET_YEAR, OrgBudgetVO.BUDGET_VERSION});
if (ArrayUtils.isEmpty(vo))
{
return null;
}
String sql =
"select * from hrp_deptbudget where pk_dept = ? and pk_dimension = '" + OrgBudgetVO.PK_PostDimension
+ "' and pk_org_budget = ('" + vo[0].getPk_org_budget() + "') order by budget_year desc, budget_version desc";
SQLParameter para1 = new SQLParameter();
para1.addParam(pk_dept);
DeptBudgetVO[] vos = null;
vos = new PersistenceDAO().retrieveBySQL(DeptBudgetVO.class, sql, para1);
if (ArrayUtils.isEmpty(vos))
{
return null;
}
return vos[0];
}
catch (PersistenceDbException e)
{
throw new DAOException(e);
}
}
public PostBudgetVO queryLatestPostBudget(String pkPost) throws PersistenceDbException
{
String sql = "select * from hrp_postbudget where pk_post=? order by budget_year desc,budget_version desc";
SQLParameter para = new SQLParameter();
para.addParam(pkPost);
PostBudgetVO[] vos = new PersistenceDAO().retrieveBySQL(PostBudgetVO.class, sql, para);
VOSortUtils.descSort(vos, new String[]{PostBudgetVO.BUDGET_YEAR, PostBudgetVO.BUDGET_VERSION});
if (ArrayUtils.isEmpty(vos))
{
return null;
}
return vos[0];
}
public PostBudgetVO[] queryRMPostBudget(String pk_dept) throws DAOException
{
try
{
String wherePart =
" select pk_org_budget from hrp_orgbudget where pk_org_budget in( select pk_org_budget from hrp_deptbudget where pk_dept = ? and pk_dimension = '"
+ OrgBudgetVO.PK_PostDimension + "' ) and publish_state = 1 order by budget_year desc,budget_version desc ";
SQLParameter para = new SQLParameter();
para.addParam(pk_dept);
OrgBudgetVO[] vo = new PersistenceDAO().retrieveBySQL(OrgBudgetVO.class, wherePart, para);
VOSortUtils.descSort(vo, new String[]{OrgBudgetVO.BUDGET_YEAR, OrgBudgetVO.BUDGET_VERSION});
if (ArrayUtils.isEmpty(vo))
{
return null;
}
String wherePart2 =
"select pk_dept_budget from hrp_deptbudget where pk_dept = ? and pk_dimension = '" + OrgBudgetVO.PK_PostDimension
+ "' and pk_org_budget = ('" + vo[0].getPk_org_budget() + "') order by budget_year desc, budget_version desc";
SQLParameter para1 = new SQLParameter();
para1.addParam(pk_dept);
DeptBudgetVO[] vos = null;
vos = new PersistenceDAO().retrieveBySQL(DeptBudgetVO.class, wherePart2, para1);
if (ArrayUtils.isEmpty(vos))
{
return null;
}
String sql = "select * from hrp_postbudget where pk_dept_budget = '" + vos[0].getPk_dept_budget() + "'";
PostBudgetVO[] postBudgetVOS = new PersistenceDAO().retrieveBySQL(PostBudgetVO.class, sql, null);
return postBudgetVOS;
}
catch (PersistenceDbException e)
{
throw new DAOException(e);
}
}
String[] retrieveAllBudgetDimension(String innercode, Integer year, boolean includeSub, boolean isStartedTotalBudget)
throws DAOException
{
StringBuilder querySQL = new StringBuilder();
querySQL.append("select distinct hrp_orgbudget.pk_dimension ");
querySQL.append("from org_adminorg inner join hrp_orgbudget on org_adminorg.pk_adminorg = hrp_orgbudget.pk_org ");
querySQL.append("inner join org_orgs on org_orgs.pk_org = hrp_orgbudget.pk_org ");
querySQL.append("where hrp_orgbudget.budget_year = ? ");
if (!isStartedTotalBudget)
{
// querySQL.append("and hrp_orgbudget.publish_state = '1' ");
querySQL.append("and ((hrp_orgbudget.publish_state = '1' and hrp_orgbudget.datasource=0) or hrp_orgbudget.datasource=1)");
}
if (includeSub)
{
querySQL.append("and org_adminorg.innercode like ? ");
}
else
{
querySQL.append("and org_adminorg.innercode like ? ");
querySQL.append("and (org_orgs.orgtype4 = 'N' or org_adminorg.innercode = ?) ");
querySQL.append("and org_adminorg.pk_adminorg not in ( ");
querySQL.append("select ");
querySQL.append("aosm.pk_adminorg ");
querySQL.append("from ");
querySQL.append("( select ");
querySQL.append(" aos.code, aos.innercode, len(aos.innercode) as innercodelen ");
querySQL.append("from ");
querySQL.append("org_orgs org inner join org_adminorg aos on org.pk_org = aos.pk_adminorg ");
querySQL.append("where ");
querySQL.append("aos.innercode like ? and aos.innercode <> ? and orgtype4 = 'Y' ) ");
querySQL.append(" sub_hrorg, org_adminorg aosm ");
querySQL.append("where ");
querySQL.append("sub_hrorg.innercode = substring(aosm. innercode , 1, sub_hrorg.innercodelen)) ");
}
querySQL.append("order by pk_dimension ");
SQLParameter parameter = new SQLParameter();
parameter.addParam(year);
if (includeSub)
{
parameter.addParam(innercode + "%");
}
else
{
parameter.addParam(innercode + "%");
parameter.addParam(innercode);
parameter.addParam(innercode + "%");
parameter.addParam(innercode);
}
ResultSetProcessor processor = new ColumnListProcessor();
List<String> result = (List<String>) getBaseDAO().executeQuery(querySQL.toString(), parameter, processor);
List<String> orderResult = new ArrayList<String>();
if (result != null && result.size() > 0)
{
boolean isPk_PostDimension = false;
for (int i = 0; i < result.size(); i++)
{
if (result.get(i).equals(OrgBudgetVO.PK_PostDimension))
{
isPk_PostDimension = true;
}
else
{
orderResult.add(result.get(i));
}
}
if (isPk_PostDimension == true)
{
orderResult.add(OrgBudgetVO.PK_PostDimension);
}
}
return orderResult.toArray(new String[0]);
}
/***************************************************************************
* 查询年度、维度和对应版本对应的分类方式<br>
* Created on 2012-5-29 14:17:08<br>
* @param innercode
* @param year
* @param pk_dimension
* @param version
* @return
* @author wangxbd
* @throws DAOException
***************************************************************************/
public String[] retrieveAllBudgetDimensionDef(String innercode, Integer year, String pk_dimension, Integer version) throws DAOException
{
StringBuilder querySQL = new StringBuilder();
querySQL.append("select distinct hrp_orgbudget_sub.pk_dimensiondef ");
querySQL.append("from org_adminorg inner join hrp_orgbudget on org_adminorg.pk_adminorg = hrp_orgbudget.pk_org ");
querySQL.append(" inner join hrp_orgbudget_sub on hrp_orgbudget.pk_org_budget =hrp_orgbudget_sub.pk_org_budget");
querySQL.append(" where hrp_orgbudget.publish_state = '1' and hrp_orgbudget.budget_year = ? ");
querySQL.append("and hrp_orgbudget.pk_dimension = ? ");
querySQL.append("and hrp_orgbudget.budget_version = ? ");
querySQL.append("and hrp_orgbudget.pk_org = ? ");
querySQL.append("order by hrp_orgbudget_sub.pk_dimensiondef ");
SQLParameter parameter = new SQLParameter();
parameter.addParam(year);
parameter.addParam(pk_dimension);
parameter.addParam(version);
parameter.addParam(innercode);
ResultSetProcessor processor = new ColumnListProcessor();
List<String> result = (List<String>) getBaseDAO().executeQuery(querySQL.toString(), parameter, processor);
return result.toArray(new String[0]);
}
/**
* 查询所有编制版本<br>
* @param pk_org
* @param year
* @param pk_dimension
* @param isStartedTotalBudget
* @return
* @throws DAOException
*/
String[] retrieveAllBudgetVersion(String innercode, Integer year, String pk_dimension, boolean includeSub, Boolean isStartedTotalBudget)
throws DAOException
{
StringBuilder querySQL = new StringBuilder();
querySQL.append("select distinct hrp_orgbudget.budget_version ");
querySQL.append("from org_adminorg inner join hrp_orgbudget on org_adminorg.pk_adminorg = hrp_orgbudget.pk_org ");
querySQL.append("inner join org_orgs on org_orgs.pk_org = hrp_orgbudget.pk_org ");
querySQL.append("where hrp_orgbudget.budget_year = ? ");
querySQL.append("and hrp_orgbudget.pk_dimension = ? ");
if (!isStartedTotalBudget)
{
querySQL.append("and ((hrp_orgbudget.publish_state = '1' and hrp_orgbudget.datasource=0) or hrp_orgbudget.datasource=1)");
}
if (includeSub)
{
querySQL.append("and org_adminorg.innercode like ? ");
}
else
{
querySQL.append("and org_adminorg.innercode like ? ");
querySQL.append("and (org_orgs.orgtype4 = 'N' or org_adminorg.innercode = ?) ");
querySQL.append("and org_adminorg.pk_adminorg not in ( ");
querySQL.append("select ");
querySQL.append("aosm.pk_adminorg ");
querySQL.append("from ");
querySQL.append("( select ");
querySQL.append(" aos.code, aos.innercode, len(aos.innercode) as innercodelen ");
querySQL.append("from ");
querySQL.append("org_orgs org inner join org_adminorg aos on org.pk_org = aos.pk_adminorg ");
querySQL.append("where ");
querySQL.append("aos.innercode like ? and aos.innercode <> ? and orgtype4 = 'Y' ) ");
querySQL.append(" sub_hrorg, org_adminorg aosm ");
querySQL.append("where ");
querySQL.append("sub_hrorg.innercode = substring(aosm. innercode , 1, sub_hrorg.innercodelen)) ");
}
querySQL.append("order by budget_version desc");
SQLParameter parameter = new SQLParameter();
parameter.addParam(year);
parameter.addParam(pk_dimension);
if (includeSub)
{
parameter.addParam(innercode + "%");
}
else
{
parameter.addParam(innercode + "%");
parameter.addParam(innercode);
parameter.addParam(innercode + "%");
parameter.addParam(innercode);
}
ResultSetProcessor processor = new ColumnListProcessor();
List<Integer> result = (List<Integer>) getBaseDAO().executeQuery(querySQL.toString(), parameter, processor);
if (result != null)
{
String[] version = new String[result.size()];
for (int i = 0; i < result.size(); i++)
{
version[i] = result.get(i).toString();
}
return version;
}
return null;
}
/**
* 查询所有编制年份<br>
* @param innercode
* @param includeSub
* @return
* @throws DAOException
*/
String[] retrieveAllBudgetYear(String innercode, boolean includeSub, Boolean isStartedTotalBudget) throws DAOException
{
StringBuilder querySQL = new StringBuilder();
querySQL.append("select distinct hrp_orgbudget.budget_year ");
querySQL.append("from org_adminorg inner join hrp_orgbudget on org_adminorg.pk_adminorg = hrp_orgbudget.pk_org ");
querySQL.append("inner join org_orgs on org_orgs.pk_org = hrp_orgbudget.pk_org ");
if (!isStartedTotalBudget)
{
// querySQL.append("where hrp_orgbudget.publish_state = '1' ");
querySQL.append("and ((hrp_orgbudget.publish_state = '1' and hrp_orgbudget.datasource=0) or hrp_orgbudget.datasource=1)");
}
else
{
querySQL.append("where 1=1 ");
}
if (includeSub)
{
querySQL.append("and org_adminorg.innercode like ? ");
}
else
{
querySQL.append("and org_adminorg.innercode like ? ");
querySQL.append("and (org_orgs.orgtype4 = 'N' or org_adminorg.innercode = ?) ");
querySQL.append("and org_adminorg.pk_adminorg not in ( ");
querySQL.append("select ");
querySQL.append("aosm.pk_adminorg ");
querySQL.append("from ");
querySQL.append("( select ");
querySQL.append(" aos.code, aos.innercode, len(aos.innercode) as innercodelen ");
querySQL.append("from ");
querySQL.append("org_orgs org inner join org_adminorg aos on org.pk_org = aos.pk_adminorg ");
querySQL.append("where ");
querySQL.append("aos.innercode like ? and aos.innercode <> ? and orgtype4 = 'Y' ) ");
querySQL.append(" sub_hrorg, org_adminorg aosm ");
querySQL.append("where ");
querySQL.append("sub_hrorg.innercode = substring(aosm. innercode , 1, sub_hrorg.innercodelen)) ");
}
querySQL.append("order by budget_year desc");
SQLParameter parameter = new SQLParameter();
if (includeSub)
{
parameter.addParam(innercode + "%");
}
else
{
parameter.addParam(innercode + "%");
parameter.addParam(innercode);
parameter.addParam(innercode + "%");
parameter.addParam(innercode);
}
ResultSetProcessor processor = new ColumnListProcessor();
List<String> result = (List<String>) getBaseDAO().executeQuery(querySQL.toString(), parameter, processor);
if (result != null)
{
String[] year = new String[result.size()];
for (int i = 0; i < result.size(); i++)
{
year[i] = result.get(i);
}
return year;
}
return null;
}
/**
* 根据组织主键返回行政组织树中的InnerCode<br>
* @param pk_org
* @return String
* @throws DAOException
*/
String retrieveAOSInnerCodeByOrgPK(String pk_org) throws DAOException
{
String querySQL = "select innercode from org_adminorg where pk_adminorg = ?";
SQLParameter parameter = new SQLParameter();
parameter.addParam(pk_org);
return (String) getBaseDAO().executeQuery(querySQL, parameter, new ColumnProcessor("innercode"));
}
AOSFeaturedOrgVO[] retrieveBudgetOrgs(String innercode, Integer year, String pk_dimension, Integer version, boolean includeSub,
Boolean isStartedTotalBudget) throws DAOException
{
StringBuilder querySQL = new StringBuilder();
// 无须查出所有属性,只要可以创建树型结构即可
querySQL
.append("select org_orgs_v.code, org_orgs_v.name, org_orgs_v.name2, org_orgs_v.name3, org_orgs_v.name4, org_orgs_v.name5, org_orgs_v.name6, ");
querySQL.append("org_adminorg.pk_adminorg, org_adminorg.pk_fatherorg, ");
querySQL.append("org_orgs.pk_org, org_orgs.pk_group, hrp_orgbudget.budget_self ");
querySQL.append("from org_orgs ");
querySQL.append("inner join org_adminorg on org_orgs.pk_org = org_adminorg.pk_adminorg ");
querySQL.append("inner join hrp_orgbudget on org_orgs.pk_org = hrp_orgbudget.pk_org ");
querySQL.append("inner join org_orgs_v on hrp_orgbudget.pk_vid = org_orgs_v.pk_vid ");
querySQL.append("left outer JOIN ORG_HRORG ON ORG_ADMINORG.PK_ADMINORG = ORG_HRORG.PK_HRORG ");
querySQL.append("where hrp_orgbudget.budget_year = ? ");
querySQL.append("and hrp_orgbudget.pk_dimension = ? ");
querySQL.append("and hrp_orgbudget.budget_version = ? ");
if (!isStartedTotalBudget)
{
// querySQL.append("and hrp_orgbudget.publish_state = '1' ");
querySQL.append("and ((hrp_orgbudget.publish_state = '1' and hrp_orgbudget.datasource=0) or hrp_orgbudget.datasource=1)");
}
if (includeSub)
{
querySQL.append("and org_adminorg.innercode like ? ");
}
else
{
querySQL.append("and org_adminorg.innercode like ? ");
querySQL.append("and ( ORG_ORGS.ORGTYPE4 = 'N' OR (ORG_ORGS.ORGTYPE4 = 'Y' AND ORG_HRORG.ENABLESTATE <> 2 ) OR ORG_ADMINORG.INNERCODE = ? )");
querySQL.append("and org_adminorg.pk_adminorg not in ( ");
querySQL.append("select ");
querySQL.append("aosm.pk_adminorg ");
querySQL.append("from ");
querySQL.append("( select ");
querySQL.append("aos.code, aos.innercode, len(aos.innercode) as innercodelen ");
querySQL.append("from ");
querySQL.append("org_orgs org inner join org_adminorg aos on org.pk_org = aos.pk_adminorg ");
querySQL.append(" left outer JOIN ORG_HRORG ON ORG_HRORG.PK_HRORG = AOS.PK_ADMINORG ");
querySQL.append("where ");
querySQL.append("aos.innercode like ? and aos.innercode <> ? and orgtype4 = 'Y' AND ORG_HRORG.ENABLESTATE = 2 ) ");
querySQL.append(" sub_hrorg, org_adminorg aosm ");
querySQL.append("where ");
querySQL.append("sub_hrorg.innercode = substring(aosm. innercode , 1, sub_hrorg.innercodelen)) ");
}
querySQL.append("order by org_adminorg.displayorder, org_orgs_v.code ");
SQLParameter parameter = new SQLParameter();
parameter.addParam(year);
parameter.addParam(pk_dimension);
parameter.addParam(version);
if (includeSub)
{
parameter.addParam(innercode + "%");
}
else
{
parameter.addParam(innercode + "%");
parameter.addParam(innercode);
parameter.addParam(innercode + "%");
parameter.addParam(innercode);
}
AOSFeaturedOrgVO[] orgVOs = (AOSFeaturedOrgVO[]) getBaseDAO().executeQuery(querySQL.toString(), parameter, new ResultSetProcessor()
{
@Override
public Object handleResultSet(ResultSet rs) throws SQLException
{
List<AOSFeaturedOrgVO> result = new ArrayList<AOSFeaturedOrgVO>();
while (rs.next())
{
AOSFeaturedOrgVO orgVO = new AOSFeaturedOrgVO();
orgVO.setCode(rs.getString(OrgVO.CODE));
int budget = rs.getInt(OrgBudgetVO.BUDGET_SELF);
if (rs.getString(OrgVO.NAME) != null)
{
orgVO.setName(rs.getString(OrgVO.NAME) + "(" + budget + ")");
}
if (rs.getString(OrgVO.NAME2) != null)
{
orgVO.setName2(rs.getString(OrgVO.NAME2) + "(" + budget + ")");
}
if (rs.getString(OrgVO.NAME3) != null)
{
orgVO.setName3(rs.getString(OrgVO.NAME3) + "(" + budget + ")");
}
orgVO.setPk_adminorg(rs.getString(AdminOrgVO.PK_ADMINORG));
orgVO.setPk_fatherorg(rs.getString(AdminOrgVO.PK_FATHERORG));
orgVO.setPk_org(rs.getString(OrgVO.PK_ORG));
orgVO.setPk_group(rs.getString(OrgVO.PK_GROUP));
result.add(orgVO);
}
return result.toArray(new AOSFeaturedOrgVO[0]);
}
});
return orgVOs;
}
/**
* 返回部门编制的占编数<br>
* @param deptPK
* @param psnclPKs
* @return
* @throws DAOException
*/
Integer retrieveDeptBudget(String deptPK, String[] psnclPKs) throws DAOException
{
InSQLCreator inSQLCreator = new InSQLCreator();
Object obj = null;
try
{
String sql = prepareDeptBudgetQuerySQL(new String[]{deptPK}, psnclPKs, inSQLCreator);
ColumnProcessor columnProcessor = new ColumnProcessor("psnsum");
obj = getBaseDAO().executeQuery(sql, columnProcessor);
}
catch (BusinessException ex)
{
Logger.error(ex.getMessage());
}
finally
{
if (inSQLCreator != null)
{
try
{
inSQLCreator.clear();
}
catch (BusinessException ex)
{
Logger.error(ex.getMessage());
}
}
}
if (obj == null)
{
return 0;
}
return (Integer) obj;
}
/**
* 返回部门编制的占编数VO 里面有人数和部门主键<br>
* @param deptPKs
* @param psnclPKs
* @return
* @throws DAOException
*/
GeneralVO[] retrieveDeptBudget(String[] deptPKs, String[] psnclPKs) throws DAOException
{
InSQLCreator inSQLCreator = new InSQLCreator();
List<GeneralVO> generalVOList = new ArrayList<GeneralVO>();
try
{
String sql = prepareDeptBudgetQuerySQL(deptPKs, psnclPKs, inSQLCreator);
generalVOList = (List<GeneralVO>) getBaseDAO().executeQuery(sql, new BeanListProcessor(GeneralVO.class));
}
catch (BusinessException ex)
{
Logger.error(ex.getMessage());
}
finally
{
if (inSQLCreator != null)
{
try
{
inSQLCreator.clear();
}
catch (BusinessException ex)
{
Logger.error(ex.getMessage());
}
}
}
return generalVOList.toArray(new GeneralVO[0]);
}
/**
* 根据年份版本获取特定组织的部门编制<br>
* @param pk_org
* @param year
* @param pk_dimension
* @param version
* @return
* @throws DAOException
*/
String[] retrieveDeptBudgetPKByYearVersion(String pk_org, Integer year, String pk_dimension, Integer version) throws DAOException
{
StringBuilder querySQL = new StringBuilder();
querySQL.append("select hrp_deptbudget.pk_dept_budget ");
querySQL.append("from hrp_deptbudget ");
querySQL.append("inner join org_dept_v on org_dept_v.pk_vid = hrp_deptbudget.pk_vid ");
querySQL.append("where hrp_deptbudget.budget_year = ? and hrp_deptbudget.budget_version = ? ");
querySQL.append("and hrp_deptbudget.pk_dimension = ? ");
querySQL.append("and hrp_deptbudget.pk_org = ? ");
querySQL.append("order by org_dept_v.code ");// 按innercode排序
SQLParameter parameter = new SQLParameter();
parameter.addParam(year);
parameter.addParam(version);
parameter.addParam(pk_dimension);
parameter.addParam(pk_org);
ResultSetProcessor processor = new ColumnListProcessor();
List<String> result = (List<String>) getBaseDAO().executeQuery(querySQL.toString(), parameter, processor);
if (result == null || result.isEmpty())
{
return new String[0];
}
return result.toArray(new String[0]);
}
/**
* 返回给定集团的部门编制记录数<br>
* @param pk_group
* @return
* @throws DAOException
*/
int retrieveDeptBudgetRecordNumber(String pk_group) throws DAOException
{
String sql = "select count(*) from hrp_deptbudget where pk_group = ?";
SQLParameter parameter = new SQLParameter();
parameter.addParam(pk_group);
Integer recordNum = (Integer) getBaseDAO().executeQuery(sql, parameter, new ColumnProcessor());
return recordNum;
}
/**
* 查询给定组织的所有部门编制年份<br>
* @param pk_org
* @return
* @throws DAOException
*/
Integer[] retrieveDeptBudgetYears(String pk_org) throws DAOException
{
String sql = "select distinct budget_year from hrp_deptbudget where pk_org = ?";
SQLParameter parameter = new SQLParameter();
parameter.addParam(pk_org);
List<Integer> years = (List<Integer>) getBaseDAO().executeQuery(sql, parameter, new ColumnListProcessor());
return years.toArray(new Integer[0]);
}
/**
* 查询当前集团下存在部门编制的组织单元PK<br>
* @param pk_group
* @return
* @throws DAOException
*/
String[] retrieveExistDeptBudgetOrgPKs(String pk_group) throws DAOException
{
String sql = " select distinct pk_org from hrp_deptbudget where pk_group = ?";
SQLParameter parameter = new SQLParameter();
parameter.addParam(pk_group);
List<String> orgPKs = (List<String>) getBaseDAO().executeQuery(sql, parameter, new ColumnListProcessor());
return orgPKs.toArray(new String[0]);
}
/**
* 返回公式解析的岗位编制的占编数
* @param deptPK
* @param psnclPKs
* @param wherePart
* @param pk_psnjob
* @return Integer 人数
* @throws DAOException
*/
public Integer retrieveFormulaPostBudget(String deptPK, String[] psnclPKs, String wherePart, String pk_psnjob) throws DAOException
{
StringBuilder querySQL = new StringBuilder();
String fromPart = "", lastSql = "";
InSQLCreator inSQLCreator = new InSQLCreator();
Object obj = null;
try
{
if (StringUtils.isEmpty(wherePart))
{
querySQL.append(" hi_psnjob.pk_dept " + " = '" + deptPK + "'");
}
else
{
ArrayList selectPartItems = new ArrayList();
Vector<String> vectorTableNames = REUtil.getUsedTable(selectPartItems, wherePart);
if (StringUtils.isNotEmpty(pk_psnjob))
{
fromPart = PsnBudgetParseFormulaUtils.joinTables(vectorTableNames);
}
else
{
fromPart = PsnBudgetCountParseFormulaUtils.joinTables(vectorTableNames);
}
querySQL.append("(" + wherePart + ") and hi_psnjob.pk_dept " + " = '" + deptPK + "'");
String whereInSql = "";
whereInSql = inSQLCreator.getInSQL(psnclPKs);
if (StringUtils.isNotEmpty(whereInSql))
{
querySQL.append(" and ");
querySQL.append("hi_psnjob.pk_psncl").append(" in (").append(whereInSql).append(")");
}
if (StringUtils.isNotEmpty(pk_psnjob))
{
querySQL.append(" and hi_psnjob.pk_psnjob ='" + pk_psnjob + "'");
}
}
lastSql = "select count(distinct hi_psnjob.pk_psndoc) from " + fromPart + " where " + querySQL.toString();
ColumnProcessor columnProcessor = new ColumnProcessor();
obj = getBaseDAO().executeQuery(lastSql, columnProcessor);
}
catch (BusinessException ex)
{
Logger.error(ex.getMessage());
}
finally
{
try
{
if (inSQLCreator != null)
{
inSQLCreator.clear();
}
}
catch (BusinessException ex)
{
Logger.error(ex.getMessage());
}
}
if (obj == null)
{
return 0;
}
return (Integer) obj;
}
/**
* 根据InnerCode查找所有归次HR组织管理的业务单元<br>
* @param innerCode
* @param condition
* @param orderPart
* @param mode
* @param strategy
* @return Object[]
* @throws DAOException
*/
public OrgVO[] retrieveOrgByHROrgInnerCode(String innerCode, OrgQueryMode mode) throws DAOException
{
StringBuilder querySQL = new StringBuilder();
SQLParameter parameter = prepareQueryOrgSQL(querySQL, innerCode, mode);
// FIXME 部门权限获取
String permissionSQL = null;
if (!StringUtil.isEmptyWithTrim(permissionSQL))
{
querySQL.append(" and org_orgs.pk_org in (").append(permissionSQL).append(")");
}
BaseProcessor processor = processor = new BeanListProcessor(AOSFeaturedOrgVO.class);
List<Object> orgVOList = (List<Object>) getBaseDAO().executeQuery(querySQL.toString(), parameter, processor);
AOSFeaturedOrgVO[] orgVOs = orgVOList.toArray(new AOSFeaturedOrgVO[0]);
return SuperVOHelper.createSuperVOsFromSuperVOs(orgVOs, OrgVO.class);
}
Map<String, Integer> retrievePostBudget(PostBudgetVO[] postBudgetVOs, String[] psnclPKs) throws BusinessException
{
InSQLCreator inSQLCreator = new InSQLCreator();
Map<String, Integer> result = new HashMap<String, Integer>();
try
{
String sql = preparePostBudgetQuerySQL(postBudgetVOs, psnclPKs, inSQLCreator);
AppendableVO[] appendableVOs =
(AppendableVO[]) getBaseDAO().executeQuery(sql, new AppendBeanArrayProcessor(AppendableVO.class));
if (appendableVOs != null)
{
for (AppendableVO vo : appendableVOs)
{
result.put((String) vo.getAttributeValue("pk_post"), (Integer) vo.getAttributeValue("count"));
}
}
}
finally
{
if (inSQLCreator != null)
{
inSQLCreator.clear();
}
}
return result;
}
/**
* 返回岗位编制的占编数<br>
* @param postPK
* @param psnclPKs
* @return
* @throws DAOException
*/
Integer retrievePostBudget(String postPK, String[] psnclPKs) throws DAOException
{
InSQLCreator inSQLCreator = new InSQLCreator();
Object obj = null;
try
{
String sql = preparePostBudgetQuerySQL(postPK, psnclPKs, inSQLCreator);
ColumnProcessor columnProcessor = new ColumnProcessor();
obj = getBaseDAO().executeQuery(sql, columnProcessor);
}
catch (BusinessException ex)
{
Logger.error(ex.getMessage());
}
finally
{
if (inSQLCreator != null)
{
try
{
inSQLCreator.clear();
}
catch (BusinessException ex)
{
Logger.error(ex.getMessage());
}
}
}
if (obj == null)
{
return 0;
}
return (Integer) obj;
}
/**
* 当参数"部门编制是否依赖单位编制"由"Y"变成"N"时,将最高版本的编制的版本改为0<br>
* @param pk_org
* @param year
*/
void updateDeptBudgetAfterDependenceChanged(String pk_org, Integer year) throws DAOException
{
String sql =
"update hrp_deptbudget set budget_version = 0 where pk_org = ? and budget_year = ? "
+ "and budget_version = (select max(budget_version) from hrp_deptbudget where pk_org = ? and budget_year = ?";
SQLParameter parameter = new SQLParameter();
parameter.addParam(pk_org);
parameter.addParam(year);
parameter.addParam(pk_org);
parameter.addParam(year);
getBaseDAO().executeUpdate(sql, parameter);
}
}