| | |
| | |
|
| | | import java.sql.ResultSet;
|
| | | import java.sql.SQLException;
|
| | | import java.util.Date;
|
| | |
|
| | | import com.base.Com;
|
| | | import com.mode.Motor_State;
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | |
| | | /**
|
| | | * 更新电机实时状态
|
| | | * @param pool
|
| | | * @param state
|
| | | */
|
| | | public static void updateMotor_State_Table(MysqlConnPool pool,Motor_State state) {
|
| | | String sql_str_upd = "UPDATE " + Sql_Mysql.Tb_Motor_State_Table +
|
| | | " SET device_id="+state.device_id+""
|
| | |
| | | sql.close_con();
|
| | | }
|
| | | }
|
| | | |
| | | /**
|
| | | * |
| | | * @param pool
|
| | | * @param state
|
| | | * @param time
|
| | | */
|
| | | public static void createTb_Motor_State_RealData_Table(MysqlConnPool pool,int device_id,Date time) {
|
| | | String sql_str = "CREATE TABLE IF NOT EXISTS "+Sql_Mysql.Tb_Motor_State_RealData_Table+device_id+"_"+Com.getDateTimeFormat(time, Com.DTF_Y_M_D)+" (" + |
| | | " `num` bigint(20) NOT NULL AUTO_INCREMENT," + |
| | | " `device_id` int(11) NOT NULL DEFAULT '100001' COMMENT '设备id'," + |
| | | " `record_time` datetime NOT NULL DEFAULT '2000-01-01 00:00:00' COMMENT '记录时间'," + |
| | | " `motor_curr` float NOT NULL DEFAULT '0' COMMENT '电机电流'," + |
| | | " `motor_power` float NOT NULL DEFAULT '0' COMMENT '电机功率'," + |
| | | " `motor_speed` float NOT NULL DEFAULT '0' COMMENT '电机转速'," + |
| | | " `motor_vol` float NOT NULL DEFAULT '0' COMMENT '电机电压'," + |
| | | " `motor_out_tmp` float NOT NULL DEFAULT '0' COMMENT '电机出口温度'," + |
| | | " `motor_into_tmp` float NOT NULL DEFAULT '0' COMMENT '电机进口温度'," + |
| | | " `motor_torque` float NOT NULL DEFAULT '0' COMMENT '电机转矩'," + |
| | | " `motor_state` int(11) NOT NULL DEFAULT '0' COMMENT '电机状态'," + |
| | | " PRIMARY KEY (`num`)" + |
| | | ") ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;";
|
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
| | | try {
|
| | | sql.sqlMysqlExecute(sql_str);
|
| | | } catch (SQLException e) {
|
| | | e.printStackTrace();
|
| | | } finally {
|
| | | sql.close_con();
|
| | | }
|
| | | }
|
| | | |
| | | /**
|
| | | * 插入历史实时数据
|
| | | * @param pool
|
| | | * @param state
|
| | | */
|
| | | public static void insertMotor_State_RealData_Table(MysqlConnPool pool,Motor_State state) {
|
| | | String sql_str_ins = " INSERT INTO " + Sql_Mysql.Tb_Motor_State_RealData_Table+state.device_id+"_"+Com.getDateTimeFormat(state.record_time, Com.DTF_Y_M_D) +
|
| | | "(device_id,record_time,motor_curr,motor_power,motor_speed,motor_vol,motor_out_tmp,motor_into_tmp,motor_torque,motor_state) " + |
| | | "VALUES("+state.device_id+",'"+Com.getDateTimeFormat(state.record_time, Com.DTF_YMDhms)+"',"+state.motor_curr+","+state.motor_power+","+state.motor_speed+","+state.motor_vol+","+state.motor_out_tmp+","+state.motor_into_tmp+","+state.motor_torque+","+state.motor_state+")";
|
| | | Sql_Mysql sql = new Sql_Mysql(pool.getConn());
|
| | | try {
|
| | | sql.sqlMysqlExecute(sql_str_ins);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | } finally {
|
| | | sql.close_con();
|
| | | }
|
| | | }
|
| | | }
|