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

import com.ssj.bean.sys.assessment.domain.TeacherAssess;
import com.ssj.dao.sys.assessment.dao.TeacherAssessDao;
import com.ssj.framework.core.common.service.BaseServiceImpl;
import com.ssj.framework.core.util.ResponseEntity;
import com.ssj.service.sys.assessment.service.TeacherAssessService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * @author Mount Liu
 * @date 2019/2/26
 */
@Service
@Transactional
public class TeacherAssessServiceImpl extends BaseServiceImpl<TeacherAssess, String> implements TeacherAssessService {

    private   Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private TeacherAssessDao dao;

    @Override
    public PagingAndSortingRepository<TeacherAssess, String> getDao() {
        return dao;
    }

    @Override
    public TeacherAssess findByTeacherIdAndHomeworkId(String teacherId, String homeworkId) {
        return dao.findByTeacherIdAndHomeworkId(teacherId, homeworkId);
    }

    @Override
    public ResponseEntity assessCorrectTeacher(String parentId, String teacherId, String homeworkId, Integer level, List<String> labelList) {
        TeacherAssess teacherAssess = new TeacherAssess();
        teacherAssess.setParentId(parentId);
        teacherAssess.setTeacherId(teacherId);
        teacherAssess.setHomeworkId(homeworkId);
        String judgeLabel = "";
        if (CollectionUtils.isNotEmpty(labelList)) {
            judgeLabel = StringUtils.join(labelList, ",");
        }
        teacherAssess.setJudgeLabel(judgeLabel);
        teacherAssess.setJudgeLevel(level);
        teacherAssess.setType(2);
        teacherAssess.setCreateTime(new Date());

        dao.save(teacherAssess);

        return new ResponseEntity().success("评价成功");
    }
}
