package com.engine.htxc.workflow.select.service.impl;

import com.engine.core.impl.Service;
import com.engine.htxc.commonutil.db.DbTools;
import com.engine.htxc.workflow.select.service.WorkflowSelectService;
import com.engine.integration.util.StringUtils;
import weaver.general.Util;

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

/**
 * <p>流程查询修改</p>
 * @author K1810015
 * @version 1.0.0
 * @ClassName WorkflowselectService.java
 * @createTime 2022-08-15 09:56:00
 */
public class WorkflowSelectServiceImpl extends Service implements WorkflowSelectService {

    private DbTools dbTools=new DbTools();

    @Override
    public boolean getnodeflag(Map<String, Object> map) {
        String requestid= Util.null2String(map.get("requestid"));
        String nodenumber= Util.null2String(map.get("nodenumber"));
        String isfreenode=Util.null2String(map.get("isfreenode"));
        String deptid=Util.null2String(map.get("deptid"));
        String userid=Util.null2String(map.get("userid"));
        if(StringUtils.isBlank(requestid) || StringUtils.isBlank(nodenumber)){
            return  false;
        }
        String nodeid= dbTools.getNodeunnumberToid(nodenumber);

        if(StringUtils.isBlank(nodeid)){
            return false;
        }

        String sql=" select * from workflow_requestlog where 1=1 and requestid=?  ";
        if(!StringUtils.isBlank(deptid)){
            sql+=" and operatordept in ("+ Arrays.stream(deptid.split(",")).collect(Collectors.joining(","))+") ";
        }
        if(!StringUtils.isBlank(userid)){
            sql+="  and operator in ( select id from hrmresource where workcode in ( select workcode from hrmresource where id in ("+userid+") ) )";
        }
        if(StringUtils.isBlank(isfreenode)){
            sql+=" and nodeid<0";
        }else {
            sql+=" and nodeid='"+nodeid+"'";
        }
        List<Map<String,Object>> listmap= dbTools.getSqlToList(sql,requestid);
        if(listmap!=null && listmap.size()>0){
            return true;
        }
        return false;
    }
}
