-- ===================================================
-- 服装成品款式档案表同步SQL
-- 源表：X6_STOCK_DEV.A3_STYLE
-- 目标表：dw_style_archive
-- 创建时间：2026-01-20
-- ===================================================

-- 1. 全量同步SQL（带分页参数）
-- 参数：:page_size, :offset
INSERT INTO dw_style_archive (style_id, style_name, brand_code, brand_name, style_year, style_state, j_price, x_price, v_price, j_cost, clerk_royaltyrate, clerk_royaltyprice, create_date, category_code, category_name, style_class_code, style_class, style_subclass_code, style_subclass, style_styles_code, style_styles, style_sex_code, style_sex, style_kind_code, style_kind, style_unit_code, style_unit, style_month_code, style_month, style_band_code, style_band, style_theme_code, style_theme, style_saletype_code, style_saletype, style_designer_code, style_designer, style_plater_code, style_plater, style_locate_code, style_locate, sizegrp_id, sizegrp_name, style_sort, style_supplier_code, style_supplier)
SELECT 
    style_id,
    style_name,
    brand_code,
    brand_name,
    style_year,
    style_state,
    j_price,
    x_price,
    v_price,
    j_cost,
    clerk_royaltyrate,
    clerk_royaltyprice,
    create_date,
    category_code,
    category_name,
    style_class_code,
    style_class,
    style_subclass_code,
    style_subclass,
    style_styles_code,
    style_styles,
    style_sex_code,
    style_sex,
    style_kind_code,
    style_kind,
    style_unit_code,
    style_unit,
    style_month_code,
    style_month,
    style_band_code,
    style_band,
    style_theme_code,
    style_theme,
    style_saletype_code,
    style_saletype,
    style_designer_code,
    style_designer,
    style_plater_code,
    style_plater,
    style_locate_code,
    style_locate,
    sizegrp_id,
    sizegrp_name,
    style_sort,
    style_supplier_code,
    style_supplier
FROM X6_STOCK_DEV.A3_STYLE
ORDER BY create_date, style_id
LIMIT :page_size OFFSET :offset;

-- 2. 增量同步SQL（带分页参数）
-- 参数：:sync_last_time, :page_size, :offset
INSERT INTO dw_style_archive (style_id, style_name, brand_code, brand_name, style_year, style_state, j_price, x_price, v_price, j_cost, clerk_royaltyrate, clerk_royaltyprice, create_date, category_code, category_name, style_class_code, style_class, style_subclass_code, style_subclass, style_styles_code, style_styles, style_sex_code, style_sex, style_kind_code, style_kind, style_unit_code, style_unit, style_month_code, style_month, style_band_code, style_band, style_theme_code, style_theme, style_saletype_code, style_saletype, style_designer_code, style_designer, style_plater_code, style_plater, style_locate_code, style_locate, sizegrp_id, sizegrp_name, style_sort, style_supplier_code, style_supplier)
SELECT 
    style_id,
    style_name,
    brand_code,
    brand_name,
    style_year,
    style_state,
    j_price,
    x_price,
    v_price,
    j_cost,
    clerk_royaltyrate,
    clerk_royaltyprice,
    create_date,
    category_code,
    category_name,
    style_class_code,
    style_class,
    style_subclass_code,
    style_subclass,
    style_styles_code,
    style_styles,
    style_sex_code,
    style_sex,
    style_kind_code,
    style_kind,
    style_unit_code,
    style_unit,
    style_month_code,
    style_month,
    style_band_code,
    style_band,
    style_theme_code,
    style_theme,
    style_saletype_code,
    style_saletype,
    style_designer_code,
    style_designer,
    style_plater_code,
    style_plater,
    style_locate_code,
    style_locate,
    sizegrp_id,
    sizegrp_name,
    style_sort,
    style_supplier_code,
    style_supplier
FROM X6_STOCK_DEV.A3_STYLE
WHERE create_date > :sync_last_time
ORDER BY create_date ASC, style_id
LIMIT :page_size OFFSET :offset;

-- 3. 统计SQL

-- 3.1 全量统计
SELECT COUNT(*) as total_count FROM X6_STOCK_DEV.A3_STYLE;

-- 3.2 增量统计（带参数）
-- 参数：:sync_last_time
SELECT COUNT(*) as incremental_count FROM X6_STOCK_DEV.A3_STYLE WHERE create_date > :sync_last_time;