package com.liangjian.dataplatform.member.dao.tertiary;

import com.liangjian.dataplatform.member.dao.JpaLifeCycleRepository;
import com.liangjian.dataplatform.member.entity.po.tertiary.Product;
import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;


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

public interface ProductRepository extends JpaLifeCycleRepository<Product,String> {

        @Query(value = "select ProductCode, ProductName, CommonTitle from  Mall.dbo.Product", nativeQuery = true)
        List<Map<String, Object>> findAllData();


//        @Query(value = "UPDATE Mall.dbo.Product set ProductName = #{#product.productName} , CommonTitle = '123' , Manufacturer = #{#product.manufacturer} , Introduction = #{#product.introduction} where ProductCode = #{#product.productCode}", nativeQuery = true)
//        int updateByProductCode(@Param("product") Product product);

        @Modifying
        @Transactional
        @Query(value = "UPDATE Mall.dbo.Product set ProductName = (:productName) , CommonTitle = (:commonTitle) , Manufacturer = (:manufacturer) , Introduction = (:Introduction) where ProductCode = (:productCode)", nativeQuery = true)
        int updateByProductCode(@Param("productName") String productName,
                                @Param("commonTitle") String commonTitle,
                                @Param("manufacturer") String manufacturer,
                                @Param("introduction") String Introduction,
                                @Param("productCode") Integer productCode);
}
