ShipmentActivity.java 4.61 KB
package com.huaheng.robot.shipment;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.huaheng.robot.R;
import com.huaheng.robot.https.HttpInterface;
import com.huaheng.robot.https.Subscribers.ProgressSubscriber;
import com.huaheng.robot.https.Subscribers.SubscriberOnNextListener;
import com.huaheng.robot.util.CommonActivity;
import com.huaheng.robot.util.Constant;
import com.huaheng.robot.util.SpeechUtil;
import com.huaheng.robot.util.WMSLog;
import com.huaheng.robot.util.WMSUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ShipmentActivity extends CommonActivity {


    @BindView(R.id.info)
    TextView info;
    @BindView(R.id.shipmentBtn)
    Button shipmentBtn;
    @BindView(R.id.lowerBtn)
    Button lowerBtn;
    private String materialCode = "123456";
    private ArrayList<ShipmentBill> shipmentBills = new ArrayList<>();
    private List<Integer> mTaskIds = null;
    private boolean calling = false;
    private Context mContext;

    @Override
    protected void initActivityOnCreate(Bundle savedInstanceState) {
        super.initActivityOnCreate(savedInstanceState);
        setContentView(R.layout.activity_shipment);
        ButterKnife.bind(this);
        mContext = this;
        String lineName = WMSUtils.getData(Constant.CURREN_LINE_NAME);
        String station = WMSUtils.getData(Constant.CURREN_STATION);
        setTitle(lineName + " " + station);
        initView();
    }

    private void initView() {
        initList();
    }

    private void freshInfo() {
        info.setText("当前状态小车正在送货过来");
        if(calling) {
            shipmentBtn.setEnabled(false);
            shipmentBtn.setBackgroundResource(R.mipmap.button6);
        }
    }

   private void initList() {
       ShipmentBill shipmentBill = new ShipmentBill();
       shipmentBill.setMaterialCode(materialCode);
       shipmentBill.setQty(new BigDecimal(1));
       shipmentBill.setLocation(null);
       shipmentBill.setPoint(1001);
       shipmentBills.add(shipmentBill);
   }

    @OnClick({R.id.shipmentBtn, R.id.lowerBtn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.shipmentBtn:
                autoShipment(shipmentBills);
                break;
            case R.id.lowerBtn:
                break;
        }
    }

    private void autoShipment(List<ShipmentBill> shipmentBills) {
        HttpInterface.getInsstance().autoShipment(new ProgressSubscriber<List<Integer>>(this, shipmentListener), shipmentBills);
    }

    SubscriberOnNextListener shipmentListener = new SubscriberOnNextListener<List<Integer>>() {

        @Override
        public void onNext(List<Integer> headerList) {
            ShipmentTaskModel shipmentTaskCreateModel = new ShipmentTaskModel();
            shipmentTaskCreateModel.setPriority((short)0);
            shipmentTaskCreateModel.setTaskType(1);  //优先整出
            int[] headerIds = new int[headerList.size()];
            for(int i=0; i< headerList.size(); i++) {
                headerIds[i] = headerList.get(i);
            }
            shipmentTaskCreateModel.setShipmentContainerHeaderIds(headerIds);
            createShipTask(shipmentTaskCreateModel);
        }

        @Override
        public void onError(String str) {

        }
    };

    private void createShipTask(ShipmentTaskModel shipmentTaskCreateModel) {
        HttpInterface.getInsstance().createShipTask(new ProgressSubscriber<List<Integer>>(this,createShipTaskListener), shipmentTaskCreateModel);
    }

    SubscriberOnNextListener createShipTaskListener = new SubscriberOnNextListener<List<Integer>>() {

        @Override
        public void onNext(List<Integer> result) {
            mTaskIds = result;
            executeList(result);
        }

        @Override
        public void onError(String str) {
            WMSLog.d("onError:" + str);
        }
    };

    private void executeList(List<Integer> taskIdS) {
        HttpInterface.getInsstance().executeList(new ProgressSubscriber<String>(this, executeListener), taskIdS);
    }

    SubscriberOnNextListener executeListener = new SubscriberOnNextListener<String>() {

        @Override
        public void onNext(String result) {
            WMSUtils.showShort(mContext.getString(R.string.call_material_success));
            calling = true;
            freshInfo();
        }

        @Override
        public void onError(String str) {
            WMSLog.d("onError:" + str);
        }
    };
}