package com.sqx.modules.course.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sqx.common.utils.Result;
import com.sqx.modules.course.dao.CourseClassificationDao;
import com.sqx.modules.course.dao.CourseUserDao;
import com.sqx.modules.course.entity.CourseUser;
import com.sqx.modules.course.service.CourseUserService;
import com.sqx.modules.orders.service.OrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

@Service
@Slf4j
public class CourseUserServiceImpl extends ServiceImpl<CourseUserDao, CourseUser> implements CourseUserService {
    @Autowired
    private CourseClassificationDao courseClassificationDao;
    @Autowired
    private OrdersService ordersService;

    @Override
    public void updateTime(Long courseId) {
        QueryWrapper<CourseUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("course_id", courseId);
        CourseUser bean = baseMapper.selectOne(queryWrapper);
        SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        bean.setUpdateTime(df1.format(new Date()));
        UpdateWrapper<CourseUser> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("course_id", courseId);
        baseMapper.update(bean, updateWrapper);
    }


    @Override
    public Result insertCourseUser(CourseUser courseUser) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        courseUser.setCreateTime(df.format(new Date()));
        baseMapper.insert(courseUser);
        return Result.success();
    }


}
