package com.sw.mes.yb.pc.dao;


import com.sw.mes.core.base.BaseDao;
import com.sw.mes.yb.pc.entity.ExceptionInfo;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface ExceptionInfoDAO extends BaseDao<ExceptionInfo, Integer> {

    @Modifying
    @Transactional
    @Query(value = "UPDATE zhxx_operate_exception_info SET usable=FALSE WHERE property_code=?1 ", nativeQuery = true)
    void updateUsable(String propertyCode);

    @Query(value = "SELECT * FROM zhxx_operate_exception_info WHERE property_code=?1 ORDER BY usable DESC, create_date DESC ",
            nativeQuery = true)
    List<ExceptionInfo> findByPropertyCode(String sectionNo);

    @Query(value = "SELECT * FROM zhxx_operate_exception_info WHERE property_code=?1 AND usable=true " +
            "ORDER BY create_date DESC ", nativeQuery = true)
    List<ExceptionInfo> getUnableByPropertyCode(String sectionNo);

    @Query(value = "SELECT * FROM zhxx_operate_exception_info WHERE property_code=?1 AND cause=?2 AND usable=TRUE " +
            "ORDER BY create_date DESC ", nativeQuery = true)
    List<ExceptionInfo> getByPropertyCodeAndCause(String sectionNo, String cause);

}
