package com.weaver.seconddev.interfaces.workflow.action;

import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.JCoStructure;
import com.sap.conn.jco.JCoTable;
import java.lang.*;
import java.util.Arrays;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.weaver.verupgrade.general.BaseBean;

/**
 * oem
 */
public class ZOEM_PRICE_DIFFERENCE_RATE {

    private static final Logger logger_8a2de3c9 = LoggerFactory.getLogger(ZOEM_PRICE_DIFFERENCE_RATE.class);

    private JCoDestination destination;

    private String[] retstr;

    private BaseBean bb = new BaseBean();

    public ZOEM_PRICE_DIFFERENCE_RATE() {
        new SAPConn();
        destination = SAPConn.getJCoDestination();
        retstr = null;
    }

    public String[] Getexecute(String[][] as, String[][] as2) {

        logger_8a2de3c9.error(String.valueOf("ZOEM_PRICE_DIFFERENCE_RATE- Getexecute --" ));
        logger_8a2de3c9.error("as == "+Arrays.deepToString(as));
        logger_8a2de3c9.error("as2 == "+Arrays.deepToString(as2));
        retstr = new String[2];
        try {
            JCoFunction jcofunction = destination.getRepository().getFunction("ZOEM_PRICE_DIFFERENCE_RATE");
            if (jcofunction == null) {
                System.out.println("ZOEM_PRICE_DIFFERENCE_RATE not found in SAP.");
                retstr[0] = "E";
                retstr[1] = "ZOEM_PRICE_DIFFERENCE_RATE not found in SAP.";
                logger_8a2de3c9.error(String.valueOf("ZOEM_PRICE_DIFFERENCE_RATE---" + retstr[1]));
            } else {
                logger_8a2de3c9.error(String.valueOf("ZOEM_PRICE_DIFFERENCE_RATE---as.length" + as.length));
                StringBuilder sb = new StringBuilder();
                JCoTable jcotable_tab = jcofunction.getTableParameterList().getTable("IT_TAB");
                jcotable_tab.clear();
                for (int i = 0; i < as.length; i++) {
                    jcotable_tab.appendRow();
                    // ??????
                    jcotable_tab.setValue("EKORG", as[i][0]);
                    // ??????
                    jcotable_tab.setValue("MATNR", as[i][1]);
                    // jcotable.setValue("MAKTX", as[i][2]);//????????
                    // ?????ERP???
                    jcotable_tab.setValue("LIFNR", as[i][3]);
                    // jcotable.setValue("NAME1", as[i][4]);//?????????
                    // ?????
                    jcotable_tab.setValue("ZZCJL", as[i][5]);
                    // ?????Ч????
                    jcotable_tab.setValue("DATAB", as[i][6]);
                    // ??Ч????????
                    jcotable_tab.setValue("DATBI", as[i][7]);
                    // ??????????
                    jcotable_tab.setValue("OEM_RULE", as[i][8]);
                    // try {
                    // jcofunction.execute(destination);
                    // JCoTable outtable = jcofunction.getTableParameterList().getTable("ET_RETURN");
                    // 
                    // String state = outtable.getValue("TYPE").toString();
                    // String message = outtable.getValue("MESSAGE").toString();
                    // if (!"S".equals(state)) {
                    // retstr[0] = "E";
                    // sb.append("??" + (i + 1) + "??????????????????"+ message + "??\r\n");
                    // }
                    // } catch (Exception exception1) {
                    // retstr[0] = "E";
                    // sb.append("??" + (i + 1) + "??????????????????"+ exception1.toString() + "??\r\n");
                    // }
                }
                JCoTable jcotable_rule = jcofunction.getTableParameterList().getTable("IT_RULE");
                jcotable_rule.clear();
                // ?????2
                for (int i = 0; i < as2.length; i++) {
                    jcotable_rule.appendRow();
                    // ??????????
                    jcotable_rule.setValue("OEM_RULE", as2[i][0]);
                    // ??????
                    jcotable_rule.setValue("CU_ST_PRICE", as2[i][1]);
                    // ????λ
                    jcotable_rule.setValue("CU_GEAR", as2[i][2]);
                    // ????????????
                    jcotable_rule.setValue("CU_CJL", as2[i][3]);
                    // ???????
                    jcotable_rule.setValue("AL_ST_PRICE", as2[i][4]);
                    // ?????λ
                    jcotable_rule.setValue("AL_GEAR", as2[i][5]);
                    // ?????????????
                    jcotable_rule.setValue("AL_CJL", as2[i][6]);
                    // try {
                    // jcofunction.execute(destination);
                    // JCoTable outtable = jcofunction.getTableParameterList().getTable("ET_RETURN");
                    // //                        JCoTable outtable = out.getTable("RETURN");
                    // 
                    // String state = outtable.getValue("TYPE").toString();
                    // String message = outtable.getValue("MESSAGE").toString();
                    // if (!"S".equals(state)) {
                    // retstr[0] = "E";
                    // sb.append("??" + (i + 1) + "??????????????????"+ message + "??\r\n");
                    // }
                    // } catch (Exception exception1) {
                    // retstr[0] = "E";
                    // sb.append("??" + (i + 1) + "??????????????????"+ exception1.toString() + "??\r\n");
                    // }
                }
                try {
                    jcofunction.execute(destination);
                    JCoTable outtable = jcofunction.getTableParameterList().getTable("ET_RETURN");
                    // JCoTable outtable = out.getTable("RETURN");
                    String state = outtable.getValue("TYPE").toString();
                    String message = outtable.getValue("MESSAGE").toString();
                    if (!"S".equals(state)) {
                        retstr[0] = "E";
                        sb.append("错误信息：" + message + "??\r\n");
                    }
                } catch (Exception exception1) {
                    retstr[0] = "E";
                    sb.append("错误信息：" + exception1.toString() + "??\r\n");
                }
                logger_8a2de3c9.error(String.valueOf("ZOEM_PRICE_DIFFERENCE_RATE---sb.length" + sb.length()));
                if (sb.length() > 0) {
                    retstr[0] = "E";
                    retstr[1] = sb.toString();
                } else {
                    retstr[0] = "S";
                    retstr[1] = "执行成功\r\n";
                }
            }
        } catch (Exception exception) {
            retstr[0] = "E";
            retstr[1] = exception.getMessage();
            logger_8a2de3c9.error(String.valueOf("ZOEM_PRICE_DIFFERENCE_RATE---exception" + exception + "||" + exception.getMessage()));
        }
        return retstr;
    }
}
