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

import com.uas.platform.b2b.ps.model.PersonalProduct;
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;


/**
 * 个人物料处理数据库操作
 *
 * Created by hejq on 2018-06-05.
 */
@Repository
public interface PersonalProductDao extends JpaSpecificationExecutor<PersonalProduct>, JpaRepository<PersonalProduct, Long> {

    /**
     * 通过id更新状态
     *
     * @param status
     * @param id
     */
    @Modifying
    @Transactional
    @Query("update PersonalProduct p set p.status = :status, p.dealTime = :date where p.id = :id")
    void updateStatusById(@Param("status") Integer status, @Param("id") Long id, @Param("date") Date date);

    /**
     * 查询个人物料是否已存在
     *
     * @param userUU 用户UU
     * @param enUU 企业UU
     * @param prId 物料Id
     * @return
     */
    Integer countByUserUUAndEnUUAndPrId(Long userUU, Long enUU, Long prId);
}
