package com.ssj.dao.sys.schoolmatecircle.dao;

import com.ssj.bean.sys.schoolmatecircle.domain.SchoolmateCircle;
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;
/**
 * @author Mount Liu
 * @date 2018/8/15
 */
@Repository
public interface SchoolmateCircleDao extends JpaRepository<SchoolmateCircle, String> {

    /**
     * 采纳解答
     * @param commentId
     */
    @Query(nativeQuery = true, value = "update scon_schoolmate_comment LEFT JOIN scon_circle_schoolmate ON scon_schoolmate_comment.schoolmate_circle_id = scon_circle_schoolmate.id "
            + " set scon_schoolmate_comment.is_accept = 1, scon_circle_schoolmate.is_accept = 1 "
            + " where scon_schoolmate_comment.id = ?1 ")
    @Modifying
    void acceptSolution(String commentId);


    @Query(nativeQuery = true, value = "UPDATE scon_schoolmate_comment\n" +
            "SET is_accept = 1\n" +
            "WHERE id =?1" )
    @Modifying
    void acceptSolutionV1(String commentId);


    @Query(nativeQuery = true, value = "UPDATE  scon_circle_schoolmate  \n" +
            "SET is_accept = 1\n" +
            "where id  in (\n" +
            "SELECT  schoolmate_circle_id from  scon_schoolmate_comment  where id  =?1\n" +
            ")")
    @Modifying
    void acceptSolutionV2(String commentId);

}
