| | |
| | |
|
| | | 设备ID:10000001
|
| | |
|
| | | |
| | | V1.110 edit by lijun 2025-01-20
|
| | | 1.新增锁具告警记录功能
|
| | | 2.新增触发告警 - |
| | | 通信故障告警
|
| | | 开锁失败
|
| | | 记录每年月季度的开锁次数,以及每年锁具状态变化记录
|
| | | |
| | | |
| | | V1.109 edit by lijun 2025-01-15
|
| | | 1.通信协议新增读取电子锁蓝牙MAC地址数据
|
| | |
|
| | |
| | | public static final String DTFYMD = "yyyyMMdd";
|
| | | public static final String DTF_hms = "HH:mm:ss";
|
| | | final public static String DTF_YM = "yyyy_MM";
|
| | | final public static String DTF_Y = "yyyy";
|
| | | public static final String DTF_YMD_h_m_s = "yyyy-MM-dd+HH_mm_ss";
|
| | |
|
| | | public static String getDateTimeFormat(Date dt, String format) {
|
| | |
| | | if(SocketComm(mRtu_Tx, ByteBuffer.allocate(0))) {
|
| | | Lock_Task_SQL.updateLock_Rt_Table(pool,client_id,mLock_State);
|
| | |
|
| | | Lock_Task_SQL.updateLock_Inf_Table(pool,client_id,mLock_State);
|
| | | Lock_Task_SQL.updateLock_Inf_Table(pool,ele_lock,mLock_State);
|
| | | |
| | | //更新锁具状态
|
| | | ele_lock.lockRecordState.setLockState(mLock_State);
|
| | |
|
| | | if(mLock_State.isIDOpen()) {
|
| | | String ctl_uname = Lock_Task_SQL.queryKeyInfByKeyNumberTable(pool,mLock_State.getLast_unlock_id());
|
| | |
| | | } finally {
|
| | | logger.info("设备断开连接:DevIp:" + client_ip + " DevId:" + mLock_State.getLockDevId());
|
| | | mLock_State.setLock_online(0);
|
| | | Lock_Task_SQL.updateLock_Inf_Table(pool,client_id,mLock_State);
|
| | | Lock_Task_SQL.updateLock_Inf_Table(pool,ele_lock,mLock_State);
|
| | | }
|
| | |
|
| | | if(null != tmp_socket) {
|
| | |
| | | import com.dev.lock.data.ElectLock_AuthIdcard;
|
| | | import com.dev.lock.data.ElectLock_ComBase;
|
| | | import com.dev.lock.data.ElectLock_Ctl_Log;
|
| | | import com.dev.lock.data.ElectLock_Inf;
|
| | | import com.dev.lock.data.ElectLock_Report;
|
| | | import com.dev.lock.data.ElectLock_State;
|
| | | import com.sql.MysqlConnPool;
|
| | | import com.sql.Sql_Mysql;
|
| | |
| | | * @param lock_id
|
| | | * @param state
|
| | | */
|
| | | public static void updateLock_Inf_Table(MysqlConnPool pool,int lock_id,ElectLock_State state) {
|
| | | public static void updateLock_Inf_Table(MysqlConnPool pool,ElectLock_Inf inf,ElectLock_State state) {
|
| | | String sql_str = "UPDATE " + Sql_Mysql.Lock_Inf_Table +
|
| | | " Set lock_state = " + state.getLock_state() +
|
| | | " ,lock_online = " + state.getLock_online() +
|
| | | " ,lock_mac = '" + state.getLockMacAddr() + "'" +
|
| | | " ,last_update_time = NOW() " +
|
| | | " WHERE lock_id = " + lock_id;
|
| | | " ,last_update_time = '" + Com.getDateTimeFormat(inf.getLast_update_time(), Com.DTF_YMDhms) + "'" +
|
| | | " WHERE lock_id = " + inf.getLock_id();
|
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
| | | try {
|
| | | sql.sqlMysqlExecute(sql_str);
|
| | |
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
| | | ResultSet res = null;
|
| | | try {
|
| | | System.out.println("====="+sql_str);
|
| | | //System.out.println("====="+sql_str);
|
| | | res = sql.sqlMysqlQuery(sql_str);
|
| | | if(res.next()) {
|
| | | uname = res.getString("uname");
|
| | | System.out.println("uname:" + uname);
|
| | | //System.out.println("uname:" + uname);
|
| | | }
|
| | | } catch (SQLException e) {
|
| | | sql.logger.error(e.toString(),e);
|
| | |
| | | }
|
| | | return uname;
|
| | | }
|
| | |
|
| | |
|
| | | public static void updateProcess_StartTime(MysqlConnPool pool, double mVersionnum) {
|
| | | String sql_str = "UPDATE " + Sql_Mysql.Process_Survey_Table + |
| | | " Set Process_starttime = NOW() " +
|
| | | " ,ProcessTime = NOW() " + |
| | | " ,ProcessVersion = 'V" + mVersionnum + "'"+
|
| | | " WHERE ProcessId = 11001";
|
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
| | | try {
|
| | | sql.sqlMysqlExecute(sql_str);
|
| | | } catch (SQLException e) {
|
| | | sql.logger.error(e.toString(),e);
|
| | | } finally {
|
| | | sql.close_con();
|
| | | }
|
| | | }
|
| | | |
| | | public static void updateProcess_ProcessTime(MysqlConnPool pool) {
|
| | | String sql_str = "UPDATE " + Sql_Mysql.Process_Survey_Table + |
| | | " Set ProcessTime = NOW() " + |
| | | " WHERE ProcessId = 11001";
|
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
| | | try {
|
| | | sql.sqlMysqlExecute(sql_str);
|
| | | } catch (SQLException e) {
|
| | | sql.logger.error(e.toString(),e);
|
| | | } finally {
|
| | | sql.close_con();
|
| | | }
|
| | | }
|
| | | |
| | | public static void queryLock_Rt_TableByLockId(MysqlConnPool pool,int lock_id,ElectLock_State state) {
|
| | | String sql_str = " SELECT * FROM " + Sql_Mysql.Lock_Rt_Table + " WHERE lock_id = " + lock_id;
|
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
| | | ResultSet res = null;
|
| | | try {
|
| | | res = sql.sqlMysqlQuery(sql_str);
|
| | | if(res.next()) {
|
| | | state.setGprs_sn(res.getString("gprs_sn")); //'gprs模块SN码',
|
| | | state.setClient_ip(res.getString("client_ip")); //'设备IP地址',
|
| | | state.setAlready_id_count(res.getInt("already_id_count")); //'当前锁已授权卡数量',
|
| | | state.setMax_id_count(res.getInt("max_id_count")); //'授权卡数量存储上限',
|
| | | state.setLock_state(res.getInt("lock_state")); //'电子锁状态[0-关 1-开]',
|
| | | state.setLock_version(res.getString("lock_version")); //'软件版本号',
|
| | | state.setUnlock_type(res.getInt("unlock_type")); //'上一次开锁方式[0-485开锁 1-刷卡开锁 2-蓝牙开锁 3-DI开锁]',
|
| | | state.setUnlock_id(res.getInt("unlock_id")); //'上一次刷开开锁卡号[仅刷开开锁时有效]',
|
| | | state.setLock_addr(res.getInt("lock_addr")); //'设备地址',
|
| | | state.setComm_count(res.getInt("comm_count")); //'通信计数',
|
| | | state.setErr_tol_count(res.getInt("err_tol_count")); //'总错误计数',
|
| | | // state.setErr_count(res.getInt("err_count")); //'连续错误计数',
|
| | | state.setOp_cmd(res.getInt("op_cmd")); //'控制命令',
|
| | | state.setId_card_set(res.getInt("id_card_set")); //'授权ID卡号',
|
| | | state.setLock_addr_set(res.getInt("lock_addr_set"));; //'设置设备地址[慎用]',
|
| | | |
| | | }
|
| | | } 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();
|
| | | }
|
| | | |
| | | }
|
| | | |
| | | public static void queryLock_Report_TableByLockId(MysqlConnPool pool,int lock_id,ElectLock_Report state,int now_year) {
|
| | | String sql_str = " SELECT * FROM " + Sql_Mysql.Lock_Report_Table + " WHERE lock_id = " + lock_id + " AND record_year = " + now_year;
|
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
| | | ResultSet res = null;
|
| | | try {
|
| | | res = sql.sqlMysqlQuery(sql_str);
|
| | | if(res.next()) {
|
| | | |
| | | state.record_year = res.getInt("record_year"); //统计年份',
|
| | | state.month1 = res.getInt("month1"); //1月开锁次数',
|
| | | state.month2 = res.getInt("month2"); //2月开锁次数',
|
| | | state.month3 = res.getInt("month3"); //3月开锁次数',
|
| | | state.month4 = res.getInt("month4"); //4月开锁次数',
|
| | | state.month5 = res.getInt("month5"); //5月开锁次数',
|
| | | state.month6 = res.getInt("month6"); //6月开锁次数',
|
| | | state.month7 = res.getInt("month7"); //7月开锁次数',
|
| | | state.month8 = res.getInt("month8"); //8月开锁次数',
|
| | | state.month9 = res.getInt("month9"); //9月开锁次数',
|
| | | state.month10 = res.getInt("month10"); //10月开锁次数',
|
| | | state.month11 = res.getInt("month11"); //11月开锁次数',
|
| | | state.month12 = res.getInt("month12"); //12月开锁次数',
|
| | | state.quarter1 = res.getInt("quarter1"); //第一季度开锁次数',
|
| | | state.quarter2 = res.getInt("quarter2"); //第二季度开锁次数',
|
| | | state.quarter3 = res.getInt("quarter3"); //第三季度开锁次数',
|
| | | state.quarter4 = res.getInt("quarter4"); //第四季度开锁次数',
|
| | | state.year_count = res.getInt("year_count"); //本年开锁次数',
|
| | | }
|
| | | } 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();
|
| | | }
|
| | | |
| | | }
|
| | | }
|
| | |
| | |
|
| | | import java.sql.ResultSet;
|
| | | import java.sql.SQLException;
|
| | | import java.time.Year;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | | import com.dev.lock.comm.Lock_Task_SQL;
|
| | | import com.sql.MysqlConnPool;
|
| | | import com.sql.Sql_Mysql;
|
| | |
|
| | |
| | | ResultSet res = null;
|
| | | boolean isChange = false;
|
| | | try {
|
| | | int nowYear = Year.now().getValue();
|
| | | |
| | | res = sql.sqlMysqlQuery(sql_str);
|
| | | while(res.next()) {
|
| | | int lock_id = res.getInt("lock_id");
|
| | |
| | | String lock_address = res.getString("lock_address"); //'锁地址',
|
| | | String lock_path = res.getString("lock_path"); //'图片路径',
|
| | | String lock_ip = res.getString("lock_ip").trim(); //'电子锁IP地址[内网可通过IP地址识别设备]',
|
| | | |
| | | Date lastUpdateTime = res.getTimestamp("last_update_time");
|
| | | int open_count = res.getInt("lock_open_count");
|
| | |
|
| | | boolean isexist = false;
|
| | | for(int k = 0 ;k<mInfs.size();k++) {
|
| | |
| | | if(isexist) {
|
| | | continue;
|
| | | } else {
|
| | | ElectLock_Inf tmp_lock = new ElectLock_Inf();
|
| | | ElectLock_Inf tmp_lock = new ElectLock_Inf(pool);
|
| | | tmp_lock.setLock_id(lock_id);
|
| | | tmp_lock.setArea_id(area_id); //'区域id',
|
| | | tmp_lock.setLock_name(lock_name); //'锁名称',
|
| | |
| | | tmp_lock.setLock_address(lock_address); //'锁地址',
|
| | | tmp_lock.setLock_path(lock_path); //'图片路径',
|
| | | tmp_lock.setLock_ip(lock_ip);; //'电子锁IP地址[内网可通过IP地址识别设备]',
|
| | | |
| | | tmp_lock.setLast_update_time(lastUpdateTime); //上一次锁具状态更新时间
|
| | | tmp_lock.setLock_open_count(open_count); //锁具开启次数
|
| | | |
| | | Lock_Task_SQL.queryLock_Rt_TableByLockId(pool, lock_id, tmp_lock.lockState);
|
| | | Lock_Task_SQL.queryLock_Report_TableByLockId(pool, lock_id, tmp_lock.lockReport, nowYear);
|
| | | |
| | | mInfs.add(tmp_lock);
|
| | | }
|
| | |
|
| | |
| | | package com.dev.lock.data;
|
| | |
|
| | | import java.util.Date;
|
| | |
|
| | | import com.dev.lock.history.InsertDataToMysql_Task;
|
| | | import com.sql.MysqlConnPool;
|
| | |
|
| | | public class ElectLock_Inf {
|
| | | |
| | | private boolean StoreDataBusy = false;
|
| | |
|
| | | private int area_id; //'区域id',
|
| | | private String lock_name; //'锁名称',
|
| | |
| | | private String lock_ip; //'电子锁IP地址[内网可通过IP地址识别设备]',
|
| | | private int lock_id; //电子锁ID
|
| | |
|
| | | public ElectLock_State lockState;
|
| | | private int lock_open_count; //'锁具开启次数'
|
| | | private Date last_update_time; //上一次锁具开启或关闭时间
|
| | |
|
| | | public ElectLock_Inf() {
|
| | | public ElectLock_State lockState;
|
| | | public ElectLock_Report lockReport;
|
| | | public ElectLock_RecordState lockRecordState;
|
| | |
|
| | | public InsertDataToMysql_Task mSqlTask;
|
| | | |
| | | public ElectLock_Inf(MysqlConnPool pool) {
|
| | | lockState = new ElectLock_State();
|
| | | lockReport = new ElectLock_Report();
|
| | | lockRecordState = new ElectLock_RecordState();
|
| | | |
| | | mSqlTask = new InsertDataToMysql_Task(this, pool);
|
| | | }
|
| | | |
| | | public boolean checkIfDataNeedStore() {
|
| | | boolean store_state = false;
|
| | | |
| | | if(true == getStoreDataBusyTag()) {
|
| | | //上一次记录数据还没结束
|
| | | store_state = false;
|
| | | } else {
|
| | | store_state = lockRecordState.checkIfDataNeedStore();
|
| | | if(true == store_state) {
|
| | | setStoreDataBusyTag();
|
| | | }
|
| | | }
|
| | | return store_state;
|
| | | }
|
| | |
|
| | | public int getArea_id() {
|
| | |
| | |
|
| | | public void setLock_id(int lock_id) {
|
| | | this.lock_id = lock_id;
|
| | | lockReport.lock_id = lock_id;
|
| | | }
|
| | |
|
| | | public void setLockState(ElectLock_State lockState) {
|
| | | this.lockState = lockState;
|
| | | }
|
| | | |
| | |
|
| | | public int getLock_open_count() {
|
| | | return lock_open_count;
|
| | | }
|
| | |
|
| | | public Date getLast_update_time() {
|
| | | return last_update_time;
|
| | | }
|
| | |
|
| | | public void setLock_open_count(int lock_open_count) {
|
| | | this.lock_open_count = lock_open_count;
|
| | | }
|
| | |
|
| | | public void setLast_update_time(Date last_update_time) {
|
| | | this.last_update_time = last_update_time;
|
| | | }
|
| | |
|
| | | public void clearStoreDataBusyTag()
|
| | | {
|
| | | StoreDataBusy = false;
|
| | | }
|
| | | private boolean getStoreDataBusyTag()
|
| | | {
|
| | | return StoreDataBusy;
|
| | | }
|
| | | private void setStoreDataBusyTag()
|
| | | {
|
| | | StoreDataBusy = true;
|
| | | }
|
| | |
|
| | |
|
| | | }
|
New file |
| | |
| | | package com.dev.lock.data;
|
| | |
|
| | | import java.util.Date;
|
| | |
|
| | | /**
|
| | | * |
| | | */
|
| | | public class ElectLock_RecordState {
|
| | | |
| | | public static final int Lock_State_Close = 0; //锁具状态-关
|
| | | public static final int Lock_State_Open = 1; //锁具状态-开
|
| | | |
| | | public boolean isNeedRecord = false; //是否需要记录历史数据
|
| | |
|
| | | public Date record_time; //'记录时间',
|
| | | |
| | | public int lock_state; //'锁具状态[0-闭锁 1-开锁]',
|
| | | public int unlock_type; //'上一次开锁方式[0-485开锁 1-刷卡开锁 2-蓝牙开锁 3-DI开锁]',
|
| | | public int unlock_id; //'上一次刷开开锁卡号[仅刷ID卡开锁时有效]',
|
| | | |
| | | public int last_lock_state; //上一次锁具状态
|
| | | |
| | | public ElectLock_RecordState(){
|
| | | |
| | | }
|
| | | |
| | | public ElectLock_RecordState clone() {
|
| | | ElectLock_RecordState state = new ElectLock_RecordState();
|
| | | state.isNeedRecord = false; //是否需要记录历史数据
|
| | |
|
| | | state.record_time = new Date(this.record_time.getTime()); //'记录时间',
|
| | | |
| | | state.lock_state = this.lock_state; //'锁具状态[0-闭锁 1-开锁]',
|
| | | state.unlock_type = this.unlock_type; //'上一次开锁方式[0-485开锁 1-刷卡开锁 2-蓝牙开锁 3-DI开锁]',
|
| | | state.unlock_id = this.unlock_id; //'上一次刷开开锁卡号[仅刷ID卡开锁时有效]',
|
| | | state.last_lock_state = this.last_lock_state; //上一次锁具状态
|
| | | return state;
|
| | | }
|
| | | |
| | | public void calNewOpenEvent() {
|
| | | |
| | | |
| | | }
|
| | | |
| | | |
| | | |
| | | |
| | | /**
|
| | | * 更新当前锁具状态
|
| | | * @param state
|
| | | */
|
| | | public void setLockState(ElectLock_State state) {
|
| | | |
| | | this.lock_state = state.getLock_state();
|
| | | this.unlock_type = state.getUnlock_type();
|
| | | this.unlock_id = state.getUnlock_id();
|
| | | |
| | | |
| | | }
|
| | |
|
| | | public boolean checkIfDataNeedStore() {
|
| | | if(last_lock_state != lock_state) {
|
| | | //状态变化时间
|
| | | record_time = new Date();
|
| | | isNeedRecord = true;
|
| | | }else {
|
| | | isNeedRecord = false;
|
| | | }
|
| | | return isNeedRecord;
|
| | | }
|
| | |
|
| | | |
| | | /**
|
| | | * 记录数据完成
|
| | | */
|
| | | public void RecordHisOK() {
|
| | | this.last_lock_state = this.lock_state;
|
| | | }
|
| | | |
| | | |
| | | }
|
New file |
| | |
| | | package com.dev.lock.data;
|
| | |
|
| | | import java.util.Calendar;
|
| | | import java.util.Date;
|
| | | import java.util.GregorianCalendar;
|
| | |
|
| | | import com.base.Com;
|
| | |
|
| | | public class ElectLock_Report {
|
| | | |
| | | public int lock_id; //锁具ID号',
|
| | | public int record_year; //统计年份',
|
| | | public int month1; //1月开锁次数',
|
| | | public int month2; //2月开锁次数',
|
| | | public int month3; //3月开锁次数',
|
| | | public int month4; //4月开锁次数',
|
| | | public int month5; //5月开锁次数',
|
| | | public int month6; //6月开锁次数',
|
| | | public int month7; //7月开锁次数',
|
| | | public int month8; //8月开锁次数',
|
| | | public int month9; //9月开锁次数',
|
| | | public int month10; //10月开锁次数',
|
| | | public int month11; //11月开锁次数',
|
| | | public int month12; //12月开锁次数',
|
| | | public int quarter1; //第一季度开锁次数',
|
| | | public int quarter2; //第二季度开锁次数',
|
| | | public int quarter3; //第三季度开锁次数',
|
| | | public int quarter4; //第四季度开锁次数',
|
| | | public int year_count; //本年开锁次数',
|
| | | |
| | | public void initNewYear(int nowYear) {
|
| | | this.record_year = nowYear; //统计年份',
|
| | | this.month1 = 0; //1月开锁次数',
|
| | | this.month2 = 0; //2月开锁次数',
|
| | | this.month3 = 0; //3月开锁次数',
|
| | | this.month4 = 0; //4月开锁次数',
|
| | | this.month5 = 0; //5月开锁次数',
|
| | | this.month6 = 0; //6月开锁次数',
|
| | | this.month7 = 0; //7月开锁次数',
|
| | | this.month8 = 0; //8月开锁次数',
|
| | | this.month9 = 0; //9月开锁次数',
|
| | | this.month10 = 0; //10月开锁次数',
|
| | | this.month11 = 0; //11月开锁次数',
|
| | | this.month12 = 0; //12月开锁次数',
|
| | | this.quarter1 = 0; //第一季度开锁次数',
|
| | | this.quarter2 = 0; //第二季度开锁次数',
|
| | | this.quarter3 = 0; //第三季度开锁次数',
|
| | | this.quarter4 = 0; //第四季度开锁次数',
|
| | | this.year_count = 0; //本年开锁次数',
|
| | | }
|
| | | |
| | | public ElectLock_Report clone() {
|
| | | |
| | | ElectLock_Report temp = new ElectLock_Report();
|
| | | temp.record_year = this.record_year; //统计年份',
|
| | | temp.month1 = this.month1; //1月开锁次数',
|
| | | temp.month2 = this.month2; //2月开锁次数',
|
| | | temp.month3 = this.month3; //3月开锁次数',
|
| | | temp.month4 = this.month4; //4月开锁次数',
|
| | | temp.month5 = this.month5; //5月开锁次数',
|
| | | temp.month6 = this.month6; //6月开锁次数',
|
| | | temp.month7 = this.month7; //7月开锁次数',
|
| | | temp.month8 = this.month8; //8月开锁次数',
|
| | | temp.month9 = this.month9; //9月开锁次数',
|
| | | temp.month10 = this.month10; //10月开锁次数',
|
| | | temp.month11 = this.month11; //11月开锁次数',
|
| | | temp.month12 = this.month12; //12月开锁次数',
|
| | | temp.quarter1 = this.quarter1; //第一季度开锁次数',
|
| | | temp.quarter2 = this.quarter2; //第二季度开锁次数',
|
| | | temp.quarter3 = this.quarter3; //第三季度开锁次数',
|
| | | temp.quarter4 = this.quarter4; //第四季度开锁次数',
|
| | | temp.year_count = this.year_count; //本年开锁次数',
|
| | | return temp;
|
| | | }
|
| | | |
| | | public void calNewOpenEvent(Date time) {
|
| | | //统计当前事件数据信息
|
| | | Calendar calendar = new GregorianCalendar();
|
| | | calendar.setTime(time);
|
| | |
|
| | | // 你还可以从Calendar对象中获取年、月、日等信息
|
| | | int year = calendar.get(Calendar.YEAR); //年份
|
| | | int month = calendar.get(Calendar.MONTH) + 1; //月份从0开始,所以加1
|
| | | |
| | | this.record_year = year;
|
| | | switch(month) {
|
| | | case 1:{
|
| | | this.month1 ++;
|
| | | this.quarter1 ++;
|
| | | }break;
|
| | | case 2:{
|
| | | this.month2 ++;
|
| | | this.quarter1 ++;
|
| | | }break;
|
| | | case 3:{
|
| | | this.month3 ++;
|
| | | this.quarter1 ++;
|
| | | }break;
|
| | | case 4:{
|
| | | this.month4 ++;
|
| | | this.quarter2 ++;
|
| | | }break;
|
| | | case 5:{
|
| | | this.month5 ++;
|
| | | this.quarter2 ++;
|
| | | }break;
|
| | | case 6:{
|
| | | this.month6 ++;
|
| | | this.quarter2 ++;
|
| | | }break;
|
| | | case 7:{
|
| | | this.month7 ++;
|
| | | this.quarter3 ++;
|
| | | }break;
|
| | | case 8:{
|
| | | this.month8 ++;
|
| | | this.quarter3 ++;
|
| | | }break;
|
| | | case 9:{
|
| | | this.month9 ++;
|
| | | this.quarter3 ++;
|
| | | }break;
|
| | | case 10:{
|
| | | this.month10 ++;
|
| | | this.quarter4 ++;
|
| | | }break;
|
| | | case 11:{
|
| | | this.month11 ++;
|
| | | this.quarter4 ++;
|
| | | }break;
|
| | | case 12:{
|
| | | this.month12 ++;
|
| | | this.quarter4 ++;
|
| | | }break;
|
| | | }
|
| | | this.year_count ++;
|
| | | }
|
| | | |
| | | public int getLock_id() {
|
| | | return lock_id;
|
| | | }
|
| | | public int getRecord_year() {
|
| | | return record_year;
|
| | | }
|
| | | public int getMonth1() {
|
| | | return month1;
|
| | | }
|
| | | public int getMonth2() {
|
| | | return month2;
|
| | | }
|
| | | public int getMonth3() {
|
| | | return month3;
|
| | | }
|
| | | public int getMonth4() {
|
| | | return month4;
|
| | | }
|
| | | public int getMonth5() {
|
| | | return month5;
|
| | | }
|
| | | public int getMonth6() {
|
| | | return month6;
|
| | | }
|
| | | public int getMonth7() {
|
| | | return month7;
|
| | | }
|
| | | public int getMonth8() {
|
| | | return month8;
|
| | | }
|
| | | public int getMonth9() {
|
| | | return month9;
|
| | | }
|
| | | public int getMonth10() {
|
| | | return month10;
|
| | | }
|
| | | public int getMonth11() {
|
| | | return month11;
|
| | | }
|
| | | public int getMonth12() {
|
| | | return month12;
|
| | | }
|
| | | public int getQuarter1() {
|
| | | return quarter1;
|
| | | }
|
| | | public int getQuarter2() {
|
| | | return quarter2;
|
| | | }
|
| | | public int getQuarter3() {
|
| | | return quarter3;
|
| | | }
|
| | | public int getQuarter4() {
|
| | | return quarter4;
|
| | | }
|
| | | public int getYear_count() {
|
| | | return year_count;
|
| | | }
|
| | | public void setLock_id(int lock_id) {
|
| | | this.lock_id = lock_id;
|
| | | }
|
| | | public void setRecord_year(int record_year) {
|
| | | this.record_year = record_year;
|
| | | }
|
| | | public void setMonth1(int month1) {
|
| | | this.month1 = month1;
|
| | | }
|
| | | public void setMonth2(int month2) {
|
| | | this.month2 = month2;
|
| | | }
|
| | | public void setMonth3(int month3) {
|
| | | this.month3 = month3;
|
| | | }
|
| | | public void setMonth4(int month4) {
|
| | | this.month4 = month4;
|
| | | }
|
| | | public void setMonth5(int month5) {
|
| | | this.month5 = month5;
|
| | | }
|
| | | public void setMonth6(int month6) {
|
| | | this.month6 = month6;
|
| | | }
|
| | | public void setMonth7(int month7) {
|
| | | this.month7 = month7;
|
| | | }
|
| | | public void setMonth8(int month8) {
|
| | | this.month8 = month8;
|
| | | }
|
| | | public void setMonth9(int month9) {
|
| | | this.month9 = month9;
|
| | | }
|
| | | public void setMonth10(int month10) {
|
| | | this.month10 = month10;
|
| | | }
|
| | | public void setMonth11(int month11) {
|
| | | this.month11 = month11;
|
| | | }
|
| | | public void setMonth12(int month12) {
|
| | | this.month12 = month12;
|
| | | }
|
| | | public void setQuarter1(int quarter1) {
|
| | | this.quarter1 = quarter1;
|
| | | }
|
| | | public void setQuarter2(int quarter2) {
|
| | | this.quarter2 = quarter2;
|
| | | }
|
| | | public void setQuarter3(int quarter3) {
|
| | | this.quarter3 = quarter3;
|
| | | }
|
| | | public void setQuarter4(int quarter4) {
|
| | | this.quarter4 = quarter4;
|
| | | }
|
| | | public void setYear_count(int year_count) {
|
| | | this.year_count = year_count;
|
| | | }
|
| | |
|
| | | |
| | | |
| | | public static void main(String[] args) {
|
| | | Date time = new Date();
|
| | | System.out.println(Com.getDateTimeFormat(time, Com.DTF_YMDhms) + "===" + "-" + (time.getMonth()+1));
|
| | | }
|
| | | |
| | | }
|
| | |
| | | // public static int Reg_Count_Real = 8; //寄存器数量
|
| | | public static int Reg_Count_Real = 11; //寄存器数量
|
| | |
|
| | | private Date record_time; //'更新时间',
|
| | | private Date record_time = new Date(0); //'更新时间',
|
| | | private String gprs_sn; //'gprs模块SN码',
|
| | | private String client_ip; //'设备IP地址',
|
| | | private int already_id_count; //'当前锁已授权卡数量',
|
| | |
| | | private int[] mac_addr = new int[6]; //锁具蓝牙MAC地址
|
| | |
|
| | | private String ctl_uname = ""; //操作用户名
|
| | | |
| | | private boolean StoreDataBusy = false;
|
| | |
|
| | | public ElectLock_State() {
|
| | |
|
| | |
| | | last_unlock_id = unlock_id; //'上一次刷开开锁卡号[仅刷开开锁时有效]',
|
| | | }
|
| | | }
|
| | | |
| | | record_time = new Date();
|
| | | buffer.compact();
|
| | | return true;
|
| | | }
|
| | |
| | | }
|
| | | err_count++;
|
| | | }
|
| | |
|
| | |
|
| | | @Override
|
| | | public String toString() {
|
New file |
| | |
| | | package com.dev.lock.history;
|
| | |
|
| | | import java.time.Year;
|
| | | import java.util.Calendar;
|
| | | import java.util.Date;
|
| | | import java.util.Timer;
|
| | | import java.util.concurrent.ExecutorService;
|
| | | import java.util.concurrent.Executors;
|
| | | import org.apache.logging.log4j.LogManager;
|
| | | import org.apache.logging.log4j.Logger;
|
| | |
|
| | | import com.dev.lock.data.ElectLock_Array;
|
| | | import com.dev.lock.data.ElectLock_Inf;
|
| | | import com.sql.MysqlConnPool;
|
| | |
|
| | | /**
|
| | | * 蓝牙电子锁历史数据记录线程
|
| | | * @author DELL
|
| | | *
|
| | | */
|
| | | public class ElectLock_HistoryData_Record_Thread extends Thread{
|
| | | |
| | | private ExecutorService m_WorkThreadPool; |
| | | private ElectLock_Array m_Data;
|
| | | private int WorkThreadCountMax = 100;
|
| | | private MysqlConnPool pool;
|
| | | private Logger logger = null;
|
| | | private static final int MaxRecordTime = 5*365; //日志记录分表最多记录5年数据
|
| | | |
| | | public ElectLock_HistoryData_Record_Thread(ElectLock_Array m_Data,MysqlConnPool pool){
|
| | | this.m_Data = m_Data;
|
| | | |
| | | this.pool = pool;
|
| | | this.logger = LogManager.getLogger(this.getClass());
|
| | | |
| | | this.m_WorkThreadPool = Executors.newFixedThreadPool(WorkThreadCountMax);
|
| | | }
|
| | | //-----------------------------------------------------------------------------//
|
| | | @Override
|
| | | public void run() {
|
| | | logger.warn("ElectLock_HistoryData_Record_Thread Started By TimerTask ...");
|
| | |
|
| | | Date now = new Date();
|
| | | //查询今年的通信信息
|
| | | for(int n=0; n<m_Data.getIteamCount(); n++) {
|
| | | ElectLock_Inf rt_data = m_Data.getIteam(n);
|
| | | //查询当前设备今年的统计结果
|
| | | ElectLock_HistoryData_Task_SQL.insertNowElectReport(pool,rt_data,now);
|
| | | }
|
| | | |
| | | Timer timer = new Timer();
|
| | | MyBattTestTask myTask1 = new MyBattTestTask(); |
| | | timer.scheduleAtFixedRate(myTask1, 1000, 1000); //任务 1秒后开始进行重复的固定速率执行(1秒钟重复一次)
|
| | | |
| | | int lastYear = 0;
|
| | | |
| | | //上一次删除历史操作记录表
|
| | | Date lastDelTime = new Date(0);
|
| | | while(true)
|
| | | {
|
| | | try {
|
| | | |
| | | sleep(500);
|
| | |
|
| | | now = new Date();
|
| | | int nowYear = Year.now().getValue();
|
| | | |
| | | if(lastYear != nowYear) {
|
| | | //年份更换,需创建指定的年份表
|
| | | for(int n=0; n<m_Data.getIteamCount(); n++) {
|
| | | ElectLock_Inf rt_data = m_Data.getIteam(n);
|
| | | //
|
| | | rt_data.lockReport.initNewYear(nowYear);
|
| | | |
| | | ElectLock_HistoryData_Task_SQL.insertDefaultLock_Report_Table(pool, rt_data.getLock_id(), nowYear);
|
| | | |
| | | ElectLock_HistoryData_Task_SQL.createLockHistTable(pool,rt_data.getLock_id(),nowYear);
|
| | | |
| | | sleep(10);
|
| | | }
|
| | | lastYear = nowYear;
|
| | | }
|
| | | |
| | | long deltimelong = (now.getTime() - lastDelTime.getTime())/1000;
|
| | | if(deltimelong > (60*60*24*MaxRecordTime)) {
|
| | | //监测分表中的超时记录
|
| | | Date delTime = getDateBefore(now, MaxRecordTime);
|
| | | ElectLock_HistoryData_Task_SQL.deleteHistoryData(pool, delTime);
|
| | | //logger.error("删除结束。。。。。。");
|
| | | |
| | | lastDelTime = now;
|
| | | |
| | | }
|
| | | |
| | | //logger.trace("BattDataTestPro_Thread m_BattTestState.getFreeStatCount():" + m_BattTestState.getFreeStatCount());
|
| | | } catch (Exception e) {
|
| | | logger.error(e.toString(),e);
|
| | | }
|
| | | }
|
| | | }
|
| | | |
| | | class MyBattTestTask extends java.util.TimerTask{
|
| | | String info = " MyBattTestTask By TimerTask ";
|
| | | |
| | | @Override
|
| | | public void run() {
|
| | | try {
|
| | | //当前时间
|
| | | Date now = new Date();
|
| | | |
| | | for(int n=0; n<m_Data.getIteamCount(); n++) {
|
| | | ElectLock_Inf rt_data = m_Data.getIteam(n);
|
| | | |
| | | boolean need_to_store = rt_data.checkIfDataNeedStore();
|
| | | |
| | | if((rt_data.getLockState().getRecord_time().getTime()+60000) < now.getTime()) {
|
| | | //设备掉线设备暂时不记录当前状态变化
|
| | | rt_data.clearStoreDataBusyTag(); //此处必须释放数据库存储busy标志.
|
| | | continue;
|
| | | }
|
| | | |
| | | if(true == need_to_store)
|
| | | {
|
| | | m_WorkThreadPool.execute(rt_data.mSqlTask);
|
| | | } else {
|
| | | rt_data.clearStoreDataBusyTag();
|
| | | }
|
| | | }
|
| | | } catch (Exception e) {
|
| | | logger.error(e.toString(), e);
|
| | | }
|
| | | }
|
| | | |
| | | public String getInfo(){
|
| | | return info; |
| | | } |
| | | public void setInfo(String info){
|
| | | this.info = info; |
| | | }
|
| | | }
|
| | | |
| | | |
| | | /**
|
| | | * 获取指定时间之前指定天数的时间
|
| | | * @param d
|
| | | * @param day
|
| | | * @return
|
| | | */
|
| | | public static Date getDateBefore(Date d,int day){
|
| | | Calendar now =Calendar.getInstance();
|
| | | now.setTime(d);
|
| | | now.set(Calendar.DATE,now.get(Calendar.DATE)-day);
|
| | | return now.getTime();
|
| | | }
|
| | | }
|
New file |
| | |
| | | package com.dev.lock.history;
|
| | |
|
| | | import java.sql.ResultSet;
|
| | | import java.sql.SQLException;
|
| | | import java.util.Date;
|
| | |
|
| | | import com.base.Com;
|
| | | import com.dev.lock.data.ElectLock_Inf;
|
| | | import com.sql.MysqlConnPool;
|
| | | import com.sql.Sql_Mysql;
|
| | |
|
| | | public class ElectLock_HistoryData_Task_SQL {
|
| | |
|
| | | /**
|
| | | * 插入或者查询今年的统计信息
|
| | | * @param pool
|
| | | * @param rt_data
|
| | | */
|
| | | public static void insertNowElectReport(MysqlConnPool pool, ElectLock_Inf rt_data,Date now) {
|
| | | String sql_str_sel = "SELECT record_year,month1,month2,month3,month4,month5,month6, " + |
| | | " month7,month8,month9,month10,month11,month12,quarter1,quarter2,quarter3,quarter4,year_count " + |
| | | " FROM " + Sql_Mysql.Lock_Report_Table + |
| | | " WHERE lock_id = " + rt_data.getLock_id() + " AND record_year = " + Com.getDateTimeFormat(now, Com.DTF_Y);
|
| | | String sql_str_ins = "INSERT INTO " + Sql_Mysql.Lock_Report_Table + "(lock_id,record_year) VALUES(" + rt_data.getLock_id() + "," + Com.getDateTimeFormat(now, Com.DTF_Y) + ");";
|
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
| | | ResultSet res = null;
|
| | | try {
|
| | | res = sql.sqlMysqlQuery(sql_str_sel);
|
| | | if(res.next()) {
|
| | | //读取今年的统计数据
|
| | | rt_data.lockReport.month1 = res.getInt("month1"); //1月开锁次数',
|
| | | rt_data.lockReport.month2 = res.getInt("month2"); //2月开锁次数',
|
| | | rt_data.lockReport.month3 = res.getInt("month3"); //3月开锁次数',
|
| | | rt_data.lockReport.month4 = res.getInt("month4"); //4月开锁次数',
|
| | | rt_data.lockReport.month5 = res.getInt("month5"); //5月开锁次数',
|
| | | rt_data.lockReport.month6 = res.getInt("month6"); //6月开锁次数',
|
| | | rt_data.lockReport.month7 = res.getInt("month7"); //7月开锁次数',
|
| | | rt_data.lockReport.month8 = res.getInt("month8"); //8月开锁次数',
|
| | | rt_data.lockReport.month9 = res.getInt("month9"); //9月开锁次数',
|
| | | rt_data.lockReport.month10 = res.getInt("month10"); //10月开锁次数',
|
| | | rt_data.lockReport.month11 = res.getInt("month11"); //11月开锁次数',
|
| | | rt_data.lockReport.month12 = res.getInt("month12"); //12月开锁次数',
|
| | | rt_data.lockReport.quarter1 = res.getInt("quarter1"); //第一季度开锁次数',
|
| | | rt_data.lockReport.quarter2 = res.getInt("quarter2"); //第二季度开锁次数',
|
| | | rt_data.lockReport.quarter3 = res.getInt("quarter3"); //第三季度开锁次数',
|
| | | rt_data.lockReport.quarter4 = res.getInt("quarter4"); //第四季度开锁次数',
|
| | | rt_data.lockReport.year_count = res.getInt("year_count"); //本年开锁次数',
|
| | | |
| | | }else {
|
| | | //插入默认数据
|
| | | 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();
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 创建指定锁具的指定表
|
| | | * @param pool
|
| | | * @param lock_id
|
| | | * @param nowYear
|
| | | */
|
| | | public static void createLockHistTable(MysqlConnPool pool, int lock_id, int nowYear) {
|
| | | String sql_str = "CREATE TABLE IF NOT EXISTS " + Sql_Mysql.Lock_His_Table + lock_id + "_" + nowYear + " (" + |
| | | " `num` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '自增主键'," + |
| | | " `lock_id` int(11) NOT NULL DEFAULT '1' COMMENT '锁具ID号'," + |
| | | " `record_time` datetime NOT NULL DEFAULT '2000-01-01 00:00:00' COMMENT '记录时间'," + |
| | | " `lock_state` int(11) NOT NULL DEFAULT '0' COMMENT '锁具状态[0-闭锁 1-开锁]'," + |
| | | " `unlock_type` int(11) NOT NULL DEFAULT '0' COMMENT '上一次开锁方式[0-485开锁 1-刷卡开锁 2-蓝牙开锁 3-DI开锁]'," + |
| | | " `unlock_id` bigint(20) NOT NULL DEFAULT '0' COMMENT '上一次刷开开锁卡号[仅刷ID卡开锁时有效]'," + |
| | | " PRIMARY KEY (`num`)" + |
| | | ") ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='锁具" + nowYear + "年状态更新表';";
|
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
| | | try {
|
| | | sql.sqlMysqlExecute(sql_str);
|
| | | } catch (SQLException e) {
|
| | | sql.logger.error(e.toString(),e);
|
| | | } finally {
|
| | | sql.close_con();
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 删除修改时间超时的历史数据表[没有修改时间的表不会有应影响]
|
| | | */
|
| | | public static void deleteHistoryData(MysqlConnPool pool, Date delTime) { |
| | | String sql_select_strs = " select TABLE_NAME,UPDATE_TIME " + |
| | | " from information_schema.tables " + |
| | | " where table_schema='db_lock_his' " + |
| | | " AND TABLE_NAME like 'tb_lock_his_%' " + |
| | | " AND CREATE_TIME <= '"+Com.getDateTimeFormat(delTime, Com.DTF_YMDhms)+"';" ;
|
| | | String sql_delete_strs = " DROP TABLE IF EXISTS ";
|
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
| | | ResultSet res = null;
|
| | | int count = 0;
|
| | | try {
|
| | | res = sql.sqlMysqlTotalQuery(sql_select_strs);
|
| | | while(res.next()) {
|
| | | if(count > 0) {
|
| | | sql_delete_strs += ",";
|
| | | }
|
| | | |
| | | sql_delete_strs += "db_lock_his." + res.getString("TABLE_NAME");
|
| | | sql.logger.warn("删除:"+res.getString("TABLE_NAME")+"\t at "+Com.getDateTimeFormat(new Date(), Com.DTF_YMDhms));
|
| | | count++;
|
| | | }
|
| | | if(count >0) {
|
| | | sql.sqlMysqlTotalExecute(sql_delete_strs);
|
| | | }
|
| | | |
| | | } catch (SQLException e) {
|
| | | sql.logger.error("deleteHistoryData():" + e.toString(), e);
|
| | | } finally {
|
| | | if(null != res) {
|
| | | try {
|
| | | res.close();
|
| | | } catch (SQLException e) {
|
| | | sql.logger.error("deleteHistoryData():" + e.toString(), e);
|
| | | }
|
| | | }
|
| | | sql.close_con();
|
| | | }
|
| | | |
| | | }
|
| | |
|
| | | /**
|
| | | * 插入指定锁具当年的默认数据
|
| | | * @param pool
|
| | | * @param lock_id
|
| | | * @param Year
|
| | | * @return
|
| | | */
|
| | | public static void insertDefaultLock_Report_Table(MysqlConnPool pool,int lock_id,int year) {
|
| | | String sql_str_sel = " SELECT * FROM " + Sql_Mysql.Lock_Report_Table + " WHERE lock_id = " + lock_id + " AND record_year = " + year;
|
| | | String sql_str_ins = "INSERT INTO db_lock_ram.tb_lock_report(lock_id,record_year) VALUES(" + lock_id + "," + year + ");";
|
| | | ResultSet res = null;
|
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
| | | 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();
|
| | | }
|
| | | }
|
| | |
|
| | | |
| | | public static void main(String[] args) {
|
| | | MysqlConnPool pool = new MysqlConnPool("192.168.10.82",3382,10);
|
| | | insertDefaultLock_Report_Table(pool, 2 , 2025);
|
| | | |
| | | }
|
| | | }
|
New file |
| | |
| | | package com.dev.lock.history;
|
| | |
|
| | | import java.sql.ResultSet;
|
| | | import java.sql.SQLException;
|
| | | import java.util.ArrayList;
|
| | |
|
| | | import com.dev.lock.data.ElectLock_Inf;
|
| | | import com.dev.lock.data.ElectLock_RecordState;
|
| | | import com.dev.lock.data.ElectLock_Report;
|
| | | import com.sql.MysqlConnPool;
|
| | | import com.sql.Sql_Mysql;
|
| | |
|
| | | public class InsertDataToMysql_Task implements Runnable{
|
| | | private ElectLock_Inf m_lock_rt = null;
|
| | | private MysqlConnPool m_Conn_Pool;
|
| | | |
| | | |
| | | public InsertDataToMysql_Task() |
| | | {
|
| | | }
|
| | | |
| | | public InsertDataToMysql_Task(ElectLock_Inf rt_dat, MysqlConnPool pool) {
|
| | | m_lock_rt = rt_dat;
|
| | | m_Conn_Pool = pool;
|
| | | |
| | | }
|
| | | @Override
|
| | | public void run() {
|
| | | Sql_Mysql sql = new Sql_Mysql(m_Conn_Pool.getConn());
|
| | | try {
|
| | | |
| | | inserTestDataToDB(sql);
|
| | | } catch (Exception e) {
|
| | | sql.logger.error(e.toString(), e);
|
| | | } finally {
|
| | | sql.close_con();
|
| | | m_lock_rt.clearStoreDataBusyTag();
|
| | | }
|
| | | }
|
| | | |
| | | |
| | | private void inserTestDataToDB(Sql_Mysql sql_v) {
|
| | | boolean result = true;
|
| | | for(int c=0; c<3; c++) {
|
| | | try {
|
| | | sql_v.mysql_con.setAutoCommit(false);
|
| | | //--------------------------------------------------------------//
|
| | | if(m_lock_rt.lockRecordState.lock_state == ElectLock_RecordState.Lock_State_Open) {
|
| | | //当前为开锁事件
|
| | | m_lock_rt.lockReport.calNewOpenEvent(m_lock_rt.lockRecordState.record_time);
|
| | | |
| | | String sql_str = InsertDataToMysql_Task_SQL.getInsertLock_Report_TableDataStr(m_lock_rt.getLock_id(),m_lock_rt.lockReport);
|
| | | |
| | | sql_v.sqlMysqlExecute(sql_str);
|
| | | }
|
| | | |
| | | |
| | | String sql_str = InsertDataToMysql_Task_SQL.getInsertLock_His_TableDataStr(m_lock_rt.getLock_id(), m_lock_rt.lockRecordState);
|
| | | //------------------------------------------------------------//
|
| | |
|
| | | sql_v.sqlMysqlExecute(sql_str);
|
| | | //------------------------------------------------------------//
|
| | | sql_v.mysql_con.commit();
|
| | | |
| | | } catch (SQLException e) {
|
| | | try {
|
| | | sql_v.mysql_con.rollback();
|
| | | } catch (SQLException e1) {
|
| | | sql_v.logger.error("InsertDataToMysql_Task.inserTestDataToDB():" + e1.toString(), e1);
|
| | | }
|
| | | sql_v.logger.error("InsertDataToMysql_Task.-inserTestDataToDB():" + e.toString(), e);
|
| | | result = false;
|
| | | } finally {
|
| | | |
| | | if(true == result) {
|
| | | m_lock_rt.lockRecordState.RecordHisOK();
|
| | | break; |
| | | } else {
|
| | | try {
|
| | | Thread.sleep(1000);
|
| | | } catch (Exception e) {
|
| | | sql_v.logger.error("InsertDataToMysql_Task.inserTestDataToDB():" + e.toString(), e);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
New file |
| | |
| | | package com.dev.lock.history;
|
| | |
|
| | | import com.base.Com;
|
| | | import com.dev.lock.data.ElectLock_RecordState;
|
| | | import com.dev.lock.data.ElectLock_Report;
|
| | | import com.sql.Sql_Mysql;
|
| | |
|
| | | public class InsertDataToMysql_Task_SQL {
|
| | |
|
| | | /**
|
| | | * 构造年度开锁记录表
|
| | | * @param sql
|
| | | * @param lock_id
|
| | | * @param report
|
| | | * @return
|
| | | */
|
| | | public static String getInsertLock_Report_TableDataStr(int lock_id,ElectLock_Report report) {
|
| | | String sql_str_upd = " UPDATE " + Sql_Mysql.Lock_Report_Table +
|
| | | " SET month1 = " + report.month1 +
|
| | | " ,month2 = " + report.month2 +
|
| | | " ,month3 = " + report.month3 +
|
| | | " ,month4 = " + report.month4 +
|
| | | " ,month5 = " + report.month5 +
|
| | | " ,month6 = " + report.month6 +
|
| | | " ,month7 = " + report.month7 +
|
| | | " ,month8 = " + report.month8 +
|
| | | " ,month9 = " + report.month9 +
|
| | | " ,month10 = " + report.month10 +
|
| | | " ,month11 = " + report.month11 +
|
| | | " ,month12 = " + report.month12 +
|
| | | " ,quarter1 = " + report.quarter1 +
|
| | | " ,quarter2 = " + report.quarter2 +
|
| | | " ,quarter3 = " + report.quarter3 +
|
| | | " ,quarter4 = " + report.quarter4 +
|
| | | " ,year_count = " + report.year_count +
|
| | | " WHERE lock_id = " + lock_id +
|
| | | " AND record_year = " + report.record_year;
|
| | | return sql_str_upd;
|
| | | }
|
| | | |
| | | |
| | | /**
|
| | | * 构造锁具开关锁,记录表
|
| | | * @param sql
|
| | | * @param lock_id
|
| | | * @param report
|
| | | * @return
|
| | | */
|
| | | public static String getInsertLock_His_TableDataStr(int lock_id,ElectLock_RecordState state) {
|
| | | String sql_str_upd = " INSERT INTO " + Sql_Mysql.Lock_His_Table + lock_id + "_" + Com.getDateTimeFormat(state.record_time, Com.DTF_Y) + " "
|
| | | + " (lock_id,record_time,lock_state,unlock_type,unlock_id) "
|
| | | + " VALUES(" |
| | | + lock_id |
| | | + ",'" + Com.getDateTimeFormat(state.record_time, Com.DTF_YMDhms) |
| | | + "'," + state.lock_state |
| | | + "," + state.unlock_type |
| | | + "," + state.unlock_id + |
| | | ");";
|
| | | return sql_str_upd;
|
| | | }
|
| | |
|
| | | }
|
| | |
| | | public static final String DB_AREA = "`db_area`";
|
| | | public static final String DB_LOCK_RAM = "`db_lock_ram`";
|
| | | public static final String DB_USER = "`db_user`";
|
| | | public static final String DB_LOCK_HIS = "`db_lock_his`"; //锁具历史状态库
|
| | |
|
| | | /*********************************************************/
|
| | | public static final String Lock_Rt_Table = DB_LOCK_RAM + ".tb_lock_rt";
|
| | | public static final String Lock_Ctl_Log_Table = DB_LOCK_RAM + ".tb_lock_ctl_log";
|
| | | public static final String Lock_Report_Table = DB_LOCK_RAM + ".tb_lock_report"; //锁具开锁次数统计表
|
| | | /*********************************************************/
|
| | | /*************** ******************************************/
|
| | | /*************** ************ db_area ******************************/
|
| | | public static final String Lock_Inf_Table = DB_AREA + ".tb_lock_inf";
|
| | | public static final String Key_Inf_Table = DB_AREA + ".tb_key_inf";
|
| | | public static final String Auth_Idcard_Table = DB_AREA + ".tb_auth_idcard"; //批量添加授权和取消授权表
|
| | | public static final String Auth_Idcard_Table = DB_AREA + ".tb_auth_idcard"; //批量添加授权和取消授权表
|
| | | public static final String Auth_Idcard_His_Table = DB_AREA + ".tb_auth_idcard_his"; //批量添加授权和取消授权历史表
|
| | | /*********************************************************/
|
| | | /***************************** db_lock_his ****************************/
|
| | | public static final String Lock_His_Table = DB_LOCK_HIS + ".tb_lock_his_"; //锁具开锁次数统计表
|
| | | |
| | | /*********************************************************/
|
| | | /***************************** db_user ****************************/
|
| | | public static final String Process_Survey_Table = DB_USER + ".tb_process_survey"; //线程管理表
|
| | | |
| | | /*********************************************************/
|
| | |
|
| | | public Logger logger;
|
| | | public Connection mysql_con;
|
| | |
| | |
|
| | | 设备ID:10000001
|
| | |
|
| | | |
| | | V1.110 edit by lijun 2025-01-20
|
| | | 1.新增锁具告警记录功能
|
| | | 2.新增触发告警 - |
| | | 通信故障告警
|
| | | 开锁失败
|
| | | 记录每年月季度的开锁次数,以及每年锁具状态变化记录
|
| | | |
| | | |
| | | V1.109 edit by lijun 2025-01-15
|
| | | 1.通信协议新增读取电子锁蓝牙MAC地址数据
|
| | |
|
| | |
| | | import com.config.AppConfig;
|
| | | import com.del.TmpFileUtil;
|
| | | import com.dev.lock.comm.Lock_ServerSocket_Thread;
|
| | | import com.dev.lock.comm.Lock_Task_SQL;
|
| | | import com.dev.lock.data.ElectLock_Array;
|
| | | import com.dev.lock.history.ElectLock_HistoryData_Record_Thread;
|
| | | import com.sql.MysqlConnPool;
|
| | | import java.sql.Connection;
|
| | | import java.sql.SQLException;
|
| | |
| | | private static Logger logger;
|
| | | private static ElectLock_Array GB_ElLock_Array;
|
| | |
|
| | |
|
| | | |
| | | |
| | | static {
|
| | | System.setProperty("log4j.configurationFile", "log4j2_electlock_dev_x64.xml");
|
| | | }
|
| | | |
| | | public static void main(String[] args) {
|
| | | TimeZone.setDefault(TimeZone.getTimeZone("GMT+8"));
|
| | | |
| | | GB_ElLock_Array = new ElectLock_Array();
|
| | |
|
| | | logger = LogManager.getLogger(main_ElectLock_Monitor.class);
|
| | |
| | | server_thread.start();
|
| | |
|
| | |
|
| | | {
|
| | | ElectLock_HistoryData_Record_Thread record_thread = new ElectLock_HistoryData_Record_Thread(GB_ElLock_Array, GB_MysqlConnPool);
|
| | | record_thread.start();
|
| | | }
|
| | |
|
| | | //FBS9600_State_SQL.updateProcess_StartTime(GB_MysqlConnPool, m_VersionNum);
|
| | | |
| | | Lock_Task_SQL.updateProcess_StartTime(GB_MysqlConnPool, m_VersionNum);
|
| | | Date last_time = new Date(0);
|
| | | while (true) {
|
| | | try {
|
| | | Thread.sleep(3000L);
|
| | |
|
| | | Date now = new Date();
|
| | | long timelong = (now.getTime()-last_time.getTime())/1000;
|
| | |
| | | TmpFileUtil.delTmpFile();
|
| | | last_time = now;
|
| | | }
|
| | | Thread.sleep(3000L);
|
| | | //FBS9600_State_SQL.updateProcess_ProcessTime(GB_MysqlConnPool); |
| | | } catch (InterruptedException e) {
|
| | | Lock_Task_SQL.updateProcess_ProcessTime(GB_MysqlConnPool); |
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
| | | try {
|
| | | Thread.sleep(1000);
|
| | | } catch (InterruptedException e1) {
|
| | | e1.printStackTrace();
|
| | | logger.error(e.toString(),e);
|
| | | }
|
| | | System.out.println(" MySQL not Start ... ");
|
| | | System.out.println(" SQLDataBase Server not Start ... ");
|
| | | } finally {
|
| | | if(conn != null) {
|
| | | try {
|
| | | conn.close();
|
| | | } catch (SQLException e) {
|
| | | e.printStackTrace();
|
| | | logger.error(e.toString(),e);
|
| | | }
|
| | | }
|
| | | }
|