package me.zhengjie.modules.dmApp.repository;

import me.zhengjie.modules.dmApp.domain.AppFoodPj;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

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

public interface AppFoodPjRepository extends JpaRepository<AppFoodPj,String>, JpaSpecificationExecutor<AppFoodPj> {
    /**
     * 菜品评价 app
     * @param
     * @return
     */
//    @Query(nativeQuery =true,value = "SELECT a.id,b.`name`,b.`code`,b.type,c.create_date as order_time,c.bh,b.picture,user_code FROM dm_order_item a " +
//            "LEFT JOIN dm_food b ON a.`code` = b.`code` LEFT JOIN dm_order_record c ON a.bh=c.bh " +
//            "WHERE c.user_code=:userCode and a.pj_type='0' and date_format( create_date, '%Y-%m-%d' ) = date_format(now(),'%Y-%m-%d') ")
//    List<AppFoodPj> selectAppFoodPj (@Param("userCode") String userCode);

    @Query(nativeQuery =true,value = "SELECT a.id,b.`name`,b.`code`,b.type,c.create_date as order_time,c.bh," +
            "l.url as picture,user_code FROM dm_order_item a inner JOIN dm_food b ON a.pid = b.id " +
            "LEFT JOIN dm_order_record c ON a.bh=c.bh LEFT JOIN dm_food_cate d ON b.type = d.cate_id " +
            "LEFT JOIN tool_local_storage l ON d.url = l.storage_id WHERE c.card=:cardid " +
            "and a.pj_type='0' and date_format( c.create_date, '%Y-%m-%d' ) = date_format(now(),'%Y-%m-%d') ")
    List<AppFoodPj> selectAppFoodPj (@Param("cardid") String cardid);
}
