package com.zkqy.execution.produce.dispersed.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.zkqy.execution.produce.dispersed.entity.BpmExecuteNodeForm;
import com.zkqy.execution.produce.dispersed.mapper.BpmExecuteNodeFormMapper;
import com.zkqy.execution.produce.dispersed.service.IBpmExecuteNodeFormService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 执行节点单Service业务层处理
 *
 * @author zkqy
 * @date 2023-12-07
 */
@Service
public class BpmExecuteNodeFormServiceImpl implements IBpmExecuteNodeFormService {

    @Autowired
    private BpmExecuteNodeFormMapper bpmExecuteNodeFormMapper;

    /**
     * 查询执行节点单
     *
     * @param id 执行节点单主键
     * @return 执行节点单
     */
    @Override
    public BpmExecuteNodeForm selectBpmExecuteNodeFormById(Long id) {
        return bpmExecuteNodeFormMapper.selectBpmExecuteNodeFormById(id);
    }

    /**
     * 查询执行节点单列表
     *
     * @param bpmExecuteNodeForm 执行节点单
     * @return 执行节点单
     */
    @Override
    public List<BpmExecuteNodeForm> selectBpmExecuteNodeFormList(BpmExecuteNodeForm bpmExecuteNodeForm) {
        return bpmExecuteNodeFormMapper.selectBpmExecuteNodeFormList(bpmExecuteNodeForm);
    }

    /**
     * 新增执行节点单
     *
     * @param bpmExecuteNodeForm 执行节点单
     * @return 结果
     */
    @Override
    public int insertBpmExecuteNodeForm(BpmExecuteNodeForm bpmExecuteNodeForm) {
        return bpmExecuteNodeFormMapper.insertBpmExecuteNodeForm(bpmExecuteNodeForm);
    }

    /**
     * 修改执行节点单
     *
     * @param bpmExecuteNodeForm 执行节点单
     * @return 结果
     */
    @Override
    public int updateBpmExecuteNodeForm(BpmExecuteNodeForm bpmExecuteNodeForm) {
        return bpmExecuteNodeFormMapper.updateBpmExecuteNodeForm(bpmExecuteNodeForm);
    }

    /**
     * 批量删除执行节点单
     *
     * @param ids 需要删除的执行节点单主键
     * @return 结果
     */
    @Override
    public int deleteBpmExecuteNodeFormByIds(Long[] ids) {
        return bpmExecuteNodeFormMapper.deleteBpmExecuteNodeFormByIds(ids);
    }

    /**
     * 删除执行节点单信息
     *
     * @param id 执行节点单主键
     * @return 结果
     */
    @Override
    public int deleteBpmExecuteNodeFormById(Long id) {
        return bpmExecuteNodeFormMapper.deleteBpmExecuteNodeFormById(id);
    }

    /**
     * 获取当前流程所有节点的表单编码以及表单类型
     *
     * @param processKey 流程编码
     * @return
     */
    @Override
    public Map<String, String> selectNodeFromInfos(String processKey) {
        Map<String, String> map = new HashMap<>();
        List<Map<String, String>> infos = bpmExecuteNodeFormMapper.selectNodeFromInfos(processKey);
        infos.forEach(item -> map.put(item.get("formKey"), item.get("formType")));
        return map;
    }

    @Override
    public BpmExecuteNodeForm getBpmExecuteNodeForm(String taskProcessKey, String taskNodeKey, String taskScriptKey) {
        return bpmExecuteNodeFormMapper.selectBpmExecuteNodeFormByTpKAndTnkAndTsk(taskProcessKey, taskNodeKey, taskScriptKey);
    }
}
