package com.ics.admin.service.impl;

import java.util.List;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ics.admin.mapper.meeting.TicketMapper;
import com.ics.admin.domain.meeting.Ticket;
import com.ics.admin.service.meeting.ITicketService;

/**
 * 优惠卷Service业务层处理
 * 
 * @author chen
 * @date 2024-02-25
 */
@Service
public class TicketServiceImpl extends ServiceImpl<TicketMapper, Ticket> implements ITicketService {
    @Autowired
    private TicketMapper ticketMapper;

    /**
     * 查询优惠卷
     * 
     * @param id 优惠卷ID
     * @return 优惠卷
     */
    @Override
    public Ticket selectTicketById(Long id) {
        return ticketMapper.selectById(id);
    }

    /**
     * 查询优惠卷列表
     * 
     * @param ticket 优惠卷
     * @return 优惠卷
     */
    @Override
    public List<Ticket> selectTicketList(Ticket ticket) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq(ticket.getParkId() !=null,"park_id", ticket.getParkId());
        queryWrapper.eq(ticket.getTitle() !=null,"title", ticket.getTitle());
        queryWrapper.eq(ticket.getTenantId() !=null,"tenant_id", ticket.getTenantId());

        return ticketMapper.selectList(queryWrapper);
    }

    /**
     * 新增优惠卷
     * 
     * @param ticket 优惠卷
     * @return 结果
     */
    @Override
    public int insertTicket(Ticket ticket) {
        return ticketMapper.insert(ticket);
    }

    /**
     * 修改优惠卷
     * 
     * @param ticket 优惠卷
     * @return 结果
     */
    @Override
    public int updateTicket(Ticket ticket) {
        return ticketMapper.updateById(ticket);
    }

    /**
     * 删除优惠卷对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteTicketByIds(String ids) {
        String[] idsArray = StrUtil.split(ids,",");
        return ticketMapper.deleteBatchIds(CollUtil.toList(idsArray));
    }

    /**
     * 删除优惠卷信息
     * 
     * @param id 优惠卷ID
     * @return 结果
     */
    @Override
    public int deleteTicketById(Long id) {
        return ticketMapper.deleteTicketById(id);
    }
}
