package com.ann.demo.repository;

import com.ann.demo.entity.filing.ArchiveDetail;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author: LeiJiaXin
 * @Date: 2019/7/12 9:10
 */
@Repository
public interface ArchiveDetailRepository extends JpaRepository<ArchiveDetail, String> {

//    @Transactional
//    @Modifying
//    @Query(value = "UPDATE ArchiveDetail o set o.flag = 1 where o.id = ?1 and o.flag = 0")
//    public Integer updateFlagById(String id);

    @Query("select o.id from ArchiveDetail o where o.applyId = ?1 and o.masterID = ?2 and o.flag = 0")
    public String findIdByApplyIdAndMasterID(String applyId, String masterId);

    @Query("select o.id from ArchiveDetail o where o.applyId = ?1  and o.flag = 0")
    public String findIdByApplyId(String applyId);

    @Query("select o.id from ArchiveDetail o where o.masterID = ?1  and o.assortID = 0")
    public String findIdByMasterIDAndAssortID(String masterID, String assortID);

    @Query(value = "select max(o.applyId) from ArchiveDetail o where o.applyId like %?1%  and o.flag = ?2")
    public String getApplyIdByApplyIdAndFlag(String applyId, String flag);

    @Transactional
    @Modifying
    @Query(value = "UPDATE ArchiveDetail o set o.flag = 2 where o.applyId = ?1 and o.flag = 0 and o.source = ?2")
    public Integer updateFlagByApplyId(String id, String source);


}

