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

import com.liangjian.dataplatform.member.entity.po.tertiary.DataDictory;
import com.liangjian.dataplatform.member.entity.po.tertiary.OrderProducts;
import io.lettuce.core.dynamic.annotation.Param;
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.NoRepositoryBean;

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


public interface OrderProductsRepository extends JpaRepository<OrderProducts, String>, JpaSpecificationExecutor<OrderProducts> {

    @Query(value ="select COUNT(DISTINCT o.OrdersCode) AS orCnt,CONVERT(varchar(100), o.CreationDate, 23) AS orDate,\n" +
            "Sum(CONVERT(bigint, p.MarketPrice) *  CONVERT(bigint, p.Amount)) AS orSum FROM Orders o LEFT JOIN OrderProducts p \n" +
            "ON p.OrdersCode=o.OrdersCode WHERE o.CreationDate>=(:beginDate) AND o.CreationDate<=(:endDate)\n" +
            "AND p.CreationDate>=(:beginDate) AND p.CreationDate<=(:endDate) GROUP BY CONVERT(varchar(100), o.CreationDate, 23) \n" +
            "order by CONVERT(varchar(100), o.CreationDate, 23);", nativeQuery = true)
    List<Map<String,Object>> findByCreationDate(@Param("beginDate") String beginDate, @Param("endDate") String endDate);
}
