package com.tykj.dev.device.train.dao;

import com.tykj.dev.device.train.entity.TrainUser;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

/**
 * @author zjm
 * @version 1.0.0
 * @ClassName TrainUserDao.java
 * @Description TODO
 * @createTime 2020年12月01日 13:55:00
 */
public interface TrainUserDao extends JpaRepository<TrainUser, Integer>, JpaSpecificationExecutor<TrainUser> {

    TrainUser findByUserIdAndTrainId(Integer userId,Integer trainId);

    List<TrainUser> findAllByIsSignUpAndTrainId(Integer IsSignUp,Integer trainId);

    List<TrainUser> findAllByTrainId(Integer trainId);

    List<TrainUser> findAllByUnitsIdAndTrainId(Integer unitId,Integer trainId);

    @Transactional
    @Modifying
    @Query("update TrainUser o set o.recordId = :recordId  where o.id =:id")
    int upDate(String recordId,Integer id);

}
