CREATE TABLE IF NOT EXISTS "product_inputs_buy" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "inputs_buy_id" varchar NOT NULL,
    "relate_outbound_id" varchar,
    "vendor_name" varchar NOT NULL,
    "vendor_id" varchar NOT NULL,
    "inputs_buy_time" datetime NOT NULL,
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "belong_business_id" bigint NOT NULL,
    "belong_business_name" varchar NOT NULL,
    "tenant_id" bigint,
    "deleted" bit NOT NULL DEFAULT FALSE,
    "creator" varchar DEFAULT '',
    "updater" varchar DEFAULT '',
    PRIMARY KEY ("id")
) COMMENT '投入品采购';

CREATE TABLE IF NOT EXISTS "product_inputs_batch" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "inputs_name" varchar NOT NULL,
    "inputs_id" varchar NOT NULL,
    "inputs_batch_id" varchar NOT NULL,
    "inputs_buy_id" varchar NOT NULL,
    "product_data" datetime NOT NULL,
    "inputs_num" int NOT NULL,
    "inputs_unit" varchar,
    "inputs_weight" varchar,
    "inputs_unit_price" varchar,
    "total_price" varchar,
    "remarks" varchar,
    "block_state" bit NOT NULL,
    "block_chain_id" varchar,
    "block_chain_block_identity" varchar,
    "belong_business_id" bigint NOT NULL,
    "belong_business_name" varchar NOT NULL,
    "tenant_id" bigint NOT NULL,
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    "creator" varchar DEFAULT '',
    "updater" varchar DEFAULT '',
    PRIMARY KEY ("id")
) COMMENT '投入品批次';
CREATE TABLE IF NOT EXISTS "product_harvest_info" (
  "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
  "harverst_id" varchar NOT NULL,
  "harverst_time" datetime NOT NULL,
  "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  "belong_business_id" bigint NOT NULL,
  "belong_business_name" varchar NOT NULL,
  "tenant_id" bigint NOT NULL,
  "deleted" bit NOT NULL DEFAULT FALSE,
  "block_chain_block_identity" varchar,
  "block_state" bit NOT NULL,
  "block_chain_id" bigint,
  "creator" varchar DEFAULT '',
  "updater" varchar DEFAULT '',
  PRIMARY KEY ("id")
) COMMENT '采收入库';
CREATE TABLE IF NOT EXISTS "product_harvest_batch" (
   "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
   "harvest_batch_id" varchar NOT NULL,
   "harvest_id" varchar NOT NULL,
   "harvest_date" datetime NOT NULL,
   "goods_name" varchar NOT NULL,
   "goods_id" varchar NOT NULL,
   "goods_num" int,
   "block_chain_id" bigint,
   "block_chain_block_identity" varchar,
   "block_state" bit NOT NULL,
   "template_name" varchar,
   "template_id" varchar,
   "remarks" varchar,
   "tenant_id" bigint NOT NULL,
   "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
   "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
   "belong_business_id" bigint NOT NULL,
   "belong_business_name" varchar NOT NULL,
   "deleted" bit NOT NULL DEFAULT FALSE,
   "creator" varchar DEFAULT '',
   "updater" varchar DEFAULT '',
   PRIMARY KEY ("id")
) COMMENT '采收批次';
CREATE TABLE IF NOT EXISTS "product_slave_device" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "device_name" varchar,
    "env_type" bigint,
    "belong_business_id" bigint NOT NULL,
    "belong_business_name" varchar NOT NULL,
    "tenant_id" bigint NOT NULL,
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    "creator" varchar DEFAULT '',
    "updater" varchar DEFAULT '',
    PRIMARY KEY ("id")
) COMMENT '从(子)设备信息';
CREATE TABLE IF NOT EXISTS "product_land_info" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "land_name" varchar,
    "land_id" varchar,
    "size" varchar,
    "state" varchar,
    "remarks" varchar,
    "land_type" varchar,
    "belong_business_id" bigint NOT NULL,
    "belong_business_name" varchar NOT NULL,
    "tenant_id" bigint NOT NULL,
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    "creator" varchar DEFAULT '',
    "updater" varchar DEFAULT '',
    PRIMARY KEY ("id")
) COMMENT '农事土地信息';
CREATE TABLE IF NOT EXISTS "product_land_plan" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "land_id" varchar NOT NULL,
    "land_name" varchar NOT NULL,
    "land_plan_id" varchar NOT NULL,
    "goods_id" varchar NOT NULL,
    "good_name" varchar NOT NULL,
    "plan_start_time" datetime NOT NULL,
    "plan_end_time" datetime NOT NULL,
    "belong_business_id" bigint NOT NULL,
    "belong_business_name" varchar NOT NULL,
    "remark" varchar,
    "tenant_id" bigint NOT NULL,
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    "creator" varchar DEFAULT '',
    "updater" varchar DEFAULT '',
    PRIMARY KEY ("id")
) COMMENT '地块作业计划';
CREATE TABLE IF NOT EXISTS "product_land_job" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "land_id" varchar NOT NULL,
    "land_name" varchar NOT NULL,
    "land_type" varchar NOT NULL,
    "job_type" varchar NOT NULL,
    "job_worker" varchar NOT NULL,
    "job_worker_id" bigint NOT NULL,
    "job_date" datetime NOT NULL,
    "remarks" varchar,
    "belong_business_id" bigint NOT NULL,
    "belong_business_name" varchar NOT NULL,
    "tenant_id" bigint NOT NULL,
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "block_state" varchar,
    "deleted" bit NOT NULL DEFAULT FALSE,
    "creator" varchar DEFAULT '',
    "updater" varchar DEFAULT '',
    PRIMARY KEY ("id")
) COMMENT '种植/养殖/畜牧作业';
CREATE TABLE IF NOT EXISTS "product_harvest_batch" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "harvest_batch_id" varchar NOT NULL,
    "harvest_id" varchar NOT NULL,
    "harvest_date" datetime NOT NULL,
    "goods_name" varchar NOT NULL,
    "goods_id" varchar NOT NULL,
    "goods_num" int,
    "block_chain_id" bigint,
    "block_chain_block_identity" varchar,
    "block_state" bit NOT NULL,
    "template_name" varchar,
    "template_id" varchar,
    "remarks" varchar,
    "tenant_id" bigint NOT NULL,
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "belong_business_id" bigint NOT NULL,
    "belong_business_name" varchar NOT NULL,
    "deleted" bit NOT NULL DEFAULT FALSE,
    "creator" varchar DEFAULT '',
    "updater" varchar DEFAULT '',
    PRIMARY KEY ("id")
) COMMENT '采收批次';
CREATE TABLE IF NOT EXISTS "product_land_job_inputs" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "land_job_id" bigint NOT NULL,
    "inputs_name" varchar NOT NULL,
    "inputs_id" varchar NOT NULL,
    "inputs_batch_id" varchar NOT NULL,
    "inputs_num" int NOT NULL,
    "inputs_unit" varchar,
    "inputs_desc" varchar,
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "belong_business_id" bigint NOT NULL,
    "belong_business_name" varchar NOT NULL,
    "tenant_id" bigint NOT NULL,
    "deleted" bit NOT NULL DEFAULT FALSE,
    "creator" varchar DEFAULT '',
    "updater" varchar DEFAULT '',
    PRIMARY KEY ("id")
) COMMENT '地块作业投入品';
CREATE TABLE IF NOT EXISTS "product_inspection" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "inspection_id" varchar NOT NULL,
    "goods_id" varchar NOT NULL,
    "goods_name" varchar NOT NULL,
    "harvest_id" varchar NOT NULL,
    "harvest_time" datetime NOT NULL,
    "inspection_standard" varchar NOT NULL,
    "inspection_result" int NOT NULL,
    "inspection_own_item" varchar NOT NULL,
    "inspection_user" varchar NOT NULL,
    "inspection_entrust_item" varchar,
    "inspection_entrust_user" varchar,
    "inspection_date" datetime NOT NULL,
    "inspection_level" varchar,
    "issuance_date" datetime,
    "block_state" int NOT NULL,
    "block_chain_id" varchar,
    "block_chain_block_identity" varchar,
    "belong_business_id" bigint NOT NULL,
    "belong_business_name" varchar NOT NULL,
    "tenant_id" bigint NOT NULL,
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    "creator" varchar DEFAULT '',
    "updater" varchar DEFAULT '',
    PRIMARY KEY ("id")
) COMMENT '检验检疫';
CREATE TABLE IF NOT EXISTS "product_inspection_item" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "inspection_id" varchar NOT NULL,
    "inspection_item_id" varchar NOT NULL,
    "inspection_item" varchar NOT NULL,
    "inspection_unit" varchar NOT NULL,
    "inspection_require" varchar NOT NULL,
    "inspection_result" varchar NOT NULL,
    "inspection_conclusion" varchar NOT NULL,
    "belong_business_id" bigint NOT NULL,
    "belong_business_name" varchar NOT NULL,
    "tenant_id" bigint NOT NULL,
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    "creator" varchar DEFAULT '',
    "updater" varchar DEFAULT '',
    PRIMARY KEY ("id")
) COMMENT '检验-检测项目';
CREATE TABLE IF NOT EXISTS "product_device_info" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "device_name" varchar,
    "land_id" varchar,
    "gateway_type" int,
    "device_type" int NOT NULL,
    "env_type" bigint,
    "controller_type" bigint,
    "monitor_type" int,
    "enabled" bit NOT NULL,
    "switch_on" bit NOT NULL,
    "close_instruction" varchar,
    "open_instruction" varchar,
    "remarks" varchar,
    "belong_business_id" bigint NOT NULL,
    "belong_business_name" varchar NOT NULL,
    "tenant_id" bigint NOT NULL,
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    "creator" varchar DEFAULT '',
    "updater" varchar DEFAULT '',
    PRIMARY KEY ("id")
) COMMENT '设备信息';
CREATE TABLE IF NOT EXISTS "product_device_operate_log" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "device_info_id" bigint NOT NULL,
    "device_name" varchar,
    "land_id" varchar NOT NULL,
    "operate_detail" varchar,
    "tenant_id" bigint NOT NULL,
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    "creator" varchar DEFAULT '',
    "updater" varchar DEFAULT '',
    PRIMARY KEY ("id")
) COMMENT '设备操作日志';
CREATE TABLE IF NOT EXISTS "product_env_type" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "env_name" varchar,
    "env_field_name" varchar NOT NULL,
    "remarks" varchar,
    "belong_business_id" bigint NOT NULL,
    "belong_business_name" varchar NOT NULL,
    "tenant_id" bigint NOT NULL,
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    "creator" varchar DEFAULT '',
    "updater" varchar DEFAULT '',
    PRIMARY KEY ("id")
) COMMENT '环境类型';
CREATE TABLE IF NOT EXISTS "product_env_data" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "env_type_id" bigint,
    "env_name" varchar,
    "land_id" varchar,
    "value" varchar,
    "belong_business_id" bigint NOT NULL,
    "belong_business_name" varchar NOT NULL,
    "tenant_id" bigint NOT NULL,
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    "creator" varchar DEFAULT '',
    "updater" varchar DEFAULT '',
    PRIMARY KEY ("id")
) COMMENT '环境数据';
CREATE TABLE IF NOT EXISTS "product_controller_type" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "controller_name" varchar,
    "con_field_name" varchar NOT NULL,
    "remarks" varchar,
    "belong_business_id" bigint NOT NULL,
    "belong_business_name" varchar NOT NULL,
    "tenant_id" bigint NOT NULL,
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    "creator" varchar DEFAULT '',
    "updater" varchar DEFAULT '',
    PRIMARY KEY ("id")
) COMMENT '控制器类型';
CREATE TABLE IF NOT EXISTS "product_land_job_type" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "type_name" varchar NOT NULL,
    "belong_business_id" bigint NOT NULL,
    "belong_business_name" varchar NOT NULL,
    "tenant_id" bigint NOT NULL,
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    "creator" varchar DEFAULT '',
    "updater" varchar DEFAULT '',
    PRIMARY KEY ("id")
) COMMENT '作业类型';
CREATE TABLE IF NOT EXISTS "product_land_info_type" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "land_type_name" varchar NOT NULL,
    "belong_business_id" bigint NOT NULL,
    "belong_business_name" varchar NOT NULL,
    "tenant_id" bigint NOT NULL,
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    "creator" varchar DEFAULT '',
    "updater" varchar DEFAULT '',
    PRIMARY KEY ("id")
) COMMENT '地块类型';
CREATE TABLE IF NOT EXISTS "product_land_block_state" (
    "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
    "land_state_name" varchar NOT NULL,
    "belong_business_id" bigint NOT NULL,
    "belong_business_name" varchar NOT NULL,
    "tenant_id" bigint NOT NULL,
    "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    "deleted" bit NOT NULL DEFAULT FALSE,
    "creator" varchar DEFAULT '',
    "updater" varchar DEFAULT '',
    PRIMARY KEY ("id")
) COMMENT '地块状态';
