#
zjj
2024-03-15 dbae31a7a7cd59048ada9b51fe8faff545324c59
src/main/java/com/zy/asrs/controller/CrnController.java
@@ -1,6 +1,7 @@
package com.zy.asrs.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.annotations.ManagerAuth;
import com.core.common.Cools;
@@ -15,12 +16,15 @@
import com.zy.asrs.domain.vo.CrnStateTableVo;
import com.zy.asrs.entity.*;
import com.zy.asrs.mapper.BasCrnErrorMapper;
import com.zy.asrs.service.ApiLogService;
import com.zy.asrs.service.BasCrnpService;
import com.zy.asrs.service.LocMastService;
import com.zy.asrs.service.WrkMastService;
import com.zy.asrs.service.impl.MainServiceImpl;
import com.zy.asrs.utils.CommandUtils;
import com.zy.asrs.utils.Utils;
import com.zy.asrs.utils.VersionUtils;
import com.zy.common.utils.HttpHandler;
import com.zy.core.CrnThread;
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.OutputQueue;
@@ -35,6 +39,7 @@
import com.zy.core.properties.SlaveProperties;
import com.zy.core.properties.SystemProperties;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.internal.engine.messageinterpolation.parser.ELState;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
@@ -59,7 +64,8 @@
    private String movePath;
    @Autowired
    private ApiLogService apiLogService;
    @Autowired
    private SlaveProperties slaveProperties;
    @Autowired
@@ -392,6 +398,12 @@
        command.setDestinationPosX(param.getBay());     // 目标库位列
        command.setDestinationPosY(param.getLev());     // 目标库位层
        command.setCommand((short)1);
        String locNo =String.format("%2d",param.getRow()) + String.format("%3d",param.getBay()) + String.format("%2d",param.getLev());
        String startlocNo =String.format("%2d",param.getSourceRow()) + String.format("%3d",param.getSourceBay()) + String.format("%2d",param.getSourceLev());
        boolean wmsLocStatus = toWmsLocStatus(1, startlocNo, locNo, param.getBarcode(), param.getBarcodeType(), param.getEmptyContainer());
        if (!wmsLocStatus){
            return R.error("库位更新失败");
        }
        return crnControl(command)?R.ok():R.error();
    }
@@ -413,6 +425,12 @@
        command.setDestinationPosZ(param.getRow());     // 目标库位排
        command.setDestinationPosX(param.getBay());     // 目标库位列
        command.setDestinationPosY(param.getLev());     // 目标库位层
        String locNo =String.format("%2d",param.getRow()) + String.format("%3d",param.getBay()) + String.format("%2d",param.getLev());
        String startlocNo =String.format("%2d",param.getSourceRow()) + String.format("%3d",param.getSourceBay()) + String.format("%2d",param.getSourceLev());
        boolean wmsLocStatus = toWmsLocStatus(2, startlocNo, locNo, param.getBarcode(), param.getBarcodeType(), param.getEmptyContainer());
        if (!wmsLocStatus){
            return R.error("库位更新失败");
        }
        return crnControl(command)?R.ok():R.error();
    }
@@ -440,6 +458,12 @@
        LocMast loc = locMastService.selectOne(new EntityWrapper<LocMast>().eq("row1", command.getDestinationPosX())
                .eq("bay1", command.getDestinationPosY()).eq("lev1", command.getDestinationPosZ()));
        VersionUtils.locMoveCheckLocType(sourceLoc, loc);
        String locNo =String.format("%2d",param.getRow()) + String.format("%3d",param.getBay()) + String.format("%2d",param.getLev());
        String startlocNo =String.format("%2d",param.getSourceRow()) + String.format("%3d",param.getSourceBay()) + String.format("%2d",param.getSourceLev());
        boolean wmsLocStatus = toWmsLocStatus(3, startlocNo, locNo, param.getBarcode(), param.getBarcodeType(), param.getEmptyContainer());
        if (!wmsLocStatus){
            return R.error("库位更新失败");
        }
        return crnControl(command)?R.ok():R.error();
    }
@@ -764,7 +788,7 @@
                }
                // 空闲判断
//                if (crnProtocol.getStatusType().equals(com.zy.core.enums.CrnStatusType.IDLE) && crnProtocol.getTaskNo() == 0) {
                if (CommandUtils.offer(SlaveType.Crn, crn.getId(), new Task(4, command), false)) {
                if (MessageQueue.offer(SlaveType.Crn, crn.getId(), new Task(4, command))) {
                    return true;
                } else {
                    throw new CoolException("命令下发失败");
@@ -864,5 +888,67 @@
        return R.ok().add(list);
    }
    public boolean toWmsLocStatus(Integer type,String startlocNo,String locNo,String barcode,String barcodeType,String emptyContainer){
        Map<String, Object> map = new HashMap<>();
        map.put("x-api-key","7a15b5db-29b6-552c-8cff-0cfec3756da2");
        WmsLocStatus param = new WmsLocStatus();
        param.setWarehouseId("1688469798893297665");
        param.setLocationCode(Utils.getWmsLocNo(locNo));
        if (emptyContainer.equals("1")){
            param.setEmptyContainer("Y");
        }else {
            param.setEmptyContainer("N");
        }
        param.setStatus("QY");
        param.setContainerCode(barcode);
        param.setContainerTypeCode(barcodeType);
        String response = null;
        try {
            response = new HttpHandler.Builder()
                    .setHeaders(map)
                    .setUri(wmsUrl)
                    .setPath("wcsManager/wcsInterface/locationUpdate")
                    .setJson(JSON.toJSONString(param))
                    .build()
                    .doPost();
        }catch (Exception e){
            log.error("库位更新失败");
        }
        JSONObject jsonObject = JSON.parseObject(response);
        if (jsonObject.getInteger("code").equals(200)){
            LocMast originLoc = locMastService.selectByLocNo(startlocNo);
            LocMast locMast = locMastService.selectByLocNo(locNo);
            if (type == 1){
                locMast.setBarcode(barcode);
                locMast.setLocSts("Z");
                locMastService.updateById(locMast);
            }else if (type == 2){
                originLoc.setLocSts("K");
                originLoc.setBarcode("");
                locMastService.updateById(originLoc);
            }else if (type == 3){
                originLoc.setLocSts("K");
                originLoc.setBarcode("");
                locMast.setBarcode(barcode);
                locMast.setLocSts("Z");
                locMastService.updateById(originLoc);
                locMastService.updateById(locMast);
            }
            apiLogService.save("Wms变更货位状态"
                    ,wmsUrl+"wcsManager/wcsInterface/inboundTaskApply"
                    ,null
                    ,"127.0.0.1"
                    ,JSON.toJSONString(param)
                    ,response
                    ,true
            );
            return true;
        }
        return false;
    }
}