package com.engine.htsc.itxqlc.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.BaseBean;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.interfaces.htsc.comInfo.PropBean;
import java.util.HashMap;
import java.util.Map;

public class ItxqlcLdspCmd extends AbstractCommonCommand<Map<String, Object>> {

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

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

    @Override
    public Map<String, Object> execute(CommandContext commandContext) {

        RecordSet rs = new RecordSet();
        BaseBean bb = new BaseBean();
        bb.writeLog( "in=================ItxqlcLdspCmd" );
        Map<String, Object> apimap = new HashMap<String, Object>();

        String requestid = Util.null2String(params.get("requestid"));
        int isldsp = 0;
        try{
            PropBean pb = new PropBean();

            int userid = user.getUID();
            String departmentid = "" ;
            String sql =" select h.departmentid,d.depttypecode,d.deptscalelevelcode \n" +
                        " from hrmresource h\n" +
                        " inner join hrmdepartmentdefined d on d.deptid = h.departmentid\n" +
                        " where h.id="+userid ;

            rs.execute(sql);
            if (rs.next()){
                departmentid = Util.null2String(rs.getString("departmentid"));
            }
            int isdept3 = 0;
            if(!"".equals(departmentid)){
                String dept3id = pb.getPropName("ITXQ_dept");
                if(!"".equals(dept3id)){
                    dept3id = "'"+dept3id.replace(",","','")+"'";
                    sql =   " select id from hrmdepartment d \n" +
                            " where d.id=" + departmentid+
                            " connect by prior d.id = d.supdepid\n" +
                            " start with d.departmentcode in("+dept3id+") ";
                    rs.execute(sql);
                    if (rs.next()){
                        isdept3++;
                    }
                }
            }
            if(isdept3 == 0){
                isldsp++;
            }else{
                sql = " select * from workflow_requestlog where requestid=" + requestid +
                      " and nodeid in(select id from workflow_nodebase where unnumber='itxqsq_gsld')";
                rs.execute(sql);
                if(rs.next()){
                    isldsp++;
                }
            }
        }catch (Exception e){
            bb.writeLog("e:"+e);
        }
        apimap.put("isldsp",isldsp+"");
        return apimap;
    }

    public static void main(String[] args) {

    }

}
