package com.ssj.dao.load.data.impl;

import com.ssj.dao.load.data.LoadDataDao;
import com.ssj.framework.core.persistence.PagingHibernateJdbcDao;
import com.ssj.service.conch.teacher.library.dto.FeedbackDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository
public class LoadDataDaoImpl implements LoadDataDao {

    @Autowired
    private PagingHibernateJdbcDao dao;

    @Override
    public List<FeedbackDTO> findFeedbackHistory(String date) {

        StringBuilder sb = new StringBuilder();
        sb.append(" select push.*, scon_homework_picture.file_key\n" +
                "        from (select id        push_id,\n" +
                "                vip_id,\n" +
                "                suggest,\n" +
                "                push_time push_time\n" +
                "                from zyb_student_push\n" +
                "                where   ? > push_time\n" +
                "        and type > 0\n" +
                "        order by push_time desc\n" +
                "         ) push\n" +
                "        left join scon_homework_picture\n" +
                "        on push.vip_id = scon_homework_picture.vip_id\n" +
                "        and to_days(push.push_time) = to_days(scon_homework_picture.create_time)\n" +
                "        and scon_homework_picture.is_delete = 0\n" +
                "        order by push.push_time desc, field(scon_homework_picture.subject, '语文', '数学', '英语')")
                ;
        List<Object> params = new ArrayList<>();
        params.add(date);
        return dao.findList(sb.toString(), params.toArray(), FeedbackDTO.class);
    }
}
