package com.sw.mes.fb.checkout.dao;

import com.sw.mes.core.base.BaseDao;
import com.sw.mes.fb.aio.entity.SpellInfo;
import com.sw.mes.fb.checkout.entity.FbJoin;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
* @Author
* @Description：
* @Date:
* @Modified By:
*/
public interface FbJoinDao extends BaseDao<FbJoin, Integer>{

    @Modifying
    @Transactional
    @Query(value = "UPDATE zhxx_fb_operate_fbjoin SET `state`=1,unbind_user=?2,unbind_time=?3,relieve_reason=?4 WHERE id =?1 ", nativeQuery = true)
    void UpdateState(int id, String username, Date date,String relieveReason);


    @Query(value = "SELECT * FROM `zhxx_fb_operate_fbjoin` WHERE  FIND_IN_SET(?1 , section_no_group)",nativeQuery = true)
    FbJoin findByGroupNo(String sectionNoFb);

    @Query(value = "SELECT * FROM `zhxx_fb_operate_fbjoin` WHERE FIND_IN_SET(?1 , section_no_group) and state= ?2 order by id desc limit 1",nativeQuery = true)
    FbJoin findByGroupNoAndState(String sectionNoFb,int state);

    @Query(value = "SELECT * FROM `zhxx_fb_operate_fbjoin` WHERE id =?1 ",nativeQuery = true)
    FbJoin getOneBySectionId(int toIntExact);

    @Query(value = "SELECT * FROM `zhxx_fb_operate_fbjoin` WHERE id IN (?1) ",nativeQuery = true)
    List<FbJoin> getFbJoinDaoList(String[] ids);

    @Query(value = "SELECT * FROM `zhxx_fb_operate_fbjoin` WHERE section_no_fb =?1 ",nativeQuery = true)
    FbJoin getFbJoinBySectionNo(String sectionNoFb);

    @Modifying
    @Transactional
    @Query(value = "UPDATE zhxx_fb_operate_fbjoin SET `is_send`=?2 WHERE id =?1 ", nativeQuery = true)
    void updateIsSend(Integer id, int i);

    @Query(value = "SELECT * FROM zhxx_fb_data_spell_info WHERE section_no =?1 ",nativeQuery = true)
    SpellInfo getFbDataSpellInfoBySectionNo(String crystalNo);
}
