package com.ssj.service.sys.wrongbook.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.dubbo.config.annotation.Service;
import com.ssj.bean.sys.wrongbook.domain.HomeworkWrongQuestion;
import com.ssj.bean.weixin.libmy.domain.LibVip;
import com.ssj.dao.sys.wrongbook.dao.WrongBookDao;
import com.ssj.dao.sys.wrongbook.dao.WrongBookQueryDao;
import com.ssj.framework.core.common.service.BaseServiceImpl;
import com.ssj.service.conch.conch.vo.WrongQuestionRecordsVO;
import com.ssj.service.sys.wrongbook.service.WrongBookService;

import java.util.Date;
import java.util.List;

@Service(version ="1.0")
@Transactional
public class WrongBookServiceImpl extends BaseServiceImpl<HomeworkWrongQuestion, String> implements WrongBookService {

    @Autowired
    private WrongBookDao wrongBookDao;
    @Autowired
    private WrongBookQueryDao wrongBookQueryDao;

    @Override
    public PagingAndSortingRepository<HomeworkWrongQuestion, String> getDao() {
        return wrongBookDao;
    }

    @Override
    public List<HomeworkWrongQuestion> findByHomeworkPictureIdIn(List<String> homeworkPictureIdList) {
        return wrongBookDao.findByHomeworkPictureIdIn(homeworkPictureIdList);
    }

    @Override
    public List<HomeworkWrongQuestion> findByHomeworkId(String workId) {
        return wrongBookDao.findByHomeworkId(workId);
    }

    @Override
    public void addWrongQuestion(String filePath, LibVip vip) {
        HomeworkWrongQuestion wrongQuestion = new HomeworkWrongQuestion();
        wrongQuestion.setImage(filePath);
        wrongQuestion.setCreateTime(new Date());
        if (vip != null) {
            wrongQuestion.setStudentId(vip.getId());
            wrongQuestion.setDerver(vip.getDerver());
        }
        this.save(wrongQuestion);
    }

    @Override
    public List<WrongQuestionRecordsVO> findByDerver(String derver) {
        return wrongBookQueryDao.findByDerver(derver);
    }
}
