package com.szpg.db.dao.impl; import com.szpg.db.dao.PgConRequestMsgDao; import com.szpg.db.data.PgConRequestMsg; import com.szpg.db.data.PgConWorkOrder; import com.szpg.db.util.ConnectionManager; import org.apache.commons.dbutils.DbUtils; import org.apache.commons.dbutils.QueryRunner; import org.apache.commons.dbutils.handlers.BeanListHandler; import org.apache.log4j.Logger; import java.sql.Connection; import java.sql.SQLException; import java.util.ArrayList; import java.util.Date; import java.util.List; public class PgConRequestMsgDaoImp implements PgConRequestMsgDao { private org.apache.log4j.Logger logger = Logger.getLogger(this.getClass().getName()); @Override public void addConRequestMsg(List<PgConRequestMsg> pgConRequestMsgList){ Connection conn = null; String insertStr = "INSERT INTO PG_CON_REQUEST_MSG " + "(BUILD_TASK_ID, DATE, TASK_ID,BUILD_COMPANY,SUPERVISOR_TEL,TEL,BUILD_PLACE,BUILD_TIME,START_PLACE," + "END_PLACE,PROJECT,BUILD_CONTENT,APPROVER,APPROVER_TIME,LOG_DATE)" + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; List<Object[]> paramObjectList=new ArrayList<>(); for(PgConRequestMsg pgConRequestMsg:pgConRequestMsgList){ Object[] params = new Object[34]; params[0] = pgConRequestMsg.getBUILD_TASK_ID(); params[1] = pgConRequestMsg.getDATE(); params[2] = pgConRequestMsg.getTASK_ID(); params[3] = pgConRequestMsg.getBUILD_COMPANY(); params[4] = pgConRequestMsg.getSUPERVISOR_TEL(); params[5] = pgConRequestMsg.getTEL(); params[6] = pgConRequestMsg.getBUILD_PLACE(); params[7] = pgConRequestMsg.getBUILD_TIME(); params[8] = pgConRequestMsg.getSTART_PLACE(); params[9] = pgConRequestMsg.getEND_PLACE(); params[10] = pgConRequestMsg.getPROJECT(); params[11] = pgConRequestMsg.getBUILD_CONTENT(); params[12] = pgConRequestMsg.getAPPROVER(); params[13] = pgConRequestMsg.getAPPROVER_TIME(); params[14] = pgConRequestMsg.getLOG_DATE(); paramObjectList.add(params); } try { conn = ConnectionManager.getConnectionFromC3P0(); conn.setAutoCommit(false); QueryRunner runner = new QueryRunner(); for (Object[] params:paramObjectList) { int count = runner.update(conn, insertStr, params); if (count > 0) logger.info("施工请点数据同步成功" + pgConRequestMsgList.toString()); else logger.info("施工请点数据同步失败!"); } } catch (Exception ex) { logger.info("施工请点数据同步异常", ex); } finally { try { DbUtils.commitAndClose(conn); } catch (SQLException e) { e.printStackTrace(); } } } @Override public String findLastRecordTime(){ Connection conn = null; String queryStr = "SELECT * FROM PG_CON_REQUEST_MSG ORDER BY LOG_DATE DESC"; try { conn = ConnectionManager.getConnectionFromC3P0(); conn.setAutoCommit(false); QueryRunner runner = new QueryRunner(); List<PgConRequestMsg> pgConRequestMsgList = (List<PgConRequestMsg>) runner.query(conn, queryStr, new BeanListHandler<PgConRequestMsg>(PgConRequestMsg.class)); if (null != pgConRequestMsgList && pgConRequestMsgList.isEmpty() == false) { logger.debug("获取最新施工请点记录成功[" + pgConRequestMsgList + "]"); return pgConRequestMsgList.get(0).getLOG_DATE(); } else return null; } catch (Exception ex) { logger.error("获取最新施工请点记录异常", ex); } finally { try { DbUtils.commitAndClose(conn); } catch (SQLException e) { e.printStackTrace(); } } return null; } }