📄 resposutil.java.svn-base
字号:
package com.nsi.components.util;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.nsi.components.department.RsPosDetail;
import com.nsi.constants.AppConstants;
import com.nsi.control.exceptions.NsiEventException;
import com.nsi.persistence.DataSrcUtil;
import com.nsi.persistence.IsqlDataSource;
import com.nsi.util.ValHelper;
/**
* @author Chris Ye, created on Oct 9, 2008
*
* ResPosUtil
*/
public final class ResPosUtil
{
private static Log log = LogFactory.getLog(ResPosUtil.class);
/**
* private constructor of ResPosUtil, prevent instantiation
*/
private ResPosUtil()
{
}
private static class ResPosUtilHolder
{
static final ResPosUtil resPosUtil = new ResPosUtil();
}
/**
* @return an instance of ResPosUtil
*/
public static ResPosUtil getInstance()
{
return ResPosUtilHolder.resPosUtil;
}
public List<RsPosDetail> getDetaillist( String deptid, String resStatusSQL ) throws NsiEventException
{
List<RsPosDetail> list = new ArrayList<RsPosDetail>();
List<Map<String,String>> result = new ArrayList<Map<String,String>>();
String sSql = "select a.respositionid, a.resourceid, a.deptroleid, b.bactive " +
"from t_res_position a, t_resource b " +
"where a.departmentid = " + deptid.trim() + " " + resStatusSQL + " " +
"and a.resourceid = b.resourceid " +
"order by a.deptroleid, b.firstname, b.middlename, b.lastname";
IsqlDataSource src = DataSrcUtil.getInstance().getDataSource();
Connection conn = null;
try
{
conn = src.getConnection();
result = src.executeRetrieve(conn, sSql);
}
catch( SQLException se )
{
log.error( "getDetaillist() caught SQLException: " + se );
}
catch( Exception ex )
{
log.error( "getDetaillist() caught Exception: " + ex );
}
finally
{
src.closeConn(conn);
}
if(!result.isEmpty())
{
int size = result.size();
for (int i = 0; i < size; i++)
{
Map<String,String> resultmap = result.get(i);
RsPosDetail detail = new RsPosDetail();
detail.setDeptid(deptid);
detail.setRsposid(ValHelper.getInstance().getValue(resultmap, "respositionid"));
detail.setResourceid(ValHelper.getInstance().getValue(resultmap, "resourceid"));
detail.setDeptroleid(ValHelper.getInstance().getValue(resultmap, "deptroleid"));
detail.setActive(ValHelper.getInstance().getValue(resultmap, "bactive"));
list.add(detail);
}
}
return list;
}
public void updateResPosition( List<RsPosDetail> list, String deptid, String loginuser ) throws NsiEventException
{
IsqlDataSource src = DataSrcUtil.getInstance().getDataSource();
Connection conn = null;
Statement stmt = null;
try
{
conn = src.getConnection();
int size = list.size();
for (int i = 0; i < size; i++)
{
stmt = conn.createStatement();
RsPosDetail detail = list.get(i);
String sSql = AppConstants.EMPTY_STRING;
String dtldeptid = detail.getDeptid();
if(deptid.trim().equalsIgnoreCase(dtldeptid.trim()))
{
String rsposid = detail.getRsposid();
String resourceid = detail.getResourceid();
String deptroleid = detail.getDeptroleid();
String delete = detail.getDeleting();
if( ValHelper.getInstance().isNotNullAndEmpty(rsposid))
{
if("T".equalsIgnoreCase(delete))
{
sSql = "delete from t_res_position where respositionid = " + rsposid + "";
}else if("F".equalsIgnoreCase(delete.trim())){
sSql = "update t_res_position " +
"set moduserid=" + loginuser.trim() + ", " +
"deptroleid=" + deptroleid + " " +
"where respositionid=" + rsposid+"";
}
}else{
if("F".equalsIgnoreCase(delete.trim()))
{
sSql = "insert into t_res_position (respositionid,resourceid,departmentid,deptroleid,moduserid ) " +
"values ( nextval('respositionid_seq'), " + resourceid.trim() + "," +
deptid.trim() + "," + deptroleid.trim() + "," + loginuser.trim() + " )";
}
}
if( ValHelper.getInstance().isNotNullAndEmpty(sSql))
{
int resultCount = src.executeUpdate(stmt, sSql);
if(resultCount != 1) throw new NsiEventException("ERROR update projectAct from t_pro_act!! resultCount = " + resultCount);
}
}
}
}
catch( SQLException se )
{
log.error( "getDetaillist() caught SQLException: " + se );
}
catch( Exception ex )
{
log.error( "getDetaillist() caught Exception: " + ex );
}
finally
{
src.closeConn(conn);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -