package com.engine.htsc.zbclbx.dao;

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.Util;
import weaver.hrm.User;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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


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

    @Override
    public Map<String, Object> execute(CommandContext commandContext) {
        RecordSet rs = new RecordSet();
        Map<String, Object> back = new HashMap<>();
        List<Map> alltreavelcode = new ArrayList<>();
        String treavelcode = Util.null2String(params.get("treavelcode"));
        String[] treavelcodeList = treavelcode.split(",");
        for (String oneTreavelcode : treavelcodeList) {
            Map<String, Object> oneTreavelcodeMap = new HashMap<>();
            String sql = "select listagg(lcbh,',') as lcbhs from uf_zbclbxandccsqgx where TREAVELCODE = '" + oneTreavelcode + "'";
            rs.executeQuery(sql);
            if (rs.next()) {
                oneTreavelcodeMap.put("lcbh", rs.getString("lcbhs"));
                oneTreavelcodeMap.put("treavelcode", oneTreavelcode);
            }
            if (oneTreavelcodeMap.size()!=0){
                alltreavelcode.add(oneTreavelcodeMap);
            }
        }
        if (alltreavelcode.size() != 0) {
            back.put("result", alltreavelcode);
        } else {
            back.put("result", "none");
        }
        return back;
    }
}
