package com.ssj.dao.sys.xb.dao;

import com.ssj.bean.sys.xb.domain.XbFeedbackImg;
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;

@Repository
public interface IXbFeedbackImgDao extends JpaRepository<XbFeedbackImg, String> {

	@Query(nativeQuery = true, value = "select * from kmt_course_xb_feedback_img t where t.feedback_id = ?1 and t.img_url = ?2  limit 1")
	XbFeedbackImg findByCouserIdAndFileKey(String id, String fileKey);

	@Query(nativeQuery = true, value = "select t.* from kmt_course_xb_feedback_img t " +
			"left join kmt_course_xb_feedback t1 on t.feedback_id = t1.id " +
			"where t1.kmt_course_id = ?1")
	List<XbFeedbackImg> findByCouserId(String courseId);

	@Query(nativeQuery = true, value = "select * from kmt_course_xb_feedback_img t where t.kmt_course_id = ?1 and t.img_url = ?2 and t.course_name=?3 limit 1")
	XbFeedbackImg findByCouserIdAndFileKeyAndCourse(String courseId, String fileKey, String courseName);

	@Query(nativeQuery = true, value = "update kmt_course_xb_feedback_img set feedback_id=?1 where kmt_course_id=?2 and course_name=?3 ")
	@Modifying
	void updateImgFeedbackId(String id, String courseId, String courseName);
}
