-- 化验系统相关表结构
-- Created at 2025-04-20
CREATE TABLE "public"."hy_record" (
	"id" serial4 NOT NULL,
	"hy_code" varchar(255),
	"type" varchar(20),
	"hy_check" smallint DEFAULT 0,
	"hy_approve" smallint DEFAULT 0,
	"check_time" timestamp without time zone,
	"approve_time" timestamp without time zone,
	"approve_user" varchar(50),
	"check_user" varchar(50),
	"hy_time" timestamp without time zone,
	"hy_values" varchar(500),
	"accept_time" timestamp without time zone,
	"accept_user" varchar(50),
	"mt" numeric(18,1),
	"mad" numeric(18,2),
	"aad" numeric(18,2),
	"ad" numeric(18,2),
	"vad" numeric(18,2),
	"vd" numeric(18,2),
	"var" numeric(18,2),
	"vdaf" numeric(18,2),
	"fcad" numeric(18,2),
	"st_ar" numeric(18,2),
	"st_ad" numeric(18,2),
	"st_d" numeric(18,2),
	"had" numeric(18,2),
	"hd" numeric(18,2),
	"qb_ad" numeric(18,3),
	"qgr_ad" numeric(18,3),
	"qgr_d" numeric(18,3),
	"qnet_ar_mj_kg" numeric(18,2),
	"qnet_ar_j_cal" numeric(18,0),
	"v" numeric(18,2),
	"aar" numeric(18,2),
	"qnet_ar" numeric(18,2),
	"qnet_ar1" numeric(18,4),
	"crc" numeric(18,0),
	"st_daf" numeric(18,2),
	"cad" numeric(18,2),
	"cd" numeric(18,2),
	"isauto" smallint,
	"hy_type" varchar(255),
	"isnormal" int4,
	CONSTRAINT "PK_HY_RECORD" PRIMARY KEY ("id")
);


CREATE TABLE "public"."hy_instrument" (
	"id" int4 NOT NULL,
	"laboratoryid" int4,
	"name" varchar(100),
	"instrumentcode" varchar(50),
	"informationid" int4,
	"specification" varchar(50),
	"remark" varchar(50),
	CONSTRAINT "PK_HY_Instrument" PRIMARY KEY ("id")
);


-- 分配表
CREATE TABLE IF NOT EXISTS "public"."hy_allot" (
    "id" int4 NOT NULL,
    "userid" int4,
    "username" varchar(50),
    "informationid" int4,
    "allottime" timestamp without time zone,
    "hy_code" varchar(50),
    "hy_type" varchar(50),
    "hy_method" varchar(50),
    "hy_quest" varchar(50),
    CONSTRAINT "PK_HY_Allot" PRIMARY KEY ("id")
);

-- 全水样品表
CREATE TABLE IF NOT EXISTS "public"."hy_fullwatersample" (
    "id" int4 NOT NULL,
    "qs_code" varchar(50),
    "qs_tonnage" numeric(18,2),
    "mt" numeric(18,1),
    "remark" varchar(50),
    "onecode" varchar(50),
    "towcode" varchar(50),
    "fx_code" varchar(50),
    "fx_onecode" varchar(50),
    "fx_twocode" varchar(50),
    CONSTRAINT "PK_HY_FullWaterSample" PRIMARY KEY ("id")
);

-- 化验信息规范表
CREATE TABLE IF NOT EXISTS "public"."hy_informationnorm" (
    "id" int4 NOT NULL,
    "information_id" int4,
    "hy_id" int4,
    "norm_name" varchar(50),
    "flag" smallint,
    "apparatus_id" int4,
    "need_compute" smallint,
    "formula" varchar(255),
    "secondformula" varchar(255),
    "mapping" varchar(255),
    "input_type" int4,
    "round" int4,
    "sort" int4
);

-- 化验项目明细表
CREATE TABLE IF NOT EXISTS "public"."hy_itemdetail" (
    "id" serial4 NOT NULL,
    "record_id" int4,
    "information_id" int4,
    "laboratory_id" int4,
    "number" int4,
    "cancellation" smallint DEFAULT 0,
    "detectionuser" varchar(50),
    "detectiontime" timestamp without time zone,
    "original_num" varchar(50),
    "hy_check" smallint DEFAULT 0,
    "checkuser" varchar(50),
    "checktime" timestamp without time zone,
    "oversize" smallint DEFAULT 0,
    CONSTRAINT "PK_HY_ITEMDETAIL" PRIMARY KEY ("id")
);

-- 实验室仪器表
CREATE TABLE IF NOT EXISTS "public"."hy_laboratoryinstrument" (
    "id" serial4 NOT NULL,
    "norm_id" int4,
    "instrument_id" int4,
    CONSTRAINT "hy_laboratoryinstrument_pkey" PRIMARY KEY ("id")
);

-- 物料分析类型表
CREATE TABLE IF NOT EXISTS "public"."hy_materialanalysis_type" (
    "id" int4 NOT NULL,
    "name" varchar(255),
    "flag" smallint,
    "sort" int4,
    "createtime" date,
    "createuser" varchar(255),
    CONSTRAINT "hy_Material_AnalysisType_pkey1" PRIMARY KEY ("id")
);

-- 物料明细表
CREATE TABLE IF NOT EXISTS "public"."hy_materialdetail" (
    "id" int4 NOT NULL,
    "name" varchar(255),
    "flag" int4,
    "sort" int4,
    "createtime" date,
    "createuser" varchar(255),
    "analysistypeid" int4,
    "materialid" int4,
    CONSTRAINT "hy_Material_AnalysisType_pkey" PRIMARY KEY ("id")
);

-- 化验规范表
CREATE TABLE IF NOT EXISTS "public"."hy_norm" (
    "id" serial4 NOT NULL,
    "norm_id" int4,
    "zbvalues" numeric(12,4),
    "itemdetail_id" int4,
    "hy_user" varchar(50),
    "checktime" timestamp without time zone,
    "explain" varchar(200),
    CONSTRAINT "PK_HY_NORM" PRIMARY KEY ("id")
);

-- 样品采集明细表
CREATE TABLE IF NOT EXISTS "public"."hy_sample_collection_detail" (
    "id" serial4 NOT NULL,
    "num" int4 NOT NULL,
    "unit_num" int4 NOT NULL,
    "time" timestamp without time zone,
    "type" int4,
    "sy_method" int4,
    "sy_time" timestamp without time zone,
    "one_num" varchar(11),
    "two_num" varchar(11),
    "three_num" varchar(11),
    "sy_starttime" timestamp without time zone,
    "sy_endtime" timestamp without time zone,
    "cy_startnum" varchar(50),
    "cy_endnum" varchar(50),
    "sy_user" varchar(20),
    "sy_car_count" int4,
    "sy_dun_weight" numeric(18,2),
    "byz_bag_count" smallint,
    "y_liu" smallint,
    "zy_user" varchar(20),
    "one_num_createtime" timestamp without time zone,
    "one_num_user" varchar(20),
    "one_num_review_status" smallint,
    "one_num_review_user" varchar(20),
    "one_num_review_time" timestamp without time zone,
    "two_num_createtime" timestamp without time zone,
    "two_num_user" varchar(20),
    "two_num_review_status" smallint,
    "two_num_review_user" varchar(20),
    "two_num_review_time" timestamp without time zone,
    "three_num_createtime" timestamp without time zone,
    "three_num_user" varchar(20),
    "three_num_review_status" smallint,
    "three_num_review_user" varchar(20),
    "three_num_review_time" timestamp without time zone,
    "hy_createtime" timestamp without time zone,
    "hy_time" timestamp without time zone,
    "hy_user" varchar(20),
    "hy_review_user" varchar(20),
    "hy_review_status" smallint,
    "hy_review_time" timestamp without time zone,
    "record_sort" int4,
    "is_print" smallint,
    "print_msg" smallint,
    "pring_user" varchar(8),
    "hy_approve" smallint,
    "hy_approve_time" timestamp without time zone,
    "hy_approve_user" varchar(20),
    "mt" numeric(18,1),
    "mad_clp" numeric(18,4),
    "mad_my" numeric(18,4),
    "mad_hh" numeric(18,4),
    "mad" numeric(18,2),
    "a_hm" numeric(18,4),
    "a_my" numeric(18,4),
    "a_hh" numeric(18,4),
    "a_hm1" numeric(18,4),
    "a_my1" numeric(18,4),
    "a_hh1" numeric(18,4),
    "aad" numeric(18,2),
    "ad" numeric(18,2),
    "v_gg" numeric(18,4),
    "v_my" numeric(18,4),
    "v_hh" numeric(18,4),
    "vad" numeric(18,2),
    "vdaf" numeric(18,2),
    "var_data" numeric(18,2),
    "vd" numeric(18,2),
    "fcad" numeric(18,2),
    "st_ad" numeric(18,2),
    "st_d" numeric(18,2),
    "st_ar" numeric(18,2),
    "had" numeric(18,2),
    "hd" numeric(18,2),
    "qb_ad" numeric(18,3),
    "qgr_ad" numeric(18,3),
    "qnet_ar" numeric(18,2),
    "qgr_d" numeric(18,2),
    "qnet_ar1" numeric(18,4),
    "byz_bag_user" varchar(50),
    "byz_bag_time" timestamp without time zone,
    "byz_bag_remark" varchar(500),
    "fc" smallint,
    "fc_reason" varchar(500),
    "fc_user" varchar(50),
    "fc_time" timestamp without time zone,
    "xk_time" timestamp without time zone,
    "xk_user" varchar(50),
    "xk_card_num" varchar(50),
    "allow_sync" smallint,
    "sync" smallint,
    "sync_time" timestamp without time zone,
    "mc_unit" int4,
    "mc_review" smallint,
    "msg_produce" smallint,
    "supply_num" int4,
    "v_data" numeric(18,2),
    "cc" smallint,
    "cc_user" varchar(50),
    "cc_time" timestamp without time zone,
    "aar" numeric(18,2),
    "is_delete" smallint,
    "alarm_remark" varchar(500),
    "zs" smallint,
    "zs_detail" smallint,
    "zs_sy_num" int4,
    "kf_qs" smallint,
    "kf_qs_time" timestamp without time zone,
    "kf_qs_reason" varchar(500),
    "qs_time" timestamp without time zone,
    "crc" numeric(18,0),
    "dk_hy" smallint,
    "dk_hy_num" varchar(50),
    "hy_copy" smallint,
    "hy_copy_num" varchar(50),
    "hy_copy_user" varchar(50),
    "hy_copy_time" timestamp without time zone,
    "already_send" smallint,
    "send_time" timestamp without time zone,
    "st_daf" numeric(18,2),
    "st" numeric(18,2),
    "two_num_weight" numeric(12,4),
    CONSTRAINT "PK_收样明细表" PRIMARY KEY ("id")
);

-- 样品交付表
CREATE TABLE IF NOT EXISTS "public"."hy_sample_delivery" (
    "id" int4 NOT NULL,
    "sample_number" varchar(255) DEFAULT '样品编号'::character varying,
    "coal_sample" varchar(255),
    "sample_weight" numeric,
    "sampler_user" varchar(255),
    "state" varchar(255),
    "check_weight" numeric,
    "sample_type" varchar(255),
    "time" date,
    "entering_type" varchar(255),
    "sample_delivery_type" varchar(255),
    "granularity" numeric,
    "container_weight" numeric,
    "sample_delivery_time" date,
    "receive_time" date,
    "sample_delivery_user" varchar(255),
    "receive_user" varchar(255),
    "notes" varchar(255),
    "serial_number" int4,
    "type" varchar(255),
    "receive_number" varchar(255),
    "samples_number_t" int4,
    "samples_number_d" int4,
    "coal_sample_d" int4,
    "receive_state" varchar(255),
    "coal_sample_t" int4,
    CONSTRAINT "zy_sample_delivery_pkey" PRIMARY KEY ("id")
);

-- 抽查表
CREATE TABLE IF NOT EXISTS "public"."hy_spotcheck" (
    "Id" int4 NOT NULL,
    "Spotcheck_Code" varchar(50),
    "Spotcheck_User" character(10),
    "Spotcheck_Time" timestamp without time zone,
    "Spotcheck_Type" varchar(50),
    "CoalSampleCode" varchar(50),
    "SampleCustodian" varchar(50),
    "SamplingTime" timestamp without time zone,
    "QualityIncoming" numeric(18,1),
    "Granularity" varchar(20),
    "SpotcheckCompare" varchar(50),
    "Mt" numeric(18,1),
    "Mad" numeric(18,2),
    "Aad" numeric(18,2) NOT NULL,
    "Ad" numeric(18,2),
    "Vad" numeric(18,2),
    "Vdaf" numeric(18,2),
    "Var" numeric(18,2),
    "St_ad" numeric(18,2),
    "St_d" numeric(18,2),
    "Qb_ad" numeric(18,3),
    "Had" numeric(18,2),
    "Qnet_ar" numeric(18,2),
    "Qnet_ar1" numeric(18,2),
    "Qgr_d" numeric(18,2),
    "Qgr_ad" numeric(18,3),
    "Vd" numeric(18,2),
    "Aar" numeric(18,2),
    "St_ar" numeric(18,2),
    "Hd" numeric(18,2),
    "FCad" numeric(18,2),
    "CRC" numeric(18,0),
    "St_daf" numeric(18,2),
    CONSTRAINT "PK_HY_Spotcheck" PRIMARY KEY ("Id")
);

-- 任务表
CREATE TABLE IF NOT EXISTS "public"."hy_task" (
    "id" int4 NOT NULL,
    "task_name" varchar(255),
    "task_type" varchar(255),
    "task_num" varchar(255),
    "is_auto" boolean,
    "task_time" date,
    "state" int4,
    "create_by" varchar(64),
    "create_time" timestamp without time zone,
    "update_by" varchar(64),
    "update_time" timestamp without time zone,
    CONSTRAINT "hy_task_pkey" PRIMARY KEY ("id")
);

-- 温湿度表
CREATE TABLE IF NOT EXISTS "public"."hy_warmhumid" (
    "id" int4 NOT NULL,
    "laboratoryid" int4,
    "temperature" numeric(18,2),
    "humidity" numeric(18,2),
    "begintime" timestamp without time zone,
    "endtime" timestamp without time zone,
    "username" varchar(50),
    CONSTRAINT "PK_HY_warmhumid" PRIMARY KEY ("id")
);

-- 重量输入表
CREATE TABLE IF NOT EXISTS "public"."hy_weight_input" (
    "id" int4 NOT NULL,
    "information_id" int4 NOT NULL,
    "information_norm_id" int4 NOT NULL,
    CONSTRAINT "PK__hy_weigh__3213E83F7BF969DE" PRIMARY KEY ("id")
);

-- 添加注释
COMMENT ON TABLE "public"."hy_allot" IS '化验分配表';
COMMENT ON TABLE "public"."hy_fullwatersample" IS '全水样品表';
COMMENT ON TABLE "public"."hy_informationnorm" IS '化验信息规范表';
COMMENT ON TABLE "public"."hy_itemdetail" IS '化验项目明细表';
COMMENT ON TABLE "public"."hy_laboratoryinstrument" IS '实验室仪器表';
COMMENT ON TABLE "public"."hy_materialanalysis_type" IS '物料分析类型表';
COMMENT ON TABLE "public"."hy_materialdetail" IS '物料明细表';
COMMENT ON TABLE "public"."hy_norm" IS '化验规范表';
COMMENT ON TABLE "public"."hy_sample_collection_detail" IS '样品采集明细表';
COMMENT ON TABLE "public"."hy_sample_delivery" IS '样品交付表';
COMMENT ON TABLE "public"."hy_spotcheck" IS '抽查表';
COMMENT ON TABLE "public"."hy_task" IS '任务表';
COMMENT ON TABLE "public"."hy_warmhumid" IS '温湿度表';
COMMENT ON TABLE "public"."hy_weight_input" IS '重量输入表';
