-- public.tb_gis_road_mile_log definition

-- Drop table

-- DROP TABLE public.tb_gis_road_mile_log;

CREATE TABLE public.tb_gis_road_mile_log (
	id varchar(32) NOT NULL,
	number_plate varchar(32) NOT NULL, -- 车牌号
	project_id varchar(32) NOT NULL, -- 所属项目id
	project_name varchar(32) NULL, -- 所属项目名称
	vehicle_brand varchar(2) null,--车辆品牌
	vehicle_model varchar(32) null,--车辆型号
	vehicle_type varchar(2) null,--车辆种类
	vin_code varchar(64) NOT NULL, -- VIN 码
	start_time timestamp NULL, -- 开始时间
	end_time timestamp NULL, -- 结束时间
	power_consume numeric(12, 2) NULL, -- 耗电量 kwh
	road_mile numeric(12, 2) NULL, -- 行驶里程 km
	energy_consume numeric(12,4),--能耗 kwh
	create_time timestamp NOT NULL, -- 入库时间
	CONSTRAINT pk_tb_gis_road_mile_log PRIMARY KEY (id)
);
CREATE INDEX tb_gis_road_mile_log_number_plate_idx ON public.tb_gis_road_mile_log USING btree (number_plate);
COMMENT ON TABLE public.tb_gis_road_mile_log IS '车辆能耗记录表';

-- Column comments

COMMENT ON COLUMN public.tb_gis_road_mile_log.number_plate IS '车牌号';
COMMENT ON COLUMN public.tb_gis_road_mile_log.project_id IS '所属项目id';
COMMENT ON COLUMN public.tb_gis_road_mile_log.project_name IS '所属项目名称';
COMMENT ON COLUMN public.tb_gis_road_mile_log.vehicle_type IS '车辆种类';
COMMENT ON COLUMN public.tb_gis_road_mile_log.vehicle_brand IS '车辆品牌';
COMMENT ON COLUMN public.tb_gis_road_mile_log.vehicle_model IS '车辆型号';
COMMENT ON COLUMN public.tb_gis_road_mile_log.vin_code IS 'VIN 码';
COMMENT ON COLUMN public.tb_gis_road_mile_log.start_time IS '开始时间';
COMMENT ON COLUMN public.tb_gis_road_mile_log.end_time IS '结束时间';
COMMENT ON COLUMN public.tb_gis_road_mile_log.power_consume IS '耗电量 耗电量 kwh';
COMMENT ON COLUMN public.tb_gis_road_mile_log.road_mile IS '行驶里程 km';
COMMENT ON COLUMN public.tb_gis_road_mile_log.energy_consume IS '能耗 kmh/km';
COMMENT ON COLUMN public.tb_gis_road_mile_log.create_time IS '入库时间';

ALTER TABLE public.tb_gis_road_mile_log ADD own_date varchar(10) NULL;
COMMENT ON COLUMN public.tb_gis_road_mile_log.own_date IS '所属日期 例如：2023-06-05';

ALTER TABLE public.tb_gis_road_mile_log ALTER COLUMN power_consume SET DEFAULT 0;
ALTER TABLE public.tb_gis_road_mile_log ALTER COLUMN road_mile SET DEFAULT 0;


--维修保养表结构调整sql

ALTER TABLE public.tb_repair_assign ADD sys_org_code varchar(32) NULL;
COMMENT ON COLUMN public.tb_repair_assign.sys_org_code IS '所属机构';
ALTER TABLE public.tb_repair_assign ADD create_time timestamp NULL;
COMMENT ON COLUMN public.tb_repair_assign.create_time IS '创建日期';
ALTER TABLE public.tb_repair_assign ADD update_time timestamp NULL;
COMMENT ON COLUMN public.tb_repair_assign.update_time IS '更新日期';
ALTER TABLE public.tb_repair_assign ADD create_by varchar(32) NULL;
COMMENT ON COLUMN public.tb_repair_assign.create_by IS '创建人';
ALTER TABLE public.tb_repair_assign ADD update_by varchar(32) NULL;
COMMENT ON COLUMN public.tb_repair_assign.update_by IS '更新人';

ALTER TABLE public.tb_repair_check ADD sys_org_code varchar(32) NULL;
COMMENT ON COLUMN public.tb_repair_check.sys_org_code IS '所属机构';
ALTER TABLE public.tb_repair_check ADD create_time timestamp NULL;
COMMENT ON COLUMN public.tb_repair_check.create_time IS '创建日期';
ALTER TABLE public.tb_repair_check ADD update_time timestamp NULL;
COMMENT ON COLUMN public.tb_repair_check.update_time IS '更新日期';
ALTER TABLE public.tb_repair_check ADD create_by varchar(32) NULL;
COMMENT ON COLUMN public.tb_repair_check.create_by IS '创建人';
ALTER TABLE public.tb_repair_check ADD update_by varchar(32) NULL;
COMMENT ON COLUMN public.tb_repair_check.update_by IS '更新人';

ALTER TABLE public.tb_repair_offer ADD sys_org_code varchar(32) NULL;
COMMENT ON COLUMN public.tb_repair_offer.sys_org_code IS '所属机构';
ALTER TABLE public.tb_repair_offer ADD create_time timestamp NULL;
COMMENT ON COLUMN public.tb_repair_offer.create_time IS '创建日期';
ALTER TABLE public.tb_repair_offer ADD update_time timestamp NULL;
COMMENT ON COLUMN public.tb_repair_offer.update_time IS '更新日期';
ALTER TABLE public.tb_repair_offer ADD create_by varchar(32) NULL;
COMMENT ON COLUMN public.tb_repair_offer.create_by IS '创建人';
ALTER TABLE public.tb_repair_offer ADD update_by varchar(32) NULL;
COMMENT ON COLUMN public.tb_repair_offer.update_by IS '更新人';



ALTER TABLE public.tb_upkeep_assign ADD sys_org_code varchar(32) NULL;
COMMENT ON COLUMN public.tb_upkeep_assign.sys_org_code IS '所属机构';
ALTER TABLE public.tb_upkeep_assign ADD create_time timestamp NULL;
COMMENT ON COLUMN public.tb_upkeep_assign.create_time IS '创建日期';
ALTER TABLE public.tb_upkeep_assign ADD update_time timestamp NULL;
COMMENT ON COLUMN public.tb_upkeep_assign.update_time IS '更新日期';
ALTER TABLE public.tb_upkeep_assign ADD create_by varchar(32) NULL;
COMMENT ON COLUMN public.tb_upkeep_assign.create_by IS '创建人';
ALTER TABLE public.tb_upkeep_assign ADD update_by varchar(32) NULL;
COMMENT ON COLUMN public.tb_upkeep_assign.update_by IS '更新人';

ALTER TABLE public.tb_upkeep_check ADD sys_org_code varchar(32) NULL;
COMMENT ON COLUMN public.tb_upkeep_check.sys_org_code IS '所属机构';
ALTER TABLE public.tb_upkeep_check ADD create_time timestamp NULL;
COMMENT ON COLUMN public.tb_upkeep_check.create_time IS '创建日期';
ALTER TABLE public.tb_upkeep_check ADD update_time timestamp NULL;
COMMENT ON COLUMN public.tb_upkeep_check.update_time IS '更新日期';
ALTER TABLE public.tb_upkeep_check ADD create_by varchar(32) NULL;
COMMENT ON COLUMN public.tb_upkeep_check.create_by IS '创建人';
ALTER TABLE public.tb_upkeep_check ADD update_by varchar(32) NULL;
COMMENT ON COLUMN public.tb_upkeep_check.update_by IS '更新人';

ALTER TABLE public.tb_upkeep_plan_check ADD sys_org_code varchar(32) NULL;
COMMENT ON COLUMN public.tb_upkeep_plan_check.sys_org_code IS '所属机构';
ALTER TABLE public.tb_upkeep_plan_check ADD create_time timestamp NULL;
COMMENT ON COLUMN public.tb_upkeep_plan_check.create_time IS '创建日期';
ALTER TABLE public.tb_upkeep_plan_check ADD update_time timestamp NULL;
COMMENT ON COLUMN public.tb_upkeep_plan_check.update_time IS '更新日期';
ALTER TABLE public.tb_upkeep_plan_check ADD create_by varchar(32) NULL;
COMMENT ON COLUMN public.tb_upkeep_plan_check.create_by IS '创建人';
ALTER TABLE public.tb_upkeep_plan_check ADD update_by varchar(32) NULL;
COMMENT ON COLUMN public.tb_upkeep_plan_check.update_by IS '更新人';


ALTER TABLE public.tb_repair_offer ALTER COLUMN in_repair_img_url TYPE varchar(2048) USING in_repair_img_url::varchar;
ALTER TABLE public.tb_repair_offer ALTER COLUMN after_repair_img_url TYPE varchar(2048) USING after_repair_img_url::varchar;
ALTER TABLE public.tb_repair_offer ALTER COLUMN attachment_url TYPE varchar(2048) USING attachment_url::varchar;

ALTER TABLE public.tb_upkeep_offer ALTER COLUMN before_upkeep_img_url TYPE varchar(2048) USING before_upkeep_img_url::varchar;
ALTER TABLE public.tb_upkeep_offer ALTER COLUMN in_upkeep_img_url TYPE varchar(2048) USING in_upkeep_img_url::varchar;
ALTER TABLE public.tb_upkeep_offer ALTER COLUMN after_upkeep_img_url TYPE varchar(2048) USING after_upkeep_img_url::varchar;


