package com.uas.platform.b2b.dao;

import com.uas.platform.b2b.model.PurchaseTender;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * Created by dongbw on 17/03/07 14:10.
 */
@Repository
public interface PurchaseTenderDao extends JpaSpecificationExecutor<PurchaseTender>, JpaRepository<PurchaseTender, Long> {

    List<PurchaseTender> findByEnUUAndCode(Long uu, String code);

    /**
     * 全包定标时，修改招标单
     * @param tenderIds
     * @param modified
     */
    @Modifying@Transactional
    @Query("update PurchaseTender p set p.modified = :modified,p.auditStatus = 0 where p.id in :tenderIds")
    void updateTenderDecide(@Param("tenderIds") Set<Long> tenderIds, @Param("modified") Date modified);

    /**
     * 全包定标时，修改投标明细
     * @param applyStatus
     * @param reason
     * @param saleTenderId
     */
    @Modifying@Transactional
    @Query("update SaleTenderItem s set s.applyStatus = :applyStatus,s.description = :reason where s.saleTender.id = :saleTenderId")
    void updateSaleTenderItemDecide(@Param("applyStatus") Short applyStatus, @Param("reason") String reason, @Param("saleTenderId") Long saleTenderId);
}
