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

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
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.bean.ActivityIslandBean;
import com.huaheng.robot.https.HttpInterface;
import com.huaheng.robot.https.HttpInterface2;
import com.huaheng.robot.https.Subscribers.ProgressSubscriber;
import com.huaheng.robot.https.Subscribers.SubscriberOnNextListener;
import com.huaheng.robot.task.ActivityIsLandInfo;
import com.huaheng.robot.task.ManualTransferActivity;
import com.huaheng.robot.task.MaterialInfo;
import com.huaheng.robot.util.CommonActivity;
import com.huaheng.robot.util.Constant;
import com.huaheng.robot.util.DataBaseHelpter;
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;
    @BindView(R.id.occupyBtn)
    Button occupyBtn;
    private String materialCode = "12345";
    private List<Integer> mTaskIds = null;
    private boolean calling = false;
    private Context mContext;
    private List<ActivityIsLandInfo> activityIsLandInfos;

    @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);
        initActivityIsLandInfo();
        getShipmentList();
    }

    private void initActivityIsLandInfo() {
        List<ActivityIslandBean> activityIslandBeans = getActivityIsLand();
        activityIsLandInfos= new ArrayList<>();
        if(activityIslandBeans != null) {
            for(ActivityIslandBean activityIslandBean : activityIslandBeans) {
                activityIsLandInfos.add(new ActivityIsLandInfo(activityIslandBean.getId(), activityIslandBean.getName()));
            }
        }
    }

    private void freshInfo() {
        if (calling) {
            shipmentBtn.setEnabled(false);
            shipmentBtn.setBackgroundResource(R.mipmap.button6);
        }
    }

    private ArrayList<ShipmentBill> getShipmentList() {
        ArrayList<ShipmentBill> shipmentBills  = new ArrayList<>();
        ShipmentBill shipmentBill = new ShipmentBill();
        shipmentBill.setMaterialCode(materialCode);
        shipmentBill.setQty(new BigDecimal(1));
        shipmentBill.setLocation(null);
        int lineNumber = Integer.parseInt(WMSUtils.getData(Constant.CURREN_LINE_NUMBER));
        WMSLog.d("lineNumber :" + lineNumber);
        if(lineNumber == 2) {
            shipmentBill.setPoint(1001);
        } else {
            shipmentBill.setPoint(5000);
        }
        shipmentBills.add(shipmentBill);
        return shipmentBills;
    }

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

                break;
            case R.id.occupyBtn:
                occupy();
                break;
        }
    }

    private void occupy() {
        showActivityIsLandDialog(activityIsLandInfos);
    }

    private List<ActivityIslandBean> getActivityIsLand() {
        String stationNumber = WMSUtils.getData(Constant.CURREN_STATION_NUMBER);
        List<ActivityIslandBean> activityIslandBeanList = new ArrayList<>();
        List<ActivityIslandBean> activityIslandBeans = DataBaseHelpter.queryAllActivityIsland();
        for(ActivityIslandBean activityIslandBean : activityIslandBeans) {
            WMSLog.d("activityIslandBean.getWorkProcessDetailId():" + activityIslandBean.getWorkProcessDetailId() +  "  stationNumber:" + stationNumber);
            if(activityIslandBean.getWorkProcessDetail().getSequence() == Integer.parseInt(stationNumber)) {
                activityIslandBeanList.add(activityIslandBean);
            }
        }
        return activityIslandBeanList;
    }

    private void showActivityIsLandDialog(final  List<ActivityIsLandInfo> activityIsLandInfos) {
        final List<String> lists = new ArrayList<>();
        final List<String> lists2 = new ArrayList<>();
        for(ActivityIsLandInfo activityIsLandInfo : activityIsLandInfos) {
            lists.add(activityIsLandInfo.getName());
            lists2.add(String.valueOf(activityIsLandInfo.getId()));
        }
        AlertDialog.Builder listDialog =
                new AlertDialog.Builder(ShipmentActivity.this);
        listDialog.setTitle(R.string.to_ccupy_postion);
        String[] strs1= lists.toArray(new String[lists.size()]);
        listDialog.setItems(strs1, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                activityIslandOccupy(Integer.parseInt(lists2.get(which)));
            }
        });
        listDialog.show();
    }

    private void shipment() {
        List<MaterialInfo> materialInfos = new ArrayList<>();
        materialInfos.add(new MaterialInfo("12345", "线圈"));
        showMaterialDialog(materialInfos);
    }

    private void showMaterialDialog(final  List<MaterialInfo> materialInfos) {
        final List<String> lists = new ArrayList<>();
        final List<String> lists2 = new ArrayList<>();
        for(MaterialInfo materialInfo : materialInfos) {
            lists.add(materialInfo.getName());
            lists2.add(String.valueOf(materialInfo.getCode()));
        }
        AlertDialog.Builder listDialog =
                new AlertDialog.Builder(ShipmentActivity.this);
        listDialog.setTitle(R.string.choose_shipment);
        String[] strs1= lists.toArray(new String[lists.size()]);
        listDialog.setItems(strs1, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                showRequestDialog(activityIsLandInfos);
            }
        });
        listDialog.show();
    }

    private void showRequestDialog(final  List<ActivityIsLandInfo> activityIsLandInfos) {
        final List<String> lists = new ArrayList<>();
        final List<String> lists2 = new ArrayList<>();
        for(ActivityIsLandInfo activityIsLandInfo : activityIsLandInfos) {
            lists.add(activityIsLandInfo.getName());
            lists2.add(String.valueOf(activityIsLandInfo.getId()));
        }
        AlertDialog.Builder listDialog =
                new AlertDialog.Builder(ShipmentActivity.this);
        listDialog.setTitle(R.string.choose_island);
        String[] strs1= lists.toArray(new String[lists.size()]);
        listDialog.setItems(strs1, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                activityIslandRequest(Integer.parseInt(lists2.get(which)));
            }
        });
        listDialog.show();
    }

    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);
        }
    };

    private void activityIslandOccupy(int id) {
        HttpInterface2.getInsstance().activityIslandOccupy(new ProgressSubscriber<String>(this, occupyListener), id);
    }

    SubscriberOnNextListener occupyListener = new SubscriberOnNextListener<String>() {

        @Override
        public void onNext(String result) {


        }

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

    private void activityIslandRequest(int id) {
        HttpInterface2.getInsstance().activityIslandRequest(new ProgressSubscriber<String>(this, requestListener), id);
    }

    SubscriberOnNextListener requestListener = new SubscriberOnNextListener<String>() {

        @Override
        public void onNext(String result) {
            List<ShipmentBill> shipmentBills = getShipmentList();
            autoShipment(shipmentBills);
        }

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


    private void cancelActivityIslandOccupy(int id) {
        HttpInterface2.getInsstance().cancelActivityIslandOccupy(new ProgressSubscriber<String>(this, cancelOccupyListener), id);
    }

    SubscriberOnNextListener cancelOccupyListener = new SubscriberOnNextListener<String>() {

        @Override
        public void onNext(String result) {
            WMSUtils.showShort(mContext.getString(R.string.call_material_success));

        }

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

    private void cancelActivityIslandRequest(int id) {
        HttpInterface2.getInsstance().cancelActivityIslandRequest(new ProgressSubscriber<String>(this, cancelRequestListener), id);
    }

    SubscriberOnNextListener cancelRequestListener = new SubscriberOnNextListener<String>() {

        @Override
        public void onNext(String result) {
            WMSUtils.showShort(mContext.getString(R.string.call_material_success));

        }

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

}