package com.ruoyi.web.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.web.domain.entity.EventAssign;
import com.ruoyi.web.mapper.EventAssignMapper;
import com.ruoyi.web.service.EventAssignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 *
 */
@Service
@Slf4j
public class EventAssignServiceImpl extends ServiceImpl<EventAssignMapper, EventAssign>
        implements EventAssignService {

    /**
     * 删除事件分配数据
     * @param eventIds
     * @param userId
     * @return
     */
    @Override
    @Transactional
    public boolean deleteEventAssign(List<Integer> eventIds, Integer userId) {
        if(CollectionUtil.isEmpty(eventIds) || ObjectUtil.isEmpty(userId)){
            return false;
        }
        // 构建查询条件
        QueryWrapper<EventAssign> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("event_id", eventIds)
                .eq("user_id", userId);

        long count = count(queryWrapper);
        if (count == 0) {
            log.info("没有找到匹配的事件记录，无需删除，eventIds={}, userId={}", eventIds, userId);
            return true;
        }

        // 执行删除操作
        return remove(queryWrapper);
    }
}




