package com.softwarebr.nunu.dao.train;

import com.brframework.commondb.core.CommonRepository;
import com.softwarebr.nunu.entity.train.Activity;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

/**
 * @date 2020-02-26 11:02:46
 * @author lilin
 */

@Repository
public interface ActivityDao extends CommonRepository<Long, Activity> {

    /**
     * 活动名称查询活动信息
     * @param name
     * @return
     */
    Activity findFirstByName(String name);

    /**
     * 更新活动报名人数
     * @param activityId 活动id
     * @param enrolment 报名人数
     */
    @Modifying
    @Query("update Activity set enrolment = enrolment+ :enrolment where id = :activityId")
    void updateEnrolment(@Param("activityId") Long activityId, @Param("enrolment") Integer enrolment);


}