<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="co.yixiang.yshop.module.system.dal.mysql.backuprecord.BackupRecordMapper">

    <!--
        一般情况下，尽可能使用 Mapper 进行 CRUD 增删改查即可。
        无法满足的场景，例如说多表关联查询，才使用 XML 编写 SQL。
        代码生成器暂时只生成 Mapper XML 文件本身，更多推荐 MybatisX 快速开发插件来生成查询。
        文档可见：https://www.yixiang.co/MyBatis/x-plugins/
     -->

    <!--
    体验版备份数据用，鉴于体验版数据不会很多，故选择一次性备份
    1、备份商品基础信息、价格、规格、优惠券等
    2、删除订单信息、售后订单信息、redis缓存等
    3、数据库加上&allowMultiQueries=true 支持多句语句
 -->


    <!--
      先清除备份表
      将商品/素材相关信息备份到备份表中
 -->
    <update id="backup">
        TRUNCATE TABLE yshop_store_product_bak;
        TRUNCATE TABLE yshop_store_product_attr_bak;
        TRUNCATE TABLE yshop_store_product_attr_value_bak;
        TRUNCATE TABLE yshop_store_product_brand_bak;
        TRUNCATE TABLE yshop_store_product_category_bak;
        TRUNCATE TABLE yshop_store_product_coupon_bak;
        TRUNCATE TABLE yshop_store_product_coupon_relation_bak;
        TRUNCATE TABLE yshop_store_product_rule_bak;
        TRUNCATE TABLE yshop_material_bak;
        TRUNCATE TABLE yshop_material_group_bak;
        insert into yshop_store_product_bak select * from yshop_store_product;
        insert into yshop_store_product_attr_bak select * from yshop_store_product_attr;
        insert into yshop_store_product_attr_value_bak select * from yshop_store_product_attr_value;
        insert into yshop_store_product_brand_bak select * from yshop_store_product_brand;
        insert into yshop_store_product_category_bak select * from yshop_store_product_category;
        insert into yshop_store_product_coupon_bak select * from yshop_store_product_coupon;
        insert into yshop_store_product_coupon_relation_bak select * from yshop_store_product_coupon_relation;
        insert into yshop_store_product_rule_bak select * from yshop_store_product_rule;
        insert into yshop_material_bak select * from yshop_material;
        insert into yshop_material_group_bak select * from yshop_material_group;
    </update>

    <!--
  先清除所有订单信息及商品评价。收藏等, 商品信息也一并清除，将备份表数据插入原表
-->
    <update id="revertBackup">
        TRUNCATE TABLE yshop_store_order;
        TRUNCATE TABLE yshop_store_order_status;
        TRUNCATE TABLE yshop_store_cart;
        TRUNCATE TABLE yshop_store_order_cart_info;
        TRUNCATE TABLE yshop_store_order_detail;
        TRUNCATE TABLE yshop_store_after_sales;
        TRUNCATE TABLE yshop_store_after_sales_item;
        TRUNCATE TABLE yshop_store_after_sales_status;
        TRUNCATE TABLE yshop_store_product_relation;
        TRUNCATE TABLE yshop_store_product_reply;
        TRUNCATE TABLE yshop_store_product;
        TRUNCATE TABLE yshop_store_product_attr;
        TRUNCATE TABLE yshop_store_product_attr_value;
        TRUNCATE TABLE yshop_store_product_brand;
        TRUNCATE TABLE yshop_store_product_category;
        TRUNCATE TABLE yshop_store_product_coupon;
        TRUNCATE TABLE yshop_store_product_coupon_relation;
        TRUNCATE TABLE yshop_store_product_rule;
        TRUNCATE TABLE yshop_material;
        TRUNCATE TABLE yshop_material_group;
        insert into yshop_store_product select * from yshop_store_product_bak;
        insert into yshop_store_product_attr select * from yshop_store_product_attr_bak;
        insert into yshop_store_product_attr_value select * from yshop_store_product_attr_value_bak;
        insert into yshop_store_product_brand select * from yshop_store_product_brand_bak;
        insert into yshop_store_product_category select * from yshop_store_product_category_bak;
        insert into yshop_store_product_coupon select * from yshop_store_product_coupon_bak;
        insert into yshop_store_product_coupon_relation select * from yshop_store_product_coupon_relation_bak;
        insert into yshop_store_product_rule select * from yshop_store_product_rule_bak;
        insert into yshop_material select * from yshop_material_bak;
        insert into yshop_material_group select * from yshop_material_group_bak;
    </update>
</mapper>
