package com.engine.htsc.cowork.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 java.util.HashMap;
import java.util.Map;

public class CoWorkCmd extends AbstractCommonCommand<Map<String, Object>> {
    @Override
    public BizLogContext getLogContext() {
        return null;
    }

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

    @Override
    public Map<String, Object> execute(CommandContext commandContext) {
        Map<String, Object> appdate = new HashMap<String, Object>();
        BaseBean bb = new BaseBean();
        RecordSet rs = new RecordSet();
        try{
            String billid = Util.null2String(params.get("billid"));
            String userid = user.getUID()+"";

            if(!"1".equals(userid)){
                String sql = " select id from hrmresource where workcode in(select workcode from hrmresource where id="+userid+") and belongto is null";
                rs.execute(sql);
                if(rs.next()){
                    userid = Util.null2String(rs.getString("id"));
                }
            }

            int flag = 0;
            String sql = " select * from uf_rw_dt3 where ry="+userid+" and mainid="+billid ;
            rs.execute(sql);
            if(rs.next()){
                flag++;
            }

            String jbrs = "" ;
            sql = " select id from hrmresource where workcode in(select workcode from hrmresource where id in(select ry from uf_rw_dt3 where mainid="+billid+"))" ;
            rs.execute(sql);
            while (rs.next()){
                String jbr = Util.null2String(rs.getString("id"));
                jbrs += jbrs == "" ? jbr : ","+jbr ;
            }
            appdate.put("flag",flag);
            appdate.put("jbrs",jbrs);
        }catch (Exception e){
            bb.writeLog("e:"+e);
        }
        return appdate;
    }
}
