package com.qs.mp.channel.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qs.mp.channel.domain.ChannelOrderDetail;
import com.qs.mp.channel.domain.param.ChannelMyTicketQueryParam;
import com.qs.mp.channel.domain.vo.ChannelMyTicketVO;
import com.qs.mp.channel.mapper.ChannelOrderDetailMapper;
import com.qs.mp.channel.service.IChannelOrderDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 经销商采购订单盲票包明细 服务实现类
 * </p>
 *
 * @author quanshu
 * @since 2022-03-02
 */
@Service
public class ChannelOrderDetailServiceImpl extends ServiceImpl<ChannelOrderDetailMapper, ChannelOrderDetail> implements IChannelOrderDetailService {


    @Override
    public List<ChannelMyTicketVO> listMyTicket(Long channelId, ChannelMyTicketQueryParam channelMyTicketQueryParam) {
        QueryWrapper<ChannelOrderDetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("t1.channel_id", channelId);
        if (Objects.nonNull(channelMyTicketQueryParam.getSaleStatus())) {
            queryWrapper.eq("t2.sale_status", channelMyTicketQueryParam.getSaleStatus());
        }
        if (StringUtils.isNotBlank(channelMyTicketQueryParam.getSearchTitle())) {
            queryWrapper.nested(wrapper -> {
                wrapper.likeRight("t2.pkg_no", channelMyTicketQueryParam.getSearchTitle())
                        .or()
                        .likeRight("t3.title", channelMyTicketQueryParam.getSearchTitle());
            });

        }
        queryWrapper.orderByDesc("t1.id");
        return this.baseMapper.selectListMyTicketByChannelIdAndchannelMyTicketQueryParam(queryWrapper);
    }
}
