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

import com.sw.mes.core.base.BaseDao;
import com.sw.mes.yb.turnstore.entity.Turnstore;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @Author
 * @Description：
 * @Date:
 * @Modified By:
 */
public interface TurnstoreDao extends BaseDao<Turnstore, Integer> {
    @Query(value = "SELECT COUNT(1) AS count FROM zhxx_turnstore_store WHERE section_no in ?1", nativeQuery = true)
    Integer getStoreCountBySectionNos(List<String> list);

    @Query(value = "SELECT * FROM zhxx_turnstore_store WHERE section_no in (?1)", nativeQuery = true)
    List<Turnstore> getStoreInfoBySectionNos(List<String> list);

    @Query(value = "SELECT * FROM zhxx_turnstore_store WHERE section_no in (?1) AND out_state='未组拖'", nativeQuery = true)
    List<Turnstore> getStoreInfoBySectionNosNew(List<String> list);

    @Query(value = "SELECT * FROM zhxx_turnstore_store WHERE section_no = ?1", nativeQuery = true)
    List<Turnstore> getStoreInfoBySectionNo(String sectionNo);

    @Query(value = "SELECT * FROM zhxx_turnstore_store WHERE section_no in (?1) AND out_state=?2", nativeQuery = true)
    List<Turnstore> getStoreInfoBySectionNos(List<String> list, String status);

    @Modifying
    @Query(value = "UPDATE zhxx_turnstore_store SET out_state=?2 WHERE section_no in(?1)", nativeQuery = true)
    void updateStoreTrayStatus(List<String> list, String status);

    @Modifying
    @Query(value = "UPDATE zhxx_turnstore_store SET out_state=?2,tray_no=?3,tray_id=?4 WHERE section_no in(?1)", nativeQuery = true)
    void updateStoreTrayNo(List<String> list, String status, String trayNo, Integer trayId);

    @Modifying
    @Query(value = "DELETE FROM zhxx_turnstore_store  WHERE section_no in(?1)", nativeQuery = true)
    void deleteBySectionNo(List<String> list);

    @Query(value = "call pro_turnstore_static_in(:sDate,:eDate,:leixing)", nativeQuery = true)
    List<Map<String, Object>> getStaticIn(@Param("sDate") String sDate, @Param("eDate") String eDate, @Param("leixing") String leixing);

    @Query(value = "call pro_turnstore_static_out(:sDate,:eDate,:leixing)", nativeQuery = true)
    List<Map<String, Object>> getStaticOut(@Param("sDate") String sDate, @Param("eDate") String eDate, @Param("leixing") String leixing);

    @Modifying
    @Transactional
    @Query(value = "UPDATE yb_inspect_data SET re_check_type='复检单晶' WHERE section_no IN(?1)", nativeQuery = true)
    void updateReCheckTypeBySectionNos(List<String> sectionNos);

    @Modifying
    @Transactional
    @Query(value = "UPDATE zhxx_data_wip_state SET `state`=?2, update_time=NOW() WHERE sn IN (?1) ", nativeQuery = true)
    void updateWipStateBySnIn(List<String> sectionNos, String state);

}
