-- 化验明细添加槽号对应名称字段
ALTER TABLE mes_assay_content_detail
	ADD slot_name VARCHAR2(100) NULL;
COMMENT ON COLUMN mes_assay_content_detail.slot_name IS '槽名称';

-- 摸具申报添加字段
ALTER TABLE mes_mold_plan
	ADD stock_num NUMBER(8, 0) NULL;
COMMENT ON COLUMN mes_mold_plan.stock_num IS '库存量';
ALTER TABLE mes_mold_plan
	ADD occupy_num NUMBER(8, 0) NULL;
COMMENT ON COLUMN mes_mold_plan.occupy_num IS '占用量';
ALTER TABLE mes_mold_plan
	ADD link_order_ids VARCHAR2(255) NULL;
COMMENT ON COLUMN mes_mold_plan.link_order_ids IS 'LINK_ORDER_IDS';

-- 字段长度修改
ALTER TABLE mes_assay_content
	MODIFY wc_id NUMBER(20, 0);
ALTER TABLE mes_assay_content
	MODIFY assay_man NUMBER(20, 0);
ALTER TABLE mes_assay_content
	MODIFY apply_id NUMBER(20, 0);
ALTER TABLE mes_assay_content
	MODIFY apply_status NUMBER(8, 0) DEFAULT 0;
ALTER TABLE mes_assay_content
	MODIFY is_used NUMBER(8, 0);
ALTER TABLE mes_assay_content_detail
	MODIFY ac_id NUMBER(20, 0);
ALTER TABLE mes_mold_plan
	MODIFY erp_id NUMBER(20, 0);
ALTER TABLE mes_mold_plan
	MODIFY yp_id NUMBER(20, 0);
ALTER TABLE mes_mold_plan
	MODIFY keeper NUMBER(20, 0);
ALTER TABLE mes_mold_plan
	MODIFY releaser NUMBER(20, 0);
ALTER TABLE mes_plate_goods_apply
	MODIFY bo_id NUMBER(20, 0);
ALTER TABLE mes_plate_goods_apply
	MODIFY br_id NUMBER(20, 0);
ALTER TABLE mes_plate_goods_apply
	MODIFY ac_id NUMBER(20, 0);
ALTER TABLE mes_plate_goods_apply
	MODIFY pgr_id NUMBER(20, 0);
ALTER TABLE mes_plate_goods_apply
	MODIFY wc_id NUMBER(20, 0);
ALTER TABLE mes_plate_goods_record
	MODIFY wc_id NUMBER(20, 0);
ALTER TABLE mes_plate_goods_record
	MODIFY approval_status NUMBER(20, 0);
ALTER TABLE mes_plate_goods_record
	MODIFY goods_bo_id NUMBER(20, 0);
ALTER TABLE mes_plate_goods_record
	MODIFY coefficient_bo_id NUMBER(20, 0);
ALTER TABLE mes_plate_goods_record_detail
	MODIFY pgrd_id NUMBER(20, 0);

ALTER TABLE mes_plate_goods_record
	ADD involving_record_code VARCHAR2(255) NULL;
COMMENT ON COLUMN mes_plate_goods_record.involving_record_code IS '本次添加涉及单号';
ALTER TABLE mes_plate_goods_record
	ADD detail_order_num NUMBER(8, 0) NULL;
COMMENT ON COLUMN mes_plate_goods_record.detail_order_num IS '本次关联订单数量';

ALTER TABLE mes_assay_content_detail
	ADD add_val NUMBER(20, 10) NULL;
COMMENT ON COLUMN mes_assay_content_detail.add_val IS '添加量值';

ALTER TABLE mes_yield_order
	ADD goods_demand NUMBER(20,10) NULL;
COMMENT ON COLUMN mes_yield_order.goods_demand IS '物料需求数量';

ALTER TABLE mes_yield_order
	ADD tools_demand NUMBER(20,10) NULL;
COMMENT ON COLUMN mes_yield_order.tools_demand IS '工装需求数量';

ALTER TABLE mes_yield_order
	ADD PLATE_GOODS_CODE NVARCHAR2(255) NULL;
COMMENT ON COLUMN mes_yield_order.PLATE_GOODS_CODE IS '需求镀层物料编码';

CREATE TABLE mes_mold_apply
(
	id             NUMBER(20, 0)   NOT NULL ENABLE,
	tenant_id      NVARCHAR2(12),
	create_user    NUMBER(20, 0),
	create_time    DATE,
	create_dept    NUMBER(20, 0),
	update_user    NUMBER(20, 0),
	update_time    DATE,
	status         NUMBER(11, 0)   NOT NULL ENABLE,
	is_deleted     NUMBER(11, 0),
	part_code      VARCHAR2(255)   NULL,
	part_name      VARCHAR2(255)   NULL,
	tool_code      VARCHAR2(255)   NULL,
	tool_name      VARCHAR2(255)   NULL,
	apply_num      NUMBER(20,10) NULL,
	plan_type_code VARCHAR2(255)   NULL,
	plan_type_name VARCHAR2(255)   NULL,
	need_date      DATE            NULL,
	qua_level      VARCHAR2(255)   NULL,
	maf_type       DECIMAL(10, 0)  NULL,
	keeper         DECIMAL(20, 0)  NULL,
	releaser       VARCHAR2(255)   NULL,
	memo           VARCHAR2(255)   NULL
) TABLESPACE jonhon_mes_data;
COMMENT ON TABLE mes_mold_apply IS '烧结模具计划-申报';
COMMENT ON COLUMN mes_mold_apply.id IS '主键';
COMMENT ON COLUMN mes_mold_apply.create_user IS '创建人';
COMMENT ON COLUMN mes_mold_apply.create_time IS '创建时间';
COMMENT ON COLUMN mes_mold_apply.create_dept IS '创建部门';
COMMENT ON COLUMN mes_mold_apply.update_user IS '更新人';
COMMENT ON COLUMN mes_mold_apply.update_time IS '更新时间';
COMMENT ON COLUMN mes_mold_apply.status IS '状态';
COMMENT ON COLUMN mes_mold_apply.is_deleted IS '删除标记';
COMMENT ON COLUMN mes_mold_apply.part_code IS '零件编码';
COMMENT ON COLUMN mes_mold_apply.part_name IS '零件名称';
COMMENT ON COLUMN mes_mold_apply.tool_code IS '工装编码';
COMMENT ON COLUMN mes_mold_apply.tool_name IS '工装名称';
COMMENT ON COLUMN mes_mold_apply.apply_num IS '申报数量';
COMMENT ON COLUMN mes_mold_apply.plan_type_code IS '计划类型; 13001:Z:制造(工装不为空且工装名称为压饼模),13002:D:夹具(工装不为空且工装名称为石墨模)';
COMMENT ON COLUMN mes_mold_apply.plan_type_name IS '计划类型; 13001:Z:制造(工装不为空且工装名称为压饼模),13002:D:夹具(工装不为空且工装名称为石墨模)';
COMMENT ON COLUMN mes_mold_apply.need_date IS '需求日期';
COMMENT ON COLUMN mes_mold_apply.qua_level IS '生产标识';
COMMENT ON COLUMN mes_mold_apply.maf_type IS '类型; 12001、热表，烧结，12002、仓库';
COMMENT ON COLUMN mes_mold_apply.keeper IS '保管员';
COMMENT ON COLUMN mes_mold_apply.releaser IS '下达人';
COMMENT ON COLUMN mes_mold_apply.memo IS '备注';


CREATE TABLE mes_mold_demand
(
	id             NUMBER(20, 0)   NOT NULL ENABLE,
	tenant_id      NVARCHAR2(12),
	create_user    NUMBER(20, 0),
	create_time    DATE,
	create_dept    NUMBER(20, 0),
	update_user    NUMBER(20, 0),
	update_time    DATE,
	status         NUMBER(11, 0)   NOT NULL ENABLE,
	is_deleted     NUMBER(11, 0),
	md_code        VARCHAR2(255)   NULL,
	part_code      VARCHAR2(255)   NULL,
	part_name      VARCHAR2(255)   NULL,
	tool_code      VARCHAR2(255)   NULL,
	tool_name      VARCHAR2(255)   NULL,
	demand_num     NUMBER(20,10) NULL,
	plan_type_code VARCHAR2(255)   NULL,
	plan_type_name VARCHAR2(255)   NULL,
	need_date      DATE            NULL,
	qua_level      VARCHAR2(255)   NULL,
	maf_type       DECIMAL(10, 0)  NULL,
	keeper         DECIMAL(20, 0)  NULL,
	releaser       VARCHAR2(255)   NULL,
	memo           VARCHAR2(255)   NULL,
	"SOURCE"       DECIMAL(8, 0)   NULL,
	stock_num      NUMBER(20,10) NULL,
	occupy_num     NUMBER(20,10) NULL,
	link_order_ids VARCHAR2(255)   NULL,
	mo_code        VARCHAR2(100)   NULL,
	mo_name        VARCHAR2(100)   NULL,
	quantity       NUMBER(20,10) NULL,
	yp_id          DECIMAL(20, 0)  NULL,
	erp_id         DECIMAL(20, 0)  NULL,
	erp_wo_code    VARCHAR2(100)   NULL,
	maf_status     DECIMAL(8, 0)   NULL,
	urgent_type    VARCHAR2(100)   NULL
) TABLESPACE jonhon_mes_data;
COMMENT ON TABLE mes_mold_demand IS '烧结模具计划-需求';
COMMENT ON COLUMN mes_mold_demand.id IS '主键';
COMMENT ON COLUMN mes_mold_demand.create_user IS '创建人';
COMMENT ON COLUMN mes_mold_demand.create_time IS '创建时间';
COMMENT ON COLUMN mes_mold_demand.create_dept IS '创建部门';
COMMENT ON COLUMN mes_mold_demand.update_user IS '更新人';
COMMENT ON COLUMN mes_mold_demand.update_time IS '更新时间';
COMMENT ON COLUMN mes_mold_demand.status IS '状态';
COMMENT ON COLUMN mes_mold_demand.is_deleted IS '删除标记';
COMMENT ON COLUMN mes_mold_demand.md_code IS '需求单号';
COMMENT ON COLUMN mes_mold_demand.part_code IS '零件编码';
COMMENT ON COLUMN mes_mold_demand.part_name IS '零件名称';
COMMENT ON COLUMN mes_mold_demand.tool_code IS '工装编码';
COMMENT ON COLUMN mes_mold_demand.tool_name IS '工装名称';
COMMENT ON COLUMN mes_mold_demand.demand_num IS '需求数量';
COMMENT ON COLUMN mes_mold_demand.plan_type_code IS '计划类型; 13001:Z:制造(工装不为空且工装名称为压饼模),13002:D:夹具(工装不为空且工装名称为石墨模)';
COMMENT ON COLUMN mes_mold_demand.plan_type_name IS '计划类型; 13001:Z:制造(工装不为空且工装名称为压饼模),13002:D:夹具(工装不为空且工装名称为石墨模)';
COMMENT ON COLUMN mes_mold_demand.need_date IS '需求日期';
COMMENT ON COLUMN mes_mold_demand.qua_level IS '生产标识';
COMMENT ON COLUMN mes_mold_demand.maf_type IS '类型; 12001、热表，烧结，12002、仓库';
COMMENT ON COLUMN mes_mold_demand.keeper IS '保管员';
COMMENT ON COLUMN mes_mold_demand.releaser IS '下达人';
COMMENT ON COLUMN mes_mold_demand.memo IS '备注';
COMMENT ON COLUMN mes_mold_demand."SOURCE" IS '计划来源;15001:自动生成，15002：人工添加';
COMMENT ON COLUMN mes_mold_demand.stock_num IS '库存量';
COMMENT ON COLUMN mes_mold_demand.occupy_num IS '占用量';
COMMENT ON COLUMN mes_mold_demand.link_order_ids IS '关联生产订单, 多个订单以'',''分割';
COMMENT ON COLUMN mes_mold_demand.mo_code IS '模具编码';
COMMENT ON COLUMN mes_mold_demand.mo_name IS '模具名称';
COMMENT ON COLUMN mes_mold_demand.quantity IS '数量';
COMMENT ON COLUMN mes_mold_demand.yp_id IS '生产计划id';
COMMENT ON COLUMN mes_mold_demand.erp_id IS 'erpId';
COMMENT ON COLUMN mes_mold_demand.erp_wo_code IS 'erpCode';
COMMENT ON COLUMN mes_mold_demand.maf_status IS '状态; 11001、新建，11002:已下发，11003、已完成';
COMMENT ON COLUMN mes_mold_demand.urgent_type IS '紧急状态';

CREATE TABLE mes_mold_demand_detail
(
	id          NUMBER(20, 0) NOT NULL ENABLE,
	tenant_id   NVARCHAR2(12),
	create_user NUMBER(20, 0),
	create_time DATE,
	create_dept NUMBER(20, 0),
	update_user NUMBER(20, 0),
	update_time DATE,
	status      NUMBER(11, 0) NOT NULL ENABLE,
	is_deleted  NUMBER(11, 0),
	md_id       NUMBER(20, 0) NULL,
	order_id    NUMBER(20, 0) NULL
) TABLESPACE jonhon_mes_data;
COMMENT ON TABLE mes_mold_demand_detail IS '烧结模具计划-订单关联表';
COMMENT ON COLUMN mes_mold_demand_detail.id IS '主键';
COMMENT ON COLUMN mes_mold_demand_detail.create_user IS '创建人';
COMMENT ON COLUMN mes_mold_demand_detail.create_time IS '创建时间';
COMMENT ON COLUMN mes_mold_demand_detail.create_dept IS '创建部门';
COMMENT ON COLUMN mes_mold_demand_detail.update_user IS '更新人';
COMMENT ON COLUMN mes_mold_demand_detail.update_time IS '更新时间';
COMMENT ON COLUMN mes_mold_demand_detail.status IS '状态';
COMMENT ON COLUMN mes_mold_demand_detail.is_deleted IS '删除标记';
COMMENT ON COLUMN mes_mold_demand_detail.md_id IS '烧结模具计划需求ID';
COMMENT ON COLUMN mes_mold_demand_detail.order_id IS '生产订单id';

ALTER TABLE mes_yield_plan
	ADD generate_glass_cake SMALLINT DEFAULT 0 NULL;
COMMENT ON COLUMN mes_yield_plan.generate_glass_cake IS '是否生成玻璃饼订单, 0:否，1：是';

ALTER TABLE mes_yield_plan
	ADD check_close_time DATE NULL;
COMMENT ON COLUMN mes_yield_plan.check_close_time IS '验证关闭时间';
ALTER TABLE mes_yield_plan
    ADD check_totqty_time DATE NULL;
COMMENT ON COLUMN mes_yield_plan.check_totqty_time IS '验证完工数时间';

ALTER TABLE mes_recorder
    MODIFY (recorder NVARCHAR2(255));
--varchar不允许修改为clob类型，所以先删除再添加
ALTER TABLE mes_recorder
    DROP COLUMN memo;
ALTER TABLE mes_recorder
    ADD (memo CLOB);

ALTER TABLE mes_plate_goods_record RENAME COLUMN plate_goods_code TO goods_code;

DROP TABLE mes_plate_goods_apply_detail;
CREATE TABLE mes_plate_goods_apply_detail
(
    id          NUMBER(20, 0) NOT NULL ENABLE,
    tenant_id   NVARCHAR2(12),
    create_user NUMBER(20, 0),
    create_time DATE,
    create_dept NUMBER(20, 0),
    update_user NUMBER(20, 0),
    update_time DATE,
    status      NUMBER(11, 0) NOT NULL ENABLE,
    is_deleted  NUMBER(11, 0),
    pga_id      NUMBER(20, 0),
    yo_id       NVARCHAR2(255)
) TABLESPACE jonhon_mes_data;
COMMENT ON TABLE mes_plate_goods_apply_detail IS '烧结模具计划-申报';
COMMENT ON COLUMN mes_plate_goods_apply_detail.id IS '主键';
COMMENT ON COLUMN mes_plate_goods_apply_detail.create_user IS '创建人';
COMMENT ON COLUMN mes_plate_goods_apply_detail.create_time IS '创建时间';
COMMENT ON COLUMN mes_plate_goods_apply_detail.create_dept IS '创建部门';
COMMENT ON COLUMN mes_plate_goods_apply_detail.update_user IS '更新人';
COMMENT ON COLUMN mes_plate_goods_apply_detail.update_time IS '更新时间';
COMMENT ON COLUMN mes_plate_goods_apply_detail.status IS '状态';
COMMENT ON COLUMN mes_plate_goods_apply_detail.is_deleted IS '删除标记';
COMMENT ON COLUMN mes_plate_goods_apply_detail.pga_id IS '添加量申报ID';
COMMENT ON COLUMN mes_plate_goods_apply_detail.yo_id IS '生产订单ID';

-- MES_PLATE_GOODS_APPLY definition

-- DDL generated by DBeaver
-- WARNING: It may differ from actual native database DDL

-- Drop table

DROP TABLE mes_plate_goods_apply;
CREATE TABLE mes_plate_goods_apply
(
    id                         NUMBER(20, 0)            NOT NULL ENABLE,
    tenant_id                  NVARCHAR2(12),
    create_user                NUMBER(20, 0),
    create_time                DATE,
    create_dept                NUMBER(20, 0),
    update_user                NUMBER(20, 0),
    update_time                DATE,
    status                     NUMBER(11, 0)            NOT NULL ENABLE,
    is_deleted                 NUMBER(11, 0)  DEFAULT 0,
    "APPROVAL_MAN"             NUMBER(20, 0),
    "APPROVAL_TIME"            DATE,
    "APPROVAL_STATUS"          NUMBER(20, 0),
    "APPROVAL_MEMO"            NVARCHAR2(255),
    bo_id                      NUMBER(20, 0),
    br_id                      NUMBER(20, 0),
    ac_id                      NUMBER(20, 0),
    pgr_id                     NUMBER(20, 0),
    code_num                   NVARCHAR2(255),
    "WC_ID"                    NUMBER(20, 0)            NOT NULL ENABLE,
    "GOODS_CODE"               NVARCHAR2(255)           NOT NULL ENABLE,
    "GOODS_DEMAND"             NUMBER(20, 10) DEFAULT 0 NOT NULL ENABLE,
    "SILVER_POTASSIUM"         NUMBER(20, 10) DEFAULT 0 NOT NULL ENABLE,
    "COEFFICIENT"              NUMBER(20, 10) DEFAULT 0 NOT NULL ENABLE,
    "DECLARED_QUOTA"           NUMBER(20, 10) DEFAULT 0 NOT NULL ENABLE,
    "DECLARED_SILVER"          NUMBER(20, 10) DEFAULT 0 NOT NULL ENABLE,
    "DECLARED_STATUS"          NUMBER         DEFAULT 0 NOT NULL ENABLE,
    "GOODS_BO_ID"              NUMBER(20, 0),
    "COEFFICIENT_BO_ID"        NUMBER(20, 0),
    "PGR_CODE"                 NVARCHAR2(255),
    "SURPLUS"                  NUMBER(20, 10) DEFAULT 0,
    "SILVER_POTASSIUM_RESIDUE" NUMBER(20, 10) DEFAULT 0,
    "DEMAND_CODE"              VARCHAR2(100),
    "INVOLVING_RECORD_CODE"    VARCHAR2(255),
    "NOT_ADD_VAL"              NUMBER(20, 10),
    "DETAIL_ORDER_NUM"         NUMBER(8, 0),
    PRIMARY KEY (id)
) TABLESPACE "JONHON_MES_DATA";
COMMENT ON TABLE mes_plate_goods_apply IS '镀层物料申报添加量';
COMMENT ON COLUMN mes_plate_goods_apply.id IS '主键';
COMMENT ON COLUMN mes_plate_goods_apply.tenant_id IS '租户ID';
COMMENT ON COLUMN mes_plate_goods_apply.create_user IS '创建人';
COMMENT ON COLUMN mes_plate_goods_apply.create_dept IS '创建部门';
COMMENT ON COLUMN mes_plate_goods_apply.create_time IS '创建时间';
COMMENT ON COLUMN mes_plate_goods_apply.update_user IS '修改人';
COMMENT ON COLUMN mes_plate_goods_apply.update_time IS '修改时间';
COMMENT ON COLUMN mes_plate_goods_apply.status IS '状态';
COMMENT ON COLUMN mes_plate_goods_apply.is_deleted IS '是否已删除';
COMMENT ON COLUMN mes_plate_goods_apply.wc_id IS '作业中心';
COMMENT ON COLUMN mes_plate_goods_apply.goods_code IS '镀层物料';
COMMENT ON COLUMN mes_plate_goods_apply.goods_demand IS '物料需求定额';
COMMENT ON COLUMN mes_plate_goods_apply.silver_potassium IS '上报银钾';
COMMENT ON COLUMN mes_plate_goods_apply.coefficient IS '银钾系数';
COMMENT ON COLUMN mes_plate_goods_apply.approval_man IS '审批人';
COMMENT ON COLUMN mes_plate_goods_apply.approval_time IS '审批时间';
COMMENT ON COLUMN mes_plate_goods_apply.approval_status IS '审批状态';
COMMENT ON COLUMN mes_plate_goods_apply.approval_memo IS '审批结果';
COMMENT ON COLUMN mes_plate_goods_apply.declared_quota IS '已申报定额';
COMMENT ON COLUMN mes_plate_goods_apply.declared_silver IS '已申报银钾';
COMMENT ON COLUMN mes_plate_goods_apply.declared_status IS '申报状态';
COMMENT ON COLUMN mes_plate_goods_apply.goods_bo_id IS '物料采购id';
COMMENT ON COLUMN mes_plate_goods_apply.coefficient_bo_id IS '银钾采购id';
COMMENT ON COLUMN mes_plate_goods_apply.surplus IS '剩余量';
COMMENT ON COLUMN mes_plate_goods_apply.silver_potassium_residue IS '上报银钾剩余量';
COMMENT ON COLUMN mes_plate_goods_apply.demand_code IS '需求单号';
COMMENT ON COLUMN mes_plate_goods_apply.involving_record_code IS '本次添加涉及单号';
COMMENT ON COLUMN mes_plate_goods_apply.not_add_val IS '本次剩余单号余量';
COMMENT ON COLUMN mes_plate_goods_apply.detail_order_num IS '本次关联订单数量';

ALTER TABLE MES_PLATE_GOODS_APPLY ADD GOODS_NAME VARCHAR2(100) NULL;
COMMENT ON COLUMN MES_PLATE_GOODS_APPLY.GOODS_NAME IS '镀层物料名称';
ALTER TABLE MES_PLATE_GOODS_RECORD ADD GOODS_NAME VARCHAR2(100) NULL;
COMMENT ON COLUMN MES_PLATE_GOODS_RECORD.GOODS_NAME IS '镀层物料名称';
