package com.engine.zjrb.pattern.cmd;

import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import org.apache.commons.lang3.StringUtils;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.User;

import java.util.*;

public class PatternUnlockingQueryCmd extends AbstractCommonCommand<Map<String,Object>> {
    public PatternUnlockingQueryCmd(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) {
        Map<String, Object> returnMap = new HashMap<String,Object>();
        BaseBean bb = new BaseBean();
        int userid = user.getUID();
        RecordSet rs = new RecordSet();
        String id = "";
        String ry = "" ;
        String taz = "";
        List<Integer> tazList = new ArrayList<Integer>();
        try{
            String sql = " select id,taz,ry from uf_pattern where ry = ? " ;
            rs.executeQuery(sql,new Object[]{userid});
            if(rs.next()){
                id = Util.null2String(rs.getString("id"));
                ry = Util.null2String(rs.getString("ry"));
                taz = Util.null2String(rs.getString("taz"));
            }
        }catch (Exception e){
            e.printStackTrace();
            bb.writeLog("e:"+e);
        }
        returnMap.put("id",id);
        returnMap.put("ry",ry);
        if(StringUtils.isNotBlank(taz)){
            String[] tazArray = taz.split(",");
            for(int i=0;i<tazArray.length;i++){
                String tazVal = tazArray[i];
                if(StringUtils.isNotBlank(tazVal)){
                    tazList.add(Integer.parseInt(tazVal));
                }
            }
        }
        returnMap.put("patternvalue",tazList);
        return returnMap;
    }
}
