子母车密集库项目中子车代码JAVA

package com.asrs.business.msgProc.msg35ProServiceImpl;

import com.asrs.business.consts.AsrsJobStatus;
import com.asrs.business.consts.AsrsJobStatusDetail;
import com.asrs.business.consts.AsrsJobType;
import com.asrs.business.consts.ReasonCode;
import com.asrs.business.msgProc.msg35ProcService.Msg35ProcService;
import com.asrs.domain.*;
import com.asrs.message.Message35;
import com.asrs.xml.util.XMLUtil;
import com.domain.XMLbean.Envelope;
import com.domain.XMLbean.XMLList.ControlArea.ControlArea;
import com.domain.XMLbean.XMLList.ControlArea.Receiver;
import com.domain.XMLbean.XMLList.ControlArea.RefId;
import com.domain.XMLbean.XMLList.ControlArea.Sender;
import com.domain.XMLbean.XMLList.DataArea.DAList.MovementReportDA;
import com.domain.XMLbean.XMLList.DataArea.FromLocation;
import com.domain.XMLbean.XMLList.DataArea.ToLocation;
import com.domain.XMLbean.XMLList.MovementReport;
import com.domain.consts.xmlbean.XMLConstant;
import com.thread.blocks.*;
import com.util.hibernate.HibernateUtil;
import org.apache.commons.lang.StringUtils;
import org.hibernate.Query;
import org.hibernate.Session;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author:
 * @Date: 
 * @Description:
 * @Modified By:
 */
public class Msg35ProRetrievalServiceImpl implements Msg35ProcService {
    private Message35 message35;
    private AsrsJob aj;
    private Block block;

    public Msg35ProRetrievalServiceImpl(Message35 message35, AsrsJob aj, Block block) {
        this.message35 = message35;
        this.aj = aj;
        this.block = block;
    }

    @Override
    public void sCar35Proc() throws Exception {
        SCar sCar = (SCar) block;
        if (message35.isPickingUpGoods()) {
            sCar.setLoad("1");
            aj.setStatus(AsrsJobStatus.PICKING);
            /*if("0051".equals(aj.getToStation())||"0053".equals(aj.getToStation())){
                Location location=Location.getByLocationNo(aj.getFromLocation());
                location.setReserved(false);
                location.setEmpty(true);
            }*/
        } else if (message35.isOnCar()) {

            sCar.setOnMCar(message35.Station);
            sCar.setBank(0);

        } else if (message35.isOffCar()) {

            sCar.setBank(Integer.parseInt(message35.Bank));
            sCar.setOnMCar(null);
            sCar.setLoad("0");
            sCar.generateMckey(message35.McKey);
            Location location = Location.getByLocationNo(aj.getFromLocation());
            sCar.setActualArea(location.getActualArea());

        } else if (message35.isOnCarCarryGoods()) {
            MCar srm = MCar.getMCarByGroupNo(sCar.getGroupNo());
            sCar.setLoad("0");
            sCar.setOnMCar(srm.getBlockNo());
            sCar.setBank(0);
            sCar.clearMckeyAndReservMckey();
            aj.setStatus(AsrsJobStatus.OUTKU);
            Query query = HibernateUtil.getCurrentSession().createQuery("from AsrsJob where type=:ajType and status=:st and statusDetail=:detail and fromStation=:frs order by generateTime asc ");
            query.setParameter("ajType", AsrsJobType.RETRIEVAL);
            query.setParameter("detail", AsrsJobStatusDetail.WAITING);
            query.setParameter("st", AsrsJobStatus.RUNNING);
            query.setParameter("frs", srm.getBlockNo());

            query.setMaxResults(1);
            AsrsJob asrsJob = (AsrsJob) query.uniqueResult();
            if (asrsJob != null) {
                Location location = Location.getByLocationNo(asrsJob.getFromLocation());
                if(location.getBay() == sCar.getBay() && location.getLevel() == sCar.getLevel()) {
                    sCar.setReservedMcKey(asrsJob.getMcKey());
                    asrsJob.setStatusDetail(AsrsJobStatusDetail.ACCEPTED);
                    asrsJob.setStatus(AsrsJobStatus.ACCEPT);
                }
            }
        }
    }

    @Override
    public void srm35Proc() throws Exception {
        Srm srm = (Srm) block;
        if (message35.isMoveUnloadGoods()) {
            srm.setMcKey(null);
        } else if (message35.isUnLoadCar()) {

            srm.setsCarBlockNo(null);

        } else if (message35.isMove()) {

            srm.setCheckLocation(true);
            srm.setLevel(Integer.parseInt(message35.Level));

            Location location = Location.getByBankBayLevel(Integer.parseInt(message35.Bank), Integer.parseInt(message35.Bay), Integer.parseInt(message35.Level), srm.getPosition());

            if (location != null) {
                srm.setActualArea(location.getActualArea());
            }

            if (message35.Bay.equals("00")) {
                srm.setDock(message35.Station);
                srm.setBay(0);
                if (StringUtils.isNotBlank(srm.getsCarBlockNo())) {
                    SCar sCar = (SCar) Block.getByBlockNo(srm.getsCarBlockNo());
                    sCar.setBay(srm.getBay());
                    sCar.setActualArea(srm.getActualArea());
                    sCar.setLevel(srm.getLevel());
                }

            } else {
                srm.setDock(null);
                srm.setBay(Integer.parseInt(message35.Bay));
                if (StringUtils.isNotBlank(srm.getsCarBlockNo())) {
                    SCar sCar = (SCar) Block.getByBlockNo(srm.getsCarBlockNo());
                    sCar.setBay(srm.getBay());
                    sCar.setLevel(srm.getLevel());
                    sCar.setActualArea(srm.getActualArea());
                }
            }

        } else if (message35.isLoadCar()) {
            SCar sCar = (SCar) Block.getByBlockNo(message35.Station);
            srm.setsCarBlockNo(sCar.getBlockNo());


            if (StringUtils.isEmpty(sCar.getMcKey()) && StringUtils.isEmpty(sCar.getReservedMcKey())) {
                if (StringUtils.isEmpty(sCar.getOnMCar())) {
                    //子车不在母车上,子车有排列层,查找货位是否是aj的源货位,如果一样,取货上车,如果不是,简单接车
                    Location sLocation = Location.getByBankBayLevel(sCar.getBank(), sCar.getBay(), sCar.getLevel(), sCar.getPosition());
                    if (sLocation.getLocationNo().equals(aj.getFromLocation())) {
                        srm.generateMckey(message35.McKey);
                    } else {

                    }

                } else {
                    //如果订单状态不是1,表明子车已经领取过任务了,子车领取过任务后,子车没有任务号后,表示已经做完任务
                    if (!aj.getStatus().equals(AsrsJobStatus.RUNNING)) {
                        srm.generateMckey(message35.McKey);
                    }
                }
            }

            if (StringUtils.isNotEmpty(sCar.getMcKey())) {
                srm.generateMckey(message35.McKey);
            } else if (StringUtils.isNotEmpty(sCar.getReservedMcKey())) {

                if (StringUtils.isEmpty(sCar.getOnMCar())) {
                    //子车不在母车上,子车有排列层,查找货位是否是aj的源货位,如果一样,取货上车,如果不是,简单接车
                    Location sLocation = Location.getByBankBayLevel(sCar.getBank(), sCar.getBay(), sCar.getLevel(), sCar.getPosition());
                    if (sLocation.getLocationNo().equals(aj.getFromLocation())) {
                        srm.generateMckey(message35.McKey);
                    } else {

                    }

                } else {
                    //子车在堆垛机,子车有reservedmckey,子车的任务和堆垛机的任务不一样
                    if (!message35.McKey.equals(sCar.getReservedMcKey())) {
                        //堆垛机上任务和子车任务不同
                        srm.generateMckey(message35.McKey);
                    }
                }
            }
        }
    }

    @Override
    public void mCar35Proc() throws Exception {
        MCar mCar = (MCar) block;
        if (message35.isMoveUnloadGoods()) {
            mCar.setMcKey(null);
        } else if (message35.isUnLoadCar()) {

            mCar.setsCarBlockNo(null);

        } else if (message35.isMove()) {

            mCar.setCheckLocation(true);
            //mCar.setLevel(Integer.parseInt(message35.Level));

            Location location = Location.getByBankBayLevel(Integer.parseInt(message35.Bank), Integer.parseInt(message35.Bay), Integer.parseInt(message35.Level), mCar.getPosition());

            if (location != null) {
                mCar.setActualArea(location.getActualArea());
            }

            if (message35.Bay.equals("00")) {
                mCar.setDock(message35.Station);
                mCar.setBay(0);
                if (StringUtils.isNotBlank(mCar.getsCarBlockNo())) {
                    SCar sCar = (SCar) Block.getByBlockNo(mCar.getsCarBlockNo());
                    sCar.setBay(mCar.getBay());
                    sCar.setActualArea(mCar.getActualArea());
                    sCar.setLevel(mCar.getLevel());
                }

            } else {
                mCar.setDock(null);
                mCar.setBay(Integer.parseInt(message35.Bay));
                if (StringUtils.isNotBlank(mCar.getsCarBlockNo())) {
                    SCar sCar = (SCar) Block.getByBlockNo(mCar.getsCarBlockNo());
                    sCar.setBay(mCar.getBay());
                    sCar.setLevel(mCar.getLevel());
                    sCar.setActualArea(mCar.getActualArea());
                }
            }

        } else if (message35.isLoadCar()) {
            SCar sCar = (SCar) Block.getByBlockNo(message35.Station);
            mCar.setsCarBlockNo(sCar.getBlockNo());


            if (StringUtils.isEmpty(sCar.getMcKey()) && StringUtils.isEmpty(sCar.getReservedMcKey())) {
                if (StringUtils.isEmpty(sCar.getOnMCar())) {
                    //子车不在母车上,子车有排列层,查找货位是否是aj的源货位,如果一样,取货上车,如果不是,简单接车

                    Location sLocation = Location.getByBankBayLevel(sCar.getBank(), sCar.getBay(), sCar.getLevel(), sCar.getPosition());
                    if (sLocation.getLocationNo().equals(aj.getFromLocation())) {
                        mCar.generateMckey(message35.McKey);
                    } else {

                    }

                } else {
                    //如果订单状态不是1,表明子车已经领取过任务了,子车领取过任务后,子车没有任务号后,表示已经做完任务
                    if (!aj.getStatus().equals(AsrsJobStatus.RUNNING)) {
                        mCar.generateMckey(message35.McKey);
                    }
                }
            }

            if (StringUtils.isNotEmpty(sCar.getMcKey())) {
                mCar.generateMckey(message35.McKey);
            } else if (StringUtils.isNotEmpty(sCar.getReservedMcKey())) {
                if (StringUtils.isEmpty(sCar.getOnMCar())) {
                    boolean hasJob=findPutawayByLevelOfMcar(false, mCar);
                    if(!hasJob){
                        //如果存在已到提升机的入库任务先去接入库任务
                        //子车不在母车上,子车有排列层,查找货位是否是aj的源货位,如果一样,取货上车,如果不是,简单接车
                        Location sLocation = Location.getByBankBayLevel(sCar.getBank(), sCar.getBay(), sCar.getLevel(), sCar.getPosition());
                        if (sLocation.getLocationNo().equals(aj.getFromLocation())) {
                            mCar.generateMckey(message35.McKey);
                        } else {

                        }
                    }

                } else {
                    //子车在堆垛机,子车有reservedmckey,子车的任务和堆垛机的任务不一样
                    if (!message35.McKey.equals(sCar.getReservedMcKey())) {
                        //堆垛机上任务和子车任务不同
                        mCar.generateMckey(message35.McKey);
                    }
                }
            }
        }
    }

    @Override
    public void lift35Proc() throws Exception {
        Lift lift = (Lift) block;
        if (message35.isMove()) {
            lift.setDock(message35.Station);
            Dock dock =lift.getDockClass(message35.Station);
            lift.setLevel(dock.getLevel());
            if (StringUtils.isBlank(lift.getMcKey())) {
                lift.setReservedMcKey(message35.McKey);
            }
        } else if (message35.isMoveCarryGoods()) {
            lift.generateMckey(message35.McKey);
            lift.setDock(null);
        } else if (message35.isMoveUnloadGoods()) {
            lift.clearMckeyAndReservMckey();
            lift.setDock(null);
        }
    }

    @Override
    public void converyor35Proc() throws Exception {
        Conveyor conveyor = (Conveyor) block;
        if (message35.isMoveCarryGoods()) {
            conveyor.generateMckey(message35.McKey);
        } else if (message35.isMoveUnloadGoods()) {
            conveyor.clearMckeyAndReservMckey();
        }
    }

    @Override
    public void station35Proc() throws Exception {
        Session session = HibernateUtil.getCurrentSession();
        StationBlock stationBlock = (StationBlock)block;
        if (message35.isMoveCarryGoods()) {
            block.setMcKey(message35.McKey);
            /*Location fromLocation = Location.getByLocationNo(aj.getFromLocation());
            if(!fromLocation.getEmpty()){
                fromLocation.setReserved(false);
                fromLocation.setEmpty(true);
            }*/
            AsrsJob asrsJob = AsrsJob.getAsrsJobByMcKey(message35.McKey);

            StationBlock toStationBlock = (StationBlock)StationBlock.getByBlockNo(asrsJob.getToStation());
            if(toStationBlock.getGroupNo()==stationBlock.getGroupNo()){
                /*LedMessage ledMessage = LedMessage.getByLedNo(stationBlock.getStationNo());
                if(ledMessage != null&&!ledMessage.isProcessed()) {
                    Query query1 =session.createQuery("from Inventory i where i.container.barcode=:barcode")
                            .setString("barcode", aj.getBarcode())
                            .setMaxResults(1);
                    Inventory inventory = (Inventory) query1.uniqueResult();
                    if (StringUtils.isNotBlank(stationBlock.getStationNo()) && inventory != null *//*&& !aj.getMcKey().equals(ledMessage.getMcKey())*//*) {
                        String skuName=inventory.getSkuCode();
                        if(StringUtils.isNotBlank(inventory.getSkuCode())){
                            Sku sku = Sku.getByCode(inventory.getSkuCode());
                            if(sku!=null){
                                skuName=sku.getSkuName();
                            }
                        }
                        Query query2 = session.createQuery("from Job where mcKey=:mcKey").setMaxResults(1);
                        Job job= (Job) query2.setString("mcKey",aj.getMcKey()).uniqueResult();
                        String p=stationBlock.getStationNo();
                        if(job!=null){
                            p=job.getFinalLoc();
                        }

                        Qty qty=(Qty) session.createQuery("from Qty where skuCode=:skuCode").setString("skuCode",inventory.getSkuCode()).setMaxResults(1).uniqueResult();
                        double count=inventory.getQty().intValue();
                        if(qty!=null&&!"ktp".equals(inventory.getSkuCode())) {
                            float i = inventory.getQty().intValue();
                            float j = qty.getQty().intValue();
                            float qqq = i / j;
                            count = Math.ceil(qqq);
                        }
                        LedMessage.show(stationBlock.getStationNo(), p, skuName, inventory.getLotNum(), aj.getBarcode()+"  "+count);
                        ledMessage.setMcKey(aj.getMcKey());
                    }
                }*/
                stationBlock.setOutLoad(true);
                retrievalFinish(aj);
            }

        }else if (message35.isMoveUnloadGoods()) {
            block.clearMckeyAndReservMckey();
        }
    }

    private void retrievalFinish(AsrsJob asrsJob) throws Exception {
        Sender sd = new Sender();
        sd.setDivision(XMLConstant.COM_DIVISION);

        Receiver receiver = new Receiver();
        receiver.setDivision(XMLConstant.WMS_DIVISION);
        RefId ri = new RefId();
        ri.setReferenceId(asrsJob.getMcKey());

        ControlArea ca = new ControlArea();
        ca.setSender(sd);
        ca.setReceiver(receiver);
        ca.setRefId(ri);
        ca.setCreationDateTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));

        Location location = Location.getByLocationNo(asrsJob.getFromLocation());
        FromLocation fromLocation = new FromLocation();
        fromLocation.setMHA(asrsJob.getFromStation());
        List<String> rack = new ArrayList<>(3);
        rack.add(String.valueOf(location.getBank()));
        rack.add(String.valueOf(location.getBay()));
        rack.add(String.valueOf(location.getLevel()));
        fromLocation.setRack(rack);

        ToLocation toLocation = new ToLocation();
        List<String> list = new ArrayList<>(3);
        list.add("");
        list.add("");
        list.add("");
        toLocation.setMHA("");
        toLocation.setRack(list);

        //创建MovementReportDA数据域对象
        MovementReportDA mrd = new MovementReportDA();
        mrd.setReasonCode(ReasonCode.RETRIEVALFINISHED);
        mrd.setStUnitId(asrsJob.getBarcode());
        mrd.setFromLocation(fromLocation);
        mrd.setToLocation(toLocation);
        //创建MovementReport响应核心对象
        MovementReport mr = new MovementReport();
        mr.setControlArea(ca);
        mr.setDataArea(mrd);
        //将MovementReport发送给wms
        Envelope el = new Envelope();
        el.setMovementReport(mr);

        XMLMessage xmlMessage = new XMLMessage();
        xmlMessage.setRecv("WMS");
        xmlMessage.setStatus("1");
        xmlMessage.setMessageInfo(XMLUtil.getSendXML(el));
        HibernateUtil.getCurrentSession().save(xmlMessage);
        XMLUtil.sendEnvelope(el);

    }


    /*
     * @author:ed_chen
     * @date:2018/4/17 15:57
     * @description:查找母车所在层的 入库任务
     * @param hasJob
     * @param mCar
     * @return:boolean
     */
    public boolean findPutawayByLevelOfMcar(boolean hasJob,MCar mCar) {
        Block block = mCar.getPreBlockHasMckey(AsrsJobType.PUTAWAY);
        if (block != null) {
            //如果上一段block有mckey,
            if (block instanceof Conveyor) {
                Conveyor conveyor = (Conveyor) block;
                if (org.apache.commons.lang3.StringUtils.isNotBlank(conveyor.getMcKey())) {
                    AsrsJob asrsJob = AsrsJob.getAsrsJobByMcKey(block.getMcKey());
                    //如果小车绑定母车的上一节是入库作业,设置小车的reservedmckey
                    if (asrsJob.getType().equals(AsrsJobType.PUTAWAY) && !asrsJob.getStatus().equals(AsrsJobStatus.DONE)) {
                        //mCar.setReservedMcKey(block.getMcKey());
                        hasJob = true;
                    }
                }
            } else if (block instanceof StationBlock) {
                if (org.apache.commons.lang3.StringUtils.isNotBlank(block.getMcKey())) {
                    //如果提升机的上一节是入库作业,设置提升机reservedmckey
                    AsrsJob asrsJob = AsrsJob.getAsrsJobByMcKey(block.getMcKey());
                    if (asrsJob.getType().equals(AsrsJobType.PUTAWAY) && !asrsJob.getStatus().equals(AsrsJobStatus.DONE) ) {
                        //mCar.setReservedMcKey(block.getMcKey());
                        hasJob = true;
                    }
                }
            }else if (block instanceof Lift) {
                if (org.apache.commons.lang3.StringUtils.isNotBlank(block.getMcKey())) {
                    //如果提升机的上一节是入库作业,设置提升机reservedmckey
                    AsrsJob asrsJob = AsrsJob.getAsrsJobByMcKey(block.getMcKey());
                    if (asrsJob.getType().equals(AsrsJobType.PUTAWAY) && !asrsJob.getStatus().equals(AsrsJobStatus.DONE) ) {
                        //mCar.setReservedMcKey(block.getMcKey());
                        hasJob = true;
                    }
                }
            }
        }
        return hasJob;
    }

}

要创建一个子母公司树,可以使用Java中的树数据结构。可以使用节点类来表示每个公司,该节点类包含公司名称、子公司、母公司等属性。然后,可以使用Java中的树类来组织这些节点,以形成子母公司树。 下面是一个简单的Java代码示例,用于创建一个子母公司树: ```java class CompanyNode { String name; List<CompanyNode> children; CompanyNode parent; public CompanyNode(String name) { this.name = name; children = new ArrayList<>(); } public void addChild(CompanyNode child) { children.add(child); child.parent = this; } } public class CompanyTree { CompanyNode root; public CompanyTree(CompanyNode root) { this.root = root; } public void print() { print(root, 0); } private void print(CompanyNode node, int depth) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < depth; i++) { sb.append(" "); } sb.append(node.name); System.out.println(sb.toString()); for (CompanyNode child : node.children) { print(child, depth + 1); } } } // Usage: CompanyNode root = new CompanyNode("Parent Company"); CompanyNode child1 = new CompanyNode("Child Company 1"); CompanyNode child2 = new CompanyNode("Child Company 2"); CompanyNode grandchild1 = new CompanyNode("Grandchild Company 1"); CompanyNode grandchild2 = new CompanyNode("Grandchild Company 2"); root.addChild(child1); root.addChild(child2); child1.addChild(grandchild1); child2.addChild(grandchild2); CompanyTree tree = new CompanyTree(root); tree.print(); ``` 上述代码将创建一个子母公司树,其中Parent Company是根节点,Child Company 1和Child Company 2是其子节点,Grandchild Company 1和Grandchild Company 2是其子节点的子节点。输出结果将打印整个树的结构。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

!chen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值