package com.weavernorth.nsyh.opinion.cmd;

import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.User;

import java.util.*;

/**
 * @Author : 孙浩
 * @Date : 2022/3/1 9:58
 * @Version 1.0
 */
public class GetNodesCmd extends AbstractCommonCommand<Map<String,Object>> {

    public GetNodesCmd(User user, Map<String,Object> params) {
        this.user = user;
        this.params = params;
    }

    @Override
    public BizLogContext getLogContext() {
        return null;
    }

    @Override
    public Map<String, Object> execute(CommandContext commandContext) {
        Map<String, Object> apidatas = new HashMap<String, Object>();
        if (null == user){
            apidatas.put("hasRight", false);
            apidatas.put("msg", "用户信息不存在");
            return apidatas;
        }
        try {
//            int workflowid =  Util.getIntValue(Util.null2String(params.get("workflowid")),0);
//            if(workflowid==0){
//                apidatas.put("hasRight", false);
//                apidatas.put("msg", "参数不足");
//                return apidatas;
//            }
            RecordSet rs = new RecordSet();
            List<Map<String,String>> nodeList = new ArrayList<>();
            rs.executeQuery("select workflowid,nodename from uf_ycqzyjxx where zt = 0 ");
            while (rs.next()){
                String workflowid = Util.null2String(rs.getString("workflowid"));
                String nodeid = Util.null2String(rs.getString("nodename"));
                if(!"".equals(workflowid)&&!"".equals(nodeid)){
                    Map<String,String> nodemap = new HashMap<>();
                    nodemap.put("workflowid",workflowid);
                    nodemap.put("nodeid",nodeid);
                    nodeList.add(nodemap);
                }
            }
            apidatas.put("nodelist",nodeList);
            apidatas.put("hasRight", true);
        } catch (Exception e) {
            apidatas.put("hasRight", false);
            apidatas.put("msg", "Exception WorkflowTodoCmd"+e);
        }
        return apidatas;
    }
}
