package cn.teammodel.repository;

import cn.teammodel.model.entity.common.Art;
import cn.teammodel.model.vo.admin.ArtElementsVo;
import com.azure.spring.data.cosmos.repository.CosmosRepository;
import com.azure.spring.data.cosmos.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ArtRepository extends CosmosRepository<Art, String> {
    /**
    * 动态投影, 查询还是要将所有的值查出来,类的动态查询不能嵌套
    */
    @Query("select s.id,s.name,s.classes,s.startTime,s.endTime,s.subjects,s.progress,s.settings from Art as s where s.progress = 'finish' and s.period.id = @periodId and s.code = @code " +
            "and (IS_NULL(@startTime) or s.startTime >= @startTime) " +
            "and (IS_NULL(@endTime) or s.startTime < @endTime) ")
    List<ArtElementsVo> findPeriodById(@Param("periodId")String periodId, @Param("code")String code, @Param("startTime")Long startTime, @Param("endTime")Long endTime);


}
