| | |
| | |
|
| | | import com.base.Com;
|
| | | import com.dev.lock.data.ElectLock_AuthIdcard;
|
| | | import com.dev.lock.data.ElectLock_Bl;
|
| | | import com.dev.lock.data.ElectLock_ComBase;
|
| | | import com.dev.lock.data.ElectLock_Ctl_Log;
|
| | | import com.dev.lock.data.ElectLock_Inf;
|
| | |
| | | sql.close_con();
|
| | | }
|
| | | }
|
| | | |
| | | /**
|
| | | * 插入默认的ID卡信息
|
| | | * @param pool
|
| | | * @param client_id
|
| | | */
|
| | | public static void insertLock_IdCard_Table(MysqlConnPool pool, int lock_id) {
|
| | | String sql_str_sel = " SELECT * FROM " + Sql_Mysql.Lock_IdCard_Table + " WHERE lock_id = " + lock_id;
|
| | | String sql_str_ins = " INSERT INTO " + Sql_Mysql.Lock_IdCard_Table + "(lock_id) VALUES(" + lock_id + ");";
|
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
| | | ResultSet res = null;
|
| | | try {
|
| | | res = sql.sqlMysqlQuery(sql_str_sel);
|
| | | if(!res.next()) {
|
| | | sql.sqlMysqlExecute(sql_str_ins);
|
| | | }
|
| | | } catch (SQLException e) {
|
| | | sql.logger.error(e.toString(),e);
|
| | | } finally {
|
| | | if(null != res) {
|
| | | try {
|
| | | res.close();
|
| | | } catch (SQLException e) {
|
| | | sql.logger.error(e.toString(),e);
|
| | | }
|
| | | }
|
| | | sql.close_con();
|
| | | }
|
| | | }
|
| | | |
| | | /**
|
| | | * 插入默认的ID卡信息
|
| | | * @param pool
|
| | | * @param client_id
|
| | | */
|
| | | public static void insertLock_Rt_Table(MysqlConnPool pool, int lock_id) {
|
| | | String sql_str_sel = " SELECT * FROM " + Sql_Mysql.Lock_Rt_Table + " WHERE lock_id = " + lock_id;
|
| | | String sql_str_ins = " INSERT INTO " + Sql_Mysql.Lock_Rt_Table + "(lock_id) VALUES(" + lock_id + ");";
|
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
| | | ResultSet res = null;
|
| | | try {
|
| | | res = sql.sqlMysqlQuery(sql_str_sel);
|
| | | if(!res.next()) {
|
| | | sql.sqlMysqlExecute(sql_str_ins);
|
| | | }
|
| | | } catch (SQLException e) {
|
| | | sql.logger.error(e.toString(),e);
|
| | | } finally {
|
| | | if(null != res) {
|
| | | try {
|
| | | res.close();
|
| | | } catch (SQLException e) {
|
| | | sql.logger.error(e.toString(),e);
|
| | | }
|
| | | }
|
| | | sql.close_con();
|
| | | }
|
| | | }
|
| | | |
| | | /**
|
| | | * 更细当前锁具的ID卡
|
| | | * @param pool
|
| | | * @param client_id
|
| | | */
|
| | | public static void updateLock_IdCard_Table(MysqlConnPool pool, ElectLock_State state) {
|
| | | StringBuffer sql_str = new StringBuffer(" UPDATE " + Sql_Mysql.Lock_IdCard_Table + " SET ");
|
| | | for(int k = 0;k<state.getId_cards().length;k++) {
|
| | | if(k > 0) {
|
| | | sql_str.append(",") ;
|
| | | }
|
| | | sql_str.append("card" + (k+1) + " = '" + state.getId_cards()[k] + "'") ;
|
| | | }
|
| | | sql_str.append(" WHERE lock_id = " + state.getLock_id()) ;
|
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
| | | try {
|
| | | sql.sqlMysqlExecute(sql_str.toString());
|
| | | } catch (SQLException e) {
|
| | | sql.logger.error(e.toString(),e);
|
| | | } finally {
|
| | | sql.close_con();
|
| | | }
|
| | | } |
| | | |
| | | /**
|
| | | * 查询当前需要开启蓝牙的计划
|
| | | * @param pool
|
| | | * @param lock_id
|
| | | * @return
|
| | | */
|
| | | public static ElectLock_Bl queryBluetoothOpenPlan(MysqlConnPool pool,int lock_id) {
|
| | | ElectLock_Bl bl = null;
|
| | | String sql_str_sel = "SELECT * FROM " + Sql_Mysql.Lock_BL_Table |
| | | + " WHERE NOW() BETWEEN start_time AND DATE_ADD(start_time,INTERVAL " + ElectLock_ComBase.Lock_BluetoothCheckTimeLong + " SECOND)"
|
| | | + " and type = 1 AND lock_id = " + lock_id;
|
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
| | | ResultSet res = null;
|
| | | try {
|
| | | res = sql.sqlMysqlQuery(sql_str_sel);
|
| | | if(res.next()) {
|
| | | bl = new ElectLock_Bl();
|
| | | bl.setLock_id(lock_id);
|
| | | bl.setCreate_time(res.getTimestamp("create_time"));
|
| | | bl.setStart_time(res.getTime("start_time"));
|
| | | bl.setStop_time(res.getTime("stop_time"));
|
| | | bl.setType(res.getInt("type"));
|
| | | }
|
| | | } catch (SQLException e) {
|
| | | sql.logger.error(e.toString(),e);
|
| | | } finally {
|
| | | if(null != res) {
|
| | | try {
|
| | | res.close();
|
| | | } catch (SQLException e) {
|
| | | sql.logger.error(e.toString(),e);
|
| | | }
|
| | | }
|
| | | sql.close_con();
|
| | | }
|
| | | return bl;
|
| | | }
|
| | | |
| | | /**
|
| | | * 查询当前需要开启蓝牙的计划
|
| | | * @param pool
|
| | | * @param lock_id
|
| | | * @return
|
| | | */
|
| | | public static ElectLock_Bl queryBluetoothClosePlan(MysqlConnPool pool,int lock_id) {
|
| | | ElectLock_Bl bl = null;
|
| | | String sql_str_sel = "SELECT * FROM " + Sql_Mysql.Lock_BL_Table |
| | | + " WHERE NOW() BETWEEN stop_time AND DATE_ADD(stop_time,INTERVAL " + ElectLock_ComBase.Lock_BluetoothCheckTimeLong + " SECOND)"
|
| | | + " and type = 1 AND lock_id = " + lock_id;
|
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
| | | ResultSet res = null;
|
| | | try {
|
| | | res = sql.sqlMysqlQuery(sql_str_sel);
|
| | | if(res.next()) {
|
| | | bl = new ElectLock_Bl();
|
| | | bl.setLock_id(lock_id);
|
| | | bl.setCreate_time(res.getTimestamp("create_time"));
|
| | | bl.setStart_time(res.getTime("start_time"));
|
| | | bl.setStop_time(res.getTime("stop_time"));
|
| | | bl.setType(res.getInt("type"));
|
| | | }
|
| | | } catch (SQLException e) {
|
| | | sql.logger.error(e.toString(),e);
|
| | | } finally {
|
| | | if(null != res) {
|
| | | try {
|
| | | res.close();
|
| | | } catch (SQLException e) {
|
| | | sql.logger.error(e.toString(),e);
|
| | | }
|
| | | }
|
| | | sql.close_con();
|
| | | }
|
| | | return bl;
|
| | | }
|
| | | |
| | | }
|