package com.ssj.dao.sys.smarttime.dao;

import com.ssj.bean.conch.conch.domain.SmarttimePicture;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;


/**
 * 类名称：SmarttimeDao<br>
 * 类描述：系统参数数据访问接口<br>
 * 
 * @version v1.0
 */
@Repository
public interface SmarttimeDao extends JpaRepository<SmarttimePicture, String> {

    public List<SmarttimePicture> findByParentIdAndIsDeleteOrderByIdDesc(String parentId, int isDelete);

    public Page<SmarttimePicture> findAll(Specification<SmarttimePicture> specification, Pageable page);

    @Modifying
    @Query(value = "update scon_smarttime_picture  set is_delete=1 where id = ?1", nativeQuery = true)
    public void deleteById(String smarttimeId);

    @Modifying
    @Query(value = "update scon_smarttime_picture  set smartsay = ?2 where id = ?1", nativeQuery = true)
	public void updateSmartSay(String smarttimeId, String smartsay);
    
    public List<SmarttimePicture> findByKeywordAndVipIdOrderByCreateTimeDesc(String keyword,String vipId);

    public long countByFileKey(String fileKey);

    /**
     * 统计学生小时光数量
     * @param vipId
     * @return
     */
    long countByVipId(String vipId);

    @Query(nativeQuery = true, value = "select * from scon_smarttime_picture where vip_id = ?2 and is_delete = 0 and date(create_time) = ?1 order by create_time desc ")
    List<SmarttimePicture> findByCreateDateVipId(String createDate, String vipId);
}
