
package org.jeecg.modules.workFlow.flowlong.mybatisplus.impl;

import org.jeecg.modules.workFlow.flowlong.engine.dao.FlwTaskActorDao;
import org.jeecg.modules.workFlow.flowlong.engine.entity.FlwTaskActor;
import org.jeecg.modules.workFlow.flowlong.mybatisplus.mapper.FlwTaskActorMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import java.util.List;

/**
 * 任务参与者数据访问层接口实现类
 *
 * <p>
 * <a href="https://aizuda.com">官网</a>尊重知识产权，不允许非法使用，后果自负，不允许非法使用，后果自负
 * </p>
 *
 * @author hubin
 * @since 1.0
 */
public class FlwTaskActorDaoImpl implements FlwTaskActorDao {
    private final FlwTaskActorMapper taskActorMapper;

    public FlwTaskActorDaoImpl(FlwTaskActorMapper taskActorMapper) {
        this.taskActorMapper = taskActorMapper;
    }

    @Override
    public boolean insert(FlwTaskActor taskActor) {
        return taskActorMapper.insert(taskActor) > 0;
    }

    @Override
    public boolean deleteById(Long id) {
        return taskActorMapper.deleteById(id) > 0;
    }

    @Override
    public boolean deleteByIds(List<Long> ids) {
        return taskActorMapper.delete(Wrappers.<FlwTaskActor>lambdaQuery()
                .in(FlwTaskActor::getId, ids)) > 0;
    }

    @Override
    public boolean deleteByTaskId(Long taskId) {
        return taskActorMapper.delete(Wrappers.<FlwTaskActor>lambdaQuery()
                .eq(FlwTaskActor::getTaskId, taskId)) > 0;
    }

    @Override
    public boolean deleteByInstanceIds(List<Long> instanceIds) {
        return taskActorMapper.delete(Wrappers.<FlwTaskActor>lambdaQuery()
                .in(FlwTaskActor::getInstanceId, instanceIds)) > 0;
    }

    @Override
    public boolean deleteByTaskIdAndAgentType(Long taskId, int agentType) {
        return taskActorMapper.delete(Wrappers.<FlwTaskActor>lambdaQuery()
                .eq(FlwTaskActor::getTaskId, taskId)
                .eq(FlwTaskActor::getAgentType, agentType)) > 0;
    }

    @Override
    public boolean deleteByTaskIdAndActorIds(Long taskId, List<String> actorIds) {
        return taskActorMapper.delete(Wrappers.<FlwTaskActor>lambdaQuery()
                .eq(FlwTaskActor::getTaskId, taskId)
                .in(FlwTaskActor::getActorId, actorIds)) > 0;
    }

    @Override
    public boolean updateById(FlwTaskActor taskActor) {
        return taskActorMapper.updateById(taskActor) > 0;
    }

    @Override
    public List<FlwTaskActor> selectListByInstanceId(Long instanceId) {
        return taskActorMapper.selectList(Wrappers.<FlwTaskActor>lambdaQuery()
                .eq(FlwTaskActor::getInstanceId, instanceId));
    }

    @Override
    public List<FlwTaskActor> selectListByTaskId(Long taskId) {
        return taskActorMapper.selectList(Wrappers.<FlwTaskActor>lambdaQuery()
                .eq(FlwTaskActor::getTaskId, taskId));
    }

    @Override
    public List<FlwTaskActor> selectListByTaskIds(List<Long> taskIds) {
        return taskActorMapper.selectList(Wrappers.<FlwTaskActor>lambdaQuery()
                .in(FlwTaskActor::getTaskId, taskIds));
    }

    @Override
    public List<FlwTaskActor> selectListByTaskIdAndActorId(Long taskId, String actorId) {
        return taskActorMapper.selectList(Wrappers.<FlwTaskActor>lambdaQuery()
                .eq(FlwTaskActor::getTaskId, taskId)
                .eq(FlwTaskActor::getActorId, actorId));
    }

    @Override
    public List<FlwTaskActor> selectListByActorId(String actorId) {
        return taskActorMapper.selectList(Wrappers.<FlwTaskActor>lambdaQuery()
                .eq(FlwTaskActor::getActorId, actorId));
    }

    @Override
    public Long selectCountByTaskIdAndActorId(Long taskId, String actorId) {
        return taskActorMapper.selectCount(Wrappers.<FlwTaskActor>lambdaQuery()
                .eq(FlwTaskActor::getTaskId, taskId)
                .eq(FlwTaskActor::getActorId, actorId));
    }
}
