package com.yunzhupaas.engine.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.yunzhupaas.base.service.SuperServiceImpl;
import com.yunzhupaas.engine.entity.FlowAuthorizeEntity;
import com.yunzhupaas.engine.mapper.FlowAuthorizeMapper;
import com.yunzhupaas.engine.service.FlowAuthorizeService;
import com.yunzhupaas.util.RandomUtil;
import com.yunzhupaas.util.StringUtil;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 流程权限表
 *
 * @author 云筑产品开发平台组
 * @version V3.1.0
 * @copyright 深圳市乐程软件有限公司
 */
@Service
public class FlowAuthorizeServiceImpl extends SuperServiceImpl<FlowAuthorizeMapper, FlowAuthorizeEntity> implements FlowAuthorizeService {

    @Override
    public List<FlowAuthorizeEntity> getList(String taskId, String nodeCode, SFunction<FlowAuthorizeEntity, ?>... columns) {
        QueryWrapper<FlowAuthorizeEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(FlowAuthorizeEntity::getTaskId, taskId);
        if (StringUtil.isNotEmpty(nodeCode)) {
            queryWrapper.lambda().eq(FlowAuthorizeEntity::getNodeCode, nodeCode);
        }
        queryWrapper.lambda().select(columns);
        return this.list(queryWrapper);
    }

    @Override
    public void create(List<FlowAuthorizeEntity> list) {
        for (FlowAuthorizeEntity entity : list) {
            entity.setId(RandomUtil.uuId());
            this.save(entity);
        }
    }
}

