package com.fdkanfang.dao.backend;

import com.fdkanfang.domain.backend.SceneProEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;


/**
 * Created by Hb_zzZ on 2019/7/23.
 */
@Mapper
public interface ISceneProMapper extends IBaseMapper<SceneProEntity, Long> {

    @Select(" SELECT count(*) FROM t_scene_pro WHERE camera_id = #{cameraId} AND rec_status = 'A' ")
    int getSceneCount(@Param("cameraId") Long cameraId);

    @Select(" SELECT * FROM t_scene_pro WHERE num = #{num} AND rec_status = 'A' LIMIT 1")
    SceneProEntity findByNum(@Param("num") String num);

    @Select(" SELECT * FROM t_scene_pro WHERE num = #{num} AND rec_status = 'I' LIMIT 1")
    SceneProEntity findDeleteSceneBySceneNum(@Param("num") String num);

    @Select(" SELECT * FROM t_scene_pro WHERE data_source LIKE CONCAT('%',#{unicode},'%') AND rec_status = #{recStatus} order by create_time desc LIMIT 1")
    SceneProEntity getSceneStatusByUnicode(@Param("unicode") String unicode, @Param("recStatus") String recStatus);

//    @Select(" SELECT * FROM t_scene_pro WHERE user_id = #{userId} AND rec_status = 'A' AND (status = 1 or status = -2) order by create_time desc")
//    List<SceneProEntity> findByUserId(@Param("userId") Long userId, @Param("cameraType") Integer cameraType);

    @Update("UPDATE t_scene_pro SET status = #{status} WHERE num = #{sceneNum}")
    int updateStatus(@Param("sceneNum") String sceneNum, @Param("status") int status);

    @Update("UPDATE t_scene_pro SET create_time = NOW(),status=-2, space = #{space}, pay_status = #{payStatus}, videos = #{videos} WHERE num = #{sceneNum}")
    int updateTime(@Param("sceneNum") String sceneNum, @Param("space") Long space, @Param("payStatus") int payStatus, @Param("videos") String videos);

//    @Select(" SELECT * FROM t_scene_pro WHERE user_id = #{userId} AND rec_status = 'A' and camera_id is not null order by create_time desc LIMIT 1 ")
//    ResponseScene findLatestOneByUserId(@Param("userId") Long userId);
//
//    @Update(" UPDATE t_scene_pro SET user_id = #{userId} WHERE camera_id = #{cameraId} ")
//    void updateUserIdByCameraId(@Param("userId") Long userId, @Param("cameraId") Long cameraId);
//
//    @Update("UPDATE t_scene_pro SET rec_status = 'I' WHERE data_source LIKE CONCAT('%',#{unicode},'%')")
//    int updateRecStatus(@Param("unicode") String unicode);
//
//    @Select(" SELECT * FROM t_scene_pro WHERE data_source LIKE CONCAT('%',#{fileId},'%') AND rec_status = 'A' order by create_time desc LIMIT 1 ")
//    SceneProEntity findByFileId(@Param("fileId") String fileId);
//
//    @Select(" select id, num from t_scene_pro where rec_status = 'A' and pay_status = -2 and (DATEDIFF(update_time,NOW()) <=-365) ")
//    List<SceneProEntity> findTempScenes();
}
