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.courseOrder.CourseOrderQueryRequest;
import com.greenorange.promotion.model.entity.CourseOrder;
import com.greenorange.promotion.service.course.CourseOrderService;
import com.greenorange.promotion.mapper.CourseOrderMapper;
import com.greenorange.promotion.utils.SqlUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
* @author 35880
* @description 针对表【course_order(课程订单表)】的数据库操作Service实现
* @createDate 2025-06-23 18:31:13
*/
@Service
public class CourseOrderServiceImpl extends ServiceImpl<CourseOrderMapper, CourseOrder>
    implements CourseOrderService{


    /**
     * 获取查询条件
     */
    @Override
    public QueryWrapper<CourseOrder> getQueryWrapper(CourseOrderQueryRequest courseOrderQueryRequest) {
        String orderNumber = courseOrderQueryRequest.getOrderNumber();
        String orderStatus = courseOrderQueryRequest.getOrderStatus();
        String sortField = courseOrderQueryRequest.getSortField();
        String sortOrder = courseOrderQueryRequest.getSortOrder();
        QueryWrapper<CourseOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(orderNumber), "orderNumber", orderNumber);
        queryWrapper.eq(StringUtils.isNotBlank(orderStatus), "orderStatus", orderStatus);
        queryWrapper.orderBy(SqlUtils.validSortField(sortField), sortOrder.equals(CommonConstant.SORT_ORDER_ASC), sortField);
        return queryWrapper;
    }
}




