/*********************************************************************************** * @@ Program Name : AssignList.java Description : 보고자 이관 List Author : Create Date : History : * @@ ***********************************************************************************/ package kr.co.kihyun.beans.totsys.repoper; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import kr.co.kihyun.beans.entity.Emul; import kr.co.kihyun.beans.entity.MDept; import kr.co.kihyun.beans.entity.MUser; import kr.co.kihyun.beans.entity.MoumiEntity; import kr.co.kihyun.beans.entity.TotReport; import kr.co.kihyun.beans.entity.UserHistory; import kr.co.kihyun.db.DBManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class RepTransfer extends DBManager { private static final Logger LOG = LoggerFactory.getLogger(RepTransfer.class); private ResultSet rs = null; private int count = 0; private String[] userIDList = null; private String[] userNameList = null; private String[] deptNameList = null; private String[] deptIDList = null; private String[] userPhoneList = null; private String[] changeUserIDList = null; private String[] changeUserDateList = null; private String[] upperDeptIDList = null; public void transListQuery(String deptID, int sysAuth) { StringBuilder sql = new StringBuilder(300); try { sql.append("SELECT us.id, sp_cm_dec_fu(us.name), em.dept_id, dp.name, us.phone FROM ") .append(MoumiEntity.getTableName(Emul.class)).append(" em, ") .append(MoumiEntity.getTableName(MUser.class)).append(" us, ") .append(MoumiEntity.getTableName(MDept.class)).append(" dp ") .append("WHERE em.user_id=us.id and em.dept_id=dp.id AND em.dept_id=? ") .append("AND us.sys_auth <= ? and (us.del_type='0' or us.del_type='N')"); rs = execQuery(sql.toString(), deptID, sysAuth); if (rs != null) { rs.last(); count = rs.getRow(); rs.beforeFirst(); } else { return; } userIDList = new String[count]; userNameList = new String[count]; userPhoneList = new String[count]; deptNameList = new String[count]; deptIDList = new String[count]; for (int i = 0; rs.next(); i++) { userIDList[i] = rs.getString(1); userNameList[i] = rs.getString(2); deptIDList[i] = rs.getString(3); deptNameList[i] = rs.getString(4); userPhoneList[i] = rs.getString(5); } } catch (SQLException sqlEx) { LOG.error("\nSQLState - {}\nMySQL Error Code - {}\nmessage - {}\nsql - {}", new Object[] { sqlEx.getSQLState(), sqlEx.getErrorCode(), sqlEx.getMessage(), sql }); throw new RuntimeException(sqlEx); } catch (Exception ex) { throw new RuntimeException(ex); } finally { close(rs); execClose(); } } public void searchListQuery(int sysAuth, String addString, String findWord) { searchListQuery(null, sysAuth, addString, findWord); } public void searchListQuery(String deptID, int sysAuth, String findOption, String findWord) { StringBuilder sql = new StringBuilder(300); ArrayList paramList = new ArrayList(); try { sql.append("SELECT us.id, sp_cm_dec_fu(us.name), us.dept_id, dp.name, us.phone, dp.upper_dept FROM ") .append(MoumiEntity.getTableName(Emul.class)).append(" em, ") .append(MoumiEntity.getTableName(MUser.class)).append(" us, ") .append(MoumiEntity.getTableName(MDept.class)).append(" dp ") .append("WHERE em.user_id=us.id and (us.del_type='0' or us.del_type='N') ") .append("and em.dept_id=dp.id AND us.sys_auth < 3 AND us.sys_auth >= 0 ") .append("AND dp.name NOT LIKE '%테스트%' AND lower(dp.name) NOT LIKE '%test%' AND "); if (deptID != null) { sql.append("em.dept_id=? AND "); paramList.add(deptID); } if ("dept".equals(findOption)) { sql.append("dp.name like ? "); paramList.add("%" + findWord + "%"); } else if ("name".equals(findOption)) { sql.append("sp_cm_dec_fu(us.name) like ? "); paramList.add("%" + findWord + "%"); } else if ("id".equals(findOption)) { sql.append("us.id like ? "); paramList.add("%" + findWord + "%"); } else { sql.append("(dp.name like ? OR sp_cm_dec_fu(us.name) like ? OR us.id like ?) "); paramList.add("%" + findWord + "%"); paramList.add("%" + findWord + "%"); paramList.add("%" + findWord + "%"); } sql.append("order by us.priority"); rs = execQuery(sql.toString(), paramList.toArray()); if (rs != null) { rs.last(); count = rs.getRow(); rs.beforeFirst(); } else { return; } userIDList = new String[count]; userNameList = new String[count]; deptIDList = new String[count]; deptNameList = new String[count]; userPhoneList = new String[count]; upperDeptIDList = new String[count]; for (int i = 0; rs.next(); i++) { userIDList[i] = rs.getString(1); userNameList[i] = rs.getString(2); deptIDList[i] = rs.getString(3); deptNameList[i] = rs.getString(4); userPhoneList[i] = rs.getString(5); upperDeptIDList[i] = rs.getString(6); } } catch (SQLException sqlEx) { LOG.error("\nSQLState - {}\nMySQL Error Code - {}\nmessage - {}\nsql - {}", new Object[] { sqlEx.getSQLState(), sqlEx.getErrorCode(), sqlEx.getMessage(), sql }); throw new RuntimeException(sqlEx); } catch (Exception ex) { throw new RuntimeException(ex); } finally { close(rs); execClose(); } } public int getDocType(Long docID, String deptID) { StringBuilder sql = new StringBuilder(90); int doc_type = 0; try { sql.append("select doc_type from ").append(MoumiEntity.getTableName(TotReport.class)) .append(" where doc_id=? and dept_id=?"); rs = execQuery(sql.toString(), docID, deptID); if (rs.next()) { doc_type = rs.getInt(1); } return doc_type; } catch (SQLException sqlEx) { LOG.error("\nSQLState - {}\nMySQL Error Code - {}\nmessage - {}\nsql - {}", new Object[] { sqlEx.getSQLState(), sqlEx.getErrorCode(), sqlEx.getMessage(), sql }); throw new RuntimeException(sqlEx); } catch (Exception ex) { throw new RuntimeException(ex); } finally { close(rs); execClose(); } } public void userTransListQuery(Long docID, String deptID) { StringBuilder sql = new StringBuilder(90); try { sql.append("SELECT user_id, change_id, write_date FROM ") .append(MoumiEntity.getTableName(UserHistory.class)) .append(" where doc_id=? and dept_id=?"); rs = execQuery(sql.toString(), docID, deptID); if (rs != null) { rs.last(); count = rs.getRow(); rs.beforeFirst(); } else { return; } userIDList = new String[count]; changeUserIDList = new String[count]; changeUserDateList = new String[count]; for (int i = 0; rs.next(); i++) { userIDList[i] = rs.getString(1); changeUserIDList[i] = rs.getString(2); changeUserDateList[i] = rs.getString(3); } } catch (SQLException sqlEx) { LOG.error("\nSQLState - {}\nMySQL Error Code - {}\nmessage - {}\nsql - {}", new Object[] { sqlEx.getSQLState(), sqlEx.getErrorCode(), sqlEx.getMessage(), sql }); throw new RuntimeException(sqlEx); } catch (Exception ex) { throw new RuntimeException(ex); } finally { close(rs); execClose(); } } public void usertransListQuery(Long docID, String deptID) { StringBuilder sql = new StringBuilder(90); try { sql.append("SELECT user_id, change_id, write_date FROM ") .append(MoumiEntity.getTableName(UserHistory.class)) .append(" where doc_id=? and dept_id=?"); rs = execQuery(sql.toString(), docID, deptID); if (rs != null) { rs.last(); count = rs.getRow(); rs.beforeFirst(); } else { return; } userIDList = new String[count]; changeUserIDList = new String[count]; changeUserDateList = new String[count]; for (int i = 0; rs.next(); i++) { userIDList[i] = rs.getString(1); changeUserIDList[i] = rs.getString(2); changeUserDateList[i] = rs.getString(3); } } catch (SQLException sqlEx) { LOG.error("\nSQLState - {}\nMySQL Error Code - {}\nmessage - {}\nsql - {}", new Object[] { sqlEx.getSQLState(), sqlEx.getErrorCode(), sqlEx.getMessage(), sql }); throw new RuntimeException(sqlEx); } catch (Exception ex) { throw new RuntimeException(ex); } finally { close(rs); execClose(); } } public int getCount() { return count; } public String[] getUserIDList() { //24.Public 메소드로부터 반환된 Private배열_CWE-495 : Update by KWON,HAN // return userIDList; String[] ret = null; if( this.userIDList != null) { ret = new String[userIDList.length]; for (int i=0; i