INSERT INTO ec_order_stat_daily_shop ( company_id, shop_id, platform_id, stat_date, sales_amount, sales_order_count, sales_quantity_sum, gmv_amount, gmv_order_count, gmv_quantity_sum, refund_amount, product_cost, freight_cost, other_cost, stat_version ) VALUES ( #{companyId}, #{shopId}, #{platformId}, #{statDate}, #{salesAmount}, #{salesOrderCount}, #{salesQuantitySum}, #{gmvAmount}, #{gmvOrderCount}, #{gmvQuantitySum}, #{refundAmount}, #{productCost}, #{freightCost}, #{otherCost}, #{statVersion} ) ON DUPLICATE KEY UPDATE platform_id = VALUES(platform_id), sales_amount = VALUES(sales_amount), sales_order_count = VALUES(sales_order_count), sales_quantity_sum = VALUES(sales_quantity_sum), gmv_amount = VALUES(gmv_amount), gmv_order_count = VALUES(gmv_order_count), gmv_quantity_sum = VALUES(gmv_quantity_sum), refund_amount = VALUES(refund_amount), product_cost = VALUES(product_cost), freight_cost = VALUES(freight_cost), other_cost = VALUES(other_cost), stat_version = VALUES(stat_version), update_time = CURRENT_TIMESTAMP DELETE FROM ec_order_stat_daily_product WHERE company_id = #{companyId} AND shop_id = #{shopId} AND stat_date = #{statDate} INSERT INTO ec_order_stat_daily_product ( company_id, shop_id, product_id, category_id, stat_date, sales_amount, sales_order_count, sales_quantity_sum, gmv_amount, gmv_order_count, gmv_quantity_sum, refund_amount, product_cost, freight_cost, other_cost, stat_version ) VALUES (#{r.companyId}, #{r.shopId}, #{r.productId}, #{r.categoryId}, #{r.statDate}, #{r.salesAmount}, #{r.salesOrderCount}, #{r.salesQuantitySum}, #{r.gmvAmount}, #{r.gmvOrderCount}, #{r.gmvQuantitySum}, #{r.refundAmount}, #{r.productCost}, #{r.freightCost}, #{r.otherCost}, #{r.statVersion}) DELETE FROM ec_order_stat_daily_spec WHERE company_id = #{companyId} AND shop_id = #{shopId} AND stat_date = #{statDate} INSERT INTO ec_order_stat_daily_spec ( company_id, shop_id, product_id, product_spec_id, stat_date, sales_amount, sales_order_count, sales_quantity_sum, gmv_amount, gmv_order_count, gmv_quantity_sum, refund_amount, product_cost, freight_cost, other_cost, stat_version ) VALUES (#{r.companyId}, #{r.shopId}, #{r.productId}, #{r.productSpecId}, #{r.statDate}, #{r.salesAmount}, #{r.salesOrderCount}, #{r.salesQuantitySum}, #{r.gmvAmount}, #{r.gmvOrderCount}, #{r.gmvQuantitySum}, #{r.refundAmount}, #{r.productCost}, #{r.freightCost}, #{r.otherCost}, #{r.statVersion}) INSERT INTO ec_order_stat_monthly_shop ( company_id, shop_id, platform_id, stat_month, sales_amount, sales_order_count, sales_quantity_sum, gmv_amount, gmv_order_count, gmv_quantity_sum, refund_amount, product_cost, freight_cost, other_cost, stat_version ) SELECT company_id, shop_id, MAX(platform_id), #{statMonth}, SUM(sales_amount), SUM(sales_order_count), SUM(sales_quantity_sum), SUM(gmv_amount), SUM(gmv_order_count), SUM(gmv_quantity_sum), SUM(refund_amount), SUM(product_cost), SUM(freight_cost), SUM(other_cost), MAX(stat_version) FROM ec_order_stat_daily_shop WHERE company_id = #{companyId} AND shop_id = #{shopId} AND stat_date >= #{statMonth} AND stat_date < DATE_ADD(#{statMonth}, INTERVAL 1 MONTH) GROUP BY company_id, shop_id ON DUPLICATE KEY UPDATE platform_id = VALUES(platform_id), sales_amount = VALUES(sales_amount), sales_order_count = VALUES(sales_order_count), sales_quantity_sum = VALUES(sales_quantity_sum), gmv_amount = VALUES(gmv_amount), gmv_order_count = VALUES(gmv_order_count), gmv_quantity_sum = VALUES(gmv_quantity_sum), refund_amount = VALUES(refund_amount), product_cost = VALUES(product_cost), freight_cost = VALUES(freight_cost), other_cost = VALUES(other_cost), stat_version = VALUES(stat_version), update_time = CURRENT_TIMESTAMP INSERT INTO ec_order_stat_yearly_shop ( company_id, shop_id, platform_id, stat_year, sales_amount, sales_order_count, sales_quantity_sum, gmv_amount, gmv_order_count, gmv_quantity_sum, refund_amount, product_cost, freight_cost, other_cost, stat_version ) SELECT company_id, shop_id, MAX(platform_id), #{statYear}, SUM(sales_amount), SUM(sales_order_count), SUM(sales_quantity_sum), SUM(gmv_amount), SUM(gmv_order_count), SUM(gmv_quantity_sum), SUM(refund_amount), SUM(product_cost), SUM(freight_cost), SUM(other_cost), MAX(stat_version) FROM ec_order_stat_monthly_shop WHERE company_id = #{companyId} AND shop_id = #{shopId} AND YEAR(stat_month) = #{statYear} GROUP BY company_id, shop_id ON DUPLICATE KEY UPDATE platform_id = VALUES(platform_id), sales_amount = VALUES(sales_amount), sales_order_count = VALUES(sales_order_count), sales_quantity_sum = VALUES(sales_quantity_sum), gmv_amount = VALUES(gmv_amount), gmv_order_count = VALUES(gmv_order_count), gmv_quantity_sum = VALUES(gmv_quantity_sum), refund_amount = VALUES(refund_amount), product_cost = VALUES(product_cost), freight_cost = VALUES(freight_cost), other_cost = VALUES(other_cost), stat_version = VALUES(stat_version), update_time = CURRENT_TIMESTAMP INSERT INTO ec_order_stat_monthly_product ( company_id, shop_id, product_id, category_id, stat_month, sales_amount, sales_order_count, sales_quantity_sum, gmv_amount, gmv_order_count, gmv_quantity_sum, refund_amount, product_cost, freight_cost, other_cost, stat_version ) SELECT company_id, shop_id, product_id, category_id, #{statMonth}, SUM(sales_amount), SUM(sales_order_count), SUM(sales_quantity_sum), SUM(gmv_amount), SUM(gmv_order_count), SUM(gmv_quantity_sum), SUM(refund_amount), SUM(product_cost), SUM(freight_cost), SUM(other_cost), MAX(stat_version) FROM ec_order_stat_daily_product WHERE company_id = #{companyId} AND shop_id = #{shopId} AND stat_date >= #{statMonth} AND stat_date < DATE_ADD(#{statMonth}, INTERVAL 1 MONTH) GROUP BY company_id, shop_id, product_id, category_id ON DUPLICATE KEY UPDATE sales_amount = VALUES(sales_amount), sales_order_count = VALUES(sales_order_count), sales_quantity_sum = VALUES(sales_quantity_sum), gmv_amount = VALUES(gmv_amount), gmv_order_count = VALUES(gmv_order_count), gmv_quantity_sum = VALUES(gmv_quantity_sum), refund_amount = VALUES(refund_amount), product_cost = VALUES(product_cost), freight_cost = VALUES(freight_cost), other_cost = VALUES(other_cost), stat_version = VALUES(stat_version), update_time = CURRENT_TIMESTAMP INSERT INTO ec_order_stat_yearly_product ( company_id, shop_id, product_id, category_id, stat_year, sales_amount, sales_order_count, sales_quantity_sum, gmv_amount, gmv_order_count, gmv_quantity_sum, refund_amount, product_cost, freight_cost, other_cost, stat_version ) SELECT company_id, shop_id, product_id, category_id, #{statYear}, SUM(sales_amount), SUM(sales_order_count), SUM(sales_quantity_sum), SUM(gmv_amount), SUM(gmv_order_count), SUM(gmv_quantity_sum), SUM(refund_amount), SUM(product_cost), SUM(freight_cost), SUM(other_cost), MAX(stat_version) FROM ec_order_stat_monthly_product WHERE company_id = #{companyId} AND shop_id = #{shopId} AND YEAR(stat_month) = #{statYear} GROUP BY company_id, shop_id, product_id, category_id ON DUPLICATE KEY UPDATE sales_amount = VALUES(sales_amount), sales_order_count = VALUES(sales_order_count), sales_quantity_sum = VALUES(sales_quantity_sum), gmv_amount = VALUES(gmv_amount), gmv_order_count = VALUES(gmv_order_count), gmv_quantity_sum = VALUES(gmv_quantity_sum), refund_amount = VALUES(refund_amount), product_cost = VALUES(product_cost), freight_cost = VALUES(freight_cost), other_cost = VALUES(other_cost), stat_version = VALUES(stat_version), update_time = CURRENT_TIMESTAMP INSERT INTO ec_order_stat_monthly_spec ( company_id, shop_id, product_id, product_spec_id, stat_month, sales_amount, sales_order_count, sales_quantity_sum, gmv_amount, gmv_order_count, gmv_quantity_sum, refund_amount, product_cost, freight_cost, other_cost, stat_version ) SELECT company_id, shop_id, product_id, product_spec_id, #{statMonth}, SUM(sales_amount), SUM(sales_order_count), SUM(sales_quantity_sum), SUM(gmv_amount), SUM(gmv_order_count), SUM(gmv_quantity_sum), SUM(refund_amount), SUM(product_cost), SUM(freight_cost), SUM(other_cost), MAX(stat_version) FROM ec_order_stat_daily_spec WHERE company_id = #{companyId} AND shop_id = #{shopId} AND stat_date >= #{statMonth} AND stat_date < DATE_ADD(#{statMonth}, INTERVAL 1 MONTH) GROUP BY company_id, shop_id, product_id, product_spec_id ON DUPLICATE KEY UPDATE sales_amount = VALUES(sales_amount), sales_order_count = VALUES(sales_order_count), sales_quantity_sum = VALUES(sales_quantity_sum), gmv_amount = VALUES(gmv_amount), gmv_order_count = VALUES(gmv_order_count), gmv_quantity_sum = VALUES(gmv_quantity_sum), refund_amount = VALUES(refund_amount), product_cost = VALUES(product_cost), freight_cost = VALUES(freight_cost), other_cost = VALUES(other_cost), stat_version = VALUES(stat_version), update_time = CURRENT_TIMESTAMP INSERT INTO ec_order_stat_yearly_spec ( company_id, shop_id, product_id, product_spec_id, stat_year, sales_amount, sales_order_count, sales_quantity_sum, gmv_amount, gmv_order_count, gmv_quantity_sum, refund_amount, product_cost, freight_cost, other_cost, stat_version ) SELECT company_id, shop_id, product_id, product_spec_id, #{statYear}, SUM(sales_amount), SUM(sales_order_count), SUM(sales_quantity_sum), SUM(gmv_amount), SUM(gmv_order_count), SUM(gmv_quantity_sum), SUM(refund_amount), SUM(product_cost), SUM(freight_cost), SUM(other_cost), MAX(stat_version) FROM ec_order_stat_monthly_spec WHERE company_id = #{companyId} AND shop_id = #{shopId} AND YEAR(stat_month) = #{statYear} GROUP BY company_id, shop_id, product_id, product_spec_id ON DUPLICATE KEY UPDATE sales_amount = VALUES(sales_amount), sales_order_count = VALUES(sales_order_count), sales_quantity_sum = VALUES(sales_quantity_sum), gmv_amount = VALUES(gmv_amount), gmv_order_count = VALUES(gmv_order_count), gmv_quantity_sum = VALUES(gmv_quantity_sum), refund_amount = VALUES(refund_amount), product_cost = VALUES(product_cost), freight_cost = VALUES(freight_cost), other_cost = VALUES(other_cost), stat_version = VALUES(stat_version), update_time = CURRENT_TIMESTAMP