package com.engine.htsc.ityssq.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.GCONST;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.interfaces.htsc.comInfo.PropBean;

import java.util.*;

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

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

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

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

        RecordSet rs = new RecordSet();
        System.out.println( "in=================ItlxlcLdspInfoCmd" );
        Map<String, Object> apimap = new HashMap<String, Object>();

        PropBean pb = new PropBean();
        List<Map<String,Object>> nsrylist = new ArrayList<Map<String,Object>>();
        Map<String,Object> nsrymap = null;
        String nsryvalues = "" ;

        String nsry = pb.getPropName("ityssq_ngry");

        String xmlx = Util.null2String(params.get("xmlx"));
        if("0".equals(xmlx) || "2".equals(xmlx)){
            if(!"".equals(nsry))
            {
                nsry = "'"+nsry.replace(",","','")+"'";
                String sql = " select id,lastname from hrmresource where workcode in("+nsry+") and belongto is null " ;
                rs.execute(sql);
                while (rs.next()){
                    String id = Util.null2String(rs.getString("id"));
                    String lastname = Util.null2String(rs.getString("lastname"));
                    nsryvalues += nsryvalues==""? id : ","+id ;
                    nsrymap = new HashMap<String,Object>();
                    nsrymap.put("id",id);
                    nsrymap.put("name",lastname);
                    nsrylist.add(nsrymap);
                }
            }
        }


        List<Map<String,Object>> bmlslist = new ArrayList<Map<String,Object>>();
        Map<String,Object> bmldmap = null;
        String bmldvalues = "" ;

        String bmld_wl = pb.getPropName("ityssq_bmld_wl");
        String bmld_cd = pb.getPropName("ityssq_bmld_cd");
        String bmlds = "" ;
        if("0".equals(xmlx)){
            bmlds += bmlds == "" ? "'"+bmld_wl+"'" : ",'"+bmld_wl+"'" ;
        }else if("1".equals(xmlx)){
            bmlds += bmlds == "" ? "'"+bmld_cd+"'" : ",'"+bmld_cd+"'" ;
        }else if("2".equals(xmlx)){
            bmlds += bmlds == "" ? "'"+bmld_wl+"'" : ",'"+bmld_wl+"'" ;
            bmlds += bmlds == "" ? "'"+bmld_cd+"'" : ",'"+bmld_cd+"'" ;
        }

        if(!"".equals(bmlds))
        {
            String sql = " select id,lastname from hrmresource where workcode in("+bmlds+") and belongto is null " ;
            rs.execute(sql);
            while (rs.next()){
                String id = Util.null2String(rs.getString("id"));
                String lastname = Util.null2String(rs.getString("lastname"));
                bmldvalues += bmldvalues==""? id : ","+id ;
                bmldmap = new HashMap<String,Object>();
                bmldmap.put("id",id);
                bmldmap.put("name",lastname);
                bmlslist.add(bmldmap);
            }
        }

        apimap.put("nsryObject",nsrylist);
        apimap.put("nsry",nsryvalues);
        apimap.put("bmlsObject",bmlslist);
        apimap.put("bmls",bmldvalues);
        return apimap;
    }

    public static void main(String[] args) {
        GCONST.setRootPath("WEB-INF/");
        GCONST.setServerName("ecology");
        Map<String, Object> params=new HashMap<>();
        params.put("xmlx","0");
        ItyssqNsryInfoCmd ItlxlcLdspInfoCmd = new ItyssqNsryInfoCmd(params);
        CommandContext ceshi= new CommandContext(null,null);
        ItlxlcLdspInfoCmd.execute(ceshi);
    }

}
