package com.foreverwin.mesnac.console;

import com.foreverwin.mesnac.common.erp.ZprodordconfStruIn;
import com.foreverwin.mesnac.common.erp.ZprodordconfStruOut;
import com.foreverwin.mesnac.common.erp.holders.TableOfZprodordconfStruInHolder;
import com.foreverwin.mesnac.common.erp.holders.TableOfZprodordconfStruOutHolder;
import com.foreverwin.mesnac.common.util.ERPAPI;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.math.BigDecimal;
import java.rmi.RemoteException;


@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
public class TmdMc {



    @Test
    public void callErpWebService() throws RemoteException {
        String shopOrder = "000100434347";
        String stepId = "0060";


        //请求参数
        ZprodordconfStruIn [] ins = new ZprodordconfStruIn[1];

        ZprodordconfStruIn struIn = new ZprodordconfStruIn();
        //生产订单
        struIn.setAufnr(shopOrder);
        //步骤标示
        struIn.setVornr(stepId);
        struIn.setAueru("1");
        //良品数量
        struIn.setLmnga(new BigDecimal(10));
        //报废数量
        struIn.setXmnga(new BigDecimal(1));
        //机器工时
        struIn.setIsm01(new BigDecimal(1));
        //人工工时
        struIn.setIsm02(new BigDecimal(1));
        struIn.setIsm03(new BigDecimal(1));
        struIn.setIsm04(new BigDecimal(1));
        struIn.setIsm05(new BigDecimal(1));
        struIn.setIsm06(new BigDecimal(1));
        ins[0] = struIn;
        TableOfZprodordconfStruInHolder inHolder = new TableOfZprodordconfStruInHolder(ins);

        //返回对象
        ZprodordconfStruOut[] outs = new ZprodordconfStruOut[1];

        ZprodordconfStruOut struOut = new ZprodordconfStruOut();
        struOut.setAufnr(shopOrder);
        struOut.setVornr(stepId);
        struOut.setAueru("1");
        struOut.setRet("");
        struOut.setMsg("");
        outs[0] = struOut;
        TableOfZprodordconfStruOutHolder outHolder = new TableOfZprodordconfStruOutHolder(outs);

        //调用WS
        ERPAPI.erpWebService().zmesProdordconf(inHolder, outHolder);
        if (outHolder == null || outHolder.value == null || outHolder.value.length <= 0) {
            System.out.println("ERP接口失败");
        } else {
            //状态： S|成功， E|失败
            String status = outHolder.value[1].getRet();
            String message = outHolder.value[1].getMsg();
            System.out.println("ERP接口返回：状态:" + status + ",消息:" + message);
        }
    }
}
