-- *****************************
-- 创建人员: 杨坤安
-- 创建时间: 2024-08-14
-- 功能描述: 产品档案填报
-- *****************************


DROP TABLE IF EXISTS sdi_oth.ods_product_info;
CREATE TABLE sdi_oth.ods_product_info (
product_code                varchar(100) not null primary key
,product_name               varchar(100)
,bu_name                    varchar(100)
,pl_name                    varchar(100)
,pr_code                    varchar(100)
,pr_name                    varchar(100)
,pi_code                    varchar(100)
,pi_name                    varchar(100)
,sale_status                varchar(100)
,is_need_predict            varchar(100)
,main_product_code          varchar(100)
,main_product_name          varchar(100)
,alc_degree                 varchar(20)
,spec                       varchar(100)
,cover_rate                 varchar(100)
,aroma_type                 varchar(100)
,price_in                   numeric
,price_out                  numeric
,update_date                varchar(50)
,update_by                  varchar(50)
);

-- 为表添加注释
COMMENT ON TABLE sdi_oth.ods_product_info IS '产品档案填报表';

-- 为字段添加注释
COMMENT ON COLUMN sdi_oth.ods_product_info.product_code IS '产品编码';
COMMENT ON COLUMN sdi_oth.ods_product_info.product_name IS '产品名称';
COMMENT ON COLUMN sdi_oth.ods_product_info.bu_name IS '产品所属事业部';
COMMENT ON COLUMN sdi_oth.ods_product_info.pl_name IS '产品线';
COMMENT ON COLUMN sdi_oth.ods_product_info.pr_code IS '产品系列编码';
COMMENT ON COLUMN sdi_oth.ods_product_info.pr_name IS '产品系列名称';
COMMENT ON COLUMN sdi_oth.ods_product_info.pi_code IS '品项编码';
COMMENT ON COLUMN sdi_oth.ods_product_info.pi_name IS '品项名称';
COMMENT ON COLUMN sdi_oth.ods_product_info.sale_status IS '销售状态';
COMMENT ON COLUMN sdi_oth.ods_product_info.is_need_predict IS '是否纳入需求预测统计';
COMMENT ON COLUMN sdi_oth.ods_product_info.main_product_code IS '主产品编码';
COMMENT ON COLUMN sdi_oth.ods_product_info.main_product_name IS '主产品名称';
COMMENT ON COLUMN sdi_oth.ods_product_info.alc_degree IS '酒精度数';
COMMENT ON COLUMN sdi_oth.ods_product_info.spec IS '规格';
COMMENT ON COLUMN sdi_oth.ods_product_info.cover_rate IS '转换率';
COMMENT ON COLUMN sdi_oth.ods_product_info.aroma_type IS '香型';
COMMENT ON COLUMN sdi_oth.ods_product_info.price_in IS '计划内价格';
COMMENT ON COLUMN sdi_oth.ods_product_info.price_out IS '计划外价格';
COMMENT ON COLUMN sdi_oth.ods_product_info.update_date IS '更新时间';
COMMENT ON COLUMN sdi_oth.ods_product_info.update_by IS '更新人';

truncate table sdi_oth.ods_product_info;
select * from sdi_oth.ods_product_info order by is_need_predict desc;
select * from sdi_oth.ods_product_info order by update_date desc;

select * from sdi_oth.ods_product_info where product_code = '1030320';

select count(1) from sdi_oth.ods_product_info;

    
-- 将dim_product产品档案表数据同步到产品档案填报表中

insert into sdi_oth.ods_product_info
SELECT
product_code
,product_name
,b.fist_dept_name as bu_name
,pl_name
,pr_code
,pr_name
,pi_code
,pi_name
,sale_status
,'' AS is_need_predict
,product_code as main_product_code
,product_name as main_product_name
,alc_degree
,spec
,pack_base_num
,aroma_type
,price_in
,price_out
,update_time
,update_by
FROM dwr.dim_product a
left join
(
    select
        fist_dept_code
        ,fist_dept_name
    from dwr.dim_department
    group by
        fist_dept_code
           ,fist_dept_name

)b
on a.bu_code = b.fist_dept_code;



select distinct  sale_status from dwr.dim_product

-- 产品档案维度表
select
    *
from dwr.dim_product
where product_name = '酱香调味酒散酒酒体'
;

-- 【1_report_产品编码】

select
    product_code
     ,product_name
from dwr.dim_product
;

select
    distinct
    pi_name
 from dwr.dim_product
;
select distinct fist_dept_code ,fist_dept_name from dwr.dim_department
