package com.crunii.micro.domain.repo.main;

import com.crunii.micro.domain.common.BaseRepo;
import com.crunii.micro.domain.entity.main.YcqPublishActivity;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Map;

/**
 * @Author: zwx
 * @CreateTime: 2023-09-19  10:01:27
 * @Description: TODO
 */
public interface PublishActivityRepo extends BaseRepo<YcqPublishActivity,Long> {
    @Modifying
    @Query(value = "update ycq_publish_activity set applyer_count=applyer_count+1 where applyer_count<limit_count and id=:id",nativeQuery = true)
    int updateApplyCount(@Param("id") Long id);

    @Modifying
    @Query(value = "update ycq_publish_activity set browse_count=browse_count+1 where id=?1",nativeQuery = true)
    void updateBrowseCount(Long id);

    @Modifying
    @Query(value = "update ycq_publish_activity set activity_state=1 where is_manual_shutdown=0 and id in (?1)",nativeQuery = true)
    void updateActivityState(List<Long> ids);

    @Modifying
    @Query(value = "update YCQ_PUBLISH_ACTIVITY set ACTIVITY_STATE=1 where now() between start_time and end_time and IS_MANUAL_SHUTDOWN=0",nativeQuery = true)
    void updateActivityStateAll();

    @Query(value = "select app_id,system_name from ycq_app_config_url where state=1",nativeQuery = true)
    Map<Long, String> findSelectBusiness();

    YcqPublishActivity findByIdAndIsDeleted(Long id, int i);
}
