package com.greenorange.promotion.service.course.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.greenorange.promotion.constant.CommonConstant;
import com.greenorange.promotion.model.dto.courseChapter.CourseChapterQueryRequest;
import com.greenorange.promotion.model.entity.CourseChapter;
import com.greenorange.promotion.service.course.CourseChapterService;
import com.greenorange.promotion.mapper.CourseChapterMapper;
import com.greenorange.promotion.utils.SqlUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
* @author 35880
* @description 针对表【course_chapter(课程章节表)】的数据库操作Service实现
* @createDate 2025-06-23 18:30:28
*/
@Service
public class CourseChapterServiceImpl extends ServiceImpl<CourseChapterMapper, CourseChapter>
    implements CourseChapterService{

    /**
     * 获取查询条件
     */
    @Override
    public QueryWrapper<CourseChapter> getQueryWrapper(CourseChapterQueryRequest courseChapterQueryRequest) {
        Long courseId = courseChapterQueryRequest.getCourseId();
        String name = courseChapterQueryRequest.getName();
        String permissions = courseChapterQueryRequest.getPermissions();
        String sortField = courseChapterQueryRequest.getSortField();
        String sortOrder = courseChapterQueryRequest.getSortOrder();
        QueryWrapper<CourseChapter> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("courseId", courseId);
        queryWrapper.eq(StringUtils.isNotBlank(name), "name", name);
        queryWrapper.eq(StringUtils.isNotBlank(permissions), "permissions", permissions);
        queryWrapper.orderBy(SqlUtils.validSortField(sortField), sortOrder.equals(CommonConstant.SORT_ORDER_ASC), sortField);
        return queryWrapper;
    }
}




