package th.co.muangthai.endrprint.dao.serviceImp; import oracle.jdbc.OracleTypes; import org.apache.commons.beanutils.BeanUtils; import org.apache.log4j.Logger; import org.hibernate.Criteria; import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.criterion.Order; import org.hibernate.criterion.Restrictions; import th.co.muangthai.endrprint.dao.serviceInterface.CommonServiceInterface; import th.co.muangthai.endrprint.model.bean.form.MsgErrorForm; import th.co.muangthai.endrprint.model.bean.form.SqlShowForm; import th.co.muangthai.endrprint.model.bean.form.data.PrinterDataTxtForm; import th.co.muangthai.endrprint.model.bean.form.data.PrintingDataForm; import th.co.muangthai.endrprint.model.bean.form.master.*; import th.co.muangthai.endrprint.model.bean.master.EndrPrintServerBean; import th.co.muangthai.endrprint.model.bean.master.EndrProvincialBean; import th.co.muangthai.endrprint.model.bean.master.EndrProvincialPrintBean; import th.co.muangthai.endrprint.model.bean.tmp.EndrTmpDataPrintBean; import th.co.muangthai.endrprint.model.hibernate.DatasourceUtil; import th.co.muangthai.endrprint.model.hibernate.HibernateUtil; import th.co.muangthai.endrprint.util.DateUtil; import th.co.muangthai.endrprint.util.TextContent; import th.co.muangthai.endrprint.util.VSMUtil; import java.io.*; import java.math.BigDecimal; import java.sql.*; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; import java.util.Date; /** * Information management CommonService Implement */ public class CommonServiceImp implements CommonServiceInterface { private Logger log = Logger.getLogger(CommonServiceImp.class); private SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy", VSMUtil.LOCALE); private SimpleDateFormat dateFormat2 = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss", VSMUtil.LOCALE); private SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss", VSMUtil.LOCALE); /** * Check Connect Database * * @return Boolean Result */ public boolean chkConnectDB() { Session session = null; try { session = HibernateUtil.getCurrentSession(); return true; } catch (Exception e) { e.printStackTrace(); } finally { HibernateUtil.closeSession(session); } return false; } /** * Update Table * * @param obj -Data Object * @return Boolean Result */ public boolean updateTable(Object obj) { Session session = HibernateUtil.getCurrentSession(); Transaction tx = session.beginTransaction(); try { if (obj instanceof List) { Iterator iter = ((List) obj).iterator(); while (iter.hasNext()) { session.saveOrUpdate(iter.next()); } } else { session.saveOrUpdate(obj); } tx.commit(); //HibernateUtils.closeSession(); return true; } catch (Exception e) { e.printStackTrace(); tx.rollback(); //HibernateUtils.closeSession(); return false; } finally { HibernateUtil.closeSession(session); } } /** * Update Table * * @param obj -Data Object * @param obj2 -Data Object * @param obj3 -Data Object * @param obj4 -Data Object * @param obj5 -Data Object * @return Boolean Result */ public boolean updateTable(Object obj, Object obj2, Object obj3, Object obj4, Object obj5) { Session session = HibernateUtil.getCurrentSession(); Transaction tx = session.beginTransaction(); try { if (null != obj) { if (obj instanceof List) { Iterator iter = ((List) obj).iterator(); while (iter.hasNext()) { session.saveOrUpdate(iter.next()); } } else { session.saveOrUpdate(obj); } } if (null != obj2) { if (obj2 instanceof List) { Iterator iter = ((List) obj2).iterator(); while (iter.hasNext()) { session.saveOrUpdate(iter.next()); } } else { session.saveOrUpdate(obj2); } } if (null != obj3) { if (obj3 instanceof List) { Iterator iter = ((List) obj3).iterator(); while (iter.hasNext()) { session.saveOrUpdate(iter.next()); } } else { session.saveOrUpdate(obj3); } } if (null != obj4) { if (obj4 instanceof List) { Iterator iter = ((List) obj4).iterator(); while (iter.hasNext()) { session.saveOrUpdate(iter.next()); } } else { session.saveOrUpdate(obj4); } } if (null != obj5) { if (obj5 instanceof List) { Iterator iter = ((List) obj5).iterator(); while (iter.hasNext()) { session.saveOrUpdate(iter.next()); } } else { session.saveOrUpdate(obj5); } } tx.commit(); //HibernateUtils.closeSession(); return true; } catch (Exception e) { log.error(e.toString(), e); //e.printStackTrace(); tx.rollback(); //HibernateUtils.closeSession(); throw new RuntimeException(e.toString(), e); } finally { HibernateUtil.closeSession(session); } } /** * Search Class By Primary key * * @param obj -Data Object * @param pk -Primary key * @return Object Result */ public Object searchClassByPK(Object obj, BigDecimal pk) { Object searchObj = null; Session session = HibernateUtil.getCurrentSession(); try { if (VSMUtil.isNotEmpty(pk)) { searchObj = session.get(obj.getClass(), pk); } } catch (Exception e) { e.printStackTrace(); } finally { HibernateUtil.closeSession(session); } return searchObj; } /** * Search Class By Primary key BigDecimal * * @param obj -Data Object * @param pk -Primary key * @return Object Result */ public Object searchClassByPKBigDecimal(Object obj, BigDecimal pk) { Object searchObj = null; Session session = HibernateUtil.getCurrentSession(); try { if (VSMUtil.isNotEmpty(pk)) { searchObj = session.get(obj.getClass(), pk); } } catch (Exception e) { e.printStackTrace(); } finally { HibernateUtil.closeSession(session); } return searchObj; } /** * Search Class By Primary key * * @param obj -Data Object * @param pk -Primary key * @return Object Result */ public Object searchClassByPK(Object obj, String pk) { Object searchObj = null; Session session = HibernateUtil.getCurrentSession(); try { if (VSMUtil.isNotEmpty(pk)) { searchObj = session.get(obj.getClass(), pk); } } catch (Exception e) { e.printStackTrace(); } finally { HibernateUtil.closeSession(session); } return searchObj; } /** * Search user login by package * * @param userId - userId * @param passWord - password * @return EndrUserLoginForm - data */ public EndrUserLoginForm searchUserLoginBeanByUserId(String userId, String passWord) { log.info("searchUserLoginBeanByUserId"); EndrUserLoginForm dbn = null; Session session = null; Connection conn = null; CallableStatement cstm = null; ResultSet rs = null; try { session = HibernateUtil.getCurrentSession(); conn = HibernateUtil.getConnection(); cstm = conn.prepareCall("{call PKG_WF_ENDR_AD.sp_sch_user_login(?,?,?)}"); cstm.registerOutParameter(1, OracleTypes.CURSOR); cstm.setString(2, userId); cstm.setString(3, passWord); cstm.execute(); rs = (ResultSet) cstm.getObject(1); while (rs.next()) { dbn = new EndrUserLoginForm(); dbn.setUserId(rs.getString("user_id")); dbn.setUserPassword(rs.getString("user_password")); dbn.setFirstname(rs.getString("firstname")); dbn.setLastname(rs.getString("lastname")); dbn.setTel(rs.getString("tel")); dbn.setUserName(rs.getString("user_name")); dbn.setCreateBy(rs.getString("create_by")); dbn.setCreateDate(rs.getTimestamp("create_date")); dbn.setUpdateBy(rs.getString("update_by")); dbn.setUpdateDate(rs.getTime("update_date")); dbn.setOperId(rs.getString("oper_id")); dbn.setDepcode(rs.getString("depcode")); } } catch (Exception e) { //e.printStackTrace(); log.error(e.toString(), e); } finally { try { HibernateUtil.close(rs, cstm); HibernateUtil.closeConnection(conn); HibernateUtil.closeSession(session); } catch (SQLException e) { //e.printStackTrace(); log.error(e.toString(), e); } } return dbn; } /** * Search user login by package * * @param userId - userId * @param firstname - firstname * @param lastname - lastname * @param operId - operId * @return List fo EndrUserLoginForm - data */ public List searchLstUserLoginBeanFormPkg(String userId, String firstname, String lastname, String operId) { log.info("searchLstUserLoginBeanFormPkg"); EndrUserLoginForm dbn = null; Session session = null; Connection conn = null; CallableStatement cstm = null; ResultSet rs = null; List lst = new ArrayList(); try { session = HibernateUtil.getCurrentSession(); conn = HibernateUtil.getConnection(); cstm = conn.prepareCall("{call PKG_WF_ENDR_AD.sp_sch_user_login_lst(?,?,?,?,?)}"); cstm.registerOutParameter(1, OracleTypes.CURSOR); cstm.setString(2, userId); cstm.setString(3, firstname); cstm.setString(4, lastname); cstm.setString(5, operId); cstm.execute(); rs = (ResultSet) cstm.getObject(1); while (rs.next()) { dbn = new EndrUserLoginForm(); dbn.setUserId(rs.getString("user_id")); dbn.setUserPassword(rs.getString("user_password")); dbn.setFirstname(rs.getString("firstname")); dbn.setLastname(rs.getString("lastname")); dbn.setTel(rs.getString("tel")); dbn.setUserName(rs.getString("user_name")); dbn.setCreateBy(rs.getString("create_by")); dbn.setCreateDate(rs.getTimestamp("create_date")); dbn.setUpdateBy(rs.getString("update_by")); dbn.setUpdateDate(rs.getTime("update_date")); dbn.setOperId(rs.getString("oper_id")); lst.add(dbn); } } catch (Exception e) { //e.printStackTrace(); log.error(e.toString(), e); } finally { try { HibernateUtil.close(rs, cstm); HibernateUtil.closeConnection(conn); HibernateUtil.closeSession(session); } catch (SQLException e) { //e.printStackTrace(); log.error(e.toString(), e); } } return lst; } /** * Search ENDR data print * * @param dataForm - PrintingDataForm * @return - List of PrintingDataForm */ public List searchPrintingDataFormPkg(PrintingDataForm dataForm) { List lst = new ArrayList(); Session session = null; Connection conn = null; CallableStatement cstm = null; ResultSet rs = null; try { session = HibernateUtil.getCurrentSession(); conn = HibernateUtil.getConnection(); cstm = conn.prepareCall("{call PKG_WF_ENDR_AD.sp_sch_data_print(?,?,?,?,?,?)}"); cstm.registerOutParameter(1, OracleTypes.CURSOR); cstm.setString(2, dataForm.getTeam()); cstm.setString(3, dataForm.getPolicyNo()); cstm.setString(4, dataForm.getClientNo()); cstm.setBigDecimal(5, null); // 0=print ,1=reprint if (VSMUtil.isNotEmpty(dataForm.getType())) { cstm.setBigDecimal(5, new BigDecimal(dataForm.getType())); } cstm.setString(6, null); // if (VSMUtil.isNotEmpty(dataForm.getApproveDate())) { //String str = DateUtil.toFormatString(dataForm.getApproveDate(), "yyyyMMdd"); //String str2 = DateUtil.toFormatStringWebEN(dataForm.getApproveDate()); String str3 = DateUtil.convertToBCCheckLocal2(dataForm.getApproveDate()); cstm.setString(6, str3); } cstm.execute(); rs = (ResultSet) cstm.getObject(1); PrintingDataForm dbn = null; while (rs.next()) { dbn = new PrintingDataForm(); dbn.setPrintingData(rs); lst.add(dbn); } } catch (Exception e) { //e.printStackTrace(); log.error(e.toString(), e); } finally { try { HibernateUtil.close(rs, cstm); HibernateUtil.closeConnection(conn); HibernateUtil.closeSession(session); } catch (SQLException e) { //e.printStackTrace(); log.error(e.toString(), e); } } return lst; } @Override public List searchEndrPrintServerFormPkg(EndrPrintServerForm dataForm) { List lst = new ArrayList(); Session session = null; Connection conn = null; CallableStatement cstm = null; ResultSet rs = null; try { session = HibernateUtil.getCurrentSession(); conn = HibernateUtil.getConnection(); cstm = conn.prepareCall("{call PKG_WF_ENDR_AD.sp_sch_endr_print_server(?,?,?,?,?,?,?,?,?,?)}"); //Set Parameter cstm.registerOutParameter(1, OracleTypes.CURSOR); cstm.setBigDecimal(2, dataForm.getServerId()); cstm.setString(3, dataForm.getServerName()); cstm.setString(4, dataForm.getPrinterName()); cstm.setString(5, dataForm.getIpAddrUat()); cstm.setString(6, dataForm.getIpAddrProd()); cstm.setString(7, dataForm.getFtpUsername()); cstm.setString(8, dataForm.getFtpPassword()); cstm.setString(9, dataForm.getFtpDirectory()); cstm.setBigDecimal(10, dataForm.getStatusFlag()); cstm.execute(); rs = (ResultSet) cstm.getObject(1); EndrPrintServerForm dbn = null; while (rs.next()) { dbn = new EndrPrintServerForm(); dbn.setEndrPrintServerData(rs); lst.add(dbn); } } catch (Exception e) { //e.printStackTrace(); log.error(e.toString(), e); } finally { try { HibernateUtil.close(rs, cstm); HibernateUtil.closeConnection(conn); HibernateUtil.closeSession(session); } catch (SQLException e) { //e.printStackTrace(); log.error(e.toString(), e); } } return lst; } /** * Search Master Pol Channel * * @param b - MstTeamForm * @return List MstPolChannelBean Result */ public List searchEndrPrintServerByBean(EndrPrintServerForm b) { List lst = new ArrayList(); Session session = null; try { session = HibernateUtil.getCurrentSession(); Criteria criteria = session.createCriteria(EndrPrintServerBean.class); if (b != null) { if (null != b.getServerId()) { criteria.add(Restrictions.eq("serverId", b.getServerId())); } if (null != b.getServerName()) { criteria.add(Restrictions.eq("serverName", b.getServerName())); } if (null != b.getPrinterName()) { criteria.add(Restrictions.like("printerName", b.getPrinterName())); } if (null != b.getIpAddrUat()) { criteria.add(Restrictions.like("ipAddrUat", b.getIpAddrUat())); } if (null != b.getIpAddrProd()) { criteria.add(Restrictions.like("ipAddrProd", b.getIpAddrProd())); } if (null != b.getFtpUsername()) { criteria.add(Restrictions.like("ftpUsername", b.getFtpUsername())); } if (null != b.getFtpPassword()) { criteria.add(Restrictions.like("ftpPassword", b.getFtpPassword())); } if (null != b.getFtpDirectory()) { criteria.add(Restrictions.like("ftpDirectory", b.getFtpDirectory())); } if (VSMUtil.isNotEmpty(b.getStatusFlag())) { criteria.add(Restrictions.eq("statusFlag", b.getStatusFlag())); } } criteria.addOrder(Order.asc("serverId")); lst = criteria.list(); } catch (Exception e) { e.printStackTrace(); } finally { HibernateUtil.closeSession(session); } return lst; } @Override public List searchEndrProvincialByBean(EndrProvincialForm b) { List lst = new ArrayList(); Session session = null; try { session = HibernateUtil.getCurrentSession(); Criteria criteria = session.createCriteria(EndrProvincialBean.class); if (b != null) { if (null != b.getProvincialId()) { criteria.add(Restrictions.eq("provincialId", b.getProvincialId())); } if (null != b.getProvincialDesc()) { criteria.add(Restrictions.eq("provincialDesc", b.getProvincialDesc())); } if (null != b.getProvincialAbbr()) { criteria.add(Restrictions.like("provincialAbbr", b.getProvincialAbbr())); } } criteria.addOrder(Order.asc("provincialId")); lst = criteria.list(); } catch (Exception e) { e.printStackTrace(); } finally { HibernateUtil.closeSession(session); } return lst; } @Override public List searchEndrProvincialPrintByPkg(BigDecimal provincialId, BigDecimal serverId, BigDecimal statusFlag) { List lst = new ArrayList(); Session session = null; Connection conn = null; CallableStatement cstm = null; ResultSet rs = null; try { session = HibernateUtil.getCurrentSession(); conn = HibernateUtil.getConnection(); cstm = conn.prepareCall("{call PKG_WF_ENDR_AD.sp_sch_endr_provincial_print(?,?,?,?)}"); cstm.registerOutParameter(1, OracleTypes.CURSOR); cstm.setBigDecimal(2, provincialId); cstm.setBigDecimal(3, serverId); cstm.setBigDecimal(4, statusFlag); cstm.execute(); rs = (ResultSet) cstm.getObject(1); EndrProvincialPrintForm dbn = null; while (rs.next()) { dbn = new EndrProvincialPrintForm(); dbn.setEndrProvincialPrintData(rs); lst.add(dbn); } } catch (Exception e) { //e.printStackTrace(); log.error(e.toString(), e); } finally { try { HibernateUtil.close(rs, cstm); HibernateUtil.closeConnection(conn); HibernateUtil.closeSession(session); } catch (SQLException e) { //e.printStackTrace(); log.error(e.toString(), e); } } return lst; } @Override public boolean insertEndrPrintServer(EndrPrintServerBean endrPrintServerBean) { Connection conn = null; Session session = null; session = HibernateUtil.getCurrentSession(); Transaction tx = session.beginTransaction(); try { conn = HibernateUtil.getConnection(); session.saveOrUpdate(endrPrintServerBean); tx.commit(); return true; } catch (Exception e) { e.printStackTrace(); tx.rollback(); } finally { try { HibernateUtil.closeConnection(conn); HibernateUtil.closeSession(session); } catch (SQLException e) { log.error(e.toString(), e); } } return false; } @Override public boolean insertEndrProvincialPrint(EndrProvincialPrintBean endrProvincialPrintBean) { Connection conn = null; Session session = null; session = HibernateUtil.getCurrentSession(); Transaction tx = session.beginTransaction(); try { conn = HibernateUtil.getConnection(); session.save(endrProvincialPrintBean); tx.commit(); return true; } catch (Exception e) { e.printStackTrace(); tx.rollback(); } finally { try { HibernateUtil.closeConnection(conn); HibernateUtil.closeSession(session); } catch (SQLException e) { log.error(e.toString(), e); } } return false; } @Override public boolean deleteEndrProvincialPrint(EndrProvincialPrintBean endrProvincialPrintBean) { Connection conn = null; Session session = null; session = HibernateUtil.getCurrentSession(); Transaction tx = session.beginTransaction(); try { conn = HibernateUtil.getConnection(); session.delete(endrProvincialPrintBean); tx.commit(); return true; } catch (Exception e) { e.printStackTrace(); tx.rollback(); } finally { try { HibernateUtil.closeConnection(conn); HibernateUtil.closeSession(session); } catch (SQLException e) { log.error(e.toString(), e); } } return false; } /** * Search master team by package * * @param userId - userId * @return List of TeamForm */ public List searchTeamFormPkg(String userId) { List lst = new ArrayList(); Session session = null; Connection conn = null; CallableStatement cstm = null; ResultSet rs = null; try { session = HibernateUtil.getCurrentSession(); conn = HibernateUtil.getConnection(); cstm = conn.prepareCall("{call PKG_WF_ENDR_AD.sp_sch_team(?,?)}"); cstm.registerOutParameter(1, OracleTypes.CURSOR); cstm.setString(2, userId); cstm.execute(); rs = (ResultSet) cstm.getObject(1); TeamForm dbn = null; while (rs.next()) { dbn = new TeamForm(); dbn.setTeamData(rs); lst.add(dbn); } } catch (Exception e) { //e.printStackTrace(); log.error(e.toString(), e); } finally { try { HibernateUtil.close(rs, cstm); HibernateUtil.closeConnection(conn); HibernateUtil.closeSession(session); } catch (SQLException e) { //e.printStackTrace(); log.error(e.toString(), e); } } return lst; } /** * Search master printer by package * * @param userId - userId * @return List of PrinterForm */ public List searchPrinterFormPkg(String userId) { List lst = new ArrayList(); Session session = null; Connection conn = null; CallableStatement cstm = null; ResultSet rs = null; try { session = HibernateUtil.getCurrentSession(); conn = HibernateUtil.getConnection(); cstm = conn.prepareCall("{call PKG_WF_ENDR_AD.sp_sch_printer(?,?)}"); cstm.registerOutParameter(1, OracleTypes.CURSOR); cstm.setString(2, userId); cstm.execute(); rs = (ResultSet) cstm.getObject(1); PrinterForm dbn = null; while (rs.next()) { dbn = new PrinterForm(); dbn.setPrinterData(rs); lst.add(dbn); } } catch (Exception e) { //e.printStackTrace(); log.error(e.toString(), e); } finally { try { HibernateUtil.close(rs, cstm); HibernateUtil.closeConnection(conn); HibernateUtil.closeSession(session); } catch (SQLException e) { //e.printStackTrace(); log.error(e.toString(), e); } } return lst; } /** * Search master provincial by package * * @param userId - userId * @return object of EndrProvincialForm */ public EndrProvincialForm searchProvincialFormPkg(String userId) { EndrProvincialForm form = null; Session session = null; Connection conn = null; CallableStatement cstm = null; ResultSet rs = null; try { session = HibernateUtil.getCurrentSession(); conn = HibernateUtil.getConnection(); cstm = conn.prepareCall("{call PKG_WF_ENDR_AD.sp_sch_provincial(?,?)}"); cstm.registerOutParameter(1, OracleTypes.CURSOR); cstm.setString(2, userId); cstm.execute(); rs = (ResultSet) cstm.getObject(1); while (rs.next()) { form = new EndrProvincialForm(); form.setProvincialData(rs); //lst.add(dbn); } } catch (Exception e) { //e.printStackTrace(); log.error(e.toString(), e); } finally { try { HibernateUtil.close(rs, cstm); HibernateUtil.closeConnection(conn); HibernateUtil.closeSession(session); } catch (SQLException e) { //e.printStackTrace(); log.error(e.toString(), e); } } return form; } /** * Search master provincial by package * * @param provincial - provincial * @return boolean */ public boolean isProvincialFormPkg(EndrProvincialForm provincial) { Session session = null; Connection conn = null; CallableStatement cstm = null; ResultSet rs = null; boolean f = false; EndrProvincialForm form = null; if (null == provincial) return f; try { session = HibernateUtil.getCurrentSession(); conn = HibernateUtil.getConnection(); cstm = conn.prepareCall("{call PKG_WF_ENDR_AD.sp_chk_provincial(?,?)}"); cstm.registerOutParameter(1, OracleTypes.VARCHAR); cstm.setBigDecimal(2, provincial.getProvincialId()); cstm.execute(); String str = (String) cstm.getObject(1); // while (rs.next()){ // form = new EndrProvincialForm(); // form.setIsProvincial(rs.getString(1)); // f = Boolean.parseBoolean(form.getIsProvincial()); // //lst.add(dbn); // } f = Boolean.parseBoolean(str); } catch (Exception e) { //e.printStackTrace(); log.error(e.toString(), e); } finally { try { HibernateUtil.close(rs, cstm); HibernateUtil.closeConnection(conn); HibernateUtil.closeSession(session); } catch (SQLException e) { //e.printStackTrace(); log.error(e.toString(), e); } } return f; } /** * Insert/Save ENDR print data into temp table by package * * @param lstEndrTmpDataPrintBean - list of ENDR print data * @return boolean */ public boolean insertEndrTmpDataPrint(List lstEndrTmpDataPrintBean) { Connection conn = null; Session session = null; session = HibernateUtil.getCurrentSession(); Transaction tx = session.beginTransaction(); try { conn = HibernateUtil.getConnection(); if (VSMUtil.isNotEmptyLst(lstEndrTmpDataPrintBean) && lstEndrTmpDataPrintBean.size() > 0) { for (int i = 0; i < lstEndrTmpDataPrintBean.size(); i++) { session.save(lstEndrTmpDataPrintBean.get(i)); } } tx.commit(); return true; } catch (Exception e) { e.printStackTrace(); tx.rollback(); } finally { try { HibernateUtil.closeConnection(conn); HibernateUtil.closeSession(session); } catch (SQLException e) { log.error(e.toString(), e); } } return false; } /** * Search ENDR print data by package * * @param sProcessID - processId * @param sType - 0 = first printing, 1 = reprint * @return List of PrinterDataTxtForm */ public List searchPrinterDataTxtFormPkg(String sProcessID, BigDecimal sType) { List lst = new ArrayList(); Session session = null; Connection conn = null; CallableStatement cstm = null; ResultSet rs = null; try { session = HibernateUtil.getCurrentSession(); conn = HibernateUtil.getConnection(); cstm = conn.prepareCall("{call PKG_WF_ENDR_AD.sp_update_data_print(?,?,?)}"); cstm.registerOutParameter(1, OracleTypes.CURSOR); cstm.setString(2, sProcessID); cstm.setBigDecimal(3, sType); cstm.execute(); rs = (ResultSet) cstm.getObject(1); PrinterDataTxtForm dbn = null; while (rs.next()) { dbn = new PrinterDataTxtForm(); dbn.setPrinterDataTxt(rs); lst.add(dbn); } } catch (Exception e) { //e.printStackTrace(); log.error(e.toString(), e); } finally { try { if (rs != null) { rs.close(); } if (cstm != null) { cstm.close(); } //HibernateUtil.close(rs,cstm); HibernateUtil.closeConnection(conn); HibernateUtil.closeSession(session); } catch (SQLException e) { //e.printStackTrace(); log.error(e.toString(), e); } } return lst; } /** * Update ENDR print data to finish by package * * @param sProcessID - processId * @param sType - 0 = first printing, 1 = reprint * @return boolean */ public boolean updateFinishFtp(String sProcessID, BigDecimal sType) { Session session = null; Connection conn = null; CallableStatement cstm = null; ResultSet rs = null; try { session = HibernateUtil.getCurrentSession(); conn = HibernateUtil.getConnection(); cstm = conn.prepareCall("{call PKG_WF_ENDR_AD.sp_finish_data_print(?,?)}"); cstm.setString(1, sProcessID); cstm.setBigDecimal(2, sType); cstm.execute(); return true; } catch (Exception e) { //e.printStackTrace(); log.error(e.toString(), e); } finally { try { HibernateUtil.close(rs, cstm); HibernateUtil.closeConnection(conn); HibernateUtil.closeSession(session); } catch (SQLException e) { //e.printStackTrace(); log.error(e.toString(), e); } } return false; } /** * Update ENDR print data to reject by package * * @param sProcessID - processId * @param sType - 0 = first printing, 1 = reject * @return boolean */ public boolean updateReject(String sProcessID, BigDecimal sType) { Session session = null; Connection conn = null; CallableStatement cstm = null; ResultSet rs = null; try { session = HibernateUtil.getCurrentSession(); conn = HibernateUtil.getConnection(); cstm = conn.prepareCall("{call PKG_WF_ENDR_AD.sp_reject_data_print(?,?)}"); cstm.setString(1, sProcessID); cstm.setBigDecimal(2, sType); cstm.execute(); return true; } catch (Exception e) { //e.printStackTrace(); log.error(e.toString(), e); } finally { try { HibernateUtil.close(rs, cstm); HibernateUtil.closeConnection(conn); HibernateUtil.closeSession(session); } catch (SQLException e) { //e.printStackTrace(); log.error(e.toString(), e); } } return false; } /** * Search data path file * * @return Map Result */ public Map getPathFile() { Session session = null; Connection conn = null; CallableStatement cstm = null; ResultSet rs = null; Map mapPathFile = new HashMap(); try { session = HibernateUtil.getCurrentSession(); conn = HibernateUtil.getConnection(); cstm = conn.prepareCall("{call PKG_WF_ENDR_AD.sp_sch_path_txt_file(?)}"); cstm.registerOutParameter(1, OracleTypes.CURSOR); cstm.execute(); rs = (ResultSet) cstm.getObject(1); while (rs.next()) { mapPathFile.put(rs.getBigDecimal("mst_path_txt_file_id"), rs.getString("path_file")); } } catch (Exception e) { log.error(e.toString(), e); } finally { try { HibernateUtil.close(rs, cstm); HibernateUtil.closeConnection(conn); HibernateUtil.closeSession(session); } catch (SQLException e) { log.error(e.toString(), e); } } return mapPathFile; } public Object[] searchTxtSql(String sql) { Session session = null; Connection conn = null; ResultSet rs = null; PreparedStatement stmt = null; ResultSetMetaData rsmd = null; List columnLst = new ArrayList(); List dataLst = new ArrayList(); // try { // String filePath = "./"+tableXml.getTxtName().toUpperCase()+".TXT"; // Delete file String filePath = "", fileNum = ""; session = HibernateUtil.getCurrentSession(); conn = HibernateUtil.getConnection(); stmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); // stmt.setString(1, strMIGIDRef); //EXECUTE QUERY // stmt.executeQuery(); // rs = stmt.getResultSet(); rs = stmt.executeQuery(); rsmd = rs.getMetaData(); int numCol = rsmd.getColumnCount(); String[][] rowCol = new String[numCol][2]; String columnRow = ""; for (int i = 1; i <= numCol; i++) { String name = rsmd.getColumnName(i); rowCol[i - 1][0] = name; rowCol[i - 1][1] = "0"; if ("java.sql.Timestamp".equals(rsmd.getColumnClassName(i)) || "java.sql.Date".equals(rsmd.getColumnClassName(i))) { rowCol[i - 1][1] = "1"; } columnLst.add(name); } int maxCol = rowCol.length; String txt = ""; // List lst = new ArrayList(); List dataRowLst = new ArrayList(); int countRow = 0; while (rs.next()) { countRow++; dataRowLst = new ArrayList(); //String[] row = MstSetArrayStringBean.setDataTxt(rs, maxCol, rowCol); for (int i = 0; i < maxCol; i++) { String typex = (String) rowCol[i][1]; if ("1".equals(typex)) { // Date Date dd = rs.getTimestamp(rowCol[i][0]); if (VSMUtil.isNotEmpty(dd)) { try { DateUtil.toFormatStringWebTh3(dd); String formattedDate = dateFormat.format(dd); if (!"00:00:00".equals(timeFormat.format(dd))) { formattedDate = dateFormat2.format(dd); } dataRowLst.add(formattedDate); } catch (ParseException e) { e.printStackTrace(); } } else { dataRowLst.add(""); } } else { dataRowLst.add(rs.getString(rowCol[i][0])); } } SqlShowForm dbean = new SqlShowForm(); dbean.setDataRow(dataRowLst); dataLst.add(dbean); if (countRow == 1000) { break; } } } catch (SQLException ex) { // log.error(ex.toString()); } finally { try { HibernateUtil.close(rs, null); HibernateUtil.closeConnection(conn); HibernateUtil.closeSession(session); } catch (SQLException e) { // log.error(e.toString(), e); } } return new Object[]{columnLst, dataLst}; } public int executeTxtSql(String sql) { Session session = null; Connection conn = null; PreparedStatement stmt = null; Transaction tx = null; int ret = 0; // try { session = HibernateUtil.getCurrentSession(); tx = session.beginTransaction(); conn = HibernateUtil.getConnection(); stmt = conn.prepareStatement(sql); ret = stmt.executeUpdate(); tx.commit(); } catch (SQLException ex) { // log.error(ex.toString()); tx.rollback(); } finally { try { HibernateUtil.closeConnection(conn); HibernateUtil.closeSession(session); } catch (SQLException e) { // log.error(e.toString(), e); } } return ret; } public boolean executeTxtSqlUpdatePkg(String sql) { Session session = null; Connection conn = null; PreparedStatement stmt = null; Transaction tx = null; // try { session = HibernateUtil.getCurrentSession(); tx = session.beginTransaction(); conn = HibernateUtil.getConnection(); stmt = conn.prepareStatement(sql); //stmt.executeQuery(); stmt.execute(); tx.commit(); return true; } catch (SQLException ex) { //log.error(ex.toString()); tx.rollback(); } finally { try { HibernateUtil.closeConnection(conn); HibernateUtil.closeSession(session); } catch (SQLException e) { // log.error(e.toString(), e); } } return false; } public Object[] searchTxtSqlEdas(String sql) { Session session = null; Connection conn = null; ResultSet rs = null; PreparedStatement stmt = null; ResultSetMetaData rsmd = null; List columnLst = new ArrayList(); List dataLst = new ArrayList(); // try { session = DatasourceUtil.getCurrentSession(); conn = DatasourceUtil.getConnection(); stmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); rs = stmt.executeQuery(); rsmd = rs.getMetaData(); int numCol = rsmd.getColumnCount(); String[][] rowCol = new String[numCol][2]; String columnRow = ""; for (int i = 1; i <= numCol; i++) { String name = rsmd.getColumnName(i); rowCol[i - 1][0] = name; rowCol[i - 1][1] = "0"; if ("java.sql.Timestamp".equals(rsmd.getColumnClassName(i)) || "java.sql.Date".equals(rsmd.getColumnClassName(i))) { rowCol[i - 1][1] = "1"; } columnLst.add(name); } int maxCol = rowCol.length; String txt = ""; //List lst = new ArrayList(); List dataRowLst = new ArrayList(); int countRow = 0; while (rs.next()) { countRow++; dataRowLst = new ArrayList(); //String[] row = MstSetArrayStringBean.setDataTxt(rs, maxCol, rowCol); for (int i = 0; i < maxCol; i++) { String typex = (String) rowCol[i][1]; if ("1".equals(typex)) { // Date Date dd = rs.getTimestamp(rowCol[i][0]); if (VSMUtil.isNotEmpty(dd)) { try { DateUtil.toFormatStringWebTh3(dd); String formattedDate = dateFormat.format(dd); if (!"00:00:00".equals(timeFormat.format(dd))) { formattedDate = dateFormat2.format(dd); } dataRowLst.add(formattedDate); } catch (ParseException e) { e.printStackTrace(); } } else { dataRowLst.add(""); } } else { dataRowLst.add(rs.getString(rowCol[i][0])); } } SqlShowForm dbean = new SqlShowForm(); dbean.setDataRow(dataRowLst); dataLst.add(dbean); if (countRow == 1000) { break; } } } catch (SQLException ex) { //log.error(ex.toString()); } finally { try { DatasourceUtil.close(rs, null); DatasourceUtil.closeConnection(conn); DatasourceUtil.closeSession(session); } catch (SQLException e) { //log.error(e.toString(), e); } } return new Object[]{columnLst, dataLst}; } /** * Search master team by package * * @param userId - userId * @return List of TeamForm */ public List searchProvincialTeamFormPkg(String userId) { List lst = new ArrayList(); Session session = null; Connection conn = null; CallableStatement cstm = null; ResultSet rs = null; try { session = HibernateUtil.getCurrentSession(); conn = HibernateUtil.getConnection(); cstm = conn.prepareCall("{call PKG_WF_ENDR_AD.sp_sch_provincial_team(?,?)}"); cstm.registerOutParameter(1, OracleTypes.CURSOR); cstm.setString(2, userId); cstm.execute(); rs = (ResultSet) cstm.getObject(1); TeamForm dbn = null; while (rs.next()) { dbn = new TeamForm(); dbn.setTeamData(rs); lst.add(dbn); } } catch (Exception e) { //e.printStackTrace(); log.error(e.toString(), e); } finally { try { HibernateUtil.close(rs, cstm); HibernateUtil.closeConnection(conn); HibernateUtil.closeSession(session); } catch (SQLException e) { //e.printStackTrace(); log.error(e.toString(), e); } } return lst; } /** * Search master printer by package * * @param userId - userId * @return List of PrinterForm */ public List searchProvincialPrinterFormPkg(String userId) { List lst = new ArrayList(); Session session = null; Connection conn = null; CallableStatement cstm = null; ResultSet rs = null; try { session = HibernateUtil.getCurrentSession(); conn = HibernateUtil.getConnection(); cstm = conn.prepareCall("{call PKG_WF_ENDR_AD.sp_sch_provincial_printer(?,?)}"); cstm.registerOutParameter(1, OracleTypes.CURSOR); cstm.setString(2, userId); cstm.execute(); rs = (ResultSet) cstm.getObject(1); PrinterForm dbn = null; while (rs.next()) { dbn = new PrinterForm(); dbn.setPrinterData(rs); lst.add(dbn); } } catch (Exception e) { //e.printStackTrace(); log.error(e.toString(), e); } finally { try { HibernateUtil.close(rs, cstm); HibernateUtil.closeConnection(conn); HibernateUtil.closeSession(session); } catch (SQLException e) { //e.printStackTrace(); log.error(e.toString(), e); } } return lst; } }