package com.uas.platform.b2b.manage.dao;

import com.uas.platform.b2b.manage.model.DeputyOrder;
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.sql.SQLException;

/**
 * 代采订单
 *
 * @author hejq
 * @date 2018-11-29 9:52
 */
@Repository
public interface DeputyOrderDao extends JpaSpecificationExecutor<DeputyOrder>, JpaRepository<DeputyOrder, Long> {

    /**
     * 更新代采订单状态
     *
     * @param id 代采订单id
     * @param status 状态码
     * @param downloadStatus 下载状态
     */
    @Transactional(rollbackFor = SQLException.class)
    @Modifying(clearAutomatically = true)
    @Query("update DeputyOrder d set d.statuscode = :status, d.downloadstatus = :downloadStatus where d.id = :id")
    void updateStatus(@Param("id") Long id, @Param("status") Integer status, @Param("downloadStatus") String downloadStatus);
}
