package com.rf.psychological.dao.repository;

import com.rf.psychological.base.repository.BaseRepository;
import com.rf.psychological.dao.model.DimensionEntity;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author zsy
 * @description:
 * @date 2021/5/14 10:54
 */
public interface DimensionRepository extends BaseRepository<DimensionEntity,String> {


    /**
     * 根据flag查询维度信息
     * @param flag
     * @return
     */
    @Query(value="select * from t_dimension_info where flag = :flag",nativeQuery=true)
    List<DimensionEntity> getDimensionByFlag(@Param("flag") String flag);


    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "delete from t_dimension_info", nativeQuery = true)
    void deleteAll();

    /**
     * 根据id修改指定字段
     *
     * @return
     */
    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "UPDATE t_dimension_info SET name = :name, question_no = :questionNo WHERE id = :id ", nativeQuery = true)
    void updateDimension(@Param("name")String name, @Param("questionNo")String questionNo,@Param("id") String id);

    @Transactional
    @Modifying
    @Query(value = "delete from t_dimension_info where flag=:flag  ", nativeQuery = true)
    void deleteDimensionByFlag(@Param("flag")String flag);


}
