package com.yihu.wlyy.statistics.dao;

import com.yihu.wlyy.statistics.model.label.SignPatientLabel;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

/**
 * Created by lyr on 2016/10/9.
 */
public interface SignPatientLabelDao extends
        PagingAndSortingRepository<SignPatientLabel, Long>,
        JpaSpecificationExecutor<SignPatientLabel> {

    /**
     * 根据标签code、标签类型、状态查询标签
     *
     * @param labelCode 标签code
     * @param labelType 标签类型
     * @param status 状态
     * @return
     */
    SignPatientLabel findByLabelCodeAndLabelTypeAndStatus(String labelCode, String labelType, Integer status);

    /**
     * 查询某个类型系统标签
     *
     * @param labelType
     * @param status
     * @return
     */
    List<SignPatientLabel> findByLabelTypeAndStatus(String labelType, Integer status);

    /**
     * 查询非自定义系统标签
     *
     * @return
     */
    @Query("select a from SignPatientLabel a where a.status = 1 and a.isSystem = 1 and a.labelType < 4")
    List<SignPatientLabel> findSystemLabels();

    /**
     * 查询某个团队自定义标签
     *
     * @param teamCode
     * @return
     */
    @Query("select a from SignPatientLabel a where a.status = 1 and (a.isSystem = 1  or a.teamCode = ?1) and a.labelType = 4")
    List<SignPatientLabel> findCustomLabels(long teamCode);

    @Query("select a from SignPatientLabel a where a.status = 1 and a.labelName = ?1 and a.labelType = ?2 and a.teamCode = ?3")
    SignPatientLabel findByLabelNameAndLabelTypeAndTeamCode(String labelName, String labelType, Long teamCode);
}