zjj
2023-12-04 0ed06e0a0520d9493732910d9545b1adc1a6afb9
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -4,10 +4,13 @@
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.Cools;
import com.core.common.R;
import com.core.exception.CoolException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.zy.asrs.domain.enums.TaskStatusType;
import com.zy.asrs.entity.*;
import com.zy.asrs.entity.param.WMSAndAGVInterfaceParam;
import com.zy.asrs.entity.param.taskCreateParam;
import com.zy.asrs.mapper.*;
import com.zy.asrs.service.*;
import com.zy.asrs.utils.CommandUtils;
@@ -23,6 +26,7 @@
import com.zy.core.model.CrnSlave;
import com.zy.core.model.DevpSlave;
import com.zy.core.model.Task;
import com.zy.core.model.command.CommandPackage;
import com.zy.core.model.command.CrnCommand;
import com.zy.core.model.protocol.CrnProtocol;
import com.zy.core.model.protocol.StaProtocol;
@@ -39,8 +43,8 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
import java.io.IOException;
import java.util.*;
/**
 * 立体仓库WCS系统主流程业务
@@ -78,13 +82,16 @@
    @Autowired
    private CommandInfoService commandInfoService;
    @Autowired
    private OpenServiceImpl openServiceImpl;
    @Value("${wms.url}")
    private String wmsUrl;
    @Value("${wms.movePath}")
    private String movePath;
    public void generateStoreWrkFile() {
    public void generateStoreWrkFile() throws IOException {
        // 根据输送线plc遍历
        for (DevpSlave devp : slaveProperties.getDevp()) {
            // 遍历入库口
@@ -100,7 +107,7 @@
                Short workNo = staProtocol.getWorkNo();
                // 判断是否满足入库条件
                if (staProtocol.isAutoing() && staProtocol.isLoading()
                        && !staProtocol.isInEnable()
                        && staProtocol.isInEnable()
                        && !staProtocol.isEmptyMk() && (workNo >= 0)
                        && staProtocol.isPakMk()) {
@@ -157,6 +164,53 @@
                    }
                    String barcode = barcodeThread.getBarcode();
                    if(!Cools.isEmpty(barcode)) {
                        ToWmsDTO toWmsDTO = new ToWmsDTO();
                        Map<String, Object> map = new HashMap<>();
                        map.put("x-api-key","7a15b5db-29b6-552c-8cff-0cfec3756da2");
                        List<Integer> list = openServiceImpl.getInEnableRoadway();
                        TaskWrk taskWrk = taskWrkService.selectOne(new EntityWrapper<TaskWrk>().eq("barcode", barcode).eq("crn_no",inSta.getBarcode()));
                        if (Cools.isEmpty(taskWrk)){
                            continue;
                        }
                        if (taskWrk.getTargetPoint() != null && taskWrk.getStartPoint() != null && taskWrk.getWrkNo() != null){
                            staProtocol.setWorkNo(taskWrk.getWrkNo().shortValue());
                            staProtocol.setStaNo(inSta.getStaNo().shortValue());
                            MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                        }else {
                            //TaskWrk taskWrk = taskWrkService.selectByTaskNo(param.getTaskNo());
                            toWmsDTO.setWarehouseId("1688469798893297665");
                            toWmsDTO.setContainerCode(barcode);
                            toWmsDTO.setApplyType("TUNNEL_LOCATION");
                            toWmsDTO.setTaskTunnel(taskWrk.getCrnNo());
                            toWmsDTO.setCanInboundTunnels(list);
                            String response = null;
                            try {
                                response = new HttpHandler.Builder()
                                        .setHeaders(map)
                                        .setUri(wmsUrl)
                                        .setPath("wcsManager/wcsInterface/inboundTaskApply")
                                        .setJson(JSON.toJSONString(toWmsDTO))
                                        .build()
                                        .doPost();
                            }catch (Exception e){
                                log.error("wms通讯失败,"+e.getMessage());
                                continue;
                            }
                            JSONObject jsonObject = JSON.parseObject(response);
                            if (jsonObject.getInteger("code").equals(200)) {
                                GetWmsDto getWmsDto = JSON.parseObject(jsonObject.get("data").toString(), GetWmsDto.class);
                                taskWrk.setOriginTargetPoint(getWmsDto.getTargetLocationCode());
                                taskWrk.setTargetPoint(Utils.getWcsLocNo(getWmsDto.getTargetLocationCode()));
                                taskWrk.setStartPoint(String.valueOf(inSta.getBackSta()));
                                if (!taskWrkService.updateById(taskWrk)){
                                    log.error("保存wms库位号失败");
                                }
                            }else {
                                log.error("wms通讯失败,"+jsonObject.get("msg"));
                            }
                        }
                    }
                }
@@ -211,9 +265,14 @@
                                if (commandInfos.isEmpty()) {
                                    continue;//命令空
                                }
//                                CommandPackage commandPackage = JSON.parseObject(commandInfo.getCommand(), CommandPackage.class);//取出命令报文
//                                CrnCommand crnCommand = JSON.parseObject(commandPackage.getCommand().toString(), CrnCommand.class);
                                Integer commandStep = taskWrk.getCommandStep();
                                CommandInfo commandInfo = commandInfos.get(commandStep);
                                StaProtocol staProtocol1 = JSON.parseObject(commandInfo.getCommand(), StaProtocol.class);
                                CommandPackage commandPackage = JSON.parseObject(commandInfo.getCommand(), CommandPackage.class);//取出命令报文
                                //StaProtocol staProtocol1 = JSON.parseObject(commandInfo.getCommand(), StaProtocol.class);
                                StaProtocol staProtocol1 = JSON.parseObject(commandPackage.getCommand().toString(), StaProtocol.class);
                                if (!MessageQueue.offer(SlaveType.Devp, crnStn.getDevpPlcId(), new Task(2, staProtocol1))) {
                                    log.error("输送线命令下方失败!!! [工作号:{}]", taskWrk.getWrkNo());
                                    continue;//命令下发失败
@@ -234,7 +293,7 @@
    /**
     * 入出库  ===>>  堆垛机入出库作业下发
     */
    public synchronized void crnIoExecute(){
    public synchronized void crnIoExecute() throws IOException {
        for (CrnSlave crn : slaveProperties.getCrn()) {
            // 获取堆垛机信息
            CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId());
@@ -279,7 +338,7 @@
    /**
     * 入库  ===>>  堆垛机站到库位
     */
    public void crnStnToLoc(CrnSlave slave, CrnProtocol crnProtocol){
    public void crnStnToLoc(CrnSlave slave, CrnProtocol crnProtocol) throws IOException {
        for (CrnSlave.CrnStn crnStn : slave.getCrnInStn()) {
            List<StaDesc> staDescs = staDescMapper.selectList(new EntityWrapper<StaDesc>().eq("crn_no", slave.getId()).eq("crn_stn", crnStn.getStaNo()));
            for (StaDesc staDesc : staDescs) {
@@ -328,7 +387,8 @@
                    continue;//命令空
                }
                CommandInfo commandInfo = commandInfos.get(commandStep);
                CrnCommand crnCommand = JSON.parseObject(commandInfo.getCommand(), CrnCommand.class);//取出命令报文
                CommandPackage commandPackage = JSON.parseObject(commandInfo.getCommand(), CommandPackage.class);//取出命令报文
                CrnCommand crnCommand = JSON.parseObject(commandPackage.getCommand().toString(), CrnCommand.class);
                if (!MessageQueue.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand))) {
                    log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", taskWrk.getCrnNo(), JSON.toJSON(crnCommand));
@@ -468,7 +528,8 @@
                            continue;//命令空
                        }
                        CommandInfo commandInfo = commandInfos.get(commandStep);
                        CrnCommand crnCommand = JSON.parseObject(commandInfo.getCommand(), CrnCommand.class);//取出命令报文
                        CommandPackage commandPackage = JSON.parseObject(commandInfo.getCommand(), CommandPackage.class);//取出命令报文
                        CrnCommand crnCommand = JSON.parseObject(commandPackage.getCommand().toString(), CrnCommand.class);
                        if (!MessageQueue.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand))) {
                            log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", taskWrk.getCrnNo(), JSON.toJSON(crnCommand));