package cn.com.qmth.examcloud.core.questions.service.impl;

import cn.com.qmth.examcloud.core.basic.api.CourseCloudService;
import cn.com.qmth.examcloud.core.basic.api.bean.CourseBean;
import cn.com.qmth.examcloud.core.basic.api.request.GetCourseReq;
import cn.com.qmth.examcloud.core.basic.api.response.GetCourseResp;
import cn.com.qmth.examcloud.core.questions.base.CommonUtils;
import cn.com.qmth.examcloud.core.questions.dao.entity.Course;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author weiwenhai
 * @date 2018.9.28
 * @company qmth
 * @description 课程对象转换
 */
@Service
public class CourseService {


    @Autowired
    CourseCloudService courseCloudService;

    public Course getCourse(Long orgId, String courseCode) {
        GetCourseReq req = new GetCourseReq();
        req.setRootOrgId(orgId);
        req.setCode(courseCode);
        GetCourseResp resp = courseCloudService.getCourse(req);
        CourseBean courseBean = resp.getCourseBean();
        Course course = new Course();
        BeanUtils.copyProperties(courseBean, course);
        if (courseBean.getEnable()) {
            course.setEnable("true");
        } else {
            course.setEnable("false");
        }
        course.setId(courseBean.getId() + "");
        course.setOrgId(courseBean.getRootOrgId() + "");
        course.setCreateTime(CommonUtils.getCurDateTime());
        return course;
    }

}
