/*package cn.com.qmth.examcloud.core.questions.starter.sync;

import cn.com.qmth.examcloud.core.questions.dao.CourseRepo;
import cn.com.qmth.examcloud.core.questions.dao.entity.Course;
import cn.com.qmth.examcloud.core.questions.dao.entity.Specialty;
import cn.com.qmth.examcloud.core.questions.dao.ExtractConfigRepo;
import cn.com.qmth.examcloud.core.questions.dao.PaperRepo;
import cn.com.qmth.examcloud.core.questions.dao.entity.ExtractConfig;
import cn.com.qmth.examcloud.core.questions.dao.entity.Paper;
import cn.com.qmth.examcloud.core.questions.dao.QuesRepo;
import cn.com.qmth.examcloud.core.questions.dao.entity.Question;
import cn.com.qmth.examcloud.core.questions.base.CommonUtils;

import com.qmth.commons.dataSync.core.annotations.DataReceive;
import com.qmth.commons.dataSync.core.entity.BaseSyncData;
import com.qmth.commons.dataSync.core.service.DataSyncService;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

*//**
 * Created by songyue on 17/8/3.
 *//*
@Service
public class DataReceiveService {

    private static final Logger log = LoggerFactory.getLogger(DataReceiveService.class);

    @Autowired
    DataSyncService dataSyncService;

    @Autowired
    QuesRepo quesRepo;

    @Autowired
    PaperRepo paperRepo;

    @Autowired
    CourseRepo courseRepo;

    @Autowired
    ExtractConfigRepo extractConfigRepo;

    @DataReceive(domain = "cn.com.qmth.examcloud.core.questions.base.core.CourseSync")
    public synchronized void readCourse(BaseSyncData baseSyncData) {
        log.info("-----------coursesync start---------");
        log.info(baseSyncData.toString());
        String courseCode = baseSyncData.getEntity().get("code");
        String orgId = baseSyncData.getEntity().get("orgId");
        String courseName = baseSyncData.getEntity().get("name");
        String courseLevel = baseSyncData.getEntity().get("level");
        String enable = baseSyncData.getEntity().get("enable");
        if (StringUtils.isEmpty(courseCode)
                || StringUtils.isEmpty(orgId)
                || StringUtils.isEmpty(courseName)
                || StringUtils.isEmpty(courseLevel)
                || StringUtils.isEmpty(enable)) {
            log.error("entity value is null");
            return;
        }

        Course localCourse = courseRepo.findFirstByCodeAndOrgId(courseCode,orgId);
        if(localCourse != null){
            localCourse.setName(courseName);
            localCourse.setLevel(courseLevel);
            localCourse.setEnable(enable);
            localCourse.setUpdateTime(CommonUtils.getCurDateTime());
            courseRepo.save(localCourse);
        }else{
            Course tempCourse = new Course();
            tempCourse.setCode(courseCode);
            tempCourse.setName(courseName);
            tempCourse.setLevel(courseLevel);
            tempCourse.setEnable(enable);
            tempCourse.setOrgId(orgId);
            tempCourse.setCreateTime(CommonUtils.getCurDateTime());
            courseRepo.save(tempCourse);
        }


        List<ExtractConfig> extractConfigs= extractConfigRepo.findByCourseCodeAndOrgId(courseCode,orgId);
        if (extractConfigs != null && extractConfigs.size() > 0) {
            for (ExtractConfig extractConfig : extractConfigs) {
                extractConfig.setCourseName(courseName);
                Course course = extractConfig.getCourse();
                if(course != null){
                    course.setName(courseName);
                    course.setLevel(courseLevel);
                    course.setEnable(enable);
                    course.setUpdateTime(CommonUtils.getCurDateTime());
                    extractConfig.setCourse(course);
                }else{
                    Course tempCourse = new Course();
                    tempCourse.setCode(courseCode);
                    tempCourse.setName(courseName);
                    tempCourse.setLevel(courseLevel);
                    tempCourse.setEnable(enable);
                    tempCourse.setOrgId(orgId);
                    tempCourse.setCreateTime(CommonUtils.getCurDateTime());
                    extractConfig.setCourse(tempCourse);
                }
            }
            extractConfigRepo.save(extractConfigs);
        }

        List<Paper> papers = paperRepo.findByCourseNoAndOrgId(courseCode, orgId);
        if (papers != null && papers.size() > 0) {
            for (Paper paper : papers) {
                Course course = paper.getCourse();
                if(course != null){
                    course.setName(courseName);
                    course.setLevel(courseLevel);
                    course.setEnable(enable);
                    course.setUpdateTime(CommonUtils.getCurDateTime());
                    paper.setCourse(course);
                }else{
                    Course tempCourse = new Course();
                    tempCourse.setCode(courseCode);
                    tempCourse.setName(courseName);
                    tempCourse.setLevel(courseLevel);
                    tempCourse.setEnable(enable);
                    tempCourse.setOrgId(orgId);
                    tempCourse.setCreateTime(CommonUtils.getCurDateTime());
                    paper.setCourse(tempCourse);
                }
            }
            paperRepo.save(papers);
        }



        List<Question> questions = quesRepo.findByCourseNoAndOrgId(courseCode, orgId);
        if (questions != null && questions.size() > 0) {
            for (Question question : questions) {
                Course course = question.getCourse();
                if(course != null){
                    course.setName(courseName);
                    course.setLevel(courseLevel);
                    course.setEnable(enable);
                    course.setUpdateTime(CommonUtils.getCurDateTime());
                    question.setCourse(course);
                }else{
                    Course tempCourse = new Course();
                    tempCourse.setCode(courseCode);
                    tempCourse.setName(courseName);
                    tempCourse.setLevel(courseLevel);
                    tempCourse.setEnable(enable);
                    tempCourse.setOrgId(orgId);
                    tempCourse.setCreateTime(CommonUtils.getCurDateTime());
                    question.setCourse(tempCourse);
                }
            }
            quesRepo.save(questions);
        }

        log.info("-----------coursesync end---------");
    }

    @DataReceive(domain = "cn.com.qmth.examcloud.core.questions.base.core.SpecialtySync")
    public synchronized void readSpecialty(BaseSyncData baseSyncData) {
        log.info("-----------specialty start---------");
        log.info(baseSyncData.toString());
        String specialtyCode = baseSyncData.getEntity().get("code");
        String orgId = baseSyncData.getEntity().get("orgId");
        String specialtyName = baseSyncData.getEntity().get("name");
        String enable = baseSyncData.getEntity().get("enable");
        if (StringUtils.isEmpty(specialtyCode)
                || StringUtils.isEmpty(orgId)
                || StringUtils.isEmpty(specialtyName)
                || StringUtils.isEmpty(enable)) {
            log.error("entity value is null");
            return;
        }
        
        boolean specialtyEnable = false;
        if(enable == "true"){
        	specialtyEnable = true;
        }

        List<Paper> papers = paperRepo.findBySpecialtyCodeAndOrgId(specialtyCode, orgId);
        if (papers != null && papers.size() > 0) {
            for (Paper paper : papers) {
                Specialty specialty = paper.getSpecialty();
                if(specialty != null){
                	specialty.setName(specialtyName);
                	specialty.setEnable(specialtyEnable);
                	specialty.setUpdateTime(new Date());
                    paper.setSpecialty(specialty);
                }else{
                	Specialty tempSpecialty = new Specialty();
                	tempSpecialty.setCode(specialtyCode);
                	tempSpecialty.setCreateTime(new Date());
                	tempSpecialty.setEnable(specialtyEnable);
                	tempSpecialty.setOrgId(Long.valueOf(orgId));
                	tempSpecialty.setName(specialtyName);
                	paper.setSpecialty(tempSpecialty);
                }
            }
            paperRepo.save(papers);
        }

        List<Question> questions = quesRepo.findBySpecialtyCodeAndOrgId(specialtyCode, orgId);
        if (questions != null && questions.size() > 0) {
            for (Question question : questions) {
            	Specialty specialty = question.getSpecialty();
                if(specialty != null){
                	specialty.setName(specialtyName);
                	specialty.setEnable(specialtyEnable);
                	specialty.setUpdateTime(new Date());
                	question.setSpecialty(specialty);
                }else{
                	Specialty tempSpecialty = new Specialty();
                	tempSpecialty.setCode(specialtyCode);
                	tempSpecialty.setCreateTime(new Date());
                	tempSpecialty.setEnable(specialtyEnable);
                	tempSpecialty.setOrgId(Long.valueOf(orgId));
                	tempSpecialty.setName(specialtyName);
                	question.setSpecialty(tempSpecialty);
                }
            }
            quesRepo.save(questions);
        }

        log.info("-----------coursesync end---------");
    }

}
*/