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.course.CourseQueryRequest;
import com.greenorange.promotion.model.entity.Course;
import com.greenorange.promotion.service.course.CourseService;
import com.greenorange.promotion.mapper.CourseMapper;
import com.greenorange.promotion.utils.SqlUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
* @author 35880
* @description 针对表【course(课程表)】的数据库操作Service实现
* @createDate 2025-06-23 18:29:49
*/
@Service
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course>
    implements CourseService{


    /**
     * 获取查询条件
     */
    @Override
    public QueryWrapper<Course> getQueryWrapper(CourseQueryRequest courseQueryRequest) {
        String name = courseQueryRequest.getName();
        String type = courseQueryRequest.getType();
        Boolean isShelves = courseQueryRequest.getIsShelves();
        String sortField = courseQueryRequest.getSortField();
        String sortOrder = courseQueryRequest.getSortOrder();
        QueryWrapper<Course> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(name), "name", name);
        queryWrapper.eq(StringUtils.isNotBlank(type), "type", type);
        queryWrapper.eq(ObjectUtils.isNotEmpty(isShelves), "isShelves", isShelves);
        queryWrapper.orderBy(SqlUtils.validSortField(sortField), sortOrder.equals(CommonConstant.SORT_ORDER_ASC), sortField);
        return queryWrapper;
    }
}




