//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package com.weaver.seconddev.interfaces.easoa;

import java.util.List;
import java.util.Map;

import com.weaver.seconddev.interfaces.prop.ConfigProp;
import org.apache.axis2.kernel.http.HTTPConstants;
import org.apache.axis2.transport.http.impl.httpclient4.HttpTransportPropertiesImpl;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class CallEasBlacklistServices  {

    public static final org.slf4j.Logger logger = LoggerFactory.getLogger(CallEasBlacklistServices.class);


    @Autowired
    private ConfigProp configProp; //注入
    /**
     * 同步黑名单 提交OA流程requestId：1362923
     * @param
     * @return
     * @throws Exception
     */
    public String[] syncBlacklist(List<Map<String, String>> list) throws Exception {
        logger.error("CallEasBlacklistServices excute start syncBlacklist------------------------");
        String[] resultArray = new String[2];
        try {
            if (list != null && list.size() >= 0) {
                SI_BlacklistSync_OUTServiceStub.BlackListSyncService input = new SI_BlacklistSync_OUTServiceStub.BlackListSyncService();
                SI_BlacklistSync_OUTServiceStub.SyncBlackListInfo info = new SI_BlacklistSync_OUTServiceStub.SyncBlackListInfo();
                for (int i = 0; i < list.size(); ++i) {
                    Map map = (Map) list.get(i);
                    String id = (String) map.get("id");
                    String bh = (String) map.get("bh");
                    String dm = (String) map.get("dm");
                    String lx = (String) map.get("lx");
                    String mc = (String) map.get("mc");
                    String zt = (String) map.get("zt") + "";
                    String yxjzq = (String) map.get("yxjzq");
                    String jyyy = (String) map.get("jyyy");
                    if (!"".equals(jyyy)) {
                        jyyy = jyyy.replace("<br>", "");
                    }
                    if (!"".equals(yxjzq)) {
                        yxjzq = yxjzq + " 00:00:00";
                    }
                    String modedatacreatedate = (String) map.get("modedatacreatedate");
                    String modedatacreatetime = (String) map.get("modedatacreatetime");
                    SI_BlacklistSync_OUTServiceStub.BlackListInfo param = new SI_BlacklistSync_OUTServiceStub.BlackListInfo();
                    param.setBlackId(id);
                    param.setCode(bh);
                    param.setAttribute1(dm);
                    param.setType(lx);
                    param.setName(mc);
                    param.setStatus(zt);
                    param.setCreateTime(modedatacreatedate + " " + modedatacreatetime);
                    param.setEndTime(yxjzq);
                    param.setReason(jyyy);

                    info.addBlackList(param);
                }
                info.setITFID("HT01BZ018");
                info.setSENDID("");
                info.setSYSID("SYS005");
                input.setSyncBlackListInfo(info);
                String uri = configProp.getNewblacklist();
                logger.error("------- uri= " + uri);
                SI_BlacklistSync_OUTServiceStub stub = new SI_BlacklistSync_OUTServiceStub(uri);
                stub._getServiceClient().getOptions().setProperty("__CHUNKED__", Boolean.FALSE);
                stub._getServiceClient().getOptions().setTimeOutInMilliSeconds(300000);
                stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT,300000);
                stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT,300000);
                HttpTransportPropertiesImpl.Authenticator auth = new HttpTransportPropertiesImpl.Authenticator();

//                auth.setUsername("pouser");
//                auth.setPassword("htjt_2018");
                String user = configProp.getHtsysjcmt_po_user();
                String password = configProp.getHtsysjcmt_po_password();
                logger.error("------- user : " + user);
                logger.error("------- password : " + password);
                auth.setUsername(user);
                auth.setPassword(password);


                stub._getServiceClient().getOptions().setProperty(org.apache.axis2.kernel.http.HTTPConstants.AUTHENTICATE,auth);
                SI_BlacklistSync_OUTServiceStub.BlackListSyncServiceResponse response = stub.sI_BlacklistSync_OUT(input);
                logger.error("------- do webservice success -------");
                SI_BlacklistSync_OUTServiceStub.ResultInfo resultInfo = response.get_return();
                resultArray[0] = resultInfo.getISTAT();
                resultArray[1] = resultInfo.getMESSAGE();
                logger.error("do blacklist webservice：[state : " + resultArray[0] + "][message : " + resultArray[1] + "]");
                logger.error("CallEasBlacklistServices excute success syncBlacklist------------------------");
            }
        } catch (Exception var19) {
            logger.error("syncBlacklist error:" + var19.toString());
            resultArray[0] = "F";
            resultArray[1] = var19.toString();
        }
        return resultArray;
    }
}
