package com.engine.htxc.apprchalink.contract.cmd;

import com.engine.common.biz.AbstractCommonCommand;
import com.engine.common.entity.BizLogContext;
import com.engine.core.interceptor.CommandContext;
import com.engine.htxc.commonutil.db.DbTools;
import com.engine.integration.util.StringUtils;
import weaver.general.Util;

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

/**
 * @author K1810015
 * @version 1.0.0
 * @ClassName ContractLinkCmd.java
 * @createTime 2022年07月26日 14:42:00
 */
public class ContractLinkCmd extends AbstractCommonCommand<Map<String, Object>> {

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

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

    @Override
    public Map<String, Object> execute(CommandContext commandContext) {
        List<Map<String,Object>> list=(List<Map<String, Object>>) params.get("data");
        if(list==null ||list.size()<=0 ){
            return null;
        }
        List<String> wherelist=new ArrayList<>();
        list.forEach((Map<String,Object> map)->{
            String deptid= Util.null2String(map.get("deptid"));
            String htlxid=Util.null2String(map.get("htlxid"));
            if(!StringUtils.isBlank(htlxid) && !StringUtils.isBlank(deptid)){
                wherelist.add("(','||htlxNew||',' like '%,"+htlxid+",%' and fqbmid='"+deptid +"')");
            }
        });
        if(wherelist.size()<=0){
            return null;
        }
        String sql="select * from uf_contapprcha where 1=1 and ";
        sql+=wherelist.stream().collect(Collectors.joining("or"));
        List retlist=new DbTools().getSqlToList(sql,(Object) null);
        if(list==null ){
            return null;
        }
        Map<String,Object> retmap=new HashMap(1);
        retmap.put("data",retlist);
        return retmap;
    }
}
