<?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="com.fdkankan.scene.mapper.ISceneUpgradeMapper">

  <insert id="transferScenePro" parameterType="java.lang.Long">
    INSERT INTO t_scene_pro(id, scene_name, scene_dec, web_site, thumb, user_id, camera_id, scene_logo, num, scene_type,
    videos, gps, scene_scheme, pay_status, scene_status, build_type, create_time, update_time, tb_status)
    SELECT t.`id`, t.`scene_name`, t.`scene_dec`, t.`web_site`, t.`thumb`, t.`user_id`, t.`camera_id`, t.`scene_logo`, t.`num`, t.`scene_type`,
    t.`videos`, t.`gps`, t.`scene_scheme`, t.`pay_status`, t.`status`, t.`build_type`, t.`create_time`, t.`update_time`,
    case when t.rec_status = 'A' then 0 else 1 end as tb_status
    FROM `t_scene_pro_v3` t WHERE t.id = #{sceneProId}
  </insert>

  <insert id="transferSceneProExt">
    INSERT INTO t_scene_pro_ext(scene_pro_id, data_source, phone_id, recommend, files_name, `algorithm`, ecs,
    `space`, firmware_version,compute_time,scene_source,vrnum,scene_resolution ,scene_from, scene_kind,`unicode`,view_count,shoot_count,create_time,update_time,tb_status)
    SELECT t.`id`, t.`data_source`, t.`phone_id`, t.`recommend`, t.`files_name`, t.`algorithm`, t.`ecs`,
    t.`space`, t.`firmware_version`, t.`compute_time`, t.`scene_source`, t.`vrnum`,
    CASE
      WHEN t.scene_source = 1 THEN '2k'
      WHEN t.scene_source = 2 THEN '1k'
      WHEN t.scene_source = 3 THEN '4k'
      WHEN t.scene_source = 4 THEN '4k'
      ELSE NULL
     END AS scene_resolution,
    CASE
      WHEN t.scene_source = 1 THEN 'pro'
      WHEN t.scene_source = 2 THEN 'lite'
      WHEN t.scene_source = 3 THEN 'minion'
      WHEN t.scene_source = 4 THEN 'laser'
      ELSE NULL
     END AS scene_from,
    #{sceneKind} scene_kind,
    t.`unicode`, t.`view_count`, t.`shoot_count`, t.`create_time`, t.`update_time`,
    case when t.rec_status = 'A' then 0 else 1 end as tb_status
    FROM `t_scene_pro_v3` t WHERE t.id = #{sceneProId}
  </insert>

  <insert id="transferScenePlus" parameterType="java.lang.Long">
    INSERT INTO t_scene_plus(`id`,`num`,`user_id`,`camera_id`,`phone_id`,`title`,`description`,`scene_status`,`scene_source`,
    `pay_status`,`scene_type`,`recommend`,`create_time`,`update_time`,`tb_status`)
    SELECT pro.id, pro.num,pro.user_id,pro.`camera_id`,ext.phone_id,pro.scene_name,pro.scene_dec,pro.scene_status,ext.`scene_source`,
    pro.pay_status,pro.scene_type,ext.recommend,pro.create_time,pro.update_time,pro.tb_status
    FROM t_scene_pro pro
    LEFT JOIN t_scene_pro_ext ext ON pro.id = ext.scene_pro_id
    WHERE pro.id = #{sceneProId}
  </insert>

  <insert id="transferScenePlusExt" parameterType="java.lang.Long">
    INSERT INTO t_scene_plus_ext(plus_id, data_source, web_site,thumb,scene_scheme,SPACE,ecs,
    shoot_count,view_count,gps,ALGORITHM,firmware_version,build_type,create_time,update_time,tb_status,
    scene_resolution, scene_from, scene_kind, videos)
    SELECT pro.id, ext.`data_source`, pro.`web_site`, pro.`thumb`, pro.`scene_scheme`, ext.`space`, ext.`ecs`,
    ext.`shoot_count`, ext.`view_count`, pro.`gps`, ext.`algorithm`, ext.`firmware_version`, pro.`build_type`, pro.`create_time`, pro.`update_time`, pro.`tb_status`,
    ext.scene_resolution, ext.scene_from, scene_kind, pro.videos
    FROM t_scene_pro pro
    LEFT JOIN t_scene_pro_ext ext ON pro.id = ext.scene_pro_id
    WHERE pro.id = #{sceneProId}
  </insert>

  <insert id="transferSceneProEdit" parameterType="java.lang.Long">
    INSERT INTO t_scene_pro_edit
    (`id`,`pro_id`,`scene_key`,`need_key`,`version`,`thumb_status`,`marker_logo`,
    `floor_logo`,`floor_logo_size`,`hots_ids`,`entry`,`bg_music`,`screencap_voice_src`,`screencap_voice_sound`,
    `screencap_voice_soundsync`,`screencap_voice_type`,`play_data`,`floor_edit_ver`,`floor_publish_ver`,
    `screencap_thumb`,`share_logo`,`create_time`,`update_time`,`tb_status`)
    SELECT `id`,`pro_id`,`scene_key`,`need_key`,`version`,`thumb_status`,`marker_logo`,
    `floor_logo`,`floor_logo_size`,`hots_ids`,`entry`,`bg_music`,`screencap_voice_src`,`screencap_voice_sound`,
    `screencap_voice_soundsync`,`screencap_voice_type`,`play_data`,`floor_edit_ver`,`floor_publish_ver`,
    `screencap_thumb`,`share_logo`,`create_time`,`update_time`,CASE WHEN rec_status = 'A' THEN 0 ELSE 1 END AS tb_status
    FROM `t_scene_pro_edit_v3` t where t.id = #{sceneProEditId}
  </insert>

  <insert id="transferSceneProEditExt" parameterType="java.lang.Long">
    INSERT INTO `t_scene_pro_edit_ext`
    (`pro_edit_id`,`pro_id`,`map_visi`,`tour_visi`,`vr_visi`,`ruler_visi`,`cad_img_visi`,`floor_plan_png`,
    `cad_info`,`pano_visi`,`m2d_visi`,`m3d_visi`,`measure_visi`,`link_scene`,`overlay`,`show_logo_bottom`,
    `images_version`,`bg_music_name`,`jump_scene`,`floor_plan_angle`,`download_num`,`videos_user`,`vr_num`,
    `create_time`,`update_time`,`tb_status`)
    SELECT  `id`,`pro_id`,`map_visi`,`tour_visi`,`vr_visi`,`ruler_visi`,`cad_img_visi`,`floor_plan_png`,
    `cad_info`,`pano_visi`,`m2d_visi`,`m3d_visi`,`measure_visi`,`link_scene`,`overlay`,`show_logo_bottom`,
    `images_version`,`bg_music_name`,`jump_scene`,`floor_plan_angle`,`download_num`,`videos_user`,`vr_num`,
    `create_time`,`update_time`,CASE WHEN rec_status = 'A' THEN 0 ELSE 1 END AS tb_status
    FROM `t_scene_pro_edit_v3` where id = #{sceneProEditId}
  </insert>

  <delete id="deleteSceneProEdit" parameterType="java.lang.Long">
    delete from t_scene_pro_edit where id = #{sceneProEditId}
  </delete>

  <delete id="deleteSceneProEditExt" parameterType="java.lang.Long">
    delete from t_scene_pro_edit_ext where pro_edit_id = #{sceneProEditId}
  </delete>

  <delete id="deleteScenePlus" parameterType="java.lang.Long">
    delete from t_scene_plus where id = #{sceneProId}
  </delete>

  <delete id="deleteScenePlusExt" parameterType="java.lang.Long">
    delete from t_scene_plus_ext where plus_id = #{sceneProId}
  </delete>

  <delete id="deleteScenePro" parameterType="java.lang.Long">
    delete from t_scene_pro where id = #{sceneProId}
  </delete>

  <delete id="deleteSceneProExt" parameterType="java.lang.Long">
    delete from t_scene_pro_ext where scene_pro_id = #{sceneProId}
  </delete>
</mapper>
