package com.dcs.hnyz.service.impl;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dcs.common.enums.GeneralStatus;
import com.dcs.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.dcs.hnyz.mapper.ActionBindingMapper;
import com.dcs.hnyz.domain.ActionBinding;
import com.dcs.hnyz.service.IActionBindingService;

import javax.annotation.Resource;

/**
 * 动作关联管理Service业务层处理
 * 
 * @author hmy
 * @date 2025-04-28
 */
@Service
public class ActionBindingServiceImpl implements IActionBindingService 
{
    @Resource
    private ActionBindingMapper actionBindingMapper;

    /**
     * 查询动作关联管理
     * 
     * @param id 动作关联管理主键
     * @return 动作关联管理
     */
    @Override
    public ActionBinding selectActionBindingById(Long id)
    {
        return actionBindingMapper.selectById(id);
    }

    /**
     * 查询动作关联管理列表
     * 
     * @param actionBinding 动作关联管理
     * @return 动作关联管理
     */
    @Override
    public List<ActionBinding> selectActionBindingList(ActionBinding actionBinding)
    {
        return actionBindingMapper.selectActionBindingList(actionBinding);
    }

    /**
     * 新增动作关联管理
     * 
     * @param actionBinding 动作关联管理
     * @return 结果
     */
    @Override
    public int insertActionBinding(ActionBinding actionBinding)
    {
        actionBinding.setCreateTime(DateUtils.getNowDate());
        return actionBindingMapper.insert(actionBinding);
    }

    /**
     * 修改动作关联管理
     * 
     * @param actionBinding 动作关联管理
     * @return 结果
     */
    @Override
    public int updateActionBinding(ActionBinding actionBinding)
    {
        actionBinding.setUpdateTime(DateUtils.getNowDate());
        return actionBindingMapper.updateById(actionBinding);
    }

    /**
     * 批量删除动作关联管理
     * 
     * @param ids 需要删除的动作关联管理主键
     * @return 结果
     */
    @Override
    public int deleteActionBindingByIds(Long[] ids)
    {
        return actionBindingMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除动作关联管理信息
     * 
     * @param id 动作关联管理主键
     * @return 结果
     */
    @Override
    public int deleteActionBindingById(Long id)
    {
        return actionBindingMapper.deleteById(id);
    }

    @Override
    public int changeStatus(ActionBinding actionBinding) {
        return actionBindingMapper.updateById(actionBinding);
    }

    @Override
    public List<Long> selectBindActionIdsByActionId(Long actionId) {
        LambdaQueryWrapper<ActionBinding> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ActionBinding::getActionId,actionId);
        wrapper.eq(ActionBinding::getStatus, GeneralStatus.ENABLE.getCode());
        wrapper.select(ActionBinding::getBindActionId);
        List<ActionBinding> actionBindings = actionBindingMapper.selectList(wrapper);
        return actionBindings.stream().map(ActionBinding::getBindActionId).collect(Collectors.toList());
    }
}
