package com.malk.aipocloud.repository.dao;

import com.malk.aipocloud.repository.entity.AbEventPo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.Date;
import java.util.List;

/**
 * 钉钉花名册同步
 */
@Transactional
public interface ABEventDao extends JpaRepository<AbEventPo, Long> {

    AbEventPo findByInstanceId(String instanceId);

    @Query("SELECT m from AbEventPo m WHERE (m.detectDateTime >= ?1 AND m.detectDateTime <= ?2) AND m.channelType = ?3 AND m.logonName = ?4 and (m.state = 'process' or (m.state = 'agree' and m.expire > ?5 ))")
    List<AbEventPo> queryList(Date sTime, Date eTime, int channel, String name, Date expire);

    @Modifying
    @Query("update AbEventPo m set m.state = ?2, m.sync = ?3 where m.instanceId = ?1")
    void updateState(String instanceId, String state, String sync);
}
