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


import com.sw.mes.core.base.BaseDao;
import com.sw.mes.fb.turnstore.entity.TurnStoreAccept;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @Author
 * @Description：
 * @Date:
 * @Modified By:
 */
public interface TurnStoreAcceptDao extends BaseDao<TurnStoreAccept, Long> {

    @Modifying
    @Transactional
    @Query(value = "UPDATE zhxx_turnstore_accept SET `state`=?2,update_user_id=?3,update_user_name=?4,remark=?5,update_time=?6 WHERE id =?1 ", nativeQuery = true)
    void affirmById(Long id, int i, Integer userID, String username, String remark, Date date);

    @Modifying
    @Transactional
    @Query(value = "UPDATE zhxx_turnstore_accept SET `state`=?2 WHERE id =?1 ", nativeQuery = true)
    void cancel(Long id, int i);

    @Modifying
    @Transactional
    @Query(value = "UPDATE zhxx_turnstore_accept SET `state`=?2 WHERE send_id =?1 ", nativeQuery = true)
    void updateBySid(Long id, int i);

    @Modifying
    @Transactional
    @Query(value = "DELETE FROM zhxx_turnstore_accept WHERE send_id =?1 and state != 1", nativeQuery = true)
    void deleteBySendId(Long sendId);

    @Query(value = "SELECT * FROM zhxx_turnstore_accept WHERE send_id =?1 and state = 1", nativeQuery = true)
    TurnStoreAccept findBySendId(Long id);
}
