-- 故障码管理
-- 故障码信息表
drop table if exists fault_code_info;
create table fault_code_info(
  fault_id        int(11)         comment '故障码主键'   primary key auto_increment,
  fault_name      varchar(32)     comment '故障名称',
  fault_code      varchar(32)     comment '故障码',
  fault_type      tinyint(4)      comment '故障类型:1-通讯丢失故障 2-车身故障 3-底盘故障 4-电子围栏故障 5-其他故障',
  fault_level     tinyint(4)      comment '故障等级:1-高级故障 2-中级故障 3-低级故障',
  alarm_flag      char(1)         default 'Y'           comment '是否产生报警（Y正常 N报警）',
  fault_desc      varchar(100)    comment '故障描述',
  fault_location  tinyint(4)      comment '故障位置',
  fault_value     bigint(20)      comment '故障值',
  status          char(1)         default '0'           comment '故障码状态（0正常 1停用）',
  del_flag        char(1)         default '0'           comment '删除标志（0存在 2删除）',
  create_by       varchar(64)     default ''            comment '创建者',
  create_time 	  datetime                              comment '创建时间',
  update_by       varchar(64)     default ''            comment '更新者',
  update_time     datetime                              comment '更新时间',
  remark          varchar(200)    comment '备注'
) engine=innodb comment = '故障码表';
insert into fault_code_info(fault_name, fault_code, fault_type, fault_level, alarm_flag, fault_desc, fault_location, fault_value, status, del_flag, create_by, create_time, remark) values ('通讯丢失故障', '0001', 1, 1, '0', '通讯丢失故障', '车辆', 0, '0', '0', 'admin', now(), '通讯丢失故障');
insert into fault_code_info(fault_name, fault_code, fault_type, fault_level, alarm_flag, fault_desc, fault_location, fault_value, status, del_flag, create_by, create_time, remark) values ('车身故障', '0002', 2, 1, '0', '车身故障', '车辆', 0, '0', '0', 'admin', now(), '车身故障');
insert into fault_code_info(fault_name, fault_code, fault_type, fault_level, alarm_flag, fault_desc, fault_location, fault_value, status, del_flag, create_by, create_time, remark) values ('底盘故障', '0003', 3, 1, '0', '底盘故障', '车辆', 0, '0', '0', 'admin', now(),'底盘故障');
insert into fault_code_info(fault_name, fault_code, fault_type, fault_level, alarm_flag, fault_desc, fault_location, fault_value, status, del_flag, create_by, create_time, remark) values ('电子围栏故障', '0004', 4, 1, '0', '电子围栏故障', '车辆', 0, '0', '0', 'admin', now(),'电子围栏故障');
insert into fault_code_info(fault_name, fault_code, fault_type, fault_level, alarm_flag, fault_desc, fault_location, fault_value, status, del_flag, create_by, create_time, remark) values ('其他故障', '0005', 5, 1, '0', '其他故障', '车辆', 0, '0', '0', 'admin', now(), '其他故障');
select fault_id,fault_name, fault_code, fault_type, fault_level, alarm_flag, fault_desc, fault_location, fault_value, status, del_flag from fault_code_info;


-- 故障记录
drop table if exists fault_logs;
create table fault_logs (
  log_id            int(11)         comment '故障码主键'   primary key auto_increment,
  car_vin           varchar(100)    comment '车辆VIN',
  car_id            bigint(40)      comment '车辆编号',
  fault_name        varchar(32)     comment '故障名称',
  fault_code        varchar(32)     comment '故障码',
  alarm_flag        char(1)         default 'Y'           comment '是否产生报警（Y正常 N报警）',
  start_alarm_time  datetime        comment '开始报警时间',
  end_alarm_time    datetime        comment '最近报警时间',
  processing_time   datetime        comment '处理时间',
  processing_by     varchar(32)     comment '处理人',
  processing_status char(1)         comment ''
)engine=innodb comment = '故障记录表';
