自动化立体仓库 - WCS系统
Junjie
2023-08-10 0e9686edc067b0779562bfa2452d49daf4cb7b18
指令
2个文件已添加
1个文件已删除
16个文件已修改
760 ■■■■ 已修改文件
src/main/java/com/zy/asrs/controller/CommandInfoController.java 55 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/controller/TaskWrkController.java 21 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/entity/CommandInfo.java 46 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/mapper/CommandInfoMapper.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/service/CommandInfoService.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/service/impl/CommandInfoServiceImpl.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/utils/CommandUtils.java 85 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/cache/MessageQueue.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/model/command/CommandPackage.java 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/model/command/CrnCommand.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/model/command/RedisCommand.java 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/model/protocol/StaProtocol.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/thread/SiemensCrnThread.java 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/core/thread/SiemensDevpThread.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/CommandInfoMapper.xml 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/commandManage/commandManage.html 94 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/taskWrk/commandManage.html 329 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/views/taskWrk/taskWrk.html 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/asrs/controller/CommandInfoController.java
@@ -1,5 +1,6 @@
package com.zy.asrs.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
@@ -13,6 +14,12 @@
import com.core.common.Cools;
import com.core.common.R;
import com.zy.common.web.BaseController;
import com.zy.core.cache.MessageQueue;
import com.zy.core.enums.SlaveType;
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.StaProtocol;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@@ -40,7 +47,6 @@
        EntityWrapper<CommandInfo> wrapper = new EntityWrapper<>();
        excludeTrash(param);
        convert(param, wrapper);
        wrapper.in("command_status", "1,2");
        if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));}
        return R.ok(commandInfoService.selectPage(new Page<>(curr, limit), wrapper));
    }
@@ -55,7 +61,6 @@
        EntityWrapper<CommandInfo> wrapper = new EntityWrapper<>();
        excludeTrash(param);
        convert(param, wrapper);
        wrapper.in("command_status", "3");
        if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));}
        return R.ok(commandInfoService.selectPage(new Page<>(curr, limit), wrapper));
    }
@@ -136,4 +141,50 @@
        return R.ok();
    }
    @PostMapping(value = "/commandInfo/executeCommand")
    @ManagerAuth
    public R executeCommand(@RequestParam("id") Integer id) {
        CommandInfo commandInfo = commandInfoService.selectById(id);
        if (commandInfo == null) {
            return R.error("指令不存在");
        }
        commandInfo.setCommandStatus(2);//执行状态
        commandInfo.setExecuteTime(new Date());
        if (commandInfoService.updateById(commandInfo)) {
            //将指令进行投递
            CommandPackage commandPackage = JSON.parseObject(commandInfo.getCommand(), CommandPackage.class);
            SlaveType type = SlaveType.findInstance(commandInfo.getDevice());
            if (type == null) {
                return R.error("未知设备");
            }
            switch (type) {
                case Crn:
                    CrnCommand crnCommand = JSON.parseObject(commandPackage.getCommand().toString(), CrnCommand.class);
                    MessageQueue.offer(type, crnCommand.getCrnNo(), new Task(2, crnCommand));
                    break;
                case Devp:
                    StaProtocol staProtocol = JSON.parseObject(commandPackage.getCommand().toString(), StaProtocol.class);
                    MessageQueue.offer(type, staProtocol.getSiteId(), new Task(2, staProtocol));
                    break;
            }
        }
        return R.ok();
    }
    @PostMapping(value = "/commandInfo/completeCommand")
    @ManagerAuth
    public R completeCommand(@RequestParam("id") Integer id) {
        CommandInfo commandInfo = commandInfoService.selectById(id);
        if (commandInfo == null) {
            return R.error("指令不存在");
        }
        commandInfo.setCommandStatus(3);//完成状态
        commandInfo.setCompleteTime(new Date());
        commandInfoService.updateById(commandInfo);
        return R.ok();
    }
}
src/main/java/com/zy/asrs/controller/TaskWrkController.java
@@ -24,10 +24,10 @@
    @Autowired
    private TaskWrkService taskWrkService;
    @RequestMapping(value = "/taskWrk/{id}/auth")
    @RequestMapping(value = "/taskWrk/{wrkNo}/auth")
    @ManagerAuth
    public R get(@PathVariable("id") String id) {
        return R.ok(taskWrkService.selectById(String.valueOf(id)));
    public R get(@PathVariable("wrkNo") Integer wrkNo) {
        return R.ok(taskWrkService.selectByWrkNo(wrkNo));
    }
    @RequestMapping(value = "/taskWrk/list/auth")
@@ -165,4 +165,19 @@
        return R.ok();
    }
    @PostMapping(value = "/taskWrk/updateCommandStep")
    @ManagerAuth(memo = "更新步序")
    public R updateCommandStep(@RequestParam Integer wrkNo, @RequestParam Integer commandStep) {
        TaskWrk taskWrk = taskWrkService.selectByWrkNo(wrkNo);
        if (taskWrk == null) {
            return R.error();
        }
        Date now = new Date();
        taskWrk.setCommandStep(commandStep);
        taskWrk.setModiTime(now);//操作时间
        taskWrk.setModiUser(getUserId());//操作员
        taskWrkService.updateById(taskWrk);
        return R.ok();
    }
}
src/main/java/com/zy/asrs/entity/CommandInfo.java
@@ -52,14 +52,6 @@
    private Date startTime;
    /**
     * 结束时间
     */
    @ApiModelProperty(value= "结束时间")
    @TableField("end_time")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    private Date endTime;
    /**
     * 指令类型
     */
    @ApiModelProperty(value= "指令类型")
@@ -93,20 +85,37 @@
    @TableField("command")
    private String command;
    /**
     * 执行时间
     */
    @ApiModelProperty(value= "执行时间")
    @TableField("execute_time")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    private Date executeTime;
    /**
     * 完成时间
     */
    @ApiModelProperty(value= "完成时间")
    @TableField("complete_time")
    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
    private Date completeTime;
    public CommandInfo() {}
    public CommandInfo(Integer id, Integer wrkNo, String taskNo, Integer commandStatus, Date startTime, Date endTime, Integer commandType, String device, String deviceLog, String commandDesc, String command) {
    public CommandInfo(Integer id, Integer wrkNo, String taskNo, Integer commandStatus, Date startTime, Integer commandType, String device, String deviceLog, String commandDesc, String command, Date executeTime, Date completeTime) {
        this.id = id;
        this.wrkNo = wrkNo;
        this.taskNo = taskNo;
        this.commandStatus = commandStatus;
        this.startTime = startTime;
        this.endTime = endTime;
        this.commandType = commandType;
        this.device = device;
        this.deviceLog = deviceLog;
        this.commandDesc = commandDesc;
        this.command = command;
        this.executeTime = executeTime;
        this.completeTime = completeTime;
    }
    public String getStartTime$(){
@@ -116,11 +125,18 @@
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.startTime);
    }
    public String getEndTime$(){
        if (Cools.isEmpty(this.endTime)){
    public String getExecuteTime$(){
        if (Cools.isEmpty(this.executeTime)){
            return "";
        }
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.endTime);
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.executeTime);
    }
    public String getCompleteTime$(){
        if (Cools.isEmpty(this.completeTime)){
            return "";
        }
        return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(this.completeTime);
    }
    /**
@@ -132,8 +148,8 @@
        }
        Date endDate = new Date();
        if (!Cools.isEmpty(this.endTime)) {
            endDate = this.endTime;
        if (!Cools.isEmpty(this.completeTime)) {
            endDate = this.completeTime;
        }
        //用来获取两个时间相差的毫秒数
src/main/java/com/zy/asrs/mapper/CommandInfoMapper.java
@@ -12,4 +12,6 @@
public interface CommandInfoMapper extends BaseMapper<CommandInfo> {
    List<CommandInfo> selectByTaskNoAndWrkNo(String taskNo, Integer wrkNo);
    List<CommandInfo> selectByWrkNo(Integer wrkNo);
}
src/main/java/com/zy/asrs/service/CommandInfoService.java
@@ -9,4 +9,6 @@
    List<CommandInfo> selectByTaskNoAndWrkNo(String taskNo, Integer wrkNo);
    List<CommandInfo> selectByWrkNo(Integer wrkNo);
}
src/main/java/com/zy/asrs/service/impl/CommandInfoServiceImpl.java
@@ -15,4 +15,9 @@
    public List<CommandInfo> selectByTaskNoAndWrkNo(String taskNo, Integer wrkNo) {
        return this.baseMapper.selectByTaskNoAndWrkNo(taskNo, wrkNo);
    }
    @Override
    public List<CommandInfo> selectByWrkNo(Integer wrkNo) {
        return this.baseMapper.selectByWrkNo(wrkNo);
    }
}
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -13,6 +13,7 @@
import com.zy.asrs.mapper.WaitPakinMapper;
import com.zy.asrs.mapper.WrkMastMapper;
import com.zy.asrs.service.*;
import com.zy.asrs.utils.CommandUtils;
import com.zy.asrs.utils.Utils;
import com.zy.asrs.utils.VersionUtils;
import com.zy.common.model.LocTypeDto;
@@ -186,7 +187,7 @@
                            staProtocol.setWorkNo(dto.getWorkNo().shortValue());
                            staProtocol.setStaNo(dto.getStaNo().shortValue());
                            devpThread.setPakMk(staProtocol.getSiteId(), false);
                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                            boolean result = CommandUtils.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                            if (!result) {
                                throw new CoolException("更新plc站点信息失败");
                            }
@@ -437,7 +438,7 @@
                    staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue());
                    staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
                    devpThread.setPakMk(staProtocol.getSiteId(), false);
                    boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                    boolean result = CommandUtils.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                    if (!result) {
                        log.error("发布命令至输送线队列失败!!! [plc编号:{}]", devp.getId());
                    }
@@ -491,7 +492,7 @@
                        // 下发站点信息
                        staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue());
                        staProtocol.setStaNo(wrkMast.getStaNo().shortValue());
                        if (!MessageQueue.offer(SlaveType.Devp, crnStn.getDevpPlcId(), new Task(2, staProtocol))) {
                        if (!CommandUtils.offer(SlaveType.Devp, crnStn.getDevpPlcId(), new Task(2, staProtocol))) {
                            continue;
                        }
@@ -624,7 +625,7 @@
            crnCommand.setDestinationPosX(locMast.getRow1().shortValue());     // 目标库位排
            crnCommand.setDestinationPosY(locMast.getBay1().shortValue());     // 目标库位列
            crnCommand.setDestinationPosZ(locMast.getLev1().shortValue());     // 目标库位层
            if (!MessageQueue.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand))) {
            if (!CommandUtils.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand))) {
                log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", taskWrk.getCrnNo(), JSON.toJSON(crnCommand));
            } else {
                // 修改工作档状态 2.设备上走 => 3.吊车入库中
@@ -705,7 +706,7 @@
                    crnCommand.setDestinationPosX(crnStn.getRow().shortValue());     // 目标库位排
                    crnCommand.setDestinationPosY(crnStn.getBay().shortValue());     // 目标库位列
                    crnCommand.setDestinationPosZ(crnStn.getLev().shortValue());     // 目标库位层
                    if (!MessageQueue.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand))) {
                    if (!CommandUtils.offer(SlaveType.Crn, taskWrk.getCrnNo(), new Task(2, crnCommand))) {
                        log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", taskWrk.getCrnNo(), JSON.toJSON(crnCommand));
                    } else {
                        // 修改工作档状态 11.生成出库ID => 12.吊车出库中
@@ -892,7 +893,7 @@
        crnCommand.setDestinationPosX(sta.getRow1().shortValue());     // 目标库位排
        crnCommand.setDestinationPosY(sta.getBay1().shortValue());     // 目标库位列
        crnCommand.setDestinationPosZ(sta.getLev1().shortValue());     // 目标库位层
        if (!MessageQueue.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) {
        if (!CommandUtils.offer(SlaveType.Crn, wrkMast.getCrnNo(), new Task(2, crnCommand))) {
            log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSON(crnCommand));
        } else {
            // 修改工作档状态 11.生成出库ID => 12.吊车出库中
@@ -1112,7 +1113,7 @@
                            staProtocol.setWorkNo(dto.getWorkNo().shortValue());
                            staProtocol.setStaNo(dto.getStaNo().shortValue());
                            devpThread.setPakMk(staProtocol.getSiteId(), false);
                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                            boolean result = CommandUtils.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                            if (!result) {
                                throw new CoolException("更新plc站点信息失败");
                            }
@@ -1263,7 +1264,7 @@
            }
            // 命令下发 -------------------------------------------------------------------------------
            if (!commands.isEmpty()) {
                if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(1, commands))) {
                if (!CommandUtils.offer(SlaveType.Led, led.getId(), new Task(1, commands))) {
                    log.error("{}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
                    continue;
                } else {
src/main/java/com/zy/asrs/utils/CommandUtils.java
@@ -3,49 +3,42 @@
import com.alibaba.fastjson.JSON;
import com.core.common.SpringUtils;
import com.zy.asrs.entity.CommandInfo;
import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.entity.TaskWrk;
import com.zy.asrs.service.CommandInfoService;
import com.zy.asrs.service.WrkMastService;
import com.zy.common.utils.RedisUtil;
import com.zy.asrs.service.TaskWrkService;
import com.zy.core.cache.MessageQueue;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.Task;
import com.zy.core.model.command.CrnCommand;
import com.zy.core.model.command.RedisCommand;
import com.zy.core.model.command.CommandPackage;
import com.zy.core.model.protocol.StaProtocol;
import java.util.ArrayList;
import java.util.Date;
public class CommandUtils {
    public static void offer(SlaveType type, Integer id, Task task) {
    public static boolean offer(SlaveType type, Integer id, Task task) {
        CommandInfoService commandInfoService = SpringUtils.getBean(CommandInfoService.class);
        if (commandInfoService == null) {
            return;
            return false;
        }
        WrkMastService wrkMastService = SpringUtils.getBean(WrkMastService.class);
        if (wrkMastService == null) {
            return;
        }
        RedisUtil redisUtil = SpringUtils.getBean(RedisUtil.class);
        if (redisUtil == null) {
            return;
        TaskWrkService taskWrkService = SpringUtils.getBean(TaskWrkService.class);
        if (taskWrkService == null) {
            return false;
        }
        CommandInfo commandInfo = null;
        WrkMast wrkMast = null;
        int wrkNo = 0;
        String taskNo = null;
        TaskWrk taskWrk = null;
        int wrkNo = 0;//工作号
        String taskNo = null;//任务号
        if (type == SlaveType.Crn) {
            RedisCommand<CrnCommand> redisCommand = new RedisCommand();
            ArrayList<CrnCommand> commands = new ArrayList<>();
            CommandPackage<CrnCommand> commandPackage = new CommandPackage<>();
            CrnCommand command = (CrnCommand) task.getData();
            wrkNo = command.getTaskNo();
            if (wrkNo != 0) {
                wrkMast = wrkMastService.selectById(wrkNo);
                taskNo = wrkMast.getTaskNo();
                taskWrk = taskWrkService.selectByWrkNo(wrkNo);
                taskNo = taskWrk.getTaskNo();
            }
            commandInfo = new CommandInfo();
@@ -53,23 +46,27 @@
            commandInfo.setTaskNo(taskNo);
            commandInfo.setCommandStatus(1);
            commandInfo.setStartTime(new Date());
            commandInfo.setDevice("crn");
            commandInfo.setCommand(JSON.toJSONString(command));
            commandInfoService.insert(commandInfo);
            command.setCommandInfo(commandInfo);
            commandInfo.setDevice(SlaveType.Crn.toString());
            commands.add(command);
            redisCommand.setWrkNo(wrkNo);
            redisCommand.setCommands(commands);
            commandPackage.setWrkNo(wrkNo);
            commandPackage.setCommand(command);
            commandPackage.setDevice("堆垛机");
            commandInfo.setCommand(JSON.toJSONString(commandPackage));
            commandInfoService.insert(commandInfo);//插入指令
            //将指令进行投递
            if (!MessageQueue.offer(type, id, task)) {
                return false;
            }
            return true;
        } else if (type == SlaveType.Devp) {
            RedisCommand<StaProtocol> redisCommand = new RedisCommand();
            ArrayList<StaProtocol> commands = new ArrayList<>();
            CommandPackage<StaProtocol> commandPackage = new CommandPackage<>();
            StaProtocol staProtocol = (StaProtocol) task.getData();
            wrkNo = staProtocol.getWorkNo();
            if (wrkNo != 0) {
                wrkMast = wrkMastService.selectById(wrkNo);
                taskNo = wrkMast.getTaskNo();
                taskWrk = taskWrkService.selectByWrkNo(wrkNo);
                taskNo = taskWrk.getTaskNo();
            }
            commandInfo = new CommandInfo();
@@ -77,17 +74,23 @@
            commandInfo.setTaskNo(taskNo);
            commandInfo.setCommandStatus(1);
            commandInfo.setStartTime(new Date());
            commandInfo.setDevice("devp");
            commandInfo.setCommand(JSON.toJSONString(staProtocol));
            commandInfoService.insert(commandInfo);
            commandInfo.setDevice(SlaveType.Devp.toString());
            staProtocol.setCommandInfo(commandInfo);
            commandPackage.setWrkNo(wrkNo);
            commandPackage.setCommand(staProtocol);
            commandPackage.setDevice("输送线");
            commands.add(staProtocol);
            redisCommand.setWrkNo(wrkNo);
            redisCommand.setCommands(commands);
            commandInfo.setCommand(JSON.toJSONString(commandPackage));
            commandInfoService.insert(commandInfo);//插入指令
            //将指令进行投递
            if (!MessageQueue.offer(type, id, task)) {
                return false;
            }
            return true;
        }
        return false;
    }
}
src/main/java/com/zy/core/cache/MessageQueue.java
@@ -62,7 +62,6 @@
     * 如果发现队列已满无法添加的话,会直接返回false。
     */
    public static boolean offer(SlaveType type, Integer id, Task task) {
        CommandUtils.offer(type, id, task);
        switch (type) {
            case Crn:
                return CRN_EXCHANGE.get(id).offer(task);
src/main/java/com/zy/core/model/command/CommandPackage.java
New file
@@ -0,0 +1,23 @@
package com.zy.core.model.command;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
 * 指令数据包
 */
@Data
public class CommandPackage<T> {
    //工作号
    private Integer wrkNo;
    //执行设备
    private String device;
    //指令
    private T command;
}
src/main/java/com/zy/core/model/command/CrnCommand.java
@@ -75,9 +75,6 @@
    // 任务确认 0:未确认 1:已确认
    private Short command = 0;
    //指令信息
    private CommandInfo commandInfo;
    public void setTaskMode(Short taskMode){
        this.taskMode = taskMode;
        this.taskModeType = CrnTaskModeType.get(taskModeType);
src/main/java/com/zy/core/model/command/RedisCommand.java
File was deleted
src/main/java/com/zy/core/model/protocol/StaProtocol.java
@@ -56,9 +56,6 @@
    // 隔壁站点(台车位置)
    private String nearbySta;
    //指令信息
    private CommandInfo commandInfo;
    public BasDevp toSqlModel(){
        BasDevp basDevp = new BasDevp();
        basDevp.setDevNo(siteId);
src/main/java/com/zy/core/thread/SiemensCrnThread.java
@@ -10,16 +10,15 @@
import com.zy.asrs.entity.BasCrnOpt;
import com.zy.asrs.entity.BasCrnp;
import com.zy.asrs.entity.CommandInfo;
import com.zy.asrs.service.BasCrnOptService;
import com.zy.asrs.service.BasCrnpService;
import com.zy.asrs.service.CommandInfoService;
import com.zy.asrs.service.DeviceErrorService;
import com.zy.asrs.entity.TaskWrk;
import com.zy.asrs.service.*;
import com.zy.core.CrnThread;
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.OutputQueue;
import com.zy.core.enums.*;
import com.zy.core.model.CrnSlave;
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 lombok.Data;
@@ -27,6 +26,7 @@
import java.text.MessageFormat;
import java.util.Date;
import java.util.List;
/**
 * 堆垛机线程
@@ -461,14 +461,17 @@
        } catch (Exception ignore) {}
        if (result.IsSuccess && result1.IsSuccess) {
            //更新指令状态
            CommandInfoService commandInfoService = SpringUtils.getBean(CommandInfoService.class);
            CommandInfo commandInfo = command.getCommandInfo();
            commandInfo.setCommandStatus(2);
            commandInfoService.updateById(commandInfo);
            log.warn("堆垛机命令下发[id:{},时间:{}] >>>>> {}", slave.getId(), DateUtils.convert(new Date(), DateUtils.yyyyMMddHHmmsssss_F), JSON.toJSON(command));
            OutputQueue.CRN.offer(MessageFormat.format("【{0}】[id:{1}] >>>>> 命令下发: {2}", DateUtils.convert(new Date()), slave.getId(), JSON.toJSON(command)));
            //更新任务步序
            TaskWrkService taskWrkService = SpringUtils.getBean(TaskWrkService.class);
            TaskWrk taskWrk = taskWrkService.selectByWrkNo(command.getTaskNo().intValue());
            if (taskWrk != null) {
                taskWrk.setCommandStep(taskWrk.getCommandStep() + 1);//更新指令步序
                taskWrkService.updateById(taskWrk);
            }
            return true;
        } else {
            OutputQueue.CRN.offer(MessageFormat.format("【{0}】写入堆垛机plc数据失败 ===>> [id:{1}] [ip:{2}] [port:{3}] [rack:{4}] [slot:{5}]", DateUtils.convert(new Date()), slave.getId(), slave.getIp(), slave.getPort(), slave.getRack(), slave.getSlot()));
src/main/java/com/zy/core/thread/SiemensDevpThread.java
@@ -10,9 +10,11 @@
import com.core.common.SpringUtils;
import com.zy.asrs.entity.BasDevp;
import com.zy.asrs.entity.CommandInfo;
import com.zy.asrs.entity.TaskWrk;
import com.zy.asrs.service.BasDevpService;
import com.zy.asrs.service.CommandInfoService;
import com.zy.asrs.service.DeviceErrorService;
import com.zy.asrs.service.TaskWrkService;
import com.zy.core.DevpThread;
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.OutputQueue;
@@ -312,11 +314,13 @@
                staProtocol.setPakMk(true);
            }
            //更新指令状态
            CommandInfoService commandInfoService = SpringUtils.getBean(CommandInfoService.class);
            CommandInfo commandInfo = staProtocol.getCommandInfo();
            commandInfo.setCommandStatus(2);
            commandInfoService.updateById(commandInfo);
            //更新任务步序
            TaskWrkService taskWrkService = SpringUtils.getBean(TaskWrkService.class);
            TaskWrk taskWrk = taskWrkService.selectByWrkNo(staProtocol.getWorkNo().intValue());
            if (taskWrk != null) {
                taskWrk.setCommandStep(taskWrk.getCommandStep() + 1);//更新指令步序
                taskWrkService.updateById(taskWrk);
            }
        }
    }
src/main/resources/mapper/CommandInfoMapper.xml
@@ -9,11 +9,12 @@
        <result column="task_no" property="taskNo" />
        <result column="command_status" property="commandStatus" />
        <result column="start_time" property="startTime" />
        <result column="end_time" property="endTime" />
        <result column="command_type" property="commandType" />
        <result column="device" property="device" />
        <result column="device_log" property="deviceLog" />
        <result column="command_desc" property="commandDesc" />
        <result column="execute_time" property="executeTime" />
        <result column="complete_time" property="completeTime" />
    </resultMap>
@@ -23,4 +24,9 @@
        and task_no = #{taskNo}
    </select>
    <select id="selectByWrkNo" resultMap="BaseResultMap">
        select * from wcs_command_info
        where wrk_no = #{wrkNo}
    </select>
</mapper>
src/main/webapp/views/commandManage/commandManage.html
@@ -10,6 +10,11 @@
        <script type="text/javascript" src="../../static/wcs/js/common.js"></script>
        <script type="text/javascript" src="../../static/wcs/js/vue.min.js"></script>
        <script type="text/javascript" src="../../static/wcs/js/element.js"></script>
        <style>
            .el-table .success-row {
                background: #d5ffc0;
            }
        </style>
    </head>
    <body>
@@ -35,13 +40,15 @@
                            <el-button type="primary" @click="resetParam">重置</el-button>
                        </el-form-item>
                    </el-form>
                    <el-table ref="singleTable" :data="tableData" style="width: 100%;">
                    <el-table ref="singleTable" :data="tableData" style="width: 100%;" :row-class-name="tableRowClassName">
                        <el-table-column label="操作" width="100">
                            <template slot-scope="scope">
                                <el-dropdown @command="(command)=>{handleCommand(command, scope.row)}">
                                    <el-button icon="el-icon-more" size="mini" type="primary"></el-button>
                                    <el-dropdown-menu slot="dropdown">
                                        <el-dropdown-item command="showTask">查看任务</el-dropdown-item>
                                        <el-dropdown-item command="executeCommand">执行指令</el-dropdown-item>
                                        <el-dropdown-item command="completeCommand">完成指令</el-dropdown-item>
                                    </el-dropdown-menu>
                                </el-dropdown>
                            </template>
@@ -66,9 +73,11 @@
                        </el-table-column>
                        <el-table-column show-overflow-tooltip property="startTime$" label="开始时间">
                        </el-table-column>
                        <el-table-column show-overflow-tooltip property="endTime$" label="结束时间">
                        <el-table-column show-overflow-tooltip property="executeTime$" label="执行时间">
                        </el-table-column>
                        <el-table-column show-overflow-tooltip property="command" label="命令报文">
                        <el-table-column show-overflow-tooltip property="completeTime$" label="完成时间">
                        </el-table-column>
                        <el-table-column show-overflow-tooltip property="command" label="命令报文" width="250">
                        </el-table-column>
                    </el-table>
@@ -98,7 +107,8 @@
                        task_no: null,
                        status: null,
                        wrk_no: null
                    }
                    },
                    commandStep: -1
                },
                created() {
                    this.init()
@@ -110,12 +120,14 @@
                    init() {
                        let taskNo = getQueryVariable('taskNo')
                        let wrkNo = getQueryVariable('wrkNo')
                        let commandStep = getQueryVariable('commandStep')
                        if (taskNo != false) {
                            this.tableSearchParam.task_no = taskNo
                        }
                        if (wrkNo != false) {
                            this.tableSearchParam.wrk_no = wrkNo
                        }
                        this.commandStep = parseInt(commandStep)
                        this.getTableData()
                    },
@@ -172,6 +184,14 @@
                                //查看任务
                                this.showTask(row)
                                break;
                            case "executeCommand":
                                //执行指令
                                this.executeCommand(row)
                                break;
                            case "completeCommand":
                                //完成指令
                                this.completeCommand(row)
                                break;
                        }
                    },
                    showTask(row) {
@@ -185,6 +205,72 @@
                            content: '../taskWrk/taskWrk.html?taskNo=' + row.taskNo + "&wrkNo=" + row.wrkNo,
                            success: function(layero, index) {}
                        });
                    },
                    tableRowClassName({row, rowIndex}) {
                        if (rowIndex === this.commandStep) {
                            return 'success-row';
                        }
                        return '';
                    },
                    executeCommand(row) {
                        //执行指令
                        let that = this
                        $.ajax({
                            url: baseUrl + "/commandInfo/executeCommand",
                            headers: {
                                'token': localStorage.getItem('token')
                            },
                            data: {
                                id: row.id
                            },
                            method: 'POST',
                            success: function(res) {
                                if (res.code == 200) {
                                    that.$message({
                                        message: "执行成功",
                                        type: 'success'
                                    });
                                    that.getTableData()
                                } else if (res.code === 403) {
                                    top.location.href = baseUrl + "/";
                                } else {
                                    that.$message({
                                        message: res.msg,
                                        type: 'error'
                                    });
                                }
                            }
                        });
                    },
                    completeCommand(row) {
                        //完成指令
                        let that = this
                        $.ajax({
                            url: baseUrl + "/commandInfo/completeCommand",
                            headers: {
                                'token': localStorage.getItem('token')
                            },
                            data: {
                                id: row.id
                            },
                            method: 'POST',
                            success: function(res) {
                                if (res.code == 200) {
                                    that.$message({
                                        message: "完成成功",
                                        type: 'success'
                                    });
                                    that.getTableData()
                                } else if (res.code === 403) {
                                    top.location.href = baseUrl + "/";
                                } else {
                                    that.$message({
                                        message: res.msg,
                                        type: 'error'
                                    });
                                }
                            }
                        });
                    }
                }
            })
src/main/webapp/views/taskWrk/commandManage.html
New file
@@ -0,0 +1,329 @@
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>指令管理</title>
        <link rel="stylesheet" href="../../static/wcs/css/element.css">
        <script type="text/javascript" src="../../static/wcs/js/jquery/jquery-3.3.1.min.js"></script>
        <script type="text/javascript" src="../../static/wms/layui/layui.js"></script>
        <script type="text/javascript" src="../../static/wcs/js/common.js"></script>
        <script type="text/javascript" src="../../static/wcs/js/vue.min.js"></script>
        <script type="text/javascript" src="../../static/wcs/js/element.js"></script>
        <style>
            .el-table .success-row {
                background: #d5ffc0;
            }
        </style>
    </head>
    <body>
        <div id="app" style="display: flex;justify-content: center;flex-wrap: wrap;">
            <div style="width: 100%;">
                <el-card class="box-card">
                    <el-form :inline="true" :model="tableSearchParam" class="demo-form-inline">
                        <el-form-item label="任务号">
                            <el-input v-model="tableSearchParam.task_no" placeholder="任务号" readonly></el-input>
                        </el-form-item>
                        <el-form-item label="工作号">
                            <el-input v-model="tableSearchParam.wrk_no" placeholder="工作号" readonly></el-input>
                        </el-form-item>
                        <el-form-item label="指令步序">
                            <el-input-number v-model="commandStep" placeholder="指令步序" :min="0"></el-input-number>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="updateCommandStep">更新步序</el-button>
                        </el-form-item>
                    </el-form>
                    <el-table ref="singleTable" :data="tableData" style="width: 100%;" :row-class-name="tableRowClassName">
                        <el-table-column label="操作" width="100">
                            <template slot-scope="scope">
                                <el-dropdown @command="(command)=>{handleCommand(command, scope.row)}">
                                    <el-button icon="el-icon-more" size="mini" type="primary"></el-button>
                                    <el-dropdown-menu slot="dropdown">
                                        <el-dropdown-item command="executeCommand">重发指令</el-dropdown-item>
                                        <el-dropdown-item command="completeCommand">完成指令</el-dropdown-item>
                                    </el-dropdown-menu>
                                </el-dropdown>
                            </template>
                        </el-table-column>
                        <el-table-column property="index" label="指令编号">
                            <template slot-scope="scope">
                                {{ scope.$index }}
                            </template>
                        </el-table-column>
                        <el-table-column property="wrkNo" label="工作号">
                        </el-table-column>
                        <el-table-column property="taskNo" label="任务号">
                        </el-table-column>
                        <el-table-column property="commandStatus$" label="指令状态">
                        </el-table-column>
                        <el-table-column show-overflow-tooltip property="durationTime" label="持续时长">
                        </el-table-column>
                        <el-table-column property="commandType" label="指令类型">
                        </el-table-column>
                        <el-table-column property="device" label="设备">
                        </el-table-column>
                        <el-table-column property="deviceLog" label="设备执行信息">
                        </el-table-column>
                        <el-table-column property="commandDesc" label="命令描述">
                        </el-table-column>
                        <el-table-column show-overflow-tooltip property="startTime$" label="开始时间">
                        </el-table-column>
                        <el-table-column show-overflow-tooltip property="executeTime$" label="执行时间">
                        </el-table-column>
                        <el-table-column show-overflow-tooltip property="completeTime$" label="完成时间">
                        </el-table-column>
                        <el-table-column show-overflow-tooltip property="command" label="命令报文" width="250">
                        </el-table-column>
                    </el-table>
                    <div style="margin-top: 10px;">
                        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                            :current-page="currentPage" :page-sizes="pageSizes" :page-size="pageSize"
                            layout="total, sizes, prev, pager, next, jumper" :total="pageTotal">
                        </el-pagination>
                    </div>
                </el-card>
            </div>
        </div>
        <script>
            var $layui = layui.config({
                base: baseUrl + "/static/wms/layui/lay/modules/"
            }).use(['layer', 'form'], function() {})
            var app = new Vue({
                el: '#app',
                data: {
                    tableData: [],
                    currentPage: 1,
                    pageSizes: [16, 30, 50, 100, 150, 200],
                    pageSize: 16,
                    pageTotal: 0,
                    tableSearchParam: {
                        task_no: null,
                        status: null,
                        wrk_no: null
                    },
                    commandStep: -1
                },
                created() {
                    this.init()
                },
                watch: {
                },
                methods: {
                    init() {
                        let taskNo = getQueryVariable('taskNo')
                        let wrkNo = getQueryVariable('wrkNo')
                        if (taskNo != false) {
                            this.tableSearchParam.task_no = taskNo
                        }
                        if (wrkNo != false) {
                            this.tableSearchParam.wrk_no = wrkNo
                        }
                        this.getTableData()
                    },
                    getTableData() {
                        let that = this;
                        let data = this.tableSearchParam
                        data.curr = this.currentPage
                        data.limit = this.pageSize
                        $.ajax({
                            url: baseUrl + "/commandInfo/list/auth",
                            headers: {
                                'token': localStorage.getItem('token')
                            },
                            data: data,
                            dataType: 'json',
                            contentType: 'application/json;charset=UTF-8',
                            method: 'GET',
                            success: function(res) {
                                if (res.code == 200) {
                                    that.tableData = res.data.records
                                    that.pageTotal = res.data.total
                                } else if (res.code === 403) {
                                    top.location.href = baseUrl + "/";
                                } else {
                                    that.$message({
                                        message: res.msg,
                                        type: 'error'
                                    });
                                }
                            }
                        });
                        $.ajax({
                            url: baseUrl + "/taskWrk/" + this.tableSearchParam.wrk_no + "/auth",
                            headers: {
                                'token': localStorage.getItem('token')
                            },
                            data: data,
                            dataType: 'json',
                            contentType: 'application/json;charset=UTF-8',
                            method: 'GET',
                            success: function(res) {
                                if (res.code == 200) {
                                    that.commandStep = parseInt(res.data.commandStep)
                                } else if (res.code === 403) {
                                    top.location.href = baseUrl + "/";
                                } else {
                                    that.$message({
                                        message: res.msg,
                                        type: 'error'
                                    });
                                }
                            }
                        });
                    },
                    handleSizeChange(val) {
                        console.log(`每页 ${val} 条`);
                        this.pageSize = val
                        this.getTableData()
                    },
                    handleCurrentChange(val) {
                        console.log(`当前页: ${val}`);
                        this.currentPage = val
                        this.getTableData()
                    },
                    resetParam() {
                        this.tableSearchParam = {
                            task_no: null,
                            status: null,
                            wrk_no: null
                        }
                        this.getTableData()
                    },
                    handleCommand(command, row) {
                        switch (command) {
                            case "showTask":
                                //查看任务
                                this.showTask(row)
                                break;
                            case "executeCommand":
                                //执行指令
                                this.executeCommand(row)
                                break;
                            case "completeCommand":
                                //完成指令
                                this.completeCommand(row)
                                break;
                        }
                    },
                    showTask(row) {
                        //查看任务
                        $layui.layer.open({
                            type: 2,
                            title: '任务管理',
                            maxmin: true,
                            area: [top.detailWidth, top.detailHeight],
                            shadeClose: true,
                            content: '../taskWrk/taskWrk.html?taskNo=' + row.taskNo + "&wrkNo=" + row.wrkNo,
                            success: function(layero, index) {}
                        });
                    },
                    tableRowClassName({row, rowIndex}) {
                        if (rowIndex === parseInt(this.commandStep)) {
                            return 'success-row';
                        }
                        return '';
                    },
                    executeCommand(row) {
                        //执行指令
                        let that = this
                        $.ajax({
                            url: baseUrl + "/commandInfo/executeCommand",
                            headers: {
                                'token': localStorage.getItem('token')
                            },
                            data: {
                                id: row.id
                            },
                            method: 'POST',
                            success: function(res) {
                                if (res.code == 200) {
                                    that.$message({
                                        message: "执行成功",
                                        type: 'success'
                                    });
                                    that.getTableData()
                                } else if (res.code === 403) {
                                    top.location.href = baseUrl + "/";
                                } else {
                                    that.$message({
                                        message: res.msg,
                                        type: 'error'
                                    });
                                }
                            }
                        });
                    },
                    completeCommand(row) {
                        //完成指令
                        let that = this
                        $.ajax({
                            url: baseUrl + "/commandInfo/completeCommand",
                            headers: {
                                'token': localStorage.getItem('token')
                            },
                            data: {
                                id: row.id
                            },
                            method: 'POST',
                            success: function(res) {
                                if (res.code == 200) {
                                    that.$message({
                                        message: "完成成功",
                                        type: 'success'
                                    });
                                    that.getTableData()
                                } else if (res.code === 403) {
                                    top.location.href = baseUrl + "/";
                                } else {
                                    that.$message({
                                        message: res.msg,
                                        type: 'error'
                                    });
                                }
                            }
                        });
                    },
                    updateCommandStep() {
                        //更新步序
                        let that = this
                        $.ajax({
                            url: baseUrl + "/taskWrk/updateCommandStep",
                            headers: {
                                'token': localStorage.getItem('token')
                            },
                            data: {
                                wrkNo: this.tableSearchParam.wrk_no,
                                commandStep: this.commandStep
                            },
                            method: 'POST',
                            success: function(res) {
                                if (res.code == 200) {
                                    that.$message({
                                        message: "更新成功",
                                        type: 'success'
                                    });
                                    that.getTableData()
                                } else if (res.code === 403) {
                                    top.location.href = baseUrl + "/";
                                } else {
                                    that.$message({
                                        message: res.msg,
                                        type: 'error'
                                    });
                                }
                            }
                        });
                    },
                }
            })
        </script>
    </body>
</html>
src/main/webapp/views/taskWrk/taskWrk.html
@@ -171,7 +171,7 @@
                                break;
                            case "assign":
                                //派发任务
                                this.assginWrk(row)
                                this.assignWrk(row)
                                break;
                            case "complete":
                                //完结任务
@@ -192,11 +192,11 @@
                            maxmin: true,
                            area: [top.detailWidth, top.detailHeight],
                            shadeClose: true,
                            content: '../commandManage/commandManage.html?taskNo=' + row.taskNo + "&wrkNo=" + wrkNo,
                            content: 'commandManage.html?taskNo=' + row.taskNo + "&wrkNo=" + wrkNo,
                            success: function(layero, index) {}
                        });
                    },
                    assginWrk(row){
                    assignWrk(row){
                        //派发任务
                        let that = this
                        $.ajax({