package me.zhengjie.modules.dm.printingCount.repository;

import me.zhengjie.modules.dm.printingCount.domain.DmPrintingCount;
import me.zhengjie.modules.dm.printingCount.service.dto.DmPrintingCountDto;
import me.zhengjie.modules.dm.printingCount.service.dto.DmPrintingCountQueryCriteria;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface DmPrintingCountRrpository extends JpaRepository<DmPrintingCount, Long>, JpaSpecificationExecutor<DmPrintingCount> {

    @Query(nativeQuery =true,value =
            "SELECT re.id,re.task_name,re.file_repeat_num,re.file_page_num,re.printer_code,re.request_user,u.`name` as 'countUser.name',d.name as 'countDept.name',de.code as 'device.code',de.name as 'device.name'," +
                    "NULL AS 'countUser.id',NULL AS 'countUser.sex',NULL AS 'countDept.remark',NULL AS 'countDept.sort_index',NULL AS 'device.update_by',NULL AS 'device.create_time',NULL AS 'device.update_time' \n" +
            " FROM dm_printing_request re \n" +
            " LEFT JOIN dm_user u ON u.id=re.request_user \n" +
            " LEFT JOIN sys_dept d ON u.dept_id = d.dept_id \n" +
            " LEFT JOIN dm_device de ON de.`code` = re.printer_code",
            countQuery=
            "SELECT count(*)\n" +
            "            LEFT JOIN dm_user u ON u.id=re.request_user \n" +
            "            LEFT JOIN sys_dept d ON u.dept_id = d.dept_id \n" +
            "            LEFT JOIN dm_device de ON re.`printer_code`=de.`code`")
    Page<DmPrintingCount> selectList (DmPrintingCountQueryCriteria criteria, Pageable pageable);
}
